@turnkey/core 1.3.0 → 1.4.1

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 (49) 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 +179 -116
  4. package/dist/__clients__/core.js.map +1 -1
  5. package/dist/__clients__/core.mjs +181 -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/__storage__/mobile/storage.d.ts +11 -11
  21. package/dist/__storage__/mobile/storage.d.ts.map +1 -1
  22. package/dist/__storage__/mobile/storage.js +54 -52
  23. package/dist/__storage__/mobile/storage.js.map +1 -1
  24. package/dist/__storage__/mobile/storage.mjs +54 -52
  25. package/dist/__storage__/mobile/storage.mjs.map +1 -1
  26. package/dist/__types__/config.d.ts +5 -0
  27. package/dist/__types__/config.d.ts.map +1 -1
  28. package/dist/__types__/http.d.ts +17 -0
  29. package/dist/__types__/http.d.ts.map +1 -0
  30. package/dist/__types__/http.js +11 -0
  31. package/dist/__types__/http.js.map +1 -0
  32. package/dist/__types__/http.mjs +9 -0
  33. package/dist/__types__/http.mjs.map +1 -0
  34. package/dist/__types__/index.d.ts +1 -0
  35. package/dist/__types__/index.d.ts.map +1 -1
  36. package/dist/__types__/method-types.d.ts +18 -1
  37. package/dist/__types__/method-types.d.ts.map +1 -1
  38. package/dist/index.d.ts +2 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +3 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/index.mjs +2 -2
  43. package/dist/utils.d.ts +12 -1
  44. package/dist/utils.d.ts.map +1 -1
  45. package/dist/utils.js +38 -4
  46. package/dist/utils.js.map +1 -1
  47. package/dist/utils.mjs +40 -7
  48. package/dist/utils.mjs.map +1 -1
  49. package/package.json +5 -6
@@ -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
  *
@@ -315,6 +350,16 @@ class TurnkeyClient {
315
350
  }, {
316
351
  errorMessage: "Unable to connect wallet account",
317
352
  errorCode: TurnkeyErrorCodes.CONNECT_WALLET_ACCOUNT_ERROR,
353
+ customErrorsByMessages: {
354
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
355
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
356
+ code: TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
357
+ },
358
+ "User rejected the request": {
359
+ message: "Connect wallet was cancelled by the user.",
360
+ code: TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
361
+ },
362
+ },
318
363
  });
319
364
  };
