@certen.io/sdk 0.5.0 → 0.7.1

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 (112) hide show
  1. package/CHANGELOG.md +599 -0
  2. package/README.md +133 -119
  3. package/dist/client.d.ts +96 -6
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +258 -20
  6. package/dist/client.js.map +1 -1
  7. package/dist/doctor.d.ts +53 -0
  8. package/dist/doctor.d.ts.map +1 -0
  9. package/dist/doctor.js +451 -0
  10. package/dist/doctor.js.map +1 -0
  11. package/dist/error-codes.d.ts +14 -0
  12. package/dist/error-codes.d.ts.map +1 -0
  13. package/dist/error-codes.js +55 -0
  14. package/dist/error-codes.js.map +1 -0
  15. package/dist/errors.d.ts +13 -1
  16. package/dist/errors.d.ts.map +1 -1
  17. package/dist/errors.js +18 -1
  18. package/dist/errors.js.map +1 -1
  19. package/dist/funding.d.ts +43 -0
  20. package/dist/funding.d.ts.map +1 -0
  21. package/dist/funding.js +116 -0
  22. package/dist/funding.js.map +1 -0
  23. package/dist/index.d.ts +10 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +19 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/oauth.d.ts +56 -0
  28. package/dist/oauth.d.ts.map +1 -0
  29. package/dist/oauth.js +68 -0
  30. package/dist/oauth.js.map +1 -0
  31. package/dist/registration.d.ts +33 -0
  32. package/dist/registration.d.ts.map +1 -0
  33. package/dist/registration.js +49 -0
  34. package/dist/registration.js.map +1 -0
  35. package/dist/resources/admin.d.ts +52 -1
  36. package/dist/resources/admin.d.ts.map +1 -1
  37. package/dist/resources/admin.js +55 -0
  38. package/dist/resources/admin.js.map +1 -1
  39. package/dist/resources/billing.d.ts +198 -19
  40. package/dist/resources/billing.d.ts.map +1 -1
  41. package/dist/resources/billing.js +297 -7
  42. package/dist/resources/billing.js.map +1 -1
  43. package/dist/resources/chains.d.ts +38 -0
  44. package/dist/resources/chains.d.ts.map +1 -0
  45. package/dist/resources/chains.js +46 -0
  46. package/dist/resources/chains.js.map +1 -0
  47. package/dist/resources/device.d.ts +43 -0
  48. package/dist/resources/device.d.ts.map +1 -0
  49. package/dist/resources/device.js +49 -0
  50. package/dist/resources/device.js.map +1 -0
  51. package/dist/resources/execute.d.ts +10 -0
  52. package/dist/resources/execute.d.ts.map +1 -1
  53. package/dist/resources/execute.js +28 -6
  54. package/dist/resources/execute.js.map +1 -1
  55. package/dist/resources/health.d.ts +34 -0
  56. package/dist/resources/health.d.ts.map +1 -0
  57. package/dist/resources/health.js +43 -0
  58. package/dist/resources/health.js.map +1 -0
  59. package/dist/resources/identity.d.ts +83 -2
  60. package/dist/resources/identity.d.ts.map +1 -1
  61. package/dist/resources/identity.js +154 -2
  62. package/dist/resources/identity.js.map +1 -1
  63. package/dist/resources/oauth-clients.d.ts +71 -0
  64. package/dist/resources/oauth-clients.d.ts.map +1 -0
  65. package/dist/resources/oauth-clients.js +75 -0
  66. package/dist/resources/oauth-clients.js.map +1 -0
  67. package/dist/resources/pending.d.ts +13 -1
  68. package/dist/resources/pending.d.ts.map +1 -1
  69. package/dist/resources/pending.js +15 -0
  70. package/dist/resources/pending.js.map +1 -1
  71. package/dist/resources/proof.d.ts +82 -0
  72. package/dist/resources/proof.d.ts.map +1 -0
  73. package/dist/resources/proof.js +112 -0
  74. package/dist/resources/proof.js.map +1 -0
  75. package/dist/resources/registration-tokens.d.ts +51 -0
  76. package/dist/resources/registration-tokens.d.ts.map +1 -0
  77. package/dist/resources/registration-tokens.js +54 -0
  78. package/dist/resources/registration-tokens.js.map +1 -0
  79. package/dist/resources/sign.d.ts.map +1 -1
  80. package/dist/resources/sign.js +12 -7
  81. package/dist/resources/sign.js.map +1 -1
  82. package/dist/resources/transaction.d.ts +20 -0
  83. package/dist/resources/transaction.d.ts.map +1 -1
  84. package/dist/resources/transaction.js +28 -0
  85. package/dist/resources/transaction.js.map +1 -1
  86. package/dist/resources/transparency.d.ts +68 -0
  87. package/dist/resources/transparency.d.ts.map +1 -0
  88. package/dist/resources/transparency.js +83 -0
  89. package/dist/resources/transparency.js.map +1 -0
  90. package/dist/resources/webhooks.d.ts +97 -0
  91. package/dist/resources/webhooks.d.ts.map +1 -0
  92. package/dist/resources/webhooks.js +112 -0
  93. package/dist/resources/webhooks.js.map +1 -0
  94. package/dist/self-signup.d.ts +66 -0
  95. package/dist/self-signup.d.ts.map +1 -0
  96. package/dist/self-signup.js +76 -0
  97. package/dist/self-signup.js.map +1 -0
  98. package/dist/shared-proof.d.ts +34 -0
  99. package/dist/shared-proof.d.ts.map +1 -0
  100. package/dist/shared-proof.js +78 -0
  101. package/dist/shared-proof.js.map +1 -0
  102. package/dist/sign-target.d.ts +34 -0
  103. package/dist/sign-target.d.ts.map +1 -0
  104. package/dist/sign-target.js +41 -0
  105. package/dist/sign-target.js.map +1 -0
  106. package/dist/types.d.ts +831 -22
  107. package/dist/types.d.ts.map +1 -1
  108. package/dist/verify-receipt.d.ts +32 -0
  109. package/dist/verify-receipt.d.ts.map +1 -0
  110. package/dist/verify-receipt.js +176 -0
  111. package/dist/verify-receipt.js.map +1 -0
  112. package/package.json +4 -3
