@ocap/state 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 (39) hide show
  1. package/esm/_virtual/rolldown_runtime.mjs +28 -1
  2. package/esm/node_modules/bn.js/lib/bn.mjs +2551 -0
  3. package/esm/states/account.d.mts +18 -2
  4. package/esm/states/account.mjs +16 -16
  5. package/esm/states/asset.d.mts +2 -5
  6. package/esm/states/asset.mjs +9 -13
  7. package/esm/states/evidence.d.mts +11 -2
  8. package/esm/states/evidence.mjs +6 -9
  9. package/esm/states/factory.mjs +15 -11
  10. package/esm/states/rollup-block.d.mts +36 -2
  11. package/esm/states/rollup-block.mjs +27 -25
  12. package/esm/states/rollup.d.mts +62 -2
  13. package/esm/states/rollup.mjs +73 -49
  14. package/esm/states/stake.d.mts +22 -2
  15. package/esm/states/stake.mjs +32 -20
  16. package/esm/states/token-factory.d.mts +15 -4
  17. package/esm/states/token-factory.mjs +47 -31
  18. package/esm/states/token.d.mts +44 -3
  19. package/esm/states/token.mjs +55 -43
  20. package/lib/_virtual/rolldown_runtime.cjs +2 -0
  21. package/lib/node_modules/bn.js/lib/bn.cjs +2554 -0
  22. package/lib/states/account.cjs +15 -15
  23. package/lib/states/account.d.cts +18 -2
  24. package/lib/states/asset.cjs +7 -13
  25. package/lib/states/asset.d.cts +2 -5
  26. package/lib/states/evidence.cjs +5 -8
  27. package/lib/states/evidence.d.cts +11 -2
  28. package/lib/states/factory.cjs +14 -10
  29. package/lib/states/rollup-block.cjs +26 -24
  30. package/lib/states/rollup-block.d.cts +36 -2
  31. package/lib/states/rollup.cjs +71 -47
  32. package/lib/states/rollup.d.cts +62 -2
  33. package/lib/states/stake.cjs +31 -19
  34. package/lib/states/stake.d.cts +22 -2
  35. package/lib/states/token-factory.cjs +46 -30
  36. package/lib/states/token-factory.d.cts +15 -4
  37. package/lib/states/token.cjs +54 -42
  38. package/lib/states/token.d.cts +44 -3
  39. package/package.json +9 -9
@@ -1,12 +1,28 @@
1
1
  import { StateContextInput } from "../contexts/state.mjs";
2
+ import { v } from "@arcblock/validator";
2
3
  import { IAccountState } from "@ocap/types";
3
- import * as joi1 from "joi";
4
4
 
5
5
  //#region src/states/account.d.ts
6
6
  declare namespace account_d_exports {
7
7
  export { create, ensureChecksumAddress, isMigrated, schema, update, updateOrCreate, validate };
8
8
  }
