@learncard/core 6.2.0 → 6.4.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,33 +4645,40 @@ declare const VerificationItemValidator: z.ZodObject<{
4645
4645
  check: string;
4646
4646
  }>;
4647
4647
  export declare type VerificationItem = z.infer<typeof VerificationItemValidator>;
4648
- declare const IDXCredentialValidator: z.ZodObject<{
4649
- id: z.ZodString;
4650
- title: z.ZodString;
4651
- storageType: z.ZodOptional<z.ZodEnum<[
4652
- "ceramic"
4653
- ]>>;
4654
- }, "strip", z.ZodTypeAny, {
4655
- storageType?: "ceramic" | undefined;
4648
+ declare const StorageTypeValidator: z.ZodEnum<[
4649
+ "ceramic"
4650
+ ]>;
4651
+ /** @group IDXPlugin */
4652
+ export declare type StorageType = z.infer<typeof StorageTypeValidator>;
4653
+ /** @group IDXPlugin */
4654
+ export declare type IDXCredential<Metadata extends Record<string, any> = Record<never, never>> = {
4656
4655
  id: string;
4657
4656
  title: string;
4657
+ storageType?: StorageType;
4658
+ [key: string]: any;
4659
+ } & Metadata;
4660
+ declare const JWKValidator: z.ZodObject<{
4661
+ kty: z.ZodString;
4662
+ crv: z.ZodString;
4663
+ x: z.ZodString;
4664
+ y: z.ZodOptional<z.ZodString>;
4665
+ d: z.ZodString;
4666
+ }, "strip", z.ZodTypeAny, {
4667
+ y?: string | undefined;
4668
+ kty: string;
4669
+ crv: string;
4670
+ x: string;
4671
+ d: string;
4658
4672
  }, {
4659
- storageType?: "ceramic" | undefined;
4660
- id: string;
4661
- title: string;
4662
- }>;
4663
- /** @group IDXPlugin */
4664
- export declare type IDXCredential = z.infer<typeof IDXCredentialValidator>;
4665
- /** @group DIDKit Plugin */
4666
- 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}`;
4667
- /** @group DIDKit Plugin */
4668
- export declare type KeyPair = {
4673
+ y?: string | undefined;
4669
4674
  kty: string;
4670
4675
  crv: string;
4671
4676
  x: string;
4672
- y?: string;
4673
4677
  d: string;
4674
- };
4678
+ }>;
4679
+ export declare type JWK = z.infer<typeof JWKValidator>;
4680
+ /** @group DIDKit Plugin */
4681
+ 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}`;
4675
4682
  /** @group DIDKit Plugin */
4676
4683
  export declare type ProofOptions = {
4677
4684
  type?: string;
@@ -4691,13 +4698,13 @@ export declare type InputMetadata = {
4691
4698
  };
4692
4699
  /** @group DIDKit Plugin */
4693
4700
  export declare type DidkitPluginMethods = {
4694
- generateEd25519KeyFromBytes: (bytes: Uint8Array) => KeyPair;
4695
- generateSecp256k1KeyFromBytes: (bytes: Uint8Array) => KeyPair;
4696
- keyToDid: (type: DidMethod, keypair: KeyPair) => string;
4697
- keyToVerificationMethod: (type: string, keypair: KeyPair) => Promise<string>;
4698
- issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: KeyPair) => Promise<VC>;
4701
+ generateEd25519KeyFromBytes: (bytes: Uint8Array) => JWK;
4702
+ generateSecp256k1KeyFromBytes: (bytes: Uint8Array) => JWK;
4703
+ keyToDid: (type: DidMethod, keypair: JWK) => string;
4704
+ keyToVerificationMethod: (type: string, keypair: JWK) => Promise<string>;
4705
+ issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: JWK) => Promise<VC>;
4699
4706
  verifyCredential: (credential: VC, options?: ProofOptions) => Promise<VerificationCheck>;
4700
- issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: KeyPair) => Promise<VP>;
4707
+ issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: JWK) => Promise<VP>;
4701
4708
  verifyPresentation: (presentation: VP, options?: ProofOptions) => Promise<VerificationCheck>;
