Skip to content

Commit

Permalink
feat: batch auth
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Sep 24, 2024
1 parent cc5e3ac commit 5befe24
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions contracts/src/P256BatchDelegation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ contract P256BatchDelegation is MultiSendCallOnly {
delegates.push(publicKey);
}

/// @notice Authorizes multiple public keys to execute on behalf of the Authority.
/// @param publicKeys - The public keys to authorize.
function authorize(P256.PublicKey[] calldata publicKeys) public {
for (uint32 i = 0; i < publicKeys.length; i++) {
authorize(publicKeys[i]);
}
}

/// @notice Revokes a delegate public key.
/// @param delegateIndex - The index of the public key to revoke.
function revoke(uint32 delegateIndex) public {
Expand All @@ -36,13 +44,26 @@ contract P256BatchDelegation is MultiSendCallOnly {
delegates.pop();
}

/// @notice Revokes multiple delegate public keys.
/// @param delegateIndices - The indices of the public keys to revoke.
function revoke(uint32[] calldata delegateIndices) public {
for (uint32 i = 0; i < delegateIndices.length; i++) {
revoke(delegateIndices[i]);
}
}

/// @notice Executes a set of calls on behalf of the Authority, provided a P256 signature over the calls and a delegate index.
/// @param calls - The calls to execute.
/// @param signature - The P256 signature over the calls: `p256.sign(keccak256(nonce ‖ calls))`.
/// @param delegateIndex - The index of the delegate public key to use.
function execute(bytes memory calls, P256.Signature memory signature, uint32 delegateIndex) public {
function execute(
bytes memory calls,
P256.Signature memory signature,
uint32 delegateIndex
) public {
bytes32 digest = keccak256(abi.encodePacked(nonce++, calls));
if (!P256.verify(digest, signature, delegates[delegateIndex])) revert InvalidSignature();
if (!P256.verify(digest, signature, delegates[delegateIndex]))
revert InvalidSignature();
multiSend(calls);
}

Expand All @@ -58,7 +79,14 @@ contract P256BatchDelegation is MultiSendCallOnly {
uint32 delegateIndex
) public {
bytes32 challenge = keccak256(abi.encodePacked(nonce++, calls));
if (!WebAuthnP256.verify(challenge, metadata, signature, delegates[delegateIndex])) revert InvalidSignature();
if (
!WebAuthnP256.verify(
challenge,
metadata,
signature,
delegates[delegateIndex]
)
) revert InvalidSignature();
multiSend(calls);
}
}

0 comments on commit 5befe24

Please sign in to comment.