@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
@@ -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
  *
@@ -379,6 +414,105 @@ class TurnkeyClient {
379
414
  errorCode: sdkTypes.TurnkeyErrorCodes.SWITCH_WALLET_CHAIN_ERROR,
380
415
  });
381
416
  };
417
+ /**
418
+ * Builds and signs a wallet login request without submitting it to Turnkey.
419
+ *
420
+ * - This function prepares a signed request for wallet authentication, which can later be used
421
+ * to log in or sign up a user with Turnkey.
422
+ * - It initializes the wallet stamper, ensures a valid session public key (generating one if needed),
423
+ * and signs the login intent with the connected wallet.
424
+ * - For Ethereum wallets, derives the public key from the stamped request header.
425
+ * - For Solana wallets, retrieves the public key directly from the connected wallet.
426
+ * - The signed request is not sent to Turnkey immediately; it is meant to be used in a subsequent flow
427
+ * (e.g., `loginOrSignupWithWallet`) where sub-organization existence is verified or created first.
428
+ *
429
+ * @param params.walletProvider - the wallet provider used for authentication and signing.
430
+ * @param params.publicKey - optional pre-generated session public key (auto-generated if not provided).
431
+ * @param params.expirationSeconds - optional session expiration time in seconds (defaults to the configured default).
432
+ * @returns A promise resolving to an object containing:
433
+ * - `signedRequest`: the signed wallet login request.
434
+ * - `publicKey`: the public key associated with the signed request.
435
+ * @throws {TurnkeyError} If the wallet stamper is not initialized, the signing process fails,
436
+ * or the public key cannot be derived or generated.
437
+ */
438
+ this.buildWalletLoginRequest = async (params) => {
439
+ const { walletProvider, publicKey: providedPublicKey } = params;
440
+ const expirationSeconds = params.expirationSeconds || auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
441
+ let generatedPublicKey = undefined;
442
+ return utils.withTurnkeyErrorHandling(async () => {
443
+ if (!this.walletManager?.stamper) {
444
+ throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
445
+ }
446
+ const futureSessionPublicKey = providedPublicKey ??
447
+ (generatedPublicKey = await this.apiKeyStamper?.createKeyPair());
448
+ if (!futureSessionPublicKey) {
449
+ 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);
450
+ }
451
+ this.walletManager.stamper.setProvider(walletProvider.interfaceType, walletProvider);
452
+ // here we sign the request with the wallet, but we don't send it to Turnkey yet
453
+ // this is because we need to check if the subOrg exists first, and create one if it doesn't
454
+ // once we have the subOrg for the publicKey, we then can send the request to Turnkey
455
+ const signedRequest = await utils.withTurnkeyErrorHandling(async () => {
456
+ return this.httpClient.stampStampLogin({
457
+ publicKey: futureSessionPublicKey,
458
+ organizationId: this.config.organizationId,
459
+ expirationSeconds,
460
+ }, enums.StamperType.Wallet);
461
+ }, {
462
+ errorMessage: "Failed to create stamped request for wallet login",
463
+ errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
464
+ customErrorsByMessages: {
465
+ "WalletConnect: The connection request has expired. Please scan the QR code again.": {
466
+ message: "Your WalletConnect session expired. Please scan the QR code again.",
467
+ code: sdkTypes.TurnkeyErrorCodes.WALLET_CONNECT_EXPIRED,
468
+ },
469
+ "Failed to sign the message": {
470
+ message: "Wallet auth was cancelled by the user.",
471
+ code: sdkTypes.TurnkeyErrorCodes.CONNECT_WALLET_CANCELLED,
472
+ },
473
+ },
474
+ });
475
+ if (!signedRequest) {
476
+ throw new sdkTypes.TurnkeyError("Failed to create stamped request for wallet login", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
477
+ }
478
+ let publicKey;
479
+ switch (walletProvider.chainInfo.namespace) {
480
+ case enums.Chain.Ethereum: {
481
+ // for Ethereum, there is no way to get the public key from the wallet address
482
+ // so we derive it from the signed request
483
+ publicKey = utils.getPublicKeyFromStampHeader(signedRequest.stamp.stampHeaderValue);
484
+ break;
485
+ }
486
+ case enums.Chain.Solana: {
487
+ // for Solana, we can get the public key from the wallet address
488
+ // since the wallet address is the public key
489
+ // this doesn't require any action from the user as long as the wallet is connected
490
+ // which it has to be since they just called stampStampLogin()
491
+ publicKey = await this.walletManager.stamper.getPublicKey(walletProvider.interfaceType, walletProvider);
492
+ break;
493
+ }
494
+ default:
495
+ throw new sdkTypes.TurnkeyError(`Unsupported interface type: ${walletProvider.interfaceType}`, sdkTypes.TurnkeyErrorCodes.INVALID_REQUEST);
496
+ }
497
+ return {
498
+ signedRequest,
499
+ publicKey: publicKey,
500
+ };
501
+ }, {
502
+ errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_BUILD_LOGIN_REQUEST_ERROR,
503
+ errorMessage: "Failed to build wallet login request",
504
+ catchFn: async () => {
505
+ if (generatedPublicKey) {
506
+ try {
507
+ await this.apiKeyStamper?.deleteKeyPair(generatedPublicKey);
508
+ }
509
+ catch (cleanupError) {
510
+ throw new sdkTypes.TurnkeyError(`Failed to clean up generated key pair`, sdkTypes.TurnkeyErrorCodes.KEY_PAIR_CLEANUP_ERROR, cleanupError);
511
+ }
512
+ }
513
+ },
514
+ });
515
+ };
382
516
  /**
383
517
  * Logs in a user using the specified wallet provider.
384
518
  *
@@ -399,7 +533,7 @@ class TurnkeyClient {
399
533
  * @throws {TurnkeyError} If the wallet stamper is uninitialized, a public key cannot be found or generated, or login fails.
400
534
  */
