@rigidity/bls-signatures v2.0.5
BLS Signatures
A browser friendly implementation of bls-signatures in TypeScript, based off of the Chia Network implementation written in Python.
Introduction
BLS Signatures is a cryptographic library used by projects and blockchains such as the Chia Network. It is a type of elliptic curve cryptography.
This particular implementation is written with TypeScript, and is not bindings to native code. This allows it to be used in the browser as well. However, if you prefer native bindings, you should check out this library instead.
Usage
In this library, bytes are stored using the Uint8Array typed array class from the ECMAScript specification for multiplatform support.
By design, the functions and methods exposed by this library are synchronous and everything is exported for ease of use.
Since it is written in TypeScript, there are built-in typings for IntelliSense. The following documentation is non-exhaustive, but should be enough for most uses.
Documentation
AugSchemeMPL
This scheme is from the BLS spec in the IETF. AugSchemeMPL is used by the Chia Network and is more secure but less efficient.
static keygen(seed)
seedis aUint8Array.- Returns a
PrivateKey.
static sign(privateKey, message)
privateKeyis aPrivateKey.messageis aUint8Array.- Returns a
JacobianPointsignature.
static verify(publicKey, message, signature)
publicKeyis aJacobianPointpublic key.messageis aUint8Array.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signature is valid.
static aggregate(signatures)
signaturesis anArray<JacobianPoint>of signatures.- Returns an aggregated
JacobianPoint.
static aggregateVerify(publicKeys, messages, signature)
publicKeysis anArray<JacobianPoint>of public keys.messagesis anArray<Uint8Array>.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signatures are valid.
deriveChildSk(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the hardened child
PrivateKeyat the index.
deriveChildSkUnhardened(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the unhardened child
PrivateKeyat the index.
deriveChildPkUnhardened(publicKey, index)
publicKeyis aJacobianPointpublic key.indexis anumber.- Returns the unhardened child
JacobianPointpublic key at the index.
BasicSchemeMPL
This scheme is from the BLS spec in the IETF. BasicSchemeMPL is very fast, but not as secure as the other schemes.
static keygen(seed)
seedis aUint8Array.- Returns a
PrivateKey.
static sign(privateKey, message)
privateKeyis aPrivateKey.messageis aUint8Array.- Returns a
JacobianPointsignature.
static verify(publicKey, message, signature)
publicKeyis aJacobianPointpublic key.messageis aUint8Array.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signature is valid.
static aggregate(signatures)
signaturesis anArray<JacobianPoint>of signatures.- Returns an aggregated
JacobianPoint.
static aggregateVerify(publicKeys, messages, signature)
publicKeysis anArray<JacobianPoint>of public keys.messagesis anArray<Uint8Array>.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signatures are valid.
deriveChildSk(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the hardened child
PrivateKeyat the index.
deriveChildSkUnhardened(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the unhardened child
PrivateKeyat the index.
deriveChildPkUnhardened(publicKey, index)
publicKeyis aJacobianPointpublic key.indexis anumber.- Returns the unhardened child
JacobianPointpublic key at the index.
PopSchemeMPL
This scheme is from the BLS spec in the IETF. PopSchemeMPL is secure, but it requires registration, for example with Ethereum 2.0 Proof of Stake.
static keygen(seed)
seedis aUint8Array.- Returns a
PrivateKey.
static sign(privateKey, message)
privateKeyis aPrivateKey.messageis aUint8Array.- Returns a
JacobianPointsignature.
static verify(publicKey, message, signature)
publicKeyis aJacobianPointpublic key.messageis aUint8Array.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signature is valid.
static aggregate(signatures)
signaturesis anArray<JacobianPoint>of signatures.- Returns an aggregated
JacobianPoint.
static aggregateVerify(publicKeys, messages, signature)
publicKeysis anArray<JacobianPoint>of public keys.messagesis anArray<Uint8Array>.signatureis aJacobianPointsignature.- Returns a
booleanfor if the signatures are valid.
static popProve(privateKey)
privateKeyis aPrivateKey.- Returns a
JacobianPointproof of possession.
static popVerify(publicKey, proof)
publicKeyis aJacobianPointpublic key.proofis aJacobianPointproof of possession.- Returns a
booleanfor if the proof of possession is valid.
static fastAggregateVerify(publicKeys, message, signature)
publicKeysis anArray<JacobianPoint>of public keys.messageis aUint8Array.signatureis aJacobianPoint.- Returns a
booleanfor if the signature is valid.
deriveChildSk(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the hardened child
PrivateKeyat the index.
deriveChildSkUnhardened(privateKey, index)
privateKeyis aPrivateKey.indexis anumber.- Returns the unhardened child
PrivateKeyat the index.
deriveChildPkUnhardened(publicKey, index)
publicKeyis aJacobianPointpublic key.indexis anumber.- Returns the unhardened child
JacobianPointpublic key at the index.
PrivateKey
static fromBytes(bytes)
bytesis aUint8Array.- Returns a
PrivateKey.
static fromHex(hex)
hexis a hexstring.- Returns a
PrivateKey.
static fromSeed(seed)
seedis aUint8Array.- Returns a
PrivateKeyderived from the seed.
static fromBigInt(value)
valueis abigint.- Returns a
PrivateKey.
static aggregate(privateKeys)
privateKeysis anArray<PrivateKey>.- Returns an aggregated
PrivateKey.
constructor(value)
valueis abigint.
getG1()
- Returns a derived
JacobianPointpublic key.
toBytes()
- Returns a
Uint8Arrayrepresentation.
toHex()
- Returns a hex
stringrepresentation.
toString()
- Returns a
stringrepresentation.
equals(value)
valueis aPrivateKey.- Returns a
booleanfor if the values are equal.
JacobianPoint
This represents both G1Element and G2Element values, which are used for public keys and signatures, respectively.
static fromBytes(bytes, isExtension)
bytesis aUint8Array.isExtensionis aboolean.- Returns a
JacobianPoint.
static fromHex(hex, isExtension)
hexis a hexstring.isExtensionis aboolean.- Returns a
JacobianPoint.
static generateG1()
- Returns a
JacobianPointG1Element.
static generateG2()
- Returns a
JacobianPointG2Element.
static infinityG1()
- Returns a
JacobianPointG1Element at infinity.
static infinityG2()
- Returns a
JacobianPointG2Element at infinity.
static fromBytesG1(bytes)
bytesis aUint8Array.- Returns a
JacobianPointG1Element.
static fromBytesG2(bytes)
bytesis aUint8Array.- Returns a
JacobianPointG2Element.
static fromHexG1(hex)
hexis a hexstring.- Returns a
JacobianPointG1Element.
static fromHexG2(hex)
hexis a hexstring.- Returns a
JacobianPointG2Element.
constructor(x, y, z, isInfinity)
x,y, andzareFqorFq2.isInfinityis aboolean.
isOnCurve()
- Returns a
booleanfor if the point is on curve.
isValid()
- Returns a
booleanfor if the point is valid.
getFingerprint()
- Returns a small
numberfingerprint that identifies the point.
toAffine()
- Returns an
AffinePointrepresentation.
toBytes()
- Returns a
Uint8Arrayrepresentation.
toHex()
- Returns a hex
stringrepresentation.
toString()
- Returns a
stringrepresentation.
double()
- Returns a
JacobianPointthat is double the value.
negate()
- Returns a
JacobianPointthat is the opposite value.
add(value)
valueis aJacobianPoint.- Returns a
JacobianPointthat is the sum of the points.
multiply(value)
valueis anFqorbigint.- Returns a
JacobianPointthat is scalar multiplied.
equals(value)
valueis aJacobianPoint.- Returns a
booleanfor if the values are equal.
clone()
- Returns an exact
JacobianPointclone.
Byte Utils
This is a collection of byte utils that can be directly imported and called, and are not part of a class.
intToBytes(value, size, endian, signed?)
valueis anumber.sizeis anumberof bytes.endianis either"big"or"little".signedis aboolean, by defaultfalse.- Returns a
Uint8Array.
bytesToInt(bytes, endian, signed?)
bytesis aUint8Array.endianis either"big"or"little".signedis aboolean, by defaultfalse.- Returns a
number.
encodeInt(value)
valueis anumber.- Returns a
Uint8Arrayencoded the way that Chia Network's CLVM does.
decodeInt(bytes)
bytesis aUint8Array.- Returns a
numberdecoded the way that Chia Network's CLVM does.
bigIntToBytes(value, size, endian, signed?)
valueis abigint.sizeis anumberof bytes.endianis either"big"or"little".signedis aboolean, by defaultfalse.- Returns a
Uint8Array.
bytesToBigInt(bytes, endian, signed?)
bytesis aUint8Array.endianis either"big"or"little".signedis aboolean, by defaultfalse.- Returns a
bigint.
encodeBigInt(value)
valueis abigint.- Returns a
Uint8Arrayencoded the way that Chia Network's CLVM does.
decodeBigInt(bytes)
bytesis aUint8Array.- Returns a
bigintdecoded the way that Chia Network's CLVM does.
concatBytes(...lists)
listsis anArray<Uint8Array>.- Returns a concatenated
Uint8Array.
bytesEqual(a, b)
ais aUint8Array.bis aUint8Array.- Returns a
booleanfor if the bytes are exactly equal.
toHex(bytes)
bytesis aUint8Array.- Returns a hex
string.
fromHex(hex)
hexis a hexstring.- Returns a
Uint8Array.
