@secux/app-sol
Version:
SecuX Hardware Wallet SOL API
180 lines (176 loc) • 6.71 kB
TypeScript
/*!
Copyright 2022 SecuX Technology Inc
Copyright Chen Wei-En
Copyright Wu Tsung-Yu
Licensed under the Apache License, Version 2.0 (the License);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an AS IS BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="node" />
/// <reference types="node" />
import { communicationData } from "@secux/utility/lib/communication";
import { ITransport } from "@secux/transport";
import { ATAOption, Ownership, SeedOption, txDetail, txOption } from "./interface";
import { Action } from "./action";
/**
* SOL package for SecuX device
*/
export declare class SecuxSOL {
static get Action(): typeof Action;
/**
* Convert ed25519 publickey to SOL address.
* @param {string | Buffer} publickey ed25519 publickey
* @param {ATAOption | SeedOption} [option]
* @returns {string} address
*/
static addressConvert(publickey: string | Buffer, option?: ATAOption | SeedOption): string;
/**
* Prepare data for SOL address.
* @param {string} path BIP32 path (hardened child key), ex: m/44'/501'/0'
* @returns {communicationData} data for sending to device
*/
static prepareAddress(path: string): communicationData;
/**
* Generate SOL address from response data.
* @param {communicationData} response data from device
* @param {ATAOption | SeedOption} [option]
* @returns {string} SOL address
*/
static resolveAddress(response: communicationData, option?: ATAOption | SeedOption): string;
/**
* Prepare data for ed25519 publickey.
* @param {string} path BIP32 path (hardened child key), ex: m/44'/501'/0'
* @returns {communicationData} data for sending to device
*/
static preparePublickey(path: string): communicationData;
/**
* Resove ed25519 publickey from response data.
* @param {communicationData} response data from device
* @returns {string} ed25519 publickey (hex string)
*/
static resolvePublickey(response: communicationData): string;
/**
* Prepare data for signing.
* @param {string} feePayer solana account
* @param {txDetail} content transaction object
* @returns {prepared} prepared object
*/
static prepareSign(feePayer: string, content: txDetail): {
commandData: communicationData;
serialized: communicationData;
};
/**
* Prepare data for signing.
* @param {communicationData} transaction serialized transaction (legacy / v0)
* @param {Array<Ownership>} ownerships accounts that need to sign transaction
* @param {txOption} [option]
* @returns {prepared} prepared object
*/
static prepareSignSerialized(transaction: communicationData, ownerships: Array<Ownership>, option?: txOption): {
commandData: communicationData;
serialized: communicationData;
};
/**
* Prepare data for signing.
* @param {string} path BIP32 path (hardened child key), ex: m/44'/501'/0'
* @param {string | Buffer} message
* @returns {communicationData} data for sending to device
*/
static prepareSignMessage(path: string, message: string | Buffer): communicationData;
/**
* Reslove signatures from response data.
* @param {communicationData} response data from device
* @returns {string} signature (base64 encoded)
*/
static resolveSignature(response: communicationData): string;
/**
* Reslove signatures from response data.
* @param {communicationData} response data from device
* @returns {Array<string>} signature array (base64 encoded)
*/
static resolveSignatureList(response: communicationData): Array<string>;
/**
* Resolve transaction for broadcasting.
* @param {communicationData} response data from device
* @param {communicationData} serialized
* @returns {string} signed transaction (hex)
*/
static resolveTransaction(response: communicationData, serialized: communicationData): string;
static getAddress(this: ITransport, path: string, option?: ATAOption | SeedOption): Promise<string>;
static getPublickey(this: ITransport, path: string): Promise<string>;
static getXPublickey(this: ITransport, path: string): Promise<string>;
static sign(this: ITransport, ...args: any[]): Promise<{
raw_tx: undefined;
signature: string;
} | {
raw_tx: string;
signature?: undefined;
}>;
}
/**
* Data type for transmission.
* @typedef {string | Buffer} communicationData
*/
/**
* Parameters for associated token address.
* @typedef {object} ATAOption
* @property {string} mintAccount token mint address
*/
/**
* Parameters for account with seed.
* @typedef {object} SeedOption
* @property {string} seed arbitary string (UTF-8)
* @property {string} programId program address
*/
/**
* The accounts required by program.
* @typedef {object} accounts
* @property {string | Buffer} publickey Ed25519 publickey
* @property {boolean} isSigner
* @property {boolean} isWritable
*/
/**
* The raw instruction object.
* @typedef {object} Instruction
* @property {string} programId program address
* @property {accounts} accounts
* @property {string | Buffer} data hex string or buffer
*/
/**
* The bultin instruction object.
* @typedef {object} BuiltinInstruction
* @property {string} type instruction type
* @property {any} params parameters
*/
/**
* Account that needs to sign transaction.
* @typedef {object} Ownership
* @property {string} path
* @property {string} account
*/
/**
* The transaction object.
* @typedef {object} txDetail
* @property {string} recentBlockhash a recent blockhash
* @property {Array<Instruction | BuiltinInstruction>} instructions a least one instruction in a transaction
* @property {Array<Ownership>} ownerships for signing via SecuX wallet
* @property {TransactionType} [txType] transaction type (normal, token, NFT)
*/
/**
* The transaction options.
* @typedef {object} txOption
* @property {string} [feePayer] solana account (base58 encoded)
* @property {TransactionType} [txType] transaction type (normal, token, NFT)
*/
/**
* Object for the signing and validation.
* @typedef {object} prepared
* @property {communicationData} commandData data for sending to device
* @property {communicationData} serialized
*/