@secux/app-btc
Advanced tools
Comparing version 2.0.0-rc6 to 2.0.1
@@ -9,2 +9,3 @@ /// <reference types="node" /> | ||
export declare class SecuxBTC { | ||
#private; | ||
/** | ||
@@ -31,2 +32,3 @@ * Get address derived by given BIP32 path | ||
}>; | ||
static deriveAddress(xpub: string, change: number, addressIndex: number, option?: AddressOption): string; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";var t=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function s(t){try{p(i.next(t))}catch(t){n(t)}}function c(t){try{p(i.throw(t))}catch(t){n(t)}}function p(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,c)}p((i=i.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"),i=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"),s=require("./utils");exports.SecuxBTC=class{static getAddress(n,c,p){var u,a;return t(this,void 0,void 0,(function*(){(0,i.default)(c,r.ow_strictPath(o.btcCoinTypes,o.btcPurposes)),p&&(0,i.default)(p,o.ow_AddressOption);const t=null!==(u=null==p?void 0:p.coin)&&void 0!==u?u:(0,s.getCoinType)(c),d=o.coinmap[t].coinType,l=void 0===(null==p?void 0:p.script)?void 0:(0,s.getPurpose)(null==p?void 0:p.script);(0,i.default)(c,r.ow_strictPath(d,l));const y=yield n.getPublickey(c,e.EllipticCurve.SECP256K1,!0),P=(0,s.getPayment)(t);switch(null!==(a=null==p?void 0:p.script)&&void 0!==a?a:(0,s.getDefaultScript)(c)){case o.ScriptType.P2SH_P2WPKH:const e=P.p2wpkh(t,{publickey:y});return P.p2sh(t,e.redeemHash).address;case o.ScriptType.P2SH_P2PKH:const r=P.p2pkh(t,{publickey:y});return P.p2sh(t,r.redeemHash).address;case o.ScriptType.P2PKH:return P.p2pkh(t,{publickey:y}).address;case o.ScriptType.P2WPKH:return P.p2wpkh(t,{publickey:y}).address;default:throw Error("Invalid or unsupported ScriptType")}}))}static signTransaction(e,c,p){return t(this,void 0,void 0,(function*(){(0,i.default)(c,i.default.array.ofType(o.ow_txInput).minLength(1));const t=(0,s.getCoinType)(c[0].path);(0,i.default)(p,o.ow_txOutput),c.map((e=>{const n=e.script?(0,s.getPurpose)(e.script):o.btcPurposes;(0,i.default)(e.path,r.ow_strictPath(o.coinmap[t].coinType,n))}));let u=(0,o.isOutuptScriptExtended)(p.to);if(u){const e=u.script?(0,s.getPurpose)(u.script):o.btcPurposes;(0,i.default)(u.path,r.ow_strictPath(o.coinmap[t].coinType,e))}if(p.utxo){const e=p.utxo.script?(0,s.getPurpose)(p.utxo.script):o.btcPurposes;(0,i.default)(p.utxo.path,r.ow_strictPath(o.coinmap[t].coinType,e))}const a=new n.SecuxPsbt(e,t);yield a.AddInputs(c),yield a.AddOutputs(p.utxo?[p.to,p.utxo]:[p.to]);const d=yield a.Sign();return{raw_tx:a.finalizeAllInputs().extractTransaction().toHex(),signature:d}}))}}; | ||
"use strict";var t,e,r=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function u(t){try{c(i.next(t))}catch(t){n(t)}}function s(t){try{c(i.throw(t))}catch(t){n(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,s)}c((i=i.apply(t,e||[])).next())}))},i=this&&this.__classPrivateFieldGet||function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxBTC=exports.ScriptType=exports.CoinType=void 0;const o=require("@secux/transport/lib/ITransaction"),n=require("@secux/utility"),u=require("@secux/utility/lib/xpub"),s=require("ow"),c=require("./interface");Object.defineProperty(exports,"CoinType",{enumerable:!0,get:function(){return c.CoinType}}),Object.defineProperty(exports,"ScriptType",{enumerable:!0,get:function(){return c.ScriptType}});const p=require("./psbt"),a=require("./utils");class d{static getAddress(u,p,l){var f,y;return r(this,void 0,void 0,(function*(){(0,s.default)(p,n.ow_strictPath(c.btcCoinTypes,c.btcPurposes)),l&&(0,s.default)(l,c.ow_AddressOption);const r=null!==(f=null==l?void 0:l.coin)&&void 0!==f?f:(0,a.getCoinType)(p),h=c.coinmap[r].coinType,P=void 0===(null==l?void 0:l.script)?void 0:(0,a.getPurpose)(null==l?void 0:l.script);(0,s.default)(p,n.ow_strictPath(h,P));const v=yield u.getPublickey(p,o.EllipticCurve.SECP256K1,!0),x=null!==(y=null==l?void 0:l.script)&&void 0!==y?y:(0,a.getDefaultScript)(p);return i(d,t,"m",e).call(d,v,r,x)}))}static signTransaction(t,e,i){return r(this,void 0,void 0,(function*(){(0,s.default)(e,s.default.array.ofType(c.ow_txInput).minLength(1));const r=(0,a.getCoinType)(e[0].path);(0,s.default)(i,c.ow_txOutput),e.map((t=>{const e=t.script?(0,a.getPurpose)(t.script):c.btcPurposes;(0,s.default)(t.path,n.ow_strictPath(c.coinmap[r].coinType,e))}));let o=(0,c.isOutuptScriptExtended)(i.to);if(o){const t=o.script?(0,a.getPurpose)(o.script):c.btcPurposes;(0,s.default)(o.path,n.ow_strictPath(c.coinmap[r].coinType,t))}if(i.utxo){const t=i.utxo.script?(0,a.getPurpose)(i.utxo.script):c.btcPurposes;(0,s.default)(i.utxo.path,n.ow_strictPath(c.coinmap[r].coinType,t))}const u=new p.SecuxPsbt(t,r);yield u.AddInputs(e),yield u.AddOutputs(i.utxo?[i.to,i.utxo]:[i.to]);const d=yield u.Sign();return{raw_tx:u.finalizeAllInputs().extractTransaction().toHex(),signature:d}}))}static deriveAddress(r,o,n,p){var l,f;(0,s.default)(o,s.default.number.uint8),(0,s.default)(n,s.default.number.uint8),(0,s.default)(p,s.default.any(s.default.undefined,c.ow_AddressOption));const y=(0,u.decodeXPUB)(r);if(3!==y.depth)throw Error(`ArgumentError: expect depth from xpub is 3, but got ${y.depth}`);if(null==p?void 0:p.script){const t=(0,a.getPurpose)(null==p?void 0:p.script);if(y.purpose!==t)throw Error(`ArgumentError: expect purpose from xpub is ${t}, but got ${y.purpose}`)}const{publickey:h}=(0,u.deriveKey)(y.publickey,y.chaincode,[o,n]),P=null!==(l=null==p?void 0:p.coin)&&void 0!==l?l:c.CoinType.BITCOIN,v=null!==(f=null==p?void 0:p.script)&&void 0!==f?f:(0,a.getDefaultScript)(`m/${y.purpose}'`);return i(d,t,"m",e).call(d,h,P,v)}}exports.SecuxBTC=d,t=d,e=function(t,e,r){const i=(0,a.getPayment)(e);switch(r){case c.ScriptType.P2SH_P2WPKH:const o=i.p2wpkh(e,{publickey:t});return i.p2sh(e,o.redeemHash).address;case c.ScriptType.P2SH_P2PKH:const n=i.p2pkh(e,{publickey:t});return i.p2sh(e,n.redeemHash).address;case c.ScriptType.P2PKH:return i.p2pkh(e,{publickey:t}).address;case c.ScriptType.P2WPKH:return i.p2wpkh(e,{publickey:t}).address;default:throw Error(`Invalid or unsupported ScriptType, got ${r} of ${e}`)}}; |
@@ -1,1 +0,1 @@ | ||
"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}; | ||
"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"),c=require("./transaction_grs"),i=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,i.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){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?c.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(),c=[];for(let e=0;e<s;e++)c.push(o());return c}; |
{ | ||
"name": "@secux/app-btc", | ||
"version": "2.0.0-rc6", | ||
"version": "2.0.1", | ||
"description": "SecuX Hardware Wallet BTC API", | ||
@@ -35,4 +35,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@secux/transport": "^2.1.3", | ||
"@secux/utility": "^2.0.6", | ||
"@secux/transport": "^2.1.4", | ||
"@secux/utility": "^2.0.7", | ||
"bech32": "^2.0.0", | ||
@@ -39,0 +39,0 @@ "bip174": "^2.0.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
60325
415
12
Updated@secux/transport@^2.1.4
Updated@secux/utility@^2.0.7