@chainpayhq/sdk 0.0.0-stage → 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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/accounts.d.ts +23 -0
  4. package/dist/accounts.js +148 -0
  5. package/dist/cards/accounts.d.ts +156 -0
  6. package/dist/cards/accounts.js +346 -0
  7. package/dist/cards/api.d.ts +379 -0
  8. package/dist/cards/api.js +241 -0
  9. package/dist/cards/commitment.d.ts +86 -0
  10. package/dist/cards/commitment.js +288 -0
  11. package/dist/cards/constants.d.ts +160 -0
  12. package/dist/cards/constants.js +163 -0
  13. package/dist/cards/draft.d.ts +57 -0
  14. package/dist/cards/draft.js +131 -0
  15. package/dist/cards/evidence.d.ts +69 -0
  16. package/dist/cards/evidence.js +41 -0
  17. package/dist/cards/hash.d.ts +9 -0
  18. package/dist/cards/hash.js +47 -0
  19. package/dist/cards/index.d.ts +14 -0
  20. package/dist/cards/index.js +14 -0
  21. package/dist/cards/instructions.d.ts +302 -0
  22. package/dist/cards/instructions.js +474 -0
  23. package/dist/cards/layout.d.ts +33 -0
  24. package/dist/cards/layout.js +137 -0
  25. package/dist/cards/math.d.ts +67 -0
  26. package/dist/cards/math.js +138 -0
  27. package/dist/cards/merchants.d.ts +23 -0
  28. package/dist/cards/merchants.js +38 -0
  29. package/dist/cards/pda.d.ts +42 -0
  30. package/dist/cards/pda.js +93 -0
  31. package/dist/cards/private-repayment.d.ts +198 -0
  32. package/dist/cards/private-repayment.js +485 -0
  33. package/dist/cards/redact.d.ts +18 -0
  34. package/dist/cards/redact.js +103 -0
  35. package/dist/cards/tee.d.ts +253 -0
  36. package/dist/cards/tee.js +605 -0
  37. package/dist/cli.d.ts +31 -0
  38. package/dist/cli.js +351 -0
  39. package/dist/client.d.ts +80 -0
  40. package/dist/client.js +493 -0
  41. package/dist/constants.d.ts +44 -0
  42. package/dist/constants.js +43 -0
  43. package/dist/crossmint-adapt.d.ts +43 -0
  44. package/dist/crossmint-adapt.js +68 -0
  45. package/dist/crossmint-order.d.ts +220 -0
  46. package/dist/crossmint-order.js +638 -0
  47. package/dist/delivery.d.ts +66 -0
  48. package/dist/delivery.js +232 -0
  49. package/dist/encoding.d.ts +51 -0
  50. package/dist/encoding.js +128 -0
  51. package/dist/index.d.ts +27 -0
  52. package/dist/index.js +26 -0
  53. package/dist/known-assets.d.ts +30 -0
  54. package/dist/known-assets.js +49 -0
  55. package/dist/mandate-request.d.ts +123 -0
  56. package/dist/mandate-request.js +401 -0
  57. package/dist/mandate.d.ts +44 -0
  58. package/dist/mandate.js +157 -0
  59. package/dist/ops-snapshot.d.ts +157 -0
  60. package/dist/ops-snapshot.js +356 -0
  61. package/dist/payment-request.d.ts +37 -0
  62. package/dist/payment-request.js +218 -0
  63. package/dist/payment.d.ts +40 -0
  64. package/dist/payment.js +214 -0
  65. package/dist/pda.d.ts +13 -0
  66. package/dist/pda.js +36 -0
  67. package/dist/receipt-export.d.ts +55 -0
  68. package/dist/receipt-export.js +149 -0
  69. package/dist/receipt.d.ts +108 -0
  70. package/dist/receipt.js +213 -0
  71. package/dist/solana.d.ts +5 -0
  72. package/dist/solana.js +20 -0
  73. package/dist/token-capabilities.d.ts +9 -0
  74. package/dist/token-capabilities.js +139 -0
  75. package/dist/token.d.ts +18 -0
  76. package/dist/token.js +55 -0
  77. package/dist/transaction-reader.d.ts +10 -0
  78. package/dist/transaction-reader.js +18 -0
  79. package/dist/transaction-v1.d.ts +18 -0
  80. package/dist/transaction-v1.js +73 -0
  81. package/dist/types.d.ts +267 -0
  82. package/dist/types.js +1 -0
  83. package/dist/x402-adapt.d.ts +20 -0
  84. package/dist/x402-adapt.js +62 -0
  85. package/dist/x402-challenge.d.ts +116 -0
  86. package/dist/x402-challenge.js +385 -0
  87. package/dist/x402.d.ts +18 -0
  88. package/dist/x402.js +35 -0
  89. package/package.json +54 -4
