@invisible-labs/sdk 0.6.0-devnet.2 → 0.6.0-devnet.4

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.
Files changed (45) hide show
  1. package/README.md +186 -70
  2. package/dist/.invisible-sdk-build-target.json +7 -0
  3. package/dist/{chunk-TQNNTV5F.js → chunk-4X5OCCQW.js} +3 -3
  4. package/dist/{chunk-TQNNTV5F.js.map → chunk-4X5OCCQW.js.map} +1 -1
  5. package/dist/{chunk-7DSVN3MV.js → chunk-5NNEO7IK.js} +41 -36
  6. package/dist/chunk-5NNEO7IK.js.map +1 -0
  7. package/dist/chunk-BRDLLGCZ.js +59 -0
  8. package/dist/chunk-BRDLLGCZ.js.map +1 -0
  9. package/dist/{chunk-NCY4FCYU.js → chunk-DIA6U2CV.js} +19 -3
  10. package/dist/chunk-DIA6U2CV.js.map +1 -0
  11. package/dist/{chunk-LBC7ALYO.js → chunk-E4DCEDAG.js} +177 -12
  12. package/dist/chunk-E4DCEDAG.js.map +1 -0
  13. package/dist/{chunk-OHIM2YWU.js → chunk-GHBQF3A7.js} +2 -2
  14. package/dist/chunk-GHBQF3A7.js.map +1 -0
  15. package/dist/{chunk-SZAYO2L5.js → chunk-NHEHCUS5.js} +3 -3
  16. package/dist/{chunk-SZAYO2L5.js.map → chunk-NHEHCUS5.js.map} +1 -1
  17. package/dist/{chunk-XUWBGET5.js → chunk-UADJCUPK.js} +125 -18
  18. package/dist/chunk-UADJCUPK.js.map +1 -0
  19. package/dist/{chunk-JRMKCE3S.js → chunk-V5HXJRBW.js} +3 -3
  20. package/dist/{chunk-JRMKCE3S.js.map → chunk-V5HXJRBW.js.map} +1 -1
  21. package/dist/{coordinator-7Y45MCCZ.js → coordinator-ZNLGAYXD.js} +3 -3
  22. package/dist/{coordinator-7Y45MCCZ.js.map → coordinator-ZNLGAYXD.js.map} +1 -1
  23. package/dist/events.js +3 -3
  24. package/dist/index.d.ts +62 -300
  25. package/dist/index.js +98 -43
  26. package/dist/index.js.map +1 -1
  27. package/dist/lp.d.ts +51 -10
  28. package/dist/lp.js +313 -86
  29. package/dist/lp.js.map +1 -1
  30. package/dist/presets.d.ts +5 -42
  31. package/dist/presets.js +11 -62
  32. package/dist/presets.js.map +1 -1
  33. package/dist/stats.js +1 -1
  34. package/dist/storage.js +1 -1
  35. package/dist/{createSession-D3ym-Ira.d.ts → types.generated-DJBTjLpP.d.ts} +37 -53
  36. package/dist/user.d.ts +94 -112
  37. package/dist/user.js +649 -248
  38. package/dist/user.js.map +1 -1
  39. package/package.json +2 -28
  40. package/dist/chunk-7DSVN3MV.js.map +0 -1
  41. package/dist/chunk-LBC7ALYO.js.map +0 -1
  42. package/dist/chunk-NCY4FCYU.js.map +0 -1
  43. package/dist/chunk-OHIM2YWU.js.map +0 -1
  44. package/dist/chunk-XUWBGET5.js.map +0 -1
  45. package/dist/types.generated-CHGSbmLp.d.ts +0 -67
package/dist/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { S as Session } from './session-DFuy54C-.js';
2
2
  export { i as isAttested } from './session-DFuy54C-.js';
3
- export { A as AttestationError, a as AttestationErrorCode, b as CommandError, c as CommandErrorCode, d as CommandErrorOptions, e as CoordinatorWireErrorCode, C as CreateSessionOptions, I as InvalidDepositAmountError, f as InvisibleError, g as InvisibleErrorCode, h as InvisibleErrorOptions, L as LpLifecycleError, i as LpLifecycleErrorCode, N as NotImplementedError, j as NotImplementedErrorCode, P as PolicyValidationError, k as PolicyValidationErrorCode, R as RoutingError, l as RoutingErrorCode, S as StorageError, m as StorageErrorCode, T as TransportError, n as TransportErrorCode, W as WalletError, o as WalletErrorCode, p as closeSession, q as createSession, r as isInvisibleError, s as normalizeError } from './createSession-D3ym-Ira.js';
3
+ export { A as AttestationError, a as AttestationErrorCode, C as CommandError, b as CommandErrorCode, c as CommandErrorOptions, d as CoordinatorWireErrorCode, I as InvalidDepositAmountError, e as InvisibleError, f as InvisibleErrorCode, g as InvisibleErrorOptions, L as LpLifecycleError, h as LpLifecycleErrorCode, i as LpPositionView, N as NotImplementedError, j as NotImplementedErrorCode, k as PayoutDestination, P as PayoutPolicy, l as PolicyValidationError, m as PolicyValidationErrorCode, R as RoutingError, n as RoutingErrorCode, S as StorageEnvelope, o as StorageError, p as StorageErrorCode, T as TransportError, q as TransportErrorCode, W as WalletError, r as WalletErrorCode, s as isInvisibleError, t as normalizeError } from './types.generated-DJBTjLpP.js';
4
4
  import { T as Transport, N as NoiseWebSocketTransportOptions, U as Unsubscribe } from './types-ZhV7TIQY.js';
