/** * BLS != BLS. * The file implements BLS (Boneh-Lynn-Shacham) signatures. * Used in both BLS (Barreto-Lynn-Scott) and BN (Barreto-Naehrig) * families of pairing-friendly curves. * Consists of two curves: G1 and G2: * - G1 is a subgroup of (x, y) E(Fq) over y² = x³ + 4. * - G2 is a subgroup of ((x₁, x₂+i), (y₁, y₂+i)) E(Fq²) over y² = x³ + 4(1 + i) where i is √-1 * - Gt, created by bilinear (ate) pairing e(G1, G2), consists of p-th roots of unity in * Fq^k where k is embedding degree. Only degree 12 is currently supported, 24 is not. * Pairing is used to aggregate and verify signatures. * There are two modes of operation: * - Long signatures: X-byte keys + 2X-byte sigs (G1 keys + G2 sigs). * - Short signatures: 2X-byte keys + X-byte sigs (G2 keys + G1 sigs). * @module **/ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { type CHash, type Hex, type PrivKey } from '../utils.ts'; import { type H2CHasher, type H2CHashOpts, type H2COpts, type htfBasicOpts, type MapToCurve } from './hash-to-curve.ts'; import { type IField } from './modular.ts'; import type { Fp12, Fp12Bls, Fp2, Fp2Bls, Fp6Bls } from './tower.ts'; import { type CurvePointsRes, type CurvePointsType, type WeierstrassPoint, type WeierstrassPointCons } from './weierstrass.ts'; type Fp = bigint; export type TwistType = 'multiplicative' | 'divisive'; export type ShortSignatureCoder = { fromBytes(bytes: Uint8Array): WeierstrassPoint; fromHex(hex: Hex): WeierstrassPoint; toBytes(point: WeierstrassPoint): Uint8Array; toHex(point: WeierstrassPoint): string; /** @deprecated use `toBytes` */ toRawBytes(point: WeierstrassPoint): Uint8Array; }; export type SignatureCoder = { fromBytes(bytes: Uint8Array): WeierstrassPoint; fromHex(hex: Hex): WeierstrassPoint; toBytes(point: WeierstrassPoint): Uint8Array; toHex(point: WeierstrassPoint): string; /** @deprecated use `toBytes` */ toRawBytes(point: WeierstrassPoint): Uint8Array; }; export type BlsFields = { Fp: IField; Fr: IField; Fp2: Fp2Bls; Fp6: Fp6Bls; Fp12: Fp12Bls; }; export type PostPrecomputePointAddFn = (Rx: Fp2, Ry: Fp2, Rz: Fp2, Qx: Fp2, Qy: Fp2) => { Rx: Fp2; Ry: Fp2; Rz: Fp2; }; export type PostPrecomputeFn = (Rx: Fp2, Ry: Fp2, Rz: Fp2, Qx: Fp2, Qy: Fp2, pointAdd: PostPrecomputePointAddFn) => void; export type BlsPairing = { Fp12: Fp12Bls; calcPairingPrecomputes: (p: WeierstrassPoint) => Precompute; millerLoopBatch: (pairs: [Precompute, Fp, Fp][]) => Fp12; pairing: (P: WeierstrassPoint, Q: WeierstrassPoint, withFinalExponent?: boolean) => Fp12; pairingBatch: (pairs: { g1: WeierstrassPoint; g2: WeierstrassPoint; }[], withFinalExponent?: boolean) => Fp12; }; export type BlsPairingParams = { ateLoopSize: bigint; xNegative: boolean; twistType: TwistType; postPrecompute?: PostPrecomputeFn; }; export type CurveType = { G1: CurvePointsType & { ShortSignature: SignatureCoder; mapToCurve: MapToCurve; htfDefaults: H2COpts; }; G2: CurvePointsType & { Signature: SignatureCoder; mapToCurve: MapToCurve; htfDefaults: H2COpts; }; fields: BlsFields; params: { ateLoopSize: BlsPairingParams['ateLoopSize']; xNegative: BlsPairingParams['xNegative']; r: bigint; twistType: BlsPairingParams['twistType']; }; htfDefaults: H2COpts; hash: CHash; randomBytes?: (bytesLength?: number) => Uint8Array; postPrecompute?: PostPrecomputeFn; }; type PrecomputeSingle = [Fp2, Fp2, Fp2][]; type Precompute = PrecomputeSingle[]; /** * BLS consists of two curves: G1 and G2: * - G1 is a subgroup of (x, y) E(Fq) over y² = x³ + 4. * - G2 is a subgroup of ((x₁, x₂+i), (y₁, y₂+i)) E(Fq²) over y² = x³ + 4(1 + i) where i is √-1 */ export interface BLSCurvePair { longSignatures: BLSSigs; shortSignatures: BLSSigs; millerLoopBatch: BlsPairing['millerLoopBatch']; pairing: BlsPairing['pairing']; pairingBatch: BlsPairing['pairingBatch']; G1: { Point: WeierstrassPointCons; } & H2CHasher; G2: { Point: WeierstrassPointCons; } & H2CHasher; fields: { Fp: IField; Fp2: Fp2Bls; Fp6: Fp6Bls; Fp12: Fp12Bls; Fr: IField; }; utils: { randomSecretKey: () => Uint8Array; /** @deprecated use randomSecretKey */ randomPrivateKey: () => Uint8Array; calcPairingPrecomputes: BlsPairing['calcPairingPrecomputes']; }; } export type CurveFn = BLSCurvePair & { /** @deprecated use `longSignatures.getPublicKey` */ getPublicKey: (secretKey: PrivKey) => Uint8Array; /** @deprecated use `shortSignatures.getPublicKey` */ getPublicKeyForShortSignatures: (secretKey: PrivKey) => Uint8Array; /** @deprecated use `longSignatures.sign` */ sign: { (message: Hex, secretKey: PrivKey, htfOpts?: htfBasicOpts): Uint8Array; (message: WeierstrassPoint, secretKey: PrivKey, htfOpts?: htfBasicOpts): WeierstrassPoint; }; /** @deprecated use `shortSignatures.sign` */ signShortSignature: { (message: Hex, secretKey: PrivKey, htfOpts?: htfBasicOpts): Uint8Array; (message: WeierstrassPoint, secretKey: PrivKey, htfOpts?: htfBasicOpts): WeierstrassPoint; }; /** @deprecated use `longSignatures.verify` */ verify: (signature: Hex | WeierstrassPoint, message: Hex | WeierstrassPoint, publicKey: Hex | WeierstrassPoint, htfOpts?: htfBasicOpts) => boolean; /** @deprecated use `shortSignatures.verify` */ verifyShortSignature: (signature: Hex | WeierstrassPoint, message: Hex | WeierstrassPoint, publicKey: Hex | WeierstrassPoint, htfOpts?: htfBasicOpts) => boolean; verifyBatch: (signature: Hex | WeierstrassPoint, messages: (Hex | WeierstrassPoint)[], publicKeys: (Hex | WeierstrassPoint)[], htfOpts?: htfBasicOpts) => boolean; /** @deprecated use `longSignatures.aggregatePublicKeys` */ aggregatePublicKeys: { (publicKeys: Hex[]): Uint8Array; (publicKeys: WeierstrassPoint[]): WeierstrassPoint; }; /** @deprecated use `longSignatures.aggregateSignatures` */ aggregateSignatures: { (signatures: Hex[]): Uint8Array; (signatures: WeierstrassPoint[]): WeierstrassPoint; }; /** @deprecated use `shortSignatures.aggregateSignatures` */ aggregateShortSignatures: { (signatures: Hex[]): Uint8Array; (signatures: WeierstrassPoint[]): WeierstrassPoint; }; G1: CurvePointsRes & H2CHasher; G2: CurvePointsRes & H2CHasher; /** @deprecated use `longSignatures.Signature` */ Signature: SignatureCoder; /** @deprecated use `shortSignatures.Signature` */ ShortSignature: ShortSignatureCoder; params: { ateLoopSize: bigint; r: bigint; twistType: TwistType; /** @deprecated */ G1b: bigint; /** @deprecated */ G2b: Fp2; }; }; type BLSInput = Hex | Uint8Array; export interface BLSSigs { getPublicKey(secretKey: PrivKey): WeierstrassPoint

; sign(hashedMessage: WeierstrassPoint, secretKey: PrivKey): WeierstrassPoint; verify(signature: WeierstrassPoint | BLSInput, message: WeierstrassPoint, publicKey: WeierstrassPoint

| BLSInput): boolean; verifyBatch: (signature: WeierstrassPoint | BLSInput, messages: WeierstrassPoint[], publicKeys: (WeierstrassPoint

| BLSInput)[]) => boolean; aggregatePublicKeys(publicKeys: (WeierstrassPoint

| BLSInput)[]): WeierstrassPoint

; aggregateSignatures(signatures: (WeierstrassPoint | BLSInput)[]): WeierstrassPoint; hash(message: Uint8Array, DST?: string | Uint8Array, hashOpts?: H2CHashOpts): WeierstrassPoint; Signature: SignatureCoder; } export declare function bls(CURVE: CurveType): CurveFn; export {}; //# sourceMappingURL=bls.d.ts.map