circomlibjs-hinkal-fork 0.0.1 → 0.0.2
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/build/main.cjs +25567 -25971
- package/main.js +0 -2
- package/package.json +1 -1
- package/src/eddsa.js +0 -286
- package/src/pedersen_hash.js +0 -132
- package/src/testblake.js +0 -18
package/main.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export {default as buildBabyjub} from "./src/babyjub.js";
|
|
2
|
-
export {default as buildEddsa} from "./src/eddsa.js";
|
|
3
2
|
export {default as evmasm} from "./src/evmasm.js";
|
|
4
3
|
|
|
5
4
|
export {default as buildMimc7} from "./src/mimc7.js";
|
|
@@ -10,7 +9,6 @@ export {default as buildMimcSponge} from "./src/mimcsponge.js";
|
|
|
10
9
|
import * as _mimcSpongeContract from "./src/mimcsponge_gencontract.js";
|
|
11
10
|
export const mimcSpongecontract=_mimcSpongeContract;
|
|
12
11
|
|
|
13
|
-
export {default as buildPedersenHash} from "./src/pedersen_hash.js";
|
|
14
12
|
|
|
15
13
|
export { buildPoseidon, buildPoseidonWasm } from "./src/poseidon_wasm.js";
|
|
16
14
|
import * as _poseidonContract from "./src/poseidon_gencontract.js";
|
package/package.json
CHANGED
package/src/eddsa.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import { Scalar } from "ffjavascript";
|
|
2
|
-
import buildBabyJub from "./babyjub.js";
|
|
3
|
-
import buildPedersenHash from "./pedersen_hash.js";
|
|
4
|
-
import buildMimc7 from "./mimc7.js";
|
|
5
|
-
import { buildPoseidon } from "./poseidon_wasm.js";
|
|
6
|
-
import buildMimcSponge from "./mimcsponge.js";
|
|
7
|
-
import createBlakeHash from "blake-hash";
|
|
8
|
-
import {Buffer} from 'buffer';
|
|
9
|
-
|
|
10
|
-
export default async function buildEddsa() {
|
|
11
|
-
const babyJub = await buildBabyJub("bn128");
|
|
12
|
-
const pedersenHash = await buildPedersenHash();
|
|
13
|
-
const mimc7 = await buildMimc7();
|
|
14
|
-
const poseidon = await buildPoseidon();
|
|
15
|
-
const mimcSponge = await buildMimcSponge();
|
|
16
|
-
return new Eddsa(babyJub, pedersenHash, mimc7, poseidon, mimcSponge);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class Eddsa {
|
|
20
|
-
|
|
21
|
-
constructor(babyJub, pedersenHash, mimc7, poseidon, mimcSponge) {
|
|
22
|
-
this.babyJub = babyJub;
|
|
23
|
-
this.pedersenHash = pedersenHash;
|
|
24
|
-
this.mimc7 = mimc7;
|
|
25
|
-
this.poseidon = poseidon;
|
|
26
|
-
this.mimcSponge = mimcSponge;
|
|
27
|
-
this.F = babyJub.F;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pruneBuffer(buff) {
|
|
31
|
-
buff[0] = buff[0] & 0xF8;
|
|
32
|
-
buff[31] = buff[31] & 0x7F;
|
|
33
|
-
buff[31] = buff[31] | 0x40;
|
|
34
|
-
return buff;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
prv2pub(prv) {
|
|
38
|
-
const F = this.babyJub.F;
|
|
39
|
-
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
|
|
40
|
-
let s = Scalar.fromRprLE(sBuff, 0, 32);
|
|
41
|
-
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, Scalar.shr(s,3));
|
|
42
|
-
return A;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
signPedersen(prv, msg) {
|
|
46
|
-
const F = this.babyJub.F;
|
|
47
|
-
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
|
|
48
|
-
const s = Scalar.fromRprLE(sBuff, 0, 32);
|
|
49
|
-
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, Scalar.shr(s, 3));
|
|
50
|
-
|
|
51
|
-
const composeBuff = new Uint8Array(32 + msg.length);
|
|
52
|
-
composeBuff.set(sBuff.slice(32), 0);
|
|
53
|
-
composeBuff.set(msg, 32);
|
|
54
|
-
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
|
|
55
|
-
let r = Scalar.mod(Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
|
|
56
|
-
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);
|
|
57
|
-
const R8p = this.babyJub.packPoint(R8);
|
|
58
|
-
const Ap = this.babyJub.packPoint(A);
|
|
59
|
-
|
|
60
|
-
const composeBuff2 = new Uint8Array(64 + msg.length);
|
|
61
|
-
composeBuff2.set(R8p, 0);
|
|
62
|
-
composeBuff2.set(Ap, 32);
|
|
63
|
-
composeBuff2.set(msg, 64);
|
|
64
|
-
|
|
65
|
-
const hmBuff = this.pedersenHash.hash(composeBuff2);
|
|
66
|
-
const hm = Scalar.fromRprLE(hmBuff, 0, 32);
|
|
67
|
-
|
|
68
|
-
const S = Scalar.mod(
|
|
69
|
-
Scalar.add(
|
|
70
|
-
r,
|
|
71
|
-
Scalar.mul(hm, s)
|
|
72
|
-
),
|
|
73
|
-
this.babyJub.subOrder
|
|
74
|
-
)
|
|
75
|
-
return {
|
|
76
|
-
R8: R8,
|
|
77
|
-
S: S
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
signMiMC(prv, msg) {
|
|
82
|
-
const F = this.babyJub.F;
|
|
83
|
-
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
|
|
84
|
-
const s = Scalar.fromRprLE(sBuff, 0, 32);
|
|
85
|
-
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, Scalar.shr(s, 3));
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const composeBuff = new Uint8Array(32 + msg.length);
|
|
89
|
-
composeBuff.set(sBuff.slice(32), 0);
|
|
90
|
-
F.toRprLE(composeBuff, 32, msg);
|
|
91
|
-
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
|
|
92
|
-
let r = Scalar.mod(Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
|
|
93
|
-
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);
|
|
94
|
-
|
|
95
|
-
const hm = this.mimc7.multiHash([R8[0], R8[1], A[0], A[1], msg]);
|
|
96
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
97
|
-
const S = Scalar.mod(
|
|
98
|
-
Scalar.add(
|
|
99
|
-
r,
|
|
100
|
-
Scalar.mul(hms, s)
|
|
101
|
-
),
|
|
102
|
-
this.babyJub.subOrder
|
|
103
|
-
)
|
|
104
|
-
return {
|
|
105
|
-
R8: R8,
|
|
106
|
-
S: S
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
signMiMCSponge(prv, msg) {
|
|
111
|
-
const F = this.babyJub.F;
|
|
112
|
-
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
|
|
113
|
-
const s = Scalar.fromRprLE(sBuff, 0, 32);
|
|
114
|
-
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, Scalar.shr(s, 3));
|
|
115
|
-
|
|
116
|
-
const composeBuff = new Uint8Array(32 + msg.length);
|
|
117
|
-
composeBuff.set(sBuff.slice(32), 0);
|
|
118
|
-
F.toRprLE(composeBuff, 32, msg);
|
|
119
|
-
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
|
|
120
|
-
let r = Scalar.mod(Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
|
|
121
|
-
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);
|
|
122
|
-
|
|
123
|
-
const hm = this.mimcSponge.multiHash([R8[0], R8[1], A[0], A[1], msg]);
|
|
124
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
125
|
-
const S = Scalar.mod(
|
|
126
|
-
Scalar.add(
|
|
127
|
-
r,
|
|
128
|
-
Scalar.mul(hms, s)
|
|
129
|
-
),
|
|
130
|
-
this.babyJub.subOrder
|
|
131
|
-
)
|
|
132
|
-
return {
|
|
133
|
-
R8: R8,
|
|
134
|
-
S: S
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
signPoseidon(prv, msg) {
|
|
139
|
-
const F = this.babyJub.F;
|
|
140
|
-
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
|
|
141
|
-
const s = Scalar.fromRprLE(sBuff, 0, 32);
|
|
142
|
-
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, Scalar.shr(s, 3));
|
|
143
|
-
|
|
144
|
-
const composeBuff = new Uint8Array(32 + msg.length);
|
|
145
|
-
composeBuff.set(sBuff.slice(32), 0);
|
|
146
|
-
F.toRprLE(composeBuff, 32, msg);
|
|
147
|
-
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
|
|
148
|
-
let r = Scalar.mod(Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
|
|
149
|
-
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);
|
|
150
|
-
|
|
151
|
-
const hm = this.poseidon([R8[0], R8[1], A[0], A[1], msg]);
|
|
152
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
153
|
-
const S = Scalar.mod(
|
|
154
|
-
Scalar.add(
|
|
155
|
-
r,
|
|
156
|
-
Scalar.mul(hms, s)
|
|
157
|
-
),
|
|
158
|
-
this.babyJub.subOrder
|
|
159
|
-
)
|
|
160
|
-
return {
|
|
161
|
-
R8: R8,
|
|
162
|
-
S: S
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
verifyPedersen(msg, sig, A) {
|
|
167
|
-
// Check parameters
|
|
168
|
-
if (typeof sig != "object") return false;
|
|
169
|
-
if (!Array.isArray(sig.R8)) return false;
|
|
170
|
-
if (sig.R8.length!= 2) return false;
|
|
171
|
-
if (!this.babyJub.inCurve(sig.R8)) return false;
|
|
172
|
-
if (!Array.isArray(A)) return false;
|
|
173
|
-
if (A.length!= 2) return false;
|
|
174
|
-
if (!this.babyJub.inCurve(A)) return false;
|
|
175
|
-
if (Scalar.geq(sig.S, this.babyJub.subOrder)) return false;
|
|
176
|
-
|
|
177
|
-
const R8p = this.babyJub.packPoint(sig.R8);
|
|
178
|
-
const Ap = this.babyJub.packPoint(A);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const composeBuff2 = new Uint8Array(64 + msg.length);
|
|
182
|
-
composeBuff2.set(R8p, 0);
|
|
183
|
-
composeBuff2.set(Ap, 32);
|
|
184
|
-
composeBuff2.set(msg, 64);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const hmBuff = this.pedersenHash.hash(composeBuff2);
|
|
188
|
-
const hm = Scalar.fromRprLE(hmBuff, 0, 32);
|
|
189
|
-
|
|
190
|
-
const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S);
|
|
191
|
-
let Pright = this.babyJub.mulPointEscalar(A, Scalar.mul(hm,8));
|
|
192
|
-
Pright = this.babyJub.addPoint(sig.R8, Pright);
|
|
193
|
-
|
|
194
|
-
if (!this.babyJub.F.eq(Pleft[0],Pright[0])) return false;
|
|
195
|
-
if (!this.babyJub.F.eq(Pleft[1],Pright[1])) return false;
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
verifyMiMC(msg, sig, A) {
|
|
200
|
-
// Check parameters
|
|
201
|
-
if (typeof sig != "object") return false;
|
|
202
|
-
if (!Array.isArray(sig.R8)) return false;
|
|
203
|
-
if (sig.R8.length!= 2) return false;
|
|
204
|
-
if (!this.babyJub.inCurve(sig.R8)) return false;
|
|
205
|
-
if (!Array.isArray(A)) return false;
|
|
206
|
-
if (A.length!= 2) return false;
|
|
207
|
-
if (!this.babyJub.inCurve(A)) return false;
|
|
208
|
-
if (sig.S>= this.babyJub.subOrder) return false;
|
|
209
|
-
|
|
210
|
-
const hm = this.mimc7.multiHash([sig.R8[0], sig.R8[1], A[0], A[1], msg]);
|
|
211
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
212
|
-
|
|
213
|
-
const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S);
|
|
214
|
-
let Pright = this.babyJub.mulPointEscalar(A, Scalar.mul(hms, 8));
|
|
215
|
-
Pright = this.babyJub.addPoint(sig.R8, Pright);
|
|
216
|
-
|
|
217
|
-
if (!this.babyJub.F.eq(Pleft[0],Pright[0])) return false;
|
|
218
|
-
if (!this.babyJub.F.eq(Pleft[1],Pright[1])) return false;
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
verifyPoseidon(msg, sig, A) {
|
|
223
|
-
|
|
224
|
-
// Check parameters
|
|
225
|
-
if (typeof sig != "object") return false;
|
|
226
|
-
if (!Array.isArray(sig.R8)) return false;
|
|
227
|
-
if (sig.R8.length!= 2) return false;
|
|
228
|
-
if (!this.babyJub.inCurve(sig.R8)) return false;
|
|
229
|
-
if (!Array.isArray(A)) return false;
|
|
230
|
-
if (A.length!= 2) return false;
|
|
231
|
-
if (!this.babyJub.inCurve(A)) return false;
|
|
232
|
-
if (sig.S>= this.babyJub.subOrder) return false;
|
|
233
|
-
|
|
234
|
-
const hm = this.poseidon([sig.R8[0], sig.R8[1], A[0], A[1], msg]);
|
|
235
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
236
|
-
|
|
237
|
-
const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S);
|
|
238
|
-
let Pright = this.babyJub.mulPointEscalar(A, Scalar.mul(hms, 8));
|
|
239
|
-
Pright = this.babyJub.addPoint(sig.R8, Pright);
|
|
240
|
-
|
|
241
|
-
if (!this.babyJub.F.eq(Pleft[0],Pright[0])) return false;
|
|
242
|
-
if (!this.babyJub.F.eq(Pleft[1],Pright[1])) return false;
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
verifyMiMCSponge(msg, sig, A) {
|
|
247
|
-
|
|
248
|
-
// Check parameters
|
|
249
|
-
if (typeof sig != "object") return false;
|
|
250
|
-
if (!Array.isArray(sig.R8)) return false;
|
|
251
|
-
if (sig.R8.length!= 2) return false;
|
|
252
|
-
if (!this.babyJub.inCurve(sig.R8)) return false;
|
|
253
|
-
if (!Array.isArray(A)) return false;
|
|
254
|
-
if (A.length!= 2) return false;
|
|
255
|
-
if (!this.babyJub.inCurve(A)) return false;
|
|
256
|
-
if (sig.S>= this.babyJub.subOrder) return false;
|
|
257
|
-
|
|
258
|
-
const hm = this.mimcSponge.multiHash([sig.R8[0], sig.R8[1], A[0], A[1], msg]);
|
|
259
|
-
const hms = Scalar.e(this.babyJub.F.toObject(hm));
|
|
260
|
-
|
|
261
|
-
const Pleft = this.babyJub.mulPointEscalar(this.babyJub.Base8, sig.S);
|
|
262
|
-
let Pright = this.babyJub.mulPointEscalar(A, Scalar.mul(hms, 8));
|
|
263
|
-
Pright = this.babyJub.addPoint(sig.R8, Pright);
|
|
264
|
-
|
|
265
|
-
if (!this.babyJub.F.eq(Pleft[0],Pright[0])) return false;
|
|
266
|
-
if (!this.babyJub.F.eq(Pleft[1],Pright[1])) return false;
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
packSignature(sig) {
|
|
271
|
-
const buff = new Uint8Array(64);
|
|
272
|
-
const R8p = this.babyJub.packPoint(sig.R8);
|
|
273
|
-
buff.set(R8p, 0)
|
|
274
|
-
const Sp = Scalar.toRprLE(buff, 32, sig.S, 32);
|
|
275
|
-
return buff;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
unpackSignature(sigBuff) {
|
|
279
|
-
return {
|
|
280
|
-
R8: this.babyJub.unpackPoint(sigBuff.slice(0,32)),
|
|
281
|
-
S: Scalar.fromRprLE(sigBuff, 32, 32)
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
package/src/pedersen_hash.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import buildBabyJub from "./babyjub.js";
|
|
2
|
-
import blake2b from "blake2b";
|
|
3
|
-
import createBlakeHash from "blake-hash";
|
|
4
|
-
import { Scalar } from "ffjavascript";
|
|
5
|
-
import {Buffer} from 'buffer';
|
|
6
|
-
|
|
7
|
-
const GENPOINT_PREFIX = "PedersenGenerator";
|
|
8
|
-
const windowSize = 4;
|
|
9
|
-
const nWindowsPerSegment = 50;
|
|
10
|
-
|
|
11
|
-
export default async function buildPedersenHash() {
|
|
12
|
-
const babyJub = await buildBabyJub();
|
|
13
|
-
return new PedersenHash(babyJub);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class PedersenHash {
|
|
17
|
-
|
|
18
|
-
constructor(babyJub) {
|
|
19
|
-
this.babyJub = babyJub;
|
|
20
|
-
this.bases = [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
baseHash(type, S) {
|
|
24
|
-
if (type == "blake") {
|
|
25
|
-
return createBlakeHash("blake256").update(S).digest();
|
|
26
|
-
} else if (type == "blake2b") {
|
|
27
|
-
return Buffer.from(blake2b(32).update(Buffer.from(S)).digest());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
hash(msg, options) {
|
|
32
|
-
options = options || {};
|
|
33
|
-
options.baseHash = options.baseHash || "blake";
|
|
34
|
-
const babyJub = this.babyJub;
|
|
35
|
-
const bitsPerSegment = windowSize*nWindowsPerSegment;
|
|
36
|
-
const bits = this.buffer2bits(msg);
|
|
37
|
-
|
|
38
|
-
const nSegments = Math.floor((bits.length - 1)/(windowSize*nWindowsPerSegment)) +1;
|
|
39
|
-
|
|
40
|
-
let accP = [babyJub.F.zero,babyJub.F.one];
|
|
41
|
-
|
|
42
|
-
for (let s=0; s<nSegments; s++) {
|
|
43
|
-
let nWindows;
|
|
44
|
-
if (s == nSegments-1) {
|
|
45
|
-
nWindows = Math.floor(((bits.length - (nSegments - 1)*bitsPerSegment) - 1) / windowSize) +1;
|
|
46
|
-
} else {
|
|
47
|
-
nWindows = nWindowsPerSegment;
|
|
48
|
-
}
|
|
49
|
-
let escalar = Scalar.e(0);
|
|
50
|
-
let exp = Scalar.e(1);
|
|
51
|
-
for (let w=0; w<nWindows; w++) {
|
|
52
|
-
let o = s*bitsPerSegment + w*windowSize;
|
|
53
|
-
let acc = Scalar.e(1);
|
|
54
|
-
for (let b=0; ((b<windowSize-1)&&(o<bits.length)) ; b++) {
|
|
55
|
-
if (bits[o]) {
|
|
56
|
-
acc = Scalar.add(acc, Scalar.shl(Scalar.e(1), b) );
|
|
57
|
-
}
|
|
58
|
-
o++;
|
|
59
|
-
}
|
|
60
|
-
if (o<bits.length) {
|
|
61
|
-
if (bits[o]) {
|
|
62
|
-
acc = Scalar.neg(acc);
|
|
63
|
-
}
|
|
64
|
-
o++;
|
|
65
|
-
}
|
|
66
|
-
escalar = Scalar.add(escalar, Scalar.mul(acc, exp));
|
|
67
|
-
exp = Scalar.shl(exp, windowSize+1);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (Scalar.lt(escalar, 0)) {
|
|
71
|
-
escalar = Scalar.add( escalar, babyJub.subOrder);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
accP = babyJub.addPoint(accP, babyJub.mulPointEscalar(this.getBasePoint(options.baseHash, s), escalar));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return babyJub.packPoint(accP);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getBasePoint(baseHashType, pointIdx) {
|
|
81
|
-
const babyJub = this.babyJub;
|
|
82
|
-
if (this.bases[pointIdx]) return this.bases[pointIdx];
|
|
83
|
-
let p= null;
|
|
84
|
-
let tryIdx = 0;
|
|
85
|
-
while (p==null) {
|
|
86
|
-
const S = GENPOINT_PREFIX + "_" + this.padLeftZeros(pointIdx, 32) + "_" + this.padLeftZeros(tryIdx, 32);
|
|
87
|
-
const h = this.baseHash(baseHashType, S);
|
|
88
|
-
h[31] = h[31] & 0xBF; // Set 255th bit to 0 (256th is the signal and 254th is the last possible bit to 1)
|
|
89
|
-
p = babyJub.unpackPoint(h);
|
|
90
|
-
tryIdx++;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const p8 = babyJub.mulPointEscalar(p, 8);
|
|
94
|
-
|
|
95
|
-
if (!babyJub.inSubgroup(p8)) {
|
|
96
|
-
throw new Error("Point not in curve");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
this.bases[pointIdx] = p8;
|
|
100
|
-
return p8;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
padLeftZeros(idx, n) {
|
|
104
|
-
let sidx = "" + idx;
|
|
105
|
-
while (sidx.length<n) sidx = "0"+sidx;
|
|
106
|
-
return sidx;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/*
|
|
110
|
-
Input a buffer
|
|
111
|
-
Returns an array of booleans. 0 is LSB of first byte and so on.
|
|
112
|
-
*/
|
|
113
|
-
buffer2bits(buff) {
|
|
114
|
-
const res = new Array(buff.length*8);
|
|
115
|
-
for (let i=0; i<buff.length; i++) {
|
|
116
|
-
const b = buff[i];
|
|
117
|
-
res[i*8] = (b & 0x01);
|
|
118
|
-
res[i*8+1] = (b & 0x02) >> 1;
|
|
119
|
-
res[i*8+2] = (b & 0x04) >> 2;
|
|
120
|
-
res[i*8+3] = (b & 0x08) >> 3;
|
|
121
|
-
res[i*8+4] = (b & 0x10) >> 4;
|
|
122
|
-
res[i*8+5] = (b & 0x20) >> 5;
|
|
123
|
-
res[i*8+6] = (b & 0x40) >> 6;
|
|
124
|
-
res[i*8+7] = (b & 0x80) >> 7;
|
|
125
|
-
}
|
|
126
|
-
return res;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
package/src/testblake.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import createBlakeHash from 'blake-hash';
|
|
2
|
-
import blake2b from "blake2b";
|
|
3
|
-
import {Buffer} from 'buffer';
|
|
4
|
-
|
|
5
|
-
const msg = (new TextEncoder()).encode("blake256");
|
|
6
|
-
const msgB = Buffer.from(msg)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const toHexString = bytes =>
|
|
10
|
-
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
|
|
11
|
-
|
|
12
|
-
const h1 = createBlakeHash('blake256').digest();
|
|
13
|
-
|
|
14
|
-
const h2 = blake2b(64).digest();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log(toHexString(h1));
|
|
18
|
-
console.log(toHexString(h2));
|