Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@secux/app-eth

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/app-eth - npm Package Compare versions

Comparing version 3.0.3 to 3.0.4

71

lib/app-eth.d.ts

@@ -29,3 +29,3 @@ /// <reference types="node" />

*/
static prepareAddress: typeof SecuxETH.preparePublickey;
static prepareAddress(path: string): communicationData;
/**

@@ -83,17 +83,2 @@ * Resolve address from response data.

/**
* @typedef tx155 EIP-155 transaction object
* @property {number} chainId network for ethereum ecosystem
* @property {string} to receiving address
* @property {number | string} value sending amount
* @property {number | string} nonce
* @property {number | string} gasPrice
* @property {number | string} gasLimit
* @property {string} [data]
*/
/**
* @typedef prepared prepared object
* @property {communicationData} commandData data for sending to device
* @property {communicationData} serialized unsigned transaction
*/
/**
* Prepare data for signing.

@@ -106,3 +91,3 @@ * @param {string} path m/44'/60'/...

commandData: communicationData;
rawTx: string | Buffer;
rawTx: communicationData;
};

@@ -117,14 +102,2 @@ /**

/**
* @typedef tx1559 EIP-1559 transaction object
* @property {number} chainId network for ethereum ecosystem
* @property {string} to receiving address
* @property {number | string} value sending amount
* @property {number | string} nonce
* @property {number | string} maxPriorityFeePerGas
* @property {number | string} maxFeePerGas
* @property {number | string} gasLimit
* @property {any[]} [content.accessList]
* @property {string} [data]
*/
/**
* Prepare data for signing (London Hard Fork).

@@ -137,3 +110,3 @@ * @param {string} path m/44'/60'/...

commandData: communicationData;
rawTx: string | Buffer;
rawTx: communicationData;
};

@@ -162,3 +135,3 @@ /**

commandData: communicationData;
rawTx: string | Buffer;
rawTx: communicationData;
};

@@ -189,3 +162,37 @@ static getAddress(this: ITransport, path: string): Promise<string>;

commandData: communicationData;
rawTx: string | Buffer;
rawTx: communicationData;
};
/**
* Data type for transmission.
* @typedef {string|Buffer} communicationData
*/
/**
* The payment object for EIP-155.
* @typedef {object} tx155
* @property {number} chainId network for ethereum ecosystem
* @property {string} to receiving address
* @property {number | string} value sending amount
* @property {number | string} nonce the number of transactions sent from this address
* @property {number | string} gasPrice the price of gas (unit: wei)
* @property {number | string} gasLimit the maximum amount of gas you are willing to consume
* @property {string} [data] abi-encoded data payload
*/
/**
* The payment object for EIP-1559.
* @typedef {object} tx1559
* @property {number} chainId network for ethereum ecosystem
* @property {string} to receiving address
* @property {number | string} value sending amount
* @property {number | string} nonce the number of transactions sent from this address
* @property {number | string} maxPriorityFeePerGas the maximum priority fee of gas (unit: wei)
* @property {number | string} maxFeePerGas the maximum price of gas (unit: wei)
* @property {number | string} gasLimit the maximum amount of gas you are willing to consume
* @property {Array<any>} [content.accessList]
* @property {string} [data] abi-encoded data payload
*/
/**
* Object for the signing and validation.
* @typedef {object} prepared
* @property {communicationData} commandData data for sending to device
* @property {communicationData} serialized unsigned transaction
*/

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

