@learncard/core 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/core.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  import { StreamID } from '@ceramicnetwork/streamid';
6
6
  import { ModelAliases } from '@glazed/types';
7
7
 
8
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
8
9
  declare const UnsignedVCValidator: z.ZodObject<{
9
10
  "@context": z.ZodArray<z.ZodString, "many">;
10
11
  id: z.ZodOptional<z.ZodString>;
@@ -4673,8 +4674,20 @@ export declare type KeyPair = {
4673
4674
  };
4674
4675
  /** @group DIDKit Plugin */
4675
4676
  export declare type ProofOptions = {
4676
- verificationMethod: string;
4677
- proofPurpose: string;
4677
+ type?: string;
4678
+ verificationMethod?: string;
4679
+ proofPurpose?: string;
4680
+ created?: string;
4681
+ challenge?: string;
4682
+ domain?: string;
4683
+ checks?: ("Proof" | "JWS" | "CredentialStatus")[];
4684
+ };
4685
+ /** @group DIDKit Plugin */
4686
+ export declare type InputMetadata = {
4687
+ accept?: string;
4688
+ versionId?: string;
4689
+ versionTime?: string;
4690
+ noCache?: boolean;
4678
4691
  };
4679
4692
  /** @group DIDKit Plugin */
4680
4693
  export declare type DidkitPluginMethods = {
@@ -4683,11 +4696,11 @@ export declare type DidkitPluginMethods = {
4683
4696
  keyToDid: (type: DidMethod, keypair: KeyPair) => string;
4684
4697
  keyToVerificationMethod: (type: string, keypair: KeyPair) => Promise<string>;
4685
4698
  issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: KeyPair) => Promise<VC>;
4686
- verifyCredential: (credential: VC) => Promise<VerificationCheck>;
4699
+ verifyCredential: (credential: VC, options?: ProofOptions) => Promise<VerificationCheck>;
4687
4700
  issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: KeyPair) => Promise<VP>;
4688
- verifyPresentation: (presentation: VP) => Promise<VerificationCheck>;
4701
+ verifyPresentation: (presentation: VP, options?: ProofOptions) => Promise<VerificationCheck>;
4689
4702
  contextLoader: (url: string) => Promise<Record<string, any>>;
4690
- resolveDid: (did: string) => Promise<Record<string, any>>;
4703
+ resolveDid: (did: string, inputMetadata?: InputMetadata) => Promise<Record<string, any>>;
4691
4704
  };
4692
4705
  /** @group DidKey Plugin */
4693
4706
  export declare type Algorithm = "ed25519" | "secp256k1";
@@ -4802,26 +4815,61 @@ export declare const CredentialsListValidator: z.ZodObject<{
4802
4815
  }>;
4803
4816
  /** @group IDXPlugin */
4804
4817
  export declare type CredentialsList = z.infer<typeof CredentialsListValidator>;