320
365
  /**
@@ -377,6 +422,105 @@ class TurnkeyClient {
377
422
  errorCode: TurnkeyErrorCodes.SWITCH_WALLET_CHAIN_ERROR,
378
423
  });
379
424
  };
425
+ /**
426
+ * Builds and signs a wallet login request without submitting it to Turnkey.
427
+ *
428
+ * - This function prepares a signed request for wallet authentication, which can later be used
429
+ * to log in or sign up a user with Turnkey.
430
+ * - It initializes the wallet stamper, ensures a valid session public key (generating one if needed),
431
+ * and signs the login intent with the connected wallet.
432
+ * - For Ethereum wallets, derives the public key from the stamped request header.
433
+ * - For Solana wallets, retrieves the public key directly from the connected wallet.
434
+ * - The signed request is not sent to Turnkey immediately; it is meant to be used in a subsequent flow
435
+ * (e.g., `loginOrSignupWithWallet`) where sub-organization existence is verified or created first.
436
+ *
437
+ * @param params.walletProvider - the wallet provider used for authentication and signing.
438
+ * @param params.publicKey - optional pre-generated session public key (auto-generated if not provided).
439
+ * @param params.expirationSeconds - optional session expiration time in seconds (defaults to the configured default).
440
+ * @returns A promise resolving to an object containing:
441
+ * - `signedRequest`: the signed wallet login request.
442
+ * - `publicKey`: the public key associated with the signed request.
443
+ * @throws {TurnkeyError} If the wallet stamper is not initialized, the signing process fails,
444
+ * or the public key cannot be derived or generated.
445
+ */
446
+ this.buildWalletLoginRequest = async (params) => {
447
+ const { walletProvider, publicKey: providedPublicKey } = params;
448
+ const expirationSeconds = params.expirationSeconds || DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
449
+ let generatedPublicKey = undefined;
450
+ return withTurnkeyErrorHandling(async () => {
451
+ if (!this.walletManager?.stamper) {
452
+ throw new TurnkeyError("Wallet stamper is not initialized", TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
453
+ }
454
+ const futureSessionPublicKey = providedPublicKey ??
455
+ (generatedPublicKey = await this.apiKeyStamper?.createKeyPair());
456
+ if (!futureSessionPublicKey) {
457
+ throw new TurnkeyError("Failed to find or generate a public key for building the wallet login request", TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR);
458
+ }
459
+ this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
460
+ // here we sign the request with the wallet, but we don't send it to Turnkey yet
461
+ // this is because we need to check if the subOrg exists first, and create one if it doesn't
462
+ // once we have the subOrg for the publicKey, we then can send the request to Turnkey
463
+ const signedRequest = await withTurnkeyErrorHandling(async () => {
464
+ return this.httpClient.stampStampLogin({
465
+ publicKey: futureSessionPublicKey,
466
+ organizationId: this.config.organizationId,
467
+ expirationSeconds,
468
+ }, StamperType.Wallet);
469
+ }, {
470
+ errorMessage: "Failed to create stamped request for wallet login",
471
+ errorCode: TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
472
+ customErrorsByMessages: {
473
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
474
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
475
+ code: TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
476
+ },
477
+ "Failed to sign the message": {
478
+ message: "Wallet auth was cancelled by the user.",
479
+ code: TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
480
+ },
481
+ },
482
+ });
483
+ if (!signedRequest) {
484
+ throw new TurnkeyError("Failed to create stamped request for wallet login", TurnkeyErrorCodes.BAD_RESPONSE);
485
+ }
486
+ let publicKey;
487
+ switch (walletProvider.chainInfo.namespace) {
488
+ case Chain.Ethereum: {
489
+ // for Ethereum, there is no way to get the public key from the wallet address
490
+ // so we derive it from the signed request
491
+ publicKey = getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
492
+ break;
493
+ }
494
+ case Chain.Solana: {
495
+ // for Solana, we can get the public key from the wallet address
496
+ // since the wallet address is the public key
497
+ // this doesn't require any action from the user as long as the wallet is connected
498
+ // which it has to be since they just called stampStampLogin()
499
+ publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
500
+ break;
501
+ }
502
+ default:
503
+ throw new TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, TurnkeyErrorCodes.INVALID_REQUEST);
504
+ }
505
+ return {
506
+ signedRequest,
507
+ publicKey: publicKey,
508
+ };
509
+ }, {
510
+ errorCode: TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
511
+ errorMessage: "Failed to build wallet login request",
512
+ catchFn: async () => {
513
+ if (generatedPublicKey) {
514
+ try {
515
+ await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
516
+ }
517
+ catch (cleanupError) {
518
+ throw new TurnkeyError(`Failed to clean up generated key pair`, TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
519
+ }
520
+ }
521
+ },
522
+ });
523
+ };
380
524
  /**
381
525
  * Logs in a user using the specified wallet provider.
382
526
  *
@@ -397,7 +541,7 @@ class TurnkeyClient {
397
541
  * @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
398
542
  */
