@getpara/core-sdk 3.0.0-alpha.1 → 3.1.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 (106) hide show
  1. package/dist/cjs/ParaCore.js +436 -86
  2. package/dist/cjs/constants.js +1 -1
  3. package/dist/cjs/cryptography/utils.js +5 -2
  4. package/dist/cjs/errors.js +10 -0
  5. package/dist/cjs/external/userManagementClient.js +21 -4
  6. package/dist/cjs/index.js +67 -1
  7. package/dist/cjs/services/AuthService.js +66 -47
  8. package/dist/cjs/services/LoginFlowService.js +30 -27
  9. package/dist/cjs/services/PollingService.js +100 -75
  10. package/dist/cjs/services/PortalUrlService.js +112 -19
  11. package/dist/cjs/services/PregenWalletService.js +125 -76
  12. package/dist/cjs/services/SessionManagementService.js +81 -10
  13. package/dist/cjs/services/SignupFlowService.js +52 -47
  14. package/dist/cjs/services/VerificationFlowService.js +13 -10
  15. package/dist/cjs/services/WalletService.js +51 -36
  16. package/dist/cjs/shares/enclave.js +44 -24
  17. package/dist/cjs/state/CoreStateManager.js +17 -5
  18. package/dist/cjs/state/actors/setupPara.js +4 -1
  19. package/dist/cjs/state/machines/walletStateMachine.js +22 -0
  20. package/dist/cjs/telemetry/BeaconSpanProcessor.js +99 -0
  21. package/dist/cjs/telemetry/config.js +15 -0
  22. package/dist/cjs/telemetry/init.js +193 -0
  23. package/dist/cjs/telemetry/modalSession.js +54 -0
  24. package/dist/cjs/telemetry/session.js +39 -0
  25. package/dist/cjs/telemetry/tracer.js +126 -0
  26. package/dist/cjs/telemetry/uxAction.js +30 -0
  27. package/dist/cjs/telemetry/uxBaggagePropagator.js +58 -0
  28. package/dist/cjs/telemetry/uxState.js +46 -0
  29. package/dist/cjs/telemetry/uxStateSpanProcessor.js +51 -0
  30. package/dist/cjs/utils/configEncoding.js +98 -0
  31. package/dist/cjs/utils/deprecation.js +13 -13
  32. package/dist/cjs/utils/index.js +11 -0
  33. package/dist/cjs/utils/partnerConfig.js +103 -0
  34. package/dist/cjs/utils/partnerConfigGating.js +83 -0
  35. package/dist/cjs/utils/stateErrorHelpers.js +6 -1
  36. package/dist/cjs/utils/url.js +10 -2
  37. package/dist/esm/ParaCore.js +441 -88
  38. package/dist/esm/constants.js +1 -1
  39. package/dist/esm/cryptography/utils.js +5 -2
  40. package/dist/esm/errors.js +9 -0
  41. package/dist/esm/external/userManagementClient.js +21 -4
  42. package/dist/esm/index.js +58 -4
  43. package/dist/esm/services/AuthService.js +66 -47
  44. package/dist/esm/services/LoginFlowService.js +30 -27
  45. package/dist/esm/services/PollingService.js +100 -75
  46. package/dist/esm/services/PortalUrlService.js +112 -19
  47. package/dist/esm/services/PregenWalletService.js +125 -76
  48. package/dist/esm/services/SessionManagementService.js +69 -11
  49. package/dist/esm/services/SignupFlowService.js +52 -47
  50. package/dist/esm/services/VerificationFlowService.js +13 -10
  51. package/dist/esm/services/WalletService.js +51 -36
  52. package/dist/esm/shares/enclave.js +44 -24
  53. package/dist/esm/state/CoreStateManager.js +17 -5
  54. package/dist/esm/state/actors/setupPara.js +4 -1
  55. package/dist/esm/state/machines/walletStateMachine.js +22 -0
  56. package/dist/esm/telemetry/BeaconSpanProcessor.js +74 -0
  57. package/dist/esm/telemetry/config.js +0 -0
  58. package/dist/esm/telemetry/init.js +130 -0
  59. package/dist/esm/telemetry/modalSession.js +29 -0
  60. package/dist/esm/telemetry/session.js +16 -0
  61. package/dist/esm/telemetry/tracer.js +84 -0
  62. package/dist/esm/telemetry/uxAction.js +8 -0
  63. package/dist/esm/telemetry/uxBaggagePropagator.js +35 -0
  64. package/dist/esm/telemetry/uxState.js +21 -0
  65. package/dist/esm/telemetry/uxStateSpanProcessor.js +28 -0
  66. package/dist/esm/utils/configEncoding.js +45 -0
  67. package/dist/esm/utils/deprecation.js +11 -12
  68. package/dist/esm/utils/index.js +6 -0
  69. package/dist/esm/utils/partnerConfig.js +67 -0
  70. package/dist/esm/utils/partnerConfigGating.js +61 -0
  71. package/dist/esm/utils/stateErrorHelpers.js +6 -1
  72. package/dist/esm/utils/url.js +10 -2
  73. package/dist/types/ParaCore.d.ts +101 -19
  74. package/dist/types/PlatformUtils.d.ts +1 -0
  75. package/dist/types/errors.d.ts +26 -0
  76. package/dist/types/external/userManagementClient.d.ts +2 -1
  77. package/dist/types/index.d.ts +15 -3
  78. package/dist/types/services/types/AuthServiceTypes.d.ts +10 -3
  79. package/dist/types/services/types/PortalUrlServiceTypes.d.ts +3 -3
  80. package/dist/types/services/types/WalletServiceTypes.d.ts +4 -0
  81. package/dist/types/state/actors/setupPara.d.ts +18 -0
  82. package/dist/types/state/machines/authStateMachine.d.ts +1 -1
  83. package/dist/types/state/machines/coreStateMachine.d.ts +30 -6
  84. package/dist/types/state/machines/walletStateMachine.d.ts +4 -0
  85. package/dist/types/state/types/core.d.ts +7 -1
  86. package/dist/types/telemetry/BeaconSpanProcessor.d.ts +10 -0
  87. package/dist/types/telemetry/config.d.ts +4 -0
  88. package/dist/types/telemetry/init.d.ts +17 -0
  89. package/dist/types/telemetry/modalSession.d.ts +5 -0
  90. package/dist/types/telemetry/session.d.ts +2 -0
  91. package/dist/types/telemetry/tracer.d.ts +10 -0
  92. package/dist/types/telemetry/uxAction.d.ts +3 -0
  93. package/dist/types/telemetry/uxBaggagePropagator.d.ts +7 -0
  94. package/dist/types/telemetry/uxState.d.ts +8 -0
  95. package/dist/types/telemetry/uxStateSpanProcessor.d.ts +9 -0
  96. package/dist/types/types/config.d.ts +15 -3
  97. package/dist/types/types/coreApi.d.ts +7 -9
  98. package/dist/types/types/serviceInterfaces.d.ts +5 -3
  99. package/dist/types/types/util.d.ts +2 -15
  100. package/dist/types/utils/configEncoding.d.ts +51 -0
  101. package/dist/types/utils/deprecation.d.ts +3 -1
  102. package/dist/types/utils/index.d.ts +2 -0
  103. package/dist/types/utils/partnerConfig.d.ts +28 -0
  104. package/dist/types/utils/partnerConfigGating.d.ts +48 -0
  105. package/dist/types/utils/url.d.ts +3 -2
  106. package/package.json +15 -4
