Skip to content

Commit

Permalink
feat: A few extra functions and params
Browse files Browse the repository at this point in the history
- Add public functions that return signer public key and address.
- Add param to skip revocation check when calling validateEasAttestation.
  • Loading branch information
micwallace committed Jul 24, 2023
1 parent 639258c commit 8a23705
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/javascript/crypto/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main/javascript/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokenscript/attestation",
"version": "0.5.1",
"version": "0.6.0",
"description": "A library for integrating cryptographic attestations into applications",
"type": "commonjs",
"main": "dist/index.js",
Expand Down
29 changes: 16 additions & 13 deletions src/main/javascript/crypto/src/eas/EasTicketAttestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
private signedAttestation: SignedOffchainAttestation;
private signerAddress: string;
private signerPublicKey: string;
private signerKeyPair?: KeyPair;
private decodedData?: {[fieldName: string]: any};
private commitmentSecret?: bigint;
private conferenceKeys?: KeyPair[];
Expand Down Expand Up @@ -172,6 +171,8 @@ export class EasTicketAttestation extends AttestableObject implements Attestable

this.signedAttestation = newAttestation;

this.recoverSignerInfo();

return this.getEasJson();
}

Expand Down Expand Up @@ -206,11 +207,6 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
return zipAndEncodeToBase64(this.getEasJson());
}

// TODO: Return ID based on decoded data
/*getTicketId(){
this.checkAttestationIsLoaded();
}*/

getAttestationData(){
this.checkAttestationIsLoaded();

Expand All @@ -227,8 +223,6 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
this.decodedData[value.name] = dataArr[index].value.value;
index++;
}

//this.decodedData["commitment"] = dataArr[index].value;
}

return this.decodedData;
Expand Down Expand Up @@ -261,7 +255,7 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
throw new Error("Commitment verification failed.");
}

async validateEasAttestation(){
async validateEasAttestation(skipRevocationCheck = false){

this.checkAttestationIsLoaded();

Expand All @@ -271,9 +265,11 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
// Expiry check
this.checkValidity();

if(skipRevocationCheck || !this.signedAttestation.message.revocable)
return;

// EAS registry check to make sure attestation is not revoked
if(this.signedAttestation.message.revocable)
await this.checkRevocation()
await this.checkRevocation()
}

private async checkRevocation(uid?: string){
Expand Down Expand Up @@ -492,7 +488,6 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
for (const key of this.conferenceKeys){

if (this.signerPublicKey.substring(2) === key.getPublicKeyAsHexStr()) {
this.signerKeyPair = key;
return true;
}
}
Expand All @@ -501,7 +496,15 @@ export class EasTicketAttestation extends AttestableObject implements Attestable
}

getSignerKeyPair(){
return this.signerKeyPair;
return KeyPair.fromPublicHex(this.signerPublicKey);

Check warning on line 499 in src/main/javascript/crypto/src/eas/EasTicketAttestation.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

getSignerKey(){

Check warning on line 502 in src/main/javascript/crypto/src/eas/EasTicketAttestation.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return this.signerPublicKey;

Check warning on line 503 in src/main/javascript/crypto/src/eas/EasTicketAttestation.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

getSignerAddress(){

Check warning on line 506 in src/main/javascript/crypto/src/eas/EasTicketAttestation.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return this.signerAddress;

Check warning on line 507 in src/main/javascript/crypto/src/eas/EasTicketAttestation.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

getCommitment(): Uint8Array {
Expand Down

0 comments on commit 8a23705

Please sign in to comment.