New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@secux/app-btc

Package Overview
Dependencies
Maintainers
0
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/app-btc - npm Package Compare versions

Comparing version 3.2.13 to 3.2.14

3

lib/interface.d.ts

@@ -26,3 +26,4 @@ /*!

P2TR = 4,
__LENGTH = 5
P2WSH = 5,
__LENGTH = 6
}

@@ -29,0 +30,0 @@ export declare enum CoinType {

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_SignOption=exports.ow_AddressOption=exports.ow_TransactionObject=exports.isOutuptScriptExtended=exports.isOutuptScript=exports.isOutputAddress=exports.ow_txOutput=exports.ow_txOutputScriptExtened=exports.ow_txOutputScript=exports.ow_txOutputAddress=exports.ow_txInput=exports.ow_PathObject=exports.ow_hashString=exports.ow_hexString=exports.ow_accountPath=exports.ow_path=exports.ow_balance=exports.btcPurposes=exports.btcCoinTypes=exports.coinmap=exports.CoinType=exports.ScriptType=exports.OPCODES=void 0;const ow_1=require("ow"),constants=require("./coindef"),utils=require("@secux/utility");var ScriptType,CoinType,coindef_1=require("./coindef");Object.defineProperty(exports,"OPCODES",{enumerable:!0,get:function(){return coindef_1.OPCODES}}),function(ScriptType){ScriptType[ScriptType.P2PKH=0]="P2PKH",ScriptType[ScriptType.P2WPKH=1]="P2WPKH",ScriptType[ScriptType.P2SH_P2PKH=2]="P2SH_P2PKH",ScriptType[ScriptType.P2SH_P2WPKH=3]="P2SH_P2WPKH",ScriptType[ScriptType.P2TR=4]="P2TR",ScriptType[ScriptType.__LENGTH=5]="__LENGTH"}(ScriptType=exports.ScriptType||(exports.ScriptType={})),function(CoinType){CoinType[CoinType.BITCOIN=0]="BITCOIN",CoinType[CoinType.TESTNET=1]="TESTNET",CoinType[CoinType.REGTEST=2]="REGTEST",CoinType[CoinType.LITECOIN=3]="LITECOIN",CoinType[CoinType.BITCOINCASH=4]="BITCOINCASH",CoinType[CoinType.GROESTL=5]="GROESTL",CoinType[CoinType.DIGIBYTE=6]="DIGIBYTE",CoinType[CoinType.DASH=7]="DASH",CoinType[CoinType.DOGECOIN=8]="DOGECOIN",CoinType[CoinType.__LENGTH=9]="__LENGTH"}(CoinType=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze(Object.values(CoinType).slice(0,CoinType.__LENGTH).map((x=>constants[x.toLowerCase()]))),exports.btcCoinTypes=Object.freeze(exports.coinmap.map((x=>Object.freeze(x.coinType)))),exports.btcPurposes=Object.freeze([Object.freeze(44),Object.freeze(49),Object.freeze(84),Object.freeze(86)]),exports.ow_balance=ow_1.default.any(ow_1.default.number.integer.positive,utils.owTool.numberString),exports.ow_path=utils.ow_strictPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_accountPath=utils.ow_accountPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_hexString=utils.owTool.hexString,exports.ow_hashString=utils.owTool.hashString,exports.ow_PathObject=ow_1.default.object.exactShape({coin:ow_1.default.number.inRange(0,CoinType.__LENGTH-1),script:ow_1.default.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_txInput=ow_1.default.object.exactShape({hash:exports.ow_hashString,vout:ow_1.default.number.greaterThanOrEqual(0),txHex:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString),script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1),satoshis:exports.ow_balance,path:exports.ow_path,publickey:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString,ow_1.default.buffer)}),exports.ow_txOutputAddress=ow_1.default.object.exactShape({address:exports.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=ow_1.default.object.exactShape({scriptHex:exports.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=ow_1.default.object.exactShape({publickey:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString,ow_1.default.buffer),path:exports.ow_path,satoshis:exports.ow_balance,script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_txOutput=ow_1.default.object.exactShape({to:ow_1.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:ow_1.default.any(ow_1.default.undefined,exports.ow_txOutputScriptExtened)}),exports.isOutputAddress=function(output){const out=output;if(out.address)return out},exports.isOutuptScript=function(output){const out=output;if(out.scriptHex)return out},exports.isOutuptScriptExtended=function(output){try{return(0,ow_1.default)(output,exports.ow_txOutputScriptExtened),output}catch(error){}},exports.ow_TransactionObject=ow_1.default.object.partialShape({rawTx:exports.ow_hexString,publickeys:ow_1.default.array.ofType(ow_1.default.any(exports.ow_hexString,ow_1.default.buffer)),coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1)}),exports.ow_AddressOption=ow_1.default.object.exactShape({coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1),script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_SignOption=ow_1.default.object.partialShape({coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1),feeRate:ow_1.default.optional.number.greaterThanOrEqual(1),isRBF:ow_1.default.optional.boolean});
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_SignOption=exports.ow_AddressOption=exports.ow_TransactionObject=exports.isOutuptScriptExtended=exports.isOutuptScript=exports.isOutputAddress=exports.ow_txOutput=exports.ow_txOutputScriptExtened=exports.ow_txOutputScript=exports.ow_txOutputAddress=exports.ow_txInput=exports.ow_PathObject=exports.ow_hashString=exports.ow_hexString=exports.ow_accountPath=exports.ow_path=exports.ow_balance=exports.btcPurposes=exports.btcCoinTypes=exports.coinmap=exports.CoinType=exports.ScriptType=exports.OPCODES=void 0;const ow_1=require("ow"),constants=require("./coindef"),utils=require("@secux/utility");var ScriptType,CoinType,coindef_1=require("./coindef");Object.defineProperty(exports,"OPCODES",{enumerable:!0,get:function(){return coindef_1.OPCODES}}),function(ScriptType){ScriptType[ScriptType.P2PKH=0]="P2PKH",ScriptType[ScriptType.P2WPKH=1]="P2WPKH",ScriptType[ScriptType.P2SH_P2PKH=2]="P2SH_P2PKH",ScriptType[ScriptType.P2SH_P2WPKH=3]="P2SH_P2WPKH",ScriptType[ScriptType.P2TR=4]="P2TR",ScriptType[ScriptType.P2WSH=5]="P2WSH",ScriptType[ScriptType.__LENGTH=6]="__LENGTH"}(ScriptType=exports.ScriptType||(exports.ScriptType={})),function(CoinType){CoinType[CoinType.BITCOIN=0]="BITCOIN",CoinType[CoinType.TESTNET=1]="TESTNET",CoinType[CoinType.REGTEST=2]="REGTEST",CoinType[CoinType.LITECOIN=3]="LITECOIN",CoinType[CoinType.BITCOINCASH=4]="BITCOINCASH",CoinType[CoinType.GROESTL=5]="GROESTL",CoinType[CoinType.DIGIBYTE=6]="DIGIBYTE",CoinType[CoinType.DASH=7]="DASH",CoinType[CoinType.DOGECOIN=8]="DOGECOIN",CoinType[CoinType.__LENGTH=9]="__LENGTH"}(CoinType=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze(Object.values(CoinType).slice(0,CoinType.__LENGTH).map((x=>constants[x.toLowerCase()]))),exports.btcCoinTypes=Object.freeze(exports.coinmap.map((x=>Object.freeze(x.coinType)))),exports.btcPurposes=Object.freeze([Object.freeze(44),Object.freeze(49),Object.freeze(84),Object.freeze(86)]),exports.ow_balance=ow_1.default.any(ow_1.default.number.integer.positive,utils.owTool.numberString),exports.ow_path=utils.ow_strictPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_accountPath=utils.ow_accountPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_hexString=utils.owTool.hexString,exports.ow_hashString=utils.owTool.hashString,exports.ow_PathObject=ow_1.default.object.exactShape({coin:ow_1.default.number.inRange(0,CoinType.__LENGTH-1),script:ow_1.default.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_txInput=ow_1.default.object.exactShape({hash:exports.ow_hashString,vout:ow_1.default.number.greaterThanOrEqual(0),txHex:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString),script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1),satoshis:exports.ow_balance,path:exports.ow_path,publickey:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString,ow_1.default.buffer)}),exports.ow_txOutputAddress=ow_1.default.object.exactShape({address:exports.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=ow_1.default.object.exactShape({scriptHex:exports.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=ow_1.default.object.exactShape({publickey:ow_1.default.any(ow_1.default.undefined,exports.ow_hexString,ow_1.default.buffer),path:exports.ow_path,satoshis:exports.ow_balance,script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_txOutput=ow_1.default.object.exactShape({to:ow_1.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:ow_1.default.any(ow_1.default.undefined,exports.ow_txOutputScriptExtened)}),exports.isOutputAddress=function(output){const out=output;if(out.address)return out},exports.isOutuptScript=function(output){const out=output;if(out.scriptHex)return out},exports.isOutuptScriptExtended=function(output){try{return(0,ow_1.default)(output,exports.ow_txOutputScriptExtened),output}catch(error){}},exports.ow_TransactionObject=ow_1.default.object.partialShape({rawTx:exports.ow_hexString,publickeys:ow_1.default.array.ofType(ow_1.default.any(exports.ow_hexString,ow_1.default.buffer)),coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1)}),exports.ow_AddressOption=ow_1.default.object.exactShape({coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1),script:ow_1.default.optional.number.inRange(0,ScriptType.__LENGTH-1)}),exports.ow_SignOption=ow_1.default.object.partialShape({coin:ow_1.default.optional.number.inRange(0,CoinType.__LENGTH-1),feeRate:ow_1.default.optional.number.greaterThanOrEqual(1),isRBF:ow_1.default.optional.boolean});

@@ -29,3 +29,3 @@ /*!

* @param {CoinType} coin
* @param {Buffer} param1 [publickey | hashed publickey]
* @param {Buffer} opt [publickey | hashed publickey]
* @returns

@@ -54,3 +54,3 @@ */