@@ -0,0 +1,302 @@
1
+ import type { Address, ChainPayInstruction } from "../types.js";
2
+ import { type CardPolicyInstructionName } from "./constants.js";
3
+ /**
4
+ * Instruction data follows contracts.md §1.3 (Anchor discriminator + Borsh
5
+ * args in the listed order). Account lists, discriminators and arg layouts
6
+ * are checked against the deployed program's IDL
7
+ * (programs/card_policy/idl/card_policy.json, Devnet
8
+ * H3aetJdQXG8EeJSCHZrpQa8iKHBw8e1p9fSPjTUsB93n) by test/cards-idl.test.mjs,
9
+ * including the `#[delegate]` macro accounts of `delegate_card`.
10
+ */
11
+ export declare const CARD_POLICY_ACCOUNT_ORDER_PROVISIONAL = false;
12
+ export type PolicyArgs = {
13
+ budgetCents: bigint;
14
+ maxPurchaseCents: bigint;
15
+ /** 0 = no count limit. */
16
+ maxPurchasesPerPeriod: number;
17
+ periodSeconds: number;
18
+ currency: string;
19
+ merchantIdHashes: Uint8Array[];
20
+ mccs: number[];
21
+ /** 0 = no expiry. Unix seconds. */
22
+ expiresAt: bigint;
23
+ recurringAllowed: boolean;
24
+ feeBps: number;
25
+ authorizer: Address;
26
+ };
27
+ export type RestoreArgs = {
28
+ policy: PolicyArgs;
29
+ periodIndex: number;
30
+ capturedCents: bigint;
31
+ reservedCents: bigint;
32
+ refundedCents: bigint;
33
+ purchasesCount: number;
34
+ /** Exception debits booked this period (program 1A review: after `purchases_count`). */
35
+ exceptionCents: bigint;
36
+ statementOutstandingCents: bigint;
37
+ ledgerHead: Uint8Array;
38
+ ledgerSeq: bigint;
39
+ reconDigest: Uint8Array;
40
+ };
41
+ export type PermissionOp = {
42
+ kind: "add_reader";
43
+ pubkey: Address;
44
+ } | {
45
+ kind: "remove_reader";
46
+ pubkey: Address;
47
+ };
48
+ export type CardInstructionArgs = {
49
+ initCard: {
50
+ cardId: Uint8Array;
51
+ issuer: number;
52
+ issuerCardRefHash: Uint8Array;
53
+ prefundLamports: bigint;
54
+ };
55
+ delegateCard: {
56
+ validator: Address;
57
+ };
58
+ initPermission: {
59
+ authorizer: Address;
60
+ };
61
+ updatePermission: {
62
+ op: PermissionOp;
63
+ };
64
+ syncPermission: Record<string, never>;
65
+ setPolicy: {
66
+ policy: PolicyArgs;
67
+ };
68
+ openCheckoutIntent: {
69
+ intentId: Uint8Array;
70
+ agent: Address;
71
+ merchantIdHash: Uint8Array;
72
+ mcc: number;
73
+ maxAmountCents: bigint;
74
+ currency: string;
75
+ expiresAt: bigint;
76
+ };
77
+ cancelCheckoutIntent: Record<string, never>;
78
+ closeCheckoutIntent: Record<string, never>;
79
+ authorize: {
80
+ authIdHash: Uint8Array;
81
+ intentId: Uint8Array;
82
+ amountCents: bigint;
83
+ currency: string;
84
+ merchantIdHash: Uint8Array;
85
+ mcc: number;
86
+ merchantInitiated: boolean;
87
+ singleMessage: boolean;
88
+ };
89
+ adjustReservation: {
90
+ newAmountCents: bigint;
91
+ };
92
+ capture: {
93
+ amountCents: bigint;
94
+ captureIdHash: Uint8Array;
95
+ };
96
+ reverse: {
97
+ amountCents: bigint;
98
+ reason: number;
99
+ eventIdHash: Uint8Array;
100
+ };
101
+ refund: {
102
+ amountCents: bigint;
103
+ eventIdHash: Uint8Array;
104
+ };
105
+ recordDispute: {
106
+ state: number;
107
+ eventIdHash: Uint8Array;
108
+ };
109
+ recordException: {
110
+ kind: number;
111
+ amountCents: bigint;
112
+ eventIdHash: Uint8Array;
113
+ };
114
+ resolveException: {
115
+ eventIdHash: Uint8Array;
116
+ resolution: number;
117
+ };
118
+ rollPeriod: Record<string, never>;
119
+ freeze: {
120
+ reason: number;
121
+ };
122
+ unfreeze: Record<string, never>;
123
+ recoveryFreeze: {
124
+ reason: number;
125
+ };
126
+ restore: {
127
+ restore: RestoreArgs;
128
+ };
129
+ confirmReconciled: {
130
+ reconDigest: Uint8Array;
131
+ };
132
+ checkpoint: {
133
+ masterSalt: Uint8Array;
134
+ seq: bigint;
135
+ };
136
+ writeCommitment: {
137
+ root: Uint8Array;
138
+ seq: bigint;
139
+ policyVersion: number;
140
+ periodIndex: number;
141
+ };
142
+ wipeCard: Record<string, never>;
143
+ closeReservation: Record<string, never>;
144
+ closeCard: Record<string, never>;
145
+ recordRepayment: {
146
+ statementDigest: Uint8Array;
147
+ amountCents: bigint;
148
+ };
149
+ repayStatement: {
150
+ statementDigest: Uint8Array;
151
+ amount: bigint;
152
+ };
153
+ recordPrivateRepayment: {
154
+ statementDigest: Uint8Array;
155
+ amountCents: bigint;
156
+ };
157
+ };
158
+ export declare function encodeCardInstructionData<K extends CardPolicyInstructionName>(name: K, args: CardInstructionArgs[K]): Uint8Array;
159
+ export type DecodedCardInstruction = {
160
+ [K in CardPolicyInstructionName]: {
161
+ name: K;
162
+ args: CardInstructionArgs[K];
163
+ };
164
+ }[CardPolicyInstructionName];
165
+ export declare function decodeCardInstructionData(data: Uint8Array): DecodedCardInstruction;
166
+ /**
167
+ * Client-side mirror of the `set_policy` validation (contracts.md §1.3 #6).
168
+ * The program is the authority; this only stops an owner from signing a
169
+ * transaction that is certain to fail. Returns plain-language problems.
170
+ */
171
+ export declare function policyArgsProblems(p: PolicyArgs): string[];
172
+ type CardRef = {
173
+ owner: Address;
174
+ cardId: Uint8Array;
175
+ };
176
+ export declare function buildInitCardInstruction(input: CardRef & {
177
+ issuer: number;
178
+ issuerCardRefHash: Uint8Array;
179
+ prefundLamports: bigint;
180
+ }, programId?: Address): ChainPayInstruction;
181
+ export declare function buildDelegateCardInstruction(input: CardRef & {
182
+ validator: Address;
183
+ }, programId?: Address): ChainPayInstruction;
184
+ /** PER. Owner creates the private permissions for policy and period. */
185
+ export declare function buildInitPermissionInstruction(input: CardRef & {
186
+ authorizer: Address;
187
+ }, programId?: Address): ChainPayInstruction;
188
+ /**
189
+ * PER. Owner adds or removes a read-only finance reader. There is no "make public" op.
190
+ * `ephemeralAccounts` (open Reservations/CheckoutIntents) are re-synced in the same
191
+ * transaction, so removing a reader also revokes their view of open holds at once.
192
+ */
193
+ export declare function buildUpdatePermissionInstruction(input: CardRef & {
194
+ op: PermissionOp;
195
+ ephemeralAccounts?: Address[];
196
+ }, programId?: Address): ChainPayInstruction;
197
+ /**
198
+ * PER. The owner signs this over their own TEE connection. Rejects a policy the program would reject.
199
+ *
200
+ * Once the card's policy is set, changing the credit terms (the authorizer, the
201
+ * fee, a larger budget or a shorter period) also needs ChainPay's current
202
+ * authorizer as `coSigner`: it rides as an extra signer account and the
203
+ * program refuses the change without it. The authorizer is never the owner.
204
+ */
205
+ export declare function buildSetPolicyInstruction(input: CardRef & {
206
+ policy: PolicyArgs;
207
+ coSigner?: Address;
208
+ }, programId?: Address): ChainPayInstruction;
209
+ /** PER. Owner freeze (reason 1). The authorizer variant lives in Axum. */
210
+ export declare function buildFreezeInstruction(input: CardRef & {
211
+ signer?: Address;
212
+ reason?: number;
213
+ }, programId?: Address): ChainPayInstruction;
214
+ /** PER. Owner only. Never built or sent by an agent tool. */
215
+ export declare function buildUnfreezeInstruction(input: CardRef, programId?: Address): ChainPayInstruction;
216
+ export declare function buildResolveExceptionInstruction(input: CardRef & {
217
+ eventIdHash: Uint8Array;
218
+ resolution: number;
219
+ }, programId?: Address): ChainPayInstruction;
220
+ export declare function buildCancelCheckoutIntentInstruction(input: CardRef & {
221
+ intentId: Uint8Array;
222
+ signer?: Address;
223
+ }, programId?: Address): ChainPayInstruction;
224
+ /**
225
+ * PER. Co-signed: owner and the card's member authorizer must both sign
226
+ * (program 1A review), so the owner alone can't rewrite counters or debt.
227
+ * Axum signs as authorizer first; the owner checks and adds a signature.
228
+ */
229
+ export declare function buildRestoreInstruction(input: CardRef & {
230
+ authorizer: Address;
231
+ restore: RestoreArgs;
232
+ }, programId?: Address): ChainPayInstruction;
233
+ /**
234
+ * PER. Owner or authorizer closes a consumed, cancelled or expired intent and
235
+ * its permission, returning the rent to the card prefund.
236
+ */
237
+ export declare function buildCloseCheckoutIntentInstruction(input: CardRef & {
238
+ intentId: Uint8Array;
239
+ signer?: Address;
240
+ }, programId?: Address): ChainPayInstruction;
241
+ export type RepayStatementInput = CardRef & {
242
+ /** The owner's ChainPay mandate whose `approvedAgent` is this card's repay agent. */
243
+ mandate: Address;
244
+ mint: Address;
245
+ sourceTokenAccount: Address;
246
+ /** The partner token account the statement's `payWith` names. */
247
+ recipientTokenAccount: Address;
248
+ /** 32-byte statement digest; becomes the receipt's `invoice_hash`. */
249
+ statementDigest: Uint8Array;
250
+ /** Exact base units of `mint` (the statement's amount due). */
251
+ amount: bigint;
252
+ tokenProgram?: Address;
253
+ chainpayProgramId?: Address;
254
+ };
255
+ /**
256
+ * Base layer, owner-signed. card_policy's repay agent PDA `["repay_agent", binding]`
257
+ * signs ChainPay `execute_payment` by CPI, so ChainPay enforces the mandate and creates
258
+ * the receipt `["receipt", mandate, statementDigest]`. The owner pays the receipt rent.
259
+ * Returns the receipt address the Axum relay verifies and `record_repayment` re-checks on PER.
260
+ */
261
+ export declare function buildRepayStatementInstruction(input: RepayStatementInput, programId?: Address): {
262
+ instruction: ChainPayInstruction;
263
+ receipt: Address;
264
+ repayAgent: Address;
265
+ };
266
+ export declare function buildConfirmReconciledInstruction(input: CardRef & {
267
+ reconDigest: Uint8Array;
268
+ }, programId?: Address): ChainPayInstruction;
269
+ /**
270
+ * PER. Owner or authorizer closes a final Reservation (fully captured, reversed
271
+ * or expired; nothing held; no open dispute) and its permission. The rent goes
272
+ * back to the card prefund and the auth id moves into the card's AuthGuard
273
+ * ring, so a replayed issuer authorization still gets `DuplicateAuthorization`.
274
+ * Axum normally does this; the owner can too.
275
+ */
276
+ export declare function buildCloseReservationInstruction(input: CardRef & {
277
+ authIdHash: Uint8Array;
278
+ signer?: Address;
279
+ }, programId?: Address): ChainPayInstruction;
280
+ /**
281
+ * `ephemeralAccounts` lists every live Reservation and CheckoutIntent of the
282
+ * card, plus its AuthGuard once a reservation was ever closed
283
+ * (`deriveAuthGuardAddress`); each goes in remaining_accounts as
284
+ * [account, its permission] so the program can close it. Omitting one leaves
285
+ * private data behind (`EphemeralAccountsOpen`).
286
+ */
287
+ export declare function buildWipeCardInstruction(input: CardRef & {
288
+ ephemeralAccounts?: Address[];
289
+ }, programId?: Address): ChainPayInstruction;
290
+ export declare function buildCloseCardInstruction(input: CardRef, programId?: Address): ChainPayInstruction;
291
+ /**
292
+ * Base layer `#[action]`. Account order is fixed by contracts.md §1.3 #24:
293
+ * commitment, binding, source_program, escrow_auth (= policy PDA), escrow (signer).
294
+ * Only the delegation program can satisfy the escrow signer; exposed for tests and card-sim.
295
+ */
296
+ export declare function buildWriteCommitmentInstruction(input: CardRef & {
297
+ root: Uint8Array;
298
+ seq: bigint;
299
+ policyVersion: number;
300
+ periodIndex: number;
301
+ }, programId?: Address): ChainPayInstruction;
302
+ export {};