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 2.0.4 to 2.1.0

43

lib/app-eth.d.ts
/// <reference types="node" />
import { ITransport } from '@secux/protocol-transaction';
import { txDetail } from './interface';
import { ITransport } from "@secux/transport";
import { tx155, tx1559 } from './interface';
import { TypedData } from "./eip712";
export { SecuxETH, txDetail, TypedData };
export { SecuxETH, tx155, tx1559, TypedData };
/**

@@ -11,5 +11,5 @@ * ETH package for SecuX device

/**
* Get EIP55 address derived by given BIP44 path
* Get EIP55 address derived by given BIP32 path
* @param {ITransport} trans
* @param {string} path BIP44
* @param {string} path BIP32
* @returns {string} EIP55 address

@@ -24,3 +24,3 @@ *

* @param {ITransport} trans
* @param {string} path BIP44
* @param {string} path BIP32
* @param {txDetail} content transaction content

@@ -31,3 +31,3 @@ * @returns {object} signed

*
* @example
* @example EIP155 transaction
* const raw_tx = await SecuxETH.signTransaction(device, "m/44'/60'/0'/0/0", {

@@ -42,3 +42,3 @@ * chainId: 1,

*
* @example
* @example ERC20 token transfer
* const raw_tx = await SecuxETH.signTransaction(device, "m/44'/60'/0'/0/0", {

@@ -53,4 +53,15 @@ * chainId: 1,

* });
*
* @example EIP1559 transaction
* const raw_tx = await SecuxETH.signTransaction(device, "m/44'/60'/0'/0/0", {
* chainId: 1,
* nonce: 0,
* maxPriorityFeePerGas: 10000,
* maxFeePerGas: 10000000,
* gasLimit: 25000,
* to: "0xD080156885651fADbD6df14145051b934660a748",
* value: 1000000000
* });
*/
static signTransaction(trans: ITransport, path: string, content: txDetail): Promise<{
static signTransaction(trans: ITransport, path: string, content: tx155 | tx1559): Promise<{
raw_tx: string;

@@ -62,5 +73,5 @@ signature: Buffer;

* @param {ITransport} trans
* @param {string} path BIP44
* @param {string} path BIP32
* @param {string} message
* @param {number} chainId default ETH mainnet
* @param {number} chainId 1(default): ETH, 56: BSC
* @returns {object} signed

@@ -77,5 +88,5 @@ * @returns {string} signed.raw_tx

* @param {ITransport} trans
* @param {string} path BIP44
* @param {string} path BIP32
* @param {TypedData} data EIP712
* @param {number} chainId default ETH mainnet
* @param {number} chainId 1(default): ETH, 56: BSC
* @returns {object} signed

@@ -85,3 +96,3 @@ * @returns {string} signed.raw_tx

*/
static signTypedMessage(trans: ITransport, path: string, data: TypedData, chainId?: number): Promise<{
static signTypedData(trans: ITransport, path: string, data: TypedData, chainId?: number): Promise<{
raw_tx: string;

@@ -93,3 +104,3 @@ signature: Buffer;

* @param {ITransport} trans
* @param {string} path BIP44
* @param {string} path BIP32
* @param {txDetail} content transaction content

@@ -100,3 +111,3 @@ * @returns {object} signed

*/
static signWalletConnectTransaction(trans: ITransport, path: string, content: txDetail): Promise<{
static signWalletConnectTransaction(trans: ITransport, path: string, content: tx155 | tx1559): Promise<{
raw_tx: string;

@@ -103,0 +114,0 @@ signature: Buffer;

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

"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&t(r,i,n);return e(r,i),r},r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,s)}u((r=r.apply(t,e||[])).next())}))},n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxETH=void 0;const a=require("js-sha3"),o=n(require("ow")),s=require("@secux/protocol-transaction"),u=i(require("@secux/utility")),c=require("./interface"),l=require("./transaction"),d=require("./eip712"),f=require("wallet-address-validator").validate;function h(t,e){return Buffer.concat([t.r,t.s,Buffer.from([t.v[0]+2*e+35])])}exports.SecuxETH=class{static getAddress(t,e){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44));let{publicKey:i}=yield s.SecuxTransactionTool.getXPublickey(t,e,!1);if(65!==i.length)throw Error(`XPubicKey length error: ${i.length} (should be 65)`);return function(t){t=t.toLowerCase().replace(/^0x/,"");const e=(0,a.keccak256)(t);let i="0x";for(let r=0;r<t.length;r++)parseInt(e[r],16)>=8?i+=t[r].toUpperCase():i+=t[r];return i}((0,a.keccak256)(i.slice(1)).slice(-40))}))}static signTransaction(t,e,i){return r(this,void 0,void 0,(function*(){if((0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_txDetail),!f(i.to,"ETH"))throw Error(`Invalid address: ${i.to}`);const r=new l.ETHTransactionBuilder(i),n=r.serialize();let a=Object.assign({},s.DefaultTransactionOption);a.tp=s.TransactionType.TOKEN;const d=yield s.SecuxTransactionTool.SignRawTransaction(t,e,n,a);return d.trimZero(),{raw_tx:r.withSignature(d).toString("hex"),signature:h(d,i.chainId)}}))}static signMessage(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,o.default.string),(0,o.default)(n,o.default.number.positive);const r=yield s.SecuxTransactionTool.SignMessage(t,e,Buffer.from(i));return r.trimZero(),{raw_tx:"",signature:h(r,n)}}))}static signTypedMessage(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_TypedData),(0,o.default)(n,o.default.number.positive);const r=function(t){const e={};for(const i in c.TYPED_MESSAGE_SCHEMA.properties)t[i]&&(e[i]=t[i]);"types"in e&&(e.types=Object.assign({EIP712Domain:[]},e.types));return e}(i),a=[];a.push(d.TypedDataUtils.hashStruct("EIP712Domain",r.domain,r.types,!0)),"EIP712Domain"!==r.primaryType&&a.push(d.TypedDataUtils.hashStruct(r.primaryType.toString(),r.message,r.types,!0));const l=Buffer.concat(a),f=yield s.SecuxTransactionTool.SignTypedMessage(t,e,l);return f.trimZero(),{raw_tx:"",signature:h(f,n)}}))}static signWalletConnectTransaction(t,e,i){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_txDetail);const r=new l.ETHTransactionBuilder(i),n=r.serialize(!0);let a=Object.assign({},s.DefaultTransactionOption);a.chainId=i.chainId;const d=yield s.SecuxTransactionTool.SignTransaction(t,e,n,a);return d.trimZero(),{raw_tx:r.withSignature(d).toString("hex"),signature:h(d,i.chainId)}}))}};
"use strict";var t=this&&this.__createBinding||(Object.create?function(t,e,i,r){void 0===r&&(r=i),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,r){void 0===r&&(r=i),t[r]=e[i]}),e=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&t(r,i,n);return e(r,i),r},r=this&&this.__awaiter||function(t,e,i,r){return new(i||(i=Promise))((function(n,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,s)}u((r=r.apply(t,e||[])).next())}))},n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxETH=void 0;const a=require("js-sha3"),o=n(require("ow")),s=require("@secux/transport/lib/ITransaction"),u=i(require("@secux/utility")),c=require("./interface"),l=require("./transaction"),d=require("./eip712"),f=require("wallet-address-validator").validate;function h(t,e){return Buffer.concat([t.r,t.s,Buffer.from([t.v[0]+2*e+35])])}exports.SecuxETH=class{static getAddress(t,e){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44));let{publicKey:i}=yield t.getXPublickey(e,!1);if(65!==i.length)throw Error(`XPubicKey length error: ${i.length} (should be 65)`);const r=function(t){t=t.toLowerCase().replace(/^0x/,"");const e=(0,a.keccak256)(t);let i="0x";for(let r=0;r<t.length;r++)parseInt(e[r],16)>=8?i+=t[r].toUpperCase():i+=t[r];return i}((0,a.keccak256)(i.slice(1)).slice(-40));return r}))}static signTransaction(t,e,i){return r(this,void 0,void 0,(function*(){if((0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,o.default.any(c.ow_tx155,c.ow_tx1559)),!f(i.to,"ETH"))throw Error(`Invalid address: ${i.to}`);const r=(0,l.getBuilder)(i),n=r.serialize(),a=yield t.SignRawTransaction(e,n,{tp:s.TransactionType.TOKEN,curve:s.EllipticCurve.SECP256K1,chainId:0,showOption:s.ShowOption.NONE});return a.trimZero(),{raw_tx:r.withSignature(a).toString("hex"),signature:h(a,i.chainId)}}))}static signMessage(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,o.default.string),(0,o.default)(n,o.default.number.positive);const r=yield t.SignMessage(e,Buffer.from(i));return r.trimZero(),{raw_tx:"",signature:h(r,n)}}))}static signTypedData(t,e,i,n=1){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,c.ow_TypedData),(0,o.default)(n,o.default.number.positive);const r=function(t){const e={};for(const i in c.TYPED_MESSAGE_SCHEMA.properties)t[i]&&(e[i]=t[i]);"types"in e&&(e.types=Object.assign({EIP712Domain:[]},e.types));return e}(i),a=[];a.push(d.TypedDataUtils.hashStruct("EIP712Domain",r.domain,r.types,!0)),"EIP712Domain"!==r.primaryType&&a.push(d.TypedDataUtils.hashStruct(r.primaryType.toString(),r.message,r.types,!0));const s=Buffer.concat(a),l=yield t.SignTypedMessage(e,s);return l.trimZero(),{raw_tx:"",signature:h(l,n)}}))}static signWalletConnectTransaction(t,e,i){return r(this,void 0,void 0,(function*(){(0,o.default)(e,u.ow_strictPath(60,44)),(0,o.default)(i,o.default.any(c.ow_tx155,c.ow_tx1559));const r=(0,l.getBuilder)(i),n=r.serialize(!0),a=yield t.SignTransaction(e,n,{tp:s.TransactionType.NORMAL,curve:s.EllipticCurve.SECP256K1,chainId:i.chainId,showOption:s.ShowOption.NONE});return a.trimZero(),{raw_tx:r.withSignature(a).toString("hex"),signature:h(a,i.chainId)}}))}};
export declare type PrefixedHexString = string;
export declare const ow_address: import("ow").StringPredicate;
export declare type txDetail = {
export declare type tx155 = {
chainId: number;

@@ -12,2 +12,13 @@ nonce: number | PrefixedHexString;

};
export declare type tx1559 = {
chainId: number;
nonce: number | PrefixedHexString;
maxPriorityFeePerGas: number | PrefixedHexString;
maxFeePerGas: number | PrefixedHexString;
gasLimit: number | PrefixedHexString;
to: string;
value: number | PrefixedHexString;
data?: string | transferData;
accessList?: any[];
};
export declare type transferData = {

@@ -21,3 +32,3 @@ toAddress: string;

}>;
export declare const ow_txDetail: import("ow").ObjectPredicate<{
export declare const ow_tx155: import("ow").ObjectPredicate<{
chainId: number;

@@ -34,2 +45,16 @@ nonce: string | number;

}>;
export declare const ow_tx1559: import("ow").ObjectPredicate<{
chainId: number;
nonce: string | number;
maxPriorityFeePerGas: string | number;
maxFeePerGas: string | number;
gasLimit: string | number;
to: string;
value: string | number;
data: string | {
toAddress: string;
amount: string | number;
} | undefined;
accessList: unknown[] | undefined;
}>;
export declare const ow_EIP712TypedData: import("ow").ObjectPredicate<{

@@ -36,0 +61,0 @@ name: string;

@@ -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.isTransferData=exports.TYPED_MESSAGE_SCHEMA=exports.ow_TypedData=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_txDetail=exports.ow_transferData=exports.ow_address=void 0;const o=r(require("ow")),i=a(require("@secux/utility"));exports.ow_address=o.default.string.matches(/^0x[0-9A-fa-f]{40}$/),exports.ow_transferData=o.default.object.exactShape({toAddress:exports.ow_address,amount:o.default.any(o.default.number.not.negative,i.ow_prefixedhexString)}),exports.ow_txDetail=o.default.object.exactShape({chainId:o.default.number.positive,nonce:o.default.any(o.default.number,i.ow_prefixedhexString),gasPrice:o.default.any(o.default.number.positive,i.ow_prefixedhexString),gasLimit:o.default.any(o.default.number.positive,i.ow_prefixedhexString),to:exports.ow_address,value:o.default.any(o.default.number.not.negative,i.ow_prefixedhexString),data:o.default.any(o.default.undefined,i.ow_prefixedhexString,exports.ow_transferData)}),exports.ow_EIP712TypedData=o.default.object.exactShape({name:o.default.string,type:o.default.string}),exports.ow_TypedMessage=o.default.object.exactShape({types:o.default.object.valuesOfType(o.default.array.ofType(exports.ow_EIP712TypedData)),primaryType:o.default.string,domain:o.default.object.exactShape({name:o.default.optional.string,version:o.default.optional.string,chainId:o.default.optional.number.not.negative,verifyingContract:o.default.optional.string}),message:o.default.object}),exports.ow_TypedData=o.default.any(exports.ow_TypedMessage),exports.TYPED_MESSAGE_SCHEMA={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},exports.isTransferData=function(e){try{return(0,o.default)(e,exports.ow_transferData),e}catch(e){}};
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,a,r){void 0===r&&(r=a),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[a]}})}:function(e,t,a,r){void 0===r&&(r=a),e[r]=t[a]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),a=this&&this.__importStar||function(a){if(a&&a.__esModule)return a;var r={};if(null!=a)for(var o in a)"default"!==o&&Object.prototype.hasOwnProperty.call(a,o)&&e(r,a,o);return t(r,a),r},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.isTransferData=exports.TYPED_MESSAGE_SCHEMA=exports.ow_TypedData=exports.ow_TypedMessage=exports.ow_EIP712TypedData=exports.ow_tx1559=exports.ow_tx155=exports.ow_transferData=exports.ow_address=void 0;const o=r(require("ow")),n=a(require("@secux/utility"));exports.ow_address=o.default.string.matches(/^0x[0-9A-fa-f]{40}$/),exports.ow_transferData=o.default.object.exactShape({toAddress:exports.ow_address,amount:o.default.any(o.default.number.not.negative,n.ow_prefixedhexString)}),exports.ow_tx155=o.default.object.exactShape({chainId:o.default.number.positive,nonce:o.default.any(o.default.number,n.ow_prefixedhexString),gasPrice:o.default.any(o.default.number.positive,n.ow_prefixedhexString),gasLimit:o.default.any(o.default.number.positive,n.ow_prefixedhexString),to:exports.ow_address,value:o.default.any(o.default.number.not.negative,n.ow_prefixedhexString),data:o.default.any(o.default.undefined,n.ow_prefixedhexString,exports.ow_transferData)}),exports.ow_tx1559=o.default.object.exactShape({chainId:o.default.number.positive,nonce:o.default.any(o.default.number,n.ow_prefixedhexString),maxPriorityFeePerGas:o.default.any(o.default.number.positive,n.ow_prefixedhexString),maxFeePerGas:o.default.any(o.default.number.positive,n.ow_prefixedhexString),gasLimit:o.default.any(o.default.number.positive,n.ow_prefixedhexString),to:exports.ow_address,value:o.default.any(o.default.number.not.negative,n.ow_prefixedhexString),data:o.default.any(o.default.undefined,n.ow_prefixedhexString,exports.ow_transferData),accessList:o.default.any(o.default.undefined,o.default.array.ofType(o.default.any()))}),exports.ow_EIP712TypedData=o.default.object.exactShape({name:o.default.string,type:o.default.string}),exports.ow_TypedMessage=o.default.object.exactShape({types:o.default.object.valuesOfType(o.default.array.ofType(exports.ow_EIP712TypedData)),primaryType:o.default.string,domain:o.default.object.exactShape({name:o.default.optional.string,version:o.default.optional.string,chainId:o.default.optional.number.not.negative,verifyingContract:o.default.optional.string}),message:o.default.object}),exports.ow_TypedData=o.default.any(exports.ow_TypedMessage),exports.TYPED_MESSAGE_SCHEMA={type:"object",properties:{types:{type:"object",additionalProperties:{type:"array",items:{type:"object",properties:{name:{type:"string"},type:{type:"string"}},required:["name","type"]}}},primaryType:{type:"string"},domain:{type:"object"},message:{type:"object"}},required:["types","primaryType","domain","message"]},exports.isTransferData=function(e){try{return(0,o.default)(e,exports.ow_transferData),e}catch(e){}};
/// <reference types="node" />
import { txDetail } from './interface';
import { Signature } from '@secux/protocol-transaction';
export { ETHTransactionBuilder };
import { Signature } from '@secux/transport/lib/ITransaction';
export { getBuilder, ETHTransactionBuilder, EIP1559Builder };
declare function getBuilder(data: any): ETHTransactionBuilder;
declare class ETHTransactionBuilder {
#private;
constructor(tx: txDetail);
constructor(tx: any);
/**

@@ -20,2 +20,11 @@ *

withSignature(sig: Signature): Buffer;
protected checkType(): void;
protected prepare(): any[];
get tx(): any;
}
declare class EIP1559Builder extends ETHTransactionBuilder {
serialize(toHash?: boolean): Buffer;
withSignature(sig: Signature): Buffer;
protected checkType(): void;
protected prepare(): any[];
}

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

"use strict";var t,e=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r),Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[r]}})}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),r=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var a in t)"default"!==a&&Object.prototype.hasOwnProperty.call(t,a)&&e(i,t,a);return r(i,t),i},a=this&&this.__classPrivateFieldSet||function(t,e,r,i,a){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?a.call(t,r):a?a.value=r:e.set(t,r),r},n=this&&this.__classPrivateFieldGet||function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ETHTransactionBuilder=void 0;const s=require("js-sha3"),o=i(require("rlp")),f=require("@ethersproject/abi"),c=require("./interface"),d=require("wallet-address-validator").validate,u=new f.Interface(["function transfer(address to, uint amount)"]);function h(t){if("number"==typeof t)return t;if("string"==typeof t){if(t.startsWith("0x")&&function(t){let e=t.startsWith("0x")?t.slice(2):t;const r=/^[0-9a-fA-F]+$/;return e=e.length%2==0?e:`0${e}`,r.test(e)}(t))return"0x0"==t||"0x00"==t?0:t;throw Error("Invalid handleRLPValue string")}throw Error("Invalid handleRLPValue type")}exports.ETHTransactionBuilder=class{constructor(e){t.set(this,void 0),a(this,t,e,"f");let r=(0,c.isTransferData)(n(this,t,"f").data);if(r){if(!d(r.toAddress,"ETH"))throw Error(`Invalid address: ${r.toAddress}`);n(this,t,"f").data=u.encodeFunctionData("transfer",[r.toAddress,r.amount])}}serialize(e=!1){const r=[h(n(this,t,"f").nonce),h(n(this,t,"f").gasPrice),h(n(this,t,"f").gasLimit),n(this,t,"f").to,h(n(this,t,"f").value),n(this,t,"f").data||"",h(n(this,t,"f").chainId),0,0],i=o.encode(r);return e?Buffer.from(s.keccak256.update(i).digest()):i}withSignature(e){const r=[h(n(this,t,"f").nonce),h(n(this,t,"f").gasPrice),h(n(this,t,"f").gasLimit),n(this,t,"f").to,h(n(this,t,"f").value),n(this,t,"f").data||"",h(2*n(this,t,"f").chainId+35+e.v[0]),e.r,e.s];return o.encode(r)}},t=new WeakMap;
"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.__classPrivateFieldSet||function(e,t,r,i,a){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?a.call(e,r):a?a.value=r:t.set(e,r),r},s=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)},n=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"),u=i(require("rlp")),c=require("@ethersproject/abi"),f=n(require("ow")),d=require("./interface"),h=require("wallet-address-validator").validate,l=new c.Interface(["function transfer(address to, uint amount)"]),p=Buffer.from([2]);exports.getBuilder=function(e){try{return(0,f.default)(e,d.ow_tx1559),new x(e)}catch(e){}return new w(e)};class w{constructor(t){e.set(this,void 0),a(this,e,t,"f"),this.checkType();let r=(0,d.isTransferData)(s(this,e,"f").data);if(r){if(!h(r.toAddress,"ETH"))throw Error(`Invalid address: ${r.toAddress}`);s(this,e,"f").data=l.encodeFunctionData("transfer",[r.toAddress,r.amount])}}serialize(t=!1){const r=[...this.prepare(),v(s(this,e,"f").chainId),0,0],i=u.encode(r);return t?Buffer.from(o.keccak256.update(i).digest()):i}withSignature(t){const r=[...this.prepare(),v(2*s(this,e,"f").chainId+35+t.v[0]),t.r,t.s];return u.encode(r)}checkType(){(0,f.default)(s(this,e,"f"),d.ow_tx155)}prepare(){return[v(s(this,e,"f").nonce),v(s(this,e,"f").gasPrice),v(s(this,e,"f").gasLimit),s(this,e,"f").to,v(s(this,e,"f").value),s(this,e,"f").data||""]}get tx(){return s(this,e,"f")}}exports.ETHTransactionBuilder=w,e=new WeakMap;class x extends w{serialize(e=!1){const t=this.prepare(),r=Buffer.concat([p,u.encode(t)]);return e?Buffer.from(o.keccak256.update(r).digest()):r}withSignature(e){const t=[...this.prepare(),v(e.v[0]),e.r,e.s],r=u.encode(t);return Buffer.concat([p,r])}checkType(){(0,f.default)(this.tx,d.ow_tx1559)}prepare(){return[v(this.tx.chainId),v(this.tx.nonce),v(this.tx.maxPriorityFeePerGas),v(this.tx.maxFeePerGas),v(this.tx.gasLimit),this.tx.to,v(this.tx.value),this.tx.data||"",this.tx.accessList||[]]}}function v(e){if("number"==typeof e)return 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")}throw Error("Invalid handleRLPValue type")}exports.EIP1559Builder=x;
{
"name": "@secux/app-eth",
"version": "2.0.4",
"version": "2.1.0",
"description": "SecuX Hardware Wallet ETH API",

@@ -30,2 +30,3 @@ "keywords": [

"test:webble": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/ble.js",
"test:virtual": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/virtual.js",
"tsc": "tsc",

@@ -36,4 +37,6 @@ "watch": "tsc --watch"

"@ethersproject/abi": "^5.4.1",
"@secux/protocol-transaction": "2.0.1",
"@secux/utility": "^2.0.1",
"@secux/transport": "^2.1.1",
"@secux/utility": "^2.0.2",
"js-sha3": "^0.8.0",
"rlp": "^2.2.6",
"wallet-address-validator": "^0.2.4"

@@ -49,7 +52,3 @@ },

"web3": "^1.5.2"
},
"peerDependencies": {
"js-sha3": "^0.8.0",
"rlp": "^2.2.6"
}
}

@@ -24,3 +24,3 @@ # `@secux/app-eth`

2. Sign legacy transaction
2. Sign legacy transaction (EIP-155)
```ts

@@ -36,3 +36,3 @@ const { raw_tx, signature } = await SecuxETH.signTransaction(

gasPrice: 1e6,
gasLimit: 1e6
gasLimit: 25000
}

@@ -42,4 +42,20 @@ );

3. Sign EIP-1559 transaction
```ts
const { raw_tx, signature } = await SecuxETH.signTransaction(
device,
"m/44'/60'/0'/0/0",
{
nonce: 0,
to: "0xD080156885651fADbD6df14145051b934660a748",
value: 1e10,
chainId: 1,
maxPriorityFeePerGas: 1e4,
maxFeePerGas: 1e6,
gasLimit: 25000
}
);
```
3. Sign transaction with Smart Contract (ERC-20)
4. Sign transaction with Smart Contract (ERC-20)
```ts

@@ -56,3 +72,3 @@ const { raw_tx, signature } = await SecuxETH.signTransaction(

gasPrice: 1e6,
gasLimit: 1e6
gasLimit: 25000
}

@@ -76,3 +92,3 @@ );

gasPrice: 1e6,
gasLimit: 1e6
gasLimit: 25000
}

@@ -104,3 +120,3 @@ );

gasPrice: 1e6,
gasLimit: 1e6
gasLimit: 25000
}

@@ -116,9 +132,99 @@ );

- Binance Smart Chain Mainnet: 56
2. Support for EIP-1559 coming soon
- goto https://chainlist.org/ for your usage
<br />
## Contracts
[andersonwu@secuxtech.com](mailto:andersonwu@secuxtech.com)
## API doc
<a name="SecuxETH"></a>
[judywang@secuxtech.com](mailto:judywang@secuxtech.com)
## SecuxETH
ETH package for SecuX device
**Kind**: global class
- [SecuxETH](#secuxeth)
- [**SecuxETH.getAddress(trans, path)** ⇒ <code>string</code>](#secuxethgetaddresstrans-path--string)
- [**SecuxETH.signTransaction(trans, path, content)** ⇒ <code>object</code>](#secuxethsigntransactiontrans-path-content--object)
- [**SecuxETH.signMessage(trans, path, message, chainId)** ⇒ <code>object</code>](#secuxethsignmessagetrans-path-message-chainid--object)
- [**SecuxETH.signTypedData(trans, path, data, chainId)** ⇒ <code>object</code>](#secuxethsigntypeddatatrans-path-data-chainid--object)
- [**SecuxETH.signWalletConnectTransaction(trans, path, content)** ⇒ <code>object</code>](#secuxethsignwalletconnecttransactiontrans-path-content--object)
<a name="SecuxETH.getAddress"></a></br>
### **SecuxETH.getAddress(trans, path)** ⇒ <code>string</code>
*Get EIP55 address derived by given BIP32 path*
**Kind**: static method of [<code>SecuxETH</code>](#SecuxETH)
**Returns**: <code>string</code> - EIP55 address
| Param | Type | Description |
| --- | --- | --- |
| trans | <code>ITransport</code> | |
| path | <code>string</code> | BIP32 |
<a name="SecuxETH.signTransaction"></a></br>
### **SecuxETH.signTransaction(trans, path, content)** ⇒ <code>object</code>
*Create transaction and Sign*
**Kind**: static method of [<code>SecuxETH</code>](#SecuxETH)
**Returns**: <code>object</code> - signed</br>
<code style="margin-left:62px">string</code> - signed.raw_tx</br>
<code style="margin-left:62px">Buffer</code> - signed.signature</br>
| Param | Type | Description |
| --- | --- | --- |
| trans | <code>ITransport</code> | |
| path | <code>string</code> | BIP32 |
| content | <code>txDetail</code> | transaction content |
<a name="SecuxETH.signMessage"></a></br>
### **SecuxETH.signMessage(trans, path, message, chainId)** ⇒ <code>object</code>
*Create message type transaction and Sign*
**Kind**: static method of [<code>SecuxETH</code>](#SecuxETH)
**Returns**: <code>object</code> - signed</br>
<code style="margin-left:62px">string</code> - signed.raw_tx</br>
<code style="margin-left:62px">Buffer</code> - signed.signature</br>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| trans | <code>ITransport</code> | | |
| path | <code>string</code> | | BIP32 |
| message | <code>string</code> | | |
| chainId | <code>number</code> | <code>1</code> | 1: ETH, 56: BSC |
<a name="SecuxETH.signTypedData"></a></br>
### **SecuxETH.signTypedData(trans, path, data, chainId)** ⇒ <code>object</code>
*Create EIP712 transaction and Sign*
**Kind**: static method of [<code>SecuxETH</code>](#SecuxETH)
**Returns**: <code>object</code> - signed</br>
<code style="margin-left:62px">string</code> - signed.raw_tx</br>
<code style="margin-left:62px">Buffer</code> - signed.signature</br>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| trans | <code>ITransport</code> | | |
| path | <code>string</code> | | BIP32 |
| data | <code>TypedData</code> | | EIP712 |
| chainId | <code>number</code> | <code>1</code> | 1: ETH, 56: BSC |
<a name="SecuxETH.signWalletConnectTransaction"></a></br>
### **SecuxETH.signWalletConnectTransaction(trans, path, content)** ⇒ <code>object</code>
*Create transaction and Sign using WalletConnect protocol*
**Kind**: static method of [<code>SecuxETH</code>](#SecuxETH)
**Returns**: <code>object</code> - signed</br>
<code style="margin-left:62px">string</code> - signed.raw_tx</br>
<code style="margin-left:62px">Buffer</code> - signed.signature</br>
| Param | Type | Description |
| --- | --- | --- |
| trans | <code>ITransport</code> | |
| path | <code>string</code> | BIP32 |
| content | <code>txDetail</code> | transaction content |
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