Skip to content

Commit c7bc073

Browse files
authored
🤖 Merge PR DefinitelyTyped#66676 Create new circomlibjs package by @cedoor
* chore: create circomlibjs types * test: add some tests to circomlibjs types * chore: add export keyword to interfaces * chore: add more types to circomlibjs * test: add more tests * chore: add more types * test: add more tests * chore: update Poseidon type * chore: support esm/cjs entry points * chore: add more specific types * chore: add new definition owner
1 parent 6dc5f15 commit c7bc073

6 files changed

Lines changed: 537 additions & 0 deletions

File tree

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import {
2+
SMT,
3+
SMTMemDb,
4+
buildSMT,
5+
buildBabyjub,
6+
buildEddsa,
7+
buildMimc7,
8+
buildPoseidon,
9+
buildMimcSponge,
10+
buildPedersenHash,
11+
evmasm,
12+
Point,
13+
} from 'circomlibjs';
14+
15+
const bigNumber = new Uint8Array([1]);
16+
const point = [bigNumber, bigNumber] as Point;
17+
const signature = {
18+
R8: point,
19+
S: BigInt(3),
20+
};
21+
22+
const db = new SMTMemDb('F');
23+
24+
new SMT(
25+
db,
26+
1,
27+
(left, right) => bigNumber,
28+
(key, value) => bigNumber,
29+
'F',
30+
);
31+
32+
new evmasm();
33+
34+
(async () => {
35+
const smt = await buildSMT(db, 0);
36+
37+
// $ExpectType any
38+
smt.delete(1);
39+
// $ExpectType any
40+
smt.find(1);
41+
// $ExpectType any
42+
smt.insert(1, 2);
43+
// $ExpectType any
44+
smt.update(1, 3);
45+
46+
// $ExpectType BabyJub
47+
const babyJub = await buildBabyjub();
48+
49+
// $ExpectType Point
50+
babyJub.addPoint(point, point);
51+
// $ExpectType Point
52+
babyJub.mulPointEscalar(point, 3);
53+
// $ExpectType boolean
54+
babyJub.inCurve(point);
55+
// $ExpectType boolean
56+
babyJub.inSubgroup(point);
57+
// $ExpectType Uint8Array
58+
babyJub.packPoint(point);
59+
// $ExpectType Point
60+
babyJub.unpackPoint(bigNumber);
61+
62+
// $ExpectType Eddsa
63+
const eddsa = await buildEddsa();
64+
65+
// $ExpectType Uint8Array
66+
eddsa.pruneBuffer(new Uint8Array([0]));
67+
// $ExpectType Point
68+
eddsa.prv2pub('sk');
69+
// $ExpectType Signature
70+
eddsa.signPedersen('sk', bigNumber);
71+
// $ExpectType Signature
72+
eddsa.signPoseidon('sk', bigNumber);
73+
// $ExpectType Signature
74+
eddsa.signMiMC('sk', bigNumber);
75+
// $ExpectType Signature
76+
eddsa.signMiMCSponge('sk', bigNumber);
77+
// $ExpectType boolean
78+
eddsa.verifyPedersen(bigNumber, signature, point);
79+
// $ExpectType boolean
80+
eddsa.verifyPoseidon(bigNumber, signature, point);
81+
// $ExpectType boolean
82+
eddsa.verifyMiMC(bigNumber, signature, point);
83+
// $ExpectType boolean
84+
eddsa.verifyMiMCSponge(bigNumber, signature, point);
85+
// $ExpectType Uint8Array
86+
const buff2 = eddsa.packSignature(signature);
87+
// $ExpectType Signature
88+
eddsa.unpackSignature(buff2);
89+
90+
// $ExpectType Mimc7
91+
const mimc7 = await buildMimc7();
92+
93+
// $ExpectType bigint
94+
mimc7.getIV('mimc');
95+
mimc7.getIV();
96+
// $ExpectType Uint8Array[]
97+
mimc7.getConstants('mimc', 3);
98+
mimc7.getConstants('mimc');
99+
mimc7.getConstants();
100+
// $ExpectType Uint8Array
101+
mimc7.hash(3, 2);
102+
// $ExpectType Uint8Array
103+
mimc7.multiHash([1, 3], 3);
104+
mimc7.multiHash([1, 3]);
105+
106+
// $ExpectType MimcSponge
107+
const mimcSponge = await buildMimcSponge();
108+
109+
// $ExpectType bigint
110+
mimcSponge.getIV('mimcsponge');
111+
mimcSponge.getIV();
112+
// $ExpectType Uint8Array[]
113+
mimcSponge.getConstants('mimcsponge', 3);
114+
mimcSponge.getConstants('mimcsponge');
115+
mimcSponge.getConstants();
116+
// $ExpectType Uint8Array
117+
mimcSponge.hash(3, 3, 2);
118+
// $ExpectType Uint8Array
119+
mimcSponge.multiHash([1, 3], 3, 3);
120+
mimcSponge.multiHash([1, 3], 3);
121+
mimcSponge.multiHash([1, 3]);
122+
123+
// $ExpectType Poseidon
124+
const poseidon = await buildPoseidon();
125+
126+
// $ExpectType any
127+
poseidon.F;
128+
// $ExpectType Uint8Array
129+
poseidon([1, 3], 3, 4);
130+
poseidon([1, 3], 3);
131+
poseidon([1, 3]);
132+
133+
// $ExpectType PedersenHash
134+
const pederson = await buildPedersenHash();
135+
136+
// $ExpectType any
137+
pederson.baseHash('blake', 3);
138+
pederson.baseHash('blake2b', 4);
139+
// $ExpectType boolean[]
140+
pederson.buffer2bits(new Uint8Array([1]));
141+
// $ExpectType Uint8Array
142+
pederson.hash(new Uint8Array([2]), {});
143+
pederson.hash(new Uint8Array([2]));
144+
// $ExpectType Point
145+
pederson.getBasePoint('blake', 3);
146+
pederson.getBasePoint('blake2b', 3);
147+
// $ExpectType string
148+
pederson.padLeftZeros(3, 4);
149+
})();

0 commit comments

Comments
 (0)