@invisible-labs/sdk 0.6.0-devnet.3 → 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.
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, 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, N as NotImplementedError, i as NotImplementedErrorCode, P as PolicyValidationError, j as PolicyValidationErrorCode, R as RoutingError, k as RoutingErrorCode, S as StorageError, l as StorageErrorCode, T as TransportError, m as TransportErrorCode, W as WalletError, n as WalletErrorCode, o as isInvisibleError, p as normalizeError } from './errors-N2touVm4.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, a as CoordinatorPoolConfig, b as CoordinatorReleasePin } from './types.generated-BSEBz4jR.js';
7
- export { A as AzureMaaPin, L as LpPositionView, c as PayoutDestination, P as PayoutPolicy, S as StorageEnvelope } from './types.generated-BSEBz4jR.js';
8
6
 
9
7
  /**
10
8
  * The API surface version this build implements. Bumped only on a breaking
@@ -134,226 +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`).
139
- *
140
- * Verifies a TDX DCAP quote on three paths, using Web Crypto (`crypto.subtle`,
141
- * a Node 22 / browser global) and `@peculiar/x509`:
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.
135
+ * `createSession` - the single entrypoint that opens an attested session.
152
136
  *
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.
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}.
156
142
  *
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 CoordinatorRuntimeProfile = "prod-hardened" | "prod-devnet-simplified";
163
- type AzureMaaPolicy = {
164
- /** Expected MAA token issuer for the approved Azure Attestation provider. */
165
- expectedIssuer: string;
166
- /** Expected JWKS endpoint for that provider. Token headers must not choose it. */
167
- expectedJwksUrl: string;
168
- /** Expected Azure Attestation evaluation policy hash from the signed token. */
169
- expectedPolicyHash: string;
170
- };
171
- type AttestationPolicy = {
172
- /**
173
- * Expected MRTD for the published production coordinator build.
174
- * Dev mode ignores this pin entirely.
175
- */
176
- expectedMrtd?: string;
177
- /**
178
- * SHA-256 hash of the approved coordinator binary. Azure production
179
- * attestation requires this pin because binary_hash is otherwise only
180
- * response metadata, even though the TPM quote binds it cryptographically.
181
- */
182
- expectedBinaryHash?: string;
183
- /** Expected compile-time runtime profile carried by the approved artifact. */
184
- expectedRuntimeProfile?: CoordinatorRuntimeProfile;
185
- /**
186
- * Runtime mode the client expects for this coordinator route. Production
187
- * builds set this to "prod" so a prod hostname cannot silently accept an
188
- * unpinned dev coordinator after DNS or load-balancer misrouting.
189
- */
190
- requiredMode?: AttestationMode;
191
- /**
192
- * Release tooling only: verify a prod quote before the new MRTD has been
193
- * published. Runtime policy must leave this unset so prod stays fail-closed
194
- * when the pin is missing.
195
- */
196
- allowUnpinnedProdMrtdForRelease?: boolean;
197
- /**
198
- * SHA-256 fingerprint (lowercase hex) of the DER-encoded Intel SGX Root CA.
199
- * Defaults to {@link INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256}. Override only in tests.
200
- */
201
- intelRootFingerprint?: string;
202
- /**
203
- * Temporary non-prod rollout escape hatch for legacy coordinators that have
204
- * not rolled out `dcap_collateral`. When collateral is present, it is always
205
- * verified. Production mode never honors this flag.
206
- */
207
- allowMissingDcapCollateral?: boolean;
208
- /**
209
- * Development-only escape hatch for a local coordinator running on a non-TDX
210
- * machine. The transport only honors this for loopback coordinator URLs.
211
- */
212
- allowLocalAttestation?: boolean;
213
- /**
214
- * Azure-specific trust policy. Required for platform="azure-tdx-dcap" because
215
- * MAA providers and policies are customer-configurable Azure resources.
216
- */
217
- azureMaa?: AzureMaaPolicy;
218
- };
219
- type SignedDcapJson = {
220
- /**
221
- * JSON string returned by Intel PCS. May be either the inner body
222
- * (`tcbInfo` / `enclaveIdentity`) or the full PCS wrapper.
223
- */
224
- body: string;
225
- /** Hex signature over the exact signed body bytes. */
226
- signature: string;
227
- /** PEM chain whose first certificate verifies `signature`, ending at Intel root. */
228
- issuerChainPem: string;
229
- };
230
- type DcapCollateral = {
231
- /** PEM X.509 CRL for the PCK certificate issuer. */
232
- pckCrlPem: string;
233
- /** PEM chain for the PCK CRL issuer, ending at Intel root. */
234
- pckCrlIssuerChainPem: string;
235
- /** PEM X.509 CRL issued by Intel root, covering collateral signing certs. */
236
- rootCaCrlPem: string;
237
- /** Signed Intel TDX TCB Info V3. */
238
- tcbInfo: SignedDcapJson;
239
- /** Signed Intel TD QE Identity V2. */
240
- qeIdentity: SignedDcapJson;
241
- };
242
- type AttestedMetadata = {
243
- mode: AttestationMode;
244
- binaryHash: string;
245
- runtimeProfile?: CoordinatorRuntimeProfile;
246
- mrtd: string;
247
- rtmr0: string;
248
- rtmr1: string;
249
- rtmr2: string;
250
- rtmr3: string;
251
- pubkeyHex: string;
252
- localAttestation: boolean;
253
- };
254
- type AttestResponse = {
255
- quote: string;
256
- /**
257
- * Nonce echoed back by the coordinator. Informational only: freshness is
258
- * enforced cryptographically via REPORT_DATA[0:32] inside the TDX quote, not
259
- * by trusting this JSON field.
260
- */
261
- nonce: string;
262
- pubkey: string;
263
- binary_hash: string;
264
- mode: AttestationMode;
265
- /** Compile-time runtime profile embedded in the coordinator artifact. */
266
- runtime_profile?: CoordinatorRuntimeProfile;
267
- /**
268
- * Platform identifier set by the coordinator. Absent on GCP (tdx-dcap).
269
- * Azure returns "azure-tdx-dcap".
270
- */
271
- platform?: string;
272
- /**
273
- * Azure only: MAA JWT from /attest/TdxVm, RS256-signed by MAA. Contains
274
- * tdx_mrtd, tdx_td_attributes_debug, and x-ms-compliance-status.
275
- */
276
- maa_token?: string;
277
- /**
278
- * Azure only: TPM PCR quote packed as
279
- * [4-byte msg_len LE][TPM2B_ATTEST][TPMT_SIGNATURE].
280
- * qualifying_data = SHA-256(nonce || noise_pubkey || binary_hash). Base64-encoded.
281
- */
282
- tpm_quote?: string;
283
- /**
284
- * Azure only: raw bytes (base64) of the JSON key-blob from HCL report NV
285
- * 0x1400001 [1056:]. SHA-256(hcl_keys_json_bytes) == DCAP REPORTDATA[0:32].
286
- * Contains the AK public key as kid="HCLAkPub".
287
- */
288
- hcl_keys_json?: string;
289
- /**
290
- * Intel DCAP verification collateral. When present, the verifier evaluates
291
- * PCK revocation, TCB Info, and TD QE Identity. Policies can require it.
292
- */
293
- dcap_collateral?: DcapCollateral;
294
- local_attestation?: boolean;
295
- };
163
+ declare function createSession(options: PublicCreateSessionOptions): Promise<Session>;
164
+
296
165
  /**
297
- * Assert that an unknown JSON value has the shape of {@link AttestResponse}.
298
- * Throws {@link AttestationError} ("NOT_ATTESTED") on any missing or wrong-typed
299
- * field. Replaces an unsafe cast so missing fields produce a typed error rather
300
- * than silently reaching downstream checks as `undefined`.
166
+ * Session guards used by mutating commands.
301
167
  */
