@turnkey/core 2.5.0 → 2.7.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 +36 -3
  2. package/dist/__clients__/core.d.ts.map +1 -1
  3. package/dist/__clients__/core.js +123 -40
  4. package/dist/__clients__/core.js.map +1 -1
  5. package/dist/__clients__/core.mjs +116 -33
  6. package/dist/__clients__/core.mjs.map +1 -1
  7. package/dist/__generated__/sdk-client-base.d.ts +21 -0
  8. package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
  9. package/dist/__generated__/sdk-client-base.js +267 -1
  10. package/dist/__generated__/sdk-client-base.js.map +1 -1
  11. package/dist/__generated__/sdk-client-base.mjs +268 -2
  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__/api/base.d.ts +2 -1
  17. package/dist/__stampers__/api/base.d.ts.map +1 -1
  18. package/dist/__stampers__/api/base.js +11 -14
  19. package/dist/__stampers__/api/base.js.map +1 -1
  20. package/dist/__stampers__/api/base.mjs +11 -14
  21. package/dist/__stampers__/api/base.mjs.map +1 -1
  22. package/dist/__stampers__/attested/base.d.ts +22 -0
  23. package/dist/__stampers__/attested/base.d.ts.map +1 -0
  24. package/dist/__stampers__/attested/base.js +50 -0
  25. package/dist/__stampers__/attested/base.js.map +1 -0
  26. package/dist/__stampers__/attested/base.mjs +48 -0
  27. package/dist/__stampers__/attested/base.mjs.map +1 -0
  28. package/dist/__types__/config.d.ts +42 -1
  29. package/dist/__types__/config.d.ts.map +1 -1
  30. package/dist/__types__/enums.d.ts +2 -1
  31. package/dist/__types__/enums.d.ts.map +1 -1
  32. package/dist/__types__/enums.js +1 -0
  33. package/dist/__types__/enums.js.map +1 -1
  34. package/dist/__types__/enums.mjs +1 -0
  35. package/dist/__types__/enums.mjs.map +1 -1
  36. package/dist/__types__/method-types/shared.d.ts +21 -1
  37. package/dist/__types__/method-types/shared.d.ts.map +1 -1
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +3 -1
  40. package/dist/utils.js.map +1 -1
  41. package/dist/utils.mjs +3 -1
  42. package/dist/utils.mjs.map +1 -1
  43. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  import { VERSION } from './version.mjs';
2
- import { TERMINAL_ACTIVITY_STATUSES, TurnkeyRequestError, TurnkeyError, TurnkeyErrorCodes } from '@turnkey/sdk-types';
2
+ import { TERMINAL_ACTIVITY_STATUSES, ActivityStatus, TurnkeyRequestError, TurnkeyError, TurnkeyErrorCodes } from '@turnkey/sdk-types';
3
3
  import { StamperType } from '../__types__/enums.mjs';
4
4
 
5
5
  /* @generated by codegen. DO NOT EDIT BY HAND */
@@ -995,6 +995,36 @@ class TurnkeySDKClientBase {
995
995
  url: fullUrl,
996
996
  };
997
997
  };
