@zondax/ledger-substrate
Version:
TS / Node API for Substrate/Polkadot based apps running on Ledger devices
208 lines (207 loc) • 11.4 kB
TypeScript
import type Transport from '@ledgerhq/hw-transport';
import BaseApp, { BIP32Path, INSGeneric } from '@zondax/ledger-js';
import { GenericResponseSign, GenericeResponseAddress, SCHEME, SS58Prefix, TransactionBlob, TransactionMetadataBlob } from './common';
export declare class PolkadotGenericApp extends BaseApp {
static _INS: {
GET_VERSION: number;
GET_ADDR: number;
SIGN: number;
SIGN_RAW: number;
};
static _params: {
cla: number;
ins: INSGeneric;
p1Values: {
ONLY_RETRIEVE: 0;
SHOW_ADDRESS_IN_DEVICE: 1;
};
chunkSize: number;
requiredPathLengths: number[];
};
txMetadataChainId?: string;
txMetadataSrvUrl?: string;
/**
* Constructs a new PolkadotGenericApp instance.
* @param transport - The transport instance.
* @param txMetadataChainId - The chain ID in the transaction metadata service.
* @param txMetadataSrvUrl - The optional transaction metadata service URL.
* @throws {Error} - If the transport is not defined.
*/
constructor(transport: Transport, txMetadataChainId?: string, txMetadataSrvUrl?: string);
/**
* Retrieves transaction metadata from the metadata service.
* @param txBlob - The transaction blob.
* @param txMetadataChainId - The optional chain ID for the transaction metadata service. This value temporarily overrides the one set in the constructor.
* @param txMetadataSrvUrl - The optional URL for the transaction metadata service. This value temporarily overrides the one set in the constructor.
* @returns The transaction metadata.
* @throws {ResponseError} - If the txMetadataSrvUrl is not defined.
*/
getTxMetadata(txBlob: TransactionBlob, txMetadataChainId?: string, txMetadataSrvUrl?: string): Promise<TransactionMetadataBlob>;
/**
* @deprecated Use getAddressEcdsa or getAddressEd25519 instead. This method will be removed in a future version.
* Retrieves the address for a given BIP44 path and SS58 prefix.
* @param bip44Path - The BIP44 path.
* @param ss58prefix - The SS58 prefix, must be an integer up to 65535.
* @param showAddrInDevice - Whether to show the address on the device.
* @param scheme - The scheme to use for the address. Default is ED25519.
* @returns The address response.
* @throws {ResponseError} If the response from the device indicates an error.
*/
getAddress(bip44Path: BIP32Path, ss58prefix: SS58Prefix, showAddrInDevice?: boolean, scheme?: SCHEME): Promise<GenericeResponseAddress>;
/**
* Retrieves the address for a given BIP44 path using the ECDSA scheme.
* @param bip44Path - The BIP44 path.
* @param showAddrInDevice - Whether to show the address on the device.
* @returns The address response.
* @throws {ResponseError} If the response from the device indicates an error.
*/
getAddressEcdsa(bip44Path: BIP32Path, showAddrInDevice?: boolean): Promise<GenericeResponseAddress>;
/**
* Retrieves the address for a given BIP44 path and SS58 prefix using the ED25519 scheme.
* @param bip44Path - The BIP44 path.
* @param ss58prefix - The SS58 prefix.
* @param showAddrInDevice - Whether to show the address on the device.
* @returns The address response.
* @throws {ResponseError} If the response from the device indicates an error.
*/
getAddressEd25519(bip44Path: BIP32Path, ss58prefix: SS58Prefix, showAddrInDevice?: boolean): Promise<GenericeResponseAddress>;
private splitBufferToChunks;
private getSignReqChunks;
/**
* Signs a transaction blob.
* @param path - The BIP44 path.
* @param ins - The instruction for signing.
* @param blob - The transaction blob.
* @param metadata - The optional metadata.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
private signImplEd25519;
/**
* Signs a transaction blob using the ECDSA scheme.
* @param path - The BIP44 path.
* @param ins - The instruction for signing.
* @param blob - The transaction blob.
* @param metadata - The optional metadata.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status. For ECDSA, the signature is in RSV format:
* - R: First 32 bytes (signature.slice(0, 32))
* - S: Next 32 bytes (signature.slice(32, 64))
* - V: Last byte (signature.slice(64, 65))
* @see parseEcdsaSignature - Use this utility function to easily parse the signature into R, S, V components
*/
private signImplEcdsa;
/**
* @deprecated Use signEcdsa or signEd25519 instead. This method will be removed in a future version.
* Signs a transaction blob retrieving the correct metadata from a metadata service.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param scheme - The scheme to use for the signing. Default is ED25519.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
sign(path: BIP32Path, txBlob: TransactionBlob, scheme?: SCHEME): Promise<GenericResponseSign>;
/**
* Signs a transaction blob using the ED25519 scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signEd25519(path: BIP32Path, txBlob: TransactionBlob): Promise<GenericResponseSign>;
/**
* Signs a transaction blob using the ECDSA scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status. For ECDSA, the signature is in RSV format:
* - R: First 32 bytes (signature.slice(0, 32))
* - S: Next 32 bytes (signature.slice(32, 64))
* - V: Last byte (signature.slice(64, 65))
* @see parseEcdsaSignature - Use this utility function to easily parse the signature into R, S, V components
*/
signEcdsa(path: BIP32Path, txBlob: TransactionBlob): Promise<GenericResponseSign>;
/**
* Signs a transaction blob with provided metadata.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param txMetadataChainId - The optional chain ID for the transaction metadata service. This value temporarily overrides the one set in the constructor.
* @param txMetadataSrvUrl - The optional URL for the transaction metadata service. This value temporarily overrides the one set in the constructor.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signMigration(path: BIP32Path, txBlob: TransactionBlob, txMetadataChainId?: string, txMetadataSrvUrl?: string): Promise<GenericResponseSign>;
/**
* @deprecated Use signRawEcdsa or signRawEd25519 instead. This method will be removed in a future version.
* Signs a raw transaction blob.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param scheme - The scheme to use for the signing. Default is ED25519.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signRaw(path: BIP32Path, txBlob: TransactionBlob, scheme?: SCHEME): Promise<GenericResponseSign>;
/**
* Signs a raw transaction blob using the ED25519 scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signRawEd25519(path: BIP32Path, txBlob: TransactionBlob): Promise<GenericResponseSign>;
/**
* Signs a raw transaction blob using the ECDSA scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status. For ECDSA, the signature is in RSV format:
* - R: First 32 bytes (signature.slice(0, 32))
* - S: Next 32 bytes (signature.slice(32, 64))
* - V: Last byte (signature.slice(64, 65))
* @see parseEcdsaSignature - Use this utility function to easily parse the signature into R, S, V components
*/
signRawEcdsa(path: BIP32Path, txBlob: TransactionBlob): Promise<GenericResponseSign>;
/**
* @deprecated Use signWithMetadataEd25519 or signWithMetadataEcdsa instead. This method will be removed in a future version.
* [Expert-only Method] Signs a transaction blob with provided metadata (this could be used also with a migration app)
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param txMetadata - The transaction metadata.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signWithMetadata(path: BIP32Path, txBlob: TransactionBlob, txMetadata: TransactionMetadataBlob, scheme?: SCHEME): Promise<GenericResponseSign>;
/**
* Signs a transaction blob with provided metadata using the ECDSA scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param txMetadata - The transaction metadata.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status. For ECDSA, the signature is in RSV format:
* - R: First 32 bytes (signature.slice(0, 32))
* - S: Next 32 bytes (signature.slice(32, 64))
* - V: Last byte (signature.slice(64, 65))
* @see parseEcdsaSignature - Use this utility function to easily parse the signature into R, S, V components
*/
signWithMetadataEcdsa(path: BIP32Path, txBlob: TransactionBlob, txMetadata: TransactionMetadataBlob): Promise<GenericResponseSign>;
/**
* Signs a transaction blob with provided metadata using the ED25519 scheme.
* @param path - The BIP44 path.
* @param txBlob - The transaction blob.
* @param txMetadata - The transaction metadata.
* @throws {ResponseError} If the response from the device indicates an error.
* @returns The response containing the signature and status.
*/
signWithMetadataEd25519(path: BIP32Path, txBlob: TransactionBlob, txMetadata: TransactionMetadataBlob): Promise<GenericResponseSign>;
/**
* Utility function to convert ECDSA signature response into RSV structure
* @param signature - The ECDSA signature buffer from the device response
* @returns Object containing R, S, and V components of the ECDSA signature
* @throws {Error} If signature length is not 65 bytes (expected for ECDSA RSV format)
*/
static parseEcdsaSignature(signature: Buffer): {
r: string;
s: string;
v: string;
};
}