Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ simplify json parsing #35

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 21 additions & 43 deletions test/WebAuthn256r1.create.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Test, stdJson } from "../lib/forge-std/src/Test.sol";
import { WebAuthnWrapper } from "./WebAuthnWrapper.sol";

contract WebAuthn256r1Test__Create is Test {

Check warning on line 7 in test/WebAuthn256r1.create.t.sol

View workflow job for this annotation

GitHub Actions / lint

Contract name must be in CamelCase

Check warning on line 7 in test/WebAuthn256r1.create.t.sol

View workflow job for this annotation

GitHub Actions / lint

Contract name must be in CamelCase
using stdJson for string;

WebAuthnWrapper internal implem;
Expand Down Expand Up @@ -46,49 +46,27 @@

// load a random credential from the JSON file
string memory fixturesId = string.concat(".data[", vm.toString(identifier), "]");
emit log_named_string("fixturesId", fixturesId);

{
// load the clientDataJSON
bytes memory credentialsResponseEncoded =
json.parseRaw(string.concat(fixturesId, ".response.clientDataJSON"));
clientDataJSON = abi.decode(credentialsResponseEncoded, (bytes));
}

{
// load the client challenge from the client data JSON
bytes memory challengeEncoded =
json.parseRaw(string.concat(fixturesId, ".responseDecoded.ClientDataJSON.challenge"));
challenge = abi.decode(challengeEncoded, (bytes));
}

{
// load the auth data from the client data JSON
bytes memory authDataEncoded = json.parseRaw(string.concat(fixturesId, ".response.authData"));
authData = abi.decode(authDataEncoded, (bytes));
}

{
// load qx
qx = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyX"));
}

{
// load qy
qy = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyY"));
}

{
// load R
string memory key = ".responseDecoded.AttestationObject.attStmt.r";
r = json.readUint(string.concat(fixturesId, key));
}

{
// load S
string memory key = ".responseDecoded.AttestationObject.attStmt.s";
s = json.readUint(string.concat(fixturesId, key));
}

// load the clientDataJSON
clientDataJSON = json.readBytes(string.concat(fixturesId, ".response.clientDataJSON"));

// load the client challenge from the client data JSON
challenge = json.readBytes(string.concat(fixturesId, ".responseDecoded.ClientDataJSON.challenge"));

// load the auth data from the client data JSON
authData = json.readBytes(string.concat(fixturesId, ".response.authData"));

// load qx
qx = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyX"));

// load qy
qy = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.authData.pubKeyY"));

// load R
r = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.attStmt.r"));

// load S
s = json.readUint(string.concat(fixturesId, ".responseDecoded.AttestationObject.attStmt.s"));

assertTrue(implem.verify(authData, clientDataJSON, challenge, r, s, qx, qy));
}
Expand Down
Loading