Skip to content

Commit 0e13ac3

Browse files
committed
weierstrass, edwards: rename Point class Interfaces for consistency
1 parent 4ad92d8 commit 0e13ac3

File tree

4 files changed

+413
-330
lines changed

4 files changed

+413
-330
lines changed

src/abstract/bls.ts

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import {
4040
weierstrassPoints,
4141
type CurvePointsRes,
4242
type CurvePointsType,
43-
type ProjConstructor,
44-
type ProjPointType,
43+
type WeierstrassPoint,
44+
type WeierstrassPointCons,
4545
} from './weierstrass.ts';
4646

4747
type Fp = bigint; // Can be different field?
@@ -52,21 +52,21 @@ const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
5252
export type TwistType = 'multiplicative' | 'divisive';
5353

5454
export type ShortSignatureCoder<Fp> = {
55-
fromBytes(bytes: Uint8Array): ProjPointType<Fp>;
56-
fromHex(hex: Hex): ProjPointType<Fp>;
57-
toBytes(point: ProjPointType<Fp>): Uint8Array;
55+
fromBytes(bytes: Uint8Array): WeierstrassPoint<Fp>;
56+
fromHex(hex: Hex): WeierstrassPoint<Fp>;
57+
toBytes(point: WeierstrassPoint<Fp>): Uint8Array;
5858
/** @deprecated use `toBytes` */
59-
toRawBytes(point: ProjPointType<Fp>): Uint8Array;
60-
toHex(point: ProjPointType<Fp>): string;
59+
toRawBytes(point: WeierstrassPoint<Fp>): Uint8Array;
60+
toHex(point: WeierstrassPoint<Fp>): string;
6161
};
6262

6363
export type SignatureCoder<Fp> = {
64-
fromBytes(bytes: Uint8Array): ProjPointType<Fp>;
65-
fromHex(hex: Hex): ProjPointType<Fp>;
66-
toBytes(point: ProjPointType<Fp>): Uint8Array;
64+
fromBytes(bytes: Uint8Array): WeierstrassPoint<Fp>;
65+
fromHex(hex: Hex): WeierstrassPoint<Fp>;
66+
toBytes(point: WeierstrassPoint<Fp>): Uint8Array;
6767
/** @deprecated use `toBytes` */
68-
toRawBytes(point: ProjPointType<Fp>): Uint8Array;
69-
toHex(point: ProjPointType<Fp>): string;
68+
toRawBytes(point: WeierstrassPoint<Fp>): Uint8Array;
69+
toHex(point: WeierstrassPoint<Fp>): string;
7070
};
7171

