@getpara/core-sdk 3.5.0 → 3.6.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 (73) hide show
  1. package/dist/cjs/ParaCore.js +78 -39
  2. package/dist/cjs/constants.js +1 -1
  3. package/dist/cjs/cryptography/utils.js +2 -2
  4. package/dist/cjs/errors.js +12 -0
  5. package/dist/cjs/external/localDevUrlOverrides.js +50 -0
  6. package/dist/cjs/external/userManagementClient.js +11 -21
  7. package/dist/cjs/index.js +15 -15
  8. package/dist/cjs/services/PortalUrlService.js +1 -1
  9. package/dist/cjs/state/actors/authenticateWithEmailOrPhone.js +1 -1
  10. package/dist/cjs/state/actors/authenticateWithExternalWallet.js +1 -1
  11. package/dist/cjs/state/actors/authenticateWithFarcaster.js +1 -1
  12. package/dist/cjs/state/actors/authenticateWithFarcasterLegacy.js +1 -1
  13. package/dist/cjs/state/actors/authenticateWithTelegram.js +1 -1
  14. package/dist/cjs/state/actors/authenticateWithTelegramLegacy.js +1 -1
  15. package/dist/cjs/state/actors/checkUserState.js +1 -1
  16. package/dist/cjs/state/actors/claimWallets.js +1 -1
  17. package/dist/cjs/state/actors/connectExternalConnectors.js +1 -1
  18. package/dist/cjs/state/actors/connectExternalWallet.js +1 -1
  19. package/dist/cjs/state/actors/createGuestWallets.js +1 -1
  20. package/dist/cjs/state/actors/createWallets.js +1 -1
  21. package/dist/cjs/state/actors/processAuthentication.js +1 -1
  22. package/dist/cjs/state/actors/setupAfterLogin.js +1 -1
  23. package/dist/cjs/state/actors/setupPara.js +1 -1
  24. package/dist/cjs/state/actors/signExternalWalletVerification.js +1 -1
  25. package/dist/cjs/state/actors/switchExternalWallet.js +1 -1
  26. package/dist/cjs/state/actors/verifyExternalWallet.js +1 -1
  27. package/dist/cjs/state/actors/verifyNewAccount.js +1 -1
  28. package/dist/cjs/state/actors/waitForExternalWalletProviders.js +1 -1
  29. package/dist/cjs/state/machines/authStateMachine.js +7 -7
  30. package/dist/cjs/state/machines/coreStateMachine.js +1 -1
  31. package/dist/cjs/state/machines/walletStateMachine.js +1 -1
  32. package/dist/cjs/telemetry/tracer.js +1 -1
  33. package/dist/cjs/utils/url.js +5 -2
  34. package/dist/esm/ParaCore.js +79 -40
  35. package/dist/esm/constants.js +1 -1
  36. package/dist/esm/cryptography/utils.js +2 -2
  37. package/dist/esm/errors.js +11 -0
  38. package/dist/esm/external/localDevUrlOverrides.js +27 -0
  39. package/dist/esm/external/userManagementClient.js +11 -21
  40. package/dist/esm/index.js +2 -2
  41. package/dist/esm/services/PortalUrlService.js +1 -1
  42. package/dist/esm/state/actors/authenticateWithEmailOrPhone.js +1 -1
  43. package/dist/esm/state/actors/authenticateWithExternalWallet.js +1 -1
  44. package/dist/esm/state/actors/authenticateWithFarcaster.js +1 -1
  45. package/dist/esm/state/actors/authenticateWithFarcasterLegacy.js +1 -1
  46. package/dist/esm/state/actors/authenticateWithTelegram.js +1 -1
  47. package/dist/esm/state/actors/authenticateWithTelegramLegacy.js +1 -1
  48. package/dist/esm/state/actors/checkUserState.js +1 -1
  49. package/dist/esm/state/actors/claimWallets.js +1 -1
  50. package/dist/esm/state/actors/connectExternalConnectors.js +1 -1
  51. package/dist/esm/state/actors/connectExternalWallet.js +1 -1
  52. package/dist/esm/state/actors/createGuestWallets.js +1 -1
  53. package/dist/esm/state/actors/createWallets.js +1 -1
  54. package/dist/esm/state/actors/processAuthentication.js +1 -1
  55. package/dist/esm/state/actors/setupAfterLogin.js +1 -1
  56. package/dist/esm/state/actors/setupPara.js +1 -1
  57. package/dist/esm/state/actors/signExternalWalletVerification.js +1 -1
  58. package/dist/esm/state/actors/switchExternalWallet.js +1 -1
  59. package/dist/esm/state/actors/verifyExternalWallet.js +1 -1
  60. package/dist/esm/state/actors/verifyNewAccount.js +1 -1
  61. package/dist/esm/state/actors/waitForExternalWalletProviders.js +1 -1
  62. package/dist/esm/state/machines/authStateMachine.js +7 -7
  63. package/dist/esm/state/machines/coreStateMachine.js +1 -1
  64. package/dist/esm/state/machines/walletStateMachine.js +1 -1
  65. package/dist/esm/telemetry/tracer.js +1 -1
  66. package/dist/esm/utils/url.js +4 -2
  67. package/dist/types/ParaCore.d.ts +1 -0
  68. package/dist/types/errors.d.ts +13 -0
  69. package/dist/types/external/localDevUrlOverrides.d.ts +4 -0
  70. package/dist/types/external/userManagementClient.d.ts +5 -4
  71. package/dist/types/types/config.d.ts +2 -0
  72. package/dist/types/utils/url.d.ts +1 -0
  73. package/package.json +4 -4
