@nuggetslife/vc 0.0.9 → 0.0.15

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.
Files changed (32) hide show
  1. package/Cargo.toml +5 -2
  2. package/index.d.ts +303 -3
  3. package/index.js +15 -1
  4. package/package.json +16 -8
  5. package/prepublish.sh +7 -0
  6. package/src/bls_signatures/bbs_bls_holder_bound_signature_2022/mod.rs +268 -0
  7. package/src/bls_signatures/bbs_bls_holder_bound_signature_2022/types.rs +26 -0
  8. package/src/bls_signatures/bbs_bls_holder_bound_signature_proof_2022/mod.rs +100 -0
  9. package/src/bls_signatures/bbs_bls_holder_bound_signature_proof_2022/types.rs +17 -0
  10. package/src/bls_signatures/bbs_bls_signature_2020/mod.rs +329 -0
  11. package/src/bls_signatures/bbs_bls_signature_2020/types.rs +37 -0
  12. package/src/bls_signatures/bbs_bls_signature_proof_2020/mod.rs +92 -0
  13. package/src/bls_signatures/bbs_bls_signature_proof_2020/types.rs +13 -0
  14. package/src/bls_signatures/bls_12381_g2_keypair/mod.rs +470 -0
  15. package/src/{types.rs → bls_signatures/bls_12381_g2_keypair/types.rs} +0 -11
  16. package/src/{validators.rs → bls_signatures/bls_12381_g2_keypair/validators.rs} +1 -1
  17. package/src/bls_signatures/bound_bls_12381_g2_keypair/mod.rs +70 -0
  18. package/src/bls_signatures/bound_bls_12381_g2_keypair/types.rs +11 -0
  19. package/src/bls_signatures/mod.rs +6 -0
  20. package/src/jsonld.rs +200 -0
  21. package/src/ld_signatures.rs +311 -0
  22. package/src/lib.rs +3 -463
  23. package/test-data/bbs.json +92 -0
  24. package/test-data/citizenVocab.json +57 -0
  25. package/test-data/controllerDocument.json +5 -0
  26. package/test-data/credentialsContext.json +315 -0
  27. package/test-data/deriveProofFrame.json +15 -0
  28. package/test-data/inputDocument.json +29 -0
  29. package/test-data/keyPair.json +6 -0
  30. package/test-data/suiteContext.json +82 -0
  31. package/test.mjs +1088 -22
  32. package/test_jsonld_crossverify.mjs +256 -0
