@learncard/core 5.1.0 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/core.d.ts CHANGED
@@ -4590,6 +4590,22 @@ declare const VerificationItemValidator: z.ZodObject<{
4590
4590
  check: string;
4591
4591
  }>;
4592
4592
  export declare type VerificationItem = z.infer<typeof VerificationItemValidator>;
4593
+ declare const IDXCredentialValidator: z.ZodObject<{
4594
+ id: z.ZodString;
4595
+ title: z.ZodString;
4596
+ storageType: z.ZodOptional<z.ZodEnum<[
4597
+ "ceramic"
4598
+ ]>>;
4599
+ }, "strip", z.ZodTypeAny, {
4600
+ storageType?: "ceramic" | undefined;
4601
+ id: string;
4602
+ title: string;
4603
+ }, {
4604
+ storageType?: "ceramic" | undefined;
4605
+ id: string;
4606
+ title: string;
4607
+ }>;
4608
+ export declare type IDXCredential = z.infer<typeof IDXCredentialValidator>;
4593
4609
  export declare type DidMethod = "key" | "tz" | "ethr" | `pkh:${"tz" | "tezos" | "sol" | "solana" | "eth" | "celo" | "poly" | "btc" | "doge" | "eip155" | "bip122"}` | `pkh:eip155:${string}` | `pkh:bip122:${string}`;
4594
4610
  export declare type KeyPair = {
4595
4611
  kty: string;
@@ -4612,6 +4628,7 @@ export declare type DidkitPluginMethods = {
4612
4628
  issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: KeyPair) => Promise<VP>;
4613
4629
  verifyPresentation: (presentation: VP) => Promise<VerificationCheck>;
4614
4630
  contextLoader: (url: string) => Promise<Record<string, any>>;
4631
+ resolveDid: (did: string) => Promise<Record<string, any>>;
4615
4632
  };
4616
4633
  export declare type Algorithm = "ed25519" | "secp256k1";