@@ -92,7 +92,9 @@ var import_user_management_client = require("@getpara/user-management-client");
92
92
  var import_node_forge = __toESM(require("node-forge"));
93
93
  var import_utils = require("./cryptography/utils.js");
94
94
  var import_userManagementClient = require("./external/userManagementClient.js");
95
+ var import_localDevUrlOverrides = require("./external/localDevUrlOverrides.js");
95
96
  var mpcComputationClient = __toESM(require("./external/mpcComputationClient.js"));
97
+ var import_url = require("./utils/url.js");
96
98
  var import_types = require("./types/index.js");
97
99
  var import_utils2 = require("./utils/index.js");
98
100
  var import_stateListener = require("./utils/stateListener.js");
@@ -124,6 +126,24 @@ if (typeof global !== "undefined") {
124
126
  self.global = self.global || self;
125
127
  }
126
128
  const { pki, jsbn } = import_node_forge.default;
129
+ const DEFAULT_SIGNING_RESULT_ERROR_MESSAGE = "Signing failed before a signature was produced.";
130
+ function getPendingTransactionId(signRes) {
131
+ return typeof signRes.pendingTransactionId === "string" && signRes.pendingTransactionId.length > 0 ? signRes.pendingTransactionId : void 0;
132
+ }
133
+ function requireSuccessfulSignatureResult(signRes) {
134
+ if (typeof signRes.signature === "string" && signRes.signature.length > 0) {
135
+ return { signature: signRes.signature };
136
+ }
137
+ throw new import_errors.SigningResultError(
138
+ typeof signRes.message === "string" && signRes.message.length > 0 ? signRes.message : DEFAULT_SIGNING_RESULT_ERROR_MESSAGE,
139
+ {
140
+ code: signRes.code,
141
+ status: signRes.status,
142
+ responseURL: signRes.responseURL,
143
+ data: signRes.data
144
+ }
145
+ );
146
+ }
127
147
  const _ParaCore = class _ParaCore {
128
148
  constructor(envOrApiKey, apiKeyOrOpts, opts) {
129
149
  __privateAdd(this, _ParaCore_instances);
@@ -263,7 +283,7 @@ const _ParaCore = class _ParaCore {
263
283
  const uxTargetId = typeof entry === "string" ? void 0 : entry.uxTargetId;
264
284
  const original = this[methodName];
265
285
  if (typeof original === "function") {
266
- this[methodName] = (...args) => {
286
+ this[methodName] = ((...args) => {
267
287
  var _a;
268
288
  const attrs = __spreadValues(__spreadProps(__spreadValues({
269
289
  "para.platform": this.platformUtils.sdkType
@@ -286,7 +306,7 @@ const _ParaCore = class _ParaCore {
286
306
  }),
287
307
  attrs
288
308
  ).catch((err) => this.trackError(methodName, err));
289
- };
309
+ });
290
310
  }
291
311
  }
292
312
  };
@@ -519,6 +539,7 @@ const _ParaCore = class _ParaCore {
519
539
  const rawPlatform = (_a = opts.hostPlatform) != null ? _a : this.platformUtils.sdkType;
520
540
  this.clientType = (0, import_userManagementClient.normalizePlatform)(rawPlatform);
521
541
  const requestAgents = (_c = (_b = this.platformUtils).getRequestAgents) == null ? void 0 : _c.call(_b);
542
+ const apiBaseUrlOverride = (0, import_localDevUrlOverrides.getDevApiBaseUrlOverride)();
522
543
  const client = (0, import_userManagementClient.initClient)({
523
544
  env,
524
545
  version: _ParaCore.version,
@@ -531,7 +552,8 @@ const _ParaCore = class _ParaCore {
531
552
  retrieveSessionCookie: this.retrieveSessionCookie,
532
553
  persistSessionCookie: this.persistSessionCookie,
533
554
  httpAgent: requestAgents == null ? void 0 : requestAgents.httpAgent,
534
- httpsAgent: requestAgents == null ? void 0 : requestAgents.httpsAgent
555
+ httpsAgent: requestAgents == null ? void 0 : requestAgents.httpsAgent,
556
+ apiBaseUrlOverride
535
557
  });
536
558
  const enclaveClient = new import_enclave.EnclaveClient({
537
559
  userManagementClient: client,
@@ -545,6 +567,9 @@ const _ParaCore = class _ParaCore {
545
567
  apiKey,
546
568
  client,
547
569
  enclaveClient,
570
+ apiBaseUrlOverride,
571
+ portalUrlOverride: (0, import_url.getGlobalPortalUrlOverride)(),
572
+ mpcNetworkUrlOverride: (0, import_localDevUrlOverrides.getDevMPCNetworkUrlOverride)(),
548
573
  disableWorkers: opts.disableWorkers,
549
574
  offloadMPCComputationURL: opts.offloadMPCComputationURL,
550
575
  useLocalFiles: opts.useLocalFiles,
@@ -1577,7 +1602,7 @@ const _ParaCore = class _ParaCore {
1577
1602
  const telemetry = res.data.partner.telemetry;
1578
1603
  if ((telemetry == null ? void 0 : telemetry.enabled) && this.ctx.env) {
1579
1604
  void (0, import_init.initTelemetry)({
1580
- tunnelUrl: `${(0, import_userManagementClient.getBaseUrl)(this.ctx.env)}telemetry`,
1605
+ tunnelUrl: `${(0, import_userManagementClient.getBaseUrl)(this.ctx.env, "http", this.ctx.apiBaseUrlOverride)}telemetry`,
1581
1606
  sampleRate: telemetry.sample_rate,
1582
1607
  sdkType: this.platformUtils.sdkType,
1583
1608
  clientType: this.clientType,
@@ -2417,6 +2442,14 @@ const _ParaCore = class _ParaCore {
2417
2442
  return result.url;
2418
2443
  });
2419
2444
  }
2445
+ getDeniedSignatureResultWithUrl(pendingTransactionId) {
2446
+ return __async(this, null, function* () {
2447
+ return {
2448
+ pendingTransactionId,
2449
+ transactionReviewUrl: yield this.getTransactionReviewUrl(pendingTransactionId)
2450
+ };
2451
+ });
2452
+ }
2420
2453
  getOnRampTransactionUrl(_0) {
2421
2454
  return __async(this, arguments, function* ({
2422
2455
  purchaseId
@@ -2479,11 +2512,9 @@ const _ParaCore = class _ParaCore {
2479
2512
  );
2480
2513
  let timeStart = Date.now();
2481
2514
  const effectiveTimeoutMs = Math.max(timeoutMs, constants.TRANSACTION_REVIEW_TIMEOUT_MS);
2482
- if (signRes.pendingTransactionId) {
2483
- const reviewUrl = yield this.getTransactionReviewUrl(
2484
- signRes.pendingTransactionId,
2485
- effectiveTimeoutMs
2486
- );
2515
+ let pendingTransactionId = getPendingTransactionId(signRes);
2516
+ if (pendingTransactionId) {
2517
+ const reviewUrl = yield this.getTransactionReviewUrl(pendingTransactionId, effectiveTimeoutMs);
2487
2518
  if (onTransactionReviewUrl) {
2488
2519
  onTransactionReviewUrl(reviewUrl);
2489
2520
  } else {
@@ -2492,8 +2523,9 @@ const _ParaCore = class _ParaCore {
2492
2523
  });
2493
2524
  }
2494
2525
  } else {
2495
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
2496
- return signRes;
2526
+ const successfulSignRes2 = requireSuccessfulSignatureResult(signRes);
2527
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, successfulSignRes2);
2528
+ return successfulSignRes2;
2497
2529
  }
2498
2530
  while (true) {
2499
2531
  if (isCanceled() || Date.now() - timeStart > effectiveTimeoutMs) {
@@ -2507,15 +2539,19 @@ const _ParaCore = class _ParaCore {
2507
2539
  "tx.review.poll",
2508
2540
  (span) => __async(this, null, function* () {
2509
2541
  var _a;
2510
- const res = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, signRes.pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
2542
+ const res = (_a = (yield this.ctx.client.getPendingTransaction(this.userId, pendingTransactionId)).data) == null ? void 0 : _a.pendingTransaction;
2511
2543
  span.setAttribute("polling.status", (res == null ? void 0 : res.approvedAt) ? "approved" : "pending");
2512
2544
  return res;
2513
2545
  }),
2514
- { "pending_transaction.id": signRes.pendingTransactionId }
2546
+ { "pending_transaction.id": pendingTransactionId }
2515
2547
  );
2516
2548
  } catch (e) {
2517
2549
  const error = new import_errors.TransactionReviewDenied();
2518
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
2550
+ (0, import_utils2.dispatchEvent)(
2551
+ import_types.ParaEvent.SIGN_MESSAGE_EVENT,
2552
+ yield this.getDeniedSignatureResultWithUrl(pendingTransactionId),
2553
+ error.message
2554
+ );
2519
2555
  throw error;
2520
2556
  }
2521
2557
  if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
@@ -2530,16 +2566,16 @@ const _ParaCore = class _ParaCore {
2530
2566
  break;
2531
2567
  }
2532
2568
  }
2533
- if (signRes.pendingTransactionId) {
2534
- const error = new import_errors.TransactionReviewTimeout(
2535
- yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
2536
- signRes.pendingTransactionId
2537
- );
2538
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes, error.message);
2569
+ pendingTransactionId = getPendingTransactionId(signRes);
2570
+ if (pendingTransactionId) {
2571
+ const deniedSignRes = yield this.getDeniedSignatureResultWithUrl(pendingTransactionId);
2572
+ const error = new import_errors.TransactionReviewTimeout(deniedSignRes.transactionReviewUrl, pendingTransactionId);
2573
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, deniedSignRes, error.message);
2539
2574
  throw error;
2540
2575
  }
2541
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, signRes);
2542
- return signRes;
2576
+ const successfulSignRes = requireSuccessfulSignatureResult(signRes);
2577
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_MESSAGE_EVENT, successfulSignRes);
2578
+ return successfulSignRes;
2543
2579
  });
2544
2580
  }
2545
2581
  signMessageInner(_0) {
@@ -2618,19 +2654,18 @@ const _ParaCore = class _ParaCore {
2618
2654
  );
2619
2655
  let timeStart = Date.now();
2620
2656
  const effectiveTimeoutMs = Math.max(timeoutMs, constants.TRANSACTION_REVIEW_TIMEOUT_MS);
2621
- if (signRes.pendingTransactionId) {
2622
- const reviewUrl = yield this.getTransactionReviewUrl(
2623
- signRes.pendingTransactionId,
2624
- effectiveTimeoutMs
2625
- );
2657
+ let pendingTransactionId = getPendingTransactionId(signRes);
2658
+ if (pendingTransactionId) {
2659
+ const reviewUrl = yield this.getTransactionReviewUrl(pendingTransactionId, effectiveTimeoutMs);
2626
2660
  if (onTransactionReviewUrl) {
2627
2661
  onTransactionReviewUrl(reviewUrl);
2628
2662
  } else {
2629
2663
  yield this.platformUtils.openPopup(reviewUrl, { type: import_types.PopupType.SIGN_TRANSACTION_REVIEW });
2630
2664
  }
2631
2665
  } else {
2632
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
2633
- return signRes;
2666
+ const successfulSignRes2 = requireSuccessfulSignatureResult(signRes);
2667
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, successfulSignRes2);
2668
+ return successfulSignRes2;
2634
2669
  }
2635
2670
  while (true) {
2636
2671
  if (isCanceled() || Date.now() - timeStart > effectiveTimeoutMs) {
@@ -2638,7 +2673,7 @@ const _ParaCore = class _ParaCore {
2638
2673
  break;
2639
2674
  }
2640
2675
  yield new Promise((resolve) => setTimeout(resolve, constants.POLLING_INTERVAL_MS));
2641
- const pendingTxId = signRes.pendingTransactionId;
2676
+ const pendingTxId = pendingTransactionId;
2642
2677
  let pendingTransaction;
2643
2678
  try {
2644
2679
  pendingTransaction = yield (0, import_tracer.wrapWithSpan)(
@@ -2653,7 +2688,11 @@ const _ParaCore = class _ParaCore {
2653
2688
  );
2654
2689
  } catch (e) {
2655
2690
  const error = new import_errors.TransactionReviewDenied();
2656
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
2691
+ (0, import_utils2.dispatchEvent)(
2692
+ import_types.ParaEvent.SIGN_TRANSACTION_EVENT,
2693
+ yield this.getDeniedSignatureResultWithUrl(pendingTxId),
2694
+ error.message
2695
+ );
2657
2696
  throw error;
2658
2697
  }
2659
2698
  if (!(pendingTransaction == null ? void 0 : pendingTransaction.approvedAt)) {
@@ -2677,16 +2716,16 @@ const _ParaCore = class _ParaCore {
2677
2716
  break;
2678
2717
  }
2679
2718
  }
2680
- if (signRes.pendingTransactionId) {
2681
- const error = new import_errors.TransactionReviewTimeout(
2682
- yield this.getTransactionReviewUrl(signRes.pendingTransactionId),
2683
- signRes.pendingTransactionId
2684
- );
2685
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes, error.message);
2719
+ pendingTransactionId = getPendingTransactionId(signRes);
2720
+ if (pendingTransactionId) {
2721
+ const deniedSignRes = yield this.getDeniedSignatureResultWithUrl(pendingTransactionId);
2722
+ const error = new import_errors.TransactionReviewTimeout(deniedSignRes.transactionReviewUrl, pendingTransactionId);
2723
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, deniedSignRes, error.message);
2686
2724
  throw error;
2687
2725
  }
2688
- (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, signRes);
2689
- return signRes;
2726
+ const successfulSignRes = requireSuccessfulSignatureResult(signRes);
2727
+ (0, import_utils2.dispatchEvent)(import_types.ParaEvent.SIGN_TRANSACTION_EVENT, successfulSignRes);
2728
+ return successfulSignRes;
2690
2729
  });
2691
2730
  }
2692
2731
  isProviderModalDisabled() {
@@ -46,7 +46,7 @@ __export(constants_exports, {
46
46
  TRANSACTION_REVIEW_TIMEOUT_MS: () => TRANSACTION_REVIEW_TIMEOUT_MS
47
47
  });
48
48
  module.exports = __toCommonJS(constants_exports);
49
- const PARA_CORE_VERSION = "3.5.0";
49
+ const PARA_CORE_VERSION = "3.6.0";
50
50
  const PREFIX = "@CAPSULE/";
51
51
  const PARA_PREFIX = "@PARA/";
52
52
  const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
@@ -161,7 +161,7 @@ function getAsymmetricKeyPair(ctx, seedValue) {
161
161
  if (!ctx.disableWorkers) {
162
162
  options.workLoad = 100;
163
163
  options.workers = seedValue ? 1 : -1;
164
- const workerBlob = yield (0, import_tracer.wrapWithSpan)("worker.load_prime", () => __async(this, null, function* () {
164
+ const workerBlob = yield (0, import_tracer.wrapWithSpan)("worker.load_prime", () => __async(null, null, function* () {
165
165
  const workerRes = yield fetch(`${(0, import_utils.getPortalBaseURL)(ctx)}/static/js/prime.worker.min.js`);
166
166
  return new Blob([yield workerRes.text()], { type: "application/javascript" });
167
167
  }));
@@ -223,7 +223,7 @@ function decryptWithDerivedPrivateKey(_0, _1) {
223
223
  function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
224
224
  return __async(this, null, function* () {
225
225
  return Promise.all(
226
- encryptedShares.map((share) => __async(this, null, function* () {
226
+ encryptedShares.map((share) => __async(null, null, function* () {
227
227
  return {
228
228
  walletId: share.walletId,
229
229
  walletScheme: share.walletScheme,
@@ -18,6 +18,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
18
18
  var errors_exports = {};
19
19
  __export(errors_exports, {
20
20
  PartnerConfigError: () => PartnerConfigError,
21
+ SigningResultError: () => SigningResultError,
21
22
  TransactionReviewDenied: () => TransactionReviewDenied,
22
23
  TransactionReviewError: () => TransactionReviewError,
23
24
  TransactionReviewTimeout: () => TransactionReviewTimeout
@@ -44,6 +45,16 @@ class TransactionReviewTimeout extends Error {
44
45
  this.pendingTransactionId = pendingTransactionId;
45
46
  }
46
47
  }
48
+ class SigningResultError extends Error {
49
+ constructor(message, options = {}) {
50
+ super(message);
51
+ this.name = "SigningResultError";
52
+ this.code = options.code;
53
+ this.status = options.status;
54
+ this.responseURL = options.responseURL;
55
+ this.data = options.data;
56
+ }
57
+ }
47
58
  class PartnerConfigError extends Error {
48
59
  constructor(code, message, detail) {
49
60
  super(message);
@@ -55,6 +66,7 @@ class PartnerConfigError extends Error {
55
66
  // Annotate the CommonJS export names for ESM import in node:
56
67
  0 && (module.exports = {
57
68
  PartnerConfigError,
69
+ SigningResultError,
58
70
  TransactionReviewDenied,
59
71
  TransactionReviewError,
60
72
  TransactionReviewTimeout
@@ -0,0 +1,50 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var localDevUrlOverrides_exports = {};
19
+ __export(localDevUrlOverrides_exports, {
20
+ getDevApiBaseUrlOverride: () => getDevApiBaseUrlOverride,
21
+ getDevMPCNetworkUrlOverride: () => getDevMPCNetworkUrlOverride
22
+ });
23
+ module.exports = __toCommonJS(localDevUrlOverrides_exports);
24
+ function getLocalDevUrlOverride(explicitOverride, globalKey, envKey) {
25
+ var _a;
26
+ const override = (_a = explicitOverride != null ? explicitOverride : typeof globalThis !== "undefined" ? globalThis[globalKey] : void 0) != null ? _a : typeof process !== "undefined" ? process.env[envKey] : void 0;
27
+ return typeof override === "string" && override ? override : void 0;
28
+ }
29
+ function normalizeDevUrlOverride(override, scheme) {
30
+ const url = new URL(override);
31
+ url.protocol = `${scheme}${url.protocol.endsWith("s:") ? "s" : ""}:`;
32
+ return url.href;
33
+ }
34
+ function getDevApiBaseUrlOverride(apiBaseUrlOverride, scheme = "http") {
35
+ const override = getLocalDevUrlOverride(apiBaseUrlOverride, "__PARA_API_BASE_URL_OVERRIDE__", "PARA_API_BASE_URL");
36
+ return override ? normalizeDevUrlOverride(override, scheme) : void 0;
37
+ }
38
+ function getDevMPCNetworkUrlOverride(mpcNetworkUrlOverride, useWebsocket) {
39
+ const override = getLocalDevUrlOverride(
40
+ mpcNetworkUrlOverride,
41
+ "__PARA_MPC_NETWORK_URL_OVERRIDE__",
42
+ "PARA_MPC_NETWORK_URL"
43
+ );
44
+ return override ? normalizeDevUrlOverride(override, useWebsocket ? "ws" : "http").replace(/\/+$/, "") : void 0;
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ getDevApiBaseUrlOverride,
49
+ getDevMPCNetworkUrlOverride
50
+ });
@@ -36,24 +36,12 @@ __export(userManagementClient_exports, {
36
36
  module.exports = __toCommonJS(userManagementClient_exports);
37
37
  var import_user_management_client = __toESM(require("@getpara/user-management-client"));
38
38
  var import_types = require("../types/index.js");
39
- function getDevApiBaseUrlOverride(scheme = "http") {
40
- const override = typeof globalThis !== "undefined" ? globalThis.__PARA_API_BASE_URL_OVERRIDE__ : void 0;
41
- if (!override || typeof override !== "string") {
42
- return void 0;
43
- }
44
- const url = new URL(override);
45
- if (scheme === "ws") {
46
- url.protocol = url.protocol === "https:" || url.protocol === "wss:" ? "wss:" : "ws:";
47
- } else {
48
- url.protocol = url.protocol === "wss:" || url.protocol === "https:" ? "https:" : "http:";
49
- }
50
- return url.toString();
51
- }
52
- function getBaseOAuthUrl(env) {
39
+ var import_localDevUrlOverrides = require("./localDevUrlOverrides.js");
40
+ function getBaseOAuthUrl(env, apiBaseUrlOverride) {
53
41
  var _a;
54
42
  switch (env) {
55
43
  case import_types.Environment.DEV:
56
- return (_a = getDevApiBaseUrlOverride()) != null ? _a : "http://localhost:8080/";
44
+ return (_a = (0, import_localDevUrlOverrides.getDevApiBaseUrlOverride)(apiBaseUrlOverride)) != null ? _a : "http://localhost:8080/";
57
45
  case import_types.Environment.SANDBOX:
58
46
  return "https://api.sandbox.usecapsule.com/";
59
47
  case import_types.Environment.BETA:
@@ -64,11 +52,11 @@ function getBaseOAuthUrl(env) {
64
52
  throw new Error(`unsupported env: ${env}`);
65
53
  }
66
54
  }
67
- function getBaseUrl(env, scheme = "http") {
55
+ function getBaseUrl(env, scheme = "http", apiBaseUrlOverride) {
68
56
  var _a;
69
57
  switch (env) {
70
58
  case import_types.Environment.DEV:
71
- return (_a = getDevApiBaseUrlOverride(scheme)) != null ? _a : `${scheme}://localhost:8080/`;
59
+ return (_a = (0, import_localDevUrlOverrides.getDevApiBaseUrlOverride)(apiBaseUrlOverride, scheme)) != null ? _a : `${scheme}://localhost:8080/`;
72
60
  case import_types.Environment.SANDBOX:
73
61
  return `${scheme}s://api.sandbox.getpara.com/`;
74
62
  case import_types.Environment.BETA:
@@ -79,11 +67,12 @@ function getBaseUrl(env, scheme = "http") {
79
67
  throw new Error(`unsupported env: ${env}`);
80
68
  }
81
69
  }
82
- function getBaseMPCNetworkUrl(env, useWebsocket) {
70
+ function getBaseMPCNetworkUrl(env, useWebsocket, mpcNetworkUrlOverride) {
71
+ var _a;
83
72
  const prefix = useWebsocket ? "ws" : "http";
84
73
  switch (env) {
85
74
  case import_types.Environment.DEV:
86
- return `${prefix}://localhost:3000`;
75
+ return (_a = (0, import_localDevUrlOverrides.getDevMPCNetworkUrlOverride)(mpcNetworkUrlOverride, useWebsocket)) != null ? _a : `${prefix}://localhost:3000`;
87
76
  case import_types.Environment.SANDBOX:
88
77
  return `${prefix}s://mpc-network.sandbox.getpara.com`;
89
78
  case import_types.Environment.BETA:
@@ -126,10 +115,11 @@ function initClient({
126
115
  persistSessionCookie,
127
116
  staticTraceContext,
128
117
  httpAgent,
129
- httpsAgent
118
+ httpsAgent,
119
+ apiBaseUrlOverride
130
120
  }) {
131
121
  return new import_user_management_client.default({
132
- userManagementHost: getBaseUrl(env),
122
+ userManagementHost: getBaseUrl(env, "http", apiBaseUrlOverride),
133
123
  version: [import_types.Environment.DEV, import_types.Environment.SANDBOX].includes(env) ? "dev" : version,
134
124
  apiKey,
135
125
  partnerId,
package/dist/cjs/index.js CHANGED
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var src_exports = {};
30
- __export(src_exports, {
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
31
  AccountLinkError: () => import_types.AccountLinkError,
32
32
  AuthLayout: () => import_user_management_client.AuthLayout,
33
33
  AuthMethod: () => import_user_management_client.AuthMethod,
@@ -70,7 +70,7 @@ __export(src_exports, {
70
70
  decryptPrivateKeyWithPassword: () => import_utils2.decryptPrivateKeyWithPassword,
71
71
  decryptWithKeyPair: () => import_utils2.decryptWithKeyPair,
72
72
  decryptWithPrivateKey: () => import_utils2.decryptWithPrivateKey,
73
- default: () => src_default,
73
+ default: () => index_default,
74
74
  dispatchEvent: () => import_utils.dispatchEvent,
75
75
  distributeNewShare: () => import_shareDistribution.distributeNewShare,
76
76
  encodeConfigParams: () => import_configEncoding.encodeConfigParams,
@@ -129,14 +129,14 @@ __export(src_exports, {
129
129
  wrapWithSpan: () => import_tracer.wrapWithSpan,
130
130
  wrapWithSpanInContext: () => import_tracer.wrapWithSpanInContext
131
131
  });
132
- module.exports = __toCommonJS(src_exports);
132
+ module.exports = __toCommonJS(index_exports);
133
133
  var import_ParaCore = require("./ParaCore.js");
134
134
  var import_user_management_client = require("@getpara/user-management-client");
135
135
  var import_types = require("./types/index.js");
136
- __reExport(src_exports, require("./types/smartAccounts.js"), module.exports);
137
- __reExport(src_exports, require("./types/coreApi.js"), module.exports);
138
- __reExport(src_exports, require("./types/events.js"), module.exports);
139
- __reExport(src_exports, require("./types/config.js"), module.exports);
136
+ __reExport(index_exports, require("./types/smartAccounts.js"), module.exports);
137
+ __reExport(index_exports, require("./types/coreApi.js"), module.exports);
138
+ __reExport(index_exports, require("./types/events.js"), module.exports);
139
+ __reExport(index_exports, require("./types/config.js"), module.exports);
140
140
  var import_utils = require("./utils/index.js");
141
141
  var import_constants = require("./constants.js");
142
142
  var import_shareDistribution = require("./shares/shareDistribution.js");
@@ -144,12 +144,12 @@ var import_KeyContainer = require("./shares/KeyContainer.js");
144
144
  var import_userManagementClient = require("./external/userManagementClient.js");
145
145
  var mpcComputationClient = __toESM(require("./external/mpcComputationClient.js"));
146
146
  var import_utils2 = require("./cryptography/utils.js");
147
- __reExport(src_exports, require("./external/userManagementClient.js"), module.exports);
148
- __reExport(src_exports, require("./errors.js"), module.exports);
149
- __reExport(src_exports, require("./utils/formatting.js"), module.exports);
150
- __reExport(src_exports, require("./utils/polling.js"), module.exports);
151
- __reExport(src_exports, require("./utils/phone.js"), module.exports);
152
- __reExport(src_exports, require("./utils/config.js"), module.exports);
147
+ __reExport(index_exports, require("./external/userManagementClient.js"), module.exports);
148
+ __reExport(index_exports, require("./errors.js"), module.exports);
149
+ __reExport(index_exports, require("./utils/formatting.js"), module.exports);
150
+ __reExport(index_exports, require("./utils/polling.js"), module.exports);
151
+ __reExport(index_exports, require("./utils/phone.js"), module.exports);
152
+ __reExport(index_exports, require("./utils/config.js"), module.exports);
153
153
  var import_wallet = require("./utils/wallet.js");
154
154
  var import_onRamps = require("./utils/onRamps.js");
155
155
  var import_url = require("./utils/url.js");
@@ -163,7 +163,7 @@ var import_uxStateSpanProcessor = require("./telemetry/uxStateSpanProcessor.js")
163
163
  var import_uxAction = require("./telemetry/uxAction.js");
164
164
  var import_modalSession = require("./telemetry/modalSession.js");
165
165
  const paraVersion = import_ParaCore.ParaCore.version;
166
- var src_default = import_ParaCore.ParaCore;
166
+ var index_default = import_ParaCore.ParaCore;
167
167
  // Annotate the CommonJS export names for ESM import in node:
168
168
  0 && (module.exports = {
169
169
  AccountLinkError,
@@ -454,7 +454,7 @@ class PortalUrlService {
454
454
  })).then((r) => r.url) : Promise.resolve(false)
455
455
  ]);
456
456
  return (0, import_url.constructUrl)({
457
- base: (0, import_userManagementClient.getBaseOAuthUrl)(__privateGet(this, _paraCoreInterface).ctx.env),
457
+ base: (0, import_userManagementClient.getBaseOAuthUrl)(__privateGet(this, _paraCoreInterface).ctx.env, __privateGet(this, _paraCoreInterface).ctx.apiBaseUrlOverride),
458
458
  path: `/auth/${method.toLowerCase()}`,
459
459
  params: __spreadValues(__spreadValues({
460
460
  apiKey: __privateGet(this, _paraCoreInterface).ctx.apiKey,
@@ -41,7 +41,7 @@ __export(authenticateWithEmailOrPhone_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithEmailOrPhone_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithEmailOrPhoneActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithEmailOrPhoneActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield authService.performSignUpOrLogIn(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(authenticateWithExternalWallet_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithExternalWallet_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithExternalWalletActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithExternalWalletActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield authService.performLoginExternalWallet(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(authenticateWithFarcaster_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithFarcaster_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithFarcasterActor = (pollingService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithFarcasterActor = (pollingService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield pollingService.waitForFarcasterEvent(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(authenticateWithFarcasterLegacy_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithFarcasterLegacy_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithFarcasterLegacyActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithFarcasterLegacyActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield authService.performVerifyFarcaster(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(authenticateWithTelegram_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithTelegram_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithTelegramActor = (pollingService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithTelegramActor = (pollingService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield pollingService.waitForTelegramEvent(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(authenticateWithTelegramLegacy_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(authenticateWithTelegramLegacy_exports);
43
43
  var import_xstate = require("xstate");
44
- const createAuthenticateWithTelegramLegacyActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createAuthenticateWithTelegramLegacyActor = (authService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield authService.performVerifyTelegram(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(checkUserState_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(checkUserState_exports);
43
43
  var import_xstate = require("xstate");
44
- const createCheckUserStateActor = (paraCoreInterface) => (0, import_xstate.fromPromise)(() => __async(void 0, null, function* () {
44
+ const createCheckUserStateActor = (paraCoreInterface) => (0, import_xstate.fromPromise)(() => __async(null, null, function* () {
45
45
  const isAuthenticated = yield paraCoreInterface.sessionManagementService.isSessionActive();
46
46
  const isFullyLoggedIn = yield paraCoreInterface.sessionManagementService.isFullyLoggedIn();
47
47
  const isGuestMode = paraCoreInterface.pregenWalletService.isGuestMode;
@@ -43,7 +43,7 @@ module.exports = __toCommonJS(claimWallets_exports);
43
43
  var import_xstate = require("xstate");
44
44
  var import_retryBackoff = require("../../utils/retryBackoff.js");
45
45
  const createClaimWalletsActor = (pregenWalletService) => (0, import_xstate.fromPromise)(
46
- (_0) => __async(void 0, [_0], function* ({ input }) {
46
+ (_0) => __async(null, [_0], function* ({ input }) {
47
47
  var _a;
48
48
  const retryCount = (_a = input == null ? void 0 : input.retryCount) != null ? _a : 0;
49
49
  if (retryCount > 0) yield (0, import_retryBackoff.sleep)((0, import_retryBackoff.retryDelay)(retryCount));
@@ -42,7 +42,7 @@ __export(connectExternalConnectors_exports, {
42
42
  module.exports = __toCommonJS(connectExternalConnectors_exports);
43
43
  var import_xstate = require("xstate");
44
44
  var import_retryBackoff = require("../../utils/retryBackoff.js");
45
- const createConnectParaConnectorsActor = (externalWalletService) => (0, import_xstate.fromPromise)((_0) => __async(void 0, [_0], function* ({ input }) {
45
+ const createConnectParaConnectorsActor = (externalWalletService) => (0, import_xstate.fromPromise)((_0) => __async(null, [_0], function* ({ input }) {
46
46
  var _a;
47
47
  const retryCount = (_a = input == null ? void 0 : input.retryCount) != null ? _a : 0;
48
48
  if (retryCount > 0) yield (0, import_retryBackoff.sleep)((0, import_retryBackoff.retryDelay)(retryCount));
@@ -41,7 +41,7 @@ __export(connectExternalWallet_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(connectExternalWallet_exports);
43
43
  var import_xstate = require("xstate");
44
- const createConnectExternalWalletActor = (externalWalletService) => (0, import_xstate.fromPromise)((params) => __async(void 0, null, function* () {
44
+ const createConnectExternalWalletActor = (externalWalletService) => (0, import_xstate.fromPromise)((params) => __async(null, null, function* () {
45
45
  return yield externalWalletService.performConnectExternalWallet(params.input);
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -41,7 +41,7 @@ __export(createGuestWallets_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(createGuestWallets_exports);
43
43
  var import_xstate = require("xstate");
44
- const createCreateGuestWalletsActor = (pregenWalletService) => (0, import_xstate.fromPromise)(() => __async(void 0, null, function* () {
44
+ const createCreateGuestWalletsActor = (pregenWalletService) => (0, import_xstate.fromPromise)(() => __async(null, null, function* () {
45
45
  return yield pregenWalletService.performCreateGuestWallets();
46
46
  }));
47
47
  // Annotate the CommonJS export names for ESM import in node:
@@ -56,7 +56,7 @@ __export(createWallets_exports, {
56
56
  module.exports = __toCommonJS(createWallets_exports);
57
57
  var import_xstate = require("xstate");
58
58
  var import_retryBackoff = require("../../utils/retryBackoff.js");
59
- const createCreateWalletsActor = (walletService) => (0, import_xstate.fromPromise)((_0) => __async(void 0, [_0], function* ({ input }) {
59
+ const createCreateWalletsActor = (walletService) => (0, import_xstate.fromPromise)((_0) => __async(null, [_0], function* ({ input }) {
60
60
  var _a;
61
61
  const retryCount = (_a = input == null ? void 0 : input.retryCount) != null ? _a : 0;
62
62
  if (retryCount > 0) yield (0, import_retryBackoff.sleep)((0, import_retryBackoff.retryDelay)(retryCount));