5
5
  export { C as ConnectionState, W as WebSocketFactory, a as WebSocketLike } from './types-ZhV7TIQY.js';
6
- import { C as CoordinatorEndpoint, b as CoordinatorReleasePin } from './types.generated-CHGSbmLp.js';
7
- export { A as AzureMaaPin, a as CoordinatorPoolConfig, L as LpPositionView, c as PayoutDestination, P as PayoutPolicy, S as StorageEnvelope } from './types.generated-CHGSbmLp.js';
8
6
 
9
7
  /**
10
8
  * The API surface version this build implements. Bumped only on a breaking
@@ -134,220 +132,48 @@ declare function inMemoryTransport(options?: InMemoryTransportOptions): InMemory
134
132
  declare function noiseWebSocketTransport(options: NoiseWebSocketTransportOptions): Transport;
135
133
 
136
134
  /**
137
- * TDX DCAP attestation verifier (SDK port of
138
- * `web/src/lib/coordinator/tdx-attestation.ts`).
135
+ * `createSession` - the single entrypoint that opens an attested session.
139
136
  *
140
- * Verifies a TDX DCAP quote on three paths, using Web Crypto (`crypto.subtle`,
141
- * a Node 22 / browser global) and `@peculiar/x509`:
137
+ * It validates the endpoint pool, opens the transport, runs the Noise XX
138
+ * handshake + TDX attestation, and returns an opaque {@link Session} that has
139
+ * already passed attestation (`attested === true`). It resolves only once
140
+ * attestation succeeds; any transport or attestation failure rejects with a
141
+ * typed {@link TransportError} / {@link AttestationError}.
142
142
  *
143
- * - GCP (spec section 5.1): cert chain to the pinned Intel SGX Root CA, TCB
144
- * validity, freshness nonce == REPORT_DATA[0:32], Noise binding ==
145
- * REPORT_DATA[32:64], debug bit clear, MRTD pin.
146
- * - Azure (spec section 5.2): MAA JWT issuer / JWKS / policy-hash / compliance
147
- * / debug, MAA<->DCAP REPORTDATA binding, hcl_keys hash binding, HCL AK pub
148
- * extraction, raw DCAP measurement binding, TPM AK quote signature, TPM
149
- * qualifying data binding.
150
- * - Local (loopback dev fallback): checks nonce and Noise pubkey consistency
151
- * only; no hardware attestation.
152
- *
153
- * Throws the SDK {@link AttestationError} (from `../core/errors.js`) with a
154
- * closed `code` on any failure. Callers fail-closed: tear down the Noise
155
- * transport rather than surface an unverified channel.
156
- *
157
- * Never log secrets, nonces, or raw decrypted payloads (spec section 9).
143
+ * A re-attestation timer re-runs verification over the live channel every
144
+ * {@link REATTEST_EVERY_MS}; on failure it marks the session unattested and
145
+ * notifies any registered policy-violation handlers. The transport is
146
+ * injectable for tests.
147
+ */
148
+
149
+ /** Close a session created by {@link createSession}. */
150
+ declare function closeSession(session: Session): void;
151
+
152
+ interface PublicCreateSessionOptions {
153
+ readonly coordinatorUrl: string;
154
+ readonly storage?: unknown;
155
+ readonly wallet?: unknown;
156
+ }
157
+ /**
158
+ * Open a production-only public SDK session.
158
159
  *
159
- * @module JW-145 / JW-431
160
+ * The caller supplies only the route and public adapters. The Azure
161
+ * production release policy is embedded by the selected SDK build.
160
162
  */
