Skip to content

Commit 4dad6d9

Browse files
authored
Merge pull request #207 from fleet-sdk/arobsn/bump-vitest
chore: audit packages
2 parents 99dde94 + 60368b2 commit 4dad6d9

File tree

5 files changed

+137
-390
lines changed

5 files changed

+137
-390
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@
3030
"@fleet-sdk/common": "workspace:^",
3131
"@fleet-sdk/crypto": "workspace:^",
3232
"@types/diff": "^7.0.2",
33-
"@vitest/coverage-v8": "^3.2.4",
33+
"@vitest/coverage-v8": "^4.0.10",
3434
"ergo-lib-wasm-nodejs": "^0.28.0",
3535
"fast-check": "^4.2.0",
36-
"happy-dom": "^18.0.1",
36+
"happy-dom": "^20.0.10",
3737
"npm-run-all": "^4.1.5",
3838
"open-cli": "^8.0.0",
3939
"sigmastate-js": "0.4.6",
4040
"tsdown": "^0.16.5",
4141
"type-fest": "^4.41.0",
4242
"typescript": "^5.9.2",
4343
"vite-tsconfig-paths": "^5.1.4",
44-
"vitest": "^3.2.4"
44+
"vitest": "^4.0.10"
4545
},
4646
"engines": {
4747
"node": ">=18",

packages/wallet/src/prover/proveDLogProtocol.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const MAX_ITERATIONS = 100;
2020
export function sign(message: Uint8Array, secretKey: Uint8Array) {
2121
for (let i = 0; i < MAX_ITERATIONS; i++) {
2222
const signature = genSignature(message, secretKey);
23+
/* v8 ignore else -- @preserve */
2324
if (signature) return signature;
24-
/* v8 ignore start */
2525
}
2626

2727
// This branch is ignored in the coverage report because it depends on randomness.
28+
/* v8 ignore next -- @preserve */
2829
throw new FleetError("Failed to generate signature");
2930
}
30-
/* v8 ignore stop */
3131

3232
/**
3333
* Generates a Schnorr signature for the given message using the provided secret key.
@@ -45,14 +45,14 @@ export function genSignature(message: Uint8Array, secretKey: Uint8Array): undefi
4545
const c = fiatShamirHash(genCommitment(pk, w, message));
4646

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

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

5454
// The next line is ignored in the coverage report because it depends on randomness.
55-
/* v8 ignore next */
55+
/* v8 ignore next -- @preserve */
5656
if (!verify(message, signature, pk)) return;
5757

5858
return signature;
@@ -74,7 +74,7 @@ function genRandomSecret() {
7474
}
7575

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

8080
return r;

packages/wallet/src/prover/prover.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,41 @@ describe("Transaction signing", () => {
5454
expect(verify_signature(addr, txBytes, proof)).to.be.true;
5555
});
5656

57+
it("Should sign a transaction with a single secret and a single input and data input", async () => {
58+
// generate keys
59+
const rootKey = await ErgoHDKey.fromMnemonic(generateMnemonic());
60+
61+
// mock inputs
62+
const input = mockUTxO({
63+
value: 1_000_000_000n,
64+
ergoTree: rootKey.address.ergoTree
65+
});
66+
67+
// build the unsigned transaction
68+
const unsignedTx = new TransactionBuilder(height)
69+
.from(input)
70+
.to(new OutputBuilder(10_000_000n, externalAddress))
71+
.withDataFrom(mockUTxO({ ergoTree: rootKey.address.ergoTree }))
72+
.sendChangeTo(rootKey.address)
73+
.payMinFee()
74+
.build();
75+
76+
// sign
77+
const prover = new Prover();
78+
const signedTx = prover.signTransaction(unsignedTx, [rootKey]);
79+
80+
// verify
81+
const proof = toBytes(signedTx.inputs[0].spendingProof?.proofBytes);
82+
83+
// verify using own verifier
84+
expect(prover.verify(unsignedTx, proof, rootKey)).to.be.true;
85+
86+
// verify using sigma-rust for comparison
87+
const txBytes = unsignedTx.toBytes();
88+
const addr = Address.from_public_key(rootKey.publicKey);
89+
expect(verify_signature(addr, txBytes, proof)).to.be.true;
90+
});
91+
5792
it("Should determine key from registers", async () => {
5893
// generate keys
5994
const rootKey = await ErgoHDKey.fromMnemonic(generateMnemonic());

0 commit comments

Comments
 (0)