@secux/utility
Advanced tools
Comparing version 3.0.6 to 3.0.7
/// <reference types="node" /> | ||
export declare const ONESIGN_THRESHOLD = 4000; | ||
export declare const MAX_HEAD_SIZE = 25; | ||
export declare const toCommunicationData: ((data: Buffer) => Buffer) | ((data: Buffer) => string); | ||
@@ -27,2 +29,3 @@ export declare function wrapResult(data: any): any; | ||
SUCCESS = 36864, | ||
USER_CANCEL = 36865, | ||
DATA_ERROR = 20481, | ||
@@ -29,0 +32,0 @@ CLA_ERROR = 20482, |
@@ -1,1 +0,1 @@ | ||
"use strict";var t,e,r,o,s=this&&this.__classPrivateFieldSet||function(t,e,r,o,s){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(t,r):s?s.value=r:e.set(t,r),r},a=this&&this.__classPrivateFieldGet||function(t,e,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?o:"a"===r?o.call(t):o?o.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.StatusCode=exports.ow_communicationData=exports.ow_base64String=exports.base64_regexp=exports.TransportStatusError=exports.to_L1_APDU=exports.getBuffer=exports.toAPDUResponse=exports.Send=exports.wrapResult=exports.toCommunicationData=void 0;const n=require("ow"),i=require("./utility"),u=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"protocol"}),f="service"===process.env.SECUX_PLATFROM;function c(t){return"string"==typeof t?Buffer.from(t,"base64"):t}exports.toCommunicationData=f?t=>t.toString("base64"):t=>t,exports.wrapResult=function(t){return f?"object"!=typeof t?t:JSON.stringify(t):t},exports.Send=function(t,e,r=0,o=0,s=Buffer.alloc(0)){const a=Buffer.alloc(2);a.writeUInt16LE(s.length,0);const n=Buffer.concat([Buffer.from([t,e,r,o]),a,s,Buffer.alloc(2),Buffer.from([0,0,0,0])]);return null==u||u.debug(`send data: ${n.toString("hex")}`),(0,exports.toCommunicationData)(n)},exports.toAPDUResponse=function(t){const e=t.readUInt16LE(0),r=t.readUInt16BE(2+e);if(e+6>t.length)throw null==u||u.warn(`Received data missing error: ${t.toString("hex")}`),Error(`Received data error: ${t.toString("hex")}`);return{data:t.slice(2,2+e),dataLength:e,status:r}},exports.getBuffer=c;const p=Buffer.from([248,2,0,0]);exports.to_L1_APDU=function(t){const e=c(t),r=Buffer.concat([p,e]);return(0,exports.toCommunicationData)(r)};class d extends Error{constructor(n){super(),t.set(this,"TransportStatusError"),e.set(this,void 0),r.set(this,void 0),o.set(this,void 0),s(this,o,n in l?l[n]:"UNKNOWN_ERROR","f"),s(this,r,n,"f"),s(this,e,`[SecuX device] ${a(this,o,"f")} (0x${n.toString(16)})`,"f")}get name(){return a(this,t,"f")}get message(){return a(this,e,"f")}get statusCode(){return a(this,r,"f")}get statusText(){return a(this,o,"f")}}var l;exports.TransportStatusError=d,t=new WeakMap,e=new WeakMap,r=new WeakMap,o=new WeakMap,exports.base64_regexp=/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/,exports.ow_base64String=n.default.string.matches(exports.base64_regexp),exports.ow_communicationData=n.default.any(exports.ow_base64String,n.default.buffer),function(t){t[t.SUCCESS=36864]="SUCCESS",t[t.DATA_ERROR=20481]="DATA_ERROR",t[t.CLA_ERROR=20482]="CLA_ERROR",t[t.INS_ERROR=20483]="INS_ERROR"}(l=exports.StatusCode||(exports.StatusCode={})); | ||
"use strict";var t,e,r,o,s=this&&this.__classPrivateFieldSet||function(t,e,r,o,s){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(t,r):s?s.value=r:e.set(t,r),r},a=this&&this.__classPrivateFieldGet||function(t,e,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!o:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?o:"a"===r?o.call(t):o?o.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.StatusCode=exports.ow_communicationData=exports.ow_base64String=exports.base64_regexp=exports.TransportStatusError=exports.to_L1_APDU=exports.getBuffer=exports.toAPDUResponse=exports.Send=exports.wrapResult=exports.toCommunicationData=exports.MAX_HEAD_SIZE=exports.ONESIGN_THRESHOLD=void 0;const n=require("ow"),i=require("./utility"),u=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"protocol"}),f="service"===process.env.SECUX_PLATFROM;function c(t){return"string"==typeof t?Buffer.from(t,"base64"):t}exports.ONESIGN_THRESHOLD=4e3,exports.MAX_HEAD_SIZE=25,exports.toCommunicationData=f?t=>t.toString("base64"):t=>t,exports.wrapResult=function(t){return f?"object"!=typeof t?t:JSON.stringify(t):t},exports.Send=function(t,e,r=0,o=0,s=Buffer.alloc(0)){const a=Buffer.alloc(2);a.writeUInt16LE(s.length,0);const n=Buffer.concat([Buffer.from([t,e,r,o]),a,s,Buffer.alloc(2),Buffer.from([0,0,0,0])]);return null==u||u.debug(`send data: ${n.toString("hex")}`),(0,exports.toCommunicationData)(n)},exports.toAPDUResponse=function(t){const e=t.readUInt16LE(0),r=t.readUInt16BE(2+e);if(e+6>t.length)throw null==u||u.warn(`Received data missing error: ${t.toString("hex")}`),Error(`Received data error: ${t.toString("hex")}`);return{data:t.slice(2,2+e),dataLength:e,status:r}},exports.getBuffer=c;const p=Buffer.from([248,2,0,0]);exports.to_L1_APDU=function(t){const e=c(t),r=Buffer.concat([p,e]);return(0,exports.toCommunicationData)(r)};class d extends Error{constructor(n){super(),t.set(this,"TransportStatusError"),e.set(this,void 0),r.set(this,void 0),o.set(this,void 0),s(this,o,n in l?l[n]:"UNKNOWN_ERROR","f"),s(this,r,n,"f"),s(this,e,`[SecuX device] ${a(this,o,"f")} (0x${n.toString(16)})`,"f")}get name(){return a(this,t,"f")}get message(){return a(this,e,"f")}get statusCode(){return a(this,r,"f")}get statusText(){return a(this,o,"f")}}var l;exports.TransportStatusError=d,t=new WeakMap,e=new WeakMap,r=new WeakMap,o=new WeakMap,exports.base64_regexp=/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/,exports.ow_base64String=n.default.string.matches(exports.base64_regexp),exports.ow_communicationData=n.default.any(exports.ow_base64String,n.default.buffer),function(t){t[t.SUCCESS=36864]="SUCCESS",t[t.USER_CANCEL=36865]="USER_CANCEL",t[t.DATA_ERROR=20481]="DATA_ERROR",t[t.CLA_ERROR=20482]="CLA_ERROR",t[t.INS_ERROR=20483]="INS_ERROR"}(l=exports.StatusCode||(exports.StatusCode={})); |
@@ -14,2 +14,3 @@ /// <reference types="node" /> | ||
static get base58String(): import("ow").StringPredicate; | ||
static get base64String(): import("ow").StringPredicate; | ||
} | ||
@@ -16,0 +17,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadPlugin=exports.isSupportedCoin=exports.supported_coin=exports.BigIntToBuffer=exports.ow_checkBufferLength=exports.ow_accountPath=exports.ow_strictPath=exports.ow_base58String=exports.ow_xpubString=exports.ow_numberString=exports.ow_hashString=exports.ow_prefixedhexString=exports.ow_hexString=exports.ow_bip32String=exports.owTool=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"),n=require("./bs58");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 p=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return p.toExtenededPublicKey}});var u=require("./signature");Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return u.Signature}}),exports.Logger=process.env.SECUX_LOGGER;const s=null===exports.Logger||void 0===exports.Logger?void 0:exports.Logger.child({id:"utility"});function i(e){let t="";return e.map((e=>t+=`${e.toString()}|`)),t=`(${t.substr(0,t.length-1)})`,t}exports.owTool=class{static get bip32String(){return t.default.string.matches(/^m(\/\d+')+(\/\d+)*$/)}static get hexString(){return t.default.string.matches(/^[0-9A-F-a-f]+$/)}static get prefixedhexString(){return t.default.string.matches(/^0x[0-9A-F-a-f]+$/)}static get hashString(){return t.default.string.matches(/^[0-9A-Z-a-z]+$/)}static get numberString(){return t.default.string.matches(/^[0-9]+$/)}static get xpubString(){return t.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/)}static get base58String(){return t.default.string.is((e=>!!n.Base58.decodeUnsafe(e)))}},exports.ow_bip32String=t.default.string.matches(/^m(\/\d+')+(\/\d+)*$/),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_base58String=t.default.string.is((e=>!!n.Base58.decodeUnsafe(e))),exports.ow_strictPath=function(e,r){const n=i("number"==typeof e?[e]:e);if(r){const e=i("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${n}'/[0-9]+'/[0-9]+/[0-9]+$`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${n}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(e,r){const n=i("number"==typeof e?[e]:e);if(r){const e=i("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${n}'/[0-9]+'`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${n}'/[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,n=!0){let o="";"number"==typeof t?o=t.toString(16):"string"==typeof t&&(o=new e.BigNumber(t).toString(16)),o.length%2!=0&&(o="0"+o);const p=Buffer.from(o,"hex");if(p.length>r)throw Error("value is too large");const u=Buffer.concat([Buffer.alloc(r-p.length),p]);return n?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"},{purpose:[44],cointype:501,name:"solana",module:"SecuxSOL",npm:"@secux/app-sol"}]),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},exports.loadPlugin=function(e,t){try{const{ITransport:r}=require("@secux/transport");void 0===r[t]&&Object.defineProperty(r,t,{enumerable:!0,configurable:!1,writable:!1,value:e})}catch(e){null==s||s.debug("The package @secux/transport is not at environment, plugin loading skipped")}},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.loadPlugin=exports.isSupportedCoin=exports.supported_coin=exports.BigIntToBuffer=exports.ow_checkBufferLength=exports.ow_accountPath=exports.ow_strictPath=exports.ow_base58String=exports.ow_xpubString=exports.ow_numberString=exports.ow_hashString=exports.ow_prefixedhexString=exports.ow_hexString=exports.ow_bip32String=exports.owTool=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"),n=require("./bs58");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 p=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return p.toExtenededPublicKey}});var u=require("./signature");Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return u.Signature}}),exports.Logger=process.env.SECUX_LOGGER;const s=null===exports.Logger||void 0===exports.Logger?void 0:exports.Logger.child({id:"utility"});function i(e){let t="";return e.map((e=>t+=`${e.toString()}|`)),t=`(${t.substring(0,t.length-1)})`,t}exports.owTool=class{static get bip32String(){return t.default.string.matches(/^m(\/\d+')+(\/\d+)*$/)}static get hexString(){return t.default.string.matches(/^[0-9A-F-a-f]+$/)}static get prefixedhexString(){return t.default.string.matches(/^0x[0-9A-F-a-f]+$/)}static get hashString(){return t.default.string.matches(/^[0-9A-Z-a-z]+$/)}static get numberString(){return t.default.string.matches(/^[0-9]+$/)}static get xpubString(){return t.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/)}static get base58String(){return t.default.string.is((e=>!!n.Base58.decodeUnsafe(e)))}static get base64String(){return t.default.string.matches(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/)}},exports.ow_bip32String=t.default.string.matches(/^m(\/\d+')+(\/\d+)*$/),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_base58String=t.default.string.is((e=>!!n.Base58.decodeUnsafe(e))),exports.ow_strictPath=function(e,r){const n=i("number"==typeof e?[e]:e);if(r){const e=i("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${n}'/[0-9]+'/[0-9]+/[0-9]+$`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${n}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(e,r){const n=i("number"==typeof e?[e]:e);if(r){const e=i("number"==typeof r?[r]:r);return t.default.string.matches(new RegExp(`^m/${e}'/${n}'/[0-9]+'`))}return t.default.string.matches(new RegExp(`^m/[0-9]+'/${n}'/[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,n=!0){let o="";"number"==typeof t?o=t.toString(16):"string"==typeof t&&(o=new e.BigNumber(t).toString(16)),o.length%2!=0&&(o="0"+o);const p=Buffer.from(o,"hex");if(p.length>r)throw Error("value is too large");const u=Buffer.concat([Buffer.alloc(r-p.length),p]);return n?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"},{purpose:[44],cointype:501,name:"solana",module:"SecuxSOL",npm:"@secux/app-sol"},{purpose:[44],cointype:330,name:"terra",module:"SecuxLUNA",npm:"@secux/app-luna"}]),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},exports.loadPlugin=function(e,t){try{const{ITransport:r}=require("@secux/transport");void 0===r[t]&&Object.defineProperty(r,t,{enumerable:!0,configurable:!1,writable:!1,value:e})}catch(e){null==s||s.debug("The package @secux/transport is not at environment, plugin loading skipped")}},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0}); |
{ | ||
"name": "@secux/utility", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"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
26439
154