git ssb

0+

wanderer🌟 / bls-lib



Commit d5061208288fe0b3090a797ef7157812f835d6bf

Merge pull request #5 from dfinity/returnBool

make some funcs return bool
wanderer authored on 11/27/2017, 4:32:12 PM
GitHub committed on 11/27/2017, 4:32:12 PM
Parent: 0dd1b30801413a39f947d8cb8f38d0f2917f252f
Parent: 3c457e85e4c76d79aaf2696a662063e81744a3e7

Files changed

docs/index.mdchanged
index.jschanged
package-lock.jsonchanged
package.jsonchanged
tests/index.jschanged
docs/index.mdView
@@ -13,8 +13,9 @@
1313 - [free](#free)
1414 - [freeArray](#freearray)
1515 - [idSetInt](#idsetint)
1616 - [idImportFromInt](#idimportfromint)
17 +- [idImport](#idimport)
1718 - [sign](#sign)
1819 - [verify](#verify)
1920 - [publicKeyExport](#publickeyexport)
2021 - [secretKeyExport](#secretkeyexport)
@@ -25,17 +26,23 @@
2526 - [publicKeyDeserialize](#publickeydeserialize)
2627 - [publicKeyImport](#publickeyimport)
2728 - [signatureDeserialize](#signaturedeserialize)
2829 - [signatureImport](#signatureimport)
30 +- [secretKeySetByCSPRNG](#secretkeysetbycsprng)
31 +- [getPublicKey](#getpublickey)
2932 - [secretKeyRecover](#secretkeyrecover)
3033 - [publicKeyRecover](#publickeyrecover)
3134 - [signatureRecover](#signaturerecover)
3235 - [secretKeyShare](#secretkeyshare)
3336 - [publicKeyShare](#publickeyshare)
37 +- [publicKeyAdd](#publickeyadd)
38 +- [secretKeyAdd](#secretkeyadd)
39 +- [publicKeyIsEqual](#publickeyisequal)
40 +- [dhKeyExchange](#dhkeyexchange)
3441
3542 ## onModuleInit
3643
37-[index.js:14-21](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L14-L21 "Source code on GitHub")
44 +[index.js:14-21](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L14-L21 "Source code on GitHub")
3845
3946 takes a callback that is called once the module is setup
4047
4148 **Parameters**
@@ -43,27 +50,27 @@
4350 - `cb`
4451
4552 ## MCLBN_CURVE_FP254BNB
4653
47-[index.js:26-26](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L26-L26 "Source code on GitHub")
54 +[index.js:26-26](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L26-L26 "Source code on GitHub")
4855
4956 the FP254BNB curve
5057
5158 ## MCLBN_CURVE_FP382_1
5259
53-[index.js:31-31](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L31-L31 "Source code on GitHub")
60 +[index.js:31-31](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L31-L31 "Source code on GitHub")
5461
5562 the FP382_1 curve
5663
5764 ## MCLBN_CURVE_FP382_2
5865
59-[index.js:36-36](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L36-L36 "Source code on GitHub")
66 +[index.js:36-36](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L36-L36 "Source code on GitHub")
6067
6168 the FP382_2 curve
6269
6370 ## init
6471
65-[index.js:53-55](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L53-L55 "Source code on GitHub")
72 +[index.js:49-51](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L49-L51 "Source code on GitHub")
6673
6774 intailizes the libary to use a given curve
6875
6976 **Parameters**
@@ -71,33 +78,33 @@
7178 - `curve` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the curves that can be used are MCLBN_CURVE_FP254BNB, MCLBN_CURVE_FP382_1 or MCLBN_CURVE_FP382_2 (optional, default `exports.MCLBN_CURVE_FP254BNB`)
7279
7380 ## secretKey
7481
75-[index.js:61-63](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L61-L63 "Source code on GitHub")
82 +[index.js:57-59](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L57-L59 "Source code on GitHub")
7683
7784 allocates a secret key
7885
7986 Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the key
8087
8188 ## publicKey
8289
83-[index.js:69-71](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L69-L71 "Source code on GitHub")
90 +[index.js:65-67](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L65-L67 "Source code on GitHub")
8491
8592 allocates a secret key
8693
8794 Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the key
8895
8996 ## signature
9097
91-[index.js:77-79](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L77-L79 "Source code on GitHub")
98 +[index.js:73-75](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L73-L75 "Source code on GitHub")
9299
93100 allocates a signature
94101
95102 Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the signture
96103
97104 ## free
98105
99-[index.js:84-86](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L84-L86 "Source code on GitHub")
106 +[index.js:80-82](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L80-L82 "Source code on GitHub")
100107
101108 frees a pointer
102109
103110 **Parameters**
@@ -105,9 +112,9 @@
105112 - `x`
106113
107114 ## freeArray
108115
109-[index.js:91-93](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L91-L93 "Source code on GitHub")
116 +[index.js:87-89](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L87-L89 "Source code on GitHub")
110117
111118 frees an array of pointers
112119
113120 **Parameters**
@@ -115,9 +122,9 @@
115122 - `a`
116123
117124 ## idSetInt
118125
119-[index.js:100-105](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L100-L105 "Source code on GitHub")
126 +[index.js:96-101](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L96-L101 "Source code on GitHub")
120127
121128 creates an ID from an int to use in with threshold groups
122129
123130 **Parameters**
@@ -126,9 +133,9 @@
126133 - `n` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int repsenting the ID. n cannot be zero.
127134
128135 ## idImportFromInt
129136
130-[index.js:112-116](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L112-L116 "Source code on GitHub")
137 +[index.js:108-112](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L108-L112 "Source code on GitHub")
131138
132139 creates an ID from an int and returns a pointer to it
133140
134141 **Parameters**
@@ -136,11 +143,23 @@
136143 - `n` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int repsenting the ID. n cannot be zero.
137144
138145 Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
139146
147 +## idImport
148 +
149 +[index.js:119-127](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L119-L127 "Source code on GitHub")
150 +
151 +creates an ID from an int and returns a pointer to it
152 +
153 +**Parameters**
154 +
155 +- `n` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int repsenting the ID. n cannot be zero.
156 +
157 +Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
158 +
140159 ## sign
141160
142-[index.js:124-124](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L124-L124 "Source code on GitHub")
161 +[index.js:135-135](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L135-L135 "Source code on GitHub")
143162
144163 signs a message
145164
146165 **Parameters**
@@ -150,9 +169,9 @@
150169 - `msg` **([TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** the message to sign
151170
152171 ## verify
153172
154-[index.js:132-132](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L132-L132 "Source code on GitHub")
173 +[index.js:144-144](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L144-L144 "Source code on GitHub")
155174
156175 verifies a signature
157176
158177 **Parameters**
@@ -160,11 +179,13 @@
160179 - `sig` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the a signature
161180 - `pk` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key
162181 - `msg` **([TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** the message that was signed
163182
183 +Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
184 +
164185 ## publicKeyExport
165186
166-[index.js:139-139](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L139-L139 "Source code on GitHub")
187 +[index.js:151-151](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L151-L151 "Source code on GitHub")
167188
168189 given a pointer to a public key this returns 64 byte Int8Array containing the key
169190
170191 **Parameters**
@@ -174,9 +195,9 @@
174195 Returns **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**
175196
176197 ## secretKeyExport
177198
178-[index.js:146-146](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L146-L146 "Source code on GitHub")
199 +[index.js:158-158](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L158-L158 "Source code on GitHub")
179200
180201 given a pointer to a secret key this returns 32 byte Int8Array containing the key
181202
182203 **Parameters**
@@ -186,9 +207,9 @@
186207 Returns **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**
187208
188209 ## signatureExport
189210
190-[index.js:153-153](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L153-L153 "Source code on GitHub")
211 +[index.js:165-165](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L165-L165 "Source code on GitHub")
191212
192213 given a pointer to a signature this returns 32 byte Int8Array containing the signature
193214
194215 **Parameters**
@@ -198,9 +219,9 @@
198219 Returns **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**
199220
200221 ## hashToSecretKey
201222
202-[index.js:160-160](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L160-L160 "Source code on GitHub")
223 +[index.js:172-172](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L172-L172 "Source code on GitHub")
203224
204225 generates a secret key given a seed phrase.
205226
206227 **Parameters**
@@ -209,9 +230,9 @@
209230 - `seed` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray))** the seed phrase
210231
211232 ## secretKeyDeserialize
212233
213-[index.js:167-167](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L167-L167 "Source code on GitHub")
234 +[index.js:179-179](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L179-L179 "Source code on GitHub")
214235
215236 write a secretKey to memory
216237
217238 **Parameters**
@@ -220,9 +241,9 @@
220241 - `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 32 byte TypedArray
221242
222243 ## secretKeyImport
223244
224-[index.js:175-179](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L175-L179 "Source code on GitHub")
245 +[index.js:187-191](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L187-L191 "Source code on GitHub")
225246
226247 write a secretKey to memory and returns a pointer to it
227248
228249 **Parameters**
@@ -234,9 +255,9 @@
234255 Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
235256
236257 ## publicKeyDeserialize
237258
238-[index.js:186-186](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L186-L186 "Source code on GitHub")
259 +[index.js:198-198](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L198-L198 "Source code on GitHub")
239260
240261 write a publicKey to memory
241262
242263 **Parameters**
@@ -245,9 +266,9 @@
245266 - `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 64 byte TypedArray
246267
247268 ## publicKeyImport
248269
249-[index.js:193-197](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L193-L197 "Source code on GitHub")
270 +[index.js:205-209](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L205-L209 "Source code on GitHub")
250271
251272 write a publicKey to memory and returns a pointer to it
252273
253274 **Parameters**
@@ -258,9 +279,9 @@
258279 Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
259280
260281 ## signatureDeserialize
261282
262-[index.js:204-204](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L204-L204 "Source code on GitHub")
283 +[index.js:216-216](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L216-L216 "Source code on GitHub")
263284
264285 write a signature to memory
265286
266287 **Parameters**
@@ -269,9 +290,9 @@
269290 - `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the signature as a 32 byte TypedArray
270291
271292 ## signatureImport
272293
273-[index.js:211-215](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L211-L215 "Source code on GitHub")
294 +[index.js:223-227](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L223-L227 "Source code on GitHub")
274295
275296 write a signature to memory and returns a pointer to it
276297
277298 **Parameters**
@@ -280,11 +301,32 @@
280301 - `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the signature as a 32 byte TypedArray
281302
282303 Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)**
283304
305 +## secretKeySetByCSPRNG
306 +
307 +[index.js:233-233](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L233-L233 "Source code on GitHub")
308 +
309 +Initialize a secret key by a Cryptographically Secure Pseudo Random Number Generator
310 +
311 +**Parameters**
312 +
313 +- `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a TypedArray
314 +
315 +## getPublicKey
316 +
317 +[index.js:240-240](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L240-L240 "Source code on GitHub")
318 +
319 +Create a public key from the secret key
320 +
321 +**Parameters**
322 +
323 +- `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the public key as a TypedArray
324 +- `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a TypedArray
325 +
284326 ## secretKeyRecover
285327
286-[index.js:223-223](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L223-L223 "Source code on GitHub")
328 +[index.js:248-248](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L248-L248 "Source code on GitHub")
287329
288330 Recovers a secret key for a group given the groups secret keys shares and the groups ids
289331
290332 **Parameters**
@@ -294,21 +336,21 @@
294336 - `idArrah` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<numbers>** an array of pointers to ids in the groups. The length of the array should be the threshold number for the group
295337
296338 ## publicKeyRecover
297339
298-[index.js:231-231](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L231-L231 "Source code on GitHub")
340 +[index.js:256-256](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L256-L256 "Source code on GitHub")
299341
300342 Recovers a public key for a group given the groups public keys shares and the groups ids
301343
302344 **Parameters**
303345
304-- `pk` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key that will be generated
346 +- `pk` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key that will be generated
305347 - `pksArray` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of pointers to the groups public key shares. The length of the array should be the threshold number for the group
306348 - `idArrah` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<numbers>** an array of pointers to ids in the groups. The length of the array should be the threshold number for the group
307349
308350 ## signatureRecover
309351
310-[index.js:239-239](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L239-L239 "Source code on GitHub")
352 +[index.js:264-264](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L264-L264 "Source code on GitHub")
311353
312354 Recovers a signature for a group given the groups public keys shares and the groups ids
313355
314356 **Parameters**
@@ -318,9 +360,9 @@
318360 - `idArrah` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<numbers>** an array of pointers to ids in the groups. The length of the array should be the threshold number for the group
319361
320362 ## secretKeyShare
321363
322-[index.js:247-247](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L247-L247 "Source code on GitHub")
364 +[index.js:272-272](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L272-L272 "Source code on GitHub")
323365
324366 Creates a secket key share for a group member given the groups members id (which is a the secret key) and array of master secret keys
325367
326368 **Parameters**
@@ -330,13 +372,59 @@
330372 - `id` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the id of the member
331373
332374 ## publicKeyShare
333375
334-[index.js:255-255](https://github.com/wanderer/bls-lib/blob/63a2cdafe199f883855c63bd361a125a6b8b464a/index.js#L255-L255 "Source code on GitHub")
376 +[index.js:280-280](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L280-L280 "Source code on GitHub")
335377
336378 Creates a public key share for a group member given the groups members id (which is a the secret key) and array of master public keys
337379
338380 **Parameters**
339381
340382 - `pkshare` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key that will be generated
341383 - `mpk` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of master public keys. The number of keys is the threshould of the group.
342384 - `id` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the id of the member
385 +
386 +## publicKeyAdd
387 +
388 +[index.js:287-287](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L287-L287 "Source code on GitHub")
389 +
390 +Take two publicKeys and adds them together. pubkey1 = pubkey1 + pubkey2
391 +
392 +**Parameters**
393 +
394 +- `pubkey1` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key
395 +- `pubkey2` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key
396 +
397 +## secretKeyAdd
398 +
399 +[index.js:294-294](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L294-L294 "Source code on GitHub")
400 +
401 +Take two secretKeys and adds them together. seckey1 = seckey1 + seckey2
402 +
403 +**Parameters**
404 +
405 +- `seckey1` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key
406 +- `seckey2` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key
407 +
408 +## publicKeyIsEqual
409 +
410 +[index.js:302-302](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L302-L302 "Source code on GitHub")
411 +
412 +Take two publicKeys and tests thier equality
413 +
414 +**Parameters**
415 +
416 +- `pubkey1` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key
417 +- `pubkey2` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key
418 + return {Boolean}
419 +
420 +## dhKeyExchange
421 +
422 +[index.js:310-310](https://github.com/dfinity/bls-lib/blob/2b6104bd4d6a111c264a5b60ec590f39c84b3da0/index.js#L310-L310 "Source code on GitHub")
423 +
424 +Does Diffie–Hellman key exchange
425 +
426 +**Parameters**
427 +
428 +- `sharedSecretKey` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secretKey that will be populated with the shared secret
429 +- `secretKey` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key
430 +- `pubkey` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key
index.jsView
@@ -1,12 +1,13 @@
11 const nop = require('nop')
2 +const Buffer = require('safe-buffer').Buffer
23 const mod = require('./build/bls_lib.js')
34
4-exports.mod = mod
5-
65 let init = false
76 let initCb = nop
87
8 +exports.mod = mod
9 +
910 /**
1011 * takes a callback that is called once the module is setup
1112 * @params {Function} cb - the callback tobe called once the module is intailized
1213 */
@@ -137,10 +138,11 @@
137138 * verifies a signature
138139 * @param {number} sig - a pointer to the a signature
139140 * @param {number} pk - a pointer to the secret key
140141 * @param {TypedArray|String} msg - the message that was signed
142 + * @returns {Boolean}
141143 */
142- exports.verify = wrapInput(mod._blsVerify, true)
144 + exports.verify = returnBool(wrapInput(mod._blsVerify))
143145
144146 /**
145147 * given a pointer to a public key this returns 64 byte Int8Array containing the key
146148 * @param {number} pk - a pointer to the secret key
@@ -166,16 +168,16 @@
166168 * generates a secret key given a seed phrase.
167169 * @param {number} sk - a pointer to a secret key
168170 * @param {String|TypedArray} seed - the seed phrase
169171 */
170- exports.hashToSecretKey = wrapInput(mod._blsHashToSecretKey, true)
172 + exports.hashToSecretKey = wrapInput(mod._blsHashToSecretKey)
171173
172174 /**
173175 * write a secretKey to memory
174176 * @param {number} sk - a pointer to a secret key
175177 * @param {TypedArray} array - the secret key as a 32 byte TypedArray
176178 */
177- exports.secretKeyDeserialize = wrapInput(mod._blsSecretKeyDeserialize, true)
179 + exports.secretKeyDeserialize = wrapInput(mod._blsSecretKeyDeserialize)
178180
179181 /**
180182 * write a secretKey to memory and returns a pointer to it
181183 * @param {number} sk - a pointer to a secret key
@@ -192,9 +194,9 @@
192194 * write a publicKey to memory
193195 * @param {number} sk - a pointer to a public key
194196 * @param {TypedArray} array - the secret key as a 64 byte TypedArray
195197 */
196- exports.publicKeyDeserialize = wrapInput(mod._blsPublicKeyDeserialize, true)
198 + exports.publicKeyDeserialize = wrapInput(mod._blsPublicKeyDeserialize)
197199
198200 /**
199201 * write a publicKey to memory and returns a pointer to it
200202 * @param {TypedArray} array - the secret key as a 64 byte TypedArray
@@ -276,11 +278,47 @@
276278 * @param {number} id - the id of the member
277279 */
278280 exports.publicKeyShare = wrapKeyShare(mod._blsPublicKeyShare, G2_SIZE)
279281
282 + /**
283 + * Take two publicKeys and adds them together. pubkey1 = pubkey1 + pubkey2
284 + * @param {number} pubkey1 - a pointer to a public key
285 + * @param {number} pubkey2 - a pointer to a public key
286 + */
287 + exports.publicKeyAdd = mod._blsPublicKeyAdd
288 +
289 + /**
290 + * Take two secretKeys and adds them together. seckey1 = seckey1 + seckey2
291 + * @param {number} seckey1 - a pointer to a secret key
292 + * @param {number} seckey2 - a pointer to a secret key
293 + */
294 + exports.secretKeyAdd = mod._blsSecretKeyAdd
295 +
296 + /**
297 + * Take two publicKeys and tests thier equality
298 + * @param {number} pubkey1 - a pointer to a public key
299 + * @param {number} pubkey2 - a pointer to a public key
300 + * return {Boolean}
301 + */
302 + exports.publicKeyIsEqual = returnBool(mod._blsPublicKeyIsEqual)
303 +
304 + /**
305 + * Does Diffie–Hellman key exchange
306 + * @param {number} sharedSecretKey - a pointer to a secretKey that will be populated with the shared secret
307 + * @param {number} secretKey - a pointer to a secret key
308 + * @param {number} pubkey - a pointer to a public key
309 + */
310 + exports.dhKeyExchange = mod._blsDHKeyExchange
311 +
280312 initCb()
281313 }
282314
315 +function returnBool (func) {
316 + return function () {
317 + return func.apply(null, arguments) === 1
318 + }
319 +}
320 +
283321 function wrapInput (func) {
284322 return function () {
285323 const args = [...arguments]
286324 let buf = args.pop()
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 320311 bytes
New file size: 296056 bytes
package.jsonView
@@ -14,26 +14,29 @@
1414 "bls",
1515 "wasm",
1616 "crypto"
1717 ],
18- "author": "mjbecze <mjbecze@gmail.com>",
18 + "contributors": [
19 + "MITSUNARI Shigeo <herumi@nifty.com>",
20 + "mjbecze <mjbecze@gmail.com>"
21 + ],
1922 "license": "MPL-2.0",
2023 "devDependencies": {
2124 "array-shuffle": "^1.0.1",
2225 "coveralls": "^3.0.0",
23- "documentation": "^5.2.0",
24- "nyc": "^11.2.1",
26 + "documentation": "^5.3.3",
27 + "nyc": "^11.3.0",
2528 "standard": "^10.0.0",
2629 "tape": "^4.0.3"
2730 },
2831 "repository": {
2932 "type": "git",
30- "url": "git@github.com:wanderer/bls-lib.git"
33 + "url": "git@github.com:dfinity/js-bls-lib.git"
3134 },
3235 "bugs": {
33- "url": "https://github.com/wanderer/bls-lib/issues"
36 + "url": "https://github.com/dfinity/js-bls-lib/issues"
3437 },
35- "homepage": "https://github.com/wanderer/bls-lib",
38 + "homepage": "https://github.com/dfinity/js-bls-lib",
3639 "standard": {
3740 "ignore": [
3841 "/mcl/",
3942 "/build/",
@@ -46,7 +49,8 @@
4649 "build"
4750 ]
4851 },
4952 "dependencies": {
50- "nop": "^1.0.0"
53 + "nop": "^1.0.0",
54 + "safe-buffer": "^5.1.1"
5155 }
5256 }
tests/index.jsView
@@ -21,9 +21,9 @@
2121 const msg = 'test'
2222 bls.sign(sig, sec, msg)
2323
2424 const v = bls.verify(sig, pub, msg)
25- t.equals(v, 1)
25 + t.equals(v, true)
2626 })
2727 })
2828
2929 tape('verify', t => {
@@ -38,9 +38,9 @@
3838
3939 bls.getPublicKey(pub, sec)
4040
4141 const v = bls.verify(sig, pub, msg)
42- t.equals(v, 1)
42 + t.equals(v, true)
4343
4444 bls.free(sec)
4545 bls.free(sig)
4646 bls.free(pub)
@@ -78,9 +78,9 @@
7878 sig = bls.signatureImport(sigArray)
7979 pub = bls.publicKeyImport(pubArray)
8080
8181 const v = bls.verify(sig, pub, msg)
82- t.equals(v, 1)
82 + t.equals(v, true)
8383
8484 bls.free(sec)
8585 bls.free(sig)
8686 bls.free(pub)
@@ -144,9 +144,9 @@
144144
145145 sigs.push(sig)
146146 const r = bls.verify(sig, pk, msg)
147147
148- t.equals(r, 1, 'should verify')
148 + t.equals(r, true, 'should verify')
149149 }
150150
151151 // recover
152152 const subIds = []

Built with git-ssb-web