@learncard/core 5.1.0 → 6.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/core.esm.js CHANGED
@@ -2888,9 +2888,9 @@ var require_package = __commonJS({
2888
2888
  }
2889
2889
  });
2890
2890
 
2891
- // (disabled):../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js
2891
+ // (disabled):../../node_modules/.pnpm/buffer@5.2.1/node_modules/buffer/index.js
2892
2892
  var require_buffer = __commonJS({
2893
- "(disabled):../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js"() {
2893
+ "(disabled):../../node_modules/.pnpm/buffer@5.2.1/node_modules/buffer/index.js"() {
2894
2894
  }
2895
2895
  });
2896
2896
 
@@ -35276,8 +35276,36 @@ import "abort-controller/polyfill";
35276
35276
 
35277
35277
  // src/wallet/base/crypto.ts
35278
35278
  import crypto2 from "isomorphic-webcrypto";
35279
- if (typeof window === "undefined")
35279
+ if (typeof window === "undefined" && !globalThis.crypto)
35280
35280
  globalThis.crypto = crypto2;
35281
+ var crypto_default = crypto2;
35282
+
35283
+ // src/wallet/base/functions/passwordToKey.ts
35284
+ var passwordToKey = /* @__PURE__ */ __name((password, salt = "salt", iterations = 1e5, digest2 = "SHA-256") => __async(void 0, null, function* () {
35285
+ var saltBuffer = Buffer.from(salt);
35286
+ var passphraseKey = Buffer.from(password);
35287
+ return crypto_default.subtle.importKey("raw", passphraseKey, { name: "PBKDF2" }, false, [
35288
+ "deriveBits",
35289
+ "deriveKey"
35290
+ ]).then(function(key2) {
35291
+ return crypto_default.subtle.deriveKey({
35292
+ name: "PBKDF2",
35293
+ salt: saltBuffer,
35294
+ iterations,
35295
+ hash: digest2
35296
+ }, key2, { name: "AES-CBC", length: 256 }, true, ["encrypt", "decrypt"]);
35297
+ }).then((webKey) => {
35298
+ return crypto_default.subtle.exportKey("raw", webKey);
35299
+ }).then((buffer2) => {
35300
+ return new Uint8Array(buffer2);
35301
+ });
35302
+ }), "passwordToKey");
35303
+
35304
+ // src/wallet/base/functions/seedToId.ts
35305
+ var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
35306
+ const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
35307
+ return `urn:digest:${Buffer.from(new Int8Array(buffer2)).toString("hex")}`;
35308
+ }), "seedToId");
35281
35309
 
35282
35310
  // src/wallet/base/wallet.ts
35283
35311
  var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
@@ -35501,6 +35529,15 @@ function __wbg_adapter_24(arg0, arg1, arg2) {
35501
35529
  wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h47a829c6210a1ab1(arg0, arg1, addHeapObject(arg2));
35502
35530
  }
35503
35531
  __name(__wbg_adapter_24, "__wbg_adapter_24");
35532
+ function resolveDID(did, input_metadata) {
35533
+ const ptr0 = passStringToWasm0(did, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35534
+ const len0 = WASM_VECTOR_LEN;
35535
+ const ptr1 = passStringToWasm0(input_metadata, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35536
+ const len1 = WASM_VECTOR_LEN;
35537
+ const ret = wasm.resolveDID(ptr0, len0, ptr1, len1);
35538
+ return takeObject(ret);
35539
+ }
35540
+ __name(resolveDID, "resolveDID");
35504
35541
  function passArray8ToWasm0(arg, malloc) {
35505
35542
  const ptr = malloc(arg.length * 1);
35506
35543
  getUint8Memory0().set(arg, ptr / 1);
@@ -36055,6 +36092,9 @@ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, fu
36055
36092
  }),
36056
36093
  contextLoader: (_wallet, url) => __async(void 0, null, function* () {
36057
36094
  return JSON.parse(yield contextLoader(url));
36095
+ }),
36096
+ resolveDid: (_wallet, did) => __async(void 0, null, function* () {
36097
+ return JSON.parse(yield resolveDID(did, "{}"));
36058
36098
  })
36059
36099
  }
36060
36100
  };
@@ -39124,6 +39164,13 @@ var CredentialInfoValidator = mod.object({
39124
39164
  issuee: ProfileValidator.optional(),
39125
39165
  credentialSubject: CredentialSubjectValidator.optional()
39126
39166
  });
39167
+ var StorageTypeValidator = mod.enum(["ceramic"]);
39168
+ var StorageTypeEnum = StorageTypeValidator.enum;
39169
+ var IDXCredentialValidator = mod.object({
39170
+ id: mod.string(),
39171
+ title: mod.string(),
39172
+ storageType: StorageTypeValidator.optional()
39173
+ });
39127
39174
 
