@secux/utility
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isSupportedCoin=exports.supported_coin=exports.BigIntToBuffer=exports.ow_checkBufferLength=exports.ow_accountPath=exports.ow_strictPath=exports.ow_xpubString=exports.ow_numberString=exports.ow_hashString=exports.ow_prefixedhexString=exports.ow_hexString=exports.ow_bip32String=exports.Logger=exports.Signature=exports.toExtenededPublicKey=exports.splitPath=exports.decodePathBuffer=exports.buildPathBuffer=void 0;const e=require("bignumber.js"),t=require("ow"),r=require("./BIP32Path");var o=require("./BIP32Path");Object.defineProperty(exports,"buildPathBuffer",{enumerable:!0,get:function(){return o.buildPathBuffer}}),Object.defineProperty(exports,"decodePathBuffer",{enumerable:!0,get:function(){return o.decodePathBuffer}}),Object.defineProperty(exports,"splitPath",{enumerable:!0,get:function(){return o.splitPath}});var n=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return n.toExtenededPublicKey}});var p=require("./signature");function u(e){let t="";return e.map((e=>t+=`${e.toString()}|`)),t=`(${t.substr(0,t.length-1)})`,t}Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return p.Signature}}),exports.Logger=process.env.SECUX_LOGGER,exports.ow_bip32String=t.default.string.matches(/^m(\/\d+'){3}((\/\d+){2})?$/),exports.ow_hexString=t.default.string.matches(/^[0-9A-F-a-f]+$/),exports.ow_prefixedhexString=t.default.string.matches(/^0x[0-9A-F-a-f]+$/),exports.ow_hashString=t.default.string.matches(/^[0-9A-Z-a-z]+$/),exports.ow_numberString=t.default.string.matches(/^[0-9]+$/),exports.ow_xpubString=t.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/),exports.ow_strictPath=function(e,r){const o=u("number"==typeof e?[e]:e);if(r){const e=u("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${o}'/[0-9]+'/[0-9]+/[0-9]+$`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${o}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(e,r){const o=u("number"==typeof e?[e]:e);if(r){const e=u("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${o}'/[0-9]+'`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${o}'/[0-9]+'`))},exports.ow_checkBufferLength=function(e){return t.default.buffer.validate((t=>({validator:t.length===e,message:r=>`ArgumentError: Expected length of ${r} is ${e}, got ${t.length}`})))},exports.BigIntToBuffer=function(t,r,o=!0){let n="";"number"==typeof t?n=t.toString(16):"string"==typeof t&&(n=new e.BigNumber(t).toString(16)),n.length%2!=0&&(n="0"+n);const p=Buffer.from(n,"hex");if(p.length>r)throw Error("value is too large");const u=Buffer.concat([Buffer.alloc(r-p.length),p]);return o?u.reverse():u},exports.supported_coin=Object.freeze([{purpose:[44,49,84,86],cointype:0,name:"bitcoin mainnet",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49,84,86],cointype:1,name:"bitcoin testnet",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:2,name:"litecoin",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:3,name:"dogecoin",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:5,name:"dash",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:17,name:"groestl",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:20,name:"digibyte",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:60,name:"ethereum",module:"SecuxETH",npm:"@secux/app-eth"},{purpose:[44],cointype:144,name:"ripple",module:"SecuxXRP",npm:"@secux/app-xrp"},{purpose:[44],cointype:145,name:"bitcoincash",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:148,name:"stellar",module:"SecuxXLM",npm:"@secux/app-xlm"},{purpose:[44],cointype:195,name:"tron",module:"SecuxTRX",npm:"@secux/app-trx"},{purpose:[44],cointype:714,name:"binance",module:"SecuxBNB",npm:"@secux/app-bnb"},{purpose:[44,1852],cointype:1815,name:"cardano",module:"SecuxADA",npm:"@secux/app-ada"}]),exports.isSupportedCoin=function(e){const t=(0,r.splitPath)(e);for(const e of exports.supported_coin)if(e.purpose.includes(t.purpose.value)&&e.cointype===t.coinType.value)return!0;return!1},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isSupportedCoin=exports.supported_coin=exports.BigIntToBuffer=exports.ow_checkBufferLength=exports.ow_accountPath=exports.ow_strictPath=exports.ow_xpubString=exports.ow_numberString=exports.ow_hashString=exports.ow_prefixedhexString=exports.ow_hexString=exports.ow_bip32String=exports.Logger=exports.Signature=exports.toExtenededPublicKey=exports.splitPath=exports.decodePathBuffer=exports.buildPathBuffer=void 0;const e=require("bignumber.js"),t=require("ow"),r=require("./BIP32Path");var o=require("./BIP32Path");Object.defineProperty(exports,"buildPathBuffer",{enumerable:!0,get:function(){return o.buildPathBuffer}}),Object.defineProperty(exports,"decodePathBuffer",{enumerable:!0,get:function(){return o.decodePathBuffer}}),Object.defineProperty(exports,"splitPath",{enumerable:!0,get:function(){return o.splitPath}});var n=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return n.toExtenededPublicKey}});var p=require("./signature");function u(e){let t="";return e.map((e=>t+=`${e.toString()}|`)),t=`(${t.substr(0,t.length-1)})`,t}Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return p.Signature}}),exports.Logger=process.env.SECUX_LOGGER,exports.ow_bip32String=t.default.string.matches(/^m(\/\d+'){3}((\/\d+){2})?$/),exports.ow_hexString=t.default.string.matches(/^[0-9A-F-a-f]+$/),exports.ow_prefixedhexString=t.default.string.matches(/^0x[0-9A-F-a-f]+$/),exports.ow_hashString=t.default.string.matches(/^[0-9A-Z-a-z]+$/),exports.ow_numberString=t.default.string.matches(/^[0-9]+$/),exports.ow_xpubString=t.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/),exports.ow_strictPath=function(e,r){const o=u("number"==typeof e?[e]:e);if(r){const e=u("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${o}'/[0-9]+'/[0-9]+/[0-9]+$`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${o}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(e,r){const o=u("number"==typeof e?[e]:e);if(r){const e=u("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${o}'/[0-9]+'`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${o}'/[0-9]+'`))},exports.ow_checkBufferLength=function(e){return t.default.buffer.validate((t=>({validator:t.length===e,message:r=>`ArgumentError: Expected length of ${r} is ${e}, got ${t.length}`})))},exports.BigIntToBuffer=function(t,r,o=!0){let n="";"number"==typeof t?n=t.toString(16):"string"==typeof t&&(n=new e.BigNumber(t).toString(16)),n.length%2!=0&&(n="0"+n);const p=Buffer.from(n,"hex");if(p.length>r)throw Error("value is too large");const u=Buffer.concat([Buffer.alloc(r-p.length),p]);return o?u.reverse():u},exports.supported_coin=Object.freeze([{purpose:[44,49,84,86],cointype:0,name:"bitcoin mainnet",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49,84,86],cointype:1,name:"bitcoin testnet",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:2,name:"litecoin",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:3,name:"dogecoin",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:5,name:"dash",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:17,name:"groestl",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44,49],cointype:20,name:"digibyte",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:60,name:"ethereum",module:"SecuxETH",npm:"@secux/app-eth"},{purpose:[44],cointype:144,name:"ripple",module:"SecuxXRP",npm:"@secux/app-xrp"},{purpose:[44],cointype:145,name:"bitcoincash",module:"SecuxBTC",npm:"@secux/app-btc"},{purpose:[44],cointype:148,name:"stellar",module:"SecuxXLM",npm:"@secux/app-xlm"},{purpose:[44],cointype:195,name:"tron",module:"SecuxTRX",npm:"@secux/app-trx"},{purpose:[44],cointype:714,name:"binance",module:"SecuxBNB",npm:"@secux/app-bnb"},{purpose:[1852],cointype:1815,name:"cardano",module:"SecuxADA",npm:"@secux/app-ada"}]),exports.isSupportedCoin=function(e){const t=(0,r.splitPath)(e);for(const e of exports.supported_coin)if(e.purpose.includes(t.purpose.value)&&e.cointype===t.coinType.value)return!0;return!1},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0}); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.deriveKey=exports.decodeXPUB=exports.toExtenededPublicKey=void 0;const e=require("./BIP32Path"),r=require("./bs58"),t=require("hash.js"),o=require("elliptic"),c=require("ow"),n=require("./utility"),u=require("groestl-hash-js"),i=null===n.Logger||void 0===n.Logger?void 0:n.Logger.child({id:"utility"}),a=new o.ec("secp256k1"),s=a.curve.n.constructor;exports.toExtenededPublicKey=function(r,t,o,u){var i;(0,c.default)(r,n.ow_bip32String),(0,c.default)(t,(0,n.ow_checkBufferLength)(4)),(0,c.default)(o,(0,n.ow_checkBufferLength)(32)),(0,c.default)(u,(0,n.ow_checkBufferLength)(33));const a=Buffer.allocUnsafe(78),s=(0,e.splitPath)(r);switch(s.purpose.value){case 44:a.writeUInt32BE(76067358,0);break;case 49:a.writeUInt32BE(77429938,0);break;case 84:a.writeUInt32BE(78792518,0);break;default:throw Error("unsupported purpose of path")}const f=s.pathNum;let p;switch(a.writeUInt8(f,4),(f>0?t:Buffer.alloc(4)).copy(a,5),f){case 1:p=s.purpose;break;case 2:p=s.coinType;break;case 3:p=s.accountId;break;case 4:p=s.change;break;case 5:p=s.addressIndex;break;default:throw Error("Invalid Path, only support 1 to 5 depth path")}const h=p.isHardened?p.value+e.HARDENED_OFFSET:null==p?void 0:p.value;return a.writeUInt32BE(h,9),o.copy(a,13),u.copy(a,45),17===(null===(i=s.coinType)||void 0===i?void 0:i.value)?l.encode(a):d.encode(a)},exports.decodeXPUB=function(e){let r,t;(0,c.default)(e,n.ow_xpubString);try{r=d.decode(e)}catch(t){null==i||i.warn(`The xpub is not Bitcoin compatible, try use Groestlcoin version:\n${e}`),r=l.decode(e)}switch(r.readUInt32BE(0)){case 76067358:t=44;break;case 77429938:t=49;break;case 78792518:t=84;break;default:throw Error(`unsupport prefix, got 0x${r.slice(0,4)}`)}const o=r.readUInt8(4),u=r.slice(5,9),a=r.slice(13,45);return{purpose:t,depth:o,publickey:r.slice(45),chaincode:a,fingerprint:u}},exports.deriveKey=function(e,r,t){(0,c.default)(e,(0,n.ow_checkBufferLength)(33)),(0,c.default)(r,(0,n.ow_checkBufferLength)(32)),(0,c.default)(t,c.default.array.ofType(c.default.number.uint8));let o={publickey:e,chaincode:r};for(const e of t)o=f(o.publickey,o.chaincode,e);return o};const d=new r.bs58Check((function(e){const r=(0,t.sha256)().update(e).digest();return Buffer.from((0,t.sha256)().update(r).digest())})),l=new r.bs58Check((function(e){return Buffer.from(u.groestl_2(e,1,1))}));function f(e,r,o){const c=Buffer.allocUnsafe(37);e.copy(c,0),c.writeUInt32BE(o,33);const n=(0,t.hmac)(t.sha512,r).update(c).digest(),u=Buffer.from(n),i=u.slice(0,32),d=u.slice(32);let l;try{const r=a.keyFromPublic(e),t=new s(i);if(t.cmp(a.curve.n)>=0)throw Error("tweak error");const o=r.getPublic().add(a.curve.g.mul(t));if(o.isInfinity())throw Error("point error");l=Buffer.from(o.encode("array",!0))}catch(t){return f(e,r,o+1)}return{publickey:l,chaincode:d}} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.deriveKey=exports.decodeXPUB=exports.toExtenededPublicKey=void 0;const e=require("./BIP32Path"),r=require("./bs58"),t=require("hash.js"),o=require("elliptic"),c=require("ow"),n=require("./utility"),u=require("groestl-hash-js"),a=null===n.Logger||void 0===n.Logger?void 0:n.Logger.child({id:"utility"}),i=new o.ec("secp256k1"),s=i.curve.n.constructor;exports.toExtenededPublicKey=function(r,t,o,u){var a;(0,c.default)(r,n.ow_bip32String),(0,c.default)(t,(0,n.ow_checkBufferLength)(4)),(0,c.default)(o,(0,n.ow_checkBufferLength)(32)),(0,c.default)(u,(0,n.ow_checkBufferLength)(33));const i=Buffer.allocUnsafe(78),s=(0,e.splitPath)(r);switch(s.purpose.value){case 44:case 86:i.writeUInt32BE(76067358,0);break;case 49:i.writeUInt32BE(77429938,0);break;case 84:i.writeUInt32BE(78792518,0);break;default:throw Error("unsupported purpose of path")}const f=s.pathNum;let p;switch(i.writeUInt8(f,4),(f>0?t:Buffer.alloc(4)).copy(i,5),f){case 1:p=s.purpose;break;case 2:p=s.coinType;break;case 3:p=s.accountId;break;case 4:p=s.change;break;case 5:p=s.addressIndex;break;default:throw Error("Invalid Path, only support 1 to 5 depth path")}const h=p.isHardened?p.value+e.HARDENED_OFFSET:null==p?void 0:p.value;return i.writeUInt32BE(h,9),o.copy(i,13),u.copy(i,45),17===(null===(a=s.coinType)||void 0===a?void 0:a.value)?d.encode(i):l.encode(i)},exports.decodeXPUB=function(e){let r,t;(0,c.default)(e,n.ow_xpubString);try{r=l.decode(e)}catch(t){null==a||a.warn(`The xpub is not Bitcoin compatible, try use Groestlcoin version:\n${e}`),r=d.decode(e)}switch(r.readUInt32BE(0)){case 76067358:t=44,null==a||a.warn("Please note that TapRoot type xpub using the same prefix, it cannot be considered here.");break;case 77429938:t=49;break;case 78792518:t=84;break;default:throw Error(`unsupport prefix, got 0x${r.slice(0,4)}`)}const o=r.readUInt8(4),u=r.slice(5,9),i=r.slice(13,45);return{purpose:t,depth:o,publickey:r.slice(45),chaincode:i,fingerprint:u}},exports.deriveKey=function(e,r,t){(0,c.default)(e,(0,n.ow_checkBufferLength)(33)),(0,c.default)(r,(0,n.ow_checkBufferLength)(32)),(0,c.default)(t,c.default.array.ofType(c.default.number.uint8));let o={publickey:e,chaincode:r};for(const e of t)o=f(o.publickey,o.chaincode,e);return o};const l=new r.bs58Check((function(e){const r=(0,t.sha256)().update(e).digest();return Buffer.from((0,t.sha256)().update(r).digest())})),d=new r.bs58Check((function(e){return Buffer.from(u.groestl_2(e,1,1))}));function f(e,r,o){const c=Buffer.allocUnsafe(37);e.copy(c,0),c.writeUInt32BE(o,33);const n=(0,t.hmac)(t.sha512,r).update(c).digest(),u=Buffer.from(n),a=u.slice(0,32),l=u.slice(32);let d;try{const r=i.keyFromPublic(e),t=new s(a);if(t.cmp(i.curve.n)>=0)throw Error("tweak error");const o=r.getPublic().add(i.curve.g.mul(t));if(o.isInfinity())throw Error("point error");d=Buffer.from(o.encode("array",!0))}catch(t){return f(e,r,o+1)}return{publickey:d,chaincode:l}} |
{ | ||
"name": "@secux/utility", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "SecuX Hardware Wallet internal tools for SDK", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
23573