4818
+ export declare type Last<T extends any[]> = T extends [
4819
+ ...any[],
4820
+ infer R
4821
+ ] ? R : never;
4822
+ export declare type RemoveLast<T extends any[]> = T extends [
4823
+ ...infer R,
4824
+ any
4825
+ ] ? R : [
4826
+ ];
4827
+ /** @group Utility Types */
4828
+ export declare type MergeObjects<Objects extends Record<string, any>[]> = undefined extends Objects[2] ? Omit<Objects[0], keyof Objects[1]> & Objects[1] : Omit<MergeObjects<RemoveLast<Objects>>, keyof Last<Objects>> & Last<Objects>;
4829
+ /** @group Universal Wallets */
4830
+ export declare type Plugin<Name extends string, PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>, DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
4831
+ name?: Name;
4832
+ pluginMethods: {
4833
+ [Key in keyof PublicMethods]: <T extends Wallet<any, PublicMethods & DependentMethods>>(wallet: T, ...args: Parameters<PublicMethods[Key]>) => ReturnType<PublicMethods[Key]>;
4834
+ };
4835
+ };
4836
+ /** @group Universal Wallets */
4837
+ export declare type PublicFieldsObj<PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
4838
+ pluginMethods: PluginMethods;
4839
+ };
4840
+ /** @group Universal Wallets */
4841
+ export declare type Wallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = PublicFieldsObj<PluginMethods> & {
4842
+ contents: any[];
4843
+ plugins: Plugin<PluginNames, Record<string, (...args: any[]) => any>>[];
4844
+ add: (content: any) => Promise<Wallet<PluginNames, PluginMethods>>;
4845
+ remove: (contentId: string) => Promise<Wallet<PluginNames, PluginMethods>>;
4846
+ addPlugin: <Name extends string, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>>(plugin: Plugin<Name, Methods>) => Promise<Wallet<"" extends PluginNames ? Name : PluginNames | Name, Record<never, never> extends PluginMethods ? Methods : MergeObjects<[
4847
+ PluginMethods,
4848
+ Methods
4849
+ ]>>>;
4850
+ };
4805
4851
  /** @group VC Plugin */
4806
4852
  export declare type VCPluginDependentMethods = {
4807
4853
  getSubjectDid: (type: "key") => string;
4808
4854
  getSubjectKeypair: () => KeyPair;
4809
4855
  keyToVerificationMethod: (type: string, keypair: KeyPair) => Promise<string>;
4810
4856
  issueCredential: (credential: UnsignedVC, options: ProofOptions, keypair: KeyPair) => Promise<VC>;
4811
- verifyCredential: (credential: VC) => Promise<VerificationCheck>;
4857
+ verifyCredential: (credential: VC, options?: ProofOptions) => Promise<VerificationCheck>;
4812
4858
  issuePresentation: (presentation: UnsignedVP, options: ProofOptions, keypair: KeyPair) => Promise<VP>;
4813
- verifyPresentation: (presentation: VP) => Promise<VerificationCheck>;
4859
+ verifyPresentation: (presentation: VP, options?: ProofOptions) => Promise<VerificationCheck>;
4814
4860
  };
4815
4861
  /** @group VC Plugin */
