@ixo/action-protocol 0.5.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ One card kind for every chain transaction: `ixo.chain.tx.v1`. Every existing
6
+ shape is unchanged. The Hub shows it only to callers that declare
7
+ `?version=4` (wire level 4 = level 3 + chain transactions; the envelope tags
8
+ stay `ixo.auth-capabilities/2` / `ixo.auth-outcome/2`), because released
9
+ 0.5.0 runtimes already declare `?version=3` and parse with exact-key parsers.
10
+
11
+ - Operation `ixo.chain.tx.v1`: `chainId`, `network`, `signer`, `memo`
12
+ (0..256 UTF-8 bytes) and `messages` (1..8, one transaction, all or
13
+ nothing). Message types (`CHAIN_TX_MESSAGE_TYPES`): `cosmos.bank.send`,
14
+ `ixo.claims.submit`, `ixo.claims.evaluate` (status 1..4), and
15
+ `ixo.token.transfer` (IXO impact tokens, 1..32 token lines).
16
+ - `chainTxIssue(operation)`: the first malformed field as the Hub's 400
17
+ `reason` (`invalid_message: messages[1].toAddress`, 0-based index, or
18
+ `invalid_operation: memo`), or null. `parseOperation` throws
19
+ `Invalid messages[1].toAddress` for the same field.
20
+ - Review view `chainTx` (`ChainTxDisplay`, `parseChainTxDisplay`): the
21
+ Hub-computed steps (title, one sentence, facts, risk, cannotUndo, the
22
+ bank-send `TransferDisplay` for bank steps), overall `riskLevel`,
23
+ `confirmTwice` (high or critical), consent text, fee, signer and `wrapped`.
24
+ It must match the operation's signer and message types in order.
25
+ - Receipt `ixo.chain.tx.v1`: chain id, tx hash, height, code, `steps` (the
26
+ message types in order), and on failure a `reason`
27
+ (`CHAIN_TX_FAILURE_REASONS`: `check_tx_rejected`, `expired_not_included`,
28
+ or `tx_failed` = included with code != 0) with an optional plain
29
+ `message` (at most 240). Never in a `/1` outcome envelope.
30
+ - Capabilities `chainTx` (`parseChainTxCapabilities`):
31
+ `{messageTypes, maxMessages}`, present exactly when `operations` lists
32
+ `ixo.chain.tx.v1`; absent (or null) otherwise.
33
+ - The operation JSON schema supports `integer` (used by the evaluation
34
+ `reason`, a uint32 the evaluator defines).
35
+ - Validation is stricter than the first 0.6.0 draft (`chainTxIssue`,
36
+ `parseOperation`): claim ids and token ids must match
37
+ `^[A-Za-z0-9:._/-]+$`; every address must decode to a 20-byte account;
38
+ a DID's `%` must start a valid `%xx` escape; the memo refuses control
39
+ characters; `verificationProof` is at most 300 characters (was 512), so
40
+ the review display can show it whole.
41
+ - No caps: chain transactions have no per-message capability rows, no
42
+ per-message enablement and no amount caps (product decision); the kind is
43
+ on by default and an operator can only disable it as a whole.
44
+ `/transfer-limits` stay for `ixo.bank.send.v1`.
45
+ - Retirement plan for `ixo.bank.send.v1` (not in this release): unchanged
46
+ until `cosmos.bank.send` in a chain tx card is proven live on every
47
+ network; then runtimes stop creating it, the Hub serves existing rows until
48
+ they are terminal and past retention, and the kind is removed in a major
49
+ version.
50
+ - Rollout order: Hub, then gateways on 0.6.0 (a pre-0.6.0 strict parser
51
+ fails its confirmation reads of chain-tx receipts), then runtimes on
52
+ `?version=4`.
53
+
3
54
  ## 0.5.0
4
55
 
5
56
  Everything in the P1 0.3.0 entry below (shipped on the stacked P1 branch), on
@@ -23,7 +74,8 @@ top of 0.4.1, plus:
23
74
 
24
75
  ## 0.3.0
25
76
 
26
- All additions are optional or v2-only; v1 envelopes are unchanged.
77
+ All additions are optional. The Hub only emits them to callers that declare
78
+ `?version=3`; v1 and v2 callers keep the 0.4.1 shapes.
27
79
 
28
80
  - Bank send `denom`: any Cosmos denom matching `DENOM`; absent means `uixo`
29
81
  (the parser fills it in).
package/README.md CHANGED
@@ -15,7 +15,14 @@ Callers declare the envelope version they parse with `?version=2` on
15
15
 
16
16
  - v1 (`ixo.auth-outcome/1`, `ixo.auth-capabilities/1`): the 0.1.0 status set
17
17
  and the 0.4.1 receipt shape, exactly. Fields added later never appear in v1.
18
- - v2 (`ixo.auth-outcome/2`, `ixo.auth-capabilities/2`): every current field.
18
+ - v2 (`ixo.auth-outcome/2`, `ixo.auth-capabilities/2`): the 0.4.1 shapes, exactly.
19
+ - `?version=3` (0.5.0): the same `/2` tags with every current field (bank
20
+ receipt `denom`/`amountBaseUnits`, capability `transfer.limits`, any-denom
21
+ sends). Declare it to receive them; v1/v2 callers never do.
22
+ - `?version=4` (0.6.0): level 3 plus chain transactions (`ixo.chain.tx.v1`
23
+ in capabilities, the `chainTx` capability key, and the right to create the
24
+ kind). Callers below 4 never see the kind, and a `POST` of it answers
25
+ `400 protocol_version_required`.
19
26
 
20
27
  ## Bank send (`ixo.bank.send.v1`)
21
28
 
@@ -32,7 +39,86 @@ Callers declare the envelope version they parse with `?version=2` on
32
39
  factory/cw20 token can call it "USDC"): `decimals` is 0, `amountDisplay` is
33
40
  base units, and the UI must show the full denom and an "unverified token"
34
41
  marker. Show the full denom for anything that is not `uixo`.
