git ssb

0+

wanderer🌟 / bls-lib



Commit fc378c64787f6a082a4aec751ccf9fdffe72e076

added examples

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 10/7/2017, 9:58:03 PM
Parent: e2174166432c22b6a7a6938be92de5d436d44a4c

Files changed

README.mdchanged
build/bls_lib.jschanged
build/bls_lib.wasmchanged
build/build.ninjachanged
exportedFuncs.jsonchanged
examples/addingKeys.jsadded
examples/dh.jsadded
examples/diffieHellman.jsadded
examples/signing.jsadded
README.mdView
@@ -38,8 +38,11 @@
3838 bls.free(pub)
3939 })
4040 ```
4141
42 +# EXAMPLES
43 +[./examples/](./examples/)
44 +
4245 # API
4346 [./docs/](./docs/index.md)
4447
4548 # BUILDING
build/bls_lib.jsView
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.wasmView
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.ninjaView
@@ -1,7 +1,7 @@
11 cflags = -I../mcl/include/ -I../cybozulib/include -I../bls/include -I../bls
22
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'"
44
55 rule buildExLib
66 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
77
exportedFuncs.jsonView
@@ -111,5 +111,9 @@
111111 "name": "blsSignatureIsEqual",
112112 "exportName": "signatureIsEqual",
113113 "returns": "number",
114114 "args": ["number", "number"]
115 +}, {
116 + "name": "blsDHKeyExchange",
117 + "exportName": "dhKeyExchange",
118 + "args": ["number", "number", "number"]
115119 }]
examples/addingKeys.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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