4617
4634
  export declare type DidKeyPluginMethods<DidMethod extends string> = {
@@ -4647,17 +4664,106 @@ export declare type IDXPluginMethods = {
4647
4664
  addVerifiableCredentialInIdx: (cred: IDXCredential) => Promise<StreamID>;
4648
4665
  removeVerifiableCredentialInIdx: (title: string) => Promise<StreamID>;
4649
4666
  };
4650
- declare enum StorageType {
4651
- ceramic = "ceramic"
4652
- }
4653
- export declare type IDXCredential = {
4667
+ declare const IDXCredentialValidator: z.ZodObject<{
4668
+ id: z.ZodString;
4669
+ title: z.ZodString;
4670
+ storageType: z.ZodOptional<z.ZodEnum<[
4671
+ "ceramic"
4672
+ ]>>;
4673
+ metadata: z.ZodOptional<z.ZodObject<{
4674
+ name: z.ZodOptional<z.ZodString>;
4675
+ image: z.ZodOptional<z.ZodString>;
4676
+ }, "strip", z.ZodAny, {
4677
+ [x: string]: any;
4678
+ name?: string | undefined;
4679
+ image?: string | undefined;
4680
+ }, {
4681
+ [x: string]: any;
4682
+ name?: string | undefined;
4683
+ image?: string | undefined;
4684
+ }>>;
4685
+ }, "strict", z.ZodTypeAny, {
4686
+ storageType?: "ceramic" | undefined;
4687
+ metadata?: {
4688
+ [x: string]: any;
4689
+ name?: string | undefined;
4690
+ image?: string | undefined;
4691
+ } | undefined;
4654
4692
  id: string;
4655
4693
  title: string;
4656
- storageType?: StorageType;
4657
- };
4658
- export declare type CredentialsList = {
4659
- credentials: IDXCredential[];
4660
- };
4694
+ }, {
4695
+ storageType?: "ceramic" | undefined;
4696
+ metadata?: {
4697
+ [x: string]: any;
4698
+ name?: string | undefined;
4699
+ image?: string | undefined;
4700
+ } | undefined;
4701
+ id: string;
4702
+ title: string;
4703
+ }>;
4704
+ export declare type IDXCredential = z.infer<typeof IDXCredentialValidator>;
4705
+ declare const CredentialsListValidator: z.ZodObject<{
4706
+ credentials: z.ZodArray<z.ZodObject<{
4707
+ id: z.ZodString;
4708
+ title: z.ZodString;
4709
+ storageType: z.ZodOptional<z.ZodEnum<[
4710
+ "ceramic"
4711
+ ]>>;
4712
+ metadata: z.ZodOptional<z.ZodObject<{
4713
+ name: z.ZodOptional<z.ZodString>;
4714
+ image: z.ZodOptional<z.ZodString>;
4715
+ }, "strip", z.ZodAny, {
4716
+ [x: string]: any;
4717
+ name?: string | undefined;
4718
+ image?: string | undefined;
4719
+ }, {
4720
+ [x: string]: any;
4721
+ name?: string | undefined;
4722
+ image?: string | undefined;
4723
+ }>>;
4724
+ }, "strict", z.ZodTypeAny, {
4725
+ storageType?: "ceramic" | undefined;
4726
+ metadata?: {
4727
+ [x: string]: any;
4728
+ name?: string | undefined;
4729
+ image?: string | undefined;
4730
+ } | undefined;
4731
+ id: string;
4732
+ title: string;
4733
+ }, {
4734
+ storageType?: "ceramic" | undefined;
4735
+ metadata?: {
4736
+ [x: string]: any;
4737
+ name?: string | undefined;
4738
+ image?: string | undefined;
4739
+ } | undefined;
4740
+ id: string;
4741
+ title: string;
4742
+ }>, "many">;
4743
+ }, "strict", z.ZodTypeAny, {
4744
+ credentials: {
4745
+ storageType?: "ceramic" | undefined;
4746
+ metadata?: {
4747
+ [x: string]: any;
4748
+ name?: string | undefined;
4749
+ image?: string | undefined;
4750
+ } | undefined;
4751
+ id: string;
4752
+ title: string;
4753
+ }[];
4754
+ }, {
4755
+ credentials: {
4756
+ storageType?: "ceramic" | undefined;
4757
+ metadata?: {
4758
+ [x: string]: any;
4759
+ name?: string | undefined;
4760
+ image?: string | undefined;
4761
+ } | undefined;
4762
+ id: string;
4763
+ title: string;
4764
+ }[];
4765
+ }>;
4766
+ export declare type CredentialsList = z.infer<typeof CredentialsListValidator>;
4661
4767
  export declare type DependentMethods = {
4662
4768
  getSubjectDid: (type: "key") => string;
4663
4769
  getSubjectKeypair: () => KeyPair;
@@ -4723,7 +4829,7 @@ export declare type AllLearnCardMethods = {
4723
4829
  * Empty error/warnings arrays means verification was successful
4724
4830
  */
4725
4831
  verifyCredential: (credential: VC) => Promise<VerificationItem[]>;
4726
- /** Creates a signed Verifiable Presentation from a signed Verifiable Credential */
4832
+ /** Signs an unsigned Verifiable Presentation, returning the signed VP */
4727
4833
  issuePresentation: (presentation: UnsignedVP) => Promise<VP>;
4728
4834
  /**
4729
4835
  * Verifies a signed Verifiable Presentation
@@ -4761,6 +4867,7 @@ export declare type AllLearnCardMethods = {
4761
4867
  * or by using `getCredentials` to get a list of all credentials that have been added to IDX
4762
4868
  */
4763
4869
  removeCredential: (title: string) => Promise<void>;
4870
+ resolveDid: (did: string) => Promise<Record<string, any>>;
4764
4871
  /**
4765
4872
  * Resolves a stream ID, returning its contents
4766
4873
  *
@@ -4825,7 +4932,7 @@ export declare type LearnCard<Methods extends keyof AllLearnCardMethods = keyof
4825
4932
  /** Raw IoE wallet instance. You shouldn't need to drop down to this level! */
4826
4933
  _wallet: RawWallet;
4827
4934
  } & Pick<AllLearnCardMethods, Methods>;
4828
- export declare type EmptyLearnCard = LearnCard<"verifyCredential" | "verifyPresentation", Wallet<"DIDKit" | "Expiration", DidkitPluginMethods & VerifyExtension>>;
4935
+ export declare type EmptyLearnCard = LearnCard<"verifyCredential" | "verifyPresentation" | "resolveDid", Wallet<"DIDKit" | "Expiration", DidkitPluginMethods & VerifyExtension>>;
4829
4936
  export declare type CeramicIDXArgs = {
4830
4937
  modelData: ModelAliases;
4831
4938
  credentialAlias: string;
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,7 +35276,7 @@ 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
35281
 
35282
35282
  // src/wallet/base/wallet.ts
@@ -35501,6 +35501,15 @@ function __wbg_adapter_24(arg0, arg1, arg2) {
35501
35501
  wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h47a829c6210a1ab1(arg0, arg1, addHeapObject(arg2));
35502
35502
  }
35503
35503
  __name(__wbg_adapter_24, "__wbg_adapter_24");
35504
+ function resolveDID(did, input_metadata) {
35505
+ const ptr0 = passStringToWasm0(did, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35506
+ const len0 = WASM_VECTOR_LEN;
35507
+ const ptr1 = passStringToWasm0(input_metadata, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35508
+ const len1 = WASM_VECTOR_LEN;
35509
+ const ret = wasm.resolveDID(ptr0, len0, ptr1, len1);
35510
+ return takeObject(ret);
35511
+ }
35512
+ __name(resolveDID, "resolveDID");
35504
35513
  function passArray8ToWasm0(arg, malloc) {
35505
35514
  const ptr = malloc(arg.length * 1);
35506
35515
  getUint8Memory0().set(arg, ptr / 1);
@@ -36055,6 +36064,9 @@ var getDidKitPlugin = /* @__PURE__ */ __name((input) => __async(void 0, null, fu
36055
36064
  }),
36056
36065
  contextLoader: (_wallet, url) => __async(void 0, null, function* () {
36057
36066
  return JSON.parse(yield contextLoader(url));
36067
+ }),
36068
+ resolveDid: (_wallet, did) => __async(void 0, null, function* () {
36069
+ return JSON.parse(yield resolveDID(did, "{}"));
36058
36070
  })
36059
36071
  }
36060
36072
  };
@@ -39124,6 +39136,13 @@ var CredentialInfoValidator = mod.object({
39124
39136
  issuee: ProfileValidator.optional(),
39125
39137
  credentialSubject: CredentialSubjectValidator.optional()
39126
39138
  });
39139
+ var StorageTypeValidator = mod.enum(["ceramic"]);
39140
+ var StorageTypeEnum = StorageTypeValidator.enum;
39141
+ var IDXCredentialValidator = mod.object({
39142
+ id: mod.string(),
39143
+ title: mod.string(),
39144
+ storageType: StorageTypeValidator.optional()
39145
+ });
39127
39146
 
39128
39147
  // ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
39129
39148
  function toInteger(dirtyNumber) {
@@ -40740,7 +40759,8 @@ var emptyWallet = /* @__PURE__ */ __name((..._0) => __async(void 0, [..._0], fun
40740
40759
  return {
40741
40760
  _wallet: wallet,
40742
40761
  verifyCredential: verifyCredential2(wallet),
40743
- verifyPresentation: wallet.pluginMethods.verifyPresentation
40762
+ verifyPresentation: wallet.pluginMethods.verifyPresentation,
40763
+ resolveDid: wallet.pluginMethods.resolveDid
40744
40764
  };
40745
40765
  }), "emptyWallet");
40746
40766
 
@@ -53434,6 +53454,18 @@ var CeramicClient = class {
53434
53454
  };
53435
53455
  __name(CeramicClient, "CeramicClient");
53436
53456
 
53457
+ // 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();
53468
+
53437
53469
  // src/wallet/plugins/idx/idx.ts
53438
53470
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
53439
53471
  const client = new CeramicClient(ceramicEndpoint);
@@ -53451,9 +53483,17 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53451
53483
  const loader = new TileLoader({ ceramic });
53452
53484
  const dataStore = new DIDDataStore({ ceramic, model: modelData });
53453
53485
  const getCredentialsListFromIdx = /* @__PURE__ */ __name((..._02) => __async(void 0, [..._02], function* (alias = credentialAlias) {
53454
- return (yield dataStore.get(alias)) || { credentials: [] };
53486
+ const list = yield dataStore.get(alias);
53487
+ if (!list)
53488
+ return { credentials: [] };
53489
+ const validationResult = yield CredentialsListValidator.spa(list);
53490
+ if (validationResult.success)
53491
+ return validationResult.data;
53492
+ console.error(validationResult.error);
53493
+ throw new Error("Invalid credentials list stored in IDX");
53455
53494
  }), "getCredentialsListFromIdx");
53456
- const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((record, alias) => __async(void 0, null, function* () {
53495
+ const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((_record, alias) => __async(void 0, null, function* () {
53496
+ const record = IDXCredentialValidator2.parse(_record);
53457
53497
  if (!record)
53458
53498
  throw new Error("record is required");
53459
53499
  if (!record.id)
@@ -53468,10 +53508,10 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53468
53508
  });
53469
53509
  if (indexOfExistingCredential > -1) {
53470
53510
  existing.credentials[indexOfExistingCredential] = __spreadValues({
53471
- storageType: "ceramic" /* ceramic */
53511
+ storageType: StorageTypeEnum.ceramic
53472
53512
  }, record);
53473
53513
  } else
53474
- existing.credentials.push(__spreadValues({ storageType: "ceramic" /* ceramic */ }, record));
53514
+ existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
53475
53515
  return dataStore.set(alias, existing);
53476
53516
  }), "addCredentialStreamIdToIdx");
53477
53517
  const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
@@ -53524,8 +53564,8 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
53524
53564
  return readContentFromCeramic(streamId);
53525
53565
  })));
53526
53566
  }),
53527
- addVerifiableCredentialInIdx: (_02, _12) => __async(void 0, [_02, _12], function* (_wallet, { title, id }) {
53528
- return addCredentialStreamIdToIdx({ title, id });
53567
+ addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
53568
+ return addCredentialStreamIdToIdx(idxCredential);
53529
53569
  }),
53530
53570
  removeVerifiableCredentialInIdx: (_wallet, title) => __async(void 0, null, function* () {
53531
53571
  return removeCredentialFromIdx(title);
@@ -57051,6 +57091,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
57051
57091
  removeCredential: (title) => __async(void 0, null, function* () {
57052
57092
  yield wallet.pluginMethods.removeVerifiableCredentialInIdx(title);
57053
57093
  }),
57094
+ resolveDid: wallet.pluginMethods.resolveDid,
57054
57095
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
57055
57096
  getTestVc: wallet.pluginMethods.getTestVc,
57056
57097
  getTestVp: wallet.pluginMethods.getTestVp,