9
- declare const schema: joi1.ObjectSchema<any>;
9
+ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly address: any;
11
+ readonly pk: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
12
+ readonly issuer: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
13
+ readonly moniker: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Invalid moniker format">]>, undefined>;
14
+ readonly nonce: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, 0>;
15
+ readonly tokens: v.OptionalSchema<any, {}>;
16
+ readonly migratedTo: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
17
+ readonly migratedFrom: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
18
+ readonly context: v.ObjectSchema<{
19
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
20
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
21
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
22
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
23
+ }, undefined>;
24
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
25
+ }, undefined>, any]>;
10
26
  declare const create: (attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
11
27
  declare const update: (state: IAccountState, attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
12
28
  declare const updateOrCreate: (state: IAccountState | null, attrs: Partial<IAccountState>, context: StateContextInput) => IAccountState;
@@ -7,7 +7,7 @@ import { CustomError } from "@ocap/util/lib/error";
7
7
  import flatten from "lodash/flatten.js";
8
8
  import pick from "lodash/pick.js";
9
9
  import uniq from "lodash/uniq.js";
10
- import { Joi, schemas } from "@arcblock/validator";
10
+ import { schemas, v, vBN, vBNMin, vDID, vFilteredRecord, vStripUnknown, vValidate } from "@arcblock/validator";
11
11
 
12
12
  //#region src/states/account.ts
13
13
  var account_exports = /* @__PURE__ */ __exportAll({
@@ -19,21 +19,21 @@ var account_exports = /* @__PURE__ */ __exportAll({
19
19
  updateOrCreate: () => updateOrCreate,
20
20
  validate: () => validate
21
21
  });
22
- const schema = Joi.object({
23
- address: Joi.DID().prefix().required(),
24
- pk: Joi.string().allow(null).allow(""),
25
- issuer: Joi.DID().prefix().allow(null).allow(""),
26
- moniker: Joi.string().regex(/^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/).allow(""),
27
- nonce: Joi.number().min(0).default(0),
28
- tokens: Joi.object().pattern(Joi.DID().prefix().role("ROLE_TOKEN"), Joi.BN().min(0)).default({}),
29
- migratedTo: Joi.array().items(Joi.DID().prefix()).default([]),
30
- migratedFrom: Joi.array().items(Joi.DID().prefix()).default([]),
22
+ const schema = v.pipe(v.object({
23
+ address: vDID({ prefix: true }),
24
+ pk: v.optional(v.nullable(v.string())),
25
+ issuer: v.optional(v.nullable(v.union([v.literal(""), vDID({ prefix: true })]))),
26
+ moniker: v.optional(v.pipe(v.string(), v.check((s) => s === "" || /^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/.test(s), "Invalid moniker format"))),
27
+ nonce: v.optional(v.pipe(v.number(), v.minValue(0)), 0),
28
+ tokens: v.optional(vFilteredRecord(vDID({
29
+ prefix: true,
30
+ role: "ROLE_TOKEN"
31
+ }), vBN(vBNMin(0))), {}),
32
+ migratedTo: v.optional(v.array(vDID({ prefix: true })), []),
33
+ migratedFrom: v.optional(v.array(vDID({ prefix: true })), []),
31
34
  context: schemas.context,
32
- data: Joi.any().optional().allow(null)
33
- }).options({
34
- stripUnknown: true,
35
- noDefaults: false
36
- });
35
+ data: v.optional(v.nullable(v.any()))
36
+ }), vStripUnknown());
37
37
  const create = (attrs, context) => {
38
38
  const account = {
39
39
  nonce: 0,
@@ -79,7 +79,7 @@ const updateOrCreate = (state, attrs, context) => {
79
79
  };
80
80
  const validate = (state) => {
81
81
  if (state.pk && typeof state.pk !== "string") state.pk = toBase58(state.pk);
82
- const { value, error } = schema.validate(state);
82
+ const { value, error } = vValidate(schema, state);
83
83
  if (error) throw new CustomError("INVALID_ACCOUNT", `Invalid account: ${error.details.map((x) => x.message).join(", ")}`);
84
84
  if (!value.data) value.data = null;
85
85
  return value;
@@ -1,15 +1,12 @@
1
1
  import { StateContextInput } from "../contexts/state.mjs";
2
- import { schemas } from "@arcblock/validator";
3
2
  import { IAssetState } from "@ocap/types";
4
- import * as joi0 from "joi";
5
3
 
6
4
  //#region src/states/asset.d.ts
7
5
  declare namespace asset_d_exports {
8
- export { create, schema, schemas, update, validate };
6
+ export { create, update, validate };
9
7
  }
10
- declare const schema: joi0.ObjectSchema<any>;
11
8
  declare const create: (attrs: Partial<IAssetState>, context: StateContextInput) => IAssetState;
12
9
  declare const update: (state: IAssetState, attrs: Partial<IAssetState>, context: StateContextInput) => IAssetState;
13
10
  declare const validate: (state: IAssetState) => IAssetState;
14
11
  //#endregion
15
- export { asset_d_exports, create, schema, schemas, update, validate };
12
+ export { asset_d_exports, create, update, validate };
@@ -3,26 +3,22 @@ import { create as create$1, update as update$1 } from "../contexts/state.mjs";
3
3
  import { toAddress } from "@ocap/util";
4
4
  import { CustomError } from "@ocap/util/lib/error";
5
5
  import pick from "lodash/pick.js";
6
- import { Joi, schemas } from "@arcblock/validator";
6
+ import { schemas, v, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
7
7
 
8
8
  //#region src/states/asset.ts
9
9
  var asset_exports = /* @__PURE__ */ __exportAll({
10
10
  create: () => create,
11
- schema: () => schema,
12
- schemas: () => schemas,
13
11
  update: () => update,
14
12
  validate: () => validate
15
13
  });
16
- const stateSchema = Joi.object({
14
+ const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
15
+ const isIsoDateOrEmpty = (s) => s === "" || ISO_DATE_RE.test(s) && !Number.isNaN(new Date(s).getTime());
16
+ const stateSchema = v.pipe(v.object({
17
17
  ...schemas.assetProps,
18
- owner: Joi.DID().prefix().required(),
19
- consumedTime: Joi.date().iso().raw().allow(""),
18
+ owner: vDID({ prefix: true }),
19
+ consumedTime: v.optional(v.pipe(v.string(), v.check(isIsoDateOrEmpty, "Must be valid ISO date or empty"))),
20
20
  context: schemas.context
21
- }).options({
22
- stripUnknown: true,
23
- noDefaults: false
24
- });
25
- const schema = schemas.assetSchema;
21
+ }), vStripUnknown());
26
22
  const create = (attrs, context) => {
27
23
  const asset = {
28
24
  consumedTime: "",
@@ -68,7 +64,7 @@ const update = (state, attrs, context) => {
68
64
  return validate(asset);
69
65
  };
70
66
  const validate = (state) => {
71
- const { value, error } = stateSchema.validate(state);
67
+ const { value, error } = vValidate(stateSchema, state);
72
68
  if (error) throw new CustomError("INVALID_ASSET", `Invalid asset: ${error.details.map((x) => x.message).join(", ")}`);
73
69
  ["endpoint", "display"].forEach((key) => {
74
70
  if (!value[key]) delete value[key];
@@ -77,4 +73,4 @@ const validate = (state) => {
77
73
  };
78
74
 
79
75
  //#endregion
80
- export { asset_exports, create, schema, schemas, update, validate };
76
+ export { asset_exports, create, update, validate };
@@ -1,12 +1,21 @@
1
1
  import { StateContextInput } from "../contexts/state.mjs";
2
+ import { v } from "@arcblock/validator";
2
3
  import { IEvidenceState } from "@ocap/types";
3
- import * as joi2 from "joi";
4
4
 
5
5
  //#region src/states/evidence.d.ts
6
6
  declare namespace evidence_d_exports {
7
7
  export { create, schema, validate };
8
8
  }
9
- declare const schema: joi2.ObjectSchema<any>;
9
+ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly hash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
11
+ readonly context: v.ObjectSchema<{
12
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
13
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
14
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
15
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
16
+ }, undefined>;
17
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
18
+ }, undefined>, any]>;
10
19
  declare const create: (attrs: Partial<IEvidenceState>, context: StateContextInput) => IEvidenceState;
11
20
  declare const validate: (state: IEvidenceState) => IEvidenceState;
12
21
  //#endregion
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { create as create$1 } from "../contexts/state.mjs";
3
3
  import { CustomError } from "@ocap/util/lib/error";
4
4
  import pick from "lodash/pick.js";
5
- import { Joi, patterns, schemas } from "@arcblock/validator";
5
+ import { patterns, schemas, v, vStripUnknown, vValidate } from "@arcblock/validator";
6
6
 
7
7
  //#region src/states/evidence.ts
8
8
  var evidence_exports = /* @__PURE__ */ __exportAll({
@@ -10,14 +10,11 @@ var evidence_exports = /* @__PURE__ */ __exportAll({
10
10
  schema: () => schema,
11
11
  validate: () => validate
12
12
  });
13
- const schema = Joi.object({
14
- hash: Joi.string().regex(patterns.txHash).required(),
13
+ const schema = v.pipe(v.object({
14
+ hash: v.pipe(v.string(), v.regex(patterns.txHash)),
15
15
  context: schemas.context,
16
- data: Joi.any().optional().allow(null)
17
- }).options({
18
- stripUnknown: true,
19
- noDefaults: false
20
- });
16
+ data: v.optional(v.nullable(v.any()))
17
+ }), vStripUnknown());
21
18
  const create = (attrs, context) => {
22
19
  return validate({
23
20
  context: create$1(context),
@@ -25,7 +22,7 @@ const create = (attrs, context) => {
25
22
  });
26
23
  };
27
24
  const validate = (state) => {
28
- const { value, error } = schema.validate(state);
25
+ const { value, error } = vValidate(schema, state);
29
26
  if (error) throw new CustomError("INVALID_EVIDENCE", `Invalid evidence state: ${error.details.map((x) => x.message).join(", ")}`);
30
27
  if (!value.data) value.data = null;
31
28
  return value;
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { create as create$1, update as update$1 } from "../contexts/state.mjs";
3
3
  import { toAddress } from "@ocap/util";
4
4
  import pick from "lodash/pick.js";
5
- import { Joi, schemas } from "@arcblock/validator";
5
+ import { schemas, v, vBN, vBNMin, vDID, vFilteredRecord, vStripUnknown, vValidate } from "@arcblock/validator";
6
6
  import { compile, getQuota, merge } from "@ocap/contract";
7
7
 
8
8
  //#region src/states/factory.ts
@@ -11,17 +11,21 @@ var factory_exports = /* @__PURE__ */ __exportAll({
11
11
  update: () => update,
12
12
  validate: () => validate
13
13
  });
14
- const stateSchema = Joi.object({
14
+ const ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
15
+ const isIsoDateOrEmpty = (s) => s === "" || ISO_DATE_RE.test(s) && !Number.isNaN(new Date(s).getTime());
16
+ const stateSchema = v.pipe(v.object({
15
17
  ...schemas.factoryProps,
16
- owner: Joi.DID().prefix().required(),
17
- numMinted: Joi.number().min(0).default(0),
18
- lastSettlement: Joi.date().iso().raw().allow(""),
19
- tokens: Joi.object().pattern(Joi.DID().prefix().role("ROLE_TOKEN"), Joi.BN().min(0)).default({}),
18
+ input: v.optional(schemas.factoryProps.input),
19
+ output: v.optional(schemas.factoryProps.output),
20
+ owner: vDID({ prefix: true }),
21
+ numMinted: v.optional(v.pipe(v.number(), v.minValue(0)), 0),
22
+ lastSettlement: v.optional(v.pipe(v.string(), v.check(isIsoDateOrEmpty, "Must be valid ISO date or empty"))),
23
+ tokens: v.optional(vFilteredRecord(vDID({
24
+ prefix: true,
25
+ role: "ROLE_TOKEN"
26
+ }), vBN(vBNMin(0))), {}),
20
27
  context: schemas.context
21
- }).options({
22
- stripUnknown: true,
23
- noDefaults: false
24
- });
28
+ }), vStripUnknown());
25
29
  const compileHook = (hook) => {
26
30
  if (hook.type === "contract") hook.compiled = merge(compile(hook.hook));
27
31
  return hook;
@@ -64,7 +68,7 @@ const update = (state, attrs, context) => {
64
68
  return validate(factory);
65
69
  };
66
70
  const validate = (state) => {
67
- const { value, error } = stateSchema.validate(state);
71
+ const { value, error } = vValidate(stateSchema, state);
68
72
  if (error) throw new Error(`Invalid factory: ${error.details.map((x) => x.message).join(", ")}`);
69
73
  ["display"].forEach((key) => {
70
74
  if (!value[key]) delete value[key];
@@ -1,12 +1,46 @@
1
1
  import { StateContextInput } from "../contexts/state.mjs";
2
+ import { v } from "@arcblock/validator";
2
3
  import { IRollupBlock } from "@ocap/types";
3
- import * as joi4 from "joi";
4
4
 
5
5
  //#region src/states/rollup-block.d.ts
6
6
  declare namespace rollup_block_d_exports {
7
7
  export { create, schema, update, validate };
8
8
  }
9
- declare const schema: joi4.ObjectSchema<any>;
9
+ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly hash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
11
+ readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.CheckAction<number, "Must be greater than 0">]>;
12
+ readonly merkleRoot: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
13
+ readonly previousHash: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
14
+ readonly txsHash: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
15
+ readonly txs: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, v.MinLengthAction<string[], 1, undefined>, v.CheckAction<string[], "Must contain unique values">]>;
16
+ readonly proposer: any;
17
+ readonly signatures: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
18
+ readonly signer: any;
19
+ readonly pk: v.AnySchema;
20
+ readonly signature: v.AnySchema;
21
+ readonly delegator: v.OptionalSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>;
22
+ readonly data: v.OptionalSchema<v.AnySchema, undefined>;
23
+ }, undefined>, undefined>, v.MinLengthAction<{
24
+ readonly signer?: any;
25
+ pk: any;
26
+ signature: any;
27
+ delegator?: any;
28
+ data?: any;
29
+ }[], 1, undefined>]>;
30
+ readonly rollup: any;
31
+ readonly mintedAmount: v.OptionalSchema<v.NullableSchema<any, undefined>, "0">;
32
+ readonly burnedAmount: v.OptionalSchema<v.NullableSchema<any, undefined>, "0">;
33
+ readonly rewardAmount: v.OptionalSchema<v.NullableSchema<any, undefined>, "0">;
34
+ readonly minReward: any;
35
+ readonly governance: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
36
+ readonly context: v.ObjectSchema<{
37
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
38
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
39
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
40
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
41
+ }, undefined>;
42
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
43
+ }, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>;
10
44
  declare const create: (attrs: Partial<IRollupBlock>, context: StateContextInput) => IRollupBlock;
11
45
  declare const update: (state: IRollupBlock, context: StateContextInput) => IRollupBlock;
12
46
  declare const validate: (state: IRollupBlock) => IRollupBlock;
@@ -2,7 +2,7 @@ import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { create as create$1, update as update$1 } from "../contexts/state.mjs";
3
3
  import { CustomError } from "@ocap/util/lib/error";
4
4
  import pick from "lodash/pick.js";
5
- import { Joi, patterns, schemas } from "@arcblock/validator";
5
+ import { patterns, schemas, v, vBN, vBNMin, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
6
6
 
7
7
  //#region src/states/rollup-block.ts
8
8
  var rollup_block_exports = /* @__PURE__ */ __exportAll({
@@ -11,31 +11,33 @@ var rollup_block_exports = /* @__PURE__ */ __exportAll({
11
11
  update: () => update,
12
12
  validate: () => validate
13
13
  });
14
- const schema = Joi.object({
15
- hash: Joi.string().regex(patterns.txHash).required(),
16
- height: Joi.number().integer().greater(0).required(),
17
- merkleRoot: Joi.string().regex(patterns.txHash).required(),
18
- previousHash: Joi.string().when("height", {
19
- is: 1,
20
- then: Joi.string().optional().allow(null).allow(""),
21
- otherwise: Joi.string().regex(patterns.txHash).required()
14
+ const schema = v.pipe(v.object({
15
+ hash: v.pipe(v.string(), v.regex(patterns.txHash)),
16
+ height: v.pipe(v.number(), v.integer(), v.check((n) => n > 0, "Must be greater than 0")),
17
+ merkleRoot: v.pipe(v.string(), v.regex(patterns.txHash)),
18
+ previousHash: v.optional(v.nullable(v.string())),
19
+ txsHash: v.pipe(v.string(), v.regex(patterns.txHash)),
20
+ txs: v.pipe(v.array(v.pipe(v.string(), v.regex(patterns.txHash))), v.minLength(1), v.check((arr) => new Set(arr).size === arr.length, "Must contain unique values")),
21
+ proposer: vDID({
22
+ prefix: true,
23
+ wallet: "ethereum"
22
24
  }),
23
- txsHash: Joi.string().regex(patterns.txHash).required(),
24
- txs: Joi.array().items(Joi.string().regex(patterns.txHash).required()).min(1).unique().required(),
25
- proposer: Joi.DID().prefix().wallet("ethereum").required(),
26
- signatures: schemas.multiSig.min(1).required(),
27
- rollup: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
28
- mintedAmount: Joi.BN().min(0).optional().allow(null).default("0"),
29
- burnedAmount: Joi.BN().min(0).optional().allow(null).default("0"),
30
- rewardAmount: Joi.BN().min(0).optional().allow(null).default("0"),
31
- minReward: Joi.BN().min(0).required(),
32
- governance: Joi.boolean().default(false),
25
+ signatures: v.pipe(schemas.multiSig, v.minLength(1)),
26
+ rollup: vDID({
27
+ prefix: true,
28
+ role: "ROLE_ROLLUP"
29
+ }),
30
+ mintedAmount: v.optional(v.nullable(vBN(vBNMin(0))), "0"),
31
+ burnedAmount: v.optional(v.nullable(vBN(vBNMin(0))), "0"),
32
+ rewardAmount: v.optional(v.nullable(vBN(vBNMin(0))), "0"),
33
+ minReward: vBN(vBNMin(0)),
34
+ governance: v.optional(v.boolean(), false),
33
35
  context: schemas.context,
34
- data: Joi.any().optional().allow(null)
35
- }).options({
36
- stripUnknown: true,
37
- noDefaults: false
38
- });
36
+ data: v.optional(v.nullable(v.any()))
37
+ }), v.forward(v.check((d) => {
38
+ if (d.height === 1) return true;
39
+ return typeof d.previousHash === "string" && patterns.txHash.test(d.previousHash);
40
+ }, "previousHash must be a valid tx hash when height > 1"), ["previousHash"]), vStripUnknown());
39
41
  const create = (attrs, context) => {
40
42
  return validate({
41
43
  context: create$1(context),
@@ -65,7 +67,7 @@ const update = (state, context) => {
65
67
  });
66
68
  };
67
69
  const validate = (state) => {
68
- const { value, error } = schema.validate(state);
70
+ const { value, error } = vValidate(schema, state);
69
71
  if (error) throw new CustomError("INVALID_ROLLUP_BLOCK", `Invalid rollup block: ${error.details.map((x) => x.message).join(", ")}`);
70
72
  if (!value.data) value.data = null;
71
73
  return value;
@@ -1,12 +1,72 @@
1
1
  import { StateContextInput } from "../contexts/state.mjs";
2
+ import { v } from "@arcblock/validator";
2
3
  import { IRollupState } from "@ocap/types";
3
- import * as joi0 from "joi";
4
4
 
5
5
  //#region src/states/rollup.d.ts
6
6
  declare namespace rollup_d_exports {
7
7
  export { close, create, migrateContract, migrateVault, pause, resume, schema, update, validate };
8
8
  }
9
- declare const schema: joi0.ObjectSchema<any>;
9
+ declare const schema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
10
+ readonly address: any;
11
+ readonly tokenAddress: any;
12
+ readonly contractAddress: any;
13
+ readonly vaultAddress: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, any], undefined>, undefined>, undefined>;
14
+ readonly migrateHistory: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
15
+ readonly vaultHistory: v.OptionalSchema<v.ArraySchema<any, undefined>, readonly []>;
16
+ readonly paused: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
17
+ readonly closed: v.OptionalSchema<v.BooleanSchema<undefined>, false>;
18
+ readonly seedValidators: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
19
+ readonly pk: v.StringSchema<undefined>;
20
+ readonly address: any;
21
+ readonly endpoint: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be a valid HTTP/HTTPS URL">]>;
22
+ }, undefined>, undefined>, v.MinLengthAction<{
23
+ pk: string;
24
+ readonly address?: any;
25
+ endpoint: string;
26
+ }[], 1, undefined>]>;
27
+ readonly validators: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
28
+ readonly pk: v.StringSchema<undefined>;
29
+ readonly address: any;
30
+ readonly endpoint: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be a valid HTTP/HTTPS URL">]>;
31
+ }, undefined>, undefined>, v.MaxLengthAction<{
32
+ pk: string;
33
+ readonly address?: any;
34
+ endpoint: string;
35
+ }[], 24, undefined>]>, readonly []>;
36
+ readonly minStakeAmount: any;
37
+ readonly maxStakeAmount: any;
38
+ readonly minSignerCount: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>;
39
+ readonly maxSignerCount: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 8, undefined>]>;
40
+ readonly minBlockSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>]>;
41
+ readonly maxBlockSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 15, undefined>]>;
42
+ readonly minBlockInterval: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 3600, undefined>]>;
43
+ readonly minBlockConfirmation: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 100, undefined>]>;
44
+ readonly minDepositAmount: any;
45
+ readonly maxDepositAmount: any;
46
+ readonly minWithdrawAmount: any;
47
+ readonly maxWithdrawAmount: any;
48
+ readonly depositFeeRate: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
49
+ readonly withdrawFeeRate: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
50
+ readonly proposerFeeShare: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
51
+ readonly publisherFeeShare: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
52
+ readonly minDepositFee: any;
53
+ readonly maxDepositFee: any;
54
+ readonly minWithdrawFee: any;
55
+ readonly maxWithdrawFee: any;
56
+ readonly blockHeight: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
57
+ readonly blockHash: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.LiteralSchema<"", undefined>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>], undefined>, undefined>, undefined>;
58
+ readonly issuer: v.OptionalSchema<v.NullableSchema<any, undefined>, undefined>;
59
+ readonly leaveWaitingPeriod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, 0>;
60
+ readonly publishWaitingPeriod: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, 0>;
61
+ readonly publishSlashRate: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10000, undefined>]>;
62
+ readonly context: v.ObjectSchema<{
63
+ readonly genesisTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
64
+ readonly genesisTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
65
+ readonly renaissanceTime: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be valid ISO date">]>;
66
+ readonly renaissanceTx: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must match tx hash pattern or be empty">]>;
67
+ }, undefined>;
68
+ readonly data: v.OptionalSchema<v.NullableSchema<v.AnySchema, undefined>, undefined>;
69
+ }, undefined>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, v.BaseValidation<any, any, v.CheckIssue<any>>, any]>;
10
70
  declare const create: (attrs: Partial<IRollupState>, context: StateContextInput) => IRollupState;
11
71
  declare const update: (state: IRollupState, updates: Partial<IRollupState>, context: StateContextInput) => IRollupState;
12
72
  declare const pause: (state: IRollupState, context: StateContextInput) => IRollupState;
@@ -1,9 +1,10 @@
1
- import { __exportAll } from "../_virtual/rolldown_runtime.mjs";
1
+ import { __exportAll, __toESM } from "../_virtual/rolldown_runtime.mjs";
2
2
  import { create as create$1, update as update$1 } from "../contexts/state.mjs";
3
+ import { require_bn } from "../node_modules/bn.js/lib/bn.mjs";
3
4
  import { toAddress } from "@ocap/util";
4
5
  import { CustomError } from "@ocap/util/lib/error";
5
6
  import pick from "lodash/pick.js";
6
- import { Joi, patterns, schemas } from "@arcblock/validator";
7
+ import { patterns, schemas, v, vBN, vBNPositive, vDID, vStripUnknown, vValidate } from "@arcblock/validator";
7
8
 
8
9
  //#region src/states/rollup.ts
9
10
  var rollup_exports = /* @__PURE__ */ __exportAll({
@@ -17,54 +18,77 @@ var rollup_exports = /* @__PURE__ */ __exportAll({
17
18
  update: () => update,
18
19
  validate: () => validate
19
20
  });
20
- const validator = Joi.object({
21
- pk: Joi.string().required(),
22
- address: Joi.DID().prefix().required(),
23
- endpoint: Joi.string().uri({ scheme: [/https?/] }).required()
21
+ var import_bn = /* @__PURE__ */ __toESM(require_bn(), 1);
22
+ const isHttpOrHttpsUrl = (s) => {
23
+ try {
24
+ return ["http:", "https:"].includes(new URL(s).protocol);
25
+ } catch {
26
+ return false;
27
+ }
28
+ };
29
+ const validatorSchema = v.object({
30
+ pk: v.string(),
31
+ address: vDID({ prefix: true }),
32
+ endpoint: v.pipe(v.string(), v.check(isHttpOrHttpsUrl, "Must be a valid HTTP/HTTPS URL"))
24
33
  });
25
- const schema = Joi.object({
26
- address: Joi.DID().prefix().role("ROLE_ROLLUP").required(),
27
- tokenAddress: Joi.DID().prefix().role("ROLE_TOKEN").required(),
28
- contractAddress: Joi.DID().prefix().wallet("ethereum").required(),
29
- vaultAddress: Joi.DID().wallet("ethereum").optional().allow(null).allow(""),
30
- migrateHistory: Joi.array().items(Joi.DID().prefix().wallet("ethereum")).default([]),
31
- vaultHistory: Joi.array().items(Joi.DID().prefix().wallet("ethereum")).default([]),
32
- paused: Joi.boolean().default(false),
33
- closed: Joi.boolean().default(false),
34
- seedValidators: Joi.array().items(validator).min(1).required(),
35
- validators: Joi.array().items(validator).max(24).default([]),
36
- minStakeAmount: Joi.BN().positive().required(),
37
- maxStakeAmount: Joi.BN().min(Joi.ref("minStakeAmount")).required(),
38
- minSignerCount: Joi.number().integer().min(Joi.ref("seedValidators", { adjust: (v) => v.length })).required(),
39
- maxSignerCount: Joi.number().integer().min(1).max(8).min(Joi.ref("minSignerCount")).required(),
40
- minBlockSize: Joi.number().integer().min(1).required(),
41
- maxBlockSize: Joi.number().integer().min(1).max(15).min(Joi.ref("minBlockSize")).required(),
42
- minBlockInterval: Joi.number().integer().min(1).max(3600).required(),
43
- minBlockConfirmation: Joi.number().integer().min(1).max(100).required(),
44
- minDepositAmount: Joi.BN().positive().less(Joi.ref("minStakeAmount")).required(),
45
- maxDepositAmount: Joi.BN().greater(Joi.ref("minDepositAmount")).less(Joi.ref("minStakeAmount")).required(),
46
- minWithdrawAmount: Joi.BN().positive().required(),
47
- maxWithdrawAmount: Joi.BN().greater(Joi.ref("minWithdrawAmount")).required(),
48
- depositFeeRate: Joi.number().integer().min(0).max(1e4).required(),
49
- withdrawFeeRate: Joi.number().integer().min(0).max(1e4).required(),
50
- proposerFeeShare: Joi.number().integer().min(1).max(1e4).required(),
51
- publisherFeeShare: Joi.number().integer().min(1).max(1e4).required(),
52
- minDepositFee: Joi.BN().positive().required(),
53
- maxDepositFee: Joi.BN().min(Joi.ref("minDepositFee")).required(),
54
- minWithdrawFee: Joi.BN().positive().required(),
55
- maxWithdrawFee: Joi.BN().min(Joi.ref("minWithdrawFee")).required(),
56
- blockHeight: Joi.number().integer().min(0).required(),
57
- blockHash: Joi.string().regex(patterns.txHash).optional().allow(null).allow(""),
58
- issuer: Joi.DID().prefix().optional().allow(null),
59
- leaveWaitingPeriod: Joi.number().integer().min(Joi.ref("minBlockInterval")).default(0),
60
- publishWaitingPeriod: Joi.number().integer().min(Joi.ref("minBlockInterval")).default(0),
61
- publishSlashRate: Joi.number().integer().min(1).max(1e4).required(),
34
+ const schema = v.pipe(v.object({
35
+ address: vDID({
36
+ prefix: true,
37
+ role: "ROLE_ROLLUP"
38
+ }),
39
+ tokenAddress: vDID({
40
+ prefix: true,
41
+ role: "ROLE_TOKEN"
42
+ }),
43
+ contractAddress: vDID({
44
+ prefix: true,
45
+ wallet: "ethereum"
46
+ }),
47
+ vaultAddress: v.optional(v.nullable(v.union([v.literal(""), vDID({ wallet: "ethereum" })]))),
48
+ migrateHistory: v.optional(v.array(vDID({
49
+ prefix: true,
50
+ wallet: "ethereum"
51
+ })), []),
52
+ vaultHistory: v.optional(v.array(vDID({
53
+ prefix: true,
54
+ wallet: "ethereum"
55
+ })), []),
56
+ paused: v.optional(v.boolean(), false),
57
+ closed: v.optional(v.boolean(), false),
58
+ seedValidators: v.pipe(v.array(validatorSchema), v.minLength(1)),
59
+ validators: v.optional(v.pipe(v.array(validatorSchema), v.maxLength(24)), []),
60
+ minStakeAmount: vBN(vBNPositive()),
61
+ maxStakeAmount: vBN(),
62
+ minSignerCount: v.pipe(v.number(), v.integer()),
63
+ maxSignerCount: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(8)),
64
+ minBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1)),
65
+ maxBlockSize: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(15)),
66
+ minBlockInterval: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(3600)),
67
+ minBlockConfirmation: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(100)),
68
+ minDepositAmount: vBN(vBNPositive()),
69
+ maxDepositAmount: vBN(),
70
+ minWithdrawAmount: vBN(vBNPositive()),
71
+ maxWithdrawAmount: vBN(),
72
+ depositFeeRate: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(1e4)),
73
+ withdrawFeeRate: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(1e4)),
74
+ proposerFeeShare: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
75
+ publisherFeeShare: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
76
+ minDepositFee: vBN(vBNPositive()),
77
+ maxDepositFee: vBN(),
78
+ minWithdrawFee: vBN(vBNPositive()),
79
+ maxWithdrawFee: vBN(),
80
+ blockHeight: v.pipe(v.number(), v.integer(), v.minValue(0)),
81
+ blockHash: v.optional(v.nullable(v.union([v.literal(""), v.pipe(v.string(), v.regex(patterns.txHash))]))),
82
+ issuer: v.optional(v.nullable(vDID({ prefix: true }))),
83
+ leaveWaitingPeriod: v.optional(v.pipe(v.number(), v.integer()), 0),
84
+ publishWaitingPeriod: v.optional(v.pipe(v.number(), v.integer()), 0),
85
+ publishSlashRate: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(1e4)),
62
86
  context: schemas.context,
63
- data: Joi.any().optional().allow(null)
64
- }).options({
65
- stripUnknown: true,
66
- noDefaults: false
67
- });
87
+ data: v.optional(v.nullable(v.any()))
88
+ }), v.forward(v.check((d) => new import_bn.default(d.maxStakeAmount).gte(new import_bn.default(d.minStakeAmount)), "maxStakeAmount must be >= minStakeAmount"), ["maxStakeAmount"]), v.forward(v.check((d) => d.minSignerCount >= d.seedValidators.length, "minSignerCount must be >= seedValidators count"), ["minSignerCount"]), v.forward(v.check((d) => d.maxSignerCount >= d.minSignerCount, "maxSignerCount must be >= minSignerCount"), ["maxSignerCount"]), v.forward(v.check((d) => d.maxBlockSize >= d.minBlockSize, "maxBlockSize must be >= minBlockSize"), ["maxBlockSize"]), v.forward(v.check((d) => new import_bn.default(d.minDepositAmount).lt(new import_bn.default(d.minStakeAmount)), "minDepositAmount must be < minStakeAmount"), ["minDepositAmount"]), v.forward(v.check((d) => {
89
+ const max = new import_bn.default(d.maxDepositAmount);
90
+ return max.gt(new import_bn.default(d.minDepositAmount)) && max.lt(new import_bn.default(d.minStakeAmount));
91
+ }, "maxDepositAmount must be > minDepositAmount and < minStakeAmount"), ["maxDepositAmount"]), v.forward(v.check((d) => new import_bn.default(d.maxWithdrawAmount).gt(new import_bn.default(d.minWithdrawAmount)), "maxWithdrawAmount must be > minWithdrawAmount"), ["maxWithdrawAmount"]), v.forward(v.check((d) => new import_bn.default(d.maxDepositFee).gte(new import_bn.default(d.minDepositFee)), "maxDepositFee must be >= minDepositFee"), ["maxDepositFee"]), v.forward(v.check((d) => new import_bn.default(d.maxWithdrawFee).gte(new import_bn.default(d.minWithdrawFee)), "maxWithdrawFee must be >= minWithdrawFee"), ["maxWithdrawFee"]), v.forward(v.check((d) => d.leaveWaitingPeriod >= d.minBlockInterval, "leaveWaitingPeriod must be >= minBlockInterval"), ["leaveWaitingPeriod"]), v.forward(v.check((d) => d.publishWaitingPeriod >= d.minBlockInterval, "publishWaitingPeriod must be >= minBlockInterval"), ["publishWaitingPeriod"]), vStripUnknown());
68
92
  const create = (attrs, context) => {
69
93
  const rollup = {
70
94
  context: create$1(context),
@@ -205,7 +229,7 @@ const migrateVault = (state, to, context) => {
205
229
  });
206
230
  };
207
231
  const validate = (state) => {
208
- const { value, error } = schema.validate(state);
232
+ const { value, error } = vValidate(schema, state);
209
233
  if (error) throw new CustomError("INVALID_ROLLUP_PROPS", error.details.map((x) => x.message).join(", "));
210
234
  if (!value.data) value.data = null;
211
235
  return value;