Skip to content

Commit 95e4e63

Browse files
authored
feat: alpha.9 (#44)
1 parent 1ae4191 commit 95e4e63

File tree

9 files changed

+54
-42
lines changed

9 files changed

+54
-42
lines changed

package-lock.json

Lines changed: 16 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"redux-thunk": "^2.4.2",
5959
"stream": "^0.0.2",
6060
"tailwindcss": "^3.3.3",
61-
"tlsn-js": "0.1.0-alpha.7.1",
61+
"tlsn-js": "0.1.0-alpha.9",
6262
"tlsn-js-v5": "npm:[email protected]",
6363
"ws": "^8.16.0"
6464
},

server/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { verify } from '../rs/verifier/index.node';
1414
// @ts-ignore
1515
import { verify as verifyV7 } from '../rs/0.1.0-alpha.7/index.node';
1616
import { Attestation } from '../web/utils/types/types';
17-
import { convertNotaryWsToHttp } from '../web/utils';
1817
import { IncomingMessage } from 'node:http';
1918
import { createServer } from 'http';
2019
import { WebSocketServer, type RawData, type WebSocket } from 'ws';
2120
import crypto from 'crypto';
2221
import qs from 'qs';
22+
import { convertNotaryWsToHttp } from '../utils/url';
2323