"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&t(i,e,a);return r(i,e),i},a=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(a,n){function o(e){try{s(i.next(e))}catch(e){n(e)}}function u(e){try{s(i.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,u)}s((i=i.apply(e,t||[])).next())}))},n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.prepareSign=exports.SecuxETH=void 0;const o=require("js-sha3"),u=require("secp256k1/elliptic"),s=n(require("ow")),c=i(require("@secux/utility")),l=require("@secux/protocol-transaction"),f=require("@secux/protocol-transaction/lib/interface"),d=require("./interface"),p=require("./transaction"),g=require("eth-sig-util"),x=require("@secux/utility/lib/communication"),h=require("./erc20"),v=require("./erc721"),y=require("./erc1155"),S=require("@secux/transport"),T=null===(e=c.Logger)||void 0===e?void 0:e.child({id:"ethereum"}),m=c.ow_strictPath(60,44);class E{static addressConvert(e){const t=function(e){(0,s.default)(e,s.default.any(c.ow_hexString,s.default.buffer));const t="string"==typeof e?Buffer.from(e,"hex"):e;if((0,s.default)(t,s.default.buffer.is((e=>33===e.length||65===e.length))),!u.publicKeyVerify(t))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${t.toString("hex")}"`);return t}(e),r=u.publicKeyConvert(t,!1),i=function(e){e=e.toLowerCase().replace(/^0x/,"");const t=(0,o.keccak256)(e);let r="0x";for(let i=0;i<e.length;i++)parseInt(t[i],16)>=8?r+=e[i].toUpperCase():r+=e[i];return r}((0,o.keccak256)(r.slice(1)).slice(-40));return i}static resolveAddress(e){(0,s.default)(e,x.ow_communicationData);const t=E.resolvePublickey(e);return E.addressConvert(t)}static preparePublickey(e){return(0,s.default)(e,m),l.SecuxTransactionTool.getPublickey(e,f.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=l.SecuxTransactionTool.resolvePublickey(e,f.EllipticCurve.SECP256K1);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,s.default)(e,m),l.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,s.default)(t,m),l.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSignSerialized(e,t){(0,s.default)(t,x.ow_communicationData);const r=(0,x.getBuffer)(t);null==T||T.debug(`- prepareSignSerialized\ninput serialized tx: ${r.toString("hex")}`);const i=p.ETHTransactionBuilder.deserialize(r);return(0,s.default)(i.tx.to,d.ow_address),b(e,i).commandData}static resolveSignature(e){return Buffer.from(l.SecuxTransactionTool.resolveSignature(e),"base64").toString("hex")}static resolveTransaction(e,t){(0,s.default)(e,x.ow_communicationData),(0,s.default)(t,x.ow_communicationData);const r=(0,x.getBuffer)(t),i=p.ETHTransactionBuilder.deserialize(r),a=Buffer.from(E.resolveSignature(e),"hex");return null==T||T.debug(`- resolveTransaction\ninput serialized tx: ${r.toString("hex")}`),`0x${i.withSignature(a).toString("hex")}`}static prepareSignEIP155(e,t){(0,s.default)(t,d.ow_tx155);return b(e,(0,p.getBuilder)(t))}static resolveSignatureEIP155(e,t){(0,s.default)(e,x.ow_communicationData),(0,s.default)(t,s.default.optional.number.positive);const r=Buffer.from(E.resolveSignature(e),"hex"),i=r[64];return void 0===t?r.writeUInt8(27+i,64):r.writeUInt8(35+2*t+i,64),r.toString("hex")}static prepareSignEIP1559(e,t){(0,s.default)(t,d.ow_tx1559);return b(e,(0,p.getBuilder)(t))}static prepareSignMessage(e,t){let r;return(0,s.default)(e,m),(0,s.default)(t,s.default.any(s.default.string.nonEmpty,s.default.buffer)),"string"==typeof t&&(r=t.startsWith("0x")?Buffer.from(t.slice(2),"hex"):Buffer.from(t)),l.SecuxTransactionTool.signMessage(e,null!=r?r:t)}static prepareSignTypedData(e,t){(0,s.default)(e,m);const r=JSON.parse(t);(0,s.default)(r,s.default.any(d.ow_EIP712TypedData,d.ow_TypedMessage));const i=g.TypedDataUtils.sanitizeData(r),a=[];a.push(g.TypedDataUtils.hashStruct("EIP712Domain",i.domain,i.types,!0)),"EIP712Domain"!==i.primaryType&&a.push(g.TypedDataUtils.hashStruct(i.primaryType.toString(),i.message,i.types,!0));const n=Buffer.concat(a);return l.SecuxTransactionTool.signTypedMessage(e,n)}static prepareSignWalletConnectTransaction(e,t){(0,s.default)(e,m),(0,s.default)(t,s.default.any(d.ow_tx155,d.ow_tx1559));const r=(0,p.getBuilder)(t),i=r.serialize(!0);return{commandData:l.SecuxTransactionTool.signTransaction(e,i,{tp:f.TransactionType.NORMAL,curve:f.EllipticCurve.SECP256K1,chainId:t.chainId}),rawTx:(0,x.toCommunicationData)(r.serialize())}}static getAddress(e){return a(this,void 0,void 0,(function*(){const t=E.prepareAddress(e),r=yield this.Exchange((0,x.getBuffer)(t));return E.resolveAddress(r)}))}static getPublickey(e){return a(this,void 0,void 0,(function*(){const t=E.preparePublickey(e),r=yield this.Exchange((0,x.getBuffer)(t));return E.resolvePublickey(r)}))}static getXPublickey(e){return a(this,void 0,void 0,(function*(){const t=E.prepareXPublickey(e),r=yield this.Exchange((0,x.getBuffer)(t));return E.resolveXPublickey(r,e)}))}static sign(e,t,r){return a(this,void 0,void 0,(function*(){const i=()=>a(this,void 0,void 0,(function*(){const r=E.prepareSignSerialized(e,t),i=yield this.Exchange((0,x.getBuffer)(r));let a=Buffer.from(E.resolveSignature(i),"hex");return a=p.ETHTransactionBuilder.deserialize((0,x.getBuffer)(t)).getSignature(a),{raw_tx:E.resolveTransaction(i,t),signature:`0x${a.toString("hex")}`}}));if("string"==typeof t){if(t.match(x.base64_regexp))return i();const a=((0,d.isJsonString)(t)?E.prepareSignTypedData:E.prepareSignMessage)(e,t),n=yield this.Exchange((0,x.getBuffer)(a));return{raw_tx:void 0,signature:`0x${E.resolveSignatureEIP155(n,r)}`}}if(Buffer.isBuffer(t))return i();let n=E.prepareSignEIP155;"boolean"==typeof r&&r&&(n=E.prepareSignWalletConnectTransaction),(t.accessList||t.maxPriorityFeePerGas||t.maxFeePerGas)&&(n=E.prepareSignEIP1559);const{commandData:o,rawTx:u}=n(e,t),s=yield this.Exchange((0,x.getBuffer)(o));let c=Buffer.from(E.resolveSignature(s),"hex");return c=p.ETHTransactionBuilder.deserialize((0,x.getBuffer)(u)).getSignature(c),{raw_tx:E.resolveTransaction(s,u),signature:`0x${c.toString("hex")}`}}))}}function b(e,t,r){var i;(0,s.default)(e,m),void 0===r&&(r=void 0===t.tx.value||"0"==t.tx.value?f.TransactionType.TOKEN:f.TransactionType.NORMAL);return{commandData:l.SecuxTransactionTool.signRawTransaction(e,t.serialize(),{tp:r,curve:f.EllipticCurve.SECP256K1,chainId:null!==(i=t.tx.chainId)&&void 0!==i?i:1}),rawTx:(0,x.toCommunicationData)(t.serialize())}}exports.SecuxETH=E,E.ERC20=h.ERC20,E.ERC721=v.ERC721,E.ERC1155=y.ERC1155,E.prepareAddress=E.preparePublickey,(0,S.loadPlugin)(E,"SecuxETH"),exports.prepareSign=b;
"use strict";var e=this&&this.__awaiter||function(e,t,r,i){return new(r||(r=Promise))((function(a,n){function o(e){try{s(i.next(e))}catch(e){n(e)}}function u(e){try{s(i.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,u)}s((i=i.apply(e,t||[])).next())}))},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.prepareSign=exports.SecuxETH=void 0;const r=require("js-sha3"),i=require("secp256k1/elliptic"),a=t(require("ow")),n=require("@secux/utility"),o=require("@secux/protocol-transaction"),u=require("@secux/protocol-transaction/lib/interface"),s=require("./interface"),c=require("./transaction"),l=require("eth-sig-util"),f=require("@secux/utility/lib/communication"),d=require("./erc20"),p=require("./erc721"),g=require("./erc1155"),x=null===n.Logger||void 0===n.Logger?void 0:n.Logger.child({id:"ethereum"}),h=(0,n.ow_strictPath)(60,44);class S{static addressConvert(e){const t=function(e){(0,a.default)(e,a.default.any(n.owTool.hexString,a.default.buffer));const t="string"==typeof e?Buffer.from(e,"hex"):e;if((0,a.default)(t,a.default.buffer.is((e=>33===e.length||65===e.length))),!i.publicKeyVerify(t))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${t.toString("hex")}"`);return t}(e),o=i.publicKeyConvert(t,!1),u=function(e){e=e.toLowerCase().replace(/^0x/,"");const t=(0,r.keccak256)(e);let i="0x";for(let r=0;r<e.length;r++)parseInt(t[r],16)>=8?i+=e[r].toUpperCase():i+=e[r];return i}((0,r.keccak256)(o.slice(1)).slice(-40));return u}static prepareAddress(e){return this.preparePublickey(e)}static resolveAddress(e){(0,a.default)(e,f.ow_communicationData);const t=S.resolvePublickey(e);return S.addressConvert(t)}static preparePublickey(e){return(0,a.default)(e,h),o.SecuxTransactionTool.getPublickey(e,u.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=o.SecuxTransactionTool.resolvePublickey(e,u.EllipticCurve.SECP256K1);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,a.default)(e,h),o.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,a.default)(t,h),o.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSignSerialized(e,t){(0,a.default)(t,f.ow_communicationData);const r=(0,f.getBuffer)(t);null==x||x.debug(`- prepareSignSerialized\ninput serialized tx: ${r.toString("hex")}`);const i=c.ETHTransactionBuilder.deserialize(r);return(0,a.default)(i.tx.to,s.ow_address),y(e,i).commandData}static resolveSignature(e){return Buffer.from(o.SecuxTransactionTool.resolveSignature(e),"base64").toString("hex")}static resolveTransaction(e,t){(0,a.default)(e,f.ow_communicationData),(0,a.default)(t,f.ow_communicationData);const r=(0,f.getBuffer)(t),i=c.ETHTransactionBuilder.deserialize(r),n=Buffer.from(S.resolveSignature(e),"hex");return null==x||x.debug(`- resolveTransaction\ninput serialized tx: ${r.toString("hex")}`),`0x${i.withSignature(n).toString("hex")}`}static prepareSignEIP155(e,t){(0,a.default)(t,s.ow_tx155);return y(e,(0,c.getBuilder)(t))}static resolveSignatureEIP155(e,t){(0,a.default)(e,f.ow_communicationData),(0,a.default)(t,a.default.optional.number.positive);const r=Buffer.from(S.resolveSignature(e),"hex"),i=r[64];return void 0===t?r.writeUInt8(27+i,64):r.writeUInt8(35+2*t+i,64),r.toString("hex")}static prepareSignEIP1559(e,t){(0,a.default)(t,s.ow_tx1559);return y(e,(0,c.getBuilder)(t))}static prepareSignMessage(e,t){let r;return(0,a.default)(e,h),(0,a.default)(t,a.default.any(a.default.string.nonEmpty,a.default.buffer)),"string"==typeof t&&(r=t.startsWith("0x")?Buffer.from(t.slice(2),"hex"):Buffer.from(t)),o.SecuxTransactionTool.signMessage(e,null!=r?r:t)}static prepareSignTypedData(e,t){(0,a.default)(e,h);const r=JSON.parse(t);(0,a.default)(r,a.default.any(s.ow_EIP712TypedData,s.ow_TypedMessage));const i=l.TypedDataUtils.sanitizeData(r),n=[];n.push(l.TypedDataUtils.hashStruct("EIP712Domain",i.domain,i.types,!0)),"EIP712Domain"!==i.primaryType&&n.push(l.TypedDataUtils.hashStruct(i.primaryType.toString(),i.message,i.types,!0));const u=Buffer.concat(n);return o.SecuxTransactionTool.signTypedMessage(e,u)}static prepareSignWalletConnectTransaction(e,t){(0,a.default)(e,h),(0,a.default)(t,a.default.any(s.ow_tx155,s.ow_tx1559));const r=(0,c.getBuilder)(t),i=r.serialize(!0),n=o.SecuxTransactionTool.signTransaction(e,i,{tp:u.TransactionType.NORMAL,curve:u.EllipticCurve.SECP256K1,chainId:t.chainId});return(0,f.wrapResult)({commandData:n,rawTx:(0,f.toCommunicationData)(r.serialize())})}static getAddress(t){return e(this,void 0,void 0,(function*(){const e=S.prepareAddress(t),r=yield this.Exchange((0,f.getBuffer)(e));return S.resolveAddress(r)}))}static getPublickey(t){return e(this,void 0,void 0,(function*(){const e=S.preparePublickey(t),r=yield this.Exchange((0,f.getBuffer)(e));return S.resolvePublickey(r)}))}static getXPublickey(t){return e(this,void 0,void 0,(function*(){const e=S.prepareXPublickey(t),r=yield this.Exchange((0,f.getBuffer)(e));return S.resolveXPublickey(r,t)}))}static sign(t,r,i){return e(this,void 0,void 0,(function*(){const a=()=>e(this,void 0,void 0,(function*(){const e=S.prepareSignSerialized(t,r),i=yield this.Exchange((0,f.getBuffer)(e));let a=Buffer.from(S.resolveSignature(i),"hex");return a=c.ETHTransactionBuilder.deserialize((0,f.getBuffer)(r)).getSignature(a),{raw_tx:S.resolveTransaction(i,r),signature:`0x${a.toString("hex")}`}}));if("string"==typeof r){if(r.match(f.base64_regexp))return a();const e=((0,s.isJsonString)(r)?S.prepareSignTypedData:S.prepareSignMessage)(t,r),n=yield this.Exchange((0,f.getBuffer)(e));return{raw_tx:void 0,signature:`0x${S.resolveSignatureEIP155(n,i)}`}}if(Buffer.isBuffer(r))return a();let n=S.prepareSignEIP155;"boolean"==typeof i&&i&&(n=S.prepareSignWalletConnectTransaction),(r.accessList||r.maxPriorityFeePerGas||r.maxFeePerGas)&&(n=S.prepareSignEIP1559);const{commandData:o,rawTx:u}=n(t,r),l=yield this.Exchange((0,f.getBuffer)(o));let d=Buffer.from(S.resolveSignature(l),"hex");return d=c.ETHTransactionBuilder.deserialize((0,f.getBuffer)(u)).getSignature(d),{raw_tx:S.resolveTransaction(l,u),signature:`0x${d.toString("hex")}`}}))}}function y(e,t,r){var i;(0,a.default)(e,h),void 0===r&&(r=void 0===t.tx.value||"0"==t.tx.value?u.TransactionType.TOKEN:u.TransactionType.NORMAL);const n=o.SecuxTransactionTool.signRawTransaction(e,t.serialize(),{tp:r,curve:u.EllipticCurve.SECP256K1,chainId:null!==(i=t.tx.chainId)&&void 0!==i?i:1});return(0,f.wrapResult)({commandData:n,rawTx:(0,f.toCommunicationData)(t.serialize())})}exports.SecuxETH=S,S.ERC20=d.ERC20,S.ERC721=p.ERC721,S.ERC1155=g.ERC1155,(0,n.loadPlugin)(S,"SecuxETH"),exports.prepareSign=y;

