@turnkey/core 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.MD +5 -0
- package/dist/__clients__/core.d.ts +1010 -0
- package/dist/__clients__/core.d.ts.map +1 -0
- package/dist/__clients__/core.js +2358 -0
- package/dist/__clients__/core.js.map +1 -0
- package/dist/__clients__/core.mjs +2356 -0
- package/dist/__clients__/core.mjs.map +1 -0
- package/dist/__generated__/sdk-client-base.d.ts +211 -0
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -0
- package/dist/__generated__/sdk-client-base.js +3219 -0
- package/dist/__generated__/sdk-client-base.js.map +1 -0
- package/dist/__generated__/sdk-client-base.mjs +3217 -0
- package/dist/__generated__/sdk-client-base.mjs.map +1 -0
- package/dist/__generated__/version.d.ts +2 -0
- package/dist/__generated__/version.d.ts.map +1 -0
- package/dist/__generated__/version.js +6 -0
- package/dist/__generated__/version.js.map +1 -0
- package/dist/__generated__/version.mjs +4 -0
- package/dist/__generated__/version.mjs.map +1 -0
- package/dist/__inputs__/public_api.types.d.ts +5170 -0
- package/dist/__inputs__/public_api.types.d.ts.map +1 -0
- package/dist/__polyfills__/window.d.ts +15 -0
- package/dist/__polyfills__/window.d.ts.map +1 -0
- package/dist/__polyfills__/window.js +30 -0
- package/dist/__polyfills__/window.js.map +1 -0
- package/dist/__polyfills__/window.mjs +28 -0
- package/dist/__polyfills__/window.mjs.map +1 -0
- package/dist/__stampers__/api/base.d.ts +20 -0
- package/dist/__stampers__/api/base.d.ts.map +1 -0
- package/dist/__stampers__/api/base.js +67 -0
- package/dist/__stampers__/api/base.js.map +1 -0
- package/dist/__stampers__/api/base.mjs +65 -0
- package/dist/__stampers__/api/base.mjs.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.d.ts +13 -0
- package/dist/__stampers__/api/mobile/stamper.d.ts.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.js +69 -0
- package/dist/__stampers__/api/mobile/stamper.js.map +1 -0
- package/dist/__stampers__/api/mobile/stamper.mjs +67 -0
- package/dist/__stampers__/api/mobile/stamper.mjs.map +1 -0
- package/dist/__stampers__/api/web/stamper.d.ts +14 -0
- package/dist/__stampers__/api/web/stamper.d.ts.map +1 -0
- package/dist/__stampers__/api/web/stamper.js +212 -0
- package/dist/__stampers__/api/web/stamper.js.map +1 -0
- package/dist/__stampers__/api/web/stamper.mjs +210 -0
- package/dist/__stampers__/api/web/stamper.mjs.map +1 -0
- package/dist/__stampers__/passkey/base.d.ts +18 -0
- package/dist/__stampers__/passkey/base.d.ts.map +1 -0
- package/dist/__stampers__/passkey/base.js +138 -0
- package/dist/__stampers__/passkey/base.js.map +1 -0
- package/dist/__stampers__/passkey/base.mjs +134 -0
- package/dist/__stampers__/passkey/base.mjs.map +1 -0
- package/dist/__storage__/base.d.ts +3 -0
- package/dist/__storage__/base.d.ts.map +1 -0
- package/dist/__storage__/base.js +27 -0
- package/dist/__storage__/base.js.map +1 -0
- package/dist/__storage__/base.mjs +25 -0
- package/dist/__storage__/base.mjs.map +1 -0
- package/dist/__storage__/mobile/storage.d.ts +18 -0
- package/dist/__storage__/mobile/storage.d.ts.map +1 -0
- package/dist/__storage__/mobile/storage.js +74 -0
- package/dist/__storage__/mobile/storage.js.map +1 -0
- package/dist/__storage__/mobile/storage.mjs +72 -0
- package/dist/__storage__/mobile/storage.mjs.map +1 -0
- package/dist/__storage__/web/storage.d.ts +19 -0
- package/dist/__storage__/web/storage.d.ts.map +1 -0
- package/dist/__storage__/web/storage.js +79 -0
- package/dist/__storage__/web/storage.js.map +1 -0
- package/dist/__storage__/web/storage.mjs +77 -0
- package/dist/__storage__/web/storage.mjs.map +1 -0
- package/dist/__types__/base.d.ts +407 -0
- package/dist/__types__/base.d.ts.map +1 -0
- package/dist/__types__/base.js +88 -0
- package/dist/__types__/base.js.map +1 -0
- package/dist/__types__/base.mjs +84 -0
- package/dist/__types__/base.mjs.map +1 -0
- package/dist/__wallet__/base.d.ts +3 -0
- package/dist/__wallet__/base.d.ts.map +1 -0
- package/dist/__wallet__/base.js +24 -0
- package/dist/__wallet__/base.js.map +1 -0
- package/dist/__wallet__/base.mjs +22 -0
- package/dist/__wallet__/base.mjs.map +1 -0
- package/dist/__wallet__/connector.d.ts +33 -0
- package/dist/__wallet__/connector.d.ts.map +1 -0
- package/dist/__wallet__/connector.js +63 -0
- package/dist/__wallet__/connector.js.map +1 -0
- package/dist/__wallet__/connector.mjs +61 -0
- package/dist/__wallet__/connector.mjs.map +1 -0
- package/dist/__wallet__/mobile/manager.d.ts +35 -0
- package/dist/__wallet__/mobile/manager.d.ts.map +1 -0
- package/dist/__wallet__/mobile/manager.js +95 -0
- package/dist/__wallet__/mobile/manager.js.map +1 -0
- package/dist/__wallet__/mobile/manager.mjs +93 -0
- package/dist/__wallet__/mobile/manager.mjs.map +1 -0
- package/dist/__wallet__/stamper.d.ts +19 -0
- package/dist/__wallet__/stamper.d.ts.map +1 -0
- package/dist/__wallet__/stamper.js +116 -0
- package/dist/__wallet__/stamper.js.map +1 -0
- package/dist/__wallet__/stamper.mjs +113 -0
- package/dist/__wallet__/stamper.mjs.map +1 -0
- package/dist/__wallet__/wallet-connect/base.d.ts +83 -0
- package/dist/__wallet__/wallet-connect/base.d.ts.map +1 -0
- package/dist/__wallet__/wallet-connect/base.js +362 -0
- package/dist/__wallet__/wallet-connect/base.js.map +1 -0
- package/dist/__wallet__/wallet-connect/base.mjs +360 -0
- package/dist/__wallet__/wallet-connect/base.mjs.map +1 -0
- package/dist/__wallet__/wallet-connect/client.d.ts +78 -0
- package/dist/__wallet__/wallet-connect/client.d.ts.map +1 -0
- package/dist/__wallet__/wallet-connect/client.js +139 -0
- package/dist/__wallet__/wallet-connect/client.js.map +1 -0
- package/dist/__wallet__/wallet-connect/client.mjs +137 -0
- package/dist/__wallet__/wallet-connect/client.mjs.map +1 -0
- package/dist/__wallet__/web/manager.d.ts +41 -0
- package/dist/__wallet__/web/manager.d.ts.map +1 -0
- package/dist/__wallet__/web/manager.js +115 -0
- package/dist/__wallet__/web/manager.js.map +1 -0
- package/dist/__wallet__/web/manager.mjs +113 -0
- package/dist/__wallet__/web/manager.mjs.map +1 -0
- package/dist/__wallet__/web/native/ethereum.d.ts +67 -0
- package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -0
- package/dist/__wallet__/web/native/ethereum.js +248 -0
- package/dist/__wallet__/web/native/ethereum.js.map +1 -0
- package/dist/__wallet__/web/native/ethereum.mjs +245 -0
- package/dist/__wallet__/web/native/ethereum.mjs.map +1 -0
- package/dist/__wallet__/web/native/solana.d.ts +19 -0
- package/dist/__wallet__/web/native/solana.d.ts.map +1 -0
- package/dist/__wallet__/web/native/solana.js +149 -0
- package/dist/__wallet__/web/native/solana.js.map +1 -0
- package/dist/__wallet__/web/native/solana.mjs +146 -0
- package/dist/__wallet__/web/native/solana.mjs.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/turnkey-helpers.d.ts +68 -0
- package/dist/turnkey-helpers.d.ts.map +1 -0
- package/dist/turnkey-helpers.js +466 -0
- package/dist/turnkey-helpers.js.map +1 -0
- package/dist/turnkey-helpers.mjs +399 -0
- package/dist/turnkey-helpers.mjs.map +1 -0
- package/dist/utils.d.ts +54 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +596 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +574 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
import { TurnkeySDKClientBase } from "../__generated__/sdk-client-base";
|
|
2
|
+
import { TDeleteSubOrganizationResponse, Session, TStampLoginResponse, v1AddressFormat, v1Attestation, v1Pagination, v1SignRawPayloadResult, v1TransactionType, v1User, ProxyTGetWalletKitConfigResponse, v1WalletAccountParams, v1PayloadEncoding, v1HashFunction } from "@turnkey/sdk-types";
|
|
3
|
+
import { ExportBundle, StamperType, TurnkeySDKClientConfig, WalletAccount, Wallet, OtpType, CreateSubOrgParams, Chain, WalletManagerBase, WalletProvider, SwitchableChain } from "../__types__/base";
|
|
4
|
+
import { CrossPlatformApiKeyStamper } from "../__stampers__/api/base";
|
|
5
|
+
import { CrossPlatformPasskeyStamper } from "../__stampers__/passkey/base";
|
|
6
|
+
type PublicMethods<T> = {
|
|
7
|
+
[K in keyof T as K extends string | number | symbol ? K extends "init" | "constructor" | "config" | "httpClient" | "user" | "wallets" ? never : K : never]: T[K] extends (...args: any[]) => any ? T[K] : never;
|
|
8
|
+
};
|
|
9
|
+
export type TurnkeyClientMethods = PublicMethods<TurnkeyClient>;
|
|
10
|
+
export declare class TurnkeyClient {
|
|
11
|
+
config: TurnkeySDKClientConfig;
|
|
12
|
+
httpClient: TurnkeySDKClientBase;
|
|
13
|
+
private apiKeyStamper?;
|
|
14
|
+
private passkeyStamper?;
|
|
15
|
+
private walletManager?;
|
|
16
|
+
private storageManager;
|
|
17
|
+
constructor(config: TurnkeySDKClientConfig, apiKeyStamper?: CrossPlatformApiKeyStamper, passkeyStamper?: CrossPlatformPasskeyStamper, walletManager?: WalletManagerBase);
|
|
18
|
+
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new passkey authenticator for the user.
|
|
21
|
+
*
|
|
22
|
+
* - This function generates a new passkey attestation and challenge, suitable for registration with the user's device.
|
|
23
|
+
* - Handles both web and React Native environments, automatically selecting the appropriate passkey creation flow.
|
|
24
|
+
* - The resulting attestation and challenge can be used to register the passkey with Turnkey.
|
|
25
|
+
*
|
|
26
|
+
* @param params.name - name of the passkey. If not provided, defaults to "A Passkey".
|
|
27
|
+
* @param params.displayName - display name for the passkey. If not provided, defaults to "A Passkey".
|
|
28
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
29
|
+
* @returns A promise that resolves to an object containing:
|
|
30
|
+
* - attestation: attestation object returned from the passkey creation process.
|
|
31
|
+
* - encodedChallenge: encoded challenge string used for passkey registration.
|
|
32
|
+
* @throws {TurnkeyError} If there is an error during passkey creation, or if the platform is unsupported.
|
|
33
|
+
*/
|
|
34
|
+
createPasskey: (params?: {
|
|
35
|
+
name?: string;
|
|
36
|
+
displayName?: string;
|
|
37
|
+
stampWith?: StamperType | undefined;
|
|
38
|
+
}) => Promise<{
|
|
39
|
+
attestation: v1Attestation;
|
|
40
|
+
encodedChallenge: string;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Logs out the current client session.
|
|
44
|
+
*
|
|
45
|
+
* - This function clears the specified session and removes any associated key pairs from storage.
|
|
46
|
+
* - If a sessionKey is provided, it logs out from that session; otherwise, it logs out from the active session.
|
|
47
|
+
* - Cleans up any api keys associated with the session.
|
|
48
|
+
*
|
|
49
|
+
* @param params.sessionKey - session key to specify which session to log out from (defaults to the active session).
|
|
50
|
+
* @returns A promise that resolves when the logout process is complete.
|
|
51
|
+
* @throws {TurnkeyError} If there is no active session or if there is an error during the logout process.
|
|
52
|
+
*/
|
|
53
|
+
logout: (params?: {
|
|
54
|
+
sessionKey?: string;
|
|
55
|
+
}) => Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Logs in a user using a passkey, optionally specifying the public key, session key, and session expiration.
|
|
58
|
+
*
|
|
59
|
+
* - This function initiates the login process with a passkey and handles session creation and storage.
|
|
60
|
+
* - If a public key is not provided, a new key pair will be generated for authentication.
|
|
61
|
+
* - If a session key is not provided, the default session key will be used.
|
|
62
|
+
* - The session expiration can be customized via the expirationSeconds parameter.
|
|
63
|
+
* - Handles cleanup of unused key pairs if login fails.
|
|
64
|
+
*
|
|
65
|
+
* @param params.publicKey - public key to use for authentication. If not provided, a new key pair will be generated.
|
|
66
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
67
|
+
* @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
|
|
68
|
+
* @returns A promise that resolves to a signed JWT session token.
|
|
69
|
+
* @throws {TurnkeyError} If there is an error during the passkey login process or if the user cancels the passkey prompt.
|
|
70
|
+
*/
|
|
71
|
+
loginWithPasskey: (params?: {
|
|
72
|
+
publicKey?: string;
|
|
73
|
+
sessionKey?: string;
|
|
74
|
+
expirationSeconds?: string;
|
|
75
|
+
}) => Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Signs up a user using a passkey, creating a new sub-organization and session.
|
|
78
|
+
*
|
|
79
|
+
* - This function creates a new passkey authenticator and uses it to register a new sub-organization for the user.
|
|
80
|
+
* - Handles both passkey creation and sub-organization creation in a single flow.
|
|
81
|
+
* - Optionally accepts additional sub-organization parameters, a custom session key, a custom passkey display name, and a custom session expiration.
|
|
82
|
+
* - Automatically generates a new API key pair for authentication and session management.
|
|
83
|
+
* - Stores the resulting session token and manages cleanup of unused key pairs.
|
|
84
|
+
*
|
|
85
|
+
* @param params.createSubOrgParams - parameters for creating a sub-organization (e.g., authenticators, user metadata).
|
|
86
|
+
* @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
|
|
87
|
+
* @param params.passkeyDisplayName - display name for the passkey (defaults to a generated name based on the current timestamp).
|
|
88
|
+
* @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
|
|
89
|
+
* @returns A promise that resolves to a signed JWT session token for the new sub-organization.
|
|
90
|
+
* @throws {TurnkeyError} If there is an error during passkey creation, sub-organization creation, or session storage.
|
|
91
|
+
*/
|
|
92
|
+
signUpWithPasskey: (params?: {
|
|
93
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
94
|
+
sessionKey?: string;
|
|
95
|
+
passkeyDisplayName?: string;
|
|
96
|
+
expirationSeconds?: string;
|
|
97
|
+
}) => Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves wallet providers from the initialized wallet manager.
|
|
100
|
+
*
|
|
101
|
+
* - Optionally filters providers by the specified blockchain chain.
|
|
102
|
+
* - Throws an error if the wallet manager is not initialized.
|
|
103
|
+
*
|
|
104
|
+
* @param chain - optional blockchain chain to filter the returned providers.
|
|
105
|
+
* @returns A promise that resolves to an array of wallet providers.
|
|
106
|
+
* @throws {TurnkeyError} If the wallet manager is uninitialized or provider retrieval fails.
|
|
107
|
+
*/
|
|
108
|
+
getWalletProviders: (chain?: Chain) => Promise<WalletProvider[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Connects the specified wallet account.
|
|
111
|
+
*
|
|
112
|
+
* - Requires the wallet manager and its connector to be initialized.
|
|
113
|
+
*
|
|
114
|
+
* @param walletProvider - wallet provider to connect.
|
|
115
|
+
* @returns A promise that resolves once the wallet account is connected.
|
|
116
|
+
* @throws {TurnkeyError} If the wallet manager is uninitialized or the connection fails.
|
|
117
|
+
*/
|
|
118
|
+
connectWalletAccount: (walletProvider: WalletProvider) => Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Disconnects the specified wallet account.
|
|
121
|
+
*
|
|
122
|
+
* - Requires the wallet manager and its connector to be initialized.
|
|
123
|
+
*
|
|
124
|
+
* @param walletProvider - wallet provider to disconnect.
|
|
125
|
+
* @returns A promise that resolves once the wallet account is disconnected.
|
|
126
|
+
* @throws {TurnkeyError} If the wallet manager is uninitialized or the disconnection fails.
|
|
127
|
+
*/
|
|
128
|
+
disconnectWalletAccount: (walletProvider: WalletProvider) => Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Switches the specified wallet provider to a different blockchain chain.
|
|
131
|
+
*
|
|
132
|
+
* - Requires the wallet manager and its connector to be initialized.
|
|
133
|
+
* - The wallet provider must have at least one connected address.
|
|
134
|
+
* - Does nothing if the wallet provider is already on the desired chain.
|
|
135
|
+
*
|
|
136
|
+
* @param walletProvider - wallet provider to switch.
|
|
137
|
+
* @param chainOrId - target chain as a chain ID string or SwitchableChain object.
|
|
138
|
+
* @returns A promise that resolves once the chain switch is complete.
|
|
139
|
+
* @throws {TurnkeyError} If the wallet manager is uninitialized, the provider is not connected, or the switch fails.
|
|
140
|
+
*/
|
|
141
|
+
switchWalletProviderChain: (walletProvider: WalletProvider, chainOrId: string | SwitchableChain) => Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Logs in a user using the specified wallet provider.
|
|
144
|
+
*
|
|
145
|
+
* - This function logs in a user by authenticating with the provided wallet provider via a wallet-based signature.
|
|
146
|
+
* - If a public key is not provided, a new one will be generated for authentication.
|
|
147
|
+
* - Optionally accepts a custom session key and session expiration time.
|
|
148
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided.
|
|
149
|
+
* - Throws an error if a public key cannot be found or generated, or if the login process fails.
|
|
150
|
+
*
|
|
151
|
+
* @param params.walletProvider - wallet provider to use for authentication.
|
|
152
|
+
* @param params.publicKey - optional public key to associate with the session (generated if not provided).
|
|
153
|
+
* @param params.sessionKey - optional key to store the session under (defaults to the default session key).
|
|
154
|
+
* @param params.expirationSeconds - optional session expiration time in seconds (defaults to the configured default).
|
|
155
|
+
* @returns A promise that resolves to the created session token.
|
|
156
|
+
* @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
|
|
157
|
+
*/
|
|
158
|
+
loginWithWallet: (params: {
|
|
159
|
+
walletProvider: WalletProvider;
|
|
160
|
+
publicKey?: string;
|
|
161
|
+
sessionKey?: string;
|
|
162
|
+
expirationSeconds?: string;
|
|
163
|
+
}) => Promise<string>;
|
|
164
|
+
/**
|
|
165
|
+
* Signs up a user using a wallet, creating a new sub-organization and session.
|
|
166
|
+
*
|
|
167
|
+
* - This function creates a new wallet authenticator and uses it to register a new sub-organization for the user.
|
|
168
|
+
* - Handles both wallet authentication and sub-organization creation in a single flow.
|
|
169
|
+
* - Optionally accepts additional sub-organization parameters, a custom session key, and a custom session expiration.
|
|
170
|
+
* - Automatically generates additional API key pairs for authentication and session management.
|
|
171
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided, and manages cleanup of unused key pairs.
|
|
172
|
+
*
|
|
173
|
+
* @param params.walletProvider - wallet provider to use for authentication.
|
|
174
|
+
* @param params.createSubOrgParams - parameters for creating a sub-organization (e.g., authenticators, user metadata).
|
|
175
|
+
* @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
|
|
176
|
+
* @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
|
|
177
|
+
* @returns A promise that resolves to a signed JWT session token for the new sub-organization.
|
|
178
|
+
* @throws {TurnkeyError} If there is an error during wallet authentication, sub-organization creation, session storage, or cleanup.
|
|
179
|
+
*/
|
|
180
|
+
signUpWithWallet: (params: {
|
|
181
|
+
walletProvider: WalletProvider;
|
|
182
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
183
|
+
sessionKey?: string;
|
|
184
|
+
expirationSeconds?: string;
|
|
185
|
+
}) => Promise<string>;
|
|
186
|
+
/**
|
|
187
|
+
* Logs in an existing user or signs up a new user using a wallet, creating a new sub-organization if needed.
|
|
188
|
+
*
|
|
189
|
+
* - This function attempts to log in the user by stamping a login request with the provided wallet.
|
|
190
|
+
* - If the wallet’s public key is not associated with an existing sub-organization, a new one is created.
|
|
191
|
+
* - Handles both wallet authentication and sub-organization creation in a single flow.
|
|
192
|
+
* - For Ethereum wallets, derives the public key from the signed request header; for Solana wallets, retrieves it directly from the wallet.
|
|
193
|
+
* - Optionally accepts additional sub-organization parameters, a custom session key, and a custom session expiration.
|
|
194
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided.
|
|
195
|
+
*
|
|
196
|
+
* @param params.walletProvider - wallet provider to use for authentication.
|
|
197
|
+
* @param params.createSubOrgParams - optional parameters for creating a sub-organization (e.g., authenticators, user metadata).
|
|
198
|
+
* @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
|
|
199
|
+
* @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
|
|
200
|
+
* @returns A promise that resolves to a signed JWT session token for the sub-organization (new or existing).
|
|
201
|
+
* @throws {TurnkeyError} If there is an error during wallet authentication, sub-organization creation, or session storage.
|
|
202
|
+
*/
|
|
203
|
+
loginOrSignupWithWallet: (params: {
|
|
204
|
+
walletProvider: WalletProvider;
|
|
205
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
206
|
+
sessionKey?: string;
|
|
207
|
+
expirationSeconds?: string;
|
|
208
|
+
}) => Promise<string>;
|
|
209
|
+
/**
|
|
210
|
+
* Initializes the OTP process by sending an OTP code to the provided contact.
|
|
211
|
+
*
|
|
212
|
+
* - This function initiates the OTP flow by sending a one-time password (OTP) code to the user's contact information (email address or phone number) via the auth proxy.
|
|
213
|
+
* - Supports both email and SMS OTP types.
|
|
214
|
+
* - Returns an OTP ID that is required for subsequent OTP verification.
|
|
215
|
+
*
|
|
216
|
+
* @param params.otpType - type of OTP to initialize (OtpType.Email or OtpType.Sms).
|
|
217
|
+
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
218
|
+
* @returns A promise that resolves to the OTP ID required for verification.
|
|
219
|
+
* @throws {TurnkeyError} If there is an error during the OTP initialization process or if the maximum number of OTPs has been reached.
|
|
220
|
+
*/
|
|
221
|
+
initOtp: (params: {
|
|
222
|
+
otpType: OtpType;
|
|
223
|
+
contact: string;
|
|
224
|
+
}) => Promise<string>;
|
|
225
|
+
/**
|
|
226
|
+
* Verifies the OTP code sent to the user.
|
|
227
|
+
*
|
|
228
|
+
* - This function verifies the OTP code entered by the user against the OTP sent to their contact information (email or phone) using the auth proxy.
|
|
229
|
+
* - If verification is successful, it returns the sub-organization ID associated with the contact (if it exists) and a verification token.
|
|
230
|
+
* - The verification token can be used for subsequent login or sign-up flows.
|
|
231
|
+
* - Handles both email and SMS OTP types.
|
|
232
|
+
*
|
|
233
|
+
* @param params.otpId - ID of the OTP to verify (returned from `initOtp`).
|
|
234
|
+
* @param params.otpCode - OTP code entered by the user.
|
|
235
|
+
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
236
|
+
* @param params.otpType - type of OTP being verified (OtpType.Email or OtpType.Sms).
|
|
237
|
+
* @returns A promise that resolves to an object containing:
|
|
238
|
+
* - subOrganizationId: sub-organization ID if the contact is already associated with a sub-organization, or an empty string if not.
|
|
239
|
+
* - verificationToken: verification token to be used for login or sign-up.
|
|
240
|
+
* @throws {TurnkeyError} If there is an error during the OTP verification process, such as an invalid code or network failure.
|
|
241
|
+
*/
|
|
242
|
+
verifyOtp: (params: {
|
|
243
|
+
otpId: string;
|
|
244
|
+
otpCode: string;
|
|
245
|
+
contact: string;
|
|
246
|
+
otpType: OtpType;
|
|
247
|
+
}) => Promise<{
|
|
248
|
+
subOrganizationId: string;
|
|
249
|
+
verificationToken: string;
|
|
250
|
+
}>;
|
|
251
|
+
/**
|
|
252
|
+
* Logs in a user using an OTP verification token.
|
|
253
|
+
*
|
|
254
|
+
* - This function logs in a user using the verification token received after OTP verification (from email or SMS).
|
|
255
|
+
* - If a public key is not provided, a new API key pair will be generated for authentication.
|
|
256
|
+
* - Optionally invalidates any existing sessions for the user if `invalidateExisting` is set to true.
|
|
257
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided.
|
|
258
|
+
* - Handles cleanup of unused key pairs if login fails.
|
|
259
|
+
*
|
|
260
|
+
* @param params.verificationToken - verification token received after OTP verification.
|
|
261
|
+
* @param params.publicKey - public key to use for authentication. If not provided, a new key pair will be generated.
|
|
262
|
+
* @param params.invalidateExisting - flag to invalidate existing session for the user.
|
|
263
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
264
|
+
* @returns A promise that resolves to a signed JWT session token.
|
|
265
|
+
* @throws {TurnkeyError} If there is an error during the OTP login process or if key pair cleanup fails.
|
|
266
|
+
*/
|
|
267
|
+
loginWithOtp: (params: {
|
|
268
|
+
verificationToken: string;
|
|
269
|
+
publicKey?: string;
|
|
270
|
+
invalidateExisting?: boolean;
|
|
271
|
+
sessionKey?: string;
|
|
272
|
+
}) => Promise<string>;
|
|
273
|
+
/**
|
|
274
|
+
* Signs up a user using an OTP verification token.
|
|
275
|
+
*
|
|
276
|
+
* - This function signs up a user using the verification token received after OTP verification (from email or SMS).
|
|
277
|
+
* - Creates a new sub-organization for the user with the provided parameters and associates the contact (email or phone) with the sub-organization.
|
|
278
|
+
* - Automatically generates a new API key pair for authentication and session management.
|
|
279
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided.
|
|
280
|
+
* - Handles both email and SMS OTP types, and supports additional sub-organization creation parameters.
|
|
281
|
+
*
|
|
282
|
+
* @param params.verificationToken - verification token received after OTP verification.
|
|
283
|
+
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
284
|
+
* @param params.otpType - type of OTP being used (OtpType.Email or OtpType.Sms).
|
|
285
|
+
* @param params.createSubOrgParams - parameters for creating a sub-organization (e.g., authenticators, user metadata).
|
|
286
|
+
* @param params.invalidateExisting - flag to invalidate existing session for the user.
|
|
287
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
288
|
+
* @returns A promise that resolves to a signed JWT session token for the new sub-organization.
|
|
289
|
+
* @throws {TurnkeyError} If there is an error during the OTP sign-up process or session storage.
|
|
290
|
+
*/
|
|
291
|
+
signUpWithOtp: (params: {
|
|
292
|
+
verificationToken: string;
|
|
293
|
+
contact: string;
|
|
294
|
+
otpType: OtpType;
|
|
295
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
296
|
+
invalidateExisting?: boolean;
|
|
297
|
+
sessionKey?: string;
|
|
298
|
+
}) => Promise<string>;
|
|
299
|
+
/**
|
|
300
|
+
* Completes the OTP authentication flow by verifying the OTP code and then either signing up or logging in the user.
|
|
301
|
+
*
|
|
302
|
+
* - This function first verifies the OTP code for the provided contact and OTP type.
|
|
303
|
+
* - If the contact is not associated with an existing sub-organization, it will automatically create a new sub-organization and complete the sign-up flow.
|
|
304
|
+
* - If the contact is already associated with a sub-organization, it will complete the login flow.
|
|
305
|
+
* - Supports passing a custom public key for authentication, invalidating existing session, specifying a session key, and providing additional sub-organization creation parameters.
|
|
306
|
+
* - Handles both email and SMS OTP types.
|
|
307
|
+
*
|
|
308
|
+
* @param params.otpId - ID of the OTP to complete (returned from `initOtp`).
|
|
309
|
+
* @param params.otpCode - OTP code entered by the user.
|
|
310
|
+
* @param params.contact - contact information for the user (e.g., email address or phone number).
|
|
311
|
+
* @param params.otpType - type of OTP being completed (OtpType.Email or OtpType.Sms).
|
|
312
|
+
* @param params.publicKey - public key to use for authentication. If not provided, a new key pair may be generated.
|
|
313
|
+
* @param params.invalidateExisting - flag to invalidate existing sessions for the user.
|
|
314
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
315
|
+
* @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
|
|
316
|
+
* @returns A promise that resolves to a signed JWT session token for the user.
|
|
317
|
+
* @throws {TurnkeyError} If there is an error during OTP verification, sign-up, or login.
|
|
318
|
+
*/
|
|
319
|
+
completeOtp: (params: {
|
|
320
|
+
otpId: string;
|
|
321
|
+
otpCode: string;
|
|
322
|
+
contact: string;
|
|
323
|
+
otpType: OtpType;
|
|
324
|
+
publicKey?: string;
|
|
325
|
+
invalidateExisting?: boolean;
|
|
326
|
+
sessionKey?: string;
|
|
327
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
328
|
+
}) => Promise<string>;
|
|
329
|
+
/**
|
|
330
|
+
* Completes the OAuth authentication flow by either signing up or logging in the user, depending on whether a sub-organization already exists for the provided OIDC token.
|
|
331
|
+
*
|
|
332
|
+
* - This function first checks if there is an existing sub-organization associated with the OIDC token.
|
|
333
|
+
* - If a sub-organization exists, it proceeds with the OAuth login flow.
|
|
334
|
+
* - If no sub-organization exists, it creates a new sub-organization and completes the sign-up flow.
|
|
335
|
+
* - Optionally accepts a custom OAuth provider name, session key, and additional sub-organization creation parameters.
|
|
336
|
+
* - Handles session storage and management, and supports invalidating existing sessions if specified.
|
|
337
|
+
*
|
|
338
|
+
* @param params.oidcToken - OIDC token received after successful authentication with the OAuth provider.
|
|
339
|
+
* @param params.publicKey - public key to use for authentication. Must be generated prior to calling this function.
|
|
340
|
+
* @param params.providerName - name of the OAuth provider (defaults to a generated name with a timestamp).
|
|
341
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
342
|
+
* @param params.invalidateExisting - flag to invalidate existing sessions for the user.
|
|
343
|
+
* @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
|
|
344
|
+
* @returns A promise that resolves to a signed JWT session token for the user.
|
|
345
|
+
* @throws {TurnkeyError} If there is an error during the OAuth completion process, such as account lookup, sign-up, or login.
|
|
346
|
+
*/
|
|
347
|
+
completeOauth: (params: {
|
|
348
|
+
oidcToken: string;
|
|
349
|
+
publicKey: string;
|
|
350
|
+
providerName?: string;
|
|
351
|
+
sessionKey?: string;
|
|
352
|
+
invalidateExisting?: boolean;
|
|
353
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
354
|
+
}) => Promise<string>;
|
|
355
|
+
/**
|
|
356
|
+
* Logs in a user using OAuth authentication.
|
|
357
|
+
*
|
|
358
|
+
* - This function logs in a user using the provided OIDC token and public key.
|
|
359
|
+
* - Optionally invalidates any existing sessions for the user if `invalidateExisting` is set to true.
|
|
360
|
+
* - Stores the resulting session token under the specified session key, or the default session key if not provided.
|
|
361
|
+
* - Handles cleanup of unused key pairs if login fails.
|
|
362
|
+
*
|
|
363
|
+
* @param params.oidcToken - OIDC token received after successful authentication with the OAuth provider.
|
|
364
|
+
* @param params.publicKey - public key to use for authentication. Must be generated prior to calling this function.
|
|
365
|
+
* @param params.invalidateExisting - flag to invalidate existing sessions for the user.
|
|
366
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
367
|
+
* @returns A promise that resolves to a signed JWT session token.
|
|
368
|
+
* @throws {TurnkeyError} If there is an error during the OAuth login process or if key pair cleanup fails.
|
|
369
|
+
*/
|
|
370
|
+
loginWithOauth: (params: {
|
|
371
|
+
oidcToken: string;
|
|
372
|
+
publicKey: string;
|
|
373
|
+
invalidateExisting?: boolean;
|
|
374
|
+
sessionKey?: string;
|
|
375
|
+
}) => Promise<string>;
|
|
376
|
+
/**
|
|
377
|
+
* Signs up a user using OAuth authentication.
|
|
378
|
+
*
|
|
379
|
+
* - This function creates a new sub-organization for the user using the provided OIDC token, public key, and provider name.
|
|
380
|
+
* - Handles the full OAuth sign-up flow, including sub-organization creation and session management.
|
|
381
|
+
* - Optionally accepts additional sub-organization creation parameters and a custom session key.
|
|
382
|
+
* - After successful sign-up, automatically logs in the user and returns a signed JWT session token.
|
|
383
|
+
*
|
|
384
|
+
* @param params.oidcToken - OIDC token received after successful authentication with the OAuth provider.
|
|
385
|
+
* @param params.publicKey - public key to associate with the new sub-organization.
|
|
386
|
+
* @param params.providerName - name of the OAuth provider (e.g., "Google", "Apple").
|
|
387
|
+
* @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
|
|
388
|
+
* @param params.sessionKey - session key to use for session creation (defaults to the default session key).
|
|
389
|
+
* @returns A promise that resolves to a signed JWT session token for the new sub-organization.
|
|
390
|
+
* @throws {TurnkeyError} If there is an error during the OAuth sign-up or login process.
|
|
391
|
+
*/
|
|
392
|
+
signUpWithOauth: (params: {
|
|
393
|
+
oidcToken: string;
|
|
394
|
+
publicKey: string;
|
|
395
|
+
providerName: string;
|
|
396
|
+
createSubOrgParams?: CreateSubOrgParams;
|
|
397
|
+
sessionKey?: string;
|
|
398
|
+
}) => Promise<string>;
|
|
399
|
+
/**
|
|
400
|
+
* Fetches all wallets for the current user, including both embedded and connected wallets.
|
|
401
|
+
*
|
|
402
|
+
* - Retrieves all wallets associated with the organizationId from the current active session.
|
|
403
|
+
* - For each embedded wallet, automatically fetches and attaches all associated wallet accounts.
|
|
404
|
+
* - For connected wallets (e.g., browser extensions or external providers), groups providers by wallet name and attaches all connected accounts.
|
|
405
|
+
* - Returns both embedded and connected wallets in a single array, each with their respective accounts populated.
|
|
406
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
407
|
+
*
|
|
408
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
409
|
+
* @returns A promise that resolves to an array of `Wallet` objects.
|
|
410
|
+
* @throws {TurnkeyError} If no active session is found or if there is an error fetching wallets.
|
|
411
|
+
*/
|
|
412
|
+
fetchWallets: (params?: {
|
|
413
|
+
stampWith?: StamperType | undefined;
|
|
414
|
+
}) => Promise<Wallet[]>;
|
|
415
|
+
/**
|
|
416
|
+
* Fetches all accounts for a specific wallet, including both embedded and connected wallet accounts.
|
|
417
|
+
*
|
|
418
|
+
* - For embedded wallets, retrieves accounts from the Turnkey API, supporting pagination (defaults to the first page with a limit of 100 accounts).
|
|
419
|
+
* - For connected wallets (e.g., browser extensions or external providers), constructs account objects for each connected address from the provided or discovered wallet providers.
|
|
420
|
+
* - Automatically determines the account type and populates relevant fields such as address, curve, and signing capability.
|
|
421
|
+
* - Optionally allows filtering by a specific set of wallet providers and supports custom pagination options.
|
|
422
|
+
* - Supports stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
423
|
+
*
|
|
424
|
+
* @param params.wallet - wallet for which to fetch accounts.
|
|
425
|
+
* @param params.walletProviders - list of wallet providers to filter by (used for connected wallets).
|
|
426
|
+
* @param params.paginationOptions - pagination options for embedded wallets.
|
|
427
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
428
|
+
* @returns A promise that resolves to an array of `v1WalletAccount` objects.
|
|
429
|
+
* @throws {TurnkeyError} If no active session is found or if there is an error fetching wallet accounts.
|
|
430
|
+
*/
|
|
431
|
+
fetchWalletAccounts: (params: {
|
|
432
|
+
wallet: Wallet;
|
|
433
|
+
walletProviders?: WalletProvider[];
|
|
434
|
+
paginationOptions?: v1Pagination;
|
|
435
|
+
stampWith?: StamperType | undefined;
|
|
436
|
+
}) => Promise<WalletAccount[]>;
|
|
437
|
+
/**
|
|
438
|
+
* Signs a message using the specified wallet account.
|
|
439
|
+
*
|
|
440
|
+
* - Supports both embedded and connected wallets.
|
|
441
|
+
* - For **connected wallets**:
|
|
442
|
+
* - Delegates signing to the wallet provider’s native signing method.
|
|
443
|
+
* - **Important:** For Ethereum wallets (e.g., MetaMask), signatures follow [EIP-191](https://eips.ethereum.org/EIPS/eip-191).
|
|
444
|
+
* The message is automatically prefixed with `"\x19Ethereum Signed Message:\n" + message length`
|
|
445
|
+
* before signing. As a result, this signature **cannot be used as a raw transaction signature**
|
|
446
|
+
* or broadcast on-chain.
|
|
447
|
+
* - For **embedded wallets**, uses the Turnkey API to sign the message directly.
|
|
448
|
+
* - Automatically handles message encoding and hashing based on the wallet account’s address format,
|
|
449
|
+
* unless explicitly overridden.
|
|
450
|
+
*
|
|
451
|
+
* @param params.message - message to sign.
|
|
452
|
+
* @param params.walletAccount - wallet account to use for signing.
|
|
453
|
+
* @param params.encoding - override for the payload encoding (defaults to the encoding appropriate for the address type).
|
|
454
|
+
* @param params.hashFunction - override for the hash function (defaults to the hash function appropriate for the address type).
|
|
455
|
+
* @param params.stampWith - stamper to tag the signing request (e.g., Passkey, ApiKey, or Wallet).
|
|
456
|
+
* @param params.addEthereumPrefix - whether to prefix the message with Ethereum's `"\x19Ethereum Signed Message:\n"` string.
|
|
457
|
+
* - If `true` (default for Ethereum), the message is prefixed before signing.
|
|
458
|
+
* - If `false`:
|
|
459
|
+
* - Connected wallets will throw an error because they always prefix automatically.
|
|
460
|
+
* - Embedded wallets will sign the raw message without any prefix.
|
|
461
|
+
*
|
|
462
|
+
* @returns A promise resolving to a `v1SignRawPayloadResult` containing the signature and metadata.
|
|
463
|
+
* @throws {TurnkeyError} If signing fails, if the wallet account does not support signing, or if the response is invalid.
|
|
464
|
+
*/
|
|
465
|
+
signMessage: (params: {
|
|
466
|
+
message: string;
|
|
467
|
+
walletAccount: WalletAccount;
|
|
468
|
+
encoding?: v1PayloadEncoding;
|
|
469
|
+
hashFunction?: v1HashFunction;
|
|
470
|
+
stampWith?: StamperType | undefined;
|
|
471
|
+
addEthereumPrefix?: boolean;
|
|
472
|
+
}) => Promise<v1SignRawPayloadResult>;
|
|
473
|
+
/**
|
|
474
|
+
* Signs a transaction using the specified wallet account.
|
|
475
|
+
*
|
|
476
|
+
* - This function signs a blockchain transaction using the provided wallet address and transaction data.
|
|
477
|
+
* - Supports all Turnkey-supported blockchain networks (e.g., Ethereum, Solana, Tron).
|
|
478
|
+
* - Automatically determines the appropriate signing method based on the transaction type.
|
|
479
|
+
* - Delegates signing to the Turnkey API, which returns the signed transaction and related metadata.
|
|
480
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
481
|
+
*
|
|
482
|
+
* @param params.walletAccount - wallet account to use for signing the transaction.
|
|
483
|
+
* @param params.unsignedTransaction - unsigned transaction data (serialized as a string) to be signed.
|
|
484
|
+
* @param params.transactionType - type of transaction (e.g., "TRANSACTION_TYPE_ETHEREUM", "TRANSACTION_TYPE_SOLANA", "TRANSACTION_TYPE_TRON").
|
|
485
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
486
|
+
* @returns A promise that resolves to a `TSignTransactionResponse` object containing the signed transaction and any additional signing metadata.
|
|
487
|
+
* @throws {TurnkeyError} If there is an error signing the transaction or if the response is invalid.
|
|
488
|
+
*/
|
|
489
|
+
signTransaction: (params: {
|
|
490
|
+
unsignedTransaction: string;
|
|
491
|
+
transactionType: v1TransactionType;
|
|
492
|
+
walletAccount: WalletAccount;
|
|
493
|
+
stampWith?: StamperType | undefined;
|
|
494
|
+
}) => Promise<string>;
|
|
495
|
+
/**
|
|
496
|
+
* Signs and broadcasts a transaction using the specified wallet account.
|
|
497
|
+
*
|
|
498
|
+
* - For **connected wallets**:
|
|
499
|
+
* - Calls the wallet’s native `signAndSendTransaction` method.
|
|
500
|
+
* - Does **not** require an `rpcUrl`.
|
|
501
|
+
*
|
|
502
|
+
* - For **embedded wallets**:
|
|
503
|
+
* - Signs the transaction using the Turnkey API.
|
|
504
|
+
* - Requires an `rpcUrl` to broadcast the transaction.
|
|
505
|
+
* - Broadcasts the transaction using a JSON-RPC client.
|
|
506
|
+
*
|
|
507
|
+
* @param params.walletAccount - wallet account to use for signing and sending.
|
|
508
|
+
* @param params.unsignedTransaction - unsigned transaction (serialized string).
|
|
509
|
+
* @param params.transactionType - transaction type (e.g., "TRANSACTION_TYPE_SOLANA").
|
|
510
|
+
* @param params.rpcUrl - required for embedded wallets to broadcast the signed transaction.
|
|
511
|
+
* @param params.stampWith - optional stamper to tag the signing request.
|
|
512
|
+
* @returns A promise that resolves to a transaction signature or hash.
|
|
513
|
+
* @throws {TurnkeyError} If signing or broadcasting fails.
|
|
514
|
+
*/
|
|
515
|
+
signAndSendTransaction: (params: {
|
|
516
|
+
unsignedTransaction: string;
|
|
517
|
+
transactionType: v1TransactionType;
|
|
518
|
+
walletAccount: WalletAccount;
|
|
519
|
+
rpcUrl?: string;
|
|
520
|
+
stampWith?: StamperType | undefined;
|
|
521
|
+
}) => Promise<string>;
|
|
522
|
+
/**
|
|
523
|
+
* Fetches the user details for the current session or a specified user.
|
|
524
|
+
*
|
|
525
|
+
* - Retrieves user details from the Turnkey API using the provided userId and organizationId, or defaults to those from the active session.
|
|
526
|
+
* - If no userId is provided, the userId from the current session is used.
|
|
527
|
+
* - If no organizationId is provided, the organizationId from the current session is used.
|
|
528
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
529
|
+
* - Ensures that an active session exists before making the request.
|
|
530
|
+
*
|
|
531
|
+
* @param params.organizationId - organization ID to specify the sub-organization (defaults to the current session's organizationId).
|
|
532
|
+
* @param params.userId - user ID to fetch specific user details (defaults to the current session's userId).
|
|
533
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
534
|
+
* @returns A promise that resolves to a `v1User` object containing the user details.
|
|
535
|
+
* @throws {TurnkeyError} If there is no active session, if there is no userId, or if there is an error fetching user details.
|
|
536
|
+
*/
|
|
537
|
+
fetchUser: (params?: {
|
|
538
|
+
organizationId?: string;
|
|
539
|
+
userId?: string;
|
|
540
|
+
stampWith?: StamperType | undefined;
|
|
541
|
+
}) => Promise<v1User>;
|
|
542
|
+
/**
|
|
543
|
+
* Updates the user's email address.
|
|
544
|
+
*
|
|
545
|
+
* - This function updates the user's email address and, if provided, verifies it using a verification token (typically from an OTP flow).
|
|
546
|
+
* - If a userId is provided, it updates the email for that specific user; otherwise, it uses the current session's userId.
|
|
547
|
+
* - If a verificationToken is not provided, the email will be updated but will not be marked as verified.
|
|
548
|
+
* - Automatically ensures an active session exists before making the request.
|
|
549
|
+
* - Handles session management and error reporting for both update and verification flows.
|
|
550
|
+
*
|
|
551
|
+
* @param params.email - new email address to set for the user.
|
|
552
|
+
* @param params.verificationToken - verification token from OTP email verification (required if verifying the email).
|
|
553
|
+
* @param params.userId - user ID to update a specific user's email (defaults to the current session's userId).
|
|
554
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
555
|
+
* @returns A promise that resolves to the userId of the updated user.
|
|
556
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating or verifying the user email.
|
|
557
|
+
*/
|
|
558
|
+
updateUserEmail: (params: {
|
|
559
|
+
email: string;
|
|
560
|
+
verificationToken?: string;
|
|
561
|
+
userId?: string;
|
|
562
|
+
stampWith?: StamperType | undefined;
|
|
563
|
+
}) => Promise<string>;
|
|
564
|
+
/**
|
|
565
|
+
* Removes the user's email address.
|
|
566
|
+
*
|
|
567
|
+
* - This function removes the user's email address by setting it to an empty string.
|
|
568
|
+
* - If a userId is provided, it removes the email for that specific user; otherwise, it uses the current session's userId.
|
|
569
|
+
* - Automatically ensures an active session exists before making the request.
|
|
570
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
571
|
+
*
|
|
572
|
+
* @param params.userId - user ID to remove a specific user's email address (defaults to the current session's userId).
|
|
573
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
574
|
+
* @returns A promise that resolves to the userId of the user whose email was removed.
|
|
575
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user email.
|
|
576
|
+
*/
|
|
577
|
+
removeUserEmail: (params?: {
|
|
578
|
+
userId?: string;
|
|
579
|
+
stampWith?: StamperType | undefined;
|
|
580
|
+
}) => Promise<string>;
|
|
581
|
+
/**
|
|
582
|
+
* Updates the user's phone number.
|
|
583
|
+
*
|
|
584
|
+
* - This function updates the user's phone number and, if provided, verifies it using a verification token (from an OTP flow).
|
|
585
|
+
* - If a userId is provided, it updates the phone number for that specific user; otherwise, it uses the current session's userId.
|
|
586
|
+
* - If a verificationToken is not provided, the phone number will be updated but will not be marked as verified.
|
|
587
|
+
* - Automatically ensures an active session exists before making the request.
|
|
588
|
+
* - Handles session management and error reporting for both update and verification flows.
|
|
589
|
+
*
|
|
590
|
+
* @param params.phoneNumber - new phone number to set for the user.
|
|
591
|
+
* @param params.verificationToken - verification token from OTP phone verification (required if verifying the phone number).
|
|
592
|
+
* @param params.userId - user ID to update a specific user's phone number (defaults to the current session's userId).
|
|
593
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
594
|
+
* @returns A promise that resolves to the userId of the updated user.
|
|
595
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating or verifying the user phone number.
|
|
596
|
+
*/
|
|
597
|
+
updateUserPhoneNumber: (params: {
|
|
598
|
+
phoneNumber: string;
|
|
599
|
+
verificationToken?: string;
|
|
600
|
+
userId?: string;
|
|
601
|
+
stampWith?: StamperType | undefined;
|
|
602
|
+
}) => Promise<string>;
|
|
603
|
+
/**
|
|
604
|
+
* Removes the user's phone number.
|
|
605
|
+
*
|
|
606
|
+
* - This function removes the user's phone number by setting it to an empty string.
|
|
607
|
+
* - If a userId is provided, it removes the phone number for that specific user; otherwise, it uses the current session's userId.
|
|
608
|
+
* - Automatically ensures an active session exists before making the request.
|
|
609
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
610
|
+
*
|
|
611
|
+
* @param params.userId - user ID to remove a specific user's phone number (defaults to the current session's userId).
|
|
612
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
613
|
+
* @returns A promise that resolves to the userId of the user whose phone number was removed.
|
|
614
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user phone number.
|
|
615
|
+
*/
|
|
616
|
+
removeUserPhoneNumber: (params?: {
|
|
617
|
+
userId?: string;
|
|
618
|
+
stampWith?: StamperType | undefined;
|
|
619
|
+
}) => Promise<string>;
|
|
620
|
+
/**
|
|
621
|
+
* Updates the user's name.
|
|
622
|
+
*
|
|
623
|
+
* - This function updates the user's display name.
|
|
624
|
+
* - If a userId is provided, it updates the name for that specific user; otherwise, it uses the current session's userId.
|
|
625
|
+
* - Automatically ensures an active session exists before making the request.
|
|
626
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
627
|
+
* - Handles session management and error reporting for the update flow.
|
|
628
|
+
*
|
|
629
|
+
* @param params.userName - new name to set for the user.
|
|
630
|
+
* @param params.userId - user ID to update a specific user's name (defaults to the current session's userId).
|
|
631
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
632
|
+
* @returns A promise that resolves to the userId of the updated user.
|
|
633
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating the user name.
|
|
634
|
+
*/
|
|
635
|
+
updateUserName: (params: {
|
|
636
|
+
userName: string;
|
|
637
|
+
userId?: string;
|
|
638
|
+
stampWith?: StamperType | undefined;
|
|
639
|
+
}) => Promise<string>;
|
|
640
|
+
/**
|
|
641
|
+
* Adds an OAuth provider to the user.
|
|
642
|
+
*
|
|
643
|
+
* - This function adds an OAuth provider (e.g., Google, Apple) to the user account.
|
|
644
|
+
* - If a userId is provided, it adds the provider for that specific user; otherwise, it uses the current session's userId.
|
|
645
|
+
* - Automatically checks if an account already exists for the provided OIDC token and prevents duplicate associations.
|
|
646
|
+
* - If the user's email is not set or not verified, attempts to update and verify the email using the email from the OIDC token.
|
|
647
|
+
* - Handles session management and error reporting for the add provider flow.
|
|
648
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
649
|
+
*
|
|
650
|
+
* @param params.providerName - name of the OAuth provider to add (e.g., "Google", "Apple").
|
|
651
|
+
* @param params.oidcToken - OIDC token for the OAuth provider.
|
|
652
|
+
* @param params.userId - user ID to add the provider for a specific user (defaults to current session's userId).
|
|
653
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
654
|
+
* @returns A promise that resolves to an array of provider IDs associated with the user.
|
|
655
|
+
* @throws {TurnkeyError} If there is no active session, if the account already exists, or if there is an error adding the OAuth provider.
|
|
656
|
+
*/
|
|
657
|
+
addOauthProvider: (params: {
|
|
658
|
+
providerName: string;
|
|
659
|
+
oidcToken: string;
|
|
660
|
+
userId?: string;
|
|
661
|
+
stampWith?: StamperType | undefined;
|
|
662
|
+
}) => Promise<string[]>;
|
|
663
|
+
/**
|
|
664
|
+
* Removes a list of OAuth providers from the user.
|
|
665
|
+
*
|
|
666
|
+
* - This function removes OAuth providers (e.g., Google, Apple) from the user's account.
|
|
667
|
+
* - If a userId is provided, it removes the providers for that specific user; otherwise, it uses the current session's userId.
|
|
668
|
+
* - Automatically ensures an active session exists before making the request.
|
|
669
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
670
|
+
* - Returns an array of remaining provider IDs associated with the user after removal.
|
|
671
|
+
*
|
|
672
|
+
* @param params.providerIds - IDs of the OAuth providers to remove.
|
|
673
|
+
* @param params.userId - user ID to remove the provider for a specific user (defaults to the current session's userId).
|
|
674
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
675
|
+
* @returns A promise that resolves to an array of provider IDs that were removed.
|
|
676
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the OAuth provider.
|
|
677
|
+
*/
|
|
678
|
+
removeOauthProviders: (params: {
|
|
679
|
+
providerIds: string[];
|
|
680
|
+
userId?: string;
|
|
681
|
+
stampWith?: StamperType | undefined;
|
|
682
|
+
}) => Promise<string[]>;
|
|
683
|
+
/**
|
|
684
|
+
* Adds a new passkey authenticator for the user.
|
|
685
|
+
*
|
|
686
|
+
* - This function prompts the user to create a new passkey (WebAuthn/FIDO2) and adds it as an authenticator for the user.
|
|
687
|
+
* - Handles both web and React Native environments, automatically selecting the appropriate passkey creation flow.
|
|
688
|
+
* - If a userId is provided, the passkey is added for that specific user; otherwise, it uses the current session's userId.
|
|
689
|
+
* - The passkey's name and display name can be customized; if not provided, defaults are generated.
|
|
690
|
+
* - The resulting passkey attestation and challenge are registered with Turnkey as a new authenticator.
|
|
691
|
+
*
|
|
692
|
+
* @param params.name - name of the passkey (defaults to "Turnkey Passkey-`timestamp`").
|
|
693
|
+
* @param params.displayName - display name of the passkey (defaults to the value of `name`).
|
|
694
|
+
* @param params.userId - user ID to add the passkey for a specific user (defaults to the current session's userId).
|
|
695
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
696
|
+
* @returns A promise that resolves to an array of authenticator IDs for the newly added passkey(s).
|
|
697
|
+
* @throws {TurnkeyError} If there is no active session, if passkey creation fails, or if there is an error adding the passkey.
|
|
698
|
+
*/
|
|
699
|
+
addPasskey: (params?: {
|
|
700
|
+
name?: string;
|
|
701
|
+
displayName?: string;
|
|
702
|
+
userId?: string;
|
|
703
|
+
stampWith?: StamperType | undefined;
|
|
704
|
+
}) => Promise<string[]>;
|
|
705
|
+
/**
|
|
706
|
+
* Removes passkeys (authenticator) from the user.
|
|
707
|
+
*
|
|
708
|
+
* - This function removes passkeys (WebAuthn/FIDO2 authenticators) from the user's account.
|
|
709
|
+
* - If a userId is provided, it removes the passkeys for that specific user; otherwise, it uses the current session's userId.
|
|
710
|
+
* - Automatically ensures an active session exists before making the request.
|
|
711
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
712
|
+
* - Returns an array of remaining authenticator IDs for the user after removal.
|
|
713
|
+
*
|
|
714
|
+
* @param params.authenticatorIds - IDs of the authenticators (passkeys) to remove.
|
|
715
|
+
* @param params.userId - user ID to remove the passkeys for a specific user (defaults to the current session's userId).
|
|
716
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
717
|
+
* @returns A promise that resolves to an array of authenticator IDs that were removed.
|
|
718
|
+
* @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the passkeys.
|
|
719
|
+
*/
|
|
720
|
+
removePasskeys: (params: {
|
|
721
|
+
authenticatorIds: string[];
|
|
722
|
+
userId?: string;
|
|
723
|
+
stampWith?: StamperType | undefined;
|
|
724
|
+
}) => Promise<string[]>;
|
|
725
|
+
/**
|
|
726
|
+
* Creates a new wallet for sub-organization.
|
|
727
|
+
*
|
|
728
|
+
* - This function creates a new wallet for the current sub-organization.
|
|
729
|
+
* - If an organizationId is provided, the wallet will be created under that specific sub-organization; otherwise, it uses the current session's organizationId.
|
|
730
|
+
* - If a list of address formats is provided, accounts will be created in the wallet based on those formats (starting from path index 0).
|
|
731
|
+
* - If a list of account parameters is provided, those accounts will be created in the wallet.
|
|
732
|
+
* - If no accounts or address formats are provided, default Ethereum and Solana accounts will be created.
|
|
733
|
+
* - Optionally allows specifying the mnemonic length for the wallet seed phrase (defaults to 12).
|
|
734
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
735
|
+
*
|
|
736
|
+
* @param params.walletName - name of the wallet to create.
|
|
737
|
+
* @param params.accounts - array of account parameters or address formats to create in the wallet.
|
|
738
|
+
* @param params.organizationId - organization ID to create the wallet under a specific sub-organization (defaults to the current session's organizationId).
|
|
739
|
+
* @param params.mnemonicLength - mnemonic length for the wallet seed phrase (defaults to 12).
|
|
740
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
741
|
+
* @returns A promise that resolves to the ID of the newly created wallet.
|
|
742
|
+
* @throws {TurnkeyError} If there is no active session or if there is an error creating the wallet.
|
|
743
|
+
*/
|
|
744
|
+
createWallet: (params: {
|
|
745
|
+
walletName: string;
|
|
746
|
+
accounts?: v1WalletAccountParams[] | v1AddressFormat[];
|
|
747
|
+
organizationId?: string;
|
|
748
|
+
mnemonicLength?: number;
|
|
749
|
+
stampWith?: StamperType | undefined;
|
|
750
|
+
}) => Promise<string>;
|
|
751
|
+
/**
|
|
752
|
+
* Creates new accounts in the specified wallet.
|
|
753
|
+
*
|
|
754
|
+
* - This function creates new wallet accounts based on the provided account parameters or address formats.
|
|
755
|
+
* - If a walletId is provided, it creates the accounts in that specific wallet; otherwise, it uses the current session's wallet.
|
|
756
|
+
* - If a list of address formats is provided, it will create accounts in the wallet based on those formats, automatically determining the next available path indexes to avoid duplicates with existing accounts.
|
|
757
|
+
* - If account parameters are provided, they are used directly for account creation.
|
|
758
|
+
* - Automatically queries existing wallet accounts to prevent duplicate account creation for the same address format and path.
|
|
759
|
+
* - Supports stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
760
|
+
*
|
|
761
|
+
* @param params.accounts - An array of account parameters or address formats to create in the wallet.
|
|
762
|
+
* @param params.walletId - ID of the wallet to create accounts in.
|
|
763
|
+
* @param params.organizationId - organization ID to create the accounts under a specific organization (walletId must be associated with the sub-organization).
|
|
764
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
765
|
+
* @returns A promise that resolves to an array of addresses for the newly created accounts.
|
|
766
|
+
* @throws {TurnkeyError} If there is no active session, if the wallet does not exist, or if there is an error creating the wallet accounts.
|
|
767
|
+
*/
|
|
768
|
+
createWalletAccounts: (params: {
|
|
769
|
+
accounts: v1WalletAccountParams[] | v1AddressFormat[];
|
|
770
|
+
walletId: string;
|
|
771
|
+
organizationId?: string;
|
|
772
|
+
stampWith?: StamperType | undefined;
|
|
773
|
+
}) => Promise<string[]>;
|
|
774
|
+
/**
|
|
775
|
+
* Exports a wallet as an encrypted bundle.
|
|
776
|
+
*
|
|
777
|
+
* - This function exports the specified wallet and its accounts as an encrypted bundle, suitable for backup or transfer.
|
|
778
|
+
* - The exported bundle contains the wallet's seed phrase, encrypted to the provided target public key.
|
|
779
|
+
* - If a targetPublicKey is provided, the bundle will be encrypted to that public key; otherwise, an error will be thrown.
|
|
780
|
+
* - If an organizationId is provided, the wallet will be exported under that sub-organization; otherwise, the current session's organizationId is used.
|
|
781
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
782
|
+
* - The exported bundle can later be imported using the `importWallet` method.
|
|
783
|
+
*
|
|
784
|
+
* @param params.walletId - ID of the wallet to export.
|
|
785
|
+
* @param params.targetPublicKey - public key to encrypt the bundle to (required).
|
|
786
|
+
* @param params.organizationId - organization ID to export the wallet under a specific sub-organization (walletId must be associated with the sub-organization).
|
|
787
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
788
|
+
* @returns A promise that resolves to an `ExportBundle` object containing the encrypted wallet seed phrase and metadata.
|
|
789
|
+
* @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the wallet.
|
|
790
|
+
*/
|
|
791
|
+
exportWallet: (params: {
|
|
792
|
+
walletId: string;
|
|
793
|
+
targetPublicKey: string;
|
|
794
|
+
organizationId?: string;
|
|
795
|
+
stampWith?: StamperType | undefined;
|
|
796
|
+
}) => Promise<ExportBundle>;
|
|
797
|
+
/**
|
|
798
|
+
* Imports a wallet from an encrypted bundle.
|
|
799
|
+
*
|
|
800
|
+
* - This function imports a wallet using the provided encrypted bundle and creates accounts based on the provided parameters.
|
|
801
|
+
* - If a userId is provided, the wallet will be imported for that specific user; otherwise, it uses the current session's userId.
|
|
802
|
+
* - If an accounts array is provided, those accounts will be created in the imported wallet; otherwise, default Ethereum and Solana accounts will be created.
|
|
803
|
+
* - The encrypted bunlde MUST be encrypted to
|
|
804
|
+
* - Automatically ensures an active session exists before making the request.
|
|
805
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
806
|
+
*
|
|
807
|
+
* @param params.encryptedBundle - encrypted bundle containing the wallet seed phrase and metadata.
|
|
808
|
+
* @param params.walletName - name of the wallet to create upon import.
|
|
809
|
+
* @param params.accounts - array of account parameters to create in the imported wallet (defaults to standard Ethereum and Solana accounts).
|
|
810
|
+
* @param params.userId - user ID to import the wallet for a specific user (defaults to the current session's userId).
|
|
811
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
812
|
+
* @returns A promise that resolves to the ID of the imported wallet.
|
|
813
|
+
* @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
|
|
814
|
+
*/
|
|
815
|
+
importWallet: (params: {
|
|
816
|
+
encryptedBundle: string;
|
|
817
|
+
walletName: string;
|
|
818
|
+
accounts?: v1WalletAccountParams[];
|
|
819
|
+
userId?: string;
|
|
820
|
+
stampWith?: StamperType | undefined;
|
|
821
|
+
}) => Promise<string>;
|
|
822
|
+
/**
|
|
823
|
+
* Deletes the current sub-organization (sub-org) for the active session.
|
|
824
|
+
*
|
|
825
|
+
* - This function deletes the sub-organization associated with the current active session.
|
|
826
|
+
* - By default, the deletion will fail if any wallets associated with the sub-organization have not been exported.
|
|
827
|
+
* - If `deleteWithoutExport` is set to true, the sub-organization will be deleted even if its wallets have not been exported (potentially resulting in loss of access to those wallets).
|
|
828
|
+
* - Requires an active session; otherwise, an error is thrown.
|
|
829
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
830
|
+
*
|
|
831
|
+
* @param params.deleteWithoutExport - flag to delete the sub-organization without requiring all wallets to be exported first (defaults to false).
|
|
832
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper.
|
|
833
|
+
* @returns A promise that resolves to a `TDeleteSubOrganizationResponse` object containing the result of the deletion.
|
|
834
|
+
* @throws {TurnkeyError} If there is no active session or if there is an error deleting the sub-organization.
|
|
835
|
+
*/
|
|
836
|
+
deleteSubOrganization: (params?: {
|
|
837
|
+
deleteWithoutExport?: boolean;
|
|
838
|
+
stampWith?: StamperType | undefined;
|
|
839
|
+
}) => Promise<TDeleteSubOrganizationResponse>;
|
|
840
|
+
/**
|
|
841
|
+
* Stores a session token and updates the session associated with the specified session key, or by default the active session.
|
|
842
|
+
*
|
|
843
|
+
* - This function parses and stores a signed JWT session token in local storage, associating it with the given session key.
|
|
844
|
+
* - If a sessionKey is provided, the session will be stored under that key; otherwise, it will use the default session key.
|
|
845
|
+
* - If a session already exists for the session key, its associated key pair will be deleted before storing the new session.
|
|
846
|
+
* - After storing the session, any unused key pairs are automatically cleared from storage.
|
|
847
|
+
* - Ensures that session management is consistent and prevents orphaned key pairs.
|
|
848
|
+
*
|
|
849
|
+
* @param params.sessionToken - JWT session token to store.
|
|
850
|
+
* @param params.sessionKey - session key to store the session under (defaults to the default session key).
|
|
851
|
+
* @returns A promise that resolves when the session is successfully stored.
|
|
852
|
+
* @throws {TurnkeyError} If there is an error storing the session or cleaning up key pairs.
|
|
853
|
+
*/
|
|
854
|
+
storeSession: (params: {
|
|
855
|
+
sessionToken: string;
|
|
856
|
+
sessionKey?: string;
|
|
857
|
+
}) => Promise<void>;
|
|
858
|
+
/**
|
|
859
|
+
* Clears the session associated with the specified session key, or the active session by default.
|
|
860
|
+
*
|
|
861
|
+
* - This function deletes the session and its associated key pair from storage.
|
|
862
|
+
* - If a sessionKey is provided, it will clear the session under that key; otherwise, it will clear the default (active) session.
|
|
863
|
+
* - Removes the session data from local storage and deletes the corresponding API key pair from the key store.
|
|
864
|
+
* - Throws an error if the session does not exist or if there is an error during the clearing process.
|
|
865
|
+
*
|
|
866
|
+
* @param params.sessionKey - session key to clear the session under (defaults to the default session key).
|
|
867
|
+
* @returns A promise that resolves when the session is successfully cleared.
|
|
868
|
+
* @throws {TurnkeyError} If the session does not exist or if there is an error clearing the session.
|
|
869
|
+
*/
|
|
870
|
+
clearSession: (params?: {
|
|
871
|
+
sessionKey?: string;
|
|
872
|
+
}) => Promise<void>;
|
|
873
|
+
/**
|
|
874
|
+
* Clears all sessions and resets the active session state.
|
|
875
|
+
*
|
|
876
|
+
* - This function removes all session data from the client and persistent storage, including all associated key pairs.
|
|
877
|
+
* - Iterates through all stored session keys, clearing each session and deleting its corresponding API key pair.
|
|
878
|
+
* - After clearing, there will be no active session, and all session-related data will be removed from local storage.
|
|
879
|
+
* - Throws an error if no sessions exist or if there is an error during the clearing process.
|
|
880
|
+
*
|
|
881
|
+
* @returns A promise that resolves when all sessions are successfully cleared.
|
|
882
|
+
* @throws {TurnkeyError} If no sessions exist or if there is an error clearing all sessions.
|
|
883
|
+
*/
|
|
884
|
+
clearAllSessions: () => Promise<void>;
|
|
885
|
+
/**
|
|
886
|
+
* Refreshes the session associated with the specified session key, or the active session by default.
|
|
887
|
+
*
|
|
888
|
+
* - This function refreshes the session and updates the session token and key pair associated with the given session key.
|
|
889
|
+
* - If a sessionKey is provided, it will refresh the session under that key; otherwise, it will use the current active session key.
|
|
890
|
+
* - Optionally allows specifying a new expiration time for the session, a custom public key, and whether to invalidate the existing session after refreshing.
|
|
891
|
+
* - Makes a request to the Turnkey API to stamp a new login and stores the refreshed session token.
|
|
892
|
+
* - Automatically manages key pair cleanup and session storage to ensure consistency.
|
|
893
|
+
* - Optionally allows stamping the request with a specific stamper (StamperType.Passkey, StamperType.ApiKey, or StamperType.Wallet).
|
|
894
|
+
*
|
|
895
|
+
* @param params.sessionKey - session key to refresh the session under (defaults to the active session key).
|
|
896
|
+
* @param params.expirationSeconds - expiration time in seconds for the refreshed session (defaults to the configured default).
|
|
897
|
+
* @param params.publicKey - public key to use for the refreshed session (if not provided, a new key pair will be generated).
|
|
898
|
+
* @param params.invalidateExisitng - flag to invalidate the existing session before refreshing (defaults to false).
|
|
899
|
+
* @param params.stampWith - parameter to stamp the request with a specific stamper.
|
|
900
|
+
* @returns A promise that resolves to a `TStampLoginResponse` object containing the refreshed session details.
|
|
901
|
+
* @throws {TurnkeyError} If the session key does not exist, if there is no active session, or if there is an error refreshing the session.
|
|
902
|
+
*/
|
|
903
|
+
refreshSession: (params?: {
|
|
904
|
+
expirationSeconds?: string;
|
|
905
|
+
publicKey?: string;
|
|
906
|
+
sessionKey?: string;
|
|
907
|
+
invalidateExisitng?: boolean;
|
|
908
|
+
stampWith?: StamperType | undefined;
|
|
909
|
+
}) => Promise<TStampLoginResponse | undefined>;
|
|
910
|
+
/**
|
|
911
|
+
* Retrieves the session associated with the specified session key, or the active session by default.
|
|
912
|
+
*
|
|
913
|
+
* - This function retrieves the session object from storage, using the provided session key or, if not specified, the current active session key.
|
|
914
|
+
* - If no session key is provided and there is no active session, it returns undefined.
|
|
915
|
+
* - Returns the session details, including public key, organization ID, user ID, and expiration.
|
|
916
|
+
*
|
|
917
|
+
* @param params.sessionKey - session key to retrieve a specific session (defaults to the current active session key).
|
|
918
|
+
* @returns A promise that resolves to a `Session` object containing the session details, or undefined if not found.
|
|
919
|
+
* @throws {TurnkeyError} If there is an error retrieving the session from storage.
|
|
920
|
+
*/
|
|
921
|
+
getSession: (params?: {
|
|
922
|
+
sessionKey?: string;
|
|
923
|
+
}) => Promise<Session | undefined>;
|
|
924
|
+
/**
|
|
925
|
+
* Retrieves all sessions stored in persistent storage.
|
|
926
|
+
*
|
|
927
|
+
* - This function fetches all session objects currently stored by the client, including those that are not active.
|
|
928
|
+
* - Returns a record mapping each session key to its corresponding `Session` object.
|
|
929
|
+
* - Useful for session management, auditing, or displaying all available sessions to the user.
|
|
930
|
+
* - Automatically skips any session keys that do not have a valid session object.
|
|
931
|
+
*
|
|
932
|
+
* @returns A promise that resolves to a record of session keys and their corresponding `Session` objects, or `undefined` if no sessions exist.
|
|
933
|
+
* @throws {TurnkeyError} If there is an error retrieving sessions from storage.
|
|
934
|
+
*/
|
|
935
|
+
getAllSessions: () => Promise<Record<string, Session> | undefined>;
|
|
936
|
+
/**
|
|
937
|
+
* Sets the active session to the specified session key.
|
|
938
|
+
*
|
|
939
|
+
* - This function updates the `activeSessionKey` in persistent storage to the specified session key.
|
|
940
|
+
* - Ensures that subsequent operations use the session associated with this key as the active session.
|
|
941
|
+
* - Does not validate whether the session key exists or is valid; it simply updates the pointer.
|
|
942
|
+
* - Useful for switching between multiple stored sessions or restoring a previous session context.
|
|
943
|
+
*
|
|
944
|
+
* @param params.sessionKey - session key to set as the active session.
|
|
945
|
+
* @returns A promise that resolves when the active session key is successfully set.
|
|
946
|
+
* @throws {TurnkeyError} If the client is not initialized or if there is an error setting the active session key.
|
|
947
|
+
*/
|
|
948
|
+
setActiveSession: (params: {
|
|
949
|
+
sessionKey: string;
|
|
950
|
+
}) => Promise<void>;
|
|
951
|
+
/**
|
|
952
|
+
* Retrieves the active session key currently set in persistent storage.
|
|
953
|
+
*
|
|
954
|
+
* - This function fetches the session key that is currently marked as active in the client's persistent storage.
|
|
955
|
+
* - The active session key determines which session is used for all session-dependent operations.
|
|
956
|
+
* - If no active session key is set, returns `undefined`.
|
|
957
|
+
* - Useful for determining which session is currently in use, especially when managing multiple sessions.
|
|
958
|
+
*
|
|
959
|
+
* @returns A promise that resolves to the active session key as a string, or `undefined` if no active session is set.
|
|
960
|
+
* @throws {TurnkeyError} If there is an error retrieving the active session key from storage.
|
|
961
|
+
*/
|
|
962
|
+
getActiveSessionKey: () => Promise<string | undefined>;
|
|
963
|
+
/**
|
|
964
|
+
* Clears any unused API key pairs from persistent storage.
|
|
965
|
+
*
|
|
966
|
+
* - This function scans all API key pairs stored in indexedDB and removes any key pairs that are not associated with a session in persistent storage.
|
|
967
|
+
* - Ensures that only key pairs referenced by existing sessions are retained, preventing orphaned or stale key pairs from accumulating.
|
|
968
|
+
* - Iterates through all stored session keys and builds a map of in-use public keys, then deletes any key pairs not present in this map.
|
|
969
|
+
* - Intended to be called after session changes (e.g., login, logout, session replacement) to keep key storage clean and secure.
|
|
970
|
+
*
|
|
971
|
+
* @returns A promise that resolves when all unused key pairs are successfully cleared.
|
|
972
|
+
* @throws {TurnkeyError} If there is an error listing, checking, or deleting unused key pairs.
|
|
973
|
+
*/
|
|
974
|
+
clearUnusedKeyPairs: () => Promise<void>;
|
|
975
|
+
/**
|
|
976
|
+
* Creates a new API key pair and returns the public key.
|
|
977
|
+
*
|
|
978
|
+
* - This function generates a new API key pair and stores it in the underlying key store (IndexedDB).
|
|
979
|
+
* - If an external key pair is provided, it will use that key pair for creation instead of generating a new one.
|
|
980
|
+
* - If `storeOverride` is set to true, the generated or provided public key will be set as the override key in the API key stamper, making it the active key for subsequent signing operations.
|
|
981
|
+
* - Ensures the API key stamper is initialized before proceeding.
|
|
982
|
+
* - Handles both native CryptoKeyPair objects and raw key material.
|
|
983
|
+
*
|
|
984
|
+
* @param params.externalKeyPair - An externally generated key pair (either a CryptoKeyPair or an object with publicKey/privateKey strings) to use instead of generating a new one.
|
|
985
|
+
* @param params.storeOverride - If true, sets the generated or provided public key as the override key in the API key stamper (defaults to false).
|
|
986
|
+
* @returnparams.s A promise that resolves to the public key of the created or provided API key pair as a string.
|
|
987
|
+
* @throws {TurnkeyError} If the API key stamper is not initialized or if there is an error during key pair creation or storage.
|
|
988
|
+
*/
|
|
989
|
+
createApiKeyPair: (params?: {
|
|
990
|
+
externalKeyPair?: CryptoKeyPair | {
|
|
991
|
+
publicKey: string;
|
|
992
|
+
privateKey: string;
|
|
993
|
+
};
|
|
994
|
+
storeOverride?: boolean;
|
|
995
|
+
}) => Promise<string>;
|
|
996
|
+
/**
|
|
997
|
+
* Fetches the WalletKit proxy authentication configuration from the auth proxy.
|
|
998
|
+
*
|
|
999
|
+
* - This function makes a request to the Turnkey auth proxy to retrieve the current WalletKit configuration,
|
|
1000
|
+
* including supported authentication methods, OAuth providers, and any custom proxy settings.
|
|
1001
|
+
* - Useful for dynamically configuring the client UI or authentication flows based on the proxy's capabilities.
|
|
1002
|
+
* - Ensures that the client is aware of the latest proxy-side configuration, which may affect available login/signup options.
|
|
1003
|
+
*
|
|
1004
|
+
* @returns A promise that resolves to a `ProxyTGetWalletKitConfigResponse` object containing the proxy authentication configuration.
|
|
1005
|
+
* @throws {TurnkeyError} If there is an error retrieving the proxy authentication configuration from the auth proxy.
|
|
1006
|
+
*/
|
|
1007
|
+
getProxyAuthConfig: () => Promise<ProxyTGetWalletKitConfigResponse>;
|
|
1008
|
+
}
|
|
1009
|
+
export {};
|
|
1010
|
+
//# sourceMappingURL=core.d.ts.map
|