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

@secux/app-eth

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/app-eth

SecuX Hardware Wallet ETH API

  • 3.0.23
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

lerna view on npm npm module downloads

@secux/app-eth

SecuX Hardware Wallet ETH API

Usage

import { SecuxETH } from "@secux/app-eth";

First, create instance of ITransport.


Examples

  1. Get address derived by given BIP44 path.
const address = await device.getAddress("m/44'/60'/0'/0/0");

/*

// transfer data to hardware wallet by custom transport layer.
const buffer = SecuxETH.prepareAddress("m/44'/60'/0'/0/0");
const response = await device.Exchange(buffer);
const address = SecuxETH.resolveAddress(response);

*/
  1. Sign legacy transaction (EIP-155).
const { raw_tx, signature } = await device.sign(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0xD080156885651fADbD6df14145051b934660a748",
        value: 1e10,
        chainId: 1,
        gasPrice: 1e6,
        gasLimit: 25000
    }
)

/*

// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxETH.prepareSignEIP155(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0xD080156885651fADbD6df14145051b934660a748",
        value: 1e10,
        chainId: 1,
        gasPrice: 1e6,
        gasLimit: 25000
    }
);
const response = await device.Exchange(commandData);
const rawTx = SecuxETH.resolveTransaction(response, rawTx);

*/
  1. Sign EIP-1559 transaction.
const { raw_tx, signature } = await device.sign(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0xD080156885651fADbD6df14145051b934660a748",
        value: 1e10,
        chainId: 1,
        maxPriorityFeePerGas: 1e4,
        maxFeePerGas: 1e6,
        gasLimit: 25000
    }
);
  1. Sign transaction with Smart Contract (ERC-20).
const { raw_tx, signature } = await device.sign(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
        value: 0,
        data: "0xa9059cbb000000000000000000000000d080156885651fadbd6df14145051b934660a7410000000000000000000000000000000000000000000000000000000000989680",
        chainId: 1,
        gasPrice: 1e6,
        gasLimit: 25000
    }
);

/*

// alternative usage
const { commandData, rawTx } = SecuxETH.ERC20.prepareTransfer(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
        value: 0,
        chainId: 1,
        gasPrice: 1e6,
        gasLimit: 25000
    },
    {
        toAddress: "0xD080156885651fADbD6df14145051b934660a748",
        amount: `0x${1e18.toString(16)}`
    }
);
const response = await device.Exchange(commandData);
const rawTx = SecuxETH.resolve(response, rawTx);

*/
  1. Sign Message transaction.
const { signature } = await device.sign("m/44'/60'/0'/0/0", msg);

// given chainId, return EIP-155 applied signature
// const { signature } = await device.sign("m/44'/60'/0'/0/0", msg, 1);

/*

// transfer data to hardware wallet by custom transport layer.
const buffer = SecuxETH.prepareSignMessage("m/44'/60'/0'/0/0", msg);
const response = await device.Exchange(buffer);
const signature = SecuxETH.resolveSignatureEIP155(response);

*/
  1. Sign TypeData transaction (EIP-712).
const { signature } = await device.sign("m/44'/60'/0'/0/0", JSON.stringify(typedData));

// given chainId, return EIP-155 applied signature
// const { signature } = await device.sign("m/44'/60'/0'/0/0", JSON.stringify(typedData), 1);

/*

// transfer data to hardware wallet by custom transport layer.
const buffer = SecuxETH.prepareSignTypedData("m/44'/60'/0'/0/0", msg);
const response = await device.Exchange(buffer);
// given chainId, return EIP-155 applied signature
const signature = SecuxETH.resolveSignatureEIP155(response, 1);

*/
  1. Sign transaction with WalletConnect.
const { raw_tx, signature } = await device.sign(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0xD080156885651fADbD6df14145051b934660a748",
        value: 0,
        data: "0x7ff36ab5000000000000000000000000000000000000000000000000302bf3f82d406d120000000000000000000000000000000000000000000000000000000000000080000000000000000000000000d080156885651fadbd6df14145051b934660a7480000000000000000000000000000000000000000000000000000000060b613630000000000000000000000000000000000000000000000000000000000000003000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000007130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56",
        chainId: 56,
        gasPrice: 1e6,
        gasLimit: 25000
    },
    true
);