4702
4709
  contextLoader: (url: string) => Promise<Record<string, any>>;
4703
4710
  resolveDid: (did: string, inputMetadata?: InputMetadata) => Promise<Record<string, any>>;
@@ -4706,37 +4713,14 @@ export declare type DidkitPluginMethods = {
4706
4713
  export declare type Algorithm = "ed25519" | "secp256k1";
4707
4714
  /** @group DidKey Plugin */
4708
4715
  export declare type DependentMethods<T extends string> = {
4709
- generateEd25519KeyFromBytes: (bytes: Uint8Array) => KeyPair;
4710
- generateSecp256k1KeyFromBytes: (bytes: Uint8Array) => KeyPair;
4711
- keyToDid: (type: T, keypair: KeyPair) => string;
4712
- };
4713
- /** @group DidKey Plugin */
4714
- export declare type JWK = {
4715
- id: string;
4716
- type: string | string[];
4717
- controller?: string;
4718
- publicKeyJwk?: any;
4719
- privateKeyJwk?: any;
4720
- "@context": string[];
4721
- name: string;
4722
- image: string;
4723
- description: string;
4724
- tags: string[];
4725
- value?: string;
4726
- generatedFrom?: [
4727
- string
4728
- ];
4716
+ generateEd25519KeyFromBytes: (bytes: Uint8Array) => JWK;
4717
+ generateSecp256k1KeyFromBytes: (bytes: Uint8Array) => JWK;
4718
+ keyToDid: (type: T, keypair: JWK) => string;
4729
4719
  };
4730
4720
  /** @group DidKey Plugin */
4731
4721
  export declare type DidKeyPluginMethods<DidMethod extends string> = {
4732
4722
  getSubjectDid: (type: DidMethod) => string;
4733
- getSubjectKeypair: (type?: Algorithm) => {
4734
- kty: string;
4735
- crv: string;
4736
- x: string;
4737
- y?: string;
4738
- d: string;
4739
- };
4723
+ getSubjectKeypair: (type?: Algorithm) => JWK;
4740
4724
  getKey: () => string;
4741
4725
  };
4742
4726
  /** @group Ethereum Plugin */
@@ -4775,46 +4759,20 @@ export declare type CeramicIDXArgs = {
4775
4759
  };
4776
4760
  /** @group IDXPlugin */
4777
4761
  export declare type IDXPluginMethods = {
4778
- getCredentialsListFromIdx: (alias?: string) => Promise<CredentialsList>;
4762
+ getCredentialsListFromIdx: <Metadata extends Record<string, any> = Record<never, never>>(alias?: string) => Promise<CredentialsList<Metadata>>;
4779
4763
  publishContentToCeramic: (cred: any) => Promise<string>;
4780
4764
  readContentFromCeramic: (streamId: string) => Promise<any>;
4781
4765
  getVerifiableCredentialFromIdx: (title: string) => Promise<VC>;
4782
4766
  getVerifiableCredentialsFromIdx: () => Promise<VC[]>;
4783
- addVerifiableCredentialInIdx: (cred: IDXCredential) => Promise<StreamID>;
4767
+ addVerifiableCredentialInIdx: <Metadata extends Record<string, any> = Record<never, never>>(cred: IDXCredential<Metadata>) => Promise<StreamID>;
4784
4768
  removeVerifiableCredentialInIdx: (title: string) => Promise<StreamID>;
4785
4769
  };
4786
4770
  /** @group IDXPlugin */
4787
- export declare const CredentialsListValidator: z.ZodObject<{
4788
- credentials: z.ZodArray<z.ZodObject<{
4789
- id: z.ZodString;
4790
- title: z.ZodString;
4791
- storageType: z.ZodOptional<z.ZodEnum<[
4792
- "ceramic"
4793
- ]>>;
4794
- }, "strip", z.ZodTypeAny, {
4795
- storageType?: "ceramic" | undefined;
4796
- id: string;
4797
- title: string;
4798
- }, {
4799
- storageType?: "ceramic" | undefined;
4800
- id: string;
4801
- title: string;
4802
- }>, "many">;
4803
- }, "strict", z.ZodTypeAny, {
4804
- credentials: {
4805
- storageType?: "ceramic" | undefined;
4806
- id: string;
4807
- title: string;
4808
- }[];
4809
- }, {
4810
- credentials: {
4811
- storageType?: "ceramic" | undefined;
4812
- id: string;
4813
- title: string;
4814
- }[];
4815
- }>;
4771
+ export declare type CredentialsList<Metadata extends Record<string, any> = Record<never, never>> = {
4772
+ credentials: Array<IDXCredential<Metadata>>;
4773
+ };
4816
4774
  /** @group IDXPlugin */
4817
- export declare type CredentialsList = z.infer<typeof CredentialsListValidator>;
4775
+ export declare const CredentialsListValidator: z.ZodType<CredentialsList>;
4818
4776
  export declare type Last<T extends any[]> = T extends [
4819
4777
  ...any[],
4820
4778
  infer R
@@ -4851,11 +4809,11 @@ export declare type Wallet<PluginNames extends string = "", PluginMethods extend
4851
4809
  /** @group VC Plugin */
4852
4810
  export declare type VCPluginDependentMethods = {
4853
4811
  getSubjectDid: (type: "key") => string;
4854
- getSubjectKeypair: () => KeyPair;
4855
- keyToVerificationMethod: (type: string, keypair: KeyPair) => Promise<string>;
4856
- issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: KeyPair) => Promise<VC>;
4812
+ getSubjectKeypair: () => JWK;
4813
+ keyToVerificationMethod: (type: string, keypair: JWK) => Promise<string>;
4814
+ issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: JWK) => Promise<VC>;
4857
4815
  verifyCredential: (credential: VC, options?: ProofOptions) => Promise<VerificationCheck>;
4858
- issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: KeyPair) => Promise<VP>;
4816
+ issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: JWK) => Promise<VP>;
4859
4817
  verifyPresentation: (presentation: VP, options?: ProofOptions) => Promise<VerificationCheck>;
