Skip to content

Commit 3d59dff

Browse files
committed
rm js-sha256
1 parent e8a9e31 commit 3d59dff

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

package-lock.json

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@
115115
"typescript": "^5.4.5"
116116
},
117117
"dependencies": {
118+
"@noble/hashes": "^1.3.2",
118119
"blakejs": "1.2.1",
119120
"cachedir": "^2.4.0",
120-
"js-sha256": "^0.9.0",
121121
"libsodium-wrappers-sumo": "^0.7.15",
122122
"reflect-metadata": "^0.1.13",
123123
"stacktrace-js": "^2.0.2",

src/lib/provable/gadgets/elliptic-curve.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Provable } from '../provable.js';
44
import { assert } from './common.js';
55
import { Field3, ForeignField, split, weakBound } from './foreign-field.js';
66
import { l, l2, l2Mask, multiRangeCheck } from './range-check.js';
7-
import { sha256 } from 'js-sha256';
7+
import { sha256 } from '@noble/hashes/sha256';
88
import { bigIntToBytes, bytesToBigInt } from '../../../bindings/crypto/bigint-helpers.js';
99
import {
1010
CurveAffine,
@@ -626,12 +626,12 @@ function getPointTable(Curve: CurveAffine, P: Point, windowSize: number, table?:
626626
function initialAggregator(Curve: CurveAffine) {
627627
// hash that identifies the curve
628628
let h = sha256.create();
629-
h.update('initial-aggregator');
630-
h.update(bigIntToBytes(Curve.modulus));
631-
h.update(bigIntToBytes(Curve.order));
632-
h.update(bigIntToBytes(Curve.a));
633-
h.update(bigIntToBytes(Curve.b));
634-
let bytes = h.array();
629+
h.update(new TextEncoder().encode('initial-aggregator'));
630+
h.update(new Uint8Array(bigIntToBytes(Curve.modulus)));
631+
h.update(new Uint8Array(bigIntToBytes(Curve.order)));
632+
h.update(new Uint8Array(bigIntToBytes(Curve.a)));
633+
h.update(new Uint8Array(bigIntToBytes(Curve.b)));
634+
let bytes = h.digest();
635635

636636
// bytes represent a 256-bit number
637637
// use that as x coordinate

src/lib/util/base58.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { versionBytes } from '../../bindings/crypto/constants.js';
22
import { Binable, withVersionNumber } from '../../bindings/lib/binable.js';
3-
import { sha256 } from 'js-sha256';
3+
import { sha256 } from '@noble/hashes/sha256';
44
import { changeBase } from '../../bindings/crypto/bigint-helpers.js';
55

66
export { toBase58Check, fromBase58Check, base58, withBase58, fieldEncodings, Base58, alphabet };
@@ -62,11 +62,12 @@ function fromBase58(base58: string) {
6262
}
6363

6464
function computeChecksum(input: number[] | Uint8Array) {
65+
let inputBytes = input instanceof Uint8Array ? input : new Uint8Array(input);
6566
let hash1 = sha256.create();
66-
hash1.update(input);
67+
hash1.update(inputBytes);
6768
let hash2 = sha256.create();
68-
hash2.update(hash1.array());
69-
return hash2.array().slice(0, 4);
69+
hash2.update(hash1.digest());
70+
return Array.from(hash2.digest().slice(0, 4));
7071
}
7172

7273
type Base58<T> = {

0 commit comments

Comments
 (0)