Skip to content

Commit 482fe12

Browse files
committed
chore: bump @noble/hashes to v2
1 parent d611b3e commit 482fe12

File tree

8 files changed

+27
-26
lines changed

8 files changed

+27
-26
lines changed

.changeset/wacky-towns-stick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fleet-sdk/crypto": patch
3+
---
4+
5+
Bump `@noble/hashes` to `v2`

packages/crypto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"@fleet-sdk/common": "workspace:^",
40-
"@noble/hashes": "^1.8.0",
40+
"@noble/hashes": "^2.0.1",
4141
"@scure/base": "^2.0.0"
4242
},
4343
"files": [

packages/crypto/src/coders/hex.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
1+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
22
import { hex as scureHex } from "@scure/base";
33
import { bench, describe } from "vitest";
44
import { regularBoxes, validBoxes } from "../../../_test-vectors/mockedBoxes";

packages/crypto/src/hashes.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomBytes } from "@noble/hashes/utils";
1+
import { randomBytes } from "@noble/hashes/utils.js";
22
import { describe, expect, it } from "vitest";
33
import { hex, utf8 } from "./coders";
44
import { blake2b, blake2b256, sha256 } from "./hashes";

packages/crypto/src/hashes.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { blake2b as _blake2b } from "@noble/hashes/blake2b";
2-
import { sha256 as _sha256 } from "@noble/hashes/sha256";
1+
import { type Blake2Opts, blake2b as _blake2b } from "@noble/hashes/blake2.js";
2+
import { sha256 as _sha256 } from "@noble/hashes/sha2.js";
33
import { hex } from "./coders";
44
import type { ByteInput } from "./types";
55

@@ -22,11 +22,17 @@ export function blake2b(message: ByteInput, options?: Blake2bOptions): Uint8Arra
2222
if (options?.salt) options.salt = ensureBytes(options.salt);
2323
if (options?.personalization) options.personalization = ensureBytes(options.personalization);
2424

25-
return _blake2b(ensureBytes(message), options);
25+
const opts: Blake2Opts = {
26+
key: options?.key ? ensureBytes(options?.key) : undefined,
27+
salt: options?.salt ? ensureBytes(options?.salt) : undefined,
28+
personalization: options?.personalization ? ensureBytes(options?.personalization) : undefined,
29+
dkLen: options?.dkLen
30+
};
31+
return _blake2b(ensureBytes(message), opts);
2632
}
2733

2834
export function blake2b256(message: ByteInput, options?: Blake2b256Options): Uint8Array {
29-
return blake2b(ensureBytes(message), { dkLen: 32, ...options });
35+
return blake2b(message, { dkLen: 32, ...options });
3036
}
3137

3238
export function sha256(message: ByteInput): Uint8Array {

packages/crypto/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils";
1+
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils.js";
22

33
/**
44
* Secure PRNG from "@noble/hashes". Uses crypto.getRandomValues, which defers to OS.

packages/wallet/src/ergoHDKey.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,17 @@ export class ErgoHDKey {
8080
return this.#address;
8181
}
8282

83-
static async fromMnemonic(
84-
mnemonic: string,
85-
options?: FromMnemonicOptions,
86-
): Promise<ErgoHDKey> {
83+
static async fromMnemonic(mnemonic: string, options?: FromMnemonicOptions): Promise<ErgoHDKey> {
8784
return ErgoHDKey.fromMasterSeed(
8885
await mnemonicToSeed(mnemonic, options?.passphrase),
89-
options?.path,
86+
options?.path
9087
);
9188
}
9289

93-
static fromMnemonicSync(
94-
mnemonic: string,
95-
options?: FromMnemonicOptions,
96-
): ErgoHDKey {
90+
static fromMnemonicSync(mnemonic: string, options?: FromMnemonicOptions): ErgoHDKey {
9791
return ErgoHDKey.fromMasterSeed(
9892
mnemonicToSeedSync(mnemonic, options?.passphrase),
99-
options?.path,
93+
options?.path
10094
);
10195
}
10296

@@ -117,16 +111,12 @@ export class ErgoHDKey {
117111
/** @deprecated use the default constructor instead */
118112
static fromExtendedKey(options: PublicKeyOptions): ErgoHDKey;
119113
/** @deprecated use the default constructor instead */
120-
static fromExtendedKey(
121-
keyOrOptions: string | PrivateKeyOptions | PublicKeyOptions,
122-
): ErgoHDKey {
114+
static fromExtendedKey(keyOrOptions: string | PrivateKeyOptions | PublicKeyOptions): ErgoHDKey {
123115
if (typeof keyOrOptions !== "string") {
124116
return new ErgoHDKey(keyOrOptions);
125117
}
126118

127-
const xKey = isHex(keyOrOptions)
128-
? base58check.encode(hex.decode(keyOrOptions))
129-
: keyOrOptions;
119+
const xKey = isHex(keyOrOptions) ? base58check.encode(hex.decode(keyOrOptions)) : keyOrOptions;
130120
return new ErgoHDKey(HDKey.fromExtendedKey(xKey));
131121
}
132122

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)