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

Update structure to match hash #8

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
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
26 changes: 20 additions & 6 deletions contracts/package/attestation/EASverify.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,32 @@
contract EASverify is AsnDecode, Pok, IdAttest {
using ECDSA for bytes32;

bytes32 constant EIP712_DOMAIN_TYPE_HASH =

Check failure on line 22 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

'EIP712_DOMAIN_TYPE_HASH' should start with _

Check failure on line 22 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

'EIP712_DOMAIN_TYPE_HASH' should start with _
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

// add some time gap to avoid problems with clock sync
uint constant TIME_GAP = 20;

Check failure on line 26 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

'TIME_GAP' should start with _

Check failure on line 26 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

'TIME_GAP' should start with _

string constant name = "EAS Attestation";

// EAS lib hardcoded schema, be carefull if you are going to change it
bytes32 constant ATTEST_TYPEHASH =
keccak256(
"Attest(bytes32 schema,address recipient,uint64 time,uint64 expirationTime,bool revocable,bytes32 refUID,bytes data)"

Check warning on line 33 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

Line length must be no more than 120 but current length is 129

Check warning on line 33 in contracts/package/attestation/EASverify.sol

View workflow job for this annotation

GitHub Actions / solhint

Line length must be no more than 120 but current length is 129
);

struct AttestationCoreData {
bytes32 schema; // The UID of the associated EAS schema
address recipient; // The recipient of the attestation.
uint64 time; // The time when the attestation expires (Unix timestamp).
uint64 time; // The time when the attestation is valid from (Unix timestamp).
uint64 expirationTime; // The time when the attestation expires (Unix timestamp).
bool revocable; // Whether the attestation is revocable.
bytes32 refUID; // The UID of the related attestation.
bytes data; // Custom attestation data.
uint256 value; // An explicit ETH amount to send to the resolver. This is important to prevent accidental user errors.
bytes32 schema;
bytes data; // The actual Schema data (eg eventId: 12345, ticketId: 6 etc)
}

struct EasTicketData {
string conferenceId;
string eventId;
string ticketIdString;
uint8 ticketClass;
bytes commitment;
Expand Down Expand Up @@ -129,6 +128,21 @@
}
}

function decodeAttestationData(
AttestationCoreData memory easAttestation
) public pure returns (
string memory eventId,
string memory ticketId,
uint8 ticketClass,
bytes memory commitment
)
{
(eventId, ticketId, ticketClass, commitment) = abi.decode(
easAttestation.data,
(string, string, uint8, bytes)
);
}

function decodeEasTicketData(
bytes memory attestation,
uint256 hashIndex,
Expand Down Expand Up @@ -184,7 +198,7 @@

activeByTimestamp = validateTicketTimestamps(payloadObjectData);

(ticket.conferenceId, ticket.ticketIdString, ticket.ticketClass, ticket.commitment) = abi.decode(
(ticket.eventId, ticket.ticketIdString, ticket.ticketClass, ticket.commitment) = abi.decode(
payloadObjectData.data,
(string, string, uint8, bytes)
);
Expand Down
8 changes: 4 additions & 4 deletions test/EAS.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const EAS_CONFIG = {

const EAS_TICKET_SCHEMA = {
fields: [
{ name: "devconId", type: "string" },
{ name: "eventId", type: "string" },
{ name: "ticketIdString", type: "string" },
{ name: "ticketClass", type: "uint8" },
{ name: "commitment", type: "bytes", isCommitment: true },
Expand Down Expand Up @@ -75,7 +75,7 @@ let attestationManager = new EasTicketAttestation(
const pubKeyConfig = { "6": issuerPrivKey };

const ticketRequestData = {
devconId: "6",
eventId: "6",
ticketIdString: "12345",
ticketClass: 2,
commitment: email,
Expand Down Expand Up @@ -186,8 +186,8 @@ describe("EAS verify", function () {

// default responce data
expect(attestResponce.ticketIssuer).to.equal(issuerWalletTestnet.address);
expect(attestResponce.ticket.conferenceId).to.equal(
ticketRequestData.devconId
expect(attestResponce.ticket.eventId).to.equal(
ticketRequestData.eventId
);
expect(attestResponce.ticket.ticketIdString).to.equal(
ticketRequestData.ticketIdString
Expand Down
Loading