@@ -13,6 +13,11 @@ const FUTURE_SEGWIT_MIN_SIZE = 2;
13
13
const FUTURE_SEGWIT_MAX_VERSION = 16 ;
14
14
const FUTURE_SEGWIT_MIN_VERSION = 1 ;
15
15
const FUTURE_SEGWIT_VERSION_DIFF = 0x50 ;
16
+ const FUTURE_SEGWIT_VERSION_WARNING =
17
+ 'WARNING: Sending to a future segwit version address can lead to loss of funds. ' +
18
+ 'End users MUST be warned carefully in the GUI and asked if they wish to proceed ' +
19
+ 'with caution. Wallets should verify the segwit version from the output of fromBech32, ' +
20
+ 'then decide when it is safe to use which version of segwit.' ;
16
21
function _toFutureSegwitAddress ( output , network ) {
17
22
const data = output . slice ( 2 ) ;
18
23
if (
@@ -28,6 +33,7 @@ function _toFutureSegwitAddress(output, network) {
28
33
throw new TypeError ( 'Invalid version for segwit address' ) ;
29
34
if ( output [ 1 ] !== data . length )
30
35
throw new TypeError ( 'Invalid script for segwit address' ) ;
36
+ console . warn ( FUTURE_SEGWIT_VERSION_WARNING ) ;
31
37
return toBech32 ( data , version , network . bech32 ) ;
32
38
}
33
39
function fromBase58Check ( address ) {
@@ -128,11 +134,13 @@ function toOutputScript(address, network) {
128
134
decodeBech32 . version <= FUTURE_SEGWIT_MAX_VERSION &&
129
135
decodeBech32 . data . length >= FUTURE_SEGWIT_MIN_SIZE &&
130
136
decodeBech32 . data . length <= FUTURE_SEGWIT_MAX_SIZE
131
- )
137
+ ) {
138
+ console . warn ( FUTURE_SEGWIT_VERSION_WARNING ) ;
132
139
return bscript . compile ( [
133
140
decodeBech32 . version + FUTURE_SEGWIT_VERSION_DIFF ,
134
141
decodeBech32 . data ,
135
142
] ) ;
143
+ }
136
144
}
137
145
}
138
146
throw new Error ( address + ' has no matching Script' ) ;
0 commit comments