@secux/app-sol
SecuX Hardware Wallet SOL API
Usage
import { SecuxSOL } from "@secux/app-sol";
First, create instance of ITransport.
Examples
-
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" } );
- main account
-
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
-
.prepareAddress(path) ⇒
communicationData
-
.resolveAddress(response, [option]) ⇒
string
-
.preparePublickey(path) ⇒
communicationData
-
.resolvePublickey(response) ⇒
string
-
.prepareSign(feePayer, content) ⇒
prepared
-
.resolveSignatureList(response) ⇒
Array.<string>
-
.resolveTransaction(response, serialized) ⇒
string
-
.addressConvert(publickey, [option]) ⇒
string
SecuxSOL.addressConvert(publickey, [option]) ⇒ Convert ed25519 publickey to SOL address.
Returns: string
- address
Param | Type | Description |
---|---|---|
publickey |
string | Buffer
|
ed25519 publickey |
[option] |
ATAOption | SeedOption
|
communicationData
SecuxSOL.prepareAddress(path) ⇒ Prepare data for SOL address.
Returns: communicationData
- data for sending to device
Param | Type | Description |
---|---|---|
path | string |
BIP32 path (hardened child key), ex: m/44'/501'/0'/0' |
string
SecuxSOL.resolveAddress(response, [option]) ⇒ Generate SOL address from response data.
Returns: string
- SOL address
Param | Type | Description |
---|---|---|
response | communicationData |
data from device |
[option] |
ATAOption | SeedOption
|
communicationData
SecuxSOL.preparePublickey(path) ⇒ Prepare data for ed25519 publickey.
Returns: communicationData
- data for sending to device
Param | Type | Description |
---|---|---|
path | string |
BIP32 path (hardened child key), ex: m/44'/501'/0'/0' |
string
SecuxSOL.resolvePublickey(response) ⇒ Resove ed25519 publickey from response data.
Returns: string
- ed25519 publickey (hex string)
Param | Type | Description |
---|---|---|
response | communicationData |
data from device |
prepared
SecuxSOL.prepareSign(feePayer, content) ⇒ Prepare data for signing.
Returns: prepared
- prepared object
Param | Type | Description |
---|---|---|
feePayer | string |
solana account |
content | txDetail |
transaction object |
Array.<string>
SecuxSOL.resolveSignatureList(response) ⇒ Reslove signatures from response data.
Returns: Array.<string>
- signature array (base58 encoded)
Param | Type | Description |
---|---|---|
response | communicationData |
data from device |
string
SecuxSOL.resolveTransaction(response, serialized) ⇒ Resolve transaction for broadcasting.
Returns: string
- signed transaction (hex)
Param | Type | Description |
---|---|---|
response | communicationData |
data from device |
serialized | communicationData |
object
ATAOption : Properties
Name | Type | Description |
---|---|---|
mintAccount | string |
token mint address |
object
SeedOption : Properties
Name | Type | Description |
---|---|---|
seed | string |
arbitary string (UTF-8) |
programId | string |
program address |
object
accounts : Properties
Name | Type | Description |
---|---|---|
publickey |
string | Buffer
|
Ed25519 publickey |
isSigner | boolean |
|
isWritable | boolean |
|
[path] | string |
the path for signing |
object
Instruction : Properties
Name | Type | Description |
---|---|---|
programId | string |
program address |
accounts | accounts |
|
data |
string | Buffer
|
hex string or buffer |
object
BuiltinInstruction : Properties
Name | Type | Description |
---|---|---|
type | string |
instruction type |
params | any |
parameters |
object
txDetail : Properties
Name | Type | Description |
---|---|---|
recentBlockhash | string |
a recent blockhash |
instructions | Array.<(Instruction|BuiltinInstruction)> |
a least one instruction in a transaction |
[feepayerPath] | string |
option for signing via SecuX wallet |
object
prepared : Properties
Name | Type | Description |
---|---|---|
commandData | communicationData |
data for sending to device |
rawTx | string |
unsigned raw transaction |
© 2018-22 SecuX Technology Inc.
authors:
andersonwu@secuxtech.com