Skip to content

Commit fe571a8

Browse files
committed
test: curve-secp256k1, sha512
1 parent c4faa3f commit fe571a8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/test-vectors/curve-secp256k1.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as secp from "../../src/curve-secp256k1";
2+
import { deepStrictEqual } from "./assert";
3+
4+
describe("curve-secp256k1", () => {
5+
it("should verify msg bb5a...", async () => {
6+
const msg =
7+
"bb5a52f42f9c9261ed4361f59422a1e30036e7c32b270c8807a419feca605023";
8+
const x = 3252872872578928810725465493269682203671229454553002637820453004368632726370n;
9+
const y = 17482644437196207387910659778872952193236850502325156318830589868678978890912n;
10+
const r = 432420386565659656852420866390673177323n;
11+
const s = 115792089237316195423570985008687907852837564279074904382605163141518161494334n;
12+
const pub = new secp.Point(x, y);
13+
const sig = new secp.Signature(r, s);
14+
deepStrictEqual(secp.verify(sig, msg, pub), true);
15+
});
16+
});

test/test-vectors/sha512.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { sha512 } from "../../src/sha512";
2+
import { toHex, utf8ToBytes } from "../../src/utils";
3+
import { deepStrictEqual } from "./assert";
4+
5+
const TEST_VECTORS = [
6+
{
7+
input: utf8ToBytes(""),
8+
output: "cf83e1357eefb8bd f1542850d66d8007 d620e4050b5715dc 83f4a921d36ce9ce 47d0d13c5d85f2b0 ff8318d2877eec2f 63b931bd47417a81 a538327af927da3e"
9+
},
10+
{
11+
input: utf8ToBytes("abc"),
12+
output: "ddaf35a193617aba cc417349ae204131 12e6fa4e89a97ea2 0a9eeee64b55d39a 2192992a274fc1a8 36ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
13+
},
14+
{
15+
input: utf8ToBytes(
16+
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
17+
),
18+
output: "204a8fc6dda82f0a 0ced7beb8e08a416 57c16ef468b228a8 279be331a703c335 96fd15c13b1b07f9 aa1d3bea57789ca0 31ad85c7a71dd703 54ec631238ca3445"
19+
},
20+
{
21+
input: utf8ToBytes(
22+
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
23+
),
24+
output: "8e959b75dae313da 8cf4f72814fc143f 8f7779c6eb9f7fa1 7299aeadb6889018 501d289e4900f7e4 331b99dec4b5433a c7d329eeb6dd2654 5e96e55b874be909"
25+
}
26+
];
27+
28+
describe("sha512", function() {
29+
for (const [i, vector] of TEST_VECTORS.entries()) {
30+
it(`Should return the right hash for the test ${i}`, async function() {
31+
deepStrictEqual(toHex(sha512(vector.input)), vector.output.replace(/ /g, ''));
32+
});
33+
}
34+
});

0 commit comments

Comments
 (0)