@ixo/action-protocol 0.5.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.
@@ -39,12 +39,102 @@ 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),
45
74
  pattern:
46
75
  "^[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
76
  };
77
+ // 0.6.0 chain transactions (`ixo.chain.tx.v1`): the shapes only. The field
78
+ // parser (`chainTxIssue` in index.js) checks addresses, DIDs and byte lengths,
79
+ // and the Hub enforces signer, network and chain rules.
80
+ const baseUnits = { ...string(1, 78), pattern: "^[1-9][0-9]*$" };
81
+ // The chain's DID segments (x/iid): [A-Za-z0-9._-] or `%` + two hex digits.
82
+ const didTail =
83
+ "(?:(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})*:)*(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})+";
84
+ const ixoDid = { ...string(9, 200), pattern: `^did:ixo:${didTail}$` };
85
+ const anyDid = { ...string(7, 200), pattern: `^did:[a-z0-9]+:${didTail}$` };
86
+ // uint64, no leading zeros (the field parser also checks the uint64 maximum).
87
+ const collectionId = { ...string(1, 20), pattern: "^(0|[1-9][0-9]{0,19})$" };
88
+ // A 20-byte ixo account address (the Hub also checks the bech32 checksum).
89
+ const account = { ...string(42, 42), pattern: "^ixo1[023456789acdefghjklmnpqrstuvwxyz]{38}$" };
90
+ // Claim ids, impact token ids and verification proofs.
91
+ const chainText = (min, max) => ({
92
+ ...string(min, max),
93
+ pattern: min > 0 ? "^[A-Za-z0-9:._/-]+$" : "^[A-Za-z0-9:._/-]*$",
94
+ });
95
+ const chainTxMessage = {
96
+ anyOf: [
97
+ object({
98
+ type: { const: "cosmos.bank.send" },
99
+ toAddress: account,
100
+ amountBaseUnits: baseUnits,
101
+ denom: optional({ ...string(3, 128), pattern: "^[a-zA-Z][a-zA-Z0-9/:._-]{2,127}$" }),
102
+ }),
103
+ object({
104
+ type: { const: "ixo.claims.submit" },
105
+ collectionId,
106
+ claimId: chainText(1, 256),
107
+ agentDid: ixoDid,
108
+ adminAddress: account,
109
+ useIntent: optional({ type: "boolean" }),
110
+ }),
111
+ object({
112
+ type: { const: "ixo.claims.evaluate" },
113
+ claimId: chainText(1, 256),
114
+ collectionId,
115
+ oracle: anyDid,
116
+ agentDid: ixoDid,
117
+ agentAddress: account,
118
+ adminAddress: account,
119
+ // EvaluationStatus 1 approved, 2 rejected, 3 disputed, 4 invalidated
120
+ // (0 pending and 5 flagged are refused).
121
+ status: enumeration(1, 2, 3, 4),
122
+ // uint32 code defined by the evaluator (the chain has no enum for it).
123
+ reason: optional({ type: "integer", minimum: 0, maximum: 4294967295 }),
124
+ verificationProof: optional(chainText(1, 300)),
125
+ }),
126
+ object({
127
+ type: { const: "ixo.token.transfer" },
128
+ recipient: account,
129
+ tokens: {
130
+ type: "array",
131
+ items: object({ id: chainText(1, 128), amount: baseUnits }),
132
+ minItems: 1,
133
+ maxItems: 32,
134
+ },
135
+ }),
136
+ ],
137
+ };
48
138
  const registry = {
49
139
  "form.submit.v1": {
50
140
  formId: string(1, 120),
@@ -129,6 +219,29 @@ const registry = {
129
219
  },
130
220
  text: string(0, 8192),
131
221
  },
222
+ "ixo.chain.tx.v1": {
223
+ chainId: string(1, 100),
224
+ network: enumeration("ixo mainnet", "ixo testnet", "ixo devnet"),
225
+ signer: account,
226
+ memo: string(0, 256),
227
+ messages: { type: "array", items: chainTxMessage, minItems: 1, maxItems: 8 },
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
+ },
132
245
  };
133
246
  export const operationKinds = Object.freeze(Object.keys(registry));
134
247
  export const operationJsonSchema = Object.freeze({
@@ -143,6 +256,12 @@ function matches(value, schema) {
143
256
  if (schema.enum) return schema.enum.includes(value);
144
257
  if (schema.type === "null") return value === null;
145
258
  if (schema.type === "boolean") return typeof value === "boolean";
259
+ if (schema.type === "integer")
260
+ return (
261
+ Number.isSafeInteger(value) &&
262
+ value >= (schema.minimum ?? Number.MIN_SAFE_INTEGER) &&
263
+ value <= (schema.maximum ?? Number.MAX_SAFE_INTEGER)
264
+ );
146
265
  if (schema.type === "string")
147
266
  return (
148
267
  typeof value === "string" &&