@certen.io/sdk 0.10.0 → 0.12.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 (80) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +57 -2
  3. package/dist/address.d.ts +12 -0
  4. package/dist/address.d.ts.map +1 -0
  5. package/dist/address.js +48 -0
  6. package/dist/address.js.map +1 -0
  7. package/dist/browser.d.ts +17 -4
  8. package/dist/browser.d.ts.map +1 -1
  9. package/dist/browser.js +14 -2
  10. package/dist/browser.js.map +1 -1
  11. package/dist/chains.d.ts +20 -0
  12. package/dist/chains.d.ts.map +1 -1
  13. package/dist/chains.js +34 -0
  14. package/dist/chains.js.map +1 -1
  15. package/dist/client.d.ts +15 -1
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +17 -3
  18. package/dist/client.js.map +1 -1
  19. package/dist/doctor.d.ts +10 -1
  20. package/dist/doctor.d.ts.map +1 -1
  21. package/dist/doctor.js +6 -4
  22. package/dist/doctor.js.map +1 -1
  23. package/dist/effect.d.ts +99 -0
  24. package/dist/effect.d.ts.map +1 -0
  25. package/dist/effect.js +139 -0
  26. package/dist/effect.js.map +1 -0
  27. package/dist/error-codes.d.ts.map +1 -1
  28. package/dist/error-codes.js +11 -0
  29. package/dist/error-codes.js.map +1 -1
  30. package/dist/errors.d.ts.map +1 -1
  31. package/dist/errors.js +3 -0
  32. package/dist/errors.js.map +1 -1
  33. package/dist/evm-rpc.d.ts +55 -0
  34. package/dist/evm-rpc.d.ts.map +1 -0
  35. package/dist/evm-rpc.js +126 -0
  36. package/dist/evm-rpc.js.map +1 -0
  37. package/dist/funding.d.ts +171 -0
  38. package/dist/funding.d.ts.map +1 -1
  39. package/dist/funding.js +190 -8
  40. package/dist/funding.js.map +1 -1
  41. package/dist/key-page.d.ts +67 -0
  42. package/dist/key-page.d.ts.map +1 -0
  43. package/dist/key-page.js +154 -0
  44. package/dist/key-page.js.map +1 -0
  45. package/dist/readiness.d.ts +133 -0
  46. package/dist/readiness.d.ts.map +1 -0
  47. package/dist/readiness.js +467 -0
  48. package/dist/readiness.js.map +1 -0
  49. package/dist/receipt.d.ts +233 -0
  50. package/dist/receipt.d.ts.map +1 -0
  51. package/dist/receipt.js +318 -0
  52. package/dist/receipt.js.map +1 -0
  53. package/dist/resources/chains.d.ts +14 -1
  54. package/dist/resources/chains.d.ts.map +1 -1
  55. package/dist/resources/chains.js +21 -0
  56. package/dist/resources/chains.js.map +1 -1
  57. package/dist/resources/execute.d.ts +62 -1
  58. package/dist/resources/execute.d.ts.map +1 -1
  59. package/dist/resources/execute.js +102 -9
  60. package/dist/resources/execute.js.map +1 -1
  61. package/dist/resources/identity.d.ts +47 -2
  62. package/dist/resources/identity.d.ts.map +1 -1
  63. package/dist/resources/identity.js +63 -1
  64. package/dist/resources/identity.js.map +1 -1
  65. package/dist/resources/transaction.d.ts +12 -1
  66. package/dist/resources/transaction.d.ts.map +1 -1
  67. package/dist/resources/transaction.js +14 -0
  68. package/dist/resources/transaction.js.map +1 -1
  69. package/dist/shared-proof.d.ts.map +1 -1
  70. package/dist/shared-proof.js +21 -1
  71. package/dist/shared-proof.js.map +1 -1
  72. package/dist/types.d.ts +207 -0
  73. package/dist/types.d.ts.map +1 -1
  74. package/dist/verify.d.ts +126 -2
  75. package/dist/verify.d.ts.map +1 -1
  76. package/dist/verify.js +191 -2
  77. package/dist/verify.js.map +1 -1
  78. package/dist/version.d.ts +1 -1
  79. package/dist/version.js +1 -1
  80. package/package.json +1 -1