7272
export type BlsFields = {
@@ -94,11 +94,11 @@ export type PostPrecomputeFn = (
9494
) => void;
9595
export type BlsPairing = {
9696
Fp12: Fp12Bls;
97-
calcPairingPrecomputes: (p: ProjPointType<Fp2>) => Precompute;
97+
calcPairingPrecomputes: (p: WeierstrassPoint<Fp2>) => Precompute;
9898
millerLoopBatch: (pairs: [Precompute, Fp, Fp][]) => Fp12;
99-
pairing: (P: ProjPointType<Fp>, Q: ProjPointType<Fp2>, withFinalExponent?: boolean) => Fp12;
99+
pairing: (P: WeierstrassPoint<Fp>, Q: WeierstrassPoint<Fp2>, withFinalExponent?: boolean) => Fp12;
100100
pairingBatch: (
101-
pairs: { g1: ProjPointType<Fp>; g2: ProjPointType<Fp2> }[],
101+
pairs: { g1: WeierstrassPoint<Fp>; g2: WeierstrassPoint<Fp2> }[],
102102
withFinalExponent?: boolean
103103
) => Fp12;
104104
};
@@ -159,47 +159,55 @@ export type CurveFn = {
159159
/** @deprecated use `longSignatures.sign` */
160160
sign: {
161161
(message: Hex, privateKey: PrivKey, htfOpts?: htfBasicOpts): Uint8Array;
162-
(message: ProjPointType<Fp2>, privateKey: PrivKey, htfOpts?: htfBasicOpts): ProjPointType<Fp2>;
162+
(
163+
message: WeierstrassPoint<Fp2>,
164+
privateKey: PrivKey,
165+
htfOpts?: htfBasicOpts
166+
): WeierstrassPoint<Fp2>;
163167
};
164168
/** @deprecated use `shortSignatures.sign` */
165169
signShortSignature: {
166170
(message: Hex, privateKey: PrivKey, htfOpts?: htfBasicOpts): Uint8Array;
167-
(message: ProjPointType<Fp>, privateKey: PrivKey, htfOpts?: htfBasicOpts): ProjPointType<Fp>;
171+
(
172+
message: WeierstrassPoint<Fp>,
173+
privateKey: PrivKey,
174+
htfOpts?: htfBasicOpts
175+
): WeierstrassPoint<Fp>;
168176
};
169177
/** @deprecated use `longSignatures.verify` */
170178
verify: (
171-
signature: Hex | ProjPointType<Fp2>,
172-
message: Hex | ProjPointType<Fp2>,
173-
publicKey: Hex | ProjPointType<Fp>,
179+
signature: Hex | WeierstrassPoint<Fp2>,
180+
message: Hex | WeierstrassPoint<Fp2>,
181+
publicKey: Hex | WeierstrassPoint<Fp>,
174182
htfOpts?: htfBasicOpts
175183
) => boolean;
176184
/** @deprecated use `shortSignatures.verify` */
177185
verifyShortSignature: (
178-
signature: Hex | ProjPointType<Fp>,
179-
message: Hex | ProjPointType<Fp>,
180-
publicKey: Hex | ProjPointType<Fp2>,
186+
signature: Hex | WeierstrassPoint<Fp>,
187+
message: Hex | WeierstrassPoint<Fp>,
188+
publicKey: Hex | WeierstrassPoint<Fp2>,
181189
htfOpts?: htfBasicOpts
182190
) => boolean;
183191
verifyBatch: (
184-
signature: Hex | ProjPointType<Fp2>,
185-
messages: (Hex | ProjPointType<Fp2>)[],
186-
publicKeys: (Hex | ProjPointType<Fp>)[],
192+
signature: Hex | WeierstrassPoint<Fp2>,
193+
messages: (Hex | WeierstrassPoint<Fp2>)[],
194+
publicKeys: (Hex | WeierstrassPoint<Fp>)[],
187195
htfOpts?: htfBasicOpts
188196
) => boolean;
189197
/** @deprecated use `longSignatures.aggregatePublicKeys` */
190198
aggregatePublicKeys: {
191199
(publicKeys: Hex[]): Uint8Array;
192-
(publicKeys: ProjPointType<Fp>[]): ProjPointType<Fp>;
200+
(publicKeys: WeierstrassPoint<Fp>[]): WeierstrassPoint<Fp>;
193201
};
194202
/** @deprecated use `longSignatures.aggregateSignatures` */
195203
aggregateSignatures: {
196204
(signatures: Hex[]): Uint8Array;
197-
(signatures: ProjPointType<Fp2>[]): ProjPointType<Fp2>;
205+
(signatures: WeierstrassPoint<Fp2>[]): WeierstrassPoint<Fp2>;
198206
};
199207
/** @deprecated use `shortSignatures.aggregateSignatures` */
200208
aggregateShortSignatures: {
201209
(signatures: Hex[]): Uint8Array;
202-
(signatures: ProjPointType<Fp>[]): ProjPointType<Fp>;
210+
(signatures: WeierstrassPoint<Fp>[]): WeierstrassPoint<Fp>;
203211
};
204212
/** @deprecated use `curves.G1` and `curves.G2` */
205213
G1: CurvePointsRes<Fp> & H2CHasher<Fp>;
@@ -218,8 +226,8 @@ export type CurveFn = {
218226
G2b: Fp2;
219227
};
220228
curves: {
221-
G1: ProjConstructor<bigint>;
222-
G2: ProjConstructor<Fp2>;
229+
G1: WeierstrassPointCons<bigint>;
230+
G2: WeierstrassPointCons<Fp2>;
223231
};
224232
fields: {
225233
Fp: IField<Fp>;
@@ -236,21 +244,21 @@ export type CurveFn = {
236244

237245
type BLSInput = Hex | Uint8Array;
238246
export interface BLSSigs<P, S> {
239-
getPublicKey(privateKey: PrivKey): ProjPointType<P>;
240-
sign(hashedMessage: ProjPointType<S>, privateKey: PrivKey): ProjPointType<S>;
247+
getPublicKey(privateKey: PrivKey): WeierstrassPoint<P>;
248+
sign(hashedMessage: WeierstrassPoint<S>, privateKey: PrivKey): WeierstrassPoint<S>;
241249
verify(
242-
signature: ProjPointType<S> | BLSInput,
243-
message: ProjPointType<S>,
244-
publicKey: ProjPointType<P> | BLSInput
250+
signature: WeierstrassPoint<S> | BLSInput,
251+
message: WeierstrassPoint<S>,
252+
publicKey: WeierstrassPoint<P> | BLSInput
245253
): boolean;
246254
verifyBatch: (
247-
signature: ProjPointType<S> | BLSInput,
248-
messages: ProjPointType<S>[],
249-
publicKeys: (ProjPointType<P> | BLSInput)[]
255+
signature: WeierstrassPoint<S> | BLSInput,
256+
messages: WeierstrassPoint<S>[],
257+
publicKeys: (WeierstrassPoint<P> | BLSInput)[]
250258
) => boolean;
251-
aggregatePublicKeys(publicKeys: (ProjPointType<P> | BLSInput)[]): ProjPointType<P>;
252-
aggregateSignatures(signatures: (ProjPointType<S> | BLSInput)[]): ProjPointType<S>;
253-
hash(message: Uint8Array, DST?: string | Uint8Array, hashOpts?: H2CHashOpts): ProjPointType<S>;
259+
aggregatePublicKeys(publicKeys: (WeierstrassPoint<P> | BLSInput)[]): WeierstrassPoint<P>;
260+
aggregateSignatures(signatures: (WeierstrassPoint<S> | BLSInput)[]): WeierstrassPoint<S>;
261+
hash(message: Uint8Array, DST?: string | Uint8Array, hashOpts?: H2CHashOpts): WeierstrassPoint<S>;
254262
Signature: SignatureCoder<S>;
255263
}
256264

@@ -275,8 +283,8 @@ function aNonEmpty(arr: any[]) {
275283
// This should be enough for bn254, no need to export full stuff?
276284
function createBlsPairing(
277285
fields: BlsFields,
278-
G1: ProjConstructor<Fp>,
279-
G2: ProjConstructor<Fp2>,
286+
G1: WeierstrassPointCons<Fp>,
287+
G2: WeierstrassPointCons<Fp2>,
280288
params: BlsPairingParams
281289
): BlsPairing {
282290
const { Fp2, Fp12 } = fields;
@@ -425,8 +433,8 @@ function createBlsSig<P, S>(
425433
isSigG1: boolean
426434
): BLSSigs<P, S> {
427435
const { Fp12, pairingBatch } = blsPairing;
428-
type PubPoint = ProjPointType<P>;
429-
type SigPoint = ProjPointType<S>;
436+
type PubPoint = WeierstrassPoint<P>;
437+
type SigPoint = WeierstrassPoint<S>;
430438
function normPub(point: PubPoint | BLSInput): PubPoint {
431439
return point instanceof PubCurve.Point ? (point as PubPoint) : PubCurve.Point.fromHex(point);
432440
}

0 commit comments

Comments
 (0)