@@ -1,32 +1,173 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import type { BalanceResponse, ObligationsResponse, DepositTarget, DepositIntentStatus } from '../types.js';
3
- /**
4
- * Balance, commitments, and adding funds.
5
- *
6
- * The two numbers here are easy to confuse and only one of them is safe to act
7
- * on. `spendable_usd` is available balance plus any credit line. `remaining_usd`
8
- * (from `obligations`) subtracts what pending intents will consume when they
9
- * execute — and multi-signature intents can wait hours or weeks for quorum, so an
10
- * account can hold a balance that is entirely committed and still be refused on
11
- * its next call. Show or gate on `remaining_usd`.
12
- *
13
- * Funding has two attribution mechanisms and this resource exposes one of them.
14
- * `openPayment` declares an exact amount to send, matched inside a TTL — it needs
15
- * no registered wallet and suits a first deposit. Registering a payer address, so
16
- * every future send credits automatically, is deliberately NOT here: that asserts
17
- * deposits from an address belong to your organization, so it requires a signed-in
18
- * owner or admin in the portal rather than a machine key.
19
- */
2
+ import { type CertenClient } from '../client.js';
3
+ import type { BalanceResponse, QuoteResponse, ObligationsResponse, DepositTarget, DepositIntentStatus, PaymentRecord, PricingCatalog, PayerAddress, LedgerEntry, ReceiptSummary, Receipt, ReceiptProof, VerificationKeys, ReceiptVerification, Pagination } from '../types.js';
20
4
  export declare class BillingResource {
21
5
  private http;
22
- constructor(http: AxiosInstance);
6
+ private client;
7
+ /**
8
+ * `client` is the whole client, not just its HTTP handle, because verifying a receipt has to
9
+ * reach the transparency log as well as billing. It is captured, never dereferenced during
10
+ * construction — the client assigns its resources in sequence, so `transparency` does not exist
11
+ * yet at this point but always does by the time anything here runs.
12
+ */
13
+ constructor(http: AxiosInstance, client: CertenClient);
14
+ /**
15
+ * Every priced operation and what it costs — one call, no guessing.
16
+ *
17
+ * `quote()` prices ONE sku on ONE chain and needs the sku name up front, which is the problem:
18
+ * the names are not guessable (`identity.provision`, not `identity.create`), and nothing listed
19
+ * them. Discovering the price of onboarding meant guessing a name, being refused, and guessing
20
+ * again.
21
+ *
22
+ * Use this to find the sku, then `quote()` to get a binding price for a specific piece of work.
23
+ * Requires `billing:read`.
24
+ */
25
+ pricing(): Promise<PricingCatalog>;
23
26
  /** Available, held, credit line, and spendable. Requires `billing:read`. */
24
27
  balance(): Promise<BalanceResponse>;
28
+ /**
29
+ * Price a piece of work before committing to it.
30
+ *
31
+ * Free, and the answer binds: pass the returned `id` as `quote_id` on the
32
+ * transaction and that is the price, regardless of what gas does in between.
33
+ * A quote is single-use and expires, so ask when you are ready to act.
34
+ *
35
+ * Worth checking `computation.gas_estimate_basis` on a cost-plus chain. A
36
+ * `class_thin` basis means the proof class has its own cost history but too
37
+ * little of it for the median to be stable — the number is indicative, and
38
+ * can move materially as more of that class executes.
39
+ */
40
+ quote(params: {
41
+ chain: string;
42
+ proofClass?: 'on_demand' | 'on_cadence';
43
+ legCount?: number;
44
+ sku?: string;
45
+ additionalChains?: string[];
46
+ }): Promise<QuoteResponse>;
47
+ /**
48
+ * Re-read a quote you already have.
49
+ *
50
+ * Quotes are single-use and expire, and there was no way to ask about one after it was issued —
51
+ * so a caller who priced some work, got interrupted, and came back had to either guess whether
52
+ * their quote was still good or throw it away and ask again. Guessing wrong means a 400 in the
53
+ * middle of a transaction; throwing it away means the price can move underneath them.
54
+ *
55
+ * `quote()` CREATES; this one READS. Requires `billing:read`.
56
+ */
57
+ quoteById(id: string): Promise<QuoteResponse & {
58
+ seconds_remaining: number | null;
59
+ }>;
25
60
  /**
26
61
  * Pending intents and what they will cost — including `remaining_usd`, the
27
62
  * amount that may actually be committed to new work.
28
63
  */
29
64
  obligations(): Promise<ObligationsResponse>;
65
+ /**
66
+ * Every balance change, newest first. Requires `billing:read`.
67
+ *
68
+ * The append-only, double-entry record behind the balance: what moved, when, and why. Corrections
69
+ * appear as new REVERSING entries rather than edits, so the history is what happened.
70
+ *
71
+ * Use `ledgerAll()` to walk the whole thing.
72
+ */
73
+ ledger(params?: {
74
+ limit?: number;
75
+ offset?: number;
76
+ }): Promise<{
77
+ entries: LedgerEntry[];
78
+ pagination?: Pagination;
79
+ }>;
80
+ /**
81
+ * Every ledger entry, paging automatically.
82
+ *
83
+ * ```ts
84
+ * for await (const entry of certen.billing.ledgerAll()) { ... }
85
+ * ```
86
+ *
87
+ * The endpoint returns no total and no `has_more`, so termination is inferred from a short page —
88
+ * which is why this belongs here once rather than in every caller that gets the condition subtly
89
+ * wrong and silently reports a partial ledger as complete.
90
+ */
91
+ ledgerAll(pageSize?: number): AsyncIterableIterator<LedgerEntry>;
92
+ /** Signed receipts for every payment, charge, refund and adjustment. Requires `billing:read`. */
93
+ receipts(params?: {
94
+ limit?: number;
95
+ offset?: number;
96
+ }): Promise<{
97
+ receipts: ReceiptSummary[];
98
+ pagination?: Pagination;
99
+ }>;
100
+ /** Every receipt, paging automatically. */
101
+ receiptsAll(pageSize?: number): AsyncIterableIterator<ReceiptSummary>;
102
+ /**
103
+ * One receipt, with its signature, its computation inputs, and the gateway's own verification.
104
+ *
105
+ * `verification` is CERTEN checking CERTEN, which settles nothing by itself. What makes the
106
+ * receipt evidence is that every check in it is reproducible by you: verify `signature` against
107
+ * `verificationKeys()`, reproduce `digest` from `body`, and fetch `receiptProof()` to show the
108
+ * receipt is in a log that was anchored on Accumulate.
109
+ */
110
+ receipt(id: string): Promise<Receipt>;
111
+ /**
112
+ * The transparency-log inclusion proof for a receipt.
113
+ *
114
+ * **Store it alongside the receipt.** It remains valid forever against the tree head it names,
115
+ * and that head is pinned on Accumulate — so the proof outlives any cooperation from CERTEN,
116
+ * which is the entire point of it existing.
117
+ *
118
+ * Defaults to the newest ANCHORED head; a proof against an unanchored head is only as good as our
119
+ * word. Only receipts with `logged: true` have one — expect a 404 otherwise.
120
+ */
121
+ receiptProof(id: string, params?: {
122
+ treeSize?: number;
123
+ }): Promise<ReceiptProof>;
124
+ /**
125
+ * The public keys receipts and tree heads are signed with.
126
+ *
127
+ * Deliberately unauthenticated on the gateway, and it should stay that way in your integration
128
+ * too: a verification key you can only obtain by asking us nicely could not settle a dispute
129
+ * with us.
130
+ */
131
+ verificationKeys(): Promise<VerificationKeys>;
132
+ /**
133
+ * Check a receipt yourself, against independently published data.
134
+ *
135
+ * Recomputes the digest from the body, verifies the ed25519 signature against the PUBLISHED key
136
+ * set, recomputes the salted leaf, folds the RFC 6962 audit path, and compares the result with a
137
+ * signed tree head fetched separately — not with the root that travelled inside the proof, which
138
+ * would be comparing the proof with itself.
139
+ *
140
+ * Never throws for a failed check: `verified` is false and the reason is in `checks`. A check that
141
+ * could not be run is `skipped`, and `complete` goes false — a verifier that cannot reach the log
142
+ * must say so rather than imply a pass.
143
+ */
144
+ verifyReceipt(id: string): Promise<ReceiptVerification>;
145
+ /**
146
+ * Register a wallet you pay from, so every future deposit from it credits automatically.
147
+ *
148
+ * This is the difference between funding once and funding repeatedly. `openPayment` opens a
149
+ * single-use intent matched on the EXACT amount within a TTL — right for a first deposit, and a
150
+ * step before every send thereafter. A registered address needs none of that: money arriving from
151
+ * it is attributed to this organization on sight.
152
+ *
153
+ * **The gateway's own 402 recommends doing this, and until now no client could.** Its `how_to_pay`
154
+ * block names `POST /v1/billing/deposit-addresses` as the recommended fix, while this SDK omitted
155
+ * it on the stated grounds that it needed a portal session rather than a machine key. That was
156
+ * wrong: the endpoint takes an API key with `billing:write`, which is exactly what an autonomous
157
+ * caller settling its own 402 is holding.
158
+ *
159
+ * An address belongs to ONE organization per chain. A duplicate is rejected rather than merged,
160
+ * because ambiguous attribution means crediting the wrong customer — expect a 409.
161
+ */
162
+ registerPayerAddress(params: {
163
+ chain: string;
164
+ address: string;
165
+ label?: string;
166
+ }): Promise<PayerAddress>;
167
+ /** Wallets registered for automatic attribution. Requires `billing:read`. */
168
+ payerAddresses(): Promise<{
169
+ addresses: PayerAddress[];
170
+ }>;
30
171
  /**
31
172
  * Where to send stablecoin, optionally opening a single-use payment matched on
32
173
  * the exact amount.
@@ -46,6 +187,18 @@ export declare class BillingResource {
46
187
  * same window moves the balance too, so inferring from it reports the wrong
47
188
  * payment as matched.
48
189
  */
190
+ /**
191
+ * Payments the gateway has seen, most recent first.
192
+ *
193
+ * Distinct from a deposit INTENT. A payment can be credited without ever matching an intent —
194
+ * see `waitForPayment` — so this is the record that says whether money actually arrived.
195
+ */
196
+ payments(params?: {
197
+ limit?: number;
198
+ }): Promise<{
199
+ payments: PaymentRecord[];
200
+ pagination?: Pagination;
201
+ }>;
49
202
  payment(reference: string): Promise<DepositIntentStatus>;
50
203
  /**
51
204
  * Resolve once the payment is credited, or when it expires.
@@ -53,11 +206,37 @@ export declare class BillingResource {
53
206
  * Returns the terminal status rather than throwing on expiry — an expired
54
207
  * payment is an ordinary outcome the caller should report, not an error. Only a
55
208
  * genuine transport or auth failure throws.
209
+ *
210
+ * **It watches the payment feed as well as the intent, and that is not belt-and-braces.**
211
+ *
212
+ * It began as a workaround for a gateway bug: the gateway closed a deposit intent only when the
213
+ * payment had been attributed BY that intent, and since attribution tries a registered payer
214
+ * address first — and the funding flow registers the sender — a paid intent was never closed.
215
+ * Observed live: 1 USDC credited in seconds with `attribution: registered_address` while the
216
+ * intent sat `open` with `matched_at: null`, until it expired an hour later. Watching only the
217
+ * intent reported "not credited" on money that had already arrived. The gateway now closes the
218
+ * intent on credit regardless of how the org was identified.
219
+ *
220
+ * The feed watch stays, for two reasons that outlive that bug. The SDK is versioned separately
221
+ * and is regularly pointed at an older gateway, where the old behaviour is still live. And the
222
+ * intent can only ever report money that matched it: a deposit for the wrong amount, or one sent
223
+ * before the intent was opened, still credits the balance and still answers the caller's actual
224
+ * question — did my money arrive.
225
+ *
226
+ * On that path the returned status is synthesised with `status: 'matched'` and the credited
227
+ * payment's id, because from the caller's point of view the money arrived.
56
228
  */
57
229
  waitForPayment(reference: string, opts?: {
58
230
  intervalMs?: number;
59
231
  timeoutMs?: number;
60
232
  onPoll?: (status: DepositIntentStatus) => void;
61
233
  }): Promise<DepositIntentStatus>;
234
+ /**
235
+ * A credited payment of this amount that arrived after `since`, if there is one.
236
+ *
237
+ * Returns null on any failure: an unavailable payments feed must never turn a wait that would
238
+ * otherwise have succeeded into an error, and the intent poll above remains the primary signal.
239
+ */
240
+ private creditedSince;
62
241
  }
