@secux/utility
Advanced tools
Comparing version 3.0.14 to 3.0.15
@@ -27,3 +27,3 @@ /*! | ||
declare function splitPath(path: string): pathObjectType; | ||
declare type pathLevelType = { | ||
type pathLevelType = { | ||
value: number; | ||
@@ -33,3 +33,3 @@ isHardened: boolean; | ||
}; | ||
declare type pathObjectType = { | ||
type pathObjectType = { | ||
pathNum: number; | ||
@@ -36,0 +36,0 @@ purpose?: pathLevelType; |
@@ -18,2 +18,2 @@ "use strict"; | ||
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; | ||
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.HARDENED_OFFSET=exports.splitPath=exports.decodePathBuffer=exports.buildPathBuffer=void 0;function splitPath(path){const elements=path.split("/"),pathLen=elements.length;if(pathLen<2||pathLen>6)throw Error("Invalid Path, only support 1 to 5 depth path");const pathProps={};return pathProps.pathNum=pathLen-1,elements.forEach(((element,index)=>{if(0===index)return;const props={},isHardened=element.length>1&&"'"===element[element.length-1];switch(props.value=isHardened?parseInt(element.slice(0,-1),10):parseInt(element,10),props.isHardened=isHardened,props.depth=index,index){case 1:pathProps.purpose=props;break;case 2:pathProps.coinType=props;break;case 3:pathProps.accountId=props;break;case 4:pathProps.change=props;break;case 5:pathProps.addressIndex=props}})),pathProps}exports.HARDENED_OFFSET=2147483648,exports.buildPathBuffer=function(path,num){const getHardenedValue=pathLevel=>{if(pathLevel&&pathLevel.isHardened)return pathLevel.value+2147483648;if(pathLevel&&!pathLevel.isHardened)return pathLevel.value;throw Error("Build path error")},pathProps=splitPath(path);let pathNum=num&&num>=1&&num<6?num:pathProps.pathNum;const buf=Buffer.alloc(4*pathNum),{purpose,coinType,accountId,change,addressIndex}=pathProps;for(let i=0;i<pathNum;i++)switch(i){case 0:buf.writeUInt32LE(getHardenedValue(purpose),4*i);break;case 1:buf.writeUInt32LE(getHardenedValue(coinType),4*i);break;case 2:buf.writeUInt32LE(getHardenedValue(accountId),4*i);break;case 3:buf.writeUInt32LE(getHardenedValue(change),4*i);break;case 4:buf.writeUInt32LE(getHardenedValue(addressIndex),4*i)}return{pathNum,pathBuffer:buf}},exports.decodePathBuffer=function(data){if(data.length%4!=0)throw Error("ArgumentError: each element of path should be 4 bytes");if(data.length<=0||data.length>20)throw Error("ArgumentError: invalid Path, only support 1 to 5 depth path");let path="m";for(let i=0;i<data.length;i+=4){const e=data.readUInt32LE(i);path=e>=2147483648?`${path}/${e-2147483648}'`:`${path}/${e}`}return path},exports.splitPath=splitPath; |
@@ -21,3 +21,3 @@ /*! | ||
export declare const Base58: bs58.BaseConverter; | ||
export declare type HashFunc = (data: Buffer) => Buffer; | ||
export type HashFunc = (data: Buffer) => Buffer; | ||
export declare class bs58Check { | ||
@@ -24,0 +24,0 @@ #private; |
@@ -18,2 +18,2 @@ "use strict"; | ||
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; | ||
*/var _bs58Check_hash,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.bs58Check=exports.Base58=void 0;const bs58=require("base-x");exports.Base58=bs58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");exports.bs58Check=class{constructor(hash){_bs58Check_hash.set(this,void 0),__classPrivateFieldSet(this,_bs58Check_hash,hash,"f")}encode(payload,prefix){const data=prefix?Buffer.concat([prefix,payload]):payload,checksum=__classPrivateFieldGet(this,_bs58Check_hash,"f").call(this,data).slice(0,4),dataToEncode=Buffer.concat([data,checksum]);return exports.Base58.encode(dataToEncode)}decode(address){return function(data,check){const payload=data.slice(0,-4),checksum=data.slice(-4),comparedChecksum=check(payload);if(checksum[0]^comparedChecksum[0]|checksum[1]^comparedChecksum[1]|checksum[2]^comparedChecksum[2]|checksum[3]^comparedChecksum[3])throw new Error("decode failed, Invalid data");return payload}(exports.Base58.decode(address),__classPrivateFieldGet(this,_bs58Check_hash,"f"))}},_bs58Check_hash=new WeakMap; |
@@ -40,6 +40,8 @@ /*! | ||
} | ||
export declare type base64String = string; | ||
export declare type communicationData = base64String | Buffer; | ||
export type base64String = string; | ||
export type communicationData = base64String | Buffer; | ||
/** | ||
* @deprecated | ||
*/ | ||
export declare const base64_regexp: RegExp; | ||
export declare const ow_base64String: import("ow").StringPredicate; | ||
export declare const ow_communicationData: import("ow").AnyPredicate<string | Buffer>; | ||
@@ -46,0 +48,0 @@ export declare enum StatusCode { |
@@ -18,2 +18,2 @@ "use strict"; | ||
limitations under the License. | ||
*/var t,e,r,o,s,a=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},n=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.StatusCodeV2=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 i=require("ow"),u=require("./utility"),f=null===u.Logger||void 0===u.Logger?void 0:u.Logger.child({id:"protocol"}),p="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=p?t=>t.toString("base64"):t=>t,exports.wrapResult=function(t){return p?"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==f||f.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==f||f.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 E=Buffer.from([248,2,0,0]);exports.to_L1_APDU=function(t){const e=c(t),r=Buffer.concat([E,e]);return(0,exports.toCommunicationData)(r)};class _ extends Error{constructor(i,u=1){var f;if(super(),t.set(this,"TransportStatusError"),e.set(this,void 0),r.set(this,void 0),o.set(this,void 0),s.set(this,void 0),a(this,s,u,"f"),2===u)a(this,o,d[i],"f");else a(this,o,R[i],"f");a(this,o,null!==(f=n(this,o,"f"))&&void 0!==f?f:"UNKNOWN_ERROR","f"),a(this,r,i,"f"),a(this,e,`[SecuX device] ${n(this,o,"f")} (0x${i.toString(16)})`,"f")}get name(){return n(this,t,"f")}get message(){return n(this,e,"f")}get statusCode(){return n(this,r,"f")}get statusText(){return n(this,o,"f")}get version(){return n(this,s,"f")}}var R,d;exports.TransportStatusError=_,t=new WeakMap,e=new WeakMap,r=new WeakMap,o=new WeakMap,s=new WeakMap,exports.base64_regexp=/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/,exports.ow_base64String=i.default.string.matches(exports.base64_regexp),exports.ow_communicationData=i.default.any(exports.ow_base64String,i.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"}(R=exports.StatusCode||(exports.StatusCode={})),function(t){t[t.OK=0]="OK",t[t.NO_LEADING_PACKET=1]="NO_LEADING_PACKET",t[t.COMMAND_OVERLAY=2]="COMMAND_OVERLAY",t[t.INVALID_COMMAND=3]="INVALID_COMMAND",t[t.INCORRENT_PARAMETER_SIZE=4]="INCORRENT_PARAMETER_SIZE",t[t.INVALID_PARAMETER_VALUE=5]="INVALID_PARAMETER_VALUE",t[t.NOT_FOUND=6]="NOT_FOUND",t[t.ALREADY_EXIST=7]="ALREADY_EXIST",t[t.IO_ERROR=8]="IO_ERROR",t[t.NOT_SUPPORT=9]="NOT_SUPPORT"}(d=exports.StatusCodeV2||(exports.StatusCodeV2={})); | ||
*/var _TransportStatusError_name,_TransportStatusError_message,_TransportStatusError_statusCode,_TransportStatusError_statusText,_TransportStatusError_version,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.StatusCodeV2=exports.StatusCode=exports.ow_communicationData=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 ow_1=require("ow"),utility_1=require("./utility"),logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"protocol"}),SERVICE="service"===process.env.SECUX_PLATFROM;function getBuffer(data){return"string"==typeof data?Buffer.from(data,"base64"):data}exports.ONESIGN_THRESHOLD=4e3,exports.MAX_HEAD_SIZE=25,exports.toCommunicationData=SERVICE?data=>data.toString("base64"):data=>data,exports.wrapResult=function(data){return SERVICE?"object"!=typeof data?data:JSON.stringify(data):data},exports.Send=function(cla,ins,p1=0,p2=0,data=Buffer.alloc(0)){const dataLengthBuffer=Buffer.alloc(2);dataLengthBuffer.writeUInt16LE(data.length,0);const buf=Buffer.concat([Buffer.from([cla,ins,p1,p2]),dataLengthBuffer,data,Buffer.alloc(2),Buffer.from([0,0,0,0])]);return null==logger||logger.debug(`send data: ${buf.toString("hex")}`),(0,exports.toCommunicationData)(buf)},exports.toAPDUResponse=function(rsp){const dataLength=rsp.readUInt16LE(0),status=rsp.readUInt16BE(2+dataLength);if(dataLength+6>rsp.length)throw null==logger||logger.warn(`Received data missing error: ${rsp.toString("hex")}`),Error(`Received data error: ${rsp.toString("hex")}`);return{data:rsp.slice(2,2+dataLength),dataLength,status}},exports.getBuffer=getBuffer;const APDU_L1_PREFIX=Buffer.from([248,2,0,0]);exports.to_L1_APDU=function(data){const buf=getBuffer(data),apdu_L1=Buffer.concat([APDU_L1_PREFIX,buf]);return(0,exports.toCommunicationData)(apdu_L1)};class TransportStatusError extends Error{constructor(code,version=1){var _a;if(super(),_TransportStatusError_name.set(this,"TransportStatusError"),_TransportStatusError_message.set(this,void 0),_TransportStatusError_statusCode.set(this,void 0),_TransportStatusError_statusText.set(this,void 0),_TransportStatusError_version.set(this,void 0),__classPrivateFieldSet(this,_TransportStatusError_version,version,"f"),2===version)__classPrivateFieldSet(this,_TransportStatusError_statusText,StatusCodeV2[code],"f");else __classPrivateFieldSet(this,_TransportStatusError_statusText,StatusCode[code],"f");__classPrivateFieldSet(this,_TransportStatusError_statusText,null!==(_a=__classPrivateFieldGet(this,_TransportStatusError_statusText,"f"))&&void 0!==_a?_a:"UNKNOWN_ERROR","f"),__classPrivateFieldSet(this,_TransportStatusError_statusCode,code,"f"),__classPrivateFieldSet(this,_TransportStatusError_message,`[SecuX device] ${__classPrivateFieldGet(this,_TransportStatusError_statusText,"f")} (0x${code.toString(16)})`,"f")}get name(){return __classPrivateFieldGet(this,_TransportStatusError_name,"f")}get message(){return __classPrivateFieldGet(this,_TransportStatusError_message,"f")}get statusCode(){return __classPrivateFieldGet(this,_TransportStatusError_statusCode,"f")}get statusText(){return __classPrivateFieldGet(this,_TransportStatusError_statusText,"f")}get version(){return __classPrivateFieldGet(this,_TransportStatusError_version,"f")}}var StatusCode,StatusCodeV2;exports.TransportStatusError=TransportStatusError,_TransportStatusError_name=new WeakMap,_TransportStatusError_message=new WeakMap,_TransportStatusError_statusCode=new WeakMap,_TransportStatusError_statusText=new WeakMap,_TransportStatusError_version=new WeakMap,exports.base64_regexp=/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/,exports.ow_communicationData=ow_1.default.any(utility_1.owTool.base64String,ow_1.default.buffer),function(StatusCode){StatusCode[StatusCode.SUCCESS=36864]="SUCCESS",StatusCode[StatusCode.USER_CANCEL=36865]="USER_CANCEL",StatusCode[StatusCode.DATA_ERROR=20481]="DATA_ERROR",StatusCode[StatusCode.CLA_ERROR=20482]="CLA_ERROR",StatusCode[StatusCode.INS_ERROR=20483]="INS_ERROR"}(StatusCode=exports.StatusCode||(exports.StatusCode={})),function(StatusCodeV2){StatusCodeV2[StatusCodeV2.OK=0]="OK",StatusCodeV2[StatusCodeV2.NO_LEADING_PACKET=1]="NO_LEADING_PACKET",StatusCodeV2[StatusCodeV2.COMMAND_OVERLAY=2]="COMMAND_OVERLAY",StatusCodeV2[StatusCodeV2.INVALID_COMMAND=3]="INVALID_COMMAND",StatusCodeV2[StatusCodeV2.INCORRENT_PARAMETER_SIZE=4]="INCORRENT_PARAMETER_SIZE",StatusCodeV2[StatusCodeV2.INVALID_PARAMETER_VALUE=5]="INVALID_PARAMETER_VALUE",StatusCodeV2[StatusCodeV2.NOT_FOUND=6]="NOT_FOUND",StatusCodeV2[StatusCodeV2.ALREADY_EXIST=7]="ALREADY_EXIST",StatusCodeV2[StatusCodeV2.IO_ERROR=8]="IO_ERROR",StatusCodeV2[StatusCodeV2.NOT_SUPPORT=9]="NOT_SUPPORT"}(StatusCodeV2=exports.StatusCodeV2||(exports.StatusCodeV2={})); |
@@ -18,2 +18,2 @@ "use strict"; | ||
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}); | ||
*/let __logger;switch(process.env.LOGGER){case"winston":require("setimmediate");const winston=require("winston");__logger=winston.createLogger({transports:[new winston.transports.Console({level:"development"===process.env.DISTRIBUTION?"debug":"warn",format:winston.format.combine(winston.format.colorize({all:!0}),winston.format.printf((({level,message,id})=>`[${level}] {${id}} \n${message}`)))})]});break;case"react-native-logs":const rnLogs=require("react-native-logs"),config={severity:"development"===process.env.DISTRIBUTION?"debug":"warn",transport:rnLogs.consoleTransport,transportOptions:{colors:"ansi"},async:!0,printLevel:!0,printDate:!1,enabled:!0};__logger=rnLogs.logger.createLogger(config),__logger.child=arg=>{const logger=__logger.extend(arg.id);return __logger.enable(arg.id),logger}}Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:__logger}); |
@@ -18,2 +18,2 @@ "use strict"; | ||
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}; | ||
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.recidFromSignature=exports.validate=void 0;const elliptic_1=require("elliptic"),BN=require("bn.js");exports.validate=function(pubkey){const key=new elliptic_1.ec("secp256k1").keyFromPublic(pubkey),{result,reason}=key.validate();return reason&&console.warn(reason),result},exports.recidFromSignature=function(payload,publicKey,signature){const secp256k1=new elliptic_1.ec("secp256k1"),n=secp256k1.curve.n,G=secp256k1.curve.g,Q=secp256k1.curve.decodePoint(publicKey),r=new BN(signature.slice(0,32)),s=new BN(signature.slice(32,64)),e=new BN(payload),sInv=s.invm(n),u1=e.mul(sInv).umod(n),u2=r.mul(sInv).umod(n),R=G.mulAdd(u1,Q,u2),isOddY=R.y.isOdd();return+(R.x.cmp(n)>=0)<<1|+isOddY<<0}; |
@@ -18,2 +18,2 @@ "use strict"; | ||
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}; | ||
*/var _a,_Signature_r,_Signature_s,_Signature_v,_Signature_toDER,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Signature=void 0;const bignumber_js_1=require("bignumber.js");class Signature{constructor(r,s,v){_Signature_r.set(this,void 0),_Signature_s.set(this,void 0),_Signature_v.set(this,void 0),__classPrivateFieldSet(this,_Signature_r,r,"f"),__classPrivateFieldSet(this,_Signature_s,s,"f"),__classPrivateFieldSet(this,_Signature_v,v,"f")}static fromSignature(sig){const rBuffer=sig.slice(0,32),sBuffer=sig.slice(32,64),vBuffer=sig.slice(64,65);return new Signature(rBuffer,sBuffer,vBuffer)}toDER(){__classPrivateFieldSet(this,_Signature_r,__classPrivateFieldGet(Signature,_a,"m",_Signature_toDER).call(Signature,__classPrivateFieldGet(this,_Signature_r,"f")),"f"),__classPrivateFieldSet(this,_Signature_s,__classPrivateFieldGet(Signature,_a,"m",_Signature_toDER).call(Signature,__classPrivateFieldGet(this,_Signature_s,"f")),"f")}flipS(isLowerHalf=!0){const SECP256K1N=new bignumber_js_1.BigNumber("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),SECP256K1N_half=new bignumber_js_1.BigNumber("0x0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD036414");let s=new bignumber_js_1.BigNumber(`0x${__classPrivateFieldGet(this,_Signature_s,"f").toString("hex")}`);if(isLowerHalf&&s>SECP256K1N_half||!isLowerHalf&&s<=SECP256K1N_half){s=SECP256K1N.minus(s),__classPrivateFieldGet(this,_Signature_s,"f").write(s.toString(16),"hex");let v=__classPrivateFieldGet(this,_Signature_v,"f").readUInt8();v=1-v,__classPrivateFieldGet(this,_Signature_v,"f").writeUInt8(v)}}get r(){return __classPrivateFieldGet(this,_Signature_r,"f")}get s(){return __classPrivateFieldGet(this,_Signature_s,"f")}get v(){return __classPrivateFieldGet(this,_Signature_v,"f")}}exports.Signature=Signature,_a=Signature,_Signature_r=new WeakMap,_Signature_s=new WeakMap,_Signature_v=new WeakMap,_Signature_toDER=function(x){const ZERO=Buffer.alloc(1,0);let i=0;for(;0===x[i];)++i;return i===x.length?ZERO:128&(x=x.slice(i))[0]?Buffer.concat([ZERO,x],1+x.length):x}; |
@@ -18,2 +18,2 @@ "use strict"; | ||
limitations under the License. | ||
*/var e,t,r,n=this&&this.__classPrivateFieldSet||function(e,t,r,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,r):o?o.value=r:t.set(e,r),r},o=this&&this.__classPrivateFieldGet||function(e,t,r,n){if("a"===r&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?n:"a"===r?n.call(e):n?n.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkFWVersion=exports.FirmwareError=exports.FirmwareType=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 s=require("bignumber.js"),i=require("ow"),p=require("./BIP32Path"),u=require("./bs58");var a=require("./BIP32Path");Object.defineProperty(exports,"buildPathBuffer",{enumerable:!0,get:function(){return a.buildPathBuffer}}),Object.defineProperty(exports,"decodePathBuffer",{enumerable:!0,get:function(){return a.decodePathBuffer}}),Object.defineProperty(exports,"splitPath",{enumerable:!0,get:function(){return a.splitPath}});var c=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return c.toExtenededPublicKey}});var l=require("./signature");Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return l.Signature}}),exports.Logger=process.env.SECUX_LOGGER;const f=null===exports.Logger||void 0===exports.Logger?void 0:exports.Logger.child({id:"utility"});var d;exports.owTool=class{static get bip32String(){return i.default.string.matches(/^m(\/\d+')+(\/\d+)*$/)}static get hexString(){return i.default.string.matches(/^[0-9A-F-a-f]+$/)}static get prefixedhexString(){return i.default.string.matches(/^0x[0-9A-F-a-f]+$/)}static get hashString(){return i.default.string.matches(/^[0-9A-Z-a-z]+$/)}static get numberString(){return i.default.string.matches(/^[0-9]+$/)}static get xpubString(){return i.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/)}static get base58String(){return i.default.string.is((e=>!!u.Base58.decodeUnsafe(e)))}static get base64String(){return i.default.string.matches(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/)}},exports.ow_bip32String=i.default.string.matches(/^m(\/\d+')+(\/\d+)*$/),exports.ow_hexString=i.default.string.matches(/^[0-9A-F-a-f]+$/),exports.ow_prefixedhexString=i.default.string.matches(/^0x[0-9A-F-a-f]+$/),exports.ow_hashString=i.default.string.matches(/^[0-9A-Z-a-z]+$/),exports.ow_numberString=i.default.string.matches(/^[0-9]+$/),exports.ow_xpubString=i.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/),exports.ow_base58String=i.default.string.is((e=>!!u.Base58.decodeUnsafe(e))),exports.ow_strictPath=function(e,t){const r=x("number"==typeof e?[e]:e);if(t){const e=x("number"==typeof t?[t]:t);return i.default.string.matches(new RegExp(`^m/${e}'/${r}'/[0-9]+'/[0-9]+/[0-9]+$`))}return i.default.string.matches(new RegExp(`^m/[0-9]+'/${r}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(e,t){const r=x("number"==typeof e?[e]:e);if(t){const e=x("number"==typeof t?[t]:t);return i.default.string.matches(new RegExp(`^m/${e}'/${r}'/[0-9]+'`))}return i.default.string.matches(new RegExp(`^m/[0-9]+'/${r}'/[0-9]+'`))},exports.ow_checkBufferLength=function(e){return i.default.buffer.validate((t=>({validator:t.length===e,message:r=>`ArgumentError: Expected length of ${r} is ${e}, got ${t.length}`})))},exports.BigIntToBuffer=function(e,t,r=!0){let n="";"number"==typeof e?n=e.toString(16):"string"==typeof e&&(n=new s.BigNumber(e).toString(16)),n.length%2!=0&&(n="0"+n);const o=Buffer.from(n,"hex");if(o.length>t)throw Error("value is too large");const i=Buffer.concat([Buffer.alloc(t-o.length),o]);return r?i.reverse():i},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,p.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==f||f.debug("The package @secux/transport is not at environment, plugin loading skipped")}},function(e){e.mcu="mcu",e.se="se"}(d=exports.FirmwareType||(exports.FirmwareType={}));class m extends Error{constructor(s,i,p){super(),e.set(this,void 0),t.set(this,void 0),r.set(this,void 0),n(this,e,d[s],"f"),n(this,r,i,"f"),n(this,t,p,"f"),this.message=`${o(this,e,"f")} firmware need update, version "${i}" needed, but got "${p}"`}get type(){return o(this,e,"f")}get currentVersion(){return o(this,t,"f")}get restrictVersion(){return o(this,r,"f")}}function x(e){let t="";return e.map((e=>t+=`${e.toString()}|`)),t=`(${t.substring(0,t.length-1)})`,t}exports.FirmwareError=m,e=new WeakMap,t=new WeakMap,r=new WeakMap,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 s=0;s<n.length-1;s++){const i=n[s],p=o[s];if(i<p)return;if(i>p)throw new m(e,t,r)}const s=n.length-1,i=o[s]+(r.includes(".D.")?1:0);if(n[s]>i)throw new m(e,t,r)},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0}); | ||
*/var _FirmwareError_type,_FirmwareError_current,_FirmwareError_restrict,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkFWVersion=exports.FirmwareError=exports.FirmwareType=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 bignumber_js_1=require("bignumber.js"),ow_1=require("ow"),BIP32Path_1=require("./BIP32Path"),bs58_1=require("./bs58");var BIP32Path_2=require("./BIP32Path");Object.defineProperty(exports,"buildPathBuffer",{enumerable:!0,get:function(){return BIP32Path_2.buildPathBuffer}}),Object.defineProperty(exports,"decodePathBuffer",{enumerable:!0,get:function(){return BIP32Path_2.decodePathBuffer}}),Object.defineProperty(exports,"splitPath",{enumerable:!0,get:function(){return BIP32Path_2.splitPath}});var xpub_1=require("./xpub");Object.defineProperty(exports,"toExtenededPublicKey",{enumerable:!0,get:function(){return xpub_1.toExtenededPublicKey}});var signature_1=require("./signature");Object.defineProperty(exports,"Signature",{enumerable:!0,get:function(){return signature_1.Signature}}),exports.Logger=process.env.SECUX_LOGGER;const logger=null===exports.Logger||void 0===exports.Logger?void 0:exports.Logger.child({id:"utility"});var FirmwareType;exports.owTool=class{static get bip32String(){return ow_1.default.string.matches(/^m(\/\d+')+(\/\d+)*$/)}static get hexString(){return ow_1.default.string.matches(/^[0-9A-F-a-f]+$/)}static get prefixedhexString(){return ow_1.default.string.matches(/^0x[0-9A-F-a-f]+$/)}static get hashString(){return ow_1.default.string.matches(/^[0-9A-Z-a-z]+$/)}static get numberString(){return ow_1.default.string.matches(/^[0-9]+$/)}static get xpubString(){return ow_1.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/)}static get base58String(){return ow_1.default.string.is((x=>!!bs58_1.Base58.decodeUnsafe(x)))}static get base64String(){return ow_1.default.string.nonEmpty.matches(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/)}},exports.ow_bip32String=ow_1.default.string.matches(/^m(\/\d+')+(\/\d+)*$/),exports.ow_hexString=ow_1.default.string.matches(/^[0-9A-F-a-f]+$/),exports.ow_prefixedhexString=ow_1.default.string.matches(/^0x[0-9A-F-a-f]+$/),exports.ow_hashString=ow_1.default.string.matches(/^[0-9A-Z-a-z]+$/),exports.ow_numberString=ow_1.default.string.matches(/^[0-9]+$/),exports.ow_xpubString=ow_1.default.string.matches(/^[1-9A-NP-Za-km-z]{111}$/),exports.ow_base58String=ow_1.default.string.is((x=>!!bs58_1.Base58.decodeUnsafe(x))),exports.ow_strictPath=function(coinType,purpose){const coins=numbersToRegExp("number"==typeof coinType?[coinType]:coinType);if(purpose){const purposes=numbersToRegExp("number"==typeof purpose?[purpose]:purpose);return ow_1.default.string.matches(new RegExp(`^m/${purposes}'/${coins}'/[0-9]+'/[0-9]+/[0-9]+$`))}return ow_1.default.string.matches(new RegExp(`^m/[0-9]+'/${coins}'/[0-9]+'/[0-9]+/[0-9]+$`))},exports.ow_accountPath=function(coinType,purpose){const coins=numbersToRegExp("number"==typeof coinType?[coinType]:coinType);if(purpose){const purposes=numbersToRegExp("number"==typeof purpose?[purpose]:purpose);return ow_1.default.string.matches(new RegExp(`^m/${purposes}'/${coins}'/[0-9]+'`))}return ow_1.default.string.matches(new RegExp(`^m/[0-9]+'/${coins}'/[0-9]+'`))},exports.ow_checkBufferLength=function(length){return ow_1.default.buffer.validate((value=>({validator:value.length===length,message:label=>`ArgumentError: Expected length of ${label} is ${length}, got ${value.length}`})))},exports.BigIntToBuffer=function(value,bufferlen,isLE=!0){let hex="";"number"==typeof value?hex=value.toString(16):"string"==typeof value&&(hex=new bignumber_js_1.BigNumber(value).toString(16)),hex.length%2!=0&&(hex="0"+hex);const tmp=Buffer.from(hex,"hex");if(tmp.length>bufferlen)throw Error("value is too large");const buf=Buffer.concat([Buffer.alloc(bufferlen-tmp.length),tmp]);return isLE?buf.reverse():buf},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(path){const bip32=(0,BIP32Path_1.splitPath)(path);for(const def of exports.supported_coin)if(def.purpose.includes(bip32.purpose.value)&&def.cointype===bip32.coinType.value)return!0;return!1},exports.loadPlugin=function(plugin,name){try{const{ITransport}=require("@secux/transport");void 0===ITransport[name]&&Object.defineProperty(ITransport,name,{enumerable:!0,configurable:!1,writable:!1,value:plugin})}catch(error){null==logger||logger.debug("The package @secux/transport is not at environment, plugin loading skipped")}},function(FirmwareType){FirmwareType.mcu="mcu",FirmwareType.se="se"}(FirmwareType=exports.FirmwareType||(exports.FirmwareType={}));class FirmwareError extends Error{constructor(type,restrict,current){super(),_FirmwareError_type.set(this,void 0),_FirmwareError_current.set(this,void 0),_FirmwareError_restrict.set(this,void 0),__classPrivateFieldSet(this,_FirmwareError_type,FirmwareType[type],"f"),__classPrivateFieldSet(this,_FirmwareError_restrict,restrict,"f"),__classPrivateFieldSet(this,_FirmwareError_current,current,"f"),this.message=`${__classPrivateFieldGet(this,_FirmwareError_type,"f")} firmware need update, version "${restrict}" needed, but got "${current}"`}get type(){return __classPrivateFieldGet(this,_FirmwareError_type,"f")}get currentVersion(){return __classPrivateFieldGet(this,_FirmwareError_current,"f")}get restrictVersion(){return __classPrivateFieldGet(this,_FirmwareError_restrict,"f")}}function numbersToRegExp(list){let a="";return list.map((c=>a+=`${c.toString()}|`)),a=`(${a.substring(0,a.length-1)})`,a}exports.FirmwareError=FirmwareError,_FirmwareError_type=new WeakMap,_FirmwareError_current=new WeakMap,_FirmwareError_restrict=new WeakMap,exports.checkFWVersion=function(type,restrict,current){if(!restrict||!current)return;const r=restrict.split(".").map((x=>parseInt(x))),c=current.split(".").map((x=>parseInt(x)));for(let i=0;i<r.length-1;i++){const _r=r[i],_c=c[i];if(_r<_c)return;if(_r>_c)throw new FirmwareError(type,restrict,current)}const last=r.length-1,minor=c[last]+(current.includes(".D.")?1:0);if(r[last]>minor)throw new FirmwareError(type,restrict,current)},process.env.SECUX_LOGGER||Object.defineProperty(process.env,"SECUX_LOGGER",{enumerable:!1,configurable:!1,writable:!1,value:void 0}); |
@@ -29,7 +29,7 @@ /*! | ||
export declare function decodeXPUB(xpub: string): { | ||
purpose: number; | ||
depth: number; | ||
publickey: Buffer; | ||
chaincode: Buffer; | ||
fingerprint: Buffer; | ||
purpose: any; | ||
depth: any; | ||
publickey: any; | ||
chaincode: any; | ||
fingerprint: any; | ||
}; | ||
@@ -36,0 +36,0 @@ export declare function deriveKey(publickey: Buffer, chaincode: Buffer, indexArray: Array<number>): { |
@@ -18,2 +18,2 @@ "use strict"; | ||
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}} | ||
*/Object.defineProperty(exports,"__esModule",{value:!0}),exports.deriveKey=exports.decodeXPUB=exports.toExtenededPublicKey=void 0;const BIP32Path_1=require("./BIP32Path"),bs58_1=require("./bs58"),hash_js_1=require("hash.js"),elliptic_1=require("elliptic"),ow_1=require("ow"),utility_1=require("./utility"),groestl=require("groestl-hash-js"),logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"utility"}),secp256k1=new elliptic_1.ec("secp256k1"),BN=secp256k1.curve.n.constructor;exports.toExtenededPublicKey=function(path,parentFingerPrint,chainCode,publicKey){var _a;(0,ow_1.default)(path,utility_1.owTool.bip32String),(0,ow_1.default)(parentFingerPrint,(0,utility_1.ow_checkBufferLength)(4)),(0,ow_1.default)(chainCode,(0,utility_1.ow_checkBufferLength)(32)),(0,ow_1.default)(publicKey,(0,utility_1.ow_checkBufferLength)(33));const buffer=Buffer.allocUnsafe(78),bip44=(0,BIP32Path_1.splitPath)(path);switch(bip44.purpose.value){case 44:case 86:buffer.writeUInt32BE(76067358,0);break;case 49:buffer.writeUInt32BE(77429938,0);break;case 84:buffer.writeUInt32BE(78792518,0);break;default:throw Error("unsupported purpose of path")}const depth=bip44.pathNum;let element;switch(buffer.writeUInt8(depth,4),(depth>0?parentFingerPrint:Buffer.alloc(4)).copy(buffer,5),depth){case 1:element=bip44.purpose;break;case 2:element=bip44.coinType;break;case 3:element=bip44.accountId;break;case 4:element=bip44.change;break;case 5:element=bip44.addressIndex;break;default:throw Error("Invalid Path, only support 1 to 5 depth path")}const index=element.isHardened?element.value+BIP32Path_1.HARDENED_OFFSET:null==element?void 0:element.value;return buffer.writeUInt32BE(index,9),chainCode.copy(buffer,13),publicKey.copy(buffer,45),17===(null===(_a=bip44.coinType)||void 0===_a?void 0:_a.value)?bs58_GRS.encode(buffer):bs58_BTC.encode(buffer)},exports.decodeXPUB=function(xpub){let payload,purpose;(0,ow_1.default)(xpub,utility_1.owTool.xpubString);try{payload=bs58_BTC.decode(xpub)}catch(error){null==logger||logger.warn(`The xpub is not Bitcoin compatible, try use Groestlcoin version:\n${xpub}`),payload=bs58_GRS.decode(xpub)}switch(payload.readUInt32BE(0)){case 76067358:purpose=44,null==logger||logger.warn("Please note that TapRoot type xpub using the same prefix, it cannot be considered here.");break;case 77429938:purpose=49;break;case 78792518:purpose=84;break;default:throw Error(`unsupport prefix, got 0x${payload.slice(0,4)}`)}const depth=payload.readUInt8(4),fingerprint=payload.slice(5,9),chaincode=payload.slice(13,45);return{purpose,depth,publickey:payload.slice(45),chaincode,fingerprint}},exports.deriveKey=function(publickey,chaincode,indexArray){(0,ow_1.default)(publickey,(0,utility_1.ow_checkBufferLength)(33)),(0,ow_1.default)(chaincode,(0,utility_1.ow_checkBufferLength)(32)),(0,ow_1.default)(indexArray,ow_1.default.array.ofType(ow_1.default.number.uint8));let xpub={publickey,chaincode};for(const index of indexArray)xpub=derive(xpub.publickey,xpub.chaincode,index);return xpub};const bs58_BTC=new bs58_1.bs58Check((function(data){const sha=(0,hash_js_1.sha256)().update(data).digest();return Buffer.from((0,hash_js_1.sha256)().update(sha).digest())})),bs58_GRS=new bs58_1.bs58Check((function(data){return Buffer.from(groestl.groestl_2(data,1,1))}));function derive(publickey,chaincode,index){const data=Buffer.allocUnsafe(37);publickey.copy(data,0),data.writeUInt32BE(index,33);const hmacSha512=(0,hash_js_1.hmac)(hash_js_1.sha512,chaincode).update(data).digest(),I=Buffer.from(hmacSha512),IL=I.slice(0,32),IR=I.slice(32);let Ki;try{const pair=secp256k1.keyFromPublic(publickey),tweak=new BN(IL);if(tweak.cmp(secp256k1.curve.n)>=0)throw Error("tweak error");const point=pair.getPublic().add(secp256k1.curve.g.mul(tweak));if(point.isInfinity())throw Error("point error");Ki=Buffer.from(point.encode("array",!0))}catch(err){return derive(publickey,chaincode,index+1)}return{publickey:Ki,chaincode:IR}} |
{ | ||
"name": "@secux/utility", | ||
"version": "3.0.14", | ||
"version": "3.0.15", | ||
"description": "SecuX Hardware Wallet internal tools for SDK", | ||
@@ -11,3 +11,3 @@ "keywords": [ | ||
], | ||
"homepage": "https://github.com/secuxtech/secux-js/tree/master/packages/utility", | ||
"homepage": "https://github.com/SecuX/secux-js/tree/master/packages/utility", | ||
"author": "SecuX Technology Inc.", | ||
@@ -14,0 +14,0 @@ "license": "Apache-2.0", |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
57394
408
6