@@ -0,0 +1,256 @@
1
+ // Cross-verification tests: NAPI JsonLd class vs JS reference jsonld.js
2
+ //
3
+ // These tests call both the JS reference library (jsonld) and the NAPI
4
+ // binding (JsonLd) with identical inputs, then assert the outputs match.
5
+ //
6
+ // Run: cd vc/js && node test_jsonld_crossverify.mjs
7
+
8
+ import test from 'node:test';
9
+ import assert from 'node:assert';
10
+ import { readFileSync } from 'node:fs';
11
+ import { resolve, dirname } from 'node:path';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { createRequire } from 'node:module';
14
+
15
+ // NAPI binding
16
+ import { JsonLd } from './index.js';
17
+
18
+ // JS reference library
19
+ const require = createRequire(import.meta.url);
20
+ const jsonld = require('jsonld');
21
+ const { extendContextLoader } = require('jsonld-signatures');
22
+
23
+ const __dirname = dirname(fileURLToPath(import.meta.url));
24
+ const dataDir = resolve(__dirname, '../../../jsonld-signatures-bbs/sample/ts-node/src/data');
25
+ const loadJson = (name) => JSON.parse(readFileSync(resolve(dataDir, name), 'utf8'));
26
+
27
+ const inputDocument = loadJson('inputDocument.json');
28
+ const keyPair = loadJson('keyPair.json');
29
+ const controllerDocument = loadJson('controllerDocument.json');
30
+ const citizenVocab = loadJson('citizenVocab.json');
31
+ const bbsContext = loadJson('bbs.json');
32
+ const credentialContext = loadJson('credentialsContext.json');
33
+ const suiteContext = loadJson('suiteContext.json');
34
+ const revealDocument = loadJson('deriveProofFrame.json');
35
+
36
+ // Contexts for the NAPI JsonLd class
37
+ const napiContexts = {
38
+ "did:example:489398593#test": keyPair,
39
+ "did:example:489398593": controllerDocument,
40
+ "https://w3id.org/citizenship/v1": citizenVocab,
41
+ "https://w3id.org/security/bbs/v1": bbsContext,
42
+ "https://www.w3.org/2018/credentials/v1": credentialContext,
43
+ "https://w3id.org/security/suites/jws-2020/v1": suiteContext,
44
+ };
45
+
46
+ // Document loader for the JS reference library
47
+ const documents = { ...napiContexts };
48
+ const customDocLoader = (url) => {
49
+ const context = documents[url];
50
+ if (context) {
51
+ return { contextUrl: null, document: context, documentUrl: url };
52
+ }
53
+ throw new Error(`Attempted to remote load context: '${url}', please cache instead`);
54
+ };
55
+ const documentLoader = extendContextLoader(customDocLoader);
56
+
57
+
58
+ //
59
+ // EXPAND cross-verification
60
+ //
61
+
62
+ test('cross-verify: expand(inputDocument) matches JS reference', async () => {
63
+ const proc = new JsonLd({ contexts: napiContexts });
64
+
65
+ const napiResult = await proc.expand(inputDocument);
66
+ const jsResult = await jsonld.expand(inputDocument, { documentLoader });
67
+
68
+ assert.deepStrictEqual(napiResult, jsResult);
69
+ });
70
+
71
+ test('cross-verify: expand(simple inline context) matches JS reference', async () => {
72
+ const proc = new JsonLd();
73
+ const input = {
74
+ "@context": { "name": "http://schema.org/name" },
75
+ "name": "Alice",
76
+ };
77
+
78
+ const napiResult = await proc.expand(input);
79
+ const jsResult = await jsonld.expand(input);
80
+
81
+ assert.deepStrictEqual(napiResult, jsResult);
82
+ });
83
+
84
+ test('cross-verify: expand(null) matches JS reference', async () => {
85
+ const proc = new JsonLd();
86
+
87
+ const napiResult = await proc.expand(null);
88
+ const jsResult = await jsonld.expand(null);
89
+
90
+ assert.deepStrictEqual(napiResult, jsResult);
91
+ });
92
+
93
+
94
+ //
95
+ // COMPACT cross-verification
96
+ //
97
+
98
+ test('cross-verify: compact(simple) matches JS reference', async () => {
99
+ const proc = new JsonLd();
100
+ const expanded = [
101
+ { "http://schema.org/name": [{ "@value": "Alice" }] }
102
+ ];
103
+ const ctx = { "name": "http://schema.org/name" };
104
+
105
+ const napiResult = await proc.compact(expanded, ctx);
106
+ const jsResult = await jsonld.compact(expanded, ctx);
107
+
108
+ assert.deepStrictEqual(napiResult, jsResult);
109
+ });
110
+
111
+ test('cross-verify: compact(expanded inputDocument) matches JS reference', async () => {
112
+ const proc = new JsonLd({ contexts: napiContexts });
113
+
114
+ const expanded = await proc.expand(inputDocument);
115
+ const ctx = [
116
+ "https://www.w3.org/2018/credentials/v1",
117
+ "https://w3id.org/citizenship/v1",
118
+ "https://w3id.org/security/bbs/v1",
119
+ ];
120
+
121
+ const napiResult = await proc.compact(expanded, ctx);
122
+ const jsResult = await jsonld.compact(expanded, ctx, { documentLoader });
123
+
124
+ assert.deepStrictEqual(napiResult, jsResult);
125
+ });
126
+
127
+
128
+ //
129
+ // FLATTEN cross-verification
130
+ //
131
+
132
+ test('cross-verify: flatten(inputDocument, null) matches JS reference', async () => {
133
+ const proc = new JsonLd({ contexts: napiContexts });
134
+
135
+ const napiResult = await proc.flatten(inputDocument, null);
136
+ const jsResult = await jsonld.flatten(inputDocument, null, { documentLoader });
137
+
138
+ assert.deepStrictEqual(napiResult, jsResult);
139
+ });
140
+
141
+
142
+ //
143
+ // FRAME cross-verification
144
+ //
145
+
146
+ test('cross-verify: frame(inputDocument) matches JS reference', async () => {
147
+ const proc = new JsonLd({ contexts: napiContexts });
148
+ const frameDoc = {
149
+ "@context": [
150
+ "https://www.w3.org/2018/credentials/v1",
151
+ "https://w3id.org/citizenship/v1",
152
+ "https://w3id.org/security/bbs/v1",
153
+ ],
154
+ "type": ["VerifiableCredential"],
155
+ };
156
+
157
+ const napiResult = await proc.frame(inputDocument, frameDoc);
158
+ const jsResult = await jsonld.frame(inputDocument, frameDoc, { documentLoader });
159
+
160
+ assert.deepStrictEqual(napiResult, jsResult);
161
+ });
162
+
163
+
164
+ //
165
+ // toRDF cross-verification
166
+ //
167
+
168
+ test('cross-verify: toRDF(inputDocument, n-quads) matches JS reference', async () => {
169
+ const proc = new JsonLd({ contexts: napiContexts });
170
+
171
+ const napiResult = await proc.toRDF(inputDocument, { format: 'application/n-quads' });
172
+ const jsResult = await jsonld.toRDF(inputDocument, { documentLoader, format: 'application/n-quads' });
173
+
174
+ assert.strictEqual(napiResult, jsResult);
175
+ });
176
+
177
+
178
+ //
179
+ // fromRDF cross-verification
180
+ //
181
+
182
+ test('cross-verify: fromRDF(nquads) matches JS reference', async () => {
183
+ const proc = new JsonLd({ contexts: napiContexts });
184
+
185
+ // Use the same N-Quads input (from JS reference to avoid any toRDF differences)
186
+ const nquads = await jsonld.toRDF(inputDocument, { documentLoader, format: 'application/n-quads' });
187
+
188
+ const napiResult = proc.fromRDF(nquads);
189
+ const jsResult = await jsonld.fromRDF(nquads);
190
+
191
+ assert.deepStrictEqual(napiResult, jsResult);
192
+ });
193
+
194
+
195
+ //
196
+ // CANONIZE cross-verification
197
+ //
198
+
199
+ test('cross-verify: canonize(inputDocument) matches JS reference', async () => {
200
+ const proc = new JsonLd({ contexts: napiContexts });
201
+
202
+ const napiResult = await proc.canonize(inputDocument);
203
+ // JS reference uses URDNA2015 (alias for RDFC-1.0 in older rdf-canonize)
204
+ const jsResult = await jsonld.canonize(inputDocument, {
205
+ documentLoader,
206
+ algorithm: 'URDNA2015',
207
+ format: 'application/n-quads',
208
+ });
209
+
210
+ assert.strictEqual(napiResult, jsResult);
211
+ });
212
+
213
+ test('cross-verify: canonize(nquads input) matches JS reference', async () => {
214
+ const proc = new JsonLd({ contexts: napiContexts });
215
+
216
+ const nquads = await jsonld.toRDF(inputDocument, { documentLoader, format: 'application/n-quads' });
217
+
218
+ const napiResult = await proc.canonize(nquads, { inputFormat: 'application/n-quads' });
219
+ const jsResult = await jsonld.canonize(nquads, {
220
+ inputFormat: 'application/n-quads',
221
+ algorithm: 'URDNA2015',
222
+ format: 'application/n-quads',
223
+ });
224
+
225
+ assert.strictEqual(napiResult, jsResult);
226
+ });
227
+
228
+
229
+ //
230
+ // Round-trip cross-verification
231
+ //
232
+
233
+ test('cross-verify: expand → compact round-trip matches JS reference', async () => {
234
+ const proc = new JsonLd({ contexts: napiContexts });
235
+
236
+ const expanded = await proc.expand(inputDocument);
237
+ const ctx = inputDocument['@context'];
238
+
239
+ const napiResult = await proc.compact(expanded, ctx);
240
+ const jsResult = await jsonld.compact(expanded, ctx, { documentLoader });
241
+
242
+ assert.deepStrictEqual(napiResult, jsResult);
243
+ });
244
+
245
+ test('cross-verify: expand → toRDF → fromRDF round-trip matches JS reference', async () => {
246
+ const proc = new JsonLd({ contexts: napiContexts });
247
+
248
+ // Expand → toRDF (N-Quads)
249
+ const nquads = await proc.toRDF(inputDocument, { format: 'application/n-quads' });
250
+
251
+ // fromRDF on same N-Quads
252
+ const napiResult = proc.fromRDF(nquads);
253
+ const jsResult = await jsonld.fromRDF(nquads);
254
+
255
+ assert.deepStrictEqual(napiResult, jsResult);
256
+ });