63
242
  //# sourceMappingURL=billing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEvC,4EAA4E;IACtE,OAAO,IAAI,OAAO,CAAC,eAAe,CAAC;IAKzC;;;OAGG;IACG,WAAW,IAAI,O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G;YACW,aAAa;CAc5B"}
@@ -1,3 +1,5 @@
1
+ import { paginate } from '../client.js';
2
+ import { verifyReceipt } from '../verify-receipt.js';
1
3
  /**
2
4
  * Balance, commitments, and adding funds.
3
5
  *
@@ -8,23 +10,107 @@
8
10
  * account can hold a balance that is entirely committed and still be refused on
9
11
  * its next call. Show or gate on `remaining_usd`.
10
12
  *
11
- * Funding has two attribution mechanisms and this resource exposes one of them.
13
+ * Funding has two attribution mechanisms and both are here.
12
14
  * `openPayment` declares an exact amount to send, matched inside a TTL — it needs
13
- * no registered wallet and suits a first deposit. Registering a payer address, so
14
- * every future send credits automatically, is deliberately NOT here: that asserts
15
- * deposits from an address belong to your organization, so it requires a signed-in
16
- * owner or admin in the portal rather than a machine key.
15
+ * no registered wallet and suits a first deposit. `registerPayerAddress` records a
16
+ * wallet once so every future send from it credits automatically.
17
+ *
18
+ * The second used to be omitted, on the stated grounds that asserting an address
19
+ * belongs to your organization required a signed-in portal owner rather than a
20
+ * machine key. That was simply wrong — the endpoint authenticates with an API key
21
+ * carrying `billing:write` — and the omission mattered, because the gateway's own
22
+ * 402 names registering a sender as the recommended fix.
23
+ */
24
+ /**
25
+ * Whole seconds until an ISO instant, or null if there is nothing usable to measure.
26
+ *
27
+ * Floored, never rounded up: a quote with 900ms left must not report 1 second and invite a caller
28
+ * to act on it.
17
29
  */
