New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@secux/utility

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/utility - npm Package Compare versions

Comparing version 3.0.9 to 3.0.10

17

lib/BIP32Path.d.ts

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -2,0 +19,0 @@ export { buildPathBuffer, decodePathBuffer, splitPath, HARDENED_OFFSET };

19

lib/BIP32Path.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.HARDENED_OFFSET=exports.splitPath=exports.decodePathBuffer=exports.buildPathBuffer=void 0;function e(e){const t=e.split("/"),r=t.length;if(r<2||r>6)throw Error("Invalid Path, only support 1 to 5 depth path");const a={};return a.pathNum=r-1,t.forEach(((e,t)=>{if(0===t)return;const r={},n=e.length>1&&"'"===e[e.length-1];switch(r.value=n?parseInt(e.slice(0,-1),10):parseInt(e,10),r.isHardened=n,r.depth=t,t){case 1:a.purpose=r;break;case 2:a.coinType=r;break;case 3:a.accountId=r;break;case 4:a.change=r;break;case 5:a.addressIndex=r}})),a}exports.HARDENED_OFFSET=2147483648,exports.buildPathBuffer=function(t,r){const a=e=>{if(e&&e.isHardened)return e.value+2147483648;if(e&&!e.isHardened)return e.value;throw Error("Build path error")},n=e(t);let o=r&&r>=1&&r<6?r:n.pathNum;const s=Buffer.alloc(4*o),{purpose:c,coinType:h,accountId:p,change:u,addressIndex:i}=n;for(let e=0;e<o;e++)switch(e){case 0:s.writeUInt32LE(a(c),4*e);break;case 1:s.writeUInt32LE(a(h),4*e);break;case 2:s.writeUInt32LE(a(p),4*e);break;case 3:s.writeUInt32LE(a(u),4*e);break;case 4:s.writeUInt32LE(a(i),4*e)}return{pathNum:o,pathBuffer:s}},exports.decodePathBuffer=function(e){if(e.length%4!=0)throw Error("ArgumentError: each element of path should be 4 bytes");if(e.length<=0||e.length>20)throw Error("ArgumentError: invalid Path, only support 1 to 5 depth path");let t="m";for(let r=0;r<e.length;r+=4){const a=e.readUInt32LE(r);t=a>=2147483648?`${t}/${a-2147483648}'`:`${t}/${a}`}return t},exports.splitPath=e;
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.HARDENED_OFFSET=exports.splitPath=exports.decodePathBuffer=exports.buildPathBuffer=void 0;function e(e){const t=e.split("/"),r=t.length;if(r<2||r>6)throw Error("Invalid Path, only support 1 to 5 depth path");const a={};return a.pathNum=r-1,t.forEach(((e,t)=>{if(0===t)return;const r={},n=e.length>1&&"'"===e[e.length-1];switch(r.value=n?parseInt(e.slice(0,-1),10):parseInt(e,10),r.isHardened=n,r.depth=t,t){case 1:a.purpose=r;break;case 2:a.coinType=r;break;case 3:a.accountId=r;break;case 4:a.change=r;break;case 5:a.addressIndex=r}})),a}exports.HARDENED_OFFSET=2147483648,exports.buildPathBuffer=function(t,r){const a=e=>{if(e&&e.isHardened)return e.value+2147483648;if(e&&!e.isHardened)return e.value;throw Error("Build path error")},n=e(t);let o=r&&r>=1&&r<6?r:n.pathNum;const s=Buffer.alloc(4*o),{purpose:c,coinType:h,accountId:p,change:u,addressIndex:i}=n;for(let e=0;e<o;e++)switch(e){case 0:s.writeUInt32LE(a(c),4*e);break;case 1:s.writeUInt32LE(a(h),4*e);break;case 2:s.writeUInt32LE(a(p),4*e);break;case 3:s.writeUInt32LE(a(u),4*e);break;case 4:s.writeUInt32LE(a(i),4*e)}return{pathNum:o,pathBuffer:s}},exports.decodePathBuffer=function(e){if(e.length%4!=0)throw Error("ArgumentError: each element of path should be 4 bytes");if(e.length<=0||e.length>20)throw Error("ArgumentError: invalid Path, only support 1 to 5 depth path");let t="m";for(let r=0;r<e.length;r+=4){const a=e.readUInt32LE(r);t=a>=2147483648?`${t}/${a-2147483648}'`:`${t}/${a}`}return t},exports.splitPath=e;

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -2,0 +19,0 @@ import * as bs58 from 'base-x';

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

