@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
@@ -17,6 +17,41 @@ class TurnkeyClient {
17
17
  constructor(config,
18
18
  // Users can pass in their own stampers, or we will create them. Should we remove this?
19
19
  apiKeyStamper, passkeyStamper, walletManager) {
20
+ /**
21
+ * Creates a new TurnkeySDKClientBase instance with the provided configuration.
22
+ * This method is used internally to create the HTTP client for making API requests,
23
+ * but can also be used to create an additional client with different configurations if needed.
24
+ * By default, it uses the configuration provided during the TurnkeyClient initialization.
25
+ *
26
+ * @param params - Optional configuration parameters to override the default client configuration.
27
+ * @param params.apiBaseUrl - The base URL of the Turnkey API (defaults to `https://api.turnkey.com` if not provided).
28
+ * @param params.organizationId - The organization ID to associate requests with.
29
+ * @param params.authProxyUrl - The base URL of the Auth Proxy (defaults to `https://authproxy.turnkey.com` if not provided).
30
+ * @param params.authProxyConfigId - The configuration ID to use when making Auth Proxy requests.
31
+ * @param params.defaultStamperType - The default stamper type to use for signing requests
32
+ * (overrides automatic detection of ApiKey, Passkey, or Wallet stampers).
33
+ *
34
+ * @returns A new instance of {@link TurnkeySDKClientBase} configured with the provided parameters.
35
+ */
36
+ this.createHttpClient = (params) => {
37
+ // We can comfortably default to the prod urls here
38
+ const apiBaseUrl = params?.apiBaseUrl || this.config.apiBaseUrl || "https://api.turnkey.com";
39
+ const authProxyUrl = params?.authProxyUrl ||
40
+ this.config.authProxyUrl ||
41
+ "https://authproxy.turnkey.com";
42
+ const organizationId = params?.organizationId || this.config.organizationId;
43
+ return new sdkClientBase.TurnkeySDKClientBase({
44
+ ...this.config,
45
+ ...params,
46
+ apiBaseUrl,
47
+ authProxyUrl,
48
+ organizationId,
49
+ apiKeyStamper: this.apiKeyStamper,
50
+ passkeyStamper: this.passkeyStamper,
51
+ walletStamper: this.walletManager?.stamper,
52
+ storageManager: this.storageManager,
53
+ });
54
+ };
20
55
  /**
21
56
  * Creates a new passkey authenticator for the user.
22
57
  *
@@ -317,6 +352,16 @@ class TurnkeyClient {
317
352
  }, {
318
353
  errorMessage: "Unable to connect wallet account",
319
354
  errorCode: sdkTypes.TurnkeyErrorCodes.CONNECT_WALLET_ACCOUNT_ERROR,
355
+ customErrorsByMessages: {
356
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
357
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
358
+ code: sdkTypes.TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
359
+ },
360
+ "User rejected the request": {
361
+ message: "Connect wallet was cancelled by the user.",
362
+ code: sdkTypes.TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
363
+ },
364
+ },
320
365
  });
321
366
  };
322
367
  /**
@@ -379,6 +424,105 @@ class TurnkeyClient {
379
424
  errorCode: sdkTypes.TurnkeyErrorCodes.SWITCH_WALLET_CHAIN_ERROR,
380
425
  });
381
426
  };
427
+ /**
428
+ * Builds and signs a wallet login request without submitting it to Turnkey.
429
+ *
430
+ * - This function prepares a signed request for wallet authentication, which can later be used
431
+ * to log in or sign up a user with Turnkey.
432
+ * - It initializes the wallet stamper, ensures a valid session public key (generating one if needed),
433
+ * and signs the login intent with the connected wallet.
434
+ * - For Ethereum wallets, derives the public key from the stamped request header.
435
+ * - For Solana wallets, retrieves the public key directly from the connected wallet.
436
+ * - The signed request is not sent to Turnkey immediately; it is meant to be used in a subsequent flow
437
+ * (e.g., `loginOrSignupWithWallet`) where sub-organization existence is verified or created first.
438
+ *
439
+ * @param params.walletProvider - the wallet provider used for authentication and signing.
440
+ * @param params.publicKey - optional pre-generated session public key (auto-generated if not provided).
441
+ * @param params.expirationSeconds - optional session expiration time in seconds (defaults to the configured default).
442
+ * @returns A promise resolving to an object containing:
443
+ * - `signedRequest`: the signed wallet login request.
444
+ * - `publicKey`: the public key associated with the signed request.
445
+ * @throws {TurnkeyError} If the wallet stamper is not initialized, the signing process fails,
446
+ * or the public key cannot be derived or generated.
447
+ */
448
+ this.buildWalletLoginRequest = async (params) => {
449
+ const { walletProvider, publicKey: providedPublicKey } = params;
450
+ const expirationSeconds = params.expirationSeconds || auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
451
+ let generatedPublicKey = undefined;
452
+ return utils.withTurnkeyErrorHandling(async () => {
453
+ if (!this.walletManager?.stamper) {
454
+ throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
455
+ }
456
+ const futureSessionPublicKey = providedPublicKey ??
457
+ (generatedPublicKey = await this.apiKeyStamper?.createKeyPair());
458
+ if (!futureSessionPublicKey) {
459
+ throw new sdkTypes.TurnkeyError("Failed to find or generate a public key for building the wallet login request", sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR);
460
+ }
461
+ this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
462
+ // here we sign the request with the wallet, but we don't send it to Turnkey yet
463
+ // this is because we need to check if the subOrg exists first, and create one if it doesn't
464
+ // once we have the subOrg for the publicKey, we then can send the request to Turnkey
465
+ const signedRequest = await utils.withTurnkeyErrorHandling(async () => {
466
+ return this.httpClient.stampStampLogin({
467
+ publicKey: futureSessionPublicKey,
468
+ organizationId: this.config.organizationId,
469
+ expirationSeconds,
470
+ }, enums.StamperType.Wallet);
471
+ }, {
472
+ errorMessage: "Failed to create stamped request for wallet login",
473
+ errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
474
+ customErrorsByMessages: {
475
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
476
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
477
+ code: sdkTypes.TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
478
+ },
479
+ "Failed to sign the message": {
480
+ message: "Wallet auth was cancelled by the user.",
481
+ code: sdkTypes.TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
482
+ },
483
+ },
484
+ });
485
+ if (!signedRequest) {
486
+ throw new sdkTypes.TurnkeyError("Failed to create stamped request for wallet login", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
487
+ }
488
+ let publicKey;
489
+ switch (walletProvider.chainInfo.namespace) {
490
+ case enums.Chain.Ethereum: {
491
+ // for Ethereum, there is no way to get the public key from the wallet address
492
+ // so we derive it from the signed request
493
+ publicKey = utils.getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
494
+ break;
495
+ }
496
+ case enums.Chain.Solana: {
497
+ // for Solana, we can get the public key from the wallet address
498
+ // since the wallet address is the public key
499
+ // this doesn't require any action from the user as long as the wallet is connected
500
+ // which it has to be since they just called stampStampLogin()
501
+ publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
502
+ break;
503
+ }
504
+ default:
505
+ throw new sdkTypes.TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
506
+ }
507
+ return {
508
+ signedRequest,
509
+ publicKey: publicKey,
510
+ };
511
+ }, {
512
+ errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
513
+ errorMessage: "Failed to build wallet login request",
514
+ catchFn: async () => {
515
+ if (generatedPublicKey) {
516
+ try {
517
+ await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
518
+ }
519
+ catch (cleanupError) {
520
+ throw new sdkTypes.TurnkeyError(`Failed to clean up generated key pair`, sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
521
+ }
522
+ }
523
+ },
524
+ });
525
+ };
382
526
  /**
383
527
  * Logs in a user using the specified wallet provider.
384
528
  *
@@ -399,7 +543,7 @@ class TurnkeyClient {
399
543
  * @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
400
544
  */
401
545
  this.loginWithWallet = async (params) => {
402
- let publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
546
+ const publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
403
547
  return utils.withTurnkeyErrorHandling(async () => {
404
548
  if (!this.walletManager?.stamper) {
405
549
  throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
@@ -546,6 +690,7 @@ class TurnkeyClient {
546
690
  * - Stores the resulting session token under the specified session key, or the default session key if not provided.
547
691
  *
548
692
  * @param params.walletProvider - wallet provider to use for authentication.
693
+ * @param params.publicKey - optional public key to associate with the session (generated if not provided).
549
694
  * @param params.createSubOrgParams - optional parameters for creating a sub-organization (e.g., authenticators, user metadata).
550
695
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
551
696
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
@@ -560,59 +705,8 @@ class TurnkeyClient {
560
705
  const createSubOrgParams = params.createSubOrgParams;
561
706
  const sessionKey = params.sessionKey || enums.SessionKey.DefaultSessionkey;
562
707
  const walletProvider = params.walletProvider;
563
- const expirationSeconds = params.expirationSeconds || auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
564
- let generatedPublicKey = undefined;
565
708
  return utils.withTurnkeyErrorHandling(async () => {
566
- if (!this.walletManager?.stamper) {
567
- throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
568
- }
569
- generatedPublicKey = await this.apiKeyStamper?.createKeyPair();
570
- this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
571
- // here we sign the request with the wallet, but we don't send it to Turnkey yet
572
- // this is because we need to check if the subOrg exists first, and create one if it doesn't
573
- // once we have the subOrg for the publicKey, we then can send the request to Turnkey
574
- const signedRequest = await utils.withTurnkeyErrorHandling(async () => {
575
- return this.httpClient.stampStampLogin({
576
- publicKey: generatedPublicKey,
577
- organizationId: this.config.organizationId,
578
- expirationSeconds,
579
- }, enums.StamperType.Wallet);
580
- }, {
581
- errorMessage: "Failed to create stamped request for wallet login",
582
- errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
583
- customErrorsByMessages: {
584
- "WalletConnect: The connection request has expired. Please scan the QR code again.": {
585
- message: "Your WalletConnect session expired. Please scan the QR code again.",
586
- code: sdkTypes.TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
587
- },
588
- "Failed to sign the message": {
589
- message: "Wallet auth was cancelled by the user.",
590
- code: sdkTypes.TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
591
- },
592
- },
593
- });
594
- if (!signedRequest) {
595
- throw new sdkTypes.TurnkeyError("Failed to create stamped request for wallet login", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
596
- }
597
- let publicKey;
598
- switch (walletProvider.chainInfo.namespace) {
599
- case enums.Chain.Ethereum: {
600
- // for Ethereum, there is no way to get the public key from the wallet address
601
- // so we derive it from the signed request
602
- publicKey = utils.getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
603
- break;
604
- }
605
- case enums.Chain.Solana: {
606
- // for Solana, we can get the public key from the wallet address
607
- // since the wallet address is the public key
608
- // this doesn't require any action from the user as long as the wallet is connected
609
- // which it has to be since they just called stampStampLogin()
610
- publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
611
- break;
612
- }
613
- default:
614
- throw new sdkTypes.TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
615
- }
709
+ const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
616
710
  // here we check if the subOrg exists and create one
617
711
  // then we send off the stamped request to Turnkey
618
712
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -643,20 +737,7 @@ class TurnkeyClient {
643
737
  }
644
738
  }
645
739
  // now we can send the stamped request to Turnkey
646
- const headers = {
647
- "Content-Type": "application/json",
648
- [signedRequest.stamp.stampHeaderName]: signedRequest.stamp.stampHeaderValue,
649
- };
650
- const res = await fetch(signedRequest.url, {
651
- method: "POST",
652
- headers,
653
- body: signedRequest.body,
654
- });
655
- if (!res.ok) {
656
- const errorText = await res.text();
657
- throw new sdkTypes.TurnkeyNetworkError(`Stamped request failed`, res.status, sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_AUTH_ERROR, errorText);
658
- }
659
- const sessionResponse = await res.json();
740
+ const sessionResponse = await utils.sendSignedRequest(signedRequest);
660
741
  const sessionToken = sessionResponse.activity.result.stampLoginResult?.session;
661
742
  if (!sessionToken) {
662
743
  throw new sdkTypes.TurnkeyError("Session token not found in the response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
@@ -675,14 +756,6 @@ class TurnkeyClient {
675
756
  errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
676
757
  errorMessage: "Failed to log in or sign up with wallet",
677
758
  catchFn: async () => {
678
- if (generatedPublicKey) {
679
- try {
680
- await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
681
- }
682
- catch (cleanupError) {
683
- throw new sdkTypes.TurnkeyError(`Failed to clean up generated key pair`, sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
684
- }
685
- }
686
759
  },
687
760
  });
688
761
  };
@@ -1125,7 +1198,7 @@ class TurnkeyClient {
1125
1198
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallets.
1126
1199
  */
1127
1200
  this.fetchWallets = async (params) => {
1128
- const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith, } = params || {};
1201
+ const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith = this.config.defaultStamperType, } = params || {};
1129
1202
  const session = await this.storageManager.getActiveSession();
1130
1203
  if (!session && !connectedOnly) {
1131
1204
  throw new sdkTypes.TurnkeyError("No active session found. Fetching embedded wallets requires a valid session. If you only need connected wallets, set the 'connectedOnly' parameter to true.", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
@@ -1234,7 +1307,7 @@ class TurnkeyClient {
1234
1307
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallet accounts.
1235
1308
  */
1236
1309
  this.fetchWalletAccounts = async (params) => {
1237
- const { wallet, stampWith, walletProviders, paginationOptions } = params;
1310
+ const { wallet, stampWith = this.config.defaultStamperType, walletProviders, paginationOptions, } = params;
1238
1311
  const session = await this.storageManager.getActiveSession();
1239
1312
  const organizationId = params?.organizationId || session?.organizationId;
1240
1313
  const userId = params?.userId || session?.userId;
@@ -1363,7 +1436,7 @@ class TurnkeyClient {
1363
1436
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching private keys.
1364
1437
  */
1365
1438
  this.fetchPrivateKeys = async (params) => {
1366
- const { stampWith } = params || {};
1439
+ const { stampWith = this.config.defaultStamperType } = params || {};
1367
1440
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1368
1441
  const organizationId = params?.organizationId || session?.organizationId;
1369
1442
  if (!organizationId) {
@@ -1419,7 +1492,7 @@ class TurnkeyClient {
1419
1492
  * @throws {TurnkeyError} If signing fails, the wallet type does not support message signing, or the response is invalid.
1420
1493
  */
1421
1494
  this.signMessage = async (params) => {
1422
- const { message, walletAccount, stampWith, addEthereumPrefix, organizationId, } = params;
1495
+ const { message, walletAccount, stampWith = this.config.defaultStamperType, addEthereumPrefix, organizationId, } = params;
1423
1496
  const hashFunction = params.hashFunction || utils.getHashFunction(walletAccount.addressFormat);
1424
1497
  const payloadEncoding = params.encoding || utils.getEncodingType(walletAccount.addressFormat);
1425
1498
  return utils.withTurnkeyErrorHandling(async () => {
@@ -1490,7 +1563,7 @@ class TurnkeyClient {
1490
1563
  * @throws {TurnkeyError} If the wallet type is unsupported, signing fails, or the response is invalid.
1491
1564
  */
1492
1565
  this.signTransaction = async (params) => {
1493
- const { walletAccount, unsignedTransaction, transactionType, stampWith, organizationId, } = params;
1566
+ const { walletAccount, unsignedTransaction, transactionType, stampWith = this.config.defaultStamperType, organizationId, } = params;
1494
1567
  return utils.withTurnkeyErrorHandling(async () => {
1495
1568
  if (walletAccount.source === enums.WalletSource.Connected) {
1496
1569
  switch (walletAccount.chainInfo.namespace) {
@@ -1545,7 +1618,7 @@ class TurnkeyClient {
1545
1618
  * @throws {TurnkeyError} If the wallet type is unsupported, or if signing/broadcasting fails.
1546
1619
  */
1547
1620
  this.signAndSendTransaction = async (params) => {
1548
- const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith, organizationId, } = params;
1621
+ const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith = this.config.defaultStamperType, organizationId, } = params;
1549
1622
  return utils.withTurnkeyErrorHandling(async () => {
1550
1623
  if (walletAccount.source === enums.WalletSource.Connected) {
1551
1624
  // this is a connected wallet account
@@ -1610,7 +1683,7 @@ class TurnkeyClient {
1610
1683
  * @throws {TurnkeyError} If there is no active session, if there is no userId, or if there is an error fetching user details.
1611
1684
  */
1612
1685
  this.fetchUser = async (params) => {
1613
- const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params || {};
1686
+ const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
1614
1687
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1615
1688
  const userId = userIdFromParams || session?.userId;
1616
1689
  if (!userId) {
@@ -1648,7 +1721,7 @@ class TurnkeyClient {
1648
1721
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, if user retrieval fails, or if user creation fails.
1649
1722
  */
1650
1723
  this.fetchOrCreateP256ApiKeyUser = async (params) => {
1651
- const { publicKey, createParams, stampWith, organizationId: organizationIdFromParams, } = params;
1724
+ const { publicKey, createParams, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
1652
1725
  return utils.withTurnkeyErrorHandling(async () => {
1653
1726
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1654
1727
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -1730,7 +1803,7 @@ class TurnkeyClient {
1730
1803
  * if fetching policies fails, or if creating policies fails.
1731
1804
  */
1732
1805
  this.fetchOrCreatePolicies = async (params) => {
1733
- const { policies, stampWith } = params;
1806
+ const { policies, stampWith = this.config.defaultStamperType } = params;
1734
1807
  return await utils.withTurnkeyErrorHandling(async () => {
1735
1808
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1736
1809
  if (!Array.isArray(policies) || policies.length === 0) {
@@ -1813,7 +1886,7 @@ class TurnkeyClient {
1813
1886
  * @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.
1814
1887
  */
1815
1888
  this.updateUserEmail = async (params) => {
1816
- const { verificationToken, email, stampWith, organizationId } = params;
1889
+ const { verificationToken, email, stampWith = this.config.defaultStamperType, organizationId, } = params;
1817
1890
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1818
1891
  const userId = params?.userId || session?.userId;
1819
1892
  if (!userId) {
@@ -1857,7 +1930,7 @@ class TurnkeyClient {
1857
1930
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user email.
1858
1931
  */
1859
1932
  this.removeUserEmail = async (params) => {
1860
- const { stampWith, organizationId } = params || {};
1933
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1861
1934
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1862
1935
  return utils.withTurnkeyErrorHandling(async () => {
1863
1936
  const userId = params?.userId || session?.userId;
@@ -1896,7 +1969,7 @@ class TurnkeyClient {
1896
1969
  * @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.
1897
1970
  */
1898
1971
  this.updateUserPhoneNumber = async (params) => {
1899
- const { verificationToken, phoneNumber, stampWith, organizationId } = params;
1972
+ const { verificationToken, phoneNumber, stampWith = this.config.defaultStamperType, organizationId, } = params;
1900
1973
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1901
1974
  const userId = params?.userId || session?.userId;
1902
1975
  if (!userId) {
@@ -1933,7 +2006,7 @@ class TurnkeyClient {
1933
2006
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user phone number.
1934
2007
  */
1935
2008
  this.removeUserPhoneNumber = async (params) => {
1936
- const { stampWith, organizationId } = params || {};
2009
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1937
2010
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1938
2011
  const userId = params?.userId || session?.userId;
1939
2012
  if (!userId) {
@@ -1971,7 +2044,7 @@ class TurnkeyClient {
1971
2044
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating the user name.
1972
2045
  */
1973
2046
  this.updateUserName = async (params) => {
1974
- const { userName, stampWith, organizationId } = params;
2047
+ const { userName, stampWith = this.config.defaultStamperType, organizationId, } = params;
1975
2048
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1976
2049
  const userId = params?.userId || session?.userId;
1977
2050
  if (!userId) {
@@ -2011,7 +2084,7 @@ class TurnkeyClient {
2011
2084
  * @throws {TurnkeyError} If there is no active session, if the account already exists, or if there is an error adding the OAuth provider.
2012
2085
  */
2013
2086
  this.addOauthProvider = async (params) => {
2014
- const { providerName, oidcToken, stampWith } = params;
2087
+ const { providerName, oidcToken, stampWith = this.config.defaultStamperType, } = params;
2015
2088
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2016
2089
  return utils.withTurnkeyErrorHandling(async () => {
2017
2090
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -2087,7 +2160,7 @@ class TurnkeyClient {
2087
2160
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the OAuth provider.
2088
2161
  */
2089
2162
  this.removeOauthProviders = async (params) => {
2090
- const { providerIds, stampWith, organizationId } = params;
2163
+ const { providerIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2091
2164
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2092
2165
  const userId = params?.userId || session?.userId;
2093
2166
  if (!userId) {
@@ -2126,7 +2199,7 @@ class TurnkeyClient {
2126
2199
  * @throws {TurnkeyError} If there is no active session, if passkey creation fails, or if there is an error adding the passkey.
2127
2200
  */
2128
2201
  this.addPasskey = async (params) => {
2129
- const { stampWith, organizationId } = params || {};
2202
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
2130
2203
  const name = params?.name || `Turnkey Passkey-${Date.now()}`;
2131
2204
  return utils.withTurnkeyErrorHandling(async () => {
2132
2205
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
@@ -2174,7 +2247,7 @@ class TurnkeyClient {
2174
2247
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the passkeys.
2175
2248
  */
2176
2249
  this.removePasskeys = async (params) => {
2177
- const { authenticatorIds, stampWith, organizationId } = params;
2250
+ const { authenticatorIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2178
2251
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2179
2252
  const userId = params?.userId || session?.userId;
2180
2253
  if (!userId) {
@@ -2215,7 +2288,7 @@ class TurnkeyClient {
2215
2288
  * @throws {TurnkeyError} If there is no active session or if there is an error creating the wallet.
2216
2289
  */
2217
2290
  this.createWallet = async (params) => {
2218
- const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith, } = params;
2291
+ const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith = this.config.defaultStamperType, } = params;
2219
2292
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2220
2293
  const organizationId = organizationIdFromParams || session?.organizationId;
2221
2294
  if (!organizationId) {
@@ -2267,7 +2340,7 @@ class TurnkeyClient {
2267
2340
  * @throws {TurnkeyError} If there is no active session, if the wallet does not exist, or if there is an error creating the wallet accounts.
2268
2341
  */
2269
2342
  this.createWalletAccounts = async (params) => {
2270
- const { accounts, walletId, organizationId: organizationIdFromParams, stampWith, } = params;
2343
+ const { accounts, walletId, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2271
2344
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2272
2345
  const organizationId = organizationIdFromParams || session?.organizationId;
2273
2346
  if (!organizationId) {
@@ -2322,7 +2395,7 @@ class TurnkeyClient {
2322
2395
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the wallet.
2323
2396
  */
2324
2397
  this.exportWallet = async (params) => {
2325
- const { walletId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2398
+ const { walletId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2326
2399
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2327
2400
  const organizationId = organizationIdFromParams || session?.organizationId;
2328
2401
  if (!organizationId) {
@@ -2360,7 +2433,7 @@ class TurnkeyClient {
2360
2433
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the private key.
2361
2434
  */
2362
2435
  this.exportPrivateKey = async (params) => {
2363
- const { privateKeyId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2436
+ const { privateKeyId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2364
2437
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2365
2438
  const organizationId = organizationIdFromParams || session?.organizationId;
2366
2439
  if (!organizationId) {
@@ -2399,7 +2472,7 @@ class TurnkeyClient {
2399
2472
  *
2400
2473
  */
2401
2474
  this.exportWalletAccount = async (params) => {
2402
- const { address, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2475
+ const { address, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2403
2476
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2404
2477
  const organizationId = organizationIdFromParams || session?.organizationId;
2405
2478
  if (!organizationId) {
@@ -2440,7 +2513,7 @@ class TurnkeyClient {
2440
2513
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2441
2514
  */
2442
2515
  this.importWallet = async (params) => {
2443
- const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2516
+ const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2444
2517
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2445
2518
  const organizationId = organizationIdFromParams || session?.organizationId;
2446
2519
  if (!organizationId) {
@@ -2498,7 +2571,7 @@ class TurnkeyClient {
2498
2571
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2499
2572
  */
2500
2573
  this.importPrivateKey = async (params) => {
2501
- const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2574
+ const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2502
2575
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2503
2576
  const organizationId = organizationIdFromParams || session?.organizationId;
2504
2577
  if (!organizationId) {
@@ -2548,7 +2621,7 @@ class TurnkeyClient {
2548
2621
  * @throws {TurnkeyError} If there is no active session or if there is an error deleting the sub-organization.
2549
2622
  */
2550
2623
  this.deleteSubOrganization = async (params) => {
2551
- const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith, } = params || {};
2624
+ const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
2552
2625
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2553
2626
  const organizationId = organizationIdFromParams || session?.organizationId;
2554
2627
  return utils.withTurnkeyErrorHandling(async () => {
@@ -2656,7 +2729,7 @@ class TurnkeyClient {
2656
2729
  * @throws {TurnkeyError} If the session key does not exist, if there is no active session, or if there is an error refreshing the session.
2657
2730
  */
2658
2731
  this.refreshSession = async (params) => {
2659
- const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, invalidateExisitng = false, } = params || {};
2732
+ const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, stampWith = this.config.defaultStamperType, invalidateExisitng = false, } = params || {};
2660
2733
  if (!sessionKey) {
2661
2734
  throw new sdkTypes.TurnkeyError("No session key provided or active session to refresh session", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
2662
2735
  }
@@ -2679,7 +2752,7 @@ class TurnkeyClient {
2679
2752
  publicKey: keyPair,
2680
2753
  expirationSeconds,
2681
2754
  invalidateExisting: invalidateExisitng,
2682
- }, params?.stampWith);
2755
+ }, stampWith);
2683
2756
  if (!res || !res.session) {
2684
2757
  throw new sdkTypes.TurnkeyError("No session found in the refresh response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
2685
2758
  }
@@ -2892,7 +2965,7 @@ class TurnkeyClient {
2892
2965
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, or if boot proof retrieval fails.
2893
2966
  */
2894
2967
  this.fetchBootProofForAppProof = async (params) => {
2895
- const { appProof, stampWith, organizationId: organizationIdFromParams, } = params;
2968
+ const { appProof, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2896
2969
  return utils.withTurnkeyErrorHandling(async () => {
2897
2970
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2898
2971
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -2939,19 +3012,9 @@ class TurnkeyClient {
2939
3012
  this.config.walletConfig?.features?.connecting) {
2940
3013
  this.walletManager = await base$3.createWalletManager(this.config.walletConfig);
2941
3014
  }
2942
- // We can comfortably default to the prod urls here
2943
- const apiBaseUrl = this.config.apiBaseUrl || "https://api.turnkey.com";
2944
- const authProxyUrl = this.config.authProxyUrl || "https://authproxy.turnkey.com";
2945
3015
  // Initialize the HTTP client with the appropriate stampers
2946
- this.httpClient = new sdkClientBase.TurnkeySDKClientBase({
2947
- ...this.config,
2948
- apiBaseUrl,
2949
- authProxyUrl,
2950
- apiKeyStamper: this.apiKeyStamper,
2951
- passkeyStamper: this.passkeyStamper,
2952
- walletStamper: this.walletManager?.stamper,
2953
- storageManager: this.storageManager,
2954
- });
3016
+ // Note: not passing anything here since we want to use the configured stampers and this.config
3017
+ this.httpClient = this.createHttpClient();
2955
3018
  }
2956
3019
  }
2957
3020