2424
const app = express();
2525
const port = process.env.PORT || 3000;
@@ -114,15 +114,15 @@ app.get('/ipfs/:cid', async (req, res) => {
114114
notaryUrl: jsonProof.notaryUrl,
115115
notaryKey: notaryPem,
116116
};
117-
} else if (jsonProof.version === '0.1.0-alpha.7') {
117+
} else if (jsonProof.version) {
118118
const notaryUrl = convertNotaryWsToHttp(jsonProof.meta.notaryUrl);
119119
const notaryPem = await fetchPublicKeyFromNotary(notaryUrl).catch(
120120
() => '',
121121
);
122122
const proof = await verifyV7(jsonProof.data, notaryPem);
123123
proof.notaryUrl = jsonProof.meta.notaryUrl;
124124
storeConfig.proofs.ipfs[req.params.cid].proof = {
125-
version: '0.1.0-alpha.7',
125+
version: jsonProof.version,
126126
time: proof.time,
127127
sent: proof.sent,
128128
recv: proof.recv,

utils/url.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function convertNotaryWsToHttp(notaryWs: string) {
2+
const { protocol, pathname, hostname, port } = new URL(notaryWs);
3+
const p = protocol === 'wss:' ? 'https:' : 'http:';
4+
const pt = port ? `:${port}` : '';
5+
const path = pathname === '/' ? '' : pathname.replace('/notarize', '');
6+
const h = hostname === 'localhost' ? '127.0.0.1' : hostname;
7+
return p + '//' + h + pt + path;
8+
}

web/components/SharedProof/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { FileDropdown } from '../FileDropdown';
77
import { PubkeyInput } from '../../pages/PubkeyInput';
88
import { AttestedData } from '../../utils/types/types';
99
import { File } from '@web-std/file';
10-
import { verify } from '../../utils';
1110

1211
export default function SharedProof(): ReactElement {
1312
const { cid } = useParams();
@@ -33,6 +32,8 @@ export default function SharedProof(): ReactElement {
3332
const onVerify = useCallback(
3433
async (key = '') => {
3534
if (!proofData?.raw) return;
35+
const { verify } = await import('../../utils');
36+
3637
const resp = await verify(proofData?.raw, key);
3738
setVerifiedProof(resp);
3839
},

web/pages/FileDrop/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { ReactElement, useCallback, useState } from 'react';
22
import { useDispatch } from 'react-redux';
3-
import { readFileAsync, safeParseJSON, verify } from '../../utils';
43
import FileUploadInput from '../../components/FileUploadInput';
54
import ProofViewer from '../../components/ProofViewer';
65
import {
@@ -24,6 +23,7 @@ export default function FileDrop(): ReactElement {
2423

2524
const onVerify = useCallback(async (json: Attestation, key = '') => {
2625
try {
26+
const { verify } = await import('../../utils');
2727
const resp = await verify(json, key);
2828
setVerifiedProof(resp);
2929
setStep('result');
@@ -54,6 +54,7 @@ export default function FileDrop(): ReactElement {
5454

5555
setError('');
5656

57+
const { readFileAsync, safeParseJSON } = await import('../../utils');
5758
const proofContent = await readFileAsync(file);
5859
const json: Attestation = safeParseJSON(proofContent);
5960

web/store/proofs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useSelector } from 'react-redux';
44
import deepEqual from 'fast-deep-equal';
55
import { EXPLORER_URL } from '../utils/constants';
66
import { Attestation, AttestedData } from '../utils/types/types';
7-
import { verify } from '../utils';
87

98
enum ActionType {
109
SetIPFSProof = 'proofs/setIPFSProof',
@@ -54,9 +53,12 @@ export const fetchProofFromIPFS =
5453
data = old.raw;
5554
}
5655

57-
const proof = await verify(data, notaryKey);
56+
if (typeof window !== 'undefined') {
57+
const { verify } = await import('../utils');
58+
const proof = await verify(data, notaryKey);
5859

59-
dispatch(setIPFSProof({ cid, proof, raw: data }));
60+
dispatch(setIPFSProof({ cid, proof, raw: data }));
61+
}
6062
};
6163

6264
export const setIPFSProof = (

web/utils/index.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React, { ReactElement, useRef } from 'react';
22
import { Attestation, AttestedData } from './types/types';
3+
import * as Comlink from 'comlink';
4+
import { convertNotaryWsToHttp } from '../../utils/url';
5+
const { init, Presentation }: any = Comlink.wrap(
6+
new Worker(new URL('./worker.ts', import.meta.url)),
7+
);
38

49
export const readFileAsync = (file: File): Promise<string> => {
510
return new Promise((resolve, reject) => {
@@ -89,8 +94,6 @@ async function initTlsnJs() {
8994
if (tlsnInitPromise) return tlsnInitPromise;
9095
const { promise, resolve } = defer();
9196
tlsnInitPromise = promise;
92-
93-
const { default: init } = await import('tlsn-js');
9497
await init();
9598
resolve();
9699
}
@@ -117,9 +120,11 @@ export async function verify(
117120
notaryKey: key,
118121
};
119122
}
120-
case '0.1.0-alpha.7': {
121-
const { Presentation, Transcript } = await import('tlsn-js');
122-
const tlsProof = new Presentation(attestation.data);
123+
case '0.1.0-alpha.7':
124+
case '0.1.0-alpha.8':
125+
case '0.1.0-alpha.9':
126+
const { Transcript } = await import('tlsn-js');
127+
const tlsProof = await new Presentation(attestation.data);
123128
const data = await tlsProof.verify();
124129
const transcript = new Transcript({
125130
sent: data.transcript.sent,
@@ -133,7 +138,7 @@ export async function verify(
133138
.catch(() => '');
134139

135140
return {
136-
version: '0.1.0-alpha.7',
141+
version: attestation.version,
137142
sent: transcript.sent(),
138143
recv: transcript.recv(),
139144
time: data.connection_info.time,
@@ -142,21 +147,11 @@ export async function verify(
142147
websocketProxyUrl: attestation.meta.websocketProxyUrl,
143148
verifierKey: verifyingKey,
144149
};
145-
}
146150
}
147151

148152
throw new Error('Invalid Proof');
149153
}
150154

151-
export function convertNotaryWsToHttp(notaryWs: string) {
152-
const { protocol, pathname, hostname, port } = new URL(notaryWs);
153-
const p = protocol === 'wss:' ? 'https:' : 'http:';
154-
const pt = port ? `:${port}` : '';
155-
const path = pathname === '/' ? '' : pathname.replace('/notarize', '');
156-
const h = hostname === 'localhost' ? '127.0.0.1' : hostname;
157-
return p + '//' + h + pt + path;
158-
}
159-
160155
function defer(): {
161156
promise: Promise<any>;
162157
resolve: (args?: any) => any;

web/utils/types/types.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
export interface AttestedData {
2-
version: '0.1.0-alpha.7' | '0.1.0-alpha.5';
2+
version:
3+
| '0.1.0-alpha.7'
4+
| '0.1.0-alpha.8'
5+
| '0.1.0-alpha.9'
6+
| '0.1.0-alpha.5';
37
time: number;
48
sent: string;
59
recv: string;
@@ -17,7 +21,7 @@ export type AttestationV0 = {
1721
};
1822

1923
export type AttestationV1 = {
20-
version: '0.1.0-alpha.7';
24+
version: '0.1.0-alpha.7' | '0.1.0-alpha.8' | '0.1.0-alpha.9';
2125
data: string;
2226
meta: {
2327
notaryUrl: string;

0 commit comments

Comments
 (0)