feat: add public key override to verify (#13)

This commit is contained in:
tsukino
2024-01-31 21:33:34 -05:00
committed by GitHub
parent e7f46fc41b
commit 7603b3de13
2 changed files with 11 additions and 4 deletions

View File

@@ -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",

View File

@@ -63,15 +63,15 @@ 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 {
@@ -79,3 +79,10 @@ export const verify = async (
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;
}