Commit 1d7f8c2384b2cf7fb3e4c249c3f8963ea65313ff
added examples
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 10/7/2017, 9:57:25 PM
Parent: 4de9b15440c5c5b1824eeead6312af9f6467c5b0
Files changed
README.md | changed |
build/bls_lib.js | changed |
build/bls_lib.wasm | changed |
build/build.ninja | changed |
exportedFuncs.json | changed |
examples/addingKeys.js | added |
examples/dh.js | added |
examples/diffieHellman.js | added |
examples/signing.js | added |
README.md | ||
---|---|---|
@@ -38,8 +38,11 @@ | ||
38 | 38 … | bls.free(pub) |
39 | 39 … | }) |
40 | 40 … | ``` |
41 | 41 … | |
42 … | +# EXAMPLES | |
43 … | +[./examples/](./examples/) | |
44 … | + | |
42 | 45 … | # API |
43 | 46 … | [./docs/](./docs/index.md) |
44 | 47 … | |
45 | 48 … | # BUILDING |
build/bls_lib.js | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 145412 bytes New file size: 145669 bytes |
build/bls_lib.wasm | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 437172 bytes New file size: 437357 bytes |
build/build.ninja | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 … | cflags = -I../mcl/include/ -I../cybozulib/include -I../bls/include -I../bls |
2 | 2 … | |
3 | -EXPORTED_BLS= "'_blsInit', '_blsIdSerialize' ,'_blsSecretKeySerialize' ,'_blsPublicKeySerialize' ,'_blsSignatureSerialize' ,'_blsIdDeserialize' ,'_blsSecretKeyDeserialize' ,'_blsPublicKeyDeserialize' ,'_blsSignatureDeserialize','_blsSecretKeyIsEqual' ,'_blsPublicKeyIsEqual' ,'_blsSignatureIsEqual' ,'_blsSecretKeySetByCSPRNG' ,'_blsGetPublicKey', '_blsSecretKeyShare' ,'_blsPublicKeyShare' ,'_blsSecretKeyRecover' ,'_blsPublicKeyRecover' ,'_blsSignatureRecover' ,'_blsSign' ,'_blsVerify', '_blsIdSetInt', '_blsHashToSecretKey', '_blsPublicKeyAdd', '_blsSecretKeyAdd', '_blsSignatureAdd'" | |
3 … | +EXPORTED_BLS= "'_blsInit', '_blsIdSerialize' ,'_blsSecretKeySerialize' ,'_blsPublicKeySerialize' ,'_blsSignatureSerialize' ,'_blsIdDeserialize' ,'_blsSecretKeyDeserialize' ,'_blsPublicKeyDeserialize' ,'_blsSignatureDeserialize','_blsSecretKeyIsEqual' ,'_blsPublicKeyIsEqual' ,'_blsSignatureIsEqual' ,'_blsSecretKeySetByCSPRNG' ,'_blsGetPublicKey', '_blsSecretKeyShare' ,'_blsPublicKeyShare' ,'_blsSecretKeyRecover' ,'_blsPublicKeyRecover' ,'_blsSignatureRecover' ,'_blsSign' ,'_blsVerify', '_blsIdSetInt', '_blsHashToSecretKey', '_blsPublicKeyAdd', '_blsSecretKeyAdd', '_blsSignatureAdd', '_blsDHKeyExchange'" | |
4 | 4 … | |
5 | 5 … | rule buildExLib |
6 | 6 … | command = emcc -O3 -o $out ../bls/src/bls_c.cpp ../mcl/src/fp.cpp -s EXPORTED_FUNCTIONS=[$EXPORTED_BLS] --pre-js ../pre.js $cflags -s WASM=1 -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 |
7 | 7 … |
exportedFuncs.json | ||
---|---|---|
@@ -111,5 +111,9 @@ | ||
111 | 111 … | "name": "blsSignatureIsEqual", |
112 | 112 … | "exportName": "signatureIsEqual", |
113 | 113 … | "returns": "number", |
114 | 114 … | "args": ["number", "number"] |
115 … | +}, { | |
116 … | + "name": "blsDHKeyExchange", | |
117 … | + "exportName": "dhKeyExchange", | |
118 … | + "args": ["number", "number", "number"] | |
115 | 119 … | }] |
examples/addingKeys.js | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 … | +const bls = require('../') | |
2 … | + | |
3 … | +bls.onModuleInit(() => { | |
4 … | + bls.init() | |
5 … | + | |
6 … | + const sk1 = bls.secretKey() | |
7 … | + const sk2 = bls.secretKey() | |
8 … | + | |
9 … | + const pk1 = bls.publicKey() | |
10 … | + const pk2 = bls.publicKey() | |
11 … | + | |
12 … | + bls.getPublicKey(pk1, sk1) | |
13 … | + bls.getPublicKey(pk2, sk2) | |
14 … | + | |
15 … | + bls.publicKeyAdd(pk1, pk2) | |
16 … | + | |
17 … | + bls.secretKeyAdd(sk1, sk2) | |
18 … | + | |
19 … | + const pk3 = bls.publicKey() | |
20 … | + bls.getPublicKey(pk3, sk1) | |
21 … | + | |
22 … | + const r = bls.publicKeyIsEqual(pk3, pk1) | |
23 … | + console.log(r) | |
24 … | + | |
25 … | + bls.freeArray([sk1, sk2, pk1, pk2, pk3]) | |
26 … | +}) |
examples/dh.js | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 … | +const bls = require('../') | |
2 … | + | |
3 … | +// Diffie–Hellman key exchange | |
4 … | +bls.onModuleInit(() => { | |
5 … | + bls.init() | |
6 … | + | |
7 … | + const sk1 = bls.secretKey() | |
8 … | + const sk2 = bls.secretKey() | |
9 … | + | |
10 … | + const pk1 = bls.publicKey() | |
11 … | + const pk2 = bls.publicKey() | |
12 … | + | |
13 … | + bls.getPublicKey(pk1, sk1) | |
14 … | + bls.getPublicKey(pk2, sk2) | |
15 … | + | |
16 … | + const sharedSec1 = bls.publicKey() | |
17 … | + const sharedSec2 = bls.publicKey() | |
18 … | + | |
19 … | + bls.dhKeyExchange(sharedSec1, sk1, pk2) | |
20 … | + bls.dhKeyExchange(sharedSec2, sk2, pk1) | |
21 … | + | |
22 … | + const r = bls.publicKeyIsEqual(sharedSec1, sharedSec2) | |
23 … | + console.log(r) | |
24 … | + | |
25 … | + bls.freeArray([sk1, sk2, pk1, pk2, sharedSec2, sharedSec1]) | |
26 … | +}) |
examples/diffieHellman.js | ||
---|---|---|
@@ -1,0 +1,23 @@ | ||
1 … | +const bls = require('../') | |
2 … | + | |
3 … | +bls.onModuleInit(() => { | |
4 … | + bls.init() | |
5 … | + | |
6 … | + const sk1 = bls.secretKey() | |
7 … | + const sk2 = bls.secretKey() | |
8 … | + | |
9 … | + const pk1 = bls.publicKey() | |
10 … | + const pk2 = bls.publicKey() | |
11 … | + | |
12 … | + bls.getPublicKey(pk1, sk1) | |
13 … | + bls.getPublicKey(pk2, sk2) | |
14 … | + | |
15 … | + const out1 = bls.publicKey() | |
16 … | + const out2 = bls.publicKey() | |
17 … | + | |
18 … | + bls.dhKeyExchange(out1, sk1, pk2) | |
19 … | + bls.dhKeyExchange(out2, sk2, pk1) | |
20 … | + | |
21 … | + const r = bls.publicKeyIsEqual(out1, out2) | |
22 … | + console.log(r) | |
23 … | +}) |
examples/signing.js | ||
---|---|---|
@@ -1,0 +1,22 @@ | ||
1 … | +const bls = require('../') | |
2 … | + | |
3 … | +bls.onModuleInit(() => { | |
4 … | + bls.init() | |
5 … | + | |
6 … | + const sec = bls.secretKey() | |
7 … | + const pub = bls.publicKey() | |
8 … | + const sig = bls.signature() | |
9 … | + | |
10 … | + bls.secretKeySetByCSPRNG(sec) | |
11 … | + const msg = 'hello world' | |
12 … | + bls.sign(sig, sec, msg) | |
13 … | + | |
14 … | + bls.getPublicKey(pub, sec) | |
15 … | + | |
16 … | + const v = bls.verify(sig, pub, msg) | |
17 … | + console.log(v) | |
18 … | + | |
19 … | + bls.free(sec) | |
20 … | + bls.free(sig) | |
21 … | + bls.free(pub) | |
22 … | +}) |
Built with git-ssb-web