From 69845c99b8c96e9b7725a953f0064616112f722e Mon Sep 17 00:00:00 2001 From: qd-qd Date: Thu, 4 Apr 2024 18:30:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20util=20script=20to=20extract=20s?= =?UTF-8?q?igner=20from=20authdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/utils/ExtractSignerAuthData.s.sol | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 script/utils/ExtractSignerAuthData.s.sol diff --git a/script/utils/ExtractSignerAuthData.s.sol b/script/utils/ExtractSignerAuthData.s.sol new file mode 100644 index 0000000..ec6679f --- /dev/null +++ b/script/utils/ExtractSignerAuthData.s.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: APACHE-2.0 +pragma solidity >=0.8.19 <0.9.0; + +import { BaseScript } from "script/Base.s.sol"; +import { SignerVaultWebAuthnP256R1 } from "src/utils/SignerVaultWebAuthnP256R1.sol"; + +/// @title ExtractSignerAuthData +/// @notice Extract a signer from the auth data +contract ExtractSignerAuthData is BaseScript { + function extractSignerAuthData(bytes calldata authData) + external + pure + returns (bytes memory credId, bytes32 credIdHash, uint256 pubkeyX, uint256 pubkeyY) + { + return SignerVaultWebAuthnP256R1.extractSignerFromAuthData(authData); + } + + function run() + external + view + returns ( + bytes memory credId, + bytes32 credIdHash, + uint256 pubkeyX, + bytes32 pubkeyXHex, + uint256 pubkeyY, + bytes32 pubkeyYHex + ) + { + // 1. get the auth data + bytes memory authData = vm.envBytes("AUTH_DATA"); + + // 2. extract the signer from the auth data + (credId, credIdHash, pubkeyX, pubkeyY) = ExtractSignerAuthData(address(this)).extractSignerAuthData(authData); + + // 3. convert the pubkey coordinates to hex + pubkeyXHex = bytes32(pubkeyX); + pubkeyYHex = bytes32(pubkeyY); + } +}