Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-walls-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/wallet": patch
---

Bump `@scure/bip32` to `v2`
5 changes: 5 additions & 0 deletions .changeset/dry-heads-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/wallet": patch
---

Bump `@scure/bip39` to `v2`
5 changes: 5 additions & 0 deletions .changeset/eight-bugs-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/crypto": patch
---

Bump `@scure/base` to `v2`
5 changes: 5 additions & 0 deletions .changeset/shiny-taxes-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/wallet": patch
---

Bump `@noble/curves` to `v2`
5 changes: 5 additions & 0 deletions .changeset/wacky-towns-stick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/crypto": patch
---

Bump `@noble/hashes` to `v2`
4 changes: 2 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"dependencies": {
"@fleet-sdk/common": "workspace:^",
"@noble/hashes": "^1.8.0",
"@scure/base": "^1.2.6"
"@noble/hashes": "^2.0.1",
"@scure/base": "^2.0.0"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/coders/hex.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
import { hex as scureHex } from "@scure/base";
import { bench, describe } from "vitest";
import { regularBoxes, validBoxes } from "../../../_test-vectors/mockedBoxes";
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/hashes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomBytes } from "@noble/hashes/utils";
import { randomBytes } from "@noble/hashes/utils.js";
import { describe, expect, it } from "vitest";
import { hex, utf8 } from "./coders";
import { blake2b, blake2b256, sha256 } from "./hashes";
Expand Down
14 changes: 10 additions & 4 deletions packages/crypto/src/hashes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blake2b as _blake2b } from "@noble/hashes/blake2b";
import { sha256 as _sha256 } from "@noble/hashes/sha256";
import { type Blake2Opts, blake2b as _blake2b } from "@noble/hashes/blake2.js";
import { sha256 as _sha256 } from "@noble/hashes/sha2.js";
import { hex } from "./coders";
import type { ByteInput } from "./types";

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

return _blake2b(ensureBytes(message), options);
const opts: Blake2Opts = {
key: options?.key ? ensureBytes(options?.key) : undefined,
salt: options?.salt ? ensureBytes(options?.salt) : undefined,
personalization: options?.personalization ? ensureBytes(options?.personalization) : undefined,
dkLen: options?.dkLen
};
return _blake2b(ensureBytes(message), opts);
}

export function blake2b256(message: ByteInput, options?: Blake2b256Options): Uint8Array {
return blake2b(ensureBytes(message), { dkLen: 32, ...options });
return blake2b(message, { dkLen: 32, ...options });
}