@@ -17,3 +17,3 @@ /// <reference types="node" />

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -32,3 +32,3 @@ /**

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -35,0 +35,0 @@ }

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

"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc1155_def=exports.ERC1155=void 0;const a=require("@ethersproject/abi"),r=require("./app-eth"),t=e(require("ow")),d=require("./interface"),s=require("./transaction"),n=require("@secux/utility");exports.ERC1155=class{static prepareSafeTransferFrom(e,a,n){var i;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,o);const u=exports.erc1155_def.encodeFunctionData("safeTransferFrom",[n.fromAddress,n.toAddress,n.id,n.value,null!==(i=n.data)&&void 0!==i?i:Buffer.alloc(0)]),l=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:u}));return(0,r.prepareSign)(e,l)}static prepareSafeBatchTransferFrom(e,a,n){var o;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,u);const i=[...n.items].sort(((e,a)=>{const r=l(e.id)-l(a.id);if(0===r)throw Error(`ArgumentError: duplicate id found, got "${l(e.id)}"`);return r})),f=exports.erc1155_def.encodeFunctionData("safeBatchTransferFrom",[n.fromAddress,n.toAddress,i.map((e=>e.id)),i.map((e=>e.value)),null!==(o=n.data)&&void 0!==o?o:Buffer.alloc(0)]),c=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:f}));return(0,r.prepareSign)(e,c)}},exports.erc1155_def=new a.Interface(["function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data)","function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data)","function balanceOf(address _owner, uint256 _id) external view returns (uint256)","function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory)","function setApprovalForAll(address _operator, bool _approved)","function isApprovedForAll(address _owner, address _operator) external view returns (bool)","event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value)","event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values)","event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)","event URI(string _value, uint256 indexed _id)","function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4)","function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external returns(bytes4)"]);const o=t.default.object.exactShape({fromAddress:d.ow_address,toAddress:d.ow_address,id:t.default.any(t.default.number.positive,d.ow_hexString32),value:t.default.any(t.default.number.positive,d.ow_hexString32),data:t.default.any(t.default.undefined,n.ow_prefixedhexString,t.default.buffer)}),i=t.default.object.exactShape({id:t.default.any(t.default.number.positive,d.ow_hexString32),value:t.default.any(t.default.number.positive,d.ow_hexString32)}),u=t.default.object.exactShape({fromAddress:d.ow_address,toAddress:d.ow_address,items:t.default.array.ofType(i),data:t.default.any(t.default.undefined,n.ow_prefixedhexString,t.default.buffer)});function l(e){return"number"==typeof e?e:parseInt(e.slice(2),16)}
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc1155_def=exports.ERC1155=void 0;const a=require("@ethersproject/abi"),r=require("./app-eth"),t=e(require("ow")),d=require("./interface"),s=require("./transaction"),n=require("@secux/utility");exports.ERC1155=class{static prepareSafeTransferFrom(e,a,n){var i;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,o);const u=exports.erc1155_def.encodeFunctionData("safeTransferFrom",[n.fromAddress,n.toAddress,n.id,n.value,null!==(i=n.data)&&void 0!==i?i:Buffer.alloc(0)]),l=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:u}));return(0,r.prepareSign)(e,l)}static prepareSafeBatchTransferFrom(e,a,n){var o;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,u);const i=[...n.items].sort(((e,a)=>{const r=l(e.id)-l(a.id);if(0===r)throw Error(`ArgumentError: duplicate id found, got "${l(e.id)}"`);return r})),f=exports.erc1155_def.encodeFunctionData("safeBatchTransferFrom",[n.fromAddress,n.toAddress,i.map((e=>e.id)),i.map((e=>e.value)),null!==(o=n.data)&&void 0!==o?o:Buffer.alloc(0)]),c=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:f}));return(0,r.prepareSign)(e,c)}},exports.erc1155_def=new a.Interface(["function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data)","function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data)","function balanceOf(address _owner, uint256 _id) external view returns (uint256)","function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory)","function setApprovalForAll(address _operator, bool _approved)","function isApprovedForAll(address _owner, address _operator) external view returns (bool)","event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value)","event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values)","event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)","event URI(string _value, uint256 indexed _id)","function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes calldata _data) external returns(bytes4)","function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external returns(bytes4)"]);const o=t.default.object.exactShape({fromAddress:d.ow_address,toAddress:d.ow_address,id:t.default.any(t.default.number.positive,d.ow_hexString32),value:t.default.any(t.default.number.positive,d.ow_hexString32),data:t.default.any(t.default.undefined,n.owTool.prefixedhexString,t.default.buffer)}),i=t.default.object.exactShape({id:t.default.any(t.default.number.positive,d.ow_hexString32),value:t.default.any(t.default.number.positive,d.ow_hexString32)}),u=t.default.object.exactShape({fromAddress:d.ow_address,toAddress:d.ow_address,items:t.default.array.ofType(i),data:t.default.any(t.default.undefined,n.owTool.prefixedhexString,t.default.buffer)});function l(e){return"number"==typeof e?e:parseInt(e.slice(2),16)}

@@ -1,2 +0,1 @@

/// <reference types="node" />
import { Interface } from "@ethersproject/abi";

@@ -17,3 +16,3 @@ import { baseData, PrefixedHexString } from "./interface";

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -32,3 +31,3 @@ /**

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -47,3 +46,3 @@ /**

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -50,0 +49,0 @@ }

@@ -17,3 +17,3 @@ /// <reference types="node" />

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -32,3 +32,3 @@ /**

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -47,3 +47,3 @@ /**

commandData: import("@secux/utility/lib/communication").communicationData;
rawTx: string | Buffer;
rawTx: import("@secux/utility/lib/communication").communicationData;
};

@@ -50,0 +50,0 @@ }

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

"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc721_def=exports.ERC721=void 0;const t=require("@ethersproject/abi"),r=require("./app-eth"),n=e(require("ow")),a=require("./interface"),s=require("./transaction"),d=require("@secux/utility"),o=require("@secux/protocol-transaction/lib/interface");exports.ERC721=class{static prepareSafeTransferFrom(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,f);const i=d.data?exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)",[d.fromAddress,d.toAddress,d.tokenId,d.data]):exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId)",[d.fromAddress,d.toAddress,d.tokenId]),u=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,u,o.TransactionType.NFT)}static prepareTransferFrom(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,u);const i=exports.erc721_def.encodeFunctionData("transferFrom",[d.fromAddress,d.toAddress,d.tokenId]),f=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,f,o.TransactionType.NFT)}static prepareApprove(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,c);const i=exports.erc721_def.encodeFunctionData("approve",[d.toAddress,d.tokenId]),u=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,u,o.TransactionType.NFT)}},exports.erc721_def=new t.Interface(["function balanceOf(address _owner) external view returns (uint256)","function ownerOf(uint256 _tokenId) external view returns (address)","function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable","function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable","function transferFrom(address _from, address _to, uint256 _tokenId) external payable","function approve(address _approved, uint256 _tokenId) external payable","function setApprovalForAll(address _operator, bool _approved) external","function getApproved(uint256 _tokenId) external view returns (address)","function isApprovedForAll(address _owner, address _operator) external view returns (bool)","function supportsInterface(bytes4 interfaceID) external view returns (bool)","function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4)","event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)","event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)","event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)","function name() external view returns (string _name)","function symbol() external view returns (string _symbol)","function tokenURI(uint256 _tokenId) external view returns (string)","function totalSupply() external view returns (uint256)","function tokenByIndex(uint256 _index) external view returns (uint256)","function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256)"]);const i={fromAddress:a.ow_address,toAddress:a.ow_address,tokenId:n.default.any(n.default.number.positive,a.ow_hexString32)},u=n.default.object.exactShape(i),f=n.default.object.exactShape(Object.assign(Object.assign({},i),{data:n.default.any(n.default.undefined,d.ow_prefixedhexString,n.default.buffer)})),c=n.default.object.exactShape({toAddress:a.ow_address,tokenId:n.default.any(n.default.number.positive,a.ow_hexString32)});
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc721_def=exports.ERC721=void 0;const t=require("@ethersproject/abi"),r=require("./app-eth"),n=e(require("ow")),a=require("./interface"),s=require("./transaction"),d=require("@secux/utility"),o=require("@secux/protocol-transaction/lib/interface");exports.ERC721=class{static prepareSafeTransferFrom(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,f);const i=d.data?exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)",[d.fromAddress,d.toAddress,d.tokenId,d.data]):exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId)",[d.fromAddress,d.toAddress,d.tokenId]),u=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,u,o.TransactionType.NFT)}static prepareTransferFrom(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,u);const i=exports.erc721_def.encodeFunctionData("transferFrom",[d.fromAddress,d.toAddress,d.tokenId]),f=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,f,o.TransactionType.NFT)}static prepareApprove(e,t,d){(0,n.default)(t,a.ow_baseData),(0,n.default)(d,c);const i=exports.erc721_def.encodeFunctionData("approve",[d.toAddress,d.tokenId]),u=(0,s.getBuilder)(Object.assign(Object.assign({},t),{data:i}));return(0,r.prepareSign)(e,u,o.TransactionType.NFT)}},exports.erc721_def=new t.Interface(["function balanceOf(address _owner) external view returns (uint256)","function ownerOf(uint256 _tokenId) external view returns (address)","function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable","function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable","function transferFrom(address _from, address _to, uint256 _tokenId) external payable","function approve(address _approved, uint256 _tokenId) external payable","function setApprovalForAll(address _operator, bool _approved) external","function getApproved(uint256 _tokenId) external view returns (address)","function isApprovedForAll(address _owner, address _operator) external view returns (bool)","function supportsInterface(bytes4 interfaceID) external view returns (bool)","function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4)","event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)","event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)","event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)","function name() external view returns (string _name)","function symbol() external view returns (string _symbol)","function tokenURI(uint256 _tokenId) external view returns (string)","function totalSupply() external view returns (uint256)","function tokenByIndex(uint256 _index) external view returns (uint256)","function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256)"]);const i={fromAddress:a.ow_address,toAddress:a.ow_address,tokenId:n.default.any(n.default.number.positive,a.ow_hexString32)},u=n.default.object.exactShape(i),f=n.default.object.exactShape(Object.assign(Object.assign({},i),{data:n.default.any(n.default.undefined,d.owTool.prefixedhexString,n.default.buffer)})),c=n.default.object.exactShape({toAddress:a.ow_address,tokenId:n.default.any(n.default.number.positive,a.ow_hexString32)});

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

"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.isJsonString=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_baseData=exports.ow_tx1559=exports.ow_tx1559_base=exports.ow_tx155=exports.ow_tx155_base=exports.ow_gasPriceUnit=exports.ow_hexString32=exports.ow_address=void 0;const o=r(require("ow")),i=a(require("@secux/utility")),n=require("wallet-address-validator").validate;exports.ow_address=o.default.string.matches(/^0x[0-9A-fa-f]{40}$/).validate((e=>({validator:n(e,"ETH"),message:`ArgumentError: invalid address, got "${e}"`}))),exports.ow_hexString32=o.default.string.matches(/^0x[a-fA-F0-9]{1,64}$/),exports.ow_gasPriceUnit=o.default.any(o.default.number.uint32.greaterThanOrEqual(1e9),i.ow_prefixedhexString);const s={chainId:o.default.number.positive,nonce:o.default.any(o.default.number,i.ow_prefixedhexString),gasPrice:exports.ow_gasPriceUnit,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)};exports.ow_tx155_base=o.default.object.partialShape(s),exports.ow_tx155=o.default.object.exactShape(Object.assign(Object.assign({},s),{data:o.default.any(o.default.undefined,i.ow_prefixedhexString)}));const d={chainId:o.default.number.positive,nonce:o.default.any(o.default.number,i.ow_prefixedhexString),maxPriorityFeePerGas:exports.ow_gasPriceUnit,maxFeePerGas:exports.ow_gasPriceUnit,gasLimit:o.default.any(o.default.number.positive,i.ow_prefixedhexString),to:exports.ow_address,value:o.default.any(o.default.undefined,o.default.number.not.negative,i.ow_prefixedhexString),accessList:o.default.any(o.default.undefined,o.default.array.ofType(o.default.any()))};exports.ow_tx1559_base=o.default.object.partialShape(d),exports.ow_tx1559=o.default.object.exactShape(Object.assign(Object.assign({},d),{data:o.default.any(o.default.undefined,i.ow_prefixedhexString)})),exports.ow_baseData=o.default.any(exports.ow_tx155_base,exports.ow_tx1559_base),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.isJsonString=function(e){try{JSON.parse(e)}catch(e){return!1}return!0};
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isJsonString=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_baseData=exports.ow_tx1559=exports.ow_tx1559_base=exports.ow_tx155=exports.ow_tx155_base=exports.ow_gasPriceUnit=exports.ow_hexString32=exports.ow_address=void 0;const t=e(require("ow")),a=require("@secux/utility"),o=require("wallet-address-validator").validate;exports.ow_address=t.default.string.matches(/^0x[0-9A-fa-f]{40}$/).validate((e=>({validator:o(e,"ETH"),message:`ArgumentError: invalid address, got "${e}"`}))),exports.ow_hexString32=t.default.string.matches(/^0x[a-fA-F0-9]{1,64}$/),exports.ow_gasPriceUnit=t.default.any(t.default.number.uint32.greaterThanOrEqual(1e9),a.owTool.prefixedhexString);const r={chainId:t.default.number.positive,nonce:t.default.any(t.default.number,a.owTool.prefixedhexString),gasPrice:exports.ow_gasPriceUnit,gasLimit:t.default.any(t.default.number.positive,a.owTool.prefixedhexString),to:exports.ow_address,value:t.default.any(t.default.number.not.negative,a.owTool.prefixedhexString)};exports.ow_tx155_base=t.default.object.partialShape(r),exports.ow_tx155=t.default.object.exactShape(Object.assign(Object.assign({},r),{data:t.default.any(t.default.undefined,a.owTool.prefixedhexString)}));const s={chainId:t.default.number.positive,nonce:t.default.any(t.default.number,a.owTool.prefixedhexString),maxPriorityFeePerGas:t.default.any(t.default.number.uint32.positive,a.owTool.prefixedhexString),maxFeePerGas:exports.ow_gasPriceUnit,gasLimit:t.default.any(t.default.number.positive,a.owTool.prefixedhexString),to:exports.ow_address,value:t.default.any(t.default.undefined,t.default.number.not.negative,a.owTool.prefixedhexString),accessList:t.default.any(t.default.undefined,t.default.array.ofType(t.default.any()))};exports.ow_tx1559_base=t.default.object.partialShape(s),exports.ow_tx1559=t.default.object.exactShape(Object.assign(Object.assign({},s),{data:t.default.any(t.default.undefined,a.owTool.prefixedhexString)})),exports.ow_baseData=t.default.any(exports.ow_tx155_base,exports.ow_tx1559_base),exports.ow_EIP712TypedData=t.default.object.exactShape({name:t.default.string,type:t.default.string}),exports.ow_TypedMessage=t.default.object.exactShape({types:t.default.object.valuesOfType(t.default.array.ofType(exports.ow_EIP712TypedData)),primaryType:t.default.string,domain:t.default.object.exactShape({name:t.default.optional.string,version:t.default.optional.string,chainId:t.default.optional.number.not.negative,verifyingContract:t.default.optional.string}),message:t.default.object}),exports.isJsonString=function(e){try{JSON.parse(e)}catch(e){return!1}return!0};

@@ -22,2 +22,3 @@ /// <reference types="node" />

protected prepare(): any[];
protected verify(data: Buffer): boolean;
get tx(): any;

@@ -24,0 +25,0 @@ }

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

"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(i,e,n);return r(i,e),i},n=this&&this.__classPrivateFieldSet||function(e,t,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(e,r):n?n.value=r:t.set(e,r),r},a=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)},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EIP1559Builder=exports.ETHTransactionBuilder=exports.getBuilder=void 0;const o=require("js-sha3"),c=i(require("rlp")),u=s(require("ow")),l=require("./interface"),f=Buffer.from([2]);exports.getBuilder=function(e){try{return(0,u.default)(e,l.ow_tx1559),new d(e)}catch(e){}return new h(e)};class h{constructor(t){if(e.set(this,void 0),n(this,e,t,"f"),"string"==typeof t.chainId&&(a(this,e,"f").chainId=parseInt(t.chainId.slice(2),16)),t.gasPrice){const e=w(t.gasPrice);if(e<1e9)throw Error(`Minimal gas price is 1 Gwei, but got ${e/1e9} Gwei.`)}if(t.maxPriorityFeePerGas){const e=w(t.maxPriorityFeePerGas);if(e<1e9)throw Error(`[maxPriorityFeePerGas] Minimal priority fee is 1 Gwei, but got ${e/1e9} Gwei.`)}if(t.maxFeePerGas){const e=w(t.maxFeePerGas);if(e<1e9)throw Error(`[maxFeePerGas] Minimal fee is 1 Gwei, but got ${e/1e9} Gwei.`)}let r=21e3;t.data&&("string"==typeof t.data?r+=68*(t.data.length/2-1):r+=68*t.data.length);const i=w(t.gasLimit);if(i<r)throw Error(`Minimal gas is ${r}, but got ${i}.`)}static deserialize(e){if(e[0]>=192){const t=c.decode(e);if(!Array.isArray(t))throw new Error("Invalid serialized tx input. Must be array");if(6!==t.length&&9!==t.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 6 values (legacy) or 9 values (EIP155).");const[r,i,n,a,s,o,u,l,f]=t;let d;return 0!==u&&27!==u&&28!==u&&(d=u),new h({nonce:r,gasPrice:i,gasLimit:n,to:a,value:s,data:o,chainId:d})}if(e[0]<=127){const t=c.decode(e.slice(1));if(!Array.isArray(t))throw new Error("Invalid serialized tx input. Must be array");if(9!==t.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 9 values (EIP1559).");const[r,i,n,a,s,o,u,l]=t;return new d({chainId:r,nonce:i,maxPriorityFeePerGas:n,maxFeePerGas:a,gasLimit:s,to:o,value:u,data:l})}throw Error(`Invalid serialized tx input, got "${e.toString("hex")}"`)}serialize(t=!1){var r;const i=[...this.prepare(),g(null!==(r=a(this,e,"f").chainId)&&void 0!==r?r:0),0,0],n=c.encode(i);return t?Buffer.from(o.keccak256.update(n).digest()):n}withSignature(e){e=this.getSignature(e);const t=[...this.prepare(),g(e.slice(64)),p(e.slice(0,32)),p(e.slice(32,64))];return c.encode(t)}getSignature(t){var r;const i=parseInt(Buffer.from(null!==(r=a(this,e,"f").chainId)&&void 0!==r?r:[0]).toString("hex"),16),n=i>0?2*i+35:27;let s=(t[64]+n).toString(16);s.length%2!=0&&(s=`0${s}`);const o=Buffer.from(s,"hex");return Buffer.concat([t.slice(0,64),o])}prepare(){var t;return[g(a(this,e,"f").nonce),g(a(this,e,"f").gasPrice),g(a(this,e,"f").gasLimit),a(this,e,"f").to,g(a(this,e,"f").value),null!==(t=a(this,e,"f").data)&&void 0!==t?t:""]}get tx(){return a(this,e,"f")}}exports.ETHTransactionBuilder=h,e=new WeakMap;class d extends h{serialize(e=!1){const t=this.prepare(),r=Buffer.concat([f,c.encode(t)]);return e?Buffer.from(o.keccak256.update(r).digest()):r}withSignature(e){const t=[...this.prepare(),g(e[64]),p(e.slice(0,32)),p(e.slice(32,64))],r=c.encode(t);return Buffer.concat([f,r])}getSignature(e){return e}prepare(){var e,t;return[g(this.tx.chainId),g(this.tx.nonce),g(this.tx.maxPriorityFeePerGas),g(this.tx.maxFeePerGas),g(this.tx.gasLimit),this.tx.to,g(this.tx.value),null!==(e=this.tx.data)&&void 0!==e?e:"",null!==(t=this.tx.accessList)&&void 0!==t?t:[]]}}function g(e){if("string"==typeof e){if(e.startsWith("0x")&&function(e){let t=e.startsWith("0x")?e.slice(2):e;const r=/^[0-9a-fA-F]+$/;return t=t.length%2==0?t:`0${t}`,r.test(t)}(e))return"0x0"==e||"0x00"==e?0:e;throw Error("Invalid handleRLPValue string")}return e}function p(e){var t;const r=(null!==(t=e.toString("hex").match(/^(00)+/g))&&void 0!==t?t:[""])[0].length/2;return e.slice(r)}function w(e){return"number"==typeof e?e:"string"==typeof e?e.startsWith("0x")?parseInt(e.slice(2),16):parseInt(e,10):Buffer.from(e).readUIntBE(0,e.length)}exports.EIP1559Builder=d;
"use strict";var e,t=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&t(i,e,n);return r(i,e),i},n=this&&this.__classPrivateFieldSet||function(e,t,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(e,r):n?n.value=r:t.set(e,r),r},a=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)},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EIP1559Builder=exports.ETHTransactionBuilder=exports.getBuilder=void 0;const o=require("secp256k1/elliptic"),c=require("js-sha3"),u=i(require("rlp")),l=require("bignumber.js"),f=s(require("ow")),h=require("./interface"),d=Buffer.from([2]);exports.getBuilder=function(e){try{return(0,f.default)(e,h.ow_tx1559),new p(e)}catch(e){}return new g(e)};class g{constructor(t){if(e.set(this,void 0),n(this,e,t,"f"),"string"==typeof t.chainId&&(a(this,e,"f").chainId=parseInt(t.chainId.slice(2),16)),t.gasPrice){const e=x(t.gasPrice);if(e.lt(1e9))throw Error(`Minimal gas price is 1 Gwei, but got ${e.div(1e9).toString()} Gwei.`)}if(t.maxPriorityFeePerGas){if(x(t.maxPriorityFeePerGas).lt(1))throw Error("[maxPriorityFeePerGas] Minimal priority fee is 1 wei.")}if(t.maxFeePerGas){const e=x(t.maxFeePerGas);if(e.lt(1e9))throw Error(`[maxFeePerGas] Minimal fee is 1 Gwei, but got ${e.div(1e9).toString()} Gwei.`)}let r=21e3;t.data&&("string"==typeof t.data?r+=68*(t.data.length/2-1):r+=68*t.data.length);const i=x(t.gasLimit);if(i.lt(r))throw Error(`Minimal gas is ${r}, but got ${i.toString()}.`)}static deserialize(e){if(e[0]>=192){const t=u.decode(e);if(!Array.isArray(t))throw new Error("Invalid serialized tx input. Must be array");if(6!==t.length&&9!==t.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 6 values (legacy) or 9 values (EIP155).");const[r,i,n,a,s,o,c,l,f]=t;let h;return 0!==c&&27!==c&&28!==c&&(h=c),new g({nonce:r,gasPrice:i,gasLimit:n,to:a,value:s,data:o,chainId:h})}if(e[0]<=127){const t=u.decode(e.slice(1));if(!Array.isArray(t))throw new Error("Invalid serialized tx input. Must be array");if(9!==t.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 9 values (EIP1559).");const[r,i,n,a,s,o,c,l]=t;return new p({chainId:r,nonce:i,maxPriorityFeePerGas:n,maxFeePerGas:a,gasLimit:s,to:o,value:c,data:l})}throw Error(`Invalid serialized tx input, got "${e.toString("hex")}"`)}serialize(t=!1){var r;const i=[...this.prepare(),w(null!==(r=a(this,e,"f").chainId)&&void 0!==r?r:0),0,0],n=u.encode(i);return t?Buffer.from(c.keccak256.update(n).digest()):n}withSignature(e){if(!this.verify(e))throw Error("invalid signature");e=this.getSignature(e);const t=[...this.prepare(),w(e.slice(64)),v(e.slice(0,32)),v(e.slice(32,64))];return u.encode(t)}getSignature(t){var r;const i=parseInt(Buffer.from(null!==(r=a(this,e,"f").chainId)&&void 0!==r?r:[0]).toString("hex"),16),n=i>0?2*i+35:27;let s=(t[64]+n).toString(16);s.length%2!=0&&(s=`0${s}`);const o=Buffer.from(s,"hex");return Buffer.concat([t.slice(0,64),o])}prepare(){var t;return[w(a(this,e,"f").nonce),w(a(this,e,"f").gasPrice),w(a(this,e,"f").gasLimit),a(this,e,"f").to,w(a(this,e,"f").value),null!==(t=a(this,e,"f").data)&&void 0!==t?t:""]}verify(e){const t=e.slice(0,64);try{o.ecdsaRecover(t,e.readUint8(64),this.serialize(!0))}catch(e){return!1}return!0}get tx(){return a(this,e,"f")}}exports.ETHTransactionBuilder=g,e=new WeakMap;class p extends g{serialize(e=!1){const t=this.prepare(),r=Buffer.concat([d,u.encode(t)]);return e?Buffer.from(c.keccak256.update(r).digest()):r}withSignature(e){if(!this.verify(e))throw Error("invalid signature");const t=[...this.prepare(),w(e[64]),v(e.slice(0,32)),v(e.slice(32,64))],r=u.encode(t);return Buffer.concat([d,r])}getSignature(e){return e}prepare(){var e,t;return[w(this.tx.chainId),w(this.tx.nonce),w(this.tx.maxPriorityFeePerGas),w(this.tx.maxFeePerGas),w(this.tx.gasLimit),this.tx.to,w(this.tx.value),null!==(e=this.tx.data)&&void 0!==e?e:"",null!==(t=this.tx.accessList)&&void 0!==t?t:[]]}}function w(e){if("string"==typeof e){if(e.startsWith("0x")&&function(e){let t=e.startsWith("0x")?e.slice(2):e;const r=/^[0-9a-fA-F]+$/;return t=t.length%2==0?t:`0${t}`,r.test(t)}(e))return"0x0"==e||"0x00"==e?0:e;throw Error("Invalid handleRLPValue string")}return e}function v(e){var t;const r=(null!==(t=e.toString("hex").match(/^(00)+/g))&&void 0!==t?t:[""])[0].length/2;return e.slice(r)}function x(e){return"number"==typeof e?new l.BigNumber(e):"string"==typeof e?e.startsWith("0x")?new l.BigNumber(e.slice(2),16):new l.BigNumber(e):new l.BigNumber(Buffer.from(e).toString("hex"),16)}exports.EIP1559Builder=p;
{
"name": "@secux/app-eth",
"version": "3.0.3",
"version": "3.0.4",
"description": "SecuX Hardware Wallet ETH API",

@@ -28,6 +28,7 @@ "keywords": [

"build": "sh ../../build.sh",
"docs": "npx tsc && jsdoc2md --template ./README.hbs ./lib/app-eth.js > README.md",
"api-docs": "npx tsc && jsdoc2md --template ./api-docs.hbs ./lib/app-eth.js > app-eth.md",
"doc": "npx tsc && jsdoc2md --template ./README.hbs ./lib/app-eth.js > README.md",
"doc:api": "sh ../../api_doc.sh ./src/app-eth.ts ./lib/app-eth.js",
"test:webusb": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/usb.js",
"test:webble": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/ble.js",
"test:webhid": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/hid.js",
"test:virtual": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/virtual.js",

@@ -40,4 +41,3 @@ "tsc": "tsc",

"@secux/protocol-transaction": "^3.0.0",
"@secux/transport": "^3.0.1",
"@secux/utility": "^3.0.0",
"@secux/utility": "^3.0.6",
"eth-sig-util": "^3.0.1",

@@ -49,2 +49,5 @@ "js-sha3": "^0.8.0",

},
"peerDependencies": {
"@secux/transport": "^3.2.0"
},
"devDependencies": {

@@ -51,0 +54,0 @@ "@ethereumjs/common": "^2.4.0",

@@ -405,3 +405,3 @@ [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)

| path | <code>string</code> | m/44'/60'/... |
| message | <code>string</code> \| <code>Buffer</code> | |
| message | <code>string</code> | |

@@ -408,0 +408,0 @@ <br/>

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