161
- type AttestationMode = "dev" | "prod";
162
- type AzureMaaPolicy = {
163
- /** Expected MAA token issuer for the approved Azure Attestation provider. */
164
- expectedIssuer: string;
165
- /** Expected JWKS endpoint for that provider. Token headers must not choose it. */
166
- expectedJwksUrl: string;
167
- /** Expected Azure Attestation evaluation policy hash from the signed token. */
168
- expectedPolicyHash: string;
169
- };
170
- type AttestationPolicy = {
171
- /**
172
- * Expected MRTD for the published production coordinator build.
173
- * Dev mode ignores this pin entirely.
174
- */
175
- expectedMrtd?: string;
176
- /**
177
- * SHA-256 hash of the approved coordinator binary. Azure production
178
- * attestation requires this pin because binary_hash is otherwise only
179
- * response metadata, even though the TPM quote binds it cryptographically.
180
- */
181
- expectedBinaryHash?: string;
182
- /**
183
- * Runtime mode the client expects for this coordinator route. Production
184
- * builds set this to "prod" so a prod hostname cannot silently accept an
185
- * unpinned dev coordinator after DNS or load-balancer misrouting.
186
- */
187
- requiredMode?: AttestationMode;
188
- /**
189
- * Release tooling only: verify a prod quote before the new MRTD has been
190
- * published. Runtime policy must leave this unset so prod stays fail-closed
191
- * when the pin is missing.
192
- */
193
- allowUnpinnedProdMrtdForRelease?: boolean;
194
- /**
195
- * SHA-256 fingerprint (lowercase hex) of the DER-encoded Intel SGX Root CA.
196
- * Defaults to {@link INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256}. Override only in tests.
197
- */
198
- intelRootFingerprint?: string;
199
- /**
200
- * Temporary non-prod rollout escape hatch for legacy coordinators that have
201
- * not rolled out `dcap_collateral`. When collateral is present, it is always
202
- * verified. Production mode never honors this flag.
203
- */
204
- allowMissingDcapCollateral?: boolean;
205
- /**
206
- * Development-only escape hatch for a local coordinator running on a non-TDX
207
- * machine. The transport only honors this for loopback coordinator URLs.
208
- */
209
- allowLocalAttestation?: boolean;
210
- /**
211
- * Azure-specific trust policy. Required for platform="azure-tdx-dcap" because
212
- * MAA providers and policies are customer-configurable Azure resources.
213
- */
214
- azureMaa?: AzureMaaPolicy;
215
- };
216
- type SignedDcapJson = {
217
- /**
218
- * JSON string returned by Intel PCS. May be either the inner body
219
- * (`tcbInfo` / `enclaveIdentity`) or the full PCS wrapper.
220
- */
221
- body: string;
222
- /** Hex signature over the exact signed body bytes. */
223
- signature: string;
224
- /** PEM chain whose first certificate verifies `signature`, ending at Intel root. */
225
- issuerChainPem: string;
226
- };
227
- type DcapCollateral = {
228
- /** PEM X.509 CRL for the PCK certificate issuer. */
229
- pckCrlPem: string;
230
- /** PEM chain for the PCK CRL issuer, ending at Intel root. */
231
- pckCrlIssuerChainPem: string;
232
- /** PEM X.509 CRL issued by Intel root, covering collateral signing certs. */
233
- rootCaCrlPem: string;
234
- /** Signed Intel TDX TCB Info V3. */
235
- tcbInfo: SignedDcapJson;
236
- /** Signed Intel TD QE Identity V2. */
237
- qeIdentity: SignedDcapJson;
238
- };
239
- type AttestedMetadata = {
240
- mode: AttestationMode;
241
- binaryHash: string;
242
- mrtd: string;
243
- rtmr0: string;
244
- rtmr1: string;
245
- rtmr2: string;
246
- rtmr3: string;
247
- pubkeyHex: string;
248
- localAttestation: boolean;
249
- };
250
- type AttestResponse = {
251
- quote: string;
252
- /**
253
- * Nonce echoed back by the coordinator. Informational only: freshness is
254
- * enforced cryptographically via REPORT_DATA[0:32] inside the TDX quote, not
255
- * by trusting this JSON field.
256
- */
257
- nonce: string;
258
- pubkey: string;
259
- binary_hash: string;
260
- mode: AttestationMode;
261
- /**
262
- * Platform identifier set by the coordinator. Absent on GCP (tdx-dcap).
263
- * Azure returns "azure-tdx-dcap".
264
- */
265
- platform?: string;
266
- /**
267
- * Azure only: MAA JWT from /attest/TdxVm, RS256-signed by MAA. Contains
268
- * tdx_mrtd, tdx_td_attributes_debug, and x-ms-compliance-status.
269
- */
270
- maa_token?: string;
271
- /**
272
- * Azure only: TPM PCR quote packed as
273
- * [4-byte msg_len LE][TPM2B_ATTEST][TPMT_SIGNATURE].
274
- * qualifying_data = SHA-256(nonce || noise_pubkey || binary_hash). Base64-encoded.
275
- */
276
- tpm_quote?: string;
277
- /**
278
- * Azure only: raw bytes (base64) of the JSON key-blob from HCL report NV
279
- * 0x1400001 [1056:]. SHA-256(hcl_keys_json_bytes) == DCAP REPORTDATA[0:32].
280
- * Contains the AK public key as kid="HCLAkPub".
281
- */
282
- hcl_keys_json?: string;
283
- /**
284
- * Intel DCAP verification collateral. When present, the verifier evaluates
285
- * PCK revocation, TCB Info, and TD QE Identity. Policies can require it.
286
- */
287
- dcap_collateral?: DcapCollateral;
288
- local_attestation?: boolean;
289
- };
163
+ declare function createSession(options: PublicCreateSessionOptions): Promise<Session>;
164
+
290
165
  /**
291
- * Assert that an unknown JSON value has the shape of {@link AttestResponse}.
292
- * Throws {@link AttestationError} ("NOT_ATTESTED") on any missing or wrong-typed
293
- * field. Replaces an unsafe cast so missing fields produce a typed error rather
294
- * than silently reaching downstream checks as `undefined`.
166
+ * Session guards used by mutating commands.
295
167
  */