399
543
  this.loginWithWallet = async (params) => {
400
- let publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
544
+ const publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
401
545
  return withTurnkeyErrorHandling(async () => {
402
546
  if (!this.walletManager?.stamper) {
403
547
  throw new TurnkeyError("Wallet stamper is not initialized", TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
@@ -544,6 +688,7 @@ class TurnkeyClient {
544
688
  * - Stores the resulting session token under the specified session key, or the default session key if not provided.
545
689
  *
546
690
  * @param params.walletProvider - wallet provider to use for authentication.
691
+ * @param params.publicKey - optional public key to associate with the session (generated if not provided).
547
692
  * @param params.createSubOrgParams - optional parameters for creating a sub-organization (e.g., authenticators, user metadata).
548
693
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
549
694
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
@@ -558,59 +703,8 @@ class TurnkeyClient {
558
703
  const createSubOrgParams = params.createSubOrgParams;
559
704
  const sessionKey = params.sessionKey || SessionKey.DefaultSessionkey;
560
705
  const walletProvider = params.walletProvider;
561
- const expirationSeconds = params.expirationSeconds || DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
562
- let generatedPublicKey = undefined;
563
706
  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
- }
707
+ const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
614
708
  // here we check if the subOrg exists and create one
615
709
  // then we send off the stamped request to Turnkey
616
710
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -641,20 +735,7 @@ class TurnkeyClient {
641
735
  }
642
736
  }
643
737
  // 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();
738
+ const sessionResponse = await sendSignedRequest(signedRequest);
658
739
  const sessionToken = sessionResponse.activity.result.stampLoginResult?.session;
659
740
  if (!sessionToken) {
660
741
  throw new TurnkeyError("Session token not found in the response", TurnkeyErrorCodes.BAD_RESPONSE);
@@ -673,14 +754,6 @@ class TurnkeyClient {
673
754
  errorCode: TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
674
755
  errorMessage: "Failed to log in or sign up with wallet",
675
756
  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
757
  },
685
758
  });
686
759
  };
@@ -1123,7 +1196,7 @@ class TurnkeyClient {
1123
1196
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallets.
1124
1197
  */
1125
1198
  this.fetchWallets = async (params) => {
1126
- const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith, } = params || {};
1199
+ const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith = this.config.defaultStamperType, } = params || {};
1127
1200
  const session = await this.storageManager.getActiveSession();
1128
1201
  if (!session && !connectedOnly) {
1129
1202
  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 +1305,7 @@ class TurnkeyClient {
1232
1305
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallet accounts.
1233
1306
  */
1234
1307
  this.fetchWalletAccounts = async (params) => {
1235
- const { wallet, stampWith, walletProviders, paginationOptions } = params;
1308
+ const { wallet, stampWith = this.config.defaultStamperType, walletProviders, paginationOptions, } = params;
1236
1309
  const session = await this.storageManager.getActiveSession();
1237
1310
  const organizationId = params?.organizationId || session?.organizationId;
1238
1311
  const userId = params?.userId || session?.userId;
@@ -1361,7 +1434,7 @@ class TurnkeyClient {
1361
1434
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching private keys.
1362
1435
  */
1363
1436
  this.fetchPrivateKeys = async (params) => {
1364
- const { stampWith } = params || {};
1437
+ const { stampWith = this.config.defaultStamperType } = params || {};
1365
1438
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1366
1439
  const organizationId = params?.organizationId || session?.organizationId;
1367
1440
  if (!organizationId) {
@@ -1417,7 +1490,7 @@ class TurnkeyClient {
1417
1490
  * @throws {TurnkeyError} If signing fails, the wallet type does not support message signing, or the response is invalid.
1418
1491
  */
1419
1492
  this.signMessage = async (params) => {
1420
- const { message, walletAccount, stampWith, addEthereumPrefix, organizationId, } = params;
1493
+ const { message, walletAccount, stampWith = this.config.defaultStamperType, addEthereumPrefix, organizationId, } = params;
1421
1494
  const hashFunction = params.hashFunction || getHashFunction(walletAccount.addressFormat);
1422
1495
  const payloadEncoding = params.encoding || getEncodingType(walletAccount.addressFormat);
1423
1496
  return withTurnkeyErrorHandling(async () => {
@@ -1488,7 +1561,7 @@ class TurnkeyClient {
1488
1561
  * @throws {TurnkeyError} If the wallet type is unsupported, signing fails, or the response is invalid.
1489
1562
  */
1490
1563
  this.signTransaction = async (params) => {
1491
- const { walletAccount, unsignedTransaction, transactionType, stampWith, organizationId, } = params;
1564
+ const { walletAccount, unsignedTransaction, transactionType, stampWith = this.config.defaultStamperType, organizationId, } = params;
1492
1565
  return withTurnkeyErrorHandling(async () => {
1493
1566
  if (walletAccount.source === WalletSource.Connected) {
1494
1567
  switch (walletAccount.chainInfo.namespace) {
@@ -1543,7 +1616,7 @@ class TurnkeyClient {
1543
1616
  * @throws {TurnkeyError} If the wallet type is unsupported, or if signing/broadcasting fails.
1544
1617
  */
1545
1618
  this.signAndSendTransaction = async (params) => {
1546
- const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith, organizationId, } = params;
1619
+ const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith = this.config.defaultStamperType, organizationId, } = params;
1547
1620
  return withTurnkeyErrorHandling(async () => {
1548
1621
  if (walletAccount.source === WalletSource.Connected) {
1549
1622
  // this is a connected wallet account
@@ -1608,7 +1681,7 @@ class TurnkeyClient {
1608
1681
  * @throws {TurnkeyError} If there is no active session, if there is no userId, or if there is an error fetching user details.
1609
1682
  */
1610
1683
  this.fetchUser = async (params) => {
1611
- const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params || {};
1684
+ const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
1612
1685
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1613
1686
  const userId = userIdFromParams || session?.userId;
1614
1687
  if (!userId) {
@@ -1646,7 +1719,7 @@ class TurnkeyClient {
1646
1719
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, if user retrieval fails, or if user creation fails.
1647
1720
  */
1648
1721
  this.fetchOrCreateP256ApiKeyUser = async (params) => {
1649
- const { publicKey, createParams, stampWith, organizationId: organizationIdFromParams, } = params;
1722
+ const { publicKey, createParams, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
1650
1723
  return withTurnkeyErrorHandling(async () => {
1651
1724
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1652
1725
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -1728,7 +1801,7 @@ class TurnkeyClient {
1728
1801
  * if fetching policies fails, or if creating policies fails.
1729
1802
  */
1730
1803
  this.fetchOrCreatePolicies = async (params) => {
1731
- const { policies, stampWith } = params;
1804
+ const { policies, stampWith = this.config.defaultStamperType } = params;
1732
1805
  return await withTurnkeyErrorHandling(async () => {
1733
1806
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1734
1807
  if (!Array.isArray(policies) || policies.length === 0) {
@@ -1811,7 +1884,7 @@ class TurnkeyClient {
1811
1884
  * @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
1885
  */
1813
1886
  this.updateUserEmail = async (params) => {
1814
- const { verificationToken, email, stampWith, organizationId } = params;
1887
+ const { verificationToken, email, stampWith = this.config.defaultStamperType, organizationId, } = params;
1815
1888
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1816
1889
  const userId = params?.userId || session?.userId;
1817
1890
  if (!userId) {
@@ -1855,7 +1928,7 @@ class TurnkeyClient {
1855
1928
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user email.
1856
1929
  */
1857
1930
  this.removeUserEmail = async (params) => {
1858
- const { stampWith, organizationId } = params || {};
1931
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1859
1932
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1860
1933
  return withTurnkeyErrorHandling(async () => {
1861
1934
  const userId = params?.userId || session?.userId;
@@ -1894,7 +1967,7 @@ class TurnkeyClient {
1894
1967
  * @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
1968
  */
1896
1969
  this.updateUserPhoneNumber = async (params) => {
1897
- const { verificationToken, phoneNumber, stampWith, organizationId } = params;
1970
+ const { verificationToken, phoneNumber, stampWith = this.config.defaultStamperType, organizationId, } = params;
1898
1971
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1899
1972
  const userId = params?.userId || session?.userId;
1900
1973
  if (!userId) {
@@ -1931,7 +2004,7 @@ class TurnkeyClient {
1931
2004
  * @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
2005
  */
1933
2006
  this.removeUserPhoneNumber = async (params) => {
1934
- const { stampWith, organizationId } = params || {};
2007
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1935
2008
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1936
2009
  const userId = params?.userId || session?.userId;
1937
2010
  if (!userId) {
@@ -1969,7 +2042,7 @@ class TurnkeyClient {
1969
2042
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating the user name.
1970
2043
  */
1971
2044
  this.updateUserName = async (params) => {
1972
- const { userName, stampWith, organizationId } = params;
2045
+ const { userName, stampWith = this.config.defaultStamperType, organizationId, } = params;
1973
2046
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1974
2047
  const userId = params?.userId || session?.userId;
1975
2048
  if (!userId) {
@@ -2009,7 +2082,7 @@ class TurnkeyClient {
2009
2082
  * @throws {TurnkeyError} If there is no active session, if the account already exists, or if there is an error adding the OAuth provider.
2010
2083
  */
2011
2084
  this.addOauthProvider = async (params) => {
2012
- const { providerName, oidcToken, stampWith } = params;
2085
+ const { providerName, oidcToken, stampWith = this.config.defaultStamperType, } = params;
2013
2086
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2014
2087
  return withTurnkeyErrorHandling(async () => {
2015
2088
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -2085,7 +2158,7 @@ class TurnkeyClient {
2085
2158
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the OAuth provider.
2086
2159
  */
2087
2160
  this.removeOauthProviders = async (params) => {
2088
- const { providerIds, stampWith, organizationId } = params;
2161
+ const { providerIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2089
2162
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2090
2163
  const userId = params?.userId || session?.userId;
2091
2164
  if (!userId) {
@@ -2124,7 +2197,7 @@ class TurnkeyClient {
2124
2197
  * @throws {TurnkeyError} If there is no active session, if passkey creation fails, or if there is an error adding the passkey.
2125
2198
  */
2126
2199
  this.addPasskey = async (params) => {
2127
- const { stampWith, organizationId } = params || {};
2200
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
2128
2201
  const name = params?.name || `Turnkey Passkey-${Date.now()}`;
2129
2202
  return withTurnkeyErrorHandling(async () => {
2130
2203
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
@@ -2172,7 +2245,7 @@ class TurnkeyClient {
2172
2245
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the passkeys.
2173
2246
  */
2174
2247
  this.removePasskeys = async (params) => {
2175
- const { authenticatorIds, stampWith, organizationId } = params;
2248
+ const { authenticatorIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2176
2249
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2177
2250
  const userId = params?.userId || session?.userId;
2178
2251
  if (!userId) {
@@ -2213,7 +2286,7 @@ class TurnkeyClient {
2213
2286
  * @throws {TurnkeyError} If there is no active session or if there is an error creating the wallet.
2214
2287
  */
2215
2288
  this.createWallet = async (params) => {
2216
- const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith, } = params;
2289
+ const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith = this.config.defaultStamperType, } = params;
2217
2290
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2218
2291
  const organizationId = organizationIdFromParams || session?.organizationId;
2219
2292
  if (!organizationId) {
@@ -2265,7 +2338,7 @@ class TurnkeyClient {
2265
2338
  * @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
2339
  */
2267
2340
  this.createWalletAccounts = async (params) => {
2268
- const { accounts, walletId, organizationId: organizationIdFromParams, stampWith, } = params;
2341
+ const { accounts, walletId, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2269
2342
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2270
2343
  const organizationId = organizationIdFromParams || session?.organizationId;
2271
2344
  if (!organizationId) {
@@ -2320,7 +2393,7 @@ class TurnkeyClient {
2320
2393
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the wallet.
2321
2394
  */
2322
2395
  this.exportWallet = async (params) => {
2323
- const { walletId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2396
+ const { walletId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2324
2397
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2325
2398
  const organizationId = organizationIdFromParams || session?.organizationId;
2326
2399
  if (!organizationId) {
@@ -2358,7 +2431,7 @@ class TurnkeyClient {
2358
2431
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the private key.
2359
2432
  */
2360
2433
  this.exportPrivateKey = async (params) => {
2361
- const { privateKeyId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2434
+ const { privateKeyId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2362
2435
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2363
2436
  const organizationId = organizationIdFromParams || session?.organizationId;
2364
2437
  if (!organizationId) {
@@ -2397,7 +2470,7 @@ class TurnkeyClient {
2397
2470
  *
2398
2471
  */
2399
2472
  this.exportWalletAccount = async (params) => {
2400
- const { address, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2473
+ const { address, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2401
2474
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2402
2475
  const organizationId = organizationIdFromParams || session?.organizationId;
2403
2476
  if (!organizationId) {
@@ -2438,7 +2511,7 @@ class TurnkeyClient {
2438
2511
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2439
2512
  */
2440
2513
  this.importWallet = async (params) => {
2441
- const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2514
+ const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2442
2515
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2443
2516
  const organizationId = organizationIdFromParams || session?.organizationId;
2444
2517
  if (!organizationId) {
@@ -2496,7 +2569,7 @@ class TurnkeyClient {
2496
2569
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2497
2570
  */
2498
2571
  this.importPrivateKey = async (params) => {
2499
- const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2572
+ const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2500
2573
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2501
2574
  const organizationId = organizationIdFromParams || session?.organizationId;
2502
2575
  if (!organizationId) {
@@ -2546,7 +2619,7 @@ class TurnkeyClient {
2546
2619
  * @throws {TurnkeyError} If there is no active session or if there is an error deleting the sub-organization.
2547
2620
  */
2548
2621
  this.deleteSubOrganization = async (params) => {
2549
- const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith, } = params || {};
2622
+ const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
2550
2623
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2551
2624
  const organizationId = organizationIdFromParams || session?.organizationId;
2552
2625
  return withTurnkeyErrorHandling(async () => {
@@ -2654,7 +2727,7 @@ class TurnkeyClient {
2654
2727
  * @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
2728
  */
2656
2729
  this.refreshSession = async (params) => {
2657
- const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, invalidateExisitng = false, } = params || {};
2730
+ const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, stampWith = this.config.defaultStamperType, invalidateExisitng = false, } = params || {};
2658
2731
  if (!sessionKey) {
2659
2732
  throw new TurnkeyError("No session key provided or active session to refresh session", TurnkeyErrorCodes.NO_SESSION_FOUND);
2660
2733
  }
@@ -2677,7 +2750,7 @@ class TurnkeyClient {
2677
2750
  publicKey: keyPair,
2678
2751
  expirationSeconds,
2679
2752
  invalidateExisting: invalidateExisitng,
2680
- }, params?.stampWith);
2753
+ }, stampWith);
2681
2754
  if (!res || !res.session) {
2682
2755
  throw new TurnkeyError("No session found in the refresh response", TurnkeyErrorCodes.BAD_RESPONSE);
2683
2756
  }
@@ -2890,7 +2963,7 @@ class TurnkeyClient {
2890
2963
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, or if boot proof retrieval fails.
2891
2964
  */
2892
2965
  this.fetchBootProofForAppProof = async (params) => {
2893
- const { appProof, stampWith, organizationId: organizationIdFromParams, } = params;
2966
+ const { appProof, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2894
2967
  return withTurnkeyErrorHandling(async () => {
2895
2968
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2896
2969
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -2937,19 +3010,9 @@ class TurnkeyClient {
2937
3010
  this.config.walletConfig?.features?.connecting) {
2938
3011
  this.walletManager = await createWalletManager(this.config.walletConfig);
2939
3012
  }
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
3013
  // 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
- });
3014
+ // Note: not passing anything here since we want to use the configured stampers and this.config
3015
+ this.httpClient = this.createHttpClient();
2953
3016
  }
2954
3017
  }
2955
3018