@x1id/resolve 0.23.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 (49) 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 +13 -0
  20. package/dist/index.js +32 -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/nsGate.d.ts +98 -0
  28. package/dist/nsGate.js +172 -0
  29. package/dist/oidc.d.ts +272 -0
  30. package/dist/oidc.js +641 -0
  31. package/dist/pay.d.ts +513 -0
  32. package/dist/pay.js +756 -0
  33. package/dist/payment.d.ts +9 -2
  34. package/dist/payment.js +9 -2
  35. package/dist/recovery.d.ts +186 -0
  36. package/dist/recovery.js +276 -0
  37. package/dist/recoveryNft.d.ts +183 -0
  38. package/dist/recoveryNft.js +291 -0
  39. package/dist/shield.d.ts +373 -0
  40. package/dist/shield.js +695 -0
  41. package/dist/subscription.d.ts +439 -0
  42. package/dist/subscription.js +642 -0
  43. package/dist/textRecords.d.ts +52 -6
  44. package/dist/textRecords.js +80 -8
  45. package/dist/types.d.ts +3 -0
  46. package/dist/x402Receipt.d.ts +246 -0
  47. package/dist/x402Receipt.js +374 -0
  48. package/package.json +18 -1
  49. package/schema/agent-manifest.json +91 -8