296
- declare function assertAttestResponse(value: unknown): asserts value is AttestResponse;
297
- declare function verifyAttestation(params: {
298
- response: AttestResponse;
299
- expectedNonce: Uint8Array;
300
- expectedNoiseStaticPub: Uint8Array;
301
- policy: AttestationPolicy;
302
- timeoutMs?: number;
303
- }): Promise<AttestedMetadata>;
304
168
 
305
169
  /**
306
- * Secure channel: Noise XX handshake + TDX attestation over a raw transport.
307
- *
308
- * Free functions, no class (SDK conformance). Given an open {@link Transport}
309
- * and a {@link CoordinatorEndpoint}, {@link establishSecureChannel} drives:
310
- *
311
- * 1. the Noise XX handshake (initiator role) over the raw byte channel:
312
- * -> msg1 (e) send raw
313
- * <- msg2 (e, ee, s, es) read raw, reveals the responder static pubkey
314
- * -> msg3 (s, se) send raw, yields the split NoiseTransport
315
- * 2. the attestation exchange over the freshly-split (but not-yet-promoted)
316
- * Noise transport:
317
- * -> encrypt(encodeAttestationRequest(nonceHex))
318
- * <- decodeAttestationResponse(decrypt(frame)) -> verifyAttestation
319
- *
320
- * On success the pending Noise transport is promoted to the live cipher and an
321
- * attested channel handle is returned: `send`/`onMessage` transparently
322
- * Noise-encrypt/decrypt application frames over the raw transport.
323
- *
324
- * The release pin (mrtd, intelRootFingerprint, azureMaa) and the endpoint's
325
- * requiredMode map to the verifier's {@link AttestationPolicy}. The loopback
326
- * local-attestation fallback (ADR-0037) is only enabled when the endpoint host
327
- * is a loopback address - it must never be honored for a remote coordinator.
328
- *
329
- * Never log secrets, nonces, shares, or decrypted payloads (spec section 9).
170
+ * Assert the session has passed attestation. Every mutating actor command calls
171
+ * this before touching the wire, so an unattested session can never sign or
172
+ * send sensitive material.
330
173
  *
331
- * @module JW-428
174
+ * @throws AttestationError `NOT_ATTESTED` when the session is not attested.
332
175
  */
333
-
334
- /** An established, attested Noise channel over a raw transport. */
335
- interface SecureChannel {
336
- /** Verified attestation metadata for the coordinator this channel reached. */
337
- readonly attestation: AttestedMetadata;
338
- /** The coordinator's Noise static public key, pinned for this channel. */
339
- readonly remoteStaticPublicKey: Uint8Array;
340
- /** Request re-attestation without consuming application frames as responses. */
341
- requestAttestation(nonceHex: string, timeoutMs: number): Promise<AttestResponse>;
342
- /** Encrypt and send one application frame over the raw transport. */
343
- send(plaintext: Uint8Array): void;
344
- /** Subscribe to decrypted inbound application frames. */
345
- onMessage(handler: (plaintext: Uint8Array) => void): Unsubscribe;
346
- /** Subscribe to fatal channel failures such as Noise decrypt desync. */
347
- onFatal(handler: (error: Error) => void): Unsubscribe;
348
- /** Tear down the channel: detach listeners and stop accepting frames. */
349
- close(): void;
350
- }
176
+ declare function assertAttested(session: Session): void;
351
177
 
352
178
  /**
353
179
  * Session-establishment seams layered on top of an open {@link Transport}.
@@ -365,17 +191,6 @@ interface SecureChannel {
365
191
  * one step should use {@link establishAttestedChannel}.
366
192
  */
367
193
 
