@nuggetslife/vc 0.0.3 → 0.0.5
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/Cargo.toml +1 -0
- package/package.json +5 -5
- package/src/lib.rs +16 -16
- package/README.md +0 -9
- package/test.mjs +0 -46
package/Cargo.toml
CHANGED
|
@@ -7,6 +7,7 @@ version = "0.0.0"
|
|
|
7
7
|
crate-type = ["cdylib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
+
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
10
11
|
base64 = "0.22.1"
|
|
11
12
|
bs58 = "0.5.1"
|
|
12
13
|
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuggetslife/vc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
7
7
|
"name": "vc",
|
|
8
8
|
"triples": {
|
|
9
|
+
"defaults": false,
|
|
9
10
|
"additional": [
|
|
10
11
|
"aarch64-apple-darwin"
|
|
11
12
|
]
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
},
|
|
14
15
|
"license": "MIT",
|
|
15
16
|
"devDependencies": {
|
|
17
|
+
"@napi-rs/cli": "^2.18.3",
|
|
18
|
+
"ava": "^6.0.1",
|
|
16
19
|
"@mattrglobal/bls12381-key-pair": "^1.2.1",
|
|
17
20
|
"@nuggetslife/ffi-bbs-signatures": "^1.3.6",
|
|
18
21
|
"@types/node": "^20.14.9",
|
|
@@ -35,9 +38,6 @@
|
|
|
35
38
|
},
|
|
36
39
|
"packageManager": "yarn@4.3.1",
|
|
37
40
|
"optionalDependencies": {
|
|
38
|
-
"@nuggetslife/vc-
|
|
39
|
-
"@nuggetslife/vc-darwin-x64": "0.0.3",
|
|
40
|
-
"@nuggetslife/vc-linux-x64-gnu": "0.0.3",
|
|
41
|
-
"@nuggetslife/vc-darwin-arm64": "0.0.3"
|
|
41
|
+
"@nuggetslife/vc-darwin-arm64": "0.0.5"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/lib.rs
CHANGED
|
@@ -42,26 +42,26 @@ impl Bls12381G2KeyPair {
|
|
|
42
42
|
// which means the base58 encoded publicKey can be either 65 or 66 chars
|
|
43
43
|
// 5.85 = log base 2 (58) which is equivalent to the number of bits
|
|
44
44
|
// encoded per character of a base58 encoded string.
|
|
45
|
-
if let Some(ref pubkey_bs58) = o.public_key_base58 {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
45
|
+
// if let Some(ref pubkey_bs58) = o.public_key_base58 {
|
|
46
|
+
// if pubkey_bs58.len() != 131 && pubkey_bs58.len() != 132 {
|
|
47
|
+
// panic!(
|
|
48
|
+
// "public_key_base58 invalid length. expected 131 or 132. got {}",
|
|
49
|
+
// pubkey_bs58.len()
|
|
50
|
+
// )
|
|
51
|
+
// }
|
|
52
|
+
// };
|
|
53
53
|
|
|
54
54
|
// Validates the size of the private key if one is included
|
|
55
55
|
// This is done by 256 bits / 5.85 = 43.7 which means
|
|
56
56
|
// the base58 encoded privateKey can be either 43 or 44 chars
|
|
57
|
-
if let Some(ref privkey_bs58) = o.private_key_base58 {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
57
|
+
// if let Some(ref privkey_bs58) = o.private_key_base58 {
|
|
58
|
+
// if privkey_bs58.len() != 43 && privkey_bs58.len() != 44 {
|
|
59
|
+
// panic!(
|
|
60
|
+
// "private_key_base58 invalid length. expected 43 or 44. got {}",
|
|
61
|
+
// privkey_bs58.len()
|
|
62
|
+
// )
|
|
63
|
+
// }
|
|
64
|
+
// };
|
|
65
65
|
|
|
66
66
|
let private_key_buffer = o
|
|
67
67
|
.private_key_base58
|
package/README.md
DELETED
package/test.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { Bls12381G2KeyPair } from '@mattrglobal/bls12381-key-pair';
|
|
4
|
-
import { Bls12381G2KeyPair as NewKeyPairClass } from './index.js'
|
|
5
|
-
import bs58 from 'bs58'
|
|
6
|
-
import bbs from '@nuggetslife/ffi-bbs-signatures'
|
|
7
|
-
|
|
8
|
-
const seed = Buffer.alloc(32, 0)
|
|
9
|
-
const address = '0x581510277Bc56802dE75BA021b66873437e0169f'
|
|
10
|
-
const addressBase58 = bs58.encode(Buffer.from(address.slice(2), 'hex'))
|
|
11
|
-
|
|
12
|
-
test('gen keypair for same seed', async () => {
|
|
13
|
-
const mattr = await Bls12381G2KeyPair.generate({ seed, });
|
|
14
|
-
const harry = await NewKeyPairClass.generate({ seed })
|
|
15
|
-
const ffi = await bbs.generateBls12381G2KeyPair(seed)
|
|
16
|
-
const ffi_sec_key = bs58.encode(Buffer.from(ffi.secretKey))
|
|
17
|
-
const ffi_pub_key = bs58.encode(Buffer.from(ffi.publicKey))
|
|
18
|
-
|
|
19
|
-
// private keys match
|
|
20
|
-
assert.equal(mattr.privateKey, harry.privateKey)
|
|
21
|
-
assert.equal(ffi_sec_key, harry.privateKey)
|
|
22
|
-
|
|
23
|
-
// public keys match
|
|
24
|
-
assert.equal(mattr.publicKey, harry.publicKey)
|
|
25
|
-
assert.equal(ffi_pub_key, harry.publicKey)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('keypair from keypair', async () => {
|
|
29
|
-
const mattr = await Bls12381G2KeyPair.generate({
|
|
30
|
-
id: `did:nuggets:${addressBase58}#bls12381g2`,
|
|
31
|
-
controller: `did:nuggets:${addressBase58}`,
|
|
32
|
-
seed,
|
|
33
|
-
});
|
|
34
|
-
const harry = await NewKeyPairClass.from({
|
|
35
|
-
id: mattr.id,
|
|
36
|
-
controller: mattr.controller,
|
|
37
|
-
publicKeyBase58: mattr.publicKey,
|
|
38
|
-
privateKeyBase58: mattr.privateKey,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
assert.equal(mattr.id, harry.id)
|
|
42
|
-
assert.equal(mattr.controller, harry.controller)
|
|
43
|
-
assert.equal(mattr.privateKey, harry.privateKey)
|
|
44
|
-
assert.equal(mattr.publicKey, harry.publicKey)
|
|
45
|
-
})
|
|
46
|
-
|