4860
4818
  };
4861
4819
  /** @group VC Plugin */
@@ -4963,14 +4921,14 @@ export declare type CHAPIPluginMethods = {
4963
4921
  success: false;
4964
4922
  reason: "did not auth" | "auth failed verification" | "did not store";
4965
4923
  }>;
4966
- storePresentationViaChapi: (presentation: VP) => Promise<Credential | undefined>;
4924
+ storePresentationViaChapi: (presentation: UnsignedVP | VP) => Promise<Credential | undefined>;
4967
4925
  };
4968
4926
  /**
4969
4927
  * @group Plugins
4970
4928
  */
4971
4929
  export declare const getCHAPIPlugin: () => Promise<Plugin<"CHAPI", CHAPIPluginMethods, CHAPIPluginDependentMethods>>;
4972
- export declare type InitFunction<Args extends Record<string, any> | undefined = Record<string, any>, Config extends keyof LearnCardConfig = keyof LearnCardConfig, ReturnValue extends LearnCard<any, any> = LearnCard<any, any>> = {
4973
- args: undefined extends Args ? Partial<Pick<LearnCardConfig, Config>> : Args & Partial<Pick<LearnCardConfig, Config>>;
4930
+ export declare type InitFunction<Args extends Record<string, any> = Record<string, any>, Config extends keyof LearnCardConfig = keyof LearnCardConfig, ReturnValue extends LearnCard<any, any> = LearnCard<any, any>> = {
4931
+ args: Args & Partial<Pick<LearnCardConfig, Config>>;
4974
4932
  returnValue: ReturnValue;
4975
4933
  };
4976
4934
  export declare type GenericInitFunction<InitFunctions extends InitFunction<any, any, any>[]> = {
@@ -5008,6 +4966,22 @@ export declare type VCTemplatePluginMethods = {
5008
4966
  did?: string;
5009
4967
  }) => Promise<UnsignedVP>;
5010
4968
  };
