@x1id/resolve 0.22.0 → 0.43.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 (51) hide show
  1. package/README.md +71 -0
  2. package/dist/accounts.d.ts +6 -0
  3. package/dist/accounts.js +6 -1
  4. package/dist/agent.d.ts +184 -8
  5. package/dist/agent.js +351 -3
  6. package/dist/agentPolicy.d.ts +238 -0
  7. package/dist/agentPolicy.js +364 -0
  8. package/dist/attestation.d.ts +25 -0
  9. package/dist/attestation.js +25 -0
  10. package/dist/checkout.d.ts +216 -0
  11. package/dist/checkout.js +327 -0
  12. package/dist/credentials.d.ts +466 -0
  13. package/dist/credentials.js +669 -0
  14. package/dist/gate.d.ts +94 -4
  15. package/dist/gate.js +206 -7
  16. package/dist/gateClient.d.ts +12 -0
  17. package/dist/giftLink.d.ts +272 -0
  18. package/dist/giftLink.js +452 -0
  19. package/dist/index.d.ts +14 -0
  20. package/dist/index.js +33 -0
  21. package/dist/loginButton.d.ts +69 -0
  22. package/dist/loginButton.js +207 -0
  23. package/dist/logo.d.ts +1 -0
  24. package/dist/logo.js +8 -0
  25. package/dist/messaging.d.ts +439 -0
  26. package/dist/messaging.js +979 -0
  27. package/dist/mintNft.d.ts +247 -0
  28. package/dist/mintNft.js +328 -0
  29. package/dist/nsGate.d.ts +98 -0
  30. package/dist/nsGate.js +172 -0
  31. package/dist/oidc.d.ts +272 -0
  32. package/dist/oidc.js +641 -0
  33. package/dist/pay.d.ts +513 -0
  34. package/dist/pay.js +756 -0
  35. package/dist/payment.d.ts +9 -2
  36. package/dist/payment.js +9 -2
  37. package/dist/recovery.d.ts +186 -0
  38. package/dist/recovery.js +276 -0
  39. package/dist/recoveryNft.d.ts +183 -0
  40. package/dist/recoveryNft.js +291 -0
  41. package/dist/shield.d.ts +373 -0
  42. package/dist/shield.js +695 -0
  43. package/dist/subscription.d.ts +439 -0
  44. package/dist/subscription.js +642 -0
  45. package/dist/textRecords.d.ts +52 -6
  46. package/dist/textRecords.js +80 -8
  47. package/dist/types.d.ts +3 -0
  48. package/dist/x402Receipt.d.ts +246 -0
  49. package/dist/x402Receipt.js +374 -0
  50. package/package.json +18 -1
  51. package/schema/agent-manifest.json +91 -8
