@invisible-labs/sdk 0.6.0-devnet.1

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 (54) hide show
  1. package/README.md +210 -0
  2. package/dist/chunk-7DSVN3MV.js +1145 -0
  3. package/dist/chunk-7DSVN3MV.js.map +1 -0
  4. package/dist/chunk-JNNVPZEU.js +599 -0
  5. package/dist/chunk-JNNVPZEU.js.map +1 -0
  6. package/dist/chunk-JRMKCE3S.js +50 -0
  7. package/dist/chunk-JRMKCE3S.js.map +1 -0
  8. package/dist/chunk-LBC7ALYO.js +3783 -0
  9. package/dist/chunk-LBC7ALYO.js.map +1 -0
  10. package/dist/chunk-NCY4FCYU.js +1911 -0
  11. package/dist/chunk-NCY4FCYU.js.map +1 -0
  12. package/dist/chunk-OHIM2YWU.js +126 -0
  13. package/dist/chunk-OHIM2YWU.js.map +1 -0
  14. package/dist/chunk-SZAYO2L5.js +123 -0
  15. package/dist/chunk-SZAYO2L5.js.map +1 -0
  16. package/dist/chunk-TQNNTV5F.js +17 -0
  17. package/dist/chunk-TQNNTV5F.js.map +1 -0
  18. package/dist/chunk-VR6T6OJS.js +24 -0
  19. package/dist/chunk-VR6T6OJS.js.map +1 -0
  20. package/dist/chunk-XUWBGET5.js +221 -0
  21. package/dist/chunk-XUWBGET5.js.map +1 -0
  22. package/dist/coordinator-7Y45MCCZ.js +4 -0
  23. package/dist/coordinator-7Y45MCCZ.js.map +1 -0
  24. package/dist/createSession-D3ym-Ira.d.ts +177 -0
  25. package/dist/dkgWorker.d.ts +2 -0
  26. package/dist/dkgWorker.js +61 -0
  27. package/dist/dkgWorker.js.map +1 -0
  28. package/dist/events.d.ts +54 -0
  29. package/dist/events.js +143 -0
  30. package/dist/events.js.map +1 -0
  31. package/dist/frostRuntime-JESDHN6O.js +4 -0
  32. package/dist/frostRuntime-JESDHN6O.js.map +1 -0
  33. package/dist/index.d.ts +499 -0
  34. package/dist/index.js +132 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/lp.d.ts +388 -0
  37. package/dist/lp.js +1711 -0
  38. package/dist/lp.js.map +1 -0
  39. package/dist/presets.d.ts +43 -0
  40. package/dist/presets.js +70 -0
  41. package/dist/presets.js.map +1 -0
  42. package/dist/session-DFuy54C-.d.ts +31 -0
  43. package/dist/stats.d.ts +47 -0
  44. package/dist/stats.js +21 -0
  45. package/dist/stats.js.map +1 -0
  46. package/dist/storage.d.ts +82 -0
  47. package/dist/storage.js +246 -0
  48. package/dist/storage.js.map +1 -0
  49. package/dist/types-ZhV7TIQY.d.ts +76 -0
  50. package/dist/types.generated-CHGSbmLp.d.ts +67 -0
  51. package/dist/user.d.ts +377 -0
  52. package/dist/user.js +1225 -0
  53. package/dist/user.js.map +1 -0
  54. package/package.json +82 -0