302
- declare function assertAttestResponse(value: unknown): asserts value is AttestResponse;
303
- declare function verifyAttestation(params: {
304
- response: AttestResponse;
305
- expectedNonce: Uint8Array;
306
- expectedNoiseStaticPub: Uint8Array;
307
- policy: AttestationPolicy;
308
- timeoutMs?: number;
309
- }): Promise<AttestedMetadata>;
310
168
 
311
169
  /**
312
- * Secure channel: Noise XX handshake + TDX attestation over a raw transport.
313
- *
314
- * Free functions, no class (SDK conformance). Given an open {@link Transport}
315
- * and a {@link CoordinatorEndpoint}, {@link establishSecureChannel} drives:
316
- *
317
- * 1. the Noise XX handshake (initiator role) over the raw byte channel:
318
- * -> msg1 (e) send raw
319
- * <- msg2 (e, ee, s, es) read raw, reveals the responder static pubkey
320
- * -> msg3 (s, se) send raw, yields the split NoiseTransport
321
- * 2. the attestation exchange over the freshly-split (but not-yet-promoted)
322
- * Noise transport:
323
- * -> encrypt(encodeAttestationRequest(nonceHex))
324
- * <- decodeAttestationResponse(decrypt(frame)) -> verifyAttestation
325
- *
326
- * On success the pending Noise transport is promoted to the live cipher and an
327
- * attested channel handle is returned: `send`/`onMessage` transparently
328
- * Noise-encrypt/decrypt application frames over the raw transport.
329
- *
330
- * The release pin (mrtd, intelRootFingerprint, azureMaa) and the endpoint's
331
- * requiredMode map to the verifier's {@link AttestationPolicy}. The loopback
332
- * local-attestation fallback (ADR-0037) is only enabled when the endpoint host
333
- * is a loopback address - it must never be honored for a remote coordinator.
334
- *
335
- * 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.
336
173
  *
337
- * @module JW-428
174
+ * @throws AttestationError `NOT_ATTESTED` when the session is not attested.
338
175
  */
