@learncard/chapi-plugin 1.1.24 → 1.1.26
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/README.md +12 -7
- package/dist/chapi-plugin.cjs.development.cjs +24 -24
- package/dist/chapi-plugin.cjs.development.cjs.map +1 -1
- package/dist/chapi-plugin.cjs.production.min.cjs.map +1 -1
- package/dist/chapi-plugin.esm.js +24 -24
- package/dist/chapi-plugin.esm.js.map +1 -1
- package/package.json +60 -58
- package/src/chapi.ts +147 -0
- package/src/global.d.ts +23 -0
- package/src/index.ts +2 -0
- package/src/types.ts +115 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { UnsignedVC, VC, UnsignedVP, VP, VerificationCheck } from '@learncard/types';
|
|
2
|
+
import { Plugin } from '@learncard/core';
|
|
3
|
+
import { ProofOptions } from '@learncard/didkit-plugin';
|
|
4
|
+
|
|
5
|
+
/** @group CHAPI Plugin */
|
|
6
|
+
export type WebCredential = {
|
|
7
|
+
new(
|
|
8
|
+
dataType: string,
|
|
9
|
+
data: VP,
|
|
10
|
+
options?: { recommendedHandlerOrigins: string[] }
|
|
11
|
+
): WebCredential;
|
|
12
|
+
type: string;
|
|
13
|
+
dataType: string;
|
|
14
|
+
data: VP;
|
|
15
|
+
options: { recommendedHandlerOrigins: string[] };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** @group CHAPI Plugin */
|
|
19
|
+
export type CredentialRequestEvent = {
|
|
20
|
+
new(args: {
|
|
21
|
+
credentialHandler: any;
|
|
22
|
+
credentialRequestOrigin: string;
|
|
23
|
+
credentialRequestOptions: any;
|
|
24
|
+
hintKey: string;
|
|
25
|
+
}): CredentialRequestEvent;
|
|
26
|
+
|
|
27
|
+
type: string;
|
|
28
|
+
|
|
29
|
+
_credentialHandler: any;
|
|
30
|
+
|
|
31
|
+
credentialRequestOrigin: string;
|
|
32
|
+
|
|
33
|
+
credentialRequestOptions: any;
|
|
34
|
+
|
|
35
|
+
hintKey: string;
|
|
36
|
+
|
|
37
|
+
openWindow: (url: string) => Promise<any>;
|
|
38
|
+
|
|
39
|
+
respondWith: (handlerResponse: Promise<null | { dataType: string; data: any }>) => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** @group CHAPI Plugin */
|
|
43
|
+
export type CredentialStoreEvent = {
|
|
44
|
+
new(args: {
|
|
45
|
+
credentialHandler: any;
|
|
46
|
+
credentialRequestOrigin: string;
|
|
47
|
+
credential: WebCredential;
|
|
48
|
+
hintKey: string;
|
|
49
|
+
}): CredentialStoreEvent;
|
|
50
|
+
|
|
51
|
+
type: string;
|
|
52
|
+
|
|
53
|
+
_credentialHandler: any;
|
|
54
|
+
|
|
55
|
+
credentialRequestOrigin: string;
|
|
56
|
+
|
|
57
|
+
credential: WebCredential;
|
|
58
|
+
|
|
59
|
+
hintKey: string;
|
|
60
|
+
|
|
61
|
+
openWindow: (url: string) => Promise<any>;
|
|
62
|
+
|
|
63
|
+
respondWith: (handlerResponse: Promise<null | { dataType: string; data: any }>) => void;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** @group CHAPI Plugin */
|
|
67
|
+
export type HandlerResponse =
|
|
68
|
+
| { type: 'redirect'; url: string }
|
|
69
|
+
| { type: 'response'; dataType: string; data: any };
|
|
70
|
+
|
|
71
|
+
/** @group CHAPI Plugin */
|
|
72
|
+
export type CHAPIPluginDependentMethods = {
|
|
73
|
+
issueCredential: (
|
|
74
|
+
credential: UnsignedVC,
|
|
75
|
+
signingOptions?: Partial<ProofOptions>
|
|
76
|
+
) => Promise<VC>;
|
|
77
|
+
issuePresentation: (
|
|
78
|
+
credential: UnsignedVP,
|
|
79
|
+
signingOptions?: Partial<ProofOptions>
|
|
80
|
+
) => Promise<VP>;
|
|
81
|
+
verifyPresentation: (
|
|
82
|
+
presentation: VP,
|
|
83
|
+
options?: Partial<ProofOptions>
|
|
84
|
+
) => Promise<VerificationCheck>;
|
|
85
|
+
getTestVp: (credential?: VC) => Promise<UnsignedVP>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** @group CHAPI Plugin */
|
|
89
|
+
export type CHAPIPluginMethods = {
|
|
90
|
+
installChapiHandler: () => Promise<void>;
|
|
91
|
+
activateChapiHandler: (args: {
|
|
92
|
+
mediatorOrigin?: string;
|
|
93
|
+
get?: (event: CredentialRequestEvent) => Promise<HandlerResponse>;
|
|
94
|
+
store?: (event: CredentialStoreEvent) => Promise<HandlerResponse>;
|
|
95
|
+
}) => Promise<void>;
|
|
96
|
+
receiveChapiEvent: () => Promise<CredentialRequestEvent | CredentialStoreEvent>;
|
|
97
|
+
storeCredentialViaChapiDidAuth: (
|
|
98
|
+
credential: UnsignedVC | UnsignedVC[]
|
|
99
|
+
) => Promise<
|
|
100
|
+
| { success: true }
|
|
101
|
+
| { success: false; reason: 'did not auth' | 'auth failed verification' | 'did not store' }
|
|
102
|
+
>;
|
|
103
|
+
storePresentationViaChapi: (
|
|
104
|
+
presentation: UnsignedVP | VP
|
|
105
|
+
) => Promise<Credential | undefined | void>;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** @group CHAPI Plugin */
|
|
109
|
+
export type CHAPIPlugin = Plugin<
|
|
110
|
+
'CHAPI',
|
|
111
|
+
any,
|
|
112
|
+
CHAPIPluginMethods,
|
|
113
|
+
any,
|
|
114
|
+
CHAPIPluginDependentMethods
|
|
115
|
+
>;
|