@turnkey/core 2.2.0 → 2.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 (33) hide show
  1. package/dist/__clients__/core.d.ts +7 -6
  2. package/dist/__clients__/core.d.ts.map +1 -1
  3. package/dist/__clients__/core.js +46 -64
  4. package/dist/__clients__/core.js.map +1 -1
  5. package/dist/__clients__/core.mjs +46 -64
  6. package/dist/__clients__/core.mjs.map +1 -1
  7. package/dist/__generated__/sdk-client-base.d.ts +62 -9
  8. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  9. package/dist/__generated__/sdk-client-base.js +947 -84
  10. package/dist/__generated__/sdk-client-base.js.map +1 -1
  11. package/dist/__generated__/sdk-client-base.mjs +947 -84
  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/__tests__/sol-send-transaction-helper-test.d.ts +2 -0
  17. package/dist/__tests__/sol-send-transaction-helper-test.d.ts.map +1 -0
  18. package/dist/__tests__/sol-send-transaction-test.d.ts +2 -0
  19. package/dist/__tests__/sol-send-transaction-test.d.ts.map +1 -0
  20. package/dist/__types__/method-types/shared.d.ts +11 -22
  21. package/dist/__types__/method-types/shared.d.ts.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +1 -1
  27. package/dist/utils.d.ts +3 -1
  28. package/dist/utils.d.ts.map +1 -1
  29. package/dist/utils.js +26 -0
  30. package/dist/utils.js.map +1 -1
  31. package/dist/utils.mjs +26 -1
  32. package/dist/utils.mjs.map +1 -1
  33. package/package.json +8 -8