4969
+ /** @group VC-API Plugin */
4970
+ export declare type APIOptions = {
4971
+ created?: string;
4972
+ challenge?: string;
4973
+ domain?: string;
4974
+ };
4975
+ /** @group VC-API Plugin */
4976
+ export declare type VCAPIPluginMethods = {
4977
+ getSubjectDid: (type: string) => string;
4978
+ issueCredential: (credential: UnsignedVC, signingOptions?: APIOptions) => Promise<VC>;
4979
+ verifyCredential: (credential: VC, options?: Omit<APIOptions, "created">) => Promise<VerificationCheck>;
4980
+ issuePresentation: (presentation: UnsignedVP, signingOptions?: APIOptions) => Promise<VP>;
4981
+ verifyPresentation: (presentation: VP, options?: Omit<APIOptions, "created">) => Promise<VerificationCheck>;
4982
+ getTestVc: (subject?: string) => UnsignedVC;
4983
+ getTestVp: (credential?: VC) => Promise<UnsignedVP>;
4984
+ };
5011
4985
  /**
5012
4986
  * Wallet holder's did
5013
4987
  *
@@ -5085,7 +5059,7 @@ export declare type GetCredentials = () => Promise<VC[]>;
5085
5059
  *
5086
5060
  * @group LearnCard Methods
5087
5061
  */
5088
- export declare type GetCredentialsList = () => Promise<IDXCredential[]>;
5062
+ export declare type GetCredentialsList = <Metadata extends Record<string, any> = Record<never, never>>() => Promise<IDXCredential<Metadata>[]>;
5089
5063
  /**
5090
5064
  * Publishes a credential to Ceramic, returning the credential's stream ID
5091
5065
  *
@@ -5105,7 +5079,7 @@ export declare type PublishCredential = (credential: VC) => Promise<string>;
5105
5079
  *
5106
5080
  * @group LearnCard Methods
5107
5081
  */
5108
- export declare type AddCredential = (credential: IDXCredential) => Promise<void>;
5082
+ export declare type AddCredential = <Metadata extends Record<string, any> = Record<never, never>>(credential: IDXCredential<Metadata>) => Promise<void>;
5109
5083
  /**
5110
5084
  * Adds a stream ID pointing to a credential (such as the one returned by `publishCredential`)
5111
5085
  * to IDX with a bespoke title
@@ -5307,6 +5281,15 @@ export declare type EmptyLearnCard = LearnCard<"newCredential" | "newPresentatio
5307
5281
  VCTemplatePluginMethods,
5308
5282
  CHAPIPluginMethods
5309
5283
  ]>>>;
5284
+ /**
5285
+ * @group LearnCard
5286
+ */
5287
+ export declare type VCAPILearnCard = LearnCard<"did" | "newCredential" | "newPresentation" | "issueCredential" | "verifyCredential" | "issuePresentation" | "verifyPresentation" | "getTestVc" | "getTestVp" | "installChapiHandler" | "activateChapiHandler" | "receiveChapiEvent" | "storePresentationViaChapi" | "storeCredentialViaChapiDidAuth", Wallet<"VC API" | "Expiration" | "VC Templates" | "CHAPI", MergeObjects<[
5288
+ VCAPIPluginMethods,
5289
+ VerifyExtension,
5290
+ VCTemplatePluginMethods,
5291
+ CHAPIPluginMethods
5292
+ ]>>>;
5310
5293
  /** @group LearnCard */
