@nuggetslife/vc 0.0.8 → 0.0.10
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/index.d.ts +4 -2
- package/package.json +13 -5
- package/prepublish.sh +7 -0
- package/src/lib.rs +34 -24
- package/src/types.rs +2 -2
- package/test.mjs +14 -0
package/index.d.ts
CHANGED
|
@@ -97,8 +97,8 @@ export interface KeyPairVerifierOptions {
|
|
|
97
97
|
export class Bls12381G2KeyPair {
|
|
98
98
|
id?: string
|
|
99
99
|
controller?: string
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
privateKeyInner?: Array<number>
|
|
101
|
+
publicKeyInner?: Array<number>
|
|
102
102
|
type: string
|
|
103
103
|
constructor(options?: KeyPairOptions | undefined | null)
|
|
104
104
|
static generate(options?: GenerateKeyPairOptions | undefined | null): Promise<Bls12381G2KeyPair>
|
|
@@ -106,6 +106,8 @@ export class Bls12381G2KeyPair {
|
|
|
106
106
|
static fromJwk(options: JwkKeyPairOptions): Promise<Bls12381G2KeyPair>
|
|
107
107
|
static fromFingerprint(options: KeyPairFromFingerPrintOptions): Promise<Bls12381G2KeyPair>
|
|
108
108
|
get publicKey(): string | null
|
|
109
|
+
get publicKeyBuffer(): Buffer
|
|
110
|
+
get privateKeyBuffer(): Buffer
|
|
109
111
|
publicKeyJwk(): JsonWebKey
|
|
110
112
|
get privateKey(): string | null
|
|
111
113
|
privateKeyJwk(): JsonWebKey
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuggetslife/vc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
"triples": {
|
|
9
9
|
"defaults": false,
|
|
10
10
|
"additional": [
|
|
11
|
-
"aarch64-apple-darwin"
|
|
11
|
+
"aarch64-apple-darwin",
|
|
12
|
+
"x86_64-apple-darwin",
|
|
13
|
+
"aarch64-unknown-linux-gnu",
|
|
14
|
+
"aarch64-unknown-linux-musl",
|
|
15
|
+
"x86_64-unknown-linux-gnu",
|
|
16
|
+
"x86_64-unknown-linux-musl"
|
|
12
17
|
]
|
|
13
18
|
}
|
|
14
19
|
},
|
|
@@ -16,8 +21,6 @@
|
|
|
16
21
|
"devDependencies": {
|
|
17
22
|
"@napi-rs/cli": "^2.18.3",
|
|
18
23
|
"ava": "^6.0.1",
|
|
19
|
-
"@mattrglobal/bls12381-key-pair": "^1.2.1",
|
|
20
|
-
"@nuggetslife/ffi-bbs-signatures": "^1.3.6",
|
|
21
24
|
"@types/node": "^20.14.9",
|
|
22
25
|
"bs58": "^6.0.0"
|
|
23
26
|
},
|
|
@@ -38,6 +41,11 @@
|
|
|
38
41
|
},
|
|
39
42
|
"packageManager": "yarn@4.3.1",
|
|
40
43
|
"optionalDependencies": {
|
|
41
|
-
"@nuggetslife/vc-darwin-arm64": "0.0.
|
|
44
|
+
"@nuggetslife/vc-darwin-arm64": "0.0.10",
|
|
45
|
+
"@nuggetslife/vc-darwin-x64": "0.0.10",
|
|
46
|
+
"@nuggetslife/vc-linux-arm64-gnu": "0.0.10",
|
|
47
|
+
"@nuggetslife/vc-linux-arm64-musl": "0.0.10",
|
|
48
|
+
"@nuggetslife/vc-linux-x64-gnu": "0.0.10",
|
|
49
|
+
"@nuggetslife/vc-linux-x64-musl": "0.0.10"
|
|
42
50
|
}
|
|
43
51
|
}
|
package/prepublish.sh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/bin/bash -xe
|
|
2
|
+
mv vc.linux-arm64-gnu.node npm/linux-arm64-gnu/
|
|
3
|
+
mv vc.linux-arm64-musl.node npm/linux-arm64-musl/
|
|
4
|
+
mv vc.linux-x64-gnu.node npm/linux-x64-gnu/
|
|
5
|
+
mv vc.linux-x64-musl.node npm/linux-x64-musl/
|
|
6
|
+
mv vc.darwin-arm64.node npm/darwin-arm64/
|
|
7
|
+
mv vc.darwin-x64.node npm/darwin-x64/
|
package/src/lib.rs
CHANGED
|
@@ -52,26 +52,26 @@ impl Bls12381G2KeyPair {
|
|
|
52
52
|
// }
|
|
53
53
|
// };
|
|
54
54
|
|
|
55
|
-
let
|
|
55
|
+
let private_key_inner = o
|
|
56
56
|
.private_key_base58
|
|
57
57
|
.map(|v| bs58::decode(v).into_vec().unwrap());
|
|
58
|
-
let
|
|
58
|
+
let public_key_inner = o
|
|
59
59
|
.public_key_base58
|
|
60
60
|
.map(|v| bs58::decode(v).into_vec().unwrap());
|
|
61
61
|
|
|
62
62
|
Self {
|
|
63
63
|
id: o.id,
|
|
64
64
|
controller: o.controller,
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
private_key_inner,
|
|
66
|
+
public_key_inner,
|
|
67
67
|
type_: String::from("Bls12381G2Key2020"),
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
None => Self {
|
|
71
71
|
id: None,
|
|
72
72
|
controller: None,
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
private_key_inner: None,
|
|
74
|
+
public_key_inner: None,
|
|
75
75
|
type_: String::from("Bls12381G2Key2020"),
|
|
76
76
|
},
|
|
77
77
|
}
|
|
@@ -239,22 +239,32 @@ impl Bls12381G2KeyPair {
|
|
|
239
239
|
#[napi(getter)]
|
|
240
240
|
pub fn public_key(&self) -> Option<String> {
|
|
241
241
|
self
|
|
242
|
-
.
|
|
242
|
+
.public_key_inner
|
|
243
243
|
.clone()
|
|
244
244
|
.map(|b| bs58::encode(b).into_string())
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
#[napi(getter)]
|
|
248
|
+
pub fn public_key_buffer(&self) -> Buffer {
|
|
249
|
+
self.public_key_inner.clone().unwrap().into()
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[napi(getter)]
|
|
253
|
+
pub fn private_key_buffer(&self) -> Buffer {
|
|
254
|
+
self.private_key_inner.clone().unwrap().into()
|
|
255
|
+
}
|
|
256
|
+
|
|
247
257
|
#[napi]
|
|
248
258
|
pub fn public_key_jwk(&self) -> Result<JsonWebKey> {
|
|
249
|
-
let Some(ref
|
|
250
|
-
return Err(napi::Error::from_reason("no
|
|
259
|
+
let Some(ref public_key_inner) = self.public_key_inner else {
|
|
260
|
+
return Err(napi::Error::from_reason("no public_key_inner"));
|
|
251
261
|
};
|
|
252
262
|
|
|
253
263
|
Ok(JsonWebKey {
|
|
254
264
|
kid: self.id.to_owned(),
|
|
255
265
|
kty: JwkKty::EC.into(),
|
|
256
266
|
crv: BlsCurveName::G2.into(),
|
|
257
|
-
x: URL_SAFE_NO_PAD.encode(
|
|
267
|
+
x: URL_SAFE_NO_PAD.encode(public_key_inner),
|
|
258
268
|
use_: None,
|
|
259
269
|
key_ops: None,
|
|
260
270
|
alg: None,
|
|
@@ -267,27 +277,27 @@ impl Bls12381G2KeyPair {
|
|
|
267
277
|
#[napi(getter)]
|
|
268
278
|
pub fn private_key(&self) -> Option<String> {
|
|
269
279
|
self
|
|
270
|
-
.
|
|
280
|
+
.private_key_inner
|
|
271
281
|
.clone()
|
|
272
282
|
.map(|b| bs58::encode(b).into_string())
|
|
273
283
|
}
|
|
274
284
|
|
|
275
285
|
#[napi]
|
|
276
286
|
pub fn private_key_jwk(&self) -> Result<JsonWebKey> {
|
|
277
|
-
let Some(ref
|
|
278
|
-
return Err(napi::Error::from_reason("no
|
|
287
|
+
let Some(ref public_key_inner) = self.public_key_inner else {
|
|
288
|
+
return Err(napi::Error::from_reason("no public_key_inner"));
|
|
279
289
|
};
|
|
280
290
|
|
|
281
|
-
let Some(ref
|
|
282
|
-
return Err(napi::Error::from_reason("no
|
|
291
|
+
let Some(ref private_key_inner) = self.private_key_inner else {
|
|
292
|
+
return Err(napi::Error::from_reason("no private_key_inner"));
|
|
283
293
|
};
|
|
284
294
|
|
|
285
295
|
Ok(JsonWebKey {
|
|
286
296
|
kid: self.id.to_owned(),
|
|
287
297
|
kty: JwkKty::EC.into(),
|
|
288
298
|
crv: BlsCurveName::G2.into(),
|
|
289
|
-
x: URL_SAFE_NO_PAD.encode(
|
|
290
|
-
d: Some(URL_SAFE_NO_PAD.encode(
|
|
299
|
+
x: URL_SAFE_NO_PAD.encode(public_key_inner),
|
|
300
|
+
d: Some(URL_SAFE_NO_PAD.encode(private_key_inner)),
|
|
291
301
|
use_: None,
|
|
292
302
|
key_ops: None,
|
|
293
303
|
alg: None,
|
|
@@ -360,14 +370,14 @@ impl Bls12381G2KeyPair {
|
|
|
360
370
|
napi::Error::from_reason(format!("failed to decode bs58 value: error: {err}"))
|
|
361
371
|
})?;
|
|
362
372
|
|
|
363
|
-
let
|
|
364
|
-
.
|
|
373
|
+
let public_key_inner = self
|
|
374
|
+
.public_key_inner
|
|
365
375
|
.clone()
|
|
366
376
|
.ok_or(napi::Error::from_reason("public key buffer is missing"))?;
|
|
367
377
|
|
|
368
378
|
let leader = hex::encode(&fingerprint_buffer[..2]);
|
|
369
379
|
let leader_match = if leader == "eb01" { true } else { false };
|
|
370
|
-
let bytes_match = if &
|
|
380
|
+
let bytes_match = if &public_key_inner == &fingerprint_buffer[2..] {
|
|
371
381
|
true
|
|
372
382
|
} else {
|
|
373
383
|
false
|
|
@@ -404,14 +414,14 @@ pub struct KeyPairSignerOptions {
|
|
|
404
414
|
impl KeyPairSigner {
|
|
405
415
|
#[napi]
|
|
406
416
|
pub async fn sign(&self, options: KeyPairSignerOptions) -> Result<Uint8Array> {
|
|
407
|
-
if self.key.
|
|
417
|
+
if self.key.private_key_inner.is_none() {
|
|
408
418
|
return Err(napi::Error::from_reason("No private key to sign with."));
|
|
409
419
|
}
|
|
410
420
|
|
|
411
421
|
let messages: Vec<Vec<u8>> = options.data.into_iter().map(|x| x.to_vec()).collect();
|
|
412
422
|
let key_pair = BlsKeyPair {
|
|
413
|
-
public_key: self.key.
|
|
414
|
-
secret_key: self.key.
|
|
423
|
+
public_key: self.key.public_key_inner.clone(),
|
|
424
|
+
secret_key: self.key.private_key_inner.clone(),
|
|
415
425
|
};
|
|
416
426
|
let sig = bls_sign(BlsBbsSignRequest { messages, key_pair })
|
|
417
427
|
.await
|
|
@@ -437,7 +447,7 @@ impl KeyPairVerifier {
|
|
|
437
447
|
#[napi]
|
|
438
448
|
pub async fn verify(&self, options: KeyPairVerifierOptions) -> Result<bool> {
|
|
439
449
|
let KeyPairVerifierOptions { data, signature } = options;
|
|
440
|
-
let Some(public_key) = self.key.
|
|
450
|
+
let Some(public_key) = self.key.public_key_inner.clone() else {
|
|
441
451
|
return Err(napi::Error::from_reason(
|
|
442
452
|
"key.public_key is required for verify",
|
|
443
453
|
));
|
package/src/types.rs
CHANGED
|
@@ -5,8 +5,8 @@ use napi::bindgen_prelude::*;
|
|
|
5
5
|
pub struct Bls12381G2KeyPair {
|
|
6
6
|
pub id: Option<String>,
|
|
7
7
|
pub controller: Option<String>,
|
|
8
|
-
pub
|
|
9
|
-
pub
|
|
8
|
+
pub private_key_inner: Option<Vec<u8>>,
|
|
9
|
+
pub public_key_inner: Option<Vec<u8>>,
|
|
10
10
|
#[napi(js_name = "type")]
|
|
11
11
|
pub type_: String,
|
|
12
12
|
}
|
package/test.mjs
CHANGED
|
@@ -76,3 +76,17 @@ test('sign and verify', async () => {
|
|
|
76
76
|
assert.equal(ms_verify_ms_sig, true)
|
|
77
77
|
assert.equal(ms_verify_hs_sig, true)
|
|
78
78
|
})
|
|
79
|
+
|
|
80
|
+
test('issuer jwk', async () => {
|
|
81
|
+
|
|
82
|
+
const mattr = await Bls12381G2KeyPair.generate({ seed, });
|
|
83
|
+
const harry = await NewKeyPairClass.generate({ seed })
|
|
84
|
+
console.log(mattr.publicKeyBuffer)
|
|
85
|
+
console.log(mattr.privateKeyBuffer)
|
|
86
|
+
|
|
87
|
+
console.log(harry.publicKeyBuffer)
|
|
88
|
+
console.log(harry.publicKeyBuffer2)
|
|
89
|
+
console.log(harry.privateKeyBuffer)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
})
|