3.0.11 • Published 2 months ago

@secux/app-sol v3.0.11

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

lerna view on npm npm module downloads

@secux/app-sol

SecuX Hardware Wallet SOL API

Usage

import { SecuxSOL } from "@secux/app-sol";

First, create instance of ITransport.

Examples

  1. Get address of bip-32 path.

    • main account

      const path = "m/44'/501'/0'";
      const address = await device.getAddress(path);
      
      /*
      
      // transfer data to hardware wallet by custom transport layer.
      const data = SecuxBTC.prepareAddress(path);
      const response = await device.Exchange(data);
      const address = SecuxBTC.resolveAddress(response, path);
      
      */
    • associated account

      const address = await device.getAddress(
          "m/44'/501'/0'", 
          // USDC
          { mintAccount: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" }
      );
    • account with seed
      const address = await device.getAddress(
          "m/44'/501'/0'",
          { 
              seed: "seed",
              programId: "Stake11111111111111111111111111111111111111"
          }
      );
  2. Sign transaction.

    • transfer asset

      const { raw_tx } = await device.sign(
          "<recentBlockhash>",
          instructions: [
              {
                  type: "transfer",
                  params: {
                      to: "<reciever account>",
                      lamports: 1e9,
                      path: "m/44'/501'/0'"
                  }
              }
          ]
      );
      
      /*
      
      // transfer data to hardware wallet by custom transport layer.
      const { commandData, serialized } = SecuxSOL.prepareSign(
          "<recentBlockhash>",
          instructions: [
              {
                  type: "transfer",
                  params: {
                      from: "<sender's account>",
                      to: "<reciever's account>",
                      lamports: 1e9,
                      path: "m/44'/501'/0'"
                  }
              }
          ]
      );
      const response = await device.Exchange(commandData);
      const raw_tx = SecuxSOL.resloveTransaction(response, serialized);
      
      */
    • transfer SPL token

      const { raw_tx } = await device.sign(
          "<recentBlockhash>",
          instructions: 
              SecuxSOL.Action.transferToken(
                  {
                      to: "<reciever's account>",
                      owner: "<sender's account>",
                      amount: 1e6,
                      mint: "<token mint account>",
                      decimal: 6,
                      path: "m/44'/501'/0'",
                      // create ATA for reciever
                      createAccount: true
                  }
              )
      );
    • native staking

      const { raw_tx } = await device.sign(
          "<recentBlockhash>",
          instructions: 
              SecuxSOL.Action.stake(
                  {
                      owner: "<main account>",
                      stake: "<stake account>",
                      vote: "<vote account>",
                      lamports: 1e9,
                      path: "m/44'/501'/0'",
      
                      // if give a seed, the createWithSeed instruction will be included.
                      // stake: "<arbitrary string>"
                  }
              )
      );
    • unstake

      const { raw_tx } = await device.sign(
          "<recentBlockhash>",
          instructions: 
              SecuxSOL.Action.unstake(
                  {
                      owner: "<main account>",
                      stake: "<stake account or seed>",
                      lamports: <withdraw amount>,
                      path: "m/44'/501'/0'"
                  }
              )
      );

API Reference

SOL package for SecuX device

Kind: global class

SecuxSOL.addressConvert(publickey, option) ⇒ string

Convert ed25519 publickey to SOL address.

Returns: string - address

ParamTypeDescription
publickeystring | Buffered25519 publickey
optionATAOption | SeedOption

SecuxSOL.prepareAddress(path) ⇒ communicationData

Prepare data for SOL address.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringBIP32 path (hardened child key), ex: m/44'/501'/0'/0'

SecuxSOL.resolveAddress(response, option) ⇒ string

Generate SOL address from response data.

Returns: string - SOL address

ParamTypeDescription
responsecommunicationDatadata from device
optionATAOption | SeedOption

SecuxSOL.preparePublickey(path) ⇒ communicationData

Prepare data for ed25519 publickey.

Returns: communicationData - data for sending to device

ParamTypeDescription
pathstringBIP32 path (hardened child key), ex: m/44'/501'/0'/0'

SecuxSOL.resolvePublickey(response) ⇒ string

Resove ed25519 publickey from response data.

Returns: string - ed25519 publickey (hex string)

ParamTypeDescription
responsecommunicationDatadata from device

SecuxSOL.prepareSign(feePayer, content) ⇒ prepared

Prepare data for signing.

Returns: prepared - prepared object

ParamTypeDescription
feePayerstringsolana account
contenttxDetailtransaction object

SecuxSOL.resolveSignatureList(response) ⇒ Array.<string>

Reslove signatures from response data.

Returns: Array.<string> - signature array (base58 encoded)

ParamTypeDescription
responsecommunicationDatadata from device

SecuxSOL.resolveTransaction(response, serialized) ⇒ string

Resolve transaction for broadcasting.

Returns: string - signed transaction (hex)

ParamTypeDescription
responsecommunicationDatadata from device
serializedcommunicationData

ATAOption : object

Properties

NameTypeDescription
mintAccountstringtoken mint address

SeedOption : object

Properties

NameTypeDescription
seedstringarbitary string (UTF-8)
programIdstringprogram address

accounts : object

Properties

NameTypeDescription
publickeystring | BufferEd25519 publickey
isSignerboolean
isWritableboolean
pathstringthe path for signing

Instruction : object

Properties

NameTypeDescription
programIdstringprogram address
accountsaccounts
datastring | Bufferhex string or buffer

BuiltinInstruction : object

Properties

NameTypeDescription
typestringinstruction type
paramsanyparameters

txDetail : object

Properties

NameTypeDescription
recentBlockhashstringa recent blockhash
instructionsArray.<(Instruction|BuiltinInstruction)>a least one instruction in a transaction
feepayerPathstringoption for signing via SecuX wallet

prepared : object

Properties

NameTypeDescription
commandDatacommunicationDatadata for sending to device
rawTxstringunsigned raw transaction

© 2018-22 SecuX Technology Inc.

authors: andersonwu@secuxtech.com

3.0.11

2 months ago

3.0.10

2 months ago

3.0.8

5 months ago

3.0.9

5 months ago

3.0.7

5 months ago

3.0.6

5 months ago

3.0.5

5 months ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago