@arcblock/validator 1.18.32 → 1.18.34

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.
@@ -6,6 +6,7 @@ export interface DIDSchema extends StringSchema {
6
6
  pk(type: KeyType): this;
7
7
  hash(type: HashType): this;
8
8
  role(type: RoleType): this;
9
+ prefix(str?: string): this;
9
10
  }
10
11
  export declare function DIDExtension(root: Root): {
11
12
  type: string;
@@ -17,6 +18,7 @@ export declare function DIDExtension(root: Root): {
17
18
  'did.pk': string;
18
19
  'did.hash': string;
19
20
  'did.role': string;
21
+ 'did.prefix': string;
20
22
  };
21
23
  validate(value: any, helpers: any): {
22
24
  errors: any;
@@ -40,9 +42,6 @@ export declare function DIDExtension(root: Root): {
40
42
  })[];
41
43
  validate(value: string, helpers: any, args: any): any;
42
44
  };
43
- wallet: {
44
- method(type: DIDTypeShortcut): DIDSchema;
45
- };
46
45
  pk: {
47
46
  method(type: KeyType): DIDSchema;
48
47
  };
@@ -52,5 +51,27 @@ export declare function DIDExtension(root: Root): {
52
51
  role: {
53
52
  method(type: RoleType): DIDSchema;
54
53
  };
54
+ wallet: {
55
+ method(type: DIDTypeShortcut): DIDSchema;
56
+ args: {
57
+ name: string;
58
+ ref: boolean;
59
+ assert: (v: any) => boolean;
60
+ message: string;
61
+ normalize: (v: any) => any;
62
+ }[];
63
+ validate(value: any, helpers: any, args?: any): any;
64
+ };
65
+ prefix: {
66
+ method(str?: string): DIDSchema;
67
+ args: {
68
+ name: string;
69
+ ref: boolean;
70
+ assert: (v: any) => boolean;
71
+ message: string;
72
+ normalize: (v: any) => any;
73
+ }[];
74
+ validate(value: any, helpers: any, args?: any): any;
75
+ };
55
76
  };
56
77
  };
@@ -8,7 +8,6 @@ const isEqual_1 = __importDefault(require("lodash/isEqual"));
8
8
  const mcrypto_1 = require("@ocap/mcrypto");
9
9
  const did_1 = require("@arcblock/did");
10
10
  const ruleTypes = {
11
- wallet: ['arcblock', 'ethereum', 'default', 'eth'],
12
11
  pk: Object.keys(mcrypto_1.types.KeyType),
13
12
  hash: Object.keys(mcrypto_1.types.HashType),
14
13
  role: Object.keys(mcrypto_1.types.RoleType),
@@ -24,6 +23,7 @@ function DIDExtension(root) {
24
23
  'did.pk': 'Expect pk type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
25
24
  'did.hash': 'Expect hash type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
26
25
  'did.role': 'Expect role type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
26
+ 'did.prefix': 'Expect prefix of {{#label}} to be "{{#expected}}"',
27
27
  },
28
28
  validate(value, helpers) {
29
29
  if (!value || typeof value !== 'string') {
@@ -53,16 +53,7 @@ function DIDExtension(root) {
53
53
  // The rule return structure is different from the root
54
54
  // eslint-disable-next-line consistent-return
55
55
  validate(value, helpers, args) {
56
- const type = (0, did_1.toTypeInfo)(value);
57
56
  const typeStr = (0, did_1.toTypeInfoStr)(value);
58
- if (args.key === 'wallet') {
59
- if (['ethereum', 'eth'].includes(args.expected) && (0, isEqual_1.default)(type, did_1.DID_TYPE_ETHEREUM) === false) {
60
- return helpers.error('did.wallet', Object.assign(Object.assign({}, args), { actual: JSON.stringify(typeStr) }));
61
- }
62
- if (['arcblock', 'default'].includes(args.expected) && (0, isEqual_1.default)(type, did_1.DID_TYPE_ARCBLOCK) === false) {
63
- return helpers.error('did.wallet', Object.assign(Object.assign({}, args), { actual: JSON.stringify(typeStr) }));
64
- }
65
- }
66
57
  if (args.key === 'pk' && typeStr.pk !== args.expected) {
67
58
  return helpers.error('did.pk', Object.assign(Object.assign({}, args), { actual: typeStr.pk }));
68
59
  }
@@ -75,12 +66,6 @@ function DIDExtension(root) {
75
66
  return value;
76
67
  },
77
68
  },
78
- wallet: {
79
- method(type) {
80
- // @ts-ignore
81
- return this.$_addRule({ name: 'type', args: { key: 'wallet', expected: type } });
82
- },
83
- },
84
69
  pk: {
85
70
  method(type) {
86
71
  // @ts-ignore
@@ -99,6 +84,56 @@ function DIDExtension(root) {
99
84
  return this.$_addRule({ name: 'type', args: { key: 'role', expected: type } });
100
85
  },
101
86
  },
87
+ wallet: {
88
+ method(type) {
89
+ // @ts-ignore
90
+ return this.$_addRule({ name: 'wallet', args: { type } });
91
+ },
92
+ args: [
93
+ {
94
+ name: 'type',
95
+ ref: true,
96
+ assert: (v) => ['arcblock', 'ethereum', 'default', 'eth'].includes(v),
97
+ message: 'must be a string',
98
+ normalize: (v) => v.trim(),
99
+ },
100
+ ],
101
+ validate(value, helpers, args = {}) {
102
+ const type = (0, did_1.toTypeInfo)(value);
103
+ const typeStr = (0, did_1.toTypeInfoStr)(value);
104
+ if (['ethereum', 'eth'].includes(args.type) && (0, isEqual_1.default)(type, did_1.DID_TYPE_ETHEREUM) === false) {
105
+ return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
106
+ }
107
+ if (['arcblock', 'default'].includes(args.type) && (0, isEqual_1.default)(type, did_1.DID_TYPE_ARCBLOCK) === false) {
108
+ return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
109
+ }
110
+ return value;
111
+ },
112
+ },
113
+ prefix: {
114
+ method(str = '') {
115
+ // @ts-ignore
116
+ return this.$_addRule({ name: 'prefix', args: { str } });
117
+ },
118
+ args: [
119
+ {
120
+ name: 'str',
121
+ ref: true,
122
+ assert: (v) => ['', did_1.DID_PREFIX].includes(v),
123
+ message: 'must be a string',
124
+ normalize: (v) => v.trim(),
125
+ },
126
+ ],
127
+ validate(value, helpers, args = {}) {
128
+ if (args.str && value.startsWith(args.str) === false) {
129
+ return helpers.error('did.prefix', { expected: args.str });
130
+ }
131
+ if (!args.str && (0, did_1.toAddress)(value) !== value) {
132
+ return helpers.error('did.prefix', { expected: args.str });
133
+ }
134
+ return value;
135
+ },
136
+ },
102
137
  },
103
138
  };
104
139
  }
package/lib/index.d.ts CHANGED
@@ -12,8 +12,11 @@ export declare const schemas: {
12
12
  multiInput: BaseJoi.ArraySchema<any[]>;
13
13
  multiSig: BaseJoi.ArraySchema<any[]>;
14
14
  foreignToken: BaseJoi.ObjectSchema<any>;
15
+ variableInput: BaseJoi.ObjectSchema<any>;
15
16
  nftDisplay: BaseJoi.ObjectSchema<any>;
16
17
  nftEndpoint: BaseJoi.ObjectSchema<any>;
18
+ nftIssuer: BaseJoi.ObjectSchema<any>;
19
+ tokenHolder: BaseJoi.AlternativesSchema<any>;
17
20
  assetProps: {
18
21
  address: DIDSchema;
19
22
  moniker: BaseJoi.StringSchema<string>;
package/lib/index.js CHANGED
@@ -16,24 +16,31 @@ const context = exports.Joi.object({
16
16
  renaissanceTx: exports.Joi.string().regex(txHash).required().allow(''),
17
17
  });
18
18
  const tokenInput = exports.Joi.object({
19
- address: exports.Joi.DID().role('ROLE_TOKEN').required(),
19
+ address: exports.Joi.DID().prefix().role('ROLE_TOKEN').required(),
20
20
  value: exports.Joi.BN().positive().required(),
21
21
  });
22
+ const variableInput = exports.Joi.object({
23
+ name: exports.Joi.string().min(1).max(256).required(),
24
+ value: exports.Joi.string().min(1).max(1024).required(),
25
+ description: exports.Joi.string().min(1).max(256).optional().allow(''),
26
+ required: exports.Joi.boolean().optional().default(false),
27
+ });
28
+ const tokenHolder = exports.Joi.alternatives().try(exports.Joi.DID().prefix().role('ROLE_ACCOUNT'), exports.Joi.DID().prefix().role('ROLE_APPLICATION'), exports.Joi.DID().prefix().wallet('ethereum'));
22
29
  const multiInput = exports.Joi.array().items(exports.Joi.object({
23
- owner: exports.Joi.DID().required(),
24
- tokens: exports.Joi.array().items(tokenInput).default([]),
25
- assets: exports.Joi.array().items(exports.Joi.DID().role('ROLE_ASSET')).default([]),
30
+ owner: tokenHolder.required(),
31
+ tokensList: exports.Joi.array().items(tokenInput).default([]),
32
+ assetsList: exports.Joi.array().items(exports.Joi.DID().prefix().role('ROLE_ASSET')).default([]),
26
33
  }));
27
34
  const multiSig = exports.Joi.array().items({
28
- signer: exports.Joi.DID().required(),
35
+ signer: exports.Joi.DID().prefix().required(),
29
36
  pk: exports.Joi.any().required(),
30
37
  signature: exports.Joi.any().required(),
31
- delegator: exports.Joi.DID().valid('').optional(),
38
+ delegator: exports.Joi.DID().prefix().valid('').optional(),
32
39
  data: exports.Joi.any().optional(),
33
40
  });
34
41
  const foreignToken = exports.Joi.object({
35
42
  type: exports.Joi.string().min(1).max(32).required(),
36
- contractAddress: exports.Joi.DID().wallet('ethereum').required(),
43
+ contractAddress: exports.Joi.DID().prefix().wallet('ethereum').required(),
37
44
  chainType: exports.Joi.string().min(1).max(32).required(),
38
45
  chainName: exports.Joi.string().min(1).max(32).required(),
39
46
  chainId: exports.Joi.number().positive().required(),
@@ -48,32 +55,40 @@ const nftEndpoint = exports.Joi.object({
48
55
  id: exports.Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required(),
49
56
  scope: exports.Joi.string().valid('public', 'private').default('public'),
50
57
  });
58
+ const nftIssuer = exports.Joi.object({
59
+ id: exports.Joi.DID().prefix().required(),
60
+ pk: exports.Joi.string().required(),
61
+ name: exports.Joi.string().min(1).max(256).required(),
62
+ });
51
63
  const assetProps = {
52
- address: exports.Joi.DID().role('ROLE_ASSET').required(),
64
+ address: exports.Joi.DID().prefix().role('ROLE_ASSET').required(),
53
65
  moniker: exports.Joi.string().min(2).max(255).required(),
54
66
  data: exports.Joi.any().required(),
55
67
  readonly: exports.Joi.boolean().default(false),
56
68
  transferrable: exports.Joi.boolean().default(false),
57
69
  ttl: exports.Joi.number().min(0).default(0),
58
- parent: exports.Joi.DID().optional().allow(''),
59
- issuer: exports.Joi.DID().optional().allow(''),
70
+ parent: exports.Joi.DID().prefix().optional().allow(''),
71
+ issuer: exports.Joi.DID().prefix().optional().allow(''),
60
72
  endpoint: nftEndpoint.optional().allow(null).default(null),
61
73
  display: nftDisplay.optional().allow(null).default(null),
62
74
  tags: exports.Joi.array().items(exports.Joi.string().min(1).max(36)).max(4).optional(),
63
75
  };
64
76
  const factoryProps = {
65
- address: exports.Joi.DID().role('ROLE_FACTORY').required(),
77
+ address: exports.Joi.DID().prefix().role('ROLE_FACTORY').required(),
66
78
  name: exports.Joi.string().min(2).max(255).required(),
67
79
  description: exports.Joi.string().min(2).max(255).required(),
68
80
  settlement: exports.Joi.string().valid('instant', 'periodic').default('instant'),
69
81
  limit: exports.Joi.number().integer().min(0).default(0),
70
- trustedIssuers: exports.Joi.array().items(exports.Joi.DID()).max(8).optional(),
82
+ trustedIssuers: exports.Joi.array().items(exports.Joi.DID().prefix()).max(8).optional(),
71
83
  data: exports.Joi.any().optional().allow(null).default(null),
72
84
  display: nftDisplay.optional().allow(null).default(null),
73
85
  input: exports.Joi.object({
74
86
  value: exports.Joi.BN().positive().min('0').default('0'),
75
87
  tokens: exports.Joi.array().items(tokenInput).max(8).optional(),
76
- assets: exports.Joi.array().items(exports.Joi.DID()).max(8).optional(),
88
+ assets: exports.Joi.array()
89
+ .items(exports.Joi.alternatives().try(exports.Joi.DID().prefix().role('ROLE_ASSET'), exports.Joi.DID().prefix().role('ROLE_FACTORY')))
90
+ .max(8)
91
+ .optional(),
77
92
  variables: exports.Joi.array()
78
93
  .items(exports.Joi.object({
79
94
  name: exports.Joi.string().min(1).max(255).required(),
@@ -109,8 +124,11 @@ exports.schemas = {
109
124
  multiInput,
110
125
  multiSig,
111
126
  foreignToken,
127
+ variableInput,
112
128
  nftDisplay,
113
129
  nftEndpoint,
130
+ nftIssuer,
131
+ tokenHolder,
114
132
  assetProps,
115
133
  assetSchema: exports.Joi.object(assetProps).options({ stripUnknown: true, noDefaults: false }),
116
134
  factoryProps,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.32",
6
+ "version": "1.18.34",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
@@ -21,11 +21,11 @@
21
21
  "build": "tsc"
22
22
  },
23
23
  "dependencies": {
24
- "@arcblock/did": "1.18.32",
25
- "@ocap/mcrypto": "1.18.32",
26
- "@ocap/util": "1.18.32",
24
+ "@arcblock/did": "1.18.34",
25
+ "@ocap/mcrypto": "1.18.34",
26
+ "@ocap/util": "1.18.34",
27
27
  "bn.js": "5.2.1",
28
- "joi": "^17.6.3",
28
+ "joi": "^17.7.0",
29
29
  "lodash": "^4.17.21",
30
30
  "type-fest": "^3.1.0"
31
31
  },
@@ -42,5 +42,5 @@
42
42
  "keywords": [],
43
43
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
44
44
  "license": "MIT",
45
- "gitHead": "44a7e8ee3e89535a4e18fbbc2ad6ff408c8e2474"
45
+ "gitHead": "c12d3cbf9617d861d83c08726d9e0d55fdf9a459"
46
46
  }