@learncard/core 1.1.5 → 1.2.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.d.ts CHANGED
@@ -2884,6 +2884,20 @@ declare const VPValidator: z.ZodObject<z.extendShape<{
2884
2884
  }[];
2885
2885
  }>;
2886
2886
  export declare type VP = z.infer<typeof VPValidator>;
2887
+ declare const VerificationCheckValidator: z.ZodObject<{
2888
+ checks: z.ZodArray<z.ZodString, "many">;
2889
+ warnings: z.ZodArray<z.ZodString, "many">;
2890
+ errors: z.ZodArray<z.ZodString, "many">;
2891
+ }, "strip", z.ZodTypeAny, {
2892
+ checks: string[];
2893
+ warnings: string[];
2894
+ errors: string[];
2895
+ }, {
2896
+ checks: string[];
2897
+ warnings: string[];
2898
+ errors: string[];
2899
+ }>;
2900
+ export declare type VerificationCheck = z.infer<typeof VerificationCheckValidator>;
2887
2901
  declare const VerificationItemValidator: z.ZodObject<{
2888
2902
  check: z.ZodString;
2889
2903
  status: z.ZodEnum<[
@@ -2905,6 +2919,12 @@ declare const VerificationItemValidator: z.ZodObject<{
2905
2919
  check: string;
2906
2920
  }>;
2907
2921
  export declare type VerificationItem = z.infer<typeof VerificationItemValidator>;
2922
+ export declare type KeyPair = {
2923
+ kty: string;
2924
+ crv: string;
2925
+ x: string;
2926
+ d: string;
2927
+ };
2908
2928
  export declare type DidKeyPluginMethods = {
2909
2929
  getSubjectDid: () => string;
2910
2930
  getSubjectKeypair: () => {
@@ -2934,11 +2954,6 @@ export declare type IDXCredential = {
2934
2954
  export declare type CredentialsList = {
2935
2955
  credentials: IDXCredential[];
2936
2956
  };
2937
- export declare type VerificationCheck = {
2938
- checks: string[];
2939
- warnings: string[];
2940
- errors: string[];
2941
- };
2942
2957
  export declare type VCPluginMethods = {
2943
2958
  issueCredential: (credential: UnsignedVC) => Promise<VC>;
2944
2959
  verifyCredential: (credential: VC) => Promise<VerificationCheck>;
@@ -2946,7 +2961,7 @@ export declare type VCPluginMethods = {
2946
2961
  verifyPresentation: (presentation: VP) => Promise<VerificationCheck>;
2947
2962
  getTestVc: (subject?: string) => UnsignedVC;
2948
2963
  getSubjectDid: () => string;
2949
- getSubjectKeypair: () => Record<string, string>;
2964
+ getSubjectKeypair: () => KeyPair;
2950
2965
  };
2951
2966
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
2952
2967
  export declare type Plugin<Name extends string, PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
@@ -2976,7 +2991,7 @@ export declare type UnlockedWallet<PluginNames extends string = "", PluginMethod
2976
2991
  addPlugin: <Name extends string, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>>(plugin: Plugin<Name, Methods>) => Promise<UnlockedWallet<"" extends PluginNames ? Name : PluginNames | Name, Record<never, never> extends PluginMethods ? Methods : PluginMethods & Methods>>;
2977
2992
  };
2978
2993
  export declare type Wallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = LockedWallet<PluginNames, PluginMethods> | UnlockedWallet<PluginNames, PluginMethods>;
2979
- export declare type LearnCardRawWallet = UnlockedWallet<"DID Key" | "VC" | "IDX" | "Expiration", DidKeyPluginMethods & VCPluginMethods & IDXPluginMethods>;
2994
+ export declare type LearnCardRawWallet = UnlockedWallet<"DIDKit" | "DID Key" | "VC" | "IDX" | "Expiration", DidKeyPluginMethods & VCPluginMethods & IDXPluginMethods>;
2980
2995
  export declare type LearnCardWallet = {
2981
2996
  /** Raw IoE wallet instance. You shouldn't need to drop down to this level! */
2982
2997
  _wallet: LearnCardRawWallet;
package/dist/core.esm.js CHANGED
@@ -43226,15 +43226,15 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
43226
43226
 
43227
43227
  // src/wallet/plugins/didkey/index.ts
43228
43228
  var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
43229
- var getDidKeyPlugin = /* @__PURE__ */ __name((key2) => __async(void 0, null, function* () {
43229
+ var getDidKeyPlugin = /* @__PURE__ */ __name((wallet, key2) => __async(void 0, null, function* () {
43230
43230
  if (key2.length === 0)
43231
43231
  throw new Error("Please don't use an empty string for a key!");
43232
43232
  if (!isHex(key2))
43233
43233
  throw new Error("Key must be a hexadecimal string!");
43234
43234
  if (key2.length > 64)
43235
43235
  throw new Error("Key must be less than 64 characters");
43236
- const keypair = JSON.parse(generateEd25519KeyFromBytes(toUint8Array(key2.padStart(64, "0"))));
43237
- const did = keyToDID("key", JSON.stringify(keypair));
43236
+ const keypair = wallet.pluginMethods.generateEd25519KeyFromBytes(toUint8Array(key2.padStart(64, "0")));
43237
+ const did = wallet.pluginMethods.keyToDid("key", keypair);
43238
43238
  return {
43239
43239
  pluginMethods: {
43240
43240
  getSubjectDid: () => did,
@@ -43260,63 +43260,65 @@ var ExpirationPlugin = /* @__PURE__ */ __name((wallet) => ({
43260
43260
  }), "ExpirationPlugin");
43261
43261
 
43262
43262
  // src/wallet/plugins/vc/issueCredential.ts
43263
- var issueCredential2 = /* @__PURE__ */ __name((wallet, credential) => __async(void 0, null, function* () {
43264
- const _kp = wallet.pluginMethods.getSubjectKeypair();
43265
- if (!_kp)
43266
- throw new Error("Cannot issue credential: Could not get subject keypair");
43267
- const kp = JSON.stringify(_kp);
43268
- const options = JSON.stringify({
43269
- verificationMethod: yield keyToVerificationMethod("key", kp),
43270
- proofPurpose: "assertionMethod"
43263
+ var issueCredential2 = /* @__PURE__ */ __name((initWallet) => {
43264
+ return (wallet, credential) => __async(void 0, null, function* () {
43265
+ const kp = wallet.pluginMethods.getSubjectKeypair();
43266
+ if (!kp)
43267
+ throw new Error("Cannot issue credential: Could not get subject keypair");
43268
+ const options = {
43269
+ verificationMethod: yield initWallet.pluginMethods.keyToVerificationMethod("key", kp),
43270
+ proofPurpose: "assertionMethod"
43271
+ };
43272
+ return initWallet.pluginMethods.issueCredential(credential, options, kp);
43271
43273
  });
43272
- return JSON.parse(yield issueCredential(JSON.stringify(credential), options, kp));
43273
- }), "issueCredential");
43274
+ }, "issueCredential");
43274
43275
 
43275
43276
  // src/wallet/plugins/vc/verifyCredential.ts
43276
- var verifyCredential2 = /* @__PURE__ */ __name((credential) => __async(void 0, null, function* () {
43277
- return JSON.parse(yield verifyCredential(JSON.stringify(credential), "{}"));
43278
- }), "verifyCredential");
43277
+ var verifyCredential2 = /* @__PURE__ */ __name((initWallet) => {
43278
+ return (_wallet, credential) => __async(void 0, null, function* () {
43279
+ return initWallet.pluginMethods.verifyCredential(credential);
43280
+ });
43281
+ }, "verifyCredential");
43279
43282
 
43280
43283
  // src/wallet/plugins/vc/issuePresentation.ts
43281
- var issuePresentation2 = /* @__PURE__ */ __name((wallet, credential) => __async(void 0, null, function* () {
43282
- const did = wallet.pluginMethods.getSubjectDid();
43283
- if (!did)
43284
- throw new Error("Cannot create presentation: No holder key found");
43285
- const holder = did;
43286
- const _kp = wallet.pluginMethods.getSubjectKeypair();
43287
- if (!_kp)
43288
- throw new Error("Cannot issue credential: Could not get subject keypair");
43289
- const kp = JSON.stringify(_kp);
43290
- const options = JSON.stringify({
43291
- verificationMethod: yield keyToVerificationMethod("key", kp),
43292
- proofPurpose: "assertionMethod"
43293
- });
43294
- const presentation = JSON.stringify({
43295
- "@context": ["https://www.w3.org/2018/credentials/v1"],
43296
- type: ["VerifiablePresentation"],
43297
- holder,
43298
- verifiableCredential: credential
43284
+ var issuePresentation2 = /* @__PURE__ */ __name((initWallet) => {
43285
+ return (wallet, credential) => __async(void 0, null, function* () {
43286
+ const did = wallet.pluginMethods.getSubjectDid();
43287
+ if (!did)
43288
+ throw new Error("Cannot create presentation: No holder key found");
43289
+ const holder = did;
43290
+ const kp = wallet.pluginMethods.getSubjectKeypair();
43291
+ if (!kp)
43292
+ throw new Error("Cannot issue credential: Could not get subject keypair");
43293
+ const options = {
43294
+ verificationMethod: yield initWallet.pluginMethods.keyToVerificationMethod("key", kp),
43295
+ proofPurpose: "assertionMethod"
43296
+ };
43297
+ const presentation = {
43298
+ "@context": ["https://www.w3.org/2018/credentials/v1"],
43299
+ type: ["VerifiablePresentation"],
43300
+ holder,
43301
+ verifiableCredential: credential
43302
+ };
43303
+ return initWallet.pluginMethods.issuePresentation(presentation, options, kp);
43299
43304
  });
43300
- return JSON.parse(yield issuePresentation(presentation, options, kp));
43301
- }), "issuePresentation");
43305
+ }, "issuePresentation");
43302
43306
 
43303
43307
  // src/wallet/plugins/vc/verifyPresentation.ts
43304
- var verifyPresentation2 = /* @__PURE__ */ __name((presentation) => __async(void 0, null, function* () {
43305
- return JSON.parse(yield verifyPresentation(JSON.stringify(presentation), "{}"));
43306
- }), "verifyPresentation");
43308
+ var verifyPresentation2 = /* @__PURE__ */ __name((initWallet) => {
43309
+ return (_wallet, presentation) => __async(void 0, null, function* () {
43310
+ return initWallet.pluginMethods.verifyPresentation(presentation);
43311
+ });
43312
+ }, "verifyPresentation");
43307
43313
 
43308
43314
  // src/wallet/plugins/vc/vc.ts
43309
43315
  var getVCPlugin = /* @__PURE__ */ __name((wallet) => __async(void 0, null, function* () {
43310
43316
  return {
43311
43317
  pluginMethods: __spreadProps(__spreadValues({}, wallet.pluginMethods), {
43312
- issueCredential: issueCredential2,
43313
- verifyCredential: (_wallet, credential) => __async(void 0, null, function* () {
43314
- return verifyCredential2(credential);
43315
- }),
43316
- issuePresentation: issuePresentation2,
43317
- verifyPresentation: (_wallet, presentation) => __async(void 0, null, function* () {
43318
- return verifyPresentation2(presentation);
43319
- }),
43318
+ issueCredential: issueCredential2(wallet),
43319
+ verifyCredential: verifyCredential2(wallet),
43320
+ issuePresentation: issuePresentation2(wallet),
43321
+ verifyPresentation: verifyPresentation2(wallet),
43320
43322
  getTestVc: (_wallet, subject = "did:example:d23dd687a7dc6787646f2eb98d0") => {
43321
43323
  const did = _wallet.pluginMethods.getSubjectDid();
43322
43324
  return {
@@ -46361,6 +46363,11 @@ var UnsignedAchievementCredentialValidator = UnsignedVCValidator.extend({
46361
46363
  var AchievementCredentialValidator = UnsignedAchievementCredentialValidator.extend({
46362
46364
  proof: ProofValidator.or(ProofValidator.array())
46363
46365
  });
46366
+ var VerificationCheckValidator = mod.object({
46367
+ checks: mod.string().array(),
46368
+ warnings: mod.string().array(),
46369
+ errors: mod.string().array()
46370
+ });
46364
46371
  var VerificationStatusValidator = mod.enum(["Success", "Failed", "Error"]);
46365
46372
  var VerificationStatusEnum = VerificationStatusValidator.enum;
46366
46373
  var VerificationItemValidator = mod.object({
@@ -48002,6 +48009,32 @@ var defaultCeramicIDXArgs = {
48002
48009
  defaultContentFamily: "SuperSkills"
48003
48010
  };
48004
48011
 
48012
+ // src/wallet/plugins/didkit/index.ts
48013
+ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, function* () {
48014
+ yield didkit_default(input);
48015
+ return {
48016
+ pluginMethods: {
48017
+ generateEd25519KeyFromBytes: (_wallet, bytes) => JSON.parse(generateEd25519KeyFromBytes(bytes)),
48018
+ keyToDid: (_wallet, type, keypair) => keyToDID(type, JSON.stringify(keypair)),
48019
+ keyToVerificationMethod: (_wallet, type, keypair) => __async(void 0, null, function* () {
48020
+ return keyToVerificationMethod(type, JSON.stringify(keypair));
48021
+ }),
48022
+ issueCredential: (_wallet, credential, options, keypair) => __async(void 0, null, function* () {
48023
+ return JSON.parse(yield issueCredential(JSON.stringify(credential), JSON.stringify(options), JSON.stringify(keypair)));
48024
+ }),
48025
+ verifyCredential: (_wallet, credential) => __async(void 0, null, function* () {
48026
+ return JSON.parse(yield verifyCredential(JSON.stringify(credential), "{}"));
48027
+ }),
48028
+ issuePresentation: (presentation, options, keypair) => __async(void 0, null, function* () {
48029
+ return issuePresentation(JSON.stringify(presentation), JSON.stringify(options), JSON.stringify(keypair));
48030
+ }),
48031
+ verifyPresentation: (_wallet, presentation) => __async(void 0, null, function* () {
48032
+ return JSON.parse(yield verifyPresentation(JSON.stringify(presentation), "{}"));
48033
+ })
48034
+ }
48035
+ };
48036
+ }), "getDidKitPlugin");
48037
+
48005
48038
  // src/wallet/init.ts
48006
48039
  var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
48007
48040
  ceramicIdx = defaultCeramicIDXArgs,
@@ -48009,7 +48042,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
48009
48042
  defaultContents = []
48010
48043
  } = {}) {
48011
48044
  yield didkit_default(didkit);
48012
- const didkeyWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getDidKeyPlugin(key2));
48045
+ const didkitWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getDidKitPlugin(didkit));
48046
+ const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
48013
48047
  const didkeyAndVCWallet = yield didkeyWallet.addPlugin(yield getVCPlugin(didkeyWallet));
48014
48048
  const idxWallet = yield didkeyAndVCWallet.addPlugin(yield getIDXPlugin(didkeyAndVCWallet, ceramicIdx));
48015
48049
  const wallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));