39128
39175
  // ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
39129
39176
  function toInteger(dirtyNumber) {
@@ -40740,7 +40787,8 @@ var emptyWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], fun
40740
40787
  return {
40741
40788
  _wallet: wallet,
40742
40789
  verifyCredential: verifyCredential2(wallet),
40743
- verifyPresentation: wallet.pluginMethods.verifyPresentation
40790
+ verifyPresentation: wallet.pluginMethods.verifyPresentation,
40791
+ resolveDid: wallet.pluginMethods.resolveDid
40744
40792
  };
40745
40793
  }), "emptyWallet");
40746
40794
 
@@ -53434,6 +53482,9 @@ var CeramicClient = class {
53434
53482
  };
53435
53483
  __name(CeramicClient, "CeramicClient");
53436
53484
 
53485
+ // src/wallet/plugins/idx/types.ts
53486
+ var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
53487
+
53437
53488
  // src/wallet/plugins/idx/idx.ts
53438
53489
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
53439
53490
  const client = new CeramicClient(ceramicEndpoint);
@@ -53451,9 +53502,17 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53451
53502
  const loader = new TileLoader({ ceramic });
53452
53503
  const dataStore = new DIDDataStore({ ceramic, model: modelData });
53453
53504
  const getCredentialsListFromIdx = /* @__PURE__ */ __name((..._02) => __async(void 0, [..._02], function* (alias = credentialAlias) {
53454
- return (yield dataStore.get(alias)) || { credentials: [] };
53505
+ const list = yield dataStore.get(alias);
53506
+ if (!list)
53507
+ return { credentials: [] };
53508
+ const validationResult = yield CredentialsListValidator.spa(list);
53509
+ if (validationResult.success)
53510
+ return validationResult.data;
53511
+ console.error(validationResult.error);
53512
+ throw new Error("Invalid credentials list stored in IDX");
53455
53513
  }), "getCredentialsListFromIdx");
53456
- const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((record, alias) => __async(void 0, null, function* () {
53514
+ const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((_record, alias) => __async(void 0, null, function* () {
53515
+ const record = IDXCredentialValidator.parse(_record);
53457
53516
  if (!record)
53458
53517
  throw new Error("record is required");
53459
53518
  if (!record.id)
@@ -53468,10 +53527,10 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53468
53527
  });
53469
53528
  if (indexOfExistingCredential > -1) {
53470
53529
  existing.credentials[indexOfExistingCredential] = __spreadValues({
53471
- storageType: "ceramic" /* ceramic */
53530
+ storageType: StorageTypeEnum.ceramic
53472
53531
  }, record);
53473
53532
  } else
53474
- existing.credentials.push(__spreadValues({ storageType: "ceramic" /* ceramic */ }, record));
53533
+ existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
53475
53534
  return dataStore.set(alias, existing);
53476
53535
  }), "addCredentialStreamIdToIdx");
53477
53536
  const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
@@ -53524,8 +53583,8 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53524
53583
  return readContentFromCeramic(streamId);
53525
53584
  })));
53526
53585
  }),
53527
- addVerifiableCredentialInIdx: (_02, _12) => __async(void 0, [_02, _12], function* (_wallet, { title, id }) {
53528
- return addCredentialStreamIdToIdx({ title, id });
53586
+ addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
53587
+ return addCredentialStreamIdToIdx(idxCredential);
53529
53588
  }),
53530
53589
  removeVerifiableCredentialInIdx: (_wallet, title) => __async(void 0, null, function* () {
53531
53590
  return removeCredentialFromIdx(title);
@@ -57051,6 +57110,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
57051
57110
  removeCredential: (title) => __async(void 0, null, function* () {
57052
57111
  yield wallet.pluginMethods.removeVerifiableCredentialInIdx(title);
57053
57112
  }),
57113
+ resolveDid: wallet.pluginMethods.resolveDid,
57054
57114
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
57055
57115
  getTestVc: wallet.pluginMethods.getTestVc,
57056
57116
  getTestVp: wallet.pluginMethods.getTestVp,
@@ -57078,8 +57138,19 @@ function initLearnCard() {
57078
57138
  }
57079
57139
  __name(initLearnCard, "initLearnCard");
57080
57140
  export {
57141
+ CredentialsListValidator,
57142
+ ExpirationPlugin,
57081
57143
  emptyWallet,
57144
+ generateWallet,
57145
+ getDidKeyPlugin,
57146
+ getDidKitPlugin,
57147
+ getEthereumPlugin,
57148
+ getIDXPlugin,
57149
+ getVCPlugin,
57150
+ getVpqrPlugin,
57082
57151
  initLearnCard,
57152
+ passwordToKey,
57153
+ seedToId,
57083
57154
  walletFromKey
57084
57155
  };
57085
57156
  /*!