@trustvc/trustvc 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +138 -0
- package/dist/core/decrypt.js +1 -1
- package/dist/core/encrypt.js +1 -1
- package/dist/esm/core/decrypt.js +1 -1
- package/dist/esm/core/encrypt.js +1 -1
- package/package.json +6 -4
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/dist/core/decrypt.js
CHANGED
package/dist/core/encrypt.js
CHANGED
package/dist/esm/core/decrypt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '
|
|
1
|
+
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
2
2
|
import { Chacha20 } from 'ts-chacha20';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
package/dist/esm/core/encrypt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '
|
|
1
|
+
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
2
2
|
import { Chacha20 } from 'ts-chacha20';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustvc/trustvc",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
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
|
-
"@
|
|
39
|
-
"@trustvc/w3c-
|
|
40
|
-
"@trustvc/w3c-
|
|
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"
|