### Table of Contents - [onModuleInit](#onmoduleinit) - [MCLBN_CURVE_FP254BNB](#mclbn_curve_fp254bnb) - [MCLBN_CURVE_FP382_1](#mclbn_curve_fp382_1) - [MCLBN_CURVE_FP382_2](#mclbn_curve_fp382_2) - [init](#init) - [secretKey](#secretkey) - [publicKey](#publickey) - [signature](#signature) - [free](#free) - [freeArray](#freearray) - [idSetInt](#idsetint) - [idImportFromInt](#idimportfromint) - [idImport](#idimport) - [sign](#sign) - [verify](#verify) - [publicKeyExport](#publickeyexport) - [secretKeyExport](#secretkeyexport) - [signatureExport](#signatureexport) - [hashToSecretKey](#hashtosecretkey) - [secretKeyDeserialize](#secretkeydeserialize) - [secretKeyImport](#secretkeyimport) - [publicKeyDeserialize](#publickeydeserialize) - [publicKeyImport](#publickeyimport) - [signatureDeserialize](#signaturedeserialize) - [signatureImport](#signatureimport) - [secretKeySetByCSPRNG](#secretkeysetbycsprng) - [getPublicKey](#getpublickey) - [secretKeyRecover](#secretkeyrecover) - [publicKeyRecover](#publickeyrecover) - [signatureRecover](#signaturerecover) - [secretKeyShare](#secretkeyshare) - [publicKeyShare](#publickeyshare) - [publicKeyAdd](#publickeyadd) - [secretKeyAdd](#secretkeyadd) - [publicKeyIsEqual](#publickeyisequal) - [dhKeyExchange](#dhkeyexchange) ## onModuleInit [index.js:14-21](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L14-L21 "Source code on GitHub") Takes a callback that is called once the module is setup **Parameters** - `cb` ## MCLBN_CURVE_FP254BNB [index.js:26-26](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L26-L26 "Source code on GitHub") The FP254BNB curve ## MCLBN_CURVE_FP382_1 [index.js:31-31](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L31-L31 "Source code on GitHub") The FP382_1 curve ## MCLBN_CURVE_FP382_2 [index.js:36-36](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L36-L36 "Source code on GitHub") The FP382_2 curve ## init [index.js:49-51](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L49-L51 "Source code on GitHub") Initializes the library to use a given curve **Parameters** - `curve` **[number](https://developer.mozilla.org/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`) ## secretKey [index.js:57-59](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L57-L59 "Source code on GitHub") Allocates a secret key Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the key ## publicKey [index.js:65-67](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L65-L67 "Source code on GitHub") Allocates a secret key Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the key ## signature [index.js:73-75](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L73-L75 "Source code on GitHub") Allocates a signature Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the pointer to the signature ## free [index.js:80-82](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L80-L82 "Source code on GitHub") Frees a pointer **Parameters** - `x` ## freeArray [index.js:87-89](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L87-L89 "Source code on GitHub") Frees an array of pointers **Parameters** - `a` ## idSetInt [index.js:96-101](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L96-L101 "Source code on GitHub") Creates an ID from an int to use with threshold groups **Parameters** - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key, secret key struct is used to hold the id - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int representing the ID. n cannot be zero. ## idImportFromInt [index.js:108-112](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L108-L112 "Source code on GitHub") Creates an ID from an int and returns a pointer to it **Parameters** - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int representing the ID. n cannot be zero. Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ## idImport [index.js:119-127](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L119-L127 "Source code on GitHub") Creates an ID from an int and returns a pointer to it **Parameters** - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a int representing the ID. n cannot be zero. Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ## sign [index.js:135-135](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L135-L135 "Source code on GitHub") Signs a message **Parameters** - `sig` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the a signature - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key - `msg` **([TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** the message to sign ## verify [index.js:144-144](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L144-L144 "Source code on GitHub") Verifies a signature **Parameters** - `sig` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the a signature - `pk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key - `msg` **([TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** the message that was signed Returns **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** ## publicKeyExport [index.js:151-151](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L151-L151 "Source code on GitHub") Given a pointer to a public key, this returns a 64 byte Int8Array containing the key **Parameters** - `pk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key Returns **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** ## secretKeyExport [index.js:158-158](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L158-L158 "Source code on GitHub") Given a pointer to a secret key, this returns a 32 byte Int8Array containing the key **Parameters** - `pk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key Returns **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** ## signatureExport [index.js:165-165](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L165-L165 "Source code on GitHub") Given a pointer to a signature, this returns a 32 byte Int8Array containing the signature **Parameters** - `pk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the secret key Returns **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** ## hashToSecretKey [index.js:172-172](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L172-L172 "Source code on GitHub") Generates a secret key given a seed phrase **Parameters** - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key - `seed` **([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray))** the seed phrase ## secretKeyDeserialize [index.js:179-179](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L179-L179 "Source code on GitHub") Writes a secretKey to memory **Parameters** - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 32 byte TypedArray ## secretKeyImport [index.js:187-191](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L187-L191 "Source code on GitHub") Writes a secretKey to memory and returns a pointer to it **Parameters** - `buf` - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 32 byte TypedArray Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ## publicKeyDeserialize [index.js:198-198](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L198-L198 "Source code on GitHub") Writes a publicKey to memory **Parameters** - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 64 byte TypedArray ## publicKeyImport [index.js:205-209](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L205-L209 "Source code on GitHub") Writes a publicKey to memory and returns a pointer to it **Parameters** - `buf` - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a 64 byte TypedArray Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ## signatureDeserialize [index.js:216-216](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L216-L216 "Source code on GitHub") Writes a signature to memory **Parameters** - `sig` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a signature - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the signature as a 32 byte TypedArray ## signatureImport [index.js:223-227](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L223-L227 "Source code on GitHub") Writes a signature to memory and returns a pointer to it **Parameters** - `buf` - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the signature as a 32 byte TypedArray Returns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ## secretKeySetByCSPRNG [index.js:233-233](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L233-L233 "Source code on GitHub") Initializes a secret key by a Cryptographically Secure Pseudo Random Number Generator **Parameters** - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a TypedArray ## getPublicKey [index.js:240-240](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L240-L240 "Source code on GitHub") Creates a public key from the secret key **Parameters** - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the public key as a TypedArray - `array` **[TypedArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the secret key as a TypedArray ## secretKeyRecover [index.js:248-248](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L248-L248 "Source code on GitHub") Recovers a secret key for a group given the groups secret keys shares and the groups ids **Parameters** - `sk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key that will be generated - `sksArray` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of pointers to the groups secret key shares. The length of the array should be the threshold number for the group - `idArrah` **[Array](https://developer.mozilla.org/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 ## publicKeyRecover [index.js:256-256](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L256-L256 "Source code on GitHub") Recovers a public key for a group given the groups public keys shares and the groups ids **Parameters** - `pk` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key that will be generated - `pksArray` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/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 - `idArrah` **[Array](https://developer.mozilla.org/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 ## signatureRecover [index.js:264-264](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L264-L264 "Source code on GitHub") Recovers a signature for a group given the groups public keys shares and the groups ids **Parameters** - `sig` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to the signature that will be generated - `sigArray` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of pointers to signature shares. The length of the array should be the threshold number for the group - `idArrah` **[Array](https://developer.mozilla.org/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 ## secretKeyShare [index.js:272-272](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L272-L272 "Source code on GitHub") Creates a secret key share for a group member given the groups members id (which is the secret key) and array of master secret keys **Parameters** - `skshare` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key that will be generated - `msk` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of master secret keys. The number of keys is the threshold of the group. - `id` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the id of the member ## publicKeyShare [index.js:280-280](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L280-L280 "Source code on GitHub") 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 **Parameters** - `pkshare` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key that will be generated - `mpk` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>** an array of master public keys. The number of keys is the threshold of the group. - `id` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the id of the member ## publicKeyAdd [index.js:287-287](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L287-L287 "Source code on GitHub") Takes two publicKeys and adds them together. pubkey1 = pubkey1 + pubkey2 **Parameters** - `pubkey1` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key - `pubkey2` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key ## secretKeyAdd [index.js:294-294](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L294-L294 "Source code on GitHub") Takes two secretKeys and adds them together. seckey1 = seckey1 + seckey2 **Parameters** - `seckey1` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key - `seckey2` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key ## publicKeyIsEqual [index.js:302-302](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L302-L302 "Source code on GitHub") Takes two publicKeys and tests their equality **Parameters** - `pubkey1` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key - `pubkey2` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key return {Boolean} ## dhKeyExchange [index.js:310-310](https://github.com/dfinity/js-bls-lib/blob/3c007f5ed0e57b38cc7df4239d9631d617eef1cc/index.js#L310-L310 "Source code on GitHub") Does Diffie–Hellman key exchange **Parameters** - `sharedSecretKey` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secretKey that will be populated with the shared secret - `secretKey` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a secret key - `pubkey` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** a pointer to a public key