UNPKG

@turnkey/core

Version:

A core JavaScript web and React Native package for interfacing with Turnkey's infrastructure.

100 lines 5.01 kB
import { type v1AddressFormat, type v1HashFunction, type v1PayloadEncoding, type Session, type externaldatav1Timestamp, type ProxyTSignupBody, type v1WalletAccountParams, type v1WalletAccount, TurnkeyErrorCodes, v1SignRawPayloadResult, v1TransactionType, ProxyTGetWalletKitConfigResponse } from "@turnkey/sdk-types"; import { type CreateSubOrgParams, type WalletProvider, EvmChainInfo, SolanaChainInfo } from "@types"; type AddressFormatConfig = { encoding: v1PayloadEncoding; hashFunction: v1HashFunction; defaultAccounts: v1WalletAccountParams[] | null; displayName: string; }; /** * Configuration for all supported address formats. * * Includes: * - encoding type * - hash function * - default accounts for the address format * - display name for the address format * * ```ts * // Example usage: * import { addressFormatConfig } from "@turnkey/sdk-core"; * * const config = addressFormatConfig["ADDRESS_FORMAT_ETHEREUM"]; * ``` */ export declare const addressFormatConfig: Record<v1AddressFormat, AddressFormatConfig>; export declare const googleISS = "https://accounts.google.com"; export declare const isReactNative: () => boolean; export declare const isWeb: () => boolean; export declare const generateRandomBuffer: () => ArrayBuffer; export declare const bytesToHex: (bytes: Uint8Array) => string; export declare const toExternalTimestamp: (date?: Date) => externaldatav1Timestamp; export declare function parseSession(token: string | Session): Session; export declare function getHashFunction(addressFormat: v1AddressFormat): v1HashFunction; export declare function getEncodingType(addressFormat: v1AddressFormat): v1PayloadEncoding; export declare function getEncodedMessage(addressFormat: v1AddressFormat, rawMessage: string): string; export declare const broadcastTransaction: (params: { signedTransaction: string; rpcUrl: string; transactionType: v1TransactionType; }) => Promise<string>; export declare function splitSignature(signature: string, addressFormat: v1AddressFormat): v1SignRawPayloadResult; export declare function isWalletAccountArray(arr: any[]): arr is v1WalletAccountParams[]; export declare function createWalletAccountFromAddressFormat(addressFormat: v1AddressFormat): v1WalletAccountParams; /**@internal */ export declare function generateWalletAccountsFromAddressFormat(params: { addresses: v1AddressFormat[]; existingWalletAccounts?: v1WalletAccount[]; }): v1WalletAccountParams[]; export declare function buildSignUpBody(params: { createSubOrgParams: CreateSubOrgParams | undefined; }): ProxyTSignupBody; /** * Extracts the public key from a Turnkey stamp header value. * @param stampHeaderValue - The base64url encoded stamp header value * @returns The public key as a hex string */ export declare function getPublicKeyFromStampHeader(stampHeaderValue: string): string; /**@internal */ export declare function isEthereumProvider(provider: WalletProvider): provider is WalletProvider & { chainInfo: EvmChainInfo; }; /**@internal */ export declare function isSolanaProvider(provider: WalletProvider): provider is WalletProvider & { chainInfo: SolanaChainInfo; }; /** @internal */ export declare function findWalletProviderFromAddress(address: string, providers: WalletProvider[]): WalletProvider | undefined; /**@internal */ export declare function getAuthProxyConfig(authProxyConfigId: string, authProxyUrl?: string | undefined): Promise<ProxyTGetWalletKitConfigResponse>; /** * @internal * Executes an async function with error handling. * * @param fn The async function to execute with error handling * @param errorOptions Options for customizing error handling * @param errorOptions.catchFn Optional function to execute in the catch block * @param errorOptions.errorMessage The default error message to use if no custom message is found * @param errorOptions.errorCode The default error code to use if no custom message is found * @param errorOptions.customMessageByCodes Optional mapping of error codes to custom messages, if you're trying to target a specific error code and surface a custom message, use this * @param errorOptions.customMessageByMessages Optional mapping of error messages to custom messages, if you're trying to target a specific error message and surface a custom message, use this * @param finallyFn Optional function to execute in the finally block * @returns The result of the async function or throws an error */ export declare function withTurnkeyErrorHandling<T>(fn: () => Promise<T>, catchOptions: { catchFn?: () => Promise<void>; errorMessage: string; errorCode: TurnkeyErrorCodes; customMessageByCodes?: Partial<Record<TurnkeyErrorCodes, { message: string; code: TurnkeyErrorCodes; }>>; customMessageByMessages?: Record<string, { message: string; code: TurnkeyErrorCodes; }>; }, finallyOptions?: { finallyFn: () => Promise<void>; }): Promise<T>; export {}; //# sourceMappingURL=utils.d.ts.map