package/dist/pay.d.ts ADDED
@@ -0,0 +1,513 @@
1
+ /**
2
+ * X1ID Pay, phase 1: on-chain invoices (docs/specs/x1id-pay-onchain.md).
3
+ *
4
+ * The registry program (`x1-handles`) holds three Pay accounts:
5
+ *
6
+ * - `PayConfig` at `["pay_config"]`: the protocol fee (`fee_bps`, hard cap
7
+ * {@link PAY_FEE_BPS_MAX}). While it does not exist the fee is 0.
8
+ * - `Invoice` at `["invoice", payee, id]`: one payment request. Its own
9
+ * address is the Solana Pay reference, so `getSignaturesForAddress(invoice)`
10
+ * finds the payment.
11
+ * - `MerchantAuthority` at `["merchant", payee, delegate]`: lets a merchant's
12
+ * server key create and cancel invoices that always pay the merchant.
13
+ *
14
+ * Every Pay instruction is routed through the program's `fallback`
15
+ * (`extra_ix`), so none of them is in the generated IDL. They are encoded
16
+ * here by hand, like `set_namespace_pricing` in `namespacePricing.ts`:
17
+ * `sha256("global:<name>")[..8]` followed by raw Borsh arguments, with
18
+ * accounts in EXACTLY the order of the program's `Accounts` structs.
19
+ *
20
+ * Optional accounts follow Anchor's convention: a skipped optional slot that
21
+ * precedes a used one is the program id ("None"); trailing unused slots are
22
+ * simply left off.
23
+ *
24
+ * Hand-rolled like the rest of this package: no Anchor client, no
25
+ * `@solana/web3.js`. PDAs come through an injected {@link PdaFinder}.
26
+ */
27
+ import type { AddressLike, BuiltInstruction } from "./delegate.js";
28
+ import { type RpcFn } from "./accounts.js";
29
+ import type { PdaFinder } from "./namespacePricing.js";
30
+ /** Hard cap on the Pay protocol fee in basis points (1%). */
31
+ export declare const PAY_FEE_BPS_MAX = 100;
32
+ /** The X1 record slot a name's payment address is read from. */
33
+ export declare const PAY_X1_COIN_TYPE = 5010000;
34
+ /** `Invoice.mint` for native XNT (`Pubkey::default()`). */
35
+ export declare const INVOICE_NATIVE_MINT = "11111111111111111111111111111111";
36
+ /** Length of an invoice id (`[u8; 16]`). */
37
+ export declare const INVOICE_ID_LEN = 16;
38
+ export declare const PAY_CONFIG_SEED = "pay_config";
39
+ export declare const INVOICE_SEED = "invoice";
40
+ export declare const MERCHANT_AUTHORITY_SEED = "merchant";
41
+ /** Allocated size of each account (8-byte discriminator + `INIT_SPACE`). */
42
+ export declare const PAY_CONFIG_ACCOUNT_LEN: number;
43
+ export declare const INVOICE_ACCOUNT_LEN: number;
44
+ export declare const MERCHANT_AUTHORITY_ACCOUNT_LEN: number;
45
+ /** Byte offsets inside a raw `Invoice` account, for `getProgramAccounts`
46
+ * `memcmp` filters. Only fields before the variable-width `handle` are fixed. */
47
+ export declare const INVOICE_OFFSETS: {
48
+ readonly version: 8;
49
+ readonly payee: 9;
50
+ readonly creator: 41;
51
+ readonly id: 73;
52
+ readonly mint: 89;
53
+ readonly amount: 121;
54
+ readonly expiresAt: 129;
55
+ readonly status: 137;
56
+ readonly paidBy: 138;
57
+ readonly paidAt: 170;
58
+ readonly handle: 178;
59
+ };
60
+ /** `sha256("global:set_pay_config")[..8]`. */
61
+ export declare const SET_PAY_CONFIG_DISCRIMINATOR: Uint8Array;
62
+ /** `sha256("global:create_invoice")[..8]`. */
63
+ export declare const CREATE_INVOICE_DISCRIMINATOR: Uint8Array;
64
+ /** `sha256("global:pay_invoice")[..8]`. */
65
+ export declare const PAY_INVOICE_DISCRIMINATOR: Uint8Array;
66
+ /** `sha256("global:cancel_invoice")[..8]`. */
67
+ export declare const CANCEL_INVOICE_DISCRIMINATOR: Uint8Array;
68
+ /** `sha256("global:close_invoice")[..8]`. */
69
+ export declare const CLOSE_INVOICE_DISCRIMINATOR: Uint8Array;
70
+ /** `sha256("global:create_merchant_authority")[..8]`. */
71
+ export declare const CREATE_MERCHANT_AUTHORITY_DISCRIMINATOR: Uint8Array;
72
+ /** `sha256("global:revoke_merchant_authority")[..8]`. */
73
+ export declare const REVOKE_MERCHANT_AUTHORITY_DISCRIMINATOR: Uint8Array;
74
+ /** `sha256("account:Invoice")[..8]`. */
75
+ export declare const INVOICE_ACCOUNT_DISCRIMINATOR: Uint8Array;
76
+ /** `sha256("account:PayConfig")[..8]`. */
77
+ export declare const PAY_CONFIG_ACCOUNT_DISCRIMINATOR: Uint8Array;
78
+ /** `sha256("account:MerchantAuthority")[..8]`. */
79
+ export declare const MERCHANT_AUTHORITY_ACCOUNT_DISCRIMINATOR: Uint8Array;
80
+ /** Program error codes added by Pay phase 1 (`RegistryError`, 6121-6135),
81
+ * plus `InvoiceTermsChanged` (6136, Sentinel run-007): `pay_invoice`'s
82
+ * pinned `expected_amount`/`expected_mint` no longer match the invoice. */
83
+ export declare const PAY_ERRORS: {
84
+ readonly PayFeeAboveMax: 6121;
85
+ readonly PayConfigMismatch: 6122;
86
+ readonly InvoiceAmountZero: 6123;
87
+ readonly InvoiceExpiryInPast: 6124;
88
+ readonly NotMerchantDelegate: 6125;
89
+ readonly PayeeNotNamePaymentAddress: 6126;
90
+ readonly PayeeNoLongerHoldsName: 6127;
91
+ readonly InvoiceHandleMismatch: 6128;
92
+ readonly InvoiceNotOpen: 6129;
93
+ readonly InvoiceExpired: 6130;
94
+ readonly InvoiceMintMismatch: 6131;
95
+ readonly InvoicePayeeMismatch: 6132;
96
+ readonly InvoiceTreasuryMismatch: 6133;
97
+ readonly NotInvoiceCloser: 6134;
98
+ readonly InvoiceStillOpen: 6135;
99
+ readonly InvoiceTermsChanged: 6136;
100
+ };
101
+ /** Anchor's `InstructionFallbackNotFound`: the deployed program predates Pay. */
102
+ export declare const PAY_NOT_DEPLOYED_ERROR = 101;
103
+ /** `Invoice.status` as stored (Borsh enum index). */
104
+ export declare const INVOICE_STATUS: {
105
+ readonly Open: 0;
106
+ readonly Paid: 1;
107
+ readonly Cancelled: 2;
108
+ };
109
+ export type InvoiceStatus = "open" | "paid" | "cancelled";
110
+ /** The fee `pay_invoice` takes from `amount` at `feeBps`: `amount * feeBps /
111
+ * 10_000`, rounded down (the program's u128 `pay_fee`). The payer always pays
112
+ * exactly `amount`; the payee receives `amount - fee`. */
113
+ export declare function payFee(amount: bigint, feeBps: number): bigint;
114
+ /** The split of one payment: what the payee and the treasury receive. */
115
+ export interface PaySplit {
116
+ readonly amount: bigint;
117
+ readonly fee: bigint;
118
+ readonly payeeReceives: bigint;
119
+ }
120
+ /** {@link payFee} as a full split. */
121
+ export declare function paySplit(amount: bigint, feeBps: number): PaySplit;
122
+ /** 16 fresh random bytes for a new invoice id (CSPRNG). */
123
+ export declare function newInvoiceId(): Uint8Array;
124
+ /** Lowercase hex of an invoice id (the form used in links). */
125
+ export declare function invoiceIdToHex(id: Uint8Array): string;
126
+ /** Parse a 32-character hex invoice id; null when malformed. */
127
+ export declare function invoiceIdFromHex(hex: string): Uint8Array | null;
128
+ /** `memo_hash` for an off-chain description: sha256 of its UTF-8 bytes. An
129
+ * empty description hashes to all zeros (no memo). */
130
+ export declare function invoiceMemoHash(text: string): Uint8Array;
131
+ /** The `["pay_config"]` singleton. */
132
+ export declare function findPayConfigPda(find: PdaFinder, programId: AddressLike): Promise<string>;
133
+ /** An invoice: `["invoice", payee, id]`. */
134
+ export declare function findInvoicePda(find: PdaFinder, programId: AddressLike, payee: AddressLike, id: Uint8Array): Promise<string>;
135
+ /** A merchant grant: `["merchant", payee, delegate]`. */
136
+ export declare function findMerchantAuthorityPda(find: PdaFinder, programId: AddressLike, payee: AddressLike, delegate: AddressLike): Promise<string>;
137
+ /** A name's X1 payment record, `["record", handle, PAY_X1_COIN_TYPE]`, the
138
+ * `payee_record` account of a handle-bound invoice (existing or not). */
139
+ export declare function findPayeeX1RecordPda(find: PdaFinder, programId: AddressLike, handle: AddressLike): Promise<string>;
140
+ /** Associated token account of `owner` for `mint` under `tokenProgram`. */
141
+ export declare function findPayTokenAccount(find: PdaFinder, owner: AddressLike, mint: AddressLike, tokenProgram: AddressLike): Promise<string>;
142
+ /** Decoded `PayConfig`. */
143
+ export interface PayConfig {
144
+ readonly version: number;
145
+ readonly bump: number;
146
+ readonly feeBps: number;
147
+ readonly updatedAt: bigint;
148
+ }
149
+ /** Decode a raw `PayConfig` (discriminator included); null if not one. */
150
+ export declare function decodePayConfig(data: Uint8Array): PayConfig | null;
151
+ /** Decoded `MerchantAuthority`. */
152
+ export interface MerchantAuthority {
153
+ readonly version: number;
154
+ readonly payee: string;
155
+ readonly delegate: string;
156
+ readonly createdAt: bigint;
157
+ readonly bump: number;
158
+ }
159
+ /** Decode a raw `MerchantAuthority` (discriminator included); null if not one. */
160
+ export declare function decodeMerchantAuthority(data: Uint8Array): MerchantAuthority | null;
161
+ /** Decoded `Invoice`. Addresses are base58; `mint === INVOICE_NATIVE_MINT`
162
+ * means native XNT. */
163
+ export interface Invoice {
164
+ readonly version: number;
165
+ readonly payee: string;
166
+ readonly creator: string;
167
+ readonly id: Uint8Array;
168
+ /** {@link INVOICE_NATIVE_MINT} for XNT, else the SPL mint. */
169
+ readonly mint: string;
170
+ readonly isNative: boolean;
171
+ readonly amount: bigint;
172
+ /** Unix seconds; 0n = never expires. */
173
+ readonly expiresAt: bigint;
174
+ readonly status: InvoiceStatus;
175
+ /** Set once Paid (the all-ones address before). */
176
+ readonly paidBy: string;
177
+ readonly paidAt: bigint;
178
+ /** The bound `Handle` account, or null. */
179
+ readonly handle: string | null;
180
+ readonly memoHash: Uint8Array;
181
+ readonly rentPayer: string;
182
+ readonly bump: number;
183
+ }
184
+ /**
185
+ * Decode a raw `Invoice` (discriminator included) in the exact Borsh order
186
+ * of state.rs: version u8 | payee | creator | id [u8;16] | mint | amount u64 |
187
+ * expires_at i64 | status u8 | paid_by | paid_at i64 | handle Option<Pubkey>
188
+ * (1 tag byte, +32 when Some) | memo_hash [u8;32] | rent_payer | bump u8.
189
+ * `handle` is variable-width, so the fields after it move by 32 bytes when
190
+ * the invoice is unbound. Null when the bytes are not an `Invoice`.
191
+ */
192
+ export declare function decodeInvoice(data: Uint8Array): Invoice | null;
193
+ /** Borsh-encode an {@link Invoice} exactly as the program stores it (the
194
+ * inverse of {@link decodeInvoice}, padded to the allocated length). Useful
195
+ * for tests, fixtures and mocks. */
196
+ export declare function encodeInvoice(inv: Omit<Invoice, "isNative">): Uint8Array;
197
+ /** "Open" / "Paid" / "Cancelled" / "Expired" (an Open invoice at or after its
198
+ * non-zero `expiresAt`). */
199
+ export type InvoiceStatusLabel = "Open" | "Paid" | "Cancelled" | "Expired";
200
+ /** Whether the invoice is past a non-zero expiry at `nowSecs` (the program's
201
+ * rule: payable while `now < expires_at`). */
202
+ export declare function isInvoiceExpired(invoice: Pick<Invoice, "expiresAt">, nowSecs: bigint | number): boolean;
203
+ /** The status a person should see at `nowSecs`. */
204
+ export declare function invoiceStatusLabel(invoice: Pick<Invoice, "status" | "expiresAt">, nowSecs: bigint | number): InvoiceStatusLabel;
205
+ /** Whether `pay_invoice` would accept the invoice at `nowSecs` (Open and not
206
+ * expired). Chain time can lag the local clock, so treat this as a hint. */
207
+ export declare function isInvoicePayable(invoice: Pick<Invoice, "status" | "expiresAt">, nowSecs: bigint | number): boolean;
208
+ /** An invoice read from chain. */
209
+ export interface FetchedInvoice {
210
+ readonly address: string;
211
+ readonly invoice: Invoice;
212
+ /** The account's lamports (its rent). */
213
+ readonly lamports: bigint;
214
+ }
215
+ /**
216
+ * Read and decode an Invoice account. Null when the account does not exist.
217
+ * Throws when it exists but is not an Invoice, or (with `programId`) is not
218
+ * owned by the registry program.
219
+ */
220
+ export declare function fetchInvoice(rpc: RpcFn, address: AddressLike, opts?: {
221
+ readonly programId?: AddressLike;
222
+ readonly commitment?: string;
223
+ }): Promise<FetchedInvoice | null>;
224
+ /** Read the live fee rate: the `PayConfig`'s `fee_bps` (clamped to the cap),
225
+ * or 0 when the account does not exist, exactly as `pay_invoice` resolves it. */
226
+ export declare function fetchPayFeeBps(rpc: RpcFn, payConfig: AddressLike, programId: AddressLike): Promise<number>;
227
+ /**
228
+ * The extra accounts a handle-bound invoice needs. `handle` and
229
+ * `payeeRecord` fill the two optional slots; the rest go to
230
+ * `remaining_accounts` in the program's order: the payee's pNFT token account
231
+ * first (tokenized names), then the `Namespace` (scoped names).
232
+ */
233
+ export interface InvoiceHandleBinding {
234
+ /** The `Handle` PDA. */
235
+ readonly handle: AddressLike;
236
+ /** {@link findPayeeX1RecordPda}(handle), whether it exists or not. */
237
+ readonly payeeRecord: AddressLike;
238
+ /** Tokenized name: the payee's associated token account for the pNFT mint. */
239
+ readonly pnftTokenAccount?: AddressLike;
240
+ /** Scoped name (`alice.pepe`): the `["namespace", label]` account. */
241
+ readonly namespace?: AddressLike;
242
+ }
243
+ export interface SetPayConfigParams {
244
+ readonly programId: AddressLike;
245
+ /** `Config.admin` (signer, pays rent on first set). */
246
+ readonly admin: AddressLike;
247
+ /** `["config"]`. */
248
+ readonly config: AddressLike;
249
+ /** `["pay_config"]` ({@link findPayConfigPda}). */
250
+ readonly payConfig: AddressLike;
251
+ /** 0..={@link PAY_FEE_BPS_MAX}. */
252
+ readonly feeBps: number;
253
+ }
254
+ /** `set_pay_config(fee_bps)`. Accounts (`SetPayConfig`): admin(s,w), config,
255
+ * pay_config(w), system_program. */
256
+ export declare function buildSetPayConfigIx(p: SetPayConfigParams): BuiltInstruction;
257
+ export interface CreateInvoiceParams {
258
+ readonly programId: AddressLike;
259
+ /** Signer: the payee, or a merchant delegate (then pass `merchantAuthority`). */
260
+ readonly creator: AddressLike;
261
+ /** Signer that funds the account rent (refunded on close). Default: creator. */
262
+ readonly rentPayer?: AddressLike;
263
+ /** Where the funds go. Default: creator. */
264
+ readonly payee?: AddressLike;
265
+ /** `["config"]`. */
266
+ readonly config: AddressLike;
267
+ /** {@link findInvoicePda}(payee, id). */
268
+ readonly invoice: AddressLike;
269
+ /** 16 bytes ({@link newInvoiceId}). */
270
+ readonly id: Uint8Array;
271
+ /** SPL mint; omit (or {@link INVOICE_NATIVE_MINT}) for native XNT. */
272
+ readonly mint?: AddressLike;
273
+ /** Base units, > 0. */
274
+ readonly amount: bigint;
275
+ /** Unix seconds, 0n / omitted = never. */
276
+ readonly expiresAt?: bigint;
277
+ /** 32 bytes ({@link invoiceMemoHash}); default all zeros. */
278
+ readonly memoHash?: Uint8Array;
279
+ /** `["merchant", payee, creator]`: required when creator != payee. */
280
+ readonly merchantAuthority?: AddressLike;
281
+ /** Bind the invoice to the payee's `@name` (`bind_handle = true`). */
282
+ readonly bindHandle?: InvoiceHandleBinding;
283
+ }
284
+ /** The Borsh arguments of `create_invoice` (after the discriminator). */
285
+ export declare function encodeCreateInvoiceArgs(a: {
286
+ readonly id: Uint8Array;
287
+ readonly mint: AddressLike;
288
+ readonly amount: bigint;
289
+ readonly expiresAt: bigint;
290
+ readonly memoHash: Uint8Array;
291
+ readonly bindHandle: boolean;
292
+ }): Uint8Array;
293
+ /**
294
+ * `create_invoice(id, mint, amount, expires_at, memo_hash, bind_handle)`.
295
+ * Accounts (`CreateInvoice`): creator(s), rent_payer(s,w), payee, config,
296
+ * invoice(w), system_program, then the optionals merchant_authority, handle,
297
+ * payee_record (program id = "None" where a later one is used), then the
298
+ * binding's remaining accounts.
299
+ */
300
+ export declare function buildCreateInvoiceIx(p: CreateInvoiceParams): BuiltInstruction;
301
+ /** The SPL account set of an SPL invoice's payment. */
302
+ export interface PayInvoiceSplAccounts {
303
+ readonly mint: AddressLike;
304
+ /** The payer's token account for the mint (debited). */
305
+ readonly payerTokenAccount: AddressLike;
306
+ /** The payee's canonical ATA (must exist; create it idempotently first). */
307
+ readonly payeeTokenAccount: AddressLike;
308
+ /** `Config.treasury`'s canonical ATA (created by the program if a fee is due). */
309
+ readonly treasuryTokenAccount: AddressLike;
310
+ /** The mint's owner: SPL Token or Token-2022. */
311
+ readonly tokenProgram: AddressLike;
312
+ }
313
+ export interface PayInvoiceParams {
314
+ readonly programId: AddressLike;
315
+ /** Signer; pays exactly the invoice amount. */
316
+ readonly payer: AddressLike;
317
+ readonly invoice: AddressLike;
318
+ /** `Invoice.payee`. */
319
+ readonly payee: AddressLike;
320
+ /** `["config"]`. */
321
+ readonly config: AddressLike;
322
+ /** `Config.treasury`. */
323
+ readonly treasury: AddressLike;
324
+ /** `["pay_config"]`, initialized or not. */
325
+ readonly payConfig: AddressLike;
326
+ /** REQUIRED: the `Invoice.amount` (base units) the payer reviewed. The
327
+ * program refuses the payment (`InvoiceTermsChanged`, 6136) if the invoice
328
+ * holds any other amount when the transaction executes. Pass the amount
329
+ * you DISPLAYED, never a value re-read after the user confirmed. */
330
+ readonly expectedAmount: bigint;
331
+ /** REQUIRED: the `Invoice.mint` the payer reviewed
332
+ * ({@link INVOICE_NATIVE_MINT} for native XNT). Same rule as
333
+ * `expectedAmount`. */
334
+ readonly expectedMint: AddressLike;
335
+ /** Required for a handle-bound invoice (`Invoice.handle`). */
336
+ readonly binding?: InvoiceHandleBinding;
337
+ /** Required for an SPL invoice. */
338
+ readonly spl?: PayInvoiceSplAccounts;
339
+ }
340
+ /** The Borsh arguments of `pay_invoice` (after the discriminator):
341
+ * `expected_amount: u64`, `expected_mint: Pubkey`. */
342
+ export declare function encodePayInvoiceArgs(a: {
343
+ readonly expectedAmount: bigint;
344
+ readonly expectedMint: AddressLike;
345
+ }): Uint8Array;
346
+ /**
347
+ * `pay_invoice(expected_amount, expected_mint)`. The two arguments pin the
348
+ * terms the payer reviewed: an Open invoice's PDA can be re-initialised with
349
+ * new terms (cancel + close + create of the same id, in one transaction) after
350
+ * the payer signed, and the program then refuses with `InvoiceTermsChanged`
351
+ * instead of charging the new amount (Sentinel x1p-007-01). A
352
+ * discriminator-only payload (SDK < 0.26) fails `InstructionDidNotDeserialize`.
353
+ *
354
+ * Accounts (`PayInvoice`): payer(s,w), invoice(w), payee(w),
355
+ * config, treasury(w), pay_config, system_program, then eight optionals:
356
+ * handle, payee_record, mint, payer_token_account(w), payee_token_account(w),
357
+ * treasury_token_account(w), token_program, associated_token_program; then
358
+ * the binding's remaining accounts. Remaining accounts start after ALL eight
359
+ * optional slots, so a native payment with a binding proof fills the six SPL
360
+ * slots with the "None" placeholder.
361
+ */
362
+ export declare function buildPayInvoiceIx(p: PayInvoiceParams): BuiltInstruction;
363
+ export interface CancelInvoiceParams {
364
+ readonly programId: AddressLike;
365
+ /** The payee, or the invoice's creator (a delegate: pass `merchantAuthority`). */
366
+ readonly signer: AddressLike;
367
+ readonly invoice: AddressLike;
368
+ /** `["merchant", payee, signer]`, needed when a delegate cancels. */
369
+ readonly merchantAuthority?: AddressLike;
370
+ }
371
+ /** `cancel_invoice()`. Accounts (`CancelInvoice`): signer(s), invoice(w),
372
+ * then the optional merchant_authority. */
373
+ export declare function buildCancelInvoiceIx(p: CancelInvoiceParams): BuiltInstruction;
374
+ export interface CloseInvoiceParams {
375
+ readonly programId: AddressLike;
376
+ /** The payee or the rent payer. */
377
+ readonly signer: AddressLike;
378
+ readonly invoice: AddressLike;
379
+ /** `Invoice.rentPayer`: receives the refund. */
380
+ readonly rentPayer: AddressLike;
381
+ }
382
+ /** `close_invoice()`. Accounts (`CloseInvoice`): signer(s), invoice(w),
383
+ * rent_payer(w). */
384
+ export declare function buildCloseInvoiceIx(p: CloseInvoiceParams): BuiltInstruction;
385
+ export interface CreateMerchantAuthorityParams {
386
+ readonly programId: AddressLike;
387
+ /** Signer; pays the rent. */
388
+ readonly payee: AddressLike;
389
+ /** The key allowed to create and cancel invoices for `payee`. */
390
+ readonly delegate: AddressLike;
391
+ /** {@link findMerchantAuthorityPda}(payee, delegate). */
392
+ readonly merchantAuthority: AddressLike;
393
+ }
394
+ /** `create_merchant_authority(delegate)`. Accounts
395
+ * (`CreateMerchantAuthority`): payee(s,w), merchant_authority(w), system_program. */
396
+ export declare function buildCreateMerchantAuthorityIx(p: CreateMerchantAuthorityParams): BuiltInstruction;
397
+ export interface RevokeMerchantAuthorityParams {
398
+ readonly programId: AddressLike;
399
+ /** Signer; receives the rent back. */
400
+ readonly payee: AddressLike;
401
+ readonly merchantAuthority: AddressLike;
402
+ }
403
+ /** `revoke_merchant_authority()`. Accounts (`RevokeMerchantAuthority`):
404
+ * payee(s,w), merchant_authority(w). */
405
+ export declare function buildRevokeMerchantAuthorityIx(p: RevokeMerchantAuthorityParams): BuiltInstruction;
406
+ /** Plain-language sentence for a Pay program error code, or null. */
407
+ export declare function payErrorMessage(code: number): string | null;
408
+ /**
409
+ * The instruction to SIMULATE (never send) to learn whether the deployed
410
+ * program has Pay: `pay_invoice` with no accounts and all-zero arguments. A
411
+ * Pay-enabled program recognizes the discriminator, decodes the arguments and
412
+ * fails account validation (3005 `AccountNotEnoughKeys`); an older one answers
413
+ * `InstructionFallbackNotFound` (101). Read the simulation's `err` with
414
+ * {@link classifyPayProbe}.
415
+ *
416
+ * Simulate it with `sigVerify: false`, `replaceRecentBlockhash: true` and a
417
+ * fee payer that EXISTS and is SYSTEM-owned (the connected wallet, or a fixed
418
+ * funded system account). A program-owned fee payer such as a multisig
419
+ * treasury fails the whole transaction (`InvalidAccountForFee`) before the
420
+ * probe runs, which says nothing about Pay.
421
+ */
422
+ export declare function buildPayProbeIx(programId: AddressLike): BuiltInstruction;
423
+ /** What a Pay probe simulation says about the deployed program. */
424
+ export type PayProbeResult =
425
+ /** The program recognized `pay_invoice` (any custom error but 101 from the probe). */
426
+ "live"
427
+ /** The probe itself failed with `InstructionFallbackNotFound` (101). */
428
+ | "not-deployed"
429
+ /** Anything else: a transaction-level error (`InvalidAccountForFee`,
430
+ * `AccountNotFound`, `InsufficientFundsForFee`, ...), an error in another
431
+ * instruction, an unexpected success, or no answer. Says nothing about Pay:
432
+ * never cache it, and let the chain decide at send time. */
433
+ | "unknown";
434
+ /**
435
+ * Classify a probe simulation's `value.err` (probe at `probeIndex`). Only an
436
+ * `InstructionError` AT the probe index is evidence: `Custom 101` =
437
+ * "not-deployed", any other custom code = "live". Everything else is
438
+ * "unknown".
439
+ */
440
+ export declare function classifyPayProbe(err: unknown, probeIndex: number): PayProbeResult;
441
+ /**
442
+ * @deprecated Two-state view of {@link classifyPayProbe}: `true` only for
443
+ * "live". It cannot tell "not deployed" from "the simulation said nothing"
444
+ * (e.g. a program-owned fee payer); use {@link classifyPayProbe}.
445
+ */
446
+ export declare function interpretPayProbe(err: unknown, probeIndex: number): boolean;
447
+ /** Whether a simulation / transaction error says the program does not know
448
+ * Pay instructions yet (Anchor `InstructionFallbackNotFound`, code 101). */
449
+ export declare function isPayNotDeployedError(err: unknown): boolean;
450
+ /** What the merchant expects the invoice to say: the terms it STORED when it
451
+ * created the invoice, never values taken from the buyer's browser. */
452
+ export interface VerifyInvoicePaidExpect {
453
+ /** The wallet the funds go to. */
454
+ readonly payee: AddressLike;
455
+ /** Exact amount in base units (bigint, a safe integer number, or a decimal
456
+ * string of base units). */
457
+ readonly amount: bigint | number | string;
458
+ /** SPL mint; omit (or {@link INVOICE_NATIVE_MINT}) for native XNT. */
459
+ readonly mint?: AddressLike;
460
+ /** The invoice id (16 bytes or 32 hex chars). Recommended: binds the check
461
+ * to ONE order, so one paid invoice can never satisfy two orders. */
462
+ readonly id?: Uint8Array | string;
463
+ /** The registry program. Default {@link DEFAULT_HANDLE_PROGRAM}. */
464
+ readonly programId?: AddressLike;
465
+ /** Default "confirmed". Use "finalized" for high-value goods (a few seconds
466
+ * later, but cannot be rolled back). */
467
+ readonly commitment?: "confirmed" | "finalized";
468
+ }
469
+ export type VerifyInvoicePaidFailure =
470
+ /** No account at that address (never created, or closed after payment). */
471
+ "not-found"
472
+ /** The account is not owned by the registry program. */
473
+ | "wrong-program"
474
+ /** The account is not an Invoice. */
475
+ | "not-invoice" | "wrong-payee" | "wrong-amount" | "wrong-mint" | "wrong-id"
476
+ /** The invoice exists with the right terms but is not Paid (yet). */
477
+ | "not-paid";
478
+ export type VerifyInvoicePaidResult = {
479
+ readonly paid: true;
480
+ readonly invoice: string;
481
+ readonly paidBy: string;
482
+ /** Unix seconds (chain clock). */
483
+ readonly paidAt: bigint;
484
+ readonly amount: bigint;
485
+ readonly mint: string;
486
+ readonly payee: string;
487
+ } | {
488
+ readonly paid: false;
489
+ readonly invoice: string;
490
+ readonly reason: VerifyInvoicePaidFailure;
491
+ /** The on-chain status when the invoice was readable. */
492
+ readonly status?: InvoiceStatus;
493
+ };
494
+ /**
495
+ * MERCHANT SERVER: is `invoice` paid, on chain, with exactly the terms you
496
+ * expect? This is the check that releases goods. A checkout widget result,
497
+ * a redirect or a webhook is only a hint to call this.
498
+ *
499
+ * Reads the Invoice account (one `getAccountInfo`) and returns `paid: true`
500
+ * only when ALL hold: the account is owned by the registry program, decodes
501
+ * as an Invoice, its payee, mint, amount (and `id`, when given) equal what you
502
+ * expect, and its status is Paid. The program moved the funds payer → payee in
503
+ * the same instruction that set Paid, so Paid means paid.
504
+ *
505
+ * Pass the invoice address and terms from YOUR database (the ones you used to
506
+ * create the invoice), never from the browser. Mark the order fulfilled once
507
+ * and idempotently: after payment the invoice can be closed, and a closed
508
+ * invoice reads as `not-found`.
509
+ *
510
+ * `rpc` is an RPC URL or an {@link RpcFn}. Throws on RPC/transport errors
511
+ * (retry) and on malformed arguments; every on-chain answer is a result.
512
+ */
513
+ export declare function verifyInvoicePaid(rpc: RpcFn | string, invoice: AddressLike, expect: VerifyInvoicePaidExpect): Promise<VerifyInvoicePaidResult>;