@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,467 @@
1
+ import { CertenError } from './errors.js';
2
+ import { chainAvailability, chainSlug, enablableChains, faucetForChain, readNativeBalance, describeUnverifiable, nativeSymbolFor, } from './chains.js';
3
+ import { assessGas, nativeAmountOf } from './funding.js';
4
+ import { verifyKeyPageHolds } from './key-page.js';
5
+ const NAMES = {
6
+ gateway: 'gateway',
7
+ credential: 'credential',
8
+ identity: 'identity',
9
+ chain: 'chain',
10
+ keyPage: 'key page',
11
+ credits: 'accumulate credits',
12
+ balance: 'gateway balance',
13
+ gas: 'gas',
14
+ };
15
+ /** Every name `runReadiness` can emit, in the order it emits them. */
16
+ export const READINESS_CHECKS = [
17
+ NAMES.gateway, NAMES.credential, NAMES.identity, NAMES.chain, NAMES.keyPage, NAMES.credits, NAMES.balance, NAMES.gas,
18
+ ];
19
+ /** The checks that depend on the identity and chain, as opposed to the organization. What `scope: 'context'` returns. */
20
+ export const CONTEXT_CHECKS = [NAMES.identity, NAMES.chain, NAMES.keyPage, NAMES.credits, NAMES.gas];
21
+ const check = (name, status, detail, extra = {}) => ({ name, status, detail, ...extra });
22
+ const statusOf = (err) => (err instanceof CertenError ? err.status : undefined);
23
+ const messageOf = (err) => (err instanceof Error ? err.message.replace(/^certen: /, '') : String(err));
24
+ const unreachable = (err) => err instanceof CertenError && (err.status === 0 || err.code === 'NETWORK_ERROR');
25
+ const hostOf = (url) => { try {
26
+ return new URL(url).host;
27
+ }
28
+ catch {
29
+ return url;
30
+ } };
31
+ const short = (hash) => (hash.length > 12 ? `${hash.slice(0, 6)}…${hash.slice(-4)}` : hash);
32
+ export async function runReadiness(client, params) {
33
+ if (!params.identityId)
34
+ throw new CertenError('certen: readiness needs an identity id.', 0, 'MISSING_IDENTITY');
35
+ if (!params.chain)
36
+ throw new CertenError('certen: readiness needs a chain.', 0, 'MISSING_CHAIN');
37
+ const scope = params.scope ?? 'full';
38
+ const full = scope === 'full';
39
+ const chain = chainSlug(params.chain);
40
+ const keyHash = params.keyHash?.trim().replace(/^0x/i, '').toLowerCase() || undefined;
41
+ const checks = [];
42
+ // Three unrelated reads, awaited together: they answer different questions and none needs another's answer. The checks are still
43
+ // emitted in dependency order below; only the I/O overlaps.
44
+ const [registryR, balanceR, identityR] = await Promise.allSettled([
45
+ !full && params.registry ? Promise.resolve(params.registry) : client.chains.list(),
46
+ full ? client.billing.balance() : Promise.resolve(null),
47
+ client.identity.get(params.identityId, { include: ['balances'] }),
48
+ ]);
49
+ const registry = registryR.status === 'fulfilled' ? registryR.value : undefined;
50
+ const context = {
51
+ identity_id: params.identityId,
52
+ adi_url: null,
53
+ key_page_url: null,
54
+ chain,
55
+ abstract_account: null,
56
+ accumulate_rpc: null,
57
+ key_hash: keyHash ?? null,
58
+ };
59
+ /** Mark every check that has not been emitted yet, from `from` on, as not evaluated. */
60
+ const skipRest = (names, why) => {
61
+ for (const name of names) {
62
+ if (!full && !CONTEXT_CHECKS.includes(name))
63
+ continue;
64
+ checks.push(check(name, 'skipped', why));
65
+ }
66
+ };
67
+ const after = (name) => READINESS_CHECKS.slice(READINESS_CHECKS.indexOf(name) + 1);
68
+ // ── gateway ────────────────────────────────────────────────────────────────────────────────────────────
69
+ if (full) {
70
+ if (registryR.status === 'fulfilled') {
71
+ checks.push(check(NAMES.gateway, 'ok', `registry v${registry.version}, ${registry.count} chains`));
72
+ }
73
+ else {
74
+ const down = unreachable(registryR.reason);
75
+ checks.push(check(NAMES.gateway, 'fail', messageOf(registryR.reason), {
76
+ code: down ? 'GATEWAY_UNREACHABLE' : 'GATEWAY_ERROR',
77
+ fix: { text: 'Check the gateway address and your network. Nothing else can be checked until this answers.' },
78
+ }));
79
+ skipRest(after(NAMES.gateway), 'gateway unreachable');
80
+ return finish(checks, context);
81
+ }
82
+ // ── credential ─────────────────────────────────────────────────────────────────────────────────────
83
+ // The balance read is the cheapest question that proves the gateway accepts the key. An identity read that was refused as
84
+ // unauthenticated says the same thing, so either one counts.
85
+ const rejected = (r) => r.status === 'rejected' && statusOf(r.reason) === 401;
86
+ if (rejected(balanceR) || rejected(identityR)) {
87
+ checks.push(check(NAMES.credential, 'fail', 'The gateway rejected this API key.', {
88
+ code: 'CREDENTIAL_REJECTED',
89
+ fix: { text: 'Sign in again or mint a new key; check which one is configured.' },
90
+ }));
91
+ skipRest(after(NAMES.credential), 'needs a working API key');
92
+ return finish(checks, context);
93
+ }
94
+ if (balanceR.status === 'fulfilled') {
95
+ checks.push(check(NAMES.credential, 'ok', 'accepted'));
96
+ }
97
+ else if (statusOf(balanceR.reason) === 403) {
98
+ // Real, but unscoped: it can sign work and cannot read billing. The balance check says what it could not see.
99
+ checks.push(check(NAMES.credential, 'ok', 'accepted, but this key has no billing:read scope'));
100
+ }
101
+ else {
102
+ checks.push(check(NAMES.credential, 'unknown', `Could not confirm the key: ${messageOf(balanceR.reason)}`, {
103
+ code: 'CREDENTIAL_UNCONFIRMED',
104
+ fix: { text: 'Retry. If it persists, check the gateway status.' },
105
+ }));
106
+ }
107
+ }
108
+ // ── identity ───────────────────────────────────────────────────────────────────────────────────────────
109
+ let identity;
110
+ if (identityR.status === 'rejected') {
111
+ const status = statusOf(identityR.reason);
112
+ checks.push(status === 404
113
+ ? check(NAMES.identity, 'fail', `The gateway has no identity ${params.identityId} in this organization.`, {
114
+ code: 'IDENTITY_NOT_FOUND',
115
+ fix: { text: 'Check the identity, or create one.' },
116
+ })
117
+ : status === 403
118
+ ? check(NAMES.identity, 'fail', 'This API key may not read identities (it lacks identity:read).', {
119
+ code: 'IDENTITY_FORBIDDEN',
120
+ fix: { text: 'Use a key with the identity:read scope.' },
121
+ })
122
+ : status === 401
123
+ ? check(NAMES.identity, 'fail', 'The gateway rejected this API key.', {
124
+ code: 'CREDENTIAL_REJECTED',
125
+ fix: { text: 'Sign in again or mint a new key.' },
126
+ })
127
+ : check(NAMES.identity, 'unknown', `Could not read the identity: ${messageOf(identityR.reason)}`, {
128
+ code: 'IDENTITY_UNREADABLE',
129
+ fix: { text: 'Retry. If it persists, check the gateway status.' },
130
+ }));
131
+ }
132
+ else {
133
+ identity = identityR.value;
134
+ context.adi_url = identity.adi_url ?? null;
135
+ context.key_page_url = identity.key_page_url ?? null;
136
+ const inFlight = ['provisioning', 'pending', 'creating'].includes(identity.status);
137
+ if (identity.status === 'active') {
138
+ checks.push(check(NAMES.identity, 'ok', `${identity.adi_url} is active`, { data: { status: identity.status } }));
139
+ }
140
+ else if (inFlight) {
141
+ checks.push(check(NAMES.identity, 'fail', `${identity.adi_url} is still ${identity.status}.`, {
142
+ code: 'IDENTITY_PROVISIONING',
143
+ fix: { text: 'Provisioning takes about 45-90 seconds. Wait for it to finish, then check again.' },
144
+ data: { status: identity.status },
145
+ }));
146
+ }
147
+ else if (identity.status === 'error') {
148
+ checks.push(check(NAMES.identity, 'fail', `${identity.adi_url} failed to provision${identity.error_message ? `: ${identity.error_message}` : '.'}`, {
149
+ code: 'IDENTITY_PROVISIONING_FAILED',
150
+ fix: { text: 'Retire this identity and create it again.' },
151
+ data: { status: identity.status },
152
+ }));
153
+ }
154
+ else {
155
+ checks.push(check(NAMES.identity, 'fail', `${identity.adi_url} is ${identity.status}, not active.`, {
156
+ code: 'IDENTITY_NOT_ACTIVE',
157
+ fix: { text: 'Use an active identity, or create one.' },
158
+ data: { status: identity.status },
159
+ }));
160
+ }
161
+ }
162
+ const identityOk = identity?.status === 'active';
163
+ if (!identityOk) {
164
+ skipRest(after(NAMES.identity), identity ? `identity is ${identity.status}` : 'identity not available');
165
+ return finish(checks, context);
166
+ }
167
+ const ident = identity;
168
+ // ── chain ──────────────────────────────────────────────────────────────────────────────────────────────
169
+ const account = (ident.chain_accounts ?? []).find((a) => chainSlug(a.chain_id) === chain);
170
+ context.abstract_account = account?.address ?? null;
171
+ checks.push(chainCheck(chain, registry, params.configuredChains, account));
172
+ // ── key page (the gateway's word, and Accumulate's) ────────────────────────────────────────────────────
173
+ const rpc = params.accumulateRpc ?? registry?.accumulate?.api;
174
+ let hold = { state: 'not-checked', why: 'no key was given to compare' };
175
+ if (ident.key_page_url) {
176
+ if (keyHash && rpc) {
177
+ context.accumulate_rpc = rpc;
178
+ try {
179
+ hold = await verifyKeyPageHolds(ident.key_page_url, keyHash, { rpc, fetch: params.fetch, timeoutMs: params.accumulateTimeoutMs });
180
+ }
181
+ catch (err) {
182
+ hold = { state: 'unreadable', rpc, reason: messageOf(err), notFound: false };
183
+ }
184
+ }
185
+ else if (keyHash) {
186
+ hold = { state: 'unreadable', rpc: '', reason: 'the gateway advertises no Accumulate endpoint and none was given', notFound: false };
187
+ }
188
+ }
189
+ checks.push(keyPageCheck(ident, keyHash, hold));
190
+ // ── accumulate credits ─────────────────────────────────────────────────────────────────────────────────
191
+ checks.push(creditsCheck(ident, hold));
192
+ // ── gateway balance ────────────────────────────────────────────────────────────────────────────────────
193
+ if (full)
194
+ checks.push(balanceCheck(balanceR));
195
+ // ── gas ────────────────────────────────────────────────────────────────────────────────────────────────
196
+ checks.push(await gasCheckOf(client, ident, chain, account?.address, params));
197
+ return finish(checks, context);
198
+ }
199
+ /**
200
+ * The gas check on its own: the same judgement `runReadiness` makes, for a caller that is waiting for one number to change.
201
+ *
202
+ * `setup --wait-for-funds` and `gas --wait` poll this, not the whole of `readiness()`: the rest of it (the registry, the Accumulate key page,
203
+ * the organization's balance) cannot change while someone is sending gas from a faucet, and asking again every few seconds would be noise
204
+ * on the gateway and on a public Accumulate node. It is the SAME function `runReadiness` calls, so the wait and `status` cannot disagree
205
+ * about when an account counts as funded.
206
+ *
207
+ * Never throws for a read that failed: that is an `unknown` check carrying the HTTP status in `data.status`, so a poller can tell a
208
+ * rejected credential (stop) from a gateway having a bad moment (carry on). It throws only for a malformed call.
209
+ */
210
+ export async function checkGas(client, params) {
211
+ if (!params.identityId)
212
+ throw new CertenError('certen: checkGas needs an identity id.', 0, 'MISSING_IDENTITY');
213
+ if (!params.chain)
214
+ throw new CertenError('certen: checkGas needs a chain.', 0, 'MISSING_CHAIN');
215
+ const chain = chainSlug(params.chain);
216
+ let ident;
217
+ try {
218
+ ident = await client.identity.get(params.identityId, { include: ['balances'] });
219
+ }
220
+ catch (err) {
221
+ return check(NAMES.gas, 'unknown', `Could not read the identity to find its gas balance: ${messageOf(err)}`, {
222
+ code: 'GAS_UNREADABLE',
223
+ fix: { text: 'Retry. If it persists, check the gateway status.' },
224
+ data: { chain, status: statusOf(err) ?? null },
225
+ });
226
+ }
227
+ const account = (ident.chain_accounts ?? []).find((a) => chainSlug(a.chain_id) === chain);
228
+ return gasCheckOf(client, ident, chain, account?.address, params);
229
+ }
230
+ /** Find the chain's balance rows on an identity already read (falling back to the portfolio on a gateway that predates `balances`) and judge them. */
231
+ async function gasCheckOf(client, ident, chain, accountAddress, params) {
232
+ let rows = ident.balances;
233
+ if (rows === undefined) {
234
+ // A gateway that predates the balances enrichment. The portfolio carries the same numbers.
235
+ try {
236
+ const portfolio = await client.portfolio.get(params.identityId);
237
+ for (const entry of portfolio.identities ?? []) {
238
+ for (const c of entry.chains ?? []) {
239
+ if (chainSlug(c.chain_id) === chain)
240
+ rows = (c.balances ?? []).map((b) => ({ chain_id: chain, address: c.address, token: b.token, balance: b.balance }));
241
+ }
242
+ }
243
+ }
244
+ catch {
245
+ rows = undefined;
246
+ }
247
+ }
248
+ const onChain = (rows ?? []).filter((b) => chainSlug(b.chain_id) === chain);
249
+ return gasCheck(chain, accountAddress ?? onChain[0]?.address, readNativeBalance(chain, onChain), params);
250
+ }
251
+ /**
252
+ * The verdict a list of checks adds up to.
253
+ *
254
+ * Exported because a caller that adds a check of its own - the CLI adds "is there a signing key on this machine", which the SDK cannot see -
255
+ * must get the verdict from the same rule rather than restate it.
256
+ */
257
+ export function summarizeReadiness(checks) {
258
+ const failed = checks.filter((c) => c.status === 'fail');
259
+ const unsettled = checks.filter((c) => c.status === 'unknown' || c.status === 'skipped');
260
+ const state = failed.length > 0 ? 'blocked' : unsettled.length > 0 ? 'unconfirmed' : 'ready';
261
+ return { ready: state === 'ready', state, first_blocker: failed[0] ?? unsettled[0] ?? null };
262
+ }
263
+ function finish(checks, context) {
264
+ return { ...summarizeReadiness(checks), checks, context };
265
+ }
266
+ function chainCheck(chain, registry, configured, account) {
267
+ if (!registry) {
268
+ return check(NAMES.chain, 'unknown', 'Could not read the gateway\'s chain registry, so whether it serves this chain is not known.', {
269
+ code: 'CHAIN_REGISTRY_UNREADABLE', fix: { text: 'Retry. If it persists, check the gateway status.' },
270
+ });
271
+ }
272
+ const availability = chainAvailability(chain, configured ?? enablableChains(), registry.chains);
273
+ switch (availability.state) {
274
+ case 'enabled':
275
+ break;
276
+ case 'unknown': {
277
+ // Not in this client's catalogue: it can still be a chain the gateway serves (a newer one). Judge it by the registry alone, and the
278
+ // gas check will say it cannot tell which balance pays for it.
279
+ const entry = registry.chains.find((c) => chainSlug(c.id) === chain);
280
+ if (entry && entry.enabled !== false)
281
+ break;
282
+ return check(NAMES.chain, 'fail', `${chain} is not a chain the gateway serves.`, {
283
+ code: 'CHAIN_NOT_SERVED', fix: { text: 'Pick a chain the gateway serves (the chain registry lists them).' },
284
+ });
285
+ }
286
+ case 'retired':
287
+ return check(NAMES.chain, 'fail', `${chain} is retired and can no longer be used.`, { code: 'CHAIN_RETIRED', fix: { text: 'Use another chain.' } });
288
+ case 'not-configured':
289
+ return check(NAMES.chain, 'fail', `${chain} is not enabled in this client's configuration.`, {
290
+ code: 'CHAIN_NOT_ENABLED', fix: { text: 'Enable it in the configured chain set, or use an enabled chain.' },
291
+ });
292
+ case 'unlisted':
293
+ return check(NAMES.chain, 'fail', `The gateway does not list ${chain}.`, { code: 'CHAIN_NOT_SERVED', fix: { text: 'Use a chain the gateway serves.' } });
294
+ case 'disabled':
295
+ return check(NAMES.chain, 'fail', `The gateway lists ${chain} but has it switched off.`, { code: 'CHAIN_DISABLED', fix: { text: 'Use another chain, or wait until it is enabled.' } });
296
+ }
297
+ if (!account) {
298
+ return check(NAMES.chain, 'fail', `${chain} is served, but this identity has no abstract account there, so it has no sender address on that chain.`, {
299
+ code: 'CHAIN_NOT_LINKED', fix: { text: 'Link the chain to this identity.' },
300
+ });
301
+ }
302
+ if (account.status === 'failed') {
303
+ return check(NAMES.chain, 'fail', `This identity's account on ${chain} (${account.address}) failed to deploy.`, {
304
+ code: 'CHAIN_ACCOUNT_FAILED', fix: { text: 'Unlink the chain and link it again.' },
305
+ });
306
+ }
307
+ return check(NAMES.chain, 'ok', `${chain} is served and linked (abstract account ${account.address})`, { data: { chain, abstract_account: account.address, account_status: account.status } });
308
+ }
309
+ function keyPageCheck(ident, keyHash, hold) {
310
+ const gateway = ident.can_sign === true ? 'yes' : ident.can_sign === false ? 'no' : 'unknown';
311
+ const data = {
312
+ key_page_url: ident.key_page_url,
313
+ gateway_can_sign: ident.can_sign ?? null,
314
+ independent: hold.state === 'holds' ? 'holds' : hold.state === 'absent' ? 'absent' : hold.state === 'unreadable' ? 'unreadable' : 'not_checked',
315
+ };
316
+ if (!ident.key_page_url) {
317
+ return check(NAMES.keyPage, 'fail', 'This identity has no key page on record.', {
318
+ code: 'KEY_PAGE_MISSING', fix: { text: 'The identity did not finish provisioning. Retire it and create it again.' }, data,
319
+ });
320
+ }
321
+ if (hold.state === 'holds' || hold.state === 'absent') {
322
+ const r = hold.reading;
323
+ Object.assign(data, { accumulate_rpc: r.rpc, keys_on_page: r.keyHashes.length, accept_threshold: r.acceptThreshold, version: r.version });
324
+ const where = `read from Accumulate (${hostOf(r.rpc)}), not the gateway`;
325
+ if (hold.state === 'holds') {
326
+ if (gateway === 'no') {
327
+ return check(NAMES.keyPage, 'fail', `Accumulate shows ${ident.key_page_url} holding your key, but the gateway says this identity cannot sign. The two disagree.`, {
328
+ code: 'KEY_PAGE_DISAGREES',
329
+ fix: { text: 'Do not sign yet. Check the identity with the gateway operator: one of the two reads is wrong, and this check will not choose between them.' }, data,
330
+ });
331
+ }
332
+ const threshold = r.acceptThreshold && r.acceptThreshold > 1 ? `; ${r.acceptThreshold} signatures are needed, so your key alone will not execute` : '';
333
+ return check(NAMES.keyPage, 'ok', `${ident.key_page_url} holds your key (${short(keyHash)}), ${where}${gateway === 'unknown' ? ' (the gateway could not say)' : ''}${threshold}`, { data });
334
+ }
335
+ // absent: a fact about the page.
336
+ return check(NAMES.keyPage, 'fail', `${ident.key_page_url} does not list your key (${short(keyHash)}), ${where}. It lists ${r.keyHashes.length} other key(s).`
337
+ + (gateway === 'yes' ? ' The gateway says this identity can sign, so it is signable by a different key than the one given.' : ''), {
338
+ code: gateway === 'yes' ? 'KEY_PAGE_DISAGREES' : 'KEY_PAGE_LACKS_KEY',
339
+ fix: { text: 'Use the key this identity was created with, or add this key to the key page.' }, data,
340
+ });
341
+ }
342
+ if (hold.state === 'unreadable') {
343
+ data.independent_error = hold.reason;
344
+ if (gateway === 'no') {
345
+ return check(NAMES.keyPage, 'fail', 'The gateway says this identity cannot sign: its key page does not hold the key it was created with.', {
346
+ code: 'IDENTITY_CANNOT_SIGN', fix: { text: 'Check the identity, or create it again with this key.' }, data,
347
+ });
348
+ }
349
+ return check(NAMES.keyPage, 'unknown', `Could not confirm from Accumulate that the key page holds your key: ${hold.reason}.`
350
+ + (gateway === 'yes' ? ' The gateway says it can sign; that is one party\'s word.' : ' The gateway could not say either.'), {
351
+ code: 'KEY_PAGE_UNCONFIRMED',
352
+ fix: { text: hold.notFound ? 'The node has no such account: check the Accumulate endpoint, or wait for the identity to anchor.' : 'Retry, or name another Accumulate node.' },
353
+ data,
354
+ });
355
+ }
356
+ // Not checked independently: no key to compare. Say what the gateway said, and that it is only that.
357
+ if (gateway === 'no') {
358
+ return check(NAMES.keyPage, 'fail', 'The gateway says this identity cannot sign: its key page does not hold the key it was created with.', {
359
+ code: 'IDENTITY_CANNOT_SIGN', fix: { text: 'Check the identity, or create it again with the right key.' }, data,
360
+ });
361
+ }
362
+ return check(NAMES.keyPage, 'warn', `${gateway === 'yes' ? 'The gateway says this identity can sign' : 'The gateway could not say whether this identity can sign'}; not checked against Accumulate (${hold.why}).`, { code: 'KEY_PAGE_NOT_INDEPENDENTLY_CHECKED', fix: { text: 'Give the signing key so the key page can be compared with it.' }, data });
363
+ }
364
+ function creditsCheck(ident, hold) {
365
+ const fromAccumulate = hold.state === 'holds' || hold.state === 'absent' ? hold.reading.creditBalance : null;
366
+ const fromGateway = typeof ident.credit_balance === 'number' && Number.isFinite(ident.credit_balance) ? ident.credit_balance : null;
367
+ const value = fromAccumulate ?? fromGateway;
368
+ const source = fromAccumulate !== null ? 'Accumulate' : 'the gateway';
369
+ const data = { key_page_url: ident.key_page_url, credits: value, source: fromAccumulate !== null ? 'accumulate' : 'gateway', gateway_credits: fromGateway };
370
+ if (value === null) {
371
+ return check(NAMES.credits, 'unknown', 'Neither Accumulate nor the gateway reported the key page\'s credit balance.', {
372
+ code: 'CREDITS_UNREADABLE', fix: { text: 'Retry. If it persists, read the key page on an Accumulate explorer.' }, data,
373
+ });
374
+ }
375
+ if (value <= 0) {
376
+ return check(NAMES.credits, 'fail', `The key page ${ident.key_page_url} has no credits (${source} reports ${value}), so Accumulate will refuse what it signs.`, {
377
+ code: 'ACCUMULATE_CREDITS_EMPTY',
378
+ fix: { text: 'Add credits to the key page. The gateway has no top-up call yet, so this is done from the Accumulate side or the portal.' }, data,
379
+ });
380
+ }
381
+ // Shown exactly as reported: whether this is whole credits or hundredths of one is not pinned by the spec, so it is not converted and
382
+ // not compared with a threshold. Zero is the only value that is certainly too low in either.
383
+ const differs = fromAccumulate !== null && fromGateway !== null && fromAccumulate !== fromGateway;
384
+ return check(NAMES.credits, 'ok', `${value} on the key page, as ${source} reports it${differs ? ` (the gateway reports ${fromGateway})` : ''}`, { data });
385
+ }
386
+ function balanceCheck(r) {
387
+ if (r.status === 'rejected') {
388
+ const forbidden = statusOf(r.reason) === 403;
389
+ return check(NAMES.balance, 'unknown', forbidden
390
+ ? 'This key has no billing:read scope, so the organization\'s balance cannot be read.'
391
+ : `Could not read the organization's balance: ${messageOf(r.reason)}`, {
392
+ code: 'GATEWAY_BALANCE_UNREADABLE',
393
+ fix: { text: forbidden ? 'Use a key with the billing:read scope.' : 'Retry. If it persists, check the gateway status.' },
394
+ });
395
+ }
396
+ const balance = r.value;
397
+ const data = { spendable_usd: balance.spendable_usd, remaining_usd: balance.remaining_usd ?? null, pending_intents: balance.pending_intents ?? null, status: balance.status };
398
+ if (balance.status !== 'active') {
399
+ return check(NAMES.balance, 'fail', `The organization's account is ${balance.status}${balance.suspended_reason ? `: ${balance.suspended_reason}` : ''}.`, {
400
+ code: 'GATEWAY_ACCOUNT_INACTIVE', fix: { text: 'Add funds to the organization\'s gateway balance.' }, data,
401
+ });
402
+ }
403
+ // `remaining_usd` is what decides whether new work is accepted: a healthy-looking balance can be entirely committed to intents awaiting quorum.
404
+ const left = balance.remaining_usd !== undefined ? Number(balance.remaining_usd) : Number(balance.spendable_usd);
405
+ if (Number.isFinite(left) && left <= 0) {
406
+ return check(NAMES.balance, 'fail', balance.remaining_usd !== undefined
407
+ ? `Nothing left to commit: ${balance.pending_intents ?? 0} pending intent(s) have claimed the balance.`
408
+ : 'The organization\'s gateway balance is empty.', { code: 'GATEWAY_BALANCE_EMPTY', fix: { text: 'Add funds to the organization\'s gateway balance (it pays CERTEN\'s fees).' }, data });
409
+ }
410
+ if (!Number.isFinite(left)) {
411
+ return check(NAMES.balance, 'unknown', `The gateway reported a balance this client cannot read (${String(balance.remaining_usd ?? balance.spendable_usd)}).`, {
412
+ code: 'GATEWAY_BALANCE_UNREADABLE', fix: { text: 'Retry. If it persists, check the gateway status.' }, data,
413
+ });
414
+ }
415
+ return check(NAMES.balance, 'ok', `$${balance.spendable_usd} spendable${balance.remaining_usd !== undefined ? `, $${balance.remaining_usd} left to commit` : ''}`, { data });
416
+ }
417
+ function gasCheck(chain, address, reading, p) {
418
+ const symbol = nativeSymbolFor(chain);
419
+ const where = address ? `${address} on ${chain}` : chain;
420
+ const faucet = faucetForChain(chain);
421
+ const assessment = assessGas({
422
+ chain, reading, amount: nativeAmountOf(chain, { amount: p.amount, tokenSymbol: p.tokenSymbol }), reserve: p.gasReserve,
423
+ });
424
+ const base = { chain, abstract_account: address ?? null, symbol: symbol ?? null, gas_reserve_is_estimate: true };
425
+ /** `howMuch` is "0.0011" or "0.0009 more"; null when the amount is not known and the instruction is just to fund it. */
426
+ const fund = (howMuch, target) => ({
427
+ text: `Send ${howMuch ? `at least ${howMuch}${symbol ? ` ${symbol}` : ''}` : 'gas'} to ${address ?? 'the abstract account'} on ${chain}`
428
+ + `${target && howMuch?.endsWith('more') ? ` (to reach ${target}${symbol ? ` ${symbol}` : ''})` : ''}.`,
429
+ ...(faucet ? { url: faucet } : {}),
430
+ });
431
+ switch (assessment.state) {
432
+ case 'sufficient': {
433
+ const data = { ...base, balance: assessment.balance, needed: assessment.needed, amount: assessment.amount, gas_reserve: assessment.reserve };
434
+ if (!assessment.estimated) {
435
+ return check(NAMES.gas, 'warn', `${where} holds ${assessment.balance} ${assessment.symbol}. There is no gas estimate for ${chain}, so only the amount (${assessment.amount}) was checked.`, { code: 'GAS_NOT_ESTIMATED', fix: { text: 'Check what one execution costs on this chain before moving value from it.' }, data });
436
+ }
437
+ return check(NAMES.gas, 'ok', `${where} holds ${assessment.balance} ${assessment.symbol}; `
438
+ + (assessment.amount === '0'
439
+ ? `about ${assessment.reserve} ${assessment.symbol} is needed for gas (an estimate)`
440
+ : `${assessment.amount} to move + about ${assessment.reserve} for gas (an estimate) needs ${assessment.needed} ${assessment.symbol}`), { data });
441
+ }
442
+ case 'empty': {
443
+ const data = { ...base, balance: assessment.balance, needed: assessment.needed, amount: assessment.amount, gas_reserve: assessment.reserve };
444
+ return check(NAMES.gas, 'fail', `${where} holds 0 ${assessment.symbol}. A value transfer from it is accepted, signed and submitted, and then parks at "anchoring" forever.`, { code: 'ABSTRACT_ACCOUNT_UNFUNDED', fix: fund(assessment.needed === '0' ? null : assessment.needed), data });
445
+ }
446
+ case 'short': {
447
+ const data = { ...base, balance: assessment.balance, needed: assessment.needed, amount: assessment.amount, gas_reserve: assessment.reserve, shortfall: assessment.shortfall, shortfall_kind: assessment.kind };
448
+ return check(NAMES.gas, 'fail', assessment.kind === 'amount'
449
+ ? `${where} holds ${assessment.balance} ${assessment.symbol}, less than the ${assessment.amount} ${assessment.symbol} to be moved.`
450
+ : assessment.reserve === '0'
451
+ ? `${where} holds ${assessment.balance} ${assessment.symbol}, which is all of the ${assessment.amount} ${assessment.symbol} to be moved: nothing would be left to pay for gas.`
452
+ : `${where} holds ${assessment.balance} ${assessment.symbol}; moving ${assessment.amount} and paying for gas needs about ${assessment.needed} (the gas share, ${assessment.reserve}, is an estimate).`, { code: 'ABSTRACT_ACCOUNT_UNDERFUNDED', fix: fund(assessment.shortfall ? `${assessment.shortfall} more` : null, assessment.needed), data });
453
+ }
454
+ case 'unknown': {
455
+ const r = assessment.reading;
456
+ const why = r.state === 'no-balances'
457
+ ? `The gateway has not reported a balance for ${where} yet (the account is not deployed or not indexed).`
458
+ : describeUnverifiable(chain, r) ?? 'the balance could not be read';
459
+ return check(NAMES.gas, 'unknown', `Cannot verify the gas on ${where}: ${why}. An intent from an unfunded account is accepted and then never executes.`, {
460
+ code: 'ABSTRACT_ACCOUNT_FUNDING_UNVERIFIABLE',
461
+ fix: { text: 'Check the account\'s gas yourself before moving value from it.', ...(faucet ? { url: faucet } : {}) },
462
+ data: { ...base, reading: r.state },
463
+ });
464
+ }
465
+ }
466
+ }
467
+ //# sourceMappingURL=readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.js","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,eAAe,GAExH,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAoB,MAAM,eAAe,CAAC;AAqHrE,MAAM,KAAK,GAAG;IACZ,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE,oBAAoB;IAC7B,OAAO,EAAE,iBAAiB;IAC1B,GAAG,EAAE,KAAK;CACF,CAAC;AAEX,sEAAsE;AACtE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,KAAK,C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