@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/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [<img src="https://user-images.githubusercontent.com/2185016/176284693-4ca14052-d067-4ea5-b170-c6cd2594ee23.png" width="400"/>](image.png)
1
+ [<img src="https://user-images.githubusercontent.com/2185016/190510561-294db809-09fd-4771-9749-6c0e0f4144fd.png" width="215"/>](https://learncard.com)
2
+
2
3
  # @learncard/core
3
4
 
4
5
  [![npm version](https://img.shields.io/npm/v/@learncard/core)](https://www.npmjs.com/package/@learncard/core)
@@ -9,7 +10,7 @@ The LearnCard Core is a pluggable, open-source, universal digital wallet to enab
9
10
 
10
11
  ## Documentation
11
12
  All LearnCard documentation can be found at:
12
- https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/
13
+ https://docs.learncard.com
13
14
 
14
15
  ## Install
15
16
 
@@ -2881,9 +2881,9 @@ var require_package = __commonJS({
2881
2881
  }
2882
2882
  });
2883
2883
 
2884
- // (disabled):../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js
2884
+ // (disabled):../../node_modules/.pnpm/buffer@5.2.1/node_modules/buffer/index.js
2885
2885
  var require_buffer = __commonJS({
2886
- "(disabled):../../node_modules/.pnpm/buffer@5.7.1/node_modules/buffer/index.js"() {
2886
+ "(disabled):../../node_modules/.pnpm/buffer@5.2.1/node_modules/buffer/index.js"() {
2887
2887
  }
2888
2888
  });
2889
2889
 
@@ -35266,8 +35266,19 @@ var require_base32_decode = __commonJS({
35266
35266
  // src/index.ts
35267
35267
  var src_exports2 = {};
35268
35268
  __export(src_exports2, {
35269
+ CredentialsListValidator: () => CredentialsListValidator,
35270
+ ExpirationPlugin: () => ExpirationPlugin,
35269
35271
  emptyWallet: () => emptyWallet,
35272
+ generateWallet: () => generateWallet,
35273
+ getDidKeyPlugin: () => getDidKeyPlugin,
35274
+ getDidKitPlugin: () => getDidKitPlugin,
35275
+ getEthereumPlugin: () => getEthereumPlugin,
35276
+ getIDXPlugin: () => getIDXPlugin,
35277
+ getVCPlugin: () => getVCPlugin,
35278
+ getVpqrPlugin: () => getVpqrPlugin,
35270
35279
  initLearnCard: () => initLearnCard,
35280
+ passwordToKey: () => passwordToKey,
35281
+ seedToId: () => seedToId,
35271
35282
  walletFromKey: () => walletFromKey
35272
35283
  });
35273
35284
  module.exports = __toCommonJS(src_exports2);
@@ -35276,8 +35287,36 @@ var import_polyfill = require("abort-controller/polyfill");
35276
35287
 
35277
35288
  // src/wallet/base/crypto.ts
35278
35289
  var import_isomorphic_webcrypto = __toESM(require("isomorphic-webcrypto"));
35279
- if (typeof window === "undefined")
35290
+ if (typeof window === "undefined" && !globalThis.crypto)
35280
35291
  globalThis.crypto = import_isomorphic_webcrypto.default;
35292
+ var crypto_default = import_isomorphic_webcrypto.default;
35293
+
35294
+ // src/wallet/base/functions/passwordToKey.ts
35295
+ var passwordToKey = /* @__PURE__ */ __name((password, salt = "salt", iterations = 1e5, digest2 = "SHA-256") => __async(void 0, null, function* () {
35296
+ var saltBuffer = Buffer.from(salt);
35297
+ var passphraseKey = Buffer.from(password);
35298
+ return crypto_default.subtle.importKey("raw", passphraseKey, { name: "PBKDF2" }, false, [
35299
+ "deriveBits",
35300
+ "deriveKey"
35301
+ ]).then(function(key2) {
35302
+ return crypto_default.subtle.deriveKey({
35303
+ name: "PBKDF2",
35304
+ salt: saltBuffer,
35305
+ iterations,
35306
+ hash: digest2
35307
+ }, key2, { name: "AES-CBC", length: 256 }, true, ["encrypt", "decrypt"]);
35308
+ }).then((webKey) => {
35309
+ return crypto_default.subtle.exportKey("raw", webKey);
35310
+ }).then((buffer2) => {
35311
+ return new Uint8Array(buffer2);
35312
+ });
35313
+ }), "passwordToKey");
35314
+
35315
+ // src/wallet/base/functions/seedToId.ts
35316
+ var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
35317
+ const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
35318
+ return `urn:digest:${Buffer.from(new Int8Array(buffer2)).toString("hex")}`;
35319
+ }), "seedToId");
35281
35320
 
35282
35321
  // src/wallet/base/wallet.ts
35283
35322
  var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
@@ -35501,6 +35540,15 @@ function __wbg_adapter_24(arg0, arg1, arg2) {
35501
35540
  wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h47a829c6210a1ab1(arg0, arg1, addHeapObject(arg2));
35502
35541
  }
35503
35542
  __name(__wbg_adapter_24, "__wbg_adapter_24");
35543
+ function resolveDID(did, input_metadata) {
35544
+ const ptr0 = passStringToWasm0(did, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35545
+ const len0 = WASM_VECTOR_LEN;
35546
+ const ptr1 = passStringToWasm0(input_metadata, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35547
+ const len1 = WASM_VECTOR_LEN;
35548
+ const ret = wasm.resolveDID(ptr0, len0, ptr1, len1);
35549
+ return takeObject(ret);
35550
+ }
35551
+ __name(resolveDID, "resolveDID");
35504
35552
  function passArray8ToWasm0(arg, malloc) {
35505
35553
  const ptr = malloc(arg.length * 1);
35506
35554
  getUint8Memory0().set(arg, ptr / 1);
@@ -36055,6 +36103,9 @@ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, fu
36055
36103
  }),
36056
36104
  contextLoader: (_wallet, url) => __async(void 0, null, function* () {
36057
36105
  return JSON.parse(yield contextLoader(url));
36106
+ }),
36107
+ resolveDid: (_wallet, did) => __async(void 0, null, function* () {
36108
+ return JSON.parse(yield resolveDID(did, "{}"));
36058
36109
  })
36059
36110
  }
36060
36111
  };
@@ -39124,6 +39175,13 @@ var CredentialInfoValidator = mod.object({
39124
39175
  issuee: ProfileValidator.optional(),
39125
39176
  credentialSubject: CredentialSubjectValidator.optional()
39126
39177
  });
39178
+ var StorageTypeValidator = mod.enum(["ceramic"]);
39179
+ var StorageTypeEnum = StorageTypeValidator.enum;
39180
+ var IDXCredentialValidator = mod.object({
39181
+ id: mod.string(),
39182
+ title: mod.string(),
39183
+ storageType: StorageTypeValidator.optional()
39184
+ });
39127
39185
 
39128
39186
  // ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
39129
39187
  function toInteger(dirtyNumber) {
@@ -40740,7 +40798,8 @@ var emptyWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], fun
40740
40798
  return {
40741
40799
  _wallet: wallet,
40742
40800
  verifyCredential: verifyCredential2(wallet),
40743
- verifyPresentation: wallet.pluginMethods.verifyPresentation
40801
+ verifyPresentation: wallet.pluginMethods.verifyPresentation,
40802
+ resolveDid: wallet.pluginMethods.resolveDid
40744
40803
  };
40745
40804
  }), "emptyWallet");
