@learncard/core 5.1.1 → 6.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.
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)
@@ -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);
@@ -35278,6 +35289,34 @@ var import_polyfill = require("abort-controller/polyfill");
35278
35289
  var import_isomorphic_webcrypto = __toESM(require("isomorphic-webcrypto"));
35279
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* () {
@@ -35985,7 +36024,7 @@ function getImports() {
35985
36024
  const ret = wasm.memory;
35986
36025
  return addHeapObject(ret);
35987
36026
  };
35988
- imports.wbg.__wbindgen_closure_wrapper10020 = function(arg0, arg1, arg2) {
36027
+ imports.wbg.__wbindgen_closure_wrapper10021 = function(arg0, arg1, arg2) {
35989
36028
  const ret = makeMutClosure(arg0, arg1, 3552, __wbg_adapter_24);
35990
36029
  return addHeapObject(ret);
35991
36030
  };
@@ -36022,7 +36061,7 @@ var didkit_wasm_default = init;
36022
36061
 
36023
36062
  // src/didkit/index.ts
36024
36063
  var initialized = false;
36025
- var init2 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/soErM6xgSNqxVeJZzo7v") => __async(void 0, null, function* () {
36064
+ var init2 = /* @__PURE__ */ __name((arg = "https://cdn.filestackcontent.com/R0BsvnoVRhezGazRDUy5") => __async(void 0, null, function* () {
36026
36065
  if (initialized)
36027
36066
  return;
36028
36067
  initialized = true;
@@ -36087,6 +36126,90 @@ var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
36087
36126
  }
36088
36127
  }), "ExpirationPlugin");
36089
36128
 
36129
+ // src/wallet/helpers/wallet.helpers.ts
36130
+ var recycleDependents = /* @__PURE__ */ __name((_methods) => ({}), "recycleDependents");
36131
+
36132
+ // src/wallet/plugins/vc-templates/templates.ts
36133
+ var VC_TEMPLATES = {
36134
+ basic: ({
36135
+ did = "did:example:d23dd687a7dc6787646f2eb98d0",
36136
+ subject = "did:example:d23dd687a7dc6787646f2eb98d0",
36137
+ issuanceDate = "2020-08-19T21:41:50Z"
36138
+ } = {}) => ({
36139
+ "@context": ["https://www.w3.org/2018/credentials/v1"],
36140
+ id: "http://example.org/credentials/3731",
36141
+ type: ["VerifiableCredential"],
36142
+ issuer: did,
36143
+ issuanceDate,
36144
+ credentialSubject: { id: subject }
36145
+ }),
36146
+ achievement: ({
36147
+ did = "did:example:d23dd687a7dc6787646f2eb98d0",
36148
+ subject = "did:example:d23dd687a7dc6787646f2eb98d0",
36149
+ name: name5 = "Teamwork Badge",
36150
+ achievementName = "Teamwork",
36151
+ description = "This badge recognizes the development of the capacity to collaborate within a group environment.",
36152
+ criteriaNarrative = "Team members are nominated for this badge by their peers and recognized upon review by Example Corp management.",
36153
+ issuanceDate = "2020-08-19T21:41:50Z"
36154
+ } = {}) => ({
36155
+ "@context": [
36156
+ "https://www.w3.org/2018/credentials/v1",
36157
+ "https://imsglobal.github.io/openbadges-specification/context.json"
36158
+ ],
36159
+ id: "http://example.com/credentials/3527",
36160
+ type: ["VerifiableCredential", "OpenBadgeCredential"],
36161
+ issuer: did,
36162
+ issuanceDate,
36163
+ name: name5,
36164
+ credentialSubject: {
36165
+ id: subject,
36166
+ type: ["AchievementSubject"],
36167
+ achievement: {
36168
+ id: "https://example.com/achievements/21st-century-skills/teamwork",
36169
+ type: ["Achievement"],
36170
+ criteria: { narrative: criteriaNarrative },
36171
+ description,
36172
+ name: achievementName
36173
+ }
36174
+ }
36175
+ })
36176
+ };
36177
+
36178
+ // src/wallet/plugins/vc-templates/vc-templates.ts
36179
+ var getVCTemplatesPlugin = /* @__PURE__ */ __name((wallet) => {
36180
+ return {
36181
+ pluginMethods: __spreadProps(__spreadValues({}, recycleDependents(wallet.pluginMethods)), {
36182
+ newCredential: (_wallet, args = { type: "basic" }) => {
36183
+ var _a, _b;
36184
+ const did = args.did || ((_b = (_a = _wallet.pluginMethods).getSubjectDid) == null ? void 0 : _b.call(_a, "key"));
36185
+ if (!did)
36186
+ throw new Error("Could not get issuer did!");
36187
+ const defaults = {
36188
+ did,
36189
+ subject: "did:example:d23dd687a7dc6787646f2eb98d0",
36190
+ issuanceDate: "2020-08-19T21:41:50Z"
36191
+ };
36192
+ const _c = args, { type = "basic" } = _c, functionArgs = __objRest(_c, ["type"]);
36193
+ if (!(type in VC_TEMPLATES))
36194
+ throw new Error("Invalid Test VC Type!");
36195
+ return VC_TEMPLATES[type](__spreadValues(__spreadValues({}, defaults), functionArgs));
36196
+ },
36197
+ newPresentation: (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (_wallet, credential, args = {}) {
36198
+ var _a, _b;
36199
+ const did = (args == null ? void 0 : args.did) || ((_b = (_a = _wallet.pluginMethods).getSubjectDid) == null ? void 0 : _b.call(_a, "key"));
36200
+ if (!did)
36201
+ throw new Error("Could not get issuer did!");
36202
+ return {
36203
+ "@context": ["https://www.w3.org/2018/credentials/v1"],
36204
+ type: ["VerifiablePresentation"],
36205
+ holder: did,
36206
+ verifiableCredential: credential
36207
+ };
36208
+ })
36209
+ })
36210
+ };
36211
+ }, "getVCTemplatesPlugin");
36212
+
36090
36213
  // ../../node_modules/.pnpm/zod@3.17.3/node_modules/zod/lib/index.mjs
36091
36214
  var util;
36092
36215
  (function(util2) {
@@ -38831,12 +38954,12 @@ var ImageValidator = mod.string().or(mod.object({
38831
38954
  caption: mod.string().optional()
38832
38955
  }));
38833
38956
  var GeoCoordinatesValidator = mod.object({
38834
- type: mod.string().array().nonempty(),
38957
+ type: mod.string().min(1).or(mod.string().array().nonempty()),
38835
38958
  latitude: mod.number(),
38836
38959
  longitude: mod.number()
38837
38960
  });
38838
38961
  var AddressValidator = mod.object({
38839
- type: mod.string().array().nonempty(),
38962
+ type: mod.string().min(1).or(mod.string().array().nonempty()),
38840
38963
  addressCountry: mod.string().optional(),
38841
38964
  addressCountryCode: mod.string().optional(),
38842
38965
  addressRegion: mod.string().optional(),
@@ -38867,7 +38990,7 @@ var IdentifierTypeValidator = mod.enum([
38867
38990
  "identifier"
38868
38991
  ]).or(mod.string());
38869
38992
  var IdentifierEntryValidator = mod.object({
38870
- type: mod.string().array().nonempty(),
38993
+ type: mod.string().min(1).or(mod.string().array().nonempty()),
38871
38994
  identifier: mod.string(),
38872
38995
  identifierType: IdentifierTypeValidator
38873
38996
  });
@@ -39087,7 +39210,7 @@ var AchievementSubjectValidator = mod.object({
39087
39210
  activityStartDate: mod.string().optional(),
39088
39211
  creditsEarned: mod.number().optional(),
39089
39212
  achievement: AchievementValidator.optional(),
39090
- identifier: IdentityObjectValidator.optional(),
39213
+ identifier: IdentityObjectValidator.array().optional(),
39091
39214
  image: ImageValidator.optional(),
39092
39215
  licenseNumber: mod.string().optional(),
39093
39216
  narrative: mod.string().optional(),
@@ -39108,7 +39231,7 @@ var EvidenceValidator = mod.object({
39108
39231
  var UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend({
39109
39232
  name: mod.string().optional(),
39110
39233
  description: mod.string().optional(),
39111
- image: mod.string().optional(),
39234
+ image: ImageValidator.optional(),
39112
39235
  credentialSubject: AchievementSubjectValidator.or(AchievementSubjectValidator.array()),
39113
39236
  endorsement: UnsignedVCValidator.array().optional(),
39114
39237
  evidence: EvidenceValidator.array().optional()
@@ -40755,9 +40878,12 @@ var verifyCredential2 = /* @__PURE__ */ __name((wallet) => {
40755
40878
  // src/wallet/initializers/emptyWallet.ts
40756
40879
  var emptyWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], function* ({ didkit } = {}) {
40757
40880
  const didkitWallet = yield (yield generateWallet()).addPlugin(yield getDidKitPlugin(didkit));
40758
- const wallet = yield didkitWallet.addPlugin(ExpirationPlugin(didkitWallet));
40881
+ const expirationWallet = yield didkitWallet.addPlugin(ExpirationPlugin(didkitWallet));
40882
+ const wallet = yield expirationWallet.addPlugin(getVCTemplatesPlugin(expirationWallet));
40759
40883
  return {
40760
40884
  _wallet: wallet,
40885
+ newCredential: wallet.pluginMethods.newCredential,
40886
+ newPresentation: wallet.pluginMethods.newPresentation,
40761
40887
  verifyCredential: verifyCredential2(wallet),
40762
40888
  verifyPresentation: wallet.pluginMethods.verifyPresentation,
40763
40889
  resolveDid: wallet.pluginMethods.resolveDid
@@ -53455,16 +53581,7 @@ var CeramicClient = class {
53455
53581
  __name(CeramicClient, "CeramicClient");
53456
53582
 
53457
53583
  // src/wallet/plugins/idx/types.ts
53458
- var StorageTypeValidator2 = mod.enum(["ceramic"]);
53459
- var StorageTypeEnum2 = StorageTypeValidator2.enum;
53460
- var CredentialMetadataValidator = mod.object({ name: mod.string().optional(), image: mod.string().optional() }).catchall(mod.any());
53461
- var IDXCredentialValidator2 = mod.object({
53462
- id: mod.string(),
53463
- title: mod.string(),
53464
- storageType: StorageTypeValidator2.optional(),
53465
- metadata: CredentialMetadataValidator.optional()
53466
- }).strict();
53467
- var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator2.array() }).strict();
53584
+ var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
53468
53585
 
53469
53586
  // src/wallet/plugins/idx/idx.ts
53470
53587
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
@@ -53493,7 +53610,7 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53493
53610
  throw new Error("Invalid credentials list stored in IDX");
53494
53611
  }), "getCredentialsListFromIdx");
53495
53612
  const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((_record, alias) => __async(void 0, null, function* () {
53496
- const record = IDXCredentialValidator2.parse(_record);
53613
+ const record = IDXCredentialValidator.parse(_record);
53497
53614
  if (!record)
53498
53615
  throw new Error("record is required");
53499
53616
  if (!record.id)
@@ -53639,9 +53756,6 @@ var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, n
53639
53756
  };
53640
53757
  }), "getDidKeyPlugin");
53641
53758
 
53642
- // src/wallet/helpers/wallet.helpers.ts
53643
- var recycleDependents = /* @__PURE__ */ __name((_methods) => ({}), "recycleDependents");
53644
-
53645
53759
  // src/wallet/plugins/vc/issueCredential.ts
53646
53760
  var issueCredential2 = /* @__PURE__ */ __name((initWallet) => {
53647
53761
  return (wallet, credential) => __async(void 0, null, function* () {
@@ -53685,7 +53799,7 @@ var verifyPresentation2 = /* @__PURE__ */ __name((initWallet) => {
53685
53799
  }, "verifyPresentation");
53686
53800
 
53687
53801
  // src/wallet/plugins/vc/vc.ts
53688
- var getVCPlugin = /* @__PURE__ */ __name((wallet) => __async(void 0, null, function* () {
53802
+ var getVCPlugin = /* @__PURE__ */ __name((wallet) => {
53689
53803
  return {
53690
53804
  pluginMethods: __spreadProps(__spreadValues({}, recycleDependents(wallet.pluginMethods)), {
53691
53805
  issueCredential: issueCredential2(wallet),
@@ -53715,7 +53829,7 @@ var getVCPlugin = /* @__PURE__ */ __name((wallet) => __async(void 0, null, funct
53715
53829
  })
53716
53830
  })
53717
53831
  };
53718
- }), "getVCPlugin");
53832
+ }, "getVCPlugin");
53719
53833
 
53720
53834
  // src/wallet/plugins/EthereumPlugin/index.ts
53721
53835
  var import_ethers2 = require("ethers");
@@ -57066,8 +57180,9 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
57066
57180
  } = {}) {
57067
57181
  const didkitWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getDidKitPlugin(didkit));
57068
57182
  const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
57069
- const didkeyAndVCWallet = yield didkeyWallet.addPlugin(yield getVCPlugin(didkeyWallet));
57070
- const idxWallet = yield didkeyAndVCWallet.addPlugin(yield getIDXPlugin(didkeyAndVCWallet, ceramicIdx));
57183
+ const didkeyAndVCWallet = yield didkeyWallet.addPlugin(getVCPlugin(didkeyWallet));
57184
+ const templateWallet = yield didkeyAndVCWallet.addPlugin(getVCTemplatesPlugin(didkeyAndVCWallet));
57185
+ const idxWallet = yield templateWallet.addPlugin(yield getIDXPlugin(templateWallet, ceramicIdx));
57071
57186
  const expirationWallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
57072
57187
  const ethWallet = yield expirationWallet.addPlugin(getEthereumPlugin(expirationWallet, ethereumConfig));
57073
57188
  const wallet = yield ethWallet.addPlugin(getVpqrPlugin(ethWallet));
@@ -57075,6 +57190,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
57075
57190
  _wallet: wallet,
57076
57191
  did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
57077
57192
  keypair: (type = "ed25519") => wallet.pluginMethods.getSubjectKeypair(type),
57193
+ newCredential: wallet.pluginMethods.newCredential,
57194
+ newPresentation: wallet.pluginMethods.newPresentation,
57078
57195
  issueCredential: wallet.pluginMethods.issueCredential,
57079
57196
  verifyCredential: verifyCredential2(wallet),
57080
57197
  issuePresentation: wallet.pluginMethods.issuePresentation,