forked from tornado-packages/noble-curves
BLS tests: remove async
This commit is contained in:
parent
f14b8d2be5
commit
cea4696599
@ -783,7 +783,7 @@ describe('bls12-381/basic', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
should('compress and decompress G1 points', async () => {
|
should('compress and decompress G1 points', () => {
|
||||||
const priv = G1Point.fromPrivateKey(42n);
|
const priv = G1Point.fromPrivateKey(42n);
|
||||||
const publicKey = priv.toHex(true);
|
const publicKey = priv.toHex(true);
|
||||||
const decomp = G1Point.fromHex(publicKey);
|
const decomp = G1Point.fromHex(publicKey);
|
||||||
@ -847,14 +847,14 @@ describe('bls12-381/basic', () => {
|
|||||||
});
|
});
|
||||||
// should aggregate signatures
|
// should aggregate signatures
|
||||||
|
|
||||||
should(`produce correct signatures (${G2_VECTORS.length} vectors)`, async () => {
|
should(`produce correct signatures (${G2_VECTORS.length} vectors)`, () => {
|
||||||
for (let vector of G2_VECTORS) {
|
for (let vector of G2_VECTORS) {
|
||||||
const [priv, msg, expected] = vector;
|
const [priv, msg, expected] = vector;
|
||||||
const sig = bls.sign(msg, priv);
|
const sig = bls.sign(msg, priv);
|
||||||
deepStrictEqual(bls.utils.bytesToHex(sig), expected);
|
deepStrictEqual(bls.utils.bytesToHex(sig), expected);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
should(`produce correct scalars (${SCALAR_VECTORS.length} vectors)`, async () => {
|
should(`produce correct scalars (${SCALAR_VECTORS.length} vectors)`, () => {
|
||||||
const options = {
|
const options = {
|
||||||
p: bls.CURVE.r,
|
p: bls.CURVE.r,
|
||||||
m: 1,
|
m: 1,
|
||||||
@ -1074,7 +1074,7 @@ describe('hash-to-curve', () => {
|
|||||||
];
|
];
|
||||||
for (let i = 0; i < VECTORS.length; i++) {
|
for (let i = 0; i < VECTORS.length; i++) {
|
||||||
const t = VECTORS[i];
|
const t = VECTORS[i];
|
||||||
should(`hash_to_field/expand_message_xmd(SHA-256) (${i})`, async () => {
|
should(`hash_to_field/expand_message_xmd(SHA-256) (${i})`, () => {
|
||||||
const p = bls.utils.expandMessageXMD(
|
const p = bls.utils.expandMessageXMD(
|
||||||
bls.utils.stringToBytes(t.msg),
|
bls.utils.stringToBytes(t.msg),
|
||||||
bls.utils.stringToBytes(DST),
|
bls.utils.stringToBytes(DST),
|
||||||
@ -1192,7 +1192,7 @@ describe('hash-to-curve', () => {
|
|||||||
];
|
];
|
||||||
for (let i = 0; i < VECTORS_BIG.length; i++) {
|
for (let i = 0; i < VECTORS_BIG.length; i++) {
|
||||||
const t = VECTORS_BIG[i];
|
const t = VECTORS_BIG[i];
|
||||||
should(`hash_to_field/expand_message_xmd(SHA-256) (long DST) (${i})`, async () => {
|
should(`hash_to_field/expand_message_xmd(SHA-256) (long DST) (${i})`, () => {
|
||||||
const p = bls.utils.expandMessageXMD(
|
const p = bls.utils.expandMessageXMD(
|
||||||
bls.utils.stringToBytes(t.msg),
|
bls.utils.stringToBytes(t.msg),
|
||||||
bls.utils.stringToBytes(LONG_DST),
|
bls.utils.stringToBytes(LONG_DST),
|
||||||
@ -1305,7 +1305,7 @@ describe('hash-to-curve', () => {
|
|||||||
];
|
];
|
||||||
for (let i = 0; i < VECTORS_SHA512.length; i++) {
|
for (let i = 0; i < VECTORS_SHA512.length; i++) {
|
||||||
const t = VECTORS_SHA512[i];
|
const t = VECTORS_SHA512[i];
|
||||||
should(`hash_to_field/expand_message_xmd(SHA-256) (long DST) (${i})`, async () => {
|
should(`hash_to_field/expand_message_xmd(SHA-256) (long DST) (${i})`, () => {
|
||||||
const p = bls.utils.expandMessageXMD(
|
const p = bls.utils.expandMessageXMD(
|
||||||
bls.utils.stringToBytes(t.msg),
|
bls.utils.stringToBytes(t.msg),
|
||||||
bls.utils.stringToBytes(DST_512),
|
bls.utils.stringToBytes(DST_512),
|
||||||
@ -1716,7 +1716,7 @@ describe('hash-to-curve', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('verify()', () => {
|
describe('verify()', () => {
|
||||||
should('verify signed message', async () => {
|
should('verify signed message', () => {
|
||||||
for (let i = 0; i < NUM_RUNS; i++) {
|
for (let i = 0; i < NUM_RUNS; i++) {
|
||||||
const [priv, msg] = G2_VECTORS[i];
|
const [priv, msg] = G2_VECTORS[i];
|
||||||
const sig = bls.sign(msg, priv);
|
const sig = bls.sign(msg, priv);
|
||||||
@ -1725,7 +1725,7 @@ describe('verify()', () => {
|
|||||||
deepStrictEqual(res, true, `${priv}-${msg}`);
|
deepStrictEqual(res, true, `${priv}-${msg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
should('not verify signature with wrong message', async () => {
|
should('not verify signature with wrong message', () => {
|
||||||
for (let i = 0; i < NUM_RUNS; i++) {
|
for (let i = 0; i < NUM_RUNS; i++) {
|
||||||
const [priv, msg] = G2_VECTORS[i];
|
const [priv, msg] = G2_VECTORS[i];
|
||||||
const invMsg = G2_VECTORS[i + 1][1];
|
const invMsg = G2_VECTORS[i + 1][1];
|
||||||
@ -1735,7 +1735,7 @@ describe('verify()', () => {
|
|||||||
deepStrictEqual(res, false);
|
deepStrictEqual(res, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
should('not verify signature with wrong key', async () => {
|
should('not verify signature with wrong key', () => {
|
||||||
for (let i = 0; i < NUM_RUNS; i++) {
|
for (let i = 0; i < NUM_RUNS; i++) {
|
||||||
const [priv, msg] = G2_VECTORS[i];
|
const [priv, msg] = G2_VECTORS[i];
|
||||||
const sig = bls.sign(msg, priv);
|
const sig = bls.sign(msg, priv);
|
||||||
@ -1746,9 +1746,9 @@ describe('verify()', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
describe('batch', () => {
|
describe('batch', () => {
|
||||||
should('verify multi-signature', async () => {
|
should.only('verify multi-signature', () => {
|
||||||
await fc.assert(
|
fc.assert(
|
||||||
fc.asyncProperty(FC_MSG_5, FC_BIGINT_5, async (messages, privateKeys) => {
|
fc.property(FC_MSG_5, FC_BIGINT_5, (messages, privateKeys) => {
|
||||||
privateKeys = privateKeys.slice(0, messages.length);
|
privateKeys = privateKeys.slice(0, messages.length);
|
||||||
messages = messages.slice(0, privateKeys.length);
|
messages = messages.slice(0, privateKeys.length);
|
||||||
const publicKey = privateKeys.map(getPubKey);
|
const publicKey = privateKeys.map(getPubKey);
|
||||||
@ -1758,36 +1758,31 @@ describe('verify()', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
should('batch verify multi-signatures', async () => {
|
should('batch verify multi-signatures', () => {
|
||||||
await fc.assert(
|
fc.assert(
|
||||||
fc.asyncProperty(
|
fc.property(FC_MSG_5, FC_MSG_5, FC_BIGINT_5, (messages, wrongMessages, privateKeys) => {
|
||||||
FC_MSG_5,
|
privateKeys = privateKeys.slice(0, messages.length);
|
||||||
FC_MSG_5,
|
messages = messages.slice(0, privateKeys.length);
|
||||||
FC_BIGINT_5,
|
wrongMessages = messages.map((a, i) =>
|
||||||
async (messages, wrongMessages, privateKeys) => {
|
typeof wrongMessages[i] === 'undefined' ? a : wrongMessages[i]
|
||||||
privateKeys = privateKeys.slice(0, messages.length);
|
);
|
||||||
messages = messages.slice(0, privateKeys.length);
|
const publicKey = privateKeys.map(getPubKey);
|
||||||
wrongMessages = messages.map((a, i) =>
|
const signatures = messages.map((message, i) => bls.sign(message, privateKeys[i]));
|
||||||
typeof wrongMessages[i] === 'undefined' ? a : wrongMessages[i]
|
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
||||||
);
|
deepStrictEqual(
|
||||||
const publicKey = privateKeys.map(getPubKey);
|
bls.verifyBatch(aggregatedSignature, wrongMessages, publicKey),
|
||||||
const signatures = messages.map((message, i) => bls.sign(message, privateKeys[i]));
|
messages.every((m, i) => m === wrongMessages[i])
|
||||||
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
);
|
||||||
deepStrictEqual(
|
})
|
||||||
bls.verifyBatch(aggregatedSignature, wrongMessages, publicKey),
|
|
||||||
messages.every((m, i) => m === wrongMessages[i])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
should('not verify multi-signature with wrong public keys', async () => {
|
should('not verify multi-signature with wrong public keys', () => {
|
||||||
await fc.assert(
|
fc.assert(
|
||||||
fc.asyncProperty(
|
fc.property(
|
||||||
FC_MSG_5,
|
FC_MSG_5,
|
||||||
FC_BIGINT_5,
|
FC_BIGINT_5,
|
||||||
FC_BIGINT_5,
|
FC_BIGINT_5,
|
||||||
async (messages, privateKeys, wrongPrivateKeys) => {
|
(messages, privateKeys, wrongPrivateKeys) => {
|
||||||
privateKeys = privateKeys.slice(0, messages.length);
|
privateKeys = privateKeys.slice(0, messages.length);
|
||||||
wrongPrivateKeys = privateKeys.map((a, i) =>
|
wrongPrivateKeys = privateKeys.map((a, i) =>
|
||||||
wrongPrivateKeys[i] !== undefined ? wrongPrivateKeys[i] : a
|
wrongPrivateKeys[i] !== undefined ? wrongPrivateKeys[i] : a
|
||||||
@ -1804,9 +1799,9 @@ describe('verify()', () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
should('verify multi-signature as simple signature', async () => {
|
should('verify multi-signature as simple signature', () => {
|
||||||
await fc.assert(
|
fc.assert(
|
||||||
fc.asyncProperty(FC_MSG, FC_BIGINT_5, async (message, privateKeys) => {
|
fc.property(FC_MSG, FC_BIGINT_5, (message, privateKeys) => {
|
||||||
const publicKey = privateKeys.map(getPubKey);
|
const publicKey = privateKeys.map(getPubKey);
|
||||||
const signatures = privateKeys.map((privateKey) => bls.sign(message, privateKey));
|
const signatures = privateKeys.map((privateKey) => bls.sign(message, privateKey));
|
||||||
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
||||||
@ -1815,23 +1810,18 @@ describe('verify()', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
should('not verify wrong multi-signature as simple signature', async () => {
|
should('not verify wrong multi-signature as simple signature', () => {
|
||||||
await fc.assert(
|
fc.assert(
|
||||||
fc.asyncProperty(
|
fc.property(FC_MSG, FC_MSG, FC_BIGINT_5, (message, wrongMessage, privateKeys) => {
|
||||||
FC_MSG,
|
const publicKey = privateKeys.map(getPubKey);
|
||||||
FC_MSG,
|
const signatures = privateKeys.map((privateKey) => bls.sign(message, privateKey));
|
||||||
FC_BIGINT_5,
|
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
||||||
async (message, wrongMessage, privateKeys) => {
|
const aggregatedPublicKey = bls.aggregatePublicKeys(publicKey);
|
||||||
const publicKey = privateKeys.map(getPubKey);
|
deepStrictEqual(
|
||||||
const signatures = privateKeys.map((privateKey) => bls.sign(message, privateKey));
|
bls.verify(aggregatedSignature, wrongMessage, aggregatedPublicKey),
|
||||||
const aggregatedSignature = bls.aggregateSignatures(signatures);
|
message === wrongMessage
|
||||||
const aggregatedPublicKey = bls.aggregatePublicKeys(publicKey);
|
);
|
||||||
deepStrictEqual(
|
})
|
||||||
bls.verify(aggregatedSignature, wrongMessage, aggregatedPublicKey),
|
|
||||||
message === wrongMessage
|
|
||||||
);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user