998
+ this.getTvcQosVersions = async (input, stampWith) => {
999
+ const session = await this.storageManager?.getActiveSession();
1000
+ return this.request("/public/v1/query/get_tvc_qos_versions", {
1001
+ ...input,
1002
+ organizationId: input.organizationId ??
1003
+ session?.organizationId ??
1004
+ this.config.organizationId,
1005
+ }, stampWith);
1006
+ };
1007
+ this.stampGetTvcQosVersions = async (input, stampWith) => {
1008
+ const activeStamper = this.getStamper(stampWith);
1009
+ if (!activeStamper) {
1010
+ return undefined;
1011
+ }
1012
+ const session = await this.storageManager?.getActiveSession();
1013
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/query/get_tvc_qos_versions";
1014
+ const body = {
1015
+ ...input,
1016
+ organizationId: input.organizationId ??
1017
+ session?.organizationId ??
1018
+ this.config.organizationId,
1019
+ };
1020
+ const stringifiedBody = JSON.stringify(body);
1021
+ const stamp = await activeStamper.stamp(stringifiedBody);
1022
+ return {
1023
+ body: stringifiedBody,
1024
+ stamp: stamp,
1025
+ url: fullUrl,
1026
+ };
1027
+ };
998
1028
  this.getUser = async (input, stampWith) => {
999
1029
  const session = await this.storageManager?.getActiveSession();
1000
1030
  return this.request("/public/v1/query/get_user", {
@@ -1475,6 +1505,36 @@ class TurnkeySDKClientBase {
1475
1505
  url: fullUrl,
1476
1506
  };
1477
1507
  };
1508
+ this.listSecrets = async (input, stampWith) => {
1509
+ const session = await this.storageManager?.getActiveSession();
1510
+ return this.request("/public/v1/query/list_secrets", {
1511
+ ...input,
1512
+ organizationId: input.organizationId ??
1513
+ session?.organizationId ??
1514
+ this.config.organizationId,
1515
+ }, stampWith);
1516
+ };
1517
+ this.stampListSecrets = async (input, stampWith) => {
1518
+ const activeStamper = this.getStamper(stampWith);
1519
+ if (!activeStamper) {
1520
+ return undefined;
1521
+ }
1522
+ const session = await this.storageManager?.getActiveSession();
1523
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/query/list_secrets";
1524
+ const body = {
1525
+ ...input,
1526
+ organizationId: input.organizationId ??
1527
+ session?.organizationId ??
1528
+ this.config.organizationId,
1529
+ };
1530
+ const stringifiedBody = JSON.stringify(body);
1531
+ const stamp = await activeStamper.stamp(stringifiedBody);
1532
+ return {
1533
+ body: stringifiedBody,
1534
+ stamp: stamp,
1535
+ url: fullUrl,
1536
+ };
1537
+ };
1478
1538
  this.getSmartContractInterfaces = async (input, stampWith) => {
1479
1539
  const session = await this.storageManager?.getActiveSession();
1480
1540
  return this.request("/public/v1/query/list_smart_contract_interfaces", {
@@ -2600,6 +2660,43 @@ class TurnkeySDKClientBase {
2600
2660
  url: fullUrl,
2601
2661
  };
2602
2662
  };
2663
+ this.createSwapQuote = async (input, stampWith) => {
2664
+ const { organizationId, timestampMs, ...rest } = input;
2665
+ //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
2666
+ const generateAppProofs = input?.generateAppProofs ?? false;
2667
+ const session = await this.storageManager?.getActiveSession();
2668
+ return this.activity("/public/v1/submit/create_swap_quote", {
2669
+ parameters: rest,
2670
+ organizationId: organizationId ??
2671
+ session?.organizationId ??
2672
+ this.config.organizationId,
2673
+ timestampMs: timestampMs ?? String(Date.now()),
2674
+ generateAppProofs: generateAppProofs ?? false,
2675
+ type: "ACTIVITY_TYPE_CREATE_SWAP_QUOTE",
2676
+ }, "createSwapQuoteResult", stampWith);
2677
+ };
2678
+ this.stampCreateSwapQuote = async (input, stampWith) => {
2679
+ const activeStamper = this.getStamper(stampWith);
2680
+ if (!activeStamper) {
2681
+ return undefined;
2682
+ }
2683
+ const { organizationId, timestampMs, ...parameters } = input;
2684
+ const session = await this.storageManager?.getActiveSession();
2685
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/submit/create_swap_quote";
2686
+ const bodyWithType = {
2687
+ parameters,
2688
+ organizationId: organizationId ?? session?.organizationId ?? this.config.organizationId,
2689
+ timestampMs: timestampMs ?? String(Date.now()),
2690
+ type: "ACTIVITY_TYPE_CREATE_SWAP_QUOTE",
2691
+ };
2692
+ const stringifiedBody = JSON.stringify(bodyWithType);
2693
+ const stamp = await activeStamper.stamp(stringifiedBody);
2694
+ return {
2695
+ body: stringifiedBody,
2696
+ stamp: stamp,
2697
+ url: fullUrl,
2698
+ };
2699
+ };
2603
2700
  this.createTvcApp = async (input, stampWith) => {
2604
2701
  const { organizationId, timestampMs, ...rest } = input;
2605
2702
  //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
@@ -3862,6 +3959,43 @@ class TurnkeySDKClientBase {
3862
3959
  url: fullUrl,
3863
3960
  };
3864
3961
  };
3962
+ this.executeSwap = async (input, stampWith) => {
3963
+ const { organizationId, timestampMs, ...rest } = input;
3964
+ //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
3965
+ const generateAppProofs = input?.generateAppProofs ?? false;
3966
+ const session = await this.storageManager?.getActiveSession();
3967
+ return this.activity("/public/v1/submit/execute_swap", {
3968
+ parameters: rest,
3969
+ organizationId: organizationId ??
3970
+ session?.organizationId ??
3971
+ this.config.organizationId,
3972
+ timestampMs: timestampMs ?? String(Date.now()),
3973
+ generateAppProofs: generateAppProofs ?? false,
3974
+ type: "ACTIVITY_TYPE_EXECUTE_SWAP_V2",
3975
+ }, "executeSwapResult", stampWith);
3976
+ };
3977
+ this.stampExecuteSwap = async (input, stampWith) => {
3978
+ const activeStamper = this.getStamper(stampWith);
3979
+ if (!activeStamper) {
3980
+ return undefined;
3981
+ }
3982
+ const { organizationId, timestampMs, ...parameters } = input;
3983
+ const session = await this.storageManager?.getActiveSession();
3984
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/submit/execute_swap";
3985
+ const bodyWithType = {
3986
+ parameters,
3987
+ organizationId: organizationId ?? session?.organizationId ?? this.config.organizationId,
3988
+ timestampMs: timestampMs ?? String(Date.now()),
3989
+ type: "ACTIVITY_TYPE_EXECUTE_SWAP_V2",
3990
+ };
3991
+ const stringifiedBody = JSON.stringify(bodyWithType);
3992
+ const stamp = await activeStamper.stamp(stringifiedBody);
3993
+ return {
3994
+ body: stringifiedBody,
3995
+ stamp: stamp,
3996
+ url: fullUrl,
3997
+ };
3998
+ };
3865
3999
  this.exportPrivateKey = async (input, stampWith) => {
3866
4000
  const { organizationId, timestampMs, ...rest } = input;
3867
4001
  //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
@@ -3899,6 +4033,43 @@ class TurnkeySDKClientBase {
3899
4033
  url: fullUrl,
3900
4034
  };
3901
4035
  };
4036
+ this.exportSecrets = async (input, stampWith) => {
4037
+ const { organizationId, timestampMs, ...rest } = input;
4038
+ //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
4039
+ const generateAppProofs = input?.generateAppProofs ?? false;
4040
+ const session = await this.storageManager?.getActiveSession();
4041
+ return this.activity("/public/v1/submit/export_secrets", {
4042
+ parameters: rest,
4043
+ organizationId: organizationId ??
4044
+ session?.organizationId ??
4045
+ this.config.organizationId,
4046
+ timestampMs: timestampMs ?? String(Date.now()),
4047
+ generateAppProofs: generateAppProofs ?? false,
4048
+ type: "ACTIVITY_TYPE_EXPORT_SECRETS",
4049
+ }, "exportSecretsResult", stampWith);
4050
+ };
4051
+ this.stampExportSecrets = async (input, stampWith) => {
4052
+ const activeStamper = this.getStamper(stampWith);
4053
+ if (!activeStamper) {
4054
+ return undefined;
4055
+ }
4056
+ const { organizationId, timestampMs, ...parameters } = input;
4057
+ const session = await this.storageManager?.getActiveSession();
4058
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/submit/export_secrets";
4059
+ const bodyWithType = {
4060
+ parameters,
4061
+ organizationId: organizationId ?? session?.organizationId ?? this.config.organizationId,
4062
+ timestampMs: timestampMs ?? String(Date.now()),
4063
+ type: "ACTIVITY_TYPE_EXPORT_SECRETS",
4064
+ };
4065
+ const stringifiedBody = JSON.stringify(bodyWithType);
4066
+ const stamp = await activeStamper.stamp(stringifiedBody);
4067
+ return {
4068
+ body: stringifiedBody,
4069
+ stamp: stamp,
4070
+ url: fullUrl,
4071
+ };
4072
+ };
3902
4073
  this.exportWallet = async (input, stampWith) => {
3903
4074
  const { organizationId, timestampMs, ...rest } = input;
3904
4075
  //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
@@ -4010,6 +4181,43 @@ class TurnkeySDKClientBase {
4010
4181
  url: fullUrl,
4011
4182
  };
4012
4183
  };
4184
+ this.importSecrets = async (input, stampWith) => {
4185
+ const { organizationId, timestampMs, ...rest } = input;
4186
+ //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
4187
+ const generateAppProofs = input?.generateAppProofs ?? false;
4188
+ const session = await this.storageManager?.getActiveSession();
4189
+ return this.activity("/public/v1/submit/import_secrets", {
4190
+ parameters: rest,
4191
+ organizationId: organizationId ??
4192
+ session?.organizationId ??
4193
+ this.config.organizationId,
4194
+ timestampMs: timestampMs ?? String(Date.now()),
4195
+ generateAppProofs: generateAppProofs ?? false,
4196
+ type: "ACTIVITY_TYPE_IMPORT_SECRETS",
4197
+ }, "importSecretsResult", stampWith);
4198
+ };
4199
+ this.stampImportSecrets = async (input, stampWith) => {
4200
+ const activeStamper = this.getStamper(stampWith);
4201
+ if (!activeStamper) {
4202
+ return undefined;
4203
+ }
4204
+ const { organizationId, timestampMs, ...parameters } = input;
4205
+ const session = await this.storageManager?.getActiveSession();
4206
+ const fullUrl = this.config.apiBaseUrl + "/public/v1/submit/import_secrets";
4207
+ const bodyWithType = {
4208
+ parameters,
4209
+ organizationId: organizationId ?? session?.organizationId ?? this.config.organizationId,
4210
+ timestampMs: timestampMs ?? String(Date.now()),
4211
+ type: "ACTIVITY_TYPE_IMPORT_SECRETS",
4212
+ };
4213
+ const stringifiedBody = JSON.stringify(bodyWithType);
4214
+ const stamp = await activeStamper.stamp(stringifiedBody);
4215
+ return {
4216
+ body: stringifiedBody,
4217
+ stamp: stamp,
4218
+ url: fullUrl,
4219
+ };
4220
+ };
4013
4221
  this.importWallet = async (input, stampWith) => {
4014
4222
  const { organizationId, timestampMs, ...rest } = input;
4015
4223
  //@ts-ignore - generateAppProofs does not exist on all request types, so we ignore the type error here for those that are missing it
@@ -5836,6 +6044,9 @@ class TurnkeySDKClientBase {
5836
6044
  if (config.walletStamper) {
5837
6045
  this.walletStamper = config.walletStamper;
5838
6046
  }
6047
+ if (config.attestedStamper) {
6048
+ this.attestedStamper = config.attestedStamper;
6049
+ }
5839
6050
  if (config.storageManager) {
5840
6051
  this.storageManager = config.storageManager;
5841
6052
  }
@@ -5853,6 +6064,9 @@ class TurnkeySDKClientBase {
5853
6064
  else if (this.walletStamper) {
5854
6065
  this.defaultStamperType = StamperType.Wallet;
5855
6066
  }
6067
+ else if (this.attestedStamper) {
6068
+ this.defaultStamperType = StamperType.Attested;
6069
+ }
5856
6070
  else {
5857
6071
  this.defaultStamperType = undefined;
5858
6072
  }
@@ -5870,6 +6084,8 @@ class TurnkeySDKClientBase {
5870
6084
  return this.passkeyStamper;
5871
6085
  case StamperType.Wallet:
5872
6086
  return this.walletStamper;
6087
+ case StamperType.Attested:
6088
+ return this.attestedStamper;
5873
6089
  default:
5874
6090
  return this.apiKeyStamper;
5875
6091
  }
@@ -5900,7 +6116,7 @@ class TurnkeySDKClientBase {
5900
6116
  */
5901
6117
  handleActivityResponse(activityData, resultKey) {
5902
6118
  const { result, status } = activityData.activity;
5903
- if (status === "ACTIVITY_STATUS_COMPLETED" && result) {
6119
+ if (status === ActivityStatus.COMPLETED && result) {
5904
6120
  // If a specific resultKey was provided, use it
5905
6121
  if (resultKey && result[resultKey]) {
5906
6122
  return {
@@ -5920,6 +6136,52 @@ class TurnkeySDKClientBase {
5920
6136
  }
5921
6137
  return activityData;
5922
6138
  }
6139
+ /**
6140
+ * If the activity requires MFA (AUTHENTICATORS_NEEDED) or consensus
6141
+ * (CONSENSUS_NEEDED) and an onMfaRequired callback is configured, fetch the
6142
+ * MFA statuses for the activity, invoke the callback, and then poll for
6143
+ * completion. Returns the (possibly updated) activity data.
6144
+ * @internal
6145
+ */
6146
+ async handleMfaIfNeeded(activityData, stampWith) {
6147
+ const AUTHENTICATORS_NEEDED = ActivityStatus.AUTHENTICATORS_NEEDED;
6148
+ // We need to check for CONSENSUS_NEEDED as well, since that can also involve MFA (user is NOT the proposer but has MFA).
6149
+ const CONSENSUS_NEEDED = ActivityStatus.CONSENSUS_NEEDED;
6150
+ const activityStatus = activityData.activity.status;
6151
+ // Only AUTHENTICATORS_NEEDED and CONSENSUS_NEEDED can involve MFA.
6152
+ // Anything else is returned as-is.
6153
+ if (activityStatus !== AUTHENTICATORS_NEEDED &&
6154
+ activityStatus !== CONSENSUS_NEEDED) {
6155
+ return activityData;
6156
+ }
6157
+ if (!this.config.onMfaRequired) {
6158
+ return activityData;
6159
+ }
6160
+ // Fetch the MFA statuses for this activity.
6161
+ const { mfaStatuses } = await this.getMfaStatus({
6162
+ activityId: activityData.activity.id,
6163
+ organizationId: activityData.activity.organizationId,
6164
+ }, stampWith);
6165
+ // For CONSENSUS_NEEDED there may be no MFA statuses.
6166
+ // In that case, return the activity as-is.
6167
+ if (activityStatus === CONSENSUS_NEEDED &&
6168
+ (!mfaStatuses || mfaStatuses.length === 0)) {
6169
+ return activityData;
6170
+ }
6171
+ const mfaContext = {
6172
+ activityId: activityData.activity.id,
6173
+ fingerprint: activityData.activity.fingerprint,
6174
+ organizationId: activityData.activity.organizationId,
6175
+ activityType: activityData.activity.type,
6176
+ activityStatus,
6177
+ mfaStatuses,
6178
+ };
6179
+ // Await the callback — it should resolve when MFA approval is complete
6180
+ await this.config.onMfaRequired(mfaContext);
6181
+ // After callback resolves, poll for the updated activity status
6182
+ activityData = await this.pollForCompletion(activityData.activity.id, stampWith);
6183
+ return activityData;
6184
+ }
5923
6185
  async request(url, body, stampWith) {
5924
6186
  const fullUrl = this.config.apiBaseUrl + url;
5925
6187
  const stringifiedBody = JSON.stringify(body);
@@ -5959,6 +6221,8 @@ class TurnkeySDKClientBase {
5959
6221
  if (!TERMINAL_ACTIVITY_STATUSES.includes(activityData.activity.status)) {
5960
6222
  activityData = await this.pollForCompletion(activityData.activity.id, stampWith);
5961
6223
  }
6224
+ // Handle MFA if needed (callback gate + re-poll)
6225
+ activityData = await this.handleMfaIfNeeded(activityData, stampWith);
5962
6226
  return this.handleActivityResponse(activityData, resultKey);
5963
6227
  }
5964
6228
  async activityDecision(url, body, stampWith) {
@@ -6044,6 +6308,8 @@ class TurnkeySDKClientBase {
6044
6308
  if (!TERMINAL_ACTIVITY_STATUSES.includes(activityData.activity.status)) {
6045
6309
  activityData = await this.pollForCompletion(activityData.activity.id);
6046
6310
  }
6311
+ // Handle MFA if needed (callback gate + re-poll)
6312
+ activityData = await this.handleMfaIfNeeded(activityData);
6047
6313
  return this.handleActivityResponse(activityData, options?.resultKey);
6048
6314
  }
6049
6315
  return data;