@trustvc/trustvc 1.0.0-alpha.2 → 1.0.0-alpha.4

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 CHANGED
@@ -0,0 +1,138 @@
1
+ # TrustVC
2
+
3
+ ## About
4
+ TrustVC is a wrapper library that facilitates the signing and verification of TrustVC W3C [Verifiable Credentials (VC)](https://github.com/TrustVC/w3c/tree/alpha) 1.0.0-alpha, adhering to the W3C [VC](https://www.w3.org/TR/vc-data-model/) Data Model v1.1 and OpenAttestation [Verifiable Documents (VD)](https://github.com/Open-Attestation/open-attestation/tree/beta) v6.10.0-beta.
5
+
6
+
7
+ ## Functions
8
+ ### 1. **Signing**
9
+
10
+ > Independent signing function for TrustVC W3C VC and OpenAttestation VD
11
+
12
+ 1. OpenAttestation Signing (signOA), supporting only OA Schema [v4](https://github.com/Open-Attestation/open-attestation/tree/beta/src/4.0)
13
+
14
+ > [!NOTE]
15
+ > Do not confuse OA Schema V4 with OA package version.
16
+
17
+ ```ts
18
+ import { wrapOA, signOA } from '@trustvc/trustvc';
19
+
20
+ const rawDocument = {
21
+ '@context': [
22
+ 'https://www.w3.org/ns/credentials/v2',
23
+ 'https://schemata.openattestation.com/com/openattestation/4.0/context.json',
24
+ ],
25
+ type: ['VerifiableCredential', 'OpenAttestationCredential'],
26
+ credentialSubject: {
27
+ id: '0x1234567890123456789012345678901234567890',
28
+ name: 'John Doe',
29
+ country: 'SG',
30
+ },
31
+ issuer: {
32
+ id: 'did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90',
33
+ type: 'OpenAttestationIssuer',
34
+ name: 'Government Technology Agency of Singapore (GovTech)',
35
+ identityProof: { identityProofType: 'DNS-DID', identifier: 'example.openattestation.com' },
36
+ },
37
+ }
38
+
39
+ const wrappedDocument = await wrapOA(rawDocument);
40
+
41
+ const signedWrappedDocument = await signOA(wrappedDocument, {
42
+ public: 'did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90#controller',
43
+ private: '<privateKey>',
44
+ });
45
+ ```
46
+
47
+ 2. TrustVC W3C Signing (signW3C)
48
+
49
+ ```ts
50
+ import { signW3C } from '@trustvc/trustvc';
51
+ import { VerificationType } from '@trustvc/w3c-issuer';
52
+
53
+ const rawDocument = {
54
+ '@context': [
55
+ 'https://www.w3.org/2018/credentials/v1',
56
+ 'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld',
57
+ 'https://w3id.org/security/bbs/v1',
58
+ 'https://w3id.org/vc/status-list/2021/v1',
59
+ ],
60
+ credentialStatus: {
61
+ id: 'https://trustvc.github.io/did/credentials/statuslist/1#1',
62
+ type: 'StatusList2021Entry',
63
+ statusPurpose: 'revocation',
64
+ statusListIndex: '10',
65
+ statusListCredential: 'https://trustvc.github.io/did/credentials/statuslist/1',
66
+ },
67
+ credentialSubject: {
68
+ name: 'TrustVC',
69
+ birthDate: '2024-04-01T12:19:52Z',
70
+ type: ['PermanentResident', 'Person'],
71
+ },
72
+ expirationDate: '2029-12-03T12:19:52Z',
73
+ issuer: 'did:web:trustvc.github.io:did:1',
74
+ type: ['VerifiableCredential'],
75
+ issuanceDate: '2024-04-01T12:19:52Z'
76
+ }
77
+
78
+ const signingResult = await signW3C(rawDocument, {
79
+ id: 'did:web:trustvc.github.io:did:1#keys-1',
80
+ controller: 'did:web:trustvc.github.io:did:1',
81
+ type: VerificationType.Bls12381G2Key2020,
82
+ publicKeyBase58:
83
+ 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ',
84
+ privateKeyBase58: '<privateKeyBase58>',
85
+ });
86
+ ```
87
+
88
+ ### 2. **Verifying**
89
+
90
+ > Single verifying function to simplify the process
91
+
92
+ 1. Verify
93
+
94
+ ```ts
95
+ import { verifyDocument } from '@trustvc/trustvc';
96
+
97
+ const signedDocument = {
98
+ '@context': [
99
+ 'https://www.w3.org/2018/credentials/v1',
100
+ 'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld',
101
+ 'https://w3id.org/security/bbs/v1',
102
+ 'https://w3id.org/vc/status-list/2021/v1',
103
+ ],
104
+ credentialStatus: {
105
+ id: 'https://trustvc.github.io/did/credentials/statuslist/1#1',
106
+ type: 'StatusList2021Entry',
107
+ statusPurpose: 'revocation',
108
+ statusListIndex: '10',
109
+ statusListCredential: 'https://trustvc.github.io/did/credentials/statuslist/1',
110
+ },
111
+ credentialSubject: {
112
+ name: 'TrustVC',
113
+ birthDate: '2024-04-01T12:19:52Z',
114
+ type: ['PermanentResident', 'Person'],
115
+ },
116
+ expirationDate: '2029-12-03T12:19:52Z',
117
+ issuer: 'did:web:trustvc.github.io:did:1',
118
+ type: ['VerifiableCredential'],
119
+ issuanceDate: '2024-04-01T12:19:52Z',
120
+ proof: {
121
+ type: 'BbsBlsSignature2020',
122
+ created: '2024-10-14T04:11:49Z',
123
+ proofPurpose: 'assertionMethod',
124
+ proofValue:
125
+ 'l79dlFQMowalep+WCFqgCvpVBcCAr0GDEFUV6S7gRVY/TQ+sp/wcwaT61PaD19rJYUHlKfzccE4m7waZyoLEkBLFiK2g54Q2i+CdtYBgDdkUDsoULSBMcH1MwGHwdjfXpldFNFrHFx/IAvLVniyeMQ==',
126
+ verificationMethod: 'did:web:trustvc.github.io:did:1#keys-1',
127
+ },
128
+ }
129
+
130
+ const resultFragments = await verifyDocument(signedDocument);
131
+ ```
132
+
133
+ ## Running the code
134
+ ```
135
+ npm install
136
+ npm run build
137
+ npm run test
138
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/trustvc",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "TrustVC library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -35,10 +35,12 @@
35
35
  "dependencies": {
36
36
  "@govtechsg/oa-verify": "9.3.0-beta.4",
37
37
  "@govtechsg/open-attestation": "6.10.0-beta.7",
38
- "@trustvc/w3c-context": "1.0.0-alpha.1",
39
- "@trustvc/w3c-issuer": "1.0.0-alpha.1",
40
- "@trustvc/w3c-vc": "1.0.0-alpha.1",
38
+ "@tradetrust-tt/token-registry": "^5.0.0-alpha",
39
+ "@trustvc/w3c-context": "^1.0.0-alpha",
40
+ "@trustvc/w3c-issuer": "^1.0.0-alpha",
41
+ "@trustvc/w3c-vc": "^1.0.0-alpha",
41
42
  "did-resolver": "^4.1.0",
43
+ "ethers": "^5.7.2",
42
44
  "js-sha3": "^0.9.3",
43
45
  "ts-chacha20": "^1.2.0",
44
46
  "web-did-resolver": "^2.0.27"
@@ -1,436 +0,0 @@
1
- import { v2 } from '@govtechsg/open-attestation';
2
-
3
- declare const SAMPLE_SIGNING_KEYS: {
4
- readonly public: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90#controller";
5
- readonly private: "0xcd27dc84c82c5814e7edac518edd5f263e7db7f25adb7a1afe13996a95583cf2";
6
- };
7
- declare const RAW_DOCUMENT_DID: {
8
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
9
- type: ["VerifiableCredential", "OpenAttestationCredential"];
10
- validFrom: string;
11
- name: string;
12
- issuer: {
13
- id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90";
14
- type: "OpenAttestationIssuer";
15
- name: string;
16
- identityProof: {
17
- identityProofType: "DNS-DID";
18
- identifier: string;
19
- };
20
- };
21
- renderMethod: {
22
- id: string;
23
- type: "OpenAttestationEmbeddedRenderer";
24
- templateName: string;
25
- }[];
26
- credentialSubject: {
27
- id: string;
28
- type: string[];
29
- name: string;
30
- licenses: {
31
- class: string;
32
- description: string;
33
- effectiveDate: string;
34
- }[];
35
- };
36
- };
37
- declare const RAW_DOCUMENT_DID_OSCP: {
38
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
39
- type: ["VerifiableCredential", "OpenAttestationCredential"];
40
- validFrom: string;
41
- name: string;
42
- issuer: {
43
- id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90";
44
- type: "OpenAttestationIssuer";
45
- name: string;
46
- identityProof: {
47
- identityProofType: "DNS-DID";
48
- identifier: string;
49
- };
50
- };
51
- credentialStatus: {
52
- id: string;
53
- type: "OpenAttestationOcspResponder";
54
- };
55
- renderMethod: {
56
- id: string;
57
- type: "OpenAttestationEmbeddedRenderer";
58
- templateName: string;
59
- }[];
60
- credentialSubject: {
61
- id: string;
62
- type: string[];
63
- name: string;
64
- licenses: {
65
- class: string;
66
- description: string;
67
- effectiveDate: string;
68
- }[];
69
- };
70
- };
71
- declare const BATCHED_RAW_DOCUMENTS_DID: {
72
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
73
- name: string;
74
- type: ["VerifiableCredential", "OpenAttestationCredential"];
75
- issuer: {
76
- id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90";
77
- type: "OpenAttestationIssuer";
78
- name: string;
79
- identityProof: {
80
- identityProofType: "DNS-DID";
81
- identifier: string;
82
- };
83
- };
84
- validFrom: string;
85
- credentialSubject: {
86
- id: string;
87
- type: string[];
88
- name: string;
89
- licenses: {
90
- class: string;
91
- description: string;
92
- effectiveDate: string;
93
- }[];
94
- };
95
- renderMethod: {
96
- id: string;
97
- type: "OpenAttestationEmbeddedRenderer";
98
- templateName: string;
99
- }[];
100
- }[];
101
- declare const WRAPPED_DOCUMENT_DID: {
102
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
103
- name: string;
104
- type: ["VerifiableCredential", "OpenAttestationCredential"];
105
- issuer: {
106
- id: string;
107
- type: "OpenAttestationIssuer";
108
- name: string;
109
- identityProof: {
110
- identityProofType: "DNS-DID";
111
- identifier: string;
112
- };
113
- };
114
- validFrom: string;
115
- credentialSubject: {
116
- id: string;
117
- type: string[];
118
- name: string;
119
- licenses: {
120
- class: string;
121
- description: string;
122
- effectiveDate: string;
123
- }[];
124
- };
125
- renderMethod: {
126
- id: string;
127
- type: "OpenAttestationEmbeddedRenderer";
128
- templateName: string;
129
- }[];
130
- proof: {
131
- type: "OpenAttestationMerkleProofSignature2018";
132
- proofPurpose: "assertionMethod";
133
- targetHash: string;
134
- proofs: any[];
135
- merkleRoot: string;
136
- salts: string;
137
- privacy: {
138
- obfuscated: any[];
139
- };
140
- };
141
- };
142
- declare const WRAPPED_DOCUMENT_DID_OSCP: {
143
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
144
- name: string;
145
- type: ["VerifiableCredential", "OpenAttestationCredential"];
146
- issuer: {
147
- id: string;
148
- type: "OpenAttestationIssuer";
149
- name: string;
150
- identityProof: {
151
- identityProofType: "DNS-DID";
152
- identifier: string;
153
- };
154
- };
155
- validFrom: string;
156
- credentialSubject: {
157
- id: string;
158
- type: string[];
159
- name: string;
160
- licenses: {
161
- class: string;
162
- description: string;
163
- effectiveDate: string;
164
- }[];
165
- };
166
- credentialStatus: {
167
- id: string;
168
- type: "OpenAttestationOcspResponder";
169
- };
170
- renderMethod: {
171
- id: string;
172
- type: "OpenAttestationEmbeddedRenderer";
173
- templateName: string;
174
- }[];
175
- proof: {
176
- type: "OpenAttestationMerkleProofSignature2018";
177
- proofPurpose: "assertionMethod";
178
- targetHash: string;
179
- proofs: any[];
180
- merkleRoot: string;
181
- salts: string;
182
- privacy: {
183
- obfuscated: any[];
184
- };
185
- };
186
- };
187
- declare const BATCHED_WRAPPED_DOCUMENTS_DID: {
188
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
189
- name: string;
190
- type: ["VerifiableCredential", "OpenAttestationCredential"];
191
- issuer: {
192
- id: string;
193
- type: "OpenAttestationIssuer";
194
- name: string;
195
- identityProof: {
196
- identityProofType: "DNS-DID";
197
- identifier: string;
198
- };
199
- };
200
- validFrom: string;
201
- credentialSubject: {
202
- id: string;
203
- type: string[];
204
- name: string;
205
- licenses: {
206
- class: string;
207
- description: string;
208
- effectiveDate: string;
209
- }[];
210
- };
211
- renderMethod: {
212
- id: string;
213
- type: "OpenAttestationEmbeddedRenderer";
214
- templateName: string;
215
- }[];
216
- proof: {
217
- type: "OpenAttestationMerkleProofSignature2018";
218
- proofPurpose: "assertionMethod";
219
- targetHash: string;
220
- proofs: string[];
221
- merkleRoot: string;
222
- salts: string;
223
- privacy: {
224
- obfuscated: any[];
225
- };
226
- };
227
- }[];
228
- declare const SIGNED_WRAPPED_DOCUMENT_DID: {
229
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
230
- name: string;
231
- type: ["VerifiableCredential", "OpenAttestationCredential"];
232
- issuer: {
233
- id: string;
234
- type: "OpenAttestationIssuer";
235
- name: string;
236
- identityProof: {
237
- identityProofType: "DNS-DID";
238
- identifier: string;
239
- };
240
- };
241
- validFrom: string;
242
- credentialSubject: {
243
- id: string;
244
- type: string[];
245
- name: string;
246
- licenses: {
247
- class: string;
248
- description: string;
249
- effectiveDate: string;
250
- }[];
251
- };
252
- renderMethod: {
253
- id: string;
254
- type: "OpenAttestationEmbeddedRenderer";
255
- templateName: string;
256
- }[];
257
- proof: {
258
- type: "OpenAttestationMerkleProofSignature2018";
259
- proofPurpose: "assertionMethod";
260
- targetHash: string;
261
- proofs: any[];
262
- merkleRoot: string;
263
- salts: string;
264
- privacy: {
265
- obfuscated: any[];
266
- };
267
- key: string;
268
- signature: string;
269
- };
270
- };
271
- declare const SIGNED_WRAPPED_DOCUMENT_DID_OSCP: {
272
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
273
- name: string;
274
- type: ["VerifiableCredential", "OpenAttestationCredential"];
275
- issuer: {
276
- id: string;
277
- type: "OpenAttestationIssuer";
278
- name: string;
279
- identityProof: {
280
- identityProofType: "DNS-DID";
281
- identifier: string;
282
- };
283
- };
284
- validFrom: string;
285
- credentialSubject: {
286
- id: string;
287
- type: string[];
288
- name: string;
289
- licenses: {
290
- class: string;
291
- description: string;
292
- effectiveDate: string;
293
- }[];
294
- };
295
- credentialStatus: {
296
- id: string;
297
- type: "OpenAttestationOcspResponder";
298
- };
299
- renderMethod: {
300
- id: string;
301
- type: "OpenAttestationEmbeddedRenderer";
302
- templateName: string;
303
- }[];
304
- proof: {
305
- type: "OpenAttestationMerkleProofSignature2018";
306
- proofPurpose: "assertionMethod";
307
- targetHash: string;
308
- proofs: any[];
309
- merkleRoot: string;
310
- salts: string;
311
- privacy: {
312
- obfuscated: any[];
313
- };
314
- key: string;
315
- signature: string;
316
- };
317
- };
318
- declare const SIGNED_WRAPPED_DOCUMENT_DID_OBFUSCATED: {
319
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
320
- name: string;
321
- type: ["VerifiableCredential", "OpenAttestationCredential"];
322
- issuer: {
323
- id: string;
324
- type: "OpenAttestationIssuer";
325
- name: string;
326
- identityProof: {
327
- identityProofType: "DNS-DID";
328
- identifier: string;
329
- };
330
- };
331
- validFrom: string;
332
- credentialSubject: {
333
- id: string;
334
- type: string[];
335
- name: string;
336
- licenses: ({
337
- class: string;
338
- effectiveDate: string;
339
- description?: undefined;
340
- } | {
341
- class: string;
342
- description: string;
343
- effectiveDate: string;
344
- })[];
345
- };
346
- proof: {
347
- type: "OpenAttestationMerkleProofSignature2018";
348
- proofPurpose: "assertionMethod";
349
- targetHash: string;
350
- proofs: any[];
351
- merkleRoot: string;
352
- salts: string;
353
- privacy: {
354
- obfuscated: string[];
355
- };
356
- key: string;
357
- signature: string;
358
- };
359
- renderMethod: {
360
- id: string;
361
- type: "OpenAttestationEmbeddedRenderer";
362
- templateName: string;
363
- }[];
364
- };
365
- declare const BATCHED_SIGNED_WRAPPED_DOCUMENTS_DID: {
366
- '@context': ["https://www.w3.org/ns/credentials/v2", "https://schemata.openattestation.com/com/openattestation/4.0/context.json"];
367
- name: string;
368
- type: ["VerifiableCredential", "OpenAttestationCredential"];
369
- issuer: {
370
- id: string;
371
- type: "OpenAttestationIssuer";
372
- name: string;
373
- identityProof: {
374
- identityProofType: "DNS-DID";
375
- identifier: string;
376
- };
377
- };
378
- validFrom: string;
379
- credentialSubject: {
380
- id: string;
381
- type: string[];
382
- name: string;
383
- licenses: {
384
- class: string;
385
- description: string;
386
- effectiveDate: string;
387
- }[];
388
- };
389
- renderMethod: {
390
- id: string;
391
- type: "OpenAttestationEmbeddedRenderer";
392
- templateName: string;
393
- }[];
394
- proof: {
395
- type: "OpenAttestationMerkleProofSignature2018";
396
- proofPurpose: "assertionMethod";
397
- targetHash: string;
398
- proofs: string[];
399
- merkleRoot: string;
400
- salts: string;
401
- privacy: {
402
- obfuscated: any[];
403
- };
404
- key: string;
405
- signature: string;
406
- };
407
- }[];
408
- declare const WRAPPED_DOCUMENT_DNS_TXT_V2: v2.WrappedDocument<v2.OpenAttestationDocument>;
409
- declare const W3C_VERIFIABLE_DOCUMENT: {
410
- '@context': string[];
411
- credentialStatus: {
412
- id: string;
413
- type: string;
414
- statusPurpose: string;
415
- statusListIndex: string;
416
- statusListCredential: string;
417
- };
418
- credentialSubject: {
419
- name: string;
420
- birthDate: string;
421
- type: string[];
422
- };
423
- expirationDate: string;
424
- issuer: string;
425
- type: string[];
426
- issuanceDate: string;
427
- proof: {
428
- type: string;
429
- created: string;
430
- proofPurpose: string;
431
- proofValue: string;
432
- verificationMethod: string;
433
- };
434
- };
435
-
436
- export { BATCHED_RAW_DOCUMENTS_DID, BATCHED_SIGNED_WRAPPED_DOCUMENTS_DID, BATCHED_WRAPPED_DOCUMENTS_DID, RAW_DOCUMENT_DID, RAW_DOCUMENT_DID_OSCP, SAMPLE_SIGNING_KEYS, SIGNED_WRAPPED_DOCUMENT_DID, SIGNED_WRAPPED_DOCUMENT_DID_OBFUSCATED, SIGNED_WRAPPED_DOCUMENT_DID_OSCP, W3C_VERIFIABLE_DOCUMENT, WRAPPED_DOCUMENT_DID, WRAPPED_DOCUMENT_DID_OSCP, WRAPPED_DOCUMENT_DNS_TXT_V2 };