@@ -83,6 +83,7 @@ var import_events = require("../types/events.js");
83
83
  var import_constants = require("../constants.js");
84
84
  var import_shareDistribution = require("../shares/shareDistribution.js");
85
85
  var import_recovery = require("../shares/recovery.js");
86
+ var import_tracer = require("../telemetry/tracer.js");
86
87
  var _authService, _pollingService, _pregenWalletService, _externalWalletService, _paraCoreInterface, _wallets, _currentWalletIds, _isWalletOwned, _getMissingTypes, _encodeWalletBase64;
87
88
  class WalletService {
88
89
  constructor(paraCore) {
@@ -164,15 +165,20 @@ class WalletService {
164
165
  }
165
166
  });
166
167
  });
168
+ // wallets.populate names the GET /users/:userId/wallets call that runs to
169
+ // refresh address state after creation/refresh; without it the GET shows up
170
+ // as a bare span at the trace top level.
167
171
  this.populateWalletAddresses = () => __async(this, null, function* () {
168
- const res = yield (__privateGet(this, _paraCoreInterface).isPortal() ? __privateGet(this, _paraCoreInterface).ctx.client.getAllWallets : __privateGet(this, _paraCoreInterface).ctx.client.getWallets)(__privateGet(this, _authService).userId, true);
169
- const wallets = res.data.wallets;
170
- wallets.forEach((entity) => {
171
- if (this.wallets[entity.id]) {
172
- this.wallets[entity.id] = __spreadValues(__spreadValues({}, (0, import_wallet2.entityToWallet)(entity)), this.wallets[entity.id]);
173
- }
174
- });
175
- yield this.setWallets(this.wallets);
172
+ return (0, import_tracer.wrapWithSpan)("wallets.populate", () => __async(this, null, function* () {
173
+ const res = yield (__privateGet(this, _paraCoreInterface).isPortal() ? __privateGet(this, _paraCoreInterface).ctx.client.getAllWallets : __privateGet(this, _paraCoreInterface).ctx.client.getWallets)(__privateGet(this, _authService).userId, true);
174
+ const wallets = res.data.wallets;
175
+ wallets.forEach((entity) => {
176
+ if (this.wallets[entity.id]) {
177
+ this.wallets[entity.id] = __spreadValues(__spreadValues({}, (0, import_wallet2.entityToWallet)(entity)), this.wallets[entity.id]);
178
+ }
179
+ });
180
+ yield this.setWallets(this.wallets);
181
+ }));
176
182
  });
