|
@@ -19,18 +19,26 @@ describe('ECDSA', function () {
|
|
|
|
|
|
describe('recover with invalid signature', function () {
|
|
|
it('with short signature', async function () {
|
|
|
- await expect(this.mock.$recover(TEST_MESSAGE, '0x1234'))
|
|
|
+ const signature = '0x1234';
|
|
|
+
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature))
|
|
|
+ .to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
+ .withArgs(2);
|
|
|
+
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature))
|
|
|
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
.withArgs(2);
|
|
|
});
|
|
|
|
|
|
it('with long signature', async function () {
|
|
|
- await expect(
|
|
|
- this.mock.$recover(
|
|
|
- TEST_MESSAGE,
|
|
|
- '0x01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789',
|
|
|
- ),
|
|
|
- )
|
|
|
+ const signature =
|
|
|
+ '0x01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789';
|
|
|
+
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature))
|
|
|
+ .to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
+ .withArgs(85);
|
|
|
+
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature))
|
|
|
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
.withArgs(85);
|
|
|
});
|
|
@@ -43,8 +51,10 @@ describe('ECDSA', function () {
|
|
|
const signature = await this.signer.signMessage(TEST_MESSAGE);
|
|
|
|
|
|
// Recover the signer address from the generated message and signature.
|
|
|
- expect(await this.mock.$recover(ethers.hashMessage(TEST_MESSAGE), signature)).to.equal(this.signer);
|
|
|
- expect(await this.mock.$recoverCalldata(ethers.hashMessage(TEST_MESSAGE), signature)).to.equal(this.signer);
|
|
|
+ await expect(this.mock.$recover(ethers.hashMessage(TEST_MESSAGE), signature)).to.eventually.equal(this.signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(ethers.hashMessage(TEST_MESSAGE), signature)).to.eventually.equal(
|
|
|
+ this.signer,
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
it('returns signer address with correct signature for arbitrary length message', async function () {
|
|
@@ -52,14 +62,18 @@ describe('ECDSA', function () {
|
|
|
const signature = await this.signer.signMessage(NON_HASH_MESSAGE);
|
|
|
|
|
|
// Recover the signer address from the generated message and signature.
|
|
|
- expect(await this.mock.$recover(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.equal(this.signer);
|
|
|
- expect(await this.mock.$recoverCalldata(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.equal(this.signer);
|
|
|
+ await expect(this.mock.$recover(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.eventually.equal(
|
|
|
+ this.signer,
|
|
|
+ );
|
|
|
+ await expect(this.mock.$recoverCalldata(ethers.hashMessage(NON_HASH_MESSAGE), signature)).to.eventually.equal(
|
|
|
+ this.signer,
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
it('returns a different address', async function () {
|
|
|
const signature = await this.signer.signMessage(TEST_MESSAGE);
|
|
|
- expect(await this.mock.$recover(WRONG_MESSAGE, signature)).to.not.be.equal(this.signer);
|
|
|
- expect(await this.mock.$recoverCalldata(WRONG_MESSAGE, signature)).to.not.be.equal(this.signer);
|
|
|
+ await expect(this.mock.$recover(WRONG_MESSAGE, signature)).to.eventually.not.equal(this.signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(WRONG_MESSAGE, signature)).to.eventually.not.equal(this.signer);
|
|
|
});
|
|
|
|
|
|
it('reverts with invalid signature', async function () {
|
|
@@ -85,22 +99,24 @@ describe('ECDSA', function () {
|
|
|
it('works with correct v value', async function () {
|
|
|
const v = '0x1b'; // 27 = 1b.
|
|
|
const signature = ethers.concat([signatureWithoutV, v]);
|
|
|
- expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.equal(signer);
|
|
|
- expect(await this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.equal(signer);
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature)).to.eventually.equal(signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.eventually.equal(signer);
|
|
|
|
|
|
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
|
|
- expect(await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s)).to.equal(
|
|
|
- signer,
|
|
|
- );
|
|
|
+ await expect(
|
|
|
+ this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
|
|
+ ).to.eventually.equal(signer);
|
|
|
|
|
|
- expect(await this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs)).to.equal(signer);
|
|
|
+ await expect(
|
|
|
+ this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs),
|
|
|
+ ).to.eventually.equal(signer);
|
|
|
});
|
|
|
|
|
|
it('rejects incorrect v value', async function () {
|
|
|
const v = '0x1c'; // 28 = 1c.
|
|
|
const signature = ethers.concat([signatureWithoutV, v]);
|
|
|
- expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
- expect(await this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature)).to.eventually.not.equal(signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.eventually.not.equal(signer);
|
|
|
|
|
|
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
|
|
expect(
|
|
@@ -154,29 +170,31 @@ describe('ECDSA', function () {
|
|
|
it('works with correct v value', async function () {
|
|
|
const v = '0x1c'; // 28 = 1c.
|
|
|
const signature = ethers.concat([signatureWithoutV, v]);
|
|
|
- expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.equal(signer);
|
|
|
- expect(await this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.equal(signer);
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature)).to.eventually.equal(signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.eventually.equal(signer);
|
|
|
|
|
|
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
|
|
- expect(await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s)).to.equal(
|
|
|
- signer,
|
|
|
- );
|
|
|
+ await expect(
|
|
|
+ this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
|
|
+ ).to.eventually.equal(signer);
|
|
|
|
|
|
- expect(await this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs)).to.equal(signer);
|
|
|
+ await expect(
|
|
|
+ this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs),
|
|
|
+ ).to.eventually.equal(signer);
|
|
|
});
|
|
|
|
|
|
it('rejects incorrect v value', async function () {
|
|
|
const v = '0x1b'; // 27 = 1b.
|
|
|
const signature = ethers.concat([signatureWithoutV, v]);
|
|
|
- expect(await this.mock.$recover(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
- expect(await this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature)).to.not.equal(signer);
|
|
|
|
|
|
const { r, s, yParityAndS: vs } = ethers.Signature.from(signature);
|
|
|
expect(
|
|
|
await this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s),
|
|
|
).to.not.equal(signer);
|
|
|
|
|
|
- expect(await this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs)).to.not.equal(
|
|
|
+ await expect(this.mock.getFunction('$recover(bytes32,bytes32,bytes32)')(TEST_MESSAGE, r, vs)).to.not.equal(
|
|
|
signer,
|
|
|
);
|
|
|
});
|
|
@@ -236,4 +254,65 @@ describe('ECDSA', function () {
|
|
|
expect(() => ethers.Signature.from(highSSignature)).to.throw('non-canonical s');
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe('parse signature', function () {
|
|
|
+ it('65 and 64 bytes signatures', async function () {
|
|
|
+ // Create the signature
|
|
|
+ const signature = await this.signer.signMessage(TEST_MESSAGE).then(ethers.Signature.from);
|
|
|
+
|
|
|
+ await expect(this.mock.$parse(signature.serialized)).to.eventually.deep.equal([
|
|
|
+ signature.v,
|
|
|
+ signature.r,
|
|
|
+ signature.s,
|
|
|
+ ]);
|
|
|
+ await expect(this.mock.$parse(signature.compactSerialized)).to.eventually.deep.equal([
|
|
|
+ signature.v,
|
|
|
+ signature.r,
|
|
|
+ signature.s,
|
|
|
+ ]);
|
|
|
+ await expect(this.mock.$parseCalldata(signature.serialized)).to.eventually.deep.equal([
|
|
|
+ signature.v,
|
|
|
+ signature.r,
|
|
|
+ signature.s,
|
|
|
+ ]);
|
|
|
+ await expect(this.mock.$parseCalldata(signature.compactSerialized)).to.eventually.deep.equal([
|
|
|
+ signature.v,
|
|
|
+ signature.r,
|
|
|
+ signature.s,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('with short signature', async function () {
|
|
|
+ const signature = '0x1234';
|
|
|
+
|
|
|
+ await expect(this.mock.$parse(signature)).to.eventually.deep.equal([0n, ethers.ZeroHash, ethers.ZeroHash]);
|
|
|
+
|
|
|
+ await expect(this.mock.$parseCalldata(signature)).to.eventually.deep.equal([
|
|
|
+ 0n,
|
|
|
+ ethers.ZeroHash,
|
|
|
+ ethers.ZeroHash,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('with long signature', async function () {
|
|
|
+ const signature =
|
|
|
+ '0x01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789';
|
|
|
+
|
|
|
+ await expect(this.mock.$recover(TEST_MESSAGE, signature))
|
|
|
+ .to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
+ .withArgs(85);
|
|
|
+
|
|
|
+ await expect(this.mock.$recoverCalldata(TEST_MESSAGE, signature))
|
|
|
+ .to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureLength')
|
|
|
+ .withArgs(85);
|
|
|
+
|
|
|
+ await expect(this.mock.$parse(signature)).to.eventually.deep.equal([0n, ethers.ZeroHash, ethers.ZeroHash]);
|
|
|
+
|
|
|
+ await expect(this.mock.$parseCalldata(signature)).to.eventually.deep.equal([
|
|
|
+ 0n,
|
|
|
+ ethers.ZeroHash,
|
|
|
+ ethers.ZeroHash,
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|