/*

// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxETH.prepareSignWalletConnectTransaction(
    "m/44'/60'/0'/0/0",
    {
        nonce: 0,
        to: "0xD080156885651fADbD6df14145051b934660a748",
        value: 0,
        data: "0x7ff36ab5000000000000000000000000000000000000000000000000302bf3f82d406d120000000000000000000000000000000000000000000000000000000000000080000000000000000000000000d080156885651fadbd6df14145051b934660a7480000000000000000000000000000000000000000000000000000000060b613630000000000000000000000000000000000000000000000000000000000000003000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c0000000000000000000000007130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56",
        chainId: 56,
        gasPrice: 1e6,
        gasLimit: 25000
    }
);
const response = await device.Exchange(commandData);
const rawTx = SecuxETH.resolveTransaction(response, rawTx);

*/

Note

  1. Value of chainId (same as EIP-155):
    • Ethereum Mainnet: 1
    • Binance Smart Chain Mainnet: 56
    • Polygon Network: 137
    • goto https://chainlist.org/ for your specific chain.

API Reference

ETH package for SecuX device

Kind: global class


SecuxETH.prepareAddress ⇒ communicationData

Prepare data for address generation.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...

SecuxETH.addressConvert(publickey) ⇒ string

Convert publickey to ETH address.

Returns: string - EIP55 address

ParamTypeDescription
publickeystring | Buffersecp256k1 publickey

SecuxETH.resolveAddress(response) ⇒ string

Resolve address from response data.

Returns: string - EIP55 address

ParamTypeDescription
responsecommunicationDatadata from device

SecuxETH.preparePublickey(path) ⇒ communicationData

Prepare data for secp256k1 publickey.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...

SecuxETH.resolvePublickey(response) ⇒ string

Resolve secp256k1 publickey from response data.

Returns: string - secp256k1 publickey (hex string)

ParamTypeDescription
responsecommunicationDatadata from device

SecuxETH.prepareXPublickey(path) ⇒ communicationData

Prepare data for xpub generation.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...

SecuxETH.resolveXPublickey(response, path) ⇒ string

Generate xpub with response data.

Returns: string - xpub

ParamTypeDescription
responsecommunicationDatadata from device
pathstringm/44'/60'/...

SecuxETH.prepareSignSerialized(path, serialized) ⇒ communicationData

Convert unsigned transaction to command data.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...
serializedcommunicationDataunsigned transaction

SecuxETH.resolveSignature(response) ⇒ string

Reslove signature from response data.

Returns: string - signature (hex string)

ParamTypeDescription
responsecommunicationDatadata from device

SecuxETH.resolveTransaction(response, serialized) ⇒ string

Serialize transaction wtih signature for broadcasting.

Returns: string - signed raw transaction

ParamTypeDescription
responsecommunicationDatadata from device
serializedcommunicationDataunsigned transaction

SecuxETH.prepareSignEIP155(path, content) ⇒ prepared

Prepare data for signing.

Returns: prepared - prepared object

ParamTypeDescription
pathstringm/44'/60'/...
contenttx155EIP-155 transaction object

SecuxETH.resolveSignatureEIP155(response, [chainId]) ⇒ string

Reslove signature and follow ethereum signature standard.

Returns: string - signature (hex string)

ParamTypeDescription
responsecommunicationDatadata from device
[chainId]numberif give a chainId, the signature will be EIP-155 applied

SecuxETH.prepareSignEIP1559(path, content) ⇒ prepared

Prepare data for signing (London Hard Fork).

Returns: prepared - prepared object

ParamTypeDescription
pathstringm/44'/60'/...
contenttx1559EIP-1559 transaction object

SecuxETH.prepareSignMessage(path, message) ⇒ communicationData

Prepare data for signing.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...
messagestring

SecuxETH.prepareSignTypedData(path, data) ⇒ communicationData

Prepare data for signing.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringm/44'/60'/...
dataJsonStringEIP712

SecuxETH.prepareSignWalletConnectTransaction(path, content) ⇒ prepared

Prepare data for signing using WalletConnect protocol.

Returns: prepared - prepared object

ParamTypeDescription
pathstringm/44'/60'/...
contenttx155 | tx1559transaction object


tx155

Properties

NameTypeDescription
chainIdnumbernetwork for ethereum ecosystem
tostringreceiving address
valuenumber | stringsending amount
noncenumber | string
gasPricenumber | string
gasLimitnumber | string
[data]string

prepared

Properties

NameTypeDescription
commandDatacommunicationDatadata for sending to device
serializedcommunicationDataunsigned transaction

tx1559

Properties

NameTypeDescription
chainIdnumbernetwork for ethereum ecosystem
tostringreceiving address
valuenumber | stringsending amount
noncenumber | string
maxPriorityFeePerGasnumber | string
maxFeePerGasnumber | string
gasLimitnumber | string
[content.accessList]Array.<any>
[data]string


© 2018-21 SecuX Technology Inc.

authors:
andersonwu@secuxtech.com

Keywords

FAQs

Package last updated on 10 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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