35
- - v2 bank receipts carry `denom` and `amountBaseUnits`.
42
+ - Bank receipts carry `denom` and `amountBaseUnits` for `?version=3` callers.
43
+
44
+ ## Chain transactions (`ixo.chain.tx.v1`)
45
+
46
+ One card kind for every chain transaction. The person sees every step in
47
+ plain words, ticks a box, and signs once; the steps run as one transaction
48
+ (all succeed or none do).
49
+
50
+ ```ts
51
+ {
52
+ kind: "ixo.chain.tx.v1",
53
+ chainId: string, // the Hub's chain
54
+ network: "ixo mainnet" | "ixo testnet" | "ixo devnet", // the Hub's network
55
+ signer: string, // the person's Hub wallet address
56
+ memo: string, // 0..256 UTF-8 bytes
57
+ messages: ChainTxMessage[], // 1..8
58
+ }
59
+ ```
60
+
61
+ | `type` | Fields | What it does |
62
+ | --- | --- | --- |
63
+ | `cosmos.bank.send` | `toAddress`, `amountBaseUnits`, `denom?` (absent = `uixo`) | Sends coins from the person's wallet. |
64
+ | `ixo.claims.submit` | `collectionId`, `claimId`, `agentDid`, `adminAddress`, `useIntent?` | Files an existing claim with a collection. The chain `agentAddress` is the signer; the Hub requires `agentDid` to be `did:ixo:<signer>`. |
65
+ | `ixo.claims.evaluate` | `claimId`, `collectionId`, `oracle`, `agentDid`, `agentAddress`, `adminAddress`, `status` (1 approve, 2 reject, 3 dispute, 4 invalidate), `reason?` (uint32), `verificationProof?` (≤ 300) | Records the signer's decision on someone else's claim. `agentDid`/`agentAddress` are the evaluator's (the signer; the Hub requires `agentAddress === signer`), not the claimant's; `oracle` is the evaluator DID recorded on the evaluation. An approval can pay the claimant. |
66
+ | `ixo.token.transfer` | `recipient`, `tokens: [{id, amount}]` (1..32) | Moves IXO impact tokens (1155-style), not IXO coins. The chain `owner` is the signer. |
67
+
68
+ - Authorization: the Hub wraps each claims message in
69
+ `/cosmos.authz.v1beta1.MsgExec {grantee: signer, msgs: [inner]}` (one
70
+ MsgExec per claims message), because submit and evaluate run under the
71
+ collection admin's authorization. Bank and token messages are signed
72
+ directly.
73
+ - Validation: `chainTxIssue(operation)` names the first bad field the way
74
+ the Hub's `400 operation_not_registered` `reason` does
75
+ (`invalid_message: messages[1].toAddress`, 0-based index). Validate with
76
+ it before calling the Hub; the Hub also checks the signer, network, chain
77
+ and bech32 checksums. Claim and token ids use only
78
+ `^[A-Za-z0-9:._/-]+$` (impact token ids on chain are 32-hex strings, and
79
+ 1155 amounts have no decimals).
80
+ - Review view `chainTx` (`ChainTxDisplay`): the Hub's plain words, the only
81
+ step text a page renders. `steps[]` each have a `title`, one-sentence
82
+ `whatItDoes`, `facts` (`technical` facts go behind a disclosure),
83
+ `riskLevel`, `cannotUndo`, and for bank steps the bank-send `transfer`
84
+ display (same verified/unverified rules). Titles and sentences never carry
85
+ a hash, denom or address ("Transfer 3 impact tokens", "Sends 1.5 IXO from
86
+ your wallet to the address below."). The memo is not a step fact: the page
87
+ shows the operation's `memo` once, as "Note", after the steps.
88
+ `confirmTwice` is true for high/critical: the page asks a second time
89
+ before signing. `consent` is the checkbox text.
90
+ - Unhappy paths (what the oracle and the person see):
91
+ 1. The message does not look right: `400 operation_not_registered` with a
92
+ `reason` naming the field (`chainTxIssue` gives the same), no card.
93
+ 2. The Hub cannot prepare it: `400 insufficient_funds`,
94
+ `400 not_authorized`, `400 fee_above_ceiling`, `400 simulation_failed`
95
+ (with a fixed `reason` phrase when known), `409 sequence_mismatch`,
96
+ `503 transfer_unavailable`; no card. At sign time the Hub can still
97
+ refuse with `409 fee_grant_changed` (the fee is no longer covered),
98
+ `409 insufficient_funds` (the wallet no longer covers it) or
99
+ `409 review_changed`; nothing is sent and the person is asked to get a
100
+ new link.
101
+ 3. The transaction failed: a `failed` receipt with `reason`
102
+ `check_tx_rejected` (never included, no fee), `tx_failed` (included with
103
+ an error: nothing in it happened, but the network fee was used) or
104
+ `expired_not_included` (never included), plus a plain `message` for the
105
+ first two.
106
+ - Receipt `ixo.chain.tx.v1`: `chainId`, `txHash`, `height`, `code`, `steps`
107
+ (`[{type}]` in order). A `failed` receipt always has a `reason`:
108
+ `check_tx_rejected` (never included; CheckTx code), `expired_not_included`
109
+ (never included; code null) or `tx_failed` (included with code != 0), and
110
+ may carry a plain `message` (≤ 240) to show the person.
111
+ - Capabilities (`?version=4`):
112
+ `chainTx: {messageTypes, maxMessages}` when the kind is listed. There are
113
+ no per-message caps and no per-message enablement.
114
+ - Retiring `ixo.bank.send.v1`: it stays unchanged until `cosmos.bank.send`
115
+ in this card is proven live on every network. Then runtimes stop creating
116
+ bank-send cards (a one-step chain tx replaces them), the Hub keeps serving
117
+ existing bank-send rows until they are terminal and past retention, and
118
+ only then is the kind removed, in a major version.
119
+ - Rollout: Hub first, then gateways on 0.6.0 (a pre-0.6.0 strict parser
120
+ fails its confirmation reads of chain-tx receipts), then runtimes on
121
+ `?version=4`.
36
122
 
37
123
  ## Options
38
124
 
@@ -45,8 +131,8 @@ unchanged, so 0.4.1 parsers keep working on V2.
45
131
  ## Capabilities
46
132
 
47
133
  `transfer` is either `{limits: [{denom, maxAmountBaseUnits}], maxFeeUixo?}`
48
- (v2; an empty `limits` means no caps) or the legacy
49
- `{maxAmountUixo, maxFeeUixo}` (v1).
134
+ (`?version=3`; an empty `limits` means no caps) or the legacy
135
+ `{maxAmountUixo, maxFeeUixo}` (v1/v2).
50
136
 
51
137
  ## Signed outcome callbacks
52
138
 
@@ -91,6 +177,10 @@ if (!ok) return new Response("unauthorized", { status: 401 });
91
177
  const outcome = parseOutcome(JSON.parse(rawBody));
92
178
  ```
93
179
 
180
+ During the transition the Hub also sends the deprecated per-account
181
+ `x-auth-hub-outcome-key` to accounts that still have one registered; it will
182
+ be removed once every oracle verifies the signature.
183
+
94
184
  Uses WebCrypto Ed25519 only (Node 20+, Cloudflare Workers, modern browsers).
95
185
 
96
186
  ## Tests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ixo/action-protocol",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Shared wire contract between IXO Auth Hub, oracle runtimes and channel gateways for reviewed action cards (operations, capabilities, outcomes, receipts).",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export type FormField = {
8
8
  };
9
9
  export type ActionOperationV1 =
10
10
  | P2Operation
11
+ | ChainTxOperation
11
12
  | {
12
13
  kind: "form.submit.v1";
13
14
  formId: string;
@@ -50,6 +51,7 @@ export type ActionReferenceV1 = {
50
51
  };
51
52
  export type ActionReceiptV1 =
52
53
  | P2Receipt
54
+ | ChainTxReceipt
53
55
  | {
54
56
  kind: "form.submission.v1";
55
57
  actionId: string;
@@ -139,6 +141,8 @@ export type ActionReviewView = {
139
141
  } | null;
140
142
  /** 0.3.0: Hub-computed transfer display (bank sends only). */
141
143
  transfer?: TransferDisplay | null;
144
+ /** 0.6.0: Hub-computed chain transaction display (chain tx cards only). */
145
+ chainTx?: ChainTxDisplay | null;
142
146
  };
143
147
  export type TransferDisplay = {
144
148
  denom: string;
@@ -180,7 +184,192 @@ export type ActionCapabilitiesV1 = {
180
184
  maxFeeUixo?: string;
181
185
  }
182
186
  | null;
187
+ /**
188
+ * 0.6.0 (`?version=4` only): present (an object) exactly when `operations`
189
+ * lists `ixo.chain.tx.v1`; absent or null otherwise.
190
+ */
191
+ chainTx?: ChainTxCapabilities | null;
192
+ };
193
+
194
+ /** 0.6.0: one card kind for every chain transaction. */
195
+ export type ChainTxMessageType =
196
+ | "cosmos.bank.send"
197
+ | "ixo.claims.submit"
198
+ | "ixo.claims.evaluate"
199
+ | "ixo.token.transfer";
200
+ /**
201
+ * Field rules (`chainTxIssue` names the first bad field):
202
+ * - addresses: a 20-byte ixo account address, `ixo1` + 38 bech32 characters
203
+ * (the Hub also checks the checksum);
204
+ * - DIDs: `did:<method>:` then segments of [A-Za-z0-9._-] or `%` + two hex
205
+ * digits, joined by ':' (the chain's x/iid rule; `agentDid` is `did:ixo:`);
206
+ * - claim ids, token ids and verification proofs: ^[A-Za-z0-9:._/-]+$;
207
+ * - collectionId: a uint64 without leading zeros.
208
+ */
209
+ export type ChainTxMessage =
210
+ | {
211
+ type: "cosmos.bank.send";
212
+ toAddress: string;
213
+ /** ^[1-9][0-9]*$ */
214
+ amountBaseUnits: string;
215
+ /** Same rule as bank.send (`DENOM`); absent = uixo. */
216
+ denom?: string;
217
+ }
218
+ | {
219
+ type: "ixo.claims.submit";
220
+ /** ^(0|[1-9][0-9]{0,19})$, ≤ 18446744073709551615 */
221
+ collectionId: string;
222
+ /** 1..256, ^[A-Za-z0-9:._/-]+$ */
223
+ claimId: string;
224
+ /**
225
+ * did:ixo:… The person filing: the Hub requires it to be the signer's
226
+ * own DID (the chain records it as attribution only and does not check
227
+ * it against the signer), else `400 operation_not_registered`,
228
+ * `reason: 'invalid_message: messages[i].agentDid'`.
229
+ */
230
+ agentDid: string;
231
+ adminAddress: string;
232
+ useIntent?: boolean;
233
+ }
234
+ | {
235
+ type: "ixo.claims.evaluate";
236
+ /** 1..256, ^[A-Za-z0-9:._/-]+$ */
237
+ claimId: string;
238
+ /** ^(0|[1-9][0-9]{0,19})$, ≤ 18446744073709551615 */
239
+ collectionId: string;
240
+ /** The evaluator DID recorded on the evaluation. */
241
+ oracle: string;
242
+ /**
243
+ * The EVALUATOR (the signer), not the claimant. The Hub requires
244
+ * `agentDid` to be the signer's own DID and `agentAddress` to equal
245
+ * `signer` (`invalid_message: messages[i].agentDid` / `.agentAddress`).
246
+ */
247
+ agentDid: string;
248
+ agentAddress: string;
249
+ adminAddress: string;
250
+ /** EvaluationStatus: 1 approved, 2 rejected, 3 disputed, 4 invalidated (0 pending, 5 flagged refused). */
251
+ status: 1 | 2 | 3 | 4;
252
+ /** uint32 code defined by the evaluator (the chain has no enum for it). */
253
+ reason?: number;
254
+ /** '' or 1..300 of ^[A-Za-z0-9:._/-]+$ (shown whole on the review). */
255
+ verificationProof?: string;
256
+ }
257
+ | {
258
+ type: "ixo.token.transfer";
259
+ recipient: string;
260
+ /** 1..32 lines; id 1..128 of ^[A-Za-z0-9:._/-]+$, amount ^[1-9][0-9]*$ */
261
+ tokens: Array<{ id: string; amount: string }>;
262
+ };
263
+ export type ChainTxOperation = {
264
+ kind: "ixo.chain.tx.v1";
265
+ /** Must equal the Hub RPC's chain id at prepare. */
266
+ chainId: string;
267
+ /** Must equal the Hub's `ixo ${CHAIN_NETWORK}`. */
268
+ network: "ixo mainnet" | "ixo testnet" | "ixo devnet";
269
+ /** 20-byte bech32 ixo address; must equal the person's Hub wallet address. */
270
+ signer: string;
271
+ /**
272
+ * 0..256 UTF-8 bytes, may be ''. No C0/C1 controls (so no newlines),
273
+ * zero-width, bidi or line/paragraph separator characters, no BOM.
274
+ */
275
+ memo: string;
276
+ /** 1..8, executed as ONE transaction (all or nothing). */
277
+ messages: ChainTxMessage[];
183
278
  };
279
+ export type ChainTxRiskLevel = "low" | "medium" | "high" | "critical";
280
+ export type ChainTxFact = { label: string; value: string; technical?: boolean };
281
+ export type ChainTxStep = {
282
+ /** 1-based */
283
+ index: number;
284
+ type: ChainTxMessageType;
285
+ /** ≤ 60, plain words. */
286
+ title: string;
287
+ /** One sentence, ≤ 160. */
288
+ whatItDoes: string;
289
+ /** `technical` facts go behind "Show technical details". */
290
+ facts: ChainTxFact[];
291
+ riskLevel: ChainTxRiskLevel;
292
+ cannotUndo: boolean;
293
+ /** cosmos.bank.send steps: the bank-send display (verified/unverified token rules). */
294
+ transfer?: TransferDisplay;
295
+ };
296
+ export type ChainTxDisplay = {
297
+ /** The highest step risk. */
298
+ riskLevel: ChainTxRiskLevel;
299
+ /** riskLevel is high or critical. */
300
+ confirmTwice: boolean;
301
+ steps: ChainTxStep[];
302
+ /** The checkbox text, ≤ 160. */
303
+ consent: string;
304
+ feeBaseUnits: string;
305
+ feeDenom: "uixo";
306
+ feeDisplay: string;
307
+ gasLimit: number;
308
+ feeGranter: string | null;
309
+ signer: string;
310
+ /** true when any step is wrapped in MsgExec. */
311
+ wrapped: boolean;
312
+ };
313
+ export type ChainTxFailureReason =
314
+ | "check_tx_rejected"
315
+ | "expired_not_included"
316
+ | "tx_failed";
317
+ export type ChainTxReceipt = {
318
+ kind: "ixo.chain.tx.v1";
319
+ actionId: string;
320
+ revision: number;
321
+ digest: string;
322
+ chainId: string;
323
+ txHash: string;
324
+ height: number | null;
325
+ /** Chain result code (0 = success) once included. */
326
+ code: number | null;
327
+ /**
328
+ * `check_tx_rejected`: never included, CheckTx `code` ≠ 0, height null;
329
+ * `expired_not_included`: never included, code null, height null;
330
+ * `tx_failed`: included (height set) with code ≠ 0.
331
+ */
332
+ reason?: ChainTxFailureReason;
333
+ /** ≤ 240, plain words for the person; only with a `reason`. */
334
+ message?: string;
335
+ /** The approved messages' types, in order. */
336
+ steps: Array<{ type: ChainTxMessageType }>;
337
+ };
338
+ export type ChainTxCapabilities = {
339
+ messageTypes: ChainTxMessageType[];
340
+ maxMessages: number;
341
+ };
342
+ export declare const CHAIN_TX_KIND: "ixo.chain.tx.v1";
343
+ export declare const CHAIN_TX_MESSAGE_TYPES: readonly [
344
+ "cosmos.bank.send",
345
+ "ixo.claims.submit",
346
+ "ixo.claims.evaluate",
347
+ "ixo.token.transfer",
348
+ ];
349
+ export declare const CHAIN_TX_MAX_MESSAGES: 8;
350
+ export declare const CHAIN_TX_MAX_TOKEN_LINES: 32;
351
+ export declare const CHAIN_TX_FAILURE_REASONS: readonly [
352
+ "check_tx_rejected",
353
+ "expired_not_included",
354
+ "tx_failed",
355
+ ];
356
+ export declare const CHAIN_TX_RISK_LEVELS: readonly [
357
+ "low",
358
+ "medium",
359
+ "high",
360
+ "critical",
361
+ ];
362
+ export declare const CHAIN_TX_EVALUATION_STATUSES: readonly [1, 2, 3, 4];
363
+ /**
364
+ * Why a proposed chain tx operation is malformed, as the Hub's 400 `reason`
365
+ * (`invalid_message: messages[1].toAddress`, 0-based; `invalid_operation: memo`),
366
+ * or null when it parses.
367
+ */
368
+ export declare function chainTxIssue(input: unknown): string | null;
369
+ export declare function parseChainTxDisplay(input: unknown): ChainTxDisplay;
370
+ export declare function parseChainTxCapabilities(
371
+ input: unknown,
372
+ ): ChainTxCapabilities;
184
373
  export declare function canonicalJson(value: unknown): string;
185
374
  export declare function digestOf(value: unknown): Promise<string>;
186
375
  export declare function parseOperation(value: unknown): ActionOperationV1;
package/src/index.js CHANGED
@@ -102,7 +102,14 @@ export async function digestOf(value) {
102
102
 
103
103
  export function parseOperation(input) {
104
104
  const op = object(input, "operation");
105
+ // 0.6.0: field-level errors first (`Invalid messages[1].toAddress`), then
106
+ // the JSON schema as a backstop.
107
+ if (op.kind === CHAIN_TX_KIND) {
108
+ const field = chainTxField(op);
109
+ if (field) fail(field);
110
+ }
105
111
  validateOperationSchema(op);
112
+ if (op.kind === CHAIN_TX_KIND) return op;
106
113
  if (op.kind === "statement.sign.v1") {
107
114
  utf8(op.statement, "statement");
108
115
  return op;
@@ -304,6 +311,7 @@ export function assertHubReferenceUrl(input, configuredOrigin) {
304
311
  export function parseReceipt(input) {
305
312
  const receipt = object(input, "receipt");
306
313
  if (p2ReceiptFields[receipt.kind]) return parseP2Receipt(receipt);
314
+ if (receipt.kind === CHAIN_TX_KIND) return parseChainTxReceipt(receipt);
307
315
  if (receipt.kind === "form.submission.v1") {
308
316
  exact(
309
317
  receipt,
@@ -395,10 +403,25 @@ export function parseReviewView(input) {
395
403
  "chatUrl",
396
404
  "service",
397
405
  "transfer",
406
+ "chainTx",
398
407
  ],
399
408
  "view",
400
409
  );
401
410
  parseReference(view.reference);
411
+ parseOperation(view.operation);
412
+ // 0.6.0: the Hub-computed chain transaction display (chain tx cards only).
413
+ if (view.chainTx !== undefined && view.chainTx !== null) {
414
+ if (view.operation?.kind !== CHAIN_TX_KIND) fail("view.chainTx");
415
+ const display = parseChainTxDisplay(view.chainTx);
416
+ if (
417
+ display.signer !== view.operation.signer ||
418
+ display.steps.length !== view.operation.messages.length ||
419
+ display.steps.some(
420
+ (step, i) => step.type !== view.operation.messages[i].type,
421
+ )
422
+ )
423
+ fail("view.chainTx");
424
+ }
402
425
  if (view.service !== undefined && view.service !== null) {
403
426
  object(view.service, "view.service");
404
427
  exact(
@@ -578,9 +601,21 @@ export function parseCapabilities(input) {
578
601
  "operations",
579
602
  "forms",
580
603
  "transfer",
604
+ "chainTx",
581
605
  ],
582
606
  "capabilities",
583
607
  );
608
+ // 0.6.0 (`?version=4`): what a chain transaction may carry. Required when
609
+ // the kind is listed; never present otherwise except as null.
610
+ if (data.chainTx !== undefined && data.chainTx !== null)
611
+ parseChainTxCapabilities(data.chainTx);
612
+ if (
613
+ Array.isArray(data.operations) &&
614
+ data.operations.includes(CHAIN_TX_KIND)
615
+ ? data.chainTx === undefined || data.chainTx === null
616
+ : data.chainTx !== undefined && data.chainTx !== null
617
+ )
618
+ fail("capabilities.chainTx");
584
619
  if (
585
620
  ![CAPABILITIES_VERSION_V1, CAPABILITIES_VERSION_V2].includes(data.version)
586
621
  )
@@ -777,6 +812,7 @@ const receiptKinds = {
777
812
  "calendar.event.create.v1": "calendar.event.created.v1",
778
813
  "vfs.access.request.v1": "vfs.access.requested.v1",
779
814
  "vfs.text.save.v1": "vfs.text.saved.v1",
815
+ "ixo.chain.tx.v1": "ixo.chain.tx.v1",
780
816
  };
781
817
  export function assertReceiptForOperation(
782
818
  operation,
@@ -800,6 +836,14 @@ export function assertReceiptForOperation(
800
836
  receipt.kind === "service.failure.v1"
801
837
  )
802
838
  fail("operation receipt");
839
+ // 0.6.0: a chain tx receipt names the approved chain and steps, in order.
840
+ if (
841
+ operation.kind === CHAIN_TX_KIND &&
842
+ (receipt.chainId !== operation.chainId ||
843
+ receipt.steps.length !== operation.messages.length ||
844
+ receipt.steps.some((step, i) => step.type !== operation.messages[i].type))
845
+ )
846
+ fail("receipt steps");
803
847
  // Every kind: the receipt must name the approved connection / target.
804
848
  if (
805
849
  "connectionId" in operation &&
@@ -1246,6 +1290,16 @@ function validCalendarInstant(value) {
1246
1290
 
1247
1291
  /** Status rules shared by review views and outcomes. */
1248
1292
  function receiptFitsStatus(receipt, status) {
1293
+ // 0.6.0: a chain tx receipt succeeds only included with code 0; a failure
1294
+ // always names its reason (tx_failed = included with code != 0).
1295
+ if (receipt.kind === CHAIN_TX_KIND) {
1296
+ if (status === "succeeded")
1297
+ return (
1298
+ receipt.code === 0 && receipt.height !== null && !("reason" in receipt)
1299
+ );
1300
+ if (status === "failed") return "reason" in receipt;
1301
+ return true;
1302
+ }
1249
1303
  const bank = receipt.kind === "ixo.bank.send.v1";
1250
1304
  if (status === "succeeded")
1251
1305
  return bank
@@ -1325,6 +1379,356 @@ export function parseTransferDisplay(input) {
1325
1379
  return t;
1326
1380
  }
1327
1381
 
1382
+ // ---------------------------------------------------------------------------
1383
+ // 0.6.0 chain transactions (`ixo.chain.tx.v1`)
1384
+ // ---------------------------------------------------------------------------
1385
+
1386
+ /** One card kind for every chain transaction (1..8 messages, all or nothing). */
1387
+ export const CHAIN_TX_KIND = "ixo.chain.tx.v1";
1388
+ export const CHAIN_TX_MESSAGE_TYPES = [
1389
+ "cosmos.bank.send",
1390
+ "ixo.claims.submit",
1391
+ "ixo.claims.evaluate",
1392
+ "ixo.token.transfer",
1393
+ ];
1394
+ export const CHAIN_TX_MAX_MESSAGES = 8;
1395
+ export const CHAIN_TX_MAX_TOKEN_LINES = 32;
1396
+ /** `check_tx_rejected`/`expired_not_included`: never included; `tx_failed`: included with code != 0. */
1397
+ export const CHAIN_TX_FAILURE_REASONS = [
1398
+ "check_tx_rejected",
1399
+ "expired_not_included",
1400
+ "tx_failed",
1401
+ ];
1402
+ export const CHAIN_TX_RISK_LEVELS = ["low", "medium", "high", "critical"];
1403
+ /** EvaluationStatus values a chain tx may record (0 pending and 5 flagged are refused). */
1404
+ export const CHAIN_TX_EVALUATION_STATUSES = [1, 2, 3, 4];
1405
+ // The chain's DID rule (x/iid/types/iid.go didValidationRegexpStr): segments of
1406
+ // [A-Za-z0-9._-] or a `%` followed by two hex digits, joined by ':', the last
1407
+ // one non-empty. Anchored at both ends here (the chain's own regex anchors
1408
+ // only its start, so it accepts any suffix; this is stricter, never looser).
1409
+ const DID_TAIL = "(?:(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})*:)*(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})+";
1410
+ const IXO_DID = new RegExp(`^did:ixo:${DID_TAIL}$`);
1411
+ const ANY_DID = new RegExp(`^did:[a-z0-9]+:${DID_TAIL}$`);
1412
+ // The Hub's isIxoAddress: canonical lowercase bech32 with exactly 20 data
1413
+ // bytes (32 payload + 6 checksum characters). The Hub also checks the checksum.
1414
+ const ACCOUNT_ADDRESS = /^ixo1[023456789acdefghjklmnpqrstuvwxyz]{38}$/;
1415
+ const BASE_UNITS = /^[1-9][0-9]{0,77}$/;
1416
+ // A uint64 without leading zeros (checked against UINT64_MAX below).
1417
+ const COLLECTION_ID = /^(0|[1-9][0-9]{0,19})$/;
1418
+ const UINT64_MAX = 18446744073709551615n;
1419
+ const UINT32_MAX = 4294967295;
1420
+ // Claim ids, impact token ids and verification proofs (CIDs, UUIDs, `X:1`).
1421
+ const CHAIN_ID_CHARS = /^[A-Za-z0-9:._/-]+$/;
1422
+ // C0/C1 controls, zero-width and bidi marks (U+061C, U+200B-U+200F,
1423
+ // U+202A-U+202E, U+2066-U+2069), line/paragraph separators and the BOM would
1424
+ // let text render as something else.
1425
+ const CONTROL =
1426
+ /[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069\ufeff]/;
1427
+ const CHAIN_TX_MESSAGE_KEYS = {
1428
+ "cosmos.bank.send": ["type", "toAddress", "amountBaseUnits", "denom"],
1429
+ "ixo.claims.submit": [
1430
+ "type",
1431
+ "collectionId",
1432
+ "claimId",
1433
+ "agentDid",
1434
+ "adminAddress",
1435
+ "useIntent",
1436
+ ],
1437
+ "ixo.claims.evaluate": [
1438
+ "type",
1439
+ "claimId",
1440
+ "collectionId",
1441
+ "oracle",
1442
+ "agentDid",
1443
+ "agentAddress",
1444
+ "adminAddress",
1445
+ "status",
1446
+ "reason",
1447
+ "verificationProof",
1448
+ ],
1449
+ "ixo.token.transfer": ["type", "recipient", "tokens"],
1450
+ };
1451
+ const plain = (value) =>
1452
+ value !== null && typeof value === "object" && !Array.isArray(value);
1453
+ const isText = (value, min = 1, max = 200) =>
1454
+ typeof value === "string" && value.length >= min && value.length <= max;
1455
+ const isMatch = (value, regex, max = 200) =>
1456
+ isText(value, 1, max) && regex.test(value);
1457
+ const isId = (value, max) => isMatch(value, CHAIN_ID_CHARS, max);
1458
+ const isCollectionId = (value) =>
1459
+ isMatch(value, COLLECTION_ID, 20) && BigInt(value) <= UINT64_MAX;
1460
+ const utf8Length = (value) => new TextEncoder().encode(value).length;
1461
+
1462
+ /** The first bad field of one message (relative to the message), or null. */
1463
+ function chainTxMessageField(m) {
1464
+ if (m.type === "cosmos.bank.send") {
1465
+ if (!isMatch(m.toAddress, ACCOUNT_ADDRESS)) return "toAddress";
1466
+ if (!isMatch(m.amountBaseUnits, BASE_UNITS, 78)) return "amountBaseUnits";
1467
+ if (m.denom !== undefined && !isMatch(m.denom, DENOM, 128)) return "denom";
1468
+ return null;
1469
+ }
1470
+ if (m.type === "ixo.claims.submit") {
1471
+ if (!isCollectionId(m.collectionId)) return "collectionId";
1472
+ if (!isId(m.claimId, 256)) return "claimId";
1473
+ if (!isMatch(m.agentDid, IXO_DID)) return "agentDid";
1474
+ if (!isMatch(m.adminAddress, ACCOUNT_ADDRESS)) return "adminAddress";
1475
+ if (m.useIntent !== undefined && typeof m.useIntent !== "boolean")
1476
+ return "useIntent";
1477
+ return null;
1478
+ }
1479
+ if (m.type === "ixo.claims.evaluate") {
1480
+ if (!isId(m.claimId, 256)) return "claimId";
1481
+ if (!isCollectionId(m.collectionId)) return "collectionId";
1482
+ if (!isMatch(m.oracle, ANY_DID)) return "oracle";
1483
+ if (!isMatch(m.agentDid, IXO_DID)) return "agentDid";
1484
+ if (!isMatch(m.agentAddress, ACCOUNT_ADDRESS)) return "agentAddress";
1485
+ if (!isMatch(m.adminAddress, ACCOUNT_ADDRESS)) return "adminAddress";
1486
+ if (!CHAIN_TX_EVALUATION_STATUSES.includes(m.status)) return "status";
1487
+ if (
1488
+ m.reason !== undefined &&
1489
+ !(Number.isSafeInteger(m.reason) && m.reason >= 0 && m.reason <= UINT32_MAX)
1490
+ )
1491
+ return "reason";
1492
+ // Optional; omit it rather than sending ''. ≤ 300 so the review shows it whole.
1493
+ if (m.verificationProof !== undefined && !isId(m.verificationProof, 300))
1494
+ return "verificationProof";
1495
+ return null;
1496
+ }
1497
+ // ixo.token.transfer
1498
+ if (!isMatch(m.recipient, ACCOUNT_ADDRESS)) return "recipient";
1499
+ if (
1500
+ !Array.isArray(m.tokens) ||
1501
+ m.tokens.length < 1 ||
1502
+ m.tokens.length > CHAIN_TX_MAX_TOKEN_LINES
1503
+ )
1504
+ return "tokens";
1505
+ for (const [j, token] of m.tokens.entries()) {
1506
+ if (!plain(token)) return `tokens[${j}]`;
1507
+ for (const key of Object.keys(token))
1508
+ if (key !== "id" && key !== "amount") return `tokens[${j}].${key}`;
1509
+ if (!isId(token.id, 128)) return `tokens[${j}].id`;
1510
+ if (!isMatch(token.amount, BASE_UNITS, 78)) return `tokens[${j}].amount`;
1511
+ }
1512
+ return null;
1513
+ }
1514
+
1515
+ /** The first bad field of a chain tx operation (`messages[1].toAddress`), or null. */
1516
+ function chainTxField(op) {
1517
+ for (const key of Object.keys(op))
1518
+ if (!["kind", "chainId", "network", "signer", "memo", "messages"].includes(key))
1519
+ return key;
1520
+ if (!isText(op.chainId, 1, 100)) return "chainId";
1521
+ if (!NETWORKS.includes(op.network)) return "network";
1522
+ if (!isMatch(op.signer, ACCOUNT_ADDRESS)) return "signer";
1523
+ // Cosmos SDK x/auth max_memo_characters counts UTF-8 bytes. The memo is
1524
+ // shown as the "Note", so it carries no control or bidi characters either.
1525
+ if (
1526
+ !isText(op.memo, 0, 256) ||
1527
+ utf8Length(op.memo) > MEMO_BYTES ||
1528
+ CONTROL.test(op.memo)
1529
+ )
1530
+ return "memo";
1531
+ if (
1532
+ !Array.isArray(op.messages) ||
1533
+ op.messages.length < 1 ||
1534
+ op.messages.length > CHAIN_TX_MAX_MESSAGES
1535
+ )
1536
+ return "messages";
1537
+ for (const [i, m] of op.messages.entries()) {
1538
+ const at = `messages[${i}]`;
1539
+ if (!plain(m)) return at;
1540
+ if (!CHAIN_TX_MESSAGE_TYPES.includes(m.type)) return `${at}.type`;
1541
+ for (const key of Object.keys(m))
1542
+ if (!CHAIN_TX_MESSAGE_KEYS[m.type].includes(key)) return `${at}.${key}`;
1543
+ const field = chainTxMessageField(m);
1544
+ if (field) return `${at}.${field}`;
1545
+ }
1546
+ return null;
1547
+ }
1548
+
1549
+ /**
1550
+ * Why a proposed chain tx operation is malformed, as the Hub's 400 `reason`:
1551
+ * `invalid_message: messages[1].toAddress` (0-based message index) or
1552
+ * `invalid_operation: memo`; null when it parses.
1553
+ */
1554
+ export function chainTxIssue(input) {
1555
+ if (!plain(input) || input.kind !== CHAIN_TX_KIND)
1556
+ return "invalid_operation: kind";
1557
+ const field = chainTxField(input);
1558
+ if (field)
1559
+ return field.startsWith("messages[")
1560
+ ? `invalid_message: ${field}`
1561
+ : `invalid_operation: ${field}`;
1562
+ try {
1563
+ validateOperationSchema(input);
1564
+ } catch {
1565
+ return "invalid_operation: operation";
1566
+ }
1567
+ return null;
1568
+ }
1569
+
1570
+ /** `GET /capabilities?version=4` `chainTx`. */
1571
+ export function parseChainTxCapabilities(input) {
1572
+ const c = object(input, "capabilities.chainTx");
1573
+ exact(c, ["messageTypes", "maxMessages"], "capabilities.chainTx");
1574
+ if (
1575
+ !Array.isArray(c.messageTypes) ||
1576
+ c.messageTypes.length < 1 ||
1577
+ new Set(c.messageTypes).size !== c.messageTypes.length ||
1578
+ c.messageTypes.some((type) => !CHAIN_TX_MESSAGE_TYPES.includes(type))
1579
+ )
1580
+ fail("capabilities.chainTx.messageTypes");
1581
+ if (
1582
+ !Number.isSafeInteger(c.maxMessages) ||
1583
+ c.maxMessages < 1 ||
1584
+ c.maxMessages > CHAIN_TX_MAX_MESSAGES
1585
+ )
1586
+ fail("capabilities.chainTx.maxMessages");
1587
+ return c;
1588
+ }
1589
+
1590
+ /** The Hub-computed review display of a chain tx (the only thing a page renders). */
1591
+ export function parseChainTxDisplay(input) {
1592
+ const d = object(input, "view.chainTx");
1593
+ exact(
1594
+ d,
1595
+ [
1596
+ "riskLevel",
1597
+ "confirmTwice",
1598
+ "steps",
1599
+ "consent",
1600
+ "feeBaseUnits",
1601
+ "feeDenom",
1602
+ "feeDisplay",
1603
+ "gasLimit",
1604
+ "feeGranter",
1605
+ "signer",
1606
+ "wrapped",
1607
+ ],
1608
+ "view.chainTx",
1609
+ );
1610
+ if (!CHAIN_TX_RISK_LEVELS.includes(d.riskLevel)) fail("view.chainTx.riskLevel");
1611
+ if (
1612
+ typeof d.confirmTwice !== "boolean" ||
1613
+ d.confirmTwice !== (d.riskLevel === "high" || d.riskLevel === "critical")
1614
+ )
1615
+ fail("view.chainTx.confirmTwice");
1616
+ if (
1617
+ !Array.isArray(d.steps) ||
1618
+ d.steps.length < 1 ||
1619
+ d.steps.length > CHAIN_TX_MAX_MESSAGES
1620
+ )
1621
+ fail("view.chainTx.steps");
1622
+ let highest = 0;
1623
+ for (const [i, step] of d.steps.entries()) {
1624
+ object(step, "view.chainTx.step");
1625
+ exact(
1626
+ step,
1627
+ [
1628
+ "index",
1629
+ "type",
1630
+ "title",
1631
+ "whatItDoes",
1632
+ "facts",
1633
+ "riskLevel",
1634
+ "cannotUndo",
1635
+ "transfer",
1636
+ ],
1637
+ "view.chainTx.step",
1638
+ );
1639
+ if (step.index !== i + 1) fail("view.chainTx.step.index");
1640
+ if (!CHAIN_TX_MESSAGE_TYPES.includes(step.type)) fail("view.chainTx.step.type");
1641
+ str(step.title, "view.chainTx.step.title", 1, 60);
1642
+ str(step.whatItDoes, "view.chainTx.step.whatItDoes", 1, 160);
1643
+ if (!Array.isArray(step.facts) || step.facts.length > 40)
1644
+ fail("view.chainTx.step.facts");
1645
+ for (const fact of step.facts) {
1646
+ object(fact, "view.chainTx.fact");
1647
+ exact(fact, ["label", "value", "technical"], "view.chainTx.fact");
1648
+ str(fact.label, "view.chainTx.fact.label", 1, 60);
1649
+ str(fact.value, "view.chainTx.fact.value", 1, 300);
1650
+ if (fact.technical !== undefined && typeof fact.technical !== "boolean")
1651
+ fail("view.chainTx.fact.technical");
1652
+ }
1653
+ const risk = CHAIN_TX_RISK_LEVELS.indexOf(step.riskLevel);
1654
+ if (risk < 0) fail("view.chainTx.step.riskLevel");
1655
+ highest = Math.max(highest, risk);
1656
+ if (typeof step.cannotUndo !== "boolean") fail("view.chainTx.step.cannotUndo");
1657
+ if (step.transfer !== undefined) {
1658
+ if (step.type !== "cosmos.bank.send") fail("view.chainTx.step.transfer");
1659
+ parseTransferDisplay(step.transfer);
1660
+ }
1661
+ }
1662
+ if (CHAIN_TX_RISK_LEVELS[highest] !== d.riskLevel)
1663
+ fail("view.chainTx.riskLevel");
1664
+ str(d.consent, "view.chainTx.consent", 1, 160);
1665
+ pattern(d.feeBaseUnits, INT, "view.chainTx.feeBaseUnits");
1666
+ if (d.feeDenom !== "uixo") fail("view.chainTx.feeDenom");
1667
+ str(d.feeDisplay, "view.chainTx.feeDisplay", 1, 80);
1668
+ num(d.gasLimit, "view.chainTx.gasLimit");
1669
+ if (d.feeGranter !== null)
1670
+ pattern(d.feeGranter, ADDRESS, "view.chainTx.feeGranter");
1671
+ pattern(d.signer, ACCOUNT_ADDRESS, "view.chainTx.signer");
1672
+ if (typeof d.wrapped !== "boolean") fail("view.chainTx.wrapped");
1673
+ return d;
1674
+ }
1675
+
1676
+ function parseChainTxReceipt(r) {
1677
+ exact(
1678
+ r,
1679
+ [
1680
+ "kind",
1681
+ "actionId",
1682
+ "revision",
1683
+ "digest",
1684
+ "chainId",
1685
+ "txHash",
1686
+ "height",
1687
+ "code",
1688
+ "reason",
1689
+ "message",
1690
+ "steps",
1691
+ ],
1692
+ "receipt",
1693
+ );
1694
+ pattern(r.actionId, ID, "receipt.actionId");
1695
+ num(r.revision, "receipt.revision");
1696
+ pattern(r.digest, HEX, "receipt.digest");
1697
+ str(r.chainId, "receipt.chainId", 1, 100);
1698
+ pattern(r.txHash, HEX, "receipt.txHash");
1699
+ if (r.height !== null) num(r.height, "receipt.height");
1700
+ if (r.code !== null && (!Number.isSafeInteger(r.code) || r.code < 0))
1701
+ fail("receipt.code");
1702
+ if ("reason" in r) {
1703
+ const failedCode = r.code !== null && r.code !== 0;
1704
+ if (
1705
+ !CHAIN_TX_FAILURE_REASONS.includes(r.reason) ||
1706
+ (r.reason === "check_tx_rejected" && (r.height !== null || !failedCode)) ||
1707
+ (r.reason === "expired_not_included" &&
1708
+ (r.height !== null || r.code !== null)) ||
1709
+ (r.reason === "tx_failed" && (r.height === null || !failedCode))
1710
+ )
1711
+ fail("receipt.reason");
1712
+ }
1713
+ // Plain words for the person, only on a failure.
1714
+ if ("message" in r) {
1715
+ if (!("reason" in r)) fail("receipt.message");
1716
+ str(r.message, "receipt.message", 1, 240);
1717
+ }
1718
+ if (
1719
+ !Array.isArray(r.steps) ||
1720
+ r.steps.length < 1 ||
1721
+ r.steps.length > CHAIN_TX_MAX_MESSAGES
1722
+ )
1723
+ fail("receipt.steps");
1724
+ for (const step of r.steps) {
1725
+ object(step, "receipt.step");
1726
+ exact(step, ["type"], "receipt.step");
1727
+ if (!CHAIN_TX_MESSAGE_TYPES.includes(step.type)) fail("receipt.step.type");
1728
+ }
1729
+ return r;
1730
+ }
1731
+
1328
1732
  export * from "./outcome-signature.js";
1329
1733
 
1330
1734
  /** The exact 0.1.0 receipt shape (v1 callers): drops the 0.3.0 bank fields. */
@@ -45,6 +45,67 @@ const mailbox = {
45
45
  pattern:
46
46
  "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$",
47
47
  };
48
+ // 0.6.0 chain transactions (`ixo.chain.tx.v1`): the shapes only. The field
49
+ // parser (`chainTxIssue` in index.js) checks addresses, DIDs and byte lengths,
50
+ // and the Hub enforces signer, network and chain rules.
51
+ const baseUnits = { ...string(1, 78), pattern: "^[1-9][0-9]*$" };
52
+ // The chain's DID segments (x/iid): [A-Za-z0-9._-] or `%` + two hex digits.
53
+ const didTail =
54
+ "(?:(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})*:)*(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})+";
55
+ const ixoDid = { ...string(9, 200), pattern: `^did:ixo:${didTail}$` };
56
+ const anyDid = { ...string(7, 200), pattern: `^did:[a-z0-9]+:${didTail}$` };
57
+ // uint64, no leading zeros (the field parser also checks the uint64 maximum).
58
+ const collectionId = { ...string(1, 20), pattern: "^(0|[1-9][0-9]{0,19})$" };
59
+ // A 20-byte ixo account address (the Hub also checks the bech32 checksum).
60
+ const account = { ...string(42, 42), pattern: "^ixo1[023456789acdefghjklmnpqrstuvwxyz]{38}$" };
61
+ // Claim ids, impact token ids and verification proofs.
62
+ const chainText = (min, max) => ({
63
+ ...string(min, max),
64
+ pattern: min > 0 ? "^[A-Za-z0-9:._/-]+$" : "^[A-Za-z0-9:._/-]*$",
65
+ });
66
+ const chainTxMessage = {
67
+ anyOf: [
68
+ object({
69
+ type: { const: "cosmos.bank.send" },
70
+ toAddress: account,
71
+ amountBaseUnits: baseUnits,
72
+ denom: optional({ ...string(3, 128), pattern: "^[a-zA-Z][a-zA-Z0-9/:._-]{2,127}$" }),
73
+ }),
74
+ object({
75
+ type: { const: "ixo.claims.submit" },
76
+ collectionId,
77
+ claimId: chainText(1, 256),
78
+ agentDid: ixoDid,
79
+ adminAddress: account,
80
+ useIntent: optional({ type: "boolean" }),
81
+ }),
82
+ object({
83
+ type: { const: "ixo.claims.evaluate" },
84
+ claimId: chainText(1, 256),
85
+ collectionId,
86
+ oracle: anyDid,
87
+ agentDid: ixoDid,
88
+ agentAddress: account,
89
+ adminAddress: account,
90
+ // EvaluationStatus 1 approved, 2 rejected, 3 disputed, 4 invalidated
91
+ // (0 pending and 5 flagged are refused).
92
+ status: enumeration(1, 2, 3, 4),
93
+ // uint32 code defined by the evaluator (the chain has no enum for it).
94
+ reason: optional({ type: "integer", minimum: 0, maximum: 4294967295 }),
95
+ verificationProof: optional(chainText(1, 300)),
96
+ }),
97
+ object({
98
+ type: { const: "ixo.token.transfer" },
99
+ recipient: account,
100
+ tokens: {
101
+ type: "array",
102
+ items: object({ id: chainText(1, 128), amount: baseUnits }),
103
+ minItems: 1,
104
+ maxItems: 32,
105
+ },
106
+ }),
107
+ ],
108
+ };
48
109
  const registry = {
49
110
  "form.submit.v1": {
50
111
  formId: string(1, 120),
@@ -129,6 +190,13 @@ const registry = {
129
190
  },
130
191
  text: string(0, 8192),
131
192
  },
193
+ "ixo.chain.tx.v1": {
194
+ chainId: string(1, 100),
195
+ network: enumeration("ixo mainnet", "ixo testnet", "ixo devnet"),
196
+ signer: account,
197
+ memo: string(0, 256),
198
+ messages: { type: "array", items: chainTxMessage, minItems: 1, maxItems: 8 },
199
+ },
132
200
  };
133
201
  export const operationKinds = Object.freeze(Object.keys(registry));
134
202
  export const operationJsonSchema = Object.freeze({
@@ -143,6 +211,12 @@ function matches(value, schema) {
143
211
  if (schema.enum) return schema.enum.includes(value);
144
212
  if (schema.type === "null") return value === null;
145
213
  if (schema.type === "boolean") return typeof value === "boolean";
214
+ if (schema.type === "integer")
215
+ return (
216
+ Number.isSafeInteger(value) &&
217
+ value >= (schema.minimum ?? Number.MIN_SAFE_INTEGER) &&
218
+ value <= (schema.maximum ?? Number.MAX_SAFE_INTEGER)
219
+ );
146
220
  if (schema.type === "string")
147
221
  return (
148
222
  typeof value === "string" &&