@kynesyslabs/demosdk 2.7.1 → 2.7.3

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.
package/build/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * as instantMessaging from "./instant_messaging";
15
15
  export * as storage from "./storage";
16
16
  export * as escrow from "./escrow";
17
17
  export * as ipfs from "./ipfs";
18
+ export * as tlsnotary from "./tlsnotary";
package/build/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ipfs = exports.escrow = exports.storage = exports.instantMessaging = exports.bridge = exports.web2 = exports.abstraction = exports.websdk = exports.l2ps = exports.demoswork = exports.wallet = exports.xmcore = exports.xmwebsdk = exports.xmlocalsdk = exports.utils = exports.encryption = exports.types = void 0;
36
+ exports.tlsnotary = exports.ipfs = exports.escrow = exports.storage = exports.instantMessaging = exports.bridge = exports.web2 = exports.abstraction = exports.websdk = exports.l2ps = exports.demoswork = exports.wallet = exports.xmcore = exports.xmwebsdk = exports.xmlocalsdk = exports.utils = exports.encryption = exports.types = void 0;
37
37
  // Common types and constants
38
38
  exports.types = __importStar(require("./types"));
39
39
  // Basic cryptographic and data manipulation functions
@@ -55,4 +55,5 @@ exports.instantMessaging = __importStar(require("./instant_messaging"));
55
55
  exports.storage = __importStar(require("./storage"));
56
56
  exports.escrow = __importStar(require("./escrow"));
57
57
  exports.ipfs = __importStar(require("./ipfs"));
