@kynesyslabs/demosdk 2.7.0 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+ /**
3
+ * TLSNotary - Browser-based HTTPS Attestation
4
+ *
5
+ * This module provides TLSNotary attestation capabilities for the Demos SDK.
6
+ * It runs the TLSNotary Prover in a Web Worker using WASM, communicates with
7
+ * a Notary server, and produces cryptographic proofs of HTTPS requests.
8
+ *
9
+ * NOTE: This module is browser-only. It requires Web Workers and WASM support.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { TLSNotary } from '@kynesyslabs/demosdk/tlsnotary';
14
+ *
15
+ * // Option 1: Explicit configuration
16
+ * const tlsn = new TLSNotary({
17
+ * notaryUrl: 'wss://node.demos.sh:7047',
18
+ * websocketProxyUrl: 'wss://node.demos.sh:55688',
19
+ * });
20
+ *
21
+ * // Option 2: Discovery via Demos instance (preferred)
22
+ * const demos = new Demos({ rpc: 'https://node.demos.sh' });
23
+ * const tlsn = await demos.tlsnotary();
24
+ *
25
+ * await tlsn.initialize();
26
+ *
27
+ * const result = await tlsn.attest({
28
+ * url: 'https://api.github.com/users/octocat',
29
+ * headers: { 'User-Agent': 'DemosSDK' },
30
+ * });
31
+ *
32
+ * console.log('Verified server:', result.verification.serverName);
33
+ * console.log('Response:', result.verification.recv);
34
+ * ```
35
+ */
36
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
37
+ if (k2 === undefined) k2 = k;
38
+ var desc = Object.getOwnPropertyDescriptor(m, k);
39
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
40
+ desc = { enumerable: true, get: function() { return m[k]; } };
41
+ }
42
+ Object.defineProperty(o, k2, desc);
43
+ }) : (function(o, m, k, k2) {
44
+ if (k2 === undefined) k2 = k;
45
+ o[k2] = m[k];
46
+ }));
47
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
48
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
49
+ }) : function(o, v) {
50
+ o["default"] = v;
51
+ });
52
+ var __importStar = (this && this.__importStar) || (function () {
53
+ var ownKeys = function(o) {
54
+ ownKeys = Object.getOwnPropertyNames || function (o) {
55
+ var ar = [];
56
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
57
+ return ar;
58
+ };
59
+ return ownKeys(o);
60
+ };
61
+ return function (mod) {
62
+ if (mod && mod.__esModule) return mod;
63
+ var result = {};
64
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
65
+ __setModuleDefault(result, mod);
66
+ return result;
67
+ };
68
+ })();
69
+ Object.defineProperty(exports, "__esModule", { value: true });
70
+ exports.TLSNotary = void 0;
71
+ const Comlink = __importStar(require("comlink"));
72
+ const tlsn_js_1 = require("tlsn-js");
73
+ /**
74
+ * TLSNotary class for browser-based HTTPS attestation
75
+ *
76
+ * This class handles:
77
+ * - Running the Prover (MPC-TLS client) in the browser via WASM
78
+ * - Communicating with the Demos Node's Notary server
79
+ * - Attesting HTTPS requests with cryptographic proofs
80
+ * - Verifying attestations offline
81
+ */
82
+ class TLSNotary {
83
+ /**
84
+ * Create a new TLSNotary instance
85
+ *
86
+ * @param config - Configuration with notary and proxy URLs
87
+ */
88
+ constructor(config) {
89
+ this.worker = null;
90
+ // Using any for Comlink wrapper as types are lost across the worker boundary
91
+ this.wasm = null;
92
+ this.initialized = false;
93
+ this.initializingPromise = null;
94
+ this.config = {
95
+ loggingLevel: "Info",
96
+ ...config,
97
+ };
98
+ }
99
+ /**
100
+ * Initialize the WASM module
101
+ *
102
+ * Must be called before any attestation operations.
103
+ * Only needs to be called once per page load.
104
+ *
105
+ * @throws Error if WASM initialization fails
106
+ */
107
+ async initialize() {
108
+ if (this.initialized)
109
+ return;
110
+ if (this.initializingPromise)
111
+ return this.initializingPromise;
112
+ this.initializingPromise = (async () => {
113
+ try {
114
+ // Create Web Worker for WASM operations
115
+ // Note: This requires a bundler that supports worker URLs (webpack, vite, etc.)
116
+ // @ts-expect-error - import.meta.url is browser-only and requires ESNext module
117
+ this.worker = new Worker(new URL("./worker.ts", import.meta.url), {
118
+ type: "module",
119
+ });
120
+ this.wasm = Comlink.wrap(this.worker);
121
+ // Initialize WASM with logging level
122
+ await this.wasm.init({ loggingLevel: this.config.loggingLevel });
123
+ this.initialized = true;
124
+ }
125
+ catch (e) {
126
+ // Clean up partially created resources
127
+ if (this.worker) {
128
+ this.worker.terminate();
129
+ this.worker = null;
130
+ }
131
+ this.wasm = null;
132
+ this.initialized = false;
133
+ // Reset promise to allow retries on failure
134
+ this.initializingPromise = null;
135
+ throw e;
136
+ }
137
+ })();
138
+ return this.initializingPromise;
139
+ }
140
+ /**
141
+ * Attest an HTTPS request using the step-by-step method
142
+ *
143
+ * This provides full control over the attestation process including
144
+ * custom commit ranges for selective disclosure.
145
+ *
146
+ * @param request - Request configuration (URL, method, headers, body)
147
+ * @param commit - Optional commit ranges for selective disclosure
148
+ * @param onStatus - Optional status callback for progress updates
149
+ * @returns Attestation result with proof and verification
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const result = await tlsn.attest({
154
+ * url: 'https://api.example.com/user',
155
+ * method: 'GET',
156
+ * headers: { 'Authorization': 'Bearer token' },
157
+ * }, {
158
+ * // Hide authorization header in the proof
159
+ * sent: [{ start: 0, end: 50 }, { start: 100, end: 200 }],
160
+ * recv: [{ start: 0, end: 500 }],
161
+ * });
162
+ * ```
163
+ */
164
+ async attest(request, commit, onStatus) {
165
+ if (!this.initialized || !this.wasm) {
166
+ throw new Error("TLSNotary not initialized. Call initialize() first.");
167
+ }
168
+ const status = onStatus || (() => { });
169
+ // Extract server DNS from URL
170
+ const url = new URL(request.url);
171
+ const serverDns = url.hostname;
172
+ // Step 1: Connect to Notary
173
+ status("Connecting to Notary server...");
174
+ const notary = tlsn_js_1.NotaryServer.from(this.config.notaryUrl);
175
+ // Step 2: Create Prover
176
+ status("Creating Prover instance...");
177
+ const prover = (await new this.wasm.Prover({
178
+ serverDns,
179
+ maxSentData: request.maxSentData || 16384,
180
+ maxRecvData: request.maxRecvData || 16384,
181
+ }));
182
+ let presentation = null;
183
+ try {
184
+ // Step 3: Setup MPC-TLS session
185
+ status("Setting up MPC-TLS session...");
186
+ await prover.setup(await notary.sessionUrl());
187
+ // Step 4: Send the HTTPS request
188
+ status(`Sending attested request to ${serverDns}...`);
189
+ const headers = {
190
+ Accept: "application/json",
191
+ ...request.headers,
192
+ };
193
+ await prover.sendRequest(this.config.websocketProxyUrl, {
194
+ url: request.url,
195
+ method: (request.method || "GET"),
196
+ headers,
197
+ body: request.body,
198
+ });
199
+ // Step 5: Get transcript
200
+ status("Getting transcript...");
201
+ const transcript = await prover.transcript();
202
+ const { sent, recv } = transcript;
203
+ // Step 6: Create commit ranges (what to reveal)
204
+ status("Creating attestation commitment...");
205
+ const commitRanges = commit || {
206
+ sent: [{ start: 0, end: Math.min(sent.length, 200) }],
207
+ recv: [{ start: 0, end: Math.min(recv.length, 300) }],
208
+ };
209
+ // Step 7: Notarize
210
+ status("Generating attestation (this may take a moment)...");
211
+ const notarizationOutputs = await prover.notarize(commitRanges);
212
+ // Step 8: Create presentation
213
+ status("Creating presentation...");
214
+ presentation = (await new this.wasm.Presentation({
215
+ attestationHex: notarizationOutputs.attestation,
216
+ secretsHex: notarizationOutputs.secrets,
217
+ notaryUrl: notarizationOutputs.notaryUrl,
218
+ websocketProxyUrl: notarizationOutputs.websocketProxyUrl,
219
+ reveal: { ...commitRanges, server_identity: true },
220
+ }));
221
+ const presentationJSON = await presentation.json();
222
+ // Step 9: Verify the presentation
223
+ status("Verifying attestation...");
224
+ const verification = await this.verify(presentationJSON);
225
+ status("Attestation complete!");
226
+ return {
227
+ presentation: presentationJSON,
228
+ verification,
229
+ };
230
+ }
231
+ finally {
232
+ // Free WASM memory to prevent leaks
233
+ if (presentation) {
234
+ await presentation.free();
235
+ }
236
+ if (prover) {
237
+ await prover.free();
238
+ }
239
+ }
240
+ }
241
+ /**
242
+ * Quick attestation using the helper method
243
+ *
244
+ * Simpler API with less control over the process.
245
+ * Good for straightforward use cases.
246
+ *
247
+ * @param options - Attestation options including request and commit config
248
+ * @returns Attestation result with proof and verification
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * const result = await tlsn.attestQuick({
253
+ * url: 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd',
254
+ * });
255
+ * ```
256
+ */
257
+ async attestQuick(options) {
258
+ if (!this.initialized || !this.wasm) {
259
+ throw new Error("TLSNotary not initialized. Call initialize() first.");
260
+ }
261
+ const { onStatus, commit, ...request } = options;
262
+ const status = onStatus || (() => { });
263
+ status("Running quick attestation...");
264
+ const presentationJSON = await this.wasm.Prover.notarize({
265
+ notaryUrl: this.config.notaryUrl,
266
+ websocketProxyUrl: this.config.websocketProxyUrl,
267
+ maxSentData: request.maxSentData || 16384,
268
+ maxRecvData: request.maxRecvData || 16384,
269
+ url: request.url,
270
+ method: (request.method || "GET"),
271
+ headers: {
272
+ Accept: "application/json",
273
+ ...request.headers,
274
+ },
275
+ body: request.body,
276
+ commit: commit || {
277
+ sent: [{ start: 0, end: 100 }],
278
+ recv: [{ start: 0, end: 200 }],
279
+ },
280
+ serverIdentity: true,
281
+ });
282
+ status("Verifying attestation...");
283
+ const verification = await this.verify(presentationJSON);
284
+ status("Quick attestation complete!");
285
+ return {
286
+ presentation: presentationJSON,
287
+ verification,
288
+ };
289
+ }
290
+ /**
291
+ * Verify a presentation/proof
292
+ *
293
+ * Can be used to verify proofs from other sources.
294
+ * This operation can be done offline.
295
+ *
296
+ * @param presentationJSON - The presentation to verify
297
+ * @returns Verification result with extracted data
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * // Load a saved proof
302
+ * const savedProof = JSON.parse(localStorage.getItem('proof'));
303
+ * const result = await tlsn.verify(savedProof);
304
+ *
305
+ * console.log('Server:', result.serverName);
306
+ * console.log('Time:', new Date(result.time * 1000));
307
+ * console.log('Response:', result.recv);
308
+ * ```
309
+ */
310
+ async verify(presentationJSON) {
311
+ if (!this.initialized || !this.wasm) {
312
+ throw new Error("TLSNotary not initialized. Call initialize() first.");
313
+ }
314
+ const proof = (await new this.wasm.Presentation(presentationJSON.data));
315
+ try {
316
+ const verifierOutput = await proof.verify();
317
+ const transcript = new tlsn_js_1.Transcript({
318
+ sent: verifierOutput.transcript?.sent || [],
319
+ recv: verifierOutput.transcript?.recv || [],
320
+ });
321
+ const vk = await proof.verifyingKey();
322
+ // Try to get notary key if available
323
+ let notaryKey = "N/A";
324
+ try {
325
+ if (this.config.notaryPublicKey) {
326
+ notaryKey = this.config.notaryPublicKey;
327
+ }
328
+ else {
329
+ const notary = tlsn_js_1.NotaryServer.from(this.config.notaryUrl);
330
+ notaryKey = await notary.publicKey("hex");
331
+ }
332
+ }
333
+ catch (error) {
334
+ // Notary might not be running for offline verification
335
+ console.warn("[TLSNotary] Could not fetch notary public key:", error instanceof Error ? error.message : error);
336
+ }
337
+ return {
338
+ time: verifierOutput.connection_info.time,
339
+ serverName: verifierOutput.server_name,
340
+ sent: transcript.sent(),
341
+ recv: transcript.recv(),
342
+ notaryKey,
343
+ verifyingKey: Buffer.from(vk.data).toString("hex"),
344
+ };
345
+ }
346
+ finally {
347
+ // Free WASM memory to prevent leaks
348
+ if (proof) {
349
+ await proof.free();
350
+ }
351
+ }
352
+ }
353
+ /**
354
+ * Get the transcript from an attestation for inspection
355
+ *
356
+ * Useful for determining commit ranges for selective disclosure.
357
+ *
358
+ * @param request - Request to send (without creating attestation)
359
+ * @returns Transcript with sent and received bytes
360
+ */
361
+ async getTranscript(request) {
362
+ if (!this.initialized || !this.wasm) {
363
+ throw new Error("TLSNotary not initialized. Call initialize() first.");
364
+ }
365
+ const url = new URL(request.url);
366
+ const serverDns = url.hostname;
367
+ const notary = tlsn_js_1.NotaryServer.from(this.config.notaryUrl);
368
+ const prover = (await new this.wasm.Prover({
369
+ serverDns,
370
+ maxSentData: request.maxSentData || 16384,
371
+ maxRecvData: request.maxRecvData || 16384,
372
+ }));
373
+ try {
374
+ await prover.setup(await notary.sessionUrl());
375
+ await prover.sendRequest(this.config.websocketProxyUrl, {
376
+ url: request.url,
377
+ method: (request.method || "GET"),
378
+ headers: {
379
+ Accept: "application/json",
380
+ ...request.headers,
381
+ },
382
+ body: request.body,
383
+ });
384
+ const transcript = await prover.transcript();
385
+ return {
386
+ sent: transcript.sent,
387
+ recv: transcript.recv,
388
+ };
389
+ }
390
+ finally {
391
+ // Free WASM memory to prevent leaks
392
+ if (prover) {
393
+ await prover.free();
394
+ }
395
+ }
396
+ }
397
+ /**
398
+ * Cleanup resources
399
+ *
400
+ * Call when done with TLSNotary to release the Web Worker.
401
+ */
402
+ destroy() {
403
+ if (this.worker) {
404
+ this.worker.terminate();
405
+ this.worker = null;
406
+ }
407
+ this.wasm = null;
408
+ this.initialized = false;
409
+ }
410
+ /**
411
+ * Check if WASM is initialized
412
+ */
413
+ isInitialized() {
414
+ return this.initialized;
415
+ }
416
+ /**
417
+ * Get current configuration
418
+ */
419
+ getConfig() {
420
+ return { ...this.config };
421
+ }
422
+ /**
423
+ * Update configuration
424
+ *
425
+ * Note: Changes take effect on next attestation.
426
+ * If changing notary URL, you may want to re-initialize.
427
+ */
428
+ updateConfig(config) {
429
+ this.config = { ...this.config, ...config };
430
+ }
431
+ }
432
+ exports.TLSNotary = TLSNotary;
433
+ exports.default = TLSNotary;
434
+ //# sourceMappingURL=TLSNotary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TLSNotary.js","sourceRoot":"","sources":["../../../src/tlsnotary/TLSNotary.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAkC;AAClC,qCAOgB;AAchB;;;;;;;;GAQG;AACH,MAA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G,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;YAE5C,OAAO;gBACH,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,IAAI,EAAE,UAAU,CAAC,IAAI;aACxB,CAAA;QACL,CAAC;gBAAS,CAAC;YACP,oCAAoC;YACpC,IAAI,MAAM,EAAE,CAAC;gBACT,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YACvB,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,OAAO;QACH,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;YACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACtB,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAA;IAC5B,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO,IAAI,CAAC,WAAW,CAAA;IAC3B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAA;IAC7B,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,MAAgC;QACzC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAA;IAC/C,CAAC;CACJ;AAlZD,8BAkZC;AAED,kBAAe,SAAS,CAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * TLSNotary SDK Module
3
+ *
4
+ * Browser-based HTTPS attestation using MPC-TLS.
5
+ *
6
+ * @packageDocumentation
7
+ * @module tlsnotary
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { TLSNotary } from '@kynesyslabs/demosdk/tlsnotary';
12
+ *
13
+ * const tlsn = new TLSNotary({
14
+ * notaryUrl: 'wss://node.demos.sh:7047',
15
+ * websocketProxyUrl: 'wss://node.demos.sh:55688',
16
+ * });
17
+ *
18
+ * await tlsn.initialize();
19
+ *
20
+ * const result = await tlsn.attest({
21
+ * url: 'https://api.github.com/users/octocat',
22
+ * });
23
+ *
24
+ * console.log('Verified:', result.verification.serverName);
25
+ * ```
26
+ */
27
+ export { TLSNotary } from "./TLSNotary";
28
+ export type { TLSNotaryConfig, TLSNotaryDiscoveryInfo, AttestRequest, AttestResult, AttestOptions, CommitRanges, Range, PresentationJSON, VerificationResult, TranscriptInfo, StatusCallback, } from "./types";
29
+ export { default } from "./TLSNotary";
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * TLSNotary SDK Module
4
+ *
5
+ * Browser-based HTTPS attestation using MPC-TLS.
6
+ *
7
+ * @packageDocumentation
8
+ * @module tlsnotary
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { TLSNotary } from '@kynesyslabs/demosdk/tlsnotary';
13
+ *
14
+ * const tlsn = new TLSNotary({
15
+ * notaryUrl: 'wss://node.demos.sh:7047',
16
+ * websocketProxyUrl: 'wss://node.demos.sh:55688',
17
+ * });
18
+ *
19
+ * await tlsn.initialize();
20
+ *
21
+ * const result = await tlsn.attest({
22
+ * url: 'https://api.github.com/users/octocat',
23
+ * });
24
+ *
25
+ * console.log('Verified:', result.verification.serverName);
26
+ * ```
27
+ */
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.default = exports.TLSNotary = void 0;
33
+ var TLSNotary_1 = require("./TLSNotary");
34
+ Object.defineProperty(exports, "TLSNotary", { enumerable: true, get: function () { return TLSNotary_1.TLSNotary; } });
35
+ // Re-export default
36
+ var TLSNotary_2 = require("./TLSNotary");
37
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(TLSNotary_2).default; } });
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tlsnotary/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;;;;AAEH,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAelB,oBAAoB;AACpB,yCAAqC;AAA5B,qHAAA,OAAO,OAAA"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * TLSNotary Types
3
+ *
4
+ * TypeScript interfaces for the TLSNotary SDK module.
5
+ */
6
+ /**
7
+ * Configuration for TLSNotary instance
8
+ */
9
+ export interface TLSNotaryConfig {
10
+ /** Notary server URL (e.g., 'wss://node.demos.sh:7047') */
11
+ notaryUrl: string;
12
+ /** WebSocket proxy URL for TCP tunneling (e.g., 'wss://node.demos.sh:55688') */
13
+ websocketProxyUrl: string;
14
+ /** Notary's public key (hex string) for verification */
15
+ notaryPublicKey?: string;
16
+ /** Logging level: 'Debug' | 'Info' | 'Warn' | 'Error' */
17
+ loggingLevel?: "Debug" | "Info" | "Warn" | "Error";
18
+ }
19
+ /**
20
+ * Discovery response from node's nodeCall
21
+ */
22
+ export interface TLSNotaryDiscoveryInfo {
23
+ /** Notary WebSocket URL */
24
+ notaryUrl: string;
25
+ /** WebSocket proxy URL */
26
+ proxyUrl: string;
27
+ /** Notary's public key (hex) */
28
+ publicKey: string;
29
+ /** TLSNotary version */
30
+ version: string;
31
+ }
32
+ /**
33
+ * Request configuration for attestation
34
+ */
35
+ export interface AttestRequest {
36
+ /** Target HTTPS URL to attest */
37
+ url: string;
38
+ /** HTTP method (default: 'GET') */
39
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
40
+ /** Request headers */
41
+ headers?: Record<string, string>;
42
+ /** Request body (for POST/PUT/PATCH) */
43
+ body?: string | object;
44
+ /** Max bytes to send (default: 16384) */
45
+ maxSentData?: number;
46
+ /** Max bytes to receive (default: 16384) */
47
+ maxRecvData?: number;
48
+ }
49
+ /**
50
+ * Byte range for selective disclosure
51
+ */
52
+ export interface Range {
53
+ /** Start byte offset (inclusive) */
54
+ start: number;
55
+ /** End byte offset (exclusive) */
56
+ end: number;
57
+ }
58
+ /**
59
+ * Commit ranges for selective disclosure
60
+ */
61
+ export interface CommitRanges {
62
+ /** Byte ranges of sent data to reveal */
63
+ sent: Range[];
64
+ /** Byte ranges of received data to reveal */
65
+ recv: Range[];
66
+ }
67
+ import type { PresentationJSON } from "tlsn-js/build/types";
68
+ export type { PresentationJSON };
69
+ /**
70
+ * Transcript information from the TLS session
71
+ */
72
+ export interface TranscriptInfo {
73
+ /** Raw bytes sent (as number array from WASM) */
74
+ sent: number[];
75
+ /** Raw bytes received (as number array from WASM) */
76
+ recv: number[];
77
+ }
78
+ /**
79
+ * Result of attestation verification
80
+ */
81
+ export interface VerificationResult {
82
+ /** Unix timestamp of the TLS session */
83
+ time: number;
84
+ /** Verified server name (e.g., 'api.github.com') */
85
+ serverName: string;
86
+ /** Revealed sent data as string */
87
+ sent: string;
88
+ /** Revealed received data as string */
89
+ recv: string;
90
+ /** Notary's public key (hex) */
91
+ notaryKey: string;
92
+ /** Verifying key from the proof (hex) */
93
+ verifyingKey: string;
94
+ }
95
+ /**
96
+ * Complete attestation result
97
+ */
98
+ export interface AttestResult {
99
+ /** Presentation JSON (the proof) */
100
+ presentation: PresentationJSON;
101
+ /** Verification result */
102
+ verification: VerificationResult;
103
+ }
104
+ /**
105
+ * Status callback for progress updates during attestation
106
+ */
107
+ export type StatusCallback = (status: string) => void;
108
+ /**
109
+ * Options for attestation with additional controls
110
+ */
111
+ export interface AttestOptions extends AttestRequest {
112
+ /** Custom commit ranges for selective disclosure */
113
+ commit?: CommitRanges;
114
+ /** Status callback for progress updates */
115
+ onStatus?: StatusCallback;
116
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /**
3
+ * TLSNotary Types
4
+ *
5
+ * TypeScript interfaces for the TLSNotary SDK module.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tlsnotary/types.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
@@ -0,0 +1,20 @@
1
+ import init, { Prover, Presentation } from "tlsn-js";
2
+ /**
3
+ * Worker API exposed via Comlink
4
+ */
5
+ declare const workerApi: {
6
+ /**
7
+ * Initialize the WASM module
8
+ */
9
+ init: typeof init;
10
+ /**
11
+ * Prover class for creating attestations
12
+ */
13
+ Prover: typeof Prover;
14
+ /**
15
+ * Presentation class for verifying attestations
16
+ */
17
+ Presentation: typeof Presentation;
18
+ };
19
+ export type WorkerApi = typeof workerApi;
20
+ export {};