File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -54,8 +54,18 @@ export function fromBech32Address(hash: string) {
5454}
5555
5656export function isBTCAddress ( hash : string ) {
57+ let pkscript = null ;
58+ try {
59+ pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . bitcoin ) . toString ( 'hex' ) ;
60+ } catch ( error ) {
61+ try {
62+ pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . testnet ) . toString ( 'hex' ) ;
63+ } catch ( error ) {
64+ return false ;
65+ }
66+ }
67+
5768 try {
58- const pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . testnet ) . toString ( 'hex' ) ;
5969 const pkscriptBuf = Buffer . from ( pkscript , 'hex' ) ;
6070 const pkscriptHash = keccak256 ( pkscriptBuf ) ;
6171 pkscriptHash . slice ( - 40 ) ;
@@ -65,8 +75,18 @@ export function isBTCAddress(hash: string) {
6575 }
6676}
6777export function fromBTCAddress ( hash : string ) {
78+ let pkscript = null ;
79+ try {
80+ pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . bitcoin ) . toString ( 'hex' ) ;
81+ } catch ( error ) {
82+ try {
83+ pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . testnet ) . toString ( 'hex' ) ;
84+ } catch ( error ) {
85+ return hash ;
86+ }
87+ }
88+
6889 try {
69- const pkscript = bitcoin . address . toOutputScript ( hash , bitcoin . networks . testnet ) . toString ( 'hex' ) ;
7090 const pkscriptBuf = Buffer . from ( pkscript , 'hex' ) ;
7191 const pkscriptHash = keccak256 ( pkscriptBuf ) ;
7292 const addr = pkscriptHash . slice ( - 40 ) ;
You can’t perform that action at this time.
0 commit comments