40746
40805
 
@@ -53434,6 +53493,9 @@ var CeramicClient = class {
53434
53493
  };
53435
53494
  __name(CeramicClient, "CeramicClient");
53436
53495
 
53496
+ // src/wallet/plugins/idx/types.ts
53497
+ var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
53498
+
53437
53499
  // src/wallet/plugins/idx/idx.ts
53438
53500
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
53439
53501
  const client = new CeramicClient(ceramicEndpoint);
@@ -53451,9 +53513,17 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53451
53513
  const loader = new TileLoader({ ceramic });
53452
53514
  const dataStore = new DIDDataStore({ ceramic, model: modelData });
53453
53515
  const getCredentialsListFromIdx = /* @__PURE__ */ __name((..._02) => __async(void 0, [..._02], function* (alias = credentialAlias) {
53454
- return (yield dataStore.get(alias)) || { credentials: [] };
53516
+ const list = yield dataStore.get(alias);
53517
+ if (!list)
53518
+ return { credentials: [] };
53519
+ const validationResult = yield CredentialsListValidator.spa(list);
53520
+ if (validationResult.success)
53521
+ return validationResult.data;
53522
+ console.error(validationResult.error);
53523
+ throw new Error("Invalid credentials list stored in IDX");
53455
53524
  }), "getCredentialsListFromIdx");
53456
- const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((record, alias) => __async(void 0, null, function* () {
53525
+ const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((_record, alias) => __async(void 0, null, function* () {
53526
+ const record = IDXCredentialValidator.parse(_record);
53457
53527
  if (!record)
53458
53528
  throw new Error("record is required");
53459
53529
  if (!record.id)
@@ -53468,10 +53538,10 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53468
53538
  });
53469
53539
  if (indexOfExistingCredential > -1) {
53470
53540
  existing.credentials[indexOfExistingCredential] = __spreadValues({
53471
- storageType: "ceramic" /* ceramic */
53541
+ storageType: StorageTypeEnum.ceramic
53472
53542
  }, record);
53473
53543
  } else
53474
- existing.credentials.push(__spreadValues({ storageType: "ceramic" /* ceramic */ }, record));
53544
+ existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
53475
53545
  return dataStore.set(alias, existing);
53476
53546
  }), "addCredentialStreamIdToIdx");
53477
53547
  const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
@@ -53524,8 +53594,8 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53524
53594
  return readContentFromCeramic(streamId);
53525
53595
  })));
53526
53596
  }),
53527
- addVerifiableCredentialInIdx: (_02, _12) => __async(void 0, [_02, _12], function* (_wallet, { title, id }) {
53528
- return addCredentialStreamIdToIdx({ title, id });
53597
+ addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
53598
+ return addCredentialStreamIdToIdx(idxCredential);
53529
53599
  }),
53530
53600
  removeVerifiableCredentialInIdx: (_wallet, title) => __async(void 0, null, function* () {
53531
53601
  return removeCredentialFromIdx(title);
@@ -57051,6 +57121,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
57051
57121
  removeCredential: (title) => __async(void 0, null, function* () {
57052
57122
  yield wallet.pluginMethods.removeVerifiableCredentialInIdx(title);
57053
57123
  }),
57124
+ resolveDid: wallet.pluginMethods.resolveDid,
57054
57125
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
57055
57126
  getTestVc: wallet.pluginMethods.getTestVc,
57056
57127
  getTestVp: wallet.pluginMethods.getTestVp,