30
+ function secondsUntil(iso) {
31
+ if (typeof iso !== 'string')
32
+ return null;
33
+ const at = Date.parse(iso);
34
+ if (!Number.isFinite(at))
35
+ return null;
36
+ return Math.max(0, Math.floor((at - Date.now()) / 1000));
37
+ }
18
38
  export class BillingResource {
19
39
  http;
20
- constructor(http) {
40
+ client;
41
+ /**
42
+ * `client` is the whole client, not just its HTTP handle, because verifying a receipt has to
43
+ * reach the transparency log as well as billing. It is captured, never dereferenced during
44
+ * construction — the client assigns its resources in sequence, so `transparency` does not exist
45
+ * yet at this point but always does by the time anything here runs.
46
+ */
47
+ constructor(http, client) {
21
48
  this.http = http;
49
+ this.client = client;
50
+ }
51
+ /**
52
+ * Every priced operation and what it costs — one call, no guessing.
53
+ *
54
+ * `quote()` prices ONE sku on ONE chain and needs the sku name up front, which is the problem:
55
+ * the names are not guessable (`identity.provision`, not `identity.create`), and nothing listed
56
+ * them. Discovering the price of onboarding meant guessing a name, being refused, and guessing
57
+ * again.
58
+ *
59
+ * Use this to find the sku, then `quote()` to get a binding price for a specific piece of work.
60
+ * Requires `billing:read`.
61
+ */
62
+ async pricing() {
63
+ const { data } = await this.http.get('/v1/pricing');
64
+ return data;
22
65
  }
23
66
  /** Available, held, credit line, and spendable. Requires `billing:read`. */
24
67
  async balance() {
25
68
  const { data } = await this.http.get('/v1/billing/balance');
26
69
  return data;
27
70
  }
71
+ /**
72
+ * Price a piece of work before committing to it.
73
+ *
74
+ * Free, and the answer binds: pass the returned `id` as `quote_id` on the
75
+ * transaction and that is the price, regardless of what gas does in between.
76
+ * A quote is single-use and expires, so ask when you are ready to act.
77
+ *
78
+ * Worth checking `computation.gas_estimate_basis` on a cost-plus chain. A
79
+ * `class_thin` basis means the proof class has its own cost history but too
80
+ * little of it for the median to be stable — the number is indicative, and
81
+ * can move materially as more of that class executes.
82
+ */
83
+ async quote(params) {
84
+ const { data } = await this.http.post('/v1/quote', {
85
+ chain: params.chain,
86
+ proof_class: params.proofClass,
87
+ leg_count: params.legCount ?? 1,
88
+ sku: params.sku,
89
+ additional_chains: params.additionalChains,
90
+ });
91
+ return data;
92
+ }
93
+ /**
94
+ * Re-read a quote you already have.
95
+ *
96
+ * Quotes are single-use and expire, and there was no way to ask about one after it was issued —
97
+ * so a caller who priced some work, got interrupted, and came back had to either guess whether
98
+ * their quote was still good or throw it away and ask again. Guessing wrong means a 400 in the
99
+ * middle of a transaction; throwing it away means the price can move underneath them.
100
+ *
101
+ * `quote()` CREATES; this one READS. Requires `billing:read`.
102
+ */
103
+ async quoteById(id) {
104
+ const { data } = await this.http.get(`/v1/quote/${encodeURIComponent(id)}`);
105
+ // `seconds_remaining` is computed HERE rather than left to the caller.
106
+ //
107
+ // The question anyone reads a quote back to answer is "can I still use this?", and answering it
108
+ // from `expires_at` means parsing a timestamp and subtracting against a clock — three chances
109
+ // to get a timezone or a unit wrong, on a value that decides whether a submission is refused
110
+ // partway through the work. `null` when the gateway sent no expiry, which is not the same as
111
+ // zero and must not be mistaken for it.
112
+ return { ...data, seconds_remaining: secondsUntil(data?.expires_at) };
113
+ }
28
114
  /**
29
115
  * Pending intents and what they will cost — including `remaining_usd`, the
30
116
  * amount that may actually be committed to new work.
@@ -33,6 +119,139 @@ export class BillingResource {
33
119
  const { data } = await this.http.get('/v1/billing/obligations');
34
120
  return data;
35
121
  }
122
+ // ── Evidence ────────────────────────────────────────────────────────────────────────────────
123
+ //
124
+ // What was I charged, and can I prove it? These four endpoints existed on the gateway from the
125
+ // start and had no client surface at all — so the one question an enterprise finance or audit
126
+ // function actually asks could only be answered by hand-rolling HTTP. The evidence was there and
127
+ // unreachable, which for an auditor is the same as absent.
128
+ /**
129
+ * Every balance change, newest first. Requires `billing:read`.
130
+ *
131
+ * The append-only, double-entry record behind the balance: what moved, when, and why. Corrections
132
+ * appear as new REVERSING entries rather than edits, so the history is what happened.
133
+ *
134
+ * Use `ledgerAll()` to walk the whole thing.
135
+ */
136
+ async ledger(params = {}) {
137
+ const { data } = await this.http.get('/v1/billing/ledger', {
138
+ params: { limit: params.limit ?? 50, offset: params.offset ?? 0 },
139
+ });
140
+ return data;
141
+ }
142
+ /**
143
+ * Every ledger entry, paging automatically.
144
+ *
145
+ * ```ts
146
+ * for await (const entry of certen.billing.ledgerAll()) { ... }
147
+ * ```
148
+ *
149
+ * The endpoint returns no total and no `has_more`, so termination is inferred from a short page —
150
+ * which is why this belongs here once rather than in every caller that gets the condition subtly
151
+ * wrong and silently reports a partial ledger as complete.
152
+ */
153
+ ledgerAll(pageSize = 100) {
154
+ return paginate(async (limit, offset) => {
155
+ const page = await this.ledger({ limit, offset });
156
+ return { items: page.entries ?? [], hasMore: page.pagination?.has_more };
157
+ }, pageSize);
158
+ }
159
+ /** Signed receipts for every payment, charge, refund and adjustment. Requires `billing:read`. */
160
+ async receipts(params = {}) {
161
+ const { data } = await this.http.get('/v1/billing/receipts', {
162
+ params: { limit: params.limit ?? 50, offset: params.offset ?? 0 },
163
+ });
164
+ return data;
165
+ }
166
+ /** Every receipt, paging automatically. */
167
+ receiptsAll(pageSize = 100) {
168
+ return paginate(async (limit, offset) => {
169
+ const page = await this.receipts({ limit, offset });
170
+ return { items: page.receipts ?? [], hasMore: page.pagination?.has_more };
171
+ }, pageSize);
172
+ }
173
+ /**
174
+ * One receipt, with its signature, its computation inputs, and the gateway's own verification.
175
+ *
176
+ * `verification` is CERTEN checking CERTEN, which settles nothing by itself. What makes the
177
+ * receipt evidence is that every check in it is reproducible by you: verify `signature` against
178
+ * `verificationKeys()`, reproduce `digest` from `body`, and fetch `receiptProof()` to show the
179
+ * receipt is in a log that was anchored on Accumulate.
180
+ */
181
+ async receipt(id) {
182
+ const { data } = await this.http.get(`/v1/billing/receipts/${encodeURIComponent(id)}`);
183
+ return data;
184
+ }
185
+ /**
186
+ * The transparency-log inclusion proof for a receipt.
187
+ *
188
+ * **Store it alongside the receipt.** It remains valid forever against the tree head it names,
189
+ * and that head is pinned on Accumulate — so the proof outlives any cooperation from CERTEN,
190
+ * which is the entire point of it existing.
191
+ *
192
+ * Defaults to the newest ANCHORED head; a proof against an unanchored head is only as good as our
193
+ * word. Only receipts with `logged: true` have one — expect a 404 otherwise.
194
+ */
195
+ async receiptProof(id, params = {}) {
196
+ const { data } = await this.http.get(`/v1/billing/receipts/${encodeURIComponent(id)}/proof`, params.treeSize ? { params: { tree_size: params.treeSize } } : undefined);
197
+ return data;
198
+ }
199
+ /**
200
+ * The public keys receipts and tree heads are signed with.
201
+ *
202
+ * Deliberately unauthenticated on the gateway, and it should stay that way in your integration
203
+ * too: a verification key you can only obtain by asking us nicely could not settle a dispute
204
+ * with us.
205
+ */
206
+ async verificationKeys() {
207
+ const { data } = await this.http.get('/v1/billing/receipts/verification-key');
208
+ return data;
209
+ }
210
+ /**
211
+ * Check a receipt yourself, against independently published data.
212
+ *
213
+ * Recomputes the digest from the body, verifies the ed25519 signature against the PUBLISHED key
214
+ * set, recomputes the salted leaf, folds the RFC 6962 audit path, and compares the result with a
215
+ * signed tree head fetched separately — not with the root that travelled inside the proof, which
216
+ * would be comparing the proof with itself.
217
+ *
218
+ * Never throws for a failed check: `verified` is false and the reason is in `checks`. A check that
219
+ * could not be run is `skipped`, and `complete` goes false — a verifier that cannot reach the log
220
+ * must say so rather than imply a pass.
221
+ */
222
+ verifyReceipt(id) {
223
+ return verifyReceipt(this.client, id);
224
+ }
225
+ /**
226
+ * Register a wallet you pay from, so every future deposit from it credits automatically.
227
+ *
228
+ * This is the difference between funding once and funding repeatedly. `openPayment` opens a
229
+ * single-use intent matched on the EXACT amount within a TTL — right for a first deposit, and a
230
+ * step before every send thereafter. A registered address needs none of that: money arriving from
231
+ * it is attributed to this organization on sight.
232
+ *
233
+ * **The gateway's own 402 recommends doing this, and until now no client could.** Its `how_to_pay`
234
+ * block names `POST /v1/billing/deposit-addresses` as the recommended fix, while this SDK omitted
235
+ * it on the stated grounds that it needed a portal session rather than a machine key. That was
236
+ * wrong: the endpoint takes an API key with `billing:write`, which is exactly what an autonomous
237
+ * caller settling its own 402 is holding.
238
+ *
239
+ * An address belongs to ONE organization per chain. A duplicate is rejected rather than merged,
240
+ * because ambiguous attribution means crediting the wrong customer — expect a 409.
241
+ */
242
+ async registerPayerAddress(params) {
243
+ const { data } = await this.http.post('/v1/billing/deposit-addresses', {
244
+ chain: params.chain,
245
+ address: params.address,
246
+ ...(params.label ? { label: params.label } : {}),
247
+ });
248
+ return data;
249
+ }
250
+ /** Wallets registered for automatic attribution. Requires `billing:read`. */
251
+ async payerAddresses() {
252
+ const { data } = await this.http.get('/v1/billing/deposit-addresses');
253
+ return data;
254
+ }
36
255
  /**
37
256
  * Where to send stablecoin, optionally opening a single-use payment matched on
38
257
  * the exact amount.
@@ -55,9 +274,24 @@ export class BillingResource {
55
274
  * same window moves the balance too, so inferring from it reports the wrong
56
275
  * payment as matched.
57
276
  */
277
+ /**
278
+ * Payments the gateway has seen, most recent first.
279
+ *
280
+ * Distinct from a deposit INTENT. A payment can be credited without ever matching an intent —
281
+ * see `waitForPayment` — so this is the record that says whether money actually arrived.
282
+ */
283
+ async payments(params = {}) {
284
+ const { data } = await this.http.get('/v1/billing/payments', {
285
+ params: { limit: params.limit ?? 10 },
286
+ });
287
+ return data;
288
+ }
58
289
  async payment(reference) {
59
290
  const { data } = await this.http.get(`/v1/billing/deposits/${encodeURIComponent(reference)}`);
60
- return data.intent;
291
+ // The response IS the intent. It used to arrive under an `intent` key with nothing beside it,
292
+ // so the wrapper carried no information — the clearest case of the inconsistency the gateway's
293
+ // 2026-08 break removed.
294
+ return data;
61
295
  }
62
296
  /**
63
297
  * Resolve once the payment is credited, or when it expires.
@@ -65,16 +299,49 @@ export class BillingResource {
65
299
  * Returns the terminal status rather than throwing on expiry — an expired
66
300
  * payment is an ordinary outcome the caller should report, not an error. Only a
67
301
  * genuine transport or auth failure throws.
302
+ *
303
+ * **It watches the payment feed as well as the intent, and that is not belt-and-braces.**
304
+ *
305
+ * It began as a workaround for a gateway bug: the gateway closed a deposit intent only when the
306
+ * payment had been attributed BY that intent, and since attribution tries a registered payer
307
+ * address first — and the funding flow registers the sender — a paid intent was never closed.
308
+ * Observed live: 1 USDC credited in seconds with `attribution: registered_address` while the
309
+ * intent sat `open` with `matched_at: null`, until it expired an hour later. Watching only the
310
+ * intent reported "not credited" on money that had already arrived. The gateway now closes the
311
+ * intent on credit regardless of how the org was identified.
312
+ *
313
+ * The feed watch stays, for two reasons that outlive that bug. The SDK is versioned separately
314
+ * and is regularly pointed at an older gateway, where the old behaviour is still live. And the
315
+ * intent can only ever report money that matched it: a deposit for the wrong amount, or one sent
316
+ * before the intent was opened, still credits the balance and still answers the caller's actual
317
+ * question — did my money arrive.
318
+ *
319
+ * On that path the returned status is synthesised with `status: 'matched'` and the credited
320
+ * payment's id, because from the caller's point of view the money arrived.
68
321
  */
69
322
  async waitForPayment(reference, opts = {}) {
70
323
  const intervalMs = opts.intervalMs ?? 5_000;
71
324
  const timeoutMs = opts.timeoutMs ?? 60 * 60 * 1_000;
72
325
  const deadline = Date.now() + timeoutMs;
326
+ // Payments already credited before this wait started are not evidence for it. Anything at or
327
+ // after this instant is.
328
+ const since = Date.now();
73
329
  for (;;) {
74
330
  const status = await this.payment(reference);
75
331
  opts.onPoll?.(status);
76
332
  if (status.status !== 'open')
77
333
  return status;
334
+ const credited = await this.creditedSince(since, status.amount_usd);
335
+ if (credited) {
336
+ const matched = {
337
+ ...status,
338
+ status: 'matched',
339
+ matched_at: credited.created_at ?? new Date().toISOString(),
340
+ payment_id: credited.id ?? null,
341
+ };
342
+ opts.onPoll?.(matched);
343
+ return matched;
344
+ }
78
345
  if (new Date(status.expires_at).getTime() <= Date.now())
79
346
  return status;
80
347
  if (Date.now() >= deadline)
@@ -82,5 +349,28 @@ export class BillingResource {
82
349
  await new Promise((r) => setTimeout(r, intervalMs));
83
350
  }
84
351
  }
352
+ /**
353
+ * A credited payment of this amount that arrived after `since`, if there is one.
354
+ *
355
+ * Returns null on any failure: an unavailable payments feed must never turn a wait that would
356
+ * otherwise have succeeded into an error, and the intent poll above remains the primary signal.
357
+ */
358
+ async creditedSince(since, amountUsd) {
359
+ try {
360
+ const { payments } = await this.payments({ limit: 10 });
361
+ return (payments ?? []).find((p) => {
362
+ if (p.status !== 'credited')
363
+ return false;
364
+ if (String(p.amount_usd) !== String(amountUsd))
365
+ return false;
366
+ const at = Date.parse(String(p.created_at ?? ''));
367
+ // A missing timestamp cannot be placed in time, so it is not treated as evidence.
368
+ return Number.isFinite(at) && at >= since - 60_000;
369
+ }) ?? null;
370
+ }
371
+ catch {
372
+ return null;
373
+ }
374
+ }
85
375
  }
86
376
  //# sourceMappingURL=billing.js.map
@@ -1 +1 @@
1
- {"version":3,"file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