@invisible-labs/sdk 0.6.0-devnet.3 → 0.6.0-devnet.5
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/README.md +129 -15
- package/dist/.invisible-sdk-build-target.json +7 -0
- package/dist/{chunk-QQSI3ZD7.js → chunk-3MDHAS4D.js} +109 -17
- package/dist/chunk-3MDHAS4D.js.map +1 -0
- package/dist/{chunk-NKRVQXRP.js → chunk-3TGQ4CZ3.js} +297 -11
- package/dist/chunk-3TGQ4CZ3.js.map +1 -0
- package/dist/chunk-DCTYBUY3.js +258 -0
- package/dist/chunk-DCTYBUY3.js.map +1 -0
- package/dist/{chunk-NHEHCUS5.js → chunk-EBWTAXNT.js} +3 -3
- package/dist/{chunk-NHEHCUS5.js.map → chunk-EBWTAXNT.js.map} +1 -1
- package/dist/{chunk-V5HXJRBW.js → chunk-HJFMDMPY.js} +3 -3
- package/dist/chunk-HJFMDMPY.js.map +1 -0
- package/dist/{chunk-GHBQF3A7.js → chunk-QRN46R3F.js} +5 -2
- package/dist/chunk-QRN46R3F.js.map +1 -0
- package/dist/chunk-Y7AK6RBV.js +4189 -0
- package/dist/chunk-Y7AK6RBV.js.map +1 -0
- package/dist/{coordinator-VVJ33WF2.js → coordinator-PEWHNZ7I.js} +3 -3
- package/dist/{coordinator-VVJ33WF2.js.map → coordinator-PEWHNZ7I.js.map} +1 -1
- package/dist/events.js +3 -3
- package/dist/index.d.ts +69 -353
- package/dist/index.js +161 -43
- package/dist/index.js.map +1 -1
- package/dist/lp.d.ts +76 -18
- package/dist/lp.js +511 -111
- package/dist/lp.js.map +1 -1
- package/dist/presets.d.ts +7 -40
- package/dist/presets.js +10 -68
- package/dist/presets.js.map +1 -1
- package/dist/stats.js +1 -1
- package/dist/storage.js +2 -243
- package/dist/storage.js.map +1 -1
- package/dist/{errors-N2touVm4.d.ts → types.generated-YhFu9ZBR.d.ts} +65 -4
- package/dist/user.d.ts +134 -8
- package/dist/user.js +991 -250
- package/dist/user.js.map +1 -1
- package/package.json +5 -31
- package/dist/chunk-BWCGNTN5.js +0 -1153
- package/dist/chunk-BWCGNTN5.js.map +0 -1
- package/dist/chunk-DIA6U2CV.js +0 -1927
- package/dist/chunk-DIA6U2CV.js.map +0 -1
- package/dist/chunk-GHBQF3A7.js.map +0 -1
- package/dist/chunk-NKRVQXRP.js.map +0 -1
- package/dist/chunk-QQSI3ZD7.js.map +0 -1
- package/dist/chunk-V5HXJRBW.js.map +0 -1
- package/dist/types.generated-BSEBz4jR.d.ts +0 -68
package/dist/user.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S as Session } from './session-DFuy54C-.js';
|
|
2
|
-
import { P as PayoutPolicy } from './types.generated-
|
|
3
|
-
export { I as InvalidDepositAmountError } from './
|
|
2
|
+
import { P as PayoutPolicy } from './types.generated-YhFu9ZBR.js';
|
|
3
|
+
export { I as InvalidDepositAmountError } from './types.generated-YhFu9ZBR.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Acceptance receipts (spec section 8.2).
|
|
@@ -18,7 +18,17 @@ interface AcceptanceReceipt {
|
|
|
18
18
|
readonly state?: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** Shared normal-user transfer types used without importing an actor entrypoint. */
|
|
21
22
|
type ClientSwapState = "new" | "awaiting_dkg" | "awaiting_deposit" | "awaiting_delegation" | "awaiting_delegate_ack" | "awaiting_delegate_ack_after_deposit" | "ready_for_settlement" | "settling" | "completed" | "refunded" | "failed";
|
|
23
|
+
type PayoutSpec = {
|
|
24
|
+
readonly mode: "instant";
|
|
25
|
+
readonly destination_address: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly mode: "scheduled";
|
|
28
|
+
readonly num_fragments: number;
|
|
29
|
+
readonly window_seconds: number;
|
|
30
|
+
readonly destination_addresses: readonly string[];
|
|
31
|
+
};
|
|
22
32
|
type SpendingPolicySnapshot = {
|
|
23
33
|
readonly asset: "SOL";
|
|
24
34
|
readonly entry_amount_lamports: number;
|
|
@@ -37,6 +47,7 @@ type SpendingPolicySnapshot = {
|
|
|
37
47
|
readonly fee_lamports: number;
|
|
38
48
|
readonly net_payout_lamports: number;
|
|
39
49
|
};
|
|
50
|
+
|
|
40
51
|
type PayoutExecutedPayload = {
|
|
41
52
|
readonly index: number;
|
|
42
53
|
readonly amount_lamports: number;
|
|
@@ -62,14 +73,16 @@ type PayoutWindowSyncSnapshot = {
|
|
|
62
73
|
readonly deadline_ms: number | null;
|
|
63
74
|
};
|
|
64
75
|
type NormalUserContractStatus = "deposit" | "activating" | "active" | "settling" | "completed" | "refunded" | "expired";
|
|
65
|
-
type NormalUserSettlementPhase = "awaiting_deposit" | "activating" | "waiting_for_liquidity" | "matched_scheduled" | "locked_pending_payout" | "submitted" | "confirming" | "completed" | "refund_pending" | "refunded" | "expired";
|
|
76
|
+
type NormalUserSettlementPhase = "awaiting_deposit" | "activating" | "waiting_for_liquidity" | "retry_delayed" | "recovery_required" | "matched_scheduled" | "locked_pending_payout" | "submitted" | "confirming" | "completed" | "refund_pending" | "refunded" | "expired";
|
|
66
77
|
type NormalUserRefundability = "available_now" | "request_pending" | "blocked_by_lock" | "stale" | "unavailable";
|
|
78
|
+
type NormalUserRefundStatus = "queued" | "reserved" | "submitted" | "confirming" | "retrying" | "finalized" | "failed" | "partial" | "canceled";
|
|
67
79
|
type SourceLiquidityUse = "not_materialized" | "available" | "locked_for_payout" | "pending_finality" | "spent" | "released";
|
|
68
80
|
type NormalUserContractSyncSnapshot = {
|
|
69
81
|
readonly contract_id: string;
|
|
70
82
|
readonly status: NormalUserContractStatus;
|
|
71
83
|
readonly settlement_phase: NormalUserSettlementPhase;
|
|
72
84
|
readonly refundability: NormalUserRefundability;
|
|
85
|
+
readonly refund_status: NormalUserRefundStatus | null;
|
|
73
86
|
readonly source_liquidity_use: SourceLiquidityUse;
|
|
74
87
|
readonly destination_wallet: string | null;
|
|
75
88
|
readonly deposit_amount_lamports: number;
|
|
@@ -79,6 +92,7 @@ type NormalUserContractSyncSnapshot = {
|
|
|
79
92
|
readonly settled_amount_lamports: number;
|
|
80
93
|
readonly protocol_fee_lamports: number;
|
|
81
94
|
readonly network_fee_lost_lamports: readonly number[];
|
|
95
|
+
readonly recovery_refund_remaining_lamports: number;
|
|
82
96
|
readonly withdrawal_requested_lamports: number;
|
|
83
97
|
readonly withdrawal_landed_lamports: number;
|
|
84
98
|
readonly withdrawal_landed_fee_lamports: number;
|
|
@@ -115,6 +129,45 @@ type RefundAcceptanceReceipt = AcceptanceReceipt & {
|
|
|
115
129
|
readonly amountLamports: number;
|
|
116
130
|
readonly acceptedAtMs?: number;
|
|
117
131
|
};
|
|
132
|
+
type RunSwapParams = {
|
|
133
|
+
amountLamports: number;
|
|
134
|
+
payoutSpec: PayoutSpec;
|
|
135
|
+
payoutDeadlineMs?: number;
|
|
136
|
+
onPolicySnapshot?: (policy: SpendingPolicySnapshot) => void;
|
|
137
|
+
recoveryCommitment?: Uint8Array;
|
|
138
|
+
syncSecret?: Uint8Array;
|
|
139
|
+
onSyncSecretReady?: (info: {
|
|
140
|
+
secretHex: string;
|
|
141
|
+
}) => void | Promise<void>;
|
|
142
|
+
resumeSecret?: Uint8Array;
|
|
143
|
+
onResumeSecretReady?: (info: {
|
|
144
|
+
secretHex: string;
|
|
145
|
+
}) => void | Promise<void>;
|
|
146
|
+
onSwapAllocated?: (info: {
|
|
147
|
+
swapId: string;
|
|
148
|
+
syncSecretHex: string;
|
|
149
|
+
resumeSecretHex: string;
|
|
150
|
+
}) => void | Promise<void>;
|
|
151
|
+
onRecoveryCodeReady?: (info: {
|
|
152
|
+
codeHex: string;
|
|
153
|
+
}) => void | Promise<void>;
|
|
154
|
+
onDelegateShareReady?: (info: {
|
|
155
|
+
swapId: string;
|
|
156
|
+
delegateShare: Uint8Array;
|
|
157
|
+
}) => void | Promise<void>;
|
|
158
|
+
delegateShare?: Uint8Array;
|
|
159
|
+
onDepositAddressReady?: (info: {
|
|
160
|
+
swapId: string;
|
|
161
|
+
jointPublicKey: Uint8Array;
|
|
162
|
+
amountLamports: number;
|
|
163
|
+
depositExpiresAtMs: number;
|
|
164
|
+
coordinatorTimestampMs: number;
|
|
165
|
+
}) => void | Promise<void>;
|
|
166
|
+
onDepositConfirmed?: (info: {
|
|
167
|
+
originAddress: string | undefined;
|
|
168
|
+
}) => void | Promise<void>;
|
|
169
|
+
payoutWindowMs?: number;
|
|
170
|
+
};
|
|
118
171
|
/**
|
|
119
172
|
* Details returned once the coordinator has accepted, initialized, and
|
|
120
173
|
* durably delegated a contract, but before the user's deposit is observed.
|
|
@@ -134,11 +187,59 @@ type ContractRequestResult = {
|
|
|
134
187
|
/** The read-only status secret. The caller must persist it if it needs sync. */
|
|
135
188
|
readonly syncSecret: Uint8Array;
|
|
136
189
|
readonly syncSecretHex: string;
|
|
190
|
+
/** The pre-delegation mutation secret. Persist it only for resume/recovery workflows. */
|
|
191
|
+
readonly resumeSecret: Uint8Array;
|
|
192
|
+
readonly resumeSecretHex: string;
|
|
137
193
|
/** Present when the SDK generated the Recovery Code for this request. */
|
|
138
194
|
readonly recoveryCodeHex?: string;
|
|
139
195
|
readonly policySnapshot: SpendingPolicySnapshot;
|
|
140
196
|
readonly delegatePolicySnapshot: SpendingPolicySnapshot;
|
|
141
197
|
};
|
|
198
|
+
/** Inputs for resuming an already allocated pre-delegation contract. */
|
|
199
|
+
type ResumePreDelegationParams = {
|
|
200
|
+
readonly swapId: string;
|
|
201
|
+
readonly resumeSecret: Uint8Array;
|
|
202
|
+
readonly syncSecret?: Uint8Array;
|
|
203
|
+
readonly recoveryCommitment: Uint8Array;
|
|
204
|
+
/** The policy snapshot returned when the contract was first allocated. */
|
|
205
|
+
readonly policySnapshot: SpendingPolicySnapshot;
|
|
206
|
+
/** Called before DkgRound2 so recovery can persist the generated Alice share. */
|
|
207
|
+
readonly onDelegateShareReady?: RunSwapParams["onDelegateShareReady"];
|
|
208
|
+
/** Supply the previously generated Alice share when DKG was already sealed. */
|
|
209
|
+
readonly delegateShare?: Uint8Array;
|
|
210
|
+
};
|
|
211
|
+
type ResumePreDelegationResult = {
|
|
212
|
+
readonly swapId: string;
|
|
213
|
+
readonly jointPublicKey?: Uint8Array;
|
|
214
|
+
readonly depositExpiresAtMs?: number;
|
|
215
|
+
readonly coordinatorTimestampMs?: number;
|
|
216
|
+
readonly delegatedAtMs: number;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
declare const CLIENT_PERSISTENCE_SCHEMA_VERSION = 1;
|
|
220
|
+
type PersistedTransferStage = "allocation" | "ready" | "terminal-cleaned";
|
|
221
|
+
/** Public, local-only projection of an SDK-owned normal-user transfer record. */
|
|
222
|
+
interface PersistedTransfer {
|
|
223
|
+
readonly schemaVersion: typeof CLIENT_PERSISTENCE_SCHEMA_VERSION;
|
|
224
|
+
readonly stage: PersistedTransferStage;
|
|
225
|
+
readonly swapId: string;
|
|
226
|
+
readonly amountLamports: number;
|
|
227
|
+
readonly destinationAddress: string;
|
|
228
|
+
readonly policySnapshot: SpendingPolicySnapshot;
|
|
229
|
+
readonly status: ClientSwapState;
|
|
230
|
+
readonly stateVersion?: number;
|
|
231
|
+
readonly updatedAtMs: number;
|
|
232
|
+
readonly coordinatorTimestampMs?: number;
|
|
233
|
+
readonly depositAddress?: string;
|
|
234
|
+
readonly depositExpiresAtMs?: number;
|
|
235
|
+
readonly delegatedAtMs?: number;
|
|
236
|
+
readonly syncSecret?: Uint8Array;
|
|
237
|
+
readonly recoveryCode?: Uint8Array;
|
|
238
|
+
}
|
|
239
|
+
declare function listPersistedTransfers(session: Session): Promise<readonly PersistedTransfer[]>;
|
|
240
|
+
declare function getPersistedTransfer(session: Session, swapId: string): Promise<PersistedTransfer | null>;
|
|
241
|
+
declare function removePersistedTransfer(session: Session, swapId: string): Promise<void>;
|
|
242
|
+
declare function purgePersistedTransfers(session: Session): Promise<void>;
|
|
142
243
|
|
|
143
244
|
/**
|
|
144
245
|
* Payout policy validation (spec sections 4.3.1 and 10.1).
|
|
@@ -214,12 +315,29 @@ interface ContractRequestArgs {
|
|
|
214
315
|
readonly onSyncSecretReady?: (info: {
|
|
215
316
|
secretHex: string;
|
|
216
317
|
}) => void | Promise<void>;
|
|
318
|
+
/** Optional precomputed pre-delegation mutation secret, copied before it reaches the wire. */
|
|
319
|
+
readonly resumeSecret?: Uint8Array;
|
|
320
|
+
/** Called before ContractRequest so the caller can persist the resume secret. */
|
|
321
|
+
readonly onResumeSecretReady?: (info: {
|
|
322
|
+
secretHex: string;
|
|
323
|
+
}) => void | Promise<void>;
|
|
324
|
+
/** Called after allocation so the caller can persist both secrets with the swap id. */
|
|
325
|
+
readonly onSwapAllocated?: (info: {
|
|
326
|
+
swapId: string;
|
|
327
|
+
syncSecretHex: string;
|
|
328
|
+
resumeSecretHex: string;
|
|
329
|
+
}) => void | Promise<void>;
|
|
217
330
|
/** Optional precomputed Recovery Code commitment for caller-managed recovery. */
|
|
218
331
|
readonly recoveryCommitment?: Uint8Array;
|
|
219
332
|
/** Called before DelegateShare so the caller can persist the generated code. */
|
|
220
333
|
readonly onRecoveryCodeReady?: (info: {
|
|
221
334
|
codeHex: string;
|
|
222
335
|
}) => void | Promise<void>;
|
|
336
|
+
/** Called before DkgRound2 so the caller can persist the generated Alice share. */
|
|
337
|
+
readonly onDelegateShareReady?: (info: {
|
|
338
|
+
swapId: string;
|
|
339
|
+
delegateShare: Uint8Array;
|
|
340
|
+
}) => void | Promise<void>;
|
|
223
341
|
}
|
|
224
342
|
/**
|
|
225
343
|
* Start a new pool entry through the current normal-user coordinator flow.
|
|
@@ -235,18 +353,26 @@ interface ContractRequestArgs {
|
|
|
235
353
|
* session cannot complete the DKG/delegation boundary.
|
|
236
354
|
*/
|
|
237
355
|
declare function contractRequest(session: Session, args: ContractRequestArgs): Promise<ContractRequestResult>;
|
|
356
|
+
/** Resume pre-delegation DKG or delegation on a caller-owned Session. */
|
|
357
|
+
declare function resumePreDelegation(session: Session, args: ResumePreDelegationParams): Promise<ResumePreDelegationResult>;
|
|
238
358
|
/** Read the actor-scoped lifecycle projection for a normal-user contract. */
|
|
239
359
|
declare function sync(session: Session, contractId: string, syncSecret: Uint8Array, timeoutMs?: number): Promise<SyncUserResponse>;
|
|
240
360
|
/** Arguments to refund a pool entry with the Recovery Code preimage. */
|
|
241
361
|
interface RequestRefundArgs {
|
|
362
|
+
/** Optional contract correlation required when multiple contracts share one Session. */
|
|
363
|
+
readonly swapId?: string;
|
|
364
|
+
/** Optional status secret used to restore the correlated contract context. */
|
|
365
|
+
readonly syncSecret?: Uint8Array;
|
|
242
366
|
/** The 32-byte Recovery Code preimage. */
|
|
243
367
|
readonly recoveryCode: Uint8Array;
|
|
244
368
|
}
|
|
245
369
|
/**
|
|
246
|
-
* Submit a normal-user `withdraw_request` with
|
|
247
|
-
* (`{ recovery_code }`).
|
|
248
|
-
*
|
|
249
|
-
*
|
|
370
|
+
* Submit a normal-user `withdraw_request` with the Recovery Code preimage
|
|
371
|
+
* (`{ recovery_code }`). Pass `swapId` and `syncSecret` when multiple contracts
|
|
372
|
+
* share one Session so the request is correlated to the intended contract.
|
|
373
|
+
* The coordinator queues a durable origin-bound withdrawal intent and terminal
|
|
374
|
+
* outcome is recovered through sync/status reads. No caller-supplied destination
|
|
375
|
+
* is accepted.
|
|
250
376
|
*
|
|
251
377
|
* @returns An acceptance receipt keyed by the resolved V0 `swapId`, including
|
|
252
378
|
* the coordinator-authoritative amount accepted for withdrawal. The
|
|
@@ -257,4 +383,4 @@ interface RequestRefundArgs {
|
|
|
257
383
|
*/
|
|
258
384
|
declare function requestRefund(session: Session, args: RequestRefundArgs): Promise<RefundAcceptanceReceipt>;
|
|
259
385
|
|
|
260
|
-
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, SUPPORTED_TOTAL_DEADLINE_MS, type SourceLiquidityUse, type SpendingPolicySnapshot, type SyncUserResponse, type SyncUserResponsePayload, type WithdrawExecutedPayload, commitmentFromCode, contractRequest, generateRecoveryCode, recoveryCodeFromHex, recoveryCodeFromUserInput, recoveryCodeToHex, requestRefund, sync };
|
|
386
|
+
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, type PersistedTransfer, type PersistedTransferStage, 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, getPersistedTransfer, listPersistedTransfers, purgePersistedTransfers, recoveryCodeFromHex, recoveryCodeFromUserInput, recoveryCodeToHex, removePersistedTransfer, requestRefund, resumePreDelegation, sync };
|