* @param {CoinType} coin
* @param {Buffer} param1 [publickey | hashed publickey]
* @param {Buffer} opt [publickey | hashed publickey]
* @returns

@@ -67,2 +67,16 @@ */

/**
* Pay to Witness Script Hash
* @param {CoinType} coin
* @param {Buffer} opt [witness | hashed redeem]
* @returns
*/
static p2wsh(coin: CoinType, opt: {
witness?: Array<Buffer>;
hash?: Buffer;
}): {
address: string;
scriptPublickey: Buffer;
redeemHash: Buffer;
};
/**
* Pay to MultiSig

@@ -94,4 +108,5 @@ * @param {number} m

static isP2WPKH(script: Buffer): boolean;
static isP2WSH(script: Buffer): boolean;
static isP2TR(script: Buffer): boolean;
}
declare function Hash160(publickey: Buffer): Buffer;

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.logger=exports.Hash160=exports.CoinType=exports.PaymentBTC=void 0;const bech32_1=require("bech32"),hash_js_1=require("hash.js"),interface_1=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return interface_1.CoinType}});const bs58_1=require("@secux/utility/lib/bs58"),utility_1=require("@secux/utility"),utils_1=require("./utils");exports.logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"payment"});class PaymentBTC{static CoinSupported(coin){if(coin===interface_1.CoinType.BITCOINCASH)throw Error("Please use class PaymentBCH instead");if(coin===interface_1.CoinType.GROESTL)throw Error("Please use class PaymentGRS instead")}static p2pkh(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");const pkHash=opt.hash?opt.hash:Hash160(opt.publickey);null===exports.logger||void 0===exports.logger||exports.logger.info(`publickey hash: ${pkHash.toString("hex")}`);const network=interface_1.coinmap[coin],address=this.bs58check.encode(pkHash,Buffer.from([network.pubKeyHash])),op=Buffer.from([interface_1.OPCODES.OP_DUP,interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUALVERIFY,interface_1.OPCODES.OP_CHECKSIG]),scriptPublickey=Buffer.concat([op,pkHash,check]),redeemHash=Hash160(scriptPublickey);return null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`),{address,scriptPublickey,redeemHash}}static p2sh(coin,redeemHash){this.CoinSupported(coin);const network=interface_1.coinmap[coin],address=this.bs58check.encode(redeemHash,Buffer.from([network.scriptHash])),op=Buffer.from([interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUAL]);return{address,scriptPublickey:Buffer.concat([op,redeemHash,check])}}static p2wpkh(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");const pkHash=opt.hash?opt.hash:Hash160(opt.publickey);null===exports.logger||void 0===exports.logger||exports.logger.info(`publickey hash: ${pkHash.toString("hex")}`);let network=interface_1.coinmap[coin];const words=bech32_1.bech32.toWords(pkHash);words.unshift(0);const address=bech32_1.bech32.encode(network.bech32,words),op=Buffer.from([interface_1.OPCODES.OP_0,20]),scriptPublickey=Buffer.concat([op,pkHash]),redeemHash=Hash160(scriptPublickey);return null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`),{address,scriptPublickey,redeemHash}}static p2ms(m,publickeys){if(m<=0)throw Error('Invalid paramter "m"');m+=interface_1.OPCODES.OP_INT_BASE;const n=publickeys.length+interface_1.OPCODES.OP_INT_BASE,multi_pk=Buffer.concat(publickeys),redeem=Buffer.concat([Buffer.from([m]),multi_pk,Buffer.from([n]),Buffer.from([interface_1.OPCODES.OP_CHECKMULTISIG])]),redeemHash=Hash160(redeem);null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`);const op=Buffer.from([interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUAL]);return{redeem,scriptPubicKey:Buffer.concat([op,redeemHash,check])}}static p2tr(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");let tweaked=opt.hash;void 0===tweaked&&(tweaked=(0,utils_1.toTweakedPublickey)(opt.publickey));const network=interface_1.coinmap[coin],words=bech32_1.bech32.toWords(tweaked);words.unshift(1);const address=bech32_1.bech32m.encode(network.bech32,words),header=Buffer.from([81,32]);return{address,scriptPublickey:Buffer.concat([header,tweaked])}}static decode(coin,address){const network=interface_1.coinmap[coin];if(network.bech32&&RegExp(`^${network.bech32}`,"i").test(address)){let result;if("p"===address.slice(network.bech32.length+1)[0])result=bech32_1.bech32m.decode(address);else result=bech32_1.bech32.decode(address);const version=result.words.shift();switch(version){case 0:const hash160=Buffer.from(bech32_1.bech32.fromWords(result.words));return null===exports.logger||void 0===exports.logger||exports.logger.debug(`bech32 address: ${address}\nbech32 decoded: ${hash160.toString("hex")}`),this.p2wpkh(coin,{hash:hash160}).scriptPublickey;case 1:const tweaked=Buffer.from(bech32_1.bech32m.fromWords(result.words));return null===exports.logger||void 0===exports.logger||exports.logger.debug(`bech32m address: ${address}\nbech32m decoded: ${tweaked.toString("hex")}`),this.p2tr(coin,{hash:tweaked}).scriptPublickey;default:throw Error(`ArgumentError: unsupported witness version, got "${version}" from address "${address}"`)}}try{const hash160=this.bs58check.decode(address),prefix=hash160[0],hash=hash160.slice(1);if(prefix===network.scriptHash)return this.p2sh(coin,hash).scriptPublickey;if(prefix===network.pubKeyHash)return this.p2pkh(coin,{hash}).scriptPublickey}catch(error){null===exports.logger||void 0===exports.logger||exports.logger.debug(`${error.toString()}, cointype: ${interface_1.CoinType[coin]}, address: ${address}`)}throw Error(`ArgumentError: invalid address for ${interface_1.CoinType[coin]}, got ${address}`)}static classify(script){if(this.isP2WPKH(script))return interface_1.ScriptType.P2WPKH;if(this.isP2PKH(script))return interface_1.ScriptType.P2PKH;if(this.isP2TR(script))return interface_1.ScriptType.P2TR;throw Error(`non-standard script: ${script.toString("hex")}`)}static isP2PKH(script){return 25===script.length&&script[0]===interface_1.OPCODES.OP_DUP&&script[1]===interface_1.OPCODES.OP_HASH160&&20===script[2]&&script[23]===interface_1.OPCODES.OP_EQUALVERIFY&&script[24]===interface_1.OPCODES.OP_CHECKSIG}static isP2SH(script){return 23===script.length&&script[0]===interface_1.OPCODES.OP_HASH160&&20===script[1]&&script[22]===interface_1.OPCODES.OP_EQUAL}static isP2WPKH(script){return 22===script.length&&script[0]===interface_1.OPCODES.OP_0&&20===script[1]}static isP2TR(script){return 34===script.length&&81===script[0]&&32===script[1]}}function Hash160(publickey){const sha=Buffer.from((0,hash_js_1.sha256)().update(publickey).digest());return Buffer.from((0,hash_js_1.ripemd160)().update(sha).digest())}exports.PaymentBTC=PaymentBTC,PaymentBTC.bs58check=new bs58_1.bs58Check((function(data){const sha1=(0,hash_js_1.sha256)().update(data).digest(),sha2=(0,hash_js_1.sha256)().update(sha1).digest();return Buffer.from(sha2)})),exports.Hash160=Hash160;
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.logger=exports.Hash160=exports.CoinType=exports.PaymentBTC=void 0;const bech32_1=require("bech32"),hash_js_1=require("hash.js"),interface_1=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return interface_1.CoinType}});const bs58_1=require("@secux/utility/lib/bs58"),utility_1=require("@secux/utility"),utils_1=require("./utils");exports.logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"payment"});class PaymentBTC{static CoinSupported(coin){if(coin===interface_1.CoinType.BITCOINCASH)throw Error("Please use class PaymentBCH instead");if(coin===interface_1.CoinType.GROESTL)throw Error("Please use class PaymentGRS instead")}static p2pkh(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");const pkHash=opt.hash?opt.hash:Hash160(opt.publickey);null===exports.logger||void 0===exports.logger||exports.logger.info(`publickey hash: ${pkHash.toString("hex")}`);const network=interface_1.coinmap[coin],address=this.bs58check.encode(pkHash,Buffer.from([network.pubKeyHash])),op=Buffer.from([interface_1.OPCODES.OP_DUP,interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUALVERIFY,interface_1.OPCODES.OP_CHECKSIG]),scriptPublickey=Buffer.concat([op,pkHash,check]),redeemHash=Hash160(scriptPublickey);return null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`),{address,scriptPublickey,redeemHash}}static p2sh(coin,redeemHash){this.CoinSupported(coin);const network=interface_1.coinmap[coin],address=this.bs58check.encode(redeemHash,Buffer.from([network.scriptHash])),op=Buffer.from([interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUAL]);return{address,scriptPublickey:Buffer.concat([op,redeemHash,check])}}static p2wpkh(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");const pkHash=opt.hash?opt.hash:Hash160(opt.publickey);null===exports.logger||void 0===exports.logger||exports.logger.info(`publickey hash: ${pkHash.toString("hex")}`);let network=interface_1.coinmap[coin];const words=bech32_1.bech32.toWords(pkHash);words.unshift(0);const address=bech32_1.bech32.encode(network.bech32,words),op=Buffer.from([interface_1.OPCODES.OP_0,20]),scriptPublickey=Buffer.concat([op,pkHash]),redeemHash=Hash160(scriptPublickey);return null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`),{address,scriptPublickey,redeemHash}}static p2wsh(coin,opt){if(this.CoinSupported(coin),!opt.witness&&!opt.hash)throw Error("Invalid Parameters");const redeemHash=opt.hash?opt.hash:Sha256(opt.witness[opt.witness.length-1]);null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`);let network=interface_1.coinmap[coin];const words=bech32_1.bech32.toWords(redeemHash);words.unshift(0);const address=bech32_1.bech32.encode(network.bech32,words),op=Buffer.from([interface_1.OPCODES.OP_0,32]);return{address,scriptPublickey:Buffer.concat([op,redeemHash]),redeemHash}}static p2ms(m,publickeys){if(m<=0)throw Error('Invalid paramter "m"');m+=interface_1.OPCODES.OP_INT_BASE;const n=publickeys.length+interface_1.OPCODES.OP_INT_BASE,multi_pk=Buffer.concat(publickeys),redeem=Buffer.concat([Buffer.from([m]),multi_pk,Buffer.from([n]),Buffer.from([interface_1.OPCODES.OP_CHECKMULTISIG])]),redeemHash=Hash160(redeem);null===exports.logger||void 0===exports.logger||exports.logger.info(`redeem hash: ${redeemHash.toString("hex")}`);const op=Buffer.from([interface_1.OPCODES.OP_HASH160,20]),check=Buffer.from([interface_1.OPCODES.OP_EQUAL]);return{redeem,scriptPubicKey:Buffer.concat([op,redeemHash,check])}}static p2tr(coin,opt){if(this.CoinSupported(coin),!opt.publickey&&!opt.hash)throw Error("Invalid Parameters");if(opt.publickey&&opt.hash)throw Error("Invalid Parameters");let tweaked=opt.hash;void 0===tweaked&&(tweaked=(0,utils_1.toTweakedPublickey)(opt.publickey));const network=interface_1.coinmap[coin],words=bech32_1.bech32.toWords(tweaked);words.unshift(1);const address=bech32_1.bech32m.encode(network.bech32,words),header=Buffer.from([81,32]);return{address,scriptPublickey:Buffer.concat([header,tweaked])}}static decode(coin,address){const network=interface_1.coinmap[coin];if(network.bech32&&RegExp(`^${network.bech32}`,"i").test(address)){let result;if("p"===address.slice(network.bech32.length+1)[0])result=bech32_1.bech32m.decode(address);else result=bech32_1.bech32.decode(address);const version=result.words.shift();switch(version){case 0:const hash160=Buffer.from(bech32_1.bech32.fromWords(result.words));if(null===exports.logger||void 0===exports.logger||exports.logger.debug(`bech32 address: ${address}\nbech32 decoded: ${hash160.toString("hex")}`),20==hash160.length)return this.p2wpkh(coin,{hash:hash160}).scriptPublickey;if(32==hash160.length)return this.p2wsh(coin,{hash:hash160}).scriptPublickey;case 1:const tweaked=Buffer.from(bech32_1.bech32m.fromWords(result.words));return null===exports.logger||void 0===exports.logger||exports.logger.debug(`bech32m address: ${address}\nbech32m decoded: ${tweaked.toString("hex")}`),this.p2tr(coin,{hash:tweaked}).scriptPublickey;default:throw Error(`ArgumentError: unsupported witness version, got "${version}" from address "${address}"`)}}try{const hash160=this.bs58check.decode(address),prefix=hash160[0],hash=hash160.slice(1);if(prefix===network.scriptHash)return this.p2sh(coin,hash).scriptPublickey;if(prefix===network.pubKeyHash)return this.p2pkh(coin,{hash}).scriptPublickey}catch(error){null===exports.logger||void 0===exports.logger||exports.logger.debug(`${error.toString()}, cointype: ${interface_1.CoinType[coin]}, address: ${address}`)}throw Error(`ArgumentError: invalid address for ${interface_1.CoinType[coin]}, got ${address}`)}static classify(script){if(this.isP2WPKH(script))return interface_1.ScriptType.P2WPKH;if(this.isP2PKH(script))return interface_1.ScriptType.P2PKH;if(this.isP2TR(script))return interface_1.ScriptType.P2TR;if(this.isP2WSH(script))return interface_1.ScriptType.P2WSH;throw Error(`non-standard script: ${script.toString("hex")}`)}static isP2PKH(script){return 25===script.length&&script[0]===interface_1.OPCODES.OP_DUP&&script[1]===interface_1.OPCODES.OP_HASH160&&20===script[2]&&script[23]===interface_1.OPCODES.OP_EQUALVERIFY&&script[24]===interface_1.OPCODES.OP_CHECKSIG}static isP2SH(script){return 23===script.length&&script[0]===interface_1.OPCODES.OP_HASH160&&20===script[1]&&script[22]===interface_1.OPCODES.OP_EQUAL}static isP2WPKH(script){return 22===script.length&&script[0]===interface_1.OPCODES.OP_0&&20===script[1]}static isP2WSH(script){return 34===script.length&&script[0]===interface_1.OPCODES.OP_0&&32===script[1]}static isP2TR(script){return 34===script.length&&81===script[0]&&32===script[1]}}function Sha256(data){const sha=(0,hash_js_1.sha256)().update(data).digest();return Buffer.from(sha)}function Hash160(publickey){const sha=Sha256(publickey);return Buffer.from((0,hash_js_1.ripemd160)().update(sha).digest())}exports.PaymentBTC=PaymentBTC,PaymentBTC.bs58check=new bs58_1.bs58Check((function(data){const sha1=Sha256(data);return Sha256(sha1)})),exports.Hash160=Hash160;
{
"name": "@secux/app-btc",
"version": "3.2.13",
"version": "3.2.14",
"description": "SecuX Hardware Wallet BTC API",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc