@arcblock/validator 1.27.15 → 1.28.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.
@@ -1,136 +1,148 @@
1
- import isEqual from 'lodash/isEqual';
2
- import { types } from '@ocap/mcrypto';
3
- import { isValid, toTypeInfo, toTypeInfoStr, DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, toAddress, } from '@arcblock/did';
1
+ import isEqual from "lodash/isEqual.js";
2
+ import { types } from "@ocap/mcrypto";
3
+ import { DID_PREFIX, DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, isValid, toAddress, toTypeInfo, toTypeInfoStr } from "@arcblock/did";
4
+
5
+ //#region src/extension/did.ts
4
6
  const ruleTypes = {
5
- pk: Object.keys(types.KeyType),
6
- hash: Object.keys(types.HashType),
7
- role: Object.keys(types.RoleType),
7
+ pk: Object.keys(types.KeyType),
8
+ hash: Object.keys(types.HashType),
9
+ role: Object.keys(types.RoleType)
8
10
  };
9
- export function DIDExtension(root) {
10
- return {
11
- type: 'DID',
12
- base: root.string().trim(),
13
- messages: {
14
- 'did.empty': 'Expect {{#label}} to be non-empty string',
15
- 'did.invalid': 'Expect {{#label}} to be valid did',
16
- 'did.wallet': 'Expect wallet type of {{#label}} to be "{{#expected}}" wallet',
17
- 'did.pk': 'Expect pk type of {{#label}} to be "{{#expected}}"',
18
- 'did.hash': 'Expect hash type of {{#label}} to be "{{#expected}}"',
19
- 'did.role': 'Expect role type of {{#label}} to be "{{#expected}}"',
20
- 'did.prefix': 'Expect prefix of {{#label}} to be "{{#expected}}"',
21
- },
22
- validate(value, helpers) {
23
- if (!value || typeof value !== 'string') {
24
- return { errors: helpers.error('did.empty', { value }) };
25
- }
26
- if (isValid(value) === false) {
27
- return { errors: helpers.error('did.invalid', { value }) };
28
- }
29
- return { value };
30
- },
31
- rules: {
32
- type: {
33
- args: [
34
- {
35
- name: 'key',
36
- ref: true,
37
- assert: (v) => Object.keys(ruleTypes).includes(v),
38
- message: `must be one of ${Object.keys(ruleTypes).join(', ')}`,
39
- },
40
- {
41
- name: 'expected',
42
- // @ts-ignore
43
- assert: (v) => Object.keys(ruleTypes).some((x) => ruleTypes[x].includes(v)),
44
- message: 'must be valid type',
45
- },
46
- ],
47
- // The rule return structure is different from the root
48
- // eslint-disable-next-line consistent-return
49
- validate(value, helpers, args) {
50
- const typeStr = toTypeInfoStr(value);
51
- if (args.key === 'pk' && typeStr.pk !== args.expected) {
52
- return helpers.error('did.pk', { ...args, actual: typeStr.pk });
53
- }
54
- if (args.key === 'hash' && typeStr.hash !== args.expected) {
55
- return helpers.error('did.hash', { ...args, actual: typeStr.hash });
56
- }
57
- if (args.key === 'role' && typeStr.role !== args.expected) {
58
- return helpers.error('did.role', { ...args, actual: typeStr.role });
59
- }
60
- return value;
61
- },
62
- },
63
- pk: {
64
- method(type) {
65
- // @ts-ignore
66
- return this.$_addRule({ name: 'type', args: { key: 'pk', expected: type } });
67
- },
68
- },
69
- hash: {
70
- method(type) {
71
- // @ts-ignore
72
- return this.$_addRule({ name: 'type', args: { key: 'hash', expected: type } });
73
- },
74
- },
75
- role: {
76
- method(type) {
77
- // @ts-ignore
78
- return this.$_addRule({ name: 'type', args: { key: 'role', expected: type } });
79
- },
80
- },
81
- wallet: {
82
- method(type) {
83
- // @ts-ignore
84
- return this.$_addRule({ name: 'wallet', args: { type } });
85
- },
86
- args: [
87
- {
88
- name: 'type',
89
- ref: true,
90
- assert: (v) => ['arcblock', 'ethereum', 'default', 'eth', 'passkey'].includes(v),
91
- message: 'must be a string',
92
- normalize: (v) => v.trim(),
93
- },
94
- ],
95
- validate(value, helpers, args = {}) {
96
- const type = toTypeInfo(value);
97
- const typeStr = toTypeInfoStr(value);
98
- if (['ethereum', 'eth'].includes(args.type) && isEqual(type, DID_TYPE_ETHEREUM) === false) {
99
- return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
100
- }
101
- if (['arcblock', 'default'].includes(args.type) && isEqual(type, DID_TYPE_ARCBLOCK) === false) {
102
- return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
103
- }
104
- if (['passkey'].includes(args.type) && isEqual(type, DID_TYPE_PASSKEY) === false) {
105
- return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
106
- }
107
- return value;
108
- },
109
- },
110
- prefix: {
111
- method(str = '') {
112
- // @ts-ignore
113
- return this.$_addRule({ name: 'prefix', args: { str } });
114
- },
115
- args: [
116
- {
117
- name: 'str',
118
- ref: true,
119
- assert: (v) => ['', DID_PREFIX].includes(v),
120
- message: 'must be a string',
121
- normalize: (v) => v.trim(),
122
- },
123
- ],
124
- validate(value, helpers, args = {}) {
125
- if (args.str && value.startsWith(args.str) === false) {
126
- return helpers.error('did.prefix', { expected: args.str });
127
- }
128
- if (!args.str && toAddress(value) !== value) {
129
- return helpers.error('did.prefix', { expected: args.str });
130
- }
131
- return value;
132
- },
133
- },
134
- },
135
- };
11
+ function DIDExtension(root) {
12
+ return {
13
+ type: "DID",
14
+ base: root.string().trim(),
15
+ messages: {
16
+ "did.empty": "Expect {{#label}} to be non-empty string",
17
+ "did.invalid": "Expect {{#label}} to be valid did",
18
+ "did.wallet": "Expect wallet type of {{#label}} to be \"{{#expected}}\" wallet",
19
+ "did.pk": "Expect pk type of {{#label}} to be \"{{#expected}}\"",
20
+ "did.hash": "Expect hash type of {{#label}} to be \"{{#expected}}\"",
21
+ "did.role": "Expect role type of {{#label}} to be \"{{#expected}}\"",
22
+ "did.prefix": "Expect prefix of {{#label}} to be \"{{#expected}}\""
23
+ },
24
+ validate(value, helpers) {
25
+ if (!value || typeof value !== "string") return { errors: helpers.error("did.empty", { value }) };
26
+ if (isValid(value) === false) return { errors: helpers.error("did.invalid", { value }) };
27
+ return { value };
28
+ },
29
+ rules: {
30
+ type: {
31
+ args: [{
32
+ name: "key",
33
+ ref: true,
34
+ assert: (v) => Object.keys(ruleTypes).includes(v),
35
+ message: `must be one of ${Object.keys(ruleTypes).join(", ")}`
36
+ }, {
37
+ name: "expected",
38
+ assert: (v) => Object.keys(ruleTypes).some((x) => ruleTypes[x].includes(v)),
39
+ message: "must be valid type"
40
+ }],
41
+ validate(value, helpers, args) {
42
+ const typeStr = toTypeInfoStr(value);
43
+ if (args.key === "pk" && typeStr.pk !== args.expected) return helpers.error("did.pk", {
44
+ ...args,
45
+ actual: typeStr.pk
46
+ });
47
+ if (args.key === "hash" && typeStr.hash !== args.expected) return helpers.error("did.hash", {
48
+ ...args,
49
+ actual: typeStr.hash
50
+ });
51
+ if (args.key === "role" && typeStr.role !== args.expected) return helpers.error("did.role", {
52
+ ...args,
53
+ actual: typeStr.role
54
+ });
55
+ return value;
56
+ }
57
+ },
58
+ pk: { method(type) {
59
+ return this.$_addRule({
60
+ name: "type",
61
+ args: {
62
+ key: "pk",
63
+ expected: type
64
+ }
65
+ });
66
+ } },
67
+ hash: { method(type) {
68
+ return this.$_addRule({
69
+ name: "type",
70
+ args: {
71
+ key: "hash",
72
+ expected: type
73
+ }
74
+ });
75
+ } },
76
+ role: { method(type) {
77
+ return this.$_addRule({
78
+ name: "type",
79
+ args: {
80
+ key: "role",
81
+ expected: type
82
+ }
83
+ });
84
+ } },
85
+ wallet: {
86
+ method(type) {
87
+ return this.$_addRule({
88
+ name: "wallet",
89
+ args: { type }
90
+ });
91
+ },
92
+ args: [{
93
+ name: "type",
94
+ ref: true,
95
+ assert: (v) => [
96
+ "arcblock",
97
+ "ethereum",
98
+ "default",
99
+ "eth",
100
+ "passkey"
101
+ ].includes(v),
102
+ message: "must be a string",
103
+ normalize: (v) => v.trim()
104
+ }],
105
+ validate(value, helpers, args = {}) {
106
+ const type = toTypeInfo(value);
107
+ const typeStr = toTypeInfoStr(value);
108
+ if (["ethereum", "eth"].includes(args.type) && isEqual(type, DID_TYPE_ETHEREUM) === false) return helpers.error("did.wallet", {
109
+ expected: args.type,
110
+ actual: JSON.stringify(typeStr)
111
+ });
112
+ if (["arcblock", "default"].includes(args.type) && isEqual(type, DID_TYPE_ARCBLOCK) === false) return helpers.error("did.wallet", {
113
+ expected: args.type,
114
+ actual: JSON.stringify(typeStr)
115
+ });
116
+ if (["passkey"].includes(args.type) && isEqual(type, DID_TYPE_PASSKEY) === false) return helpers.error("did.wallet", {
117
+ expected: args.type,
118
+ actual: JSON.stringify(typeStr)
119
+ });
120
+ return value;
121
+ }
122
+ },
123
+ prefix: {
124
+ method(str = "") {
125
+ return this.$_addRule({
126
+ name: "prefix",
127
+ args: { str }
128
+ });
129
+ },
130
+ args: [{
131
+ name: "str",
132
+ ref: true,
133
+ assert: (v) => ["", DID_PREFIX].includes(v),
134
+ message: "must be a string",
135
+ normalize: (v) => v.trim()
136
+ }],
137
+ validate(value, helpers, args = {}) {
138
+ if (args.str && value.startsWith(args.str) === false) return helpers.error("did.prefix", { expected: args.str });
139
+ if (!args.str && toAddress(value) !== value) return helpers.error("did.prefix", { expected: args.str });
140
+ return value;
141
+ }
142
+ }
143
+ }
144
+ };
136
145
  }
146
+
147
+ //#endregion
148
+ export { DIDExtension };
package/esm/index.d.ts CHANGED
@@ -1,51 +1,55 @@
1
- import BaseJoi, { Root } from 'joi';
2
- import { BNSchema } from './extension/bn';
3
- import { DIDSchema } from './extension/did';
4
- export interface ExtendedRoot extends Root {
5
- DID(): DIDSchema;
6
- BN(): BNSchema;
1
+ import { BNSchema } from "./extension/bn.js";
2
+ import { DIDSchema } from "./extension/did.js";
3
+ import BaseJoi, { Root } from "joi";
4
+
5
+ //#region src/index.d.ts
6
+ interface ExtendedRoot extends Root {
7
+ DID(): DIDSchema;
8
+ BN(): BNSchema;
7
9
  }
8
- export declare const Joi: ExtendedRoot;
9
- export declare const schemas: {
10
- context: BaseJoi.ObjectSchema<any>;
11
- tokenInput: BaseJoi.ObjectSchema<any>;
12
- multiInput: BaseJoi.ArraySchema<any[]>;
13
- multiSig: BaseJoi.ArraySchema<any[]>;
14
- foreignToken: BaseJoi.ObjectSchema<any>;
15
- variableInput: BaseJoi.ObjectSchema<any>;
16
- nftDisplay: BaseJoi.ObjectSchema<any>;
17
- nftEndpoint: BaseJoi.ObjectSchema<any>;
18
- nftIssuer: BaseJoi.ObjectSchema<any>;
19
- tokenHolder: BaseJoi.AlternativesSchema<any>;
20
- assetProps: {
21
- address: DIDSchema;
22
- moniker: BaseJoi.StringSchema<string>;
23
- data: BaseJoi.AnySchema<any>;
24
- readonly: BaseJoi.BooleanSchema<boolean>;
25
- transferrable: BaseJoi.BooleanSchema<boolean>;
26
- ttl: BaseJoi.NumberSchema<number>;
27
- parent: DIDSchema;
28
- issuer: DIDSchema;
29
- endpoint: BaseJoi.ObjectSchema<any>;
30
- display: BaseJoi.ObjectSchema<any>;
31
- tags: BaseJoi.ArraySchema<any[]>;
32
- };
33
- assetSchema: BaseJoi.ObjectSchema<any>;
34
- factoryProps: {
35
- address: DIDSchema;
36
- name: BaseJoi.StringSchema<string>;
37
- description: BaseJoi.StringSchema<string>;
38
- settlement: BaseJoi.StringSchema<string>;
39
- limit: BaseJoi.NumberSchema<number>;
40
- trustedIssuers: BaseJoi.ArraySchema<any[]>;
41
- data: BaseJoi.AnySchema<any>;
42
- display: BaseJoi.ObjectSchema<any>;
43
- input: BaseJoi.ObjectSchema<any>;
44
- output: BaseJoi.ObjectSchema<any>;
45
- hooks: BaseJoi.ArraySchema<any[]>;
46
- };
47
- factorySchema: BaseJoi.ObjectSchema<any>;
10
+ declare const Joi: ExtendedRoot;
11
+ declare const schemas: {
12
+ context: BaseJoi.ObjectSchema<any>;
13
+ tokenInput: BaseJoi.ObjectSchema<any>;
14
+ multiInput: BaseJoi.ArraySchema<any[]>;
15
+ multiSig: BaseJoi.ArraySchema<any[]>;
16
+ foreignToken: BaseJoi.ObjectSchema<any>;
17
+ variableInput: BaseJoi.ObjectSchema<any>;
18
+ nftDisplay: BaseJoi.ObjectSchema<any>;
19
+ nftEndpoint: BaseJoi.ObjectSchema<any>;
20
+ nftIssuer: BaseJoi.ObjectSchema<any>;
21
+ tokenHolder: BaseJoi.AlternativesSchema<any>;
22
+ assetProps: {
23
+ address: DIDSchema;
24
+ moniker: BaseJoi.StringSchema<string>;
25
+ data: BaseJoi.AnySchema<any>;
26
+ readonly: BaseJoi.BooleanSchema<boolean>;
27
+ transferrable: BaseJoi.BooleanSchema<boolean>;
28
+ ttl: BaseJoi.NumberSchema<number>;
29
+ parent: DIDSchema;
30
+ issuer: DIDSchema;
31
+ endpoint: BaseJoi.ObjectSchema<any>;
32
+ display: BaseJoi.ObjectSchema<any>;
33
+ tags: BaseJoi.ArraySchema<any[]>;
34
+ };
35
+ assetSchema: BaseJoi.ObjectSchema<any>;
36
+ factoryProps: {
37
+ address: DIDSchema;
38
+ name: BaseJoi.StringSchema<string>;
39
+ description: BaseJoi.StringSchema<string>;
40
+ settlement: BaseJoi.StringSchema<string>;
41
+ limit: BaseJoi.NumberSchema<number>;
42
+ trustedIssuers: BaseJoi.ArraySchema<any[]>;
43
+ data: BaseJoi.AnySchema<any>;
44
+ display: BaseJoi.ObjectSchema<any>;
45
+ input: BaseJoi.ObjectSchema<any>;
46
+ output: BaseJoi.ObjectSchema<any>;
47
+ hooks: BaseJoi.ArraySchema<any[]>;
48
+ };
49
+ factorySchema: BaseJoi.ObjectSchema<any>;
48
50
  };
49
- export declare const patterns: {
50
- txHash: RegExp;
51
+ declare const patterns: {
52
+ txHash: RegExp;
51
53
  };
54
+ //#endregion
55
+ export { ExtendedRoot, Joi, patterns, schemas };
package/esm/index.js CHANGED
@@ -1,133 +1,139 @@
1
- import BaseJoi from 'joi';
2
- import { BNExtension } from './extension/bn';
3
- import { DIDExtension } from './extension/did';
4
- export const Joi = BaseJoi.extend(DIDExtension).extend(BNExtension);
1
+ import { BNExtension } from "./extension/bn.js";
2
+ import { DIDExtension } from "./extension/did.js";
3
+ import BaseJoi from "joi";
4
+
5
+ //#region src/index.ts
6
+ const Joi = BaseJoi.extend(DIDExtension).extend(BNExtension);
5
7
  const txHash = /^(0x)?([A-Fa-f0-9]{64})$/;
6
8
  const context = Joi.object({
7
- genesisTime: Joi.date().iso().required().raw(),
8
- genesisTx: Joi.string().regex(txHash).required().allow(''),
9
- renaissanceTime: Joi.date().iso().required().raw(),
10
- renaissanceTx: Joi.string().regex(txHash).required().allow(''),
9
+ genesisTime: Joi.date().iso().required().raw(),
10
+ genesisTx: Joi.string().regex(txHash).required().allow(""),
11
+ renaissanceTime: Joi.date().iso().required().raw(),
12
+ renaissanceTx: Joi.string().regex(txHash).required().allow("")
11
13
  });
12
14
  const tokenInput = Joi.object({
13
- address: Joi.DID().prefix().role('ROLE_TOKEN').required(),
14
- value: Joi.BN().min(0).required(),
15
+ address: Joi.DID().prefix().role("ROLE_TOKEN").required(),
16
+ value: Joi.BN().min(0).required()
15
17
  });
16
18
  const variableInput = Joi.object({
17
- name: Joi.string().min(1).max(256).required(),
18
- value: Joi.string().min(1).max(1024).required(),
19
- description: Joi.string().min(1).max(256).optional().allow(''),
20
- required: Joi.boolean().optional().default(false),
19
+ name: Joi.string().min(1).max(256).required(),
20
+ value: Joi.string().min(1).max(1024).required(),
21
+ description: Joi.string().min(1).max(256).optional().allow(""),
22
+ required: Joi.boolean().optional().default(false)
21
23
  });
22
- const tokenHolder = Joi.alternatives().try(Joi.DID().prefix().role('ROLE_ACCOUNT'), Joi.DID().prefix().role('ROLE_APPLICATION'), Joi.DID().prefix().role('ROLE_BLOCKLET'), Joi.DID().prefix().wallet('ethereum'), Joi.DID().prefix().wallet('passkey'));
24
+ const tokenHolder = Joi.alternatives().try(Joi.DID().prefix().role("ROLE_ACCOUNT"), Joi.DID().prefix().role("ROLE_APPLICATION"), Joi.DID().prefix().role("ROLE_BLOCKLET"), Joi.DID().prefix().wallet("ethereum"), Joi.DID().prefix().wallet("passkey"));
23
25
  const multiInput = Joi.array().items(Joi.object({
24
- owner: tokenHolder.required(),
25
- tokensList: Joi.array().items(tokenInput).default([]),
26
- assetsList: Joi.array().items(Joi.DID().prefix().role('ROLE_ASSET')).default([]),
26
+ owner: tokenHolder.required(),
27
+ tokensList: Joi.array().items(tokenInput).default([]),
28
+ assetsList: Joi.array().items(Joi.DID().prefix().role("ROLE_ASSET")).default([])
27
29
  }));
28
30
  const multiSig = Joi.array().items({
29
- signer: Joi.DID().prefix().required(),
30
- pk: Joi.any().required(),
31
- signature: Joi.any().required(),
32
- delegator: Joi.DID().prefix().valid('').optional(),
33
- data: Joi.any().optional(),
31
+ signer: Joi.DID().prefix().required(),
32
+ pk: Joi.any().required(),
33
+ signature: Joi.any().required(),
34
+ delegator: Joi.DID().prefix().valid("").optional(),
35
+ data: Joi.any().optional()
34
36
  });
35
37
  const foreignToken = Joi.object({
36
- type: Joi.string().min(1).max(32).required(),
37
- contractAddress: Joi.DID().prefix().wallet('ethereum').required(),
38
- chainType: Joi.string().min(1).max(32).required(),
39
- chainName: Joi.string().min(1).max(32).required(),
40
- chainId: Joi.number().positive().required(),
38
+ type: Joi.string().min(1).max(32).required(),
39
+ contractAddress: Joi.DID().prefix().wallet("ethereum").required(),
40
+ chainType: Joi.string().min(1).max(32).required(),
41
+ chainName: Joi.string().min(1).max(32).required(),
42
+ chainId: Joi.number().positive().required()
41
43
  });
42
44
  const nftDisplay = Joi.object({
43
- type: Joi.string().valid('svg', 'url', 'uri').required(),
44
- content: Joi.string()
45
- .when('type', { is: 'uri', then: Joi.string().max(20480).dataUri().required() }) // 20kb
46
- .when('type', { is: 'url', then: Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required() }), // prettier-ignore
45
+ type: Joi.string().valid("svg", "url", "uri").required(),
46
+ content: Joi.string().when("type", {
47
+ is: "uri",
48
+ then: Joi.string().max(20480).dataUri().required()
49
+ }).when("type", {
50
+ is: "url",
51
+ then: Joi.string().max(2048).uri({ scheme: ["http", "https"] }).required()
52
+ })
47
53
  });
48
54
  const nftEndpoint = Joi.object({
49
- id: Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required(), // prettier-ignore
50
- scope: Joi.string().valid('public', 'private').default('public'),
55
+ id: Joi.string().max(2048).uri({ scheme: ["http", "https"] }).required(),
56
+ scope: Joi.string().valid("public", "private").default("public")
51
57
  });
52
58
  const nftIssuer = Joi.object({
53
- id: Joi.DID().prefix().required(),
54
- pk: Joi.string().required(),
55
- name: Joi.string().min(1).max(256).required(),
59
+ id: Joi.DID().prefix().required(),
60
+ pk: Joi.string().required(),
61
+ name: Joi.string().min(1).max(256).required()
56
62
  });
57
63
  const assetProps = {
58
- address: Joi.DID().prefix().role('ROLE_ASSET').required(),
59
- moniker: Joi.string().min(2).max(255).required(),
60
- data: Joi.any().required(),
61
- readonly: Joi.boolean().default(false),
62
- transferrable: Joi.boolean().default(false),
63
- ttl: Joi.number().min(0).default(0),
64
- parent: Joi.DID().prefix().optional().allow(''),
65
- issuer: Joi.DID().prefix().optional().allow(''),
66
- endpoint: nftEndpoint.optional().allow(null).default(null),
67
- display: nftDisplay.optional().allow(null).default(null),
68
- tags: Joi.array().items(Joi.string().min(1).max(64)).max(4).optional(),
64
+ address: Joi.DID().prefix().role("ROLE_ASSET").required(),
65
+ moniker: Joi.string().min(2).max(255).required(),
66
+ data: Joi.any().required(),
67
+ readonly: Joi.boolean().default(false),
68
+ transferrable: Joi.boolean().default(false),
69
+ ttl: Joi.number().min(0).default(0),
70
+ parent: Joi.DID().prefix().optional().allow(""),
71
+ issuer: Joi.DID().prefix().optional().allow(""),
72
+ endpoint: nftEndpoint.optional().allow(null).default(null),
73
+ display: nftDisplay.optional().allow(null).default(null),
74
+ tags: Joi.array().items(Joi.string().min(1).max(64)).max(4).optional()
69
75
  };
70
76
  const factoryProps = {
71
- address: Joi.DID().prefix().role('ROLE_FACTORY').required(),
72
- name: Joi.string().min(2).max(255).required(),
73
- description: Joi.string().min(2).max(255).required(),
74
- settlement: Joi.string().valid('instant', 'periodic').default('instant'),
75
- limit: Joi.number().integer().min(0).default(0),
76
- trustedIssuers: Joi.array().items(Joi.DID().prefix()).max(8).optional(),
77
- data: Joi.any().optional().allow(null).default(null),
78
- display: nftDisplay.optional().allow(null).default(null),
79
- input: Joi.object({
80
- value: Joi.BN().positive().min('0').default('0'),
81
- tokens: Joi.array().items(tokenInput).max(8).optional(),
82
- assets: Joi.array()
83
- .items(Joi.alternatives().try(Joi.DID().prefix().role('ROLE_ASSET'), Joi.DID().prefix().role('ROLE_FACTORY')))
84
- .max(8)
85
- .optional(),
86
- variables: Joi.array()
87
- .items(Joi.object({
88
- name: Joi.string().min(1).max(255).required(),
89
- description: Joi.string().max(255).optional().allow(''),
90
- required: Joi.boolean().required(),
91
- }))
92
- .optional(),
93
- }),
94
- output: Joi.object({
95
- moniker: Joi.string().min(2).max(255).required(),
96
- data: Joi.any().required(),
97
- readonly: Joi.boolean().default(false),
98
- transferrable: Joi.boolean().default(false),
99
- ttl: Joi.number().min(0).default(0),
100
- parent: Joi.string().max(255).required(), // should be template
101
- issuer: Joi.string().max(255).required(), // should be template
102
- endpoint: nftEndpoint.optional(),
103
- display: nftDisplay.optional(),
104
- tags: Joi.array().items(Joi.string().min(1).max(64)).max(4).optional(),
105
- }),
106
- hooks: Joi.array()
107
- .items(Joi.object({
108
- name: Joi.string().valid('mint', 'postMint', 'preMint').required(),
109
- type: Joi.string().valid('url', 'contract').required(),
110
- hook: Joi.string().min(1).max(4096).required(), // due to amazon qldb limit, 32 transfers
111
- compiled: Joi.array().items(Joi.object()).optional(),
112
- }))
113
- .optional(),
77
+ address: Joi.DID().prefix().role("ROLE_FACTORY").required(),
78
+ name: Joi.string().min(2).max(255).required(),
79
+ description: Joi.string().min(2).max(255).required(),
80
+ settlement: Joi.string().valid("instant", "periodic").default("instant"),
81
+ limit: Joi.number().integer().min(0).default(0),
82
+ trustedIssuers: Joi.array().items(Joi.DID().prefix()).max(8).optional(),
83
+ data: Joi.any().optional().allow(null).default(null),
84
+ display: nftDisplay.optional().allow(null).default(null),
85
+ input: Joi.object({
86
+ value: Joi.BN().positive().min("0").default("0"),
87
+ tokens: Joi.array().items(tokenInput).max(8).optional(),
88
+ assets: Joi.array().items(Joi.alternatives().try(Joi.DID().prefix().role("ROLE_ASSET"), Joi.DID().prefix().role("ROLE_FACTORY"))).max(8).optional(),
89
+ variables: Joi.array().items(Joi.object({
90
+ name: Joi.string().min(1).max(255).required(),
91
+ description: Joi.string().max(255).optional().allow(""),
92
+ required: Joi.boolean().required()
93
+ })).optional()
94
+ }),
95
+ output: Joi.object({
96
+ moniker: Joi.string().min(2).max(255).required(),
97
+ data: Joi.any().required(),
98
+ readonly: Joi.boolean().default(false),
99
+ transferrable: Joi.boolean().default(false),
100
+ ttl: Joi.number().min(0).default(0),
101
+ parent: Joi.string().max(255).required(),
102
+ issuer: Joi.string().max(255).required(),
103
+ endpoint: nftEndpoint.optional(),
104
+ display: nftDisplay.optional(),
105
+ tags: Joi.array().items(Joi.string().min(1).max(64)).max(4).optional()
106
+ }),
107
+ hooks: Joi.array().items(Joi.object({
108
+ name: Joi.string().valid("mint", "postMint", "preMint").required(),
109
+ type: Joi.string().valid("url", "contract").required(),
110
+ hook: Joi.string().min(1).max(4096).required(),
111
+ compiled: Joi.array().items(Joi.object()).optional()
112
+ })).optional()
114
113
  };
115
- export const schemas = {
116
- context,
117
- tokenInput,
118
- multiInput,
119
- multiSig,
120
- foreignToken,
121
- variableInput,
122
- nftDisplay,
123
- nftEndpoint,
124
- nftIssuer,
125
- tokenHolder,
126
- assetProps,
127
- assetSchema: Joi.object(assetProps).options({ stripUnknown: true, noDefaults: false }),
128
- factoryProps,
129
- factorySchema: Joi.object(factoryProps).options({ stripUnknown: true, noDefaults: false }),
130
- };
131
- export const patterns = {
132
- txHash,
114
+ const schemas = {
115
+ context,
116
+ tokenInput,
117
+ multiInput,
118
+ multiSig,
119
+ foreignToken,
120
+ variableInput,
121
+ nftDisplay,
122
+ nftEndpoint,
123
+ nftIssuer,
124
+ tokenHolder,
125
+ assetProps,
126
+ assetSchema: Joi.object(assetProps).options({
127
+ stripUnknown: true,
128
+ noDefaults: false
129
+ }),
130
+ factoryProps,
131
+ factorySchema: Joi.object(factoryProps).options({
132
+ stripUnknown: true,
133
+ noDefaults: false
134
+ })
133
135
  };
136
+ const patterns = { txHash };
137
+
138
+ //#endregion
139
+ export { Joi, patterns, schemas };