@ocap/tx-protocols 1.29.27 → 1.30.1

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 (78) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +32 -0
  2. package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
  3. package/esm/node_modules/valibot/dist/index.mjs +663 -0
  4. package/esm/protocols/account/delegate.mjs +42 -36
  5. package/esm/protocols/account/migrate.mjs +7 -10
  6. package/esm/protocols/account/revoke-delegate.mjs +11 -11
  7. package/esm/protocols/asset/acquire-v2.mjs +19 -13
  8. package/esm/protocols/asset/acquire-v3.mjs +17 -14
  9. package/esm/protocols/asset/consume.mjs +9 -9
  10. package/esm/protocols/asset/create.mjs +2 -1
  11. package/esm/protocols/asset/mint.mjs +19 -13
  12. package/esm/protocols/asset/update.mjs +11 -11
  13. package/esm/protocols/governance/claim-stake.mjs +10 -10
  14. package/esm/protocols/governance/return-stake.mjs +11 -11
  15. package/esm/protocols/governance/revoke-stake.mjs +10 -10
  16. package/esm/protocols/governance/slash-stake.mjs +11 -11
  17. package/esm/protocols/governance/stake.mjs +16 -16
  18. package/esm/protocols/rollup/claim-reward.mjs +21 -18
  19. package/esm/protocols/rollup/close.mjs +16 -13
  20. package/esm/protocols/rollup/create-block.mjs +25 -22
  21. package/esm/protocols/rollup/join.mjs +14 -12
  22. package/esm/protocols/rollup/leave.mjs +12 -11
  23. package/esm/protocols/rollup/migrate.mjs +15 -12
  24. package/esm/protocols/rollup/pause.mjs +9 -9
  25. package/esm/protocols/rollup/resume.mjs +9 -9
  26. package/esm/protocols/rollup/update.mjs +31 -28
  27. package/esm/protocols/token/create.mjs +25 -22
  28. package/esm/protocols/token/deposit-v2.mjs +20 -14
  29. package/esm/protocols/token/withdraw-v2.mjs +20 -14
  30. package/esm/protocols/token-factory/burn.mjs +12 -12
  31. package/esm/protocols/token-factory/create.mjs +45 -37
  32. package/esm/protocols/token-factory/mint.mjs +13 -12
  33. package/esm/protocols/token-factory/update.mjs +21 -21
  34. package/esm/protocols/trade/exchange-v2.mjs +15 -15
  35. package/esm/protocols/trade/transfer-v2.mjs +12 -12
  36. package/esm/protocols/trade/transfer-v3.mjs +7 -10
  37. package/esm/util.d.mts +3 -1
  38. package/esm/util.mjs +16 -1
  39. package/lib/_virtual/rolldown_runtime.cjs +2 -0
  40. package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
  41. package/lib/node_modules/valibot/dist/index.cjs +683 -0
  42. package/lib/protocols/account/delegate.cjs +41 -35
  43. package/lib/protocols/account/migrate.cjs +6 -9
  44. package/lib/protocols/account/revoke-delegate.cjs +10 -10
  45. package/lib/protocols/asset/acquire-v2.cjs +18 -12
  46. package/lib/protocols/asset/acquire-v3.cjs +16 -13
  47. package/lib/protocols/asset/consume.cjs +8 -8
  48. package/lib/protocols/asset/create.cjs +2 -1
  49. package/lib/protocols/asset/mint.cjs +18 -12
  50. package/lib/protocols/asset/update.cjs +10 -10
  51. package/lib/protocols/governance/claim-stake.cjs +9 -9
  52. package/lib/protocols/governance/return-stake.cjs +10 -10
  53. package/lib/protocols/governance/revoke-stake.cjs +9 -9
  54. package/lib/protocols/governance/slash-stake.cjs +10 -10
  55. package/lib/protocols/governance/stake.cjs +15 -15
  56. package/lib/protocols/rollup/claim-reward.cjs +20 -17
  57. package/lib/protocols/rollup/close.cjs +15 -12
  58. package/lib/protocols/rollup/create-block.cjs +24 -21
  59. package/lib/protocols/rollup/join.cjs +13 -11
  60. package/lib/protocols/rollup/leave.cjs +11 -10
  61. package/lib/protocols/rollup/migrate.cjs +14 -11
  62. package/lib/protocols/rollup/pause.cjs +8 -8
  63. package/lib/protocols/rollup/resume.cjs +8 -8
  64. package/lib/protocols/rollup/update.cjs +29 -27
  65. package/lib/protocols/token/create.cjs +23 -20
  66. package/lib/protocols/token/deposit-v2.cjs +19 -13
  67. package/lib/protocols/token/withdraw-v2.cjs +19 -13
  68. package/lib/protocols/token-factory/burn.cjs +11 -11
  69. package/lib/protocols/token-factory/create.cjs +43 -35
  70. package/lib/protocols/token-factory/mint.cjs +12 -11
  71. package/lib/protocols/token-factory/update.cjs +19 -19
  72. package/lib/protocols/trade/exchange-v2.cjs +14 -14
  73. package/lib/protocols/trade/transfer-v2.cjs +11 -11
  74. package/lib/protocols/trade/transfer-v3.cjs +6 -9
  75. package/lib/util.cjs +17 -0
  76. package/lib/util.d.cts +3 -1
  77. package/package.json +16 -18
  78. package/tools/fixtures.ts +2 -1
