@nuggetslife/vc 0.0.21 → 0.0.24
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/generate_golden_files.mjs +181 -0
- package/index.d.ts +154 -0
- package/index.js +27 -1
- package/package.json +8 -11
- package/src/bbs_2023.rs +71 -0
- package/src/bbs_ietf.rs +255 -0
- package/src/bls_signatures/bbs_bls_holder_bound_signature_2022/mod.rs +7 -38
- package/src/bls_signatures/bbs_bls_holder_bound_signature_proof_2022/mod.rs +3 -13
- package/src/bls_signatures/bbs_bls_signature_2020/mod.rs +4 -34
- package/src/bls_signatures/bbs_bls_signature_2020/types.rs +0 -1
- package/src/bls_signatures/bbs_bls_signature_proof_2020/mod.rs +3 -13
- package/src/bls_signatures/bls_12381_g2_keypair/mod.rs +16 -16
- package/src/bls_signatures/bound_bls_12381_g2_keypair/mod.rs +3 -3
- package/src/jose.rs +415 -0
- package/src/jsonld.rs +4 -26
- package/src/ld_signatures.rs +29 -24
- package/src/lib.rs +4 -0
- package/src/sd_jwt.rs +133 -0
- package/test-data/golden/inputDocument-minimal.json +17 -0
- package/test-data/golden/inputDocument-rich.json +29 -0
- package/test-data/golden/mattrglobal-derived-prc.json +36 -0
- package/test-data/golden/mattrglobal-signed-minimal.json +30 -0
- package/test-data/golden/mattrglobal-signed-prc.json +42 -0
- package/test-data/golden/mattrglobal-signed-rich.json +42 -0
- package/test.mjs +38 -0
- package/test_backward_compat.mjs +287 -0
- package/test_bbs_2023.mjs +195 -0
- package/test_bbs_ietf.mjs +168 -0
- package/test_fuzz.mjs +202 -0
- package/test_jose.mjs +497 -0
- package/test_jsonld_crossverify.mjs +1 -1
- package/test_sd_jwt.mjs +197 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* generate_golden_files.mjs
|
|
3
|
+
*
|
|
4
|
+
* Generates golden-file signed VCs using the @mattrglobal library.
|
|
5
|
+
* These fixtures are saved as static JSON for backward compatibility testing
|
|
6
|
+
* against the new NAPI-based implementation.
|
|
7
|
+
*
|
|
8
|
+
* Outputs:
|
|
9
|
+
* test-data/golden/mattrglobal-signed-prc.json (BbsBlsSignature2020 signed VC)
|
|
10
|
+
* test-data/golden/mattrglobal-derived-prc.json (BbsBlsSignatureProof2020 derived proof)
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* node generate_golden_files.mjs
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
17
|
+
import { resolve, dirname } from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { createRequire } from 'node:module';
|
|
20
|
+
|
|
21
|
+
// @mattrglobal libraries (CJS, loaded via createRequire)
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const { Bls12381G2KeyPair } = require('@mattrglobal/bls12381-key-pair');
|
|
24
|
+
const {
|
|
25
|
+
BbsBlsSignature2020,
|
|
26
|
+
BbsBlsSignatureProof2020,
|
|
27
|
+
deriveProof,
|
|
28
|
+
} = require('@mattrglobal/jsonld-signatures-bbs');
|
|
29
|
+
const { sign, purposes, extendContextLoader } = require('jsonld-signatures');
|
|
30
|
+
|
|
31
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
const dataDir = resolve(__dirname, 'test-data');
|
|
33
|
+
const goldenDir = resolve(dataDir, 'golden');
|
|
34
|
+
const loadJson = (name) => JSON.parse(readFileSync(resolve(dataDir, name), 'utf8'));
|
|
35
|
+
|
|
36
|
+
// Load test data
|
|
37
|
+
const inputDocument = loadJson('inputDocument.json');
|
|
38
|
+
const keyPairJson = loadJson('keyPair.json');
|
|
39
|
+
const controllerDocument = loadJson('controllerDocument.json');
|
|
40
|
+
const citizenVocab = loadJson('citizenVocab.json');
|
|
41
|
+
const bbsContext = loadJson('bbs.json');
|
|
42
|
+
const credentialsContext = loadJson('credentialsContext.json');
|
|
43
|
+
const suiteContext = loadJson('suiteContext.json');
|
|
44
|
+
const revealDocument = loadJson('deriveProofFrame.json');
|
|
45
|
+
|
|
46
|
+
// Build document loader (same pattern as test_jsonld_crossverify.mjs)
|
|
47
|
+
const documents = {
|
|
48
|
+
"did:example:489398593#test": keyPairJson,
|
|
49
|
+
"did:example:489398593": controllerDocument,
|
|
50
|
+
"https://w3id.org/citizenship/v1": citizenVocab,
|
|
51
|
+
"https://w3id.org/security/bbs/v1": bbsContext,
|
|
52
|
+
"https://www.w3.org/2018/credentials/v1": credentialsContext,
|
|
53
|
+
"https://w3id.org/security/suites/jws-2020/v1": suiteContext,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const customDocLoader = (url) => {
|
|
57
|
+
const context = documents[url];
|
|
58
|
+
if (context) {
|
|
59
|
+
return { contextUrl: null, document: context, documentUrl: url };
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Attempted to remote load context: '${url}', please cache instead`);
|
|
62
|
+
};
|
|
63
|
+
const documentLoader = extendContextLoader(customDocLoader);
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
// Ensure golden directory exists
|
|
67
|
+
mkdirSync(goldenDir, { recursive: true });
|
|
68
|
+
|
|
69
|
+
// ---------- Step 1: Sign the PRC document ----------
|
|
70
|
+
console.log('Creating key pair from test data...');
|
|
71
|
+
const keyPair = await Bls12381G2KeyPair.from({
|
|
72
|
+
id: keyPairJson.id,
|
|
73
|
+
controller: keyPairJson.controller,
|
|
74
|
+
publicKeyBase58: keyPairJson.publicKeyBase58,
|
|
75
|
+
privateKeyBase58: keyPairJson.privateKeyBase58,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const suite = new BbsBlsSignature2020({ key: keyPair });
|
|
79
|
+
|
|
80
|
+
console.log('Signing inputDocument with @mattrglobal BbsBlsSignature2020...');
|
|
81
|
+
const signedDocument = await sign(inputDocument, {
|
|
82
|
+
suite,
|
|
83
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
84
|
+
documentLoader,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const signedPath = resolve(goldenDir, 'mattrglobal-signed-prc.json');
|
|
88
|
+
writeFileSync(signedPath, JSON.stringify(signedDocument, null, 2) + '\n');
|
|
89
|
+
console.log(` Saved signed document to: ${signedPath}`);
|
|
90
|
+
console.log(` Proof type: ${signedDocument.proof.type}`);
|
|
91
|
+
console.log(` Verification method: ${signedDocument.proof.verificationMethod}`);
|
|
92
|
+
|
|
93
|
+
// ---------- Step 2: Derive a proof ----------
|
|
94
|
+
console.log('Deriving proof with @mattrglobal BbsBlsSignatureProof2020...');
|
|
95
|
+
const derivedDocument = await deriveProof(signedDocument, revealDocument, {
|
|
96
|
+
suite: new BbsBlsSignatureProof2020(),
|
|
97
|
+
documentLoader,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const derivedPath = resolve(goldenDir, 'mattrglobal-derived-prc.json');
|
|
101
|
+
writeFileSync(derivedPath, JSON.stringify(derivedDocument, null, 2) + '\n');
|
|
102
|
+
console.log(` Saved derived document to: ${derivedPath}`);
|
|
103
|
+
console.log(` Proof type: ${derivedDocument.proof.type}`);
|
|
104
|
+
console.log(` Nonce present: ${!!derivedDocument.proof.nonce}`);
|
|
105
|
+
|
|
106
|
+
// ---------- Step 3: Verify both documents ----------
|
|
107
|
+
console.log('Verifying signed document...');
|
|
108
|
+
const { verify } = require('jsonld-signatures');
|
|
109
|
+
const verifySignedResult = await verify(signedDocument, {
|
|
110
|
+
suite: new BbsBlsSignature2020(),
|
|
111
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
112
|
+
documentLoader,
|
|
113
|
+
});
|
|
114
|
+
console.log(` Signed document verified: ${verifySignedResult.verified}`);
|
|
115
|
+
if (!verifySignedResult.verified) {
|
|
116
|
+
console.error(' ERROR:', verifySignedResult.error);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log('Verifying derived document...');
|
|
121
|
+
const verifyDerivedResult = await verify(derivedDocument, {
|
|
122
|
+
suite: new BbsBlsSignatureProof2020(),
|
|
123
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
124
|
+
documentLoader,
|
|
125
|
+
});
|
|
126
|
+
console.log(` Derived document verified: ${verifyDerivedResult.verified}`);
|
|
127
|
+
if (!verifyDerivedResult.verified) {
|
|
128
|
+
console.error(' ERROR:', verifyDerivedResult.error);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---------- Step 4: Sign additional VC variants ----------
|
|
133
|
+
// These test different field counts (BBS+ signatures depend on statement count)
|
|
134
|
+
|
|
135
|
+
const loadGolden = (name) => JSON.parse(readFileSync(resolve(goldenDir, name), 'utf8'));
|
|
136
|
+
|
|
137
|
+
// Minimal VC (few fields)
|
|
138
|
+
const minimalDoc = loadGolden('inputDocument-minimal.json');
|
|
139
|
+
console.log('Signing minimal VC (few fields)...');
|
|
140
|
+
const signedMinimal = await sign(minimalDoc, {
|
|
141
|
+
suite: new BbsBlsSignature2020({ key: keyPair }),
|
|
142
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
143
|
+
documentLoader,
|
|
144
|
+
});
|
|
145
|
+
const minimalPath = resolve(goldenDir, 'mattrglobal-signed-minimal.json');
|
|
146
|
+
writeFileSync(minimalPath, JSON.stringify(signedMinimal, null, 2) + '\n');
|
|
147
|
+
console.log(` Saved: ${minimalPath}`);
|
|
148
|
+
|
|
149
|
+
// Rich VC (many fields, similar to Nuggets identity credentials)
|
|
150
|
+
const richDoc = loadGolden('inputDocument-rich.json');
|
|
151
|
+
console.log('Signing rich VC (many fields)...');
|
|
152
|
+
const signedRich = await sign(richDoc, {
|
|
153
|
+
suite: new BbsBlsSignature2020({ key: keyPair }),
|
|
154
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
155
|
+
documentLoader,
|
|
156
|
+
});
|
|
157
|
+
const richPath = resolve(goldenDir, 'mattrglobal-signed-rich.json');
|
|
158
|
+
writeFileSync(richPath, JSON.stringify(signedRich, null, 2) + '\n');
|
|
159
|
+
console.log(` Saved: ${richPath}`);
|
|
160
|
+
|
|
161
|
+
// Verify additional variants
|
|
162
|
+
for (const [name, doc] of [['minimal', signedMinimal], ['rich', signedRich]]) {
|
|
163
|
+
const result = await verify(doc, {
|
|
164
|
+
suite: new BbsBlsSignature2020(),
|
|
165
|
+
purpose: new purposes.AssertionProofPurpose(),
|
|
166
|
+
documentLoader,
|
|
167
|
+
});
|
|
168
|
+
console.log(` ${name} VC verified: ${result.verified}`);
|
|
169
|
+
if (!result.verified) {
|
|
170
|
+
console.error(' ERROR:', result.error);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log('\nAll golden files generated and verified successfully.');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
main().catch((err) => {
|
|
179
|
+
console.error('Fatal error:', err);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
package/index.d.ts
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
+
export interface Bbs2023VerifyOutput {
|
|
7
|
+
verified: boolean
|
|
8
|
+
error?: string
|
|
9
|
+
}
|
|
10
|
+
export declare function bbs2023Sign(options: any): any
|
|
11
|
+
export declare function bbs2023Derive(options: any): any
|
|
12
|
+
export declare function bbs2023Verify(document: any, publicKey?: string | undefined | null): Bbs2023VerifyOutput
|
|
13
|
+
export interface BbsIetfKeyPair {
|
|
14
|
+
/** Hex-encoded secret key (32 bytes) */
|
|
15
|
+
secretKey: string
|
|
16
|
+
/** Hex-encoded public key (96 bytes, compressed G2) */
|
|
17
|
+
publicKey: string
|
|
18
|
+
}
|
|
19
|
+
export declare function bbsIetfKeygen(ikm?: Buffer | undefined | null, keyInfo?: Buffer | undefined | null, ciphersuite?: string | undefined | null): BbsIetfKeyPair
|
|
20
|
+
export declare function bbsIetfSign(secretKey: Buffer, publicKey: Buffer, header: Buffer | undefined | null, messages: Array<string>, ciphersuite?: string | undefined | null): Buffer
|
|
21
|
+
export declare function bbsIetfVerify(publicKey: Buffer, signature: Buffer, header: Buffer | undefined | null, messages: Array<string>, ciphersuite?: string | undefined | null): boolean
|
|
22
|
+
export declare function bbsIetfProofGen(publicKey: Buffer, signature: Buffer, header: Buffer | undefined | null, presentationHeader: Buffer | undefined | null, messages: Array<string>, disclosedIndices: Array<number>, ciphersuite?: string | undefined | null): Buffer
|
|
23
|
+
export declare function bbsIetfProofVerify(publicKey: Buffer, proof: Buffer, header: Buffer | undefined | null, presentationHeader: Buffer | undefined | null, disclosedMessages: any, totalMessageCount: number, ciphersuite?: string | undefined | null): boolean
|
|
6
24
|
export interface BoundSignatureSuiteOptions {
|
|
7
25
|
key?: KeyPairOptions
|
|
8
26
|
verificationMethod?: string
|
|
@@ -164,6 +182,120 @@ export interface BoundKeyPairOptions {
|
|
|
164
182
|
commitment: Uint8Array
|
|
165
183
|
blinded: Array<number>
|
|
166
184
|
}
|
|
185
|
+
export const enum JoseNamedCurve {
|
|
186
|
+
P256 = 0,
|
|
187
|
+
P384 = 1,
|
|
188
|
+
P521 = 2,
|
|
189
|
+
Secp256k1 = 3,
|
|
190
|
+
Ed25519 = 4,
|
|
191
|
+
Ed448 = 5,
|
|
192
|
+
X25519 = 6,
|
|
193
|
+
X448 = 7
|
|
194
|
+
}
|
|
195
|
+
export const enum JoseContentEncryption {
|
|
196
|
+
A128gcm = 0,
|
|
197
|
+
A192gcm = 1,
|
|
198
|
+
A256gcm = 2,
|
|
199
|
+
A128cbcHs256 = 3,
|
|
200
|
+
A192cbcHs384 = 4,
|
|
201
|
+
A256cbcHs512 = 5
|
|
202
|
+
}
|
|
203
|
+
export const enum JoseKeyEncryption {
|
|
204
|
+
Dir = 0,
|
|
205
|
+
EcdhEs = 1,
|
|
206
|
+
EcdhEsA128kw = 2,
|
|
207
|
+
EcdhEsA192kw = 3,
|
|
208
|
+
EcdhEsA256kw = 4,
|
|
209
|
+
Rsa1_5 = 5,
|
|
210
|
+
RsaOaep = 6,
|
|
211
|
+
RsaOaep256 = 7,
|
|
212
|
+
RsaOaep384 = 8,
|
|
213
|
+
RsaOaep512 = 9,
|
|
214
|
+
Pbes2Hs256A128kw = 10,
|
|
215
|
+
Pbes2Hs384A192kw = 11,
|
|
216
|
+
Pbes2Hs512A256kw = 12,
|
|
217
|
+
A128kw = 13,
|
|
218
|
+
A192kw = 14,
|
|
219
|
+
A256kw = 15,
|
|
220
|
+
A128gcmkw = 16,
|
|
221
|
+
A192gcmkw = 17,
|
|
222
|
+
A256gcmkw = 18
|
|
223
|
+
}
|
|
224
|
+
export const enum JoseSigningAlgorithm {
|
|
225
|
+
Es256 = 0,
|
|
226
|
+
Es384 = 1,
|
|
227
|
+
Es512 = 2,
|
|
228
|
+
Es256k = 3,
|
|
229
|
+
Eddsa = 4,
|
|
230
|
+
Hs256 = 5,
|
|
231
|
+
Hs384 = 6,
|
|
232
|
+
Hs512 = 7,
|
|
233
|
+
Rs256 = 8,
|
|
234
|
+
Rs384 = 9,
|
|
235
|
+
Rs512 = 10,
|
|
236
|
+
Ps256 = 11,
|
|
237
|
+
Ps384 = 12,
|
|
238
|
+
Ps512 = 13
|
|
239
|
+
}
|
|
240
|
+
export interface JoseEncryptResult {
|
|
241
|
+
ciphertext: string
|
|
242
|
+
tag?: string
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generate a JWK key pair and return the JWK (public + private) as a JSON object.
|
|
246
|
+
* Matches ffi-jose `generateJWK({ namedCurve })`.
|
|
247
|
+
*/
|
|
248
|
+
export declare function generateJwk(namedCurve: JoseNamedCurve): any
|
|
249
|
+
/**
|
|
250
|
+
* Generate a full key pair (JWK, PEM, DER formats) and return as a JSON object.
|
|
251
|
+
* Matches ffi-jose `generateKeyPair(type, { namedCurve })`.
|
|
252
|
+
*/
|
|
253
|
+
export declare function generateKeyPair(namedCurve: JoseNamedCurve): any
|
|
254
|
+
/**
|
|
255
|
+
* Low-level symmetric encryption. Key and IV as hex strings, plaintext as base64.
|
|
256
|
+
* Matches ffi-jose `encrypt(enc, plaintext, cek, iv, aad, didcomm)`.
|
|
257
|
+
*/
|
|
258
|
+
export declare function joseEncrypt(enc: JoseContentEncryption, key: string, iv: string, message: string, aad?: string | undefined | null): JoseEncryptResult
|
|
259
|
+
/**
|
|
260
|
+
* Low-level symmetric decryption. Returns base64-encoded plaintext.
|
|
261
|
+
* Matches ffi-jose `decrypt(enc, cek, ciphertext, iv, tag, aad)`.
|
|
262
|
+
*/
|
|
263
|
+
export declare function joseDecrypt(enc: JoseContentEncryption, key: string, iv: string, ciphertext: string, aad?: string | undefined | null, tag?: string | undefined | null): string
|
|
264
|
+
/**
|
|
265
|
+
* Encrypt a JSON payload for one or more recipients using JWE General JSON serialization.
|
|
266
|
+
* Matches ffi-jose `generalEncryptJson(alg, enc, payload, recipients, didcomm)`.
|
|
267
|
+
*/
|
|
268
|
+
export declare function generalEncryptJson(alg: JoseKeyEncryption, enc: JoseContentEncryption, payload: any, recipients: Array<any>, didcomm?: boolean | undefined | null): any
|
|
269
|
+
/**
|
|
270
|
+
* Decrypt a JWE JSON object using a JWK private key.
|
|
271
|
+
* Matches ffi-jose `decryptJson(jwe, jwk)`.
|
|
272
|
+
*/
|
|
273
|
+
export declare function decryptJson(jwe: any, jwk: any): any
|
|
274
|
+
/**
|
|
275
|
+
* Sign a JSON payload using JWS Compact serialization.
|
|
276
|
+
* Matches ffi-jose `compactSignJson(alg, payload, jwk, didcomm)`.
|
|
277
|
+
*/
|
|
278
|
+
export declare function compactSignJson(alg: JoseSigningAlgorithm, payload: any, jwk: any, didcomm?: boolean | undefined | null): string
|
|
279
|
+
/**
|
|
280
|
+
* Verify a JWS Compact serialization and return the payload.
|
|
281
|
+
* Matches ffi-jose `compactJsonVerify(jws, jwk)`.
|
|
282
|
+
*/
|
|
283
|
+
export declare function compactJsonVerify(jws: string, jwk: any): any
|
|
284
|
+
/**
|
|
285
|
+
* Sign a JSON payload using JWS Flattened JSON serialization.
|
|
286
|
+
* Matches ffi-jose `flattenedSignJson(alg, payload, jwk, didcomm)`.
|
|
287
|
+
*/
|
|
288
|
+
export declare function flattenedSignJson(alg: JoseSigningAlgorithm, payload: any, jwk: any, didcomm?: boolean | undefined | null): any
|
|
289
|
+
/**
|
|
290
|
+
* Verify a JWS Flattened or General JSON serialization and return the payload.
|
|
291
|
+
* Matches ffi-jose `jsonVerify(jws, jwk)`.
|
|
292
|
+
*/
|
|
293
|
+
export declare function jsonVerify(jws: any, jwk: any): any
|
|
294
|
+
/**
|
|
295
|
+
* Sign a JSON payload using JWS General JSON serialization with multiple signers.
|
|
296
|
+
* Matches ffi-jose `generalSignJson(payload, jwks, didcomm)`.
|
|
297
|
+
*/
|
|
298
|
+
export declare function generalSignJson(payload: any, jwks: Array<any>, didcomm?: boolean | undefined | null): any
|
|
167
299
|
/**
|
|
168
300
|
* Sign a document with BbsBlsSignature2020 and embed the proof.
|
|
169
301
|
*
|
|
@@ -222,6 +354,28 @@ export declare function unblindSignature(blindSignature: Uint8Array, blindingFac
|
|
|
222
354
|
* Output: derived document JSON with embedded proof
|
|
223
355
|
*/
|
|
224
356
|
export declare function deriveProofHolderBound(proofDocument: any, revealDocument: any, options: any): Promise<any>
|
|
357
|
+
export interface SdJwtDisclosure {
|
|
358
|
+
salt: string
|
|
359
|
+
claimName: string
|
|
360
|
+
claimValue: any
|
|
361
|
+
encoded: string
|
|
362
|
+
digest: string
|
|
363
|
+
}
|
|
364
|
+
export interface SdJwtIssueOutput {
|
|
365
|
+
sdJwt: string
|
|
366
|
+
disclosures: Array<SdJwtDisclosure>
|
|
367
|
+
}
|
|
368
|
+
export interface SdJwtPresentOutput {
|
|
369
|
+
presentation: string
|
|
370
|
+
}
|
|
371
|
+
export interface SdJwtVerifyOutput {
|
|
372
|
+
verified: boolean
|
|
373
|
+
claims: any
|
|
374
|
+
error?: string
|
|
375
|
+
}
|
|
376
|
+
export declare function sdJwtIssue(claims: any, disclosable: Array<string>, jwk: any, alg: string, holderJwk?: any | undefined | null, decoyCount?: number | undefined | null): SdJwtIssueOutput
|
|
377
|
+
export declare function sdJwtPresent(sdJwt: string, disclosuresToReveal: Array<string>, kbJwk?: any | undefined | null, kbAlg?: string | undefined | null, audience?: string | undefined | null, nonce?: string | undefined | null): SdJwtPresentOutput
|
|
378
|
+
export declare function sdJwtVerify(presentation: string, issuerJwk: any, holderJwk?: any | undefined | null, audience?: string | undefined | null, nonce?: string | undefined | null): SdJwtVerifyOutput
|
|
225
379
|
export declare class BbsBlsHolderBoundSignature2022 {
|
|
226
380
|
type: string
|
|
227
381
|
constructor(options?: BoundSignatureSuiteOptions | undefined | null)
|
package/index.js
CHANGED
|
@@ -310,8 +310,16 @@ if (!nativeBinding) {
|
|
|
310
310
|
throw new Error(`Failed to load native binding`)
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
const { BbsBlsHolderBoundSignature2022, BbsBlsHolderBoundSignatureProof2022, BbsBlsSignature2020, BbsBlsSignatureProof2020, Bls12381G2KeyPair, KeyPairSigner, KeyPairVerifier, BoundBls12381G2KeyPair, JsonLd, ldSign, ldVerify, ldDeriveProof, deriveProof, createCommitment, verifyCommitment, unblindSignature, deriveProofHolderBound } = nativeBinding
|
|
313
|
+
const { bbs2023Sign, bbs2023Derive, bbs2023Verify, bbsIetfKeygen, bbsIetfSign, bbsIetfVerify, bbsIetfProofGen, bbsIetfProofVerify, BbsBlsHolderBoundSignature2022, BbsBlsHolderBoundSignatureProof2022, BbsBlsSignature2020, BbsBlsSignatureProof2020, Bls12381G2KeyPair, KeyPairSigner, KeyPairVerifier, BoundBls12381G2KeyPair, JoseNamedCurve, JoseContentEncryption, JoseKeyEncryption, JoseSigningAlgorithm, generateJwk, generateKeyPair, joseEncrypt, joseDecrypt, generalEncryptJson, decryptJson, compactSignJson, compactJsonVerify, flattenedSignJson, jsonVerify, generalSignJson, JsonLd, ldSign, ldVerify, ldDeriveProof, deriveProof, createCommitment, verifyCommitment, unblindSignature, deriveProofHolderBound, sdJwtIssue, sdJwtPresent, sdJwtVerify } = nativeBinding
|
|
314
314
|
|
|
315
|
+
module.exports.bbs2023Sign = bbs2023Sign
|
|
316
|
+
module.exports.bbs2023Derive = bbs2023Derive
|
|
317
|
+
module.exports.bbs2023Verify = bbs2023Verify
|
|
318
|
+
module.exports.bbsIetfKeygen = bbsIetfKeygen
|
|
319
|
+
module.exports.bbsIetfSign = bbsIetfSign
|
|
320
|
+
module.exports.bbsIetfVerify = bbsIetfVerify
|
|
321
|
+
module.exports.bbsIetfProofGen = bbsIetfProofGen
|
|
322
|
+
module.exports.bbsIetfProofVerify = bbsIetfProofVerify
|
|
315
323
|
module.exports.BbsBlsHolderBoundSignature2022 = BbsBlsHolderBoundSignature2022
|
|
316
324
|
module.exports.BbsBlsHolderBoundSignatureProof2022 = BbsBlsHolderBoundSignatureProof2022
|
|
317
325
|
module.exports.BbsBlsSignature2020 = BbsBlsSignature2020
|
|
@@ -320,6 +328,21 @@ module.exports.Bls12381G2KeyPair = Bls12381G2KeyPair
|
|
|
320
328
|
module.exports.KeyPairSigner = KeyPairSigner
|
|
321
329
|
module.exports.KeyPairVerifier = KeyPairVerifier
|
|
322
330
|
module.exports.BoundBls12381G2KeyPair = BoundBls12381G2KeyPair
|
|
331
|
+
module.exports.JoseNamedCurve = JoseNamedCurve
|
|
332
|
+
module.exports.JoseContentEncryption = JoseContentEncryption
|
|
333
|
+
module.exports.JoseKeyEncryption = JoseKeyEncryption
|
|
334
|
+
module.exports.JoseSigningAlgorithm = JoseSigningAlgorithm
|
|
335
|
+
module.exports.generateJwk = generateJwk
|
|
336
|
+
module.exports.generateKeyPair = generateKeyPair
|
|
337
|
+
module.exports.joseEncrypt = joseEncrypt
|
|
338
|
+
module.exports.joseDecrypt = joseDecrypt
|
|
339
|
+
module.exports.generalEncryptJson = generalEncryptJson
|
|
340
|
+
module.exports.decryptJson = decryptJson
|
|
341
|
+
module.exports.compactSignJson = compactSignJson
|
|
342
|
+
module.exports.compactJsonVerify = compactJsonVerify
|
|
343
|
+
module.exports.flattenedSignJson = flattenedSignJson
|
|
344
|
+
module.exports.jsonVerify = jsonVerify
|
|
345
|
+
module.exports.generalSignJson = generalSignJson
|
|
323
346
|
module.exports.JsonLd = JsonLd
|
|
324
347
|
module.exports.ldSign = ldSign
|
|
325
348
|
module.exports.ldVerify = ldVerify
|
|
@@ -329,3 +352,6 @@ module.exports.createCommitment = createCommitment
|
|
|
329
352
|
module.exports.verifyCommitment = verifyCommitment
|
|
330
353
|
module.exports.unblindSignature = unblindSignature
|
|
331
354
|
module.exports.deriveProofHolderBound = deriveProofHolderBound
|
|
355
|
+
module.exports.sdJwtIssue = sdJwtIssue
|
|
356
|
+
module.exports.sdJwtPresent = sdJwtPresent
|
|
357
|
+
module.exports.sdJwtVerify = sdJwtVerify
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuggetslife/vc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -22,10 +22,7 @@
|
|
|
22
22
|
"@mattrglobal/jsonld-signatures-bbs": "^1.2.0",
|
|
23
23
|
"@napi-rs/cli": "^2.18.3",
|
|
24
24
|
"@types/node": "^20.14.9",
|
|
25
|
-
"
|
|
26
|
-
},
|
|
27
|
-
"ava": {
|
|
28
|
-
"timeout": "3m"
|
|
25
|
+
"jsonld": "^8.3.3"
|
|
29
26
|
},
|
|
30
27
|
"engines": {
|
|
31
28
|
"node": ">= 10"
|
|
@@ -35,17 +32,17 @@
|
|
|
35
32
|
"build": "napi build --platform --release",
|
|
36
33
|
"build:debug": "napi build --platform",
|
|
37
34
|
"prepublishOnly": "napi prepublish -t npm",
|
|
38
|
-
"test": "
|
|
35
|
+
"test": "node test.mjs && node test_jose.mjs && node test_sd_jwt.mjs && node test_jsonld_crossverify.mjs && node test_backward_compat.mjs",
|
|
39
36
|
"universal": "napi universal",
|
|
40
37
|
"version": "napi version"
|
|
41
38
|
},
|
|
42
39
|
"packageManager": "yarn@4.3.1",
|
|
43
40
|
"optionalDependencies": {
|
|
44
|
-
"@nuggetslife/vc-darwin-arm64": "0.0.
|
|
45
|
-
"@nuggetslife/vc-linux-arm64-gnu": "0.0.
|
|
46
|
-
"@nuggetslife/vc-linux-arm64-musl": "0.0.
|
|
47
|
-
"@nuggetslife/vc-linux-x64-gnu": "0.0.
|
|
48
|
-
"@nuggetslife/vc-linux-x64-musl": "0.0.
|
|
41
|
+
"@nuggetslife/vc-darwin-arm64": "0.0.24",
|
|
42
|
+
"@nuggetslife/vc-linux-arm64-gnu": "0.0.24",
|
|
43
|
+
"@nuggetslife/vc-linux-arm64-musl": "0.0.24",
|
|
44
|
+
"@nuggetslife/vc-linux-x64-gnu": "0.0.24",
|
|
45
|
+
"@nuggetslife/vc-linux-x64-musl": "0.0.24"
|
|
49
46
|
},
|
|
50
47
|
"dependencies": {}
|
|
51
48
|
}
|
package/src/bbs_2023.rs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
use serde_json::Value;
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Result types
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
#[napi(object)]
|
|
8
|
+
pub struct Bbs2023VerifyOutput {
|
|
9
|
+
pub verified: bool,
|
|
10
|
+
pub error: Option<String>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// bbs2023Sign — create a base proof (issuer)
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
#[napi(js_name = "bbs2023Sign")]
|
|
18
|
+
pub fn bbs2023_sign(options: Value) -> napi::Result<Value> {
|
|
19
|
+
let sign_opts: vc::bbs_2023::SignOptions = serde_json::from_value(options)
|
|
20
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Sign parse options: {e}")))?;
|
|
21
|
+
|
|
22
|
+
let rt = tokio::runtime::Runtime::new()
|
|
23
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Sign runtime: {e}")))?;
|
|
24
|
+
|
|
25
|
+
let result = rt
|
|
26
|
+
.block_on(vc::bbs_2023::create_base_proof(sign_opts))
|
|
27
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Sign failed: {e}")))?;
|
|
28
|
+
|
|
29
|
+
Ok(result)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// bbs2023Derive — create a derived proof (holder)
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
#[napi(js_name = "bbs2023Derive")]
|
|
37
|
+
pub fn bbs2023_derive(options: Value) -> napi::Result<Value> {
|
|
38
|
+
let derive_opts: vc::bbs_2023::DeriveOptions = serde_json::from_value(options)
|
|
39
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Derive parse options: {e}")))?;
|
|
40
|
+
|
|
41
|
+
let rt = tokio::runtime::Runtime::new()
|
|
42
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Derive runtime: {e}")))?;
|
|
43
|
+
|
|
44
|
+
let result = rt
|
|
45
|
+
.block_on(vc::bbs_2023::create_derived_proof(derive_opts))
|
|
46
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Derive failed: {e}")))?;
|
|
47
|
+
|
|
48
|
+
Ok(result)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// bbs2023Verify — verify a base or derived proof
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
#[napi(js_name = "bbs2023Verify")]
|
|
56
|
+
pub fn bbs2023_verify(
|
|
57
|
+
document: Value,
|
|
58
|
+
public_key: Option<String>,
|
|
59
|
+
) -> napi::Result<Bbs2023VerifyOutput> {
|
|
60
|
+
let rt = tokio::runtime::Runtime::new()
|
|
61
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Verify runtime: {e}")))?;
|
|
62
|
+
|
|
63
|
+
let result = rt
|
|
64
|
+
.block_on(vc::bbs_2023::verify_proof(document, public_key))
|
|
65
|
+
.map_err(|e| napi::Error::from_reason(format!("bbs2023Verify failed: {e}")))?;
|
|
66
|
+
|
|
67
|
+
Ok(Bbs2023VerifyOutput {
|
|
68
|
+
verified: result.verified,
|
|
69
|
+
error: result.error,
|
|
70
|
+
})
|
|
71
|
+
}
|