@ledgerhq/hw-app-canton
Version:
Ledger Hardware Wallet Canton Application API
153 lines • 4.48 kB
TypeScript
import type Transport from "@ledgerhq/hw-transport";
export type * from "./types";
export declare const CLA = 224;
export declare const P1_NON_CONFIRM = 0;
export declare const P1_CONFIRM = 1;
export declare const P1_SIGN_UNTYPED_VERSIONED_MESSAGE = 1;
export declare const P1_SIGN_PREPARED_TRANSACTION = 2;
export declare const P2_NONE = 0;
export declare const P2_FIRST = 1;
export declare const P2_MORE = 2;
export declare const P2_MSG_END = 4;
export declare const INS: {
GET_VERSION: number;
GET_APP_NAME: number;
GET_ADDR: number;
SIGN: number;
};
export declare const STATUS: {
OK: number;
USER_CANCEL: number;
};
export declare const SIGNATURE_FRAMING_BYTE = 64;
export declare const SIGNATURE_END_BYTE = 0;
export type AppConfig = {
version: string;
};
export type CantonAddress = {
publicKey: string;
address: string;
path: string;
};
export type CantonSignature = {
signature: string;
applicationSignature?: string;
};
export type CantonPreparedTransaction = {
damlTransaction: Uint8Array;
nodes: Uint8Array[];
metadata: Uint8Array;
inputContracts: Uint8Array[];
};
export type CantonUntypedVersionedMessage = {
transactions: string[];
challenge?: string;
};
/**
* Canton BOLOS API
*/
export default class Canton {
transport: Transport;
constructor(transport: Transport, scrambleKey?: string);
/**
* Get a Canton address for a given BIP-32 path.
*
* @param path a path in BIP-32 format
* @param display whether to display the address on the device
* @return the address and public key
*/
getAddress(path: string, display?: boolean): Promise<CantonAddress>;
/**
* Sign a Canton transaction
* using the appropriate signing method based on transaction type.
*
* @param path a path in BIP-32 format
* @param data either prepared transaction components, untyped versioned message, or txHash string (backwards compatibility)
* @return the signature
*/
signTransaction(path: string, data: CantonPreparedTransaction | CantonUntypedVersionedMessage | string): Promise<CantonSignature>;
/**
* Sign a transaction hash (backwards compatibility)
* @private
*/
private signTxHash;
/**
* Sign a prepared Canton transaction
* @private
*/
private signPreparedTransaction;
/**
* Sign topology transactions for Canton onboarding
* @private
*/
private signUntypedVersionedMessage;
/**
* Get the app configuration.
* @return the app configuration including version
*/
getAppConfiguration(): Promise<AppConfig>;
/**
* Validate Uint8Array with descriptive error message
* @private
*/
private validateUint8Array;
/**
* Unified chunking strategy for sending data to device
*
* P2 flag combinations per protocol (see app-canton/doc/APDU.md):
* - P2_MORE (0x02): More chunks to come for current transaction
* - P2_MORE | P2_MSG_END (0x06): Transaction complete, more transactions expected
* - P2_MSG_END (0x04): Final transaction, end of sequence
*
* @private
*/
private sendChunkedData;
/**
* Create optimized chunks from payload
* @private
*/
private createChunks;
/**
* Parse signature response - handles both TLV format (onboarding) and single signatures
* @private
*/
private parseSignatureResponse;
/**
* Check transport response for errors and throw appropriate exceptions
* @private
*/
private checkTransportResponse;
/**
* Extract response data from transport response
* APDU responses have format: [data][status_code(2_bytes)]
* @private
*/
private extractResponseData;
/**
* Serialize a BIP-32 path string to a data buffer for Canton BOLOS
* @private
*/
private serializeBipPath;
/**
* Serialize a BIP path array to a data buffer for Canton BOLOS
* @private
*/
private serializePath;
/**
* Convert public key to address
* @private
*/
private publicKeyToAddress;
/**
* Extract Pubkey info from APDU response
* @private
* @returns Object with publicKey and chainCode as hex strings
*/
private extractPublicKeyAndChainCode;
/**
* Extract AppVersion from APDU response
* @private
*/
private extractVersion;
}
//# sourceMappingURL=Canton.d.ts.map