@ixo/action-protocol 0.6.0 → 0.7.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 +42 -0
- package/README.md +32 -0
- package/package.json +1 -1
- package/src/index.d.ts +147 -0
- package/src/index.js +286 -3
- package/src/operation-schema.js +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
Two operation kinds for reviewed submissions the person makes on a claim
|
|
6
|
+
collection. Both are approved with `/decision` (no separate sign step); the Hub
|
|
7
|
+
signs with the keys it holds for the person.
|
|
8
|
+
|
|
9
|
+
- `ixo.bid.submit.v1`: send an application (`role: "SA"`) to the collection's
|
|
10
|
+
bids bot. `data` is the JSON object of the `#bco` SurveyJS answers;
|
|
11
|
+
`summary` is what the card shows: 0-100 `{field, label, value}` rows, one
|
|
12
|
+
per answer of `data` (`submissionSummaryIssue`, `submissionDisplayValue`:
|
|
13
|
+
the parser refuses a card that does not show exactly its data). Receipt
|
|
14
|
+
`ixo.bid.submission.v1` (`collectionId`, `bidId` or null, `submittedAt`).
|
|
15
|
+
- `ixo.claim.submit.v1`: submit a claim. `data` is the JSON object of the
|
|
16
|
+
`#vct` answers without file questions; `evidence` (0-30) lists files the
|
|
17
|
+
channel gateway holds (`field`, https `url`, `filename`, `mimetype`, `size`,
|
|
18
|
+
lowercase `sha256`), which the Hub uploads to the collection's VFS claims
|
|
19
|
+
lane and places at `field`. Receipt `ixo.claim.submission.v1`
|
|
20
|
+
(`collectionId`, `claimId`, lowercase `transactionHash`, `height` of the
|
|
21
|
+
block that included it, `submittedAt`).
|
|
22
|
+
- `ixo.submission.failed.v1`: the receipt of a failed application or claim
|
|
23
|
+
submission (`step`: collection, evidence, key, bid_bot, claim_bot or chain;
|
|
24
|
+
`message`; optional `detail`; `failedAt`). v2 envelopes only. `message` is
|
|
25
|
+
plain words the Hub chose from the step and a known cause, always with a
|
|
26
|
+
next step: the only text a gateway or runtime may show or relay. `detail`
|
|
27
|
+
is optional technical text (what a service or the network said) for the
|
|
28
|
+
review page's closed disclosure; never relay it. Both are at most 500 and
|
|
29
|
+
must already be in `sanitizeSubmissionText` form (no control, zero-width or
|
|
30
|
+
bidi characters, nothing link-like, collapsed whitespace), or the parser
|
|
31
|
+
refuses them.
|
|
32
|
+
- `sanitizeSubmissionText(text)`, `SUBMISSION_TEXT_MAX`: the sanitizer the
|
|
33
|
+
parser checks against (idempotent). It looks at the first 2000 characters
|
|
34
|
+
only and its expressions are bounded, so no input makes it slow; unpaired
|
|
35
|
+
surrogates are dropped and the result is always a fixed point.
|
|
36
|
+
- Review view `collectionName` (application and claim cards): the
|
|
37
|
+
collection's name as the Hub read it when the card was made, or null.
|
|
38
|
+
- Review view `networkFee` (claim cards only): `covered` (a usable fee grant
|
|
39
|
+
allows the claim's MsgExec) or `balance` (the person's IXO pays it, also
|
|
40
|
+
when the grants could not be read). `SUBMISSION_NETWORK_FEES`.
|
|
41
|
+
- The Hub offers and accepts these kinds only from callers that declare
|
|
42
|
+
`?version=5` (wire level 5 = level 4 + these cards; a 0.6.0 parser
|
|
43
|
+
rejects an unknown kind).
|
|
44
|
+
|
|
3
45
|
## 0.6.0
|
|
4
46
|
|
|
5
47
|
One card kind for every chain transaction: `ixo.chain.tx.v1`. Every existing
|
package/README.md
CHANGED
|
@@ -24,6 +24,38 @@ Callers declare the envelope version they parse with `?version=2` on
|
|
|
24
24
|
kind). Callers below 4 never see the kind, and a `POST` of it answers
|
|
25
25
|
`400 protocol_version_required`.
|
|
26
26
|
|
|
27
|
+
- `?version=5` (0.7.0): level 4 plus the application and claim cards
|
|
28
|
+
(`ixo.bid.submit.v1`, `ixo.claim.submit.v1`) and their receipts. Callers
|
|
29
|
+
below 5 never see the kinds and get `400 protocol_version_required` for
|
|
30
|
+
them.
|
|
31
|
+
|
|
32
|
+
## Applications and claims (`ixo.bid.submit.v1`, `ixo.claim.submit.v1`, 0.7.0)
|
|
33
|
+
|
|
34
|
+
- `summary`: one row per answer of `data`, `{field, label, value}`. `field`
|
|
35
|
+
is the answer's path (object keys and array indices joined with `.`, e.g.
|
|
36
|
+
`shops.1.name`); `value` is exactly `submissionDisplayValue(answer)`: a
|
|
37
|
+
string as it is, a number or boolean as `String(value)`, `null` as `""`,
|
|
38
|
+
an array of strings, numbers and booleans joined with `", "`. The answers
|
|
39
|
+
are the leaves of `data` (objects and arrays of objects are walked, not
|
|
40
|
+
shown); every answer needs exactly one row, no row may name anything
|
|
41
|
+
else, keys may not be empty or contain `.`, and a claim's evidence `field`
|
|
42
|
+
must not already hold an answer. `parseOperation` refuses any other card;
|
|
43
|
+
`submissionSummaryIssue(op)` names the first problem.
|
|
44
|
+
- Approved with `/decision` and `declaration: true`; the Hub runs the steps as the person and may
|
|
45
|
+
finish after the approve response (`submitted` first, then `succeeded` or
|
|
46
|
+
`failed`; a claim's transaction can also be `unknown` until it is seen).
|
|
47
|
+
- Receipts: `ixo.bid.submission.v1` (`collectionId`, `bidId` or null,
|
|
48
|
+
`submittedAt`); `ixo.claim.submission.v1` (`collectionId`, `claimId`,
|
|
49
|
+
lowercase `transactionHash`, `height`, `submittedAt`).
|
|
50
|
+
- Failure: `ixo.submission.failed.v1` with `step`, `message`, optional
|
|
51
|
+
`detail`, `failedAt`. Show or relay **`message` only**: it is the Hub's own
|
|
52
|
+
plain sentence and always says what to do next. `detail` is technical text
|
|
53
|
+
for the review page's "Show technical details"; never show it in a chat.
|
|
54
|
+
Both are sanitized (`sanitizeSubmissionText`) and the parser refuses any
|
|
55
|
+
other form.
|
|
56
|
+
- A claim card's review view carries `networkFee`: `covered` or `balance`
|
|
57
|
+
(who pays the network fee; no amount).
|
|
58
|
+
|
|
27
59
|
## Bank send (`ixo.bank.send.v1`)
|
|
28
60
|
|
|
29
61
|
- `denom`: any Cosmos denom matching `DENOM`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ixo/action-protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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
|
@@ -6,9 +6,54 @@ export type FormField = {
|
|
|
6
6
|
value: string;
|
|
7
7
|
source: "user" | "record" | "suggestion";
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* 0.7.0: one row an application or claim card shows: one answer of `data`.
|
|
11
|
+
* `field` is the answer's path in `data` (a key, or a dot path into objects
|
|
12
|
+
* and dynamic panels, e.g. "shops.3.name"); `value` must be exactly
|
|
13
|
+
* `submissionDisplayValue` of the answer there. Every answer of `data` has
|
|
14
|
+
* exactly one row (see `submissionSummaryIssue`).
|
|
15
|
+
*/
|
|
16
|
+
export type SubmissionSummaryRow = { field: string; label: string; value: string };
|
|
17
|
+
/** 0.7.0: a file the person sent on the channel, uploaded by the Hub as claim evidence. */
|
|
18
|
+
export type ClaimEvidence = {
|
|
19
|
+
/** SurveyJS question name (a dot path for panel items, e.g. "shops.3.photo"). */
|
|
20
|
+
field: string;
|
|
21
|
+
/** https link the gateway serves the bytes from. */
|
|
22
|
+
url: string;
|
|
23
|
+
filename: string;
|
|
24
|
+
mimetype: string;
|
|
25
|
+
size: number;
|
|
26
|
+
/** Lowercase hex SHA-256 of the bytes. */
|
|
27
|
+
sha256: string;
|
|
28
|
+
};
|
|
29
|
+
export type SubmissionNetwork = "ixo mainnet" | "ixo testnet" | "ixo devnet";
|
|
30
|
+
/** 0.7.0: send an application (the collection's #bco answers) to the bids bot as the person. */
|
|
31
|
+
export type BidSubmitOperation = {
|
|
32
|
+
kind: "ixo.bid.submit.v1";
|
|
33
|
+
network: SubmissionNetwork;
|
|
34
|
+
collectionId: string;
|
|
35
|
+
title: string;
|
|
36
|
+
role: "SA";
|
|
37
|
+
summary: SubmissionSummaryRow[];
|
|
38
|
+
/** JSON object: the SurveyJS answers. */
|
|
39
|
+
data: string;
|
|
40
|
+
};
|
|
41
|
+
/** 0.7.0: submit a claim (the collection's #vct answers plus evidence) as the person. */
|
|
42
|
+
export type ClaimSubmitOperation = {
|
|
43
|
+
kind: "ixo.claim.submit.v1";
|
|
44
|
+
network: SubmissionNetwork;
|
|
45
|
+
collectionId: string;
|
|
46
|
+
title: string;
|
|
47
|
+
summary: SubmissionSummaryRow[];
|
|
48
|
+
/** JSON object: the SurveyJS answers, file questions left out. */
|
|
49
|
+
data: string;
|
|
50
|
+
evidence: ClaimEvidence[];
|
|
51
|
+
};
|
|
9
52
|
export type ActionOperationV1 =
|
|
10
53
|
| P2Operation
|
|
11
54
|
| ChainTxOperation
|
|
55
|
+
| BidSubmitOperation
|
|
56
|
+
| ClaimSubmitOperation
|
|
12
57
|
| {
|
|
13
58
|
kind: "form.submit.v1";
|
|
14
59
|
formId: string;
|
|
@@ -52,6 +97,52 @@ export type ActionReferenceV1 = {
|
|
|
52
97
|
export type ActionReceiptV1 =
|
|
53
98
|
| P2Receipt
|
|
54
99
|
| ChainTxReceipt
|
|
100
|
+
| {
|
|
101
|
+
kind: "ixo.bid.submission.v1";
|
|
102
|
+
actionId: string;
|
|
103
|
+
revision: number;
|
|
104
|
+
digest: string;
|
|
105
|
+
collectionId: string;
|
|
106
|
+
/** The bids bot's id for the bid, when it gave one. */
|
|
107
|
+
bidId: string | null;
|
|
108
|
+
submittedAt: number;
|
|
109
|
+
}
|
|
110
|
+
| {
|
|
111
|
+
kind: "ixo.claim.submission.v1";
|
|
112
|
+
actionId: string;
|
|
113
|
+
revision: number;
|
|
114
|
+
digest: string;
|
|
115
|
+
collectionId: string;
|
|
116
|
+
/** The claim's CID from the claims bot. */
|
|
117
|
+
claimId: string;
|
|
118
|
+
/** Lowercase hex: the MsgExec(MsgSubmitClaim) transaction. */
|
|
119
|
+
transactionHash: string;
|
|
120
|
+
/** The block that transaction was included in. */
|
|
121
|
+
height: number;
|
|
122
|
+
submittedAt: number;
|
|
123
|
+
}
|
|
124
|
+
| {
|
|
125
|
+
/** 0.7.0: an application or claim submission that stopped before it finished. */
|
|
126
|
+
kind: "ixo.submission.failed.v1";
|
|
127
|
+
actionId: string;
|
|
128
|
+
revision: number;
|
|
129
|
+
digest: string;
|
|
130
|
+
step: SubmissionFailureStep;
|
|
131
|
+
/**
|
|
132
|
+
* Plain words the Hub chose from the step and a known cause, always with
|
|
133
|
+
* a next step (at most 500, sanitized). The only text a gateway or
|
|
134
|
+
* runtime may show or relay.
|
|
135
|
+
*/
|
|
136
|
+
message: string;
|
|
137
|
+
/**
|
|
138
|
+
* Optional technical text (a service's or the network's answer),
|
|
139
|
+
* sanitized: no control, zero-width or bidi characters, nothing
|
|
140
|
+
* link-like, whitespace collapsed, at most 500. For the review page's
|
|
141
|
+
* closed "technical details" disclosure only; never relay it.
|
|
142
|
+
*/
|
|
143
|
+
detail?: string;
|
|
144
|
+
failedAt: number;
|
|
145
|
+
}
|
|
55
146
|
| {
|
|
56
147
|
kind: "form.submission.v1";
|
|
57
148
|
actionId: string;
|
|
@@ -143,6 +234,20 @@ export type ActionReviewView = {
|
|
|
143
234
|
transfer?: TransferDisplay | null;
|
|
144
235
|
/** 0.6.0: Hub-computed chain transaction display (chain tx cards only). */
|
|
145
236
|
chainTx?: ChainTxDisplay | null;
|
|
237
|
+
/**
|
|
238
|
+
* 0.7.0 (claim cards only): who pays the claim's network fee, read once
|
|
239
|
+
* when the card was made (no amount: the transaction is built later).
|
|
240
|
+
* `covered`: a usable fee grant allows it; `balance`: the person's IXO
|
|
241
|
+
* pays it (also when the grants could not be read).
|
|
242
|
+
*/
|
|
243
|
+
networkFee?: SubmissionNetworkFee | null;
|
|
244
|
+
/**
|
|
245
|
+
* 0.7.0 (application and claim cards): the collection's readable name
|
|
246
|
+
* (its protocol entity's Profile `name`, sanitized, at most 120) as the Hub
|
|
247
|
+
* read it when the card was made; null when none could be read. Show it
|
|
248
|
+
* with `operation.collectionId`.
|
|
249
|
+
*/
|
|
250
|
+
collectionName?: string | null;
|
|
146
251
|
};
|
|
147
252
|
export type TransferDisplay = {
|
|
148
253
|
denom: string;
|
|
@@ -746,3 +851,45 @@ export declare function publicKeyFromDidDocument(
|
|
|
746
851
|
): Uint8Array;
|
|
747
852
|
/** The exact 0.1.0 receipt shape for v1 callers (drops the 0.3.0 bank fields). */
|
|
748
853
|
export declare function v1Receipt<T extends ActionReceiptV1 | null>(receipt: T): T;
|
|
854
|
+
|
|
855
|
+
/** 0.7.0 */
|
|
856
|
+
export type SubmissionFailureStep =
|
|
857
|
+
| "collection"
|
|
858
|
+
| "evidence"
|
|
859
|
+
| "key"
|
|
860
|
+
| "bid_bot"
|
|
861
|
+
| "claim_bot"
|
|
862
|
+
| "chain";
|
|
863
|
+
export declare const SUBMISSION_FAILURE_STEPS: readonly SubmissionFailureStep[];
|
|
864
|
+
/**
|
|
865
|
+
* 0.7.0: how one answer is shown on the card: a string as it is; a number or
|
|
866
|
+
* boolean as String(value); null as ""; an array of strings, numbers and
|
|
867
|
+
* booleans as its items' display forms joined with ", " ("" when empty).
|
|
868
|
+
* Anything else (an object, a nested or mixed array) has no display form:
|
|
869
|
+
* undefined. Objects and arrays of objects are not answers but containers
|
|
870
|
+
* (their answers are the rows below them).
|
|
871
|
+
*/
|
|
872
|
+
export declare function submissionDisplayValue(value: unknown): string | undefined;
|
|
873
|
+
/**
|
|
874
|
+
* 0.7.0: why an application or claim card's `summary` does not show exactly
|
|
875
|
+
* its `data`, as the Hub's 400 `reason`, or null. The answers of `data` are
|
|
876
|
+
* its leaves: walking objects key by key and arrays of objects index by
|
|
877
|
+
* index (path segments joined with "."), every other value is an answer at
|
|
878
|
+
* its path. Every answer needs exactly one row with that `field` and its
|
|
879
|
+
* display form as `value`; no row may name anything else; a key may not be
|
|
880
|
+
* empty or contain "."; a claim's evidence `field` must not already hold an
|
|
881
|
+
* answer (a file is shown as a file, not a row).
|
|
882
|
+
*/
|
|
883
|
+
export declare function submissionSummaryIssue(
|
|
884
|
+
operation: BidSubmitOperation | ClaimSubmitOperation,
|
|
885
|
+
): string | null;
|
|
886
|
+
export type SubmissionNetworkFee = "covered" | "balance";
|
|
887
|
+
export declare const SUBMISSION_NETWORK_FEES: readonly SubmissionNetworkFee[];
|
|
888
|
+
/** 0.7.0: the longest failure `message` or `detail` (UTF-16 units). */
|
|
889
|
+
export declare const SUBMISSION_TEXT_MAX: 500;
|
|
890
|
+
/**
|
|
891
|
+
* 0.7.0: plain text safe to show: control characters become spaces,
|
|
892
|
+
* invisible and bidi characters are dropped, link-like text becomes
|
|
893
|
+
* `[link]`, whitespace is collapsed, cut to SUBMISSION_TEXT_MAX. Idempotent.
|
|
894
|
+
*/
|
|
895
|
+
export declare function sanitizeSubmissionText(text: string): string;
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,8 @@ const HEX = /^[a-f0-9]{64}$/;
|
|
|
9
9
|
const ADDRESS = /^ixo1[023456789acdefghjklmnpqrstuvwxyz]{38,59}$/;
|
|
10
10
|
const INT = /^(0|[1-9][0-9]*)$/;
|
|
11
11
|
const FIELD = /^[a-z][a-z0-9_]{0,39}$/;
|
|
12
|
+
/** 0.7.0 application and claim cards: an existing collection (never 0). */
|
|
13
|
+
const SUBMISSION_COLLECTION_ID = /^[1-9][0-9]{0,19}$/;
|
|
12
14
|
/** Envelope tags. v1 carries only the 0.1 status/receipt set; v2 adds terminal non-execution outcomes. */
|
|
13
15
|
export const OUTCOME_VERSION_V1 = "ixo.auth-outcome/1";
|
|
14
16
|
export const OUTCOME_VERSION_V2 = "ixo.auth-outcome/2";
|
|
@@ -230,6 +232,24 @@ export function parseOperation(input) {
|
|
|
230
232
|
if (new TextEncoder().encode(op.memo).length > MEMO_BYTES) fail("memo");
|
|
231
233
|
return op.denom === undefined ? { ...op, denom: "uixo" } : op;
|
|
232
234
|
}
|
|
235
|
+
if (op.kind === "ixo.bid.submit.v1" || op.kind === "ixo.claim.submit.v1") {
|
|
236
|
+
// Shape is checked by the schema; here the parts a schema cannot say.
|
|
237
|
+
jsonObject(op.data, "data");
|
|
238
|
+
// The card shows exactly what is sent and signed.
|
|
239
|
+
const issue = submissionSummaryIssue(op);
|
|
240
|
+
if (issue) fail(issue);
|
|
241
|
+
if (op.kind === "ixo.claim.submit.v1") {
|
|
242
|
+
const files = new Set();
|
|
243
|
+
for (const item of op.evidence) {
|
|
244
|
+
const url = new URL(item.url);
|
|
245
|
+
if (url.protocol !== "https:" || url.username || url.password || url.hash)
|
|
246
|
+
fail("evidence.url");
|
|
247
|
+
if (files.has(item.url)) fail("duplicate evidence");
|
|
248
|
+
files.add(item.url);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return op;
|
|
252
|
+
}
|
|
233
253
|
if (op.kind === "resource.read.v1") {
|
|
234
254
|
exact(
|
|
235
255
|
op,
|
|
@@ -379,6 +399,65 @@ export function parseReceipt(input) {
|
|
|
379
399
|
}
|
|
380
400
|
return receipt;
|
|
381
401
|
}
|
|
402
|
+
if (receipt.kind === "ixo.bid.submission.v1") {
|
|
403
|
+
exact(
|
|
404
|
+
receipt,
|
|
405
|
+
["kind", "actionId", "revision", "digest", "collectionId", "bidId", "submittedAt"],
|
|
406
|
+
"receipt",
|
|
407
|
+
);
|
|
408
|
+
tuple(receipt);
|
|
409
|
+
pattern(receipt.collectionId, SUBMISSION_COLLECTION_ID, "receipt.collectionId");
|
|
410
|
+
if (receipt.bidId !== null) str(receipt.bidId, "receipt.bidId", 1, 200);
|
|
411
|
+
num(receipt.submittedAt, "receipt.submittedAt");
|
|
412
|
+
return receipt;
|
|
413
|
+
}
|
|
414
|
+
if (receipt.kind === "ixo.claim.submission.v1") {
|
|
415
|
+
exact(
|
|
416
|
+
receipt,
|
|
417
|
+
[
|
|
418
|
+
"kind",
|
|
419
|
+
"actionId",
|
|
420
|
+
"revision",
|
|
421
|
+
"digest",
|
|
422
|
+
"collectionId",
|
|
423
|
+
"claimId",
|
|
424
|
+
"transactionHash",
|
|
425
|
+
"height",
|
|
426
|
+
"submittedAt",
|
|
427
|
+
],
|
|
428
|
+
"receipt",
|
|
429
|
+
);
|
|
430
|
+
tuple(receipt);
|
|
431
|
+
pattern(receipt.collectionId, SUBMISSION_COLLECTION_ID, "receipt.collectionId");
|
|
432
|
+
str(receipt.claimId, "receipt.claimId", 1, 200);
|
|
433
|
+
pattern(receipt.transactionHash, HEX, "receipt.transactionHash");
|
|
434
|
+
// The block the claim's MsgExec(MsgSubmitClaim) was included in.
|
|
435
|
+
num(receipt.height, "receipt.height");
|
|
436
|
+
num(receipt.submittedAt, "receipt.submittedAt");
|
|
437
|
+
return receipt;
|
|
438
|
+
}
|
|
439
|
+
if (receipt.kind === "ixo.submission.failed.v1") {
|
|
440
|
+
exact(
|
|
441
|
+
receipt,
|
|
442
|
+
["kind", "actionId", "revision", "digest", "step", "message", "detail", "failedAt"],
|
|
443
|
+
"receipt",
|
|
444
|
+
);
|
|
445
|
+
tuple(receipt);
|
|
446
|
+
if (!SUBMISSION_FAILURE_STEPS.includes(receipt.step)) fail("receipt.step");
|
|
447
|
+
// Plain words the Hub chose (never raw text): shown to the person and
|
|
448
|
+
// relayed by gateways and runtimes. Already in sanitized form.
|
|
449
|
+
if (sanitizeSubmissionText(str(receipt.message, "receipt.message", 1, 500)) !== receipt.message)
|
|
450
|
+
fail("receipt.message");
|
|
451
|
+
// Optional technical text, for the review page's closed disclosure only.
|
|
452
|
+
if (
|
|
453
|
+
"detail" in receipt &&
|
|
454
|
+
sanitizeSubmissionText(str(receipt.detail, "receipt.detail", 1, SUBMISSION_TEXT_MAX)) !==
|
|
455
|
+
receipt.detail
|
|
456
|
+
)
|
|
457
|
+
fail("receipt.detail");
|
|
458
|
+
num(receipt.failedAt, "receipt.failedAt");
|
|
459
|
+
return receipt;
|
|
460
|
+
}
|
|
382
461
|
return fail("receipt.kind");
|
|
383
462
|
}
|
|
384
463
|
|
|
@@ -404,6 +483,8 @@ export function parseReviewView(input) {
|
|
|
404
483
|
"service",
|
|
405
484
|
"transfer",
|
|
406
485
|
"chainTx",
|
|
486
|
+
"networkFee",
|
|
487
|
+
"collectionName",
|
|
407
488
|
],
|
|
408
489
|
"view",
|
|
409
490
|
);
|
|
@@ -422,6 +503,17 @@ export function parseReviewView(input) {
|
|
|
422
503
|
)
|
|
423
504
|
fail("view.chainTx");
|
|
424
505
|
}
|
|
506
|
+
// 0.7.0: who pays a claim's network fee, read once when the card was made.
|
|
507
|
+
if (view.networkFee !== undefined && view.networkFee !== null) {
|
|
508
|
+
if (view.operation?.kind !== "ixo.claim.submit.v1") fail("view.networkFee");
|
|
509
|
+
if (!SUBMISSION_NETWORK_FEES.includes(view.networkFee)) fail("view.networkFee");
|
|
510
|
+
}
|
|
511
|
+
// 0.7.0: the collection's name as the Hub read it when the card was made.
|
|
512
|
+
if (view.collectionName !== undefined && view.collectionName !== null) {
|
|
513
|
+
if (!SUBMISSION_KINDS.includes(view.operation?.kind)) fail("view.collectionName");
|
|
514
|
+
if (sanitizeSubmissionText(str(view.collectionName, "view.collectionName", 1, 120)) !== view.collectionName)
|
|
515
|
+
fail("view.collectionName");
|
|
516
|
+
}
|
|
425
517
|
if (view.service !== undefined && view.service !== null) {
|
|
426
518
|
object(view.service, "view.service");
|
|
427
519
|
exact(
|
|
@@ -738,6 +830,97 @@ export function parseCapabilities(input) {
|
|
|
738
830
|
return data;
|
|
739
831
|
}
|
|
740
832
|
|
|
833
|
+
/** 0.7.0: see index.d.ts. */
|
|
834
|
+
export function submissionDisplayValue(value) {
|
|
835
|
+
if (typeof value === "string") return value;
|
|
836
|
+
if (typeof value === "boolean") return String(value);
|
|
837
|
+
if (typeof value === "number") return Number.isFinite(value) ? String(value) : undefined;
|
|
838
|
+
if (value === null) return "";
|
|
839
|
+
if (
|
|
840
|
+
Array.isArray(value) &&
|
|
841
|
+
value.every((item) => ["string", "number", "boolean"].includes(typeof item))
|
|
842
|
+
) {
|
|
843
|
+
const shown = value.map(submissionDisplayValue);
|
|
844
|
+
return shown.includes(undefined) ? undefined : shown.join(", ");
|
|
845
|
+
}
|
|
846
|
+
return undefined;
|
|
847
|
+
}
|
|
848
|
+
const plainObject = (value) =>
|
|
849
|
+
value !== null && typeof value === "object" && !Array.isArray(value);
|
|
850
|
+
/** The answers of `data`: path -> display form, or an issue string. */
|
|
851
|
+
function submissionAnswers(data) {
|
|
852
|
+
const answers = new Map();
|
|
853
|
+
const walk = (node, prefix) => {
|
|
854
|
+
for (const key of Object.keys(node)) {
|
|
855
|
+
if (key === "" || key.includes(".")) return `invalid_operation: data key ${JSON.stringify(key).slice(0, 60)}`;
|
|
856
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
857
|
+
const value = node[key];
|
|
858
|
+
let issue = null;
|
|
859
|
+
if (plainObject(value)) issue = walk(value, path);
|
|
860
|
+
else if (Array.isArray(value) && value.length && value.every(plainObject)) {
|
|
861
|
+
for (const [index, item] of value.entries()) {
|
|
862
|
+
issue = walk(item, `${path}.${index}`);
|
|
863
|
+
if (issue) break;
|
|
864
|
+
}
|
|
865
|
+
} else {
|
|
866
|
+
const shown = submissionDisplayValue(value);
|
|
867
|
+
if (shown === undefined) return `invalid_operation: data.${path} has no display form`;
|
|
868
|
+
answers.set(path, shown);
|
|
869
|
+
}
|
|
870
|
+
if (issue) return issue;
|
|
871
|
+
}
|
|
872
|
+
return null;
|
|
873
|
+
};
|
|
874
|
+
const issue = walk(data, "");
|
|
875
|
+
return issue ?? answers;
|
|
876
|
+
}
|
|
877
|
+
/** The value at a dot path of `data` (objects by key, arrays by index), or undefined. */
|
|
878
|
+
function valueAt(data, path) {
|
|
879
|
+
let node = data;
|
|
880
|
+
for (const part of path.split(".")) {
|
|
881
|
+
if (Array.isArray(node) && /^\d+$/.test(part)) node = node[Number(part)];
|
|
882
|
+
else if (plainObject(node) && Object.prototype.hasOwnProperty.call(node, part)) node = node[part];
|
|
883
|
+
else return undefined;
|
|
884
|
+
}
|
|
885
|
+
return node;
|
|
886
|
+
}
|
|
887
|
+
/** 0.7.0: see index.d.ts. */
|
|
888
|
+
export function submissionSummaryIssue(op) {
|
|
889
|
+
let data;
|
|
890
|
+
try {
|
|
891
|
+
data = JSON.parse(op.data);
|
|
892
|
+
} catch {
|
|
893
|
+
return "invalid_operation: data";
|
|
894
|
+
}
|
|
895
|
+
if (!plainObject(data)) return "invalid_operation: data";
|
|
896
|
+
const answers = submissionAnswers(data);
|
|
897
|
+
if (typeof answers === "string") return answers;
|
|
898
|
+
const seen = new Set();
|
|
899
|
+
for (const [index, row] of (op.summary ?? []).entries()) {
|
|
900
|
+
if (seen.has(row.field)) return `invalid_operation: summary[${index}].field repeats`;
|
|
901
|
+
seen.add(row.field);
|
|
902
|
+
if (!answers.has(row.field)) return `invalid_operation: summary[${index}].field is not an answer`;
|
|
903
|
+
if (answers.get(row.field) !== row.value) return `invalid_operation: summary[${index}].value is not the answer`;
|
|
904
|
+
}
|
|
905
|
+
for (const path of answers.keys())
|
|
906
|
+
if (!seen.has(path)) return `invalid_operation: data.${path} has no summary row`;
|
|
907
|
+
if (op.kind === "ixo.claim.submit.v1")
|
|
908
|
+
for (const [index, item] of op.evidence.entries())
|
|
909
|
+
if (valueAt(data, item.field) !== undefined)
|
|
910
|
+
return `invalid_operation: evidence[${index}].field already holds an answer`;
|
|
911
|
+
return null;
|
|
912
|
+
}
|
|
913
|
+
/** 0.7.0: a string that must hold one JSON object (SurveyJS answers). */
|
|
914
|
+
const jsonObject = (value, field) => {
|
|
915
|
+
let parsed;
|
|
916
|
+
try {
|
|
917
|
+
parsed = JSON.parse(value);
|
|
918
|
+
} catch {
|
|
919
|
+
fail(field);
|
|
920
|
+
}
|
|
921
|
+
object(parsed, field);
|
|
922
|
+
return parsed;
|
|
923
|
+
};
|
|
741
924
|
const utf8 = (value, field) => {
|
|
742
925
|
str(value, field, 0, 8192);
|
|
743
926
|
if (
|
|
@@ -813,7 +996,88 @@ const receiptKinds = {
|
|
|
813
996
|
"vfs.access.request.v1": "vfs.access.requested.v1",
|
|
814
997
|
"vfs.text.save.v1": "vfs.text.saved.v1",
|
|
815
998
|
"ixo.chain.tx.v1": "ixo.chain.tx.v1",
|
|
999
|
+
"ixo.bid.submit.v1": "ixo.bid.submission.v1",
|
|
1000
|
+
"ixo.claim.submit.v1": "ixo.claim.submission.v1",
|
|
816
1001
|
};
|
|
1002
|
+
/** 0.7.0: kinds whose failed outcome carries `ixo.submission.failed.v1`. */
|
|
1003
|
+
const SUBMISSION_KINDS = ["ixo.bid.submit.v1", "ixo.claim.submit.v1"];
|
|
1004
|
+
/** 0.7.0: the step a bid or claim submission stopped at. */
|
|
1005
|
+
export const SUBMISSION_FAILURE_STEPS = [
|
|
1006
|
+
"collection",
|
|
1007
|
+
"evidence",
|
|
1008
|
+
"key",
|
|
1009
|
+
"bid_bot",
|
|
1010
|
+
"claim_bot",
|
|
1011
|
+
"chain",
|
|
1012
|
+
];
|
|
1013
|
+
/**
|
|
1014
|
+
* 0.7.0: a claim card's network fee as read when the card was made: a
|
|
1015
|
+
* usable fee grant allowing MsgExec covers it, or the person's IXO balance
|
|
1016
|
+
* pays it (also when the grants could not be read).
|
|
1017
|
+
*/
|
|
1018
|
+
export const SUBMISSION_NETWORK_FEES = ["covered", "balance"];
|
|
1019
|
+
/** 0.7.0: the longest failure `message` or `detail`, in UTF-16 units. */
|
|
1020
|
+
export const SUBMISSION_TEXT_MAX = 500;
|
|
1021
|
+
// Control characters (C0, DEL, C1, line/paragraph separators) become spaces.
|
|
1022
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/gu;
|
|
1023
|
+
// Invisible and direction-changing characters are dropped: zero-width
|
|
1024
|
+
// characters, bidi embeddings, overrides and isolates, word joiners and
|
|
1025
|
+
// invisible operators, variation selectors, the BOM, soft hyphen and the
|
|
1026
|
+
// Hangul and Mongolian fillers.
|
|
1027
|
+
const INVISIBLE_CHARACTERS =
|
|
1028
|
+
/[\u00ad\u034f\u061c\u115f\u1160\u17b4\u17b5\u180b-\u180f\u200b-\u200f\u202a-\u202e\u2060-\u206f\u3164\ufe00-\ufe0f\ufeff\uffa0]/gu;
|
|
1029
|
+
// Anything a chat app or browser could turn into a link: a URL with a
|
|
1030
|
+
// scheme, a www. host, an email address, or a dotted host name ending in a
|
|
1031
|
+
// letters-only label (with an optional port and path). Every branch starts
|
|
1032
|
+
// at a word boundary and every repetition is bounded, so a match attempt
|
|
1033
|
+
// does a bounded amount of work at each position (no catastrophic
|
|
1034
|
+
// backtracking); the input is also cut to SANITIZE_INPUT_MAX first.
|
|
1035
|
+
const LINK_LIKE =
|
|
1036
|
+
/\b[a-z][a-z0-9+.-]{0,31}:\/\/\S{0,2048}|\bwww\.\S{0,2048}|\b[^\s@]{1,64}@[^\s@]{1,255}\.[^\s@]{1,63}|\b(?:[a-z0-9-]{1,63}\.){1,16}[a-z]{2,63}\b(?::\d{1,5})?(?:\/\S{0,2048})?/giu;
|
|
1037
|
+
/** At most this much input is looked at (4 x SUBMISSION_TEXT_MAX). */
|
|
1038
|
+
const SANITIZE_INPUT_MAX = 2000;
|
|
1039
|
+
/**
|
|
1040
|
+
* 0.7.0: text safe to show as plain text: control characters become spaces,
|
|
1041
|
+
* invisible and bidi characters are dropped, anything link-like becomes
|
|
1042
|
+
* `[link]`, whitespace is collapsed and the result is cut to
|
|
1043
|
+
* SUBMISSION_TEXT_MAX (never inside a surrogate pair). The same text in
|
|
1044
|
+
* comes out unchanged, so a parser can check a value is already safe.
|
|
1045
|
+
*/
|
|
1046
|
+
export function sanitizeSubmissionText(text) {
|
|
1047
|
+
// Bounded input before any expression runs; then unpaired surrogates (also
|
|
1048
|
+
// one the cut split) are dropped, so every pass sees well-formed text.
|
|
1049
|
+
let out = sanitizeOnce(String(text).slice(0, SANITIZE_INPUT_MAX));
|
|
1050
|
+
// A pass can only change the text again at its cut tail (a new link-like
|
|
1051
|
+
// tail, or a "[link]" pushed over the limit), so it settles within a few
|
|
1052
|
+
// passes; SANITIZE_PASSES is a hard bound. Should it ever not settle, the
|
|
1053
|
+
// empty string (itself stable) is returned: the result is ALWAYS a fixed
|
|
1054
|
+
// point, so sanitize(sanitize(x)) === sanitize(x) and a parser can check it.
|
|
1055
|
+
for (let pass = 0; pass < SANITIZE_PASSES; pass++) {
|
|
1056
|
+
const next = sanitizeOnce(out);
|
|
1057
|
+
if (next === out) return out;
|
|
1058
|
+
out = next;
|
|
1059
|
+
}
|
|
1060
|
+
return "";
|
|
1061
|
+
}
|
|
1062
|
+
const SANITIZE_PASSES = 8;
|
|
1063
|
+
// A high surrogate not followed by a low one, or a low one not after a high one.
|
|
1064
|
+
const UNPAIRED_SURROGATES = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
1065
|
+
function sanitizeOnce(text) {
|
|
1066
|
+
const cleaned = text
|
|
1067
|
+
.replace(UNPAIRED_SURROGATES, "")
|
|
1068
|
+
.replace(CONTROL_CHARACTERS, " ")
|
|
1069
|
+
.replace(INVISIBLE_CHARACTERS, "")
|
|
1070
|
+
.replace(LINK_LIKE, "[link]")
|
|
1071
|
+
.replace(/\s+/gu, " ")
|
|
1072
|
+
.trim();
|
|
1073
|
+
if (cleaned.length <= SUBMISSION_TEXT_MAX) return cleaned;
|
|
1074
|
+
let out = "";
|
|
1075
|
+
for (const point of cleaned) {
|
|
1076
|
+
if (out.length + point.length > SUBMISSION_TEXT_MAX) break;
|
|
1077
|
+
out += point;
|
|
1078
|
+
}
|
|
1079
|
+
return out.trimEnd();
|
|
1080
|
+
}
|
|
817
1081
|
export function assertReceiptForOperation(
|
|
818
1082
|
operation,
|
|
819
1083
|
receipt,
|
|
@@ -831,9 +1095,16 @@ export function assertReceiptForOperation(
|
|
|
831
1095
|
receipt.service === serviceForOperation(operation)
|
|
832
1096
|
)
|
|
833
1097
|
return receipt;
|
|
1098
|
+
if (
|
|
1099
|
+
status === "failed" &&
|
|
1100
|
+
receipt.kind === "ixo.submission.failed.v1" &&
|
|
1101
|
+
SUBMISSION_KINDS.includes(operation.kind)
|
|
1102
|
+
)
|
|
1103
|
+
return receipt;
|
|
834
1104
|
if (
|
|
835
1105
|
receiptKinds[operation.kind] !== receipt.kind ||
|
|
836
|
-
receipt.kind === "service.failure.v1"
|
|
1106
|
+
receipt.kind === "service.failure.v1" ||
|
|
1107
|
+
receipt.kind === "ixo.submission.failed.v1"
|
|
837
1108
|
)
|
|
838
1109
|
fail("operation receipt");
|
|
839
1110
|
// 0.6.0: a chain tx receipt names the approved chain and steps, in order.
|
|
@@ -844,6 +1115,13 @@ export function assertReceiptForOperation(
|
|
|
844
1115
|
receipt.steps.some((step, i) => step.type !== operation.messages[i].type))
|
|
845
1116
|
)
|
|
846
1117
|
fail("receipt steps");
|
|
1118
|
+
// 0.7.0: an application or claim receipt names the approved collection.
|
|
1119
|
+
if (
|
|
1120
|
+
operation.kind !== CHAIN_TX_KIND &&
|
|
1121
|
+
"collectionId" in receipt &&
|
|
1122
|
+
receipt.collectionId !== operation.collectionId
|
|
1123
|
+
)
|
|
1124
|
+
fail("receipt collection");
|
|
847
1125
|
// Every kind: the receipt must name the approved connection / target.
|
|
848
1126
|
if (
|
|
849
1127
|
"connectionId" in operation &&
|
|
@@ -1304,9 +1582,14 @@ function receiptFitsStatus(receipt, status) {
|
|
|
1304
1582
|
if (status === "succeeded")
|
|
1305
1583
|
return bank
|
|
1306
1584
|
? receipt.code === 0 && receipt.height !== null && !("reason" in receipt)
|
|
1307
|
-
: receipt.kind !== "service.failure.v1"
|
|
1585
|
+
: receipt.kind !== "service.failure.v1" &&
|
|
1586
|
+
receipt.kind !== "ixo.submission.failed.v1";
|
|
1308
1587
|
if (status === "failed") {
|
|
1309
|
-
if (
|
|
1588
|
+
if (
|
|
1589
|
+
receipt.kind === "service.failure.v1" ||
|
|
1590
|
+
receipt.kind === "ixo.submission.failed.v1"
|
|
1591
|
+
)
|
|
1592
|
+
return true;
|
|
1310
1593
|
if (!bank) return false;
|
|
1311
1594
|
if ("reason" in receipt) return true; // checked by parseReceipt
|
|
1312
1595
|
return (
|
package/src/operation-schema.js
CHANGED
|
@@ -39,6 +39,35 @@ const instant = {
|
|
|
39
39
|
"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?(?:Z|[+-]\\d{2}:\\d{2})$",
|
|
40
40
|
};
|
|
41
41
|
const hex = { ...string(64, 64), pattern: "^[a-f0-9]{64}$" };
|
|
42
|
+
// 0.7.0 application and claim cards: the network, a claim collection that
|
|
43
|
+
// exists (never 0), and the rows the review card shows, one per answer.
|
|
44
|
+
const integer = (minimum, maximum) => ({ type: "integer", minimum, maximum });
|
|
45
|
+
const network = enumeration("ixo mainnet", "ixo testnet", "ixo devnet");
|
|
46
|
+
const submissionCollectionId = { ...string(1, 20), pattern: "^[1-9][0-9]{0,19}$" };
|
|
47
|
+
// Each row shows one answer of `data`: `field` is its path (as an evidence
|
|
48
|
+
// `field`), `value` its display form (submissionDisplayValue); the parser
|
|
49
|
+
// checks that every answer has its row and every row is its answer.
|
|
50
|
+
const summary = {
|
|
51
|
+
type: "array",
|
|
52
|
+
items: object({
|
|
53
|
+
field: string(1, 200),
|
|
54
|
+
label: string(1, 200),
|
|
55
|
+
value: string(0, 2000),
|
|
56
|
+
}),
|
|
57
|
+
// No rows only when `data` has no answers (a claim of files only).
|
|
58
|
+
minItems: 0,
|
|
59
|
+
maxItems: 100,
|
|
60
|
+
};
|
|
61
|
+
// 0.6.0: a file the person sent on the channel, kept by the gateway until the
|
|
62
|
+
// Hub uploads it as claim evidence.
|
|
63
|
+
const evidence = object({
|
|
64
|
+
field: string(1, 200),
|
|
65
|
+
url: string(1, 2000),
|
|
66
|
+
filename: string(1, 200),
|
|
67
|
+
mimetype: string(1, 100),
|
|
68
|
+
size: integer(1, 52428800),
|
|
69
|
+
sha256: hex,
|
|
70
|
+
});
|
|
42
71
|
// One ASCII mailbox only; no display names, address lists or header characters.
|
|
43
72
|
const mailbox = {
|
|
44
73
|
...string(3, 254),
|
|
@@ -197,6 +226,22 @@ const registry = {
|
|
|
197
226
|
memo: string(0, 256),
|
|
198
227
|
messages: { type: "array", items: chainTxMessage, minItems: 1, maxItems: 8 },
|
|
199
228
|
},
|
|
229
|
+
"ixo.bid.submit.v1": {
|
|
230
|
+
network,
|
|
231
|
+
collectionId: submissionCollectionId,
|
|
232
|
+
title: string(1, 120),
|
|
233
|
+
role: { const: "SA" },
|
|
234
|
+
summary,
|
|
235
|
+
data: string(2, 60000),
|
|
236
|
+
},
|
|
237
|
+
"ixo.claim.submit.v1": {
|
|
238
|
+
network,
|
|
239
|
+
collectionId: submissionCollectionId,
|
|
240
|
+
title: string(1, 120),
|
|
241
|
+
summary,
|
|
242
|
+
data: string(2, 60000),
|
|
243
|
+
evidence: { type: "array", items: evidence, maxItems: 30 },
|
|
244
|
+
},
|
|
200
245
|
};
|
|
201
246
|
export const operationKinds = Object.freeze(Object.keys(registry));
|
|
202
247
|
export const operationJsonSchema = Object.freeze({
|