package/dist/user.d.ts ADDED
@@ -0,0 +1,377 @@
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';
6
+
7
+ /**
8
+ * Acceptance receipts (spec section 8.2).
9
+ *
10
+ * Every mutating command returns an asynchronous acceptance receipt - `accepted`
11
+ * plus a correlation `requestId` - never the resulting domain state. Outcomes
12
+ * arrive later through `sync` reads or `events` subscriptions.
13
+ */
14
+ /** The receipt a mutating command resolves to once the coordinator accepts it. */
15
+ interface AcceptanceReceipt {
16
+ readonly accepted: true;
17
+ /** Correlation id for this logical action; stable across transient retries. */
18
+ readonly requestId: string;
19
+ /** Optional coordinator-reported request state (e.g. `REQUESTED`). */
20
+ readonly state?: string;
21
+ }
22
+
23
+ type ClientSwapState = "new" | "awaiting_dkg" | "awaiting_deposit" | "awaiting_delegation" | "awaiting_delegate_ack" | "awaiting_delegate_ack_after_deposit" | "ready_for_settlement" | "settling" | "completed" | "refunded" | "failed";
24
+ type PayoutSpec = {
25
+ readonly mode: "instant";
26
+ readonly destination_address: string;
27
+ } | {
28
+ readonly mode: "scheduled";
29
+ readonly num_fragments: number;
30
+ readonly window_seconds: number;
31
+ readonly destination_addresses: readonly string[];
32
+ };
33
+ type SpendingPolicySnapshot = {
34
+ readonly asset: "SOL";
35
+ readonly entry_amount_lamports: number;
36
+ readonly total_committed_lamports: number;
37
+ readonly payout_deadline_ms: number;
38
+ readonly payout_window_ms?: number;
39
+ readonly payout_schedule: readonly {
40
+ readonly destination_address: string;
41
+ }[];
42
+ readonly fragment_count: number;
43
+ readonly payout_mode: "instant" | "scheduled";
44
+ readonly matching_mode: "exact_1_to_1";
45
+ readonly fragmentation_allowed: "payout_side_only";
46
+ readonly min_fee_bps: number;
47
+ readonly fee_bps: number;
48
+ readonly fee_lamports: number;
49
+ readonly net_payout_lamports: number;
50
+ };
51
+ type PayoutExecutedPayload = {
52
+ readonly index: number;
53
+ readonly amount_lamports: number;
54
+ readonly destination_address: string;
55
+ readonly tx_signature: string;
56
+ readonly executed_at_ms: number;
57
+ readonly final: boolean;
58
+ };
59
+ type WithdrawExecutedPayload = {
60
+ readonly tx_signature: string;
61
+ readonly amount_lamports: number;
62
+ readonly withdrawn_at_ms: number;
63
+ readonly trigger: "user_request" | "auto_deadline";
64
+ readonly destination_address: string;
65
+ };
66
+ type RefundExecutedPayload = WithdrawExecutedPayload;
67
+ type SyncRetryInstruction = {
68
+ readonly should_retry: boolean;
69
+ readonly poll_after_ms: number | null;
70
+ };
71
+ type PayoutWindowSyncSnapshot = {
72
+ readonly starts_at_ms: number;
73
+ readonly deadline_ms: number | null;
74
+ };
75
+ 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";
77
+ type NormalUserRefundability = "available_now" | "request_pending" | "blocked_by_lock" | "stale" | "unavailable";
78
+ type SourceLiquidityUse = "not_materialized" | "available" | "locked_for_payout" | "pending_finality" | "spent" | "released";
79
+ type NormalUserContractSyncSnapshot = {
80
+ readonly contract_id: string;
81
+ readonly status: NormalUserContractStatus;
82
+ readonly settlement_phase: NormalUserSettlementPhase;
83
+ readonly refundability: NormalUserRefundability;
84
+ readonly source_liquidity_use: SourceLiquidityUse;
85
+ readonly destination_wallet: string | null;
86
+ readonly deposit_amount_lamports: number;
87
+ readonly deposit_expires_at_ms: number;
88
+ readonly payout_window: PayoutWindowSyncSnapshot;
89
+ readonly settlement_tx_hashes: readonly string[];
90
+ readonly settled_amount_lamports: number;
91
+ readonly protocol_fee_lamports: number;
92
+ readonly network_fee_lost_lamports: readonly number[];
93
+ readonly withdrawal_requested_lamports: number;
94
+ readonly withdrawal_landed_lamports: number;
95
+ readonly withdrawal_landed_fee_lamports: number;
96
+ readonly withdrawal_canceled_lamports: number;
97
+ readonly withdrawal_network_fee_loss_lamports: number;
98
+ readonly withdrawal_tx_hashes: readonly string[];
99
+ readonly retry: SyncRetryInstruction;
100
+ readonly state_version: number;
101
+ readonly updated_at_ms: number;
102
+ };
103
+ type NormalUserActorSyncSnapshot = {
104
+ readonly actor: "normal_user";
105
+ readonly snapshot: NormalUserContractSyncSnapshot;
106
+ };
107
+ type SyncUserResponsePayload = {
108
+ readonly state: ClientSwapState;
109
+ readonly fragments_executed: readonly PayoutExecutedPayload[];
110
+ readonly withdraw_execution?: RefundExecutedPayload;
111
+ readonly actor_sync?: NormalUserActorSyncSnapshot;
112
+ };
113
+ type WithdrawAcceptedPayload = {
114
+ readonly status: "accepted";
115
+ readonly amount_lamports: number;
116
+ readonly destination_address: string;
117
+ readonly accepted_at_ms: number;
118
+ };
119
+ type RunSwapParams = {
120
+ amountLamports: number;
121
+ payoutSpec: PayoutSpec;
122
+ payoutDeadlineMs?: number;
123
+ onPolicySnapshot?: (policy: SpendingPolicySnapshot) => void;
124
+ recoveryCommitment?: Uint8Array;
125
+ syncSecret?: Uint8Array;
126
+ onSyncSecretReady?: (info: {
127
+ secretHex: string;
128
+ }) => void | Promise<void>;
129
+ onRecoveryCodeReady?: (info: {
130
+ codeHex: string;
131
+ }) => void | Promise<void>;
132
+ delegateShare?: Uint8Array;
133
+ onDepositAddressReady?: (info: {
134
+ swapId: string;
135
+ jointPublicKey: Uint8Array;
136
+ amountLamports: number;
137
+ depositExpiresAtMs: number;
138
+ coordinatorTimestampMs: number;
139
+ }) => void | Promise<void>;
140
+ onDepositConfirmed?: (info: {
141
+ originAddress: string | undefined;
142
+ }) => void | Promise<void>;
143
+ payoutWindowMs?: number;
144
+ };
145
+ /** Parameters for the pre-deposit portion of a normal-user contract flow. */
146
+ type ContractRequestParams = Omit<RunSwapParams, "onDepositConfirmed">;
147
+ /**
148
+ * Details returned once the coordinator has accepted, initialized, and
149
+ * durably delegated a contract, but before the user's deposit is observed.
150
+ */
151
+ type ContractRequestResult = {
152
+ readonly accepted: true;
153
+ /** V0 has no separate durable request id, so this aliases `swapId`. */
154
+ readonly requestId: string;
155
+ readonly state: "awaiting_deposit";
156
+ readonly swapId: string;
157
+ readonly depositAddress: string;
158
+ readonly jointPublicKey: Uint8Array;
159
+ readonly amountLamports: number;
160
+ readonly depositExpiresAtMs: number;
161
+ readonly coordinatorTimestampMs: number;
162
+ readonly delegatedAtMs: number;
163
+ /** The read-only status secret. The caller must persist it if it needs sync. */
164
+ readonly syncSecret: Uint8Array;
165
+ readonly syncSecretHex: string;
166
+ /** Present when the SDK generated the Recovery Code for this request. */
167
+ readonly recoveryCodeHex?: string;
168
+ readonly policySnapshot: SpendingPolicySnapshot;
169
+ readonly delegatePolicySnapshot: SpendingPolicySnapshot;
170
+ };
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;
201
+ };
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>;
233
+ };
234
+ declare function createCoordinatorSession(options: CoordinatorSessionOptions): CoordinatorSessionHandle;
235
+ declare function isBenignTransportDrop(err: unknown): boolean;
236
+
237
+ /**
238
+ * Payout policy validation (spec sections 4.3.1 and 10.1).
239
+ *
240
+ * A two-stage check: AJV enforces the structural shape, then the semantic rules
241
+ * that JSON Schema cannot express are applied. Any failure throws a
242
+ * `PolicyValidationError` and the policy never reaches the wire. Pure and
243
+ * synchronous; no transport, no I/O.
244
+ */
245
+
246
+ /**
247
+ * Conversion factor used by the public payout-window selector.
248
+ */
249
+ declare const PAYOUT_WINDOW_MILLISECONDS_PER_SECOND = 1000;
250
+ /** `totalDeadlineMs` value that selects the coordinator's instant payout mode. */
251
+ declare const INSTANT_PAYOUT_WINDOW_MS = 0;
252
+ /**
253
+ * `totalDeadlineMs` values accepted by the current normal-user SDK surface.
254
+ * Zero selects instant payout; positive values select a scheduled window.
255
+ */
256
+ declare const SUPPORTED_TOTAL_DEADLINE_MS: readonly number[];
257
+
258
+ /** Byte length of the Recovery Code preimage used by normal-user withdrawals. */
259
+ declare const RECOVERY_CODE_BYTE_LENGTH = 32;
260
+ declare function generateRecoveryCode(): Promise<{
261
+ code: Uint8Array;
262
+ commitment: Uint8Array;
263
+ }>;
264
+ declare function commitmentFromCode(code: Uint8Array): Promise<Uint8Array>;
265
+ declare function recoveryCodeToHex(code: Uint8Array): string;
266
+ declare function recoveryCodeFromHex(hex: string): Uint8Array;
267
+ declare function recoveryCodeFromUserInput(input: string): Uint8Array;
268
+
269
+ /**
270
+ * `@invisible-labs/sdk/user` - normal-user (private transfer) commands (spec 4.3).
271
+ *
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`.
275
+ */
276
+
277
+ /** Inclusive minimum private-transfer entry amount in lamports. */
278
+ declare const MIN_ENTRY_AMOUNT_LAMPORTS = 400000000;
279
+ /** Inclusive maximum private-transfer entry amount in lamports. */
280
+ declare const MAX_ENTRY_AMOUNT_LAMPORTS = 100000000000;
281
+ /** Arguments to start a new private-transfer pool entry. */
282
+ interface ContractRequestArgs {
283
+ /**
284
+ * Gross private-transfer amount in lamports.
285
+ *
286
+ * At the contract boundary, this is the exact amount the coordinator expects
287
+ * to observe at the fundable deposit address and hold in the joint wallet.
288
+ * It is the custody-side amount before protocol and network-fee accounting,
289
+ * not the net amount a payout destination receives.
290
+ */
291
+ readonly amountLamports: number;
292
+ /**
293
+ * Where and how the output is delivered. V0 normal-user requests support
294
+ * exactly one payout destination and validate the policy locally before
295
+ * submission. `batchExclusionId` is rejected in V0; its planned V1 meaning
296
+ * is campaign-scoped batch exclusion, never a stable actor identity.
297
+ * `destinations[*].minDelayMs` and `destinations[*].maxDelayMs` are also
298
+ * rejected in V0 because the current runtime does not honor them.
299
+ * `totalDeadlineMs` selects the payout window: use `0` for instant payout,
300
+ * or one of the coordinator-supported scheduled durations exposed by
301
+ * `SUPPORTED_TOTAL_DEADLINE_MS`.
302
+ */
303
+ 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
+ /** Optional caller-owned status secret, copied before it reaches the wire. */
310
+ readonly syncSecret?: Uint8Array;
311
+ /** Called before ContractRequest so the caller can persist the status secret. */
312
+ readonly onSyncSecretReady?: (info: {
313
+ secretHex: string;
314
+ }) => void | Promise<void>;
315
+ /** Optional precomputed Recovery Code commitment for caller-managed recovery. */
316
+ readonly recoveryCommitment?: Uint8Array;
317
+ /** Called before DelegateShare so the caller can persist the generated code. */
318
+ readonly onRecoveryCodeReady?: (info: {
319
+ codeHex: string;
320
+ }) => void | Promise<void>;
321
+ }
322
+ /**
323
+ * Start a new pool entry through the current normal-user coordinator flow.
324
+ * Resolves after DKG and durable share delegation, before the user's deposit
325
+ * is observed. The returned `depositAddress` is the joint-wallet address.
326
+ * `payoutPolicy.totalDeadlineMs` selects the payout window: omitted or `0`
327
+ * selects instant payout; the supported positive millisecond values select
328
+ * the corresponding scheduled coordinator window.
329
+ *
330
+ * @throws PolicyValidationError if the payout policy is invalid (never hits the wire).
331
+ * @throws AttestationError if the session is not attested.
332
+ * @throws CommandError if the coordinator rejects the request or the local
333
+ * session cannot complete the DKG/delegation boundary.
334
+ */
335
+ declare function contractRequest(session: Session, args: ContractRequestArgs): Promise<ContractRequestResult>;
336
+ /** 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>;
338
+ /** Arguments to refund a pool entry with the Recovery Code preimage. */
339
+ interface RequestRefundArgs {
340
+ /** The 32-byte Recovery Code preimage. */
341
+ readonly recoveryCode: Uint8Array;
342
+ }
343
+ /**
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.
348
+ *
349
+ * @returns An acceptance receipt keyed by the resolved V0 `swapId`. The
350
+ * coordinator's durable execution result is read later through `sync`.
351
+ * @throws AttestationError if the session is not attested.
352
+ * @throws PolicyValidationError if `recoveryCode` is not exactly 32 bytes.
353
+ * @throws CommandError if the coordinator rejects the withdrawal request.
354
+ */
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>;
376
+
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 };