@@ -10,54 +10,60 @@ import { scopeMatchAny } from "@ocap/util";
10
10
  import Debug from "debug";
11
11
  import { formatMessage } from "@ocap/message";
12
12
  import cloneDeep from "lodash/cloneDeep.js";
13
- import { Joi } from "@arcblock/validator";
13
+ import { v, vBN, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
14
14
 
15
15
  //#region src/protocols/account/delegate.ts
16
16
  const debug = Debug("@ocap/tx-protocols:delegate");
17
17
  const runner = new Runner("delegate");
18
18
  runner.use(pipes.VerifyMultiSig(0));
19
- const rateLimit = Joi.object({
20
- interval: Joi.number().integer().greater(0).required(),
21
- anchor: Joi.number().integer().min(0).optional().allow(null).default(0)
19
+ const rateLimit = v.object({
20
+ interval: v.pipe(v.number(), v.integer(), v.minValue(1)),
21
+ anchor: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0)
22
22
  });
23
- const tokenLimit = Joi.object({
24
- address: Joi.DID().prefix().role("ROLE_TOKEN").required(),
25
- toList: Joi.array().items(Joi.DID().prefix()).max(32).unique().optional().allow(null).default([]),
26
- txCount: Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
27
- txAllowance: Joi.BN().optional().allow(null).default("0"),
28
- totalAllowance: Joi.BN().optional().allow(null).default("0"),
29
- validUntil: Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
30
- rate: rateLimit.optional().allow(null)
23
+ const tokenLimit = v.object({
24
+ address: vDID({
25
+ prefix: true,
26
+ role: "ROLE_TOKEN"
27
+ }),
28
+ toList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(32))), []),
29
+ txCount: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
30
+ txAllowance: v.optional(v.nullable(vBN()), "0"),
31
+ totalAllowance: v.optional(v.nullable(vBN()), "0"),
32
+ validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
33
+ rate: v.optional(v.nullable(rateLimit))
31
34
  });
32
- const assetLimit = Joi.object({
33
- address: Joi.array().items(Joi.DID().prefix().role("ROLE_ASSET")).unique().max(1024).optional().allow(null).default([]),
34
- toList: Joi.array().items(Joi.DID().prefix()).unique().max(32).optional().allow(null).default([]),
35
- txCount: Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
36
- validUntil: Joi.number().integer().min(0).empty("").optional().allow(null).default(0),
37
- rate: rateLimit.optional().allow(null)
35
+ const assetLimit = v.object({
36
+ address: v.optional(v.nullable(v.pipe(v.array(vDID({
37
+ prefix: true,
38
+ role: "ROLE_ASSET"
39
+ })), v.maxLength(1024))), []),
40
+ toList: v.optional(v.nullable(v.pipe(v.array(vDID({ prefix: true })), v.maxLength(32))), []),
41
+ txCount: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
42
+ validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
43
+ rate: v.optional(v.nullable(rateLimit))
38
44
  });
39
- const schema = Joi.object({
40
- address: Joi.DID().prefix().role("ROLE_DELEGATION").required(),
41
- to: Joi.DID().prefix().required(),
42
- opsList: Joi.array().items(Joi.object({
43
- typeUrl: Joi.string().required(),
44
- limit: Joi.object({
45
- tokensList: Joi.array().items(tokenLimit).unique((a, b) => a.address === b.address).max(32),
46
- assetsList: Joi.array().items(assetLimit).max(32)
47
- }).optional().allow(null).default({
45
+ const schema = v.pipe(v.object({
46
+ address: vDID({
47
+ prefix: true,
48
+ role: "ROLE_DELEGATION"
49
+ }),
50
+ to: vDID({ prefix: true }),
51
+ opsList: v.pipe(v.array(v.object({
52
+ typeUrl: v.string(),
53
+ limit: v.optional(v.nullable(v.object({
54
+ tokensList: v.optional(v.pipe(v.array(tokenLimit), v.maxLength(32)), []),
55
+ assetsList: v.optional(v.pipe(v.array(assetLimit), v.maxLength(32)), [])
56
+ })), {
48
57
  tokensList: [],
49
58
  assetsList: []
50
59
  })
51
- })).unique((a, b) => a.typeUrl === b.typeUrl).min(1).required(),
52
- denyList: Joi.array().items(Joi.string().pattern(/^fg:/).max(256)).max(128).unique().optional().allow(null).default([]),
53
- validUntil: Joi.number().integer().min(0).optional().allow(null).default(0),
54
- data: Joi.any().optional().allow(null)
55
- }).options({
56
- stripUnknown: true,
57
- noDefaults: false
58
- });
60
+ })), v.minLength(1), v.check((arr) => new Set(arr.map((x) => x.typeUrl)).size === arr.length, "opsList must not contain duplicate typeUrl entries")),
61
+ denyList: v.optional(v.nullable(v.pipe(v.array(v.pipe(v.string(), v.regex(/^fg:/), v.maxLength(256))), v.maxLength(128), v.check((arr) => new Set(arr).size === arr.length, "denyList must not contain duplicates"))), []),
62
+ validUntil: v.optional(v.nullable(v.pipe(v.number(), v.integer(), v.minValue(0))), 0),
63
+ data: v.optional(v.nullable(v.any()))
64
+ }), vStripUnknown());
59
65
  runner.use((context, next) => {
60
- const { error, value } = schema.validate(context.itx);
66
+ const { error, value } = vValidate(schema, context.itx);
61
67
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
62
68
  context.formattedItx = formatMessage("DelegateTx", context.itx);
63
69
  context.validatedItx = value;
@@ -6,7 +6,7 @@ import { CustomError } from "@ocap/util/lib/error";
6
6
  import { fromPublicKey, toTypeInfo } from "@arcblock/did";
7
7
  import { account } from "@ocap/state";
8
8
  import Debug from "debug";
9
- import { Joi } from "@arcblock/validator";
9
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
10
  import { types } from "@ocap/mcrypto";
11
11
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
12
  import flatten from "lodash/flatten.js";
@@ -17,16 +17,13 @@ const { RoleType } = types;
17
17
  const debug = Debug("@ocap/tx-protocols:migrate");
18
18
  const runner = new Runner("account_migrate");
19
19
  runner.use(pipes.VerifyMultiSig(0));
20
- const schema = Joi.object({
21
- address: Joi.DID().prefix().required(),
22
- pk: Joi.any().required(),
23
- data: Joi.any().optional().allow(null)
24
- }).options({
25
- stripUnknown: true,
26
- noDefaults: false
27
- });
20
+ const schema = v.pipe(v.object({
21
+ address: vDID({ prefix: true }),
22
+ pk: v.any(),
23
+ data: v.optional(v.nullable(v.any()))
24
+ }), vStripUnknown());
28
25
  runner.use((context, next) => {
29
- const { error } = schema.validate(context.itx);
26
+ const { error } = vValidate(schema, context.itx);
30
27
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
31
28
  return next();
32
29
  });
@@ -8,23 +8,23 @@ import { account, delegation } from "@ocap/state";
8
8
  import Debug from "debug";
9
9
  import { getListField } from "@ocap/util/lib/get-list-field";
10
10
  import cloneDeep from "lodash/cloneDeep.js";
11
- import { Joi } from "@arcblock/validator";
11
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
12
12
 
13
13
  //#region src/protocols/account/revoke-delegate.ts
14
14
  const debug = Debug("@ocap/tx-protocols:delegate");
15
15
  const runner = new Runner("revoke_delegate");
16
16
  runner.use(pipes.VerifyMultiSig(0));
17
- const schema = Joi.object({
18
- address: Joi.DID().prefix().role("ROLE_DELEGATION").required(),
19
- to: Joi.DID().prefix().required(),
20
- typeUrlsList: Joi.array().items(Joi.string().required()).min(1).required(),
21
- data: Joi.any().optional().allow(null)
22
- }).options({
23
- stripUnknown: true,
24
- noDefaults: false
25
- });
17
+ const schema = v.pipe(v.object({
18
+ address: vDID({
19
+ prefix: true,
20
+ role: "ROLE_DELEGATION"
21
+ }),
22
+ to: vDID({ prefix: true }),
23
+ typeUrlsList: v.pipe(v.array(v.string()), v.minLength(1)),
24
+ data: v.optional(v.nullable(v.any()))
25
+ }), vStripUnknown());
26
26
  runner.use((context, next) => {
27
- const { error } = schema.validate(context.itx);
27
+ const { error } = vValidate(schema, context.itx);
28
28
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
29
29
  return next();
30
30
  });
@@ -11,7 +11,7 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
11
11
  import { CustomError } from "@ocap/util/lib/error";
12
12
  import { account, asset, delegation, factory } from "@ocap/state";
13
13
  import Debug from "debug";
14
- import { Joi, schemas } from "@arcblock/validator";
14
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
15
15
  import { promisify } from "node:util";
16
16
 
17
17
  //#region src/protocols/asset/acquire-v2.ts
@@ -22,19 +22,25 @@ const verifyTokenBalance = promisify(pipes.VerifyTokenBalance({
22
22
  }));
23
23
  const runner = new Runner("acquire_asset_v2");
24
24
  runner.use(pipes.VerifyMultiSig(0));
25
- const schema = Joi.object({
26
- factory: Joi.DID().prefix().role("ROLE_FACTORY").required(),
27
- address: Joi.DID().prefix().role("ROLE_ASSET").required(),
28
- assetsList: Joi.array().items(Joi.DID().prefix().role("ROLE_ASSET")).default([]),
29
- variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
30
- issuer: schemas.nftIssuer.required(),
31
- data: Joi.any().optional().allow(null)
32
- }).options({
33
- stripUnknown: true,
34
- noDefaults: false
35
- });
25
+ const schema = v.pipe(v.object({
26
+ factory: vDID({
27
+ prefix: true,
28
+ role: "ROLE_FACTORY"
29
+ }),
30
+ address: vDID({
31
+ prefix: true,
32
+ role: "ROLE_ASSET"
33
+ }),
34
+ assetsList: v.optional(v.array(vDID({
35
+ prefix: true,
36
+ role: "ROLE_ASSET"
37
+ })), []),
38
+ variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
39
+ issuer: schemas.nftIssuer,
40
+ data: v.optional(v.nullable(v.any()))
41
+ }), vStripUnknown());
36
42
  runner.use(({ itx }, next) => {
37
- const { error } = schema.validate(itx);
43
+ const { error } = vValidate(schema, itx);
38
44
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
39
45
  return next();
40
46
  });
@@ -13,7 +13,7 @@ import { account, asset, factory } from "@ocap/state";
13
13
  import { BN } from "@ocap/util";
14
14
  import Debug from "debug";
15
15
  import { getListField } from "@ocap/util/lib/get-list-field";
16
- import { Joi, schemas } from "@arcblock/validator";
16
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
17
17
  import { promisify } from "node:util";
18
18
  import isEqual from "lodash/isEqual.js";
19
19
 
@@ -24,20 +24,23 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
24
24
  ownerKey: "owner"
25
25
  }));
26
26
  const runner = new Runner("acquire_asset_v3");
27
- const schema = Joi.object({
28
- factory: Joi.DID().prefix().role("ROLE_FACTORY").required(),
29
- address: Joi.DID().prefix().role("ROLE_ASSET").required(),
30
- inputsList: schemas.multiInput.min(1).required(),
31
- owner: schemas.tokenHolder.required(),
32
- variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
33
- issuer: schemas.nftIssuer.required(),
34
- data: Joi.any().optional().allow(null)
35
- }).options({
36
- stripUnknown: true,
37
- noDefaults: false
38
- });
27
+ const schema = v.pipe(v.object({
28
+ factory: vDID({
29
+ prefix: true,
30
+ role: "ROLE_FACTORY"
31
+ }),
32
+ address: vDID({
33
+ prefix: true,
34
+ role: "ROLE_ASSET"
35
+ }),
36
+ inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
37
+ owner: schemas.tokenHolder,
38
+ variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
39
+ issuer: schemas.nftIssuer,
40
+ data: v.optional(v.nullable(v.any()))
41
+ }), vStripUnknown());
39
42
  runner.use(({ itx }, next) => {
40
- const { error } = schema.validate(itx);
43
+ const { error } = vValidate(schema, itx);
41
44
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
42
45
  return next();
43
46
  });
@@ -4,21 +4,21 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
4
4
  import { CustomError } from "@ocap/util/lib/error";
5
5
  import { account, asset } from "@ocap/state";
6
6
  import Debug from "debug";
7
- import { Joi } from "@arcblock/validator";
7
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
8
8
 
9
9
  //#region src/protocols/asset/consume.ts
10
10
  const debug = Debug("@ocap/tx-protocols:consume-asset");
11
11
  const runner = new Runner("consume_asset");
12
- const schema = Joi.object({
13
- address: Joi.DID().prefix().role("ROLE_ASSET").required(),
14
- data: Joi.any().optional().allow(null)
15
- }).options({
16
- stripUnknown: true,
17
- noDefaults: false
18
- });
12
+ const schema = v.pipe(v.object({
13
+ address: vDID({
14
+ prefix: true,
15
+ role: "ROLE_ASSET"
16
+ }),
17
+ data: v.optional(v.nullable(v.any()))
18
+ }), vStripUnknown());
19
19
  runner.use((context, next) => {
20
20
  const { itx } = context;
21
- const { error } = schema.validate(itx);
21
+ const { error } = vValidate(schema, itx);
22
22
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
23
23
  return next();
24
24
  });
@@ -9,13 +9,14 @@ import Debug from "debug";
9
9
  import { formatMessage } from "@ocap/message";
10
10
  import { getListField } from "@ocap/util/lib/get-list-field";
11
11
  import cloneDeep from "lodash/cloneDeep.js";
12
+ import { schemas, vValidate } from "@arcblock/validator";
12
13
 
13
14
  //#region src/protocols/asset/create.ts
14
15
  const debug = Debug("@ocap/tx-protocols:create-asset");
15
16
  const runner = new Runner("create_asset");
16
17
  runner.use((context, next) => {
17
18
  const itx = formatMessage("CreateAssetTx", context.itx);
18
- const { error } = asset.schema.validate(itx);
19
+ const { error } = vValidate(schemas.assetSchema, itx);
19
20
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
20
21
  return next();
21
22
  });
@@ -8,25 +8,31 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
8
8
  import { CustomError } from "@ocap/util/lib/error";
9
9
  import { account, asset, factory } from "@ocap/state";
10
10
  import Debug from "debug";
11
- import { Joi, schemas } from "@arcblock/validator";
11
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
12
12
 
13
13
  //#region src/protocols/asset/mint.ts
14
14
  const debug = Debug("@ocap/tx-protocols:mint-asset");
15
15
  const runner = new Runner("mint_asset");
16
16
  runner.use(pipes.VerifyMultiSig(0));
17
- const schema = Joi.object({
18
- factory: Joi.DID().prefix().role("ROLE_FACTORY").required(),
19
- address: Joi.DID().prefix().role("ROLE_ASSET").required(),
20
- assetsList: Joi.array().items(Joi.DID().prefix().role("ROLE_ASSET")).default([]),
21
- variablesList: Joi.array().items(schemas.variableInput).optional().allow(null).default([]),
22
- owner: schemas.tokenHolder.required(),
23
- data: Joi.any().optional().allow(null)
24
- }).options({
25
- stripUnknown: true,
26
- noDefaults: false
27
- });
17
+ const schema = v.pipe(v.object({
18
+ factory: vDID({
19
+ prefix: true,
20
+ role: "ROLE_FACTORY"
21
+ }),
22
+ address: vDID({
23
+ prefix: true,
24
+ role: "ROLE_ASSET"
25
+ }),
26
+ assetsList: v.optional(v.array(vDID({
27
+ prefix: true,
28
+ role: "ROLE_ASSET"
29
+ })), []),
30
+ variablesList: v.optional(v.nullable(v.array(schemas.variableInput)), []),
31
+ owner: schemas.tokenHolder,
32
+ data: v.optional(v.nullable(v.any()))
33
+ }), vStripUnknown());
28
34
  runner.use(({ itx }, next) => {
29
- const { error } = schema.validate(itx);
35
+ const { error } = vValidate(schema, itx);
30
36
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
31
37
  return next();
32
38
  });
@@ -5,25 +5,25 @@ import { Runner, pipes } from "@ocap/tx-pipeline";
5
5
  import { CustomError } from "@ocap/util/lib/error";
6
6
  import { account, asset } from "@ocap/state";
7
7
  import Debug from "debug";
8
- import { Joi } from "@arcblock/validator";
8
+ import { v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
9
9
  import { diff } from "deep-diff";
10
10
 
11
11
  //#region src/protocols/asset/update.ts
12
12
  const debug = Debug("@ocap/tx-protocols:update-asset");
13
13
  const runner = new Runner("update_asset");
14
14
  runner.use(pipes.VerifyMultiSig(0));
15
- const schema = Joi.object({
16
- address: Joi.DID().prefix().role("ROLE_ASSET").required(),
17
- moniker: Joi.string().min(2).max(255).optional().allow(null).allow(""),
18
- consumed: Joi.boolean().optional().allow(null).default(false),
19
- data: Joi.any().optional().allow(null)
20
- }).options({
21
- stripUnknown: true,
22
- noDefaults: false
23
- });
15
+ const schema = v.pipe(v.object({
16
+ address: vDID({
17
+ prefix: true,
18
+ role: "ROLE_ASSET"
19
+ }),
20
+ moniker: v.optional(v.nullable(v.pipe(v.string(), v.maxLength(255)))),
21
+ consumed: v.optional(v.nullable(v.boolean()), false),
22
+ data: v.optional(v.nullable(v.any()))
23
+ }), vStripUnknown());
24
24
  runner.use((context, next) => {
25
25
  const { itx } = context;
26
- const { error } = schema.validate(itx);
26
+ const { error } = vValidate(schema, itx);
27
27
  if (error) return next(new CustomError("INVALID_TX", `Invalid itx: ${error.message}`));
28
28
  if (!itx.moniker && !itx.data) return next(new CustomError("INVALID_TX", "itx.moniker and itx.data can not be empty at the same time"));
29
29
  context.newData = decodeAnySafe(itx.data ?? null);
@@ -6,23 +6,23 @@ import { CustomError } from "@ocap/util/lib/error";
6
6
  import { account, asset, evidence, stake } from "@ocap/state";
7
7
  import { BN } from "@ocap/util";
8
8
  import Debug from "debug";
9
- import { Joi, patterns } from "@arcblock/validator";
9
+ import { patterns, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
10
10
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
11
11
 
12
12
  //#region src/protocols/governance/claim-stake.ts
13
13
  const debug = Debug("@ocap/tx-protocols:claim-stake");
14
14
  const runner = new Runner("claim_stake");
15
15
  runner.use(pipes.VerifyMultiSig(0));
16
- const schema = Joi.object({
17
- address: Joi.DID().prefix().role("ROLE_STAKE").required(),
18
- evidence: Joi.object({ hash: Joi.string().regex(patterns.txHash).required() }).required(),
19
- data: Joi.any().optional().allow(null)
20
- }).options({
21
- stripUnknown: true,
22
- noDefaults: false
23
- });
16
+ const schema = v.pipe(v.object({
17
+ address: vDID({
18
+ prefix: true,
19
+ role: "ROLE_STAKE"
20
+ }),
21
+ evidence: v.object({ hash: v.pipe(v.string(), v.regex(patterns.txHash)) }),
22
+ data: v.optional(v.nullable(v.any()))
23
+ }), vStripUnknown());
24
24
  runner.use(({ itx }, next) => {
25
- const { error } = schema.validate(itx);
25
+ const { error } = vValidate(schema, itx);
26
26
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
27
27
  });
28
28
  runner.use(pipes.ExtractState({
@@ -7,7 +7,7 @@ import { account, asset, stake } from "@ocap/state";
7
7
  import { BN } from "@ocap/util";
8
8
  import Debug from "debug";
9
9
  import { getListField } from "@ocap/util/lib/get-list-field";
10
- import { Joi, schemas } from "@arcblock/validator";
10
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
11
11
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
12
  import isEmpty from "lodash/isEmpty.js";
13
13
 
@@ -15,17 +15,17 @@ import isEmpty from "lodash/isEmpty.js";
15
15
  const debug = Debug("@ocap/tx-protocols:return-stake");
16
16
  const runner = new Runner("return_stake");
17
17
  runner.use(pipes.VerifyMultiSig(0));
18
- const schema = Joi.object({
19
- address: Joi.DID().prefix().role("ROLE_STAKE").required(),
20
- message: Joi.string().trim().min(1).max(256).required(),
21
- outputsList: schemas.multiInput.min(1).required(),
22
- data: Joi.any().optional().allow(null)
23
- }).options({
24
- stripUnknown: true,
25
- noDefaults: false
26
- });
18
+ const schema = v.pipe(v.object({
19
+ address: vDID({
20
+ prefix: true,
21
+ role: "ROLE_STAKE"
22
+ }),
23
+ message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
24
+ outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
25
+ data: v.optional(v.nullable(v.any()))
26
+ }), vStripUnknown());
27
27
  runner.use(({ itx }, next) => {
28
- const { error } = schema.validate(itx);
28
+ const { error } = vValidate(schema, itx);
29
29
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
30
30
  });
31
31
  runner.use(pipes.VerifyTxInput({
@@ -7,7 +7,7 @@ import { account, stake } from "@ocap/state";
7
7
  import { BN } from "@ocap/util";
8
8
  import Debug from "debug";
9
9
  import { getListField } from "@ocap/util/lib/get-list-field";
10
- import { Joi, schemas } from "@arcblock/validator";
10
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
11
11
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
12
  import isEmpty from "lodash/isEmpty.js";
13
13
 
@@ -15,16 +15,16 @@ import isEmpty from "lodash/isEmpty.js";
15
15
  const debug = Debug("@ocap/tx-protocols:revoke-stake");
16
16
  const runner = new Runner("revoke_stake");
17
17
  runner.use(pipes.VerifyMultiSig(0));
18
- const schema = Joi.object({
19
- address: Joi.DID().prefix().role("ROLE_STAKE").required(),
20
- outputsList: schemas.multiInput.min(1).required(),
21
- data: Joi.any().optional().allow(null)
22
- }).options({
23
- stripUnknown: true,
24
- noDefaults: false
25
- });
18
+ const schema = v.pipe(v.object({
19
+ address: vDID({
20
+ prefix: true,
21
+ role: "ROLE_STAKE"
22
+ }),
23
+ outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
24
+ data: v.optional(v.nullable(v.any()))
25
+ }), vStripUnknown());
26
26
  runner.use(({ itx }, next) => {
27
- const { error } = schema.validate(itx);
27
+ const { error } = vValidate(schema, itx);
28
28
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
29
29
  });
30
30
  runner.use(pipes.VerifyTxInput({
@@ -7,7 +7,7 @@ import { account, asset, stake } from "@ocap/state";
7
7
  import { BN } from "@ocap/util";
8
8
  import Debug from "debug";
9
9
  import { getListField } from "@ocap/util/lib/get-list-field";
10
- import { Joi, schemas } from "@arcblock/validator";
10
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
11
11
  import { getRelatedAddresses } from "@ocap/util/lib/get-related-addr";
12
12
  import isEmpty from "lodash/isEmpty.js";
13
13
 
@@ -15,17 +15,17 @@ import isEmpty from "lodash/isEmpty.js";
15
15
  const debug = Debug("@ocap/tx-protocols:slash-stake");
16
16
  const runner = new Runner("slash_stake");
17
17
  runner.use(pipes.VerifyMultiSig(0));
18
- const schema = Joi.object({
19
- address: Joi.DID().prefix().role("ROLE_STAKE").required(),
20
- message: Joi.string().trim().min(1).max(256).required(),
21
- outputsList: schemas.multiInput.min(1).required(),
22
- data: Joi.any().optional().allow(null)
23
- }).options({
24
- stripUnknown: true,
25
- noDefaults: false
26
- });
18
+ const schema = v.pipe(v.object({
19
+ address: vDID({
20
+ prefix: true,
21
+ role: "ROLE_STAKE"
22
+ }),
23
+ message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
24
+ outputsList: v.pipe(schemas.multiInput, v.minLength(1)),
25
+ data: v.optional(v.nullable(v.any()))
26
+ }), vStripUnknown());
27
27
  runner.use(({ itx }, next) => {
28
- const { error } = schema.validate(itx);
28
+ const { error } = vValidate(schema, itx);
29
29
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
30
30
  });
31
31
  runner.use(pipes.VerifyTxInput({
@@ -9,7 +9,7 @@ import { account, asset, stake } from "@ocap/state";
9
9
  import { BN, fromTokenToUnit } from "@ocap/util";
10
10
  import Debug from "debug";
11
11
  import { getListField } from "@ocap/util/lib/get-list-field";
12
- import { Joi, schemas } from "@arcblock/validator";
12
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
13
13
  import { promisify } from "node:util";
14
14
  import isEmpty from "lodash/isEmpty.js";
15
15
 
@@ -20,22 +20,22 @@ const verifyAssetOwner = promisify(pipes.VerifyUpdater({
20
20
  ownerKey: "owner"
21
21
  }));
22
22
  const runner = new Runner("stake");
23
- const schema = Joi.object({
24
- address: Joi.DID().prefix().role("ROLE_STAKE").required(),
25
- receiver: Joi.DID().prefix().required(),
26
- slashersList: Joi.array().items(Joi.DID().prefix()).default([]),
27
- locked: Joi.boolean().default(false),
28
- inputsList: schemas.multiInput.min(1).required(),
29
- message: Joi.string().trim().min(1).max(256).required(),
30
- revokeWaitingPeriod: Joi.number().integer().min(0).default(0),
31
- data: Joi.any().optional().allow(null),
32
- nonce: Joi.string().trim().min(1).max(256).allow("").optional().allow(null)
33
- }).options({
34
- stripUnknown: true,
35
- noDefaults: false
36
- });
23
+ const schema = v.pipe(v.object({
24
+ address: vDID({
25
+ prefix: true,
26
+ role: "ROLE_STAKE"
27
+ }),
28
+ receiver: vDID({ prefix: true }),
29
+ slashersList: v.optional(v.array(vDID({ prefix: true })), []),
30
+ locked: v.optional(v.boolean(), false),
31
+ inputsList: v.pipe(schemas.multiInput, v.minLength(1)),
32
+ message: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256)),
33
+ revokeWaitingPeriod: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0)), 0),
34
+ data: v.optional(v.nullable(v.any())),
35
+ nonce: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(256))])))
36
+ }), vStripUnknown());
37
37
  runner.use(({ itx }, next) => {
38
- const { error } = schema.validate(itx);
38
+ const { error } = vValidate(schema, itx);
39
39
  return next(error ? new CustomError("INVALID_TX", `Invalid itx: ${error.message}`) : void 0);
40
40
  });
41
41
  runner.use(pipes.VerifyTxInput({