@secux/app-btc
Advanced tools
Comparing version 3.1.5 to 3.1.6
@@ -1,1 +0,1 @@ | ||
"use strict";var e,t=this&&this.__decorate||function(e,t,r,i){var o,u=arguments.length,n=u<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(n=(u<3?o(n):u>3?o(t,r,n):o(t,r))||n);return u>3&&n&&Object.defineProperty(t,r,n),n},r=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(o,u){function n(e){try{s(i.next(e))}catch(e){u(e)}}function c(e){try{s(i.throw(e))}catch(e){u(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(n,c)}s((i=i.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxBTC=exports.ScriptType=exports.CoinType=void 0;const i=require("secp256k1/elliptic"),o=require("varuint-bitcoin"),u=require("@secux/utility"),n=require("@secux/utility/lib/xpub"),c=require("ow"),s=require("@secux/protocol-transaction"),p=require("@secux/utility/lib/communication"),a=require("@secux/protocol-transaction/lib/interface"),l=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return l.CoinType}}),Object.defineProperty(exports,"ScriptType",{enumerable:!0,get:function(){return l.ScriptType}});const d=require("./psbt"),f=require("./utils"),y=require("@secux/transport");let v=e=class{static addressConvert(e,t){const r=(0,f.getPublickey)(e);(0,c.default)(t,c.default.any(l.ow_path,l.ow_PathObject));const o=Buffer.from(i.publicKeyConvert(r,!0)),u="string"==typeof t?(0,f.getCoinType)(t):t.coin,n="string"==typeof t?(0,f.getDefaultScript)(t):t.script,s=(0,f.getPayment)(u);switch(n){case l.ScriptType.P2SH_P2WPKH:const e=s.p2wpkh(u,{publickey:o});return s.p2sh(u,e.redeemHash).address;case l.ScriptType.P2SH_P2PKH:const t=s.p2pkh(u,{publickey:o});return s.p2sh(u,t.redeemHash).address;case l.ScriptType.P2PKH:return s.p2pkh(u,{publickey:o}).address;case l.ScriptType.P2WPKH:return s.p2wpkh(u,{publickey:o}).address;case l.ScriptType.P2TR:return s.p2tr(u,{publickey:o}).address;default:throw Error(`Invalid or unsupported ScriptType, got ${n} of ${u}`)}}static prepareAddress(e,t){return this.preparePublickey(e,t)}static resolveAddress(t,r){const i=e.resolvePublickey(t);return e.addressConvert(i,r)}static preparePublickey(e,t){var r;(0,c.default)(e,l.ow_path),t&&(0,c.default)(t,l.ow_AddressOption);const i=null!==(r=null==t?void 0:t.coin)&&void 0!==r?r:(0,f.getCoinType)(e),o=l.coinmap[i].coinType,n=void 0===(null==t?void 0:t.script)?void 0:(0,f.getPurpose)(null==t?void 0:t.script);return(0,c.default)(e,u.ow_strictPath(o,n)),s.SecuxTransactionTool.getPublickey(e,a.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=s.SecuxTransactionTool.resolvePublickey(e,a.EllipticCurve.SECP256K1,!0);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,c.default)(e,l.ow_accountPath),s.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,c.default)(t,l.ow_accountPath),s.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSign(e,t,r){var i;(0,c.default)(e,c.default.array.ofType(l.ow_txInput).minLength(1)),(0,c.default)(r,c.default.any(c.default.undefined,l.ow_SignOption));const o=null!==(i=null==r?void 0:r.coin)&&void 0!==i?i:(0,f.getCoinType)(e[0].path);(0,c.default)(t,l.ow_txOutput),e.map((e=>{const t=e.script?(0,f.getPurpose)(e.script):l.btcPurposes;(0,c.default)(e.path,u.ow_strictPath(l.coinmap[o].coinType,t))}));let n=(0,l.isOutuptScriptExtended)(t.to);if(n){const e=n.script?(0,f.getPurpose)(n.script):l.btcPurposes;(0,c.default)(n.path,u.ow_strictPath(l.coinmap[o].coinType,e))}if(t.utxo){const e=t.utxo.script?(0,f.getPurpose)(t.utxo.script):l.btcPurposes;(0,c.default)(t.utxo.path,u.ow_strictPath(l.coinmap[o].coinType,e))}const s=new d.SecuxPsbt(o);return s.AddInputs(e),s.AddOutputs(t.utxo?[t.to,t.utxo]:[t.to]),s.PrepareSign(null==r?void 0:r.feeRate)}static resolveSignatureList(e){return s.SecuxTransactionTool.resolveSignatureList(e).map((e=>Buffer.from(e,"base64"))).map((e=>u.Signature.fromSignature(e))).map((e=>Buffer.concat([e.r,e.s]).toString("hex")))}static resolveTransaction(t,r,i,o=l.CoinType.BITCOIN){(0,c.default)(t,p.ow_communicationData),(0,c.default)(r,u.ow_hexString),(0,c.default)(i,c.default.array.ofType(c.default.any(u.ow_hexString,c.default.buffer))),(0,c.default)(o,c.default.number.inRange(0,l.CoinType.__LENGTH-1));const n=e.resolveSignatureList(t).map((e=>Buffer.from(e,"hex"))),s=i.map((e=>(0,f.getPublickey)(e)));return d.SecuxPsbt.FromBuffer(Buffer.from(r,"hex"),o).appendSignature(n,s).finalizeAllInputs().extractTransaction().toHex()}static getAddress(t,i){var o,u;return r(this,void 0,void 0,(function*(){const r=e.prepareAddress(t,i),n=yield this.Exchange((0,p.getBuffer)(r));return e.resolveAddress(n,{coin:null!==(o=null==i?void 0:i.coin)&&void 0!==o?o:(0,f.getCoinType)(t),script:null!==(u=null==i?void 0:i.script)&&void 0!==u?u:(0,f.getDefaultScript)(t)})}))}static getPublickey(t,i){return r(this,void 0,void 0,(function*(){const r=e.preparePublickey(t,i),o=yield this.Exchange((0,p.getBuffer)(r));return e.resolvePublickey(o)}))}static getXPublickey(t){return r(this,void 0,void 0,(function*(){const r=e.prepareXPublickey(t),i=yield this.Exchange((0,p.getBuffer)(r));return e.resolveXPublickey(i,t)}))}static sign(t,i,o){var u,n;return r(this,void 0,void 0,(function*(){const c={},s=t=>r(this,void 0,void 0,(function*(){if(void 0!==c[t])return c[t];const r=yield e.getPublickey.call(this,t,{coin:a}),i=Buffer.from(r,"hex");return c[t]=i,i})),a=null!==(u=null==o?void 0:o.coin)&&void 0!==u?u:(0,f.getCoinType)(t[0].path);for(const e of t)void 0===e.publickey&&(e.publickey=yield s(e.path));i.to.path&&void 0===i.to.publickey&&(i.to.publickey=yield s(i.to.path)),(null===(n=i.utxo)||void 0===n?void 0:n.path)&&void 0===i.utxo.publickey&&(i.utxo.publickey=yield s(i.utxo.path));const{commandData:l,rawTx:d}=e.prepareSign(t,i,{coin:a,feeRate:null==o?void 0:o.feeRate}),y=yield this.Exchange((0,p.getBuffer)(l));return{raw_tx:e.resolveTransaction(y,d,t.map((e=>e.publickey)),a)}}))}static deriveAddress(t,r,i,o){var u,s;(0,c.default)(r,c.default.number.uint8),(0,c.default)(i,c.default.number.uint8),(0,c.default)(o,c.default.any(c.default.undefined,l.ow_AddressOption));const p=(0,n.decodeXPUB)(t);if(3!==p.depth)throw Error(`ArgumentError: expect depth from xpub is 3, but got ${p.depth}`);if(null==o?void 0:o.script)if(o.script in[l.ScriptType.P2PKH,l.ScriptType.P2SH_P2PKH,l.ScriptType.P2SH_P2WPKH,l.ScriptType.P2WPKH]){const e=(0,f.getPurpose)(null==o?void 0:o.script);if(p.purpose!==e)throw Error(`ArgumentError: expect purpose from xpub is ${e}, but got ${p.purpose}`)}else{if(44!==p.purpose)throw Error(`ArgumentError: expect purpose from xpub is 44, but got ${p.purpose}`);p.purpose,(0,f.getPurpose)(null==o?void 0:o.script)}const{publickey:a}=(0,n.deriveKey)(p.publickey,p.chaincode,[r,i]),d=null!==(u=null==o?void 0:o.coin)&&void 0!==u?u:l.CoinType.BITCOIN,y=null!==(s=null==o?void 0:o.script)&&void 0!==s?s:(0,f.getDefaultScript)(`m/${p.purpose}'`);return e.addressConvert(a,{coin:d,script:y})}static getVirtualSize(e,t){const r=8+o.encodingLength(e.length)+o.encodingLength(t.length)+e.reduce(((e,t)=>e+40+(0,f.sliceSize)((0,f.getInScriptSize)(t))),0)+t.reduce(((e,t)=>e+8+(0,f.sliceSize)((0,f.getOutScriptSize)(t))),0),i=e.map((e=>(0,f.getWitnessSize)(e)));return(4*r+(i.some((e=>0!==e.length))?2+i.reduce(((e,t)=>e+(0,f.vectorSize)(t)),0):0))/4}};v=e=t([(0,y.staticImplements)()],v),exports.SecuxBTC=v,(0,y.loadPlugin)(v,"SecuxBTC"); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxBTC=exports.ScriptType=exports.CoinType=void 0;const e=require("secp256k1/elliptic"),t=require("varuint-bitcoin"),r=require("@secux/utility"),i=require("@secux/utility/lib/xpub"),o=require("ow"),u=require("@secux/protocol-transaction"),c=require("@secux/utility/lib/communication"),n=require("@secux/protocol-transaction/lib/interface"),a=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return a.CoinType}}),Object.defineProperty(exports,"ScriptType",{enumerable:!0,get:function(){return a.ScriptType}});const s=require("./psbt"),p=require("./utils");class l{static addressConvert(t,r){const i=(0,p.getPublickey)(t);(0,o.default)(r,o.default.any(a.ow_path,a.ow_PathObject));const u=Buffer.from(e.publicKeyConvert(i,!0)),c="string"==typeof r?(0,p.getCoinType)(r):r.coin,n="string"==typeof r?(0,p.getDefaultScript)(r):r.script,s=(0,p.getPayment)(c);switch(n){case a.ScriptType.P2SH_P2WPKH:const e=s.p2wpkh(c,{publickey:u});return s.p2sh(c,e.redeemHash).address;case a.ScriptType.P2SH_P2PKH:const t=s.p2pkh(c,{publickey:u});return s.p2sh(c,t.redeemHash).address;case a.ScriptType.P2PKH:return s.p2pkh(c,{publickey:u}).address;case a.ScriptType.P2WPKH:return s.p2wpkh(c,{publickey:u}).address;case a.ScriptType.P2TR:return s.p2tr(c,{publickey:u}).address;default:throw Error(`Invalid or unsupported ScriptType, got ${n} of ${c}`)}}static prepareAddress(e,t){return this.preparePublickey(e,t)}static resolveAddress(e,t){const r=l.resolvePublickey(e);return l.addressConvert(r,t)}static preparePublickey(e,t){var i;(0,o.default)(e,a.ow_path),t&&(0,o.default)(t,a.ow_AddressOption);const c=null!==(i=null==t?void 0:t.coin)&&void 0!==i?i:(0,p.getCoinType)(e),s=a.coinmap[c].coinType,l=void 0===(null==t?void 0:t.script)?void 0:(0,p.getPurpose)(null==t?void 0:t.script);return(0,o.default)(e,(0,r.ow_strictPath)(s,l)),u.SecuxTransactionTool.getPublickey(e,n.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=u.SecuxTransactionTool.resolvePublickey(e,n.EllipticCurve.SECP256K1,!0);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,o.default)(e,a.ow_accountPath),u.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,o.default)(t,a.ow_accountPath),u.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSign(e,t,i){var u;(0,o.default)(e,o.default.array.ofType(a.ow_txInput).minLength(1)),(0,o.default)(i,o.default.any(o.default.undefined,a.ow_SignOption));const n=null!==(u=null==i?void 0:i.coin)&&void 0!==u?u:(0,p.getCoinType)(e[0].path);(0,o.default)(t,a.ow_txOutput),e.map((e=>{const t=e.script?(0,p.getPurpose)(e.script):a.btcPurposes;(0,o.default)(e.path,(0,r.ow_strictPath)(a.coinmap[n].coinType,t))}));let l=(0,a.isOutuptScriptExtended)(t.to);if(l){const e=l.script?(0,p.getPurpose)(l.script):a.btcPurposes;(0,o.default)(l.path,(0,r.ow_strictPath)(a.coinmap[n].coinType,e))}if(t.utxo){const e=t.utxo.script?(0,p.getPurpose)(t.utxo.script):a.btcPurposes;(0,o.default)(t.utxo.path,(0,r.ow_strictPath)(a.coinmap[n].coinType,e))}const d=new s.SecuxPsbt(n);return d.AddInputs(e),d.AddOutputs(t.utxo?[t.to,t.utxo]:[t.to]),(0,c.wrapResult)(d.PrepareSign(null==i?void 0:i.feeRate))}static resolveSignatureList(e){return u.SecuxTransactionTool.resolveSignatureList(e).map((e=>Buffer.from(e,"base64"))).map((e=>r.Signature.fromSignature(e))).map((e=>Buffer.concat([e.r,e.s]).toString("hex")))}static resolveTransaction(e,t,r,i=a.CoinType.BITCOIN){(0,o.default)(e,c.ow_communicationData),(0,o.default)(t,a.ow_hexString),(0,o.default)(r,o.default.array.ofType(o.default.any(a.ow_hexString,o.default.buffer))),(0,o.default)(i,o.default.number.inRange(0,a.CoinType.__LENGTH-1));const u=l.resolveSignatureList(e).map((e=>Buffer.from(e,"hex"))),n=r.map((e=>(0,p.getPublickey)(e)));return s.SecuxPsbt.FromBuffer(Buffer.from(t,"hex"),i).appendSignature(u,n).finalizeAllInputs().extractTransaction().toHex()}static async getAddress(e,t){var r,i;const o=l.prepareAddress(e,t),u=await this.Exchange((0,c.getBuffer)(o));return l.resolveAddress(u,{coin:null!==(r=null==t?void 0:t.coin)&&void 0!==r?r:(0,p.getCoinType)(e),script:null!==(i=null==t?void 0:t.script)&&void 0!==i?i:(0,p.getDefaultScript)(e)})}static async getPublickey(e,t){const r=l.preparePublickey(e,t),i=await this.Exchange((0,c.getBuffer)(r));return l.resolvePublickey(i)}static async getXPublickey(e){const t=l.prepareXPublickey(e),r=await this.Exchange((0,c.getBuffer)(t));return l.resolveXPublickey(r,e)}static async sign(e,t,r){var i,o;const u={},n=async e=>{if(void 0!==u[e])return u[e];const t=await l.getPublickey.call(this,e,{coin:a}),r=Buffer.from(t,"hex");return u[e]=r,r},a=null!==(i=null==r?void 0:r.coin)&&void 0!==i?i:(0,p.getCoinType)(e[0].path);for(const t of e)void 0===t.publickey&&(t.publickey=await n(t.path));t.to.path&&void 0===t.to.publickey&&(t.to.publickey=await n(t.to.path)),(null===(o=t.utxo)||void 0===o?void 0:o.path)&&void 0===t.utxo.publickey&&(t.utxo.publickey=await n(t.utxo.path));const{commandData:s,rawTx:d}=l.prepareSign(e,t,{coin:a,feeRate:null==r?void 0:r.feeRate}),f=await this.Exchange((0,c.getBuffer)(s));return{raw_tx:l.resolveTransaction(f,d,e.map((e=>e.publickey)),a)}}static deriveAddress(e,t,r,u){var c,n;(0,o.default)(t,o.default.number.uint8),(0,o.default)(r,o.default.number.uint8),(0,o.default)(u,o.default.any(o.default.undefined,a.ow_AddressOption));const s=(0,i.decodeXPUB)(e);if(3!==s.depth)throw Error(`ArgumentError: expect depth from xpub is 3, but got ${s.depth}`);if(null==u?void 0:u.script)if(u.script in[a.ScriptType.P2PKH,a.ScriptType.P2SH_P2PKH,a.ScriptType.P2SH_P2WPKH,a.ScriptType.P2WPKH]){const e=(0,p.getPurpose)(null==u?void 0:u.script);if(s.purpose!==e)throw Error(`ArgumentError: expect purpose from xpub is ${e}, but got ${s.purpose}`)}else{if(44!==s.purpose)throw Error(`ArgumentError: expect purpose from xpub is 44, but got ${s.purpose}`);s.purpose,(0,p.getPurpose)(null==u?void 0:u.script)}const{publickey:d}=(0,i.deriveKey)(s.publickey,s.chaincode,[t,r]),f=null!==(c=null==u?void 0:u.coin)&&void 0!==c?c:a.CoinType.BITCOIN,y=null!==(n=null==u?void 0:u.script)&&void 0!==n?n:(0,p.getDefaultScript)(`m/${s.purpose}'`);return l.addressConvert(d,{coin:f,script:y})}static getVirtualSize(e,r){const i=8+t.encodingLength(e.length)+t.encodingLength(r.length)+e.reduce(((e,t)=>e+40+(0,p.sliceSize)((0,p.getInScriptSize)(t))),0)+r.reduce(((e,t)=>e+8+(0,p.sliceSize)((0,p.getOutScriptSize)(t))),0),o=e.map((e=>(0,p.getWitnessSize)(e)));return(4*i+(o.some((e=>0!==e.length))?2+o.reduce(((e,t)=>e+(0,p.vectorSize)(t)),0):0))/4}}exports.SecuxBTC=l,(0,r.loadPlugin)(l,"SecuxBTC"); |
@@ -29,2 +29,4 @@ /// <reference types="node" /> | ||
export declare const ow_accountPath: import("ow").StringPredicate; | ||
export declare const ow_hexString: import("ow").StringPredicate; | ||
export declare const ow_hashString: import("ow").StringPredicate; | ||
export declare type PathObject = { | ||
@@ -31,0 +33,0 @@ coin: CoinType; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_SignOption=exports.ow_AddressOption=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_accountPath=exports.ow_path=exports.ow_balance=exports.btcPurposes=exports.btcCoinTypes=exports.coinmap=exports.CoinType=exports.ScriptType=exports.OPCODES=void 0;const e=require("ow"),t=require("./coindef"),o=require("@secux/utility");var r,p,s=require("./coindef");Object.defineProperty(exports,"OPCODES",{enumerable:!0,get:function(){return s.OPCODES}}),function(e){e[e.P2PKH=0]="P2PKH",e[e.P2WPKH=1]="P2WPKH",e[e.P2SH_P2PKH=2]="P2SH_P2PKH",e[e.P2SH_P2WPKH=3]="P2SH_P2WPKH",e[e.P2TR=4]="P2TR",e[e.__LENGTH=5]="__LENGTH"}(r=exports.ScriptType||(exports.ScriptType={})),function(e){e[e.BITCOIN=0]="BITCOIN",e[e.TESTNET=1]="TESTNET",e[e.REGTEST=2]="REGTEST",e[e.LITECOIN=3]="LITECOIN",e[e.BITCOINCASH=4]="BITCOINCASH",e[e.GROESTL=5]="GROESTL",e[e.DIGIBYTE=6]="DIGIBYTE",e[e.DASH=7]="DASH",e[e.DOGECOIN=8]="DOGECOIN",e[e.__LENGTH=9]="__LENGTH"}(p=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze(Object.values(p).slice(0,p.__LENGTH).map((e=>t[e.toLowerCase()]))),exports.btcCoinTypes=Object.freeze(exports.coinmap.map((e=>Object.freeze(e.coinType)))),exports.btcPurposes=Object.freeze([Object.freeze(44),Object.freeze(49),Object.freeze(84),Object.freeze(86)]),exports.ow_balance=e.default.number.integer.positive.lessThanOrEqual(9007199254740991),exports.ow_path=o.ow_strictPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_accountPath=o.ow_accountPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_PathObject=e.default.object.exactShape({coin:e.default.number.inRange(0,p.__LENGTH-1),script:e.default.number.inRange(0,r.__LENGTH-1)}),exports.ow_txInput=e.default.object.exactShape({hash:o.ow_hashString,vout:e.default.number.greaterThanOrEqual(0),txHex:e.default.any(e.default.undefined,o.ow_hexString),script:e.default.optional.number.inRange(0,r.__LENGTH-1),satoshis:exports.ow_balance,path:exports.ow_path,publickey:e.default.any(e.default.undefined,o.ow_hexString,e.default.buffer)}),exports.ow_txOutputAddress=e.default.object.exactShape({address:o.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=e.default.object.exactShape({scriptHex:o.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=e.default.object.exactShape({publickey:e.default.any(e.default.undefined,o.ow_hexString,e.default.buffer),path:exports.ow_path,satoshis:exports.ow_balance,script:e.default.optional.number.inRange(0,r.__LENGTH-1)}),exports.ow_txOutput=e.default.object.exactShape({to:e.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:e.default.any(e.default.undefined,exports.ow_txOutputScriptExtened)}),exports.isOutputAddress=function(e){const t=e;if(t.address)return t},exports.isOutuptScript=function(e){const t=e;if(t.scriptHex)return t},exports.isOutuptScriptExtended=function(t){try{return(0,e.default)(t,exports.ow_txOutputScriptExtened),t}catch(e){}},exports.ow_AddressOption=e.default.object.exactShape({coin:e.default.optional.number.inRange(0,p.__LENGTH-1),script:e.default.optional.number.inRange(0,r.__LENGTH-1)}),exports.ow_SignOption=e.default.object.exactShape({coin:e.default.optional.number.inRange(0,p.__LENGTH-1),feeRate:e.default.optional.number.greaterThanOrEqual(1)}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_SignOption=exports.ow_AddressOption=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 t=require("ow"),e=require("./coindef"),o=require("@secux/utility");var r,p,s=require("./coindef");Object.defineProperty(exports,"OPCODES",{enumerable:!0,get:function(){return s.OPCODES}}),function(t){t[t.P2PKH=0]="P2PKH",t[t.P2WPKH=1]="P2WPKH",t[t.P2SH_P2PKH=2]="P2SH_P2PKH",t[t.P2SH_P2WPKH=3]="P2SH_P2WPKH",t[t.P2TR=4]="P2TR",t[t.__LENGTH=5]="__LENGTH"}(r=exports.ScriptType||(exports.ScriptType={})),function(t){t[t.BITCOIN=0]="BITCOIN",t[t.TESTNET=1]="TESTNET",t[t.REGTEST=2]="REGTEST",t[t.LITECOIN=3]="LITECOIN",t[t.BITCOINCASH=4]="BITCOINCASH",t[t.GROESTL=5]="GROESTL",t[t.DIGIBYTE=6]="DIGIBYTE",t[t.DASH=7]="DASH",t[t.DOGECOIN=8]="DOGECOIN",t[t.__LENGTH=9]="__LENGTH"}(p=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze(Object.values(p).slice(0,p.__LENGTH).map((t=>e[t.toLowerCase()]))),exports.btcCoinTypes=Object.freeze(exports.coinmap.map((t=>Object.freeze(t.coinType)))),exports.btcPurposes=Object.freeze([Object.freeze(44),Object.freeze(49),Object.freeze(84),Object.freeze(86)]),exports.ow_balance=t.default.number.integer.positive.lessThanOrEqual(9007199254740991),exports.ow_path=o.ow_strictPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_accountPath=o.ow_accountPath(exports.btcCoinTypes,exports.btcPurposes),exports.ow_hexString=o.owTool.hexString,exports.ow_hashString=o.owTool.hashString,exports.ow_PathObject=t.default.object.exactShape({coin:t.default.number.inRange(0,p.__LENGTH-1),script:t.default.number.inRange(0,r.__LENGTH-1)}),exports.ow_txInput=t.default.object.exactShape({hash:exports.ow_hashString,vout:t.default.number.greaterThanOrEqual(0),txHex:t.default.any(t.default.undefined,exports.ow_hexString),script:t.default.optional.number.inRange(0,r.__LENGTH-1),satoshis:exports.ow_balance,path:exports.ow_path,publickey:t.default.any(t.default.undefined,exports.ow_hexString,t.default.buffer)}),exports.ow_txOutputAddress=t.default.object.exactShape({address:exports.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=t.default.object.exactShape({scriptHex:exports.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=t.default.object.exactShape({publickey:t.default.any(t.default.undefined,exports.ow_hexString,t.default.buffer),path:exports.ow_path,satoshis:exports.ow_balance,script:t.default.optional.number.inRange(0,r.__LENGTH-1)}),exports.ow_txOutput=t.default.object.exactShape({to:t.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:t.default.any(t.default.undefined,exports.ow_txOutputScriptExtened)}),exports.isOutputAddress=function(t){const e=t;if(e.address)return e},exports.isOutuptScript=function(t){const e=t;if(e.scriptHex)return e},exports.isOutuptScriptExtended=function(e){try{return(0,t.default)(e,exports.ow_txOutputScriptExtened),e}catch(t){}},exports.ow_AddressOption=t.default.object.exactShape({coin:t.default.optional.number.inRange(0,p.__LENGTH-1),script:t.default.optional.number.inRange(0,r.__LENGTH-1)}),exports.ow_SignOption=t.default.object.exactShape({coin:t.default.optional.number.inRange(0,p.__LENGTH-1),feeRate:t.default.optional.number.greaterThanOrEqual(1)}); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.taggedHash=exports.toTweakedPublickey=exports.getPublickey=exports.scriptWitnessToWitnessStack=exports.witnessStackToScriptWitness=exports.vectorSize=exports.sliceSize=exports.getOutScriptSize=exports.getWitnessSize=exports.getInScriptSize=exports.getSerializer=exports.getDefaultScript=exports.getPurpose=exports.getCoinType=exports.getPayment=void 0;const e=require("secp256k1/elliptic"),t=require("varuint-bitcoin"),r=require("./interface"),n=require("./payment"),c=require("./payment_bch"),i=require("./payment_grs"),o=require("./transaction"),s=require("./transaction_grs"),p=require("ow"),u=require("@secux/utility"),a=require("hash.js"),f=require("./bip340");function S(e){const t=e.match(/\d+/g),n=parseInt(t[1],10);for(let e=0;e<r.coinmap.length;e++)if(n===r.coinmap[e].coinType)return e;throw Error(`ArgumentError: unsupport cointype of BIP32 path, got ${e}`)}function P(e){return t.encodingLength(e)+e}function T(t){(0,p.default)(t,p.default.any(u.ow_hexString,p.default.buffer));const r="string"==typeof t?Buffer.from(t,"hex"):t;if((0,p.default)(r,p.default.buffer.is((e=>33===e.length||65===e.length))),!e.publicKeyVerify(r))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${r.toString("hex")}"`);return r}exports.getPayment=function(e){switch(e){case r.CoinType.BITCOINCASH:return c.PaymentBCH;case r.CoinType.GROESTL:return i.PaymentGRS;default:return n.PaymentBTC}},exports.getCoinType=S,exports.getPurpose=function(e){switch(e){case r.ScriptType.P2PKH:return 44;case r.ScriptType.P2SH_P2PKH:case r.ScriptType.P2SH_P2WPKH:return 49;case r.ScriptType.P2WPKH:return 84;case r.ScriptType.P2TR:return 86}throw Error(`ArgumentError: unsupport ScriptType, got ${e}`)},exports.getDefaultScript=function(e){const t=e.match(/\d+/g),n=parseInt(t[0],10),c=t[1]?S(e):r.CoinType.BITCOIN;switch(n){case 44:return r.ScriptType.P2PKH;case 49:return c!==r.CoinType.BITCOINCASH?r.ScriptType.P2SH_P2WPKH:r.ScriptType.P2SH_P2PKH;case 84:return r.ScriptType.P2WPKH;case 86:return r.ScriptType.P2TR}throw Error(`ArgumentError: unsupport purpose of path, got "${n}" from ${e}`)},exports.getSerializer=function(e){return e===r.CoinType.GROESTL?s.TransactionGRS:o.Transaction},exports.getInScriptSize=function(e){switch(e){case r.ScriptType.P2PKH:case r.ScriptType.P2SH_P2PKH:return 107;case r.ScriptType.P2SH_P2WPKH:return 23}return 0},exports.getWitnessSize=function(e,t=o.Transaction.SIGHASH_DEFAULT){switch(e){case r.ScriptType.P2SH_P2WPKH:case r.ScriptType.P2WPKH:return[72,33];case r.ScriptType.P2TR:return t===o.Transaction.SIGHASH_DEFAULT?[64]:[65]}return[]},exports.getOutScriptSize=function(e){switch(e){case r.ScriptType.P2PKH:return 25;case r.ScriptType.P2SH_P2PKH:case r.ScriptType.P2SH_P2WPKH:return 23;case r.ScriptType.P2WPKH:return 22;case r.ScriptType.P2TR:return 34}return 0},exports.sliceSize=P,exports.vectorSize=function(e){return t.encodingLength(e.length)+e.reduce(((e,t)=>e+P(t)),0)},exports.witnessStackToScriptWitness=function(e){let r=Buffer.allocUnsafe(0);const n=e=>{const n=r.length,c=t.encodingLength(e);r=Buffer.concat([r,Buffer.allocUnsafe(c)]),t.encode(e,r,n)};n(e.length);for(const t of e)n(t.length),r=Buffer.concat([r,Buffer.from(t)]);return r},exports.scriptWitnessToWitnessStack=function(e){let r=0;const n=()=>{const n=t.decode(e,r);return r+=t.decode.bytes,n},c=()=>{const t=n();return r+=t,e.slice(r-t,r)},i=n(),o=[];for(let e=0;e<i;e++)o.push(c());return o},exports.getPublickey=T,exports.toTweakedPublickey=function(e){const t=T(e).slice(1,33),r=y("TapTweak",t);return(0,f.taprootConvert)(t,r)};const g=Object.fromEntries(["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"].map((e=>{const t=function(e){return Buffer.from((0,a.sha256)().update(e).digest())}(e);return[e,Buffer.concat([t,t])]})));function y(e,t){const r=Buffer.concat([g[e],t]);return Buffer.from((0,a.sha256)().update(r).digest())}exports.taggedHash=y; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.taggedHash=exports.toTweakedPublickey=exports.getPublickey=exports.scriptWitnessToWitnessStack=exports.witnessStackToScriptWitness=exports.vectorSize=exports.sliceSize=exports.getOutScriptSize=exports.getWitnessSize=exports.getInScriptSize=exports.getSerializer=exports.getDefaultScript=exports.getPurpose=exports.getCoinType=exports.getPayment=void 0;const e=require("secp256k1/elliptic"),t=require("varuint-bitcoin"),r=require("./interface"),n=require("./payment"),c=require("./payment_bch"),i=require("./payment_grs"),o=require("./transaction"),s=require("./transaction_grs"),p=require("ow"),u=require("hash.js"),a=require("./bip340");function f(e){const t=e.match(/\d+/g),n=parseInt(t[1],10);for(let e=0;e<r.coinmap.length;e++)if(n===r.coinmap[e].coinType)return e;throw Error(`ArgumentError: unsupport cointype of BIP32 path, got ${e}`)}function S(e){return t.encodingLength(e)+e}function P(t){(0,p.default)(t,p.default.any(r.ow_hexString,p.default.buffer));const n="string"==typeof t?Buffer.from(t,"hex"):t;if((0,p.default)(n,p.default.buffer.is((e=>33===e.length||65===e.length))),!e.publicKeyVerify(n))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${n.toString("hex")}"`);return n}exports.getPayment=function(e){switch(e){case r.CoinType.BITCOINCASH:return c.PaymentBCH;case r.CoinType.GROESTL:return i.PaymentGRS;default:return n.PaymentBTC}},exports.getCoinType=f,exports.getPurpose=function(e){switch(e){case r.ScriptType.P2PKH:return 44;case r.ScriptType.P2SH_P2PKH:case r.ScriptType.P2SH_P2WPKH:return 49;case r.ScriptType.P2WPKH:return 84;case r.ScriptType.P2TR:return 86}throw Error(`ArgumentError: unsupport ScriptType, got ${e}`)},exports.getDefaultScript=function(e){const t=e.match(/\d+/g),n=parseInt(t[0],10),c=t[1]?f(e):r.CoinType.BITCOIN;switch(n){case 44:return r.ScriptType.P2PKH;case 49:return c!==r.CoinType.BITCOINCASH?r.ScriptType.P2SH_P2WPKH:r.ScriptType.P2SH_P2PKH;case 84:return r.ScriptType.P2WPKH;case 86:return r.ScriptType.P2TR}throw Error(`ArgumentError: unsupport purpose of path, got "${n}" from ${e}`)},exports.getSerializer=function(e){return e===r.CoinType.GROESTL?s.TransactionGRS:o.Transaction},exports.getInScriptSize=function(e){switch(e){case r.ScriptType.P2PKH:case r.ScriptType.P2SH_P2PKH:return 107;case r.ScriptType.P2SH_P2WPKH:return 23}return 0},exports.getWitnessSize=function(e,t=o.Transaction.SIGHASH_DEFAULT){switch(e){case r.ScriptType.P2SH_P2WPKH:case r.ScriptType.P2WPKH:return[72,33];case r.ScriptType.P2TR:return t===o.Transaction.SIGHASH_DEFAULT?[64]:[65]}return[]},exports.getOutScriptSize=function(e){switch(e){case r.ScriptType.P2PKH:return 25;case r.ScriptType.P2SH_P2PKH:case r.ScriptType.P2SH_P2WPKH:return 23;case r.ScriptType.P2WPKH:return 22;case r.ScriptType.P2TR:return 34}return 0},exports.sliceSize=S,exports.vectorSize=function(e){return t.encodingLength(e.length)+e.reduce(((e,t)=>e+S(t)),0)},exports.witnessStackToScriptWitness=function(e){let r=Buffer.allocUnsafe(0);const n=e=>{const n=r.length,c=t.encodingLength(e);r=Buffer.concat([r,Buffer.allocUnsafe(c)]),t.encode(e,r,n)};n(e.length);for(const t of e)n(t.length),r=Buffer.concat([r,Buffer.from(t)]);return r},exports.scriptWitnessToWitnessStack=function(e){let r=0;const n=()=>{const n=t.decode(e,r);return r+=t.decode.bytes,n},c=()=>{const t=n();return r+=t,e.slice(r-t,r)},i=n(),o=[];for(let e=0;e<i;e++)o.push(c());return o},exports.getPublickey=P,exports.toTweakedPublickey=function(e){const t=P(e).slice(1,33),r=g("TapTweak",t);return(0,a.taprootConvert)(t,r)};const T=Object.fromEntries(["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"].map((e=>{const t=function(e){return Buffer.from((0,u.sha256)().update(e).digest())}(e);return[e,Buffer.concat([t,t])]})));function g(e,t){const r=Buffer.concat([T[e],t]);return Buffer.from((0,u.sha256)().update(r).digest())}exports.taggedHash=g; |
{ | ||
"name": "@secux/app-btc", | ||
"version": "3.1.5", | ||
"version": "3.1.6", | ||
"description": "SecuX Hardware Wallet BTC API", | ||
@@ -21,3 +21,4 @@ "keywords": [ | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"dist" | ||
], | ||
@@ -39,3 +40,3 @@ "publishConfig": { | ||
"@secux/protocol-transaction": "^3.0.0", | ||
"@secux/utility": "^3.0.2", | ||
"@secux/utility": "^3.0.6", | ||
"bech32": "^2.0.0", | ||
@@ -53,3 +54,3 @@ "bigi": "^1.4.2", | ||
"peerDependencies": { | ||
"@secux/transport": "^3.0.1" | ||
"@secux/transport": "^3.2.0" | ||
}, | ||
@@ -56,0 +57,0 @@ "devDependencies": { |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
557820
33
651
1
80
15
18
4
Updated@secux/utility@^3.0.6