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.4 to 3.0.5

dist/index.js

2

lib/app-eth.js

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

"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;
"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"),p=require("./erc721"),g=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).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))}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))}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));const r=(0,u.getBuilder)(t),i=r.serialize(!0),c=n.SecuxTransactionTool.signTransaction(e,i,{tp:s.TransactionType.NORMAL,curve:s.EllipticCurve.SECP256K1,chainId:t.chainId});return(0,l.wrapResult)({commandData:c,rawTx:(0,l.toCommunicationData)(r.serialize())})}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){var i;(0,a.default)(e,x),void 0===r&&(r=void 0===t.tx.value||"0"==t.tx.value?s.TransactionType.TOKEN:s.TransactionType.NORMAL);const o=n.SecuxTransactionTool.signRawTransaction(e,t.serialize(),{tp:r,curve:s.EllipticCurve.SECP256K1,chainId:null!==(i=t.tx.chainId)&&void 0!==i?i:1});return(0,l.wrapResult)({commandData:o,rawTx:(0,l.toCommunicationData)(t.serialize())})}exports.SecuxETH=S,S.ERC20=f.ERC20,S.ERC721=p.ERC721,S.ERC1155=g.ERC1155,(0,i.loadPlugin)(S,"SecuxETH"),exports.prepareSign=T;
{
"name": "@secux/app-eth",
"version": "3.0.4",
"version": "3.0.5",
"description": "SecuX Hardware Wallet ETH API",

@@ -21,3 +21,4 @@ "keywords": [

"files": [
"lib"
"lib",
"dist"
],

@@ -24,0 +25,0 @@ "publishConfig": {

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