4816
- export declare type VCPluginMethods = VCPluginDependentMethods & {
4817
- issueCredential: (credential: UnsignedVC) => Promise<VC>;
4818
- verifyCredential: (credential: VC) => Promise<VerificationCheck>;
4819
- issuePresentation: (credential: UnsignedVP) => Promise<VP>;
4820
- verifyPresentation: (presentation: VP) => Promise<VerificationCheck>;
4862
+ export declare type VCPluginMethods = {
4863
+ issueCredential: (credential: UnsignedVC, signingOptions?: Partial<ProofOptions>) => Promise<VC>;
4864
+ verifyCredential: (credential: VC, options?: Partial<ProofOptions>) => Promise<VerificationCheck>;
4865
+ issuePresentation: (credential: UnsignedVP, signingOptions?: Partial<ProofOptions>) => Promise<VP>;
4866
+ verifyPresentation: (presentation: VP, options?: Partial<ProofOptions>) => Promise<VerificationCheck>;
4821
4867
  getTestVc: (subject?: string) => UnsignedVC;
4822
4868
  getTestVp: (credential?: VC) => Promise<UnsignedVP>;
4823
4869
  };
4824
4870
  /** @group VC Plugin */
4871
+ export declare type VCImplicitWallet = Wallet<string, VCPluginMethods & VCPluginDependentMethods>;
4872
+ /** @group VC Plugin */
4825
4873
  export declare type VerifyExtension = {
4826
4874
  verifyCredential: (credential: VC) => Promise<VerificationCheck>;
4827
4875
  };
@@ -4834,7 +4882,93 @@ export declare type VpqrPluginMethods = {
4834
4882
  export declare type VpqrPluginDependentMethods = {
4835
4883
  contextLoader: (url: string) => Promise<Record<string, any>>;
4836
4884
  };
4837
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
4885
+ /** @group CHAPI Plugin */
4886
+ export declare type WebCredential = {
4887
+ new (dataType: string, data: VP, options?: {
4888
+ recommendedHandlerOrigins: string[];
4889
+ }): WebCredential;
4890
+ type: string;
4891
+ dataType: string;
4892
+ data: VP;
4893
+ options: {
4894
+ recommendedHandlerOrigins: string[];
4895
+ };
4896
+ };
4897
+ /** @group CHAPI Plugin */
4898
+ export declare type CredentialRequestEvent = {
4899
+ new (args: {
4900
+ credentialHandler: any;
4901
+ credentialRequestOrigin: string;
4902
+ credentialRequestOptions: any;
4903
+ hintKey: string;
4904
+ }): CredentialRequestEvent;
4905
+ type: string;
4906
+ _credentialHandler: any;
4907
+ credentialRequestOrigin: string;
4908
+ credentialRequestOptions: any;
4909
+ hintKey: string;
4910
+ openWindow: (url: string) => Promise<any>;
4911
+ respondWith: (handlerResponse: Promise<null | {
4912
+ dataType: string;
4913
+ data: any;
4914
+ }>) => void;
4915
+ };
4916
+ /** @group CHAPI Plugin */
4917
+ export declare type CredentialStoreEvent = {
4918
+ new (args: {
4919
+ credentialHandler: any;
4920
+ credentialRequestOrigin: string;
4921
+ credential: WebCredential;
4922
+ hintKey: string;
4923
+ }): CredentialStoreEvent;
4924
+ type: string;
4925
+ _credentialHandler: any;
4926
+ credentialRequestOrigin: string;
4927
+ credential: WebCredential;
4928
+ hintKey: string;
4929
+ openWindow: (url: string) => Promise<any>;
4930
+ respondWith: (handlerResponse: Promise<null | {
4931
+ dataType: string;
4932
+ data: any;
4933
+ }>) => void;
4934
+ };
4935
+ /** @group CHAPI Plugin */
4936
+ export declare type HandlerResponse = {
4937
+ type: "redirect";
4938
+ url: string;
4939
+ } | {
4940
+ type: "response";
4941
+ dataType: string;
4942
+ data: any;
4943
+ };
4944
+ /** @group CHAPI Plugin */
4945
+ export declare type CHAPIPluginDependentMethods = {
4946
+ issueCredential: (credential: UnsignedVC, signingOptions?: Partial<ProofOptions>) => Promise<VC>;
4947
+ issuePresentation: (credential: UnsignedVP, signingOptions?: Partial<ProofOptions>) => Promise<VP>;
4948
+ verifyPresentation: (presentation: VP, options?: Partial<ProofOptions>) => Promise<VerificationCheck>;
4949
+ getTestVp: (credential?: VC) => Promise<UnsignedVP>;
4950
+ };
4951
+ /** @group CHAPI Plugin */
4952
+ export declare type CHAPIPluginMethods = {
4953
+ installChapiHandler: () => Promise<void>;
4954
+ activateChapiHandler: (args: {
4955
+ mediatorOrigin?: string;
4956
+ get?: (event: CredentialRequestEvent) => Promise<HandlerResponse>;
4957
+ store?: (event: CredentialStoreEvent) => Promise<HandlerResponse>;
4958
+ }) => Promise<void>;
4959
+ receiveChapiEvent: () => Promise<CredentialRequestEvent | CredentialStoreEvent>;
4960
+ storeCredentialViaChapiDidAuth: (credential: UnsignedVC) => Promise<{
4961
+ success: true;
4962
+ } | {
4963
+ success: false;
4964
+ reason: "did not auth" | "auth failed verification" | "did not store";
4965
+ }>;
4966
+ storePresentationViaChapi: (presentation: VP) => Promise<Credential | undefined>;
4967
+ };
4968
+ /**
4969
+ * @group Plugins
4970
+ */
4971
+ export declare const getCHAPIPlugin: () => Promise<Plugin<"CHAPI", CHAPIPluginMethods, CHAPIPluginDependentMethods>>;
4838
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>> = {
4839
4973
  args: undefined extends Args ? Partial<Pick<LearnCardConfig, Config>> : Args & Partial<Pick<LearnCardConfig, Config>>;
4840
4974
  returnValue: ReturnValue;
@@ -4848,25 +4982,6 @@ export declare type DiscriminatedUnionize<T extends object = {}, K extends strin
4848
4982
  [Key2 in K]: Key;
4849
4983
  } & T[Key];
4850
4984
  }[keyof T];
4851
- /** @group Universal Wallets */
4852
- export declare type Plugin<Name extends string, PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
4853
- name?: Name;
4854
- pluginMethods: {
4855
- [Key in keyof PublicMethods]: <T extends Wallet<any, PublicMethods>>(wallet: T, ...args: Parameters<PublicMethods[Key]>) => ReturnType<PublicMethods[Key]>;
4856
- };
4857
- };
4858
- /** @group Universal Wallets */
4859
- export declare type PublicFieldsObj<PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = {
4860
- pluginMethods: PluginMethods;
4861
- };
4862
- /** @group Universal Wallets */
4863
- export declare type Wallet<PluginNames extends string = "", PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>> = PublicFieldsObj<PluginMethods> & {
4864
- contents: any[];
4865
- plugins: Plugin<PluginNames, Record<string, (...args: any[]) => any>>[];
4866
- add: (content: any) => Promise<Wallet<PluginNames, PluginMethods>>;
4867
- remove: (contentId: string) => Promise<Wallet<PluginNames, PluginMethods>>;
4868
- addPlugin: <Name extends string, Methods extends Record<string, (...args: any[]) => any> = Record<never, never>>(plugin: Plugin<Name, Methods>) => Promise<Wallet<"" extends PluginNames ? Name : PluginNames | Name, Record<never, never> extends PluginMethods ? Methods : PluginMethods & Methods>>;
4869
- };
4870
4985
  /** @group VC Templates Plugin */
