@dexterai/vault 0.1.0

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 (43) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +61 -0
  3. package/dist/constants/index.cjs +92 -0
  4. package/dist/constants/index.d.cts +34 -0
  5. package/dist/constants/index.d.ts +34 -0
  6. package/dist/constants/index.js +57 -0
  7. package/dist/counterfactual.cjs +138 -0
  8. package/dist/counterfactual.d.cts +17 -0
  9. package/dist/counterfactual.d.ts +17 -0
  10. package/dist/counterfactual.js +113 -0
  11. package/dist/index.cjs +140 -0
  12. package/dist/index.d.cts +2 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +113 -0
  15. package/dist/instructions/index.cjs +5016 -0
  16. package/dist/instructions/index.d.cts +290 -0
  17. package/dist/instructions/index.d.ts +290 -0
  18. package/dist/instructions/index.js +4989 -0
  19. package/dist/messages/index.cjs +156 -0
  20. package/dist/messages/index.d.cts +89 -0
  21. package/dist/messages/index.d.ts +89 -0
  22. package/dist/messages/index.js +125 -0
  23. package/dist/precompile/index.cjs +192 -0
  24. package/dist/precompile/index.d.cts +45 -0
  25. package/dist/precompile/index.d.ts +45 -0
  26. package/dist/precompile/index.js +149 -0
  27. package/dist/reader/index.cjs +121 -0
  28. package/dist/reader/index.d.cts +41 -0
  29. package/dist/reader/index.d.ts +41 -0
  30. package/dist/reader/index.js +93 -0
  31. package/dist/signers/node/index.cjs +62 -0
  32. package/dist/signers/node/index.d.cts +21 -0
  33. package/dist/signers/node/index.d.ts +21 -0
  34. package/dist/signers/node/index.js +27 -0
  35. package/dist/signers/types.cjs +18 -0
  36. package/dist/signers/types.d.cts +34 -0
  37. package/dist/signers/types.d.ts +34 -0
  38. package/dist/signers/types.js +0 -0
  39. package/dist/types.cjs +18 -0
  40. package/dist/types.d.cts +104 -0
  41. package/dist/types.d.ts +104 -0
  42. package/dist/types.js +0 -0
  43. package/package.json +53 -0
