Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@secux/app-btc

Package Overview
Dependencies
Maintainers
2
Versions
35
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 2.0.0-rc1 to 2.0.0-rc2

3

lib/app-btc.d.ts

@@ -13,7 +13,6 @@ /// <reference types="node" />

* @param {string} path BIP32
* @param {ScriptType} script script type
* @param {AddressOption} [option]
* @returns {string} address
*/
static getAddress(trans: ITransport, path: string, script: ScriptType, option?: AddressOption): Promise<string>;
static getAddress(trans: ITransport, path: string, option?: AddressOption): Promise<string>;
/**

@@ -20,0 +19,0 @@ * Create transaction and Sign

@@ -1,1 +0,1 @@

"use strict";var t=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function u(t){try{c(n.next(t))}catch(t){o(t)}}function p(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,p)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxBTC=exports.ScriptType=exports.CoinType=void 0;const e=require("@secux/transport/lib/ITransaction"),r=require("@secux/utility"),n=require("ow"),i=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return i.CoinType}}),Object.defineProperty(exports,"ScriptType",{enumerable:!0,get:function(){return i.ScriptType}});const o=require("./psbt"),u=require("./utils");exports.SecuxBTC=class{static getAddress(o,p,c,s){return t(this,void 0,void 0,(function*(){(0,n.default)(c,n.default.number.inRange(0,i.ScriptType.__LENGTH-1));const t=(0,u.getPurpose)(c);(0,n.default)(p,r.ow_strictPath(i.btcCoinTypes,t)),(0,n.default)(s,n.default.any(n.default.undefined,i.ow_AddressOption));const a=yield o.getPublickey(p,e.EllipticCurve.SECP256K1,!0),d=(0,u.getCoinType)(p),l=(0,u.getPayment)(d);switch(c){case i.ScriptType.P2SH_P2WPKH:const t=l.p2wpkh(d,{publickey:a});return l.p2sh(d,t.redeemHash).address;case i.ScriptType.P2SH_P2PKH:const e=l.p2pkh(d,{publickey:a});return l.p2sh(d,e.redeemHash).address;case i.ScriptType.P2PKH:return l.p2pkh(d,{publickey:a}).address;case i.ScriptType.P2WPKH:return l.p2wpkh(d,{publickey:a}).address;default:throw Error("Invalid or unsupported ScriptType")}}))}static signTransaction(e,p,c){return t(this,void 0,void 0,(function*(){(0,n.default)(p,n.default.array.ofType(i.ow_txInput).minLength(1));const t=(0,u.getCoinType)(p[0].path);(0,n.default)(c,i.ow_txOutput),p.map((e=>{(0,n.default)(e.path,r.ow_strictPath(i.coinmap[t].coinType))}));let s=(0,i.isOutuptScriptExtended)(c.to);s&&(0,n.default)(s.path,r.ow_strictPath(i.coinmap[t].coinType)),c.utxo&&(0,n.default)(c.utxo.path,r.ow_strictPath(i.coinmap[t].coinType));const a=new o.SecuxPsbt(e,t);yield a.AddInputs(p),yield a.AddOutputs(c.utxo?[c.to,c.utxo]:[c.to]);const d=yield a.Sign();return{raw_tx:a.finalizeAllInputs().extractTransaction().toHex(),signature:d}}))}};
"use strict";var t=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(o,n){function p(t){try{c(r.next(t))}catch(t){n(t)}}function s(t){try{c(r.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(p,s)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxBTC=exports.ScriptType=exports.CoinType=void 0;const e=require("@secux/transport/lib/ITransaction"),i=require("@secux/utility"),r=require("ow"),o=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return o.CoinType}}),Object.defineProperty(exports,"ScriptType",{enumerable:!0,get:function(){return o.ScriptType}});const n=require("./psbt"),p=require("./utils");exports.SecuxBTC=class{static getAddress(n,s,c){var u,a;return t(this,void 0,void 0,(function*(){c&&(0,r.default)(c,o.ow_AddressOption);const t=void 0===(null==c?void 0:c.coin)?o.btcCoinTypes:o.coinmap[null==c?void 0:c.coin].coinType,d=void 0===(null==c?void 0:c.script)?null===(u=i.supported_coin.find((e=>e.cointype===t)))||void 0===u?void 0:u.purpose:(0,p.getPurpose)(null==c?void 0:c.script);(0,r.default)(s,i.ow_strictPath(t,d));const l=yield n.getPublickey(s,e.EllipticCurve.SECP256K1,!0),y=(0,p.getCoinType)(s),f=(0,p.getPayment)(y);switch(null!==(a=null==c?void 0:c.script)&&void 0!==a?a:(0,p.getDefaultScript)(s)){case o.ScriptType.P2SH_P2WPKH:const t=f.p2wpkh(y,{publickey:l});return f.p2sh(y,t.redeemHash).address;case o.ScriptType.P2SH_P2PKH:const e=f.p2pkh(y,{publickey:l});return f.p2sh(y,e.redeemHash).address;case o.ScriptType.P2PKH:return f.p2pkh(y,{publickey:l}).address;case o.ScriptType.P2WPKH:return f.p2wpkh(y,{publickey:l}).address;default:throw Error("Invalid or unsupported ScriptType")}}))}static signTransaction(e,s,c){return t(this,void 0,void 0,(function*(){(0,r.default)(s,r.default.array.ofType(o.ow_txInput).minLength(1));const t=(0,p.getCoinType)(s[0].path);(0,r.default)(c,o.ow_txOutput),s.map((e=>{const n=e.script?(0,p.getPurpose)(e.script):o.btcPurposes;(0,r.default)(e.path,i.ow_strictPath(o.coinmap[t].coinType,n))}));let u=(0,o.isOutuptScriptExtended)(c.to);if(u){const e=u.script?(0,p.getPurpose)(u.script):o.btcPurposes;(0,r.default)(u.path,i.ow_strictPath(o.coinmap[t].coinType,e))}if(c.utxo){const e=c.utxo.script?(0,p.getPurpose)(c.utxo.script):o.btcPurposes;(0,r.default)(c.utxo.path,i.ow_strictPath(o.coinmap[t].coinType,e))}const a=new n.SecuxPsbt(e,t);yield a.AddInputs(s),yield a.AddOutputs(c.utxo?[c.to,c.utxo]:[c.to]);const d=yield a.Sign();return{raw_tx:a.finalizeAllInputs().extractTransaction().toHex(),signature:d}}))}};

@@ -15,3 +15,3 @@ import * as constants from "./coindef";

txHex?: string;
script: ScriptType;
script?: ScriptType;
satoshis: number;

@@ -24,3 +24,3 @@ path: string;

txHex: string | undefined;
script: number;
script: number | undefined;
satoshis: number;

@@ -46,3 +46,3 @@ path: string;

export declare type txOutputScriptExtened = {
script: ScriptType;
script?: ScriptType;
path: string;

@@ -52,3 +52,3 @@ satoshis: number;

export declare const ow_txOutputScriptExtened: import("ow").ObjectPredicate<{
script: number;
script: number | undefined;
path: string;

@@ -66,3 +66,3 @@ satoshis: number;

} | {
script: number;
script: number | undefined;
path: string;

@@ -72,3 +72,3 @@ satoshis: number;

utxo: {
script: number;
script: number | undefined;
path: string;

@@ -98,5 +98,7 @@ satoshis: number;

coin?: CoinType;
script?: ScriptType;
};
export declare const ow_AddressOption: import("ow").ObjectPredicate<{
coin: number | undefined;
script: number | undefined;
}>;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_AddressOption=exports.btcPurposes=exports.btcCoinTypes=exports.coinmap=exports.CoinType=exports.isOutuptScriptExtended=exports.isOutuptScript=exports.isOutputAddress=exports.ow_txOutput=exports.ow_txOutputScriptExtened=exports.ow_txOutputScript=exports.ow_txOutputAddress=exports.ow_txInput=exports.ow_balance=exports.ScriptType=exports.OPCODES=void 0;const e=require("ow"),t=require("./coindef"),r=require("@secux/utility");var o,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.__LENGTH=4]="__LENGTH"}(o=exports.ScriptType||(exports.ScriptType={})),exports.ow_balance=e.default.number.integer.positive.lessThanOrEqual(9007199254740991),exports.ow_txInput=e.default.object.exactShape({hash:r.ow_hashString,vout:e.default.number.greaterThanOrEqual(0),txHex:e.default.any(e.default.undefined,r.ow_hexString),script:e.default.number.inRange(0,o.__LENGTH-1),satoshis:exports.ow_balance,path:r.ow_bip32String}),exports.ow_txOutputAddress=e.default.object.exactShape({address:r.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=e.default.object.exactShape({scriptHex:r.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=e.default.object.exactShape({script:e.default.number.inRange(0,o.__LENGTH-1),path:r.ow_bip32String,satoshis:exports.ow_balance}),exports.ow_txOutput=e.default.object.exactShape({to:e.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:e.default.any(exports.ow_txOutputScriptExtened,e.default.undefined)}),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(e){const t=e;if(t.path&&t.script in o)return t},function(e){e[e.BITCOIN=0]="BITCOIN",e[e.TESTNET=1]="TESTNET",e[e.LITECOIN=2]="LITECOIN",e[e.BITCOINCASH=3]="BITCOINCASH",e[e.GROESTL=4]="GROESTL",e[e.DIGIBYTE=5]="DIGIBYTE",e[e.DASH=6]="DASH",e[e.DOGECOIN=7]="DOGECOIN",e[e.__LENGTH=8]="__LENGTH"}(p=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze([Object.freeze(t.bitcoin),Object.freeze(t.testnet),Object.freeze(t.litecoin),Object.freeze(t.bitcoincash),Object.freeze(t.groestl),Object.freeze(t.digibyte),Object.freeze(t.dash),Object.freeze(t.dogecoin)]),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)]),exports.ow_AddressOption=e.default.object.exactShape({coin:e.default.optional.number.inRange(0,p.__LENGTH-1)});
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_AddressOption=exports.btcPurposes=exports.btcCoinTypes=exports.coinmap=exports.CoinType=exports.isOutuptScriptExtended=exports.isOutuptScript=exports.isOutputAddress=exports.ow_txOutput=exports.ow_txOutputScriptExtened=exports.ow_txOutputScript=exports.ow_txOutputAddress=exports.ow_txInput=exports.ow_balance=exports.ScriptType=exports.OPCODES=void 0;const e=require("ow"),t=require("./coindef"),r=require("@secux/utility");var o,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.__LENGTH=4]="__LENGTH"}(o=exports.ScriptType||(exports.ScriptType={})),exports.ow_balance=e.default.number.integer.positive.lessThanOrEqual(9007199254740991),exports.ow_txInput=e.default.object.exactShape({hash:r.ow_hashString,vout:e.default.number.greaterThanOrEqual(0),txHex:e.default.any(e.default.undefined,r.ow_hexString),script:e.default.optional.number.inRange(0,o.__LENGTH-1),satoshis:exports.ow_balance,path:r.ow_bip32String}),exports.ow_txOutputAddress=e.default.object.exactShape({address:r.ow_hashString,satoshis:exports.ow_balance}),exports.ow_txOutputScript=e.default.object.exactShape({scriptHex:r.ow_hexString,satoshis:exports.ow_balance}),exports.ow_txOutputScriptExtened=e.default.object.exactShape({script:e.default.optional.number.inRange(0,o.__LENGTH-1),path:r.ow_bip32String,satoshis:exports.ow_balance}),exports.ow_txOutput=e.default.object.exactShape({to:e.default.any(exports.ow_txOutputAddress,exports.ow_txOutputScriptExtened),utxo:e.default.any(exports.ow_txOutputScriptExtened,e.default.undefined)}),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){}},function(e){e[e.BITCOIN=0]="BITCOIN",e[e.TESTNET=1]="TESTNET",e[e.LITECOIN=2]="LITECOIN",e[e.BITCOINCASH=3]="BITCOINCASH",e[e.GROESTL=4]="GROESTL",e[e.DIGIBYTE=5]="DIGIBYTE",e[e.DASH=6]="DASH",e[e.DOGECOIN=7]="DOGECOIN",e[e.__LENGTH=8]="__LENGTH"}(p=exports.CoinType||(exports.CoinType={})),exports.coinmap=Object.freeze([Object.freeze(t.bitcoin),Object.freeze(t.testnet),Object.freeze(t.litecoin),Object.freeze(t.bitcoincash),Object.freeze(t.groestl),Object.freeze(t.digibyte),Object.freeze(t.dash),Object.freeze(t.dogecoin)]),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)]),exports.ow_AddressOption=e.default.object.exactShape({coin:e.default.optional.number.inRange(0,p.__LENGTH-1),script:e.default.optional.number.inRange(0,o.__LENGTH-1)});

@@ -1,1 +0,1 @@

"use strict";var t,i,e,s,r,n,o,a,u,h,c,p,f,d=this&&this.__awaiter||function(t,i,e,s){return new(e||(e=Promise))((function(r,n){function o(t){try{u(s.next(t))}catch(t){n(t)}}function a(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}u((s=s.apply(t,i||[])).next())}))},l=this&&this.__classPrivateFieldSet||function(t,i,e,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof i?t!==i||!r:!i.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(t,e):r?r.value=e:i.set(t,e),e},S=this&&this.__classPrivateFieldGet||function(t,i,e,s){if("a"===e&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof i?t!==i||!s:!i.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?s:"a"===e?s.call(t):s?s.value:i.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxPsbt=void 0;const w=require("bip174"),g=require("bip174/src/lib/utils"),y=require("./script"),T=require("@secux/utility"),_=require("@secux/transport"),P=require("./interface"),v=require("./utils"),m=require("./transaction"),b=null===_.Logger||void 0===_.Logger?void 0:_.Logger.child({id:"psbt"});function W(t,i,e){const s=t.__NON_WITNESS_UTXO_TX_CACHE;if(!s[e]){t.__NON_WITNESS_UTXO_BUF_CACHE[e]=i.nonWitnessUtxo;const s=m.Transaction.fromBuffer(i.nonWitnessUtxo);t.__NON_WITNESS_UTXO_TX_CACHE[e]=s}return s[e]}exports.SecuxPsbt=class{constructor(p,f){t.add(this),i.set(this,void 0),e.set(this,void 0),s.set(this,void 0),r.set(this,void 0),n.set(this,{}),o.set(this,[]),a.set(this,void 0),u.set(this,Buffer.alloc(0)),h.set(this,[]),c.set(this,{address:"",value:""}),l(this,i,p,"f"),l(this,e,new w.Psbt(new x),"f"),l(this,s,f,"f"),l(this,r,(0,v.getPayment)(S(this,s,"f")),"f"),l(this,a,{__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:S(this,e,"f").globalMap.unsignedTx.tx},"f"),f===P.CoinType.BITCOINCASH&&(S(this,a,"f").__TX.version=1)}AddInput(i){return d(this,void 0,void 0,(function*(){const n=yield S(this,t,"m",p).call(this,i.path),u={},c={};switch(i.script){case P.ScriptType.P2PKH:if(!i.txHex)throw Error("ArgumentError: Previous transaction raw data needed");u.nonWitnessUtxo=Buffer.from(i.txHex,"hex");const t=S(this,e,"f").inputs.length;S(this,a,"f").__NON_WITNESS_UTXO_BUF_CACHE[t]=u.nonWitnessUtxo;const o=m.Transaction.fromBuffer(u.nonWitnessUtxo);S(this,a,"f").__NON_WITNESS_UTXO_TX_CACHE[t]=o;break;case P.ScriptType.P2SH_P2WPKH:const h=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:n});u.witnessUtxo={script:S(this,r,"f").p2sh(S(this,s,"f"),h.redeemHash).scriptPublickey,value:i.satoshis},c.redeemScript=h.scriptPublickey;break;case P.ScriptType.P2WPKH:u.witnessUtxo={script:S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:n}).scriptPublickey,value:i.satoshis};break;default:throw Error("Invalid ScriptType")}const f=Object.assign(Object.assign({hash:i.hash,index:i.vout},u),c);return S(this,e,"f").addInput(f),S(this,h,"f").push(i.script),S(this,o,"f").push(i.path),this}))}AddInputs(t){return d(this,void 0,void 0,(function*(){for(const i of t)yield this.AddInput(i);return this}))}AddOutput(i){return d(this,void 0,void 0,(function*(){const n=(0,T.BigIntToBuffer)(i.satoshis,8);let o,a,h,f,d=i.satoshis;if(o=(0,P.isOutuptScriptExtended)(i)){const i=yield S(this,t,"m",p).call(this,o.path);switch(f=o.path,o.script){case P.ScriptType.P2SH_P2WPKH:if(!o.path.startsWith("m/49'/"))throw Error("P2SH(...) should use m/49' path");const t=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:i}).redeemHash,e=S(this,r,"f").p2sh(S(this,s,"f"),t);a=e.scriptPublickey,h=e.address;break;case P.ScriptType.P2PKH:if(!o.path.startsWith("m/44'/"))throw Error("P2PKH should use m/44' path");const n=S(this,r,"f").p2pkh(S(this,s,"f"),{publickey:i});a=n.scriptPublickey,h=n.address;break;case P.ScriptType.P2WPKH:if(!o.path.startsWith("m/84'/"))throw Error("P2WPKH should use m/84' path");const u=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:i});a=u.scriptPublickey,h=u.address;break;default:throw Error("Invalid ScriptType")}}else if(o=(0,P.isOutputAddress)(i))a=S(this,r,"f").decode(S(this,s,"f"),o.address),h=o.address;else{if(!(o=(0,P.isOutuptScript)(i)))throw Error("Invalid parameter of output");a=Buffer.from(o.scriptHex,"hex")}return 0===S(this,e,"f").outputs.length?(l(this,u,Buffer.concat([S(this,u,"f"),n,Buffer.from([a.length]),a]),"f"),S(this,c,"f").address=h,S(this,c,"f").value=(1e-8*d).toString()):l(this,u,Buffer.concat([S(this,u,"f"),n,(0,T.buildPathBuffer)(f).pathBuffer]),"f"),S(this,e,"f").addOutput({script:a,value:d}),this}))}AddOutputs(t){return d(this,void 0,void 0,(function*(){for(const i of t)yield this.AddOutput(i);return this}))}Sign(){return d(this,void 0,void 0,(function*(){l(this,u,Buffer.concat([Buffer.from([S(this,e,"f").outputs.length]),S(this,u,"f")]),"f");const r=S(this,e,"f").inputs.map(((t,i)=>{const r=S(this,h,"f")[i],{data:n}=function(t,i,e,s,r){const n=r.__TX,o=e.sighashType||m.Transaction.SIGHASH_ALL,a=(0,v.getSerializer)(t);let u;if(e.nonWitnessUtxo){const t=W(r,e,i),s=n.ins[i].hash,o=a.getHash(t);if(!s.equals(o))throw new Error(`Non-witness UTXO hash for input #${i} doesn't match the hash specified in the prevout`);const h=n.ins[i].index;u=t.outs[h]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");u=e.witnessUtxo}const h=function(t,i,e,s){let r;switch(i){case P.ScriptType.P2SH_P2PKH:case P.ScriptType.P2SH_P2WPKH:if(!e)throw Error("scriptPubkey is P2SH but redeemScript missing");r=e;break;default:r=t}if(!r)throw Error("cannot extract script");return r}(u.script,s,e.redeemScript,e.witnessScript);let c;switch(null==b||b.debug(`input #${i} script type: ${P.ScriptType[s]}`),null==b||b.debug(`script: ${h.toString("hex")}`),s){case P.ScriptType.P2WPKH:case P.ScriptType.P2SH_P2WPKH:null==b||b.debug("p2wpkh");const s=(0,v.getPayment)(t).p2pkh(t,{hash:h.slice(2)}).scriptPublickey;c=a.dataForWitnessV0(n,i,s,u.value,o);break;default:if(t===P.CoinType.BITCOINCASH)null==b||b.debug("bch using bip143"),c=a.dataForWitnessV0(n,i,h,u.value,64|o);else{if(null==b||b.debug("non-segwit"),!e.nonWitnessUtxo)throw Error(`Input #${i} has witnessUtxo but non-segwit script: ${h.toString("hex")}`);c=a.dataForSignature(n,i,h,o)}}return{script:h,sighashType:o,data:c}}(S(this,s,"f"),i,S(this,e,"f").inputs[i],r,S(this,a,"f"));return S(this,s,"f")!==P.CoinType.BITCOINCASH&&r===P.ScriptType.P2PKH?{data:n,confirm:Buffer.alloc(0)}:{data:n,confirm:S(this,u,"f")}}));for(let t=0;t<r.length;t++)null==b||b.debug(`tx data [${t}]: ${r[t].data.toString("hex")}`),null==b||b.debug(`confirm data [${t}]: ${r[t].confirm.toString("hex")}`);const n=r.map((t=>t.data)),c=yield S(this,i,"f").SignRawTransactionGroup(S(this,o,"f"),n,r[0].confirm);let f=[];for(let i=0;i<S(this,e,"f").inputs.length;i++){const r=c[i];r.trimZero();const n=Buffer.concat([r.r,r.s]);let a=S(this,e,"f").inputs[i].sighashType||m.Transaction.SIGHASH_ALL;S(this,s,"f")===P.CoinType.BITCOINCASH&&(a|=64);const u=[{pubkey:yield S(this,t,"m",p).call(this,S(this,o,"f")[i]),signature:y.encode(n,a)}];S(this,e,"f").updateInput(i,{partialSig:u}),f.push(u[0].signature)}return f}))}finalizeAllInputs(){if(S(this,e,"f").inputs.length<1)throw Error("utxo input cannot be empty");return S(this,e,"f").inputs.forEach(((t,i)=>{(0,g.checkForInput)(S(this,e,"f").inputs,i);const s=function(t,i,e){var s;const r=e.__TX;let n;if(i.witnessScript)n=i.witnessScript;else if(i.redeemScript)n=i.redeemScript;else if(i.nonWitnessUtxo){const s=W(e,i,t),o=r.ins[t].index;n=s.outs[o].script}else n=null===(s=i.witnessUtxo)||void 0===s?void 0:s.script;return n}(i,t,S(this,a,"f"));if(!s)throw new Error(`No script found for input #${i}`);if(t.sighashType&&t.partialSig){const{partialSig:i,sighashType:e}=t;for(const t of i){const{hashType:i}=y.decode(t.signature);if(i!==e)throw new Error("Signature sighash does not match input sighash type")}}const{finalScriptSig:r,finalScriptWitness:n}=function(t,i){let e,s;const{signature:r,pubkey:n}=i[0];switch(t){case P.ScriptType.P2PKH:e=y.compile([r,n]);break;case P.ScriptType.P2SH_P2PKH:e=(()=>{const t=y.compile([r,n]),i=y.decompile(t),e={output:i[i.length-1],input:y.compile(i.slice(0,-1))};return y.compile([y.decompile(e.input),e.output])})();break;case P.ScriptType.P2SH_P2WPKH:case P.ScriptType.P2WPKH:s=(0,v.witnessStackToScriptWitness)([r,n])}return{finalScriptSig:e,finalScriptWitness:s}}(S(this,h,"f")[i],t.partialSig);if(r&&S(this,e,"f").updateInput(i,{finalScriptSig:r}),n&&S(this,e,"f").updateInput(i,{finalScriptWitness:n}),!r&&!n)throw new Error(`Unknown error finalizing input #${i}`)})),this}extractTransaction(){if(!S(this,e,"f").inputs.every((t=>!!t.finalScriptSig||!!t.finalScriptWitness)))throw new Error("Not finalized");const t=S(this,a,"f").__TX.clone();return S(this,e,"f").inputs.forEach(((i,e)=>{i.finalScriptSig&&(t.ins[e].script=i.finalScriptSig),i.finalScriptWitness&&(t.ins[e].witness=(0,v.scriptWitnessToWitnessStack)(i.finalScriptWitness))})),t}},i=new WeakMap,e=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,a=new WeakMap,u=new WeakMap,h=new WeakMap,c=new WeakMap,t=new WeakSet,p=function(t){var e;return d(this,void 0,void 0,(function*(){let s=null===(e=S(this,n,"f")[t])||void 0===e?void 0:e.publicKey;if(!s){const e=yield S(this,i,"f").getXPublickey(t,!0);s=e.publicKey,S(this,n,"f")[t]=e}return s}))};class x{constructor(t=Buffer.from([2,0,0,0,0,0,0,0,0,0])){f.set(this,void 0),l(this,f,m.Transaction.fromBuffer(t),"f")}getInputOutputCounts(){return{inputCount:S(this,f,"f").ins.length,outputCount:S(this,f,"f").outs.length}}addInput(t){if(void 0===t.hash||void 0===t.index||!Buffer.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");const i="string"==typeof t.hash?Buffer.from(Buffer.from(t.hash,"hex").reverse()):t.hash;S(this,f,"f").addInput(i,t.index,t.sequence)}addOutput(t){if(void 0===t.script||void 0===t.value||!Buffer.isBuffer(t.script)||"number"!=typeof t.value)throw new Error("Error adding output.");S(this,f,"f").addOutput(t.script,t.value)}toBuffer(){return S(this,f,"f").toBuffer()}get tx(){return S(this,f,"f")}}f=new WeakMap;
"use strict";var t,i,e,s,r,n,o,a,h,p,u,c,f,l=this&&this.__awaiter||function(t,i,e,s){return new(e||(e=Promise))((function(r,n){function o(t){try{h(s.next(t))}catch(t){n(t)}}function a(t){try{h(s.throw(t))}catch(t){n(t)}}function h(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,a)}h((s=s.apply(t,i||[])).next())}))},d=this&&this.__classPrivateFieldSet||function(t,i,e,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof i?t!==i||!r:!i.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(t,e):r?r.value=e:i.set(t,e),e},S=this&&this.__classPrivateFieldGet||function(t,i,e,s){if("a"===e&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof i?t!==i||!s:!i.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?s:"a"===e?s.call(t):s?s.value:i.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxPsbt=void 0;const w=require("bip174"),g=require("bip174/src/lib/utils"),y=require("./script"),P=require("@secux/utility"),T=require("@secux/transport"),_=require("./interface"),v=require("./utils"),m=require("./transaction"),b=null===T.Logger||void 0===T.Logger?void 0:T.Logger.child({id:"psbt"});function k(t,i,e){const s=t.__NON_WITNESS_UTXO_TX_CACHE;if(!s[e]){t.__NON_WITNESS_UTXO_BUF_CACHE[e]=i.nonWitnessUtxo;const s=m.Transaction.fromBuffer(i.nonWitnessUtxo);t.__NON_WITNESS_UTXO_TX_CACHE[e]=s}return s[e]}exports.SecuxPsbt=class{constructor(c,f){t.add(this),i.set(this,void 0),e.set(this,void 0),s.set(this,void 0),r.set(this,void 0),n.set(this,{}),o.set(this,[]),a.set(this,void 0),h.set(this,Buffer.alloc(0)),p.set(this,[]),u.set(this,{address:"",value:""}),d(this,i,c,"f"),d(this,e,new w.Psbt(new H),"f"),d(this,s,f,"f"),d(this,r,(0,v.getPayment)(S(this,s,"f")),"f"),d(this,a,{__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:S(this,e,"f").globalMap.unsignedTx.tx},"f"),f===_.CoinType.BITCOINCASH&&(S(this,a,"f").__TX.version=1)}AddInput(i){var n;return l(this,void 0,void 0,(function*(){const h=yield S(this,t,"m",c).call(this,i.path),u={},f={},l=null!==(n=i.script)&&void 0!==n?n:(0,v.getDefaultScript)(i.path);switch(l){case _.ScriptType.P2PKH:if(!i.txHex)throw Error("ArgumentError: Previous transaction raw data needed");u.nonWitnessUtxo=Buffer.from(i.txHex,"hex");const t=S(this,e,"f").inputs.length;S(this,a,"f").__NON_WITNESS_UTXO_BUF_CACHE[t]=u.nonWitnessUtxo;const n=m.Transaction.fromBuffer(u.nonWitnessUtxo);S(this,a,"f").__NON_WITNESS_UTXO_TX_CACHE[t]=n;break;case _.ScriptType.P2SH_P2PKH:const o=S(this,r,"f").p2pkh(S(this,s,"f"),{publickey:h});u.witnessUtxo={script:S(this,r,"f").p2sh(S(this,s,"f"),o.redeemHash).scriptPublickey,value:i.satoshis},f.redeemScript=o.scriptPublickey;break;case _.ScriptType.P2SH_P2WPKH:const p=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:h});u.witnessUtxo={script:S(this,r,"f").p2sh(S(this,s,"f"),p.redeemHash).scriptPublickey,value:i.satoshis},f.redeemScript=p.scriptPublickey;break;case _.ScriptType.P2WPKH:u.witnessUtxo={script:S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:h}).scriptPublickey,value:i.satoshis};break;default:throw Error(`ArgumentError: Invalid ScriptType of input#${S(this,e,"f").inputs.length}, got "${_.ScriptType[l]}"`)}const d=Object.assign(Object.assign({hash:i.hash,index:i.vout},u),f);return S(this,e,"f").addInput(d),S(this,p,"f").push(l),S(this,o,"f").push(i.path),this}))}AddInputs(t){return l(this,void 0,void 0,(function*(){for(const i of t)yield this.AddInput(i);return this}))}AddOutput(i){var n;return l(this,void 0,void 0,(function*(){const o=(0,P.BigIntToBuffer)(i.satoshis,8);let a,p,f,l,w=i.satoshis;if(a=(0,_.isOutuptScriptExtended)(i)){const i=yield S(this,t,"m",c).call(this,a.path);l=a.path;const o=null!==(n=a.script)&&void 0!==n?n:(0,v.getDefaultScript)(l);switch(o){case _.ScriptType.P2SH_P2WPKH:if(!a.path.startsWith("m/49'/"))throw Error("P2SH(...) should use m/49' path");let t=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:i}).redeemHash,n=S(this,r,"f").p2sh(S(this,s,"f"),t);p=n.scriptPublickey,f=n.address;break;case _.ScriptType.P2SH_P2PKH:if(!a.path.startsWith("m/49'/"))throw Error("P2SH(...) should use m/49' path");t=S(this,r,"f").p2pkh(S(this,s,"f"),{publickey:i}).redeemHash,n=S(this,r,"f").p2sh(S(this,s,"f"),t),p=n.scriptPublickey,f=n.address;break;case _.ScriptType.P2PKH:if(!a.path.startsWith("m/44'/"))throw Error("P2PKH should use m/44' path");const h=S(this,r,"f").p2pkh(S(this,s,"f"),{publickey:i});p=h.scriptPublickey,f=h.address;break;case _.ScriptType.P2WPKH:if(!a.path.startsWith("m/84'/"))throw Error("P2WPKH should use m/84' path");const u=S(this,r,"f").p2wpkh(S(this,s,"f"),{publickey:i});p=u.scriptPublickey,f=u.address;break;default:throw Error(`ArgumentError: Invalid ScriptType of output#${S(this,e,"f").outputs.length}, got "${_.ScriptType[o]}"`)}}else if(a=(0,_.isOutputAddress)(i))p=S(this,r,"f").decode(S(this,s,"f"),a.address),f=a.address;else{if(!(a=(0,_.isOutuptScript)(i)))throw Error("Invalid parameter of output");p=Buffer.from(a.scriptHex,"hex")}return 0===S(this,e,"f").outputs.length?(d(this,h,Buffer.concat([S(this,h,"f"),o,Buffer.from([p.length]),p]),"f"),S(this,u,"f").address=f,S(this,u,"f").value=(1e-8*w).toString()):d(this,h,Buffer.concat([S(this,h,"f"),o,(0,P.buildPathBuffer)(l).pathBuffer]),"f"),S(this,e,"f").addOutput({script:p,value:w}),this}))}AddOutputs(t){return l(this,void 0,void 0,(function*(){for(const i of t)yield this.AddOutput(i);return this}))}Sign(){return l(this,void 0,void 0,(function*(){d(this,h,Buffer.concat([Buffer.from([S(this,e,"f").outputs.length]),S(this,h,"f")]),"f");const r=S(this,e,"f").inputs.map(((t,i)=>{const r=S(this,p,"f")[i],{data:n}=function(t,i,e,s,r){const n=r.__TX,o=e.sighashType||m.Transaction.SIGHASH_ALL,a=(0,v.getSerializer)(t);let h;if(e.nonWitnessUtxo){const t=k(r,e,i),s=n.ins[i].hash,o=a.getHash(t);if(!s.equals(o))throw new Error(`Non-witness UTXO hash for input #${i} doesn't match the hash specified in the prevout`);const p=n.ins[i].index;h=t.outs[p]}else{if(!e.witnessUtxo)throw new Error("Need a Utxo input item for signing");h=e.witnessUtxo}const p=function(t,i,e,s){let r;switch(i){case _.ScriptType.P2SH_P2PKH:case _.ScriptType.P2SH_P2WPKH:if(!e)throw Error("scriptPubkey is P2SH but redeemScript missing");r=e;break;default:r=t}if(!r)throw Error("cannot extract script");return r}(h.script,s,e.redeemScript,e.witnessScript);let u;switch(null==b||b.debug(`input #${i} script type: ${_.ScriptType[s]}`),null==b||b.debug(`script: ${p.toString("hex")}`),s){case _.ScriptType.P2WPKH:case _.ScriptType.P2SH_P2WPKH:case _.ScriptType.P2SH_P2PKH:null==b||b.debug(_.ScriptType[s]);const r=(0,v.getPayment)(t).p2pkh(t,{hash:p.slice(2)}).scriptPublickey;u=a.dataForWitnessV0(n,i,r,h.value,o);break;default:if(t===_.CoinType.BITCOINCASH)null==b||b.debug("bch using bip143"),u=a.dataForWitnessV0(n,i,p,h.value,64|o);else{if(null==b||b.debug("non-segwit"),!e.nonWitnessUtxo)throw Error(`Input #${i} has witnessUtxo but non-segwit script: ${p.toString("hex")}`);u=a.dataForSignature(n,i,p,o)}}return{script:p,sighashType:o,data:u}}(S(this,s,"f"),i,S(this,e,"f").inputs[i],r,S(this,a,"f"));return S(this,s,"f")!==_.CoinType.BITCOINCASH&&r===_.ScriptType.P2PKH?{data:n,confirm:Buffer.alloc(0)}:{data:n,confirm:S(this,h,"f")}}));for(let t=0;t<r.length;t++)null==b||b.debug(`tx data [${t}]: ${r[t].data.toString("hex")}`),null==b||b.debug(`confirm data [${t}]: ${r[t].confirm.toString("hex")}`);const n=r.map((t=>t.data)),u=yield S(this,i,"f").SignRawTransactionGroup(S(this,o,"f"),n,r[0].confirm);let f=[];for(let i=0;i<S(this,e,"f").inputs.length;i++){const r=u[i];r.trimZero();const n=Buffer.concat([r.r,r.s]);let a=S(this,e,"f").inputs[i].sighashType||m.Transaction.SIGHASH_ALL;S(this,s,"f")===_.CoinType.BITCOINCASH&&(a|=64);const h=[{pubkey:yield S(this,t,"m",c).call(this,S(this,o,"f")[i]),signature:y.encode(n,a)}];S(this,e,"f").updateInput(i,{partialSig:h}),f.push(h[0].signature)}return f}))}finalizeAllInputs(){if(S(this,e,"f").inputs.length<1)throw Error("utxo input cannot be empty");return S(this,e,"f").inputs.forEach(((t,i)=>{(0,g.checkForInput)(S(this,e,"f").inputs,i);const s=function(t,i,e){var s;const r=e.__TX;let n;if(i.witnessScript)n=i.witnessScript;else if(i.redeemScript)n=i.redeemScript;else if(i.nonWitnessUtxo){const s=k(e,i,t),o=r.ins[t].index;n=s.outs[o].script}else n=null===(s=i.witnessUtxo)||void 0===s?void 0:s.script;return n}(i,t,S(this,a,"f"));if(!s)throw new Error(`No script found for input #${i}`);if(t.sighashType&&t.partialSig){const{partialSig:i,sighashType:e}=t;for(const t of i){const{hashType:i}=y.decode(t.signature);if(i!==e)throw new Error("Signature sighash does not match input sighash type")}}const{finalScriptSig:r,finalScriptWitness:n}=function(t,i){let e,s;const{signature:r,pubkey:n}=i[0];switch(t){case _.ScriptType.P2PKH:e=y.compile([r,n]);break;case _.ScriptType.P2SH_P2PKH:e=(()=>{const t=y.compile([r,n]),i=y.decompile(t),e={output:i[i.length-1],input:y.compile(i.slice(0,-1))};return y.compile([y.decompile(e.input),e.output])})();break;case _.ScriptType.P2SH_P2WPKH:case _.ScriptType.P2WPKH:s=(0,v.witnessStackToScriptWitness)([r,n])}return{finalScriptSig:e,finalScriptWitness:s}}(S(this,p,"f")[i],t.partialSig);if(r&&S(this,e,"f").updateInput(i,{finalScriptSig:r}),n&&S(this,e,"f").updateInput(i,{finalScriptWitness:n}),!r&&!n)throw new Error(`Unknown error finalizing input #${i}`)})),this}extractTransaction(){if(!S(this,e,"f").inputs.every((t=>!!t.finalScriptSig||!!t.finalScriptWitness)))throw new Error("Not finalized");const t=S(this,a,"f").__TX.clone();return S(this,e,"f").inputs.forEach(((i,e)=>{i.finalScriptSig&&(t.ins[e].script=i.finalScriptSig),i.finalScriptWitness&&(t.ins[e].witness=(0,v.scriptWitnessToWitnessStack)(i.finalScriptWitness))})),t}},i=new WeakMap,e=new WeakMap,s=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,a=new WeakMap,h=new WeakMap,p=new WeakMap,u=new WeakMap,t=new WeakSet,c=function(t){var e;return l(this,void 0,void 0,(function*(){let s=null===(e=S(this,n,"f")[t])||void 0===e?void 0:e.publicKey;if(!s){const e=yield S(this,i,"f").getXPublickey(t,!0);s=e.publicKey,S(this,n,"f")[t]=e}return s}))};class H{constructor(t=Buffer.from([2,0,0,0,0,0,0,0,0,0])){f.set(this,void 0),d(this,f,m.Transaction.fromBuffer(t),"f")}getInputOutputCounts(){return{inputCount:S(this,f,"f").ins.length,outputCount:S(this,f,"f").outs.length}}addInput(t){if(void 0===t.hash||void 0===t.index||!Buffer.isBuffer(t.hash)&&"string"!=typeof t.hash||"number"!=typeof t.index)throw new Error("Error adding input.");const i="string"==typeof t.hash?Buffer.from(Buffer.from(t.hash,"hex").reverse()):t.hash;S(this,f,"f").addInput(i,t.index,t.sequence)}addOutput(t){if(void 0===t.script||void 0===t.value||!Buffer.isBuffer(t.script)||"number"!=typeof t.value)throw new Error("Error adding output.");S(this,f,"f").addOutput(t.script,t.value)}toBuffer(){return S(this,f,"f").toBuffer()}get tx(){return S(this,f,"f")}}f=new WeakMap;

@@ -8,4 +8,5 @@ /// <reference types="node" />

export declare function getPurpose(script: ScriptType): number;
export declare function getDefaultScript(path: string): ScriptType;
export declare function getSerializer(coin: CoinType): typeof Transaction;
export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
export declare function scriptWitnessToWitnessStack(buffer: Buffer): Buffer[];

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.scriptWitnessToWitnessStack=exports.witnessStackToScriptWitness=exports.getSerializer=exports.getPurpose=exports.getCoinType=exports.getPayment=void 0;const e=require("varuint-bitcoin"),t=require("./interface"),r=require("./payment"),n=require("./payment_bch"),o=require("./payment_grs"),s=require("./transaction"),i=require("./transaction_grs"),c=require("ow"),p=require("@secux/utility");exports.getPayment=function(e){switch(e){case t.CoinType.BITCOINCASH:return n.PaymentBCH;case t.CoinType.GROESTL:return o.PaymentGRS;default:return r.PaymentBTC}},exports.getCoinType=function(e){(0,c.default)(e,p.ow_bip32String);const r=e.match(/\d+/g),n=parseInt(r[1],10);for(let e=0;e<t.coinmap.length;e++)if(n===t.coinmap[e].coinType)return e;throw Error(`ArgumentError: unsupport cointype of BIP32 path, got ${e}`)},exports.getPurpose=function(e){switch(e){case t.ScriptType.P2PKH:return 44;case t.ScriptType.P2SH_P2PKH:case t.ScriptType.P2SH_P2WPKH:return 49;case t.ScriptType.P2WPKH:return 84}throw Error(`ArgumentError: unsupport ScriptType, got ${e}`)},exports.getSerializer=function(e){return e===t.CoinType.GROESTL?i.TransactionGRS:s.Transaction},exports.witnessStackToScriptWitness=function(t){let r=Buffer.allocUnsafe(0);const n=t=>{const n=r.length,o=e.encodingLength(t);r=Buffer.concat([r,Buffer.allocUnsafe(o)]),e.encode(t,r,n)};n(t.length);for(const e of t)n(e.length),r=Buffer.concat([r,Buffer.from(e)]);return r},exports.scriptWitnessToWitnessStack=function(t){let r=0;const n=()=>{const n=e.decode(t,r);return r+=e.decode.bytes,n},o=()=>{const e=n();return r+=e,t.slice(r-e,r)},s=n(),i=[];for(let e=0;e<s;e++)i.push(o());return i};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.scriptWitnessToWitnessStack=exports.witnessStackToScriptWitness=exports.getSerializer=exports.getDefaultScript=exports.getPurpose=exports.getCoinType=exports.getPayment=void 0;const e=require("varuint-bitcoin"),t=require("./interface"),r=require("./payment"),n=require("./payment_bch"),o=require("./payment_grs"),s=require("./transaction"),i=require("./transaction_grs"),c=require("ow"),p=require("@secux/utility");exports.getPayment=function(e){switch(e){case t.CoinType.BITCOINCASH:return n.PaymentBCH;case t.CoinType.GROESTL:return o.PaymentGRS;default:return r.PaymentBTC}},exports.getCoinType=function(e){(0,c.default)(e,p.ow_bip32String);const r=e.match(/\d+/g),n=parseInt(r[1],10);for(let e=0;e<t.coinmap.length;e++)if(n===t.coinmap[e].coinType)return e;throw Error(`ArgumentError: unsupport cointype of BIP32 path, got ${e}`)},exports.getPurpose=function(e){switch(e){case t.ScriptType.P2PKH:return 44;case t.ScriptType.P2SH_P2PKH:case t.ScriptType.P2SH_P2WPKH:return 49;case t.ScriptType.P2WPKH:return 84}throw Error(`ArgumentError: unsupport ScriptType, got ${e}`)},exports.getDefaultScript=function(e){(0,c.default)(e,p.ow_bip32String);const r=e.match(/\d+/g),n=parseInt(r[0],10);switch(n){case 44:return t.ScriptType.P2PKH;case 49:return t.ScriptType.P2SH_P2WPKH;case 84:return t.ScriptType.P2WPKH}throw Error(`ArgumentError: unsupport purpose of path, got "${n}" from ${e}`)},exports.getSerializer=function(e){return e===t.CoinType.GROESTL?i.TransactionGRS:s.Transaction},exports.witnessStackToScriptWitness=function(t){let r=Buffer.allocUnsafe(0);const n=t=>{const n=r.length,o=e.encodingLength(t);r=Buffer.concat([r,Buffer.allocUnsafe(o)]),e.encode(t,r,n)};n(t.length);for(const e of t)n(e.length),r=Buffer.concat([r,Buffer.from(e)]);return r},exports.scriptWitnessToWitnessStack=function(t){let r=0;const n=()=>{const n=e.decode(t,r);return r+=e.decode.bytes,n},o=()=>{const e=n();return r+=e,t.slice(r-e,r)},s=n(),i=[];for(let e=0;e<s;e++)i.push(o());return i};
{
"name": "@secux/app-btc",
"version": "2.0.0-rc1",
"version": "2.0.0-rc2",
"description": "SecuX Hardware Wallet BTC API",

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

@@ -8,3 +8,3 @@ # `@secux/app-btc`

```ts
import { SecuxBTC, ScriptType } from "@secux/app-btc";
import { CoinType, SecuxBTC, ScriptType } from "@secux/app-btc";
```

@@ -22,24 +22,26 @@

```ts
// native segwit address
// native segwit address (default script: P2WPKH)
const address = SecuxBTC.getAddress(
device,
"m/84'/0'/0'/0/0",
ScriptType.P2WPKH,
// optional object
{
coin: CoinType.BITCOIN // define cointype for checking path, optional
// define cointype for checking path
coin: CoinType.BITCOIN,
// define specific script
script: ScriptType.P2WPKH
}
);
// segwit address
// segwit address (default script: P2SH_P2WPKH)
const address = SecuxBTC.getAddress(
device,
"m/49'/0'/0'/0/0",
ScriptType.P2SH_P2WPKH
"m/49'/0'/0'/0/0"
);
// legacy address
// legacy address (default script: P2PKH)
const address = SecuxBTC.getAddress(
device,
"m/44'/0'/0'/0/0",
ScriptType.P2PKH
"m/44'/0'/0'/0/0"
);

@@ -53,4 +55,3 @@ ```

device,
"m/84'/3'/0'/0/0",
ScriptType.P2WPKH
"m/84'/3'/0'/0/0"
);

@@ -61,4 +62,3 @@

device,
"m/49'/2'/0'/0/0",
ScriptType.P2SH_P2WPKH
"m/49'/2'/0'/0/0",
);

@@ -69,4 +69,3 @@

device,
"m/44'/145'/0'/0/0",
ScriptType.P2PKH
"m/44'/145'/0'/0/0"
);

@@ -83,3 +82,2 @@ ```

txHex: "0100000001b103a004f672080ceae8277e83c296b5ac090ae78157979211da3e2d41399d1b010000006b483045022100f19d88e6a17789dc399ff2a93b4516bb44af32928d4986138f1a4f7f37ab277b022046fc14c958bc8aa97fea1d2fbf80982534cf51634d46c4d5178e5ca6698bca07012102f8667cfb5b80c3695e3f0c9078589cb04e8d15e71bdae89ebf24b82f9d663d5cffffffff02bc020000000000001976a9145c592f40134c6179a1ce5b06b28d5c2ae443113188ac00040000000000001976a9146d65ced4ef49e23cdbb4be9d510b38e5be28e10688ac00000000",
script: ScriptType.P2PKH,
satoshis: 700,

@@ -91,2 +89,3 @@ path: "m/44'/0'/0'/0/0"

vout: 0,
// optional, you can use specific script for each input
script: ScriptType.P2SH_P2WPKH,

@@ -99,3 +98,2 @@ satoshis: 6000,

vout: 1,
script: ScriptType.P2WPKH,
satoshis: 1083,

@@ -111,3 +109,2 @@ path: "m/84'/0'/0'/1/0"

// or send to another account
// script: ScriptType.P2WPKH,
// path: "m/84'/0'/1'/0/3",

@@ -118,3 +115,2 @@ // satoshis: 6100

const utxo = {
script: ScriptType.P2PKH,
path: "m/44'/0'/0'/0/0",

@@ -138,3 +134,3 @@ satoshis: 6100

## SecuxBTC
### `SecuxBTC`
BTC package for SecuX device

@@ -145,8 +141,8 @@

- [SecuxBTC](#secuxbtc)
- [**SecuxBTC.getAddress(trans, path, script, [option])** ⇒ <code>string</code>](#secuxbtcgetaddresstrans-path-script-option--string)
- [**SecuxBTC.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code>](#secuxbtcsigntransactiontrans-inputs-outputs--object)
- [**SecuxBTC.getAddress(trans, path, [option])** ⇒ <code>string</code>](#secuxbtcgetaddresstrans-path-option--string)
- [SecuxBTC.signTransaction(trans, inputs, outputs) ⇒ <code>object</code>](#secuxbtcsigntransactiontrans-inputs-outputs--object)
<a name="SecuxBTC.getAddress"></a><br/>
### **SecuxBTC.getAddress(trans, path, script, [option])** ⇒ <code>string</code>
### **SecuxBTC.getAddress(trans, path, [option])** ⇒ <code>string</code>
*Get address derived by given BIP32 path*

@@ -161,3 +157,2 @@

| path | <code>string</code> | BIP32 |
| script | <code>ScriptType</code> | script type |
| [option] | <code>AddressOption</code> | |

@@ -167,8 +162,7 @@

### **SecuxBTC.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code>
### SecuxBTC.signTransaction(trans, inputs, outputs) ⇒ <code>object</code>
*Create transaction and Sign*
**Kind**: static method of [<code>SecuxBTC</code>](#SecuxBTC)
**Returns**: <br/>
<code>object</code> - signed<br/>
**Returns**: <code>object</code> - signed<br/>
<code>string</code> - signed.raw_tx<br/>

@@ -175,0 +169,0 @@ <code>Array&lt;Buffer&gt;</code> - signed.signature<br/>

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