Sitelet https://github.com/wjorgensen/OneWalletDemo/commit/8b373cdae322091855bc8b99f46b6d910eb2a637
Skip to content

Commit 8b373cd

Browse files
committed
chore: up
1 parent 2458c1d commit 8b373cd

4 files changed

Lines changed: 53 additions & 100 deletions

File tree

‎contracts/src/ExperimentDelegation.sol‎

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ contract ExperimentDelegation is MultiSendCallOnly {
1515
// Data Structures
1616
////////////////////////////////////////////////////////////////////////
1717

18-
/// @notice The type of key.
19-
enum KeyType {
20-
P256,
21-
WebAuthnP256
22-
}
23-
2418
/// @notice A Key that can be used to authorize calls.
2519
/// @custom:property authorized - Whether the key is authorized.
2620
/// @custom:property publicKey - ECDSA public key.
2721
/// @custom:property expiry - Unix timestamp at which the key expires.
28-
/// @custom:property keyType - Type of key.
2922
struct Key {
3023
bool authorized;
3124
uint256 expiry;
32-
KeyType keyType;
3325
ECDSA.PublicKey publicKey;
3426
}
3527

@@ -61,19 +53,16 @@ contract ExperimentDelegation is MultiSendCallOnly {
6153

6254
/// @notice Authorizes a new public key.
6355
/// @param publicKey - The public key to authorize.
64-
/// @param keyType - The type of key. 0 = P256, 1 = WebAuthn-P256, 2 = WebCrypto-P256.
6556
/// @param expiry - The Unix timestamp at which the key expires.
6657
function authorize(
6758
ECDSA.PublicKey calldata publicKey,
68-
KeyType keyType,
6959
uint256 expiry
70-
) public returns (uint32 publicKeyIndex) {
60+
) public returns (uint32 keyIndex) {
7161
if (msg.sender != address(this)) revert InvalidAuthority();
7262

7363
Key memory key = Key({
7464
authorized: true,
7565
expiry: expiry,
76-
keyType: keyType,
7766
publicKey: publicKey
7867
});
7968
keys.push(key);
@@ -83,15 +72,13 @@ contract ExperimentDelegation is MultiSendCallOnly {
8372

8473
/// @notice Authorizes a new public key on behalf of the Authority, provided the Authority's signature.
8574
/// @param publicKey - The public key to authorize.
86-
/// @param keyType - The type of key. 0 = P256, 1 = WebAuthn-P256, 2 = WebCrypto-P256.
8775
/// @param expiry - The Unix timestamp at which the key expires.
8876
/// @param signature - EOA secp256k1 signature over the public key.
8977
function authorize(
9078
ECDSA.PublicKey calldata publicKey,
91-
KeyType keyType,
9279
uint256 expiry,
9380
ECDSA.RecoveredSignature calldata signature
94-
) public returns (uint32 publicKeyIndex) {
81+
) public returns (uint32 keyIndex) {
9582
bytes32 digest = keccak256(
9683
abi.encodePacked(nonce++, publicKey.x, publicKey.y, expiry)
9784
);
@@ -106,7 +93,6 @@ contract ExperimentDelegation is MultiSendCallOnly {
10693
Key memory key = Key({
10794
authorized: true,
10895
expiry: expiry,
109-
keyType: keyType,
11096
publicKey: publicKey
11197
});
11298
keys.push(key);
@@ -115,21 +101,21 @@ contract ExperimentDelegation is MultiSendCallOnly {
115101
}
116102

117103
/// @notice Revokes an authorized public key.
118-
/// @param publicKeyIndex - The index of the public key to revoke.
119-
function revoke(uint32 publicKeyIndex) public {
104+
/// @param keyIndex - The index of the public key to revoke.
105+
function revoke(uint32 keyIndex) public {
120106
if (msg.sender != address(this)) revert InvalidAuthority();
121-
keys[publicKeyIndex].authorized = false;
107+
keys[keyIndex].authorized = false;
122108
}
123109

124110
/// @notice Revokes an authorized public key on behalf of the Authority, provided the Authority's signature.
125-
/// @param publicKeyIndex - The index of the public key to revoke.
111+
/// @param keyIndex - The index of the public key to revoke.
126112
/// @param signature - EOA secp256k1 signature over the public key index.
127113
function revoke(
128-
uint32 publicKeyIndex,
114+
uint32 keyIndex,
129115
ECDSA.RecoveredSignature calldata signature
130116
) public {
131117
bytes32 digest = keccak256(
132-
abi.encodePacked(nonce++, publicKeyIndex)
118+
abi.encodePacked(nonce++, keyIndex)
133119
);
134120
address signer = ecrecover(
135121
digest,
@@ -138,7 +124,7 @@ contract ExperimentDelegation is MultiSendCallOnly {
138124
bytes32(signature.s)
139125
);
140126
if (signer != address(this)) revert InvalidSignature();
141-
keys[publicKeyIndex].authorized = false;
127+
keys[keyIndex].authorized = false;
142128
}
143129

144130
/// @notice Executes a set of calls.
@@ -151,18 +137,18 @@ contract ExperimentDelegation is MultiSendCallOnly {
151137
/// @notice Executes a set of calls on behalf of the Authority, provided a P256 signature over the calls and a public key index.
152138
/// @param calls - The calls to execute.
153139
/// @param signature - The P256 signature over the calls: `p256.sign(keccak256(nonce ‖ calls))`.
154-
/// @param publicKeyIndex - The index of the authorized public key to use.
140+
/// @param keyIndex - The index of the authorized public key to use.
155141
/// @param prehash - Whether to SHA-256 hash the digest.
156142
function execute(
157143
bytes memory calls,
158144
ECDSA.Signature memory signature,
159-
uint32 publicKeyIndex,
145+
uint32 keyIndex,
160146
bool prehash
161147
) public {
162148
bytes32 digest = keccak256(abi.encodePacked(nonce++, calls));
163149
if (prehash) digest = sha256(abi.encodePacked(digest));
164150

165-
Key memory key = keys[publicKeyIndex];
151+
Key memory key = keys[keyIndex];
166152
if (!key.authorized) revert KeyNotAuthorized();
167153
if (key.expiry > 0 && key.expiry < block.timestamp) revert KeyExpired();
168154

@@ -177,19 +163,16 @@ contract ExperimentDelegation is MultiSendCallOnly {
177163
/// @param calls - The calls to execute.
178164
/// @param signature - The WebAuthn-wrapped P256 signature over the calls: `p256.sign(keccak256(nonce ‖ calls))`.
179165
/// @param metadata - The WebAuthn metadata.
180-
/// @param publicKeyIndex - The index of the authorized public key to use.
181-
/// @param prehash - Whether to SHA-256 hash the digest.
166+
/// @param keyIndex - The index of the authorized public key to use.
182167
function execute(
183168
bytes memory calls,
184169
ECDSA.Signature memory signature,
185170
WebAuthnP256.Metadata memory metadata,
186-
uint32 publicKeyIndex,
187-
bool prehash
171+
uint32 keyIndex
188172
) public {
189173
bytes32 challenge = keccak256(abi.encodePacked(nonce++, calls));
190-
if (prehash) challenge = sha256(abi.encodePacked(challenge));
191174

192-
Key memory key = keys[publicKeyIndex];
175+
Key memory key = keys[keyIndex];
193176
if (!key.authorized) revert KeyNotAuthorized();
194177
if (key.expiry > 0 && key.expiry < block.timestamp) revert KeyExpired();
195178

‎contracts/test/ExperimentDelegation.t.sol‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@ contract ExperimentDelegationTest is Test {
4949

5050
vm.prank(address(delegation));
5151
vm.resumeGasMetering();
52-
delegation.authorize(publicKey, ExperimentDelegation.KeyType.P256, 0);
52+
delegation.authorize(publicKey, 0);
5353
vm.pauseGasMetering();
5454

5555
(
5656
bool authorized,
5757
uint256 expiry,
58-
ExperimentDelegation.KeyType keyType,
5958
ECDSA.PublicKey memory authorizedPublicKey
6059
) = delegation.keys(0);
6160
assertEq(authorized, true);
@@ -74,7 +73,7 @@ contract ExperimentDelegationTest is Test {
7473

7574
vm.resumeGasMetering();
7675
vm.expectRevert(ExperimentDelegation.InvalidAuthority.selector);
77-
delegation.authorize(publicKey, ExperimentDelegation.KeyType.P256, 0);
76+
delegation.authorize(publicKey, 0);
7877
}
7978

8079
function test_revoke() public {
@@ -84,7 +83,7 @@ contract ExperimentDelegationTest is Test {
8483
ECDSA.PublicKey memory publicKey = ECDSA.PublicKey(x, y);
8584

8685
vm.prank(address(delegation));
87-
delegation.authorize(publicKey, ExperimentDelegation.KeyType.P256, 0);
86+
delegation.authorize(publicKey, 0);
8887

8988
delegation.keys(0);
9089

@@ -96,7 +95,6 @@ contract ExperimentDelegationTest is Test {
9695
(
9796
bool authorized,
9897
uint256 expiry,
99-
ExperimentDelegation.KeyType keyType,
10098
ECDSA.PublicKey memory authorizedPublicKey
10199
) = delegation.keys(0);
102100
assertEq(authorized, false);
@@ -143,7 +141,6 @@ contract ExperimentDelegationTest is Test {
143141
vm.prank(address(delegation));
144142
delegation.authorize(
145143
ECDSA.PublicKey(x, y),
146-
ExperimentDelegation.KeyType.P256,
147144
0
148145
);
149146

@@ -200,7 +197,6 @@ contract ExperimentDelegationTest is Test {
200197
vm.prank(address(delegation));
201198
delegation.authorize(
202199
ECDSA.PublicKey(x, y),
203-
ExperimentDelegation.KeyType.P256,
204200
0
205201
);
206202

@@ -256,7 +252,6 @@ contract ExperimentDelegationTest is Test {
256252
vm.prank(address(delegation));
257253
delegation.authorize(
258254
ECDSA.PublicKey(x, y),
259-
ExperimentDelegation.KeyType.P256,
260255
block.timestamp
261256
);
262257

@@ -309,7 +304,6 @@ contract ExperimentDelegationTest is Test {
309304
vm.prank(address(delegation));
310305
delegation.authorize(
311306
ECDSA.PublicKey(x, y),
312-
ExperimentDelegation.KeyType.P256,
313307
0
314308
);
315309

‎example/src/contracts.ts‎

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ export const ExperimentDelegation = {
1515
{ name: 'y', type: 'uint256', internalType: 'uint256' },
1616
],
1717
},
18+
{ name: 'expiry', type: 'uint256', internalType: 'uint256' },
1819
{
19-
name: 'keyType',
20-
type: 'uint8',
21-
internalType: 'enum ExperimentDelegation.KeyType',
20+
name: 'signature',
21+
type: 'tuple',
22+
internalType: 'struct ECDSA.RecoveredSignature',
23+
components: [
24+
{ name: 'r', type: 'uint256', internalType: 'uint256' },
25+
{ name: 's', type: 'uint256', internalType: 'uint256' },
26+
{ name: 'yParity', type: 'uint8', internalType: 'uint8' },
27+
],
2228
},
23-
{ name: 'expiry', type: 'uint256', internalType: 'uint256' },
24-
],
25-
outputs: [
26-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
2729
],
30+
outputs: [{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' }],
2831
stateMutability: 'nonpayable',
2932
},
3033
{
@@ -40,26 +43,9 @@ export const ExperimentDelegation = {
4043
{ name: 'y', type: 'uint256', internalType: 'uint256' },
4144
],
4245
},
43-
{
44-
name: 'keyType',
45-
type: 'uint8',
46-
internalType: 'enum ExperimentDelegation.KeyType',
47-
},
4846
{ name: 'expiry', type: 'uint256', internalType: 'uint256' },
49-
{
50-
name: 'signature',
51-
type: 'tuple',
52-
internalType: 'struct ECDSA.RecoveredSignature',
53-
components: [
54-
{ name: 'r', type: 'uint256', internalType: 'uint256' },
55-
{ name: 's', type: 'uint256', internalType: 'uint256' },
56-
{ name: 'yParity', type: 'uint8', internalType: 'uint8' },
57-
],
58-
},
59-
],
60-
outputs: [
61-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
6247
],
48+
outputs: [{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' }],
6349
stateMutability: 'nonpayable',
6450
},
6551
{
@@ -83,8 +69,23 @@ export const ExperimentDelegation = {
8369
{ name: 's', type: 'uint256', internalType: 'uint256' },
8470
],
8571
},
86-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
87-
{ name: 'prehash', type: 'bool', internalType: 'bool' },
72+
{
73+
name: 'metadata',
74+
type: 'tuple',
75+
internalType: 'struct WebAuthnP256.Metadata',
76+
components: [
77+
{ name: 'authenticatorData', type: 'bytes', internalType: 'bytes' },
78+
{ name: 'clientDataJSON', type: 'string', internalType: 'string' },
79+
{ name: 'challengeIndex', type: 'uint16', internalType: 'uint16' },
80+
{ name: 'typeIndex', type: 'uint16', internalType: 'uint16' },
81+
{
82+
name: 'userVerificationRequired',
83+
type: 'bool',
84+
internalType: 'bool',
85+
},
86+
],
87+
},
88+
{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' },
8889
],
8990
outputs: [],
9091
stateMutability: 'nonpayable',
@@ -103,23 +104,7 @@ export const ExperimentDelegation = {
103104
{ name: 's', type: 'uint256', internalType: 'uint256' },
104105
],
105106
},
106-
{
107-
name: 'metadata',
108-
type: 'tuple',
109-
internalType: 'struct WebAuthnP256.Metadata',
110-
components: [
111-
{ name: 'authenticatorData', type: 'bytes', internalType: 'bytes' },
112-
{ name: 'clientDataJSON', type: 'string', internalType: 'string' },
113-
{ name: 'challengeIndex', type: 'uint16', internalType: 'uint16' },
114-
{ name: 'typeIndex', type: 'uint16', internalType: 'uint16' },
115-
{
116-
name: 'userVerificationRequired',
117-
type: 'bool',
118-
internalType: 'bool',
119-
},
120-
],
121-
},
122-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
107+
{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' },
123108
{ name: 'prehash', type: 'bool', internalType: 'bool' },
124109
],
125110
outputs: [],
@@ -132,11 +117,6 @@ export const ExperimentDelegation = {
132117
outputs: [
133118
{ name: 'authorized', type: 'bool', internalType: 'bool' },
134119
{ name: 'expiry', type: 'uint256', internalType: 'uint256' },
135-
{
136-
name: 'keyType',
137-
type: 'uint8',
138-
internalType: 'enum ExperimentDelegation.KeyType',
139-
},
140120
{
141121
name: 'publicKey',
142122
type: 'tuple',
@@ -166,17 +146,15 @@ export const ExperimentDelegation = {
166146
{
167147
type: 'function',
168148
name: 'revoke',
169-
inputs: [
170-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
171-
],
149+
inputs: [{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' }],
172150
outputs: [],
173151
stateMutability: 'nonpayable',
174152
},
175153
{
176154
type: 'function',
177155
name: 'revoke',
178156
inputs: [
179-
{ name: 'publicKeyIndex', type: 'uint32', internalType: 'uint32' },
157+
{ name: 'keyIndex', type: 'uint32', internalType: 'uint32' },
180158
{
181159
name: 'signature',
182160
type: 'tuple',
@@ -196,7 +174,7 @@ export const ExperimentDelegation = {
196174
{ type: 'error', name: 'KeyExpired', inputs: [] },
197175
{ type: 'error', name: 'KeyNotAuthorized', inputs: [] },
198176
],
199-
address: '0x685641EbFDC2c04201d4E09f04712F41cc727567',
177+
address: '0x6bbce6b04736f9db8d3dbE509b87Da3BC1435439',
200178
} as const
201179

202180
export const ExperimentERC20 = {

0 commit comments

Comments
 (0)