import { Hash, Signature, Address, TypedData, Hex, TypedDataDefinition, TransactionSerializable, Authorization, TransactionSerializableEIP7702 } from 'viem'; import { ec } from 'elliptic'; import * as bn_js from 'bn.js'; import { BN } from 'bn.js'; import { Buffer as Buffer$1 } from 'buffer'; declare const CALLDATA: { EVM: { type: number; parsers: { parseSolidityJSONABI: (sig: string, abi: any[]) => { def: { canonicalName: string; def: any; }; }; parseCanonicalName: (sig: string, name: string) => any[]; }; processors: { getNestedCalldata: (def: any, calldata: any) => any[]; replaceNestedDefs: (def: any, nestedDefs: any) => any; }; }; }; declare enum LatticeGetAddressesFlag { none = 0,// For formatted addresses secp256k1Pubkey = 3, ed25519Pubkey = 4, bls12_381Pubkey = 5, secp256k1Xpub = 6 } declare enum LatticeSignHash { none = 0, keccak256 = 1, sha256 = 2 } declare enum LatticeSignCurve { secp256k1 = 0, ed25519 = 1, bls12_381 = 2 } declare enum LatticeSignEncoding { none = 1, solana = 2, evm = 4, eth_deposit = 5, eip7702_auth = 6, eip7702_auth_list = 7 } declare enum LatticeSignBlsDst { NUL = 1, POP = 2 } declare enum LatticeEncDataSchema { eip2335 = 0 } /** * Externally exported constants used for building requests * @public */ declare const EXTERNAL$1: { readonly GET_ADDR_FLAGS: { readonly SECP256K1_PUB: LatticeGetAddressesFlag.secp256k1Pubkey; readonly ED25519_PUB: LatticeGetAddressesFlag.ed25519Pubkey; readonly BLS12_381_G1_PUB: LatticeGetAddressesFlag.bls12_381Pubkey; readonly SECP256K1_XPUB: LatticeGetAddressesFlag.secp256k1Xpub; }; readonly SIGNING: { readonly HASHES: { readonly NONE: LatticeSignHash.none; readonly KECCAK256: LatticeSignHash.keccak256; readonly SHA256: LatticeSignHash.sha256; }; readonly CURVES: { readonly SECP256K1: LatticeSignCurve.secp256k1; readonly ED25519: LatticeSignCurve.ed25519; readonly BLS12_381_G2: LatticeSignCurve.bls12_381; }; readonly ENCODINGS: { readonly NONE: LatticeSignEncoding.none; readonly SOLANA: LatticeSignEncoding.solana; readonly EVM: LatticeSignEncoding.evm; readonly ETH_DEPOSIT: LatticeSignEncoding.eth_deposit; readonly EIP7702_AUTH: LatticeSignEncoding.eip7702_auth; readonly EIP7702_AUTH_LIST: LatticeSignEncoding.eip7702_auth_list; }; readonly BLS_DST: { readonly BLS_DST_NUL: LatticeSignBlsDst.NUL; readonly BLS_DST_POP: LatticeSignBlsDst.POP; }; }; readonly ENC_DATA: { readonly SCHEMAS: { readonly BLS_KEYSTORE_EIP2335_PBKDF_V4: LatticeEncDataSchema; }; }; readonly ETH_CONSENSUS_SPEC: { readonly NETWORKS: { readonly MAINNET_GENESIS: { readonly networkName: "mainnet"; readonly forkVersion: Buffer; readonly validatorsRoot: Buffer; }; }; readonly DOMAINS: { readonly DEPOSIT: Buffer; readonly VOLUNTARY_EXIT: Buffer; }; }; }; /** @internal */ declare const CURRENCIES: { readonly ETH: "ETH"; readonly BTC: "BTC"; readonly ETH_MSG: "ETH_MSG"; }; /** * Derivation path for Bitcoin legacy xpub (BIP44). * Use with fetchAddressesByDerivationPath() and LatticeGetAddressesFlag.secp256k1Xpub * @example * const xpub = await fetchAddressesByDerivationPath(BTC_LEGACY_XPUB_PATH, { * flag: LatticeGetAddressesFlag.secp256k1Xpub * }); */ declare const BTC_LEGACY_XPUB_PATH = "44'/0'/0'"; /** * Derivation path for Bitcoin wrapped segwit ypub (BIP49). * Use with fetchAddressesByDerivationPath() and LatticeGetAddressesFlag.secp256k1Xpub * @example * const ypub = await fetchAddressesByDerivationPath(BTC_WRAPPED_SEGWIT_YPUB_PATH, { * flag: LatticeGetAddressesFlag.secp256k1Xpub * }); */ declare const BTC_WRAPPED_SEGWIT_YPUB_PATH = "49'/0'/0'"; /** * Derivation path for Bitcoin native segwit zpub (BIP84). * Use with fetchAddressesByDerivationPath() and LatticeGetAddressesFlag.secp256k1Xpub * @example * const zpub = await fetchAddressesByDerivationPath(BTC_SEGWIT_ZPUB_PATH, { * flag: LatticeGetAddressesFlag.secp256k1Xpub * }); */ declare const BTC_SEGWIT_ZPUB_PATH = "84'/0'/0'"; interface KVRecords { [key: string]: string; } type KeyPair = ec.KeyPair; type WalletPath = [number, number, number, number, number]; type Currency = keyof typeof CURRENCIES; type SigningPath = number[]; interface SignData { tx?: string; txHash?: Hash; changeRecipient?: string; sig?: Signature; sigs?: Buffer[]; signer?: Address; err?: string; } interface Wallet { /** 32 byte id */ uid: Buffer; /** 20 char (max) string */ name: Buffer | null; /** 4 byte flag */ capabilities: number; /** External or internal wallet */ external: boolean; } interface ActiveWallets { internal: Wallet; external: Wallet; } interface AddKvRecordsRequestParams { records: KVRecords; type?: number; caseSensitive?: boolean; } interface EIP2335KeyExportReq { path: number[]; c?: number; kdf?: number; walletUID?: Buffer; } interface FetchEncDataRequest { schema: number; params: EIP2335KeyExportReq; } interface GenericSigningData { calldataDecoding: { reserved: number; maxSz: number; }; baseReqSz: number; baseDataSz: number; hashTypes: typeof EXTERNAL$1.SIGNING.HASHES; curveTypes: typeof EXTERNAL$1.SIGNING.CURVES; encodingTypes: { NONE: typeof EXTERNAL$1.SIGNING.ENCODINGS.NONE; SOLANA: typeof EXTERNAL$1.SIGNING.ENCODINGS.SOLANA; EVM?: typeof EXTERNAL$1.SIGNING.ENCODINGS.EVM; }; } interface FirmwareConstants { abiCategorySz: number; abiMaxRmv: number; addrFlagsAllowed: boolean; allowBtcLegacyAndSegwitAddrs: boolean; allowedEthTxTypes: number[]; contractDeployKey: string; eip712MaxTypeParams: number; eip712Supported: boolean; ethMaxDataSz: number; ethMaxGasPrice: number; ethMaxMsgSz: number; ethMsgPreHashAllowed: boolean; extraDataFrameSz: number; extraDataMaxFrames: number; genericSigning: GenericSigningData; getAddressFlags: [ typeof EXTERNAL$1.GET_ADDR_FLAGS.ED25519_PUB, typeof EXTERNAL$1.GET_ADDR_FLAGS.SECP256K1_PUB ]; kvActionMaxNum: number; kvActionsAllowed: boolean; kvKeyMaxStrSz: number; kvRemoveMaxNum: number; kvValMaxStrSz: number; maxDecoderBufSz: number; personalSignHeaderSz: number; prehashAllowed: boolean; reqMaxDataSz: number; varAddrPathSzAllowed: boolean; flexibleAddrPaths?: boolean; } interface GetAddressesRequestParams { startPath: number[]; n: number; flag?: number; iterIdx?: number; } interface GetKvRecordsRequestParams { type?: number; n?: number; start?: number; } type AddressTag = { caseSensitive: boolean; id: number; key: string; type: number; val: string; }; interface GetKvRecordsData { records: AddressTag[]; fetched: number; total: number; } interface RemoveKvRecordsRequestParams { type?: number; ids?: string[]; } type ETH_MESSAGE_PROTOCOLS = 'eip712' | 'signPersonal'; interface SigningPayload = TypedData> { signerPath: SigningPath; payload: Uint8Array | Uint8Array[] | Buffer | Buffer[] | Hex | EIP712MessagePayload; curveType: number; hashType: number; encodingType?: number; protocol?: ETH_MESSAGE_PROTOCOLS; decoder?: Buffer; } interface SignRequestParams = TypedData> { data: SigningPayload | BitcoinSignPayload; currency?: Currency; cachedData?: unknown; nextCode?: Buffer; } type PreviousOutput = { txHash: string; value: number; index: number; signerPath: number[]; }; type BitcoinSignPayload = { prevOuts: PreviousOutput[]; recipient: string; value: number; fee: number; changePath: number[]; }; interface EIP712MessagePayload = TypedData, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData> { types: TTypedData; domain: TTypedData extends TypedData ? TypedDataDefinition['domain'] : Record; primaryType: TPrimaryType; message: TTypedData extends TypedData ? TypedDataDefinition['message'] : Record; } /** * `Client` is a class-based interface for managing a Lattice device. * * @deprecated * - This class is deprecated for external use. It is used internally by the SDK to manage * the state of the connection to the Lattice device. It is not recommended to use this class directly. * The recommended way to interact with the Lattice is through the functional interface. * - See the [`src/api` directory on GitHub](https://github.com/GridPlus/gridplus-sdk/tree/dev/src/api) * or [learn more in the docs](https://gridplus.github.io/gridplus-sdk/). * */ declare class Client { /** Is the Lattice paired with this Client. */ isPaired: boolean; /** The time to wait for a response before cancelling. */ timeout: number; /** The base of the remote url to which the SDK sends requests. */ baseUrl: string; /** @internal The `baseUrl` plus the `deviceId`. Set in {@link connect} when it completes successfully. */ url?: string; /** `name` is a human readable string associated with this app on the Lattice */ private name; private key; /**`privKey` is used to generate a keypair, which is used for maintaining an encrypted messaging channel with the target Lattice */ private privKey; private retryCount; private fwVersion?; private skipRetryOnWrongWallet; /** Temporary secret that is generated by the Lattice device */ private _ephemeralPub; /** The ID of the connected Lattice */ private deviceId?; /** Information about the current wallet. Should be null unless we know a wallet is present */ activeWallets: ActiveWallets; /** A wrapper function for handling retries and injecting the {@link Client} class */ private retryWrapper; /** Function to set the stored client data */ private setStoredClient?; /** * @param params - Parameters are passed as an object. */ constructor({ baseUrl, name, privKey, stateData, timeout, retryCount, skipRetryOnWrongWallet, deviceId, setStoredClient, }: { /** The base URL of the signing server. */ baseUrl?: string; /** The name of the client. */ name?: string; /** The private key of the client.*/ privKey?: Buffer | string; /** Number of times to retry a request if it fails. */ retryCount?: number; /** The time to wait for a response before cancelling. */ timeout?: number; /** User can pass in previous state data to rehydrate connected session */ stateData?: string; /** If true we will not retry if we get a wrong wallet error code */ skipRetryOnWrongWallet?: boolean; /** The ID of the connected Lattice */ deviceId?: string; /** Function to set the stored client data */ setStoredClient?: (clientData: string | null) => Promise; }); /** * Get the public key associated with the client's static keypair. * The public key is used for identifying the client to the Lattice. * @internal * @returns Buffer */ get publicKey(): Buffer; /** * Get the pairing name for this client instance */ getAppName(): string; /** * Get the `deviceId` for this client instance */ getDeviceId(): string; /** * Get the shared secret, derived via ECDH from the local private key and the ephemeral public key * @internal * @returns Buffer */ get sharedSecret(): Buffer; /** @internal */ get ephemeralPub(): KeyPair; /** @internal */ set ephemeralPub(ephemeralPub: KeyPair); /** * Attempt to contact a device based on its `deviceId`. The response should include an ephemeral * public key, which is used to pair with the device in a later request. * @category Lattice */ connect(deviceId: string): Promise; /** * If a pairing secret is provided, `pair` uses it to sign a hash of the public key, name, and * pairing secret. It then sends the name and signature to the device. If no pairing secret is * provided, `pair` sends a zero-length name buffer to the device. * @category Lattice */ pair(pairingSecret: string): Promise; /** * Takes a starting path and a number to get the addresses associated with the active wallet. * @category Lattice */ getAddresses({ startPath, n, flag, iterIdx, }: GetAddressesRequestParams): Promise; /** * Builds and sends a request for signing to the Lattice. * @category Lattice */ sign({ data, currency, cachedData, nextCode, }: SignRequestParams): Promise; /** * Fetch the active wallet in the Lattice. */ fetchActiveWallet(): Promise; /** * Takes in a set of key-value records and sends a request to add them to the Lattice. * @category Lattice */ addKvRecords({ type, records, caseSensitive, }: AddKvRecordsRequestParams): Promise; /** * Fetches a list of key-value records from the Lattice. * @category Lattice */ getKvRecords({ type, n, start, }: GetKvRecordsRequestParams): Promise; /** * Takes in an array of ids and sends a request to remove them from the Lattice. * @category Lattice */ removeKvRecords({ type, ids, }: RemoveKvRecordsRequestParams): Promise; /** * Fetch a record of encrypted data from the Lattice. * Must specify a data type. Returns a Buffer containing * data formatted according to the specified type. * @category Lattice */ fetchEncryptedData(params: FetchEncDataRequest): Promise; /** Get the active wallet */ getActiveWallet(): Wallet; /** Check if the user has an active wallet */ hasActiveWallet(): boolean; /** * Reset the active wallets to empty values. * @category Device Response * @internal */ resetActiveWallets(): void; /** * Get a JSON string containing state data that can be used to rehydrate a session. Pass the * contents of this to the constructor as `stateData` to rehydrate. * @internal */ getStateData(): string; /** * Returns the firmware version constants for the given firmware version. * @internal */ getFwConstants(): FirmwareConstants; /** * `getFwVersion` gets the firmware version of the paired device. * @internal */ getFwVersion(): { fix: number; minor: number; major: number; }; /** * Handles the mutation of Client state in the primary functions. */ mutate({ deviceId, ephemeralPub, url, isPaired, fwVersion, activeWallets, }: { deviceId?: string; ephemeralPub?: KeyPair; url?: string; isPaired?: boolean; fwVersion?: Buffer; activeWallets?: ActiveWallets; }): void; /** * Return JSON-stringified version of state data. Can be used to rehydrate an SDK session without * reconnecting to the target Lattice. * @internal */ private packStateData; /** * Unpack a JSON-stringified version of state data and apply it to state. This will allow us to * rehydrate an old session. * @internal */ private unpackAndApplyStateData; } /** * Fetches calldata from a remote scanner based on the transaction's `chainId` */ declare function fetchCalldataDecoder(_data: Uint8Array | string, to: string, _chainId: number | string, recurse?: boolean): Promise<{ abi: any; def: Buffer$1; }>; /** @internal */ declare const EXTERNAL: { fetchCalldataDecoder: typeof fetchCalldataDecoder; generateAppSecret: (deviceId: Buffer$1 | string, password: Buffer$1 | string, appName: Buffer$1 | string) => Buffer$1; getV: (tx: any, resp: any) => bn_js; getYParity: (messageHash: Buffer$1 | Uint8Array | string | { messageHash: any; signature: any; publicKey: any; } | any, signature?: { r: any; s: any; } | any, publicKey?: Buffer$1 | Uint8Array | string) => number; convertRecoveryToV: (recovery: number, txData?: any) => Buffer$1 | InstanceType; }; declare const getClient: () => Promise; declare function parseDerivationPath(path: string): number[]; type FetchAddressesParams = { n?: number; startPathIndex?: number; flag?: number; }; declare const fetchAddresses: (overrides?: Partial) => Promise; /** * Fetches a single address from the device. * * @note By default, this function fetches m/44'/60'/0'/0/0 * @param path - either the index of ETH signing path or the derivation path to fetch */ declare const fetchAddress: (path?: number | WalletPath) => Promise; declare const fetchBtcLegacyAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBtcSegwitAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBtcWrappedSegwitAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBtcLegacyChangeAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBtcSegwitChangeAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBtcWrappedSegwitChangeAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchSolanaAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchLedgerLiveAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchLedgerLegacyAddresses: ({ n, startPathIndex }?: FetchAddressesParams) => Promise; declare const fetchBip44ChangeAddresses: ({ n, startPathIndex, }?: FetchAddressesParams) => Promise; declare function fetchAddressesByDerivationPath(path: string, { n, startPathIndex, flag }?: FetchAddressesParams): Promise; /** * Fetches Bitcoin legacy extended public key (xpub) for BIP44 (m/44'/0'/0'). * @returns xpub string */ declare function fetchBtcXpub(): Promise; /** * Fetches Bitcoin wrapped segwit extended public key (ypub) for BIP49 (m/49'/0'/0'). * @returns ypub string */ declare function fetchBtcYpub(): Promise; /** * Fetches Bitcoin native segwit extended public key (zpub) for BIP84 (m/84'/0'/0'). * @returns zpub string */ declare function fetchBtcZpub(): Promise; /** * Sends request to the Lattice to add Address Tags. */ declare const addAddressTags: (tags: [{ [key: string]: string; }]) => Promise; /** * Fetches Address Tags from the Lattice. */ declare const fetchAddressTags: ({ n, start, }?: { n?: number; start?: number; }) => Promise; /** * Removes Address Tags from the Lattice. */ declare const removeAddressTags: (tags: AddressTag[]) => Promise; type AuthorizationRequest = { chainId: number; nonce: number; } & ({ address: Address; } | { contractAddress: Address; }); /** * Sign a transaction using Viem-compatible transaction types */ type RawTransaction = Hex | Uint8Array | Buffer; declare const sign: (transaction: TransactionSerializable | RawTransaction, overrides?: Omit) => Promise; /** * Sign a message with support for EIP-712 typed data and const assertions */ declare function signMessage(payload: string | Uint8Array | Buffer | Buffer[] | EIP712MessagePayload>, overrides?: Omit): Promise; /** * Signs an EIP-7702 authorization to set code for an externally owned account (EOA). * Returns a Viem-compatible authorization object. */ declare const signAuthorization: (authorization: AuthorizationRequest, overrides?: Omit) => Promise; /** * Sign an EIP-7702 transaction using Viem-compatible types */ declare const signAuthorizationList: (tx: TransactionSerializableEIP7702) => Promise; declare const signBtcLegacyTx: (payload: BitcoinSignPayload) => Promise; declare const signBtcSegwitTx: (payload: BitcoinSignPayload) => Promise; declare const signBtcWrappedSegwitTx: (payload: BitcoinSignPayload) => Promise; declare const signSolanaTx: (payload: Buffer, overrides?: SignRequestParams) => Promise; /** * Fetches the active wallets */ declare const fetchActiveWallets: () => Promise; /** * @interface {Object} SetupParameters - parameters for the setup function * @prop {string} SetupParameters.deviceId - the device id of the client * @prop {string} SetupParameters.password - the password of the client * @prop {string} SetupParameters.name - the name of the client * @prop {string} SetupParameters.appSecret - the app secret of the client * @prop {Function} SetupParameters.getStoredClient - a function that returns the stored client data * @prop {Function} SetupParameters.setStoredClient - a function that stores the client data */ type SetupParameters = { deviceId: string; password: string; name: string; appSecret?: string; getStoredClient: () => Promise; setStoredClient: (clientData: string | null) => Promise; baseUrl?: string; } | { getStoredClient: () => Promise; setStoredClient: (clientData: string | null) => Promise; }; /** * `setup` initializes the Client and executes `connect()` if necessary. It returns a promise that * resolves to a boolean that indicates whether the Client is paired to the application to which it's * attempting to connect. * * @param {Object} SetupParameters - paramaters for the setup function * @param {string} SetupParameters.deviceId - the device id of the client * @param {string} SetupParameters.password - the password of the client * @param {string} SetupParameters.name - the name of the client * @param {string} SetupParameters.appSecret - the app secret of the client * @param {Function} SetupParameters.getStoredClient - a function that returns the stored client data * @param {Function} SetupParameters.setStoredClient - a function that stores the client data * @returns {Promise} - a promise that resolves to a boolean that indicates whether the Client is paired to the application to which it's attempting to connect * */ declare const setup: (params: SetupParameters) => Promise; declare const connect: (deviceId: string) => Promise; declare const pair: (pairingCode: string) => Promise; export { BTC_LEGACY_XPUB_PATH, BTC_SEGWIT_ZPUB_PATH, BTC_WRAPPED_SEGWIT_YPUB_PATH, CALLDATA as Calldata, Client, EXTERNAL$1 as Constants, EXTERNAL as Utils, addAddressTags, connect, fetchActiveWallets, fetchAddress, fetchAddressTags, fetchAddresses, fetchAddressesByDerivationPath, fetchBip44ChangeAddresses, fetchBtcLegacyAddresses, fetchBtcLegacyChangeAddresses, fetchBtcSegwitAddresses, fetchBtcSegwitChangeAddresses, fetchBtcWrappedSegwitAddresses, fetchBtcWrappedSegwitChangeAddresses, fetchBtcXpub, fetchBtcYpub, fetchBtcZpub, fetchLedgerLegacyAddresses, fetchLedgerLiveAddresses, fetchSolanaAddresses, getClient, pair, parseDerivationPath, removeAddressTags, setup, sign, signAuthorization, signAuthorizationList, signBtcLegacyTx, signBtcSegwitTx, signBtcWrappedSegwitTx, signMessage, signSolanaTx };