401
535
  this.loginWithWallet = async (params) => {
402
- let publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
536
+ const publicKey = params.publicKey || (await this.apiKeyStamper?.createKeyPair());
403
537
  return utils.withTurnkeyErrorHandling(async () => {
404
538
  if (!this.walletManager?.stamper) {
405
539
  throw new sdkTypes.TurnkeyError("Wallet stamper is not initialized", sdkTypes.TurnkeyErrorCodes.WALLET_MANAGER_COMPONENT_NOT_INITIALIZED);
@@ -546,6 +680,7 @@ class TurnkeyClient {
546
680
  * - Stores the resulting session token under the specified session key, or the default session key if not provided.
547
681
  *
548
682
  * @param params.walletProvider - wallet provider to use for authentication.
683
+ * @param params.publicKey - optional public key to associate with the session (generated if not provided).
549
684
  * @param params.createSubOrgParams - optional parameters for creating a sub-organization (e.g., authenticators, user metadata).
550
685
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
551
686
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
@@ -560,59 +695,8 @@ class TurnkeyClient {
560
695
  const createSubOrgParams = params.createSubOrgParams;
561
696
  const sessionKey = params.sessionKey || enums.SessionKey.DefaultSessionkey;
562
697
  const walletProvider = params.walletProvider;
563
- const expirationSeconds = params.expirationSeconds || auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS;
564
- let generatedPublicKey = undefined;
565
698
  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
- }
699
+ const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
616
700
  // here we check if the subOrg exists and create one
617
701
  // then we send off the stamped request to Turnkey
618
702
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -643,20 +727,7 @@ class TurnkeyClient {
643
727
  }
644
728
  }
645
729
  // 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();
730
+ const sessionResponse = await utils.sendSignedRequest(signedRequest);
660
731
  const sessionToken = sessionResponse.activity.result.stampLoginResult?.session;
661
732
  if (!sessionToken) {
662
733
  throw new sdkTypes.TurnkeyError("Session token not found in the response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
@@ -675,14 +746,6 @@ class TurnkeyClient {
675
746
  errorCode: sdkTypes.TurnkeyErrorCodes.WALLET_LOGIN_OR_SIGNUP_ERROR,
676
747
  errorMessage: "Failed to log in or sign up with wallet",
677
748
  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
749
  },
687
750
  });
688
751
  };
@@ -1125,7 +1188,7 @@ class TurnkeyClient {
1125
1188
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallets.
1126
1189
  */
1127
1190
  this.fetchWallets = async (params) => {
1128
- const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith, } = params || {};
1191
+ const { walletProviders, organizationId: organizationIdFromParams, userId: userIdFromParams, connectedOnly, stampWith = this.config.defaultStamperType, } = params || {};
1129
1192
  const session = await this.storageManager.getActiveSession();
1130
1193
  if (!session && !connectedOnly) {
1131
1194
  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 +1297,7 @@ class TurnkeyClient {
1234
1297
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching wallet accounts.
1235
1298
  */
1236
1299
  this.fetchWalletAccounts = async (params) => {
1237
- const { wallet, stampWith, walletProviders, paginationOptions } = params;
1300
+ const { wallet, stampWith = this.config.defaultStamperType, walletProviders, paginationOptions, } = params;
1238
1301
  const session = await this.storageManager.getActiveSession();
1239
1302
  const organizationId = params?.organizationId || session?.organizationId;
1240
1303
  const userId = params?.userId || session?.userId;
@@ -1363,7 +1426,7 @@ class TurnkeyClient {
1363
1426
  * @throws {TurnkeyError} If no active session is found or if there is an error fetching private keys.
1364
1427
  */
1365
1428
  this.fetchPrivateKeys = async (params) => {
1366
- const { stampWith } = params || {};
1429
+ const { stampWith = this.config.defaultStamperType } = params || {};
1367
1430
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1368
1431
  const organizationId = params?.organizationId || session?.organizationId;
1369
1432
  if (!organizationId) {
@@ -1419,7 +1482,7 @@ class TurnkeyClient {
1419
1482
  * @throws {TurnkeyError} If signing fails, the wallet type does not support message signing, or the response is invalid.
1420
1483
  */
1421
1484
  this.signMessage = async (params) => {
1422
- const { message, walletAccount, stampWith, addEthereumPrefix, organizationId, } = params;
1485
+ const { message, walletAccount, stampWith = this.config.defaultStamperType, addEthereumPrefix, organizationId, } = params;
1423
1486
  const hashFunction = params.hashFunction || utils.getHashFunction(walletAccount.addressFormat);
1424
1487
  const payloadEncoding = params.encoding || utils.getEncodingType(walletAccount.addressFormat);
1425
1488
  return utils.withTurnkeyErrorHandling(async () => {
@@ -1490,7 +1553,7 @@ class TurnkeyClient {
1490
1553
  * @throws {TurnkeyError} If the wallet type is unsupported, signing fails, or the response is invalid.
1491
1554
  */
1492
1555
  this.signTransaction = async (params) => {
1493
- const { walletAccount, unsignedTransaction, transactionType, stampWith, organizationId, } = params;
1556
+ const { walletAccount, unsignedTransaction, transactionType, stampWith = this.config.defaultStamperType, organizationId, } = params;
1494
1557
  return utils.withTurnkeyErrorHandling(async () => {
1495
1558
  if (walletAccount.source === enums.WalletSource.Connected) {
1496
1559
  switch (walletAccount.chainInfo.namespace) {
@@ -1545,7 +1608,7 @@ class TurnkeyClient {
1545
1608
  * @throws {TurnkeyError} If the wallet type is unsupported, or if signing/broadcasting fails.
1546
1609
  */
1547
1610
  this.signAndSendTransaction = async (params) => {
1548
- const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith, organizationId, } = params;
1611
+ const { walletAccount, unsignedTransaction, transactionType, rpcUrl, stampWith = this.config.defaultStamperType, organizationId, } = params;
1549
1612
  return utils.withTurnkeyErrorHandling(async () => {
1550
1613
  if (walletAccount.source === enums.WalletSource.Connected) {
1551
1614
  // this is a connected wallet account
@@ -1610,7 +1673,7 @@ class TurnkeyClient {
1610
1673
  * @throws {TurnkeyError} If there is no active session, if there is no userId, or if there is an error fetching user details.
1611
1674
  */
1612
1675
  this.fetchUser = async (params) => {
1613
- const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params || {};
1676
+ const { organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
1614
1677
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1615
1678
  const userId = userIdFromParams || session?.userId;
1616
1679
  if (!userId) {
@@ -1648,7 +1711,7 @@ class TurnkeyClient {
1648
1711
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, if user retrieval fails, or if user creation fails.
1649
1712
  */
1650
1713
  this.fetchOrCreateP256ApiKeyUser = async (params) => {
1651
- const { publicKey, createParams, stampWith, organizationId: organizationIdFromParams, } = params;
1714
+ const { publicKey, createParams, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
1652
1715
  return utils.withTurnkeyErrorHandling(async () => {
1653
1716
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1654
1717
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -1730,7 +1793,7 @@ class TurnkeyClient {
1730
1793
  * if fetching policies fails, or if creating policies fails.
1731
1794
  */
1732
1795
  this.fetchOrCreatePolicies = async (params) => {
1733
- const { policies, stampWith } = params;
1796
+ const { policies, stampWith = this.config.defaultStamperType } = params;
1734
1797
  return await utils.withTurnkeyErrorHandling(async () => {
1735
1798
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1736
1799
  if (!Array.isArray(policies) || policies.length === 0) {
@@ -1813,7 +1876,7 @@ class TurnkeyClient {
1813
1876
  * @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
1877
  */
1815
1878
  this.updateUserEmail = async (params) => {
1816
- const { verificationToken, email, stampWith, organizationId } = params;
1879
+ const { verificationToken, email, stampWith = this.config.defaultStamperType, organizationId, } = params;
1817
1880
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1818
1881
  const userId = params?.userId || session?.userId;
1819
1882
  if (!userId) {
@@ -1857,7 +1920,7 @@ class TurnkeyClient {
1857
1920
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the user email.
1858
1921
  */
1859
1922
  this.removeUserEmail = async (params) => {
1860
- const { stampWith, organizationId } = params || {};
1923
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1861
1924
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1862
1925
  return utils.withTurnkeyErrorHandling(async () => {
1863
1926
  const userId = params?.userId || session?.userId;
@@ -1896,7 +1959,7 @@ class TurnkeyClient {
1896
1959
  * @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
1960
  */
1898
1961
  this.updateUserPhoneNumber = async (params) => {
1899
- const { verificationToken, phoneNumber, stampWith, organizationId } = params;
1962
+ const { verificationToken, phoneNumber, stampWith = this.config.defaultStamperType, organizationId, } = params;
1900
1963
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1901
1964
  const userId = params?.userId || session?.userId;
1902
1965
  if (!userId) {
@@ -1933,7 +1996,7 @@ class TurnkeyClient {
1933
1996
  * @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
1997
  */
1935
1998
  this.removeUserPhoneNumber = async (params) => {
1936
- const { stampWith, organizationId } = params || {};
1999
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
1937
2000
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1938
2001
  const userId = params?.userId || session?.userId;
1939
2002
  if (!userId) {
@@ -1971,7 +2034,7 @@ class TurnkeyClient {
1971
2034
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error updating the user name.
1972
2035
  */
1973
2036
  this.updateUserName = async (params) => {
1974
- const { userName, stampWith, organizationId } = params;
2037
+ const { userName, stampWith = this.config.defaultStamperType, organizationId, } = params;
1975
2038
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1976
2039
  const userId = params?.userId || session?.userId;
1977
2040
  if (!userId) {
@@ -2011,7 +2074,7 @@ class TurnkeyClient {
2011
2074
  * @throws {TurnkeyError} If there is no active session, if the account already exists, or if there is an error adding the OAuth provider.
2012
2075
  */
2013
2076
  this.addOauthProvider = async (params) => {
2014
- const { providerName, oidcToken, stampWith } = params;
2077
+ const { providerName, oidcToken, stampWith = this.config.defaultStamperType, } = params;
2015
2078
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2016
2079
  return utils.withTurnkeyErrorHandling(async () => {
2017
2080
  const accountRes = await this.httpClient.proxyGetAccount({
@@ -2087,7 +2150,7 @@ class TurnkeyClient {
2087
2150
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the OAuth provider.
2088
2151
  */
2089
2152
  this.removeOauthProviders = async (params) => {
2090
- const { providerIds, stampWith, organizationId } = params;
2153
+ const { providerIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2091
2154
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2092
2155
  const userId = params?.userId || session?.userId;
2093
2156
  if (!userId) {
@@ -2126,7 +2189,7 @@ class TurnkeyClient {
2126
2189
  * @throws {TurnkeyError} If there is no active session, if passkey creation fails, or if there is an error adding the passkey.
2127
2190
  */
2128
2191
  this.addPasskey = async (params) => {
2129
- const { stampWith, organizationId } = params || {};
2192
+ const { stampWith = this.config.defaultStamperType, organizationId } = params || {};
2130
2193
  const name = params?.name || `Turnkey Passkey-${Date.now()}`;
2131
2194
  return utils.withTurnkeyErrorHandling(async () => {
2132
2195
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
@@ -2174,7 +2237,7 @@ class TurnkeyClient {
2174
2237
  * @throws {TurnkeyError} If there is no active session, if the userId is missing, or if there is an error removing the passkeys.
2175
2238
  */
2176
2239
  this.removePasskeys = async (params) => {
2177
- const { authenticatorIds, stampWith, organizationId } = params;
2240
+ const { authenticatorIds, stampWith = this.config.defaultStamperType, organizationId, } = params;
2178
2241
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2179
2242
  const userId = params?.userId || session?.userId;
2180
2243
  if (!userId) {
@@ -2215,7 +2278,7 @@ class TurnkeyClient {
2215
2278
  * @throws {TurnkeyError} If there is no active session or if there is an error creating the wallet.
2216
2279
  */
2217
2280
  this.createWallet = async (params) => {
2218
- const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith, } = params;
2281
+ const { walletName, accounts, organizationId: organizationIdFromParams, mnemonicLength, stampWith = this.config.defaultStamperType, } = params;
2219
2282
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2220
2283
  const organizationId = organizationIdFromParams || session?.organizationId;
2221
2284
  if (!organizationId) {
@@ -2267,7 +2330,7 @@ class TurnkeyClient {
2267
2330
  * @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
2331
  */
2269
2332
  this.createWalletAccounts = async (params) => {
2270
- const { accounts, walletId, organizationId: organizationIdFromParams, stampWith, } = params;
2333
+ const { accounts, walletId, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2271
2334
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2272
2335
  const organizationId = organizationIdFromParams || session?.organizationId;
2273
2336
  if (!organizationId) {
@@ -2322,7 +2385,7 @@ class TurnkeyClient {
2322
2385
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the wallet.
2323
2386
  */
2324
2387
  this.exportWallet = async (params) => {
2325
- const { walletId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2388
+ const { walletId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2326
2389
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2327
2390
  const organizationId = organizationIdFromParams || session?.organizationId;
2328
2391
  if (!organizationId) {
@@ -2360,7 +2423,7 @@ class TurnkeyClient {
2360
2423
  * @throws {TurnkeyError} If there is no active session, if the targetPublicKey is missing, or if there is an error exporting the private key.
2361
2424
  */
2362
2425
  this.exportPrivateKey = async (params) => {
2363
- const { privateKeyId, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2426
+ const { privateKeyId, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2364
2427
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2365
2428
  const organizationId = organizationIdFromParams || session?.organizationId;
2366
2429
  if (!organizationId) {
@@ -2399,7 +2462,7 @@ class TurnkeyClient {
2399
2462
  *
2400
2463
  */
2401
2464
  this.exportWalletAccount = async (params) => {
2402
- const { address, targetPublicKey, stampWith, organizationId: organizationIdFromParams, } = params;
2465
+ const { address, targetPublicKey, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2403
2466
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2404
2467
  const organizationId = organizationIdFromParams || session?.organizationId;
2405
2468
  if (!organizationId) {
@@ -2440,7 +2503,7 @@ class TurnkeyClient {
2440
2503
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2441
2504
  */
2442
2505
  this.importWallet = async (params) => {
2443
- const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2506
+ const { encryptedBundle, accounts, walletName, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2444
2507
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2445
2508
  const organizationId = organizationIdFromParams || session?.organizationId;
2446
2509
  if (!organizationId) {
@@ -2498,7 +2561,7 @@ class TurnkeyClient {
2498
2561
  * @throws {TurnkeyError} If there is no active session, if the encrypted bundle is invalid, or if there is an error importing the wallet.
2499
2562
  */
2500
2563
  this.importPrivateKey = async (params) => {
2501
- const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith, } = params;
2564
+ const { encryptedBundle, privateKeyName, addressFormats, curve, organizationId: organizationIdFromParams, userId: userIdFromParams, stampWith = this.config.defaultStamperType, } = params;
2502
2565
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2503
2566
  const organizationId = organizationIdFromParams || session?.organizationId;
2504
2567
  if (!organizationId) {
@@ -2548,7 +2611,7 @@ class TurnkeyClient {
2548
2611
  * @throws {TurnkeyError} If there is no active session or if there is an error deleting the sub-organization.
2549
2612
  */
2550
2613
  this.deleteSubOrganization = async (params) => {
2551
- const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith, } = params || {};
2614
+ const { deleteWithoutExport = false, organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, } = params || {};
2552
2615
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2553
2616
  const organizationId = organizationIdFromParams || session?.organizationId;
2554
2617
  return utils.withTurnkeyErrorHandling(async () => {
@@ -2656,7 +2719,7 @@ class TurnkeyClient {
2656
2719
  * @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
2720
  */
2658
2721
  this.refreshSession = async (params) => {
2659
- const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, invalidateExisitng = false, } = params || {};
2722
+ const { sessionKey = await this.storageManager.getActiveSessionKey(), expirationSeconds = auth.DEFAULT_SESSION_EXPIRATION_IN_SECONDS, publicKey, stampWith = this.config.defaultStamperType, invalidateExisitng = false, } = params || {};
2660
2723
  if (!sessionKey) {
2661
2724
  throw new sdkTypes.TurnkeyError("No session key provided or active session to refresh session", sdkTypes.TurnkeyErrorCodes.NO_SESSION_FOUND);
2662
2725
  }
@@ -2679,7 +2742,7 @@ class TurnkeyClient {
2679
2742
  publicKey: keyPair,
2680
2743
  expirationSeconds,
2681
2744
  invalidateExisting: invalidateExisitng,
2682
- }, params?.stampWith);
2745
+ }, stampWith);
2683
2746
  if (!res || !res.session) {
2684
2747
  throw new sdkTypes.TurnkeyError("No session found in the refresh response", sdkTypes.TurnkeyErrorCodes.BAD_RESPONSE);
2685
2748
  }
@@ -2892,7 +2955,7 @@ class TurnkeyClient {
2892
2955
  * @throws {TurnkeyError} If there is no active session, if the input is invalid, or if boot proof retrieval fails.
2893
2956
  */
2894
2957
  this.fetchBootProofForAppProof = async (params) => {
2895
- const { appProof, stampWith, organizationId: organizationIdFromParams, } = params;
2958
+ const { appProof, stampWith = this.config.defaultStamperType, organizationId: organizationIdFromParams, } = params;
2896
2959
  return utils.withTurnkeyErrorHandling(async () => {
2897
2960
  const session = await utils.getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
2898
2961
  const organizationId = organizationIdFromParams || session?.organizationId;
@@ -2939,19 +3002,9 @@ class TurnkeyClient {
2939
3002
  this.config.walletConfig?.features?.connecting) {
2940
3003
  this.walletManager = await base$3.createWalletManager(this.config.walletConfig);
2941
3004
  }
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
3005
  // 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
- });
3006
+ // Note: not passing anything here since we want to use the configured stampers and this.config
3007
+ this.httpClient = this.createHttpClient();
2955
3008
  }
2956
3009
  }
2957
3010