368
- /** Result of a completed Noise XX handshake. */
369
- interface NoiseHandshakeResult {
370
- /** The coordinator's Noise static public key, pinned for this session. */
371
- readonly noiseStaticPublicKey: Uint8Array;
372
- /**
373
- * The attested secure channel produced by this handshake. Carried so a
374
- * subsequent {@link performAttestation} can read attestation evidence without
375
- * re-running the exchange. Internal: not part of the structural contract.
376
- */
377
- readonly channel: SecureChannel;
378
- }
379
194
  /** Result of a completed TDX attestation. */
380
195
  interface AttestationResult {
381
196
  /** The verified release MRTD. */
@@ -384,6 +199,8 @@ interface AttestationResult {
384
199
  readonly mode: "prod" | "dev";
385
200
  /** Coordinator binary hash reported by the verified attestation response. */
386
201
  readonly binaryHash: string;
202
+ /** Compile-time runtime profile carried by the attested coordinator artifact. */
203
+ readonly runtimeProfile?: "prod-hardened" | "prod-devnet-simplified";
387
204
  /** Noise static public key bound into the attestation quote. */
388
205
  readonly pubkeyHex: string;
389
206
  /** True only for explicit loopback local development attestation. */
@@ -395,76 +212,38 @@ interface AttestationResult {
395
212
  /** When verification completed (epoch ms), stamped by the caller. */
396
213
  readonly verifiedAtMs: number;
397
214
  }
398
- /**
399
- * Run the Noise XX handshake over an open transport and pin the coordinator's
400
- * static key. Drives a full attested-channel establishment (attestation is
401
- * bound to the same Noise cipher) and returns the handshake half; read the
402
- * attestation half from {@link performAttestation} with the returned result.
403
- *
404
- * @throws TransportError if the channel fails or the handshake is malformed.
405
- * @throws AttestationError if attestation verification fails.
406
- */
407
- declare function performNoiseHandshake(transport: Transport, endpoint: CoordinatorEndpoint, nonce?: Uint8Array): Promise<NoiseHandshakeResult>;
408
- /**
409
- * Verify the coordinator's TDX attestation, bound to the handshake's Noise
410
- * static key. Reads the evidence captured by {@link performNoiseHandshake}.
411
- *
412
- * @throws TransportError if the handshake result carries no channel.
413
- */
414
- declare function performAttestation(_transport: Transport, handshake: NoiseHandshakeResult): Promise<AttestationResult>;
415
-
416
- /**
417
- * Session guards used by mutating commands.
418
- */
419
215
 
420
- /**
421
- * Assert the session has passed attestation. Every mutating actor command calls
422
- * this before touching the wire, so an unattested session can never sign or
423
- * send sensitive material.
424
- *
425
- * @throws AttestationError `NOT_ATTESTED` when the session is not attested.
426
- */
427
- declare function assertAttested(session: Session): void;
428
-
429
- /**
430
- * `attestation` - read controls and verification triggers (spec section 4.1).
431
- *
432
- * Grouped as a small object of free functions over the opaque `Session`. The
433
- * read accessors (`current`, `policy`) report the last verified result and the
434
- * active pin; `assertValid` re-runs attestation over the live channel and
435
- * `onPolicyViolation` subscribes to out-of-band re-attestation failures.
436
- */
216
+ interface PublicProductionReleasePolicy {
217
+ readonly expectedMrtd: string;
218
+ readonly expectedBinaryHash: string;
219
+ readonly expectedRuntimeProfile: "prod-hardened" | "prod-devnet-simplified";
220
+ }
437
221
 
222
+ interface PublicAttestationPolicy {
223
+ readonly expectedMrtd: string;
224
+ readonly expectedBinaryHash?: string;
225
+ readonly expectedRuntimeProfile?: "prod-hardened" | "prod-devnet-simplified";
226
+ readonly intelRootFingerprint?: string;
227
+ readonly azureMaa?: {
228
+ readonly expectedIssuer: string;
229
+ readonly expectedJwksUrl: string;
230
+ readonly expectedPolicyHash: string;
231
+ };
232
+ }
233
+ /** Public attestation read controls. Policy construction remains internal. */
438
234
  declare const attestation: {
439
- /**
440
- * Force-verify the current session against the active policy by re-running
441
- * attestation over the live channel. Updates the stored result on success.
442
- *
443
- * @throws AttestationError if verification fails.
444
- * @throws TransportError if the session has no live attested channel.
445
- */
235
+ productionPolicy(): PublicProductionReleasePolicy;
446
236
  assertValid(session: Session): Promise<AttestationResult>;
447
- /** The last verified attestation result, or `null` before first attestation. */
448
237
  current(session: Session): AttestationResult | null;
449
- /** The release pin the active leader endpoint is verified against. Read-only. */
450
- policy(session: Session): CoordinatorReleasePin;
451
- /**
452
- * Subscribe to out-of-band attestation failures (e.g. during periodic
453
- * re-attestation). The handler fires with the verification error; returns an
454
- * unsubscribe function.
455
- */
238
+ policy(session: Session): PublicAttestationPolicy;
456
239
  onPolicyViolation(session: Session, handler: (error: Error) => void): Unsubscribe;
457
240
  };
458
241
 
459
- /**
460
- * `coordinator` - endpoint pool inspection and failover (spec section 4.2).
461
- *
462
- * `endpoints` is a read accessor that works today. Leader discovery, version
463
- * reporting, and failover depend on the coordinator network surface and are
464
- * deferred (marked 🟡 V0-target in the spec).
465
- */
466
-
467
- /** Coordinator-reported version and role snapshot. */
242
+ interface PublicCoordinatorEndpoint {
243
+ readonly coordinatorUrl: string;
244
+ readonly roleHint?: "leader" | "watcher";
245
+ readonly weight?: number;
246
+ }
468
247
  interface CoordinatorVersion {
469
248
  readonly mode: "prod" | "dev";
470
249
  readonly protocolVersion: string;
@@ -473,27 +252,10 @@ interface CoordinatorVersion {
473
252
  readonly leaderEpoch: number;
474
253
  }
475
254
  declare const coordinator: {
476
- /** All configured endpoints, in the order supplied. Read-only. */
477
- endpoints(session: Session): readonly CoordinatorEndpoint[];
478
- /**
479
- * The endpoint currently accepting mutating commands.
480
- *
481
- * @throws NotImplementedError - deferred (coordinator-pending).
482
- */
483
- currentLeader(_session: Session): Promise<CoordinatorEndpoint | null>;
484
- /**
485
- * The coordinator-reported version snapshot.
486
- *
487
- * @throws NotImplementedError - deferred (coordinator-pending).
488
- */
255
+ endpoints(session: Session): readonly PublicCoordinatorEndpoint[];
256
+ currentLeader(_session: Session): Promise<PublicCoordinatorEndpoint | null>;
489
257
  version(_session: Session): Promise<CoordinatorVersion>;
490
- /**
491
- * Tear down the active session and reconnect through the next healthy
492
- * endpoint, forcing a fresh attestation.
493
- *
494
- * @throws NotImplementedError - deferred (coordinator-pending).
495
- */
496
258
  forceFailover(_session: Session): Promise<void>;
497
259
  };
498
260
 
499
- export { type ApiVersion, type AttestResponse, type AttestationMode, type AttestationPolicy, type AttestationResult, type AzureMaaPolicy, type Brand, CoordinatorEndpoint, CoordinatorReleasePin, type CoordinatorVersion, type ExponentialBackoff, type ExponentialBackoffOptions, type Hex, type Lamports, type NoiseHandshakeResult, NoiseWebSocketTransportOptions, type PublicKey, type RequestId, Session, Transport, Unsubscribe, apiVersion, assertAttestResponse, assertAttested, attestation, coordinator, createExponentialBackoff, hex, inMemoryTransport, lamports, noiseWebSocketTransport, performAttestation, performNoiseHandshake, publicKey, requestId, verifyAttestation };
261
+ export { type ApiVersion, type AttestationResult, type Brand, type CoordinatorVersion, type PublicCreateSessionOptions as CreateSessionOptions, type ExponentialBackoff, type ExponentialBackoffOptions, type Hex, type Lamports, NoiseWebSocketTransportOptions, type PublicAttestationPolicy, type PublicCoordinatorEndpoint, type PublicKey, type RequestId, Session, Transport, Unsubscribe, apiVersion, assertAttested, attestation, closeSession, coordinator, createExponentialBackoff, createSession, hex, inMemoryTransport, lamports, noiseWebSocketTransport, publicKey, requestId };
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
- import { createStateController, reattestSerialized } from './chunk-7DSVN3MV.js';
2
- export { closeSession, createExponentialBackoff, createSession, noiseWebSocketTransport, performAttestation, performNoiseHandshake } from './chunk-7DSVN3MV.js';
3
- export { assertAttested, hex, lamports, publicKey, requestId } from './chunk-SZAYO2L5.js';
4
- import { getSessionState, failSessionClosed } from './chunk-JRMKCE3S.js';
5
- export { assertAttestResponse, verifyAttestation } from './chunk-NCY4FCYU.js';
6
- import { TransportError, NotImplementedError } from './chunk-OHIM2YWU.js';
7
- export { AttestationError, CommandError, InvalidDepositAmountError, InvisibleError, LpLifecycleError, NotImplementedError, PolicyValidationError, RoutingError, StorageError, TransportError, WalletError, isInvisibleError, normalizeError } from './chunk-OHIM2YWU.js';
1
+ import { createStateController, createSessionInternal, isLoopbackUrl, reattestSerialized } from './chunk-5NNEO7IK.js';
2
+ export { closeSession, createExponentialBackoff, noiseWebSocketTransport } from './chunk-5NNEO7IK.js';
3
+ export { assertAttested, hex, lamports, publicKey, requestId } from './chunk-NHEHCUS5.js';
4
+ import { getSessionState, failSessionClosed } from './chunk-V5HXJRBW.js';
5
+ import { createAzureProductionEndpoint, APPROVED_PRODUCTION_RUNTIME_PROFILE } from './chunk-BRDLLGCZ.js';
6
+ import './chunk-DIA6U2CV.js';
7
+ import { TransportError, NotImplementedError } from './chunk-GHBQF3A7.js';
8
+ export { AttestationError, CommandError, InvalidDepositAmountError, InvisibleError, LpLifecycleError, NotImplementedError, PolicyValidationError, RoutingError, StorageError, TransportError, WalletError, isInvisibleError, normalizeError } from './chunk-GHBQF3A7.js';
8
9
  import './chunk-VR6T6OJS.js';
9
10
 
10
11
  // src/core/version.ts
@@ -51,15 +52,76 @@ function inMemoryTransport(options = {}) {
51
52
  };
52
53
  }
53
54
 
54
- // src/attestation/index.ts
55
+ // src/presets/productionBinaryHash.ts
56
+ var APPROVED_PRODUCTION_COORDINATOR_BINARY_HASH = "92237e1cc0d528a12288ff5a2d99eff38ab387080d31eb4146526daa6c973860".toLowerCase() ;
57
+
58
+ // src/presets/productionMrtd.ts
59
+ var APPROVED_PRODUCTION_COORDINATOR_MRTD = "a2e61f1316e9e367e9c1f7a0adc98c48eb13875c399c85d286cee5ea2b05e57f2df9f61d903b0ae7ac5607d843dfffc1".toLowerCase() ;
60
+
61
+ // src/session/publicReleasePolicy.ts
62
+ function publicProductionReleasePolicy() {
63
+ return {
64
+ expectedMrtd: APPROVED_PRODUCTION_COORDINATOR_MRTD,
65
+ expectedBinaryHash: APPROVED_PRODUCTION_COORDINATOR_BINARY_HASH,
66
+ expectedRuntimeProfile: APPROVED_PRODUCTION_RUNTIME_PROFILE
67
+ };
68
+ }
69
+
70
+ // src/session/publicSession.ts
71
+ var PUBLIC_SESSION_OPTION_KEYS = /* @__PURE__ */ new Set(["coordinatorUrl", "storage", "wallet"]);
72
+ var PUBLIC_COORDINATOR_URL_PROTOCOL = "wss:";
73
+ var PUBLIC_COORDINATOR_URL_ERROR = "public SDK createSession requires a non-loopback wss:// coordinatorUrl";
74
+ async function createSession(options) {
75
+ assertPublicOptions(options);
76
+ const parsedUrl = parsePublicCoordinatorUrl(options.coordinatorUrl);
77
+ const releasePolicy = publicProductionReleasePolicy();
78
+ const endpoint = createAzureProductionEndpoint({
79
+ wsUrl: options.coordinatorUrl,
80
+ expectedHostname: parsedUrl.hostname,
81
+ approvedBinaryHash: releasePolicy.expectedBinaryHash,
82
+ approvedMrtd: releasePolicy.expectedMrtd
83
+ });
84
+ const internalOptions = {
85
+ coordinator: { endpoints: [endpoint] },
86
+ ...options.storage === void 0 ? {} : { storage: options.storage },
87
+ ...options.wallet === void 0 ? {} : { wallet: options.wallet }
88
+ };
89
+ return createSessionInternal(internalOptions);
90
+ }
91
+ function assertPublicOptions(options) {
92
+ if (typeof options !== "object" || options === null || Array.isArray(options)) {
93
+ throw new TypeError("public SDK createSession options must be an object");
94
+ }
95
+ for (const key of Object.keys(options)) {
96
+ if (!PUBLIC_SESSION_OPTION_KEYS.has(key)) {
97
+ throw new Error(`public SDK createSession does not accept option ${key}`);
98
+ }
99
+ }
100
+ const coordinatorUrl = options.coordinatorUrl;
101
+ if (typeof coordinatorUrl !== "string") {
102
+ throw new TypeError("public SDK createSession requires coordinatorUrl");
103
+ }
104
+ }
105
+ function parsePublicCoordinatorUrl(value) {
106
+ let parsed;
107
+ try {
108
+ parsed = new URL(value);
109
+ } catch (cause) {
110
+ const error = new Error(PUBLIC_COORDINATOR_URL_ERROR);
111
+ error.cause = cause;
112
+ throw error;
113
+ }
114
+ if (parsed.protocol !== PUBLIC_COORDINATOR_URL_PROTOCOL || isLoopbackUrl(value)) {
115
+ throw new Error(PUBLIC_COORDINATOR_URL_ERROR);
116
+ }
117
+ return parsed;
118
+ }
119
+
120
+ // src/attestation/public.ts
55
121
  var attestation = {
56
- /**
57
- * Force-verify the current session against the active policy by re-running
58
- * attestation over the live channel. Updates the stored result on success.
59
- *
60
- * @throws AttestationError if verification fails.
61
- * @throws TransportError if the session has no live attested channel.
62
- */
122
+ productionPolicy() {
123
+ return publicProductionReleasePolicy();
124
+ },
63
125
  async assertValid(session) {
64
126
  const state = getSessionState(session);
65
127
  const endpoint = state.pool.endpoints[0];
@@ -74,19 +136,25 @@ var attestation = {
74
136
  throw error;
75
137
  }
76
138
  },
77
- /** The last verified attestation result, or `null` before first attestation. */
78
139
  current(session) {
79
140
  return getSessionState(session).attestation;
80
141
  },
81
- /** The release pin the active leader endpoint is verified against. Read-only. */
82
142
  policy(session) {
83
- return getSessionState(session).pool.endpoints[0].releasePin;
143
+ const pin = getSessionState(session).pool.endpoints[0].releasePin;
144
+ return {
145
+ expectedMrtd: pin.mrtd,
146
+ ...pin.binaryHash === void 0 ? {} : { expectedBinaryHash: pin.binaryHash },
147
+ ...pin.runtimeProfile === void 0 ? {} : { expectedRuntimeProfile: pin.runtimeProfile },
148
+ ...pin.intelRootFingerprint === void 0 ? {} : { intelRootFingerprint: pin.intelRootFingerprint },
149
+ ...pin.azureMaa === void 0 ? {} : {
150
+ azureMaa: {
151
+ expectedIssuer: pin.azureMaa.issuer,
152
+ expectedJwksUrl: pin.azureMaa.jwksUrl,
153
+ expectedPolicyHash: pin.azureMaa.policyHash
154
+ }
155
+ }
156
+ };
84
157
  },
85
- /**
86
- * Subscribe to out-of-band attestation failures (e.g. during periodic
87
- * re-attestation). The handler fires with the verification error; returns an
88
- * unsubscribe function.
89
- */
90
158
  onPolicyViolation(session, handler) {
91
159
  const handlers = getSessionState(session).policyViolationHandlers;
92
160
  handlers.add(handler);
@@ -94,39 +162,26 @@ var attestation = {
94
162
  }
95
163
  };
96
164
 
97
- // src/coordinator/index.ts
165
+ // src/coordinator/public.ts
98
166
  var coordinator = {
99
- /** All configured endpoints, in the order supplied. Read-only. */
100
167
  endpoints(session) {
101
- return getSessionState(session).pool.endpoints;
168
+ return getSessionState(session).pool.endpoints.map((endpoint) => ({
169
+ coordinatorUrl: endpoint.wsUrl,
170
+ ...endpoint.roleHint === void 0 ? {} : { roleHint: endpoint.roleHint },
171
+ ...endpoint.weight === void 0 ? {} : { weight: endpoint.weight }
172
+ }));
102
173
  },
103
- /**
104
- * The endpoint currently accepting mutating commands.
105
- *
106
- * @throws NotImplementedError - deferred (coordinator-pending).
107
- */
108
174
  currentLeader(_session) {
109
175
  return Promise.reject(new NotImplementedError("coordinator.currentLeader"));
110
176
  },
111
- /**
112
- * The coordinator-reported version snapshot.
113
- *
114
- * @throws NotImplementedError - deferred (coordinator-pending).
115
- */
116
177
  version(_session) {
117
178
  return Promise.reject(new NotImplementedError("coordinator.version"));
118
179
  },
119
- /**
120
- * Tear down the active session and reconnect through the next healthy
121
- * endpoint, forcing a fresh attestation.
122
- *
123
- * @throws NotImplementedError - deferred (coordinator-pending).
124
- */
125
180
  forceFailover(_session) {
126
181
  return Promise.reject(new NotImplementedError("coordinator.forceFailover"));
127
182
  }
128
183
  };
129
184
 
130
- export { apiVersion, attestation, coordinator, inMemoryTransport, isAttested };
185
+ export { apiVersion, attestation, coordinator, createSession, inMemoryTransport, isAttested };
131
186
  //# sourceMappingURL=index.js.map
132
187
  //# sourceMappingURL=index.js.map