@aztec/foundation 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/array/index.d.ts +2 -1
- package/dest/array/index.d.ts.map +1 -1
- package/dest/array/index.js +1 -0
- package/dest/array/sorted_array.d.ts +10 -0
- package/dest/array/sorted_array.d.ts.map +1 -0
- package/dest/array/sorted_array.js +106 -0
- package/dest/branded-types/block_number.d.ts +53 -0
- package/dest/branded-types/block_number.d.ts.map +1 -0
- package/dest/branded-types/block_number.js +75 -0
- package/dest/branded-types/checkpoint_number.d.ts +54 -0
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -0
- package/dest/branded-types/checkpoint_number.js +77 -0
- package/dest/branded-types/index.d.ts +3 -1
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +2 -0
- package/dest/buffer/buffer16.d.ts +2 -2
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +4 -2
- package/dest/buffer/buffer32.d.ts +2 -2
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +4 -2
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +11 -4
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +18 -9
- package/dest/config/network_config.d.ts +13 -1
- package/dest/config/network_config.d.ts.map +1 -1
- package/dest/config/network_config.js +3 -1
- package/dest/config/parse-env.d.ts +3 -0
- package/dest/config/parse-env.d.ts.map +1 -0
- package/dest/config/parse-env.js +7 -0
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/bls/bn254_keystore.js +1 -1
- package/dest/crypto/bls/index.js +1 -1
- package/dest/crypto/bn254/index.d.ts +35 -51
- package/dest/crypto/bn254/index.d.ts.map +1 -1
- package/dest/crypto/bn254/index.js +51 -140
- package/dest/crypto/ecdsa/signature.d.ts +2 -2
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/ecdsa/signature.js +2 -2
- package/dest/crypto/grumpkin/index.d.ts +4 -2
- package/dest/crypto/grumpkin/index.d.ts.map +1 -1
- package/dest/crypto/grumpkin/index.js +2 -1
- package/dest/crypto/keys/index.d.ts +2 -2
- package/dest/crypto/keys/index.d.ts.map +1 -1
- package/dest/crypto/keys/index.js +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.d.ts +2 -2
- package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
- package/dest/crypto/pedersen/pedersen.wasm.js +1 -1
- package/dest/crypto/poseidon/index.d.ts +2 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +1 -1
- package/dest/crypto/random/randomness_singleton.d.ts +2 -2
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +3 -3
- package/dest/crypto/schnorr/index.d.ts +3 -2
- package/dest/crypto/schnorr/index.d.ts.map +1 -1
- package/dest/crypto/schnorr/index.js +1 -1
- package/dest/crypto/schnorr/signature.d.ts +2 -2
- package/dest/crypto/schnorr/signature.d.ts.map +1 -1
- package/dest/crypto/schnorr/signature.js +2 -2
- package/dest/crypto/sha256/index.d.ts +2 -2
- package/dest/crypto/sha256/index.d.ts.map +1 -1
- package/dest/crypto/sha256/index.js +1 -1
- package/dest/crypto/sha512/index.d.ts +2 -2
- package/dest/crypto/sha512/index.d.ts.map +1 -1
- package/dest/crypto/sha512/index.js +1 -1
- package/dest/crypto/signature/index.d.ts +2 -2
- package/dest/crypto/signature/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.d.ts +2 -2
- package/dest/crypto/sync/pedersen/index.d.ts.map +1 -1
- package/dest/crypto/sync/pedersen/index.js +1 -1
- package/dest/crypto/sync/poseidon/index.d.ts +2 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +1 -1
- package/dest/{fields/bls12_fields.d.ts → curves/bls12/field.d.ts} +3 -3
- package/dest/curves/bls12/field.d.ts.map +1 -0
- package/dest/{fields/bls12_fields.js → curves/bls12/field.js} +12 -9
- package/dest/curves/bls12/index.d.ts +3 -0
- package/dest/curves/bls12/index.d.ts.map +1 -0
- package/dest/curves/bls12/index.js +2 -0
- package/dest/{fields/bls12_point.d.ts → curves/bls12/point.d.ts} +4 -4
- package/dest/curves/bls12/point.d.ts.map +1 -0
- package/dest/{fields/bls12_point.js → curves/bls12/point.js} +10 -8
- package/dest/{fields/fields.d.ts → curves/bn254/field.d.ts} +7 -15
- package/dest/curves/bn254/field.d.ts.map +1 -0
- package/dest/{fields/fields.js → curves/bn254/field.js} +35 -49
- package/dest/curves/bn254/index.d.ts +3 -0
- package/dest/curves/bn254/index.d.ts.map +1 -0
- package/dest/curves/bn254/index.js +2 -0
- package/dest/curves/bn254/point.d.ts +54 -0
- package/dest/curves/bn254/point.d.ts.map +1 -0
- package/dest/curves/bn254/point.js +143 -0
- package/dest/curves/grumpkin/index.d.ts +10 -0
- package/dest/curves/grumpkin/index.d.ts.map +1 -0
- package/dest/curves/grumpkin/index.js +3 -0
- package/dest/{fields → curves/grumpkin}/point.d.ts +3 -3
- package/dest/curves/grumpkin/point.d.ts.map +1 -0
- package/dest/{fields → curves/grumpkin}/point.js +7 -7
- package/dest/eth-address/index.d.ts +3 -2
- package/dest/eth-address/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +10 -3
- package/dest/iterator/filter.d.ts +3 -0
- package/dest/iterator/filter.d.ts.map +1 -0
- package/dest/iterator/filter.js +7 -0
- package/dest/iterator/index.d.ts +2 -0
- package/dest/iterator/index.d.ts.map +1 -0
- package/dest/iterator/index.js +1 -0
- package/dest/log/pino-logger.d.ts +1 -1
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +1 -1
- package/dest/schemas/schemas.d.ts +7 -3
- package/dest/schemas/schemas.d.ts.map +1 -1
- package/dest/schemas/schemas.js +9 -3
- package/dest/schemas/types.d.ts +31 -1
- package/dest/schemas/types.d.ts.map +1 -1
- package/dest/schemas/types.js +25 -1
- package/dest/serialize/field_reader.d.ts +2 -2
- package/dest/serialize/field_reader.d.ts.map +1 -1
- package/dest/serialize/field_reader.js +1 -1
- package/dest/serialize/free_funcs.d.ts +2 -2
- package/dest/serialize/free_funcs.d.ts.map +1 -1
- package/dest/serialize/free_funcs.js +1 -1
- package/dest/serialize/serialize.d.ts +2 -2
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +1 -1
- package/dest/sleep/index.d.ts +3 -1
- package/dest/sleep/index.d.ts.map +1 -1
- package/dest/sleep/index.js +4 -0
- package/dest/timer/date.d.ts +2 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +3 -0
- package/dest/trees/balanced_merkle_tree.d.ts +1 -1
- package/dest/trees/balanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/balanced_merkle_tree.js +3 -1
- package/dest/trees/indexed_merkle_tree.js +1 -1
- package/dest/trees/membership_witness.d.ts +2 -2
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +1 -1
- package/dest/trees/merkle_tree_calculator.js +1 -1
- package/dest/trees/sibling_path.d.ts +2 -2
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -2
- package/dest/trees/unbalanced_merkle_tree.d.ts +3 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree.js +6 -0
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +1 -2
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +0 -4
- package/dest/types/index.d.ts +3 -1
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +3 -0
- package/package.json +25 -7
- package/src/array/index.ts +1 -0
- package/src/array/sorted_array.ts +133 -0
- package/src/branded-types/block_number.ts +112 -0
- package/src/branded-types/checkpoint_number.ts +115 -0
- package/src/branded-types/index.ts +2 -0
- package/src/buffer/buffer16.ts +2 -2
- package/src/buffer/buffer32.ts +2 -2
- package/src/config/env_var.ts +29 -10
- package/src/config/index.ts +22 -6
- package/src/config/network_config.ts +2 -0
- package/src/config/parse-env.ts +4 -0
- package/src/crypto/bls/bn254_keystore.ts +1 -1
- package/src/crypto/bls/index.ts +1 -1
- package/src/crypto/bn254/index.ts +50 -159
- package/src/crypto/ecdsa/signature.ts +2 -2
- package/src/crypto/grumpkin/index.ts +3 -1
- package/src/crypto/keys/index.ts +1 -1
- package/src/crypto/pedersen/pedersen.wasm.ts +1 -1
- package/src/crypto/poseidon/index.ts +1 -1
- package/src/crypto/random/randomness_singleton.ts +2 -4
- package/src/crypto/schnorr/index.ts +2 -1
- package/src/crypto/schnorr/signature.ts +2 -2
- package/src/crypto/sha256/index.ts +1 -1
- package/src/crypto/sha512/index.ts +1 -1
- package/src/crypto/signature/index.ts +1 -1
- package/src/crypto/sync/pedersen/index.ts +1 -1
- package/src/crypto/sync/poseidon/index.ts +1 -1
- package/src/{fields/bls12_fields.ts → curves/bls12/field.ts} +6 -6
- package/src/curves/bls12/index.ts +2 -0
- package/src/{fields/bls12_point.ts → curves/bls12/point.ts} +7 -7
- package/src/{fields/fields.ts → curves/bn254/field.ts} +33 -56
- package/src/curves/bn254/index.ts +2 -0
- package/src/curves/bn254/point.ts +170 -0
- package/src/curves/grumpkin/index.ts +11 -0
- package/src/{fields → curves/grumpkin}/point.ts +7 -7
- package/src/eth-address/index.ts +8 -2
- package/src/iterator/filter.ts +11 -0
- package/src/iterator/index.ts +1 -0
- package/src/log/pino-logger.ts +2 -1
- package/src/schemas/schemas.ts +14 -3
- package/src/schemas/types.ts +33 -0
- package/src/serialize/field_reader.ts +1 -1
- package/src/serialize/free_funcs.ts +1 -1
- package/src/serialize/serialize.ts +1 -1
- package/src/sleep/index.ts +6 -0
- package/src/timer/date.ts +4 -0
- package/src/trees/balanced_merkle_tree.ts +3 -1
- package/src/trees/indexed_merkle_tree.ts +1 -1
- package/src/trees/membership_witness.ts +1 -1
- package/src/trees/merkle_tree_calculator.ts +1 -1
- package/src/trees/sibling_path.ts +2 -2
- package/src/trees/unbalanced_merkle_tree.ts +14 -0
- package/src/trees/unbalanced_merkle_tree_calculator.ts +0 -10
- package/src/types/index.ts +5 -0
- package/dest/crypto/bn254/bn254_utils.d.ts +0 -39
- package/dest/crypto/bn254/bn254_utils.d.ts.map +0 -1
- package/dest/crypto/bn254/bn254_utils.js +0 -56
- package/dest/crypto/index.d.ts +0 -17
- package/dest/crypto/index.d.ts.map +0 -1
- package/dest/crypto/index.js +0 -16
- package/dest/fields/bls12_fields.d.ts.map +0 -1
- package/dest/fields/bls12_point.d.ts.map +0 -1
- package/dest/fields/coordinate.d.ts +0 -63
- package/dest/fields/coordinate.d.ts.map +0 -1
- package/dest/fields/coordinate.js +0 -96
- package/dest/fields/fields.d.ts.map +0 -1
- package/dest/fields/index.d.ts +0 -6
- package/dest/fields/index.d.ts.map +0 -1
- package/dest/fields/index.js +0 -5
- package/dest/fields/point.d.ts.map +0 -1
- package/dest/index.d.ts +0 -31
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -31
- package/dest/json-rpc/server/telemetry.d.ts +0 -2
- package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
- package/dest/json-rpc/server/telemetry.js +0 -0
- package/src/crypto/bn254/bn254_utils.ts +0 -64
- package/src/crypto/index.ts +0 -16
- package/src/fields/coordinate.ts +0 -104
- package/src/fields/index.ts +0 -5
- package/src/index.ts +0 -31
- package/src/json-rpc/server/telemetry.ts +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BN254_G1_GENERATOR,
|
|
3
|
+
BN254_G2_GENERATOR,
|
|
4
|
+
BarretenbergSync,
|
|
5
|
+
type Bn254G1Point as BbApiBn254G1Point,
|
|
6
|
+
type Bn254G2Point as BbApiBn254G2Point,
|
|
7
|
+
} from '@aztec/bb.js';
|
|
8
|
+
|
|
9
|
+
import { Fq, Fr } from './field.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* BN254 G1 point using foundation field classes.
|
|
13
|
+
* Represents a point on the BN254 elliptic curve in affine coordinates.
|
|
14
|
+
*/
|
|
15
|
+
export class Bn254G1Point {
|
|
16
|
+
constructor(
|
|
17
|
+
public readonly x: Fq,
|
|
18
|
+
public readonly y: Fq,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
private toBbApiPoint(): BbApiBn254G1Point {
|
|
22
|
+
return {
|
|
23
|
+
x: this.x.toBuffer(),
|
|
24
|
+
y: this.y.toBuffer(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static fromBbApiPoint(point: BbApiBn254G1Point): Bn254G1Point {
|
|
29
|
+
return new Bn254G1Point(Fq.fromBuffer(Buffer.from(point.x)), Fq.fromBuffer(Buffer.from(point.y)));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async isOnCurve(): Promise<boolean> {
|
|
33
|
+
await BarretenbergSync.initSingleton();
|
|
34
|
+
const api = BarretenbergSync.getSingleton();
|
|
35
|
+
|
|
36
|
+
const apiPoint = this.toBbApiPoint();
|
|
37
|
+
const response = api.bn254G1IsOnCurve({ point: apiPoint });
|
|
38
|
+
return response.isOnCurve;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the generator point for BN254 G1, or perform scalar multiplication.
|
|
43
|
+
* When called without arguments, returns the base generator point.
|
|
44
|
+
* When called with a scalar, returns scalar * generator (useful for public key derivation).
|
|
45
|
+
*/
|
|
46
|
+
static async generator(scalar?: Fr): Promise<Bn254G1Point> {
|
|
47
|
+
if (!scalar) {
|
|
48
|
+
return new Bn254G1Point(
|
|
49
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.x)),
|
|
50
|
+
Fq.fromBuffer(Buffer.from(BN254_G1_GENERATOR.y)),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await BarretenbergSync.initSingleton();
|
|
55
|
+
const api = BarretenbergSync.getSingleton();
|
|
56
|
+
|
|
57
|
+
const response = api.bn254G1Mul({
|
|
58
|
+
point: BN254_G1_GENERATOR,
|
|
59
|
+
scalar: scalar.toBuffer(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Decompress a BN254 G1 point from compressed form (32 bytes).
|
|
67
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
68
|
+
* in the most significant bit.
|
|
69
|
+
*/
|
|
70
|
+
static async fromCompressed(compressed: Buffer): Promise<Bn254G1Point> {
|
|
71
|
+
if (compressed.length !== 32) {
|
|
72
|
+
throw new Error('Invalid compressed point length');
|
|
73
|
+
}
|
|
74
|
+
await BarretenbergSync.initSingleton();
|
|
75
|
+
const api = BarretenbergSync.getSingleton();
|
|
76
|
+
|
|
77
|
+
const response = api.bn254G1FromCompressed({
|
|
78
|
+
compressed: new Uint8Array(compressed),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return Bn254G1Point.fromBbApiPoint(response.point);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Compress this BN254 G1 point to 32 bytes.
|
|
86
|
+
* The compressed format encodes the x-coordinate and the sign bit of the y-coordinate
|
|
87
|
+
* in the most significant bit (bit 255).
|
|
88
|
+
*/
|
|
89
|
+
compress(): Buffer {
|
|
90
|
+
const xBytes = this.x.toBuffer();
|
|
91
|
+
// Get the least significant bit of y to determine the sign
|
|
92
|
+
const yLsb = this.y.toBigInt() & 1n;
|
|
93
|
+
// If y is odd, set the most significant bit (bit 255) of the output
|
|
94
|
+
if (yLsb === 1n) {
|
|
95
|
+
xBytes[0] |= 0x80;
|
|
96
|
+
}
|
|
97
|
+
return xBytes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
equals(other: Bn254G1Point): boolean {
|
|
101
|
+
return this.x.equals(other.x) && this.y.equals(other.y);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
toString(): string {
|
|
105
|
+
return `Bn254G1Point(x: ${this.x.toString()}, y: ${this.y.toString()})`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* BN254 G2 point using foundation field classes.
|
|
111
|
+
* Represents a point on the BN254 G2 curve (twist curve) in affine coordinates.
|
|
112
|
+
* G2 points use extension field coordinates (Fq2).
|
|
113
|
+
*/
|
|
114
|
+
export class Bn254G2Point {
|
|
115
|
+
constructor(
|
|
116
|
+
public readonly x: [Fq, Fq],
|
|
117
|
+
public readonly y: [Fq, Fq],
|
|
118
|
+
) {}
|
|
119
|
+
|
|
120
|
+
private toBbApiPoint(): BbApiBn254G2Point {
|
|
121
|
+
return {
|
|
122
|
+
x: [this.x[0].toBuffer(), this.x[1].toBuffer()],
|
|
123
|
+
y: [this.y[0].toBuffer(), this.y[1].toBuffer()],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private static fromBbApiPoint(point: BbApiBn254G2Point): Bn254G2Point {
|
|
128
|
+
return new Bn254G2Point(
|
|
129
|
+
[Fq.fromBuffer(Buffer.from(point.x[0])), Fq.fromBuffer(Buffer.from(point.x[1]))],
|
|
130
|
+
[Fq.fromBuffer(Buffer.from(point.y[0])), Fq.fromBuffer(Buffer.from(point.y[1]))],
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the generator point for BN254 G2, or perform scalar multiplication.
|
|
136
|
+
* When called without arguments, returns the base generator point.
|
|
137
|
+
* When called with a scalar, returns scalar * generator.
|
|
138
|
+
*/
|
|
139
|
+
static async generator(scalar?: Fr): Promise<Bn254G2Point> {
|
|
140
|
+
if (!scalar) {
|
|
141
|
+
return new Bn254G2Point(
|
|
142
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.x[1]))],
|
|
143
|
+
[Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[0])), Fq.fromBuffer(Buffer.from(BN254_G2_GENERATOR.y[1]))],
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await BarretenbergSync.initSingleton();
|
|
148
|
+
const api = BarretenbergSync.getSingleton();
|
|
149
|
+
|
|
150
|
+
const response = api.bn254G2Mul({
|
|
151
|
+
point: BN254_G2_GENERATOR as BbApiBn254G2Point,
|
|
152
|
+
scalar: scalar.toBuffer(),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return Bn254G2Point.fromBbApiPoint(response.point);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
equals(other: Bn254G2Point): boolean {
|
|
159
|
+
return (
|
|
160
|
+
this.x[0].equals(other.x[0]) &&
|
|
161
|
+
this.x[1].equals(other.x[1]) &&
|
|
162
|
+
this.y[0].equals(other.y[0]) &&
|
|
163
|
+
this.y[1].equals(other.y[1])
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
toString(): string {
|
|
168
|
+
return `Bn254G2Point(x: (${this.x[0].toString()}, ${this.x[1].toString()}), y: (${this.y[0].toString()}, ${this.y[1].toString()}))`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Fq } from '../bn254/field.js';
|
|
2
|
+
|
|
3
|
+
export * from './point.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GrumpkinScalar is an Fq.
|
|
7
|
+
* @remarks Called GrumpkinScalar because it is used to represent elements in Grumpkin's scalar field as defined in
|
|
8
|
+
* the Aztec Protocol Specs.
|
|
9
|
+
*/
|
|
10
|
+
export type GrumpkinScalar = Fq;
|
|
11
|
+
export const GrumpkinScalar = Fq;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { toBigIntBE } from '
|
|
2
|
-
import { poseidon2Hash } from '
|
|
3
|
-
import { randomBoolean } from '
|
|
4
|
-
import { hexSchemaFor } from '
|
|
5
|
-
import { BufferReader, FieldReader, serializeToBuffer } from '
|
|
6
|
-
import { bufferToHex, hexToBuffer } from '
|
|
7
|
-
import { Fr } from '
|
|
1
|
+
import { toBigIntBE } from '../../bigint-buffer/index.js';
|
|
2
|
+
import { poseidon2Hash } from '../../crypto/poseidon/index.js';
|
|
3
|
+
import { randomBoolean } from '../../crypto/random/index.js';
|
|
4
|
+
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
5
|
+
import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
|
|
6
|
+
import { bufferToHex, hexToBuffer } from '../../string/index.js';
|
|
7
|
+
import { Fr } from '../bn254/field.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents a Point on an elliptic curve with x and y coordinates.
|
package/src/eth-address/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { inspect } from 'util';
|
|
|
2
2
|
|
|
3
3
|
import { keccak256String } from '../crypto/keccak/index.js';
|
|
4
4
|
import { randomBytes } from '../crypto/random/index.js';
|
|
5
|
-
import { Fr } from '../
|
|
5
|
+
import { Fr } from '../curves/bn254/index.js';
|
|
6
6
|
import { hexSchemaFor } from '../schemas/utils.js';
|
|
7
7
|
import { BufferReader, FieldReader } from '../serialize/index.js';
|
|
8
8
|
import { TypeRegistry } from '../serialize/type_registry.js';
|
|
@@ -249,7 +249,7 @@ export class EthAddress {
|
|
|
249
249
|
/** Converts a number into an address. Useful for testing. */
|
|
250
250
|
static fromNumber(num: bigint | number): EthAddress {
|
|
251
251
|
const buffer = Buffer.alloc(EthAddress.SIZE_IN_BYTES);
|
|
252
|
-
buffer.writeBigUInt64BE(BigInt(num),
|
|
252
|
+
buffer.writeBigUInt64BE(BigInt(num), EthAddress.SIZE_IN_BYTES - 8);
|
|
253
253
|
return new EthAddress(buffer);
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -261,6 +261,12 @@ export class EthAddress {
|
|
|
261
261
|
// Serialization from hex string.
|
|
262
262
|
return hexSchemaFor(EthAddress, EthAddress.isAddress);
|
|
263
263
|
}
|
|
264
|
+
|
|
265
|
+
static areEqual(a: EthAddress | string, b: EthAddress | string) {
|
|
266
|
+
const addrA = typeof a === 'string' ? EthAddress.fromString(a) : a;
|
|
267
|
+
const addrB = typeof b === 'string' ? EthAddress.fromString(b) : b;
|
|
268
|
+
return addrA.equals(addrB);
|
|
269
|
+
}
|
|
264
270
|
}
|
|
265
271
|
|
|
266
272
|
// For deserializing JSON.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Wraps an async iterable iterator such that it filters values based on a predicate. */
|
|
2
|
+
export async function* filter<T>(
|
|
3
|
+
iterator: AsyncIterableIterator<T>,
|
|
4
|
+
predicate: (item: T) => boolean | Promise<boolean>,
|
|
5
|
+
): AsyncIterableIterator<T> {
|
|
6
|
+
for await (const item of iterator) {
|
|
7
|
+
if (await predicate(item)) {
|
|
8
|
+
yield item;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { filter } from './filter.js';
|
package/src/log/pino-logger.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type { Writable } from 'stream';
|
|
|
5
5
|
import { inspect } from 'util';
|
|
6
6
|
|
|
7
7
|
import { compactArray } from '../collection/array.js';
|
|
8
|
-
import {
|
|
8
|
+
import type { EnvVar } from '../config/index.js';
|
|
9
|
+
import { parseBooleanEnv } from '../config/parse-env.js';
|
|
9
10
|
import { GoogleCloudLoggerConfig } from './gcloud-logger-config.js';
|
|
10
11
|
import { getLogLevelFromFilters, parseEnv } from './log-filters.js';
|
|
11
12
|
import type { LogLevel } from './log-levels.js';
|
package/src/schemas/schemas.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { EpochNumber, EpochNumberSchema } from '../branded-types/epoch.js';
|
|
|
4
4
|
import { SlotNumber, SlotNumberSchema } from '../branded-types/slot.js';
|
|
5
5
|
import { Buffer32 } from '../buffer/buffer32.js';
|
|
6
6
|
import { SecretValue } from '../config/secret_value.js';
|
|
7
|
+
import { Fq, Fr } from '../curves/bn254/field.js';
|
|
8
|
+
import { Point } from '../curves/grumpkin/point.js';
|
|
7
9
|
import { EthAddress } from '../eth-address/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { Point } from '../fields/point.js';
|
|
10
|
-
import { isHex, withoutHexPrefix } from '../string/index.js';
|
|
10
|
+
import { isHex, withHexPrefix, withoutHexPrefix } from '../string/index.js';
|
|
11
11
|
import { bufferSchema, hexSchema } from './utils.js';
|
|
12
12
|
|
|
13
13
|
export const schemas = {
|
|
@@ -58,6 +58,14 @@ export const schemas = {
|
|
|
58
58
|
.max(2 ** 32 - 1),
|
|
59
59
|
),
|
|
60
60
|
|
|
61
|
+
/** Coerces input to UInt64. */
|
|
62
|
+
UInt64: z.union([z.bigint(), z.number(), z.string()]).pipe(
|
|
63
|
+
z.coerce
|
|
64
|
+
.bigint()
|
|
65
|
+
.min(0n)
|
|
66
|
+
.max(2n ** 64n - 1n),
|
|
67
|
+
),
|
|
68
|
+
|
|
61
69
|
/** Accepts a hex string as a Buffer32 type. */
|
|
62
70
|
Buffer32: z.string().refine(isHex, 'Not a valid hex string').transform(Buffer32.fromString),
|
|
63
71
|
|
|
@@ -74,6 +82,9 @@ export const schemas = {
|
|
|
74
82
|
/** Hex string with an optional 0x prefix which gets removed as part of the parsing. */
|
|
75
83
|
HexString: hexSchema,
|
|
76
84
|
|
|
85
|
+
/** Hex string with an optional 0x prefix which gets enforced as part of the parsing. */
|
|
86
|
+
HexStringWith0x: z.string().refine(isHex, 'Not a valid hex string').transform(withHexPrefix),
|
|
87
|
+
|
|
77
88
|
/** A secret config value */
|
|
78
89
|
SecretValue: SecretValue.schema,
|
|
79
90
|
};
|
package/src/schemas/types.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
|
|
3
3
|
export type ZodFor<T> = ZodType<T, any, any>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a schema validator that enforces all properties of type T are present in the schema.
|
|
7
|
+
* This provides compile-time safety to ensure schemas don't miss optional properties.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* interface MyConfig {
|
|
12
|
+
* foo: string;
|
|
13
|
+
* bar?: number;
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* // ✅ This will work - all keys present
|
|
17
|
+
* const schema1 = zodFor<MyConfig>()(z.object({
|
|
18
|
+
* foo: z.string(),
|
|
19
|
+
* bar: z.number().optional(),
|
|
20
|
+
* }));
|
|
21
|
+
*
|
|
22
|
+
* // ❌ This will error - 'bar' is missing
|
|
23
|
+
* const schema2 = zodFor<MyConfig>()(z.object({
|
|
24
|
+
* foo: z.string(),
|
|
25
|
+
* }));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function zodFor<T>() {
|
|
29
|
+
return (schema => schema) as <S extends ZodType<any, any, any>>(
|
|
30
|
+
schema: keyof T extends keyof S['_output']
|
|
31
|
+
? keyof S['_output'] extends keyof T
|
|
32
|
+
? S
|
|
33
|
+
: S & { __error__: 'Schema has extra keys not in type'; __extra__: Exclude<keyof S['_output'], keyof T> }
|
|
34
|
+
: S & { __error__: 'Schema is missing keys from type'; __missing__: Exclude<keyof T, keyof S['_output']> },
|
|
35
|
+
) => S;
|
|
36
|
+
}
|
package/src/sleep/index.ts
CHANGED
|
@@ -73,3 +73,9 @@ export class InterruptibleSleep {
|
|
|
73
73
|
export function sleep<T>(ms: number, returnValue?: T): Promise<T> {
|
|
74
74
|
return new Promise(resolve => setTimeout(() => resolve(returnValue as T), ms));
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Sleeps until the target date */
|
|
78
|
+
export function sleepUntil<T>(target: Date, now: Date, returnValue?: T): Promise<T> {
|
|
79
|
+
const ms = target.getTime() - now.getTime();
|
|
80
|
+
return sleep(ms, returnValue);
|
|
81
|
+
}
|
package/src/timer/date.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { pedersenHash as pedersenHashArray
|
|
1
|
+
import { pedersenHash as pedersenHashArray } from '@aztec/foundation/crypto/pedersen';
|
|
2
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
3
|
+
import { sha256Trunc } from '@aztec/foundation/crypto/sha256';
|
|
2
4
|
|
|
3
5
|
import type { AsyncHasher, Hasher } from './hasher.js';
|
|
4
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '../
|
|
1
|
+
import { Fr } from '../curves/bn254/index.js';
|
|
2
2
|
import { assertLength } from '../serialize/index.js';
|
|
3
3
|
import type { IndexedTreeLeafPreimage } from './indexed_tree_leaf.js';
|
|
4
4
|
import { MembershipWitness } from './membership_witness.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertMemberLength } from '../array/array.js';
|
|
2
2
|
import { toBigIntBE, toBufferBE } from '../bigint-buffer/index.js';
|
|
3
|
-
import { Fr } from '../
|
|
3
|
+
import { Fr } from '../curves/bn254/field.js';
|
|
4
4
|
import { schemas } from '../schemas/schemas.js';
|
|
5
5
|
import { BufferReader, type Tuple, serializeToBuffer } from '../serialize/index.js';
|
|
6
6
|
import type { SiblingPath } from './sibling_path.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { makeTuple } from '../array/array.js';
|
|
2
|
-
import { pedersenHash } from '../crypto/index.js';
|
|
3
|
-
import { Fr } from '../
|
|
2
|
+
import { pedersenHash } from '../crypto/pedersen/index.js';
|
|
3
|
+
import { Fr } from '../curves/bn254/index.js';
|
|
4
4
|
import { schemas } from '../schemas/index.js';
|
|
5
5
|
import {
|
|
6
6
|
type Tuple,
|
|
@@ -4,12 +4,16 @@ import {
|
|
|
4
4
|
poseidonMerkleHash,
|
|
5
5
|
shaMerkleHash,
|
|
6
6
|
} from './balanced_merkle_tree.js';
|
|
7
|
+
import { UnbalancedMerkleTreeCalculator } from './unbalanced_merkle_tree_calculator.js';
|
|
7
8
|
|
|
8
9
|
export const computeUnbalancedShaRoot = (leaves: Buffer[]) => computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
|
|
9
10
|
|
|
10
11
|
export const computeUnbalancedPoseidonRoot = async (leaves: Buffer[]) =>
|
|
11
12
|
await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
12
13
|
|
|
14
|
+
export const computeCompressedUnbalancedShaRoot = (leaves: Buffer[]) =>
|
|
15
|
+
computeCompressedUnbalancedMerkleTreeRoot(leaves);
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* Computes the Merkle root of an unbalanced tree.
|
|
15
19
|
*
|
|
@@ -101,6 +105,16 @@ export async function computeUnbalancedMerkleTreeRootAsync(
|
|
|
101
105
|
return root!;
|
|
102
106
|
}
|
|
103
107
|
|
|
108
|
+
export function computeCompressedUnbalancedMerkleTreeRoot(
|
|
109
|
+
leaves: Buffer[],
|
|
110
|
+
valueToCompress = Buffer.alloc(32),
|
|
111
|
+
emptyRoot = Buffer.alloc(32),
|
|
112
|
+
hasher = shaMerkleHash,
|
|
113
|
+
): Buffer {
|
|
114
|
+
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
115
|
+
return calculator.getRoot();
|
|
116
|
+
}
|
|
117
|
+
|
|
104
118
|
/// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
|
|
105
119
|
/// the left most subtree of the wonky tree with a total of `numLeaves` leaves.
|
|
106
120
|
///
|
|
@@ -3,16 +3,6 @@ import type { Hasher } from './hasher.js';
|
|
|
3
3
|
import { SiblingPath } from './sibling_path.js';
|
|
4
4
|
import { type TreeNodeLocation, UnbalancedTreeStore } from './unbalanced_tree_store.js';
|
|
5
5
|
|
|
6
|
-
export function computeCompressedUnbalancedMerkleTreeRoot(
|
|
7
|
-
leaves: Buffer[],
|
|
8
|
-
valueToCompress = Buffer.alloc(32),
|
|
9
|
-
emptyRoot = Buffer.alloc(32),
|
|
10
|
-
hasher?: Hasher['hash'],
|
|
11
|
-
): Buffer {
|
|
12
|
-
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
13
|
-
return calculator.getRoot();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
6
|
interface TreeNode {
|
|
17
7
|
value: Buffer;
|
|
18
8
|
leafIndex?: number;
|
package/src/types/index.ts
CHANGED
|
@@ -19,6 +19,11 @@ export function unfreeze<T>(obj: T): Writeable<T> {
|
|
|
19
19
|
return obj as Writeable<T>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** Is defined type guard */
|
|
23
|
+
export function isDefined<T>(value: T | undefined): value is T {
|
|
24
|
+
return value !== undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
/** Resolves a record-like type. Lifted from viem. */
|
|
23
28
|
export type Prettify<T> = {
|
|
24
29
|
[K in keyof T]: T[K];
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BN254 utility functions for point operations.
|
|
3
|
-
* Provides compression, decompression, and public key generation for the BN254 curve.
|
|
4
|
-
* Uses the bb.js Barretenberg backend for point operations.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Generate a compressed BN254 G1 public key from a private key.
|
|
8
|
-
*
|
|
9
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
10
|
-
* @returns Compressed G1 point (32 bytes with sign bit in MSB)
|
|
11
|
-
*/
|
|
12
|
-
export declare function computeBn254G1PublicKeyCompressed(privateKeyHex: string): Promise<string>;
|
|
13
|
-
/**
|
|
14
|
-
* Generate uncompressed BN254 G1 public key from a private key.
|
|
15
|
-
*
|
|
16
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
17
|
-
* @returns G1 point in affine coordinates
|
|
18
|
-
*/
|
|
19
|
-
export declare function computeBn254G1PublicKey(privateKeyHex: string): Promise<{
|
|
20
|
-
x: bigint;
|
|
21
|
-
y: bigint;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* Generate BN254 G2 public key from a private key.
|
|
25
|
-
*
|
|
26
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
27
|
-
* @returns G2 point in affine coordinates
|
|
28
|
-
*/
|
|
29
|
-
export declare function computeBn254G2PublicKey(privateKeyHex: string): Promise<{
|
|
30
|
-
x: {
|
|
31
|
-
c0: bigint;
|
|
32
|
-
c1: bigint;
|
|
33
|
-
};
|
|
34
|
-
y: {
|
|
35
|
-
c0: bigint;
|
|
36
|
-
c1: bigint;
|
|
37
|
-
};
|
|
38
|
-
}>;
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm4yNTRfdXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jcnlwdG8vYm4yNTQvYm4yNTRfdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0E7Ozs7R0FJRztBQUVIOzs7OztHQUtHO0FBQ0gsd0JBQXNCLGlDQUFpQyxDQUFDLGFBQWEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQVU5RjtBQUVEOzs7OztHQUtHO0FBQ0gsd0JBQXNCLHVCQUF1QixDQUFDLGFBQWEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDO0lBQUUsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUFDLENBQUMsRUFBRSxNQUFNLENBQUE7Q0FBRSxDQUFDLENBUXRHO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBc0IsdUJBQXVCLENBQUMsYUFBYSxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUM7SUFDNUUsQ0FBQyxFQUFFO1FBQUUsRUFBRSxFQUFFLE1BQU0sQ0FBQztRQUFDLEVBQUUsRUFBRSxNQUFNLENBQUE7S0FBRSxDQUFDO0lBQzlCLENBQUMsRUFBRTtRQUFFLEVBQUUsRUFBRSxNQUFNLENBQUM7UUFBQyxFQUFFLEVBQUUsTUFBTSxDQUFBO0tBQUUsQ0FBQztDQUMvQixDQUFDLENBV0QifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bn254_utils.d.ts","sourceRoot":"","sources":["../../../src/crypto/bn254/bn254_utils.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAsB,iCAAiC,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAU9F;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAQtG;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5E,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/B,CAAC,CAWD"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Fr } from '../../fields/fields.js';
|
|
2
|
-
import { Bn254G1Point, Bn254G2Point } from './index.js';
|
|
3
|
-
/**
|
|
4
|
-
* BN254 utility functions for point operations.
|
|
5
|
-
* Provides compression, decompression, and public key generation for the BN254 curve.
|
|
6
|
-
* Uses the bb.js Barretenberg backend for point operations.
|
|
7
|
-
*/ /**
|
|
8
|
-
* Generate a compressed BN254 G1 public key from a private key.
|
|
9
|
-
*
|
|
10
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
11
|
-
* @returns Compressed G1 point (32 bytes with sign bit in MSB)
|
|
12
|
-
*/ export async function computeBn254G1PublicKeyCompressed(privateKeyHex) {
|
|
13
|
-
const sk = BigInt(privateKeyHex);
|
|
14
|
-
const skReduced = sk % Fr.MODULUS;
|
|
15
|
-
// Generate G1 point on BN254 curve using bb.js
|
|
16
|
-
const scalar = Fr.fromString(skReduced.toString());
|
|
17
|
-
const pk1 = await Bn254G1Point.generator(scalar);
|
|
18
|
-
// Compress the point using the primitive method
|
|
19
|
-
return '0x' + pk1.compress().toString('hex');
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Generate uncompressed BN254 G1 public key from a private key.
|
|
23
|
-
*
|
|
24
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
25
|
-
* @returns G1 point in affine coordinates
|
|
26
|
-
*/ export async function computeBn254G1PublicKey(privateKeyHex) {
|
|
27
|
-
const sk = BigInt(privateKeyHex);
|
|
28
|
-
const skReduced = sk % Fr.MODULUS;
|
|
29
|
-
const scalar = Fr.fromString(skReduced.toString());
|
|
30
|
-
const pk1 = await Bn254G1Point.generator(scalar);
|
|
31
|
-
return {
|
|
32
|
-
x: pk1.x.toBigInt(),
|
|
33
|
-
y: pk1.y.toBigInt()
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Generate BN254 G2 public key from a private key.
|
|
38
|
-
*
|
|
39
|
-
* @param privateKeyHex - Private key as 0x-prefixed hex string
|
|
40
|
-
* @returns G2 point in affine coordinates
|
|
41
|
-
*/ export async function computeBn254G2PublicKey(privateKeyHex) {
|
|
42
|
-
const sk = BigInt(privateKeyHex);
|
|
43
|
-
const skReduced = sk % Fr.MODULUS;
|
|
44
|
-
const scalar = Fr.fromString(skReduced.toString());
|
|
45
|
-
const pk2 = await Bn254G2Point.generator(scalar);
|
|
46
|
-
return {
|
|
47
|
-
x: {
|
|
48
|
-
c0: pk2.x[0].toBigInt(),
|
|
49
|
-
c1: pk2.x[1].toBigInt()
|
|
50
|
-
},
|
|
51
|
-
y: {
|
|
52
|
-
c0: pk2.y[0].toBigInt(),
|
|
53
|
-
c1: pk2.y[1].toBigInt()
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
package/dest/crypto/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './keccak/index.js';
|
|
2
|
-
export * from './random/index.js';
|
|
3
|
-
export * from './sha256/index.js';
|
|
4
|
-
export * from './sha512/index.js';
|
|
5
|
-
export * from './pedersen/index.js';
|
|
6
|
-
export * from './poseidon/index.js';
|
|
7
|
-
export * from './secp256k1-signer/index.js';
|
|
8
|
-
export * from './keys/index.js';
|
|
9
|
-
export * from './aes128/index.js';
|
|
10
|
-
export * from './bn254/index.js';
|
|
11
|
-
export * from './grumpkin/index.js';
|
|
12
|
-
export * from './ecdsa/index.js';
|
|
13
|
-
export * from './secp256k1/index.js';
|
|
14
|
-
export * from './schnorr/index.js';
|
|
15
|
-
export * from './signature/index.js';
|
|
16
|
-
export * from './bls/index.js';
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jcnlwdG8vaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyw2QkFBNkIsQ0FBQztBQUM1QyxjQUFjLGlCQUFpQixDQUFDO0FBQ2hDLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxrQkFBa0IsQ0FBQztBQUNqQyxjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLGNBQWMsa0JBQWtCLENBQUM7QUFDakMsY0FBYyxzQkFBc0IsQ0FBQztBQUNyQyxjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsc0JBQXNCLENBQUM7QUFDckMsY0FBYyxnQkFBZ0IsQ0FBQyJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC"}
|
package/dest/crypto/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from './keccak/index.js';
|
|
2
|
-
export * from './random/index.js';
|
|
3
|
-
export * from './sha256/index.js';
|
|
4
|
-
export * from './sha512/index.js';
|
|
5
|
-
export * from './pedersen/index.js';
|
|
6
|
-
export * from './poseidon/index.js';
|
|
7
|
-
export * from './secp256k1-signer/index.js';
|
|
8
|
-
export * from './keys/index.js';
|
|
9
|
-
export * from './aes128/index.js';
|
|
10
|
-
export * from './bn254/index.js';
|
|
11
|
-
export * from './grumpkin/index.js';
|
|
12
|
-
export * from './ecdsa/index.js';
|
|
13
|
-
export * from './secp256k1/index.js';
|
|
14
|
-
export * from './schnorr/index.js';
|
|
15
|
-
export * from './signature/index.js';
|
|
16
|
-
export * from './bls/index.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bls12_fields.d.ts","sourceRoot":"","sources":["../../src/fields/bls12_fields.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAK/B,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAcjC;;GAEG;AACH,8BAAsB,UAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,CAAS;IAE1B,SAAS,aAAa,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAiBpD;IAED,SAAS,CAAC,QAAQ,CAAC,OAAO,IAAI,MAAM,CAAC;IACrC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,IAAI,MAAM,CAKjB;IAED,QAAQ,IAAI,KAAK,MAAM,EAAE,CAExB;IAED,QAAQ,IAAI,MAAM,CAQjB;IAED,YAAY,IAAI;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAUlC;IAED,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAE/B;IAED,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAE3B;IAED,MAAM,IAAI,OAAO,CAEhB;IAED,OAAO,IAAI,OAAO,CAEjB;IAED,UAAU,IAAI,OAAO,CAIpB;IAED,cAAc,IAAI,MAAM,CAEvB;IAED,OAAO,SAEN;C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