@@ -13,6 +13,11 @@ const FUTURE_SEGWIT_MIN_SIZE = 2;
1313const FUTURE_SEGWIT_MAX_VERSION = 16 ;
1414const FUTURE_SEGWIT_MIN_VERSION = 1 ;
1515const 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.' ;
1621function _toFutureSegwitAddress ( output , network ) {
1722 const data = output . slice ( 2 ) ;
1823 if (
@@ -28,6 +33,7 @@ function _toFutureSegwitAddress(output, network) {
2833 throw new TypeError ( 'Invalid version for segwit address' ) ;
2934 if ( output [ 1 ] !== data . length )
3035 throw new TypeError ( 'Invalid script for segwit address' ) ;
36+ console . warn ( FUTURE_SEGWIT_VERSION_WARNING ) ;
3137 return toBech32 ( data , version , network . bech32 ) ;
3238}
3339function fromBase58Check ( address ) {
@@ -128,11 +134,13 @@ function toOutputScript(address, network) {
128134 decodeBech32 . version <= FUTURE_SEGWIT_MAX_VERSION &&
129135 decodeBech32 . data . length >= FUTURE_SEGWIT_MIN_SIZE &&
130136 decodeBech32 . data . length <= FUTURE_SEGWIT_MAX_SIZE
131- )
137+ ) {
138+ console . warn ( FUTURE_SEGWIT_VERSION_WARNING ) ;
132139 return bscript . compile ( [
133140 decodeBech32 . version + FUTURE_SEGWIT_VERSION_DIFF ,
134141 decodeBech32 . data ,
135142 ] ) ;
143+ }
136144 }
137145 }
138146 throw new Error ( address + ' has no matching Script' ) ;
0 commit comments