@@ -0,0 +1,439 @@
1
+ /**
2
+ * X1ID Pay, phase 2: SPL pull subscriptions (docs/specs/x1id-pay-onchain.md
3
+ * §3/§4).
4
+ *
5
+ * - `Subscription` at `["sub", payer, payee, id]`: created and paid for by
6
+ * the PAYER, its terms (mint, decimals, amount, period, max charges, the
7
+ * optional `@name` binding) fixed for life. Any change = a new id.
8
+ * - The payer's delegate PDA `["sub_delegate", payer]` is the SPL delegate on
9
+ * the payer's canonical ATA. ONE per payer (an SPL account has a single
10
+ * delegate), so the SPL approval is shared by every subscription of that
11
+ * payer in a mint. The program tracks each subscription's own share in
12
+ * `allowanceLeft` (layout v2, Sentinel run-011): a charge needs and spends
13
+ * `amount` of it, so no subscription can spend another's share.
14
+ * - The payer's `SubLedger` at `["sub_ledger", payer, mint]` (Sentinel S-01)
15
+ * holds the running total of the Active shares in that mint. It is created
16
+ * on first use by `create_subscription` (payer-funded, 82 bytes) and is
17
+ * passed to every subscription instruction except close.
18
+ * - `create_subscription` records `amount × min(charges left, 12)` as the new
19
+ * subscription's `allowanceLeft`, adds it to the ledger and SETS the SPL
20
+ * approval to the new ledger total (not "current + window"), so an outside
21
+ * revoke / approve or a re-created ATA can never leave a share unbacked
22
+ * while another subscription spends it. An unlimited (or > 12-charge)
23
+ * subscription needs a top-up after 12 charges:
24
+ * {@link buildTopUpSubscriptionIx} (raises the share and the ledger, then
25
+ * re-approves the ledger total; a plain SPL `Approve` alone does not extend
26
+ * a subscription).
27
+ * - Any cancel (payer or payee) removes the subscription's `allowanceLeft`
28
+ * from the ledger. A payer cancel with `giveBack` also re-approves
29
+ * `min(current approval, remaining ledger total)` (Revoke at 0).
30
+ * - `charge_subscription` is a permissionless crank with NO arguments: it
31
+ * pulls exactly `amount` once `now >= next_due_at` (fee to the treasury as
32
+ * `pay_invoice`), then moves `next_due_at` to the next slot of the
33
+ * creation-anchored schedule after `now` ({@link subNextDueAt}).
34
+ * - SPL Token and Token-2022 only; native XNT is not pullable (use invoices).
35
+ * Token-2022 mints must carry only {@link SUB_ALLOWED_MINT_EXTENSIONS}.
36
+ *
37
+ * Routed through the program's `fallback` (`extra_ix`) like the rest of Pay:
38
+ * `sha256("global:<name>")[..8]` + raw Borsh, accounts in exactly the order of
39
+ * the program's `Accounts` structs. Hand-rolled, no web3.js.
40
+ */
41
+ import type { AddressLike, BuiltInstruction } from "./delegate.js";
42
+ import type { RpcFn } from "./accounts.js";
43
+ import type { PdaFinder } from "./namespacePricing.js";
44
+ import type { InvoiceHandleBinding } from "./pay.js";
45
+ export declare const SUBSCRIPTION_SEED = "sub";
46
+ export declare const SUB_DELEGATE_SEED = "sub_delegate";
47
+ /** The payer's per-mint ledger: `["sub_ledger", payer, mint]`. */
48
+ export declare const SUB_LEDGER_SEED = "sub_ledger";
49
+ /** Allocated size of a `SubLedger` (8-byte discriminator + 74). */
50
+ export declare const SUB_LEDGER_ACCOUNT_LEN: number;
51
+ /** Current `SubLedger.version`. */
52
+ export declare const SUB_LEDGER_VERSION = 1;
53
+ /** Length of a subscription id (`[u8; 16]`). */
54
+ export declare const SUBSCRIPTION_ID_LEN = 16;
55
+ /** Allocated size of a `Subscription` (8-byte discriminator + `INIT_SPACE`;
56
+ * 238 since layout v2 added `allowance_left`). */
57
+ export declare const SUBSCRIPTION_ACCOUNT_LEN: number;
58
+ /** Current `Subscription.version`: 2 added `allowance_left`; 3 (same bytes)
59
+ * marks a subscription counted in its payer's `SubLedger`. A v2 account is
60
+ * refused by `charge_subscription` until a payer top-up adopts it. */
61
+ export declare const SUBSCRIPTION_VERSION = 3;
62
+ /** Shortest / longest billing period, seconds (1 hour / 5 × 366 days). */
63
+ export declare const SUB_PERIOD_MIN_SECS = 3600n;
64
+ export declare const SUB_PERIOD_MAX_SECS: bigint;
65
+ /** Charges' worth of allowance `create_subscription` approves (and records
66
+ * as the subscription's `allowanceLeft`) at most. */
67
+ export declare const SUB_APPROVE_WINDOW_CHARGES = 12n;
68
+ /** Token-2022 mint extension types a subscription mint may carry. */
69
+ export declare const SUB_ALLOWED_MINT_EXTENSIONS: readonly number[];
70
+ /** Byte offsets inside a raw `Subscription`, for `getProgramAccounts`
71
+ * `memcmp` filters. Fields before the variable-width `handle` are fixed. */
72
+ export declare const SUBSCRIPTION_OFFSETS: {
73
+ readonly version: 8;
74
+ readonly payer: 9;
75
+ readonly payee: 41;
76
+ readonly id: 73;
77
+ readonly mint: 89;
78
+ readonly decimals: 121;
79
+ readonly amount: 122;
80
+ readonly periodSecs: 130;
81
+ readonly nextDueAt: 138;
82
+ readonly maxCharges: 146;
83
+ readonly chargesMade: 150;
84
+ readonly status: 154;
85
+ readonly createdAt: 155;
86
+ readonly lastChargedAt: 163;
87
+ readonly handle: 171;
88
+ };
89
+ /** `sha256("global:create_subscription")[..8]`. */
90
+ export declare const CREATE_SUBSCRIPTION_DISCRIMINATOR: Uint8Array;
91
+ /** `sha256("global:charge_subscription")[..8]`. */
92
+ export declare const CHARGE_SUBSCRIPTION_DISCRIMINATOR: Uint8Array;
93
+ /** `sha256("global:cancel_subscription")[..8]`. */
94
+ export declare const CANCEL_SUBSCRIPTION_DISCRIMINATOR: Uint8Array;
95
+ /** `sha256("global:close_subscription")[..8]`. */
96
+ export declare const CLOSE_SUBSCRIPTION_DISCRIMINATOR: Uint8Array;
97
+ /** `sha256("global:top_up_subscription")[..8]`. */
98
+ export declare const TOP_UP_SUBSCRIPTION_DISCRIMINATOR: Uint8Array;
99
+ /** `sha256("account:Subscription")[..8]`. */
100
+ export declare const SUBSCRIPTION_ACCOUNT_DISCRIMINATOR: Uint8Array;
101
+ /** `sha256("account:SubLedger")[..8]`. */
102
+ export declare const SUB_LEDGER_ACCOUNT_DISCRIMINATOR: Uint8Array;
103
+ /** Byte offsets inside a raw `SubLedger` (fixed layout). */
104
+ export declare const SUB_LEDGER_OFFSETS: {
105
+ readonly version: 8;
106
+ readonly payer: 9;
107
+ readonly mint: 41;
108
+ readonly total: 73;
109
+ readonly bump: 81;
110
+ };
111
+ /** Program error codes added by Pay phase 2 (`RegistryError`, 6138-6150),
112
+ * plus the upgrade-5 Sentinel block at 6230-6235 (run-011 and the S-01
113
+ * ledger; 6158-6229 belong to upgrade 6). Subscriptions also reuse the Pay
114
+ * phase 1 codes for the fee config (6122), the `@name` binding (6126-6128)
115
+ * and the mint/payee/treasury accounts (6131-6133); see `PAY_ERRORS`. */
116
+ export declare const SUBSCRIPTION_ERRORS: {
117
+ readonly SubscriptionAmountZero: 6138;
118
+ readonly SubscriptionPeriodOutOfRange: 6139;
119
+ readonly SubscriptionStartOutOfRange: 6140;
120
+ readonly SubscriptionMintNotSupported: 6141;
121
+ readonly SubscriptionPayerIsPayee: 6142;
122
+ readonly SubscriptionDelegateInUse: 6143;
123
+ readonly SubscriptionNotActive: 6144;
124
+ readonly SubscriptionNotDue: 6145;
125
+ readonly SubscriptionFinished: 6146;
126
+ readonly SubscriptionAllowanceExhausted: 6147;
127
+ readonly SubscriptionTokenAccountMismatch: 6148;
128
+ readonly NotSubscriptionParty: 6149;
129
+ readonly SubscriptionStillActive: 6150;
130
+ /** `payee` = the payer's own `["sub_delegate", payer]` PDA. */
131
+ readonly SubscriptionPayeeIsDelegate: 6230;
132
+ /** `top_up_subscription` above `amount × charges left`. */
133
+ readonly SubscriptionTopUpTooLarge: 6233;
134
+ /** Cancel without the `SubLedger` (a ledger-counted subscription or a
135
+ * give-back), or a charge of a legacy v2 subscription not yet adopted. */
136
+ readonly SubscriptionLedgerRequired: 6234;
137
+ /** The ledger total would overflow u64 (or fall below a share). */
138
+ readonly SubscriptionLedgerOutOfRange: 6235;
139
+ };
140
+ /** `Subscription.status` as stored (Borsh enum index). */
141
+ export declare const SUBSCRIPTION_STATUS: {
142
+ readonly Active: 0;
143
+ readonly Cancelled: 1;
144
+ };
145
+ export type SubscriptionStatus = "active" | "cancelled";
146
+ /** The next due time after a charge at `now >= nextDueAt`: the first slot of
147
+ * the creation-anchored schedule strictly after `now` (the program's
148
+ * `sub_next_due_at`). One charge per period; missed periods are forfeited. */
149
+ export declare function subNextDueAt(nextDueAt: bigint, periodSecs: bigint, now: bigint | number): bigint;
150
+ /** `amount × min(charges left, 12)` (unlimited = the full window),
151
+ * saturating at u64::MAX: what `create_subscription` adds to the shared
152
+ * approval and sets as the subscription's `allowanceLeft`. (A payer-signed
153
+ * `cancel_subscription` gives back the stored `allowanceLeft`, not this.) */
154
+ export declare function subWindowAllowance(amount: bigint, maxCharges: number, chargesMade?: number): bigint;
155
+ /** Whether a raw mint account (owned by `owner`) may back a subscription:
156
+ * any classic SPL mint; a Token-2022 mint only with extensions in
157
+ * {@link SUB_ALLOWED_MINT_EXTENSIONS} (the program's
158
+ * `sub_mint_extensions_allowed`). */
159
+ export declare function isSubscriptionMintSupported(data: Uint8Array, owner: string): boolean;
160
+ /** 16 fresh random bytes for a new subscription id (CSPRNG). */
161
+ export declare function newSubscriptionId(): Uint8Array;
162
+ /** A subscription: `["sub", payer, payee, id]`. */
163
+ export declare function findSubscriptionPda(find: PdaFinder, programId: AddressLike, payer: AddressLike, payee: AddressLike, id: Uint8Array): Promise<string>;
164
+ /** The payer's SPL delegate for every subscription: `["sub_delegate", payer]`. */
165
+ export declare function findSubDelegatePda(find: PdaFinder, programId: AddressLike, payer: AddressLike): Promise<string>;
166
+ /** The payer's ledger of Active subscription shares in one mint:
167
+ * `["sub_ledger", payer, mint]`. */
168
+ export declare function findSubLedgerPda(find: PdaFinder, programId: AddressLike, payer: AddressLike, mint: AddressLike): Promise<string>;
169
+ /** Decoded `Subscription`. Addresses are base58. */
170
+ export interface Subscription {
171
+ readonly version: number;
172
+ readonly payer: string;
173
+ readonly payee: string;
174
+ readonly id: Uint8Array;
175
+ readonly mint: string;
176
+ readonly decimals: number;
177
+ readonly amount: bigint;
178
+ readonly periodSecs: bigint;
179
+ readonly nextDueAt: bigint;
180
+ /** 0 = unlimited. */
181
+ readonly maxCharges: number;
182
+ readonly chargesMade: number;
183
+ readonly status: SubscriptionStatus;
184
+ readonly createdAt: bigint;
185
+ /** 0n before the first charge. */
186
+ readonly lastChargedAt: bigint;
187
+ /** The bound `Handle` account, or null. */
188
+ readonly handle: string | null;
189
+ readonly memoHash: Uint8Array;
190
+ readonly bump: number;
191
+ readonly delegateBump: number;
192
+ /** This subscription's own unused share of the shared approval (layout
193
+ * v2). Each charge needs and spends `amount` of it; 0n for a v1 account. */
194
+ readonly allowanceLeft: bigint;
195
+ }
196
+ /**
197
+ * Decode a raw `Subscription` (discriminator included) in the Borsh order of
198
+ * state.rs: version u8 | payer | payee | id [u8;16] | mint | decimals u8 |
199
+ * amount u64 | period_secs i64 | next_due_at i64 | max_charges u32 |
200
+ * charges_made u32 | status u8 | created_at i64 | last_charged_at i64 |
201
+ * handle Option<Pubkey> | memo_hash [u8;32] | bump u8 | delegate_bump u8 |
202
+ * allowance_left u64 (version 2; a version-1 account decodes with
203
+ * `allowanceLeft = 0n`). Null when the bytes are not a `Subscription`.
204
+ */
205
+ export declare function decodeSubscription(data: Uint8Array): Subscription | null;
206
+ /** Borsh-encode a {@link Subscription} exactly as the program stores it (the
207
+ * inverse of {@link decodeSubscription}, zero-padded to the allocation). */
208
+ export declare function encodeSubscription(s: Subscription): Uint8Array;
209
+ /** Decoded `SubLedger`. Addresses are base58. */
210
+ export interface SubLedger {
211
+ readonly version: number;
212
+ readonly payer: string;
213
+ readonly mint: string;
214
+ /** Σ `allowanceLeft` of the payer's Active subscriptions in `mint`; the
215
+ * SPL approval the program sets on every create / top-up. */
216
+ readonly total: bigint;
217
+ readonly bump: number;
218
+ }
219
+ /** Decode a raw `SubLedger` (discriminator included): version u8 | payer |
220
+ * mint | total u64 | bump u8. Null when the bytes are not a `SubLedger`. */
221
+ export declare function decodeSubLedger(data: Uint8Array): SubLedger | null;
222
+ /** Borsh-encode a {@link SubLedger} exactly as the program stores it. */
223
+ export declare function encodeSubLedger(l: SubLedger): Uint8Array;
224
+ /** Read and decode a payer's `SubLedger`. Null when it does not exist yet
225
+ * (no subscription in that mint so far); throws when it exists but is not
226
+ * one (or, with `programId`, is not owned by it). */
227
+ export declare function fetchSubLedger(rpc: RpcFn, address: AddressLike, opts?: {
228
+ readonly programId?: AddressLike;
229
+ readonly commitment?: string;
230
+ }): Promise<{
231
+ readonly address: string;
232
+ readonly ledger: SubLedger;
233
+ readonly lamports: bigint;
234
+ } | null>;
235
+ /** Whether every allowed charge has been made (`maxCharges > 0`). */
236
+ export declare function isSubscriptionFinished(s: Pick<Subscription, "maxCharges" | "chargesMade">): boolean;
237
+ /** Whether `charge_subscription` would pass its status/schedule checks at
238
+ * `nowSecs` (Active, charges left, `now >= nextDueAt`). The allowance,
239
+ * balance, binding and lockdown are checked on chain. */
240
+ export declare function isSubscriptionDue(s: Pick<Subscription, "status" | "maxCharges" | "chargesMade" | "nextDueAt">, nowSecs: bigint | number): boolean;
241
+ /** Read and decode a Subscription. Null when it does not exist; throws when
242
+ * it exists but is not one (or, with `programId`, is not owned by it). */
243
+ export declare function fetchSubscription(rpc: RpcFn, address: AddressLike, opts?: {
244
+ readonly programId?: AddressLike;
245
+ readonly commitment?: string;
246
+ }): Promise<{
247
+ readonly address: string;
248
+ readonly subscription: Subscription;
249
+ readonly lamports: bigint;
250
+ } | null>;
251
+ export interface CreateSubscriptionParams {
252
+ readonly programId: AddressLike;
253
+ /** Signer; opts in, pays the rent and owns `payerTokenAccount`. */
254
+ readonly payer: AddressLike;
255
+ readonly payee: AddressLike;
256
+ /** `["config"]`. */
257
+ readonly config: AddressLike;
258
+ /** {@link findSubscriptionPda}(payer, payee, id). */
259
+ readonly subscription: AddressLike;
260
+ /** {@link findSubDelegatePda}(payer). */
261
+ readonly subDelegate: AddressLike;
262
+ /** {@link findSubLedgerPda}(payer, mint); created by this instruction on
263
+ * the payer's first subscription in the mint (payer-funded). */
264
+ readonly subLedger: AddressLike;
265
+ /** 16 bytes ({@link newSubscriptionId}). */
266
+ readonly id: Uint8Array;
267
+ /** SPL Token or Token-2022 mint. */
268
+ readonly mint: AddressLike;
269
+ /** The payer's canonical ATA for `mint` (must have no other delegate). */
270
+ readonly payerTokenAccount: AddressLike;
271
+ /** The mint's owner. */
272
+ readonly tokenProgram: AddressLike;
273
+ /** Base units per charge, > 0. */
274
+ readonly amount: bigint;
275
+ /** Seconds, {@link SUB_PERIOD_MIN_SECS}..={@link SUB_PERIOD_MAX_SECS}. */
276
+ readonly periodSecs: bigint;
277
+ /** Unix seconds of the first charge; 0n / omitted = now. */
278
+ readonly firstDueAt?: bigint;
279
+ /** Total charges; 0 / omitted = unlimited. */
280
+ readonly maxCharges?: number;
281
+ /** 32 bytes (`invoiceMemoHash` of the plan text); default zeros. */
282
+ readonly memoHash?: Uint8Array;
283
+ /** Bind to the payee's `@name` (every charge re-checks it). */
284
+ readonly bindHandle?: InvoiceHandleBinding;
285
+ }
286
+ /** The Borsh arguments of `create_subscription` (after the discriminator). */
287
+ export declare function encodeCreateSubscriptionArgs(a: {
288
+ readonly id: Uint8Array;
289
+ readonly mint: AddressLike;
290
+ readonly amount: bigint;
291
+ readonly periodSecs: bigint;
292
+ readonly firstDueAt: bigint;
293
+ readonly maxCharges: number;
294
+ readonly memoHash: Uint8Array;
295
+ readonly bindHandle: boolean;
296
+ }): Uint8Array;
297
+ /**
298
+ * `create_subscription(id, mint, amount, period_secs, first_due_at,
299
+ * max_charges, memo_hash, bind_handle)`. Accounts (`CreateSubscription`):
300
+ * payer(s,w), payee, config, subscription(w), sub_delegate, sub_ledger(w),
301
+ * mint, payer_token_account(w), token_program, system_program, then the
302
+ * optional handle, payee_record and the binding's remaining accounts.
303
+ *
304
+ * The program records {@link subWindowAllowance} as the subscription's own
305
+ * `allowanceLeft`, adds it to the payer's ledger and approves `subDelegate`
306
+ * on `payerTokenAccount` for EXACTLY the new ledger total (the sum of every
307
+ * Active share in the mint), so the wallet shows that delegate approval.
308
+ * Fails with `SubscriptionDelegateInUse` (6143) if the ATA has another app's
309
+ * delegate; prepend an SPL `Revoke` if the payer agrees. Refuses `payee` =
310
+ * `subDelegate` (6230: funds sent there could never move).
311
+ */
312
+ export declare function buildCreateSubscriptionIx(p: CreateSubscriptionParams): BuiltInstruction;
313
+ export interface ChargeSubscriptionParams {
314
+ readonly programId: AddressLike;
315
+ /** Any signer (pays the tx fee and, once per mint, the treasury ATA rent). */
316
+ readonly cranker: AddressLike;
317
+ readonly subscription: AddressLike;
318
+ /** `["config"]`. */
319
+ readonly config: AddressLike;
320
+ /** `Config.treasury`. */
321
+ readonly treasury: AddressLike;
322
+ /** `["pay_config"]`, initialized or not. */
323
+ readonly payConfig: AddressLike;
324
+ /** {@link findSubDelegatePda}(Subscription.payer). */
325
+ readonly subDelegate: AddressLike;
326
+ /** {@link findSubLedgerPda}(Subscription.payer, Subscription.mint). */
327
+ readonly subLedger: AddressLike;
328
+ /** `Subscription.mint`. */
329
+ readonly mint: AddressLike;
330
+ /** The payer's canonical ATA. */
331
+ readonly payerTokenAccount: AddressLike;
332
+ /** The payee's canonical ATA (must exist). */
333
+ readonly payeeTokenAccount: AddressLike;
334
+ /** The treasury's canonical ATA (created by the program if a fee is due). */
335
+ readonly treasuryTokenAccount: AddressLike;
336
+ readonly tokenProgram: AddressLike;
337
+ /** Required for a handle-bound subscription (`Subscription.handle`). */
338
+ readonly binding?: InvoiceHandleBinding;
339
+ }
340
+ /**
341
+ * `charge_subscription()`: no arguments; the program reads every term from
342
+ * the Subscription. Accounts (`ChargeSubscription`): cranker(s,w),
343
+ * subscription(w), config, treasury, pay_config, sub_delegate,
344
+ * sub_ledger(w), mint, payer_token_account(w), payee_token_account(w),
345
+ * treasury_token_account(w), token_program, associated_token_program,
346
+ * system_program, then the optional handle, payee_record and the binding's
347
+ * remaining accounts. After an outside revoke of the payer's approval every
348
+ * charge fails with 6147 until the payer's next create / top-up.
349
+ */
350
+ export declare function buildChargeSubscriptionIx(p: ChargeSubscriptionParams): BuiltInstruction;
351
+ export interface CancelSubscriptionParams {
352
+ readonly programId: AddressLike;
353
+ /** The payer or the payee. */
354
+ readonly signer: AddressLike;
355
+ readonly subscription: AddressLike;
356
+ /** {@link findSubLedgerPda}(Subscription.payer, Subscription.mint).
357
+ * Required (the cancel removes the share from it); `null` only for a
358
+ * legacy version-2 subscription cancelled without `giveBack`. */
359
+ readonly subLedger: AddressLike | null;
360
+ /** Payer only: also shrink the SPL approval to `min(current, ledger total
361
+ * after this cancel)` (Revoke at 0). */
362
+ readonly giveBack?: {
363
+ readonly payerTokenAccount: AddressLike;
364
+ readonly subDelegate: AddressLike;
365
+ readonly tokenProgram: AddressLike;
366
+ };
367
+ }
368
+ /** `cancel_subscription()`. Accounts (`CancelSubscription`): signer(s),
369
+ * subscription(w), sub_ledger(w) (the program id as "None" when `null`),
370
+ * then the optional payer_token_account(w), sub_delegate, token_program
371
+ * (used only when the payer signs). */
372
+ export declare function buildCancelSubscriptionIx(p: CancelSubscriptionParams): BuiltInstruction;
373
+ export interface CloseSubscriptionParams {
374
+ readonly programId: AddressLike;
375
+ /** The payer or the payee. */
376
+ readonly signer: AddressLike;
377
+ readonly subscription: AddressLike;
378
+ /** `Subscription.payer`: receives the rent. */
379
+ readonly payer: AddressLike;
380
+ }
381
+ /** `close_subscription()`. Accounts (`CloseSubscription`): signer(s),
382
+ * subscription(w), payer(w). Only once Cancelled or finished. */
383
+ export declare function buildCloseSubscriptionIx(p: CloseSubscriptionParams): BuiltInstruction;
384
+ export interface TopUpSubscriptionParams {
385
+ readonly programId: AddressLike;
386
+ /** Signer: `Subscription.payer` (pays the fee, and the ledger rent if a
387
+ * legacy subscription has none yet; X1ID pays nothing). */
388
+ readonly payer: AddressLike;
389
+ readonly subscription: AddressLike;
390
+ /** `["config"]`. */
391
+ readonly config: AddressLike;
392
+ /** {@link findSubDelegatePda}(payer). */
393
+ readonly subDelegate: AddressLike;
394
+ /** {@link findSubLedgerPda}(payer, Subscription.mint). */
395
+ readonly subLedger: AddressLike;
396
+ /** The payer's canonical ATA for `Subscription.mint`. */
397
+ readonly payerTokenAccount: AddressLike;
398
+ /** The mint's token program. */
399
+ readonly tokenProgram: AddressLike;
400
+ /** Base units to ADD to `allowanceLeft` and the ledger total, > 0. For a
401
+ * bounded subscription the new `allowanceLeft` may not exceed `amount ×
402
+ * (maxCharges - chargesMade)` (6233). E.g. `amount × 12n` for another
403
+ * 12-charge window of an unlimited subscription. */
404
+ readonly amount: bigint;
405
+ }
406
+ /**
407
+ * `top_up_subscription(amount)`: raise ONE subscription's `allowanceLeft`
408
+ * and the payer's ledger total by `amount`, then approve the payer's
409
+ * delegate PDA for EXACTLY the new ledger total (also restoring the pool
410
+ * after an outside revoke). Accounts (`TopUpSubscription`): payer(s,w),
411
+ * subscription(w), config, sub_delegate, sub_ledger(w),
412
+ * payer_token_account(w), token_program, system_program. Payer only; Active
413
+ * and not finished; refused during lockdown and when the ATA has another
414
+ * app's delegate (6143).
415
+ */
416
+ export declare function buildTopUpSubscriptionIx(p: TopUpSubscriptionParams): BuiltInstruction;
417
+ export interface SubscriptionAllowanceParams {
418
+ /** The mint's token program (SPL Token or Token-2022). */
419
+ readonly tokenProgram: AddressLike;
420
+ /** The payer's canonical ATA. */
421
+ readonly payerTokenAccount: AddressLike;
422
+ /** {@link findSubDelegatePda}(payer). */
423
+ readonly subDelegate: AddressLike;
424
+ /** Signer: the payer (the ATA's owner). */
425
+ readonly payer: AddressLike;
426
+ /** The NEW total allowance (an SPL Approve sets, it does not add): e.g.
427
+ * the payer's `SubLedger.total` ({@link fetchSubLedger}). */
428
+ readonly allowance: bigint;
429
+ }
430
+ /** A plain SPL `Approve` (instruction 4, same bytes under both token
431
+ * programs) of the payer's delegate PDA: a precise re-approve, e.g. to cut
432
+ * the surplus a payee-cancelled subscription left back to the ledger total.
433
+ * It does NOT extend a subscription (each charge also needs the
434
+ * subscription's own `allowanceLeft`); use {@link buildTopUpSubscriptionIx}
435
+ * for that (it also re-approves the ledger total). */
436
+ export declare function buildSubscriptionAllowanceIx(p: SubscriptionAllowanceParams): BuiltInstruction;
437
+ /** Plain-language sentence for a subscription error code (6138-6150,
438
+ * 6230, 6233-6235), or null (see `payErrorMessage` for the shared Pay codes). */
439
+ export declare function subscriptionErrorMessage(code: number): string | null;