@learncard/sss-key-manager 0.1.14 → 0.1.16

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.
@@ -6,11 +6,7 @@ var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
8
  var __commonJS = (cb, mod) => function __require() {
9
- try {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
- } catch (e) {
12
- throw mod = 0, e;
13
- }
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
10
  };
15
11
  var __copyProps = (to, from, except, desc) => {
16
12
  if (from && typeof from === "object" || typeof from === "function") {
@@ -17350,7 +17346,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
17350
17346
  includePersonalData: external_exports.boolean().optional().default(false),
17351
17347
  format: external_exports.enum(["prompt", "structured"]).optional().default("prompt"),
17352
17348
  instructions: external_exports.string().optional(),
17353
- detailLevel: external_exports.enum(["compact", "expanded"]).optional().default("compact")
17349
+ detailLevel: external_exports.enum(["compact", "expanded"]).optional().default("compact"),
17350
+ waitForSync: external_exports.boolean().optional().default(false)
17354
17351
  });
17355
17352
  var SummaryCredentialKeywordValidator = external_exports.object({
17356
17353
  occupations: external_exports.array(external_exports.string()).nullable(),
@@ -19032,7 +19029,15 @@ function createSSSStrategy(config) {
19032
19029
  };
19033
19030
  },
19034
19031
  async storeAuthShare(token, providerType, authShare, primaryDid, didAuthVp) {
19035
- const { shareVersion } = await putAuthShare(serverUrl, token, providerType, authShare, primaryDid, didAuthVp, tenantId);
19032
+ const { shareVersion } = await putAuthShare(
19033
+ serverUrl,
19034
+ token,
19035
+ providerType,
19036
+ authShare,
19037
+ primaryDid,
19038
+ didAuthVp,
19039
+ tenantId
19040
+ );
19036
19041
  await storage.storeShareVersion(shareVersion, activeStorageId);
19037
19042
  lastShareVersion = shareVersion;
19038
19043
  },
@@ -19125,7 +19130,14 @@ function createSSSStrategy(config) {
19125
19130
  throw new Error("No auth share found on server");
19126
19131
  }
19127
19132
  const authShareStr = typeof serverData.authShare === "object" ? serverData.authShare.encryptedData : serverData.authShare;
19128
- const privateKey = await reconstructFromShares([recoveryShare, authShareStr]);
19133
+ let privateKey;
19134
+ try {
19135
+ privateKey = await reconstructFromShares([recoveryShare, authShareStr]);
19136
+ } catch {
19137
+ throw new Error(
19138
+ "Recovery produced an incorrect key. The recovery key may be outdated. Please try a different recovery method."
19139
+ );
19140
+ }
19129
19141
  const primaryDid = serverData.primaryDid || "";
19130
19142
  if (primaryDid && didFromPrivateKey) {
19131
19143
  const derivedDid = await didFromPrivateKey(privateKey);
@@ -19156,13 +19168,44 @@ function createSSSStrategy(config) {
19156
19168
  const { shares } = await splitAndVerify(privateKey);
19157
19169
  lastEmailShare = shares.emailShare;
19158
19170
  await storage.storeDeviceShare(shares.deviceShare, activeStorageId);
19159
- const serverData = await fetchAuthShareRaw(serverUrl, token, providerType, void 0, tenantId);
19171
+ const serverData = await fetchAuthShareRaw(
19172
+ serverUrl,
19173
+ token,
19174
+ providerType,
19175
+ void 0,
19176
+ tenantId
19177
+ );
19160
19178
  const primaryDid = serverData?.primaryDid || "";
19161
- const { shareVersion } = await putAuthShare(serverUrl, token, providerType, shares.authShare, primaryDid, vpJwt, tenantId);
19179
+ const { shareVersion } = await putAuthShare(
19180
+ serverUrl,
19181
+ token,
19182
+ providerType,
19183
+ shares.authShare,
19184
+ primaryDid,
19185
+ vpJwt,
19186
+ tenantId
19187
+ );
19162
19188
  await storage.storeShareVersion(shareVersion, activeStorageId);
19163
19189
  if (enableEmailBackupShare && input.method !== "email" && lastEmailShare) {
19164
- const resend = hasRecoveryEmail ? sendEmailShareToRecoveryEmail(serverUrl, token, providerType, lastEmailShare, shareVersion, tenantId) : authUser?.email ? sendEmailBackupShare(serverUrl, token, providerType, lastEmailShare, authUser.email, shareVersion, tenantId) : Promise.resolve();
19165
- resend.catch((e) => console.warn("Email backup share re-send failed (non-fatal):", e));
19190
+ const resend = hasRecoveryEmail ? sendEmailShareToRecoveryEmail(
19191
+ serverUrl,
19192
+ token,
19193
+ providerType,
19194
+ lastEmailShare,
19195
+ shareVersion,
19196
+ tenantId
19197
+ ) : authUser?.email ? sendEmailBackupShare(
19198
+ serverUrl,
19199
+ token,
19200
+ providerType,
19201
+ lastEmailShare,
19202
+ authUser.email,
19203
+ shareVersion,
19204
+ tenantId
19205
+ ) : Promise.resolve();
19206
+ resend.catch(
19207
+ (e) => console.warn("Email backup share re-send failed (non-fatal):", e)
19208
+ );
19166
19209
  lastEmailShare = void 0;
19167
19210
  }
19168
19211
  switch (input.method) {
@@ -19172,27 +19215,44 @@ function createSSSStrategy(config) {
19172
19215
  shares.recoveryShare,
19173
19216
  credential.credentialId
19174
19217
  );
19175
- await postRecoveryMethod(serverUrl, token, providerType, {
19176
- type: "passkey",
19177
- encryptedShare: {
19178
- encryptedData: encryptedShare.encryptedData,
19179
- iv: encryptedShare.iv
19218
+ await postRecoveryMethod(
19219
+ serverUrl,
19220
+ token,
19221
+ providerType,
19222
+ {
19223
+ type: "passkey",
19224
+ encryptedShare: {
19225
+ encryptedData: encryptedShare.encryptedData,
19226
+ iv: encryptedShare.iv
19227
+ },
19228
+ credentialId: credential.credentialId,
19229
+ shareVersion
19180
19230
  },
19181
- credentialId: credential.credentialId,
19182
- shareVersion
19183
- }, vpJwt, tenantId);
19231
+ vpJwt,
19232
+ tenantId
19233
+ );
19184
19234
  return { method: "passkey", credentialId: credential.credentialId };
19185
19235
  }
19186
19236
  case "phrase": {
19187
19237
  const phrase = await shareToRecoveryPhrase(shares.recoveryShare);
19188
- await postRecoveryMethod(serverUrl, token, providerType, {
19189
- type: "phrase",
19190
- shareVersion
19191
- }, vpJwt, tenantId);
19238
+ await postRecoveryMethod(
19239
+ serverUrl,
19240
+ token,
19241
+ providerType,
19242
+ {
19243
+ type: "phrase",
19244
+ shareVersion
19245
+ },
19246
+ vpJwt,
19247
+ tenantId
19248
+ );
19192
19249
  return { method: "phrase", phrase };
19193
19250
  }
19194
19251
  case "backup": {
19195
- const encrypted = await encryptWithPassword(shares.recoveryShare, input.password);
19252
+ const encrypted = await encryptWithPassword(
19253
+ shares.recoveryShare,
19254
+ input.password
19255
+ );
19196
19256
  const backupFile = {
19197
19257
  version: 1,
19198
19258
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -19205,10 +19265,17 @@ function createSSSStrategy(config) {
19205
19265
  kdfParams: encrypted.kdfParams
19206
19266
  }
19207
19267
  };
19208
- await postRecoveryMethod(serverUrl, token, providerType, {
19209
- type: "backup",
19210
- shareVersion
19211
- }, vpJwt, tenantId);
19268
+ await postRecoveryMethod(
19269
+ serverUrl,
19270
+ token,
19271
+ providerType,
19272
+ {
19273
+ type: "backup",
19274
+ shareVersion
19275
+ },
19276
+ vpJwt,
19277
+ tenantId
19278
+ );
19212
19279
  return { method: "backup", backupFile };
19213
19280
  }
19214
19281
  case "email": {
@@ -19220,10 +19287,17 @@ function createSSSStrategy(config) {
19220
19287
  shareVersion,
19221
19288
  tenantId
19222
19289
  );
19223
- await postRecoveryMethod(serverUrl, token, providerType, {
19224
- type: "email",
19225
- shareVersion
19226
- }, vpJwt, tenantId);
19290
+ await postRecoveryMethod(
19291
+ serverUrl,
19292
+ token,
19293
+ providerType,
19294
+ {
19295
+ type: "email",
19296
+ shareVersion
19297
+ },
19298
+ vpJwt,
19299
+ tenantId
19300
+ );
19227
19301
  hasRecoveryEmail = true;
19228
19302
  return { method: "email" };
19229
19303
  }
@@ -19231,7 +19305,13 @@ function createSSSStrategy(config) {
19231
19305
  },
19232
19306
  async getAvailableRecoveryMethods(token, providerType) {
19233
19307
  try {
19234
- const serverData = await fetchAuthShareRaw(serverUrl, token, providerType, void 0, tenantId);
19308
+ const serverData = await fetchAuthShareRaw(
19309
+ serverUrl,
19310
+ token,
19311
+ providerType,
19312
+ void 0,
19313
+ tenantId
19314
+ );
19235
19315
  const methods = serverData?.recoveryMethods || [];
19236
19316
  if (enableEmailBackupShare && !methods.some((m) => m.type === "email")) {
19237
19317
  methods.push({ type: "email", createdAt: /* @__PURE__ */ new Date() });
@@ -19267,7 +19347,9 @@ function createSSSStrategy(config) {
19267
19347
  async sendEmailBackupShare(token, providerType, _privateKey, email) {
19268
19348
  if (!enableEmailBackupShare) return;
19269
19349
  if (!lastEmailShare) {
19270
- console.warn("Cannot send email backup share: no cached email share from splitKey()");
19350
+ console.warn(
19351
+ "Cannot send email backup share: no cached email share from splitKey()"
19352
+ );
19271
19353
  return;
19272
19354
  }
19273
19355
  if (hasRecoveryEmail) {
@@ -19284,7 +19366,15 @@ function createSSSStrategy(config) {
19284
19366
  console.warn("Cannot send email backup share: no email address");
19285
19367
  return;
19286
19368
  }
19287
- await sendEmailBackupShare(serverUrl, token, providerType, lastEmailShare, email, lastShareVersion, tenantId);
19369
+ await sendEmailBackupShare(
19370
+ serverUrl,
19371
+ token,
19372
+ providerType,
19373
+ lastEmailShare,
19374
+ email,
19375
+ lastShareVersion,
19376
+ tenantId
19377
+ );
19288
19378
  }
19289
19379
  lastEmailShare = void 0;
19290
19380
  lastShareVersion = void 0;