5311
5294
  export declare type LearnCardConfig = {
5312
5295
  ceramicIdx: CeramicIDXArgs;
@@ -5315,15 +5298,21 @@ export declare type LearnCardConfig = {
5315
5298
  ethereumConfig: EthereumConfig;
5316
5299
  };
5317
5300
  /** @group Init Functions */
5318
- export declare type EmptyWallet = InitFunction<undefined, "didkit", EmptyLearnCard>;
5301
+ export declare type EmptyWallet = InitFunction<{}, "didkit", EmptyLearnCard>;
5319
5302
  /** @group Init Functions */
5320
5303
  export declare type WalletFromKey = InitFunction<{
5321
5304
  seed: string;
5322
5305
  }, keyof LearnCardConfig, LearnCard>;
5323
5306
  /** @group Init Functions */
5307
+ export declare type WalletFromVcApi = InitFunction<{
5308
+ vcApi: true | string;
5309
+ did?: string;
5310
+ }, "defaultContents", VCAPILearnCard>;
5311
+ /** @group Init Functions */
5324
5312
  export declare type InitLearnCard = GenericInitFunction<[
5325
5313
  EmptyWallet,
5326
- WalletFromKey
5314
+ WalletFromKey,
5315
+ WalletFromVcApi
5327
5316
  ]>;
5328
5317
  /**
5329
5318
  * Generates an empty wallet with no key material
@@ -5337,6 +5326,12 @@ export declare const emptyWallet: ({ didkit }?: EmptyWallet["args"]) => Promise<
5337
5326
  * @group Init Functions
5338
5327
  */
5339
5328
  export declare const walletFromKey: (key: string, { ceramicIdx, didkit, defaultContents, ethereumConfig, }?: Partial<LearnCardConfig>) => Promise<LearnCard>;
5329
+ /**
5330
+ * Generates a LearnCard Wallet from a 64 character seed string
5331
+ *
5332
+ * @group Init Functions
5333
+ */
5334
+ export declare const walletFromApiUrl: (url: string, did?: string, { defaultContents }?: Partial<LearnCardConfig>) => Promise<WalletFromVcApi["returnValue"]>;
5340
5335
  /**
5341
5336
  * Generates an Empty Wallet
5342
5337
  *
@@ -5349,8 +5344,12 @@ export declare function initLearnCard(config?: EmptyWallet["args"]): Promise<Emp
5349
5344
  * @group Init Functions
5350
5345
  */
5351
5346
  export declare function initLearnCard(config: WalletFromKey["args"]): Promise<WalletFromKey["returnValue"]>;
5352
- export declare const passwordToKey: (password: string, salt?: string, iterations?: number, digest?: string) => Promise<Uint8Array>;
5353
- export declare const seedToId: (seed: Uint8Array) => Promise<string>;
5347
+ /**
5348
+ * Generates a wallet that can sign VCs/VPs from a VC API
5349
+ *
5350
+ * @group Init Functions
5351
+ */
5352
+ export declare function initLearnCard(config: WalletFromVcApi["args"]): Promise<WalletFromVcApi["returnValue"]>;
5354
5353
  /** @group Universal Wallets */
5355
5354
  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>>;
5356
5355
  /**
@@ -5382,7 +5381,7 @@ export declare const ExpirationPlugin: (wallet: Wallet<any, VerifyExtension>) =>
5382
5381
  */
5383
5382
  export declare const getEthereumPlugin: (initWallet: Wallet<string, {
5384
5383
  getSubjectDid: (type: DidMethod) => string;
5385
- getSubjectKeypair: (type?: Algorithm) => KeyPair;
5384
+ getSubjectKeypair: (type?: Algorithm) => JWK;
5386
5385
  }>, config: EthereumConfig) => Plugin<"Ethereum", EthereumPluginMethods>;
5387
5386
  /**
5388
5387
  * @group Plugins
package/dist/core.esm.js CHANGED
@@ -36939,34 +36939,6 @@ import "abort-controller/polyfill";
36939
36939
  import crypto2 from "isomorphic-webcrypto";
36940
36940
  if (typeof window === "undefined" && !globalThis.crypto)
36941
36941
  globalThis.crypto = crypto2;
36942
- var crypto_default = crypto2;
36943
-
36944
- // src/wallet/base/functions/passwordToKey.ts
36945
- var passwordToKey = /* @__PURE__ */ __name((password, salt = "salt", iterations = 1e5, digest2 = "SHA-256") => __async(void 0, null, function* () {
36946
- var saltBuffer = Buffer.from(salt);
36947
- var passphraseKey = Buffer.from(password);
36948
- return crypto_default.subtle.importKey("raw", passphraseKey, { name: "PBKDF2" }, false, [
36949
- "deriveBits",
36950
- "deriveKey"
36951
- ]).then(function(key2) {
36952
- return crypto_default.subtle.deriveKey({
36953
- name: "PBKDF2",
36954
- salt: saltBuffer,
36955
- iterations,
36956
- hash: digest2
36957
- }, key2, { name: "AES-CBC", length: 256 }, true, ["encrypt", "decrypt"]);
36958
- }).then((webKey) => {
36959
- return crypto_default.subtle.exportKey("raw", webKey);
36960
- }).then((buffer2) => {
36961
- return new Uint8Array(buffer2);
36962
- });
36963
- }), "passwordToKey");
36964
-
36965
- // src/wallet/base/functions/seedToId.ts
36966
- var seedToId = /* @__PURE__ */ __name((seed) => __async(void 0, null, function* () {
36967
- const buffer2 = yield crypto_default.subtle.digest("SHA-256", seed);
36968
- return `urn:digest:${Buffer.from(new Int8Array(buffer2)).toString("hex")}`;
36969
- }), "seedToId");
36970
36942
 
36971
36943
  // src/wallet/base/wallet.ts
36972
36944
  var addPluginToWallet = /* @__PURE__ */ __name((wallet, plugin) => __async(void 0, null, function* () {
@@ -39240,7 +39212,8 @@ var getCHAPIPlugin = /* @__PURE__ */ __name(() => __async(void 0, null, function
39240
39212
  return { success: false, reason: "did not auth" };
39241
39213
  const verification = yield wallet.pluginMethods.verifyPresentation(res.data, {
39242
39214
  challenge,
39243
- domain
39215
+ domain,
39216
+ proofPurpose: "authentication"
39244
39217
  });
39245
39218
  if (verification.warnings.length > 0 || verification.errors.length > 0) {
39246
39219
  return { success: false, reason: "auth failed verification" };
@@ -39249,7 +39222,7 @@ var getCHAPIPlugin = /* @__PURE__ */ __name(() => __async(void 0, null, function
39249
39222
  if (!Array.isArray(credential.credentialSubject)) {
39250
39223
  credential.credentialSubject.id = subject;
39251
39224
  }
39252
- const vp = yield wallet.pluginMethods.issuePresentation(yield wallet.pluginMethods.getTestVp(yield wallet.pluginMethods.issueCredential(credential)));
39225
+ const vp = yield wallet.pluginMethods.getTestVp(yield wallet.pluginMethods.issueCredential(credential));
39253
39226
  const success = yield wallet.pluginMethods.storePresentationViaChapi(vp);
39254
39227
  if (success)
39255
39228
  return { success: true };
@@ -42208,7 +42181,7 @@ var AlignmentValidator = mod.object({
42208
42181
  targetType: AlignmentTargetTypeValidator.optional(),
42209
42182
  targetUrl: mod.string()
42210
42183
  });
42211
- var AchievementTypeValidator = mod.enum([
42184
+ var KnownAchievementTypeValidator = mod.enum([
42212
42185
  "Achievement",
42213
42186
  "ApprenticeshipCertificate",
42214
42187
  "Assessment",
@@ -42240,7 +42213,8 @@ var AchievementTypeValidator = mod.enum([
42240
42213
  "MicroCredential",
42241
42214
  "ResearchDoctorate",
42242
42215
  "SecondarySchoolDiploma"
42243
- ]).or(mod.string());
42216
+ ]);
42217
+ var AchievementTypeValidator = KnownAchievementTypeValidator.or(mod.string());
42244
42218
  var CriteriaValidator = mod.object({ id: mod.string().optional(), narrative: mod.string().optional() }).catchall(mod.any());
42245
42219
  var EndorsementSubjectValidator = mod.object({
42246
42220
  id: mod.string(),
@@ -42399,6 +42373,13 @@ var IDXCredentialValidator = mod.object({
42399
42373
  id: mod.string(),
42400
42374
  title: mod.string(),
42401
42375
  storageType: StorageTypeValidator.optional()
42376
+ }).catchall(mod.any());
42377
+ var JWKValidator = mod.object({
42378
+ kty: mod.string(),
42379
+ crv: mod.string(),
42380
+ x: mod.string(),
42381
+ y: mod.string().optional(),
42382
+ d: mod.string()
42402
42383
  });
42403
42384
 
42404
42385
  // ../../node_modules/.pnpm/date-fns@2.28.0/node_modules/date-fns/esm/_lib/toInteger/index.js
@@ -60375,11 +60356,131 @@ var walletFromKey = /* @__PURE__ */ __name((_0, ..._1) => __async(void 0, [_0, .
60375
60356
  };
60376
60357
  }), "walletFromKey");
60377
60358
 
60359
+ // src/wallet/plugins/vc-api/helpers.ts
60360
+ var post = /* @__PURE__ */ __name((url, data) => __async(void 0, null, function* () {
60361
+ return fetch(url, {
60362
+ method: "POST",
60363
+ headers: { "Content-Type": "application/json" },
60364
+ body: JSON.stringify(data)
60365
+ });
60366
+ }), "post");
60367
+ var isSuccessful = /* @__PURE__ */ __name((status) => status.toString().startsWith("2"), "isSuccessful");
60368
+
60369
+ // src/wallet/plugins/vc-api/index.ts
60370
+ var getVCAPIPlugin = /* @__PURE__ */ __name((_0) => __async(void 0, [_0], function* ({
60371
+ url: _url,
60372
+ did: _did
60373
+ }) {
60374
+ const url = _url.endsWith("/") ? _url.slice(0, -1) : _url;
60375
+ let did = _did;
60376
+ if (!did) {
60377
+ const res = yield fetch(`${url}/did`);
60378
+ if (res.status === 200)
60379
+ did = yield res.text();
60380
+ }
60381
+ if (!did)
60382
+ throw new Error("Could not retrieve did from VC API! Please suppy a did.");
60383
+ return {
60384
+ pluginMethods: {
60385
+ getSubjectDid: () => did,
60386
+ issueCredential: (_wallet, credential, options) => __async(void 0, null, function* () {
60387
+ yield UnsignedVCValidator.parseAsync(credential);
60388
+ const response = yield post(`${url}/credentials/issue`, { credential, options });
60389
+ if (!isSuccessful(response.status)) {
60390
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
60391
+ }
60392
+ return VCValidator.parseAsync(yield response.json());
60393
+ }),
60394
+ verifyCredential: (_wallet, verifiableCredential, options) => __async(void 0, null, function* () {
60395
+ yield VCValidator.parseAsync(verifiableCredential);
60396
+ const response = yield post(`${url}/credentials/verify`, {
60397
+ verifiableCredential,
60398
+ options
60399
+ });
60400
+ if (!isSuccessful(response.status)) {
60401
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
60402
+ }
60403
+ return VerificationCheckValidator.parseAsync(yield response.json());
60404
+ }),
60405
+ issuePresentation: (_wallet, presentation, options) => __async(void 0, null, function* () {
60406
+ yield UnsignedVPValidator.parseAsync(presentation);
60407
+ const response = yield post(`${url}/presentations/issue`, {
60408
+ presentation,
60409
+ options
60410
+ });
60411
+ if (!isSuccessful(response.status)) {
60412
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
60413
+ }
60414
+ return VPValidator.parseAsync(yield response.json());
60415
+ }),
60416
+ verifyPresentation: (_wallet, verifiablePresentation, options) => __async(void 0, null, function* () {
60417
+ yield VPValidator.parseAsync(verifiablePresentation);
60418
+ const response = yield post(`${url}/presentations/verify`, {
60419
+ verifiablePresentation,
60420
+ options
60421
+ });
60422
+ if (!isSuccessful(response.status)) {
60423
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
60424
+ }
60425
+ return VerificationCheckValidator.parseAsync(yield response.json());
60426
+ }),
60427
+ getTestVc: (_wallet, subject = "did:example:d23dd687a7dc6787646f2eb98d0") => {
60428
+ return {
60429
+ "@context": ["https://www.w3.org/2018/credentials/v1"],
60430
+ id: "http://example.org/credentials/3731",
60431
+ type: ["VerifiableCredential"],
60432
+ issuer: did,
60433
+ issuanceDate: "2020-08-19T21:41:50Z",
60434
+ credentialSubject: { id: subject }
60435
+ };
60436
+ },
60437
+ getTestVp: (_wallet, _credential) => __async(void 0, null, function* () {
60438
+ const credential = _credential || (yield _wallet.pluginMethods.issueCredential(_wallet.pluginMethods.getTestVc()));
60439
+ return {
60440
+ "@context": ["https://www.w3.org/2018/credentials/v1"],
60441
+ type: ["VerifiablePresentation"],
60442
+ holder: did,
60443
+ verifiableCredential: credential
60444
+ };
60445
+ })
60446
+ }
60447
+ };
60448
+ }), "getVCAPIPlugin");
60449
+
60450
+ // src/wallet/initializers/apiWallet.ts
60451
+ var walletFromApiUrl = /* @__PURE__ */ __name((_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (url, did, { defaultContents = [] } = {}) {
60452
+ const apiWallet = yield (yield generateWallet(defaultContents)).addPlugin(yield getVCAPIPlugin({ url, did }));
60453
+ const expirationWallet = yield apiWallet.addPlugin(ExpirationPlugin(apiWallet));
60454
+ const templateWallet = yield expirationWallet.addPlugin(getVCTemplatesPlugin());
60455
+ const wallet = yield templateWallet.addPlugin(yield getCHAPIPlugin());
60456
+ return {
60457
+ _wallet: wallet,
60458
+ did: (type = "key") => wallet.pluginMethods.getSubjectDid(type),
60459
+ newCredential: wallet.pluginMethods.newCredential,
60460
+ newPresentation: wallet.pluginMethods.newPresentation,
60461
+ issueCredential: wallet.pluginMethods.issueCredential,
60462
+ verifyCredential: verifyCredential2(wallet),
60463
+ issuePresentation: wallet.pluginMethods.issuePresentation,
60464
+ verifyPresentation: wallet.pluginMethods.verifyPresentation,
60465
+ getTestVc: wallet.pluginMethods.getTestVc,
60466
+ getTestVp: wallet.pluginMethods.getTestVp,
60467
+ installChapiHandler: wallet.pluginMethods.installChapiHandler,
60468
+ activateChapiHandler: wallet.pluginMethods.activateChapiHandler,
60469
+ receiveChapiEvent: wallet.pluginMethods.receiveChapiEvent,
60470
+ storePresentationViaChapi: wallet.pluginMethods.storePresentationViaChapi,
60471
+ storeCredentialViaChapiDidAuth: wallet.pluginMethods.storeCredentialViaChapiDidAuth
60472
+ };
60473
+ }), "walletFromApiUrl");
60474
+
60378
60475
  // src/wallet/init.ts
60379
60476
  function initLearnCard() {
60380
60477
  return __async(this, arguments, function* (config2 = {}) {
60478
+ if ("vcApi" in config2) {
60479
+ const _a = config2, { vcApi, did } = _a, apiConfig = __objRest(_a, ["vcApi", "did"]);
60480
+ return walletFromApiUrl(typeof vcApi === "string" ? vcApi : "https://bridge.learncard.com", vcApi === true ? "did:key:z6MkjSz4mYqcn7dePGuktJ5PxecMkXQQHWRg8Lm6okATyFVh" : did, apiConfig);
60481
+ }
60381
60482
  if ("seed" in config2) {
60382
- const _a = config2, { seed } = _a, keyConfig = __objRest(_a, ["seed"]);
60483
+ const _b = config2, { seed } = _b, keyConfig = __objRest(_b, ["seed"]);
60383
60484
  return walletFromKey(seed, keyConfig);
60384
60485
  }
60385
60486
  return emptyWallet(config2);
@@ -60399,8 +60500,7 @@ export {
60399
60500
  getVCPlugin,
60400
60501
  getVpqrPlugin,
60401
60502
  initLearnCard,
60402
- passwordToKey,
60403
- seedToId,
60503
+ walletFromApiUrl,
60404
60504
  walletFromKey
60405
60505
  };
60406
60506
  /*!