@getpara/core-sdk 3.0.0-alpha.0 → 3.0.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.
- package/dist/cjs/ParaCore.js +436 -86
- package/dist/cjs/constants.js +1 -1
- package/dist/cjs/cryptography/utils.js +5 -2
- package/dist/cjs/errors.js +10 -0
- package/dist/cjs/external/userManagementClient.js +21 -4
- package/dist/cjs/index.js +67 -1
- package/dist/cjs/services/AuthService.js +66 -47
- package/dist/cjs/services/LoginFlowService.js +30 -27
- package/dist/cjs/services/PollingService.js +100 -75
- package/dist/cjs/services/PortalUrlService.js +112 -19
- package/dist/cjs/services/PregenWalletService.js +125 -76
- package/dist/cjs/services/SessionManagementService.js +15 -8
- package/dist/cjs/services/SignupFlowService.js +52 -47
- package/dist/cjs/services/VerificationFlowService.js +13 -10
- package/dist/cjs/services/WalletService.js +51 -36
- package/dist/cjs/shares/enclave.js +46 -26
- package/dist/cjs/state/CoreStateManager.js +17 -5
- package/dist/cjs/state/actors/setupPara.js +4 -1
- package/dist/cjs/state/machines/walletStateMachine.js +22 -0
- package/dist/cjs/telemetry/config.js +15 -0
- package/dist/cjs/telemetry/init.js +185 -0
- package/dist/cjs/telemetry/modalSession.js +54 -0
- package/dist/cjs/telemetry/session.js +39 -0
- package/dist/cjs/telemetry/tracer.js +126 -0
- package/dist/cjs/telemetry/uxAction.js +30 -0
- package/dist/cjs/telemetry/uxBaggagePropagator.js +58 -0
- package/dist/cjs/telemetry/uxState.js +46 -0
- package/dist/cjs/telemetry/uxStateSpanProcessor.js +51 -0
- package/dist/cjs/utils/configEncoding.js +98 -0
- package/dist/cjs/utils/deprecation.js +13 -13
- package/dist/cjs/utils/formatting.js +5 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/cjs/utils/partnerConfig.js +103 -0
- package/dist/cjs/utils/partnerConfigGating.js +83 -0
- package/dist/cjs/utils/stateErrorHelpers.js +6 -1
- package/dist/cjs/utils/url.js +10 -2
- package/dist/esm/ParaCore.js +441 -88
- package/dist/esm/constants.js +1 -1
- package/dist/esm/cryptography/utils.js +5 -2
- package/dist/esm/errors.js +9 -0
- package/dist/esm/external/userManagementClient.js +21 -4
- package/dist/esm/index.js +58 -4
- package/dist/esm/services/AuthService.js +66 -47
- package/dist/esm/services/LoginFlowService.js +30 -27
- package/dist/esm/services/PollingService.js +100 -75
- package/dist/esm/services/PortalUrlService.js +112 -19
- package/dist/esm/services/PregenWalletService.js +125 -76
- package/dist/esm/services/SessionManagementService.js +15 -8
- package/dist/esm/services/SignupFlowService.js +52 -47
- package/dist/esm/services/VerificationFlowService.js +13 -10
- package/dist/esm/services/WalletService.js +51 -36
- package/dist/esm/shares/enclave.js +46 -26
- package/dist/esm/state/CoreStateManager.js +17 -5
- package/dist/esm/state/actors/setupPara.js +4 -1
- package/dist/esm/state/machines/walletStateMachine.js +22 -0
- package/dist/esm/telemetry/config.js +0 -0
- package/dist/esm/telemetry/init.js +118 -0
- package/dist/esm/telemetry/modalSession.js +29 -0
- package/dist/esm/telemetry/session.js +16 -0
- package/dist/esm/telemetry/tracer.js +84 -0
- package/dist/esm/telemetry/uxAction.js +8 -0
- package/dist/esm/telemetry/uxBaggagePropagator.js +35 -0
- package/dist/esm/telemetry/uxState.js +21 -0
- package/dist/esm/telemetry/uxStateSpanProcessor.js +28 -0
- package/dist/esm/utils/configEncoding.js +45 -0
- package/dist/esm/utils/deprecation.js +11 -12
- package/dist/esm/utils/formatting.js +4 -0
- package/dist/esm/utils/index.js +6 -0
- package/dist/esm/utils/partnerConfig.js +67 -0
- package/dist/esm/utils/partnerConfigGating.js +61 -0
- package/dist/esm/utils/stateErrorHelpers.js +6 -1
- package/dist/esm/utils/url.js +10 -2
- package/dist/types/ParaCore.d.ts +101 -19
- package/dist/types/PlatformUtils.d.ts +1 -0
- package/dist/types/errors.d.ts +26 -0
- package/dist/types/external/userManagementClient.d.ts +2 -1
- package/dist/types/index.d.ts +15 -3
- package/dist/types/services/types/AuthServiceTypes.d.ts +10 -3
- package/dist/types/services/types/PortalUrlServiceTypes.d.ts +3 -3
- package/dist/types/services/types/WalletServiceTypes.d.ts +4 -0
- package/dist/types/state/actors/setupPara.d.ts +18 -0
- package/dist/types/state/machines/authStateMachine.d.ts +1 -1
- package/dist/types/state/machines/coreStateMachine.d.ts +30 -6
- package/dist/types/state/machines/walletStateMachine.d.ts +4 -0
- package/dist/types/state/types/core.d.ts +7 -1
- package/dist/types/telemetry/config.d.ts +4 -0
- package/dist/types/telemetry/init.d.ts +17 -0
- package/dist/types/telemetry/modalSession.d.ts +5 -0
- package/dist/types/telemetry/session.d.ts +2 -0
- package/dist/types/telemetry/tracer.d.ts +10 -0
- package/dist/types/telemetry/uxAction.d.ts +3 -0
- package/dist/types/telemetry/uxBaggagePropagator.d.ts +7 -0
- package/dist/types/telemetry/uxState.d.ts +8 -0
- package/dist/types/telemetry/uxStateSpanProcessor.d.ts +9 -0
- package/dist/types/types/config.d.ts +15 -3
- package/dist/types/types/coreApi.d.ts +7 -9
- package/dist/types/types/serviceInterfaces.d.ts +5 -3
- package/dist/types/types/util.d.ts +2 -15
- package/dist/types/utils/configEncoding.d.ts +51 -0
- package/dist/types/utils/deprecation.d.ts +3 -1
- package/dist/types/utils/formatting.d.ts +1 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/partnerConfig.d.ts +28 -0
- package/dist/types/utils/partnerConfigGating.d.ts +48 -0
- package/dist/types/utils/url.d.ts +3 -2
- package/package.json +14 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__async
|
|
3
3
|
} from "../chunk-7B52C2XE.js";
|
|
4
|
+
import { wrapWithSpan } from "../telemetry/tracer.js";
|
|
4
5
|
class EnclaveClient {
|
|
5
6
|
constructor({
|
|
6
7
|
userManagementClient,
|
|
@@ -172,40 +173,59 @@ ${exportedAsBase64}
|
|
|
172
173
|
* Persist key shares to the enclave
|
|
173
174
|
* @param shares Array of share data to persist
|
|
174
175
|
*/
|
|
176
|
+
// enclave.persist_shares wraps the encrypt + POST /enclave/key-shares pair so
|
|
177
|
+
// both the (CPU-bound) ECIES encryption and the network call show up under a
|
|
178
|
+
// named parent in the trace. Encryption can dominate the wall time so it's
|
|
179
|
+
// worth spelling out separately from the POST itself.
|
|
175
180
|
persistShares(shares) {
|
|
176
181
|
return __async(this, null, function* () {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
return wrapWithSpan(
|
|
183
|
+
"enclave.persist_shares",
|
|
184
|
+
() => __async(this, null, function* () {
|
|
185
|
+
const payload = {
|
|
186
|
+
shares,
|
|
187
|
+
jwt: this.retrieveJwt()
|
|
188
|
+
};
|
|
189
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
190
|
+
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
191
|
+
return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
|
|
192
|
+
}),
|
|
193
|
+
{ "enclave.share_count": shares.length }
|
|
194
|
+
);
|
|
184
195
|
});
|
|
185
196
|
}
|
|
186
197
|
/**
|
|
187
198
|
* Retrieve key shares from the enclave
|
|
188
199
|
* @param query Query parameters for finding shares (single query or array of queries)
|
|
189
200
|
*/
|
|
201
|
+
// enclave.retrieve_shares wraps the JWT issue + ECDH keypair gen + GET
|
|
202
|
+
// /enclave/key-shares + decrypt pipeline. The decrypt step can be slow on
|
|
203
|
+
// many-share accounts so a named span makes that latency easy to spot.
|
|
190
204
|
retrieveShares(query) {
|
|
191
205
|
return __async(this, null, function* () {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
return wrapWithSpan(
|
|
207
|
+
"enclave.retrieve_shares",
|
|
208
|
+
() => __async(this, null, function* () {
|
|
209
|
+
yield this.issueEnclaveJwt();
|
|
210
|
+
const frontendKeyPair = yield this.generateFrontendKeyPair();
|
|
211
|
+
const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
|
|
212
|
+
const fullQuery = query.map((q) => ({
|
|
213
|
+
userId: q.userId
|
|
214
|
+
}));
|
|
215
|
+
const payload = {
|
|
216
|
+
query: fullQuery,
|
|
217
|
+
responsePublicKey: responsePublicKeyPEM,
|
|
218
|
+
jwt: this.retrieveJwt()
|
|
219
|
+
};
|
|
220
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
221
|
+
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
222
|
+
const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
|
|
223
|
+
const encryptedResponse = JSON.parse(response.payload);
|
|
224
|
+
const decryptedData = yield this.decryptForFrontend(encryptedResponse);
|
|
225
|
+
return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
|
|
226
|
+
}),
|
|
227
|
+
{ "enclave.query_count": query.length }
|
|
228
|
+
);
|
|
209
229
|
});
|
|
210
230
|
}
|
|
211
231
|
deleteShares() {
|
|
@@ -247,13 +267,13 @@ ${exportedAsBase64}
|
|
|
247
267
|
};
|
|
248
268
|
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
249
269
|
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
250
|
-
const response = yield this.userManagementClient.getPregenShares(encryptedPayloadStr);
|
|
270
|
+
const response = yield this.userManagementClient.getPregenShares(encryptedPayloadStr, query.walletIds);
|
|
251
271
|
if (!response.payload) {
|
|
252
272
|
return [];
|
|
253
273
|
}
|
|
254
274
|
const encryptedResponse = JSON.parse(response.payload);
|
|
255
275
|
const decryptedData = yield this.decryptForFrontend(encryptedResponse);
|
|
256
|
-
return decryptedData.shares;
|
|
276
|
+
return Array.isArray(decryptedData == null ? void 0 : decryptedData.shares) ? decryptedData.shares : [];
|
|
257
277
|
} catch (error) {
|
|
258
278
|
throw new Error(
|
|
259
279
|
`Failed to retrieve pregen shares for user ${query.userId}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
@@ -80,7 +80,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
80
80
|
* Extracts all data needed by UI consumers from authStateResult.
|
|
81
81
|
*/
|
|
82
82
|
computeAuthStateInfo(authContext, walletContext) {
|
|
83
|
-
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;
|
|
83
|
+
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;
|
|
84
84
|
const defaultAuthStateInfo = {
|
|
85
85
|
userId: null,
|
|
86
86
|
isPasskeySupported: false,
|
|
@@ -98,6 +98,9 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
98
98
|
passkeyId: null,
|
|
99
99
|
verificationUrl: null,
|
|
100
100
|
verificationFullUrl: null,
|
|
101
|
+
deliveryChannel: null,
|
|
102
|
+
fallbackUsed: false,
|
|
103
|
+
fallbackChannel: null,
|
|
101
104
|
externalWalletVerification: null,
|
|
102
105
|
recoverySecret: null,
|
|
103
106
|
isNewUser: false
|
|
@@ -137,6 +140,9 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
137
140
|
let verificationFullUrl = null;
|
|
138
141
|
let passkeyHints = null;
|
|
139
142
|
let passkeyId = null;
|
|
143
|
+
let deliveryChannel = null;
|
|
144
|
+
let fallbackUsed = false;
|
|
145
|
+
let fallbackChannel = null;
|
|
140
146
|
if (stage === "login") {
|
|
141
147
|
const loginState = authStateResult;
|
|
142
148
|
const authMethods = (_j = loginState.loginAuthMethods) != null ? _j : [];
|
|
@@ -170,6 +176,9 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
170
176
|
const verifyState = authStateResult;
|
|
171
177
|
verificationUrl = (_C = verifyState.loginUrl) != null ? _C : null;
|
|
172
178
|
verificationFullUrl = (_D = verifyState.loginFullUrl) != null ? _D : null;
|
|
179
|
+
deliveryChannel = (_E = verifyState.deliveryChannel) != null ? _E : null;
|
|
180
|
+
fallbackUsed = (_F = verifyState.fallbackUsed) != null ? _F : false;
|
|
181
|
+
fallbackChannel = (_G = verifyState.fallbackChannel) != null ? _G : null;
|
|
173
182
|
}
|
|
174
183
|
return {
|
|
175
184
|
userId,
|
|
@@ -188,10 +197,13 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
188
197
|
passkeyId,
|
|
189
198
|
verificationUrl,
|
|
190
199
|
verificationFullUrl,
|
|
200
|
+
deliveryChannel,
|
|
201
|
+
fallbackUsed,
|
|
202
|
+
fallbackChannel,
|
|
191
203
|
externalWalletVerification: externalWalletVerification ? {
|
|
192
|
-
signatureVerificationMessage: (
|
|
193
|
-
walletAddress: (
|
|
194
|
-
walletType: (
|
|
204
|
+
signatureVerificationMessage: (_H = externalWalletVerification.signatureVerificationMessage) != null ? _H : "",
|
|
205
|
+
walletAddress: (_J = (_I = externalWalletVerification.externalWallet) == null ? void 0 : _I.address) != null ? _J : "",
|
|
206
|
+
walletType: (_L = (_K = externalWalletVerification.externalWallet) == null ? void 0 : _K.type) != null ? _L : ""
|
|
195
207
|
} : null,
|
|
196
208
|
recoverySecret,
|
|
197
209
|
isNewUser
|
|
@@ -253,7 +265,7 @@ const _CoreStateManager = class _CoreStateManager {
|
|
|
253
265
|
}
|
|
254
266
|
authStateInfoEqual(a, b) {
|
|
255
267
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
256
|
-
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(
|
|
268
|
+
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(
|
|
257
269
|
(hint, i) => hint.useragent === b.passkeyHints[i].useragent && hint.aaguid === b.passkeyHints[i].aaguid
|
|
258
270
|
);
|
|
259
271
|
}
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
} from "../../chunk-7B52C2XE.js";
|
|
4
4
|
import { fromPromise } from "xstate";
|
|
5
5
|
const createSetupParaActor = (paraCoreInterface) => fromPromise(() => __async(void 0, null, function* () {
|
|
6
|
-
|
|
6
|
+
const eagerPartnerLoad = paraCoreInterface.isPortal() ? Promise.resolve() : paraCoreInterface.sessionManagementService.touchSession().catch((e) => {
|
|
7
|
+
paraCoreInterface.devLog("setupPara: eager partner load via touchSession failed; will retry lazily", e);
|
|
8
|
+
});
|
|
9
|
+
yield Promise.all([paraCoreInterface.setup(), eagerPartnerLoad]);
|
|
7
10
|
}));
|
|
8
11
|
export {
|
|
9
12
|
createSetupParaActor
|
|
@@ -161,6 +161,28 @@ function createWalletStateMachine(paraCoreInterface) {
|
|
|
161
161
|
]
|
|
162
162
|
},
|
|
163
163
|
needs_wallets: {
|
|
164
|
+
// `needs_wallets` is otherwise a passive state that waits for the consumer
|
|
165
|
+
// to dispatch `WAIT_FOR_WALLET_CREATION`. That contract is fine for
|
|
166
|
+
// `isNewUser` reaching this state without auto-create (`checking_wallet_state`
|
|
167
|
+
// guard at line ~127), but it traps existing users who landed here via
|
|
168
|
+
// `waiting_for_wallets` COMPLETE with `needsWallet=true` — i.e., an
|
|
169
|
+
// authenticated user whose wallets don't satisfy the partner's
|
|
170
|
+
// `supportedWalletTypes` (e.g. EVM-only user logging into a Solana-only
|
|
171
|
+
// partner). Their auth flow set `shouldAutoCreateWallets: true` via
|
|
172
|
+
// `authenticateWithOAuth` / `authenticateWithEmailOrPhone`, but the
|
|
173
|
+
// existing `claiming_wallets` guard requires `isNewUser ||
|
|
174
|
+
// shouldClaimGuestWallets`, neither of which is true for them, so
|
|
175
|
+
// auto-create silently never happens.
|
|
176
|
+
//
|
|
177
|
+
// When `shouldAutoCreate` is true, route directly to `creating_wallets`.
|
|
178
|
+
// `createWalletPerType` is partner-aware via `#getMissingTypes`, so it
|
|
179
|
+
// provisions exactly the missing required types (no duplicates).
|
|
180
|
+
always: [
|
|
181
|
+
{
|
|
182
|
+
target: "creating_wallets",
|
|
183
|
+
guard: "shouldAutoCreate"
|
|
184
|
+
}
|
|
185
|
+
],
|
|
164
186
|
on: {
|
|
165
187
|
WAIT_FOR_WALLET_CREATION: {
|
|
166
188
|
target: "claiming_wallets",
|
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../chunk-7B52C2XE.js";
|
|
5
|
+
import { BatchSpanProcessor, BasicTracerProvider, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-base";
|
|
6
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
7
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
8
|
+
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
|
|
9
|
+
import { context, propagation, trace } from "@opentelemetry/api";
|
|
10
|
+
import { CompositePropagator, W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
11
|
+
import { UxStateSpanProcessor } from "./uxStateSpanProcessor.js";
|
|
12
|
+
import { UxBaggagePropagator } from "./uxBaggagePropagator.js";
|
|
13
|
+
let initialized = false;
|
|
14
|
+
let tracerProvider;
|
|
15
|
+
const readyCallbacks = [];
|
|
16
|
+
function onTelemetryReady(cb) {
|
|
17
|
+
if (initialized) {
|
|
18
|
+
cb();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
readyCallbacks.push(cb);
|
|
22
|
+
}
|
|
23
|
+
function initTelemetry(opts) {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
if (initialized) return;
|
|
26
|
+
initialized = true;
|
|
27
|
+
const isWeb = opts.sdkType === "WEB" && typeof window !== "undefined";
|
|
28
|
+
if (isWeb && !opts.isPortal) {
|
|
29
|
+
try {
|
|
30
|
+
const { ZoneContextManager } = yield import("@opentelemetry/context-zone");
|
|
31
|
+
const zoneManager = new ZoneContextManager().enable();
|
|
32
|
+
context.setGlobalContextManager(zoneManager);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const resource = resourceFromAttributes(__spreadValues(__spreadValues({
|
|
37
|
+
[ATTR_SERVICE_NAME]: opts.isPortal ? "para-portal" : "para-sdk",
|
|
38
|
+
[ATTR_SERVICE_VERSION]: opts.sdkVersion,
|
|
39
|
+
"para.platform": opts.sdkType
|
|
40
|
+
}, opts.partnerId ? { "para.partner_id": opts.partnerId } : {}), opts.resourceAttributes));
|
|
41
|
+
const exporter = new OTLPTraceExporter({
|
|
42
|
+
url: opts.tunnelUrl
|
|
43
|
+
// No auth header — the tunnel is a dumb proxy. Per-IP rate limit + body cap on the
|
|
44
|
+
// BE side keep abuse contained.
|
|
45
|
+
});
|
|
46
|
+
const sampler = new TraceIdRatioBasedSampler(Math.max(0, Math.min(1, opts.sampleRate)));
|
|
47
|
+
tracerProvider = new BasicTracerProvider({
|
|
48
|
+
resource,
|
|
49
|
+
sampler,
|
|
50
|
+
spanProcessors: [new UxStateSpanProcessor(), new BatchSpanProcessor(exporter)]
|
|
51
|
+
});
|
|
52
|
+
trace.setGlobalTracerProvider(tracerProvider);
|
|
53
|
+
propagation.setGlobalPropagator(
|
|
54
|
+
new CompositePropagator({
|
|
55
|
+
propagators: [new W3CTraceContextPropagator(), new UxBaggagePropagator()]
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
if (isWeb) {
|
|
59
|
+
try {
|
|
60
|
+
const [{ registerInstrumentations }, { FetchInstrumentation }, { XMLHttpRequestInstrumentation }] = yield Promise.all([
|
|
61
|
+
import("@opentelemetry/instrumentation"),
|
|
62
|
+
import("@opentelemetry/instrumentation-fetch"),
|
|
63
|
+
import("@opentelemetry/instrumentation-xml-http-request")
|
|
64
|
+
]);
|
|
65
|
+
const propagateTraceHeaderCorsUrls = [
|
|
66
|
+
/^https?:\/\/api\.[^/]*getpara\.com/,
|
|
67
|
+
/^https?:\/\/api\.[^/]*usecapsule\.com/
|
|
68
|
+
];
|
|
69
|
+
if (opts.isDev) {
|
|
70
|
+
propagateTraceHeaderCorsUrls.push(/^https?:\/\/localhost/);
|
|
71
|
+
}
|
|
72
|
+
registerInstrumentations({
|
|
73
|
+
// Both fetch and XHR are instrumented because axios uses XHR by default in
|
|
74
|
+
// the browser and `window.fetch` for first-party SDK code paths that opt in.
|
|
75
|
+
// Without XHR instrumentation, axios calls don't produce client spans AND
|
|
76
|
+
// Zone-tracked traceparent injection through our manual interceptor isn't
|
|
77
|
+
// always reliable on native async/await — the auto-instrumentation handles
|
|
78
|
+
// both span creation and W3C propagation in one pass.
|
|
79
|
+
instrumentations: [
|
|
80
|
+
new FetchInstrumentation({ propagateTraceHeaderCorsUrls }),
|
|
81
|
+
new XMLHttpRequestInstrumentation({ propagateTraceHeaderCorsUrls })
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
} catch (e) {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
while (readyCallbacks.length) {
|
|
88
|
+
const cb = readyCallbacks.shift();
|
|
89
|
+
try {
|
|
90
|
+
cb();
|
|
91
|
+
} catch (e) {
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function isTelemetryInitialized() {
|
|
97
|
+
return initialized;
|
|
98
|
+
}
|
|
99
|
+
function flushTelemetry() {
|
|
100
|
+
return __async(this, null, function* () {
|
|
101
|
+
if (!tracerProvider) return;
|
|
102
|
+
try {
|
|
103
|
+
yield tracerProvider.forceFlush();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function __resetTelemetryForTests() {
|
|
109
|
+
initialized = false;
|
|
110
|
+
tracerProvider = void 0;
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
__resetTelemetryForTests,
|
|
114
|
+
flushTelemetry,
|
|
115
|
+
initTelemetry,
|
|
116
|
+
isTelemetryInitialized,
|
|
117
|
+
onTelemetryReady
|
|
118
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
import { context as otelContext, trace } from "@opentelemetry/api";
|
|
3
|
+
const TRACER_NAME = "para-sdk";
|
|
4
|
+
let activeSpan;
|
|
5
|
+
let activeCtx;
|
|
6
|
+
function startModalSession() {
|
|
7
|
+
if (activeSpan) return;
|
|
8
|
+
activeSpan = trace.getTracer(TRACER_NAME).startSpan("ui.modal.session");
|
|
9
|
+
activeCtx = trace.setSpan(otelContext.active(), activeSpan);
|
|
10
|
+
}
|
|
11
|
+
function endModalSession() {
|
|
12
|
+
activeSpan == null ? void 0 : activeSpan.end();
|
|
13
|
+
activeSpan = void 0;
|
|
14
|
+
activeCtx = void 0;
|
|
15
|
+
}
|
|
16
|
+
function getModalSessionContext() {
|
|
17
|
+
return activeCtx;
|
|
18
|
+
}
|
|
19
|
+
function __resetModalSessionForTests() {
|
|
20
|
+
activeSpan == null ? void 0 : activeSpan.end();
|
|
21
|
+
activeSpan = void 0;
|
|
22
|
+
activeCtx = void 0;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
__resetModalSessionForTests,
|
|
26
|
+
endModalSession,
|
|
27
|
+
getModalSessionContext,
|
|
28
|
+
startModalSession
|
|
29
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
3
|
+
let sessionId;
|
|
4
|
+
function getOrCreateSessionId() {
|
|
5
|
+
if (!sessionId) {
|
|
6
|
+
sessionId = uuidv4();
|
|
7
|
+
}
|
|
8
|
+
return sessionId;
|
|
9
|
+
}
|
|
10
|
+
function __resetSessionForTests() {
|
|
11
|
+
sessionId = void 0;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
__resetSessionForTests,
|
|
15
|
+
getOrCreateSessionId
|
|
16
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "../chunk-7B52C2XE.js";
|
|
4
|
+
import {
|
|
5
|
+
context as otelContext,
|
|
6
|
+
propagation,
|
|
7
|
+
SpanStatusCode,
|
|
8
|
+
trace
|
|
9
|
+
} from "@opentelemetry/api";
|
|
10
|
+
import { getModalSessionContext } from "./modalSession.js";
|
|
11
|
+
const TRACER_NAME = "para-sdk";
|
|
12
|
+
function getTracer() {
|
|
13
|
+
return trace.getTracer(TRACER_NAME);
|
|
14
|
+
}
|
|
15
|
+
let defaultParentContext;
|
|
16
|
+
function setDefaultParentContext(ctx) {
|
|
17
|
+
defaultParentContext = ctx;
|
|
18
|
+
}
|
|
19
|
+
function getDefaultParentContext() {
|
|
20
|
+
return defaultParentContext;
|
|
21
|
+
}
|
|
22
|
+
function wrapWithSpan(name, fn, attributes) {
|
|
23
|
+
return __async(this, null, function* () {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const active = otelContext.active();
|
|
26
|
+
const activeSpan = trace.getSpan(active);
|
|
27
|
+
const parentCtx = activeSpan ? active : (_b = (_a = getModalSessionContext()) != null ? _a : defaultParentContext) != null ? _b : active;
|
|
28
|
+
return otelContext.with(
|
|
29
|
+
parentCtx,
|
|
30
|
+
() => getTracer().startActiveSpan(name, { attributes }, (span) => __async(this, null, function* () {
|
|
31
|
+
try {
|
|
32
|
+
const result = yield fn(span);
|
|
33
|
+
return result;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
span.recordException(err);
|
|
36
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
37
|
+
throw err;
|
|
38
|
+
} finally {
|
|
39
|
+
span.end();
|
|
40
|
+
}
|
|
41
|
+
}))
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function extractTraceContextFromUrl(search) {
|
|
46
|
+
return propagation.extract(otelContext.active(), getUrlTraceCarrier(search));
|
|
47
|
+
}
|
|
48
|
+
function getUrlTraceCarrier(search) {
|
|
49
|
+
const url = search != null ? search : typeof window !== "undefined" ? window.location.search : "";
|
|
50
|
+
const params = new URLSearchParams(url);
|
|
51
|
+
const carrier = {};
|
|
52
|
+
const tp = params.get("traceparent");
|
|
53
|
+
const ts = params.get("tracestate");
|
|
54
|
+
if (tp) carrier.traceparent = tp;
|
|
55
|
+
if (ts) carrier.tracestate = ts;
|
|
56
|
+
return carrier;
|
|
57
|
+
}
|
|
58
|
+
function wrapWithSpanInContext(parentContext, name, fn) {
|
|
59
|
+
return __async(this, null, function* () {
|
|
60
|
+
return otelContext.with(
|
|
61
|
+
parentContext,
|
|
62
|
+
() => wrapWithSpan(name, (span) => {
|
|
63
|
+
const traceHeaders = {};
|
|
64
|
+
propagation.inject(otelContext.active(), traceHeaders, {
|
|
65
|
+
set: (carrier, key, value) => {
|
|
66
|
+
carrier[key] = value;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return fn(span, traceHeaders);
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
import { SpanStatusCode as SpanStatusCode2 } from "@opentelemetry/api";
|
|
75
|
+
export {
|
|
76
|
+
SpanStatusCode2 as SpanStatusCode,
|
|
77
|
+
extractTraceContextFromUrl,
|
|
78
|
+
getDefaultParentContext,
|
|
79
|
+
getTracer,
|
|
80
|
+
getUrlTraceCarrier,
|
|
81
|
+
setDefaultParentContext,
|
|
82
|
+
wrapWithSpan,
|
|
83
|
+
wrapWithSpanInContext
|
|
84
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__privateAdd,
|
|
3
|
+
__privateGet
|
|
4
|
+
} from "../chunk-7B52C2XE.js";
|
|
5
|
+
var _inner;
|
|
6
|
+
import {
|
|
7
|
+
propagation
|
|
8
|
+
} from "@opentelemetry/api";
|
|
9
|
+
import { W3CBaggagePropagator } from "@opentelemetry/core";
|
|
10
|
+
import { getUxState } from "./uxState.js";
|
|
11
|
+
import { getOrCreateSessionId } from "./session.js";
|
|
12
|
+
class UxBaggagePropagator {
|
|
13
|
+
constructor() {
|
|
14
|
+
__privateAdd(this, _inner, new W3CBaggagePropagator());
|
|
15
|
+
}
|
|
16
|
+
inject(ctx, carrier, setter) {
|
|
17
|
+
var _a;
|
|
18
|
+
const state = getUxState();
|
|
19
|
+
let bag = (_a = propagation.getBaggage(ctx)) != null ? _a : propagation.createBaggage();
|
|
20
|
+
bag = bag.setEntry("ui.session_id", { value: getOrCreateSessionId() });
|
|
21
|
+
if (state.view) bag = bag.setEntry("ui.view", { value: state.view });
|
|
22
|
+
if (state.lastInteraction) bag = bag.setEntry("ui.last_interaction", { value: state.lastInteraction });
|
|
23
|
+
__privateGet(this, _inner).inject(propagation.setBaggage(ctx, bag), carrier, setter);
|
|
24
|
+
}
|
|
25
|
+
extract(ctx, carrier, getter) {
|
|
26
|
+
return __privateGet(this, _inner).extract(ctx, carrier, getter);
|
|
27
|
+
}
|
|
28
|
+
fields() {
|
|
29
|
+
return __privateGet(this, _inner).fields();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
_inner = new WeakMap();
|
|
33
|
+
export {
|
|
34
|
+
UxBaggagePropagator
|
|
35
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
const state = {};
|
|
3
|
+
function getUxState() {
|
|
4
|
+
return state;
|
|
5
|
+
}
|
|
6
|
+
function setCurrentView(view) {
|
|
7
|
+
state.view = view;
|
|
8
|
+
}
|
|
9
|
+
function setLastInteraction(targetId) {
|
|
10
|
+
state.lastInteraction = targetId;
|
|
11
|
+
}
|
|
12
|
+
function __resetUxStateForTests() {
|
|
13
|
+
state.view = void 0;
|
|
14
|
+
state.lastInteraction = void 0;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
__resetUxStateForTests,
|
|
18
|
+
getUxState,
|
|
19
|
+
setCurrentView,
|
|
20
|
+
setLastInteraction
|
|
21
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
import { getUxState } from "./uxState.js";
|
|
3
|
+
import { getOrCreateSessionId } from "./session.js";
|
|
4
|
+
let currentUserId;
|
|
5
|
+
function setCurrentUserId(userId) {
|
|
6
|
+
currentUserId = userId;
|
|
7
|
+
}
|
|
8
|
+
class UxStateSpanProcessor {
|
|
9
|
+
onStart(span, _parentContext) {
|
|
10
|
+
const state = getUxState();
|
|
11
|
+
span.setAttribute("ui.session_id", getOrCreateSessionId());
|
|
12
|
+
if (currentUserId) span.setAttribute("user.id", currentUserId);
|
|
13
|
+
if (state.view) span.setAttribute("ui.view", state.view);
|
|
14
|
+
if (state.lastInteraction) span.setAttribute("ui.last_interaction", state.lastInteraction);
|
|
15
|
+
}
|
|
16
|
+
onEnd() {
|
|
17
|
+
}
|
|
18
|
+
forceFlush() {
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
shutdown() {
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
UxStateSpanProcessor,
|
|
27
|
+
setCurrentUserId
|
|
28
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "../chunk-7B52C2XE.js";
|
|
4
|
+
import { Buffer } from "buffer";
|
|
5
|
+
import base64url from "base64url";
|
|
6
|
+
const ENCODED_CONFIG_VERSION = 1;
|
|
7
|
+
function isCompressionStreamSupported() {
|
|
8
|
+
return typeof CompressionStream !== "undefined" && typeof DecompressionStream !== "undefined";
|
|
9
|
+
}
|
|
10
|
+
function encodeConfigParams(config) {
|
|
11
|
+
return __async(this, null, function* () {
|
|
12
|
+
if (!isCompressionStreamSupported()) return null;
|
|
13
|
+
try {
|
|
14
|
+
const json = JSON.stringify(config);
|
|
15
|
+
const stream = new Blob([json]).stream().pipeThrough(new CompressionStream("gzip"));
|
|
16
|
+
const compressed = new Uint8Array(yield new Response(stream).arrayBuffer());
|
|
17
|
+
return base64url.encode(Buffer.from(compressed));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function tryDecodeConfig(s) {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
if (!isCompressionStreamSupported()) return null;
|
|
26
|
+
if (!/^[A-Za-z0-9_-]+$/.test(s)) return null;
|
|
27
|
+
try {
|
|
28
|
+
const compressed = base64url.toBuffer(s);
|
|
29
|
+
const stream = new Blob([compressed]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
30
|
+
const json = yield new Response(stream).text();
|
|
31
|
+
const parsed = JSON.parse(json);
|
|
32
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
33
|
+
if (parsed.v !== ENCODED_CONFIG_VERSION) return null;
|
|
34
|
+
return parsed;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
ENCODED_CONFIG_VERSION,
|
|
42
|
+
encodeConfigParams,
|
|
43
|
+
isCompressionStreamSupported,
|
|
44
|
+
tryDecodeConfig
|
|
45
|
+
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import "../chunk-7B52C2XE.js";
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
console.warn(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
\u2192 Guide: ${MIGRATION_GUIDE_URL}`
|
|
12
|
-
);
|
|
2
|
+
const warnedScopedKeys = /* @__PURE__ */ new Set();
|
|
3
|
+
function warnOnce(scope, key, message) {
|
|
4
|
+
const fullKey = `${scope}::${key}`;
|
|
5
|
+
if (warnedScopedKeys.has(fullKey)) return;
|
|
6
|
+
warnedScopedKeys.add(fullKey);
|
|
7
|
+
console.warn(`[Para] ${message}`);
|
|
8
|
+
}
|
|
9
|
+
function _resetWarnOnceForTests() {
|
|
10
|
+
warnedScopedKeys.clear();
|
|
13
11
|
}
|
|
14
12
|
export {
|
|
15
|
-
|
|
13
|
+
_resetWarnOnceForTests,
|
|
14
|
+
warnOnce
|
|
16
15
|
};
|
|
@@ -10,6 +10,9 @@ function hexStringToBase64(hexString) {
|
|
|
10
10
|
}
|
|
11
11
|
return Buffer.from(hexString, "hex").toString("base64");
|
|
12
12
|
}
|
|
13
|
+
function base58ToBase64(base58Str) {
|
|
14
|
+
return Buffer.from(base58Decode(base58Str)).toString("base64");
|
|
15
|
+
}
|
|
13
16
|
function hexToSignature(hexSig) {
|
|
14
17
|
return {
|
|
15
18
|
r: `0x${hexSig.slice(2, 66)}`,
|
|
@@ -160,6 +163,7 @@ function truncateAddress(str, addressType, {
|
|
|
160
163
|
return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
|
|
161
164
|
}
|
|
162
165
|
export {
|
|
166
|
+
base58ToBase64,
|
|
163
167
|
compressPubkey,
|
|
164
168
|
decimalToHex,
|
|
165
169
|
getCosmosAddress,
|