339
-
340
- /** An established, attested Noise channel over a raw transport. */
341
- interface SecureChannel {
342
- /** Verified attestation metadata for the coordinator this channel reached. */
343
- readonly attestation: AttestedMetadata;
344
- /** The coordinator's Noise static public key, pinned for this channel. */
345
- readonly remoteStaticPublicKey: Uint8Array;
346
- /** Request re-attestation without consuming application frames as responses. */
347
- requestAttestation(nonceHex: string, timeoutMs: number): Promise<AttestResponse>;
348
- /** Encrypt and send one application frame over the raw transport. */
349
- send(plaintext: Uint8Array): void;
350
- /** Subscribe to decrypted inbound application frames. */
351
- onMessage(handler: (plaintext: Uint8Array) => void): Unsubscribe;
352
- /** Subscribe to fatal channel failures such as Noise decrypt desync. */
353
- onFatal(handler: (error: Error) => void): Unsubscribe;
354
- /** Tear down the channel: detach listeners and stop accepting frames. */
355
- close(): void;
356
- }
176
+ declare function assertAttested(session: Session): void;
357
177
 
358
178
  /**
359
179
  * Session-establishment seams layered on top of an open {@link Transport}.
@@ -371,17 +191,6 @@ interface SecureChannel {
371
191
  * one step should use {@link establishAttestedChannel}.
372
192
  */
373
193
 
374
- /** Result of a completed Noise XX handshake. */
375
- interface NoiseHandshakeResult {
376
- /** The coordinator's Noise static public key, pinned for this session. */
377
- readonly noiseStaticPublicKey: Uint8Array;
378
- /**
379
- * The attested secure channel produced by this handshake. Carried so a
380
- * subsequent {@link performAttestation} can read attestation evidence without
381
- * re-running the exchange. Internal: not part of the structural contract.
382
- */
383
- readonly channel: SecureChannel;
384
- }
385
194
  /** Result of a completed TDX attestation. */
