@secux/app-eth
Advanced tools
Comparing version 3.0.7 to 3.0.8
@@ -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.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"),s=require("@secux/protocol-transaction/lib/interface"),o=require("./interface"),u=require("./transaction"),c=require("eth-sig-util"),l=require("@secux/utility/lib/communication"),f=require("./erc20"),g=require("./erc721"),p=require("./erc1155"),d=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"ethereum"}),x=(0,i.ow_strictPath)(60,44);class S{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),s=r.publicKeyConvert(n,!1),o=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)(s.slice(1)).slice(-40));return o}static prepareAddress(e){return this.preparePublickey(e)}static resolveAddress(e){(0,a.default)(e,l.ow_communicationData);const t=S.resolvePublickey(e);return S.addressConvert(t)}static preparePublickey(e){return(0,a.default)(e,x),n.SecuxTransactionTool.getPublickey(e,s.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=n.SecuxTransactionTool.resolvePublickey(e,s.EllipticCurve.SECP256K1);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,a.default)(e,x),n.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,a.default)(t,x),n.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSignSerialized(e,t){(0,a.default)(t,l.ow_communicationData);const r=(0,l.getBuffer)(t);null==d||d.debug(`- prepareSignSerialized\ninput serialized tx: ${r.toString("hex")}`);const i=u.ETHTransactionBuilder.deserialize(r);return(0,a.default)(i.tx.to,o.ow_address),T(e,i,!1).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(S.resolveSignature(e),"hex");return null==d||d.debug(`- resolveTransaction\ninput serialized tx: ${r.toString("hex")}`),`0x${i.withSignature(n).toString("hex")}`}static prepareSignEIP155(e,t){(0,a.default)(t,o.ow_tx155);return T(e,(0,u.getBuilder)(t),!1)}static resolveSignatureEIP155(e,t){(0,a.default)(e,l.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,o.ow_tx1559);return T(e,(0,u.getBuilder)(t),!1)}static prepareSignMessage(e,t){let r;return(0,a.default)(e,x),(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,a.default)(e,x);const r=JSON.parse(t);(0,a.default)(r,a.default.any(o.ow_EIP712TypedData,o.ow_TypedMessage));const i=c.TypedDataUtils.sanitizeData(r),s=[];s.push(c.TypedDataUtils.hashStruct("EIP712Domain",i.domain,i.types,!0)),"EIP712Domain"!==i.primaryType&&s.push(c.TypedDataUtils.hashStruct(i.primaryType.toString(),i.message,i.types,!0));const u=Buffer.concat(s);return n.SecuxTransactionTool.signTypedMessage(e,u)}static prepareSignWalletConnectTransaction(e,t){(0,a.default)(e,x),(0,a.default)(t,a.default.any(o.ow_tx155,o.ow_tx1559));return T(e,(0,u.getBuilder)(t),!0)}static async getAddress(e){const t=S.prepareAddress(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolveAddress(r)}static async getPublickey(e){const t=S.preparePublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolvePublickey(r)}static async getXPublickey(e){const t=S.prepareXPublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolveXPublickey(r,e)}static async sign(e,t,r){const a=async()=>{const r=S.prepareSignSerialized(e,t),a=await this.Exchange((0,l.getBuffer)(r));let i=Buffer.from(S.resolveSignature(a),"hex");return i=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(t)).getSignature(i),{raw_tx:S.resolveTransaction(a,t),signature:`0x${i.toString("hex")}`}};if("string"==typeof t){if(t.match(l.base64_regexp))return a();const i=((0,o.isJsonString)(t)?S.prepareSignTypedData:S.prepareSignMessage)(e,t),n=await this.Exchange((0,l.getBuffer)(i));return{raw_tx:void 0,signature:`0x${S.resolveSignatureEIP155(n,r)}`}}if(Buffer.isBuffer(t))return a();let i=S.prepareSignEIP155;"boolean"==typeof r&&r&&(i=S.prepareSignWalletConnectTransaction),(t.accessList||t.maxPriorityFeePerGas||t.maxFeePerGas)&&(i=S.prepareSignEIP1559);const{commandData:n,rawTx:s}=i(e,t),c=await this.Exchange((0,l.getBuffer)(n));let f=Buffer.from(S.resolveSignature(c),"hex");return f=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(s)).getSignature(f),{raw_tx:S.resolveTransaction(c,s),signature:`0x${f.toString("hex")}`}}}function T(e,t,r,i){var o;(0,a.default)(e,x),void 0===i&&(i=void 0===t.tx.value||"0"==t.tx.value?s.TransactionType.TOKEN:s.TransactionType.NORMAL),r&&(i=s.TransactionType.NORMAL);const u={tp:i,curve:s.EllipticCurve.SECP256K1,chainId:null!==(o=t.tx.chainId)&&void 0!==o?o:1},c=r?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=S,S.ERC20=f.ERC20,S.ERC721=g.ERC721,S.ERC1155=p.ERC1155,(0,i.loadPlugin)(S,"SecuxETH"),exports.prepareSign=T; | ||
"use strict";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"),s=require("@secux/protocol-transaction/lib/interface"),o=require("./interface"),u=require("./transaction"),c=require("eth-sig-util"),l=require("@secux/utility/lib/communication"),f=require("./erc20"),g=require("./erc721"),p=require("./erc1155"),d=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"ethereum"}),x=(0,i.ow_strictPath)(60,44);class S{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),s=r.publicKeyConvert(n,!1),o=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)(s.slice(1)).slice(-40));return o}static prepareAddress(e){return this.preparePublickey(e)}static resolveAddress(e){(0,a.default)(e,l.ow_communicationData);const t=S.resolvePublickey(e);return S.addressConvert(t)}static preparePublickey(e){return(0,a.default)(e,x),n.SecuxTransactionTool.getPublickey(e,s.EllipticCurve.SECP256K1)}static resolvePublickey(e){const t=n.SecuxTransactionTool.resolvePublickey(e,s.EllipticCurve.SECP256K1);return Buffer.from(t,"base64").toString("hex")}static prepareXPublickey(e){return(0,a.default)(e,x),n.SecuxTransactionTool.getXPublickey(e)}static resolveXPublickey(e,t){return(0,a.default)(t,x),n.SecuxTransactionTool.resolveXPublickey(e,t)}static prepareSignSerialized(e,t){(0,a.default)(t,l.ow_communicationData);const r=(0,l.getBuffer)(t);null==d||d.debug(`- prepareSignSerialized\ninput serialized tx: ${r.toString("hex")}`);const i=u.ETHTransactionBuilder.deserialize(r);return(0,a.default)(i.tx.to,o.ow_address),T(e,i,!1).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(S.resolveSignature(e),"hex");return null==d||d.debug(`- resolveTransaction\ninput serialized tx: ${r.toString("hex")}`),`0x${i.withSignature(n).toString("hex")}`}static prepareSignEIP155(e,t){(0,a.default)(t,o.ow_tx155);return T(e,(0,u.getBuilder)(t),!1)}static resolveSignatureEIP155(e,t){(0,a.default)(e,l.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,o.ow_tx1559);return T(e,(0,u.getBuilder)(t),!1)}static prepareSignMessage(e,t){let r;return(0,a.default)(e,x),(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,a.default)(e,x),(0,a.default)(t,a.default.string);const r=JSON.parse(t),i=c.TypedDataUtils.sanitizeData(r),s=[];s.push(c.TypedDataUtils.hashStruct("EIP712Domain",i.domain,i.types,!0)),"EIP712Domain"!==i.primaryType&&s.push(c.TypedDataUtils.hashStruct(i.primaryType.toString(),i.message,i.types,!0));const o=Buffer.concat(s);return n.SecuxTransactionTool.signTypedMessage(e,o)}static prepareSignWalletConnectTransaction(e,t){(0,a.default)(e,x),(0,a.default)(t,a.default.any(o.ow_tx155,o.ow_tx1559));return T(e,(0,u.getBuilder)(t),!0)}static async getAddress(e){const t=S.prepareAddress(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolveAddress(r)}static async getPublickey(e){const t=S.preparePublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolvePublickey(r)}static async getXPublickey(e){const t=S.prepareXPublickey(e),r=await this.Exchange((0,l.getBuffer)(t));return S.resolveXPublickey(r,e)}static async sign(e,t,r){const a=async()=>{const r=S.prepareSignSerialized(e,t),a=await this.Exchange((0,l.getBuffer)(r));let i=Buffer.from(S.resolveSignature(a),"hex");return i=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(t)).getSignature(i),{raw_tx:S.resolveTransaction(a,t),signature:`0x${i.toString("hex")}`}};if("string"==typeof t){if(t.match(l.base64_regexp))return a();const i=((0,o.isJsonString)(t)?S.prepareSignTypedData:S.prepareSignMessage)(e,t),n=await this.Exchange((0,l.getBuffer)(i));return{raw_tx:void 0,signature:`0x${S.resolveSignatureEIP155(n,r)}`}}if(Buffer.isBuffer(t))return a();let i=S.prepareSignEIP155;"boolean"==typeof r&&r&&(i=S.prepareSignWalletConnectTransaction),(t.accessList||t.maxPriorityFeePerGas||t.maxFeePerGas)&&(i=S.prepareSignEIP1559);const{commandData:n,rawTx:s}=i(e,t),c=await this.Exchange((0,l.getBuffer)(n));let f=Buffer.from(S.resolveSignature(c),"hex");return f=u.ETHTransactionBuilder.deserialize((0,l.getBuffer)(s)).getSignature(f),{raw_tx:S.resolveTransaction(c,s),signature:`0x${f.toString("hex")}`}}}function T(e,t,r,i){var o;(0,a.default)(e,x),void 0===i&&(i=void 0===t.tx.value||"0"==t.tx.value?s.TransactionType.TOKEN:s.TransactionType.NORMAL),r&&(i=s.TransactionType.NORMAL);const u={tp:i,curve:s.EllipticCurve.SECP256K1,chainId:null!==(o=t.tx.chainId)&&void 0!==o?o:1},c=r?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=S,S.ERC20=f.ERC20,S.ERC721=g.ERC721,S.ERC1155=p.ERC1155,(0,i.loadPlugin)(S,"SecuxETH"),exports.prepareSign=T; |
{ | ||
"name": "@secux/app-eth", | ||
"version": "3.0.7", | ||
"version": "3.0.8", | ||
"description": "SecuX Hardware Wallet ETH API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
824595