@turnkey/core 1.3.0 → 1.4.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.
Files changed (43) hide show
  1. package/dist/__clients__/core.d.ts +41 -1
  2. package/dist/__clients__/core.d.ts.map +1 -1
  3. package/dist/__clients__/core.js +169 -116
  4. package/dist/__clients__/core.js.map +1 -1
  5. package/dist/__clients__/core.mjs +171 -118
  6. package/dist/__clients__/core.mjs.map +1 -1
  7. package/dist/__generated__/sdk-client-base.d.ts +2 -2
  8. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  9. package/dist/__generated__/sdk-client-base.js +23 -3
  10. package/dist/__generated__/sdk-client-base.js.map +1 -1
  11. package/dist/__generated__/sdk-client-base.mjs +23 -3
  12. package/dist/__generated__/sdk-client-base.mjs.map +1 -1
  13. package/dist/__generated__/version.d.ts +1 -1
  14. package/dist/__generated__/version.js +1 -1
  15. package/dist/__generated__/version.mjs +1 -1
  16. package/dist/__stampers__/passkey/base.d.ts +1 -3
  17. package/dist/__stampers__/passkey/base.d.ts.map +1 -1
  18. package/dist/__stampers__/passkey/base.js.map +1 -1
  19. package/dist/__stampers__/passkey/base.mjs.map +1 -1
  20. package/dist/__types__/config.d.ts +5 -0
  21. package/dist/__types__/config.d.ts.map +1 -1
  22. package/dist/__types__/http.d.ts +17 -0
  23. package/dist/__types__/http.d.ts.map +1 -0
  24. package/dist/__types__/http.js +11 -0
  25. package/dist/__types__/http.js.map +1 -0
  26. package/dist/__types__/http.mjs +9 -0
  27. package/dist/__types__/http.mjs.map +1 -0
  28. package/dist/__types__/index.d.ts +1 -0
  29. package/dist/__types__/index.d.ts.map +1 -1
  30. package/dist/__types__/method-types.d.ts +18 -1
  31. package/dist/__types__/method-types.d.ts.map +1 -1
  32. package/dist/index.d.ts +2 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +3 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.mjs +2 -2
  37. package/dist/utils.d.ts +12 -1
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +27 -0
  40. package/dist/utils.js.map +1 -1
  41. package/dist/utils.mjs +29 -3
  42. package/dist/utils.mjs.map +1 -1
  43. package/package.json +4 -5
@@ -1,8 +1,8 @@
1
1
  import { TurnkeySDKClientBase } from '../__generated__/sdk-client-base.mjs';
2
- import { TurnkeyErrorCodes, TurnkeyError, TurnkeyNetworkError, AuthAction } from '@turnkey/sdk-types';
2
+ import { TurnkeyErrorCodes, TurnkeyError, AuthAction } from '@turnkey/sdk-types';
3
3
  import { DEFAULT_SESSION_EXPIRATION_IN_SECONDS } from '../__types__/auth.mjs';
4
4
  import { SessionKey, StamperType, WalletSource, Chain, FilterType, OtpTypeToFilterTypeMap, OtpType, Curve, SignIntent } from '../__types__/enums.mjs';
5
- import { withTurnkeyErrorHandling, isValidPasskeyName, isWeb, isReactNative, buildSignUpBody, findWalletProviderFromAddress, addressFromPublicKey, getCurveTypeFromProvider, getPublicKeyFromStampHeader, fetchAllWalletAccountsWithCursor, mapAccountsToWallet, toExternalTimestamp, getAuthenticatorAddresses, isEthereumProvider, isSolanaProvider, getActiveSessionOrThrowIfRequired, getHashFunction, getEncodingType, getEncodedMessage, splitSignature, broadcastTransaction, getPolicySignature, googleISS, isWalletAccountArray, generateWalletAccountsFromAddressFormat } from '../utils.mjs';
5
+ import { withTurnkeyErrorHandling, isValidPasskeyName, isWeb, isReactNative, buildSignUpBody, findWalletProviderFromAddress, getPublicKeyFromStampHeader, addressFromPublicKey, getCurveTypeFromProvider, sendSignedRequest, fetchAllWalletAccountsWithCursor, mapAccountsToWallet, toExternalTimestamp, getAuthenticatorAddresses, isEthereumProvider, isSolanaProvider, getActiveSessionOrThrowIfRequired, getHashFunction, getEncodingType, getEncodedMessage, splitSignature, broadcastTransaction, getPolicySignature, googleISS, isWalletAccountArray, generateWalletAccountsFromAddressFormat } from '../utils.mjs';
6
6
  import { createStorageManager } from '../__storage__/base.mjs';