@@ -0,0 +1,290 @@
1
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * initialize_vault — bootstrap a fresh vault PDA bound to a passkey.
5
+ *
6
+ * Verbatim port of dexter-api/src/vault/instructions.ts:142-160.
7
+ */
8
+
9
+ interface InitializeVaultParams {
10
+ vaultPda: PublicKey;
11
+ payer: PublicKey;
12
+ dexterAuthority: PublicKey;
13
+ passkeyPubkey: Uint8Array;
14
+ /** v2: cooling-off is u32 seconds (negative was meaningless; u32 caps at ~136y). */
15
+ coolingOffSeconds: number;
16
+ /**
17
+ * v2: opaque 32-byte identity claim, operator-defined. Renamed from
18
+ * supabaseUserId. dexter-api writes the 16-byte Supabase UUID into the
19
+ * first 16 bytes and zero-pads the rest. The PDA seed uses only the
20
+ * leading 16 bytes (`identity_claim[..16]`) which preserves the
21
+ * derivation across the rename.
22
+ */
23
+ identityClaim: Uint8Array;
24
+ }
25
+ declare function buildInitializeVaultInstruction(p: InitializeVaultParams): TransactionInstruction;
26
+
27
+ /**
28
+ * set_swig — bind a Swig state PDA into the vault (passkey-signed).
29
+ *
30
+ * Verbatim port of dexter-api/src/vault/instructions.ts:173-189.
31
+ */
32
+
33
+ interface SetSwigParams {
34
+ vaultPda: PublicKey;
35
+ swigAddress: PublicKey;
36
+ clientDataJSON: Uint8Array;
37
+ authenticatorData: Uint8Array;
38
+ }
39
+ declare function buildSetSwigInstruction(p: SetSwigParams): TransactionInstruction;
40
+
41
+ /**
42
+ * register_session_key — authorize a session ed25519 key under a vault.
43
+ *
44
+ * Verbatim port of dexter-x402-sdk/src/tab/instructions.ts:168-194.
45
+ *
46
+ * Accounts (in declaration order — Anchor is strict):
47
+ * 0. [writable] vault — the Vault PDA being mutated
48
+ * 1. [readonly] instructions_sysvar — address-constrained
49
+ *
50
+ * Args (Borsh-serialized after the 8-byte discriminator):
51
+ * session_pubkey: [u8; 32]
52
+ * max_amount: u64
53
+ * expires_at: i64
54
+ * allowed_counterparty: Pubkey (32 bytes)
55
+ * nonce: u32
56
+ * client_data_json: Vec<u8>
57
+ * authenticator_data: Vec<u8>
58
+ */
59
+
60
+ interface BuildRegisterSessionKeyArgs {
61
+ vaultPda: PublicKey;
62
+ sessionPubkey: Uint8Array;
63
+ maxAmount: bigint;
64
+ expiresAt: bigint;
65
+ allowedCounterparty: PublicKey;
66
+ nonce: number;
67
+ clientDataJSON: Uint8Array;
68
+ authenticatorData: Uint8Array;
69
+ }
70
+ declare function buildRegisterSessionKeyInstruction(args: BuildRegisterSessionKeyArgs): TransactionInstruction;
71
+
72
+ /**
73
+ * revoke_session_key — invalidate the vault's current active session.
74
+ *
75
+ * Verbatim port of dexter-x402-sdk/src/tab/instructions.ts:215-232.
76
+ *
77
+ * Accounts: same as register (vault, instructions_sysvar).
78
+ *
79
+ * Args (Borsh after the 8-byte discriminator):
80
+ * client_data_json: Vec<u8>
81
+ * authenticator_data: Vec<u8>
82
+ *
83
+ * IMPORTANT: there is NO session_pubkey arg. The on-chain handler reads
84
+ * the session pubkey from vault.active_session directly. The session
85
+ * pubkey IS part of the 128-byte signed message (the program rebuilds it
86
+ * from on-chain state), but it is NOT a tx arg.
87
+ */
88
+
89
+ interface BuildRevokeSessionKeyArgs {
90
+ vaultPda: PublicKey;
91
+ clientDataJSON: Uint8Array;
92
+ authenticatorData: Uint8Array;
93
+ }
94
+ declare function buildRevokeSessionKeyInstruction(args: BuildRevokeSessionKeyArgs): TransactionInstruction;
95
+
96
+ /**
97
+ * settle_voucher — legacy counter-only ix; dexter_authority increments or
98
+ * decrements the vault's pending_voucher_count.
99
+ *
100
+ * Verbatim port of dexter-api/src/vault/instructions.ts:202-214.
101
+ */
102
+
103
+ interface SettleVoucherParams {
104
+ vaultPda: PublicKey;
105
+ dexterAuthority: PublicKey;
106
+ amount: bigint;
107
+ increment: boolean;
108
+ }
109
+ declare function buildSettleVoucherInstruction(p: SettleVoucherParams): TransactionInstruction;
110
+
111
+ /**
112
+ * settle_tab_voucher — Tab streaming settlement; the vault verifies the
113
+ * session-key signature (via an Ed25519 precompile sibling) and then drives
114
+ * the Swig transfer via its role-3 ProgramExec authority.
115
+ *
116
+ * Verbatim port of dexter-api/src/vault/instructions.ts:458-481.
117
+ *
118
+ * Account ordering MUST match the on-chain Anchor struct:
119
+ * [0] swig — required by Swig's ProgramExec validator
120
+ * [1] swig_wallet_address — canonical PDA under the Swig program
121
+ * [2] vault — the vault PDA being mutated
122
+ * [3] dexter_authority — signer; must equal vault.dexter_authority
123
+ * [4] instructions_sysvar — for the Ed25519 precompile sibling lookup
124
+ */
125
+
126
+ interface SettleTabVoucherParams {
127
+ vaultPda: PublicKey;
128
+ swigAddress: PublicKey;
129
+ dexterAuthority: PublicKey;
130
+ channelId: Uint8Array;
131
+ cumulativeAmount: bigint;
132
+ sequenceNumber: number;
133
+ }
134
+ declare function buildSettleTabVoucherInstruction(p: SettleTabVoucherParams): TransactionInstruction;
135
+
136
+ /**
137
+ * Withdrawal-path vault instructions.
138
+ * - request_withdrawal — passkey signs; mutates pending_withdrawal
139
+ * - finalize_withdrawal — passkey signs; Swig role 1 drives the SPL transfer
140
+ * - force_release — buyer's passkey clears a stuck count after the grace window
141
+ *
142
+ * All three are passkey-signed and require a secp256r1 precompile sibling.
143
+ * finalize_withdrawal and force_release additionally interact with Swig's
144
+ * ProgramExec validator (role 1 marker = finalize_withdrawal discriminator).
145
+ */
146
+
147
+ /**
148
+ * Derive the canonical Swig wallet-address PDA: seeds = ["swig-wallet-address", swig_state].
149
+ * The vault program enforces this derivation; we recompute client-side
150
+ * so we can pass it as account[1] of finalize_withdrawal / settle_tab_voucher.
151
+ */
152
+ declare function deriveSwigWalletAddress(swigAddress: PublicKey): PublicKey;
153
+ interface RequestWithdrawalParams {
154
+ vaultPda: PublicKey;
155
+ amount: bigint;
156
+ destination: PublicKey;
157
+ signedAt: bigint;
158
+ clientDataJSON: Uint8Array;
159
+ authenticatorData: Uint8Array;
160
+ }
161
+ declare function buildRequestWithdrawalInstruction(p: RequestWithdrawalParams): TransactionInstruction;
162
+ interface FinalizeWithdrawalParams {
163
+ vaultPda: PublicKey;
164
+ swigAddress: PublicKey;
165
+ clientDataJSON: Uint8Array;
166
+ authenticatorData: Uint8Array;
167
+ }
168
+ /**
169
+ * Account ordering MUST match the on-chain Anchor struct:
170
+ * [0] swig — required by Swig's ProgramExec validator + bound via Anchor `address`
171
+ * [1] swig_wallet_address — canonical PDA under the Swig program
172
+ * [2] vault — the vault PDA being mutated
173
+ * [3] instructions_sysvar — for the secp256r1 precompile sibling lookup
174
+ */
175
+ declare function buildFinalizeWithdrawalInstruction(p: FinalizeWithdrawalParams): TransactionInstruction;
176
+ interface ForceReleaseParams {
177
+ vaultPda: PublicKey;
178
+ clientDataJSON: Uint8Array;
179
+ authenticatorData: Uint8Array;
180
+ }
181
+ /**
182
+ * BUYER-controlled: the buyer's passkey clears a stuck count after the grace
183
+ * period. Op message is "force_release" || swig_address.
184
+ */
185
+ declare function buildForceReleaseInstruction(p: ForceReleaseParams): TransactionInstruction;
186
+
187
+ /**
188
+ * rotate_passkey + rotate_dexter_authority — rotate the two long-lived
189
+ * authorities bound to the vault.
190
+ *
191
+ * Verbatim port of dexter-api/src/vault/instructions.ts:340-383.
192
+ */
193
+
194
+ interface RotatePasskeyParams {
195
+ vaultPda: PublicKey;
196
+ newPasskeyPubkey: Uint8Array;
197
+ clientDataJSON: Uint8Array;
198
+ authenticatorData: Uint8Array;
199
+ }
200
+ /** Op message the current passkey must sign: "rotate_passkey" || new_pubkey. */
201
+ declare function buildRotatePasskeyInstruction(p: RotatePasskeyParams): TransactionInstruction;
202
+ interface RotateDexterAuthorityParams {
203
+ vaultPda: PublicKey;
204
+ currentDexterAuthority: PublicKey;
205
+ newDexterAuthority: PublicKey;
206
+ }
207
+ declare function buildRotateDexterAuthorityInstruction(p: RotateDexterAuthorityParams): TransactionInstruction;
208
+
209
+ /**
210
+ * prove_passkey — read-only proof-of-control; the Solana analogue of EIP-1271.
211
+ *
212
+ * Verbatim port of dexter-api/src/vault/instructions.ts:406-422.
213
+ *
214
+ * Proves the passkey controlling `vaultPda` authorized `challenge`, mutating
215
+ * NOTHING. The on-chain handler reconstructs the op message as
216
+ * "siwx_login" || challenge and verifies it via the SIMD-0075 secp256r1
217
+ * precompile sibling (which MUST precede this instruction). A verifier treats a
218
+ * passing `simulateTransaction([secp256r1_verify, prove_passkey], {sigVerify:false})`
219
+ * (err === null) as proof of control. The `vault` account is read-only and
220
+ * non-signer — no Dexter key, no fee, no state change.
221
+ */
222
+
223
+ interface ProvePasskeyParams {
224
+ vaultPda: PublicKey;
225
+ challenge: Uint8Array;
226
+ clientDataJSON: Uint8Array;
227
+ authenticatorData: Uint8Array;
228
+ }
229
+ declare function buildProvePasskeyInstruction(p: ProvePasskeyParams): TransactionInstruction;
230
+
231
+ /**
232
+ * Canonical 4-role Swig provisioning bundle.
233
+ *
234
+ * THE ONLY place in the codebase that knows about Swig roles 0/1/2/3. Every
235
+ * enrollment path — dexter-api production, dexter-vault tests, future
236
+ * consumers — calls this. The drift bug that ate 4 hours on 2026-06-02 is
237
+ * structurally impossible because the role list lives in exactly one file.
238
+ *
239
+ * Role assignment (locked):
240
+ * role 0 — Ed25519(fee-payer), manageAuthority only (bootstrap; can't spend)
241
+ * role 1 — ProgramExec(vault, marker=finalize_withdrawal), all (withdraw path)
242
+ * role 2 — Ed25519Session(master, TTL'd + token-limited), all (streaming spend)
243
+ * role 3 — ProgramExec(vault, marker=settle_tab_voucher), all (Tab settle path)
244
+ *
245
+ * The HMAC key the Swig-id derivation needs is a CALLER-PROVIDED 32-byte
246
+ * seed. Production passes its session-master secret; tests pass a stable
247
+ * random seed they generated themselves. The package never touches process.env.
248
+ */
249
+
250
+ declare const SWIG_PROGRAM_EXEC_PREFIX: Uint8Array<ArrayBuffer>;
251
+ declare const SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB: Uint8Array<ArrayBuffer>;
252
+ declare const SWIG_PROGRAM_EXEC_MARKERS: readonly Uint8Array[];
253
+ interface BuildSwigCreationBundleParams {
254
+ feePayer: string;
255
+ dexterMasterPubkey: string;
256
+ identitySeed: Uint8Array;
257
+ /** 32-byte HMAC key for Swig-id derivation. Caller-provided (no env access). */
258
+ hmacKey: Uint8Array;
259
+ sessionTtlSeconds?: bigint;
260
+ spendLimitAtomic?: bigint;
261
+ }
262
+ interface SwigCreationBundleOutput {
263
+ swigAddress: string;
264
+ swigIdBase58: string;
265
+ instructions: any[];
266
+ }
267
+ declare function buildSwigCreationBundle(params: BuildSwigCreationBundleParams): Promise<SwigCreationBundleOutput>;
268
+ declare function expectedSwigAddressFor(identitySeed: Uint8Array, hmacKey: Uint8Array): Promise<string>;
269
+ interface SwigOwnershipCheck {
270
+ ok: boolean;
271
+ reason?: string;
272
+ }
273
+ declare function verifySwigIsOurs(params: {
274
+ swigAddress: string;
275
+ identitySeed: Uint8Array;
276
+ hmacKey: Uint8Array;
277
+ dexterMasterPubkey: string;
278
+ rpcEndpoint: string;
279
+ }): Promise<SwigOwnershipCheck>;
280
+ /**
281
+ * deriveVaultPda — supabaseUserId is the 16-byte UUID; the vault PDA seeds are
282
+ * ["vault", supabaseUserId]. Kept here because it's the canonical Swig-pair PDA
283
+ * derivation. Mirror of dexter-api/src/vault/instructions.ts.
284
+ */
285
+ declare function deriveVaultPda(supabaseUserId: Uint8Array): {
286
+ pda: PublicKey;
287
+ bump: number;
288
+ };
289
+
290
+ export { type BuildRegisterSessionKeyArgs, type BuildRevokeSessionKeyArgs, type BuildSwigCreationBundleParams, type FinalizeWithdrawalParams, type ForceReleaseParams, type InitializeVaultParams, type ProvePasskeyParams, type RequestWithdrawalParams, type RotateDexterAuthorityParams, type RotatePasskeyParams, SWIG_PROGRAM_EXEC_MARKERS, SWIG_PROGRAM_EXEC_PREFIX, SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB, type SetSwigParams, type SettleTabVoucherParams, type SettleVoucherParams, type SwigCreationBundleOutput, type SwigOwnershipCheck, buildFinalizeWithdrawalInstruction, buildForceReleaseInstruction, buildInitializeVaultInstruction, buildProvePasskeyInstruction, buildRegisterSessionKeyInstruction, buildRequestWithdrawalInstruction, buildRevokeSessionKeyInstruction, buildRotateDexterAuthorityInstruction, buildRotatePasskeyInstruction, buildSetSwigInstruction, buildSettleTabVoucherInstruction, buildSettleVoucherInstruction, buildSwigCreationBundle, deriveSwigWalletAddress, deriveVaultPda, expectedSwigAddressFor, verifySwigIsOurs };
@@ -0,0 +1,290 @@
1
+ import { PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * initialize_vault — bootstrap a fresh vault PDA bound to a passkey.
5
+ *
6
+ * Verbatim port of dexter-api/src/vault/instructions.ts:142-160.
7
+ */
8
+
9
+ interface InitializeVaultParams {
10
+ vaultPda: PublicKey;
11
+ payer: PublicKey;
12
+ dexterAuthority: PublicKey;
13
+ passkeyPubkey: Uint8Array;
14
+ /** v2: cooling-off is u32 seconds (negative was meaningless; u32 caps at ~136y). */
15
+ coolingOffSeconds: number;
16
+ /**
17
+ * v2: opaque 32-byte identity claim, operator-defined. Renamed from
18
+ * supabaseUserId. dexter-api writes the 16-byte Supabase UUID into the
19
+ * first 16 bytes and zero-pads the rest. The PDA seed uses only the
20
+ * leading 16 bytes (`identity_claim[..16]`) which preserves the
21
+ * derivation across the rename.
22
+ */
23
+ identityClaim: Uint8Array;
24
+ }
25
+ declare function buildInitializeVaultInstruction(p: InitializeVaultParams): TransactionInstruction;
26
+
27
+ /**
28
+ * set_swig — bind a Swig state PDA into the vault (passkey-signed).
29
+ *
30
+ * Verbatim port of dexter-api/src/vault/instructions.ts:173-189.
31
+ */
32
+
33
+ interface SetSwigParams {
34
+ vaultPda: PublicKey;
35
+ swigAddress: PublicKey;
36
+ clientDataJSON: Uint8Array;
37
+ authenticatorData: Uint8Array;
38
+ }
39
+ declare function buildSetSwigInstruction(p: SetSwigParams): TransactionInstruction;
40
+
41
+ /**
42
+ * register_session_key — authorize a session ed25519 key under a vault.
43
+ *
44
+ * Verbatim port of dexter-x402-sdk/src/tab/instructions.ts:168-194.
45
+ *
46
+ * Accounts (in declaration order — Anchor is strict):
47
+ * 0. [writable] vault — the Vault PDA being mutated
48
+ * 1. [readonly] instructions_sysvar — address-constrained
49
+ *
50
+ * Args (Borsh-serialized after the 8-byte discriminator):
51
+ * session_pubkey: [u8; 32]
52
+ * max_amount: u64
53
+ * expires_at: i64
54
+ * allowed_counterparty: Pubkey (32 bytes)
55
+ * nonce: u32
56
+ * client_data_json: Vec<u8>
57
+ * authenticator_data: Vec<u8>
58
+ */
59
+
60
+ interface BuildRegisterSessionKeyArgs {
61
+ vaultPda: PublicKey;
62
+ sessionPubkey: Uint8Array;
63
+ maxAmount: bigint;
64
+ expiresAt: bigint;
65
+ allowedCounterparty: PublicKey;
66
+ nonce: number;
67
+ clientDataJSON: Uint8Array;
68
+ authenticatorData: Uint8Array;
69
+ }
70
+ declare function buildRegisterSessionKeyInstruction(args: BuildRegisterSessionKeyArgs): TransactionInstruction;
71
+
72
+ /**
73
+ * revoke_session_key — invalidate the vault's current active session.
74
+ *
75
+ * Verbatim port of dexter-x402-sdk/src/tab/instructions.ts:215-232.
76
+ *
77
+ * Accounts: same as register (vault, instructions_sysvar).
78
+ *
79
+ * Args (Borsh after the 8-byte discriminator):
80
+ * client_data_json: Vec<u8>
81
+ * authenticator_data: Vec<u8>
82
+ *
83
+ * IMPORTANT: there is NO session_pubkey arg. The on-chain handler reads
84
+ * the session pubkey from vault.active_session directly. The session
85
+ * pubkey IS part of the 128-byte signed message (the program rebuilds it
86
+ * from on-chain state), but it is NOT a tx arg.
87
+ */
88
+
89
+ interface BuildRevokeSessionKeyArgs {
90
+ vaultPda: PublicKey;
91
+ clientDataJSON: Uint8Array;
92
+ authenticatorData: Uint8Array;
93
+ }
94
+ declare function buildRevokeSessionKeyInstruction(args: BuildRevokeSessionKeyArgs): TransactionInstruction;
95
+
96
+ /**
97
+ * settle_voucher — legacy counter-only ix; dexter_authority increments or
98
+ * decrements the vault's pending_voucher_count.
99
+ *
100
+ * Verbatim port of dexter-api/src/vault/instructions.ts:202-214.
101
+ */
102
+
103
+ interface SettleVoucherParams {
104
+ vaultPda: PublicKey;
105
+ dexterAuthority: PublicKey;
106
+ amount: bigint;
107
+ increment: boolean;
108
+ }
109
+ declare function buildSettleVoucherInstruction(p: SettleVoucherParams): TransactionInstruction;
110
+
111
+ /**
112
+ * settle_tab_voucher — Tab streaming settlement; the vault verifies the
113
+ * session-key signature (via an Ed25519 precompile sibling) and then drives
114
+ * the Swig transfer via its role-3 ProgramExec authority.
115
+ *
116
+ * Verbatim port of dexter-api/src/vault/instructions.ts:458-481.
117
+ *
118
+ * Account ordering MUST match the on-chain Anchor struct:
119
+ * [0] swig — required by Swig's ProgramExec validator
120
+ * [1] swig_wallet_address — canonical PDA under the Swig program
121
+ * [2] vault — the vault PDA being mutated
122
+ * [3] dexter_authority — signer; must equal vault.dexter_authority
123
+ * [4] instructions_sysvar — for the Ed25519 precompile sibling lookup
124
+ */
125
+
126
+ interface SettleTabVoucherParams {
127
+ vaultPda: PublicKey;
128
+ swigAddress: PublicKey;
129
+ dexterAuthority: PublicKey;
130
+ channelId: Uint8Array;
131
+ cumulativeAmount: bigint;
132
+ sequenceNumber: number;
133
+ }
134
+ declare function buildSettleTabVoucherInstruction(p: SettleTabVoucherParams): TransactionInstruction;
135
+
136
+ /**
137
+ * Withdrawal-path vault instructions.
138
+ * - request_withdrawal — passkey signs; mutates pending_withdrawal
139
+ * - finalize_withdrawal — passkey signs; Swig role 1 drives the SPL transfer
140
+ * - force_release — buyer's passkey clears a stuck count after the grace window
141
+ *
142
+ * All three are passkey-signed and require a secp256r1 precompile sibling.
143
+ * finalize_withdrawal and force_release additionally interact with Swig's
144
+ * ProgramExec validator (role 1 marker = finalize_withdrawal discriminator).
145
+ */
146
+
147
+ /**
148
+ * Derive the canonical Swig wallet-address PDA: seeds = ["swig-wallet-address", swig_state].
149
+ * The vault program enforces this derivation; we recompute client-side
150
+ * so we can pass it as account[1] of finalize_withdrawal / settle_tab_voucher.
151
+ */
152
+ declare function deriveSwigWalletAddress(swigAddress: PublicKey): PublicKey;
153
+ interface RequestWithdrawalParams {
154
+ vaultPda: PublicKey;
155
+ amount: bigint;
156
+ destination: PublicKey;
157
+ signedAt: bigint;
158
+ clientDataJSON: Uint8Array;
159
+ authenticatorData: Uint8Array;
160
+ }
161
+ declare function buildRequestWithdrawalInstruction(p: RequestWithdrawalParams): TransactionInstruction;
162
+ interface FinalizeWithdrawalParams {
163
+ vaultPda: PublicKey;
164
+ swigAddress: PublicKey;
165
+ clientDataJSON: Uint8Array;
166
+ authenticatorData: Uint8Array;
167
+ }
168
+ /**
169
+ * Account ordering MUST match the on-chain Anchor struct:
170
+ * [0] swig — required by Swig's ProgramExec validator + bound via Anchor `address`
171
+ * [1] swig_wallet_address — canonical PDA under the Swig program
172
+ * [2] vault — the vault PDA being mutated
173
+ * [3] instructions_sysvar — for the secp256r1 precompile sibling lookup
174
+ */
175
+ declare function buildFinalizeWithdrawalInstruction(p: FinalizeWithdrawalParams): TransactionInstruction;
176
+ interface ForceReleaseParams {
177
+ vaultPda: PublicKey;
178
+ clientDataJSON: Uint8Array;
179
+ authenticatorData: Uint8Array;
180
+ }
181
+ /**
182
+ * BUYER-controlled: the buyer's passkey clears a stuck count after the grace
183
+ * period. Op message is "force_release" || swig_address.
184
+ */
185
+ declare function buildForceReleaseInstruction(p: ForceReleaseParams): TransactionInstruction;
186
+
187
+ /**
188
+ * rotate_passkey + rotate_dexter_authority — rotate the two long-lived
189
+ * authorities bound to the vault.
190
+ *
191
+ * Verbatim port of dexter-api/src/vault/instructions.ts:340-383.
192
+ */
193
+
194
+ interface RotatePasskeyParams {
195
+ vaultPda: PublicKey;
196
+ newPasskeyPubkey: Uint8Array;
197
+ clientDataJSON: Uint8Array;
198
+ authenticatorData: Uint8Array;
199
+ }
200
+ /** Op message the current passkey must sign: "rotate_passkey" || new_pubkey. */
201
+ declare function buildRotatePasskeyInstruction(p: RotatePasskeyParams): TransactionInstruction;
202
+ interface RotateDexterAuthorityParams {
203
+ vaultPda: PublicKey;
204
+ currentDexterAuthority: PublicKey;
205
+ newDexterAuthority: PublicKey;
206
+ }
207
+ declare function buildRotateDexterAuthorityInstruction(p: RotateDexterAuthorityParams): TransactionInstruction;
208
+
209
+ /**
210
+ * prove_passkey — read-only proof-of-control; the Solana analogue of EIP-1271.
211
+ *
212
+ * Verbatim port of dexter-api/src/vault/instructions.ts:406-422.
213
+ *
214
+ * Proves the passkey controlling `vaultPda` authorized `challenge`, mutating
215
+ * NOTHING. The on-chain handler reconstructs the op message as
216
+ * "siwx_login" || challenge and verifies it via the SIMD-0075 secp256r1
217
+ * precompile sibling (which MUST precede this instruction). A verifier treats a
218
+ * passing `simulateTransaction([secp256r1_verify, prove_passkey], {sigVerify:false})`
219
+ * (err === null) as proof of control. The `vault` account is read-only and
220
+ * non-signer — no Dexter key, no fee, no state change.
221
+ */
222
+
223
+ interface ProvePasskeyParams {
224
+ vaultPda: PublicKey;
225
+ challenge: Uint8Array;
226
+ clientDataJSON: Uint8Array;
227
+ authenticatorData: Uint8Array;
228
+ }
229
+ declare function buildProvePasskeyInstruction(p: ProvePasskeyParams): TransactionInstruction;
230
+
231
+ /**
232
+ * Canonical 4-role Swig provisioning bundle.
233
+ *
234
+ * THE ONLY place in the codebase that knows about Swig roles 0/1/2/3. Every
235
+ * enrollment path — dexter-api production, dexter-vault tests, future
236
+ * consumers — calls this. The drift bug that ate 4 hours on 2026-06-02 is
237
+ * structurally impossible because the role list lives in exactly one file.
238
+ *
239
+ * Role assignment (locked):
240
+ * role 0 — Ed25519(fee-payer), manageAuthority only (bootstrap; can't spend)
241
+ * role 1 — ProgramExec(vault, marker=finalize_withdrawal), all (withdraw path)
242
+ * role 2 — Ed25519Session(master, TTL'd + token-limited), all (streaming spend)
243
+ * role 3 — ProgramExec(vault, marker=settle_tab_voucher), all (Tab settle path)
244
+ *
245
+ * The HMAC key the Swig-id derivation needs is a CALLER-PROVIDED 32-byte
246
+ * seed. Production passes its session-master secret; tests pass a stable
247
+ * random seed they generated themselves. The package never touches process.env.
248
+ */
249
+
250
+ declare const SWIG_PROGRAM_EXEC_PREFIX: Uint8Array<ArrayBuffer>;
251
+ declare const SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB: Uint8Array<ArrayBuffer>;
252
+ declare const SWIG_PROGRAM_EXEC_MARKERS: readonly Uint8Array[];
253
+ interface BuildSwigCreationBundleParams {
254
+ feePayer: string;
255
+ dexterMasterPubkey: string;
256
+ identitySeed: Uint8Array;
257
+ /** 32-byte HMAC key for Swig-id derivation. Caller-provided (no env access). */
258
+ hmacKey: Uint8Array;
259
+ sessionTtlSeconds?: bigint;
260
+ spendLimitAtomic?: bigint;
261
+ }
262
+ interface SwigCreationBundleOutput {
263
+ swigAddress: string;
264
+ swigIdBase58: string;
265
+ instructions: any[];
266
+ }
267
+ declare function buildSwigCreationBundle(params: BuildSwigCreationBundleParams): Promise<SwigCreationBundleOutput>;
268
+ declare function expectedSwigAddressFor(identitySeed: Uint8Array, hmacKey: Uint8Array): Promise<string>;
269
+ interface SwigOwnershipCheck {
270
+ ok: boolean;
271
+ reason?: string;
272
+ }
273
+ declare function verifySwigIsOurs(params: {
274
+ swigAddress: string;
275
+ identitySeed: Uint8Array;
276
+ hmacKey: Uint8Array;
277
+ dexterMasterPubkey: string;
278
+ rpcEndpoint: string;
279
+ }): Promise<SwigOwnershipCheck>;
280
+ /**
281
+ * deriveVaultPda — supabaseUserId is the 16-byte UUID; the vault PDA seeds are
282
+ * ["vault", supabaseUserId]. Kept here because it's the canonical Swig-pair PDA
283
+ * derivation. Mirror of dexter-api/src/vault/instructions.ts.
284
+ */
285
+ declare function deriveVaultPda(supabaseUserId: Uint8Array): {
286
+ pda: PublicKey;
287
+ bump: number;
288
+ };
289
+
290
+ export { type BuildRegisterSessionKeyArgs, type BuildRevokeSessionKeyArgs, type BuildSwigCreationBundleParams, type FinalizeWithdrawalParams, type ForceReleaseParams, type InitializeVaultParams, type ProvePasskeyParams, type RequestWithdrawalParams, type RotateDexterAuthorityParams, type RotatePasskeyParams, SWIG_PROGRAM_EXEC_MARKERS, SWIG_PROGRAM_EXEC_PREFIX, SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB, type SetSwigParams, type SettleTabVoucherParams, type SettleVoucherParams, type SwigCreationBundleOutput, type SwigOwnershipCheck, buildFinalizeWithdrawalInstruction, buildForceReleaseInstruction, buildInitializeVaultInstruction, buildProvePasskeyInstruction, buildRegisterSessionKeyInstruction, buildRequestWithdrawalInstruction, buildRevokeSessionKeyInstruction, buildRotateDexterAuthorityInstruction, buildRotatePasskeyInstruction, buildSetSwigInstruction, buildSettleTabVoucherInstruction, buildSettleVoucherInstruction, buildSwigCreationBundle, deriveSwigWalletAddress, deriveVaultPda, expectedSwigAddressFor, verifySwigIsOurs };