58
+ exports.tlsnotary = __importStar(require("./tlsnotary"));
58
59
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA6B;AAC7B,iDAAgC;AAChC,sDAAsD;AACtD,2DAA0C;AAC1C,iDAAgC;AAEhC,gCAAgC;AAChC,oEAAmD;AACnD,gEAA+C;AAC/C,4DAA2C,CAAC,gCAAgC;AAE5E,mDAAkC;AAClC,yDAAwC;AAExC,+CAA8B;AAE9B,mDAAkC;AAClC,6DAA4C;AAC5C,2DAA0C;AAE1C,qCAAqC;AACrC,mDAAkC;AAElC,wEAAuD;AAEvD,qDAAoC;AAEpC,mDAAkC;AAElC,+CAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA6B;AAC7B,iDAAgC;AAChC,sDAAsD;AACtD,2DAA0C;AAC1C,iDAAgC;AAEhC,gCAAgC;AAChC,oEAAmD;AACnD,gEAA+C;AAC/C,4DAA2C,CAAC,gCAAgC;AAE5E,mDAAkC;AAClC,yDAAwC;AAExC,+CAA8B;AAE9B,mDAAkC;AAClC,6DAA4C;AAC5C,2DAA0C;AAE1C,qCAAqC;AACrC,mDAAkC;AAElC,wEAAuD;AAEvD,qDAAoC;AAEpC,mDAAkC;AAElC,+CAA8B;AAE9B,yDAAwC"}
@@ -0,0 +1,186 @@
1
+ /**
2
+ * TLSNotary - Browser-based HTTPS Attestation
3
+ *
4
+ * This module provides TLSNotary attestation capabilities for the Demos SDK.
5
+ * It runs the TLSNotary Prover in a Web Worker using WASM, communicates with
6
+ * a Notary server, and produces cryptographic proofs of HTTPS requests.
7
+ *
8
+ * NOTE: This module is browser-only. It requires Web Workers and WASM support.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { TLSNotary } from '@kynesyslabs/demosdk/tlsnotary';
13
+ *
14
+ * // Option 1: Explicit configuration
15
+ * const tlsn = new TLSNotary({
16
+ * notaryUrl: 'wss://node.demos.sh:7047',
17
+ * websocketProxyUrl: 'wss://node.demos.sh:55688',
18
+ * });
19
+ *
20
+ * // Option 2: Discovery via Demos instance (preferred)
21
+ * const demos = new Demos({ rpc: 'https://node.demos.sh' });
22
+ * const tlsn = await demos.tlsnotary();
23
+ *
24
+ * await tlsn.initialize();
25
+ *
26
+ * const result = await tlsn.attest({
27
+ * url: 'https://api.github.com/users/octocat',
28
+ * headers: { 'User-Agent': 'DemosSDK' },
29
+ * });
30
+ *
31
+ * console.log('Verified server:', result.verification.serverName);
32
+ * console.log('Response:', result.verification.recv);
33
+ * ```
34
+ */
35
+ import type { PresentationJSON } from "tlsn-js/build/types";
36
+ import type { TLSNotaryConfig, AttestRequest, AttestResult, CommitRanges, VerificationResult, AttestOptions, StatusCallback, TranscriptInfo } from "./types";
37
+ /**
38
+ * TLSNotary class for browser-based HTTPS attestation
39
+ *
40
+ * This class handles:
41
+ * - Running the Prover (MPC-TLS client) in the browser via WASM
42
+ * - Communicating with the Demos Node's Notary server
43
+ * - Attesting HTTPS requests with cryptographic proofs
44
+ * - Verifying attestations offline
45
+ */
46
+ export declare class TLSNotary {
47
+ private config;
48
+ private worker;
49
+ private wasm;
50
+ private initialized;
51
+ private initializingPromise;
52
+ /**
53
+ * Create a new TLSNotary instance
54
+ *
55
+ * @param config - Configuration with notary and proxy URLs
56
+ */
57
+ constructor(config: TLSNotaryConfig);
58
+ /**
59
+ * Initialize the WASM module
60
+ *
61
+ * Must be called before any attestation operations.
62
+ * Only needs to be called once per page load.
63
+ *
64
+ * @throws Error if WASM initialization fails
65
+ */
66
+ initialize(): Promise<void>;
67
+ /**
68
+ * Request a dynamic WebSocket proxy for a target URL
69
+ *
70
+ * This method calls the node's `requestTLSNproxy` endpoint to get a
71
+ * dynamically allocated proxy for the specific target domain.
72
+ * Proxies auto-expire after 30 seconds of inactivity.
73
+ *
74
+ * @param targetUrl - The HTTPS URL to create a proxy for
75
+ * @returns Proxy response with websocketProxyUrl
76
+ * @throws Error if RPC URL is not configured or proxy request fails
77
+ *
78
+ * @internal This is called automatically by attest/attestQuick methods
79
+ */
80
+ private requestProxy;
81
+ /**
82
+ * Get the WebSocket proxy URL for a target URL
83
+ *
84
+ * Automatically requests a dynamic proxy from the node if rpcUrl is configured,
85
+ * otherwise falls back to the static websocketProxyUrl.
86
+ *
87
+ * @param targetUrl - The target HTTPS URL
88
+ * @param onStatus - Optional status callback
89
+ * @returns The websocket proxy URL to use
90
+ */
91
+ private getProxyUrl;
92
+ /**
93
+ * Attest an HTTPS request using the step-by-step method
94
+ *
95
+ * This provides full control over the attestation process including
96
+ * custom commit ranges for selective disclosure.
97
+ *
98
+ * @param request - Request configuration (URL, method, headers, body)
99
+ * @param commit - Optional commit ranges for selective disclosure
100
+ * @param onStatus - Optional status callback for progress updates
101
+ * @returns Attestation result with proof and verification
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const result = await tlsn.attest({
106
+ * url: 'https://api.example.com/user',
107
+ * method: 'GET',
108
+ * headers: { 'Authorization': 'Bearer token' },
109
+ * }, {
110
+ * // Hide authorization header in the proof
111
+ * sent: [{ start: 0, end: 50 }, { start: 100, end: 200 }],
112
+ * recv: [{ start: 0, end: 500 }],
113
+ * });
114
+ * ```
115
+ */
116
+ attest(request: AttestRequest, commit?: CommitRanges, onStatus?: StatusCallback): Promise<AttestResult>;
117
+ /**
118
+ * Quick attestation using the helper method
119
+ *
120
+ * Simpler API with less control over the process.
121
+ * Good for straightforward use cases.
122
+ *
123
+ * @param options - Attestation options including request and commit config
124
+ * @returns Attestation result with proof and verification
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const result = await tlsn.attestQuick({
129
+ * url: 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd',
130
+ * });
131
+ * ```
132
+ */
133
+ attestQuick(options: AttestOptions): Promise<AttestResult>;
134
+ /**
135
+ * Verify a presentation/proof
136
+ *
137
+ * Can be used to verify proofs from other sources.
138
+ * This operation can be done offline.
139
+ *
140
+ * @param presentationJSON - The presentation to verify
141
+ * @returns Verification result with extracted data
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // Load a saved proof
146
+ * const savedProof = JSON.parse(localStorage.getItem('proof'));
147
+ * const result = await tlsn.verify(savedProof);
148
+ *
149
+ * console.log('Server:', result.serverName);
150
+ * console.log('Time:', new Date(result.time * 1000));
151
+ * console.log('Response:', result.recv);
152
+ * ```
153
+ */
154
+ verify(presentationJSON: PresentationJSON): Promise<VerificationResult>;
155
+ /**
156
+ * Get the transcript from an attestation for inspection
157
+ *
158
+ * Useful for determining commit ranges for selective disclosure.
159
+ *
160
+ * @param request - Request to send (without creating attestation)
161
+ * @returns Transcript with sent and received bytes
162
+ */
163
+ getTranscript(request: AttestRequest): Promise<TranscriptInfo>;
164
+ /**
165
+ * Cleanup resources
166
+ *
167
+ * Call when done with TLSNotary to release the Web Worker.
168
+ */
169
+ destroy(): void;
170
+ /**
171
+ * Check if WASM is initialized
172
+ */
173
+ isInitialized(): boolean;
174
+ /**
175
+ * Get current configuration
176
+ */
177
+ getConfig(): TLSNotaryConfig;
178
+ /**
179
+ * Update configuration
180
+ *
181
+ * Note: Changes take effect on next attestation.
182
+ * If changing notary URL, you may want to re-initialize.
183
+ */
184
+ updateConfig(config: Partial<TLSNotaryConfig>): void;
185
+ }
186
+ export default TLSNotary;