@learncard/core 6.4.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/core.d.ts CHANGED
@@ -4645,16 +4645,10 @@ declare const VerificationItemValidator: z.ZodObject<{
4645
4645
  check: string;
4646
4646
  }>;
4647
4647
  export declare type VerificationItem = z.infer<typeof VerificationItemValidator>;
4648
- declare const StorageTypeValidator: z.ZodEnum<[
4649
- "ceramic"
4650
- ]>;
4651
- /** @group IDXPlugin */
4652
- export declare type StorageType = z.infer<typeof StorageTypeValidator>;
4653
4648
  /** @group IDXPlugin */
4654
4649
  export declare type IDXCredential<Metadata extends Record<string, any> = Record<never, never>> = {
4655
4650
  id: string;
4656
- title: string;
4657
- storageType?: StorageType;
4651
+ uri: string;
4658
4652
  [key: string]: any;
4659
4653
  } & Metadata;
4660
4654
  declare const JWKValidator: z.ZodObject<{
@@ -4750,29 +4744,16 @@ export declare type Token = {
4750
4744
  };
4751
4745
  /** @group Ethereum Plugin */
4752
4746
  export declare type TokenList = Token[];
4753
- /** @group IDXPlugin */
4754
- export declare type CeramicIDXArgs = {
4755
- modelData: ModelAliases;
4756
- credentialAlias: string;
4757
- ceramicEndpoint: string;
4758
- defaultContentFamily: string;
4747
+ /** @group VC Resolution Plugin */
4748
+ export declare type LC_URI<URI extends string = ""> = string | URI;
4749
+ /** @group VC Resolution Plugin */
4750
+ export declare type VCResolutionPluginMethods = {
4751
+ resolveCredential: (uri?: LC_URI) => Promise<VC | undefined>;
4759
4752
  };
4760
- /** @group IDXPlugin */
4761
- export declare type IDXPluginMethods = {
4762
- getCredentialsListFromIdx: <Metadata extends Record<string, any> = Record<never, never>>(alias?: string) => Promise<CredentialsList<Metadata>>;
4763
- publishContentToCeramic: (cred: any) => Promise<string>;
4764
- readContentFromCeramic: (streamId: string) => Promise<any>;
4765
- getVerifiableCredentialFromIdx: (title: string) => Promise<VC>;
4766
- getVerifiableCredentialsFromIdx: () => Promise<VC[]>;
4767
- addVerifiableCredentialInIdx: <Metadata extends Record<string, any> = Record<never, never>>(cred: IDXCredential<Metadata>) => Promise<StreamID>;
4768
- removeVerifiableCredentialInIdx: (title: string) => Promise<StreamID>;
4753
+ /** @group VC Resolution Plugin */
4754
+ export declare type ResolutionExtension<URI extends string> = {
4755
+ resolveCredential: (uri?: LC_URI<URI>) => Promise<VC | undefined>;
4769
4756
  };
4770
- /** @group IDXPlugin */
4771
- export declare type CredentialsList<Metadata extends Record<string, any> = Record<never, never>> = {
4772
- credentials: Array<IDXCredential<Metadata>>;
4773
- };
4774
- /** @group IDXPlugin */
4775
- export declare const CredentialsListValidator: z.ZodType<CredentialsList>;
4776
4757
  export declare type Last<T extends any[]> = T extends [
4777
4758
  ...any[],
4778
4759
  infer R
@@ -4806,6 +4787,52 @@ export declare type Wallet<PluginNames extends string = "", PluginMethods extend
4806
4787
  Methods
4807
4788
  ]>>>;
4808
4789
  };
4790
+ /** @group IDXPlugin */
4791
+ export declare type CeramicIDXArgs = {
4792
+ modelData: ModelAliases;
4793
+ credentialAlias: string;
4794
+ ceramicEndpoint: string;
4795
+ defaultContentFamily: string;
4796
+ };
4797
+ /** @group IDXPlugin */
4798
+ export declare type CeramicURI = `lc:ceramic:${string}`;
4799
+ /** @group IDXPlugin */
4800
+ export declare const CeramicURIValidator: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
4801
+ /** @group IDXPlugin */
4802
+ export declare type IDXPluginMethods<URI extends string = ""> = {
4803
+ getCredentialsListFromIdx: <Metadata extends Record<string, any> = Record<never, never>>(alias?: string) => Promise<CredentialsList<Metadata>>;
4804
+ publishContentToCeramic: (cred: any) => Promise<CeramicURI>;
4805
+ readContentFromCeramic: (streamId: string) => Promise<any>;
4806
+ getVerifiableCredentialFromIdx: (id: string) => Promise<VC | undefined>;
4807
+ getVerifiableCredentialsFromIdx: () => Promise<VC[]>;
4808
+ addVerifiableCredentialInIdx: <Metadata extends Record<string, any> = Record<never, never>>(cred: IDXCredential<Metadata>) => Promise<CeramicURI>;
4809
+ removeVerifiableCredentialInIdx: (title: string) => Promise<StreamID>;
4810
+ } & ResolutionExtension<URI | CeramicURI>;
4811
+ /** @group IDXPlugin */
4812
+ export declare type IDXPluginDependentMethods<URI extends string = ""> = {
4813
+ getKey: () => string;
4814
+ } & ResolutionExtension<URI>;
4815
+ /** @group IDXPlugin */
4816
+ export declare type CredentialsList<Metadata extends Record<string, any> = Record<never, never>> = {
4817
+ credentials: Array<IDXCredential<Metadata>>;
4818
+ };
4819
+ /** @group IDXPlugin */
4820
+ export declare const CredentialsListValidator: z.ZodType<CredentialsList>;
4821
+ /** @group IDXPlugin */
4822
+ export declare type BackwardsCompatIDXCredential<Metadata extends Record<string, any> = Record<never, never>> = {
4823
+ [key: string]: any;
4824
+ id: string;
4825
+ title: string;
4826
+ storageType?: "ceramic";
4827
+ } & Metadata;
4828
+ /** @group IDXPlugin */
4829
+ export declare const BackwardsCompatIDXCredentialValidator: z.ZodType<BackwardsCompatIDXCredential>;
4830
+ /** @group IDXPlugin */
4831
+ export declare type BackwardsCompatCredentialsList<Metadata extends Record<string, any> = Record<never, never>> = {
4832
+ credentials: Array<IDXCredential<Metadata> | BackwardsCompatIDXCredential<Metadata>>;
4833
+ };
4834
+ /** @group IDXPlugin */
4835
+ export declare const BackwardsCompatCredentialsListValidator: z.ZodType<BackwardsCompatCredentialsList>;
4809
4836
  /** @group VC Plugin */
4810
4837
  export declare type VCPluginDependentMethods = {
4811
4838
  getSubjectDid: (type: "key") => string;
@@ -4982,6 +5009,39 @@ export declare type VCAPIPluginMethods = {
4982
5009
  getTestVc: (subject?: string) => UnsignedVC;
4983
5010
  getTestVp: (credential?: VC) => Promise<UnsignedVP>;
4984
5011
  };
5012
+ /**
5013
+ *
5014
+ * @group Plugins
5015
+ */
5016
+ export declare const getDidKitPlugin: (input?: InitInput | Promise<InitInput>) => Promise<Plugin<"DIDKit", DidkitPluginMethods>>;
5017
+ /**
5018
+ *
5019
+ * @group Plugins
5020
+ */
5021
+ export declare const getDidKeyPlugin: <DidMethod extends string>(wallet: Wallet<string, DependentMethods<DidMethod>>, key: string) => Promise<Plugin<"DID Key", DidKeyPluginMethods<DidMethod>, Record<never, never>>>;
5022
+ /**
5023
+ * @group Plugins
5024
+ */
5025
+ export declare const getVCPlugin: (wallet: Wallet<string, VCPluginDependentMethods>) => Plugin<"VC", VCPluginMethods, VCPluginDependentMethods>;
5026
+ /**
5027
+ * @group Plugins
5028
+ */
5029
+ export declare const getIDXPlugin: <URI extends string = "">(wallet: Wallet<any, IDXPluginDependentMethods<URI>>, { modelData, credentialAlias, ceramicEndpoint, defaultContentFamily }: CeramicIDXArgs) => Promise<Plugin<"IDX", IDXPluginMethods<URI>, Record<never, never>>>;
5030
+ /**
5031
+ * @group Plugins
5032
+ */
5033
+ export declare const ExpirationPlugin: (wallet: Wallet<any, VerifyExtension>) => Plugin<"Expiration", VerifyExtension>;
5034
+ /**
5035
+ * @group Plugins
5036
+ */
5037
+ export declare const getEthereumPlugin: (initWallet: Wallet<string, {
5038
+ getSubjectDid: (type: DidMethod) => string;
5039
+ getSubjectKeypair: (type?: Algorithm) => JWK;
5040
+ }>, config: EthereumConfig) => Plugin<"Ethereum", EthereumPluginMethods>;
5041
+ /**
5042
+ * @group Plugins
5043
+ */
5044
+ export declare const getVpqrPlugin: (wallet: Wallet<string, VpqrPluginDependentMethods>) => Plugin<"Vpqr", VpqrPluginMethods>;
4985
5045
  /**
4986
5046
  * Wallet holder's did
4987
5047
  *
@@ -5047,7 +5107,7 @@ export declare type VerifyPresentation = (presentation: VP, options?: Partial<Pr
5047
5107
  *
5048
5108
  * @group LearnCard Methods
5049
5109
  */
5050
- export declare type GetCredential = (title: string) => Promise<VC>;
5110
+ export declare type GetCredential = (title: string) => Promise<VC | undefined>;
5051
5111
  /**
5052
5112
  * Returns all credentials from IDX
5053
5113
  *
@@ -5061,35 +5121,31 @@ export declare type GetCredentials = () => Promise<VC[]>;
5061
5121
  */
5062
5122
  export declare type GetCredentialsList = <Metadata extends Record<string, any> = Record<never, never>>() => Promise<IDXCredential<Metadata>[]>;
5063
5123
  /**
5064
- * Publishes a credential to Ceramic, returning the credential's stream ID
5124
+ * Publishes a credential to Ceramic, returning the credential's Ceramic URI
5065
5125
  *
5066
- * This stream ID may then be shared/persisted/resolved to gain access to the credential
5126
+ * This URI may then be shared/persisted/resolved to gain access to the credential
5067
5127
  *
5068
- * Resolving a stream ID can be done by passing the stream ID to `readFromCeramic`
5128
+ * Resolving a URI can be done by passing the URI to `resolveCredential`
5069
5129
  *
5070
5130
  * @group LearnCard Methods
5071
5131
  */
5072
- export declare type PublishCredential = (credential: VC) => Promise<string>;
5132
+ export declare type PublishCredential = (credential: VC) => Promise<CeramicURI>;
5073
5133
  /**
5074
- * Adds a stream ID pointing to a credential (such as the one returned by `publishCredential`)
5075
- * to IDX with a bespoke title
5134
+ * Adds a URI pointing to a credential (such as the one returned by `publishCredential`)
5135
+ * to IDX with a bespoke ID
5076
5136
  *
5077
- * The credential may then be retrieved using `getCredential` and passing in that bespoke title,
5078
- * or by using `getCredentials` to get a list of all credentials that have been added to IDX
5137
+ * The credential may then be retrieved using `getCredential` and passing in that bespoke ID,
5138
+ * or by using `getCredentials`/`getCredentialsList` to get a list of all credentials that have been added to IDX
5079
5139
  *
5080
5140
  * @group LearnCard Methods
5081
5141
  */
5082
5142
  export declare type AddCredential = <Metadata extends Record<string, any> = Record<never, never>>(credential: IDXCredential<Metadata>) => Promise<void>;
5083
5143
  /**
5084
- * Adds a stream ID pointing to a credential (such as the one returned by `publishCredential`)
5085
- * to IDX with a bespoke title
5086
- *
5087
- * The credential may then be retrieved using `getCredential` and passing in that bespoke title,
5088
- * or by using `getCredentials` to get a list of all credentials that have been added to IDX
5144
+ * Removes a credential from IDX by passing in its bespoke ID
5089
5145
  *
5090
5146
  * @group LearnCard Methods
5091
5147
  */
5092
- export declare type RemoveCredential = (title: string) => Promise<void>;
5148
+ export declare type RemoveCredential = (id: string) => Promise<void>;
5093
5149
  /**
5094
5150
  * Resolves a did to its did document
5095
5151
  *
@@ -5099,12 +5155,18 @@ export declare type ResolveDid = (did: string, inputMetadata?: InputMetadata) =>
5099
5155
  /**
5100
5156
  * Resolves a stream ID, returning its contents
5101
5157
  *
5158
+ * @group LearnCard Methods
5159
+ */
5160
+ export declare type ReadFromCeramic = (streamId: string) => Promise<any>;
5161
+ /**
5162
+ * Resolves a LearnCard URI (e.g. lc:ceramic:1234561)
5163
+ *
5102
5164
  * This can be given the return value of `publishCredential` to gain access to the credential
5103
5165
  * that was published
5104
5166
  *
5105
5167
  * @group LearnCard Methods
5106
5168
  */
5107
- export declare type ReadFromCeramic = (streamId: string) => Promise<any>;
5169
+ export declare type ResolveCredential = (URI?: string | "" | `lc:ceramic:${string}`) => Promise<VC | undefined>;
5108
5170
  /**
5109
5171
  * Returns an example credential, optionally allowing a subject's did to be passed in
5110
5172
  *
@@ -5238,6 +5300,7 @@ export declare type AllLearnCardMethods = {
5238
5300
  removeCredential: RemoveCredential;
5239
5301
  resolveDid: ResolveDid;
5240
5302
  readFromCeramic: ReadFromCeramic;
5303
+ resolveCredential: ResolveCredential;
5241
5304
  getTestVc: GetTestVc;
5242
5305
  getTestVp: GetTestVp;
5243
5306
  getEthereumAddress: GetEthereumAddress;
@@ -5256,10 +5319,11 @@ export declare type AllLearnCardMethods = {
5256
5319
  storeCredentialViaChapiDidAuth: StoreCredentialViaChapiDidAuth;
5257
5320
  };
5258
5321
  /** @group Universal Wallets */
5259
- export declare type LearnCardRawWallet = Wallet<"DIDKit" | "DID Key" | "VC" | "VC Templates" | "IDX" | "Expiration" | "Ethereum" | "Vpqr" | "CHAPI", MergeObjects<[
5322
+ export declare type LearnCardRawWallet = Wallet<"DIDKit" | "DID Key" | "VC" | "VC Templates" | "VC Resolution" | "IDX" | "Expiration" | "Ethereum" | "Vpqr" | "CHAPI", MergeObjects<[
5260
5323
  DidKeyPluginMethods<DidMethod>,
5261
5324
  VCPluginMethods,
5262
5325
  VCTemplatePluginMethods,
5326
+ VCResolutionPluginMethods,
5263
5327
  IDXPluginMethods,
5264
5328
  EthereumPluginMethods,
5265
5329
  VpqrPluginMethods,
@@ -5352,41 +5416,6 @@ export declare function initLearnCard(config: WalletFromKey["args"]): Promise<Wa
5352
5416
  export declare function initLearnCard(config: WalletFromVcApi["args"]): Promise<WalletFromVcApi["returnValue"]>;
5353
5417
  /** @group Universal Wallets */
5354
5418
  export declare const generateWallet: <PluginNames extends string, PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>>(contents?: any[], _wallet?: Partial<Wallet<any, PluginMethods>>) => Promise<Wallet<PluginNames, PluginMethods>>;
5355
- /**
5356
- *
5357
- * @group Plugins
5358
- */
5359
- export declare const getDidKitPlugin: (input?: InitInput | Promise<InitInput>) => Promise<Plugin<"DIDKit", DidkitPluginMethods>>;
5360
- /**
5361
- *
5362
- * @group Plugins
5363
- */
5364
- export declare const getDidKeyPlugin: <DidMethod extends string>(wallet: Wallet<string, DependentMethods<DidMethod>>, key: string) => Promise<Plugin<"DID Key", DidKeyPluginMethods<DidMethod>, Record<never, never>>>;
5365
- /**
5366
- * @group Plugins
5367
- */
5368
- export declare const getVCPlugin: (wallet: Wallet<string, VCPluginDependentMethods>) => Plugin<"VC", VCPluginMethods, VCPluginDependentMethods>;
5369
- /**
5370
- * @group Plugins
5371
- */
5372
- export declare const getIDXPlugin: (wallet: Wallet<any, {
5373
- getKey: () => string;
5374
- }>, { modelData, credentialAlias, ceramicEndpoint, defaultContentFamily }: CeramicIDXArgs) => Promise<Plugin<"IDX", IDXPluginMethods>>;
5375
- /**
5376
- * @group Plugins
5377
- */
5378
- export declare const ExpirationPlugin: (wallet: Wallet<any, VerifyExtension>) => Plugin<"Expiration", VerifyExtension>;
5379
- /**
5380
- * @group Plugins
5381
- */
5382
- export declare const getEthereumPlugin: (initWallet: Wallet<string, {
5383
- getSubjectDid: (type: DidMethod) => string;
5384
- getSubjectKeypair: (type?: Algorithm) => JWK;
5385
- }>, config: EthereumConfig) => Plugin<"Ethereum", EthereumPluginMethods>;
5386
- /**
5387
- * @group Plugins
5388
- */
5389
- export declare const getVpqrPlugin: (wallet: Wallet<string, VpqrPluginDependentMethods>) => Plugin<"Vpqr", VpqrPluginMethods>;
5390
5419
  export * from "@wallet/init";
5391
5420
  export { Wallet, Plugin } from "types/wallet";
5392
5421
  export * from "types/LearnCard";
package/dist/core.esm.js CHANGED
@@ -42367,13 +42367,7 @@ var CredentialInfoValidator = mod.object({
42367
42367
  issuee: ProfileValidator.optional(),
42368
42368
  credentialSubject: CredentialSubjectValidator.optional()
42369
42369
  });
42370
- var StorageTypeValidator = mod.enum(["ceramic"]);
42371
- var StorageTypeEnum = StorageTypeValidator.enum;
42372
- var IDXCredentialValidator = mod.object({
42373
- id: mod.string(),
42374
- title: mod.string(),
42375
- storageType: StorageTypeValidator.optional()
42376
- }).catchall(mod.any());
42370
+ var IDXCredentialValidator = mod.object({ id: mod.string(), uri: mod.string() }).catchall(mod.any());
42377
42371
  var JWKValidator = mod.object({
42378
42372
  kty: mod.string(),
42379
42373
  crv: mod.string(),
@@ -56701,8 +56695,16 @@ var CeramicClient = class {
56701
56695
  };
56702
56696
  __name(CeramicClient, "CeramicClient");
56703
56697
 
56698
+ // src/wallet/plugins/idx/helpers.ts
56699
+ var streamIdToCeramicURI = /* @__PURE__ */ __name((id) => `lc:ceramic:${id}`, "streamIdToCeramicURI");
56700
+
56704
56701
  // src/wallet/plugins/idx/types.ts
56702
+ var CeramicURIValidator = mod.string().refine((string2) => string2.split(":").length === 3 && string2.split(":")[0] === "lc", "URI must be of the form lc:${storage}:${url}").refine((string2) => string2.split(":")[1] === "ceramic", "URI must use storage type ceramic (i.e. must be lc:ceramic:${streamID})");
56705
56703
  var CredentialsListValidator = mod.object({ credentials: IDXCredentialValidator.array() }).strict();
56704
+ var BackwardsCompatIDXCredentialValidator = mod.object({ id: mod.string(), title: mod.string(), storageType: mod.literal("ceramic").optional() }).catchall(mod.any());
56705
+ var BackwardsCompatCredentialsListValidator = mod.object({
56706
+ credentials: IDXCredentialValidator.or(BackwardsCompatIDXCredentialValidator).array()
56707
+ }).strict();
56706
56708
 
56707
56709
  // src/wallet/plugins/idx/idx.ts
56708
56710
  var getCeramicClientFromWalletSuite = /* @__PURE__ */ __name((wallet, ceramicEndpoint) => __async(void 0, null, function* () {
@@ -56727,38 +56729,32 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
56727
56729
  const validationResult = yield CredentialsListValidator.spa(list);
56728
56730
  if (validationResult.success)
56729
56731
  return validationResult.data;
56732
+ const backwardsCompatValidationResult = yield BackwardsCompatCredentialsListValidator.spa(list);
56733
+ if (backwardsCompatValidationResult.success) {
56734
+ const oldCreds = backwardsCompatValidationResult.data.credentials;
56735
+ const newCreds = oldCreds.map((cred) => {
56736
+ if ("uri" in cred)
56737
+ return cred;
56738
+ const _a = cred, { title, id, storageType } = _a, rest = __objRest(_a, ["title", "id", "storageType"]);
56739
+ return __spreadProps(__spreadValues({}, rest), {
56740
+ id: title,
56741
+ uri: `lc:ceramic:${id.replace("ceramic://", "")}`
56742
+ });
56743
+ });
56744
+ const credentialsList = { credentials: newCreds };
56745
+ yield dataStore.set(credentialAlias, credentialsList);
56746
+ return credentialsList;
56747
+ }
56730
56748
  console.error(validationResult.error);
56731
56749
  throw new Error("Invalid credentials list stored in IDX");
56732
56750
  }), "getCredentialsListFromIdx");
56733
- const addCredentialStreamIdToIdx = /* @__PURE__ */ __name((_record, alias) => __async(void 0, null, function* () {
56734
- const record = IDXCredentialValidator.parse(_record);
56735
- if (!record)
56736
- throw new Error("record is required");
56737
- if (!record.id)
56738
- throw Error("No streamId provided");
56739
- if (record.id.indexOf("ceramic://") === -1)
56740
- record.id = "ceramic://" + record.id;
56741
- if (!alias)
56742
- alias = credentialAlias;
56743
- const existing = yield getCredentialsListFromIdx(alias);
56744
- const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
56745
- return credential.title === record.title;
56746
- });
56747
- if (indexOfExistingCredential > -1) {
56748
- existing.credentials[indexOfExistingCredential] = __spreadValues({
56749
- storageType: StorageTypeEnum.ceramic
56750
- }, record);
56751
- } else
56752
- existing.credentials.push(__spreadValues({ storageType: StorageTypeEnum.ceramic }, record));
56753
- return dataStore.set(alias, existing);
56754
- }), "addCredentialStreamIdToIdx");
56755
- const removeCredentialFromIdx = /* @__PURE__ */ __name((title, alias) => __async(void 0, null, function* () {
56756
- if (!title)
56757
- throw new Error("record is required");
56751
+ const removeCredentialFromIdx = /* @__PURE__ */ __name((id, alias) => __async(void 0, null, function* () {
56752
+ if (!id)
56753
+ throw new Error("Must provide id to remove");
56758
56754
  if (!alias)
56759
56755
  alias = credentialAlias;
56760
56756
  const existing = yield getCredentialsListFromIdx(alias);
56761
- existing.credentials = existing.credentials.filter((credential) => credential.title !== title);
56757
+ existing.credentials = existing.credentials.filter((credential) => credential.id !== id);
56762
56758
  return dataStore.set(alias, existing);
56763
56759
  }), "removeCredentialFromIdx");
56764
56760
  const publishContentToCeramic = /* @__PURE__ */ __name((_02, ..._12) => __async(void 0, [_02, ..._12], function* (content, metadata = {}, options = {}) {
@@ -56783,30 +56779,56 @@ var getIDXPlugin = /* @__PURE__ */ __name((_0, _1) => __async(void 0, [_0, _1],
56783
56779
  return getCredentialsListFromIdx(alias);
56784
56780
  }),
56785
56781
  publishContentToCeramic: (_wallet, cred) => __async(void 0, null, function* () {
56786
- return publishContentToCeramic(cred);
56782
+ return streamIdToCeramicURI(yield publishContentToCeramic(cred));
56787
56783
  }),
56788
56784
  readContentFromCeramic: (_wallet, streamId) => __async(void 0, null, function* () {
56789
56785
  return readContentFromCeramic(streamId);
56790
56786
  }),
56791
- getVerifiableCredentialFromIdx: (_wallet, title) => __async(void 0, null, function* () {
56787
+ getVerifiableCredentialFromIdx: (_wallet, id) => __async(void 0, null, function* () {
56792
56788
  var _a;
56793
56789
  const credentialList = yield getCredentialsListFromIdx();
56794
- const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.title) === title);
56795
- return credential && (yield readContentFromCeramic(credential.id));
56790
+ const credential = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.find((cred) => (cred == null ? void 0 : cred.id) === id);
56791
+ return (credential == null ? void 0 : credential.uri) ? _wallet.pluginMethods.resolveCredential(credential.uri) : void 0;
56796
56792
  }),
56797
- getVerifiableCredentialsFromIdx: () => __async(void 0, null, function* () {
56793
+ getVerifiableCredentialsFromIdx: (_wallet) => __async(void 0, null, function* () {
56798
56794
  var _a, _b;
56799
56795
  const credentialList = yield getCredentialsListFromIdx();
56800
- const streamIds = (_b = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.map((credential) => credential == null ? void 0 : credential.id)) != null ? _b : [];
56801
- return Promise.all(streamIds.map((streamId) => __async(void 0, null, function* () {
56802
- return readContentFromCeramic(streamId);
56803
- })));
56796
+ const uris = (_b = (_a = credentialList == null ? void 0 : credentialList.credentials) == null ? void 0 : _a.map((credential) => credential == null ? void 0 : credential.uri)) != null ? _b : [];
56797
+ return (yield Promise.all(uris.map((uri) => __async(void 0, null, function* () {
56798
+ return _wallet.pluginMethods.resolveCredential(uri);
56799
+ })))).filter((vc) => !!vc);
56804
56800
  }),
56805
56801
  addVerifiableCredentialInIdx: (_wallet, idxCredential) => __async(void 0, null, function* () {
56806
- return addCredentialStreamIdToIdx(idxCredential);
56802
+ const record = IDXCredentialValidator.parse(idxCredential);
56803
+ if (!record)
56804
+ throw new Error("record is required");
56805
+ if (!record.uri)
56806
+ throw Error("No URI provided");
56807
+ yield _wallet.pluginMethods.resolveCredential(record.uri);
56808
+ const existing = yield getCredentialsListFromIdx(credentialAlias);
56809
+ const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
56810
+ return credential.id === record.id;
56811
+ });
56812
+ if (indexOfExistingCredential > -1) {
56813
+ existing.credentials[indexOfExistingCredential] = record;
56814
+ } else
56815
+ existing.credentials.push(record);
56816
+ return streamIdToCeramicURI(yield dataStore.set(credentialAlias, existing));
56817
+ }),
56818
+ removeVerifiableCredentialInIdx: (_wallet, id) => __async(void 0, null, function* () {
56819
+ return removeCredentialFromIdx(id);
56807
56820
  }),
56808
- removeVerifiableCredentialInIdx: (_wallet, title) => __async(void 0, null, function* () {
56809
- return removeCredentialFromIdx(title);
56821
+ resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
56822
+ if (!uri)
56823
+ return void 0;
56824
+ if (uri.startsWith("ceramic://")) {
56825
+ return VCValidator.parseAsync(yield readContentFromCeramic(uri));
56826
+ }
56827
+ const verificationResult = yield CeramicURIValidator.spa(uri);
56828
+ if (!verificationResult.success)
56829
+ return wallet.pluginMethods.resolveCredential(uri);
56830
+ const streamId = verificationResult.data.split(":")[2];
56831
+ return VCValidator.parseAsync(yield readContentFromCeramic(streamId));
56810
56832
  })
56811
56833
  }
56812
56834
  };
@@ -60297,6 +60319,15 @@ var defaultEthereumArgs = {
60297
60319
  network: "mainnet"
60298
60320
  };
60299
60321
 
60322
+ // src/wallet/plugins/vc-resolution/index.ts
60323
+ var VCResolutionPlugin = {
60324
+ pluginMethods: {
60325
+ resolveCredential: (_wallet, uri) => __async(void 0, null, function* () {
60326
+ throw new Error(`No Credential Resolution Plugins found that can resolve ${uri}`);
60327
+ })
60328
+ }
60329
+ };
60330
+
60300
60331
  // src/wallet/initializers/walletFromKey.ts
60301
60332
  var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, ..._1], function* (key2, {
60302
60333
  ceramicIdx = defaultCeramicIDXArgs,
@@ -60308,7 +60339,8 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
60308
60339
  const didkeyWallet = yield didkitWallet.addPlugin(yield getDidKeyPlugin(didkitWallet, key2));
60309
60340
  const didkeyAndVCWallet = yield didkeyWallet.addPlugin(getVCPlugin(didkeyWallet));
60310
60341
  const templateWallet = yield didkeyAndVCWallet.addPlugin(getVCTemplatesPlugin());
60311
- const idxWallet = yield templateWallet.addPlugin(yield getIDXPlugin(templateWallet, ceramicIdx));
60342
+ const resolutionWallet = yield templateWallet.addPlugin(VCResolutionPlugin);
60343
+ const idxWallet = yield resolutionWallet.addPlugin(yield getIDXPlugin(resolutionWallet, ceramicIdx));
60312
60344
  const expirationWallet = yield idxWallet.addPlugin(ExpirationPlugin(idxWallet));
60313
60345
  const ethWallet = yield expirationWallet.addPlugin(getEthereumPlugin(expirationWallet, ethereumConfig));
60314
60346
  const vpqrWallet = yield ethWallet.addPlugin(getVpqrPlugin(ethWallet));
@@ -60337,6 +60369,7 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
60337
60369
  }),
60338
60370
  resolveDid: wallet.pluginMethods.resolveDid,
60339
60371
  readFromCeramic: wallet.pluginMethods.readContentFromCeramic,
60372
+ resolveCredential: wallet.pluginMethods.resolveCredential,
60340
60373
  getTestVc: wallet.pluginMethods.getTestVc,
60341
60374
  getTestVp: wallet.pluginMethods.getTestVp,
60342
60375
  vpFromQrCode: wallet.pluginMethods.vpFromQrCode,
@@ -60488,6 +60521,9 @@ function initLearnCard() {
60488
60521
  }
60489
60522
  __name(initLearnCard, "initLearnCard");
60490
60523
  export {
60524
+ BackwardsCompatCredentialsListValidator,
60525
+ BackwardsCompatIDXCredentialValidator,
60526
+ CeramicURIValidator,
60491
60527
  CredentialsListValidator,
60492
60528
  ExpirationPlugin,
60493
60529
  emptyWallet,