export function sha256(message: ByteInput): Uint8Array {
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils";
import { randomBytes as nobleRandomBytes } from "@noble/hashes/utils.js";

/**
* Secure PRNG from "@noble/hashes". Uses crypto.getRandomValues, which defers to OS.
Expand Down
6 changes: 3 additions & 3 deletions packages/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"@fleet-sdk/core": "workspace:^",
"@fleet-sdk/crypto": "workspace:^",
"@fleet-sdk/serializer": "workspace:^",
"@noble/curves": "^1.9.2",
"@scure/bip32": "^1.7.0",
"@scure/bip39": "^1.6.0"
"@noble/curves": "^2.0.1",
"@scure/bip32": "^2.0.1",
"@scure/bip39": "^2.0.1"
},
"engines": {
"node": ">=18"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/src/mnemonic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateMnemonic as generate, validateMnemonic as validate } from "@scure/bip39";
import { wordlist as english } from "@scure/bip39/wordlists/english";
import { wordlist as english } from "@scure/bip39/wordlists/english.js";

export function generateMnemonic(strength = 160, wordlist = english): string {
return generate(wordlist, strength);
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/prover/proveDLogProtocol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hex } from "@fleet-sdk/crypto";
import { secp256k1 } from "@noble/curves/secp256k1";
import { secp256k1 } from "@noble/curves/secp256k1.js";
import { Address, verify_signature } from "ergo-lib-wasm-nodejs";
import fc from "fast-check";
import { describe, expect, it, test } from "vitest";
Expand Down Expand Up @@ -79,7 +79,7 @@ describe("ProveDLog protocol", () => {
sk: fc.uint8Array({ minLength: 32, maxLength: 32 })
}),
({ msg, sk }) => {
const pk = getPublicKey(hex.encode(sk));
const pk = getPublicKey(sk);
const signature = sign(msg, sk);

expect(verify(msg, signature, pk)).to.be.true;
Expand Down
19 changes: 10 additions & 9 deletions packages/wallet/src/prover/proveDLogProtocol.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FleetError, _0n, concatBytes } from "@fleet-sdk/common";
import { bigintBE, blake2b256, hex, randomBytes, validateEcPoint } from "@fleet-sdk/crypto";
import { secp256k1 } from "@noble/curves/secp256k1";
import { secp256k1 } from "@noble/curves/secp256k1.js";

const { ProjectivePoint: ECPoint, CURVE } = secp256k1;
const G = ECPoint.BASE;
const { Point } = secp256k1;
const G = Point.BASE;
const N = Point.CURVE().n;

const BLAKE2B_256_DIGEST_LEN = 32;
const ERGO_SOUNDNESS_BYTES = 24;
Expand Down Expand Up @@ -39,16 +40,16 @@ export function sign(message: Uint8Array, secretKey: Uint8Array) {
*/
export function genSignature(message: Uint8Array, secretKey: Uint8Array): undefined | Uint8Array {
const sk = bigintBE.encode(secretKey);
const pk = G.multiply(sk).toRawBytes();
const pk = G.multiply(sk).toBytes();
const k = genRandomSecret();
const w = G.multiply(k).toRawBytes();
const w = G.multiply(k).toBytes();
const c = fiatShamirHash(genCommitment(pk, w, message));

// The next line is ignored in the coverage report because it depends on randomness.
/* v8 ignore next -- @preserve */
if (c === 0n) throw new FleetError("Failed to generate challenge");

const z = umod(sk * c + k, CURVE.n);
const z = umod(sk * c + k, N);
const signature = concatBytes(bigintBE.decode(c), bigintBE.decode(z));

// The next line is ignored in the coverage report because it depends on randomness.
Expand All @@ -69,7 +70,7 @@ function genRandomSecret() {
let c = 0;

while (r === 0n && c < MAX_ITERATIONS) {
r = umod(bigintBE.encode(randomBytes(32)), CURVE.n);
r = umod(bigintBE.encode(randomBytes(32)), N);
c++;
}

Expand Down Expand Up @@ -105,8 +106,8 @@ export function verify(message: Uint8Array, proof: Uint8Array, publicKey: Uint8A
const c = bigintBE.encode(proof.slice(0, ERGO_SOUNDNESS_BYTES));
const z = bigintBE.encode(proof.slice(ERGO_SOUNDNESS_BYTES, ERGO_SCHNORR_SIG_LEN));

const t = ECPoint.fromHex(publicKey).multiply(CURVE.n - c);
const w = G.multiply(z).add(t).toRawBytes();
const t = Point.fromBytes(publicKey).multiply(N - c);
const w = G.multiply(z).add(t).toBytes();
const c2 = fiatShamirHash(genCommitment(publicKey, w, message));

return c2 === c;
Expand Down
4 changes: 1 addition & 3 deletions packages/wallet/src/wordlists.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
korean,
portuguese,
simplifiedChinese,
spanish,
traditionalChinese
spanish
} from "./wordlists";

describe("wordlists", () => {
Expand All @@ -18,7 +17,6 @@ describe("wordlists", () => {
expect(english).to.have.length(wordlistLength);
expect(portuguese).to.have.length(wordlistLength);
expect(simplifiedChinese).to.have.length(wordlistLength);
expect(traditionalChinese).to.have.length(wordlistLength);
expect(czech).to.have.length(wordlistLength);
expect(french).to.have.length(wordlistLength);
expect(italian).to.have.length(wordlistLength);
Expand Down
19 changes: 9 additions & 10 deletions packages/wallet/src/wordlists.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export { wordlist as english } from "@scure/bip39/wordlists/english";
export { wordlist as japanese } from "@scure/bip39/wordlists/japanese";
export { wordlist as korean } from "@scure/bip39/wordlists/korean";
export { wordlist as spanish } from "@scure/bip39/wordlists/spanish";
export { wordlist as simplifiedChinese } from "@scure/bip39/wordlists/simplified-chinese";
export { wordlist as traditionalChinese } from "@scure/bip39/wordlists/traditional-chinese";
export { wordlist as french } from "@scure/bip39/wordlists/french";
export { wordlist as italian } from "@scure/bip39/wordlists/italian";
export { wordlist as portuguese } from "@scure/bip39/wordlists/portuguese";
export { wordlist as czech } from "@scure/bip39/wordlists/czech";
export { wordlist as english } from "@scure/bip39/wordlists/english.js";
export { wordlist as japanese } from "@scure/bip39/wordlists/japanese.js";
export { wordlist as korean } from "@scure/bip39/wordlists/korean.js";
export { wordlist as spanish } from "@scure/bip39/wordlists/spanish.js";
export { wordlist as simplifiedChinese } from "@scure/bip39/wordlists/simplified-chinese.js";
export { wordlist as french } from "@scure/bip39/wordlists/french.js";
export { wordlist as italian } from "@scure/bip39/wordlists/italian.js";
export { wordlist as portuguese } from "@scure/bip39/wordlists/portuguese.js";
export { wordlist as czech } from "@scure/bip39/wordlists/czech.js";
66 changes: 36 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading