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

@secux/app-eth

Package Overview
Dependencies
Maintainers
1
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.14 to 3.0.15

2

lib/app-eth.js

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/var e=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 t=require("js-sha3"),r=require("secp256k1/elliptic"),a=e(require("ow")),i=require("@secux/utility"),n=require("@secux/protocol-transaction"),o=require("@secux/protocol-transaction/lib/interface"),s=require("./interface"),u=require("./transaction"),c=require("eth-sig-util"),l=require("@secux/utility/lib/communication"),f=require("./erc20"),p=require("./erc721"),g=require("./erc1155"),d=require("@secux/transport"),x=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"ethereum"}),T=(0,i.ow_strictPath)(60,44),h={crypto:"2.12",nifty:"0.02.1"};class y{static addressConvert(e){const n=function(e){(0,a.default)(e,a.default.any(i.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))),!r.publicKeyVerify(t))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${t.toString("hex")}"`);return t}(e),o=r.publicKeyConvert(n,!1),s=function(e){e=e.toLowerCase().replace(/^0x/,"");const r=(0,t.keccak256)(e);let a="0x";for(let t=0;t<e.length;t++)parseInt(r[t],16)>=8?a+=e[t].toUpperCase():a+=e[t];return a}((0,t.keccak256)(o.slice(1)).slice(-40));return s}static prepareAddress(e){return this.preparePublickey(e)}static resolveAddress(e){(0,a.default)(e,l.ow_communicationData);const t=y.resolvePublickey(e);return y.addressConvert(t)}static preparePublickey(e){return(0,a.default)(e,T),n.SecuxTransactionTool.getPublickey(e,o.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=n.SecuxTransactionTool.resolvePublickey(e,o.EllipticCurve.SECP256K1);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,a.default)(e,T),n.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,a.default)(t,T),n.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSignSerialized(e,t,r){(0,a.default)(t,l.ow_communicationData);const i=(0,l.getBuffer)(t);null==x||x.debug(`- prepareSignSerialized\ninput serialized tx: ${i.toString("hex")}`);return S(e,u.ETHTransactionBuilder.deserialize(i),r).commandData}static resolveSignature(e){return Buffer.from(n.SecuxTransactionTool.resolveSignature(e),"base64").toString("hex")}static resolveTransaction(e,t){(0,a.default)(e,l.ow_communicationData),(0,a.default)(t,l.ow_communicationData);const r=(0,l.getBuffer)(t),i=u.ETHTransactionBuilder.deserialize(r),n=Buffer.from(y.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,r){(0,a.default)(t,s.ow_tx155);return S(e,(0,u.getBuilder)(t),r)}static resolveSignatureEIP155(e,t){(0,a.default)(e,l.ow_communicationData),(0,a.default)(t,a.default.optional.number.positive);const r=Buffer.from(y.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,r){(0,a.default)(t,s.ow_tx1559);return S(e,(0,u.getBuilder)(t),r)}static prepareSignMessage(e,t){let r;return(0,i.checkFWVersion)("mcu",h[d.ITransport.deviceType],d.ITransport.mcuVersion),(0,a.default)(e,T),(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)),n.SecuxTransactionTool.signMessage(e,null!=r?r:t)}static prepareSignTypedData(e,t){(0,i.checkFWVersion)("mcu",h[d.ITransport.deviceType],d.ITransport.mcuVersion),(0,a.default)(e,T),(0,a.default)(t,a.default.string);const r=JSON.parse(t),o=c.TypedDataUtils.sanitizeData(r),s=[];s.push(c.TypedDataUtils.hashStruct("EIP712Domain",o.domain,o.types,!0)),"EIP712Domain"!==o.primaryType&&s.push(c.TypedDataUtils.hashStruct(o.primaryType.toString(),o.message,o.types,!0));const u=Buffer.concat(s);return n.SecuxTransactionTool.signTypedMessage(e,u)}static prepareSignWalletConnectTransaction(e,t){(0,a.default)(e,T),(0,a.default)(t,a.default.any(s.ow_tx155,s.ow_tx1559));const r=(0,u.getBuilder)(t),i=r.chainId||1,c=n.SecuxTransactionTool.signTransaction(e,r.serialize(!0),{tp:o.TransactionType.NORMAL,curve:o.EllipticCurve.SECP256K1,chainId:i>65535?65535:i});return(0,l.wrapResult)({commandData:c,rawTx:(0,l.toCommunicationData)(r.serialize())})}static async getAddress(e){const t=y.prepareAddress(e),r=await this.Exchange((0,l.getBuffer)(t));return y.resolveAddress(r)}static async getPublickey(e){const t=y.preparePublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return y.resolvePublickey(r)}static async getXPublickey(e){const t=y.prepareXPublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return y.resolveXPublickey(r,e)}static async sign(e,t,r){const a=async()=>{const a=y.prepareSignSerialized(e,t,r),i=await this.Exchange((0,l.getBuffer)(a));let n=Buffer.from(y.resolveSignature(i),"hex");return n=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(t)).getSignature(n),{raw_tx:y.resolveTransaction(i,t),signature:`0x${n.toString("hex")}`}};if("string"==typeof t){if(t.match(l.base64_regexp))return a();const i=((0,s.isJsonString)(t)?y.prepareSignTypedData:y.prepareSignMessage)(e,t),n=await this.Exchange((0,l.getBuffer)(i));return{raw_tx:void 0,signature:`0x${y.resolveSignatureEIP155(n,r)}`}}if(Buffer.isBuffer(t))return a();let i=y.prepareSignEIP155;(t.accessList||t.maxPriorityFeePerGas||t.maxFeePerGas)&&(i=y.prepareSignEIP1559),"boolean"==typeof r&&r&&(i=y.prepareSignWalletConnectTransaction);const{commandData:n,rawTx:o}=i(e,t,r),c=await this.Exchange((0,l.getBuffer)(n));let f=Buffer.from(y.resolveSignature(c),"hex");return f=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(o)).getSignature(f),{raw_tx:y.resolveTransaction(c,o),signature:`0x${f.toString("hex")}`}}}function S(e,t,r){(0,i.checkFWVersion)("mcu",h[d.ITransport.deviceType],d.ITransport.mcuVersion),(0,a.default)(e,T),r||(r=t.tx.value?o.TransactionType.NORMAL:function(e){const t=Buffer.isBuffer(e)?e.toString("hex"):null==e?void 0:e.replace(/^0x/,"");if(!t)return!1;const r=["23b872dd","42842e0e","f242432a"];console.log(t);for(const e of r)if(t.startsWith(e))return!0;return!1}(t.tx.data)?o.TransactionType.NFT:o.TransactionType.TOKEN);const s=function(e){const t=[{identify:"a9059cbb",length:136},{identify:"23b872dd",length:200},{identify:"095ea7b3",length:136},{identify:"42842e0e",length:200},{identify:"f242432a",length:392}],r=Buffer.isBuffer(e)?e.toString("hex"):null==e?void 0:e.replace(/^0x/,"");if(!r)return!1;for(const e of t)if(r.startsWith(e.identify)&&r.length===e.length)return!1;return!0}(t.tx.data);s&&(r=o.TransactionType.NORMAL);const u={tp:r,curve:o.EllipticCurve.SECP256K1,chainId:t.chainId||1};u.chainId>65535&&(u.chainId=65535);const c=s?n.SecuxTransactionTool.signTransaction(e,t.serialize(!0),u):n.SecuxTransactionTool.signRawTransaction(e,t.serialize(),u);return(0,l.wrapResult)({commandData:c,rawTx:(0,l.toCommunicationData)(t.serialize())})}exports.SecuxETH=y,y.ERC20=f.ERC20,y.ERC721=p.ERC721,y.ERC1155=g.ERC1155,(0,i.loadPlugin)(y,"SecuxETH"),exports.prepareSign=S;
*/var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.prepareSign=exports.SecuxETH=void 0;const js_sha3_1=require("js-sha3"),secp256k1=require("secp256k1/elliptic"),ow_1=__importDefault(require("ow")),utility_1=require("@secux/utility"),protocol_transaction_1=require("@secux/protocol-transaction"),interface_1=require("@secux/protocol-transaction/lib/interface"),interface_2=require("./interface"),transaction_1=require("./transaction"),eth_sig_util_1=require("eth-sig-util"),communication_1=require("@secux/utility/lib/communication"),erc20_1=require("./erc20"),erc721_1=require("./erc721"),erc1155_1=require("./erc1155"),transport_1=require("@secux/transport"),logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"ethereum"}),ow_path=(0,utility_1.ow_strictPath)(60,44),mcu={crypto:"2.12",nifty:"0.02.1"};class SecuxETH{static addressConvert(publickey){const pk=function(data){(0,ow_1.default)(data,ow_1.default.any(utility_1.owTool.hexString,ow_1.default.buffer));const pk="string"==typeof data?Buffer.from(data,"hex"):data;if((0,ow_1.default)(pk,ow_1.default.buffer.is((x=>33===x.length||65===x.length))),!secp256k1.publicKeyVerify(pk))throw Error(`ArgumentError: invalid secp256k1 publickey, got "${pk.toString("hex")}"`);return pk}(publickey),uncompressed=secp256k1.publicKeyConvert(pk,!1),encodedAddr=function(address){address=address.toLowerCase().replace(/^0x/,"");const hash=(0,js_sha3_1.keccak256)(address);let ret="0x";for(let i=0;i<address.length;i++)parseInt(hash[i],16)>=8?ret+=address[i].toUpperCase():ret+=address[i];return ret}((0,js_sha3_1.keccak256)(uncompressed.slice(1)).slice(-40));return encodedAddr}static prepareAddress(path){return this.preparePublickey(path)}static resolveAddress(response){(0,ow_1.default)(response,communication_1.ow_communicationData);const pk=SecuxETH.resolvePublickey(response);return SecuxETH.addressConvert(pk)}static preparePublickey(path){return(0,ow_1.default)(path,ow_path),protocol_transaction_1.SecuxTransactionTool.getPublickey(path,interface_1.EllipticCurve.SECP256K1)}static resolvePublickey(response){const pk=protocol_transaction_1.SecuxTransactionTool.resolvePublickey(response,interface_1.EllipticCurve.SECP256K1);return Buffer.from(pk,"base64").toString("hex")}static prepareXPublickey(path){return(0,ow_1.default)(path,ow_path),protocol_transaction_1.SecuxTransactionTool.getXPublickey(path)}static resolveXPublickey(response,path){return(0,ow_1.default)(path,ow_path),protocol_transaction_1.SecuxTransactionTool.resolveXPublickey(response,path)}static prepareSignSerialized(path,serialized,txType){(0,ow_1.default)(serialized,communication_1.ow_communicationData);const buf=(0,communication_1.getBuffer)(serialized);null==logger||logger.debug(`- prepareSignSerialized\ninput serialized tx: ${buf.toString("hex")}`);return prepareSign(path,transaction_1.ETHTransactionBuilder.deserialize(buf),txType).commandData}static resolveSignature(response){return Buffer.from(protocol_transaction_1.SecuxTransactionTool.resolveSignature(response),"base64").toString("hex")}static resolveTransaction(response,serialized){(0,ow_1.default)(response,communication_1.ow_communicationData),(0,ow_1.default)(serialized,communication_1.ow_communicationData);const buf=(0,communication_1.getBuffer)(serialized),builder=transaction_1.ETHTransactionBuilder.deserialize(buf),signature=Buffer.from(SecuxETH.resolveSignature(response),"hex");return null==logger||logger.debug(`- resolveTransaction\ninput serialized tx: ${buf.toString("hex")}`),`0x${builder.withSignature(signature).toString("hex")}`}static prepareSignEIP155(path,content,txType){(0,ow_1.default)(content,interface_2.ow_tx155);return prepareSign(path,(0,transaction_1.getBuilder)(content),txType)}static resolveSignatureEIP155(response,chainId){(0,ow_1.default)(response,communication_1.ow_communicationData),(0,ow_1.default)(chainId,ow_1.default.optional.number.positive);const signature=Buffer.from(SecuxETH.resolveSignature(response),"hex"),v=signature[64];return void 0===chainId?signature.writeUInt8(27+v,64):signature.writeUInt8(35+2*chainId+v,64),signature.toString("hex")}static prepareSignEIP1559(path,content,txType){(0,ow_1.default)(content,interface_2.ow_tx1559);return prepareSign(path,(0,transaction_1.getBuilder)(content),txType)}static prepareSignMessage(path,message){let buffer;return(0,utility_1.checkFWVersion)("mcu",mcu[transport_1.ITransport.deviceType],transport_1.ITransport.mcuVersion),(0,ow_1.default)(path,ow_path),(0,ow_1.default)(message,ow_1.default.any(ow_1.default.string.nonEmpty,ow_1.default.buffer)),"string"==typeof message&&(buffer=message.startsWith("0x")?Buffer.from(message.slice(2),"hex"):Buffer.from(message)),protocol_transaction_1.SecuxTransactionTool.signMessage(path,null!=buffer?buffer:message)}static prepareSignTypedData(path,typedData){(0,utility_1.checkFWVersion)("mcu",mcu[transport_1.ITransport.deviceType],transport_1.ITransport.mcuVersion),(0,ow_1.default)(path,ow_path),(0,ow_1.default)(typedData,ow_1.default.string);const data=JSON.parse(typedData),sanitizedData=eth_sig_util_1.TypedDataUtils.sanitizeData(data),parts=[];parts.push(eth_sig_util_1.TypedDataUtils.hashStruct("EIP712Domain",sanitizedData.domain,sanitizedData.types,!0)),"EIP712Domain"!==sanitizedData.primaryType&&parts.push(eth_sig_util_1.TypedDataUtils.hashStruct(sanitizedData.primaryType.toString(),sanitizedData.message,sanitizedData.types,!0));const buf=Buffer.concat(parts);return protocol_transaction_1.SecuxTransactionTool.signTypedMessage(path,buf)}static prepareSignWalletConnectTransaction(path,content){(0,ow_1.default)(path,ow_path),(0,ow_1.default)(content,ow_1.default.any(interface_2.ow_tx155,interface_2.ow_tx1559));const builder=(0,transaction_1.getBuilder)(content),chainId=builder.chainId||1,data=protocol_transaction_1.SecuxTransactionTool.signTransaction(path,builder.serialize(!0),{tp:interface_1.TransactionType.NORMAL,curve:interface_1.EllipticCurve.SECP256K1,chainId:chainId>65535?65535:chainId});return(0,communication_1.wrapResult)({commandData:data,rawTx:(0,communication_1.toCommunicationData)(builder.serialize())})}static async getAddress(path){const buffer=SecuxETH.prepareAddress(path),response=await this.Exchange((0,communication_1.getBuffer)(buffer));return SecuxETH.resolveAddress(response)}static async getPublickey(path){const buffer=SecuxETH.preparePublickey(path),response=await this.Exchange((0,communication_1.getBuffer)(buffer));return SecuxETH.resolvePublickey(response)}static async getXPublickey(path){const buffer=SecuxETH.prepareXPublickey(path),response=await this.Exchange((0,communication_1.getBuffer)(buffer));return SecuxETH.resolveXPublickey(response,path)}static async sign(path,args,option){const signSerialized=async()=>{const data=SecuxETH.prepareSignSerialized(path,args,option),rsp=await this.Exchange((0,communication_1.getBuffer)(data));let signature=Buffer.from(SecuxETH.resolveSignature(rsp),"hex");return signature=transaction_1.ETHTransactionBuilder.deserialize((0,communication_1.getBuffer)(args)).getSignature(signature),{raw_tx:SecuxETH.resolveTransaction(rsp,args),signature:`0x${signature.toString("hex")}`}};if("string"==typeof args){if(args.match(communication_1.base64_regexp))return signSerialized();const data=((0,interface_2.isJsonString)(args)?SecuxETH.prepareSignTypedData:SecuxETH.prepareSignMessage)(path,args),rsp=await this.Exchange((0,communication_1.getBuffer)(data));return{raw_tx:void 0,signature:`0x${SecuxETH.resolveSignatureEIP155(rsp,option)}`}}if(Buffer.isBuffer(args))return signSerialized();let func=SecuxETH.prepareSignEIP155;(args.accessList||args.maxPriorityFeePerGas||args.maxFeePerGas)&&(func=SecuxETH.prepareSignEIP1559),"boolean"==typeof option&&option&&(func=SecuxETH.prepareSignWalletConnectTransaction);const{commandData,rawTx}=func(path,args,option),rsp=await this.Exchange((0,communication_1.getBuffer)(commandData));let signature=Buffer.from(SecuxETH.resolveSignature(rsp),"hex");return signature=transaction_1.ETHTransactionBuilder.deserialize((0,communication_1.getBuffer)(rawTx)).getSignature(signature),{raw_tx:SecuxETH.resolveTransaction(rsp,rawTx),signature:`0x${signature.toString("hex")}`}}}function prepareSign(path,builder,tp){(0,utility_1.checkFWVersion)("mcu",mcu[transport_1.ITransport.deviceType],transport_1.ITransport.mcuVersion),(0,ow_1.default)(path,ow_path),tp||(tp=builder.tx.value?interface_1.TransactionType.NORMAL:function(data){const abiData=Buffer.isBuffer(data)?data.toString("hex"):null==data?void 0:data.replace(/^0x/,"");if(!abiData)return!1;const abiNFT=["23b872dd","42842e0e","f242432a"];console.log(abiData);for(const abi of abiNFT)if(abiData.startsWith(abi))return!0;return!1}(builder.tx.data)?interface_1.TransactionType.NFT:interface_1.TransactionType.TOKEN);const isBlind=function(data){const abiSupported=[{identify:"a9059cbb",length:136},{identify:"23b872dd",length:200},{identify:"095ea7b3",length:136},{identify:"42842e0e",length:200},{identify:"f242432a",length:392}],abiData=Buffer.isBuffer(data)?data.toString("hex"):null==data?void 0:data.replace(/^0x/,"");if(!abiData)return!1;for(const abi of abiSupported)if(abiData.startsWith(abi.identify)&&abiData.length===abi.length)return!1;return!0}(builder.tx.data);isBlind&&(tp=interface_1.TransactionType.NORMAL);const option={tp,curve:interface_1.EllipticCurve.SECP256K1,chainId:builder.chainId||1};option.chainId>65535&&(option.chainId=65535);const buf=isBlind?protocol_transaction_1.SecuxTransactionTool.signTransaction(path,builder.serialize(!0),option):protocol_transaction_1.SecuxTransactionTool.signRawTransaction(path,builder.serialize(),option);return(0,communication_1.wrapResult)({commandData:buf,rawTx:(0,communication_1.toCommunicationData)(builder.serialize())})}exports.SecuxETH=SecuxETH,SecuxETH.ERC20=erc20_1.ERC20,SecuxETH.ERC721=erc721_1.ERC721,SecuxETH.ERC1155=erc1155_1.ERC1155,(0,utility_1.loadPlugin)(SecuxETH,"SecuxETH"),exports.prepareSign=prepareSign;

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/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"),o=require("@secux/protocol-transaction/lib/interface");exports.ERC1155=class{static prepareSafeTransferFrom(e,a,n){var u;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,i);const l=exports.erc1155_def.encodeFunctionData("safeTransferFrom",[n.fromAddress,n.toAddress,n.id,n.value,null!==(u=n.data)&&void 0!==u?u:Buffer.alloc(0)]),f=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:l}));return(0,r.prepareSign)(e,f,o.TransactionType.NFT)}static prepareSafeBatchTransferFrom(e,a,n){var i;(0,t.default)(a,d.ow_baseData),(0,t.default)(n,l);const u=[...n.items].sort(((e,a)=>{const r=f(e.id)-f(a.id);if(0===r)throw Error(`ArgumentError: duplicate id found, got "${f(e.id)}"`);return r})),c=exports.erc1155_def.encodeFunctionData("safeBatchTransferFrom",[n.fromAddress,n.toAddress,u.map((e=>e.id)),u.map((e=>e.value)),null!==(i=n.data)&&void 0!==i?i:Buffer.alloc(0)]),_=(0,s.getBuilder)(Object.assign(Object.assign({},a),{data:c}));return(0,r.prepareSign)(e,_,o.TransactionType.NFT)}},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 i=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)}),u=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)}),l=t.default.object.exactShape({fromAddress:d.ow_address,toAddress:d.ow_address,items:t.default.array.ofType(u),data:t.default.any(t.default.undefined,n.owTool.prefixedhexString,t.default.buffer)});function f(e){return"number"==typeof e?e:parseInt(e.slice(2),16)}
*/var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc1155_def=exports.ERC1155=void 0;const abi_1=require("@ethersproject/abi"),app_eth_1=require("./app-eth"),ow_1=__importDefault(require("ow")),interface_1=require("./interface"),transaction_1=require("./transaction"),utility_1=require("@secux/utility"),interface_2=require("@secux/protocol-transaction/lib/interface");exports.ERC1155=class{static prepareSafeTransferFrom(path,content,args){var _a;(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferArgs);const data=exports.erc1155_def.encodeFunctionData("safeTransferFrom",[args.fromAddress,args.toAddress,args.id,args.value,null!==(_a=args.data)&&void 0!==_a?_a:Buffer.alloc(0)]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.NFT)}static prepareSafeBatchTransferFrom(path,content,args){var _a;(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_batchTransferArgs);const sorted=[...args.items].sort(((a,b)=>{const compare=toNumber(a.id)-toNumber(b.id);if(0===compare)throw Error(`ArgumentError: duplicate id found, got "${toNumber(a.id)}"`);return compare})),data=exports.erc1155_def.encodeFunctionData("safeBatchTransferFrom",[args.fromAddress,args.toAddress,sorted.map((x=>x.id)),sorted.map((x=>x.value)),null!==(_a=args.data)&&void 0!==_a?_a:Buffer.alloc(0)]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.NFT)}},exports.erc1155_def=new abi_1.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 ow_transferArgs=ow_1.default.object.exactShape({fromAddress:interface_1.ow_address,toAddress:interface_1.ow_address,id:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32),value:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32),data:ow_1.default.any(ow_1.default.undefined,utility_1.owTool.prefixedhexString,ow_1.default.buffer)}),ow_item=ow_1.default.object.exactShape({id:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32),value:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)}),ow_batchTransferArgs=ow_1.default.object.exactShape({fromAddress:interface_1.ow_address,toAddress:interface_1.ow_address,items:ow_1.default.array.ofType(ow_item),data:ow_1.default.any(ow_1.default.undefined,utility_1.owTool.prefixedhexString,ow_1.default.buffer)});function toNumber(value){return"number"==typeof value?value:parseInt(value.slice(2),16)}

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc20_def=exports.ERC20=void 0;const r=require("@ethersproject/abi"),t=e(require("ow")),s=require("./app-eth"),a=require("./interface"),n=require("./transaction"),o=require("@secux/protocol-transaction/lib/interface");exports.ERC20=class{static prepareTransfer(e,r,u){(0,t.default)(r,a.ow_baseData),(0,t.default)(u,i);const d=exports.erc20_def.encodeFunctionData("transfer",[u.toAddress,u.amount]),c=(0,n.getBuilder)(Object.assign(Object.assign({},r),{data:d}));return(0,s.prepareSign)(e,c,o.TransactionType.TOKEN)}static prepareTransferFrom(e,r,i){(0,t.default)(r,a.ow_baseData),(0,t.default)(i,u);const d=exports.erc20_def.encodeFunctionData("transferFrom",[i.fromAddress,i.toAddress,i.amount]),c=(0,n.getBuilder)(Object.assign(Object.assign({},r),{data:d}));return(0,s.prepareSign)(e,c,o.TransactionType.TOKEN)}static prepareApprove(e,r,u){(0,t.default)(r,a.ow_baseData),(0,t.default)(u,i);const d=exports.erc20_def.encodeFunctionData("approve",[u.toAddress,u.amount]),c=(0,n.getBuilder)(Object.assign(Object.assign({},r),{data:d}));return(0,s.prepareSign)(e,c,o.TransactionType.TOKEN)}},exports.erc20_def=new r.Interface(["function name() public view returns (string)","function symbol() public view returns (string)","function decimals() public view returns (uint8)","function totalSupply() public view returns (uint256)","function balanceOf(address _owner) public view returns (uint256 balance)","function transfer(address _to, uint256 _value) public returns (bool success)","function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)","function approve(address _spender, uint256 _value) public returns (bool success)","function allowance(address _owner, address _spender) public view returns (uint256 remaining)","event Transfer(address indexed _from, address indexed _to, uint256 _value)","event Approval(address indexed _owner, address indexed _spender, uint256 _value)"]);const i=t.default.object.exactShape({toAddress:a.ow_address,amount:t.default.any(t.default.number.positive,a.ow_hexString32)}),u=t.default.object.exactShape({fromAddress:a.ow_address,toAddress:a.ow_address,amount:t.default.any(t.default.number.positive,a.ow_hexString32)});
*/var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc20_def=exports.ERC20=void 0;const abi_1=require("@ethersproject/abi"),ow_1=__importDefault(require("ow")),app_eth_1=require("./app-eth"),interface_1=require("./interface"),transaction_1=require("./transaction"),interface_2=require("@secux/protocol-transaction/lib/interface");exports.ERC20=class{static prepareTransfer(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferData);const data=exports.erc20_def.encodeFunctionData("transfer",[args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}static prepareTransferFrom(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferFromData);const data=exports.erc20_def.encodeFunctionData("transferFrom",[args.fromAddress,args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}static prepareApprove(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferData);const data=exports.erc20_def.encodeFunctionData("approve",[args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}},exports.erc20_def=new abi_1.Interface(["function name() public view returns (string)","function symbol() public view returns (string)","function decimals() public view returns (uint8)","function totalSupply() public view returns (uint256)","function balanceOf(address _owner) public view returns (uint256 balance)","function transfer(address _to, uint256 _value) public returns (bool success)","function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)","function approve(address _spender, uint256 _value) public returns (bool success)","function allowance(address _owner, address _spender) public view returns (uint256 remaining)","event Transfer(address indexed _from, address indexed _to, uint256 _value)","event Approval(address indexed _owner, address indexed _spender, uint256 _value)"]);const ow_transferData=ow_1.default.object.exactShape({toAddress:interface_1.ow_address,amount:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)}),ow_transferFromData=ow_1.default.object.exactShape({fromAddress:interface_1.ow_address,toAddress:interface_1.ow_address,amount:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)});

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/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)});
*/var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc721_def=exports.ERC721=void 0;const abi_1=require("@ethersproject/abi"),app_eth_1=require("./app-eth"),ow_1=__importDefault(require("ow")),interface_1=require("./interface"),transaction_1=require("./transaction"),utility_1=require("@secux/utility"),interface_2=require("@secux/protocol-transaction/lib/interface");exports.ERC721=class{static prepareSafeTransferFrom(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_safeTransferDataArgs);const data=args.data?exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data)",[args.fromAddress,args.toAddress,args.tokenId,args.data]):exports.erc721_def.encodeFunctionData("safeTransferFrom(address _from, address _to, uint256 _tokenId)",[args.fromAddress,args.toAddress,args.tokenId]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.NFT)}static prepareTransferFrom(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_safeTransferArgs);const data=exports.erc721_def.encodeFunctionData("transferFrom",[args.fromAddress,args.toAddress,args.tokenId]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.NFT)}static prepareApprove(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_approveArgs);const data=exports.erc721_def.encodeFunctionData("approve",[args.toAddress,args.tokenId]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.NFT)}},exports.erc721_def=new abi_1.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 _safeTransferArgs={fromAddress:interface_1.ow_address,toAddress:interface_1.ow_address,tokenId:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)},ow_safeTransferArgs=ow_1.default.object.exactShape(_safeTransferArgs),ow_safeTransferDataArgs=ow_1.default.object.exactShape(Object.assign(Object.assign({},_safeTransferArgs),{data:ow_1.default.any(ow_1.default.undefined,utility_1.owTool.prefixedhexString,ow_1.default.buffer)})),ow_approveArgs=ow_1.default.object.exactShape({toAddress:interface_1.ow_address,tokenId:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)});

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/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.any(t.default.number.positive,a.owTool.prefixedhexString),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.any(t.default.number.positive,a.owTool.prefixedhexString),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};
*/var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};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 ow_1=__importDefault(require("ow")),utility_1=require("@secux/utility"),validate=require("wallet-address-validator").validate;exports.ow_address=ow_1.default.string.matches(/^0x[0-9A-Fa-f]{40}$/).validate((x=>({validator:validate(x,"ETH"),message:`ArgumentError: invalid address, got "${x}"`}))),exports.ow_hexString32=ow_1.default.string.matches(/^0x[a-fA-F0-9]{1,64}$/),exports.ow_gasPriceUnit=ow_1.default.any(ow_1.default.number.uint32.positive,utility_1.owTool.prefixedhexString);const __tx155={chainId:ow_1.default.any(ow_1.default.number.positive,utility_1.owTool.prefixedhexString),nonce:ow_1.default.any(ow_1.default.number,utility_1.owTool.prefixedhexString),gasPrice:exports.ow_gasPriceUnit,gasLimit:ow_1.default.any(ow_1.default.number.positive,utility_1.owTool.prefixedhexString),to:exports.ow_address,value:ow_1.default.any(ow_1.default.number.not.negative,utility_1.owTool.prefixedhexString)};exports.ow_tx155_base=ow_1.default.object.partialShape(__tx155),exports.ow_tx155=ow_1.default.object.exactShape(Object.assign(Object.assign({},__tx155),{data:ow_1.default.any(ow_1.default.undefined,utility_1.owTool.prefixedhexString)}));const __tx1559={chainId:ow_1.default.any(ow_1.default.number.positive,utility_1.owTool.prefixedhexString),nonce:ow_1.default.any(ow_1.default.number,utility_1.owTool.prefixedhexString),maxPriorityFeePerGas:ow_1.default.any(ow_1.default.number.uint32.positive,utility_1.owTool.prefixedhexString),maxFeePerGas:exports.ow_gasPriceUnit,gasLimit:ow_1.default.any(ow_1.default.number.positive,utility_1.owTool.prefixedhexString),to:exports.ow_address,value:ow_1.default.any(ow_1.default.undefined,ow_1.default.number.not.negative,utility_1.owTool.prefixedhexString),accessList:ow_1.default.any(ow_1.default.undefined,ow_1.default.array.ofType(ow_1.default.any()))};exports.ow_tx1559_base=ow_1.default.object.partialShape(__tx1559),exports.ow_tx1559=ow_1.default.object.exactShape(Object.assign(Object.assign({},__tx1559),{data:ow_1.default.any(ow_1.default.undefined,utility_1.owTool.prefixedhexString)})),exports.ow_baseData=ow_1.default.any(exports.ow_tx155_base,exports.ow_tx1559_base),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.isJsonString=function(str){try{JSON.parse(str)}catch(error){return!1}return!0};

