@tevm/voltaire / crypto/Bls12381
crypto/Bls12381
Namespaces
Classes
Bls12381Error
Defined in: src/crypto/Bls12381/errors.js:12 Base error class for BLS12-381 operationsExtends
Error
Extended by
InvalidPointErrorInvalidSubgroupErrorInvalidScalarErrorInvalidFieldElementErrorPairingErrorSignatureError
Constructors
Constructor
new Bls12381Error(Defined in: src/crypto/Bls12381/errors.js:16message):Bls12381Error
Parameters
message
string
Returns
Bls12381Error
Overrides
Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:18
Inherited from
Error.name
InvalidFieldElementError
Defined in: src/crypto/Bls12381/errors.js:58 Error thrown when field element is invalidExtends
Constructors
Constructor
new InvalidFieldElementError(Defined in: src/crypto/Bls12381/errors.js:62reason?):InvalidFieldElementError
Parameters
reason?
string
Returns
InvalidFieldElementError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:64
Inherited from
Bls12381Error.name
InvalidPointError
Defined in: src/crypto/Bls12381/errors.js:25 Error thrown when a point is not on the curveExtends
Constructors
Constructor
new InvalidPointError(): InvalidPointError
Defined in: src/crypto/Bls12381/errors.js:26
Returns
InvalidPointError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:28
Inherited from
Bls12381Error.name
InvalidScalarError
Defined in: src/crypto/Bls12381/errors.js:45 Error thrown when a scalar is invalidExtends
Constructors
Constructor
new InvalidScalarError(Defined in: src/crypto/Bls12381/errors.js:49reason?):InvalidScalarError
Parameters
reason?
string
Returns
InvalidScalarError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:51
Inherited from
Bls12381Error.name
InvalidSubgroupError
Defined in: src/crypto/Bls12381/errors.js:35 Error thrown when a point is not in the correct subgroupExtends
Constructors
Constructor
new InvalidSubgroupError(): InvalidSubgroupError
Defined in: src/crypto/Bls12381/errors.js:36
Returns
InvalidSubgroupError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:38
Inherited from
Bls12381Error.name
PairingError
Defined in: src/crypto/Bls12381/errors.js:71 Error thrown when pairing check failsExtends
Constructors
Constructor
new PairingError(Defined in: src/crypto/Bls12381/errors.js:75reason?):PairingError
Parameters
reason?
string
Returns
PairingError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:77
Inherited from
Bls12381Error.name
SignatureError
Defined in: src/crypto/Bls12381/errors.js:84 Error thrown when signature operation failsExtends
Constructors
Constructor
new SignatureError(Defined in: src/crypto/Bls12381/errors.js:88reason?):SignatureError
Parameters
reason?
string
Returns
SignatureError
Overrides
Bls12381Error.constructor
Properties
name
name: string
Defined in: src/crypto/Bls12381/errors.js:90
Inherited from
Bls12381Error.name
Variables
B_G1
Defined in: src/crypto/Bls12381/constants.js:33 G1 curve coefficient b = 4 y^2 = x^3 + 4 over FpconstB_G1:bigint=4n
B_G2
Defined in: src/crypto/Bls12381/constants.js:41 G2 curve coefficient b = 4(1+i) y^2 = x^3 + 4(1+i) over Fp2 Represented as [4, 4] for the Fp2 elementconstB_G2:object
Type Declaration
c0
c0: bigint
c1
c1: bigint
BLS_X
Defined in: src/crypto/Bls12381/constants.js:93 BLS parameter x (used in Miller loop) x = -0xd201000000010000 (negative)constBLS_X:bigint=0xd201000000010000n
BLS_X_IS_NEGATIVE
Defined in: src/crypto/Bls12381/constants.js:99 BLS parameter x is negativeconstBLS_X_IS_NEGATIVE:boolean=true
Bls12381
Defined in: src/crypto/Bls12381/Bls12381.js:104 Bls12381 main exportconstBls12381:object
Type Declaration
aggregate()
aggregate: (Aggregate multiple BLS signatures into one The aggregated signature can be verified against an aggregated public key (when all signers signed the same message) or via batch verification (when signers signed different messages).signatures) =>Uint8Array<ArrayBufferLike>
Parameters
signatures
Uint8Array<ArrayBufferLike>[]
Array of compressed G1 signatures (48 bytes each)
Returns
Uint8Array<ArrayBufferLike>
Aggregated signature (48 bytes compressed G1)
Throws
If aggregation fails or no signatures providedExample
aggregatePublicKeys()
aggregatePublicKeys: (Aggregate multiple public keys into one Used when multiple signers sign the same message and you want to verify against a single aggregated public key.publicKeys) =>Uint8Array<ArrayBufferLike>
Parameters
publicKeys
Uint8Array<ArrayBufferLike>[]
Array of compressed G2 public keys (96 bytes each)
Returns
Uint8Array<ArrayBufferLike>
Aggregated public key (96 bytes compressed G2)
Throws
If aggregation fails or no public keys providedExample
aggregateVerify()
aggregateVerify: (Verify an aggregated signature where all signers signed the same message This is the most common case in Ethereum consensus - multiple validators sign the same block/attestation.aggregatedSignature,message,publicKeys) =>boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
message
Uint8Array<ArrayBufferLike>
The message that was signed by all parties
publicKeys
Uint8Array<ArrayBufferLike>[]
Public keys of all signers (48 bytes each)
Returns
boolean
True if the aggregated signature is valid
Example
batchVerify()
batchVerify: (Verify an aggregated signature where each signer signed a different message Uses multi-pairing verification: product of e(pk_i, H(msg_i)) == e(G1, aggSig)aggregatedSignature,messages,publicKeys) =>boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
messages
Uint8Array<ArrayBufferLike>[]
Messages that were signed (one per signer)
publicKeys
Uint8Array<ArrayBufferLike>[]
Public keys (one per signer, same order as messages)
Returns
boolean
True if the aggregated signature is valid
Throws
If messages and publicKeys have different lengthsExample
derivePublicKey()
derivePublicKey: (Derive a BLS12-381 public key from a private key Public key = privateKey * G2_generatorprivateKey) =>Uint8Array<ArrayBufferLike>
Parameters
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Uint8Array<ArrayBufferLike>
Compressed G2 public key (96 bytes)
Throws
If private key is invalidExample
derivePublicKeyPoint()
derivePublicKeyPoint: (Derive a BLS12-381 public key as a G1 point (uncompressed)privateKey) =>Bls12381G1PointType
Parameters
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key
Returns
Bls12381G1PointType
Public key as G1 point
Throws
If private key is invalidfastAggregateVerify()
fastAggregateVerify: (Fast aggregate verify (same message case) Optimized for the common case where all signers signed the same message. This is faster than aggregateVerify when you already have the aggregated public key.aggregatedSignature,message,aggregatedPublicKey) =>boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
message
Uint8Array<ArrayBufferLike>
The message that was signed
aggregatedPublicKey
Uint8Array<ArrayBufferLike>
Pre-computed aggregated public key (48 bytes)
Returns
boolean
True if valid
Fp
Fp: Fp
Fp2
Fp2: Fp2
Fr
Fr: Fr
G1
G1: G1
G2
G2: G2
isValidPrivateKey()
isValidPrivateKey: (Check if a private key is valid A valid private key must be:privateKey) =>boolean
- 32 bytes
- Non-zero
- Less than the curve order (Fr modulus)
Parameters
privateKey
Uint8Array<ArrayBufferLike>
Private key to validate
Returns
boolean
True if valid
Example
Pairing
Pairing: Pairing
BLS12-381 Pairing Operations
Optimal Ate pairing implementation for BLS12-381.
e: G1 x G2 -> GT
NOTE: Full pairing implementation requires Fp6, Fp12 tower extensions
and Miller loop computation. For production use, the native blst
library should be used via the Zig FFI bindings.
This module provides the interface and simplified implementations
for testing and educational purposes.
See
https://hackmd.io/@benjaminion/bls12-381 for pairing detailsSince
0.0.0randomPrivateKey()
randomPrivateKey: () =>Generate a random BLS12-381 private key Uses cryptographically secure random number generation. The key is guaranteed to be valid (non-zero and less than curve order).Uint8Array<ArrayBufferLike>
Returns
Uint8Array<ArrayBufferLike>
32-byte private key
Example
sign()
sign: (Sign a message using BLS12-381 Uses the Ethereum consensus “short signatures” scheme:message,privateKey) =>Uint8Array<ArrayBufferLike>
- Signature = privateKey * H(message) where H maps to G1
- Signatures are 48 bytes (compressed G1 point)
Parameters
message
Uint8Array<ArrayBufferLike>
Message to sign
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Uint8Array<ArrayBufferLike>
Signature as compressed G1 point (48 bytes)
Throws
If private key is invalidThrows
If signing failsExample
signPoint()
signPoint: (Sign a pre-hashed message (G2 point) using BLS12-381 For advanced use when you have already hashed the message to G2.messagePoint,privateKey) =>Bls12381G2PointType
Parameters
messagePoint
Bls12381G2PointType
Message as G2 point
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Bls12381G2PointType
Signature as G2 point (projective)
Throws
If private key is invalidThrows
If signing failsverify()
verify: (Verify a BLS12-381 signature Uses pairing check for verification.signature,message,publicKey) =>boolean
Parameters
signature
Uint8Array<ArrayBufferLike>
Compressed G1 signature (48 bytes)
message
Uint8Array<ArrayBufferLike>
Original message that was signed
publicKey
Uint8Array<ArrayBufferLike>
Compressed G2 public key (96 bytes)
Returns
boolean
True if signature is valid
Throws
If verification fails due to invalid inputsExample
verifyPoint()
verifyPoint: (Verify a BLS signature with pre-computed points (advanced) For use when you have already deserialized the points.signaturePoint,messagePoint,publicKeyPoint) =>boolean
Parameters
signaturePoint
Bls12381G2PointType
Signature as G2 point
messagePoint
Bls12381G2PointType
Message hash as G2 point
publicKeyPoint
Bls12381G1PointType
Public key as G1 point
Returns
boolean
True if signature is valid
Example
EMBEDDING_DEGREE
Defined in: src/crypto/Bls12381/constants.js:86 Embedding degree k = 12constEMBEDDING_DEGREE:number=12
FP_MOD
Defined in: src/crypto/Bls12381/constants.js:17 Base field modulus p (381 bits) p = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabconstFP_MOD:bigint=0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn
FR_MOD
Defined in: src/crypto/Bls12381/constants.js:25 Scalar field modulus r (curve order, 255 bits) r = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001constFR_MOD:bigint=0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n
G1_GENERATOR_X
Defined in: src/crypto/Bls12381/constants.js:47 G1 generator x-coordinateconstG1_GENERATOR_X:bigint=0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bbn
G1_GENERATOR_Y
Defined in: src/crypto/Bls12381/constants.js:54 G1 generator y-coordinateconstG1_GENERATOR_Y:bigint=0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1n
G2_COFACTOR
Defined in: src/crypto/Bls12381/constants.js:79 G2 cofactor h2 (large value)constG2_COFACTOR:bigint=0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5n
G2_GENERATOR_X
Defined in: src/crypto/Bls12381/constants.js:61 G2 generator x-coordinate (Fp2 element)constG2_GENERATOR_X:object
Type Declaration
c0
c0: bigint
c1
c1: bigint
G2_GENERATOR_Y
Defined in: src/crypto/Bls12381/constants.js:70 G2 generator y-coordinate (Fp2 element)constG2_GENERATOR_Y:object
Type Declaration
c0
c0: bigint
c1
c1: bigint
Functions
aggregate()
aggregate(Defined in: src/crypto/Bls12381/aggregate.js:43 Aggregate multiple BLS signatures into one The aggregated signature can be verified against an aggregated public key (when all signers signed the same message) or via batch verification (when signers signed different messages).signatures):Uint8Array<ArrayBufferLike>
Parameters
signatures
Uint8Array<ArrayBufferLike>[]
Array of compressed G1 signatures (48 bytes each)
Returns
Uint8Array<ArrayBufferLike>
Aggregated signature (48 bytes compressed G1)
Throws
If aggregation fails or no signatures providedExample
aggregatePublicKeys()
aggregatePublicKeys(Defined in: src/crypto/Bls12381/aggregate.js:89 Aggregate multiple public keys into one Used when multiple signers sign the same message and you want to verify against a single aggregated public key.publicKeys):Uint8Array<ArrayBufferLike>
Parameters
publicKeys
Uint8Array<ArrayBufferLike>[]
Array of compressed G2 public keys (96 bytes each)
Returns
Uint8Array<ArrayBufferLike>
Aggregated public key (96 bytes compressed G2)
Throws
If aggregation fails or no public keys providedExample
aggregateVerify()
aggregateVerify(Defined in: src/crypto/Bls12381/aggregateVerify.js:47 Verify an aggregated signature where all signers signed the same message This is the most common case in Ethereum consensus - multiple validators sign the same block/attestation.aggregatedSignature,message,publicKeys):boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
message
Uint8Array<ArrayBufferLike>
The message that was signed by all parties
publicKeys
Uint8Array<ArrayBufferLike>[]
Public keys of all signers (48 bytes each)
Returns
boolean
True if the aggregated signature is valid
Example
batchVerify()
batchVerify(Defined in: src/crypto/Bls12381/aggregateVerify.js:105 Verify an aggregated signature where each signer signed a different message Uses multi-pairing verification: product of e(pk_i, H(msg_i)) == e(G1, aggSig)aggregatedSignature,messages,publicKeys):boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
messages
Uint8Array<ArrayBufferLike>[]
Messages that were signed (one per signer)
publicKeys
Uint8Array<ArrayBufferLike>[]
Public keys (one per signer, same order as messages)
Returns
boolean
True if the aggregated signature is valid
Throws
If messages and publicKeys have different lengthsExample
derivePublicKey()
derivePublicKey(Defined in: src/crypto/Bls12381/derivePublicKey.js:38 Derive a BLS12-381 public key from a private key Public key = privateKey * G2_generatorprivateKey):Uint8Array<ArrayBufferLike>
Parameters
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Uint8Array<ArrayBufferLike>
Compressed G2 public key (96 bytes)
Throws
If private key is invalidExample
derivePublicKeyPoint()
derivePublicKeyPoint(Defined in: src/crypto/Bls12381/derivePublicKey.js:80 Derive a BLS12-381 public key as a G1 point (uncompressed)privateKey):Bls12381G1PointType
Parameters
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key
Returns
Bls12381G1PointType
Public key as G1 point
Throws
If private key is invalidfastAggregateVerify()
fastAggregateVerify(Defined in: src/crypto/Bls12381/aggregateVerify.js:148 Fast aggregate verify (same message case) Optimized for the common case where all signers signed the same message. This is faster than aggregateVerify when you already have the aggregated public key.aggregatedSignature,message,aggregatedPublicKey):boolean
Parameters
aggregatedSignature
Uint8Array<ArrayBufferLike>
Aggregated signature (96 bytes)
message
Uint8Array<ArrayBufferLike>
The message that was signed
aggregatedPublicKey
Uint8Array<ArrayBufferLike>
Pre-computed aggregated public key (48 bytes)
Returns
boolean
True if valid
isValidPrivateKey()
isValidPrivateKey(Defined in: src/crypto/Bls12381/randomPrivateKey.js:55 Check if a private key is valid A valid private key must be:privateKey):boolean
- 32 bytes
- Non-zero
- Less than the curve order (Fr modulus)
Parameters
privateKey
Uint8Array<ArrayBufferLike>
Private key to validate
Returns
boolean
True if valid
Example
randomPrivateKey()
randomPrivateKey():Defined in: src/crypto/Bls12381/randomPrivateKey.js:29 Generate a random BLS12-381 private key Uses cryptographically secure random number generation. The key is guaranteed to be valid (non-zero and less than curve order).Uint8Array<ArrayBufferLike>
Returns
Uint8Array<ArrayBufferLike>
32-byte private key
Example
sign()
sign(Defined in: src/crypto/Bls12381/sign.js:44 Sign a message using BLS12-381 Uses the Ethereum consensus “short signatures” scheme:message,privateKey):Uint8Array<ArrayBufferLike>
- Signature = privateKey * H(message) where H maps to G1
- Signatures are 48 bytes (compressed G1 point)
Parameters
message
Uint8Array<ArrayBufferLike>
Message to sign
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Uint8Array<ArrayBufferLike>
Signature as compressed G1 point (48 bytes)
Throws
If private key is invalidThrows
If signing failsExample
signPoint()
signPoint(Defined in: src/crypto/Bls12381/sign.js:91 Sign a pre-hashed message (G2 point) using BLS12-381 For advanced use when you have already hashed the message to G2.messagePoint,privateKey):Bls12381G2PointType
Parameters
messagePoint
Bls12381G2PointType
Message as G2 point
privateKey
Uint8Array<ArrayBufferLike>
32-byte private key (scalar in Fr)
Returns
Bls12381G2PointType
Signature as G2 point (projective)
Throws
If private key is invalidThrows
If signing failsverify()
verify(Defined in: src/crypto/Bls12381/verify.js:41 Verify a BLS12-381 signature Uses pairing check for verification.signature,message,publicKey):boolean
Parameters
signature
Uint8Array<ArrayBufferLike>
Compressed G1 signature (48 bytes)
message
Uint8Array<ArrayBufferLike>
Original message that was signed
publicKey
Uint8Array<ArrayBufferLike>
Compressed G2 public key (96 bytes)
Returns
boolean
True if signature is valid
Throws
If verification fails due to invalid inputsExample
verifyPoint()
verifyPoint(Defined in: src/crypto/Bls12381/verify.js:78 Verify a BLS signature with pre-computed points (advanced) For use when you have already deserialized the points.signaturePoint,messagePoint,publicKeyPoint):boolean
Parameters
signaturePoint
Bls12381G2PointType
Signature as G2 point
messagePoint
Bls12381G2PointType
Message hash as G2 point
publicKeyPoint
Bls12381G1PointType
Public key as G1 point
Returns
boolean
True if signature is valid