@@ -0,0 +1,233 @@
1
+ import type { CertenClient } from './client.js';
2
+ import { type IntentOutcomeName, type IntentStatusClass } from './intent-states.js';
3
+ import { type ReceiptEffect, type RecipientSnapshot } from './effect.js';
4
+ import type { ChainsListResponse, TransactionResponse } from './types.js';
5
+ /**
6
+ * The receipt: the one record the docs have always told people to keep, assembled for them.
7
+ *
8
+ * After a transfer the walkthrough sent a person to four commands (`tx status`, `proof get`, `proof verify`, `proof verify --rpc`) and a
9
+ * hand-comparison, to find out what happened and to write down the intent id, the Accumulate transaction, the destination transaction and
10
+ * the proof. Every one of those facts was already in a response. This puts them in one document, says which are established and which are
11
+ * not, and gives the document a version so a script can rely on its shape.
12
+ *
13
+ * **This module is pure.** It takes what was fetched and verified and returns the record; it makes no request. The fetching and the
14
+ * verifying are `buildReceipt` in `@certen.io/sdk/verify`, which needs the verifier, and nothing here does.
15
+ *
16
+ * **The verdict is the weakest honest reading, and it has five values** (`ReceiptVerdict`):
17
+ * - `verified`: the action completed, the proof verifies, and nothing the receipt checked contradicts it;
18
+ * - `partial`: it completed, and something is not established. The gaps are named, one by one, in `gaps`. PARTIAL and NO EVIDENCE are
19
+ * never shown as verified, here or anywhere that renders this;
20
+ * - `failed`: the intent failed, or a layer of the proof was checked and does not hold;
21
+ * - `pending`: it has not finished, or it executed and the proof is still being produced;
22
+ * - `unproven`: it executed and its proof can never be produced (declared by an operator). Nothing can be verified, and it says so.
23
+ *
24
+ * **Unknown is not OK.** A proof that could not be fetched is `unavailable`, a recipient that could not be read is `unreadable`; neither is
25
+ * ever turned into `verified` or `confirmed` by the absence of bad news.
26
+ */
27
+ export declare const RECEIPT_VERSION = 1;
28
+ export type ReceiptVerdict = 'verified' | 'partial' | 'failed' | 'pending' | 'unproven';
29
+ export type ProofVerdict = 'verified' | 'partial' | 'failed' | 'no_evidence' | 'pending' | 'unavailable' | 'not_applicable';
30
+ export type StageState = 'done' | 'pending' | 'failed' | 'unknown' | 'skipped';
31
+ export interface ReceiptRequest {
32
+ kind: 'transfer' | 'contract_call' | 'intent';
33
+ chain: string;
34
+ chain_id: number | null;
35
+ identity_id: string;
36
+ adi_url: string | null;
37
+ from: string | null;
38
+ to: string | null;
39
+ /** Whole units; null for a call that forwards no value or a request that is not a transfer. */
40
+ amount: string | null;
41
+ asset: string | null;
42
+ contract_call: {
43
+ target: string;
44
+ function_signature: string;
45
+ value_wei: string;
46
+ } | null;
47
+ }
48
+ export interface ReceiptSigner {
49
+ key: string | null;
50
+ public_key_hash: string | null;
51
+ }
52
+ export interface ReceiptStage {
53
+ id: 'signed' | 'anchored' | 'executed' | 'proof_verified';
54
+ label: string;
55
+ state: StageState;
56
+ detail?: string;
57
+ }
58
+ export interface ReceiptProofLayer {
59
+ id: string;
60
+ title: string;
61
+ verdict: 'verified' | 'failed' | 'not_checked' | 'not_in_document';
62
+ reason?: string;
63
+ /** The statement of the proof format this layer establishes (`S6`), when the verifier names one. */
64
+ statement?: string;
65
+ /** What it was checked against (hashes, heights, counts). For `certen receipt --explain`. */
66
+ evidence?: Record<string, unknown>;
67
+ }
68
+ export interface ReceiptProof {
69
+ verdict: ProofVerdict;
70
+ detail: string;
71
+ /** True only when a verifier ran in this process over bytes the gateway served. */
72
+ checked_here: boolean;
73
+ /** True when the bundle's receipts root and block hash were compared with a header from a node the caller named. */
74
+ node_checked: boolean;
75
+ layers: ReceiptProofLayer[];
76
+ /** Layers the document carries (everything not `not_in_document`), and how many of those were verified. */
77
+ layers_total: number;
78
+ layers_verified: number;
79
+ layers_not_carried: number;
80
+ /** The carried layers that are not established, with the reason each gives. */
81
+ not_established: Array<{
82
+ id: string;
83
+ title: string;
84
+ reason: string;
85
+ }>;
86
+ proof_id: string | null;
87
+ evidence: {
88
+ found: boolean;
89
+ code?: string;
90
+ reason?: string;
91
+ bundle_error?: string;
92
+ };
93
+ }
94
+ export interface ReceiptGap {
95
+ code: 'INTENT_NOT_TERMINAL' | 'PROOF_PENDING' | 'PROOF_NOT_FETCHED' | 'PROOF_NO_EVIDENCE' | 'PROOF_LAYER_NOT_ESTABLISHED' | 'PROOF_LAYER_FAILED' | 'NODE_NOT_CONSULTED' | 'EFFECT_UNCHECKED' | 'EFFECT_UNREADABLE' | 'EFFECT_NOT_OBSERVED';
96
+ text: string;
97
+ }
98
+ export interface Receipt {
99
+ receipt_version: typeof RECEIPT_VERSION;
100
+ intent_id: string;
101
+ kind: ReceiptRequest['kind'] | 'unknown';
102
+ created_at: string;
103
+ updated_at: string;
104
+ gateway: string | null;
105
+ request: ReceiptRequest | null;
106
+ signed_with: ReceiptSigner | null;
107
+ status: {
108
+ gateway_status: string;
109
+ class: IntentStatusClass;
110
+ outcome: IntentOutcomeName;
111
+ terminal: boolean;
112
+ reason_code: string | null;
113
+ reason: string | null;
114
+ completion_basis: string | null;
115
+ validator_state: string | null;
116
+ };
117
+ ids: {
118
+ intent_id: string;
119
+ accumulate_tx: string | null;
120
+ accumulate_tx_hash: string | null;
121
+ destination_tx: string | null;
122
+ /** Where the destination hash came from: the verified execution proof, or the validators' own record. Never a guess. */
123
+ destination_tx_source: 'proof' | 'validators' | null;
124
+ destination_chain: string | null;
125
+ destination_block: number | null;
126
+ proof_id: string | null;
127
+ write_back_tx: string | null;
128
+ };
129
+ links: {
130
+ destination_tx: string | null;
131
+ accumulate_explorer: string | null;
132
+ };
133
+ stages: ReceiptStage[];
134
+ effect: ReceiptEffect;
135
+ proof: ReceiptProof;
136
+ verdict: ReceiptVerdict;
137
+ /** One line, in plain words, that a person can read instead of the rest. */
138
+ headline: string;
139
+ /** What is not established, one entry each. Empty exactly when `verdict` is `verified` (or `unproven`, where nothing can be). */
140
+ gaps: ReceiptGap[];
141
+ /** The recipient's balance taken before signing, kept so a later `receipt --rpc` can still measure the rise. */
142
+ recipient_snapshot: RecipientSnapshot | null;
143
+ }
144
+ /** What `verifyBundle` (from `@certen.io/sdk/verify`) returns, in the part this module reads. Structural, so no verifier is imported here. */
145
+ export interface VerificationLike {
146
+ overall: 'verified' | 'partial' | 'failed' | 'no_evidence';
147
+ layers: Array<{
148
+ id: string;
149
+ title: string;
150
+ verdict: 'verified' | 'failed' | 'not_checked' | 'not_in_document';
151
+ reason?: string;
152
+ statement?: string;
153
+ evidence?: Record<string, unknown>;
154
+ }>;
155
+ failure?: {
156
+ layer: string;
157
+ message: string;
158
+ };
159
+ evidenceFound: boolean;
160
+ execution?: {
161
+ ok: boolean;
162
+ txHash: string;
163
+ blockNumber: number;
164
+ chainId: string;
165
+ } | null;
166
+ headerCheck?: {
167
+ ok: boolean;
168
+ } | null;
169
+ }
170
+ export interface ReceiptProofInput {
171
+ /** The verdict, or null when no verification was attempted or it could not be. */
172
+ verification: VerificationLike | null;
173
+ /** The gateway served no portable document: why. */
174
+ notServed?: {
175
+ code: string;
176
+ reason: string;
177
+ } | null;
178
+ bundleError?: string | null;
179
+ /** The evidence could not be fetched at all (a network failure, a 5xx): why. Not the same as there being none. */
180
+ unavailable?: string | null;
181
+ /** A header from the caller's own node was compared. */
182
+ nodeConsulted?: boolean;
183
+ /** A node was given and could not be used (unreachable, or not answering as a node): why. The proof was checked without it. */
184
+ nodeError?: string | null;
185
+ }
186
+ export interface AssembleReceiptInput {
187
+ intentId: string;
188
+ transaction: TransactionResponse;
189
+ request?: ReceiptRequest | null;
190
+ signedWith?: ReceiptSigner | null;
191
+ gateway?: string | null;
192
+ registry?: Pick<ChainsListResponse, 'accumulate' | 'chains'> | null;
193
+ proof?: ReceiptProofInput | null;
194
+ effect?: ReceiptEffect | null;
195
+ snapshot?: RecipientSnapshot | null;
196
+ /** An earlier receipt for the same intent: its creation time and request are kept, so a refresh never forgets what was asked. */
197
+ previous?: Receipt | null;
198
+ now?: () => Date;
199
+ }
200
+ /**
201
+ * Put everything known about one intent into a receipt.
202
+ *
203
+ * Idempotent in the sense that matters: assembling again from fresher inputs (a proof that has since been served, a node that is now
204
+ * given) replaces what was uncertain and keeps `created_at`, the request and the pre-signing snapshot.
205
+ */
206
+ export declare function assembleReceipt(input: AssembleReceiptInput): Receipt;
207
+ export interface FeeEstimate {
208
+ state: 'estimated' | 'unavailable';
209
+ sku: string;
210
+ chain: string;
211
+ /** The platform's own fee, USD. Null when the price book has no entry. */
212
+ platform_fee_usd: string | null;
213
+ /** `flat` is all-in; `quoted` adds gas dynamically at execution, so this is the platform component only. */
214
+ mode: string | null;
215
+ max_charge_usd: string | null;
216
+ /** The catalogue's gas reserve for the chain, whole native units: an estimate, not a quote. */
217
+ gas_reserve: string | null;
218
+ gas_symbol: string | null;
219
+ price_book_version: string | null;
220
+ /** Always says it is an estimate. */
221
+ note: string;
222
+ }
223
+ /** The price-book entry for a proof-gated execution. */
224
+ export declare const EXECUTION_SKU = "proof.execute";
225
+ /**
226
+ * What a send will cost, as far as the gateway has published it.
227
+ *
228
+ * The price book, not a quote: `POST /v1/quote` creates a binding quote and the gateway publishes no per-execution gas figure (PLAN G5), so the
229
+ * most that can be said before signing is the platform's own fee and a reserve for gas. Both are labelled estimates wherever they are shown.
230
+ * Never throws: a price book that cannot be read is "unavailable", and the card says so rather than showing a number it does not have.
231
+ */
232
+ export declare function estimateFee(client: Pick<CertenClient, 'billing'>, chain: string): Promise<FeeEstimate>;
233
+ //# sourceMappingURL=receipt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt.d.ts","sourceRoot":"","sources":["../src/receipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EAAiB,KAAK,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAmB,KAAK,aAAa,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AACxF,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,SAAS,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAC5H,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/E,MAAM,WAAW,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,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAuB5G"}
@@ -0,0 +1,318 @@
1
+ import { chainInfo, chainSlug, gasReserveFor, nativeSymbolFor } from './chains.js';
2
+ import { describeReasonCode } from './reason-codes.js';
3
+ import { intentOutcome } from './intent-states.js';
4
+ import { noEffectToCheck } from './effect.js';
5
+ /**
6
+ * The receipt: the one record the docs have always told people to keep, assembled for them.
7
+ *
8
+ * After a transfer the walkthrough sent a person to four commands (`tx status`, `proof get`, `proof verify`, `proof verify --rpc`) and a
9
+ * hand-comparison, to find out what happened and to write down the intent id, the Accumulate transaction, the destination transaction and
10
+ * the proof. Every one of those facts was already in a response. This puts them in one document, says which are established and which are
11
+ * not, and gives the document a version so a script can rely on its shape.
12
+ *
13
+ * **This module is pure.** It takes what was fetched and verified and returns the record; it makes no request. The fetching and the
14
+ * verifying are `buildReceipt` in `@certen.io/sdk/verify`, which needs the verifier, and nothing here does.
15
+ *
16
+ * **The verdict is the weakest honest reading, and it has five values** (`ReceiptVerdict`):
17
+ * - `verified`: the action completed, the proof verifies, and nothing the receipt checked contradicts it;
18
+ * - `partial`: it completed, and something is not established. The gaps are named, one by one, in `gaps`. PARTIAL and NO EVIDENCE are
19
+ * never shown as verified, here or anywhere that renders this;
20
+ * - `failed`: the intent failed, or a layer of the proof was checked and does not hold;
21
+ * - `pending`: it has not finished, or it executed and the proof is still being produced;
22
+ * - `unproven`: it executed and its proof can never be produced (declared by an operator). Nothing can be verified, and it says so.
23
+ *
24
+ * **Unknown is not OK.** A proof that could not be fetched is `unavailable`, a recipient that could not be read is `unreadable`; neither is
25
+ * ever turned into `verified` or `confirmed` by the absence of bad news.
26
+ */
27
+ export const RECEIPT_VERSION = 1;
28
+ const HEX64 = /([a-f0-9]{64})/i;
29
+ const proofIdOf = (tx) => (typeof tx.proof_id === 'string' && tx.proof_id ? tx.proof_id : null);
30
+ function explorerTxUrl(registry, chain, hash) {
31
+ if (!registry || !chain || !hash)
32
+ return null;
33
+ // A registry that came back malformed costs the link and nothing else: a receipt must not fail to exist because an explorer URL could not be built.
34
+ const entry = Array.isArray(registry.chains) ? registry.chains.find((c) => chainSlug(c.id) === chainSlug(chain)) : undefined;
35
+ // Only an EVM explorer has a path this module is sure of; other families differ enough that a guessed path would 404.
36
+ if (!entry || entry.family !== 'evm' || !entry.explorer)
37
+ return null;
38
+ return `${entry.explorer.replace(/\/+$/, '')}/tx/${hash}`;
39
+ }
40
+ /** The weakest honest reading of the proof, from what was fetched and verified. */
41
+ function proofOf(outcome, input, proofId) {
42
+ const base = { proof_id: proofId, layers: [], layers_total: 0, layers_verified: 0, layers_not_carried: 0, not_established: [] };
43
+ const noEvidence = (extra = {}) => ({ found: false, ...extra });
44
+ if (outcome.outcome === 'failed') {
45
+ return { ...base, verdict: 'not_applicable', detail: 'The intent failed, so there is no execution to prove.', checked_here: false, node_checked: false, evidence: noEvidence() };
46
+ }
47
+ if (outcome.outcome === 'completed_unproven') {
48
+ return {
49
+ ...base, verdict: 'not_applicable', checked_here: false, node_checked: false, evidence: noEvidence(),
50
+ detail: 'The action executed and its proof can never be produced (declared by an operator with the evidence). Nothing can be verified for it.',
51
+ };
52
+ }
53
+ if (outcome.outcome === 'pending' || outcome.outcome === 'unknown') {
54
+ return { ...base, verdict: 'pending', detail: 'The intent has not finished, so there is nothing to prove yet.', checked_here: false, node_checked: false, evidence: noEvidence() };
55
+ }
56
+ if (outcome.outcome === 'executed') {
57
+ return { ...base, verdict: 'pending', detail: 'The action executed on its chain and its proof bundle is still being produced.', checked_here: false, node_checked: false, evidence: noEvidence() };
58
+ }
59
+ // completed: the proof is what makes that claim checkable.
60
+ const v = input?.verification ?? null;
61
+ if (!v) {
62
+ const why = input?.unavailable ?? 'no verification was made';
63
+ return { ...base, verdict: 'unavailable', detail: `The proof could not be checked: ${why}.`, checked_here: false, node_checked: false, evidence: noEvidence({ reason: why }) };
64
+ }
65
+ const layers = v.layers.map((l) => ({
66
+ id: l.id, title: l.title, verdict: l.verdict, ...(l.reason ? { reason: l.reason } : {}),
67
+ ...(l.statement ? { statement: l.statement } : {}), ...(l.evidence && Object.keys(l.evidence).length > 0 ? { evidence: l.evidence } : {}),
68
+ }));
69
+ const carried = layers.filter((l) => l.verdict !== 'not_in_document');
70
+ const verified = carried.filter((l) => l.verdict === 'verified').length;
71
+ const notEstablished = carried.filter((l) => l.verdict === 'not_checked').map((l) => ({ id: l.id, title: l.title, reason: l.reason ?? 'not established' }));
72
+ const evidence = {
73
+ found: v.evidenceFound,
74
+ ...(input?.notServed ? { code: input.notServed.code, reason: input.notServed.reason } : {}),
75
+ ...(input?.bundleError ? { bundle_error: input.bundleError } : {}),
76
+ };
77
+ const common = {
78
+ proof_id: proofId, layers, layers_total: carried.length, layers_verified: verified, layers_not_carried: layers.length - carried.length,
79
+ not_established: notEstablished, checked_here: true, node_checked: Boolean(input?.nodeConsulted && v.headerCheck), evidence,
80
+ };
81
+ if (v.overall === 'verified') {
82
+ return { ...common, verdict: 'verified', detail: `${verified} of ${carried.length} layers carried, all checked here from the proof's own bytes.` };
83
+ }
84
+ if (v.overall === 'failed') {
85
+ return { ...common, verdict: 'failed', detail: `A layer was checked and does not hold: ${v.failure?.layer ?? 'unknown'}: ${v.failure?.message ?? 'failed'}.` };
86
+ }
87
+ if (v.overall === 'no_evidence') {
88
+ return { ...common, verdict: 'no_evidence', detail: input?.notServed ? `${input.notServed.code}: ${input.notServed.reason}` : 'Nothing about the Accumulate side could be checked.' };
89
+ }
90
+ return {
91
+ ...common, verdict: 'partial',
92
+ detail: `${verified} of ${carried.length} layers carried are established; ${notEstablished.map((l) => l.id).join(', ') || 'a layer'} ${notEstablished.length === 1 ? 'is' : 'are'} not.`,
93
+ };
94
+ }
95
+ function stagesOf(outcome, tx, proof, ids, chain) {
96
+ const on = chain ? ` on ${chain}` : '';
97
+ const beyondSigning = !['created', 'signing_required', ''].includes(outcome.status);
98
+ const failed = outcome.outcome === 'failed';
99
+ const ranOnChain = outcome.outcome === 'executed' || outcome.outcome === 'completed' || outcome.outcome === 'completed_unproven';
100
+ const hasAccum = Boolean(ids.accumulate_tx_hash);
101
+ const signed = failed && !hasAccum
102
+ ? { id: 'signed', label: 'signed', state: 'unknown', detail: 'the intent failed before an Accumulate transaction was recorded' }
103
+ : { id: 'signed', label: 'signed', state: beyondSigning ? 'done' : 'pending' };
104
+ const anchored = ranOnChain
105
+ ? { id: 'anchored', label: 'anchored on Accumulate', state: 'done', ...(ids.accumulate_tx_hash ? { detail: ids.accumulate_tx_hash } : {}) }
106
+ : failed ? { id: 'anchored', label: 'anchored on Accumulate', state: hasAccum ? 'unknown' : 'skipped' }
107
+ : { id: 'anchored', label: 'anchored on Accumulate', state: beyondSigning ? 'pending' : 'skipped' };
108
+ const executed = ranOnChain
109
+ ? { id: 'executed', label: `executed${on}`, state: 'done', ...(ids.destination_tx ? { detail: ids.destination_tx } : {}) }
110
+ : failed ? { id: 'executed', label: `executed${on}`, state: 'failed', detail: outcome.reason ? describeReasonCode(outcome.reason) ?? outcome.reason : tx.error_message ?? undefined }
111
+ : { id: 'executed', label: `executed${on}`, state: 'pending' };
112
+ const stateOfProof = proof.verdict === 'verified' ? 'done'
113
+ : proof.verdict === 'failed' ? 'failed'
114
+ : proof.verdict === 'pending' ? 'pending'
115
+ : proof.verdict === 'not_applicable' ? 'skipped'
116
+ : 'unknown';
117
+ const verifiedStage = { id: 'proof_verified', label: 'proof verified locally', state: stateOfProof, ...(proof.verdict === 'verified' ? {} : { detail: proof.detail }) };
118
+ return [signed, anchored, executed, verifiedStage];
119
+ }
120
+ /**
121
+ * Put everything known about one intent into a receipt.
122
+ *
123
+ * Idempotent in the sense that matters: assembling again from fresher inputs (a proof that has since been served, a node that is now
124
+ * given) replaces what was uncertain and keeps `created_at`, the request and the pre-signing snapshot.
125
+ */
126
+ export function assembleReceipt(input) {
127
+ const now = (input.now?.() ?? new Date()).toISOString();
128
+ const tx = input.transaction;
129
+ const outcome = intentOutcome(tx);
130
+ const previous = input.previous ?? null;
131
+ const request = input.request ?? previous?.request ?? null;
132
+ const proofId = proofIdOf(tx) ?? previous?.ids.proof_id ?? null;
133
+ const proof = proofOf(outcome, input.proof, proofId);
134
+ const verification = input.proof?.verification ?? null;
135
+ const execution = verification?.execution && verification.execution.ok ? verification.execution : null;
136
+ const members = tx.validator?.members ?? [];
137
+ const settlement = members.find((m) => typeof m.settlement_tx === 'string' && m.settlement_tx)?.settlement_tx ?? null;
138
+ const destinationTx = execution?.txHash ?? settlement ?? previous?.ids.destination_tx ?? null;
139
+ const source = execution?.txHash ? 'proof' : settlement ? 'validators' : previous?.ids.destination_tx ? previous.ids.destination_tx_source : null;
140
+ const executionChain = execution ? chainInfo(execution.chainId)?.slug ?? null : null;
141
+ const memberChain = members[0]?.chain_id !== undefined ? chainInfo(members[0].chain_id)?.slug ?? null : null;
142
+ const destinationChain = request ? chainSlug(request.chain) : executionChain ?? memberChain ?? previous?.ids.destination_chain ?? null;
143
+ const accumTx = typeof tx.accum_tx_hash === 'string' && tx.accum_tx_hash ? tx.accum_tx_hash : previous?.ids.accumulate_tx ?? null;
144
+ const writeBack = tx.proofs?.find((p) => p.write_back_tx)?.write_back_tx ?? members.find((m) => m.write_back_tx)?.write_back_tx ?? previous?.ids.write_back_tx ?? null;
145
+ const ids = {
146
+ intent_id: input.intentId,
147
+ accumulate_tx: accumTx,
148
+ accumulate_tx_hash: accumTx ? accumTx.match(HEX64)?.[1]?.toLowerCase() ?? null : null,
149
+ destination_tx: destinationTx,
150
+ destination_tx_source: source,
151
+ destination_chain: destinationChain,
152
+ destination_block: execution?.blockNumber ?? previous?.ids.destination_block ?? null,
153
+ proof_id: proofId,
154
+ write_back_tx: writeBack,
155
+ };
156
+ // Nothing supplied is not "nothing to check": a transfer has an effect, and not looking at it is UNCHECKED, which keeps a receipt from being
157
+ // verified. A call with no expected event, or an intent with no request on record, has nothing to compare, and says so.
158
+ // Says what is true: a failed intent has nothing to compare; one that has not finished has not been looked at YET; only a finished transfer
159
+ // that nobody checked is "not checked".
160
+ const effect = input.effect ?? previous?.effect ?? (request?.kind === 'transfer'
161
+ ? outcome.outcome === 'failed'
162
+ ? noEffectToCheck('The intent failed, so there is no transfer to check.')
163
+ : { kind: 'native_transfer', state: 'unchecked', amount: request.amount ?? undefined, detail: outcome.outcome === 'completed' || outcome.outcome === 'completed_unproven'
164
+ ? 'The effect of this transfer was not checked.' : 'Not checked yet: the transfer has not completed.' }
165
+ : noEffectToCheck(request?.kind === 'contract_call'
166
+ ? 'A contract call has no balance to compare; pass an expected event to check one.'
167
+ : 'There is no request on record to check an effect against.'));
168
+ const stages = stagesOf(outcome, tx, proof, ids, destinationChain);
169
+ // ── gaps: what is not established, one by one ────────────────────────────────────────────────────────
170
+ const gaps = [];
171
+ if (outcome.outcome === 'pending' || outcome.outcome === 'unknown') {
172
+ gaps.push({ code: 'INTENT_NOT_TERMINAL', text: `The intent is still ${outcome.status || 'unknown'}; it has not finished.` });
173
+ }
174
+ else if (outcome.outcome === 'executed') {
175
+ gaps.push({ code: 'PROOF_PENDING', text: 'The action executed; its proof bundle is still being produced.' });
176
+ }
177
+ else if (outcome.outcome === 'completed') {
178
+ if (proof.verdict === 'unavailable')
179
+ gaps.push({ code: 'PROOF_NOT_FETCHED', text: proof.detail });
180
+ if (proof.verdict === 'no_evidence')
181
+ gaps.push({ code: 'PROOF_NO_EVIDENCE', text: proof.detail });
182
+ if (proof.verdict === 'failed')
183
+ gaps.push({ code: 'PROOF_LAYER_FAILED', text: proof.detail });
184
+ const outcomeLayer = proof.layers.find((l) => l.id === 'outcome');
185
+ const nodeGap = Boolean(outcomeLayer && outcomeLayer.verdict === 'not_checked' && !proof.node_checked);
186
+ for (const l of proof.not_established) {
187
+ // With no evidence at all every layer reads "not checked" for the one same reason, which PROOF_NO_EVIDENCE already states: eleven copies
188
+ // of it would bury the single fact.
189
+ if (proof.verdict === 'no_evidence')
190
+ break;
191
+ // The execution layer's own reason ("until it is compared with a header from your own RPC") is the node gap below, which says it with
192
+ // the actionable cause; listing both would be the same fact twice.
193
+ if (l.id === 'outcome' && nodeGap)
194
+ continue;
195
+ gaps.push({ code: 'PROOF_LAYER_NOT_ESTABLISHED', text: `${l.title} (${l.id}): ${l.reason}` });
196
+ }
197
+ if (nodeGap) {
198
+ gaps.push({
199
+ code: 'NODE_NOT_CONSULTED',
200
+ text: input.proof?.nodeError
201
+ ? `The node you gave could not be used (${input.proof.nodeError}), so the execution layer rests on the validators' own statement of the block.`
202
+ : 'The execution layer rests on the validators\' own statement of the block until it is compared with a header from a node you trust.',
203
+ });
204
+ }
205
+ if (effect.state === 'unchecked')
206
+ gaps.push({ code: 'EFFECT_UNCHECKED', text: effect.detail });
207
+ if (effect.state === 'unreadable')
208
+ gaps.push({ code: 'EFFECT_UNREADABLE', text: effect.detail });
209
+ if (effect.state === 'not_observed')
210
+ gaps.push({ code: 'EFFECT_NOT_OBSERVED', text: effect.detail });
211
+ }
212
+ // ── the verdict: the weakest honest reading ─────────────────────────────────────────────────────────
213
+ let verdict;
214
+ let headline;
215
+ if (outcome.outcome === 'failed') {
216
+ verdict = 'failed';
217
+ const why = outcome.reason ? describeReasonCode(outcome.reason) ?? outcome.reason : tx.error_message;
218
+ headline = `FAILED: the intent ${outcome.status}${why ? `. ${why}` : ''}`;
219
+ }
220
+ else if (outcome.outcome === 'completed_unproven') {
221
+ verdict = 'unproven';
222
+ headline = 'EXECUTED, NOT PROVABLE: the action ran and its proof can never be produced. Nothing is verified for it.';
223
+ }
224
+ else if (outcome.outcome !== 'completed') {
225
+ verdict = 'pending';
226
+ headline = outcome.outcome === 'executed' ? 'PENDING: executed; the proof is still being produced' : `PENDING: the intent is ${outcome.status || 'not finished'}`;
227
+ }
228
+ else if (proof.verdict === 'failed') {
229
+ verdict = 'failed';
230
+ headline = `FAILED: ${proof.detail} Do not rely on this proof.`;
231
+ }
232
+ else if (proof.verdict === 'verified' && (effect.state === 'confirmed' || effect.state === 'not_applicable')) {
233
+ verdict = 'verified';
234
+ headline = `VERIFIED: ${proof.layers_verified} of ${proof.layers_total} layers carried, checked here`;
235
+ }
236
+ else if (proof.verdict === 'verified') {
237
+ // The proof holds and the second look at the value does not agree, or could not be made. Unknown is not ok: a receipt that says VERIFIED
238
+ // over a balance nobody read would be the lie this exists to avoid, so it is PARTIAL, naming which.
239
+ verdict = 'partial';
240
+ headline = `PARTIAL: the proof verifies, but ${effect.state === 'not_observed'
241
+ ? 'the recipient\'s balance did not rise as expected'
242
+ : effect.state === 'unreadable' ? 'the recipient\'s balance could not be read' : 'the recipient\'s balance was not checked'}`;
243
+ }
244
+ else {
245
+ verdict = 'partial';
246
+ headline = proof.verdict === 'partial' ? `PARTIAL: ${proof.detail}`
247
+ : proof.verdict === 'no_evidence' ? `NO EVIDENCE: ${proof.detail}`
248
+ : `PARTIAL: ${proof.detail}`;
249
+ }
250
+ return {
251
+ receipt_version: RECEIPT_VERSION,
252
+ intent_id: input.intentId,
253
+ kind: request?.kind ?? previous?.kind ?? 'unknown',
254
+ created_at: previous?.created_at ?? now,
255
+ updated_at: now,
256
+ gateway: input.gateway ?? previous?.gateway ?? null,
257
+ request,
258
+ signed_with: input.signedWith ?? previous?.signed_with ?? null,
259
+ status: {
260
+ gateway_status: outcome.status,
261
+ class: outcome.class,
262
+ outcome: outcome.outcome,
263
+ terminal: outcome.terminal,
264
+ reason_code: typeof tx.reason_code === 'string' && tx.reason_code ? tx.reason_code : null,
265
+ reason: outcome.reason,
266
+ completion_basis: typeof tx.completion_basis === 'string' && tx.completion_basis ? tx.completion_basis : null,
267
+ validator_state: tx.validator?.state ?? null,
268
+ },
269
+ ids,
270
+ links: {
271
+ destination_tx: explorerTxUrl(input.registry, destinationChain, destinationTx),
272
+ accumulate_explorer: input.registry?.accumulate?.explorer ?? null,
273
+ },
274
+ stages,
275
+ effect,
276
+ proof,
277
+ verdict,
278
+ headline,
279
+ gaps,
280
+ recipient_snapshot: input.snapshot ?? previous?.recipient_snapshot ?? null,
281
+ };
282
+ }
283
+ /** The price-book entry for a proof-gated execution. */
284
+ export const EXECUTION_SKU = 'proof.execute';
285
+ /**
286
+ * What a send will cost, as far as the gateway has published it.
287
+ *
288
+ * The price book, not a quote: `POST /v1/quote` creates a binding quote and the gateway publishes no per-execution gas figure (PLAN G5), so the
289
+ * most that can be said before signing is the platform's own fee and a reserve for gas. Both are labelled estimates wherever they are shown.
290
+ * Never throws: a price book that cannot be read is "unavailable", and the card says so rather than showing a number it does not have.
291
+ */
292
+ export async function estimateFee(client, chain) {
293
+ const slug = chainSlug(chain);
294
+ const gas = gasReserveFor(slug) ?? null;
295
+ const symbol = nativeSymbolFor(slug) ?? null;
296
+ const unavailable = (why, version = null) => ({
297
+ state: 'unavailable', sku: EXECUTION_SKU, chain: slug, platform_fee_usd: null, mode: null, max_charge_usd: null, gas_reserve: gas, gas_symbol: symbol,
298
+ price_book_version: version, note: `Not available: ${why}. The fee is estimated only from the price book (certen pricing), never quoted.`,
299
+ });
300
+ try {
301
+ const book = await client.billing.pricing();
302
+ const items = (book.items ?? []).filter((i) => i.sku === EXECUTION_SKU);
303
+ const item = items.find((i) => chainSlug(i.chain) === slug) ?? items.find((i) => i.chain === '*');
304
+ if (!item)
305
+ return unavailable(`the price book has no ${EXECUTION_SKU} entry for ${slug}`, book.price_book_version ?? null);
306
+ return {
307
+ state: 'estimated', sku: EXECUTION_SKU, chain: slug, platform_fee_usd: item.platform_fee_usd ?? null, mode: item.mode ?? null,
308
+ max_charge_usd: item.max_charge_usd ?? null, gas_reserve: gas, gas_symbol: symbol, price_book_version: book.price_book_version ?? null,
309
+ note: item.mode === 'quoted'
310
+ ? 'An estimate from the price book: the platform fee only. Gas is priced when it executes, up to a ceiling.'
311
+ : 'An estimate from the price book, not a binding quote.',
312
+ };
313
+ }
314
+ catch (err) {
315
+ return unavailable(err instanceof Error ? err.message.replace(/^certen: /, '') : 'the price book could not be read');
316
+ }
317
+ }
318
+ //# sourceMappingURL=receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receipt.js","sourceRoot":"","s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IAAI,IAAI,IAAI;YAC7H,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,IAAI,IAAI;YACtI,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,QAAQ;gBAC1B,CAAC,CAAC,0GAA0G;gBAC5G,CAAC,CAAC,uDAAuD;SAC5D,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,WAAW,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC;IACvH,CAAC;AACH,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import type { ChainsListResponse, ChainDetailResponse } from '../types.js';
2
+ import type { ChainsListResponse, ChainDetailResponse, AddressBalanceResponse } from '../types.js';
3
3
  import { type ChainCatalogueEntry } from '../chains.js';
