@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/presets.d.ts CHANGED
@@ -1,43 +1,6 @@
1
- import { C as CoordinatorEndpoint } from './types.generated-CHGSbmLp.js';
1
+ /** Public coordinator URL conveniences. Policy construction stays internal. */
2
+ declare function invisibleProd(): string;
3
+ declare function invisibleProdAzure(): string;
4
+ declare function invisibleDevnet(): string;
2
5
 
3
- /**
4
- * `@invisible-labs/sdk/presets` - optional Invisible coordinator endpoint presets.
5
- *
6
- * This is the ONLY module permitted to name an `invisible.exchange` host (spec
7
- * section 6.2). Partners who self-host ignore it entirely and pass their own
8
- * `CoordinatorEndpoint[]` to `createSession`. The core never imports this module.
9
- *
10
- * Production presets embed an approved Azure TDX boot measurement and trust
11
- * roots. The caller must provide the separately approved coordinator binary
12
- * hash before a production endpoint can be constructed. Dormant or
13
- * development targets keep placeholders until approval.
14
- */
15
-
16
- /**
17
- * Production GCP TDX coordinator endpoint.
18
- *
19
- * Currently dormant: GCP is neither the live production nor development TEE
20
- * path. Kept only for a future explicit GCP relight, or a partner self-hosting
21
- * on GCP.
22
- */
23
- declare function invisibleProdGcp(): CoordinatorEndpoint[];
24
- /** Production Azure TDX coordinator endpoint. The live prod TEE today. */
25
- declare function invisibleProdAzure(approvedBinaryHash: string): CoordinatorEndpoint[];
26
- /**
27
- * The currently-active Invisible production preset. Integrators that just want
28
- * "Invisible prod" use this and stay on whichever cloud is live.
29
- *
30
- * Switching the prod target between Azure and GCP is this one line:
31
- * `export const invisibleProd = invisibleProdAzure` -> `invisibleProdGcp`.
32
- */
33
- declare const invisibleProd: typeof invisibleProdAzure;
34
- /** Public Invisible devnet, served by the hardened Azure prod coordinator. */
35
- declare const invisibleDevnet: typeof invisibleProdAzure;
36
- /** Dormant GCP development coordinator endpoint. Not the active dev target today. */
37
- declare function invisibleDevGcp(): CoordinatorEndpoint[];
38
- /** Azure development coordinator endpoint. The active dev TEE today. */
39
- declare function invisibleDevAzure(): CoordinatorEndpoint[];
40
- /** The currently-active Invisible development preset. */
41
- declare const invisibleDev: typeof invisibleDevAzure;
42
-
43
- export { invisibleDev, invisibleDevAzure, invisibleDevGcp, invisibleDevnet, invisibleProd, invisibleProdAzure, invisibleProdGcp };
6
+ export { invisibleDevnet, invisibleProd, invisibleProdAzure };
package/dist/presets.js CHANGED
@@ -1,70 +1,19 @@
1
- import { INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256 } from './chunk-NCY4FCYU.js';
2
- import './chunk-OHIM2YWU.js';
1
+ import { AZURE_PROD_COORDINATOR_URL } from './chunk-BRDLLGCZ.js';
2
+ import './chunk-DIA6U2CV.js';
3
+ import './chunk-GHBQF3A7.js';
3
4
  import './chunk-VR6T6OJS.js';
4
5
 
