Skip to content

Commit

Permalink
chore: up
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Sep 24, 2024
1 parent 1f90a41 commit 25d682e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions contracts/src/P256BatchDelegation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,50 @@ contract P256BatchDelegation is MultiSendCallOnly {
/// @notice Thrown when a signature is invalid.
error InvalidSignature();

/// @notice List of authorized invoker public keys.
P256.PublicKey[] public invokers;
/// @notice List of authorized delegate public keys.
P256.PublicKey[] public delegates;

/// @notice Internal nonce used for replay protection.
uint256 public nonce;

/// @notice Authorizes a new public key to invoke on behalf of the Authority.
/// @notice Authorizes a new public key to execute on behalf of the Authority.
/// @param publicKey - The public key to authorize.
function authorize(P256.PublicKey calldata publicKey) public {
if (msg.sender != address(this)) revert InvalidAuthority();
invokers.push(publicKey);
delegates.push(publicKey);
}

/// @notice Revokes an invoker public key.
/// @param invokerIndex - The index of the public key to revoke.
function revoke(uint32 invokerIndex) public {
/// @notice Revokes a delegate public key.
/// @param delegateIndex - The index of the public key to revoke.
function revoke(uint32 delegateIndex) public {
if (msg.sender != address(this)) revert InvalidAuthority();
invokers[invokerIndex] = invokers[invokers.length - 1];
invokers.pop();
delegates[delegateIndex] = delegates[delegates.length - 1];
delegates.pop();
}

/// @notice Executes a set of calls on behalf of the Authority, provided a P256 signature over the calls and an invoker index.
/// @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 invokerIndex - The index of the invoker public key to use.
function execute(bytes memory calls, P256.Signature memory signature, uint32 invokerIndex) public {
/// @param delegateIndex - The index of the delegate public key to use.
function execute(bytes memory calls, P256.Signature memory signature, uint32 delegateIndex) public {
bytes32 digest = keccak256(abi.encodePacked(nonce++, calls));
if (!P256.verify(digest, signature, invokers[invokerIndex])) revert InvalidSignature();
if (!P256.verify(digest, signature, delegates[delegateIndex])) revert InvalidSignature();
multiSend(calls);
}

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

0 comments on commit 25d682e

Please sign in to comment.