4
4
  /**
5
5
  * The contract registry: which chains CERTEN is deployed on, and at what addresses.
@@ -35,6 +35,19 @@ export declare class ChainsResource {
35
35
  * handed them, and making them translate is a step that buys nothing.
36
36
  */
37
37
  get(idOrChainId: string | number): Promise<ChainDetailResponse>;
38
+ /**
39
+ * The native balance of ANY EVM address on a chain the gateway serves, read through the gateway's own node.
40
+ *
41
+ * **Unlike `list()` and `get()`, this needs an API key.** The gateway reads through its node, so an open version would be an open RPC
42
+ * proxy. The scope is the existing balance-read scope.
43
+ *
44
+ * `balance` is whole units of the native token as a decimal string (`0.25`). `0` is a successful read of an empty account; a node that
45
+ * did not answer is a `BALANCE_UNREADABLE` error, never a zero. A mistyped address is refused here, before any request, with the same
46
+ * `INVALID_ADDRESS` the gateway would give (a mixed-case address whose EIP-55 checksum does not hold names the correct capitalisation).
47
+ * Chains this gateway does not serve answer `UNKNOWN_CHAIN`. Reading through the gateway trusts the gateway's node: for a check that does
48
+ * not, use `readEvmBalance` with a node you chose.
49
+ */
50
+ balance(idOrChainId: string | number, address: string): Promise<AddressBalanceResponse>;
38
51
  /**
39
52
  * The chains to offer: the configured set (default: the catalogue's live chains) narrowed to
40
53
  * those the gateway serves right now.
@@ -1 +1 @@
1
- {"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../src/resources/chains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAA8C,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGpG;;;;;;;;;;;GAWG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEvC;;;;;;;OAOG;IACG,IAAI,CAAC,MAAM,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUjG;;;;;OAKG;IACG,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAKrE;;;;;;;OAOG;IACG,OAAO,CAAC,UAAU,GAAE,SAAS,MAAM,EAA2B,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAItG"}
1
+ {"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../../src/resources/chains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAA8C,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKpG;;;;;;;;;;;GAWG;AACH,qBAAa,cAAc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