Skip to content

BubbleTrouble14/react-native-bls-signatures

Repository files navigation

React Native BLS Signatures

This is a React Native wrapper for BLS Signatures that offers quick and direct bindings to the native C++ library, accessible through a user-friendly TypeScript API.

Installation

To use this library in your React Native project run the following command:

yarn add react-native-bls-signatures

or

npm install react-native-bls-signatures

Example

const seed = Uint8Array.from([
  0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192, 19, 18, 12, 89, 6, 220, 18, 102,
  58, 209, 82, 12, 62, 89, 110, 182, 9, 44, 20, 254, 22,
]);

const sk = AugSchemeMPL.keyGen(seed);
const pk = sk.getG1();

const message = Uint8Array.from([1, 2, 3, 4, 5]);
const signature = AugSchemeMPL.sign(sk, message);

const ok = AugSchemeMPL.verify(pk, message, signature);
console.log(ok); // true

Documentation

AugSchemeMPL

Static Methods:

  • skToG1(sk: PrivateKey) -> G1Element
  • keyGen(seed: Uint8Array) -> PrivateKey
  • sign(sk: PrivateKey, msg: Uint8Array) -> G2Element
  • signPrepend(sk: PrivateKey, msg: Uint8Array, prependPk: G1Element) -> G2Element
  • verify(pk: G1Element, msg: Uint8Array, sig: G2Element) -> boolean
  • aggregate(g2Elements: G2Element[]) -> G2Element
  • aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element) -> boolean
  • deriveChildSk(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildSkUnhardened(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildPkUnhardened(pk: G1Element, index: number) -> G1Element

BasicSchemeMPL

Static Methods:

  • skToG1(sk: PrivateKey) -> G1Element
  • keyGen(seed: Uint8Array) -> PrivateKey
  • sign(sk: PrivateKey, msg: Uint8Array) -> G2Element
  • verify(pk: G1Element, msg: Uint8Array, sig: G2Element) -> boolean
  • aggregate(g2Elements: G2Element[]) -> G2Element
  • aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element) -> boolean
  • deriveChildSk(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildSkUnhardened(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildPkUnhardened(pk: G1Element, index: number) -> G1Element

PopSchemeMPL

Static Methods:

  • skToG1(sk: PrivateKey) -> G1Element
  • keyGen(seed: Uint8Array) -> PrivateKey
  • sign(sk: PrivateKey, msg: Uint8Array) -> G2Element
  • verify(pk: G1Element, msg: Uint8Array, sig: G2Element) -> boolean
  • aggregate(g2Elements: G2Element[]) -> G2Element
  • aggregateVerify(pks: G1Element[], msgs: Uint8Array[], sig: G2Element) -> boolean
  • deriveChildSk(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildSkUnhardened(sk: PrivateKey, index: number) -> PrivateKey
  • deriveChildPkUnhardened(pk: G1Element, index: number) -> G1Element
  • popVerify(pk: G1Element, sigProof: G2Element) -> boolean
  • popProve(sk: PrivateKey) -> G2Element
  • fastAggregateVerify(pks: G1Element[], msg: Uint8Array, sig: G2Element) -> boolean

PrivateKey

Static Methods:

  • fromBytes(bytes: Uint8Array, modOrder?: boolean) -> PrivateKey
  • fromHex(hex: string) -> PrivateKey
  • aggregate(pks: PrivateKey[]) -> PrivateKey

Methods:

  • toBytes() -> Uint8Array
  • toHex() -> string
  • toString() -> string
  • equals(sk: PrivateKey) -> boolean
  • getG1() -> G1Element
  • getG2() -> G2Element

G1Element

Static Methods:

  • fromBytes(bytes: Uint8Array) -> G1Element
  • fromHex(hex: string) -> G1Element

Methods:

  • toBytes() -> Uint8Array
  • toHex() -> string
  • getFingerPrint() -> number
  • add(g1e: G1Element) -> G1Element
  • negate() -> G1Element
  • equals(g1e: G1Element) -> boolean

G2Element

Static Methods:

  • fromBytes(bytes: Uint8Array) -> G2Element
  • fromHex(hex: string) -> G2Element

Methods:

  • toBytes() -> Uint8Array
  • toHex() -> string
  • add(g2e: G2Element) -> G2Element
  • negate() -> G2Element
  • equals(g2e: G2Element) -> boolean

Utils

  • hash256(msg: Uint8Array) -> Uint8Array
  • toHex(bytes: Uint8Array) -> string
  • fromHex(hex: string) -> Uint8Array
  • getRandomSeed() -> Uint8Array (Used for testing)

Libsodium license

The libsodium static library is licensed under the ISC license which requires the following copyright notice.

ISC License

Copyright (c) 2013-2020 Frank Denis <j at pureftpd dot org>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

BLST license

BLST is used with the Apache 2.0 license

Resources