chia-bls
v1.0.3
Published
A browser friendly implementation of bls-signatures.
Downloads
823
Readme
BLS Signatures
A browser friendly implementation of bls-signatures in TypeScript, based off of the Python implementation.
Introduction
BLS Signatures is a cryptographic library used by projects and blockchains such as the Chia blockchain. 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)
seed
is aUint8Array
.- Returns a
PrivateKey
.
static sign(privateKey, message)
privateKey
is aPrivateKey
.message
is aUint8Array
.- Returns a
JacobianPoint
signature.
static sign_prepend(privateKey, message, prependPublicKey)
privateKey
is aPrivateKey
.message
is aUint8Array
.prependPublicKey
is aJacobianPoint
public key.- Returns a
JacobianPoint
signature.
static verify(publicKey, message, signature)
publicKey
is aJacobianPoint
public key.message
is aUint8Array
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signature is valid.
static aggregate(signatures)
signatures
is anArray<JacobianPoint>
of signatures.- Returns an aggregated
JacobianPoint
.
static aggregateVerify(publicKeys, messages, signature)
publicKeys
is anArray<JacobianPoint>
of public keys.messages
is anArray<Uint8Array>
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signatures are valid.
deriveChildSk(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the hardened child
PrivateKey
at the index.
deriveChildSkUnhardened(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the unhardened child
PrivateKey
at the index.
deriveChildPkUnhardened(publicKey, index)
publicKey
is aJacobianPoint
public key.index
is anumber
.- Returns the unhardened child
JacobianPoint
public 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)
seed
is aUint8Array
.- Returns a
PrivateKey
.
static sign(privateKey, message)
privateKey
is aPrivateKey
.message
is aUint8Array
.- Returns a
JacobianPoint
signature.
static verify(publicKey, message, signature)
publicKey
is aJacobianPoint
public key.message
is aUint8Array
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signature is valid.
static aggregate(signatures)
signatures
is anArray<JacobianPoint>
of signatures.- Returns an aggregated
JacobianPoint
.
static aggregateVerify(publicKeys, messages, signature)
publicKeys
is anArray<JacobianPoint>
of public keys.messages
is anArray<Uint8Array>
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signatures are valid.
deriveChildSk(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the hardened child
PrivateKey
at the index.
deriveChildSkUnhardened(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the unhardened child
PrivateKey
at the index.
deriveChildPkUnhardened(publicKey, index)
publicKey
is aJacobianPoint
public key.index
is anumber
.- Returns the unhardened child
JacobianPoint
public 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)
seed
is aUint8Array
.- Returns a
PrivateKey
.
static sign(privateKey, message)
privateKey
is aPrivateKey
.message
is aUint8Array
.- Returns a
JacobianPoint
signature.
static verify(publicKey, message, signature)
publicKey
is aJacobianPoint
public key.message
is aUint8Array
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signature is valid.
static aggregate(signatures)
signatures
is anArray<JacobianPoint>
of signatures.- Returns an aggregated
JacobianPoint
.
static aggregateVerify(publicKeys, messages, signature)
publicKeys
is anArray<JacobianPoint>
of public keys.messages
is anArray<Uint8Array>
.signature
is aJacobianPoint
signature.- Returns a
boolean
for if the signatures are valid.
static popProve(privateKey)
privateKey
is aPrivateKey
.- Returns a
JacobianPoint
proof of possession.
static popVerify(publicKey, proof)
publicKey
is aJacobianPoint
public key.proof
is aJacobianPoint
proof of possession.- Returns a
boolean
for if the proof of possession is valid.
static fastAggregateVerify(publicKeys, message, signature)
publicKeys
is anArray<JacobianPoint>
of public keys.message
is aUint8Array
.signature
is aJacobianPoint
.- Returns a
boolean
for if the signature is valid.
deriveChildSk(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the hardened child
PrivateKey
at the index.
deriveChildSkUnhardened(privateKey, index)
privateKey
is aPrivateKey
.index
is anumber
.- Returns the unhardened child
PrivateKey
at the index.
deriveChildPkUnhardened(publicKey, index)
publicKey
is aJacobianPoint
public key.index
is anumber
.- Returns the unhardened child
JacobianPoint
public key at the index.
PrivateKey
static fromBytes(bytes)
bytes
is aUint8Array
.- Returns a
PrivateKey
.
static fromHex(hex)
hex
is a hexstring
.- Returns a
PrivateKey
.
static fromSeed(seed)
seed
is aUint8Array
.- Returns a
PrivateKey
derived from the seed.
static fromBigInt(value)
value
is abigint
.- Returns a
PrivateKey
.
static aggregate(privateKeys)
privateKeys
is anArray<PrivateKey>
.- Returns an aggregated
PrivateKey
.
constructor(value)
value
is abigint
.
getG1()
- Returns a derived
JacobianPoint
public key.
toBytes()
- Returns a
Uint8Array
representation.
toHex()
- Returns a hex
string
representation.
toString()
- Returns a
string
representation.
equals(value)
value
is aPrivateKey
.- Returns a
boolean
for 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)
bytes
is aUint8Array
.isExtension
is aboolean
.- Returns a
JacobianPoint
.
static fromHex(hex, isExtension)
hex
is a hexstring
.isExtension
is aboolean
.- Returns a
JacobianPoint
.
static generateG1()
- Returns a
JacobianPoint
G1Element.
static generateG2()
- Returns a
JacobianPoint
G2Element.
static infinityG1()
- Returns a
JacobianPoint
G1Element at infinity.
static infinityG2()
- Returns a
JacobianPoint
G2Element at infinity.
static fromBytesG1(bytes)
bytes
is aUint8Array
.- Returns a
JacobianPoint
G1Element.
static fromBytesG2(bytes)
bytes
is aUint8Array
.- Returns a
JacobianPoint
G2Element.
static fromHexG1(hex)
hex
is a hexstring
.- Returns a
JacobianPoint
G1Element.
static fromHexG2(hex)
hex
is a hexstring
.- Returns a
JacobianPoint
G2Element.
constructor(x, y, z, isInfinity)
x
,y
, andz
areFq
orFq2
.isInfinity
is aboolean
.
isOnCurve()
- Returns a
boolean
for if the point is on curve.
isValid()
- Returns a
boolean
for if the point is valid.
getFingerprint()
- Returns a small
number
fingerprint that identifies the point.
toAffine()
- Returns an
AffinePoint
representation.
toBytes()
- Returns a
Uint8Array
representation.
toHex()
- Returns a hex
string
representation.
toString()
- Returns a
string
representation.
double()
- Returns a
JacobianPoint
that is double the value.
negate()
- Returns a
JacobianPoint
that is the opposite value.
add(value)
value
is aJacobianPoint
.- Returns a
JacobianPoint
that is the sum of the points.
multiply(value)
value
is anFq
orbigint
.- Returns a
JacobianPoint
that is scalar multiplied.
equals(value)
value
is aJacobianPoint
.- Returns a
boolean
for if the values are equal.
clone()
- Returns an exact
JacobianPoint
clone.
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?)
value
is anumber
.size
is anumber
of bytes.endian
is either"big"
or"little"
.signed
is aboolean
, by defaultfalse
.- Returns a
Uint8Array
.
bytesToInt(bytes, endian, signed?)
bytes
is aUint8Array
.endian
is either"big"
or"little"
.signed
is aboolean
, by defaultfalse
.- Returns a
number
.
encodeInt(value)
value
is anumber
.- Returns a
Uint8Array
encoded the way that Chia Network's CLVM does.
decodeInt(bytes)
bytes
is aUint8Array
.- Returns a
number
decoded the way that Chia Network's CLVM does.
bigIntToBytes(value, size, endian, signed?)
value
is abigint
.size
is anumber
of bytes.endian
is either"big"
or"little"
.signed
is aboolean
, by defaultfalse
.- Returns a
Uint8Array
.
bytesToBigInt(bytes, endian, signed?)
bytes
is aUint8Array
.endian
is either"big"
or"little"
.signed
is aboolean
, by defaultfalse
.- Returns a
bigint
.
encodeBigInt(value)
value
is abigint
.- Returns a
Uint8Array
encoded the way that Chia Network's CLVM does.
decodeBigInt(bytes)
bytes
is aUint8Array
.- Returns a
bigint
decoded the way that Chia Network's CLVM does.
concatBytes(...lists)
lists
is anArray<Uint8Array>
.- Returns a concatenated
Uint8Array
.
bytesEqual(a, b)
a
is aUint8Array
.b
is aUint8Array
.- Returns a
boolean
for if the bytes are exactly equal.
toHex(bytes)
bytes
is aUint8Array
.- Returns a hex
string
.
fromHex(hex)
hex
is a hexstring
.- Returns a
Uint8Array
.