UNPKG

@turnkey/core

Version:

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

160 lines 8.6 kB
import { type v1AddressFormat, type v1HashFunction, type v1PayloadEncoding, type Session, type externaldatav1Timestamp, type ProxyTSignupBody, type v1ApiKeyParamsV2, type v1AuthenticatorParamsV2, type v1WalletAccountParams, type v1WalletAccount, type v1OauthProviderParams, type v1SignRawPayloadResult, type v1TransactionType, type ProxyTGetWalletKitConfigResponse, type v1User, type v1CreatePolicyIntentV3, type VerificationToken, TurnkeyErrorCodes } from "@turnkey/sdk-types"; import { type CreateSubOrgParams, type WalletProvider, Chain, EvmChainInfo, SolanaChainInfo, EmbeddedWallet, StamperType, TSignedRequest } from "./__types__"; import type { TurnkeySDKClientBase } from "./__generated__/sdk-client-base"; type AddressFormatConfig = { encoding: v1PayloadEncoding; hashFunction: v1HashFunction; defaultAccounts: v1WalletAccountParams[] | null; displayName: string; }; 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 getActiveSessionOrThrowIfRequired(stampWith: StamperType | undefined, getActiveSession: () => Promise<Session | undefined>): Promise<Session | undefined>; 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(payloadEncoding: v1PayloadEncoding, rawMessage: Uint8Array): string; export declare function hexSignedTxToBase58(hex: 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 getPolicySignature(policy: v1CreatePolicyIntentV3): 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 getCurveTypeFromProvider(provider: WalletProvider): "API_KEY_CURVE_SECP256K1" | "API_KEY_CURVE_ED25519"; /** @internal */ export declare function getSignatureSchemeFromProvider(provider: WalletProvider): "SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191" | "SIGNATURE_SCHEME_TK_API_ED25519"; /** @internal */ export declare function findWalletProviderFromAddress(address: string, providers: WalletProvider[]): WalletProvider | undefined; /** * Derives a wallet address from a given public key and chain. * * @param chain - "ethereum" or "solana" * @param publicKey - The raw public key string (can be compressed or uncompressed) * @returns The derived wallet address */ export declare function addressFromPublicKey(chain: Chain, publicKey: string): string; /**@internal */ export declare function getAuthenticatorAddresses(user: v1User): { ethereum: string[]; solana: string[]; }; /**@internal */ export declare function getAuthProxyConfig(authProxyConfigId: string, authProxyUrl?: string | undefined): Promise<ProxyTGetWalletKitConfigResponse>; /** * Submits a signed request to Turnkey. * * You can pass in the SignedRequest returned by any of the SDK's * stamping methods (stampStampLogin, stampGetPolicies, etc.). * * @deprecated Use `httpClient.sendSignedRequest()` instead, which includes * automatic activity polling and result extraction. * * @param signedRequest A SignedRequest object returned by a stamping method. * @returns The parsed JSON response from Turnkey. * @throws TurnkeyNetworkError if the request fails. */ export declare function sendSignedRequest<T = any>(signedRequest: TSignedRequest): Promise<T>; /** * @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.customErrorsByCodes 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.customErrorsByMessages 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; customErrorsByCodes?: Partial<Record<TurnkeyErrorCodes, { message: string; code: TurnkeyErrorCodes; }>>; customErrorsByMessages?: Record<string, { message: string; code: TurnkeyErrorCodes; }>; }, finallyOptions?: { finallyFn: () => Promise<void>; }): Promise<T>; /** * @internal * * Asserts that the provided key pair is a valid P-256 ECDSA key pair. * @param pair The key pair to validate. */ export declare function assertValidP256ECDSAKeyPair(pair: CryptoKeyPair): Promise<void>; export declare function isValidPasskeyName(name: string): string; export declare function mapAccountsToWallet(accounts: v1WalletAccount[], walletMap: Map<string, EmbeddedWallet>): EmbeddedWallet[]; export declare function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T>; export declare function fetchAllWalletAccountsWithCursor(httpClient: TurnkeySDKClientBase, organizationId: string, stampWith?: StamperType): Promise<v1WalletAccount[]>; export declare function decodeVerificationToken(verificationToken: string): VerificationToken; export declare function getClientSignatureMessageForLogin({ verificationToken, sessionPublicKey, }: { verificationToken: string; sessionPublicKey?: string; }): { message: string; publicKey: string; }; export declare function getClientSignatureMessageForSignup({ verificationToken, email, phoneNumber, apiKeys, authenticators, oauthProviders, }: { verificationToken: string; email?: string; phoneNumber?: string; apiKeys?: v1ApiKeyParamsV2[]; authenticators?: v1AuthenticatorParamsV2[]; oauthProviders?: v1OauthProviderParams[]; }): { message: string; publicKey: string; }; /** * Wraps a promise with a timeout. If the promise doesn't resolve within * the specified duration, it resolves to the fallback value instead of throwing. * * @param promise - The promise to wrap. * @param fallback - Value to return if the timeout is reached. * @param timeoutMs - Timeout duration in milliseconds. Defaults to 1000ms. * @returns The result of the promise, or the fallback if timed out. */ export declare const withTimeoutFallback: <T>(promise: Promise<T>, fallback: T, timeoutMs?: number) => Promise<T>; export {}; //# sourceMappingURL=utils.d.ts.map