Skip to content

Commit 6079eb3

Browse files
Amxxernestognw
andauthored
Add signer constructors (#5757)
Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent 61f81e3 commit 6079eb3

16 files changed

+49
-56
lines changed

.changeset/all-geese-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': patch
3+
---
4+
5+
Add constructors to the different signers.

contracts/mocks/account/AccountMock.sol

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ abstract contract AccountMock is Account, ERC7739, ERC7821, ERC721Holder, ERC115
3838
}
3939

4040
abstract contract AccountECDSAMock is Account, SignerECDSA, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
41-
constructor(address signerAddr) {
42-
_setSigner(signerAddr);
43-
}
44-
4541
/// @inheritdoc ERC7821
4642
function _erc7821AuthorizedExecutor(
4743
address caller,
@@ -53,10 +49,6 @@ abstract contract AccountECDSAMock is Account, SignerECDSA, ERC7739, ERC7821, ER
5349
}
5450

5551
abstract contract AccountP256Mock is Account, SignerP256, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
56-
constructor(bytes32 qx, bytes32 qy) {
57-
_setSigner(qx, qy);
58-
}
59-
6052
/// @inheritdoc ERC7821
6153
function _erc7821AuthorizedExecutor(
6254
address caller,
@@ -68,10 +60,6 @@ abstract contract AccountP256Mock is Account, SignerP256, ERC7739, ERC7821, ERC7
6860
}
6961