@@ -312,13 +312,14 @@ class TurnkeyClient {
312
312
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
313
313
  * @param params.createSubOrgParams - parameters for creating a sub-organization (e.g., authenticators, user metadata).
314
314
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
315
+ * @param params.captchaToken - optional captcha token for bot prevention (must be enabled in the auth proxy config to take effect).
315
316
  * @returns A promise that resolves to a {@link PasskeyAuthResult}, which includes:
316
317
  * - `sessionToken`: the signed JWT session token.
317
318
  * - `credentialId`: the credential ID associated with the passkey created.
318
319
  * @throws {TurnkeyError} If there is an error during passkey creation, sub-organization creation, or session storage.
319
320
  */
320
321
  this.signUpWithPasskey = async (params) => {
321
- const { passkeyDisplayName, challenge, expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, createSubOrgParams, sessionKey = SessionKey.DefaultSessionkey, } = params || {};
322
+ const { passkeyDisplayName, challenge, expirationSeconds = DEFAULT_SESSION_EXPIRATION_IN_SECONDS, createSubOrgParams, sessionKey = SessionKey.DefaultSessionkey, captchaToken, } = params || {};
322
323
  const generatedPublicKey = await this.createApiKeyPair();
323
324
  return withTurnkeyErrorHandling(async () => {
324
325
  if (!this.passkeyStamper) {
@@ -355,7 +356,7 @@ class TurnkeyClient {
355
356
  ],
356
357
  },
357
358
  });
358
- const res = await this.httpClient.proxySignupV2(signUpBody);
359
+ const res = await this.httpClient.proxySignupV2(signUpBody, captchaToken);
359
360
  if (!res) {
360
361
  throw new TurnkeyError(`Sign up failed`, TurnkeyErrorCodes.PASSKEY_SIGNUP_AUTH_ERROR);
361
362
  }
@@ -703,6 +704,7 @@ class TurnkeyClient {
703
704
  * @param params.sessionKey - session key to use for storing the session (defaults to the default session key).
704
705
  * @param params.expirationSeconds - session expiration time in seconds (defaults to the configured default).
705
706
  * @param params.organizationId - organization ID to target (defaults to the session's organization ID or the parent organization ID).
707
+ * @param params.captchaToken - optional captcha token for bot prevention during OTP initialization (must be enabled in the auth proxy config to take effect).
706
708
  * @returns A promise that resolves to an object containing:
707
709
  * - `sessionToken`: the signed JWT session token.
708
710
  * - `address`: the authenticated wallet address.
@@ -710,7 +712,7 @@ class TurnkeyClient {
710
712
  * @throws {TurnkeyError} If there is an error during wallet authentication, sub-organization creation, or session storage.
711
713
  */
712
714
  this.loginOrSignupWithWallet = async (params) => {
713
- const { walletProvider, createSubOrgParams, sessionKey = SessionKey.DefaultSessionkey, } = params;
715
+ const { walletProvider, createSubOrgParams, sessionKey = SessionKey.DefaultSessionkey, captchaToken, } = params;
714
716
  return withTurnkeyErrorHandling(async () => {
715
717
  const { signedRequest, publicKey } = await this.buildWalletLoginRequest(params);
716
718
  // here we check if the subOrg exists and create one
@@ -738,7 +740,7 @@ class TurnkeyClient {
738
740
  ],
739
741
  },
740
742
  });
741
- signupRes = await this.httpClient.proxySignupV2(signUpBody);
743
+ signupRes = await this.httpClient.proxySignupV2(signUpBody, captchaToken);
742
744
  if (!signupRes) {
743
745
  throw new TurnkeyError(`Sign up failed`, TurnkeyErrorCodes.WALLET_SIGNUP_AUTH_ERROR);
744
746
  }
@@ -776,6 +778,7 @@ class TurnkeyClient {
776
778
  * @param params.otpType - type of OTP to initialize (OtpType.Email or OtpType.Sms).
777
779
  * @param params.contact - contact information for the user (e.g., email address or phone number).
778
780
  * @param params.organizationId - optional organization ID to target (defaults to the session's organization ID or the parent organization ID).
781
+ * @param params.captchaToken - optional captcha token for bot prevention during OTP initialization (must be enabled in the auth proxy config to take effect).
779
782
  * @returns A promise that resolves to an {@link InitOtpResult}, which includes:
780
783
  * - `otpId`: the ID of the initiated OTP.
781
784
  * - `otpEncryptionTargetBundle`: the signed encryption target bundle for encrypting the OTP code.
@@ -783,7 +786,11 @@ class TurnkeyClient {
783
786
  */
784
787
  this.initOtp = async (params) => {
785
788
  return withTurnkeyErrorHandling(async () => {
786
- const initOtpRes = await this.httpClient.proxyInitOtpV2(params);
789
+ const { otpType, contact, captchaToken } = params;
790
+ const initOtpRes = await this.httpClient.proxyInitOtpV2({
791
+ otpType,
792
+ contact,
793
+ }, captchaToken);
787
794
  if (!initOtpRes ||
788
795
  !initOtpRes.otpId ||
789
796
  !initOtpRes.otpEncryptionTargetBundle) {
@@ -939,12 +946,13 @@ class TurnkeyClient {
939
946
  * @param params.createSubOrgParams - parameters for creating a sub-organization (e.g., authenticators, user metadata).
940
947
  * @param params.invalidateExisting - flag to invalidate existing session for the user.
941
948
  * @param params.sessionKey - session key to use for session creation (defaults to the default session key).
949
+ * @param params.captchaToken - optional captcha token for bot prevention during OTP initialization (must be enabled in the auth proxy config to take effect).
942
950
  * @returns A promise that resolves to a {@link BaseAuthResult}, which includes:
943
951
  * - `sessionToken`: the signed JWT session token.
944
952
  * @throws {TurnkeyError} If there is an error during the OTP sign-up process or session storage.
945
953
  */
946
954
  this.signUpWithOtp = async (params) => {
947
- const { verificationToken, contact, otpType, createSubOrgParams, invalidateExisting, sessionKey, } = params;
955
+ const { verificationToken, contact, otpType, createSubOrgParams, invalidateExisting, sessionKey, captchaToken, } = params;
948
956
  // build sign up body without client signature first
949
957
  const signUpBody = buildSignUpBody({
950
958
  createSubOrgParams: {
@@ -984,7 +992,7 @@ class TurnkeyClient {
984
992
  const signupRes = await this.httpClient.proxySignupV2({
985
993
  ...signUpBody,
986
994
  clientSignature,
987
- });
995
+ }, captchaToken);
988
996
  if (!signupRes) {
989
997
  throw new TurnkeyError(`Auth proxy OTP sign up failed`, TurnkeyErrorCodes.OTP_SIGNUP_ERROR);
990
998
  }
@@ -1021,6 +1029,7 @@ class TurnkeyClient {
1021
1029
  * @param params.invalidateExisting - flag to invalidate existing sessions for the user.
1022
1030
  * @param params.sessionKey - session key to use for session creation (defaults to the default session key).
1023
1031
  * @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
1032
+ * @param params.captchaToken - optional captcha token for bot prevention during OTP initialization (must be enabled in the auth proxy config to take effect).
1024
1033
  * @returns A promise that resolves to an object containing:
1025
1034
  * - `sessionToken`: the signed JWT session token.
1026
1035
  * - `verificationToken`: the OTP verification token.
@@ -1028,7 +1037,7 @@ class TurnkeyClient {
1028
1037
  * @throws {TurnkeyError} If there is an error during OTP verification, sign-up, or login.
1029
1038
  */
1030
1039
  this.completeOtp = async (params) => {
1031
- const { otpId, otpCode, otpEncryptionTargetBundle, contact, otpType, invalidateExisting = false, sessionKey, createSubOrgParams, } = params;
1040
+ const { otpId, otpCode, otpEncryptionTargetBundle, contact, otpType, invalidateExisting = false, sessionKey, createSubOrgParams, captchaToken, } = params;
1032
1041
  const publicKey = params.publicKey ?? (await this.createApiKeyPair());
1033
1042
  if (!publicKey) {
1034
1043
  throw new TurnkeyError("No public key available. Either pass a publicKey or ensure apiKeyStamper is configured.", TurnkeyErrorCodes.INVALID_REQUEST);
@@ -1060,6 +1069,7 @@ class TurnkeyClient {
1060
1069
  ...(createSubOrgParams && { createSubOrgParams }),
1061
1070
  ...(invalidateExisting && { invalidateExisting }),
1062
1071
  ...(sessionKey && { sessionKey }),
1072
+ ...(captchaToken && { captchaToken }),
1063
1073
  });
1064
1074
  return {
1065
1075
  ...signUpRes,
@@ -1109,6 +1119,7 @@ class TurnkeyClient {
1109
1119
  * @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
1110
1120
  * @param params.invalidateExisting - flag to invalidate existing sessions for the user.
1111
1121
  * @param params.sessionKey - session key to use for session creation (defaults to the default session key).
1122
+ * @param params.captchaToken - optional captcha token for bot prevention during OAuth completion (must be enabled in the auth proxy config to take effect).
1112
1123
  *
1113
1124
  * @returns A promise that resolves to an object containing:
1114
1125
  * - `sessionToken`: the signed JWT session token.
@@ -1116,7 +1127,7 @@ class TurnkeyClient {
1116
1127
  * @throws {TurnkeyError} If there is an error during the OAuth completion process, such as account lookup, sign-up, or login.
1117
1128
  */
1118
1129
  this.completeOauth = async (params) => {
1119
- const { oidcToken, publicKey, providerName, createSubOrgParams, invalidateExisting, sessionKey, } = params;
1130
+ const { oidcToken, publicKey, providerName, createSubOrgParams, invalidateExisting, sessionKey, captchaToken, } = params;
1120
1131
  return withTurnkeyErrorHandling(async () => {
1121
1132
  const accountRes = await this.httpClient.proxyGetAccount({
1122
1133
  filterType: "OIDC_TOKEN",
@@ -1150,6 +1161,7 @@ class TurnkeyClient {
1150
1161
  }),
1151
1162
  ...(invalidateExisting && { invalidateExisting }),
1152
1163
  ...(sessionKey && { sessionKey }),
1164
+ ...(captchaToken && { captchaToken }),
1153
1165
  });
1154
1166
  return {
1155
1167
  ...signUpRes,
@@ -1238,12 +1250,13 @@ class TurnkeyClient {
1238
1250
  * @param params.providerName - name of the OAuth provider (e.g., "Google", "Apple").
1239
1251
  * @param params.createSubOrgParams - parameters for sub-organization creation (e.g., authenticators, user metadata).
1240
1252
  * @param params.sessionKey - session key to use for session creation (defaults to the default session key).
1253
+ * @param params.captchaToken - optional captcha token for bot prevention during OTP initialization (must be enabled in the auth proxy config to take effect).
1241
1254
  * @returns A promise that resolves to a {@link BaseAuthResult}, which includes:
1242
1255
  * - `sessionToken`: the signed JWT session token.
1243
1256
  * @throws {TurnkeyError} If there is an error during the OAuth sign-up or login process.
1244
1257
  */
1245
1258
  this.signUpWithOauth = async (params) => {
1246
- const { oidcToken, publicKey, providerName = "OpenID Connect Provider" + " " + Date.now(), createSubOrgParams, sessionKey, } = params;
1259
+ const { oidcToken, publicKey, providerName = "OpenID Connect Provider" + " " + Date.now(), createSubOrgParams, sessionKey, captchaToken, } = params;
1247
1260
  return withTurnkeyErrorHandling(async () => {
1248
1261
  const signUpBody = buildSignUpBody({
1249
1262
  createSubOrgParams: {
@@ -1257,7 +1270,7 @@ class TurnkeyClient {
1257
1270
  ],
1258
1271
  },
1259
1272
  });
1260
- const signupRes = await this.httpClient.proxySignupV2(signUpBody);
1273
+ const signupRes = await this.httpClient.proxySignupV2(signUpBody, captchaToken);
1261
1274
  if (!signupRes) {
1262
1275
  throw new TurnkeyError(`Auth proxy OAuth signup failed`, TurnkeyErrorCodes.OAUTH_SIGNUP_ERROR);
1263
1276
  }
@@ -1861,9 +1874,6 @@ class TurnkeyClient {
1861
1874
  });
1862
1875
  };
1863
1876
  /**
1864
- * @beta
1865
- * * **API subject to change**
1866
- *
1867
1877
  * Signs and submits an Ethereum transaction using a Turnkey-managed (embedded) wallet.
1868
1878
  *
1869
1879
  * This method performs **authorization and signing**, and submits the transaction
@@ -1896,44 +1906,23 @@ class TurnkeyClient {
1896
1906
  */
1897
1907
  this.ethSendTransaction = async (params) => {
1898
1908
  const { organizationId: organizationIdFromParams, stampWith = this.config.defaultStamperType, transaction, } = params;
1899
- const { from, to, caip2, value, data, nonce, gasLimit, maxFeePerGas, maxPriorityFeePerGas, sponsor, gasStationNonce, } = transaction;
1900
1909
  const session = await getActiveSessionOrThrowIfRequired(stampWith, this.storageManager.getActiveSession);
1901
1910
  const organizationId = organizationIdFromParams || session?.organizationId;
1902
1911
  if (!organizationId) {
1903
1912
  throw new TurnkeyError("Organization ID must be provided to send a transaction", TurnkeyErrorCodes.INVALID_REQUEST);
1904
1913
  }
1905
1914
  return withTurnkeyErrorHandling(async () => {
1906
- //
1907
- // Build Turnkey intent
1908
- //
1909
- const intent = {
1910
- from,
1911
- to,
1912
- caip2,
1913
- ...(value ? { value } : {}),
1914
- ...(data ? { data } : {}),
1915
- ...(nonce !== undefined ? { nonce } : {}),
1916
- };
1917
- if (sponsor) {
1918
- intent.sponsor = true;
1919
- if (gasStationNonce !== undefined)
1920
- intent.gasStationNonce = gasStationNonce;
1921
- }
1922
- else {
1923
- if (gasLimit)
1924
- intent.gasLimit = gasLimit;
1925
- if (maxFeePerGas)
1926
- intent.maxFeePerGas = maxFeePerGas;
1927
- if (maxPriorityFeePerGas)
1928
- intent.maxPriorityFeePerGas = maxPriorityFeePerGas;
1929
- }
1930
- //
1931
- // Submit to Turnkey
1932
- //
1933
- const resp = await this.httpClient.ethSendTransaction({
1934
- ...intent,
1935
- organizationId,
1936
- });
1915
+ // Conditionally call v2 activity if calls array exists.
1916
+ // TODO (breaking change): eventually, we wont generate the v1 activity at all, remove this check and update the intent.
1917
+ const resp = "calls" in transaction
1918
+ ? await this.httpClient.ethSendTransactionV2({
1919
+ ...transaction,
1920
+ organizationId,
1921
+ })
1922
+ : await this.httpClient.ethSendTransaction({
1923
+ ...transaction,
1924
+ organizationId,
1925
+ });
1937
1926
  const id = resp.sendTransactionStatusId;
1938
1927
  if (!id) {
1939
1928
  throw new TurnkeyError("Missing sendTransactionStatusId", TurnkeyErrorCodes.ETH_SEND_TRANSACTION_ERROR);
@@ -1945,9 +1934,6 @@ class TurnkeyClient {
1945
1934
  });
1946
1935
  };
1947
1936
  /**
1948
- * @beta
1949
- * * **API subject to change**
1950
- *
1951
1937
  * Signs and submits a Solana transaction using a Turnkey-managed (embedded) wallet.
1952
1938
  *
1953
1939
  * This method performs **authorization and signing**, and submits the transaction
@@ -1982,21 +1968,17 @@ class TurnkeyClient {
1982
1968
  throw new TurnkeyError("Organization ID must be provided to send a transaction", TurnkeyErrorCodes.INVALID_REQUEST);
1983
1969
  }
1984
1970
  return withTurnkeyErrorHandling(async () => {
1985
- const intent = {
1986
- unsignedTransaction: transaction.unsignedTransaction,
1987
- signWith: transaction.signWith,
1988
- caip2: transaction.caip2,
1989
- ...(transaction.sponsor !== undefined
1990
- ? { sponsor: transaction.sponsor }
1991
- : {}),
1992
- ...(transaction.recentBlockhash
1993
- ? { recentBlockhash: transaction.recentBlockhash }
1994
- : {}),
1995
- };
1996
- const resp = await this.httpClient.solSendTransaction({
1997
- ...intent,
1998
- organizationId,
1999
- }, stampWith);
1971
+ // Conditionally call the v2 activity if the signWiths array exists.
1972
+ // TODO (breaking change): eventually, we wont generate the v1 activity at all, remove this check and update the intent.
1973
+ const resp = "signWiths" in transaction
1974
+ ? await this.httpClient.solSendTransactionV2({
1975
+ ...transaction,
1976
+ organizationId,
1977
+ }, stampWith)
1978
+ : await this.httpClient.solSendTransaction({
1979
+ ...transaction,
1980
+ organizationId,
1981
+ }, stampWith);
2000
1982
  const id = resp.sendTransactionStatusId;
2001
1983
  if (!id) {
2002
1984
  throw new TurnkeyError("Missing sendTransactionStatusId", TurnkeyErrorCodes.SOL_SEND_TRANSACTION_ERROR);