177
183
  this.addToCurrentWalletIds = (walletIds, options) => __async(this, null, function* () {
178
184
  const updatedWalletIds = __spreadValues({}, this.currentWalletIds);
@@ -212,31 +218,35 @@ class WalletService {
212
218
  );
213
219
  let signer;
214
220
  let wallet;
215
- let keygenRes;
216
- switch (walletType) {
217
- case "STELLAR":
218
- case "SOLANA": {
219
- keygenRes = yield __privateGet(this, _paraCoreInterface).platformUtils.ed25519Keygen(
220
- __privateGet(this, _paraCoreInterface).ctx,
221
- __privateGet(this, _authService).userId,
222
- __privateGet(this, _paraCoreInterface).retrieveSessionCookie(),
223
- __privateGet(this, _paraCoreInterface).getBackupKitEmailProps(),
224
- walletType
225
- );
226
- break;
227
- }
228
- default: {
229
- keygenRes = yield __privateGet(this, _paraCoreInterface).platformUtils.keygen(
230
- __privateGet(this, _paraCoreInterface).ctx,
231
- __privateGet(this, _authService).userId,
232
- walletType,
233
- null,
234
- __privateGet(this, _paraCoreInterface).retrieveSessionCookie(),
235
- __privateGet(this, _paraCoreInterface).getBackupKitEmailProps()
236
- );
237
- break;
221
+ const keygenRes = yield (0, import_tracer.wrapWithSpan)(
222
+ "mpc.keygen",
223
+ () => __async(this, null, function* () {
224
+ switch (walletType) {
225
+ case "STELLAR":
226
+ case "SOLANA":
227
+ return __privateGet(this, _paraCoreInterface).platformUtils.ed25519Keygen(
228
+ __privateGet(this, _paraCoreInterface).ctx,
229
+ __privateGet(this, _authService).userId,
230
+ __privateGet(this, _paraCoreInterface).retrieveSessionCookie(),
231
+ __privateGet(this, _paraCoreInterface).getBackupKitEmailProps(),
232
+ walletType
233
+ );
234
+ default:
235
+ return __privateGet(this, _paraCoreInterface).platformUtils.keygen(
236
+ __privateGet(this, _paraCoreInterface).ctx,
237
+ __privateGet(this, _authService).userId,
238
+ walletType,
239
+ null,
240
+ __privateGet(this, _paraCoreInterface).retrieveSessionCookie(),
241
+ __privateGet(this, _paraCoreInterface).getBackupKitEmailProps()
242
+ );
243
+ }
244
+ }),
245
+ {
246
+ "wallet.type": walletType,
247
+ "wallet.scheme": walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS"
238
248
  }
239
- }
249
+ );
240
250
  const walletId = keygenRes.walletId;
241
251
  const walletScheme = walletType === "SOLANA" || walletType === "STELLAR" ? "ED25519" : "DKLS";
242
252
  signer = keygenRes.signer;
@@ -444,11 +454,16 @@ class WalletService {
444
454
  }
445
455
  return type;
446
456
  });
457
+ // wallets.fetch names the post-keygen wallet list reads (the polling-style
458
+ // GETs that follow each MPC keygen). The auto-instrumented HTTP child carries
459
+ // the URL and status so this stays cheap.
447
460
  this.fetchWallets = () => __async(this, null, function* () {
448
- const res = yield __privateGet(this, _paraCoreInterface).isPortal() || __privateGet(this, _paraCoreInterface).isParaConnect() ? __privateGet(this, _paraCoreInterface).ctx.client.getAllWallets(__privateGet(this, _authService).userId) : __privateGet(this, _paraCoreInterface).ctx.client.getWallets(__privateGet(this, _authService).userId, true);
449
- return res.data.wallets.filter(
450
- (wallet) => !!wallet.address && wallet.sharesPersisted && (__privateGet(this, _paraCoreInterface).isParaConnect() || !__privateGet(this, _paraCoreInterface).isParaConnect() && this.isWalletSupported((0, import_wallet2.entityToWallet)(wallet)))
451
- );
461
+ return (0, import_tracer.wrapWithSpan)("wallets.fetch", () => __async(this, null, function* () {
462
+ const res = yield __privateGet(this, _paraCoreInterface).isPortal() || __privateGet(this, _paraCoreInterface).isParaConnect() ? __privateGet(this, _paraCoreInterface).ctx.client.getAllWallets(__privateGet(this, _authService).userId) : __privateGet(this, _paraCoreInterface).ctx.client.getWallets(__privateGet(this, _authService).userId, true);
463
+ return res.data.wallets.filter(
464
+ (wallet) => !!wallet.address && wallet.sharesPersisted && (__privateGet(this, _paraCoreInterface).isParaConnect() || !__privateGet(this, _paraCoreInterface).isParaConnect() && this.isWalletSupported((0, import_wallet2.entityToWallet)(wallet)))
465
+ );
466
+ }));
452
467
  });
453
468
  this.getWalletBalance = (_0) => __async(this, [_0], function* ({ walletId, rpcUrl }) {
454
469
  return (yield __privateGet(this, _paraCoreInterface).ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
@@ -40,6 +40,7 @@ __export(enclave_exports, {
40
40
  EnclaveClient: () => EnclaveClient
41
41
  });
42
42
  module.exports = __toCommonJS(enclave_exports);
43
+ var import_tracer = require("../telemetry/tracer.js");
43
44
  class EnclaveClient {
44
45
  constructor({
45
46
  userManagementClient,
@@ -211,40 +212,59 @@ ${exportedAsBase64}
211
212
  * Persist key shares to the enclave
212
213
  * @param shares Array of share data to persist
213
214
  */
215
+ // enclave.persist_shares wraps the encrypt + POST /enclave/key-shares pair so
216
+ // both the (CPU-bound) ECIES encryption and the network call show up under a
217
+ // named parent in the trace. Encryption can dominate the wall time so it's
218
+ // worth spelling out separately from the POST itself.
214
219
  persistShares(shares) {
215
220
  return __async(this, null, function* () {
216
- const payload = {
217
- shares,
218
- jwt: this.retrieveJwt()
219
- };
220
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
221
- const encryptedPayloadStr = JSON.stringify(encryptedPayload);
222
- return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
221
+ return (0, import_tracer.wrapWithSpan)(
222
+ "enclave.persist_shares",
223
+ () => __async(this, null, function* () {
224
+ const payload = {
225
+ shares,
226
+ jwt: this.retrieveJwt()
227
+ };
228
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
229
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
230
+ return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
231
+ }),
232
+ { "enclave.share_count": shares.length }
233
+ );
223
234
  });
224
235
  }
225
236
  /**
226
237
  * Retrieve key shares from the enclave
227
238
  * @param query Query parameters for finding shares (single query or array of queries)
228
239
  */
240
+ // enclave.retrieve_shares wraps the JWT issue + ECDH keypair gen + GET
241
+ // /enclave/key-shares + decrypt pipeline. The decrypt step can be slow on
242
+ // many-share accounts so a named span makes that latency easy to spot.
229
243
  retrieveShares(query) {
230
244
  return __async(this, null, function* () {
231
- yield this.issueEnclaveJwt();
232
- const frontendKeyPair = yield this.generateFrontendKeyPair();
233
- const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
234
- const fullQuery = query.map((q) => ({
235
- userId: q.userId
236
- }));
237
- const payload = {
238
- query: fullQuery,
239
- responsePublicKey: responsePublicKeyPEM,
240
- jwt: this.retrieveJwt()
241
- };
242
- const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
243
- const encryptedPayloadStr = JSON.stringify(encryptedPayload);
244
- const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
245
- const encryptedResponse = JSON.parse(response.payload);
246
- const decryptedData = yield this.decryptForFrontend(encryptedResponse);
247
- return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
245
+ return (0, import_tracer.wrapWithSpan)(
246
+ "enclave.retrieve_shares",
247
+ () => __async(this, null, function* () {
248
+ yield this.issueEnclaveJwt();
249
+ const frontendKeyPair = yield this.generateFrontendKeyPair();
250
+ const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
251
+ const fullQuery = query.map((q) => ({
252
+ userId: q.userId
253
+ }));
254
+ const payload = {
255
+ query: fullQuery,
256
+ responsePublicKey: responsePublicKeyPEM,
257
+ jwt: this.retrieveJwt()
258
+ };
259
+ const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
260
+ const encryptedPayloadStr = JSON.stringify(encryptedPayload);
261
+ const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
262
+ const encryptedResponse = JSON.parse(response.payload);
263
+ const decryptedData = yield this.decryptForFrontend(encryptedResponse);
264
+ return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
265
+ }),
266
+ { "enclave.query_count": query.length }
267
+ );
248
268
  });
249
269
  }
250
270
  deleteShares() {
@@ -115,7 +115,7 @@ const _CoreStateManager = class _CoreStateManager {
115
115
  * Extracts all data needed by UI consumers from authStateResult.
116
116
  */
117
117
  computeAuthStateInfo(authContext, walletContext) {
118
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
118
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L;
119
119
  const defaultAuthStateInfo = {
120
120
  userId: null,
121
121
  isPasskeySupported: false,
@@ -133,6 +133,9 @@ const _CoreStateManager = class _CoreStateManager {
133
133
  passkeyId: null,
134
134
  verificationUrl: null,
135
135
  verificationFullUrl: null,
136
+ deliveryChannel: null,
137
+ fallbackUsed: false,
138
+ fallbackChannel: null,
136
139
  externalWalletVerification: null,
137
140
  recoverySecret: null,
138
141
  isNewUser: false
@@ -172,6 +175,9 @@ const _CoreStateManager = class _CoreStateManager {
172
175
  let verificationFullUrl = null;
173
176
  let passkeyHints = null;
174
177
  let passkeyId = null;
178
+ let deliveryChannel = null;
179
+ let fallbackUsed = false;
180
+ let fallbackChannel = null;
175
181
  if (stage === "login") {
176
182
  const loginState = authStateResult;
177
183
  const authMethods = (_j = loginState.loginAuthMethods) != null ? _j : [];
@@ -205,6 +211,9 @@ const _CoreStateManager = class _CoreStateManager {
205
211
  const verifyState = authStateResult;
206
212
  verificationUrl = (_C = verifyState.loginUrl) != null ? _C : null;
207
213
  verificationFullUrl = (_D = verifyState.loginFullUrl) != null ? _D : null;
214
+ deliveryChannel = (_E = verifyState.deliveryChannel) != null ? _E : null;
215
+ fallbackUsed = (_F = verifyState.fallbackUsed) != null ? _F : false;
216
+ fallbackChannel = (_G = verifyState.fallbackChannel) != null ? _G : null;
208
217
  }
209
218
  return {
210
219
  userId,
@@ -223,10 +232,13 @@ const _CoreStateManager = class _CoreStateManager {
223
232
  passkeyId,
224
233
  verificationUrl,
225
234
  verificationFullUrl,
235
+ deliveryChannel,
236
+ fallbackUsed,
237
+ fallbackChannel,
226
238
  externalWalletVerification: externalWalletVerification ? {
227
- signatureVerificationMessage: (_E = externalWalletVerification.signatureVerificationMessage) != null ? _E : "",
228
- walletAddress: (_G = (_F = externalWalletVerification.externalWallet) == null ? void 0 : _F.address) != null ? _G : "",
229
- walletType: (_I = (_H = externalWalletVerification.externalWallet) == null ? void 0 : _H.type) != null ? _I : ""
239
+ signatureVerificationMessage: (_H = externalWalletVerification.signatureVerificationMessage) != null ? _H : "",
240
+ walletAddress: (_J = (_I = externalWalletVerification.externalWallet) == null ? void 0 : _I.address) != null ? _J : "",
241
+ walletType: (_L = (_K = externalWalletVerification.externalWallet) == null ? void 0 : _K.type) != null ? _L : ""
230
242
  } : null,
231
243
  recoverySecret,
232
244
  isNewUser
@@ -288,7 +300,7 @@ const _CoreStateManager = class _CoreStateManager {
288
300
  }
289
301
  authStateInfoEqual(a, b) {
290
302
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
291
- return a.userId === b.userId && a.isPasskeySupported === b.isPasskeySupported && a.hasPasskey === b.hasPasskey && a.hasPassword === b.hasPassword && a.hasPin === b.hasPin && a.passkeyUrl === b.passkeyUrl && a.passkeyFullUrl === b.passkeyFullUrl && a.passkeyKnownDeviceUrl === b.passkeyKnownDeviceUrl && a.passwordUrl === b.passwordUrl && a.passwordFullUrl === b.passwordFullUrl && a.pinUrl === b.pinUrl && a.pinFullUrl === b.pinFullUrl && a.passkeyId === b.passkeyId && a.verificationUrl === b.verificationUrl && a.verificationFullUrl === b.verificationFullUrl && a.recoverySecret === b.recoverySecret && a.isNewUser === b.isNewUser && ((_a = a.externalWalletVerification) == null ? void 0 : _a.signatureVerificationMessage) === ((_b = b.externalWalletVerification) == null ? void 0 : _b.signatureVerificationMessage) && ((_c = a.externalWalletVerification) == null ? void 0 : _c.walletAddress) === ((_d = b.externalWalletVerification) == null ? void 0 : _d.walletAddress) && ((_e = a.externalWalletVerification) == null ? void 0 : _e.walletType) === ((_f = b.externalWalletVerification) == null ? void 0 : _f.walletType) && ((_g = a.passkeyHints) == null ? void 0 : _g.length) === ((_h = b.passkeyHints) == null ? void 0 : _h.length) && ((_i = a.passkeyHints) != null ? _i : []).every(
303
+ return a.userId === b.userId && a.isPasskeySupported === b.isPasskeySupported && a.hasPasskey === b.hasPasskey && a.hasPassword === b.hasPassword && a.hasPin === b.hasPin && a.passkeyUrl === b.passkeyUrl && a.passkeyFullUrl === b.passkeyFullUrl && a.passkeyKnownDeviceUrl === b.passkeyKnownDeviceUrl && a.passwordUrl === b.passwordUrl && a.passwordFullUrl === b.passwordFullUrl && a.pinUrl === b.pinUrl && a.pinFullUrl === b.pinFullUrl && a.passkeyId === b.passkeyId && a.verificationUrl === b.verificationUrl && a.verificationFullUrl === b.verificationFullUrl && a.deliveryChannel === b.deliveryChannel && a.fallbackUsed === b.fallbackUsed && a.fallbackChannel === b.fallbackChannel && a.recoverySecret === b.recoverySecret && a.isNewUser === b.isNewUser && ((_a = a.externalWalletVerification) == null ? void 0 : _a.signatureVerificationMessage) === ((_b = b.externalWalletVerification) == null ? void 0 : _b.signatureVerificationMessage) && ((_c = a.externalWalletVerification) == null ? void 0 : _c.walletAddress) === ((_d = b.externalWalletVerification) == null ? void 0 : _d.walletAddress) && ((_e = a.externalWalletVerification) == null ? void 0 : _e.walletType) === ((_f = b.externalWalletVerification) == null ? void 0 : _f.walletType) && ((_g = a.passkeyHints) == null ? void 0 : _g.length) === ((_h = b.passkeyHints) == null ? void 0 : _h.length) && ((_i = a.passkeyHints) != null ? _i : []).every(
292
304
  (hint, i) => hint.useragent === b.passkeyHints[i].useragent && hint.aaguid === b.passkeyHints[i].aaguid
293
305
  );
294
306
  }
@@ -42,7 +42,10 @@ __export(setupPara_exports, {
42
42
  module.exports = __toCommonJS(setupPara_exports);
43
43
  var import_xstate = require("xstate");
44
44
  const createSetupParaActor = (paraCoreInterface) => (0, import_xstate.fromPromise)(() => __async(void 0, null, function* () {
45
- yield paraCoreInterface.setup();
45
+ const eagerPartnerLoad = paraCoreInterface.isPortal() ? Promise.resolve() : paraCoreInterface.sessionManagementService.touchSession().catch((e) => {
46
+ paraCoreInterface.devLog("setupPara: eager partner load via touchSession failed; will retry lazily", e);
47
+ });
48
+ yield Promise.all([paraCoreInterface.setup(), eagerPartnerLoad]);
46
49
  }));
47
50
  // Annotate the CommonJS export names for ESM import in node:
48
51
  0 && (module.exports = {
@@ -215,6 +215,28 @@ function createWalletStateMachine(paraCoreInterface) {
215
215
  ]
216
216
  },
217
217
  needs_wallets: {
218
+ // `needs_wallets` is otherwise a passive state that waits for the consumer
219
+ // to dispatch `WAIT_FOR_WALLET_CREATION`. That contract is fine for
220
+ // `isNewUser` reaching this state without auto-create (`checking_wallet_state`
221
+ // guard at line ~127), but it traps existing users who landed here via
222
+ // `waiting_for_wallets` COMPLETE with `needsWallet=true` — i.e., an
223
+ // authenticated user whose wallets don't satisfy the partner's
224
+ // `supportedWalletTypes` (e.g. EVM-only user logging into a Solana-only
225
+ // partner). Their auth flow set `shouldAutoCreateWallets: true` via
226
+ // `authenticateWithOAuth` / `authenticateWithEmailOrPhone`, but the
227
+ // existing `claiming_wallets` guard requires `isNewUser ||
228
+ // shouldClaimGuestWallets`, neither of which is true for them, so
229
+ // auto-create silently never happens.
230
+ //
231
+ // When `shouldAutoCreate` is true, route directly to `creating_wallets`.
232
+ // `createWalletPerType` is partner-aware via `#getMissingTypes`, so it
233
+ // provisions exactly the missing required types (no duplicates).
234
+ always: [
235
+ {
236
+ target: "creating_wallets",
237
+ guard: "shouldAutoCreate"
238
+ }
239
+ ],
218
240
  on: {
219
241
  WAIT_FOR_WALLET_CREATION: {
220
242
  target: "claiming_wallets",
@@ -0,0 +1,99 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
22
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
23
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
24
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
25
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
26
+ var BeaconSpanProcessor_exports = {};
27
+ __export(BeaconSpanProcessor_exports, {
28
+ BeaconSpanProcessor: () => BeaconSpanProcessor
29
+ });
30
+ module.exports = __toCommonJS(BeaconSpanProcessor_exports);
31
+ var import_otlp_transformer = require("@opentelemetry/otlp-transformer");
32
+ var _spans, _pagehideListener, _visibilityListener, _url, _BeaconSpanProcessor_instances, flushViaBeacon_fn;
33
+ const MAX_BUFFER_SIZE = 200;
34
+ class BeaconSpanProcessor {
35
+ constructor(url) {
36
+ __privateAdd(this, _BeaconSpanProcessor_instances);
37
+ __privateAdd(this, _spans, []);
38
+ __privateAdd(this, _pagehideListener);
39
+ __privateAdd(this, _visibilityListener);
40
+ __privateAdd(this, _url);
41
+ __privateSet(this, _url, url);
42
+ if (typeof window !== "undefined") {
43
+ __privateSet(this, _pagehideListener, () => __privateMethod(this, _BeaconSpanProcessor_instances, flushViaBeacon_fn).call(this));
44
+ __privateSet(this, _visibilityListener, () => {
45
+ if (typeof document !== "undefined" && document.visibilityState === "hidden") {
46
+ __privateMethod(this, _BeaconSpanProcessor_instances, flushViaBeacon_fn).call(this);
47
+ }
48
+ });
49
+ window.addEventListener("pagehide", __privateGet(this, _pagehideListener));
50
+ if (typeof document !== "undefined") {
51
+ document.addEventListener("visibilitychange", __privateGet(this, _visibilityListener));
52
+ }
53
+ }
54
+ }
55
+ onStart(_span, _parentContext) {
56
+ }
57
+ onEnd(span) {
58
+ __privateGet(this, _spans).push(span);
59
+ if (__privateGet(this, _spans).length > MAX_BUFFER_SIZE) {
60
+ __privateGet(this, _spans).shift();
61
+ }
62
+ }
63
+ forceFlush() {
64
+ return Promise.resolve();
65
+ }
66
+ shutdown() {
67
+ __privateMethod(this, _BeaconSpanProcessor_instances, flushViaBeacon_fn).call(this);
68
+ if (__privateGet(this, _pagehideListener) && typeof window !== "undefined") {
69
+ window.removeEventListener("pagehide", __privateGet(this, _pagehideListener));
70
+ __privateSet(this, _pagehideListener, void 0);
71
+ }
72
+ if (__privateGet(this, _visibilityListener) && typeof document !== "undefined") {
73
+ document.removeEventListener("visibilitychange", __privateGet(this, _visibilityListener));
74
+ __privateSet(this, _visibilityListener, void 0);
75
+ }
76
+ __privateSet(this, _spans, []);
77
+ return Promise.resolve();
78
+ }
79
+ }
80
+ _spans = new WeakMap();
81
+ _pagehideListener = new WeakMap();
82
+ _visibilityListener = new WeakMap();
83
+ _url = new WeakMap();
84
+ _BeaconSpanProcessor_instances = new WeakSet();
85
+ flushViaBeacon_fn = function() {
86
+ if (__privateGet(this, _spans).length === 0) return;
87
+ if (typeof navigator === "undefined" || typeof navigator.sendBeacon !== "function") return;
88
+ try {
89
+ const body = import_otlp_transformer.JsonTraceSerializer.serializeRequest(__privateGet(this, _spans));
90
+ const blob = new Blob([body], { type: "application/json" });
91
+ navigator.sendBeacon(__privateGet(this, _url), blob);
92
+ __privateSet(this, _spans, []);
93
+ } catch (e) {
94
+ }
95
+ };
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ BeaconSpanProcessor
99
+ });
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var config_exports = {};
15
+ module.exports = __toCommonJS(config_exports);
@@ -0,0 +1,193 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
+ // If the importer is in node compatibility mode or this is not an ESM
35
+ // file that has been converted to a CommonJS file using a Babel-
36
+ // compatible transform (i.e. "__esModule" has not been set), then set
37
+ // "default" to the CommonJS "module.exports" for node compatibility.
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
39
+ mod
40
+ ));
41
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
+ var __async = (__this, __arguments, generator) => {
43
+ return new Promise((resolve, reject) => {
44
+ var fulfilled = (value) => {
45
+ try {
46
+ step(generator.next(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var rejected = (value) => {
52
+ try {
53
+ step(generator.throw(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
59
+ step((generator = generator.apply(__this, __arguments)).next());
60
+ });
61
+ };
62
+ var init_exports = {};
63
+ __export(init_exports, {
64
+ __resetTelemetryForTests: () => __resetTelemetryForTests,
65
+ flushTelemetry: () => flushTelemetry,
66
+ initTelemetry: () => initTelemetry,
67
+ isTelemetryInitialized: () => isTelemetryInitialized,
68
+ onTelemetryReady: () => onTelemetryReady
69
+ });
70
+ module.exports = __toCommonJS(init_exports);
71
+ var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
72
+ var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
73
+ var import_resources = require("@opentelemetry/resources");
74
+ var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
75
+ var import_api = require("@opentelemetry/api");
76
+ var import_core = require("@opentelemetry/core");
77
+ var import_uxStateSpanProcessor = require("./uxStateSpanProcessor.js");
78
+ var import_uxBaggagePropagator = require("./uxBaggagePropagator.js");
79
+ let initialized = false;
80
+ let tracerProvider;
81
+ const readyCallbacks = [];
82
+ function onTelemetryReady(cb) {
83
+ if (initialized) {
84
+ cb();
85
+ return;
86
+ }
87
+ readyCallbacks.push(cb);
88
+ }
89
+ function initTelemetry(opts) {
90
+ return __async(this, null, function* () {
91
+ if (initialized) return;
92
+ initialized = true;
93
+ const isWeb = opts.sdkType === "WEB" && typeof window !== "undefined";
94
+ if (isWeb && !opts.isPortal) {
95
+ try {
96
+ const { ZoneContextManager } = yield import("@opentelemetry/context-zone");
97
+ const zoneManager = new ZoneContextManager().enable();
98
+ import_api.context.setGlobalContextManager(zoneManager);
99
+ } catch (e) {
100
+ }
101
+ }
102
+ const resource = (0, import_resources.resourceFromAttributes)(__spreadValues(__spreadValues({
103
+ [import_semantic_conventions.ATTR_SERVICE_NAME]: opts.isPortal ? "para-portal" : "para-sdk",
104
+ [import_semantic_conventions.ATTR_SERVICE_VERSION]: opts.sdkVersion,
105
+ "para.platform": opts.sdkType
106
+ }, opts.partnerId ? { "para.partner_id": opts.partnerId } : {}), opts.resourceAttributes));
107
+ const exporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
108
+ url: opts.tunnelUrl
109
+ // No auth header — the tunnel is a dumb proxy. Per-IP rate limit + body cap on the
110
+ // BE side keep abuse contained.
111
+ });
112
+ const sampler = new import_sdk_trace_base.TraceIdRatioBasedSampler(Math.max(0, Math.min(1, opts.sampleRate)));
113
+ const spanProcessors = [new import_uxStateSpanProcessor.UxStateSpanProcessor(), new import_sdk_trace_base.BatchSpanProcessor(exporter)];
114
+ if (isWeb && opts.isPortal) {
115
+ try {
116
+ const { BeaconSpanProcessor } = yield import("./BeaconSpanProcessor.js");
117
+ spanProcessors.push(new BeaconSpanProcessor(opts.tunnelUrl));
118
+ } catch (e) {
119
+ }
120
+ }
121
+ tracerProvider = new import_sdk_trace_base.BasicTracerProvider({
122
+ resource,
123
+ sampler,
124
+ spanProcessors
125
+ });
126
+ import_api.trace.setGlobalTracerProvider(tracerProvider);
127
+ import_api.propagation.setGlobalPropagator(
128
+ new import_core.CompositePropagator({
129
+ propagators: [new import_core.W3CTraceContextPropagator(), new import_uxBaggagePropagator.UxBaggagePropagator()]
130
+ })
131
+ );
132
+ if (isWeb) {
133
+ try {
134
+ const [{ registerInstrumentations }, { FetchInstrumentation }, { XMLHttpRequestInstrumentation }] = yield Promise.all([
135
+ import("@opentelemetry/instrumentation"),
136
+ import("@opentelemetry/instrumentation-fetch"),
137
+ import("@opentelemetry/instrumentation-xml-http-request")
138
+ ]);
139
+ const propagateTraceHeaderCorsUrls = [
140
+ /^https?:\/\/api\.[^/]*getpara\.com/,
141
+ /^https?:\/\/api\.[^/]*usecapsule\.com/
142
+ ];
143
+ if (opts.isDev) {
144
+ propagateTraceHeaderCorsUrls.push(/^https?:\/\/localhost/);
145
+ }
146
+ registerInstrumentations({
147
+ // Both fetch and XHR are instrumented because axios uses XHR by default in
148
+ // the browser and `window.fetch` for first-party SDK code paths that opt in.
149
+ // Without XHR instrumentation, axios calls don't produce client spans AND
150
+ // Zone-tracked traceparent injection through our manual interceptor isn't
151
+ // always reliable on native async/await — the auto-instrumentation handles
152
+ // both span creation and W3C propagation in one pass.
153
+ instrumentations: [
154
+ new FetchInstrumentation({ propagateTraceHeaderCorsUrls }),
155
+ new XMLHttpRequestInstrumentation({ propagateTraceHeaderCorsUrls })
156
+ ]
157
+ });
158
+ } catch (e) {
159
+ }
160
+ }
161
+ while (readyCallbacks.length) {
162
+ const cb = readyCallbacks.shift();
163
+ try {
164
+ cb();
165
+ } catch (e) {
166
+ }
167
+ }
168
+ });
169
+ }
170
+ function isTelemetryInitialized() {
171
+ return initialized;
172
+ }
173
+ function flushTelemetry() {
174
+ return __async(this, null, function* () {
175
+ if (!tracerProvider) return;
176
+ try {
177
+ yield tracerProvider.forceFlush();
178
+ } catch (e) {
179
+ }
180
+ });
181
+ }
182
+ function __resetTelemetryForTests() {
183
+ initialized = false;
184
+ tracerProvider = void 0;
185
+ }
186
+ // Annotate the CommonJS export names for ESM import in node:
187
+ 0 && (module.exports = {
188
+ __resetTelemetryForTests,
189
+ flushTelemetry,
190
+ initTelemetry,
191
+ isTelemetryInitialized,
192
+ onTelemetryReady
193
+ });