7062
abstract contract AccountRSAMock is Account, SignerRSA, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
71-
constructor(bytes memory e, bytes memory n) {
72-
_setSigner(e, n);
73-
}
74-
7563
/// @inheritdoc ERC7821
7664
function _erc7821AuthorizedExecutor(
7765
address caller,
@@ -141,10 +129,6 @@ abstract contract AccountERC7579HookedMock is AccountERC7579Hooked {
141129
}
142130

143131
abstract contract AccountERC7913Mock is Account, SignerERC7913, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
144-
constructor(bytes memory _signer) {
145-
_setSigner(_signer);
146-
}
147-
148132
/// @inheritdoc ERC7821
149133
function _erc7821AuthorizedExecutor(
150134
address caller,
@@ -156,11 +140,6 @@ abstract contract AccountERC7913Mock is Account, SignerERC7913, ERC7739, ERC7821
156140
}
157141

158142
abstract contract AccountMultiSignerMock is Account, MultiSignerERC7913, ERC7739, ERC7821, ERC721Holder, ERC1155Holder {
159-
constructor(bytes[] memory signers, uint64 threshold) {
160-
_addSigners(signers);
161-
_setThreshold(threshold);
162-
}
163-
164143
/// @inheritdoc ERC7821
165144
function _erc7821AuthorizedExecutor(
166145
address caller,
@@ -179,12 +158,6 @@ abstract contract AccountMultiSignerWeightedMock is
179158
ERC721Holder,
180159
ERC1155Holder
181160
{
182-
constructor(bytes[] memory signers, uint64[] memory weights, uint64 threshold) {
183-
_addSigners(signers);
184-
_setSignerWeights(signers, weights);
185-
_setThreshold(threshold);
186-
}
187-
188161
/// @inheritdoc ERC7821
189162
function _erc7821AuthorizedExecutor(
190163
address caller,

contracts/mocks/utils/cryptography/ERC7739Mock.sol

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,11 @@
33
pragma solidity ^0.8.20;
44

55
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
6-
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
76
import {ERC7739} from "../../../utils/cryptography/signers/draft-ERC7739.sol";
87
import {SignerECDSA} from "../../../utils/cryptography/signers/SignerECDSA.sol";
98
import {SignerP256} from "../../../utils/cryptography/signers/SignerP256.sol";
109
import {SignerRSA} from "../../../utils/cryptography/signers/SignerRSA.sol";
1110

12-
contract ERC7739ECDSAMock is ERC7739, SignerECDSA {
13-
constructor(address signerAddr) EIP712("ERC7739ECDSA", "1") {
14-
_setSigner(signerAddr);
15-
}
16-
}
17-
18-
contract ERC7739P256Mock is ERC7739, SignerP256 {
19-
constructor(bytes32 qx, bytes32 qy) EIP712("ERC7739P256", "1") {
20-
_setSigner(qx, qy);
21-
}
22-
}
23-
24-
contract ERC7739RSAMock is ERC7739, SignerRSA {
25-
constructor(bytes memory e, bytes memory n) EIP712("ERC7739RSA", "1") {
26-
_setSigner(e, n);
27-
}
28-
}
11+
abstract contract ERC7739ECDSAMock is ERC7739, SignerECDSA {}
12+
abstract contract ERC7739P256Mock is ERC7739, SignerP256 {}
13+
abstract contract ERC7739RSAMock is ERC7739, SignerRSA {}

contracts/utils/cryptography/signers/MultiSignerERC7913.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ abstract contract MultiSignerERC7913 is AbstractSigner {
6969
/// @dev The `threshold` is unreachable given the number of `signers`.
7070
error MultiSignerERC7913UnreachableThreshold(uint64 signers, uint64 threshold);
7171

72+
constructor(bytes[] memory signers_, uint64 threshold_) {
73+
_addSigners(signers_);
74+
_setThreshold(threshold_);
75+
}
76+
7277
/**
7378
* @dev Returns a slice of the set of authorized signers.
7479
*

contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ abstract contract MultiSignerERC7913Weighted is MultiSignerERC7913 {
6767
/// @dev Thrown when the arrays lengths don't match. See {_setSignerWeights}.
6868
error MultiSignerERC7913WeightedMismatchedLength();
6969

70+
constructor(bytes[] memory signers_, uint64[] memory weights_, uint64 threshold_) MultiSignerERC7913(signers_, 1) {
71+
_setSignerWeights(signers_, weights_);
72+
_setThreshold(threshold_);
73+
}
74+
7075
/// @dev Gets the weight of a signer. Returns 0 if the signer is not authorized.
7176
function signerWeight(bytes memory signer) public view virtual returns (uint64) {
7277
unchecked {

contracts/utils/cryptography/signers/SignerECDSA.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import {ECDSA} from "../ECDSA.sol";
2727
abstract contract SignerECDSA is AbstractSigner {
2828
address private _signer;
2929

30+
constructor(address signerAddr) {
31+
_setSigner(signerAddr);
32+
}
33+
3034
/**
3135
* @dev Sets the signer with the address of the native signer. This function should be called during construction
3236
* or through an initializer.

contracts/utils/cryptography/signers/SignerERC7913.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import {SignatureChecker} from "../SignatureChecker.sol";
3131
abstract contract SignerERC7913 is AbstractSigner {
3232
bytes private _signer;
3333

34+
constructor(bytes memory signer_) {
35+
_setSigner(signer_);
36+
}
37+
3438
/// @dev Return the ERC-7913 signer (i.e. `verifier || key`).
3539
function signer() public view virtual returns (bytes memory) {
3640
return _signer;

contracts/utils/cryptography/signers/SignerP256.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ abstract contract SignerP256 is AbstractSigner {
3030

3131
error SignerP256InvalidPublicKey(bytes32 qx, bytes32 qy);
3232

33+
constructor(bytes32 qx, bytes32 qy) {
34+
_setSigner(qx, qy);
35+
}
36+
3337
/**
3438
* @dev Sets the signer with a P256 public key. This function should be called during construction
3539
* or through an initializer.

contracts/utils/cryptography/signers/SignerRSA.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ abstract contract SignerRSA is AbstractSigner {
2828
bytes private _e;
2929
bytes private _n;
3030

31+
constructor(bytes memory e, bytes memory n) {
32+
_setSigner(e, n);
33+
}
34+
3135
/**
3236
* @dev Sets the signer with a RSA public key. This function should be called during construction
3337
* or through an initializer.

test/account/AccountECDSA.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function fixture() {
1919

2020
// ERC-4337 account
2121
const helper = new ERC4337Helper();
22-
const mock = await helper.newAccount('$AccountECDSAMock', ['AccountECDSA', '1', signer]);
22+
const mock = await helper.newAccount('$AccountECDSAMock', [signer, 'AccountECDSA', '1']);
2323

2424
// ERC-4337 Entrypoint domain
2525
const entrypointDomain = await getDomain(entrypoint.v08);

0 commit comments

Comments
 (0)