"use strict";var e,t=this&&this.__classPrivateFieldSet||function(e,t,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 t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(e,r):s?s.value=r:t.set(e,r),r},r=this&&this.__classPrivateFieldGet||function(e,t,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?o:"a"===r?o.call(e):o?o.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.bs58Check=exports.Base58=void 0;const o=require("base-x");exports.Base58=o("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");exports.bs58Check=class{constructor(r){e.set(this,void 0),t(this,e,r,"f")}encode(t,o){const s=o?Buffer.concat([o,t]):t,a=r(this,e,"f").call(this,s).slice(0,4),i=Buffer.concat([s,a]);return exports.Base58.encode(i)}decode(t){return function(e,t){const r=e.slice(0,-4),o=e.slice(-4),s=t(r);if(o[0]^s[0]|o[1]^s[1]|o[2]^s[2]|o[3]^s[3])throw new Error("decode failed, Invalid data");return r}(exports.Base58.decode(t),r(this,e,"f"))}},e=new WeakMap;
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/var e,t=this&&this.__classPrivateFieldSet||function(e,t,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 t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?s.call(e,r):s?s.value=r:t.set(e,r),r},r=this&&this.__classPrivateFieldGet||function(e,t,r,o){if("a"===r&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?o:"a"===r?o.call(e):o?o.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.bs58Check=exports.Base58=void 0;const o=require("base-x");exports.Base58=o("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");exports.bs58Check=class{constructor(r){e.set(this,void 0),t(this,e,r,"f")}encode(t,o){const s=o?Buffer.concat([o,t]):t,a=r(this,e,"f").call(this,s).slice(0,4),i=Buffer.concat([s,a]);return exports.Base58.encode(i)}decode(t){return function(e,t){const r=e.slice(0,-4),o=e.slice(-4),s=t(r);if(o[0]^s[0]|o[1]^s[1]|o[2]^s[2]|o[3]^s[3])throw new Error("decode failed, Invalid data");return r}(exports.Base58.decode(t),r(this,e,"f"))}},e=new WeakMap;

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -2,0 +19,0 @@ export declare const ONESIGN_THRESHOLD = 4000;

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

"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={}));
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/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={}));

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
declare let __logger: any;

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

"use strict";let e;switch(process.env.LOGGER){case"winston":require("setimmediate");const r=require("winston");e=r.createLogger({transports:[new r.transports.Console({level:"development"===process.env.DISTRIBUTION?"debug":"warn",format:r.format.combine(r.format.colorize({all:!0}),r.format.printf((({level:e,message:r,id:t})=>`[${e}] {${t}} \n${r}`)))})]});break;case"react-native-logs":const t=require("react-native-logs"),n={severity:"development"===process.env.DISTRIBUTION?"debug":"warn",transport:t.consoleTransport,transportOptions:{colors:"ansi"},async:!0,printLevel:!0,printDate:!1,enabled:!0};e=t.logger.createLogger(n),e.child=r=>{const t=e.extend(r.id);return e.enable(r.id),t}}Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:e});
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/let e;switch(process.env.LOGGER){case"winston":require("setimmediate");const r=require("winston");e=r.createLogger({transports:[new r.transports.Console({level:"development"===process.env.DISTRIBUTION?"debug":"warn",format:r.format.combine(r.format.colorize({all:!0}),r.format.printf((({level:e,message:r,id:t})=>`[${e}] {${t}} \n${r}`)))})]});break;case"react-native-logs":const t=require("react-native-logs"),n={severity:"development"===process.env.DISTRIBUTION?"debug":"warn",transport:t.consoleTransport,transportOptions:{colors:"ansi"},async:!0,printLevel:!0,printDate:!1,enabled:!0};e=t.logger.createLogger(n),e.child=r=>{const t=e.extend(r.id);return e.enable(r.id),t}}Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:e});

