@trustvc/trustvc 1.6.0-alpha.5 → 1.6.0-alpha.7
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 +144 -48
- package/dist/cjs/core/documentBuilder.js +38 -14
- package/dist/cjs/verify/fragments/document-integrity/ecdsaW3CSignatureIntegrity.js +3 -3
- package/dist/cjs/verify/fragments/document-integrity/w3cSignatureIntegrity.js +2 -2
- package/dist/cjs/w3c/derive.js +11 -0
- package/dist/cjs/w3c/index.js +7 -0
- package/dist/cjs/w3c/sign.js +2 -2
- package/dist/esm/core/documentBuilder.js +39 -15
- package/dist/esm/verify/fragments/document-integrity/ecdsaW3CSignatureIntegrity.js +1 -1
- package/dist/esm/verify/fragments/document-integrity/w3cSignatureIntegrity.js +1 -1
- package/dist/esm/w3c/derive.js +9 -0
- package/dist/esm/w3c/index.js +1 -0
- package/dist/esm/w3c/sign.js +2 -2
- package/dist/types/core/documentBuilder.d.ts +14 -4
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/w3c/derive.d.ts +11 -0
- package/dist/types/w3c/index.d.ts +1 -0
- package/dist/types/w3c/sign.d.ts +6 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -16,15 +16,16 @@ TrustVC is a comprehensive wrapper library designed to simplify the signing and
|
|
|
16
16
|
- [2. **Signing**](#2-signing)
|
|
17
17
|
- [a) OpenAttestation Signing (signOA) v2 v3](#a-openattestation-signing-signoa-v2-v3)
|
|
18
18
|
- [b) TrustVC W3C Signing (signW3C)](#b-trustvc-w3c-signing-signw3c)
|
|
19
|
-
- [3. **
|
|
20
|
-
- [4. **
|
|
21
|
-
- [5. **
|
|
22
|
-
- [6. **
|
|
19
|
+
- [3. **Deriving (Selective Disclosure)**](#3-deriving-selective-disclosure)
|
|
20
|
+
- [4. **Verifying**](#4-verifying)
|
|
21
|
+
- [5. **Encryption**](#5-encryption)
|
|
22
|
+
- [6. **Decryption**](#6-decryption)
|
|
23
|
+
- [7. **TradeTrust Token Registry**](#7-tradetrust-token-registry)
|
|
23
24
|
- [Usage](#usage-2)
|
|
24
25
|
- [TradeTrustToken](#tradetrusttoken)
|
|
25
26
|
- [a) Token Registry v4](#a-token-registry-v4)
|
|
26
27
|
- [b) Token Registry V5](#b-token-registry-v5)
|
|
27
|
-
- [
|
|
28
|
+
- [8. **Document Builder**](#8-document-builder)
|
|
28
29
|
|
|
29
30
|
## Installation
|
|
30
31
|
|
|
@@ -154,15 +155,17 @@ const signedWrappedDocument = await signOA(wrappedDocument, {
|
|
|
154
155
|
|
|
155
156
|
#### b) TrustVC W3C Signing (signW3C)
|
|
156
157
|
|
|
158
|
+
The `signW3C` function signs W3C Verifiable Credentials using the provided cryptographic suite and key pair. By default, it uses the **ecdsa-sd-2023** crypto suite unless otherwise specified.
|
|
159
|
+
|
|
157
160
|
```ts
|
|
158
161
|
import { signW3C, VerificationType } from '@trustvc/trustvc';
|
|
159
162
|
|
|
160
163
|
const rawDocument = {
|
|
161
164
|
'@context': [
|
|
162
|
-
'https://www.w3.org/
|
|
163
|
-
'https://
|
|
164
|
-
'https://w3id.org/security/bbs/v1',
|
|
165
|
+
'https://www.w3.org/ns/credentials/v2',
|
|
166
|
+
'https://w3id.org/security/data-integrity/v2',
|
|
165
167
|
'https://w3id.org/vc/status-list/2021/v1',
|
|
168
|
+
'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld',
|
|
166
169
|
],
|
|
167
170
|
credentialStatus: {
|
|
168
171
|
id: 'https://trustvc.github.io/did/credentials/statuslist/1#1',
|
|
@@ -172,29 +175,113 @@ const rawDocument = {
|
|
|
172
175
|
statusListCredential: 'https://trustvc.github.io/did/credentials/statuslist/1',
|
|
173
176
|
},
|
|
174
177
|
credentialSubject: {
|
|
175
|
-
|
|
178
|
+
type: ['Person']
|
|
179
|
+
givenName: 'TrustVC',
|
|
176
180
|
birthDate: '2024-04-01T12:19:52Z',
|
|
177
|
-
type: ['PermanentResident', 'Person'],
|
|
178
181
|
},
|
|
179
|
-
expirationDate: '2029-12-03T12:19:52Z',
|
|
180
182
|
issuer: 'did:web:trustvc.github.io:did:1',
|
|
181
183
|
type: ['VerifiableCredential'],
|
|
182
|
-
|
|
184
|
+
validFrom: '2024-04-01T12:19:52Z',
|
|
185
|
+
validUntil: '2029-12-03T12:19:52Z'
|
|
183
186
|
};
|
|
184
187
|
|
|
188
|
+
// Using default ecdsa-sd-2023 crypto suite
|
|
185
189
|
const signingResult = await signW3C(rawDocument, {
|
|
186
|
-
|
|
190
|
+
'@context': 'https://w3id.org/security/multikey/v1',
|
|
191
|
+
id: 'did:web:trustvc.github.io:did:1#multikey-1',
|
|
192
|
+
type: VerificationType.Multikey,
|
|
187
193
|
controller: 'did:web:trustvc.github.io:did:1',
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
194
|
+
publicKeyMultibase: 'zDnaemDNwi4G5eTzGfRooFFu5Kns3be6yfyVNtiaMhWkZbwtc',
|
|
195
|
+
secretKeyMultibase: '<secretKeyMultibase>'
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// You can also specify mandatory pointers for selective disclosure with ecdsa-sd-2023
|
|
199
|
+
const signingResultWithPointers = await signW3C(
|
|
200
|
+
rawDocument,
|
|
201
|
+
{
|
|
202
|
+
'@context': 'https://w3id.org/security/multikey/v1',
|
|
203
|
+
id: 'did:web:trustvc.github.io:did:1#multikey-1',
|
|
204
|
+
type: VerificationType.Multikey,
|
|
205
|
+
controller: 'did:web:trustvc.github.io:did:1',
|
|
206
|
+
publicKeyMultibase: 'zDnaemDNwi4G5eTzGfRooFFu5Kns3be6yfyVNtiaMhWkZbwtc',
|
|
207
|
+
secretKeyMultibase: '<secretKeyMultibase>'
|
|
208
|
+
},
|
|
209
|
+
'ecdsa-sd-2023',
|
|
210
|
+
{
|
|
211
|
+
mandatoryPointers: ['/credentialStatus']
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// Alternatively, specify a different crypto suite. Ensure the context is updated to include the crypto suite.
|
|
216
|
+
const signingResultWithBbs = await signW3C(
|
|
217
|
+
rawDocument,
|
|
218
|
+
{
|
|
219
|
+
id: 'did:web:trustvc.github.io:did:1#keys-1',
|
|
220
|
+
controller: 'did:web:trustvc.github.io:did:1',
|
|
221
|
+
type: VerificationType.Bls12381G2Key2020,
|
|
222
|
+
publicKeyBase58: 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ',
|
|
223
|
+
privateKeyBase58: '<privateKeyBase58>',
|
|
224
|
+
},
|
|
225
|
+
'BbsBlsSignature2020'
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
### 3. **Deriving (Selective Disclosure)**
|
|
233
|
+
|
|
234
|
+
> When using ECDSA-SD-2023 crypto suite, we can derive a new credential with selective disclosure. This means you can choose which parts of the credential to reveal while keeping others hidden.
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import { deriveW3C } from '@trustvc/trustvc';
|
|
238
|
+
|
|
239
|
+
// This is a signed document using ecdsa-sd-2023
|
|
240
|
+
const signedDocument = {
|
|
241
|
+
'@context': [
|
|
242
|
+
'https://www.w3.org/ns/credentials/v2',
|
|
243
|
+
'https://w3id.org/security/data-integrity/v2',
|
|
244
|
+
'https://w3id.org/vc/status-list/2021/v1',
|
|
245
|
+
'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld'
|
|
246
|
+
],
|
|
247
|
+
credentialStatus: {
|
|
248
|
+
id: 'https://trustvc.github.io/did/credentials/statuslist/1#1',
|
|
249
|
+
type: 'StatusList2021Entry',
|
|
250
|
+
statusPurpose: 'revocation',
|
|
251
|
+
statusListIndex: '10',
|
|
252
|
+
statusListCredential: 'https://trustvc.github.io/did/credentials/statuslist/1'
|
|
253
|
+
},
|
|
254
|
+
credentialSubject: {
|
|
255
|
+
type: ['Person'],
|
|
256
|
+
givenName: 'TrustVC',
|
|
257
|
+
birthDate: '2024-04-01T12:19:52Z'
|
|
258
|
+
},
|
|
259
|
+
issuer: 'did:web:trustvc.github.io:did:1',
|
|
260
|
+
type: ['VerifiableCredential'],
|
|
261
|
+
validFrom: '2024-04-01T12:19:52Z',
|
|
262
|
+
validUntil: '2029-12-03T12:19:52Z',
|
|
263
|
+
id: 'urn:uuid:0198bd9e-6686-7ccd-9b2a-ce763ae710d7',
|
|
264
|
+
proof: {
|
|
265
|
+
type: 'DataIntegrityProof',
|
|
266
|
+
created: '2025-08-18T14:38:51Z',
|
|
267
|
+
verificationMethod: 'did:web:trustvc.github.io:did:1#multikey-1',
|
|
268
|
+
cryptosuite: 'ecdsa-sd-2023',
|
|
269
|
+
proofPurpose: 'assertionMethod',
|
|
270
|
+
proofValue: 'u2V0AhVhAxfLFkbv8J_O3zJAQrSWrEY3sgeMwN02b2eaHEgjnJYu1rnCBYORfZUVZwRoRuNIiY1NTGHmQpzlgqtQz7A0R3FgjgCQDzt3_aUvSMrlIZdsyVcB4KPHHjA4BbSv-PZ4Bbm4GpY5YIA1mQ8LYmpjJ7vNvN3DsfIengZrnziTLO9exbZjn1KqFilhA0lp1y6BZ-fhiUdWsojYesLDSzCy6Tq_AICaIvCjYSJMEaY7SomJnCkdpuhM0GQHDTy5kjzb7sSzowACqDDf9OVhAfOC7vg4WQGrI6M3dvLZW3KlBzp1SurRz1PPeHcqOGEDrqybzIlolwNXMhc2T8rcVLl-E04wNsiVjamvqWAQN-lhA4HmVqIxKuR0QvCMEVq3cjUU7G1pQbgMdp9HZDasOT9nh_k5l3JfcXB1_qtRblljXWN0FRKAr9T-DhxzDzGl3-lhA4nNDzd-6xl74rWqr_7U9XZE7LoE-mbgBsyOAOlfHGumMxwddnEZp2iD2uZ7lLXX8Q-nSDXJVvUqKLksy1l2vqVhAm3daNYjH1kVrTW7V-DElcj3K_QfbHEvjd1F2TGVGtBVhF8o01yCxXRX0vzk-AZLZnpDnAUBTSTF5Q8rF-t7L9lhAO7NeIXQtQsdncqtLm2qk1XzFYL2FM5Hx4GZOX39VyT4T0AlFRZQuY9WXYnvMZSvacRvJaSJk5S3cZ6uBminQgVhAExuTEvJQu42-SiaOJ_6M0EjuQfqIgJE-JHirmYs3AAoH_4EKUtPU3y_jRB8XFZxA-wtFDv3KJjqXtNo5aA_6f1hAaokZPSJghFufTaVR8LAwHpXOncGJblKpUZQjKWuA_o2s6tGmx-ja0wgpsqSxvAGMTtkhFTMOI2-tzUuGE05tk1hAzABtV2yEX-RAQFpxkuV0XydAsJDh2dPscrpPHqMfmORsC3xRNL73uDaqqlaL99CvOgq4kJWmChw7TUYO62yaSVhA5-F-snwj-OZtws7_qMwvBgeNK9wvkZTlFLjRV6GDYx6r5TaLkR05GVzyBMv0Qs2z-cXPRZByS7p7_hbeykoYSYJnL2lzc3VlcmovdmFsaWRGcm9t'
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// Derive a new credential with only specific fields disclosed
|
|
275
|
+
const derivationResult = await deriveW3C(signedDocument, {
|
|
276
|
+
// Only reveal the credential type and givenName, hide birthDate
|
|
277
|
+
selectivePointers: ['/type', '/credentialSubject/givenName']
|
|
192
278
|
});
|
|
279
|
+
|
|
193
280
|
```
|
|
194
281
|
|
|
195
282
|
---
|
|
196
283
|
|
|
197
|
-
###
|
|
284
|
+
### 4. **Verifying**
|
|
198
285
|
|
|
199
286
|
> TrustVC simplifies the verification process with a single function that supports both W3C Verifiable Credentials (VCs) and OpenAttestation Verifiable Documents (VDs). Whether you're working with W3C standards or OpenAttestation standards, TrustVC handles the verification seamlessly.
|
|
200
287
|
|
|
@@ -239,7 +326,7 @@ const resultFragments = await verifyDocument(signedDocument);
|
|
|
239
326
|
|
|
240
327
|
---
|
|
241
328
|
|
|
242
|
-
###
|
|
329
|
+
### 5. **Encryption**
|
|
243
330
|
|
|
244
331
|
> The `encrypt` function encrypts plaintext messages using the **ChaCha20** encryption algorithm, ensuring the security and integrity of the input data. It supports custom keys and nonces, returning the encrypted message in hexadecimal format.
|
|
245
332
|
|
|
@@ -316,7 +403,7 @@ It also relies on the `ts-chacha20` library for encryption operations.
|
|
|
316
403
|
|
|
317
404
|
---
|
|
318
405
|
|
|
319
|
-
###
|
|
406
|
+
### 6. **Decryption**
|
|
320
407
|
|
|
321
408
|
> The `decrypt` function decrypts messages encrypted with the **ChaCha20** algorithm. It converts the input from a hexadecimal format back into plaintext using the provided key and nonce.
|
|
322
409
|
|
|
@@ -399,7 +486,7 @@ It also relies on the `ts-chacha20` library for decryption operations.
|
|
|
399
486
|
|
|
400
487
|
---
|
|
401
488
|
|
|
402
|
-
###
|
|
489
|
+
### 7. **TradeTrust Token Registry**
|
|
403
490
|
|
|
404
491
|
> The Electronic Bill of Lading (eBL) is a digital document that can be used to prove the ownership of goods. It is a standardized document that is accepted by all major shipping lines and customs authorities. The [Token Registry](https://github.com/TradeTrust/token-registry) repository contains both the smart contract (v4 and v5) code for token registry (in `/contracts`) as well as the node package for using this library (in `/src`).
|
|
405
492
|
> The TrustVC library not only simplifies signing and verification but also imports and integrates existing TradeTrust libraries and smart contracts for token registry (V4 and V5), making it a versatile tool for decentralized identity and trust solutions.
|
|
@@ -589,8 +676,8 @@ function rejectTransferOwners(bytes calldata _remark) external;
|
|
|
589
676
|
|
|
590
677
|
For more information on Token Registry and Title Escrow contracts **version v5**, please visit the readme of [TradeTrust Token Registry V5](https://github.com/TradeTrust/token-registry/blob/master/README.md)
|
|
591
678
|
|
|
592
|
-
###
|
|
593
|
-
> The `DocumentBuilder` class helps build and manage W3C Verifiable Credentials (VCs) with credential status features. It supports creating documents with two types of credential statuses: `transferableRecords` and `verifiableDocument`. It can sign the document using a private key, verify its signature, and serialize the document to a JSON format. Additionally, it allows for configuration of document rendering methods and expiration dates.
|
|
679
|
+
### 8. **Document Builder**
|
|
680
|
+
> The `DocumentBuilder` class helps build and manage W3C Verifiable Credentials (VCs) with credential status features, implementing the **W3C VC Data Model 2.0** specification. It supports creating documents with two types of credential statuses: `transferableRecords` and `verifiableDocument`. It can sign the document using a private key, verify its signature, and serialize the document to a JSON format. Additionally, it allows for configuration of document rendering methods and expiration dates.
|
|
594
681
|
|
|
595
682
|
#### Usage
|
|
596
683
|
|
|
@@ -603,7 +690,7 @@ To learn more about defining custom contexts, check out the [Credential Subject
|
|
|
603
690
|
// Adds a custom vocabulary used to define terms in the `credentialSubject`.
|
|
604
691
|
// Users can define their own context if they have domain-specific fields or custom data structures.
|
|
605
692
|
const builder = new DocumentBuilder({
|
|
606
|
-
'@context': 'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-
|
|
693
|
+
'@context': 'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld'
|
|
607
694
|
});
|
|
608
695
|
```
|
|
609
696
|
|
|
@@ -612,8 +699,8 @@ Set the subject of the Verifiable Credential, which typically contains informati
|
|
|
612
699
|
|
|
613
700
|
```ts
|
|
614
701
|
builder.credentialSubject({
|
|
615
|
-
|
|
616
|
-
|
|
702
|
+
type: ['Person'],
|
|
703
|
+
givenName: 'TrustVC',
|
|
617
704
|
});
|
|
618
705
|
```
|
|
619
706
|
|
|
@@ -649,7 +736,7 @@ builder.credentialStatus({
|
|
|
649
736
|
```
|
|
650
737
|
|
|
651
738
|
##### Set Expiration Date
|
|
652
|
-
You can set
|
|
739
|
+
You can set a valid until date (expiration) for the document.
|
|
653
740
|
|
|
654
741
|
```ts
|
|
655
742
|
builder.expirationDate('2026-01-01T00:00:00Z');
|
|
@@ -677,16 +764,17 @@ builder.qrCode({
|
|
|
677
764
|
```
|
|
678
765
|
|
|
679
766
|
##### Sign the Document
|
|
680
|
-
To sign the document, provide a `PrivateKeyPair` from `@trustvc/trustvc`.
|
|
767
|
+
To sign the document, provide a `PrivateKeyPair` from `@trustvc/trustvc`. The builder uses ECDSA key for signing by default.
|
|
681
768
|
|
|
682
769
|
```ts
|
|
683
770
|
const privateKey: PrivateKeyPair = {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
771
|
+
'@context': 'https://w3id.org/security/multikey/v1',
|
|
772
|
+
id: 'did:web:example.com#multikey-1',
|
|
773
|
+
type: VerificationType.Multikey,
|
|
774
|
+
controller: 'did:web:example.com',
|
|
775
|
+
publicKeyMultibase: 'your-public-key-multibase',
|
|
776
|
+
secretKeyMultibase: 'your-secret-key-multibase',
|
|
777
|
+
}
|
|
690
778
|
|
|
691
779
|
const signedDocument = await builder.sign(privateKey);
|
|
692
780
|
console.log(signedDocument);
|
|
@@ -696,19 +784,18 @@ Example Output After Signing
|
|
|
696
784
|
```json
|
|
697
785
|
{
|
|
698
786
|
"@context": [
|
|
699
|
-
"https://www.w3.org/
|
|
700
|
-
"https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-
|
|
701
|
-
"https://
|
|
702
|
-
"https://trustvc.io/context/render-method-context.json",
|
|
787
|
+
"https://www.w3.org/ns/credentials/v2",
|
|
788
|
+
"https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld",
|
|
789
|
+
"https://trustvc.io/context/render-method-context-v2.json",
|
|
703
790
|
"https://trustvc.io/context/qrcode-context.json",
|
|
704
|
-
"https://w3id.org/security/
|
|
791
|
+
"https://w3id.org/security/data-integrity/v2"
|
|
705
792
|
],
|
|
706
793
|
"type": ["VerifiableCredential"],
|
|
707
794
|
"credentialSubject": {
|
|
708
|
-
"
|
|
709
|
-
"
|
|
795
|
+
"type": ["Person"],
|
|
796
|
+
"givenName": "TrustVC",
|
|
710
797
|
},
|
|
711
|
-
"
|
|
798
|
+
"validUntil": "2026-01-01T00:00:00Z",
|
|
712
799
|
"renderMethod": [
|
|
713
800
|
{
|
|
714
801
|
"id": "https://example.com/rendering-method",
|
|
@@ -727,21 +814,30 @@ Example Output After Signing
|
|
|
727
814
|
"statusListIndex": "<placeholder>",
|
|
728
815
|
"statusListCredential": "https://example.com/status-list"
|
|
729
816
|
},
|
|
730
|
-
"issuer": "did:example
|
|
731
|
-
"
|
|
817
|
+
"issuer": "did:web:example.com",
|
|
818
|
+
"validFrom": "2025-01-01T00:00:00Z",
|
|
732
819
|
"id": "urn:bnid:_:0195fec2-4ae1-7cca-9182-03fd7da5142b",
|
|
733
820
|
"proof": {
|
|
734
|
-
"type": "
|
|
821
|
+
"type": "DataIntegrityProof",
|
|
735
822
|
"created": "2025-01-01T00:00:01Z",
|
|
823
|
+
"verificationMethod": "did:web:example.com#multikey-1",
|
|
824
|
+
"cryptosuite": "ecdsa-sd-2023",
|
|
736
825
|
"proofPurpose": "assertionMethod",
|
|
737
|
-
"proofValue": "
|
|
738
|
-
"verificationMethod": "did:example:456#key1"
|
|
826
|
+
"proofValue": "u2V0AhVhAh1oLoiuV2AwmSa2ZspbmrG2gCDbpZW.......",
|
|
739
827
|
}
|
|
740
828
|
}
|
|
741
829
|
```
|
|
742
830
|
|
|
831
|
+
##### Deriving the Document
|
|
832
|
+
Provide the attributes to reveal to the `derive` method.
|
|
833
|
+
|
|
834
|
+
```ts
|
|
835
|
+
const derivedDocument = await builder.derive(['/credentialSubject/givenName']);
|
|
836
|
+
console.log(derivedDocument);
|
|
837
|
+
```
|
|
838
|
+
|
|
743
839
|
##### Verify the Document
|
|
744
|
-
To verify the signature of the signed document
|
|
840
|
+
To verify the signature of the signed document, ensure the document is derived first and then call the `verify` method.
|
|
745
841
|
|
|
746
842
|
```ts
|
|
747
843
|
const isVerified = await builder.verify();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var w3cIssuer = require('@trustvc/w3c-issuer');
|
|
3
4
|
var w3c = require('../w3c');
|
|
4
5
|
var w3cCredentialStatus = require('@trustvc/w3c-credential-status');
|
|
5
6
|
var w3cVc = require('@trustvc/w3c-vc');
|
|
@@ -9,6 +10,7 @@ var tokenRegistryV5$1 = require('@tradetrust-tt/token-registry-v5');
|
|
|
9
10
|
var tokenRegistryV4 = require('../token-registry-v4');
|
|
10
11
|
var tokenRegistryV5 = require('../token-registry-v5');
|
|
11
12
|
var utils = require('../utils');
|
|
13
|
+
var w3cContext = require('@trustvc/w3c-context');
|
|
12
14
|
|
|
13
15
|
var __defProp = Object.defineProperty;
|
|
14
16
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -30,6 +32,8 @@ class DocumentBuilder {
|
|
|
30
32
|
// Required fields that must be present in the document.
|
|
31
33
|
isSigned = false;
|
|
32
34
|
// Tracks if a document is signed
|
|
35
|
+
isDerived = false;
|
|
36
|
+
// Tracks if a document is derived
|
|
33
37
|
/**
|
|
34
38
|
* Constructor to initialize the document builder.
|
|
35
39
|
* @param {Partial<VerifiableCredential>} input - The input document.
|
|
@@ -63,18 +67,17 @@ class DocumentBuilder {
|
|
|
63
67
|
tokenRegistry: config.tokenRegistry
|
|
64
68
|
};
|
|
65
69
|
this.rpcProviderUrl = config.rpcProviderUrl;
|
|
66
|
-
this.addContext(
|
|
70
|
+
this.addContext(w3cContext.TR_CONTEXT_URL);
|
|
67
71
|
} else if (isVerifiable) {
|
|
68
72
|
this.selectedStatusType = "verifiableDocument";
|
|
69
73
|
this.statusConfig = {
|
|
70
74
|
id: `${config.url}#${config.index}`,
|
|
71
|
-
type: "
|
|
75
|
+
type: "BitstringStatusListEntry",
|
|
72
76
|
statusPurpose: config.purpose || "revocation",
|
|
73
77
|
// Set status purpose to "revocation" by default.
|
|
74
78
|
statusListIndex: config.index,
|
|
75
79
|
statusListCredential: config.url
|
|
76
80
|
};
|
|
77
|
-
this.addContext("https://w3id.org/vc/status-list/2021/v1");
|
|
78
81
|
} else {
|
|
79
82
|
throw new Error("Configuration Error: Missing required fields for credential status.");
|
|
80
83
|
}
|
|
@@ -83,25 +86,25 @@ class DocumentBuilder {
|
|
|
83
86
|
// Sets the expiration date of the document.
|
|
84
87
|
expirationDate(date) {
|
|
85
88
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
86
|
-
this.document.
|
|
89
|
+
this.document.validUntil = typeof date === "string" ? date : date.toISOString();
|
|
87
90
|
return this;
|
|
88
91
|
}
|
|
89
92
|
// Defines the rendering method for the document.
|
|
90
93
|
renderMethod(method) {
|
|
91
94
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
92
95
|
this.document.renderMethod = [method];
|
|
93
|
-
this.addContext(
|
|
96
|
+
this.addContext(w3cContext.RENDER_CONTEXT_V2_URL);
|
|
94
97
|
return this;
|
|
95
98
|
}
|
|
96
99
|
// Defines the qrcode for the document.
|
|
97
100
|
qrCode(method) {
|
|
98
101
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
99
102
|
this.document.qrCode = method;
|
|
100
|
-
this.addContext(
|
|
103
|
+
this.addContext(w3cContext.QRCODE_CONTEXT_URL);
|
|
101
104
|
return this;
|
|
102
105
|
}
|
|
103
106
|
// Sign the document using the provided private key and an optional cryptographic suite.
|
|
104
|
-
async sign(privateKey, cryptoSuite) {
|
|
107
|
+
async sign(privateKey, cryptoSuite, options) {
|
|
105
108
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
106
109
|
if (this.selectedStatusType) {
|
|
107
110
|
this.document.credentialStatus = this.statusConfig;
|
|
@@ -119,16 +122,36 @@ class DocumentBuilder {
|
|
|
119
122
|
await this.verifyTokenRegistry();
|
|
120
123
|
}
|
|
121
124
|
this.document.issuer = privateKey.id.split("#")[0];
|
|
122
|
-
this.document.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
this.document.validFrom = this.document.validFrom || (/* @__PURE__ */ new Date()).toISOString();
|
|
126
|
+
if (!cryptoSuite || cryptoSuite === "ecdsa-sd-2023") {
|
|
127
|
+
this.addContext(w3cContext.DATA_INTEGRITY_V2_URL);
|
|
128
|
+
} else {
|
|
129
|
+
this.addContext(w3cContext.BBS_V1_URL);
|
|
130
|
+
}
|
|
131
|
+
const signedVC = await w3c.signW3C(this.document, privateKey, cryptoSuite, options);
|
|
125
132
|
if (signedVC.error) throw new Error(`Signing Error: ${signedVC.error}`);
|
|
126
133
|
this.isSigned = true;
|
|
127
134
|
return signedVC.signed;
|
|
128
135
|
}
|
|
136
|
+
async derive(revealedAttributes) {
|
|
137
|
+
if (!this.isSigned) throw new Error("Configuration Error: Document is not signed yet.");
|
|
138
|
+
if (this.isDerived) throw new Error("Configuration Error: Document is already derived.");
|
|
139
|
+
const derivedCredential = await w3c.deriveW3C(
|
|
140
|
+
this.document,
|
|
141
|
+
revealedAttributes
|
|
142
|
+
);
|
|
143
|
+
if (derivedCredential.error) throw new Error(`Derivation Error: ${derivedCredential.error}`);
|
|
144
|
+
this.document = derivedCredential.derived;
|
|
145
|
+
this.isDerived = true;
|
|
146
|
+
return derivedCredential.derived;
|
|
147
|
+
}
|
|
129
148
|
// Verify the document.
|
|
130
149
|
async verify() {
|
|
131
150
|
if (!this.isSigned) throw new Error("Verification Error: Document is not signed yet.");
|
|
151
|
+
const cryptosuite = this.document?.proof?.cryptosuite;
|
|
152
|
+
if (cryptosuite === w3cIssuer.CryptoSuite.EcdsaSd2023 && !this.isDerived) {
|
|
153
|
+
throw new Error("Verification Error: Document is not derived yet. Use derive() first.");
|
|
154
|
+
}
|
|
132
155
|
const verificationResult = await w3c.verifyW3CSignature(
|
|
133
156
|
this.document
|
|
134
157
|
);
|
|
@@ -167,10 +190,11 @@ class DocumentBuilder {
|
|
|
167
190
|
}
|
|
168
191
|
// Private helper method to build the context for the document, ensuring uniqueness and adding the default W3C context.
|
|
169
192
|
buildContext(context) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
const arrayContext = Array.isArray(context) ? context : context ? [context] : [];
|
|
194
|
+
if (arrayContext.includes(w3cContext.VC_V1_URL)) {
|
|
195
|
+
throw new Error("Document builder does not support data model v1.1.");
|
|
196
|
+
}
|
|
197
|
+
return [w3cContext.VC_V2_URL, ...arrayContext].filter((v, i, a) => a.indexOf(v) === i);
|
|
174
198
|
}
|
|
175
199
|
// Private helper method to add a new context to the document if it does not already exist.
|
|
176
200
|
addContext(context) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var verify = require('../../../w3c/verify');
|
|
4
4
|
var w3cVc = require('@trustvc/w3c-vc');
|
|
5
5
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
@@ -42,11 +42,11 @@ const ecdsaW3CSignatureIntegrity = {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
45
|
-
let verificationResult = await
|
|
45
|
+
let verificationResult = await verify.verifyW3CSignature(document, verifierOptions);
|
|
46
46
|
let isDerived = true;
|
|
47
47
|
if (!verificationResult.verified && verificationResult.error?.includes(DERIVE_CREDENTIAL_ERROR)) {
|
|
48
48
|
const derivedCredential = await w3cVc.deriveCredential(document, []);
|
|
49
|
-
verificationResult = await
|
|
49
|
+
verificationResult = await verify.verifyW3CSignature(derivedCredential.derived, verifierOptions);
|
|
50
50
|
isDerived = false;
|
|
51
51
|
}
|
|
52
52
|
if (verificationResult.verified) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var verify = require('../../../w3c/verify');
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -23,7 +23,7 @@ const w3cSignatureIntegrity = {
|
|
|
23
23
|
}, "test"),
|
|
24
24
|
verify: /* @__PURE__ */ __name(async (document, verifierOptions) => {
|
|
25
25
|
const doc = document;
|
|
26
|
-
const verificationResult = await
|
|
26
|
+
const verificationResult = await verify.verifyW3CSignature(doc, verifierOptions);
|
|
27
27
|
if (verificationResult.verified) {
|
|
28
28
|
return {
|
|
29
29
|
type: "DOCUMENT_INTEGRITY",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var w3cVc = require('@trustvc/w3c-vc');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const deriveW3C = /* @__PURE__ */ __name(async (credential, revealedAttributes) => {
|
|
8
|
+
return w3cVc.deriveCredential(credential, revealedAttributes);
|
|
9
|
+
}, "deriveW3C");
|
|
10
|
+
|
|
11
|
+
exports.deriveW3C = deriveW3C;
|
package/dist/cjs/w3c/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var sign = require('./sign');
|
|
|
7
7
|
var types = require('./types');
|
|
8
8
|
var vc = require('./vc');
|
|
9
9
|
var verify = require('./verify');
|
|
10
|
+
var derive = require('./derive');
|
|
10
11
|
|
|
11
12
|
function _interopNamespace(e) {
|
|
12
13
|
if (e && e.__esModule) return e;
|
|
@@ -55,3 +56,9 @@ Object.keys(verify).forEach(function (k) {
|
|
|
55
56
|
get: function () { return verify[k]; }
|
|
56
57
|
});
|
|
57
58
|
});
|
|
59
|
+
Object.keys(derive).forEach(function (k) {
|
|
60
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return derive[k]; }
|
|
63
|
+
});
|
|
64
|
+
});
|
package/dist/cjs/w3c/sign.js
CHANGED
|
@@ -4,8 +4,8 @@ var w3cVc = require('@trustvc/w3c-vc');
|
|
|
4
4
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
const signW3C = /* @__PURE__ */ __name(async (credential, keyPair, cryptoSuite = "
|
|
8
|
-
return w3cVc.signCredential(credential, keyPair, cryptoSuite);
|
|
7
|
+
const signW3C = /* @__PURE__ */ __name(async (credential, keyPair, cryptoSuite = "ecdsa-sd-2023", options) => {
|
|
8
|
+
return w3cVc.signCredential(credential, keyPair, cryptoSuite, options);
|
|
9
9
|
}, "signW3C");
|
|
10
10
|
|
|
11
11
|
exports.signW3C = signW3C;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CryptoSuite } from '@trustvc/w3c-issuer';
|
|
2
|
+
import { signW3C, deriveW3C, verifyW3CSignature } from '../w3c';
|
|
2
3
|
import { assertCredentialStatus, assertTransferableRecords } from '@trustvc/w3c-credential-status';
|
|
3
4
|
import { verifyCredentialStatus } from '@trustvc/w3c-vc';
|
|
4
5
|
import { ethers } from 'ethers';
|
|
@@ -7,6 +8,7 @@ import { constants as constants$1 } from '@tradetrust-tt/token-registry-v5';
|
|
|
7
8
|
import { v4Contracts } from '../token-registry-v4';
|
|
8
9
|
import { v5Contracts } from '../token-registry-v5';
|
|
9
10
|
import { SUPPORTED_CHAINS } from '../utils';
|
|
11
|
+
import { TR_CONTEXT_URL, RENDER_CONTEXT_V2_URL, QRCODE_CONTEXT_URL, DATA_INTEGRITY_V2_URL, BBS_V1_URL, VC_V1_URL, VC_V2_URL } from '@trustvc/w3c-context';
|
|
10
12
|
|
|
11
13
|
var __defProp = Object.defineProperty;
|
|
12
14
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -28,6 +30,8 @@ class DocumentBuilder {
|
|
|
28
30
|
// Required fields that must be present in the document.
|
|
29
31
|
isSigned = false;
|
|
30
32
|
// Tracks if a document is signed
|
|
33
|
+
isDerived = false;
|
|
34
|
+
// Tracks if a document is derived
|
|
31
35
|
/**
|
|
32
36
|
* Constructor to initialize the document builder.
|
|
33
37
|
* @param {Partial<VerifiableCredential>} input - The input document.
|
|
@@ -61,18 +65,17 @@ class DocumentBuilder {
|
|
|
61
65
|
tokenRegistry: config.tokenRegistry
|
|
62
66
|
};
|
|
63
67
|
this.rpcProviderUrl = config.rpcProviderUrl;
|
|
64
|
-
this.addContext(
|
|
68
|
+
this.addContext(TR_CONTEXT_URL);
|
|
65
69
|
} else if (isVerifiable) {
|
|
66
70
|
this.selectedStatusType = "verifiableDocument";
|
|
67
71
|
this.statusConfig = {
|
|
68
72
|
id: `${config.url}#${config.index}`,
|
|
69
|
-
type: "
|
|
73
|
+
type: "BitstringStatusListEntry",
|
|
70
74
|
statusPurpose: config.purpose || "revocation",
|
|
71
75
|
// Set status purpose to "revocation" by default.
|
|
72
76
|
statusListIndex: config.index,
|
|
73
77
|
statusListCredential: config.url
|
|
74
78
|
};
|
|
75
|
-
this.addContext("https://w3id.org/vc/status-list/2021/v1");
|
|
76
79
|
} else {
|
|
77
80
|
throw new Error("Configuration Error: Missing required fields for credential status.");
|
|
78
81
|
}
|
|
@@ -81,25 +84,25 @@ class DocumentBuilder {
|
|
|
81
84
|
// Sets the expiration date of the document.
|
|
82
85
|
expirationDate(date) {
|
|
83
86
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
84
|
-
this.document.
|
|
87
|
+
this.document.validUntil = typeof date === "string" ? date : date.toISOString();
|
|
85
88
|
return this;
|
|
86
89
|
}
|
|
87
90
|
// Defines the rendering method for the document.
|
|
88
91
|
renderMethod(method) {
|
|
89
92
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
90
93
|
this.document.renderMethod = [method];
|
|
91
|
-
this.addContext(
|
|
94
|
+
this.addContext(RENDER_CONTEXT_V2_URL);
|
|
92
95
|
return this;
|
|
93
96
|
}
|
|
94
97
|
// Defines the qrcode for the document.
|
|
95
98
|
qrCode(method) {
|
|
96
99
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
97
100
|
this.document.qrCode = method;
|
|
98
|
-
this.addContext(
|
|
101
|
+
this.addContext(QRCODE_CONTEXT_URL);
|
|
99
102
|
return this;
|
|
100
103
|
}
|
|
101
104
|
// Sign the document using the provided private key and an optional cryptographic suite.
|
|
102
|
-
async sign(privateKey, cryptoSuite) {
|
|
105
|
+
async sign(privateKey, cryptoSuite, options) {
|
|
103
106
|
if (this.isSigned) throw new Error("Configuration Error: Document is already signed.");
|
|
104
107
|
if (this.selectedStatusType) {
|
|
105
108
|
this.document.credentialStatus = this.statusConfig;
|
|
@@ -117,16 +120,36 @@ class DocumentBuilder {
|
|
|
117
120
|
await this.verifyTokenRegistry();
|
|
118
121
|
}
|
|
119
122
|
this.document.issuer = privateKey.id.split("#")[0];
|
|
120
|
-
this.document.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
this.document.validFrom = this.document.validFrom || (/* @__PURE__ */ new Date()).toISOString();
|
|
124
|
+
if (!cryptoSuite || cryptoSuite === "ecdsa-sd-2023") {
|
|
125
|
+
this.addContext(DATA_INTEGRITY_V2_URL);
|
|
126
|
+
} else {
|
|
127
|
+
this.addContext(BBS_V1_URL);
|
|
128
|
+
}
|
|
129
|
+
const signedVC = await signW3C(this.document, privateKey, cryptoSuite, options);
|
|
123
130
|
if (signedVC.error) throw new Error(`Signing Error: ${signedVC.error}`);
|
|
124
131
|
this.isSigned = true;
|
|
125
132
|
return signedVC.signed;
|
|
126
133
|
}
|
|
134
|
+
async derive(revealedAttributes) {
|
|
135
|
+
if (!this.isSigned) throw new Error("Configuration Error: Document is not signed yet.");
|
|
136
|
+
if (this.isDerived) throw new Error("Configuration Error: Document is already derived.");
|
|
137
|
+
const derivedCredential = await deriveW3C(
|
|
138
|
+
this.document,
|
|
139
|
+
revealedAttributes
|
|
140
|
+
);
|
|
141
|
+
if (derivedCredential.error) throw new Error(`Derivation Error: ${derivedCredential.error}`);
|
|
142
|
+
this.document = derivedCredential.derived;
|
|
143
|
+
this.isDerived = true;
|
|
144
|
+
return derivedCredential.derived;
|
|
145
|
+
}
|
|
127
146
|
// Verify the document.
|
|
128
147
|
async verify() {
|
|
129
148
|
if (!this.isSigned) throw new Error("Verification Error: Document is not signed yet.");
|
|
149
|
+
const cryptosuite = this.document?.proof?.cryptosuite;
|
|
150
|
+
if (cryptosuite === CryptoSuite.EcdsaSd2023 && !this.isDerived) {
|
|
151
|
+
throw new Error("Verification Error: Document is not derived yet. Use derive() first.");
|
|
152
|
+
}
|
|
130
153
|
const verificationResult = await verifyW3CSignature(
|
|
131
154
|
this.document
|
|
132
155
|
);
|
|
@@ -165,10 +188,11 @@ class DocumentBuilder {
|
|
|
165
188
|
}
|
|
166
189
|
// Private helper method to build the context for the document, ensuring uniqueness and adding the default W3C context.
|
|
167
190
|
buildContext(context) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
191
|
+
const arrayContext = Array.isArray(context) ? context : context ? [context] : [];
|
|
192
|
+
if (arrayContext.includes(VC_V1_URL)) {
|
|
193
|
+
throw new Error("Document builder does not support data model v1.1.");
|
|
194
|
+
}
|
|
195
|
+
return [VC_V2_URL, ...arrayContext].filter((v, i, a) => a.indexOf(v) === i);
|
|
172
196
|
}
|
|
173
197
|
// Private helper method to add a new context to the document if it does not already exist.
|
|
174
198
|
addContext(context) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { deriveCredential } from '@trustvc/w3c-vc';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const deriveW3C = /* @__PURE__ */ __name(async (credential, revealedAttributes) => {
|
|
6
|
+
return deriveCredential(credential, revealedAttributes);
|
|
7
|
+
}, "deriveW3C");
|
|
8
|
+
|
|
9
|
+
export { deriveW3C };
|
package/dist/esm/w3c/index.js
CHANGED
package/dist/esm/w3c/sign.js
CHANGED
|
@@ -2,8 +2,8 @@ import { signCredential } from '@trustvc/w3c-vc';
|
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const signW3C = /* @__PURE__ */ __name(async (credential, keyPair, cryptoSuite = "
|
|
6
|
-
return signCredential(credential, keyPair, cryptoSuite);
|
|
5
|
+
const signW3C = /* @__PURE__ */ __name(async (credential, keyPair, cryptoSuite = "ecdsa-sd-2023", options) => {
|
|
6
|
+
return signCredential(credential, keyPair, cryptoSuite, options);
|
|
7
7
|
}, "signW3C");
|
|
8
8
|
|
|
9
9
|
export { signW3C };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
2
|
-
import { VerifiableCredential, CryptoSuiteName, SignedVerifiableCredential } from '@trustvc/w3c-vc';
|
|
2
|
+
import { VerifiableCredential, CryptoSuiteName, SignedVerifiableCredential, ContextDocument } from '@trustvc/w3c-vc';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Configuration for a W3C Verifiable Document using a Bitstring Status List.
|
|
@@ -39,7 +39,7 @@ interface RenderMethod {
|
|
|
39
39
|
templateName: string;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Configuration for the
|
|
42
|
+
* Configuration for the qrcode used in a Verifiable Credential document.
|
|
43
43
|
* @property {string} uri - A unique identifier for the qrcode, typically a URL or URI.
|
|
44
44
|
* @property {string} type - The type of the qrcode method (e.g., 'TrustVCQRCode').
|
|
45
45
|
*/
|
|
@@ -47,8 +47,16 @@ interface qrCode {
|
|
|
47
47
|
uri: string;
|
|
48
48
|
type: string;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Options for signing a document.
|
|
52
|
+
* @property {string[]} mandatoryPointers - The mandatory pointers to be used for signing the document.
|
|
53
|
+
*/
|
|
54
|
+
interface SignOptions {
|
|
55
|
+
mandatoryPointers?: string[];
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
58
|
* Main class responsible for building, configuring, and signing documents with credential statuses.
|
|
59
|
+
* This class implements the W3C Verifiable Credentials Data Model 2.0 specification.
|
|
52
60
|
*/
|
|
53
61
|
declare class DocumentBuilder {
|
|
54
62
|
private document;
|
|
@@ -58,6 +66,7 @@ declare class DocumentBuilder {
|
|
|
58
66
|
private rpcProviderUrl;
|
|
59
67
|
private requiredFields;
|
|
60
68
|
private isSigned;
|
|
69
|
+
private isDerived;
|
|
61
70
|
/**
|
|
62
71
|
* Constructor to initialize the document builder.
|
|
63
72
|
* @param {Partial<VerifiableCredential>} input - The input document.
|
|
@@ -69,7 +78,8 @@ declare class DocumentBuilder {
|
|
|
69
78
|
expirationDate(date: string | Date): this;
|
|
70
79
|
renderMethod(method: RenderMethod): this;
|
|
71
80
|
qrCode(method: qrCode): this;
|
|
72
|
-
sign(privateKey: PrivateKeyPair, cryptoSuite?: CryptoSuiteName): Promise<SignedVerifiableCredential>;
|
|
81
|
+
sign(privateKey: PrivateKeyPair, cryptoSuite?: CryptoSuiteName, options?: SignOptions): Promise<SignedVerifiableCredential>;
|
|
82
|
+
derive(revealedAttributes: ContextDocument | string[]): Promise<SignedVerifiableCredential>;
|
|
73
83
|
verify(): Promise<boolean>;
|
|
74
84
|
toString(): string;
|
|
75
85
|
private isTransferableRecordsConfig;
|
|
@@ -82,4 +92,4 @@ declare class DocumentBuilder {
|
|
|
82
92
|
private supportsInterface;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
|
-
export { DocumentBuilder, type RenderMethod, type W3CTransferableRecordsConfig, type W3CVerifiableDocumentConfig, type qrCode };
|
|
95
|
+
export { DocumentBuilder, type RenderMethod, type SignOptions, type W3CTransferableRecordsConfig, type W3CVerifiableDocumentConfig, type qrCode };
|
|
@@ -7,7 +7,7 @@ export { fetchEventTime, mergeTransfersV4, mergeTransfersV5, sortLogChain } from
|
|
|
7
7
|
export { getEndorsementChain } from './endorsement-chain/retrieveEndorsementChain.js';
|
|
8
8
|
export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTransferEventType, TokenTransferEvent, TokenTransferEventType, TradeTrustTokenEventType, TransferBaseEvent, TransferEvent, TransferEventType, TypedEvent } from './endorsement-chain/types.js';
|
|
9
9
|
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './endorsement-chain/useEndorsementChain.js';
|
|
10
|
-
export { DocumentBuilder, RenderMethod, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './documentBuilder.js';
|
|
10
|
+
export { DocumentBuilder, RenderMethod, SignOptions, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './documentBuilder.js';
|
|
11
11
|
import '@trustvc/w3c-vc';
|
|
12
12
|
import 'ethers';
|
|
13
13
|
import '@tradetrust-tt/tt-verify/dist/types/src/types/core';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export { fetchEventTime, mergeTransfersV4, mergeTransfersV5, sortLogChain } from
|
|
|
24
24
|
export { getEndorsementChain } from './core/endorsement-chain/retrieveEndorsementChain.js';
|
|
25
25
|
export { EndorsementChain, ParsedLog, TitleEscrowTransferEvent, TitleEscrowTransferEventType, TokenTransferEvent, TokenTransferEventType, TradeTrustTokenEventType, TransferBaseEvent, TransferEvent, TransferEventType, TypedEvent } from './core/endorsement-chain/types.js';
|
|
26
26
|
export { TitleEscrowInterface, checkSupportsInterface, fetchEndorsementChain, getDocumentOwner, getTitleEscrowAddress, isTitleEscrowVersion } from './core/endorsement-chain/useEndorsementChain.js';
|
|
27
|
-
export { DocumentBuilder, RenderMethod, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './core/documentBuilder.js';
|
|
27
|
+
export { DocumentBuilder, RenderMethod, SignOptions, W3CTransferableRecordsConfig, W3CVerifiableDocumentConfig, qrCode } from './core/documentBuilder.js';
|
|
28
28
|
export { signOA } from './open-attestation/sign.js';
|
|
29
29
|
export { KeyPair } from './open-attestation/types.js';
|
|
30
30
|
export { diagnose, getAssetId, getDocumentData, getIssuerAddress, getTemplateURL, isDocumentRevokable, isRawV2Document, isRawV3Document, isSignedWrappedV2Document, isSignedWrappedV3Document, isTransferableAsset, isWrappedV2Document, isWrappedV3Document } from './open-attestation/utils.js';
|
|
@@ -40,6 +40,7 @@ export { RawVerifiableCredential, SignedVerifiableCredential, SigningResult, Ver
|
|
|
40
40
|
export { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
41
41
|
export { i as vc } from './index-1ws_BWZW.js';
|
|
42
42
|
export { verifyW3CSignature } from './w3c/verify.js';
|
|
43
|
+
export { deriveW3C } from './w3c/derive.js';
|
|
43
44
|
export { errorMessageHandling, w3cCredentialStatusRevoked, w3cCredentialStatusSuspended } from './utils/fragment/index.js';
|
|
44
45
|
export * from '@tradetrust-tt/tradetrust-utils/constants/network';
|
|
45
46
|
export { generate12ByteNonce, generate32ByteKey, stringToUint8Array } from './utils/stringUtils/index.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SignedVerifiableCredential, ContextDocument, DerivedResult } from '@trustvc/w3c-vc';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Derives a credential with selective disclosure based on revealed attributes.
|
|
5
|
+
* @param {object} credential - The verifiable credential to be selectively disclosed.
|
|
6
|
+
* @param {object|string[]} revealedAttributes - For BBS+: The attributes from the credential that should be revealed. For ECDSA-SD-2023: Array of selective pointers.
|
|
7
|
+
* @returns {Promise<DerivedResult>} A DerivedResult containing the derived proof or an error message.
|
|
8
|
+
*/
|
|
9
|
+
declare const deriveW3C: (credential: SignedVerifiableCredential, revealedAttributes: ContextDocument | string[]) => Promise<DerivedResult>;
|
|
10
|
+
|
|
11
|
+
export { deriveW3C };
|
|
@@ -6,5 +6,6 @@ export { RawVerifiableCredential, SignedVerifiableCredential, SigningResult, Ver
|
|
|
6
6
|
export { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
7
7
|
export { i as vc } from '../index-1ws_BWZW.js';
|
|
8
8
|
export { verifyW3CSignature } from './verify.js';
|
|
9
|
+
export { deriveW3C } from './derive.js';
|
|
9
10
|
import '@trustvc/w3c-context';
|
|
10
11
|
import '@trustvc/w3c-credential-status';
|
package/dist/types/w3c/sign.d.ts
CHANGED
|
@@ -5,9 +5,13 @@ import { PrivateKeyPair } from '@trustvc/w3c-issuer';
|
|
|
5
5
|
* Signs a W3C Verifiable Credential using the provided cryptographic suite and key pair.
|
|
6
6
|
* @param {RawVerifiableCredential} credential - The verifiable credential object that needs to be signed.
|
|
7
7
|
* @param {PrivateKeyPair} keyPair - The private and public key pair used for signing the credential.
|
|
8
|
-
* @param {CryptoSuiteName} [cryptoSuite='
|
|
8
|
+
* @param {CryptoSuiteName} [cryptoSuite='ecdsa-sd-2023'] - The cryptographic suite to be used for signing (default is 'ecdsa-sd-2023').
|
|
9
|
+
* @param {object} [options] - Optional parameters including mandatoryPointers for ECDSA-SD-2023.
|
|
10
|
+
* @param {string[]} [options.mandatoryPointers] - Optional mandatory pointers for ECDSA-SD-2023.
|
|
9
11
|
* @returns {Promise<SigningResult>} A promise that resolves to the result of the signing operation, which includes the signed credential.
|
|
10
12
|
*/
|
|
11
|
-
declare const signW3C: (credential: RawVerifiableCredential, keyPair: PrivateKeyPair, cryptoSuite?: CryptoSuiteName
|
|
13
|
+
declare const signW3C: (credential: RawVerifiableCredential, keyPair: PrivateKeyPair, cryptoSuite?: CryptoSuiteName, options?: {
|
|
14
|
+
mandatoryPointers?: string[];
|
|
15
|
+
}) => Promise<SigningResult>;
|
|
12
16
|
|
|
13
17
|
export { signW3C };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustvc/trustvc",
|
|
3
|
-
"version": "1.6.0-alpha.
|
|
3
|
+
"version": "1.6.0-alpha.7",
|
|
4
4
|
"description": "TrustVC library",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -121,11 +121,11 @@
|
|
|
121
121
|
"@tradetrust-tt/tradetrust": "^6.10.2",
|
|
122
122
|
"@tradetrust-tt/tradetrust-utils": "^2.4.2",
|
|
123
123
|
"@tradetrust-tt/tt-verify": "^9.5.1",
|
|
124
|
-
"@trustvc/w3c": "^1.3.0-alpha.
|
|
125
|
-
"@trustvc/w3c-context": "^1.3.0-alpha.
|
|
126
|
-
"@trustvc/w3c-credential-status": "^1.3.0-alpha.
|
|
124
|
+
"@trustvc/w3c": "^1.3.0-alpha.7",
|
|
125
|
+
"@trustvc/w3c-context": "^1.3.0-alpha.7",
|
|
126
|
+
"@trustvc/w3c-credential-status": "^1.3.0-alpha.7",
|
|
127
127
|
"@trustvc/w3c-issuer": "^1.3.0-alpha.5",
|
|
128
|
-
"@trustvc/w3c-vc": "^1.3.0-alpha.
|
|
128
|
+
"@trustvc/w3c-vc": "^1.3.0-alpha.7",
|
|
129
129
|
"ethers": "^5.8.0",
|
|
130
130
|
"ethersV6": "npm:ethers@^6.14.4",
|
|
131
131
|
"js-sha3": "^0.9.3",
|