386
195
  interface AttestationResult {
387
196
  /** The verified release MRTD. */
@@ -403,124 +212,38 @@ interface AttestationResult {
403
212
  /** When verification completed (epoch ms), stamped by the caller. */
404
213
  readonly verifiedAtMs: number;
405
214
  }
406
- /**
407
- * Run the Noise XX handshake over an open transport and pin the coordinator's
408
- * static key. Drives a full attested-channel establishment (attestation is
409
- * bound to the same Noise cipher) and returns the handshake half; read the
410
- * attestation half from {@link performAttestation} with the returned result.
411
- *
412
- * @throws TransportError if the channel fails or the handshake is malformed.
413
- * @throws AttestationError if attestation verification fails.
414
- */
415
- declare function performNoiseHandshake(transport: Transport, endpoint: CoordinatorEndpoint, nonce?: Uint8Array): Promise<NoiseHandshakeResult>;
416
- /**
417
- * Verify the coordinator's TDX attestation, bound to the handshake's Noise
418
- * static key. Reads the evidence captured by {@link performNoiseHandshake}.
419
- *
420
- * @throws TransportError if the handshake result carries no channel.
421
- */
422
- declare function performAttestation(_transport: Transport, handshake: NoiseHandshakeResult): Promise<AttestationResult>;
423
215
 
424
- /**
425
- * `createSession` - the single entrypoint that opens an attested session.
426
- *
427
- * It validates the endpoint pool, opens the transport, runs the Noise XX
428
- * handshake + TDX attestation, and returns an opaque {@link Session} that has
429
- * already passed attestation (`attested === true`). It resolves only once
430
- * attestation succeeds; any transport or attestation failure rejects with a
431
- * typed {@link TransportError} / {@link AttestationError}.
432
- *
433
- * A re-attestation timer re-runs verification over the live channel every
434
- * {@link REATTEST_EVERY_MS}; on failure it marks the session unattested and
435
- * notifies any registered policy-violation handlers. The transport is
436
- * injectable for tests.
437
- */
438
-
439
- /** Options for {@link createSession}. */
440
- interface CreateSessionOptions {
441
- /**
442
- * The coordinator endpoint pool. Must contain at least one endpoint. No
443
- * hostname is provided by default; supply your own or use `@invisible-labs/sdk/presets`.
444
- */
445
- readonly coordinator: CoordinatorPoolConfig;
446
- /**
447
- * Storage adapter for recoverable secrets. Typed by `@invisible-labs/sdk/storage`;
448
- * accepted here so the session can be threaded into storage-backed flows.
449
- */
450
- readonly storage?: unknown;
451
- /** Wallet adapter used for storage key derivation and signing. */
452
- readonly wallet?: unknown;
453
- /**
454
- * Inject a transport. Defaults to a Noise WebSocket transport over the first
455
- * endpoint. Tests pass an in-memory transport (paired with a loopback
456
- * coordinator that can complete the handshake + attestation).
457
- */
458
- readonly transport?: Transport;
216
+ interface PublicProductionReleasePolicy {
217
+ readonly expectedMrtd: string;
218
+ readonly expectedBinaryHash: string;
219
+ readonly expectedRuntimeProfile: "prod-hardened" | "prod-devnet-simplified";
459
220
  }
460
- /**
461
- * Open an attested session against the configured coordinator pool.
462
- *
463
- * @throws Error if the pool config is structurally invalid (including an empty
464
- * `endpoints` array).
465
- * @throws TransportError if the connection or Noise handshake fails.
466
- * @throws AttestationError if attestation verification fails.
467
- */
468
- declare function createSession(options: CreateSessionOptions): Promise<Session>;
469
- /** Close a session created by {@link createSession}. */
470
- declare function closeSession(session: Session): void;
471
-
472
- /**
473
- * Session guards used by mutating commands.
474
- */
475
-
476
- /**
477
- * Assert the session has passed attestation. Every mutating actor command calls
478
- * this before touching the wire, so an unattested session can never sign or
479
- * send sensitive material.
480
- *
481
- * @throws AttestationError `NOT_ATTESTED` when the session is not attested.
482
- */
483
- declare function assertAttested(session: Session): void;
484
-
485
- /**
486
- * `attestation` - read controls and verification triggers (spec section 4.1).
487
- *
488
- * Grouped as a small object of free functions over the opaque `Session`. The
489
- * read accessors (`current`, `policy`) report the last verified result and the
490
- * active pin; `assertValid` re-runs attestation over the live channel and
491
- * `onPolicyViolation` subscribes to out-of-band re-attestation failures.
492
- */
493
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. */
494
234
  declare const attestation: {
495
- /**
496
- * Force-verify the current session against the active policy by re-running
497
- * attestation over the live channel. Updates the stored result on success.
498
- *
499
- * @throws AttestationError if verification fails.
500
- * @throws TransportError if the session has no live attested channel.
501
- */
235
+ productionPolicy(): PublicProductionReleasePolicy;
502
236
  assertValid(session: Session): Promise<AttestationResult>;
503
- /** The last verified attestation result, or `null` before first attestation. */
504
237
  current(session: Session): AttestationResult | null;
505
- /** The release pin the active leader endpoint is verified against. Read-only. */
506
- policy(session: Session): CoordinatorReleasePin;
507
- /**
508
- * Subscribe to out-of-band attestation failures (e.g. during periodic
509
- * re-attestation). The handler fires with the verification error; returns an
510
- * unsubscribe function.
511
- */
238
+ policy(session: Session): PublicAttestationPolicy;
512
239
  onPolicyViolation(session: Session, handler: (error: Error) => void): Unsubscribe;
513
240
  };
514
241
 
515
- /**
516
- * `coordinator` - endpoint pool inspection and failover (spec section 4.2).
517
- *
518
- * `endpoints` is a read accessor that works today. Leader discovery, version
519
- * reporting, and failover depend on the coordinator network surface and are
520
- * deferred (marked 🟡 V0-target in the spec).
521
- */
522
-
523
- /** Coordinator-reported version and role snapshot. */
242
+ interface PublicCoordinatorEndpoint {
243
+ readonly coordinatorUrl: string;
244
+ readonly roleHint?: "leader" | "watcher";
245
+ readonly weight?: number;
246
+ }
524
247
  interface CoordinatorVersion {
525
248
  readonly mode: "prod" | "dev";
526
249
  readonly protocolVersion: string;
@@ -529,27 +252,10 @@ interface CoordinatorVersion {
529
252
  readonly leaderEpoch: number;
530
253
  }
531
254
  declare const coordinator: {
532
- /** All configured endpoints, in the order supplied. Read-only. */
533
- endpoints(session: Session): readonly CoordinatorEndpoint[];
534
- /**
535
- * The endpoint currently accepting mutating commands.
536
- *
537
- * @throws NotImplementedError - deferred (coordinator-pending).
538
- */
539
- currentLeader(_session: Session): Promise<CoordinatorEndpoint | null>;
540
- /**
541
- * The coordinator-reported version snapshot.
542
- *
543
- * @throws NotImplementedError - deferred (coordinator-pending).
544
- */
255
+ endpoints(session: Session): readonly PublicCoordinatorEndpoint[];
256
+ currentLeader(_session: Session): Promise<PublicCoordinatorEndpoint | null>;
545
257
  version(_session: Session): Promise<CoordinatorVersion>;
546
- /**
547
- * Tear down the active session and reconnect through the next healthy
548
- * endpoint, forcing a fresh attestation.
549
- *
550
- * @throws NotImplementedError - deferred (coordinator-pending).
551
- */
552
258
  forceFailover(_session: Session): Promise<void>;
553
259
  };
554
260
 
555
- export { type ApiVersion, type AttestResponse, type AttestationMode, type AttestationPolicy, type AttestationResult, type AzureMaaPolicy, type Brand, CoordinatorEndpoint, CoordinatorPoolConfig, CoordinatorReleasePin, type CoordinatorRuntimeProfile, type CoordinatorVersion, type CreateSessionOptions, type ExponentialBackoff, type ExponentialBackoffOptions, type Hex, type Lamports, type NoiseHandshakeResult, NoiseWebSocketTransportOptions, type PublicKey, type RequestId, Session, Transport, Unsubscribe, apiVersion, assertAttestResponse, assertAttested, attestation, closeSession, coordinator, createExponentialBackoff, createSession, 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,8 +1,9 @@
1
- import { createStateController, reattestSerialized } from './chunk-BWCGNTN5.js';
2
- export { closeSession, createExponentialBackoff, createSession, noiseWebSocketTransport, performAttestation, performNoiseHandshake } from './chunk-BWCGNTN5.js';
1
+ import { createStateController, createSessionInternal, isLoopbackUrl, reattestSerialized } from './chunk-5NNEO7IK.js';
2
+ export { closeSession, createExponentialBackoff, noiseWebSocketTransport } from './chunk-5NNEO7IK.js';
3
3
  export { assertAttested, hex, lamports, publicKey, requestId } from './chunk-NHEHCUS5.js';
4
4
  import { getSessionState, failSessionClosed } from './chunk-V5HXJRBW.js';
5
- export { assertAttestResponse, verifyAttestation } from './chunk-DIA6U2CV.js';
5
+ import { createAzureProductionEndpoint, APPROVED_PRODUCTION_RUNTIME_PROFILE } from './chunk-BRDLLGCZ.js';
6
+ import './chunk-DIA6U2CV.js';
6
7
  import { TransportError, NotImplementedError } from './chunk-GHBQF3A7.js';
7
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';
@@ -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