7
7
  import { CrossPlatformApiKeyStamper } from '../__stampers__/api/base.mjs';
8
8
  import { CrossPlatformPasskeyStamper } from '../__stampers__/passkey/base.mjs';
@@ -15,6 +15,41 @@ class TurnkeyClient {
15
15
  constructor(config,
16
16
  // Users can pass in their own stampers, or we will create them. Should we remove this?
17
17
  apiKeyStamper, passkeyStamper, walletManager) {
18
+ /**
19
+ * Creates a new TurnkeySDKClientBase instance with the provided configuration.
20
+ * This method is used internally to create the HTTP client for making API requests,
21
+ * but can also be used to create an additional client with different configurations if needed.
22
+ * By default, it uses the configuration provided during the TurnkeyClient initialization.
23
+ *
24
+ * @param params - Optional configuration parameters to override the default client configuration.
25
+ * @param params.apiBaseUrl - The base URL of the Turnkey API (defaults to `https://api.turnkey.com` if not provided).
26
+ * @param params.organizationId - The organization ID to associate requests with.
27
+ * @param params.authProxyUrl - The base URL of the Auth Proxy (defaults to `https://authproxy.turnkey.com` if not provided).
28
+ * @param params.authProxyConfigId - The configuration ID to use when making Auth Proxy requests.
29
+ * @param params.defaultStamperType - The default stamper type to use for signing requests
30
+ * (overrides automatic detection of ApiKey, Passkey, or Wallet stampers).
31
+ *
32
+ * @returns A new instance of {@link TurnkeySDKClientBase} configured with the provided parameters.
33
+ */
34
+ this.createHttpClient = (params) => {
35
+ // We can comfortably default to the prod urls here
36
+ const apiBaseUrl = params?.apiBaseUrl || this.config.apiBaseUrl || "https://api.turnkey.com";
37
+ const authProxyUrl = params?.authProxyUrl ||
38
+ this.config.authProxyUrl ||
39
+ "https://authproxy.turnkey.com";
40
+ const organizationId = params?.organizationId || this.config.organizationId;
41
+ return new TurnkeySDKClientBase({
42
+ ...this.config,
43
+ ...params,
44
+ apiBaseUrl,
45
+ authProxyUrl,
46
+ organizationId,
47
+ apiKeyStamper: this.apiKeyStamper,
48
+ passkeyStamper: this.passkeyStamper,
49
+ walletStamper: this.walletManager?.stamper,
50
+ storageManager: this.storageManager,
51
+ });
52
+ };
18
53
  /**
19
54
  * Creates a new passkey authenticator for the user.
20
55
  *
@@ -377,6 +412,105 @@ class TurnkeyClient {
377
412
  errorCode: TurnkeyErrorCodes.SWITCH_WALLET_CHAIN_ERROR,
378
413
  });
379
414
  };
415
+ /**
416
+ * Builds and signs a wallet login request without submitting it to Turnkey.
417
+ *
418
+ * - This function prepares a signed request for wallet authentication, which can later be used
419
+ * to log in or sign up a user with Turnkey.
420
+ * - It initializes the wallet stamper, ensures a valid session public key (generating one if needed),
421
+ * and signs the login intent with the connected wallet.
422
+ * - For Ethereum wallets, derives the public key from the stamped request header.
423
+ * - For Solana wallets, retrieves the public key directly from the connected wallet.
424
+ * - The signed request is not sent to Turnkey immediately; it is meant to be used in a subsequent flow
425
+ * (e.g., `loginOrSignupWithWallet`) where sub-organization existence is verified or created first.
426
+ *
427
+ * @param params.walletProvider - the wallet provider used for authentication and signing.
428
+ * @param params.publicKey - optional pre-generated session public key (auto-generated if not provided).
429
+ * @param params.expirationSeconds - optional session expiration time in seconds (defaults to the configured default).
430
+ * @returns A promise resolving to an object containing:
431
+ * - `signedRequest`: the signed wallet login request.
432
+ * - `publicKey`: the public key associated with the signed request.
433
+ * @throws {TurnkeyError} If the wallet stamper is not initialized, the signing process fails,
434
+ * or the public key cannot be derived or generated.
435
+ */
436
+ this.buildWalletLoginRequest = async (params) => {
437
+ const { walletProvider, publicKey: providedPublicKey } = params;
438
+ const expirationSeconds = params.expirationSeconds || DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
439
+ let generatedPublicKey = undefined;
440
+ return withTurnkeyErrorHandling(async () => {
441
+ if (!this.walletManager?.stamper) {
442
+ throw new TurnkeyError("Wallet stamper is not initialized", TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
443
+ }
444
+ const futureSessionPublicKey = providedPublicKey ??
445
+ (generatedPublicKey = await this.apiKeyStamper?.createKeyPair());
446
+ if (!futureSessionPublicKey) {
447
+ throw new TurnkeyError("Failed to find or generate a public key for building the wallet login request", TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR);
448
+ }
449
+ this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
450
+ // here we sign the request with the wallet, but we don't send it to Turnkey yet
451
+ // this is because we need to check if the subOrg exists first, and create one if it doesn't
452
+ // once we have the subOrg for the publicKey, we then can send the request to Turnkey
453
+ const signedRequest = await withTurnkeyErrorHandling(async () => {
454
+ return this.httpClient.stampStampLogin({
455
+ publicKey: futureSessionPublicKey,
456
+ organizationId: this.config.organizationId,
457
+ expirationSeconds,
458
+ }, StamperType.Wallet);
459
+ }, {
460
+ errorMessage: "Failed to create stamped request for wallet login",
461
+ errorCode: TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
462
+ customErrorsByMessages: {
463
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
464
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
465
+ code: TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
466
+ },
467
+ "Failed to sign the message": {
468
+ message: "Wallet auth was cancelled by the user.",
469
+ code: TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
470
+ },
471
+ },
472
+ });
473
+ if (!signedRequest) {
474
+ throw new TurnkeyError("Failed to create stamped request for wallet login", TurnkeyErrorCodes.BAD_RESPONSE);
475
+ }
476
+ let publicKey;
477
+ switch (walletProvider.chainInfo.namespace) {
478
+ case Chain.Ethereum: {
479
+ // for Ethereum, there is no way to get the public key from the wallet address
480
+ // so we derive it from the signed request
481
+ publicKey = getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
482
+ break;
483
+ }
484
+ case Chain.Solana: {
485
+ // for Solana, we can get the public key from the wallet address
486
+ // since the wallet address is the public key
487
+ // this doesn't require any action from the user as long as the wallet is connected
488
+ // which it has to be since they just called stampStampLogin()
489
+ publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
490
+ break;
491
+ }
492
+ default:
493
+ throw new TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, TurnkeyErrorCodes.INVALID_REQUEST);
494
+ }
495
+ return {
496
+ signedRequest,
497
+ publicKey: publicKey,
498
+ };
499
+ }, {
500
+ errorCode: TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
501
+ errorMessage: "Failed to build wallet login request",
502
+ catchFn: async () => {
503
+ if (generatedPublicKey) {
504
+ try {
505
+ await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
506
+ }
507
+ catch (cleanupError) {
508
+ throw new TurnkeyError(`Failed to clean up generated key pair`, TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
509
+ }
510
+ }
511
+ },
512
+ });
513
+ };
380
514
  /**
381
515
  * Logs in a user using the specified wallet provider.
382
516
  *
@@ -397,7 +531,7 @@ class TurnkeyClient {
397
531
  * @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
398
532
  */
399
533
  this.loginWithWallet = async (params) => {
400
- let publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
534
+ const publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
401
535
  return withTurnkeyErrorHandling(async () => {
402
536
  if (!this.walletManager?.stamper) {
403
537
  throw new TurnkeyError("Wallet stamper is not initialized", TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
@@ -544,6 +678,7 @@ class TurnkeyClient {
544
678
  * - Stores the resulting session token under the specified session key, or the default session key if not provided.
545
679
  *
546
680
  * @param params.walletProvider - wallet provider to use for authentication.
681
+ * @param params.publicKey - optional public key to associate with the session (generated if not provided).
547
682
  * @param params.createSubOrgParams - optional parameters for creating a sub-organization (e.g., authenticators, user metadata).
548
683
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
549
684
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
@@ -558,59 +693,8 @@ class TurnkeyClient {
558
693
  const createSubOrgParams = params.createSubOrgParams;
559
694
  const sessionKey = params.sessionKey || SessionKey.DefaultSessionkey;
560
695
  const walletProvider = params.walletProvider;
561
- const expirationSeconds = params.expirationSeconds || DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
562
- let generatedPublicKey = undefined;
563
696
  return withTurnkeyErrorHandling(async () => {
564
- if (!this.walletManager?.stamper) {
565
- throw new TurnkeyError("Wallet stamper is not initialized", TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
566
- }
567
- generatedPublicKey = await this.apiKeyStamper?.createKeyPair();
568
- this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
569
- // here we sign the request with the wallet, but we don't send it to Turnkey yet
570
- // this is because we need to check if the subOrg exists first, and create one if it doesn't
571
- // once we have the subOrg for the publicKey, we then can send the request to Turnkey
572
- const signedRequest = await withTurnkeyErrorHandling(async () => {
573
- return this.httpClient.stampStampLogin({
574
- publicKey: generatedPublicKey,
575
- organizationId: this.config.organizationId,
576
- expirationSeconds,
577
- }, StamperType.Wallet);
578
- }, {
579
- errorMessage: "Failed to create stamped request for wallet login",
580
- errorCode: TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
581
- customErrorsByMessages: {
582
- "WalletConnect: The connection request has expired. Please scan the QR code again.": {
583
- message: "Your WalletConnect session expired. Please scan the QR code again.",
584
- code: TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
585
- },
586
- "Failed to sign the message": {
587
- message: "Wallet auth was cancelled by the user.",
588
- code: TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
589
- },
590
- },
591
- });
592
- if (!signedRequest) {
593
- throw new TurnkeyError("Failed to create stamped request for wallet login", TurnkeyErrorCodes.BAD_RESPONSE);
594
- }
595
- let publicKey;
596
- switch (walletProvider.chainInfo.namespace) {
597
- case Chain.Ethereum: {
598
- // for Ethereum, there is no way to get the public key from the wallet address
599
- // so we derive it from the signed request
600
- publicKey = getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
601
- break;
602
- }
603
- case Chain.Solana: {
604
- // for Solana, we can get the public key from the wallet address
605
- // since the wallet address is the public key
606
- // this doesn't require any action from the user as long as the wallet is connected
607
- // which it has to be since they just called stampStampLogin()
608
- publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
609
- break;
610
- }
611
- default:
612
- throw new TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, TurnkeyErrorCodes.INVALID_REQUEST);
613
- }
697
+ const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
614
698
  // here we check if the subOrg exists and create one
615
699
  // then we send off the stamped request to Turnkey
616
700
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -641,20 +725,7 @@ class TurnkeyClient {
641
725
  }
642
726
  }
643
727
  // now we can send the stamped request to Turnkey
644
- const headers = {
645
- "Content-Type": "application/json",
646
- [signedRequest.stamp.stampHeaderName]: signedRequest.stamp.stampHeaderValue,
647
- };
648
- const res = await fetch(signedRequest.url, {
649
- method: "POST",
650
- headers,
651
- body: signedRequest.body,
652
- });
653
- if (!res.ok) {
654
- const errorText = await res.text();
655
- throw new TurnkeyNetworkError(`Stamped request failed`, res.status, TurnkeyErrorCodes.WALLET_LOGIN_AUTH_ERROR, errorText);
656
- }
657
- const sessionResponse = await res.json();
728
+ const sessionResponse = await sendSignedRequest(signedRequest);
658
729
  const sessionToken = sessionResponse.activity.result.stampLoginResult?.session;
659
730
  if (!sessionToken) {
660
731
  throw new TurnkeyError("Session token not found in the response", TurnkeyErrorCodes.BAD_RESPONSE);
@@ -673,14 +744,6 @@ class TurnkeyClient {
673
744
  errorCode: TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
674
745
  errorMessage: "Failed to log in or sign up with wallet",
675
746
  catchFn: async () => {
676
- if (generatedPublicKey) {
677
- try {
678
- await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
679
- }
680
- catch (cleanupError) {
681
- throw new TurnkeyError(`Failed to clean up generated key pair`, TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
682
- }
683
- }
684
747
  },
685
748
  });
686
749
  };
@@ -1123,7 +1186,7 @@ class TurnkeyClient {
1123
1186
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallets.
1124
1187
  */
1125
1188
  this.fetchWallets = async (params) => {
1126
- const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith, } = params || {};
1189
+ const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith = this.config.defaultStamperType, } = params || {};
1127
1190
  const session = await this.storageManager.getActiveSession();
1128
1191
  if (!session && !connectedOnly) {
1129
1192
  throw new TurnkeyError("No active session found. Fetching embedded wallets requires a valid session. If you only need connected wallets, set the 'connectedOnly' parameter to true.", TurnkeyErrorCodes.NO_SESSION_FOUND);
@@ -1232,7 +1295,7 @@ class TurnkeyClient {
1232
1295
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallet accounts.
1233
1296
  */
1234
1297
  this.fetchWalletAccounts = async (params) => {
1235
- const { wallet, stampWith, walletProviders, paginationOptions } = params;
1298
+ const { wallet, stampWith = this.config.defaultStamperType, walletProviders, paginationOptions, } = params;
1236
1299
  const session = await this.storageManager.getActiveSession();
1237
1300
  const organizationId = params?.organizationId || session?.organizationId;
1238
1301
  const userId = params?.userId || session?.userId;
@@ -1361,7 +1424,7 @@ class TurnkeyClient {
1361
1424
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching private keys.
1362
1425
  */
1363
1426
  this.fetchPrivateKeys = async (params) => {
1364
- const { stampWith } = params || {};
1427
+ const { stampWith = this.config.defaultStamperType } = params || {};
1365
1428
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1366
1429
  const organizationId = params?.organizationId || session?.organizationId;
1367
1430
  if (!organizationId) {
@@ -1417,7 +1480,7 @@ class TurnkeyClient {
1417
1480
  * @throws {TurnkeyError} If signing fails, the wallet type does not support message signing, or the response is invalid.
1418
1481
  */
1419
1482
  this.signMessage = async (params) => {
1420
- const { message, walletAccount, stampWith, addEthereumPrefix, organizationId, } = params;
1483
+ const { message, walletAccount, stampWith = this.config.defaultStamperType, addEthereumPrefix, organizationId, } = params;
1421
1484
  const hashFunction = params.hashFunction || getHashFunction(walletAccount.addressFormat);
1422
1485
  const payloadEncoding = params.encoding || getEncodingType(walletAccount.addressFormat);
1423
1486
  return withTurnkeyErrorHandling(async () => {
@@ -1488,7 +1551,7 @@ class TurnkeyClient {
1488
1551
  * @throws {TurnkeyError} If the wallet type is unsupported, signing fails, or the response is invalid.
1489
1552
  */
1490
1553
  this.signTransaction = async (params) => {
1491
- const { walletAccount, unsignedTransaction, transactionType, stampWith, organizationId, } = params;
1554
+ const { walletAccount, unsignedTransaction, transactionType, stampWith = this.config.defaultStamperType, organizationId, } = params;
1492
1555
  return withTurnkeyErrorHandling(async () => {
1493
1556
  if (walletAccount.source === WalletSource.Connected) {
1494
1557
  switch (walletAccount.chainInfo.namespace) {
@@ -1543,7 +1606,7 @@ class TurnkeyClient {
1543
1606
  * @throws {TurnkeyError} If the wallet type is unsupported, or if signing/broadcasting fails.
1544
1607
  */
1545
1608
  this.signAndSendTransaction = async (params) => {
1546
- const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith, organizationId, } = params;
1609
+ const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith = this.config.defaultStamperType, organizationId, } = params;
1547
1610
  return withTurnkeyErrorHandling(async () => {
1548
1611
  if (walletAccount.source === WalletSource.Connected) {
1549
1612
  // this is a connected wallet account
@@ -1608,7 +1671,7 @@ class TurnkeyClient {
1608
1671
  * @throws {TurnkeyError} If there is no active session, if there is no userId, or if there is an error fetching user details.
1609
1672
  */
1610
1673
  this.fetchUser = async (params) => {
1611
- const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params || {};
1674
+ const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
1612
1675
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1613
1676
  const userId = userIdFromParams || session?.userId;
1614
1677
  if (!userId) {
@@ -1646,7 +1709,7 @@ class TurnkeyClient {
1646
1709
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, if user retrieval fails, or if user creation fails.
1647
1710
  */
1648
1711
  this.fetchOrCreateP256ApiKeyUser = async (params) => {
1649
- const { publicKey, createParams, stampWith, organizationId: organizationIdFromParams, } = params;
1712
+ const { publicKey, createParams, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
1650
1713
  return withTurnkeyErrorHandling(async () => {
1651
1714
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1652
1715
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -1728,7 +1791,7 @@ class TurnkeyClient {
1728
1791
  * if fetching policies fails, or if creating policies fails.
1729
1792
  */
1730
1793
  this.fetchOrCreatePolicies = async (params) => {
1731
- const { policies, stampWith } = params;
1794
+ const { policies, stampWith = this.config.defaultStamperType } = params;
1732
1795
  return await withTurnkeyErrorHandling(async () => {
1733
1796
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1734
1797
  if (!Array.isArray(policies) || policies.length === 0) {
@@ -1811,7 +1874,7 @@ class TurnkeyClient {
1811
1874
  * @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.
1812
1875
  */
1813
1876
  this.updateUserEmail = async (params) => {
1814
- const { verificationToken, email, stampWith, organizationId } = params;
1877
+ const { verificationToken, email, stampWith = this.config.defaultStamperType, organizationId, } = params;
1815
1878
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1816
1879
  const userId = params?.userId || session?.userId;
1817
1880
  if (!userId) {
@@ -1855,7 +1918,7 @@ class TurnkeyClient {
1855
1918
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user email.
1856
1919
  */
1857
1920
  this.removeUserEmail = async (params) => {
1858
- const { stampWith, organizationId } = params || {};
1921
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1859
1922
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1860
1923
  return withTurnkeyErrorHandling(async () => {
1861
1924
  const userId = params?.userId || session?.userId;
@@ -1894,7 +1957,7 @@ class TurnkeyClient {
1894
1957
  * @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.
1895
1958
  */
1896
1959
  this.updateUserPhoneNumber = async (params) => {
1897
- const { verificationToken, phoneNumber, stampWith, organizationId } = params;
1960
+ const { verificationToken, phoneNumber, stampWith = this.config.defaultStamperType, organizationId, } = params;
1898
1961
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1899
1962
  const userId = params?.userId || session?.userId;
1900
1963
  if (!userId) {
@@ -1931,7 +1994,7 @@ class TurnkeyClient {
1931
1994
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user phone number.
1932
1995
  */
1933
1996
  this.removeUserPhoneNumber = async (params) => {
1934
- const { stampWith, organizationId } = params || {};
1997
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1935
1998
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1936
1999
  const userId = params?.userId || session?.userId;
1937
2000
  if (!userId) {
@@ -1969,7 +2032,7 @@ class TurnkeyClient {
1969
2032
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating the user name.
1970
2033
  */
1971
2034
  this.updateUserName = async (params) => {
1972
- const { userName, stampWith, organizationId } = params;
2035
+ const { userName, stampWith = this.config.defaultStamperType, organizationId, } = params;
1973
2036
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1974
2037
  const userId = params?.userId || session?.userId;
1975
2038
  if (!userId) {
@@ -2009,7 +2072,7 @@ class TurnkeyClient {
2009
2072
  * @throws {TurnkeyError} If there is no active session, if the account already exists, or if there is an error adding the OAuth provider.
2010
2073
  */
2011
2074
  this.addOauthProvider = async (params) => {
2012
- const { providerName, oidcToken, stampWith } = params;
2075
+ const { providerName, oidcToken, stampWith = this.config.defaultStamperType, } = params;
2013
2076
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2014
2077
  return withTurnkeyErrorHandling(async () => {
2015
2078
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -2085,7 +2148,7 @@ class TurnkeyClient {
2085
2148
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the OAuth provider.
2086
2149
  */
2087
2150
  this.removeOauthProviders = async (params) => {
2088
- const { providerIds, stampWith, organizationId } = params;
2151
+ const { providerIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2089
2152
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2090
2153
  const userId = params?.userId || session?.userId;
2091
2154
  if (!userId) {
@@ -2124,7 +2187,7 @@ class TurnkeyClient {
2124
2187
  * @throws {TurnkeyError} If there is no active session, if passkey creation fails, or if there is an error adding the passkey.
2125
2188
  */
2126
2189
  this.addPasskey = async (params) => {
2127
- const { stampWith, organizationId } = params || {};
2190
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
2128
2191
  const name = params?.name || `Turnkey Passkey-${Date.now()}`;
2129
2192
  return withTurnkeyErrorHandling(async () => {
2130
2193
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
@@ -2172,7 +2235,7 @@ class TurnkeyClient {
2172
2235
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the passkeys.
2173
2236
  */
2174
2237
  this.removePasskeys = async (params) => {
2175
- const { authenticatorIds, stampWith, organizationId } = params;
2238
+ const { authenticatorIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2176
2239
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2177
2240
  const userId = params?.userId || session?.userId;
2178
2241
  if (!userId) {
@@ -2213,7 +2276,7 @@ class TurnkeyClient {
2213
2276
  * @throws {TurnkeyError} If there is no active session or if there is an error creating the wallet.
2214
2277
  */
2215
2278
  this.createWallet = async (params) => {
2216
- const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith, } = params;
2279
+ const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith = this.config.defaultStamperType, } = params;
2217
2280
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2218
2281
  const organizationId = organizationIdFromParams || session?.organizationId;
2219
2282
  if (!organizationId) {
@@ -2265,7 +2328,7 @@ class TurnkeyClient {
2265
2328
  * @throws {TurnkeyError} If there is no active session, if the wallet does not exist, or if there is an error creating the wallet accounts.
2266
2329
  */
2267
2330
  this.createWalletAccounts = async (params) => {
2268
- const { accounts, walletId, organizationId: organizationIdFromParams, stampWith, } = params;
2331
+ const { accounts, walletId, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2269
2332
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2270
2333
  const organizationId = organizationIdFromParams || session?.organizationId;
2271
2334
  if (!organizationId) {
@@ -2320,7 +2383,7 @@ class TurnkeyClient {
2320
2383
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the wallet.
2321
2384
  */
2322
2385
  this.exportWallet = async (params) => {
2323
- const { walletId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2386
+ const { walletId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2324
2387
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2325
2388
  const organizationId = organizationIdFromParams || session?.organizationId;
2326
2389
  if (!organizationId) {
@@ -2358,7 +2421,7 @@ class TurnkeyClient {
2358
2421
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the private key.
2359
2422
  */
2360
2423
  this.exportPrivateKey = async (params) => {
2361
- const { privateKeyId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2424
+ const { privateKeyId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2362
2425
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2363
2426
  const organizationId = organizationIdFromParams || session?.organizationId;
2364
2427
  if (!organizationId) {
@@ -2397,7 +2460,7 @@ class TurnkeyClient {
2397
2460
  *
2398
2461
  */
2399
2462
  this.exportWalletAccount = async (params) => {
2400
- const { address, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2463
+ const { address, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2401
2464
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2402
2465
  const organizationId = organizationIdFromParams || session?.organizationId;
2403
2466
  if (!organizationId) {
@@ -2438,7 +2501,7 @@ class TurnkeyClient {
2438
2501
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2439
2502
  */
2440
2503
  this.importWallet = async (params) => {
2441
- const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2504
+ const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2442
2505
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2443
2506
  const organizationId = organizationIdFromParams || session?.organizationId;
2444
2507
  if (!organizationId) {
@@ -2496,7 +2559,7 @@ class TurnkeyClient {
2496
2559
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2497
2560
  */
2498
2561
  this.importPrivateKey = async (params) => {
2499
- const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2562
+ const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2500
2563
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2501
2564
  const organizationId = organizationIdFromParams || session?.organizationId;
2502
2565
  if (!organizationId) {
@@ -2546,7 +2609,7 @@ class TurnkeyClient {
2546
2609
  * @throws {TurnkeyError} If there is no active session or if there is an error deleting the sub-organization.
2547
2610
  */
2548
2611
  this.deleteSubOrganization = async (params) => {
2549
- const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith, } = params || {};
2612
+ const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
2550
2613
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2551
2614
  const organizationId = organizationIdFromParams || session?.organizationId;
2552
2615
  return withTurnkeyErrorHandling(async () => {
@@ -2654,7 +2717,7 @@ class TurnkeyClient {
2654
2717
  * @throws {TurnkeyError} If the session key does not exist, if there is no active session, or if there is an error refreshing the session.
2655
2718
  */
2656
2719
  this.refreshSession = async (params) => {
2657
- const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, invalidateExisitng = false, } = params || {};
2720
+ const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, stampWith = this.config.defaultStamperType, invalidateExisitng = false, } = params || {};
2658
2721
  if (!sessionKey) {
2659
2722
  throw new TurnkeyError("No session key provided or active session to refresh session", TurnkeyErrorCodes.NO_SESSION_FOUND);
2660
2723
  }
@@ -2677,7 +2740,7 @@ class TurnkeyClient {
2677
2740
  publicKey: keyPair,
2678
2741
  expirationSeconds,
2679
2742
  invalidateExisting: invalidateExisitng,
2680
- }, params?.stampWith);
2743
+ }, stampWith);
2681
2744
  if (!res || !res.session) {
2682
2745
  throw new TurnkeyError("No session found in the refresh response", TurnkeyErrorCodes.BAD_RESPONSE);
2683
2746
  }
@@ -2890,7 +2953,7 @@ class TurnkeyClient {
2890
2953
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, or if boot proof retrieval fails.
2891
2954
  */
2892
2955
  this.fetchBootProofForAppProof = async (params) => {
2893
- const { appProof, stampWith, organizationId: organizationIdFromParams, } = params;
2956
+ const { appProof, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2894
2957
  return withTurnkeyErrorHandling(async () => {
2895
2958
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2896
2959
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -2937,19 +3000,9 @@ class TurnkeyClient {
2937
3000
  this.config.walletConfig?.features?.connecting) {
2938
3001
  this.walletManager = await createWalletManager(this.config.walletConfig);
2939
3002
  }
2940
- // We can comfortably default to the prod urls here
2941
- const apiBaseUrl = this.config.apiBaseUrl || "https://api.turnkey.com";
2942
- const authProxyUrl = this.config.authProxyUrl || "https://authproxy.turnkey.com";
2943
3003
  // Initialize the HTTP client with the appropriate stampers
2944
- this.httpClient = new TurnkeySDKClientBase({
2945
- ...this.config,
2946
- apiBaseUrl,
2947
- authProxyUrl,
2948
- apiKeyStamper: this.apiKeyStamper,
2949
- passkeyStamper: this.passkeyStamper,
2950
- walletStamper: this.walletManager?.stamper,
2951
- storageManager: this.storageManager,
2952
- });
3004
+ // Note: not passing anything here since we want to use the configured stampers and this.config
3005
+ this.httpClient = this.createHttpClient();
2953
3006
  }
2954
3007
  }
2955
3008