@@ -18,2 +18,2 @@ "use strict";

limitations under the License.
*/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,Object.assign({},t),"f"),"string"==typeof t.chainId)a(this,e,"f").chainId=Buffer.from(t.chainId.slice(2),"hex");else if("number"==typeof t.chainId){let r=t.chainId.toString(16);r.length%2!=0&&(r=`0${r}`),a(this,e,"f").chainId=Buffer.from(r,"hex")}if(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);i.lt(r)&&console.warn(`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,h=parseInt(Buffer.from(c).toString("hex"),16);let d;return[0,27,28].includes(h)||(d=c),new g({nonce:r,gasPrice:i,gasLimit:n,to:a,value:s,data:o,chainId:d})}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&&12!==t.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 9 or 12 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 chainId(){if(a(this,e,"f").chainId)return parseInt(Buffer.from(a(this,e,"f").chainId).toString("hex"),16)}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;
*/var _ETHTransactionBuilder_tx,__createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var desc=Object.getOwnPropertyDescriptor(m,k);desc&&!("get"in desc?!m.__esModule:desc.writable||desc.configurable)||(desc={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,desc)}:function(o,m,k,k2){void 0===k2&&(k2=k),o[k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){if(mod&&mod.__esModule)return mod;var result={};if(null!=mod)for(var k in mod)"default"!==k&&Object.prototype.hasOwnProperty.call(mod,k)&&__createBinding(result,mod,k);return __setModuleDefault(result,mod),result},__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)},__importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EIP1559Builder=exports.ETHTransactionBuilder=exports.getBuilder=void 0;const secp256k1=require("secp256k1/elliptic"),js_sha3_1=require("js-sha3"),rlp=__importStar(require("rlp")),bignumber_js_1=require("bignumber.js"),ow_1=__importDefault(require("ow")),interface_1=require("./interface"),utility_1=require("@secux/utility"),logger=null===utility_1.Logger||void 0===utility_1.Logger?void 0:utility_1.Logger.child({id:"ethereum"}),EIP1559_TransactionType=Buffer.from([2]);exports.getBuilder=function(data){try{return(0,ow_1.default)(data,interface_1.ow_tx1559),new EIP1559Builder(data)}catch(error){}return new ETHTransactionBuilder(data)};class ETHTransactionBuilder{constructor(tx){if(_ETHTransactionBuilder_tx.set(this,void 0),__classPrivateFieldSet(this,_ETHTransactionBuilder_tx,Object.assign({},tx),"f"),"string"==typeof tx.chainId)__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId=Buffer.from(tx.chainId.slice(2),"hex");else if("number"==typeof tx.chainId){let str=tx.chainId.toString(16);str.length%2!=0&&(str=`0${str}`),__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId=Buffer.from(str,"hex")}if(tx.gasPrice){const gasPrice=getValue(tx.gasPrice);gasPrice.lt(1)&&(null==logger||logger.warn(`Minimal gas price is 1 wei, but got ${gasPrice.toString()} wei.`))}if(tx.maxPriorityFeePerGas){getValue(tx.maxPriorityFeePerGas).lt(1)&&(null==logger||logger.warn("[maxPriorityFeePerGas] Minimal priority fee is 1 wei."))}if(tx.maxFeePerGas){const maxFee=getValue(tx.maxFeePerGas);maxFee.lt(1)&&(null==logger||logger.warn(`[maxFeePerGas] Minimal fee is 1 wei, but got ${maxFee.toString()} wei.`))}let estimatedGas=21e3;tx.data&&("string"==typeof tx.data?estimatedGas+=68*(tx.data.length/2-1):estimatedGas+=68*tx.data.length);const gasLimit=getValue(tx.gasLimit);gasLimit.lt(estimatedGas)&&(null==logger||logger.warn(`Minimal gas is ${estimatedGas}, but got ${gasLimit.toString()}.`))}static deserialize(serialized){if(serialized[0]>=192){const values=rlp.decode(serialized);if(!Array.isArray(values))throw new Error("Invalid serialized tx input. Must be array");if(6!==values.length&&9!==values.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 6 values (legacy) or 9 values (EIP155).");const[nonce,gasPrice,gasLimit,to,value,data,v,r,s]=values,_v=parseInt(Buffer.from(v).toString("hex"),16);let chainId;return[0,27,28].includes(_v)||(chainId=v),new ETHTransactionBuilder({nonce,gasPrice,gasLimit,to,value,data,chainId})}if(serialized[0]<=127){const values=rlp.decode(serialized.slice(1));if(!Array.isArray(values))throw new Error("Invalid serialized tx input. Must be array");if(9!==values.length&&12!==values.length)throw new Error("Invalid transaction. Only expecting unsigned tx with 9 or 12 values (EIP1559).");const[chainId,nonce,maxPriorityFeePerGas,maxFeePerGas,gasLimit,to,value,data]=values;return new EIP1559Builder({chainId,nonce,maxPriorityFeePerGas,maxFeePerGas,gasLimit,to,value,data})}throw Error(`Invalid serialized tx input, got "${serialized.toString("hex")}"`)}serialize(toHash=!1){var _a;const transaction=[...this.prepare(),handleRLPValue(null!==(_a=__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId)&&void 0!==_a?_a:0),0,0],encoded=rlp.encode(transaction);return toHash?Buffer.from(js_sha3_1.keccak256.update(encoded).digest()):encoded}withSignature(sig){if(!this.verify(sig))throw Error("invalid signature");sig=this.getSignature(sig);const transaction=[...this.prepare(),handleRLPValue(sig.slice(64)),trimZeroForRLP(sig.slice(0,32)),trimZeroForRLP(sig.slice(32,64))];return rlp.encode(transaction)}getSignature(sig){var _a;const chainId=parseInt(Buffer.from(null!==(_a=__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId)&&void 0!==_a?_a:[0]).toString("hex"),16),offset=chainId>0?2*chainId+35:27;let v_hex=(sig[64]+offset).toString(16);v_hex.length%2!=0&&(v_hex=`0${v_hex}`);const v=Buffer.from(v_hex,"hex");return Buffer.concat([sig.slice(0,64),v])}prepare(){var _a;return[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),null!==(_a=__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").data)&&void 0!==_a?_a:""]}verify(data){const sig=data.slice(0,64);try{secp256k1.ecdsaRecover(sig,data.readUint8(64),this.serialize(!0))}catch(error){return!1}return!0}get chainId(){if(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId)return parseInt(Buffer.from(__classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f").chainId).toString("hex"),16)}get tx(){return __classPrivateFieldGet(this,_ETHTransactionBuilder_tx,"f")}}exports.ETHTransactionBuilder=ETHTransactionBuilder,_ETHTransactionBuilder_tx=new WeakMap;class EIP1559Builder extends ETHTransactionBuilder{serialize(toHash=!1){const transaction=this.prepare(),encoded=Buffer.concat([EIP1559_TransactionType,rlp.encode(transaction)]);return toHash?Buffer.from(js_sha3_1.keccak256.update(encoded).digest()):encoded}withSignature(sig){if(!this.verify(sig))throw Error("invalid signature");const transaction=[...this.prepare(),handleRLPValue(sig[64]),trimZeroForRLP(sig.slice(0,32)),trimZeroForRLP(sig.slice(32,64))],encoded=rlp.encode(transaction);return Buffer.concat([EIP1559_TransactionType,encoded])}getSignature(sig){return sig}prepare(){var _a,_b;return[handleRLPValue(this.tx.chainId),handleRLPValue(this.tx.nonce),handleRLPValue(this.tx.maxPriorityFeePerGas),handleRLPValue(this.tx.maxFeePerGas),handleRLPValue(this.tx.gasLimit),this.tx.to,handleRLPValue(this.tx.value),null!==(_a=this.tx.data)&&void 0!==_a?_a:"",null!==(_b=this.tx.accessList)&&void 0!==_b?_b:[]]}}function handleRLPValue(input){if("string"==typeof input){if(input.startsWith("0x")&&function(str){let newStr=str.startsWith("0x")?str.slice(2):str;const regexp=/^[0-9a-fA-F]+$/;return newStr=newStr.length%2==0?newStr:`0${newStr}`,regexp.test(newStr)}(input))return"0x0"==input||"0x00"==input?0:input;throw Error("Invalid handleRLPValue string")}return input}function trimZeroForRLP(data){var _a;const zeros=(null!==(_a=data.toString("hex").match(/^(00)+/g))&&void 0!==_a?_a:[""])[0].length/2;return data.slice(zeros)}function getValue(data){return"number"==typeof data?new bignumber_js_1.BigNumber(data):"string"==typeof data?data.startsWith("0x")?new bignumber_js_1.BigNumber(data.slice(2),16):new bignumber_js_1.BigNumber(data):new bignumber_js_1.BigNumber(Buffer.from(data).toString("hex"),16)}exports.EIP1559Builder=EIP1559Builder;
{
"name": "@secux/app-eth",
"version": "3.0.14",
"version": "3.0.15",
"description": "SecuX Hardware Wallet ETH API",

@@ -42,3 +42,3 @@ "keywords": [

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

@@ -45,0 +45,0 @@ "js-sha3": "^0.8.0",

Sorry, the diff of this file is too big to display

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