mirror of
https://github.com/tlsnotary/tlsn-js.git
synced 2026-01-09 20:47:55 -05:00
feat: add public key override to verify (#13)
This commit is contained in:
@@ -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",
|
||||
|
||||
13
src/index.ts
13
src/index.ts
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user