@secux/app-eth
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -25,3 +25,5 @@ /// <reference types="node" /> | ||
* @param {txDetail} content transaction content | ||
* @returns {string} signed transaction | ||
* @returns {object} signed | ||
* @returns {string} signed.raw_tx | ||
* @returns {Buffer} signed.signature | ||
* | ||
@@ -59,3 +61,5 @@ * @example | ||
* @param {number} chainId default ETH mainnet | ||
* @returns {string} signature | ||
* @returns {object} signed | ||
* @returns {string} signed.raw_tx | ||
* @returns {Buffer} signed.signature | ||
*/ | ||
@@ -72,3 +76,5 @@ static signMessage(trans: ITransport, path: string, message: string, chainId?: number): Promise<{ | ||
* @param {number} chainId default ETH mainnet | ||
* @returns {string} signature | ||
* @returns {object} signed | ||
* @returns {string} signed.raw_tx | ||
* @returns {Buffer} signed.signature | ||
*/ | ||
@@ -84,3 +90,5 @@ static signTypedMessage(trans: ITransport, path: string, data: TypedData, chainId?: number): Promise<{ | ||
* @param {txDetail} content transaction content | ||
* @returns {string} signed transaction | ||
* @returns {object} signed | ||
* @returns {string} signed.raw_tx | ||
* @returns {Buffer} signed.signature | ||
*/ | ||
@@ -87,0 +95,0 @@ static signWalletConnectTransaction(trans: ITransport, path: string, content: txDetail): Promise<{ |
@@ -1,1 +0,1 @@ | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,r){t[r=void 0===r?i:r]=e[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)"default"!==i&&Object.prototype.hasOwnProperty.call(t,i)&&__createBinding(e,t,i);return __setModuleDefault(e,t),e},__awaiter=this&&this.__awaiter||function(t,o,s,c){return new(s=s||Promise)(function(i,e){function r(t){try{n(c.next(t))}catch(t){e(t)}}function a(t){try{n(c.throw(t))}catch(t){e(t)}}function n(t){var e;t.done?i(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(r,a)}n((c=c.apply(t,o||[])).next())})},__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxETH=void 0;const js_sha3_1=require("js-sha3"),ow_1=__importDefault(require("ow")),protocol_transaction_1=require("@secux/protocol-transaction"),utils=__importStar(require("@secux/utility")),interface_1=require("./interface"),transaction_1=require("./transaction"),eip712_1=require("./eip712"),validate=require("wallet-address-validator").validate;class SecuxETH{static getAddress(e,i){return __awaiter(this,void 0,void 0,function*(){(0,ow_1.default)(i,utils.ow_strictPath(60,44));let t=(yield protocol_transaction_1.SecuxTransactionTool.getXPublickey(e,i,!1))["publicKey"];if(65!==t.length)throw Error(`XPubicKey length error: ${t.length} (should be 65)`);return toChecksumAddress((0,js_sha3_1.keccak256)(t.slice(1)).slice(-40))})}static signTransaction(a,n,o){return __awaiter(this,void 0,void 0,function*(){if((0,ow_1.default)(n,utils.ow_strictPath(60,44)),(0,ow_1.default)(o,interface_1.ow_txDetail),!validate(o.to,"ETH"))throw Error(`Invalid address: ${o.to}`);const t=new transaction_1.ETHTransactionBuilder(o);var e=t.serialize();let i=Object.assign({},protocol_transaction_1.DefaultTransactionOption);i.tp=protocol_transaction_1.TransactionType.TOKEN;const r=yield protocol_transaction_1.SecuxTransactionTool.SignRawTransaction(a,n,e,i);return r.trimZero(),{raw_tx:t.withSignature(r).toString("hex"),signature:BuildSignature(r,o.chainId)}})}static signMessage(e,i,r,a=1){return __awaiter(this,void 0,void 0,function*(){(0,ow_1.default)(i,utils.ow_strictPath(60,44)),(0,ow_1.default)(r,ow_1.default.string),(0,ow_1.default)(a,ow_1.default.number.positive);const t=yield protocol_transaction_1.SecuxTransactionTool.SignMessage(e,i,Buffer.from(r));return t.trimZero(),{raw_tx:"",signature:BuildSignature(t,a)}})}static signTypedMessage(a,n,o,s=1){return __awaiter(this,void 0,void 0,function*(){(0,ow_1.default)(n,utils.ow_strictPath(60,44)),(0,ow_1.default)(o,interface_1.ow_TypedData),(0,ow_1.default)(s,ow_1.default.number.positive);const t=sanitizeData(o),e=[];e.push(eip712_1.TypedDataUtils.hashStruct("EIP712Domain",t.domain,t.types,!0)),"EIP712Domain"!==t.primaryType&&e.push(eip712_1.TypedDataUtils.hashStruct(t.primaryType.toString(),t.message,t.types,!0));var i=Buffer.concat(e);const r=yield protocol_transaction_1.SecuxTransactionTool.SignTypedMessage(a,n,i);return r.trimZero(),{raw_tx:"",signature:BuildSignature(r,s)}})}static signWalletConnectTransaction(a,n,o){return __awaiter(this,void 0,void 0,function*(){(0,ow_1.default)(n,utils.ow_strictPath(60,44)),(0,ow_1.default)(o,interface_1.ow_txDetail);const t=new transaction_1.ETHTransactionBuilder(o);var e=t.serialize(!0);let i=Object.assign({},protocol_transaction_1.DefaultTransactionOption);i.chainId=o.chainId;const r=yield protocol_transaction_1.SecuxTransactionTool.SignTransaction(a,n,e,i);return r.trimZero(),{raw_tx:t.withSignature(r).toString("hex"),signature:BuildSignature(r,o.chainId)}})}}function toChecksumAddress(e){e=e.toLowerCase().replace(/^0x/,"");var i=(0,js_sha3_1.keccak256)(e);let r="0x";for(let t=0;t<e.length;t++)8<=parseInt(i[t],16)?r+=e[t].toUpperCase():r+=e[t];return r}function BuildSignature(t,e){return Buffer.concat([t.r,t.s,Buffer.from([t.v[0]+2*e+35])])}function sanitizeData(t){const e={};for(const i in interface_1.TYPED_MESSAGE_SCHEMA.properties)t[i]&&(e[i]=t[i]);return"types"in e&&(e.types=Object.assign({EIP712Domain:[]},e.types)),e}exports.SecuxETH=SecuxETH; | ||
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&t(r,i,n);return e(r,i),r},r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,s)}u((r=r.apply(t,e||[])).next())}))},n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxETH=void 0;const a=require("js-sha3"),o=n(require("ow")),s=require("@secux/protocol-transaction"),u=i(require("@secux/utility")),c=require("./interface"),l=require("./transaction"),d=require("./eip712"),f=require("wallet-address-validator").validate;function h(t,e){return Buffer.concat([t.r,t.s,Buffer.from([t.v[0]+2*e+35])])}exports.SecuxETH=class{static getAddress(t,e){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44));let{publicKey:i}=yield s.SecuxTransactionTool.getXPublickey(t,e,!1);if(65!==i.length)throw Error(`XPubicKey length error: ${i.length} (should be 65)`);return function(t){t=t.toLowerCase().replace(/^0x/,"");const e=(0,a.keccak256)(t);let i="0x";for(let r=0;r<t.length;r++)parseInt(e[r],16)>=8?i+=t[r].toUpperCase():i+=t[r];return i}((0,a.keccak256)(i.slice(1)).slice(-40))}))}static signTransaction(t,e,i){return r(this,void 0,void 0,(function*(){if((0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_txDetail),!f(i.to,"ETH"))throw Error(`Invalid address: ${i.to}`);const r=new l.ETHTransactionBuilder(i),n=r.serialize();let a=Object.assign({},s.DefaultTransactionOption);a.tp=s.TransactionType.TOKEN;const d=yield s.SecuxTransactionTool.SignRawTransaction(t,e,n,a);return d.trimZero(),{raw_tx:r.withSignature(d).toString("hex"),signature:h(d,i.chainId)}}))}static signMessage(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,o.default.string),(0,o.default)(n,o.default.number.positive);const r=yield s.SecuxTransactionTool.SignMessage(t,e,Buffer.from(i));return r.trimZero(),{raw_tx:"",signature:h(r,n)}}))}static signTypedMessage(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_TypedData),(0,o.default)(n,o.default.number.positive);const r=function(t){const e={};for(const i in c.TYPED_MESSAGE_SCHEMA.properties)t[i]&&(e[i]=t[i]);"types"in e&&(e.types=Object.assign({EIP712Domain:[]},e.types));return e}(i),a=[];a.push(d.TypedDataUtils.hashStruct("EIP712Domain",r.domain,r.types,!0)),"EIP712Domain"!==r.primaryType&&a.push(d.TypedDataUtils.hashStruct(r.primaryType.toString(),r.message,r.types,!0));const l=Buffer.concat(a),f=yield s.SecuxTransactionTool.SignTypedMessage(t,e,l);return f.trimZero(),{raw_tx:"",signature:h(f,n)}}))}static signWalletConnectTransaction(t,e,i){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_txDetail);const r=new l.ETHTransactionBuilder(i),n=r.serialize(!0);let a=Object.assign({},s.DefaultTransactionOption);a.chainId=i.chainId;const d=yield s.SecuxTransactionTool.SignTransaction(t,e,n,a);return d.trimZero(),{raw_tx:r.withSignature(d).toString("hex"),signature:h(d,i.chainId)}}))}}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TypedDataUtils=void 0;const js_sha3_1=require("js-sha3"),abi_1=require("@ethersproject/abi"),TYPED_MESSAGE_SCHEMA={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]};class TypedDataUtils{static encodeData(e,t,n,a=!0){const s=["bytes32"],r=[this.hashType(e,n)];if(a){const o=(t,e,s)=>{if(void 0!==n[e])return["bytes32",null==s?"0x0000000000000000000000000000000000000000000000000000000000000000":keccak(this.encodeData(e,s,n,a))];if(void 0===s)throw new Error(`missing value for field ${t} of type ${e}`);if("bytes"===e)return["bytes32",keccak(s)];if("string"===e)return["bytes32",keccak(s="string"==typeof s?Buffer.from(s,"utf8"):s)];if(e.lastIndexOf("]")!==e.length-1)return[e,s];{const r=e.slice(0,e.lastIndexOf("[")),i=s.map(e=>o(t,r,e));return["bytes32",keccak(abi_1.defaultAbiCoder.encode(i.map(([e])=>e),i.map(([,e])=>e)))]}};for(const c of n[e]){var[i,p]=o(c.name,c.type,t[c.name]);s.push(i),r.push(p)}}else for(const y of n[e]){let e=t[y.name];if(void 0!==e)if("bytes"===y.type)s.push("bytes32"),e=keccak(e),r.push(e);else if("string"===y.type)s.push("bytes32"),"string"==typeof e&&(e=Buffer.from(e,"utf8")),e=keccak(e),r.push(e);else if(void 0!==n[y.type])s.push("bytes32"),e=keccak(this.encodeData(y.type,e,n,a)),r.push(e);else{if(y.type.lastIndexOf("]")===y.type.length-1)throw new Error("Arrays are unimplemented in encodeData; use V4 extension");s.push(y.type),r.push(e)}}return abi_1.defaultAbiCoder.encode(s,r)}static encodeType(t,e){let s="",r=this.findTypeDependencies(t,e).filter(e=>e!==t);r=[t].concat(r.sort());for(const i of r){if(!e[i])throw new Error(`No type definition specified: ${i}`);s+=`${i}(${e[i].map(({name:e,type:t})=>`${t} ${e}`).join(",")})`}return s}static findTypeDependencies(e,t,s=[]){if([e]=e.match(/^\w*/u),s.includes(e)||void 0===t[e])return s;s.push(e);for(const r of t[e])for(const i of this.findTypeDependencies(r.type,t,s))s.includes(i)||s.push(i);return s}static hashStruct(e,t,s,r=!0){return keccak(this.encodeData(e,t,s,r))}static hashType(e,t){return keccak(this.encodeType(e,t))}static sanitizeData(e){const t={};for(const s in TYPED_MESSAGE_SCHEMA.properties)e[s]&&(t[s]=e[s]);return"types"in t&&(t.types=Object.assign({EIP712Domain:[]},t.types)),t}}function keccak(e){return Buffer.from(js_sha3_1.keccak256.update(e).digest())}exports.TypedDataUtils=TypedDataUtils; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.TypedDataUtils=void 0;const e=require("js-sha3"),t=require("@ethersproject/abi"),s={types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}};function r(t){return Buffer.from(e.keccak256.update(t).digest())}exports.TypedDataUtils=class{static encodeData(e,s,n,i=!0){const o=["bytes32"],p=[this.hashType(e,n)];if(i){const a=(e,s,o)=>{if(void 0!==n[s])return["bytes32",null==o?"0x0000000000000000000000000000000000000000000000000000000000000000":r(this.encodeData(s,o,n,i))];if(void 0===o)throw new Error(`missing value for field ${e} of type ${s}`);if("bytes"===s)return["bytes32",r(o)];if("string"===s)return"string"==typeof o&&(o=Buffer.from(o,"utf8")),["bytes32",r(o)];if(s.lastIndexOf("]")===s.length-1){const n=s.slice(0,s.lastIndexOf("[")),i=o.map((t=>a(e,n,t)));return["bytes32",r(t.defaultAbiCoder.encode(i.map((([e])=>e)),i.map((([,e])=>e))))]}return[s,o]};for(const t of n[e]){const[e,r]=a(t.name,t.type,s[t.name]);o.push(e),p.push(r)}}else for(const t of n[e]){let e=s[t.name];if(void 0!==e)if("bytes"===t.type)o.push("bytes32"),e=r(e),p.push(e);else if("string"===t.type)o.push("bytes32"),"string"==typeof e&&(e=Buffer.from(e,"utf8")),e=r(e),p.push(e);else if(void 0!==n[t.type])o.push("bytes32"),e=r(this.encodeData(t.type,e,n,i)),p.push(e);else{if(t.type.lastIndexOf("]")===t.type.length-1)throw new Error("Arrays are unimplemented in encodeData; use V4 extension");o.push(t.type),p.push(e)}}return t.defaultAbiCoder.encode(o,p)}static encodeType(e,t){let s="",r=this.findTypeDependencies(e,t).filter((t=>t!==e));r=[e].concat(r.sort());for(const e of r){if(!t[e])throw new Error(`No type definition specified: ${e}`);s+=`${e}(${t[e].map((({name:e,type:t})=>`${t} ${e}`)).join(",")})`}return s}static findTypeDependencies(e,t,s=[]){if([e]=e.match(/^\w*/u),s.includes(e)||void 0===t[e])return s;s.push(e);for(const r of t[e])for(const e of this.findTypeDependencies(r.type,t,s))!s.includes(e)&&s.push(e);return s}static hashStruct(e,t,s,n=!0){return r(this.encodeData(e,t,s,n))}static hashType(e,t){return r(this.encodeType(e,t))}static sanitizeData(e){const t={};for(const r in s)e[r]&&(t[r]=e[r]);return"types"in t&&(t.types=Object.assign({EIP712Domain:[]},t.types)),t}}; |
@@ -1,1 +0,1 @@ | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,o){void 0===o&&(o=a),Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[a]}})}:function(e,t,a,o){e[o=void 0===o?a:o]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isTransferData=exports.TYPED_MESSAGE_SCHEMA=exports.ow_TypedData=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_txDetail=exports.ow_transferData=exports.ow_address=void 0;const ow_1=__importDefault(require("ow")),utils=__importStar(require("@secux/utility"));function isTransferData(e){try{return(0,ow_1.default)(e,exports.ow_transferData),e}catch(e){}}exports.ow_address=ow_1.default.string.matches(/^0x[0-9A-fa-f]{40}$/),exports.ow_transferData=ow_1.default.object.exactShape({toAddress:exports.ow_address,amount:ow_1.default.any(ow_1.default.number.not.negative,utils.ow_prefixedhexString)}),exports.ow_txDetail=ow_1.default.object.exactShape({chainId:ow_1.default.number.positive,nonce:ow_1.default.any(ow_1.default.number,utils.ow_prefixedhexString),gasPrice:ow_1.default.any(ow_1.default.number.positive,utils.ow_prefixedhexString),gasLimit:ow_1.default.any(ow_1.default.number.positive,utils.ow_prefixedhexString),to:exports.ow_address,value:ow_1.default.any(ow_1.default.number.not.negative,utils.ow_prefixedhexString),data:ow_1.default.any(ow_1.default.undefined,utils.ow_prefixedhexString,exports.ow_transferData)}),exports.ow_EIP712TypedData=ow_1.default.object.exactShape({name:ow_1.default.string,type:ow_1.default.string}),exports.ow_TypedMessage=ow_1.default.object.exactShape({types:ow_1.default.object.valuesOfType(ow_1.default.array.ofType(exports.ow_EIP712TypedData)),primaryType:ow_1.default.string,domain:ow_1.default.object.exactShape({name:ow_1.default.optional.string,version:ow_1.default.optional.string,chainId:ow_1.default.optional.number.not.negative,verifyingContract:ow_1.default.optional.string}),message:ow_1.default.object}),exports.ow_TypedData=ow_1.default.any(exports.ow_TypedMessage),exports.TYPED_MESSAGE_SCHEMA={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},exports.isTransferData=isTransferData; | ||
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,a,r){void 0===r&&(r=a),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[a]}})}:function(e,t,a,r){void 0===r&&(r=a),e[r]=t[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(a){if(a&&a.__esModule)return a;var r={};if(null!=a)for(var o in a)"default"!==o&&Object.prototype.hasOwnProperty.call(a,o)&&e(r,a,o);return t(r,a),r},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isTransferData=exports.TYPED_MESSAGE_SCHEMA=exports.ow_TypedData=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_txDetail=exports.ow_transferData=exports.ow_address=void 0;const o=r(require("ow")),i=a(require("@secux/utility"));exports.ow_address=o.default.string.matches(/^0x[0-9A-fa-f]{40}$/),exports.ow_transferData=o.default.object.exactShape({toAddress:exports.ow_address,amount:o.default.any(o.default.number.not.negative,i.ow_prefixedhexString)}),exports.ow_txDetail=o.default.object.exactShape({chainId:o.default.number.positive,nonce:o.default.any(o.default.number,i.ow_prefixedhexString),gasPrice:o.default.any(o.default.number.positive,i.ow_prefixedhexString),gasLimit:o.default.any(o.default.number.positive,i.ow_prefixedhexString),to:exports.ow_address,value:o.default.any(o.default.number.not.negative,i.ow_prefixedhexString),data:o.default.any(o.default.undefined,i.ow_prefixedhexString,exports.ow_transferData)}),exports.ow_EIP712TypedData=o.default.object.exactShape({name:o.default.string,type:o.default.string}),exports.ow_TypedMessage=o.default.object.exactShape({types:o.default.object.valuesOfType(o.default.array.ofType(exports.ow_EIP712TypedData)),primaryType:o.default.string,domain:o.default.object.exactShape({name:o.default.optional.string,version:o.default.optional.string,chainId:o.default.optional.number.not.negative,verifyingContract:o.default.optional.string}),message:o.default.object}),exports.ow_TypedData=o.default.any(exports.ow_TypedMessage),exports.TYPED_MESSAGE_SCHEMA={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},exports.isTransferData=function(e){try{return(0,o.default)(e,exports.ow_transferData),e}catch(e){}}; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _ETHTransactionBuilder_tx,__createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,i){void 0===i&&(i=a),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[a]}})}:function(e,t,a,i){e[i=void 0===i?a:i]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t},__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,a,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,a):r?r.value=a:t.set(e,a),a},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,a,i){if("a"===a&&!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"===a?i:"a"===a?i.call(e):i?i.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ETHTransactionBuilder=void 0;const js_sha3_1=require("js-sha3"),rlp=__importStar(require("rlp")),abi_1=require("@ethersproject/abi"),interface_1=require("./interface"),validate=require("wallet-address-validator").validate,Contracts=new abi_1.Interface(["function transfer(address to, uint amount)"]);class ETHTransactionBuilder{constructor(e){_ETHTransactionBuilder_tx.set(this,void 0),__classPrivateFieldSet(this,_ETHTransactionBuilder_tx,e,"f");e=(0,interface_1.isTransferData)(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").data);if(e){if(!validate(e.toAddress,"ETH"))throw Error(`Invalid address: ${e.toAddress}`);__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").data=Contracts.encodeFunctionData("transfer",[e.toAddress,e.amount])}}serialize(e=!1){var t=[handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").nonce),handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").gasPrice),handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").gasLimit),__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").to,handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").value),__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").data||"",handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId),0,0],t=rlp.encode(t);return e?Buffer.from(js_sha3_1.keccak256.update(t).digest()):t}withSignature(e){e=[handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").nonce),handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").gasPrice),handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").gasLimit),__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").to,handleRLPValue(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").value),__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").data||"",handleRLPValue(2*__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId+35+e.v[0]),e.r,e.s];return rlp.encode(e)}}function handleRLPValue(e){if("number"==typeof e)return e;if("string"!=typeof e)throw Error("Invalid handleRLPValue type");if(e.startsWith("0x")&&isHex(e))return"0x0"==e||"0x00"==e?0:e;throw Error("Invalid handleRLPValue string")}function isHex(e){let t=e.startsWith("0x")?e.slice(2):e;return t=t.length%2==0?t:`0${t}`,/^[0-9a-fA-F]+$/.test(t)}exports.ETHTransactionBuilder=ETHTransactionBuilder,_ETHTransactionBuilder_tx=new WeakMap; | ||
"use strict";var t,e=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r),Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),r=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var a in t)"default"!==a&&Object.prototype.hasOwnProperty.call(t,a)&&e(i,t,a);return r(i,t),i},a=this&&this.__classPrivateFieldSet||function(t,e,r,i,a){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?a.call(t,r):a?a.value=r:e.set(t,r),r},n=this&&this.__classPrivateFieldGet||function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ETHTransactionBuilder=void 0;const s=require("js-sha3"),o=i(require("rlp")),f=require("@ethersproject/abi"),c=require("./interface"),d=require("wallet-address-validator").validate,u=new f.Interface(["function transfer(address to, uint amount)"]);function h(t){if("number"==typeof t)return t;if("string"==typeof t){if(t.startsWith("0x")&&function(t){let e=t.startsWith("0x")?t.slice(2):t;const r=/^[0-9a-fA-F]+$/;return e=e.length%2==0?e:`0${e}`,r.test(e)}(t))return"0x0"==t||"0x00"==t?0:t;throw Error("Invalid handleRLPValue string")}throw Error("Invalid handleRLPValue type")}exports.ETHTransactionBuilder=class{constructor(e){t.set(this,void 0),a(this,t,e,"f");let r=(0,c.isTransferData)(n(this,t,"f").data);if(r){if(!d(r.toAddress,"ETH"))throw Error(`Invalid address: ${r.toAddress}`);n(this,t,"f").data=u.encodeFunctionData("transfer",[r.toAddress,r.amount])}}serialize(e=!1){const r=[h(n(this,t,"f").nonce),h(n(this,t,"f").gasPrice),h(n(this,t,"f").gasLimit),n(this,t,"f").to,h(n(this,t,"f").value),n(this,t,"f").data||"",h(n(this,t,"f").chainId),0,0],i=o.encode(r);return e?Buffer.from(s.keccak256.update(i).digest()):i}withSignature(e){const r=[h(n(this,t,"f").nonce),h(n(this,t,"f").gasPrice),h(n(this,t,"f").gasLimit),n(this,t,"f").to,h(n(this,t,"f").value),n(this,t,"f").data||"",h(2*n(this,t,"f").chainId+35+e.v[0]),e.r,e.s];return o.encode(r)}},t=new WeakMap; |
{ | ||
"name": "@secux/app-eth", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "SecuX Hardware Wallet ETH API", | ||
@@ -27,2 +27,3 @@ "keywords": [ | ||
"scripts": { | ||
"build": "sh ../../build.sh", | ||
"test:webusb": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/usb.js", | ||
@@ -35,3 +36,3 @@ "test:webble": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/ble.js", | ||
"@ethersproject/abi": "^5.4.1", | ||
"@secux/protocol-transaction": "^2.0.0", | ||
"@secux/protocol-transaction": "2.0.1", | ||
"@secux/utility": "^2.0.1", | ||
@@ -38,0 +39,0 @@ "wallet-address-validator": "^0.2.4" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
285
0
26238
+ Added@secux/protocol-transaction@2.0.1(transitive)
- Removed@secux/protocol-transaction@2.1.4(transitive)