4871
4986
  export declare type VcTemplates = {
4872
4987
  basic: {
@@ -4888,7 +5003,6 @@ export declare type VcTemplates = {
4888
5003
  export declare type NewCredentialFunction = (args?: DiscriminatedUnionize<VcTemplates>) => UnsignedVC;
4889
5004
  /** @group VC Templates Plugin */
4890
5005
  export declare type VCTemplatePluginMethods = {
4891
- getSubjectDid?: (type: "key") => string;
4892
5006
  newCredential: NewCredentialFunction;
4893
5007
  newPresentation: (credential: VC, args?: {
4894
5008
  did?: string;
@@ -4931,7 +5045,7 @@ export declare type NewPresentation = (credential: VC, args?: {
4931
5045
  *
4932
5046
  * @group LearnCard Methods
4933
5047
  */
4934
- export declare type IssueCredential = (credential: UnsignedVC) => Promise<VC>;
5048
+ export declare type IssueCredential = (credential: UnsignedVC, signingOptions?: Partial<ProofOptions>) => Promise<VC>;
4935
5049
  /**
4936
5050
  * Verifies a signed Verifiable Credential
4937
5051
  *
@@ -4939,13 +5053,13 @@ export declare type IssueCredential = (credential: UnsignedVC) => Promise<VC>;
4939
5053
  *
4940
5054
  * @group LearnCard Methods
4941
5055
  */
4942
- export declare type VerifyCredential = (credential: VC) => Promise<VerificationItem[]>;
5056
+ export declare type VerifyCredential = (credential: VC, options?: Partial<ProofOptions>) => Promise<VerificationItem[]>;
4943
5057
  /**
4944
5058
  * Signs an unsigned Verifiable Presentation, returning the signed VP
4945
5059
  *
4946
5060
  * @group LearnCard Methods
4947
5061
  */
4948
- export declare type IssuePresentation = (presentation: UnsignedVP) => Promise<VP>;
5062
+ export declare type IssuePresentation = (presentation: UnsignedVP, signingOptions?: Partial<ProofOptions>) => Promise<VP>;
4949
5063
  /**
4950
5064
  * Verifies a signed Verifiable Presentation
4951
5065
  *
@@ -4953,7 +5067,7 @@ export declare type IssuePresentation = (presentation: UnsignedVP) => Promise<VP
4953
5067
  *
4954
5068
  * @group LearnCard Methods
4955
5069
  */
4956
- export declare type VerifyPresentation = (presentation: VP) => Promise<VerificationCheck>;
5070
+ export declare type VerifyPresentation = (presentation: VP, options?: Partial<ProofOptions>) => Promise<VerificationCheck>;
4957
5071
  /**
4958
5072
  * Returns the credential marked with `title` from IDX
4959
5073
  *
@@ -5007,7 +5121,7 @@ export declare type RemoveCredential = (title: string) => Promise<void>;
5007
5121
  *
5008
5122
  * @group LearnCard Methods
5009
5123
  */
5010
- export declare type ResolveDid = (did: string) => Promise<Record<string, any>>;
5124
+ export declare type ResolveDid = (did: string, inputMetadata?: InputMetadata) => Promise<Record<string, any>>;
5011
5125
  /**
5012
5126
  * Resolves a stream ID, returning its contents
5013
5127
  *
@@ -5091,6 +5205,45 @@ export declare type VpFromQrCode = (text: string) => Promise<VP>;
5091
5205
  * @group LearnCard Methods
5092
5206
  */
5093
5207
  export declare type VpToQrCode = (vp: VP) => Promise<string>;
5208
+ /**
5209
+ * Sets up CHAPI
5210
+ *
5211
+ * @group LearnCard Methods
5212
+ */
5213
+ export declare type InstallChapiHandler = () => Promise<void>;
5214
+ /**
5215
+ * Activates CHAPI
5216
+ *
5217
+ * @group LearnCard Methods
5218
+ */
5219
+ export declare type ActivateChapiHandler = (args: {
5220
+ mediatorOrigin?: string;
5221
+ get?: (event: CredentialRequestEvent) => Promise<HandlerResponse>;
5222
+ store?: (event: CredentialStoreEvent) => Promise<HandlerResponse>;
5223
+ }) => Promise<void>;
5224
+ /**
5225
+ * Receives a CHAPI Event
5226
+ *
5227
+ * @group LearnCard Methods
5228
+ */
5229
+ export declare type ReceiveChapiEvent = () => Promise<CredentialRequestEvent | CredentialStoreEvent>;
5230
+ /**
5231
+ * Stores a VP via CHAPI
5232
+ *
5233
+ * @group LearnCard Methods
5234
+ */
5235
+ export declare type StorePresentationViaChapi = (presentation: VP) => Promise<Credential | undefined>;
5236
+ /**
5237
+ * Stores a Credential via CHAPI using DIDAuth
5238
+ *
5239
+ * @group LearnCard Methods
5240
+ */
5241
+ export declare type StoreCredentialViaChapiDidAuth = (credential: UnsignedVC) => Promise<{
5242
+ success: true;
5243
+ } | {
5244
+ success: false;
5245
+ reason: "did not auth" | "auth failed verification" | "did not store";
5246
+ }>;
5094
5247
  /**
5095
5248
  * @group LearnCard Methods
5096
5249
  */
@@ -5122,9 +5275,22 @@ export declare type AllLearnCardMethods = {
5122
5275
  addInfuraProjectId: AddInfuraProjectId;
5123
5276
  vpFromQrCode: VpFromQrCode;
5124
5277
  vpToQrCode: VpToQrCode;
5278
+ installChapiHandler: InstallChapiHandler;
5279
+ activateChapiHandler: ActivateChapiHandler;
5280
+ receiveChapiEvent: ReceiveChapiEvent;
5281
+ storePresentationViaChapi: StorePresentationViaChapi;
5282
+ storeCredentialViaChapiDidAuth: StoreCredentialViaChapiDidAuth;
5125
5283
  };
5126
5284
  /** @group Universal Wallets */
5127
- export declare type LearnCardRawWallet = Wallet<"DIDKit" | "DID Key" | "VC" | "VC Templates" | "IDX" | "Expiration" | "Ethereum" | "Vpqr", DidKeyPluginMethods<DidMethod> & VCPluginMethods & VCTemplatePluginMethods & IDXPluginMethods & EthereumPluginMethods & VpqrPluginMethods>;
5285
+ export declare type LearnCardRawWallet = Wallet<"DIDKit" | "DID Key" | "VC" | "VC Templates" | "IDX" | "Expiration" | "Ethereum" | "Vpqr" | "CHAPI", MergeObjects<[
5286
+ DidKeyPluginMethods<DidMethod>,
5287
+ VCPluginMethods,
5288
+ VCTemplatePluginMethods,
5289
+ IDXPluginMethods,
5290
+ EthereumPluginMethods,
5291
+ VpqrPluginMethods,
5292
+ CHAPIPluginMethods
5293
+ ]>>;
5128
5294
  /**
5129
5295
  * @group LearnCard
5130
5296
  */
@@ -5135,7 +5301,12 @@ export declare type LearnCard<Methods extends keyof AllLearnCardMethods = keyof
5135
5301
  /**
5136
5302
  * @group LearnCard
5137
5303
  */
5138
- export declare type EmptyLearnCard = LearnCard<"newCredential" | "newPresentation" | "verifyCredential" | "verifyPresentation" | "resolveDid", Wallet<"DIDKit" | "Expiration" | "VC Templates", DidkitPluginMethods & VerifyExtension & VCTemplatePluginMethods>>;
5304
+ export declare type EmptyLearnCard = LearnCard<"newCredential" | "newPresentation" | "verifyCredential" | "verifyPresentation" | "resolveDid" | "installChapiHandler" | "activateChapiHandler" | "receiveChapiEvent" | "storePresentationViaChapi" | "storeCredentialViaChapiDidAuth", Wallet<"DIDKit" | "Expiration" | "VC Templates" | "CHAPI", MergeObjects<[
5305
+ DidkitPluginMethods,
5306
+ VerifyExtension,
5307
+ VCTemplatePluginMethods,
5308
+ CHAPIPluginMethods
5309
+ ]>>>;
5139
5310
  /** @group LearnCard */
5140
5311
  export declare type LearnCardConfig = {
5141
5312
  ceramicIdx: CeramicIDXArgs;
@@ -5191,11 +5362,11 @@ export declare const getDidKitPlugin: (input?: InitInput | Promise<InitInput>) =
5191
5362
  *
5192
5363
  * @group Plugins
5193
5364
  */
5194
- export declare const getDidKeyPlugin: <DidMethod extends string>(wallet: Wallet<string, DependentMethods<DidMethod>>, key: string) => Promise<Plugin<"DID Key", DidKeyPluginMethods<DidMethod>>>;
5365
+ export declare const getDidKeyPlugin: <DidMethod extends string>(wallet: Wallet<string, DependentMethods<DidMethod>>, key: string) => Promise<Plugin<"DID Key", DidKeyPluginMethods<DidMethod>, Record<never, never>>>;
5195
5366
  /**
5196
5367
  * @group Plugins
5197
5368
  */
5198
- export declare const getVCPlugin: (wallet: Wallet<string, VCPluginDependentMethods>) => Plugin<"VC", VCPluginMethods>;
5369
+ export declare const getVCPlugin: (wallet: Wallet<string, VCPluginDependentMethods>) => Plugin<"VC", VCPluginMethods, VCPluginDependentMethods>;
5199
5370
  /**
5200
5371
  * @group Plugins
5201
5372
  */