5
- // src/presets/index.ts
6
- var PLACEHOLDER_PIN = {
7
- mrtd: "",
8
- intelRootFingerprint: ""
9
- };
10
- var BINARY_HASH_HEX = /^[0-9a-f]{64}$/i;
11
- var AZURE_PROD_RELEASE_PIN = {
12
- mrtd: "ff450b138c5ee6734a43dc35afb437abfa24ef743bc9e9484ef4af365fcd89a6c50913248ed7fcb92a7d42b1ba7da984",
13
- intelRootFingerprint: INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256,
14
- azureMaa: {
15
- issuer: "https://sharedweu.weu.attest.azure.net",
16
- jwksUrl: "https://sharedweu.weu.attest.azure.net/certs",
17
- policyHash: "9NY0VnTQ-IiBriBplVUpFbczcDaEBUwsiFYAzHu_gco"
18
- }
19
- };
20
- function invisibleProdGcp() {
21
- return [
22
- {
23
- wsUrl: "wss://tee.invisible.exchange/ws-noise",
24
- expectedHostname: "tee.invisible.exchange",
25
- releasePin: { ...PLACEHOLDER_PIN },
26
- requiredMode: "prod"
27
- }
28
- ];
6
+ // src/public-presets.ts
7
+ function invisibleProd() {
8
+ return AZURE_PROD_COORDINATOR_URL;
29
9
  }
30
- function invisibleProdAzure(approvedBinaryHash) {
31
- const binaryHash = typeof approvedBinaryHash === "string" ? approvedBinaryHash.toLowerCase() : "";
32
- if (!BINARY_HASH_HEX.test(binaryHash)) {
33
- throw new Error("invisibleProdAzure requires an approved 64-character binary SHA-256 hash");
34
- }
35
- return [
36
- {
37
- wsUrl: "wss://tee-azure.invisible.exchange/ws-noise",
38
- expectedHostname: "tee-azure.invisible.exchange",
39
- releasePin: { ...AZURE_PROD_RELEASE_PIN, binaryHash },
40
- requiredMode: "prod"
41
- }
42
- ];
10
+ function invisibleProdAzure() {
11
+ return AZURE_PROD_COORDINATOR_URL;
43
12
  }
44
- var invisibleProd = invisibleProdAzure;
45
- var invisibleDevnet = invisibleProdAzure;
46
- function invisibleDevGcp() {
47
- return [
48
- {
49
- wsUrl: "wss://tee-dev.invisible.exchange/ws-noise",
50
- expectedHostname: "tee-dev.invisible.exchange",
51
- releasePin: { ...PLACEHOLDER_PIN },
52
- requiredMode: "dev"
53
- }
54
- ];
13
+ function invisibleDevnet() {
14
+ return AZURE_PROD_COORDINATOR_URL;
55
15
  }
56
- function invisibleDevAzure() {
57
- return [
58
- {
59
- wsUrl: "wss://tee-azure-dev.invisible.exchange/ws-noise",
60
- expectedHostname: "tee-azure-dev.invisible.exchange",
61
- releasePin: { ...PLACEHOLDER_PIN },
62
- requiredMode: "dev"
63
- }
64
- ];
65
- }
66
- var invisibleDev = invisibleDevAzure;
67
16
 
68
- export { invisibleDev, invisibleDevAzure, invisibleDevGcp, invisibleDevnet, invisibleProd, invisibleProdAzure, invisibleProdGcp };
17
+ export { invisibleDevnet, invisibleProd, invisibleProdAzure };
69
18
  //# sourceMappingURL=presets.js.map
70
19
  //# sourceMappingURL=presets.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/presets/index.ts"],"names":[],"mappings":";;;;;AAgBA,IAAM,eAAA,GAAkB;AAAA,EACtB,IAAA,EAAM,EAAA;AAAA,EACN,oBAAA,EAAsB;AACxB,CAAA;AAEA,IAAM,eAAA,GAAkB,iBAAA;AAExB,IAAM,sBAAA,GAAyB;AAAA,EAC7B,IAAA,EAAM,kGAAA;AAAA,EACN,oBAAA,EAAsB,oCAAA;AAAA,EACtB,QAAA,EAAU;AAAA,IACR,MAAA,EAAQ,wCAAA;AAAA,IACR,OAAA,EAAS,8CAAA;AAAA,IACT,UAAA,EAAY;AAAA;AAEhB,CAAA;AASO,SAAS,gBAAA,GAA0C;AACxD,EAAA,OAAO;AAAA,IACL;AAAA,MACE,KAAA,EAAO,uCAAA;AAAA,MACP,gBAAA,EAAkB,wBAAA;AAAA,MAClB,UAAA,EAAY,EAAE,GAAG,eAAA,EAAgB;AAAA,MACjC,YAAA,EAAc;AAAA;AAChB,GACF;AACF;AAGO,SAAS,mBAAmB,kBAAA,EAAmD;AACpF,EAAA,MAAM,aAAa,OAAO,kBAAA,KAAuB,QAAA,GAAW,kBAAA,CAAmB,aAAY,GAAI,EAAA;AAC/F,EAAA,IAAI,CAAC,eAAA,CAAgB,IAAA,CAAK,UAAU,CAAA,EAAG;AACrC,IAAA,MAAM,IAAI,MAAM,0EAA0E,CAAA;AAAA,EAC5F;AACA,EAAA,OAAO;AAAA,IACL;AAAA,MACE,KAAA,EAAO,6CAAA;AAAA,MACP,gBAAA,EAAkB,8BAAA;AAAA,MAClB,UAAA,EAAY,EAAE,GAAG,sBAAA,EAAwB,UAAA,EAAW;AAAA,MACpD,YAAA,EAAc;AAAA;AAChB,GACF;AACF;AASO,IAAM,aAAA,GAAgB;AAGtB,IAAM,eAAA,GAAkB;AAGxB,SAAS,eAAA,GAAyC;AACvD,EAAA,OAAO;AAAA,IACL;AAAA,MACE,KAAA,EAAO,2CAAA;AAAA,MACP,gBAAA,EAAkB,4BAAA;AAAA,MAClB,UAAA,EAAY,EAAE,GAAG,eAAA,EAAgB;AAAA,MACjC,YAAA,EAAc;AAAA;AAChB,GACF;AACF;AAGO,SAAS,iBAAA,GAA2C;AACzD,EAAA,OAAO;AAAA,IACL;AAAA,MACE,KAAA,EAAO,iDAAA;AAAA,MACP,gBAAA,EAAkB,kCAAA;AAAA,MAClB,UAAA,EAAY,EAAE,GAAG,eAAA,EAAgB;AAAA,MACjC,YAAA,EAAc;AAAA;AAChB,GACF;AACF;AAGO,IAAM,YAAA,GAAe","file":"presets.js","sourcesContent":["/**\n * `@invisible-labs/sdk/presets` - optional Invisible coordinator endpoint presets.\n *\n * This is the ONLY module permitted to name an `invisible.exchange` host (spec\n * section 6.2). Partners who self-host ignore it entirely and pass their own\n * `CoordinatorEndpoint[]` to `createSession`. The core never imports this module.\n *\n * Production presets embed an approved Azure TDX boot measurement and trust\n * roots. The caller must provide the separately approved coordinator binary\n * hash before a production endpoint can be constructed. Dormant or\n * development targets keep placeholders until approval.\n */\n\nimport { INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256 } from \"../attestation/verifier.js\";\nimport type { CoordinatorEndpoint } from \"../schemas/types.generated.js\";\n\nconst PLACEHOLDER_PIN = {\n mrtd: \"\",\n intelRootFingerprint: \"\",\n} as const;\n\nconst BINARY_HASH_HEX = /^[0-9a-f]{64}$/i;\n\nconst AZURE_PROD_RELEASE_PIN = {\n mrtd: \"ff450b138c5ee6734a43dc35afb437abfa24ef743bc9e9484ef4af365fcd89a6c50913248ed7fcb92a7d42b1ba7da984\",\n intelRootFingerprint: INTEL_SGX_ROOT_CA_FINGERPRINT_SHA256,\n azureMaa: {\n issuer: \"https://sharedweu.weu.attest.azure.net\",\n jwksUrl: \"https://sharedweu.weu.attest.azure.net/certs\",\n policyHash: \"9NY0VnTQ-IiBriBplVUpFbczcDaEBUwsiFYAzHu_gco\",\n },\n} as const;\n\n/**\n * Production GCP TDX coordinator endpoint.\n *\n * Currently dormant: GCP is neither the live production nor development TEE\n * path. Kept only for a future explicit GCP relight, or a partner self-hosting\n * on GCP.\n */\nexport function invisibleProdGcp(): CoordinatorEndpoint[] {\n return [\n {\n wsUrl: \"wss://tee.invisible.exchange/ws-noise\",\n expectedHostname: \"tee.invisible.exchange\",\n releasePin: { ...PLACEHOLDER_PIN },\n requiredMode: \"prod\",\n },\n ];\n}\n\n/** Production Azure TDX coordinator endpoint. The live prod TEE today. */\nexport function invisibleProdAzure(approvedBinaryHash: string): CoordinatorEndpoint[] {\n const binaryHash = typeof approvedBinaryHash === \"string\" ? approvedBinaryHash.toLowerCase() : \"\";\n if (!BINARY_HASH_HEX.test(binaryHash)) {\n throw new Error(\"invisibleProdAzure requires an approved 64-character binary SHA-256 hash\");\n }\n return [\n {\n wsUrl: \"wss://tee-azure.invisible.exchange/ws-noise\",\n expectedHostname: \"tee-azure.invisible.exchange\",\n releasePin: { ...AZURE_PROD_RELEASE_PIN, binaryHash },\n requiredMode: \"prod\",\n },\n ];\n}\n\n/**\n * The currently-active Invisible production preset. Integrators that just want\n * \"Invisible prod\" use this and stay on whichever cloud is live.\n *\n * Switching the prod target between Azure and GCP is this one line:\n * `export const invisibleProd = invisibleProdAzure` -> `invisibleProdGcp`.\n */\nexport const invisibleProd = invisibleProdAzure;\n\n/** Public Invisible devnet, served by the hardened Azure prod coordinator. */\nexport const invisibleDevnet = invisibleProdAzure;\n\n/** Dormant GCP development coordinator endpoint. Not the active dev target today. */\nexport function invisibleDevGcp(): CoordinatorEndpoint[] {\n return [\n {\n wsUrl: \"wss://tee-dev.invisible.exchange/ws-noise\",\n expectedHostname: \"tee-dev.invisible.exchange\",\n releasePin: { ...PLACEHOLDER_PIN },\n requiredMode: \"dev\",\n },\n ];\n}\n\n/** Azure development coordinator endpoint. The active dev TEE today. */\nexport function invisibleDevAzure(): CoordinatorEndpoint[] {\n return [\n {\n wsUrl: \"wss://tee-azure-dev.invisible.exchange/ws-noise\",\n expectedHostname: \"tee-azure-dev.invisible.exchange\",\n releasePin: { ...PLACEHOLDER_PIN },\n requiredMode: \"dev\",\n },\n ];\n}\n\n/** The currently-active Invisible development preset. */\nexport const invisibleDev = invisibleDevAzure;\n"]}
1
+ {"version":3,"sources":["../src/public-presets.ts"],"names":[],"mappings":";;;;;;AAIO,SAAS,aAAA,GAAwB;AACtC,EAAA,OAAO,0BAAA;AACT;AAEO,SAAS,kBAAA,GAA6B;AAC3C,EAAA,OAAO,0BAAA;AACT;AAEO,SAAS,eAAA,GAA0B;AACxC,EAAA,OAAO,0BAAA;AACT","file":"presets.js","sourcesContent":["/** Public coordinator URL conveniences. Policy construction stays internal. */\n\nimport { AZURE_PROD_COORDINATOR_URL } from \"./presets/production.js\";\n\nexport function invisibleProd(): string {\n return AZURE_PROD_COORDINATOR_URL;\n}\n\nexport function invisibleProdAzure(): string {\n return AZURE_PROD_COORDINATOR_URL;\n}\n\nexport function invisibleDevnet(): string {\n return AZURE_PROD_COORDINATOR_URL;\n}\n"]}
package/dist/stats.js CHANGED
@@ -1,4 +1,4 @@
1
- import { NotImplementedError } from './chunk-OHIM2YWU.js';
1
+ import { NotImplementedError } from './chunk-GHBQF3A7.js';
2
2
  import './chunk-VR6T6OJS.js';
3
3
 
4
4
  // src/stats/index.ts
package/dist/storage.js CHANGED
@@ -1,4 +1,4 @@
1
- import { StorageError } from './chunk-OHIM2YWU.js';
1
+ import { StorageError } from './chunk-GHBQF3A7.js';
2
2
  import './chunk-VR6T6OJS.js';
3
3
 
4
4
  // src/storage/index.ts
@@ -1,7 +1,3 @@
1
- import { S as Session } from './session-DFuy54C-.js';
2
- import { T as Transport } from './types-ZhV7TIQY.js';
3
- import { a as CoordinatorPoolConfig } from './types.generated-CHGSbmLp.js';
4
-
5
1
  /**
6
2
  * The closed error taxonomy from docs/sdk-specification.md section 8.3.
7
3
  *
@@ -16,7 +12,7 @@ import { a as CoordinatorPoolConfig } from './types.generated-CHGSbmLp.js';
16
12
  * The conformance lint allowlists this file for that reason.
17
13
  */
18
14
  /** Attestation verification failures. Stop; do not retry without a new pin. */
19
- type AttestationErrorCode = "CERT_CHAIN_INVALID" | "TCB_REJECTED" | "FRESHNESS_NONCE_MISMATCH" | "NOISE_BINDING_MISMATCH" | "DEBUG_BIT_SET" | "MRTD_MISMATCH" | "AZURE_MAA_ISSUER_MISMATCH" | "AZURE_MAA_JWKS_INVALID" | "AZURE_MAA_POLICY_HASH_MISMATCH" | "AZURE_MAA_NOT_COMPLIANT" | "AZURE_MAA_DCAP_MISMATCH" | "AZURE_HCL_KEYS_MISMATCH" | "AZURE_AK_PUB_INVALID" | "AZURE_TPM_AK_QUOTE_INVALID" | "AZURE_TPM_QUALIFYING_DATA_MISMATCH" | "NOT_ATTESTED";
15
+ type AttestationErrorCode = "CERT_CHAIN_INVALID" | "TCB_REJECTED" | "FRESHNESS_NONCE_MISMATCH" | "NOISE_BINDING_MISMATCH" | "DEBUG_BIT_SET" | "MRTD_MISMATCH" | "RUNTIME_PROFILE_MISMATCH" | "AZURE_MAA_ISSUER_MISMATCH" | "AZURE_MAA_JWKS_INVALID" | "AZURE_MAA_POLICY_HASH_MISMATCH" | "AZURE_MAA_NOT_COMPLIANT" | "AZURE_MAA_DCAP_MISMATCH" | "AZURE_HCL_KEYS_MISMATCH" | "AZURE_AK_PUB_INVALID" | "AZURE_TPM_AK_QUOTE_INVALID" | "AZURE_TPM_QUALIFYING_DATA_MISMATCH" | "NOT_ATTESTED";
20
16
  /** Transport-level failures. Reconnect through the pool and re-attest. */
21
17
  type TransportErrorCode = "WS_HANDSHAKE_FAILED" | "NOISE_HANDSHAKE_FAILED" | "NOISE_FRAME_TOO_LARGE" | "CONNECTION_LOST";
22
18
  /** Leader/role routing failures. Failover and re-attest. */
@@ -126,52 +122,40 @@ declare function isInvisibleError(value: unknown): value is InvisibleError;
126
122
  */
127
123
  declare function normalizeError(error: unknown, fallback?: string): string;
128
124
 
129
- /**
130
- * `createSession` - the single entrypoint that opens an attested session.
131
- *
132
- * It validates the endpoint pool, opens the transport, runs the Noise XX
133
- * handshake + TDX attestation, and returns an opaque {@link Session} that has
134
- * already passed attestation (`attested === true`). It resolves only once
135
- * attestation succeeds; any transport or attestation failure rejects with a
136
- * typed {@link TransportError} / {@link AttestationError}.
137
- *
138
- * A re-attestation timer re-runs verification over the live channel every
139
- * {@link REATTEST_EVERY_MS}; on failure it marks the session unattested and
140
- * notifies any registered policy-violation handlers. The transport is
141
- * injectable for tests.
142
- */
143
-
144
- /** Options for {@link createSession}. */
145
- interface CreateSessionOptions {
146
- /**
147
- * The coordinator endpoint pool. Must contain at least one endpoint. No
148
- * hostname is provided by default; supply your own or use `@invisible-labs/sdk/presets`.
149
- */
150
- readonly coordinator: CoordinatorPoolConfig;
151
- /**
152
- * Storage adapter for recoverable secrets. Typed by `@invisible-labs/sdk/storage`;
153
- * accepted here so the session can be threaded into storage-backed flows.
154
- */
155
- readonly storage?: unknown;
156
- /** Wallet adapter used for storage key derivation and signing. */
157
- readonly wallet?: unknown;
158
- /**
159
- * Inject a transport. Defaults to a Noise WebSocket transport over the first
160
- * endpoint. Tests pass an in-memory transport (paired with a loopback
161
- * coordinator that can complete the handshake + attestation).
162
- */
163
- readonly transport?: Transport;
164
- }
165
- /**
166
- * Open an attested session against the configured coordinator pool.
167
- *
168
- * @throws Error if the pool config is structurally invalid (including an empty
169
- * `endpoints` array).
170
- * @throws TransportError if the connection or Noise handshake fails.
171
- * @throws AttestationError if attestation verification fails.
172
- */
173
- declare function createSession(options: CreateSessionOptions): Promise<Session>;
174
- /** Close a session created by {@link createSession}. */
175
- declare function closeSession(session: Session): void;
125
+ type LpPositionView = {
126
+ readonly id: string;
127
+ readonly status: "dkg_pending" | "active" | "withdrawing" | "closed";
128
+ readonly targetShardCount: number;
129
+ readonly authPublicKey: string;
130
+ readonly refillPublicKey: string;
131
+ readonly withdrawalCommitment: string;
132
+ readonly committedLamports: number;
133
+ readonly earnedLamports: number;
134
+ readonly refillThreshold: number;
135
+ readonly shards: readonly {
136
+ readonly [key: string]: unknown;
137
+ }[];
138
+ readonly createdAt: number;
139
+ };
140
+ type PayoutDestination = {
141
+ readonly address: string;
142
+ readonly sharePercent: number;
143
+ readonly minDelayMs?: number;
144
+ readonly maxDelayMs?: number;
145
+ readonly minLamports?: number;
146
+ };
147
+ type PayoutPolicy = {
148
+ readonly destinations: readonly PayoutDestination[];
149
+ readonly totalDeadlineMs?: number;
150
+ readonly batchExclusionId?: string;
151
+ };
152
+ type StorageEnvelope = {
153
+ readonly namespace: string;
154
+ readonly key: string;
155
+ readonly alg: "AES-GCM" | "none";
156
+ readonly ciphertext: string;
157
+ readonly iv?: string;
158
+ readonly createdAtMs: number;
159
+ };
176
160
 
177
- export { AttestationError as A, type CreateSessionOptions as C, InvalidDepositAmountError as I, LpLifecycleError as L, NotImplementedError as N, PolicyValidationError as P, RoutingError as R, StorageError as S, TransportError as T, WalletError as W, type AttestationErrorCode as a, CommandError as b, type CommandErrorCode as c, type CommandErrorOptions as d, type CoordinatorWireErrorCode as e, InvisibleError as f, type InvisibleErrorCode as g, type InvisibleErrorOptions as h, type LpLifecycleErrorCode as i, type NotImplementedErrorCode as j, type PolicyValidationErrorCode as k, type RoutingErrorCode as l, type StorageErrorCode as m, type TransportErrorCode as n, type WalletErrorCode as o, closeSession as p, createSession as q, isInvisibleError as r, normalizeError as s };
161
+ export { AttestationError as A, CommandError as C, InvalidDepositAmountError as I, LpLifecycleError as L, NotImplementedError as N, type PayoutPolicy as P, RoutingError as R, type StorageEnvelope as S, TransportError as T, WalletError as W, type AttestationErrorCode as a, type CommandErrorCode as b, type CommandErrorOptions as c, type CoordinatorWireErrorCode as d, InvisibleError as e, type InvisibleErrorCode as f, type InvisibleErrorOptions as g, type LpLifecycleErrorCode as h, type LpPositionView as i, type NotImplementedErrorCode as j, type PayoutDestination as k, PolicyValidationError as l, type PolicyValidationErrorCode as m, type RoutingErrorCode as n, StorageError as o, type StorageErrorCode as p, type TransportErrorCode as q, type WalletErrorCode as r, isInvisibleError as s, normalizeError as t };
package/dist/user.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { S as Session } from './session-DFuy54C-.js';
2
- import { a as CoordinatorPoolConfig, P as PayoutPolicy } from './types.generated-CHGSbmLp.js';
3
- import { C as CreateSessionOptions } from './createSession-D3ym-Ira.js';
4
- export { I as InvalidDepositAmountError } from './createSession-D3ym-Ira.js';
5
- import './types-ZhV7TIQY.js';
2
+ import { P as PayoutPolicy } from './types.generated-DJBTjLpP.js';
3
+ export { I as InvalidDepositAmountError } from './types.generated-DJBTjLpP.js';
6
4
 
7
5
  /**
8
6
  * Acceptance receipts (spec section 8.2).
@@ -73,14 +71,16 @@ type PayoutWindowSyncSnapshot = {
73
71
  readonly deadline_ms: number | null;
74
72
  };
75
73
  type NormalUserContractStatus = "deposit" | "activating" | "active" | "settling" | "completed" | "refunded" | "expired";
76
- type NormalUserSettlementPhase = "awaiting_deposit" | "activating" | "waiting_for_liquidity" | "matched_scheduled" | "locked_pending_payout" | "submitted" | "confirming" | "completed" | "refund_pending" | "refunded" | "expired";
74
+ type NormalUserSettlementPhase = "awaiting_deposit" | "activating" | "waiting_for_liquidity" | "retry_delayed" | "recovery_required" | "matched_scheduled" | "locked_pending_payout" | "submitted" | "confirming" | "completed" | "refund_pending" | "refunded" | "expired";
77
75
  type NormalUserRefundability = "available_now" | "request_pending" | "blocked_by_lock" | "stale" | "unavailable";
76
+ type NormalUserRefundStatus = "queued" | "reserved" | "submitted" | "confirming" | "retrying" | "finalized" | "failed" | "partial" | "canceled";
78
77
  type SourceLiquidityUse = "not_materialized" | "available" | "locked_for_payout" | "pending_finality" | "spent" | "released";
79
78
  type NormalUserContractSyncSnapshot = {
80
79
  readonly contract_id: string;
81
80
  readonly status: NormalUserContractStatus;
82
81
  readonly settlement_phase: NormalUserSettlementPhase;
83
82
  readonly refundability: NormalUserRefundability;
83
+ readonly refund_status: NormalUserRefundStatus | null;
84
84
  readonly source_liquidity_use: SourceLiquidityUse;
85
85
  readonly destination_wallet: string | null;
86
86
  readonly deposit_amount_lamports: number;
@@ -90,6 +90,7 @@ type NormalUserContractSyncSnapshot = {
90
90
  readonly settled_amount_lamports: number;
91
91
  readonly protocol_fee_lamports: number;
92
92
  readonly network_fee_lost_lamports: readonly number[];
93
+ readonly recovery_refund_remaining_lamports: number;
93
94
  readonly withdrawal_requested_lamports: number;
94
95
  readonly withdrawal_landed_lamports: number;
95
96
  readonly withdrawal_landed_fee_lamports: number;
@@ -110,11 +111,21 @@ type SyncUserResponsePayload = {
110
111
  readonly withdraw_execution?: RefundExecutedPayload;
111
112
  readonly actor_sync?: NormalUserActorSyncSnapshot;
112
113
  };
113
- type WithdrawAcceptedPayload = {
114
- readonly status: "accepted";
115
- readonly amount_lamports: number;
116
- readonly destination_address: string;
117
- readonly accepted_at_ms: number;
114
+ /**
115
+ * Actor-scoped sync response plus the coordinator clock used to produce it.
116
+ * The timestamp is envelope metadata, not part of the wire payload.
117
+ */
118
+ type SyncUserResponse = SyncUserResponsePayload & {
119
+ readonly coordinatorTimestampMs: number;
120
+ };
121
+ /**
122
+ * Acceptance receipt for a normal-user refund, including the coordinator's
123
+ * authoritative amount claim. The timestamp is absent when the coordinator
124
+ * reports that the request already executed before the client received it.
125
+ */
126
+ type RefundAcceptanceReceipt = AcceptanceReceipt & {
127
+ readonly amountLamports: number;
128
+ readonly acceptedAtMs?: number;
118
129
  };
119
130
  type RunSwapParams = {
120
131
  amountLamports: number;
@@ -126,9 +137,22 @@ type RunSwapParams = {
126
137
  onSyncSecretReady?: (info: {
127
138
  secretHex: string;
128
139
  }) => void | Promise<void>;
140
+ resumeSecret?: Uint8Array;
141
+ onResumeSecretReady?: (info: {
142
+ secretHex: string;
143
+ }) => void | Promise<void>;
144
+ onSwapAllocated?: (info: {
145
+ swapId: string;
146
+ syncSecretHex: string;
147
+ resumeSecretHex: string;
148
+ }) => void | Promise<void>;
129
149
  onRecoveryCodeReady?: (info: {
130
150
  codeHex: string;
131
151
  }) => void | Promise<void>;
152
+ onDelegateShareReady?: (info: {
153
+ swapId: string;
154
+ delegateShare: Uint8Array;
155
+ }) => void | Promise<void>;
132
156
  delegateShare?: Uint8Array;
133
157
  onDepositAddressReady?: (info: {
134
158
  swapId: string;
@@ -142,8 +166,6 @@ type RunSwapParams = {
142
166
  }) => void | Promise<void>;
143
167
  payoutWindowMs?: number;
144
168
  };
145
- /** Parameters for the pre-deposit portion of a normal-user contract flow. */
146
- type ContractRequestParams = Omit<RunSwapParams, "onDepositConfirmed">;
147
169
  /**
148
170
  * Details returned once the coordinator has accepted, initialized, and
149
171
  * durably delegated a contract, but before the user's deposit is observed.
@@ -163,76 +185,34 @@ type ContractRequestResult = {
163
185
  /** The read-only status secret. The caller must persist it if it needs sync. */
164
186
  readonly syncSecret: Uint8Array;
165
187
  readonly syncSecretHex: string;
188
+ /** The pre-delegation mutation secret. Persist it only for resume/recovery workflows. */
189
+ readonly resumeSecret: Uint8Array;
190
+ readonly resumeSecretHex: string;
166
191
  /** Present when the SDK generated the Recovery Code for this request. */
167
192
  readonly recoveryCodeHex?: string;
168
193
  readonly policySnapshot: SpendingPolicySnapshot;
169
194
  readonly delegatePolicySnapshot: SpendingPolicySnapshot;
170
195
  };
171
- type SwapResult = {
172
- swapId: string;
173
- jointPublicKey: Uint8Array;
174
- depositTxSignature: string;
175
- depositObservedAtMs: number;
176
- delegatedAtMs: number;
177
- recoveryCodeHex?: string;
178
- policySnapshot: SpendingPolicySnapshot;
179
- delegatePolicySnapshot: SpendingPolicySnapshot;
180
- };
181
- type RefundIntentResult = {
182
- readonly kind: "executed";
183
- readonly refund: RefundExecutedPayload;
184
- } | {
185
- readonly kind: "accepted";
186
- readonly accepted: WithdrawAcceptedPayload;
187
- };
188
- type SessionStatus = "idle" | "connecting" | "running" | "done" | "failed";
189
- type CoordinatorSessionOptions = {
190
- coordinator: CoordinatorPoolConfig;
191
- createSession?: (options: CreateSessionOptions) => Promise<Session>;
192
- };
193
- type StateChangeListener = (swapState: ClientSwapState, sessionStatus: SessionStatus) => void;
194
- type LogListener = (msg: string, direction: "in" | "out" | "info") => void;
195
- type PayoutExecutedListener = (payload: PayoutExecutedPayload, swapId: string) => void;
196
- type RefundExecutedListener = (payload: RefundExecutedPayload, swapId: string) => void;
197
- type NormalUserActorSyncListener = (payload: NormalUserActorSyncSnapshot, coordinatorTimestampMs: number) => void;
198
- type CoordinatorProtocolError = Error & {
199
- readonly code: string;
200
- readonly failedReqId?: number;
196
+ /** Inputs for resuming an already allocated pre-delegation contract. */
197
+ type ResumePreDelegationParams = {
198
+ readonly swapId: string;
199
+ readonly resumeSecret: Uint8Array;
200
+ readonly syncSecret?: Uint8Array;
201
+ readonly recoveryCommitment: Uint8Array;
202
+ /** The policy snapshot persisted when the contract was first allocated. */
203
+ readonly policySnapshot: SpendingPolicySnapshot;
204
+ /** Called before DkgRound2 so recovery can persist the generated Alice share. */
205
+ readonly onDelegateShareReady?: RunSwapParams["onDelegateShareReady"];
206
+ /** Supply the previously generated Alice share when DKG was already sealed. */
207
+ readonly delegateShare?: Uint8Array;
201
208
  };
202
- type CoordinatorErrorListener = (err: CoordinatorProtocolError) => void;
203
- type CoordinatorSessionHandle = {
204
- onStateChange(listener: StateChangeListener): () => void;
205
- onLog(listener: LogListener): () => void;
206
- onPayoutExecuted(listener: PayoutExecutedListener): () => void;
207
- onRefundExecuted(listener: RefundExecutedListener): () => void;
208
- onNormalUserActorSync(listener: NormalUserActorSyncListener): () => void;
209
- onCoordinatorError(listener: CoordinatorErrorListener): () => void;
210
- readonly currentSwapState: ClientSwapState;
211
- readonly currentSessionStatus: SessionStatus;
212
- runSwap(params: RunSwapParams): Promise<SwapResult>;
213
- contractRequest(params: ContractRequestParams): Promise<ContractRequestResult>;
214
- close(): void;
215
- restoreSwapContext(params: {
216
- swapId: string;
217
- syncSecret?: Uint8Array;
218
- }): void;
219
- requestSwapStatus(timeoutMs?: number): Promise<SyncUserResponsePayload>;
220
- startSwapStatusReconciliation(intervalMs?: number): () => void;
221
- requestRefund(params: {
222
- swapId?: string;
223
- syncSecret?: Uint8Array;
224
- recoveryCode: Uint8Array;
225
- timeoutMs?: number;
226
- }): Promise<RefundExecutedPayload>;
227
- requestRefundIntent(params: {
228
- swapId?: string;
229
- syncSecret?: Uint8Array;
230
- recoveryCode: Uint8Array;
231
- timeoutMs?: number;
232
- }): Promise<RefundIntentResult>;
209
+ type ResumePreDelegationResult = {
210
+ readonly swapId: string;
211
+ readonly jointPublicKey?: Uint8Array;
212
+ readonly depositExpiresAtMs?: number;
213
+ readonly coordinatorTimestampMs?: number;
214
+ readonly delegatedAtMs: number;
233
215
  };
234
- declare function createCoordinatorSession(options: CoordinatorSessionOptions): CoordinatorSessionHandle;
235
- declare function isBenignTransportDrop(err: unknown): boolean;
236
216
 
237
217
  /**
238
218
  * Payout policy validation (spec sections 4.3.1 and 10.1).
@@ -269,13 +249,12 @@ declare function recoveryCodeFromUserInput(input: string): Uint8Array;
269
249
  /**
270
250
  * `@invisible-labs/sdk/user` - normal-user (private transfer) commands (spec 4.3).
271
251
  *
272
- * The functional user API and the frontend `createCoordinatorSession` facade
273
- * share the same coordinator lifecycle implementation. Importing this module
274
- * must not pull in `/lp`, `/stats`, or `/events`.
252
+ * The normal-user API is functional and operates on the caller-owned attested
253
+ * Session. Importing this module must not pull in `/lp`, `/stats`, or `/events`.
275
254
  */
276
255
 
277
256
  /** Inclusive minimum private-transfer entry amount in lamports. */
278
- declare const MIN_ENTRY_AMOUNT_LAMPORTS = 400000000;
257
+ declare const MIN_ENTRY_AMOUNT_LAMPORTS = 1500000000;
279
258
  /** Inclusive maximum private-transfer entry amount in lamports. */
280
259
  declare const MAX_ENTRY_AMOUNT_LAMPORTS = 100000000000;
281
260
  /** Arguments to start a new private-transfer pool entry. */
@@ -287,6 +266,8 @@ interface ContractRequestArgs {
287
266
  * to observe at the fundable deposit address and hold in the joint wallet.
288
267
  * It is the custody-side amount before protocol and network-fee accounting,
289
268
  * not the net amount a payout destination receives.
269
+ * The value must be a safe integer between {@link MIN_ENTRY_AMOUNT_LAMPORTS}
270
+ * and {@link MAX_ENTRY_AMOUNT_LAMPORTS}, inclusive.
290
271
  */
291
272
  readonly amountLamports: number;
292
273
  /**
@@ -301,23 +282,35 @@ interface ContractRequestArgs {
301
282
  * `SUPPORTED_TOTAL_DEADLINE_MS`.
302
283
  */
303
284
  readonly payoutPolicy: PayoutPolicy;
304
- /**
305
- * Retained for API compatibility. The current wire contract always commits a
306
- * sync secret because status reads are keyed by that commitment.
307
- */
308
- readonly sync?: boolean;
309
285
  /** Optional caller-owned status secret, copied before it reaches the wire. */
310
286
  readonly syncSecret?: Uint8Array;
311
287
  /** Called before ContractRequest so the caller can persist the status secret. */
312
288
  readonly onSyncSecretReady?: (info: {
313
289
  secretHex: string;
314
290
  }) => void | Promise<void>;
291
+ /** Optional precomputed pre-delegation mutation secret, copied before it reaches the wire. */
292
+ readonly resumeSecret?: Uint8Array;
293
+ /** Called before ContractRequest so the caller can persist the resume secret. */
294
+ readonly onResumeSecretReady?: (info: {
295
+ secretHex: string;
296
+ }) => void | Promise<void>;
297
+ /** Called after allocation so the caller can persist both secrets with the swap id. */
298
+ readonly onSwapAllocated?: (info: {
299
+ swapId: string;
300
+ syncSecretHex: string;
301
+ resumeSecretHex: string;
302
+ }) => void | Promise<void>;
315
303
  /** Optional precomputed Recovery Code commitment for caller-managed recovery. */
316
304
  readonly recoveryCommitment?: Uint8Array;
317
305
  /** Called before DelegateShare so the caller can persist the generated code. */
318
306
  readonly onRecoveryCodeReady?: (info: {
319
307
  codeHex: string;
320
308
  }) => void | Promise<void>;
309
+ /** Called before DkgRound2 so the caller can persist the generated Alice share. */
310
+ readonly onDelegateShareReady?: (info: {
311
+ swapId: string;
312
+ delegateShare: Uint8Array;
313
+ }) => void | Promise<void>;
321
314
  }
322
315
  /**
323
316
  * Start a new pool entry through the current normal-user coordinator flow.
@@ -333,45 +326,34 @@ interface ContractRequestArgs {
333
326
  * session cannot complete the DKG/delegation boundary.
334
327
  */
335
328
  declare function contractRequest(session: Session, args: ContractRequestArgs): Promise<ContractRequestResult>;
329
+ /** Resume pre-delegation DKG or delegation on a caller-owned Session. */
330
+ declare function resumePreDelegation(session: Session, args: ResumePreDelegationParams): Promise<ResumePreDelegationResult>;
336
331
  /** Read the actor-scoped lifecycle projection for a normal-user contract. */
337
- declare function sync(session: Session, contractId: string, syncSecret: Uint8Array, timeoutMs?: number): Promise<SyncUserResponsePayload>;
332
+ declare function sync(session: Session, contractId: string, syncSecret: Uint8Array, timeoutMs?: number): Promise<SyncUserResponse>;
338
333
  /** Arguments to refund a pool entry with the Recovery Code preimage. */
339
334
  interface RequestRefundArgs {
335
+ /** Optional contract correlation required when multiple contracts share one Session. */
336
+ readonly swapId?: string;
337
+ /** Optional status secret used to restore the correlated contract context. */
338
+ readonly syncSecret?: Uint8Array;
340
339
  /** The 32-byte Recovery Code preimage. */
341
340
  readonly recoveryCode: Uint8Array;
342
341
  }
343
342
  /**
344
- * Submit a normal-user `withdraw_request` with only the Recovery Code preimage
345
- * (`{ recovery_code }`). The coordinator queues a durable origin-bound
346
- * withdrawal intent and terminal outcome is recovered through sync/status
347
- * reads. No caller-supplied destination is accepted.
343
+ * Submit a normal-user `withdraw_request` with the Recovery Code preimage
344
+ * (`{ recovery_code }`). Pass `swapId` and `syncSecret` when multiple contracts
345
+ * share one Session so the request is correlated to the intended contract.
346
+ * The coordinator queues a durable origin-bound withdrawal intent and terminal
347
+ * outcome is recovered through sync/status reads. No caller-supplied destination
348
+ * is accepted.
348
349
  *
349
- * @returns An acceptance receipt keyed by the resolved V0 `swapId`. The
350
+ * @returns An acceptance receipt keyed by the resolved V0 `swapId`, including
351
+ * the coordinator-authoritative amount accepted for withdrawal. The
350
352
  * coordinator's durable execution result is read later through `sync`.
351
353
  * @throws AttestationError if the session is not attested.
352
354
  * @throws PolicyValidationError if `recoveryCode` is not exactly 32 bytes.
353
355
  * @throws CommandError if the coordinator rejects the withdrawal request.
354
356
  */
355
- declare function requestRefund(session: Session, args: RequestRefundArgs): Promise<AcceptanceReceipt>;
356
- /**
357
- * Read the fundable deposit address for a request once the sealed contract
358
- * exposes it (`sync`).
359
- *
360
- * @throws NotImplementedError - read execution is deferred.
361
- */
362
- declare function getDepositAddress(_session: Session, _requestId: string, _syncSecret: Uint8Array): Promise<string>;
363
- /**
364
- * Subscribe to live sync messages for a request.
365
- *
366
- * @throws NotImplementedError - subscriptions are deferred.
367
- */
368
- declare function subscribe(_session: Session, _requestId: string, _syncSecret: Uint8Array, _handler: (event: unknown) => void): never;
369
- /**
370
- * Recover open requests after a tab close or restart by replaying the storage
371
- * adapter and re-subscribing.
372
- *
373
- * @throws NotImplementedError - replay is deferred.
374
- */
375
- declare function replayFromStorage(_session: Session, _storage: unknown): Promise<void>;
357
+ declare function requestRefund(session: Session, args: RequestRefundArgs): Promise<RefundAcceptanceReceipt>;
376
358
 
377
- export { type ClientSwapState, type ContractRequestArgs, type ContractRequestParams, type ContractRequestResult, type CoordinatorProtocolError, type CoordinatorSessionHandle, type CoordinatorSessionOptions, INSTANT_PAYOUT_WINDOW_MS, MAX_ENTRY_AMOUNT_LAMPORTS, MIN_ENTRY_AMOUNT_LAMPORTS, type NormalUserActorSyncSnapshot, type NormalUserRefundability, type NormalUserSettlementPhase, PAYOUT_WINDOW_MILLISECONDS_PER_SECOND, type PayoutExecutedPayload, type PayoutSpec, RECOVERY_CODE_BYTE_LENGTH, type RefundExecutedPayload, type RefundIntentResult, type RequestRefundArgs, type RunSwapParams, SUPPORTED_TOTAL_DEADLINE_MS, type SessionStatus, type SourceLiquidityUse, type SpendingPolicySnapshot, type SwapResult, type SyncUserResponsePayload, type WithdrawExecutedPayload, commitmentFromCode, contractRequest, createCoordinatorSession, generateRecoveryCode, getDepositAddress, isBenignTransportDrop, recoveryCodeFromHex, recoveryCodeFromUserInput, recoveryCodeToHex, replayFromStorage, requestRefund, subscribe, sync };
359
+ export { type ContractRequestArgs, type ContractRequestResult, INSTANT_PAYOUT_WINDOW_MS, MAX_ENTRY_AMOUNT_LAMPORTS, MIN_ENTRY_AMOUNT_LAMPORTS, type NormalUserActorSyncSnapshot, type NormalUserRefundability, type NormalUserSettlementPhase, PAYOUT_WINDOW_MILLISECONDS_PER_SECOND, type PayoutExecutedPayload, RECOVERY_CODE_BYTE_LENGTH, type RefundAcceptanceReceipt, type RefundExecutedPayload, type RequestRefundArgs, type ResumePreDelegationParams, type ResumePreDelegationResult, SUPPORTED_TOTAL_DEADLINE_MS, type SourceLiquidityUse, type SpendingPolicySnapshot, type SyncUserResponse, type SyncUserResponsePayload, type WithdrawExecutedPayload, commitmentFromCode, contractRequest, generateRecoveryCode, recoveryCodeFromHex, recoveryCodeFromUserInput, recoveryCodeToHex, requestRefund, resumePreDelegation, sync };