Skip to content

Commit

Permalink
feat: add public key override to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtsukino committed Feb 1, 2024
1 parent e7f46fc commit 3d82cb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tlsn-js",
"version": "v0.1.0-alpha.3-rc2",
"version": "v0.1.0-alpha.3",
"description": "",
"repository": "https://github.com/tlsnotary/tlsn-js",
"main": "build/index.js",
Expand Down
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,26 @@ export const prove = async (

export const verify = async (
proof: Proof,
publicKeyOverride?: string,
): Promise<{
time: number;
sent: string;
recv: string;
notaryUrl: string;
}> => {
const res = await fetch(proof.notaryUrl + '/info');
const json: any = await res.json();
const publicKey = json.publicKey as string;
const publicKey =
publicKeyOverride || (await fetchPublicKeyFromNotary(proof.notaryUrl));
const tlsn = await getTLSN();
const result = await tlsn.verify(proof, publicKey);
return {
...result,
notaryUrl: proof.notaryUrl,
};
};

async function fetchPublicKeyFromNotary(notaryUrl: string) {
const res = await fetch(notaryUrl + '/info');
const json: any = await res.json();
if (!json.publicKey) throw new Error('invalid response');
return json.publicKey;
}

0 comments on commit 3d82cb9

Please sign in to comment.