@@ -0,3 +1,20 @@

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />
export declare function validate(pubkey: Buffer): boolean;
export declare function recidFromSignature(payload: Uint8Array, publicKey: Uint8Array, signature: Uint8Array): number;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.recidFromSignature=exports.validate=void 0;const e=require("elliptic"),r=require("bn.js");exports.validate=function(r){const n=new e.ec("secp256k1").keyFromPublic(r),{result:t,reason:c}=n.validate();return c&&console.warn(c),t},exports.recidFromSignature=function(n,t,c){const o=new e.ec("secp256k1"),i=o.curve.n,u=o.curve.g,s=o.curve.decodePoint(t),d=new r(c.slice(0,32)),l=new r(c.slice(32,64)),a=new r(n),m=l.invm(i),p=a.mul(m).umod(i),v=d.mul(m).umod(i),w=u.mulAdd(p,s,v),x=w.y.isOdd();return+(w.x.cmp(i)>=0)<<1|+x<<0};
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.recidFromSignature=exports.validate=void 0;const e=require("elliptic"),r=require("bn.js");exports.validate=function(r){const n=new e.ec("secp256k1").keyFromPublic(r),{result:t,reason:c}=n.validate();return c&&console.warn(c),t},exports.recidFromSignature=function(n,t,c){const o=new e.ec("secp256k1"),i=o.curve.n,u=o.curve.g,s=o.curve.decodePoint(t),d=new r(c.slice(0,32)),l=new r(c.slice(32,64)),a=new r(n),m=l.invm(i),p=a.mul(m).umod(i),v=d.mul(m).umod(i),w=u.mulAdd(p,s,v),x=w.y.isOdd();return+(w.x.cmp(i)>=0)<<1|+x<<0};

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -2,0 +19,0 @@ export declare class Signature {

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

"use strict";var e,t,r,i,F,s=this&&this.__classPrivateFieldSet||function(e,t,r,i,F){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!F)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!F:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?F.call(e,r):F?F.value=r:t.set(e,r),r},n=this&&this.__classPrivateFieldGet||function(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Signature=void 0;const o=require("bignumber.js");class a{constructor(e,F,n){t.set(this,void 0),r.set(this,void 0),i.set(this,void 0),s(this,t,e,"f"),s(this,r,F,"f"),s(this,i,n,"f")}static fromSignature(e){const t=e.slice(0,32),r=e.slice(32,64),i=e.slice(64,65);return new a(t,r,i)}toDER(){s(this,t,n(a,e,"m",F).call(a,n(this,t,"f")),"f"),s(this,r,n(a,e,"m",F).call(a,n(this,r,"f")),"f")}flipS(e=!0){const t=new o.BigNumber("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),F=new o.BigNumber("0x0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD036414");let s=new o.BigNumber(`0x${n(this,r,"f").toString("hex")}`);if(e&&s>F||!e&&s<=F){s=t.minus(s),n(this,r,"f").write(s.toString(16),"hex");let e=n(this,i,"f").readUInt8();e=1-e,n(this,i,"f").writeUInt8(e)}}get r(){return n(this,t,"f")}get s(){return n(this,r,"f")}get v(){return n(this,i,"f")}}exports.Signature=a,e=a,t=new WeakMap,r=new WeakMap,i=new WeakMap,F=function(e){const t=Buffer.alloc(1,0);let r=0;for(;0===e[r];)++r;return r===e.length?t:128&(e=e.slice(r))[0]?Buffer.concat([t,e],1+e.length):e};
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/var e,t,r,i,F,s=this&&this.__classPrivateFieldSet||function(e,t,r,i,F){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!F)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!F:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?F.call(e,r):F?F.value=r:t.set(e,r),r},n=this&&this.__classPrivateFieldGet||function(e,t,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(e):i?i.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Signature=void 0;const o=require("bignumber.js");class a{constructor(e,F,n){t.set(this,void 0),r.set(this,void 0),i.set(this,void 0),s(this,t,e,"f"),s(this,r,F,"f"),s(this,i,n,"f")}static fromSignature(e){const t=e.slice(0,32),r=e.slice(32,64),i=e.slice(64,65);return new a(t,r,i)}toDER(){s(this,t,n(a,e,"m",F).call(a,n(this,t,"f")),"f"),s(this,r,n(a,e,"m",F).call(a,n(this,r,"f")),"f")}flipS(e=!0){const t=new o.BigNumber("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),F=new o.BigNumber("0x0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD036414");let s=new o.BigNumber(`0x${n(this,r,"f").toString("hex")}`);if(e&&s>F||!e&&s<=F){s=t.minus(s),n(this,r,"f").write(s.toString(16),"hex");let e=n(this,i,"f").readUInt8();e=1-e,n(this,i,"f").writeUInt8(e)}}get r(){return n(this,t,"f")}get s(){return n(this,r,"f")}get v(){return n(this,i,"f")}}exports.Signature=a,e=a,t=new WeakMap,r=new WeakMap,i=new WeakMap,F=function(e){const t=Buffer.alloc(1,0);let r=0;for(;0===e[r];)++r;return r===e.length?t:128&(e=e.slice(r))[0]?Buffer.concat([t,e],1+e.length):e};

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -57,1 +74,2 @@ export { buildPathBuffer, decodePathBuffer, splitPath } from "./BIP32Path";

export declare function loadPlugin(plugin: Function, name: string): void;
export declare function checkFWVersion(type: string, restrict: string, current: string): void;

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

"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,49],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"},{purpose:[44],cointype:235,name:"fioprotocol",module:"SecuxFIO",npm:"@secux/app-fio"}]),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";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkFWVersion=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,49],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"},{purpose:[44],cointype:235,name:"fioprotocol",module:"SecuxFIO",npm:"@secux/app-fio"}]),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")}},exports.checkFWVersion=function(e,t,r){if(!t||!r)return;const n=t.split(".").map((e=>parseInt(e))),o=r.split(".").map((e=>parseInt(e)));for(let p=0;p<t.length;p++){const u=n[p],s=o[p];if(u<s)return;if(u>s)throw Error(`${e} firmware need update, version "${t}" needed, but got "${r}"`)}},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0});

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

/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />

@@ -2,0 +19,0 @@ /**

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

"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.owTool.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.owTool.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}}
"use strict";
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/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.owTool.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.owTool.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}}

2

package.json
{
"name": "@secux/utility",
"version": "3.0.9",
"version": "3.0.10",
"description": "SecuX Hardware Wallet internal tools for SDK",

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

Sorry, the diff of this file is not supported yet

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