@trustvc/trustvc 1.6.0-alpha.5 → 1.6.0-alpha.6

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
@@ -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. **Verifying**](#3-verifying)
20
- - [4. **Encryption**](#4-encryption)
21
- - [5. **Decryption**](#5-decryption)
22
- - [6. **TradeTrust Token Registry**](#6-tradetrust-token-registry)
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
- - [7. **Document Builder**](#7-document-builder)
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/2018/credentials/v1',
163
- 'https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld',
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
- name: 'TrustVC',
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
- issuanceDate: '2024-04-01T12:19:52Z',
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
- id: 'did:web:trustvc.github.io:did:1#keys-1',
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
- type: VerificationType.Bls12381G2Key2020,
189
- publicKeyBase58:
190
- 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ',
191
- privateKeyBase58: '<privateKeyBase58>',
194
+ publicKeyMultibase: 'zDnaemDNwi4G5eTzGfRooFFu5Kns3be6yfyVNtiaMhWkZbwtc',
195
+ secretKeyMultibase: '<secretKeyMultibase>'
192
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']
278
+ });
279
+
193
280
  ```
194
281
 
195
282
  ---
196
283
 
197
- ### 3. **Verifying**
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
- ### 4. **Encryption**
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
- ### 5. **Decryption**
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
- ### 6. **TradeTrust Token Registry**
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,7 +676,7 @@ 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
- ### 7. **Document Builder**
679
+ ### 8. **Document Builder**
593
680
  > 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.
594
681
 
595
682
  #### Usage
@@ -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;
@@ -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
+ });
@@ -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 = "BbsBlsSignature2020") => {
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;
@@ -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 };
@@ -9,3 +9,4 @@ export * from './types';
9
9
  import * as vc from './vc';
10
10
  export { vc };
11
11
  export * from './verify';
12
+ export * from './derive';
@@ -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 = "BbsBlsSignature2020") => {
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 };
@@ -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';
@@ -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='BbsBlsSignature2020'] - The cryptographic suite to be used for signing (default is 'BbsBlsSignature2020').
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) => Promise<SigningResult>;
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.5",
3
+ "version": "1.6.0-alpha.6",
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.5",
125
- "@trustvc/w3c-context": "^1.3.0-alpha.5",
126
- "@trustvc/w3c-credential-status": "^1.3.0-alpha.5",
124
+ "@trustvc/w3c": "^1.3.0-alpha.6",
125
+ "@trustvc/w3c-context": "^1.3.0-alpha.6",
126
+ "@trustvc/w3c-credential-status": "^1.3.0-alpha.6",
127
127
  "@trustvc/w3c-issuer": "^1.3.0-alpha.5",
128
- "@trustvc/w3c-vc": "^1.3.0-alpha.5",
128
+ "@trustvc/w3c-vc": "^1.3.0-alpha.6",
129
129
  "ethers": "^5.8.0",
130
130
  "ethersV6": "npm:ethers@^6.14.4",
131
131
  "js-sha3": "^0.9.3",