@arcblock/validator 1.18.166 → 1.19.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.
@@ -0,0 +1,96 @@
1
+ import { Root, AnySchema } from 'joi';
2
+ import BN from 'bn.js';
3
+ export interface BNSchema extends AnySchema {
4
+ min(threshold: any): this;
5
+ gte(threshold: any): this;
6
+ max(threshold: any): this;
7
+ lte(threshold: any): this;
8
+ greater(threshold: any): this;
9
+ gt(threshold: any): this;
10
+ less(threshold: any): this;
11
+ lt(threshold: any): this;
12
+ positive(): this;
13
+ negative(): this;
14
+ }
15
+ export declare function BNExtension(root: Root): {
16
+ type: string;
17
+ base: AnySchema<any>;
18
+ messages: {
19
+ 'bn.nan': string;
20
+ 'bn.max': string;
21
+ 'bn.min': string;
22
+ 'bn.less': string;
23
+ 'bn.greater': string;
24
+ 'bn.positive': string;
25
+ 'bn.negative': string;
26
+ };
27
+ prepare(value: any, helpers: any): {
28
+ value: BN;
29
+ errors?: undefined;
30
+ } | {
31
+ errors: any;
32
+ value?: undefined;
33
+ };
34
+ coerce(value: BN): {
35
+ value: string;
36
+ };
37
+ validate(value: any): {
38
+ value: any;
39
+ };
40
+ rules: {
41
+ gt: {
42
+ args: ({
43
+ name: string;
44
+ ref: boolean;
45
+ assert: (v: any) => v is BN;
46
+ message: string;
47
+ normalize: (v: any) => BN;
48
+ } | {
49
+ name: string;
50
+ assert: (v: any) => v is boolean;
51
+ message: string;
52
+ ref?: undefined;
53
+ normalize?: undefined;
54
+ })[];
55
+ validate(value: any, helpers: any, args: any): any;
56
+ };
57
+ lt: {
58
+ args: ({
59
+ name: string;
60
+ ref: boolean;
61
+ assert: (v: any) => v is BN;
62
+ message: string;
63
+ normalize: (v: any) => BN;
64
+ } | {
65
+ name: string;
66
+ assert: (v: any) => v is boolean;
67
+ message: string;
68
+ ref?: undefined;
69
+ normalize?: undefined;
70
+ })[];
71
+ validate(value: any, helpers: any, args: any): any;
72
+ };
73
+ min: {
74
+ alias: string;
75
+ method(threshold: any): BNSchema;
76
+ };
77
+ max: {
78
+ alias: string;
79
+ method(threshold: any): BNSchema;
80
+ };
81
+ greater: {
82
+ alias: string;
83
+ method(threshold: any): BNSchema;
84
+ };
85
+ less: {
86
+ alias: string;
87
+ method(threshold: any): BNSchema;
88
+ };
89
+ positive: {
90
+ method(): BNSchema;
91
+ };
92
+ negative: {
93
+ method(): BNSchema;
94
+ };
95
+ };
96
+ };
@@ -0,0 +1,130 @@
1
+ import BN from 'bn.js';
2
+ export function BNExtension(root) {
3
+ return {
4
+ type: 'BN',
5
+ base: root.any(),
6
+ messages: {
7
+ 'bn.nan': '{{#label}} is not a big number',
8
+ 'bn.max': '{{#label}} needs to be less than or equal to "{{#threshold}}"',
9
+ 'bn.min': '{{#label}} needs to be greater than or equal to "{{#threshold}}"',
10
+ 'bn.less': '{{#label}} needs to be less than "{{#threshold}}"',
11
+ 'bn.greater': '{{#label}} needs to be greater than "{{#threshold}}"',
12
+ 'bn.positive': '{{#label}} needs to be positive',
13
+ 'bn.negative': '{{#label}} needs to be negative',
14
+ },
15
+ prepare(value, helpers) {
16
+ try {
17
+ return { value: new BN(value) };
18
+ }
19
+ catch (err) {
20
+ return { errors: helpers.error('bn.nan') };
21
+ }
22
+ },
23
+ coerce(value) {
24
+ return { value: value.toString(10) };
25
+ },
26
+ validate(value) {
27
+ return { value };
28
+ },
29
+ rules: {
30
+ gt: {
31
+ args: [
32
+ {
33
+ name: 'threshold',
34
+ ref: true,
35
+ assert: (v) => BN.isBN(v),
36
+ message: 'must be a big number',
37
+ normalize: (v) => new BN(v),
38
+ },
39
+ {
40
+ name: 'equal',
41
+ assert: (v) => typeof v === 'boolean',
42
+ message: 'must be a boolean',
43
+ },
44
+ ],
45
+ // The rule return structure is different from the root
46
+ // eslint-disable-next-line consistent-return
47
+ validate(value, helpers, args) {
48
+ const v = new BN(value);
49
+ if (args.equal && v.lt(args.threshold)) {
50
+ return helpers.error('bn.min', args);
51
+ }
52
+ if (!args.equal && v.lte(args.threshold)) {
53
+ return helpers.error('bn.greater', args);
54
+ }
55
+ // must return value when valid
56
+ return value;
57
+ },
58
+ },
59
+ lt: {
60
+ args: [
61
+ {
62
+ name: 'threshold',
63
+ ref: true,
64
+ assert: (v) => BN.isBN(v),
65
+ message: 'must be a big number',
66
+ normalize: (v) => new BN(v),
67
+ },
68
+ {
69
+ name: 'equal',
70
+ assert: (v) => typeof v === 'boolean',
71
+ message: 'must be a boolean',
72
+ },
73
+ ],
74
+ // The rule return structure is different from the root
75
+ // eslint-disable-next-line consistent-return
76
+ validate(value, helpers, args) {
77
+ const v = new BN(value);
78
+ if (args.equal && v.gt(args.threshold)) {
79
+ return helpers.error('bn.max', args);
80
+ }
81
+ if (!args.equal && v.gte(args.threshold)) {
82
+ return helpers.error('bn.less', args);
83
+ }
84
+ // must return value when valid
85
+ return value;
86
+ },
87
+ },
88
+ min: {
89
+ alias: 'gte',
90
+ method(threshold) {
91
+ // @ts-ignore
92
+ return this.$_addRule({ name: 'gt', args: { threshold, equal: true } });
93
+ },
94
+ },
95
+ max: {
96
+ alias: 'lte',
97
+ method(threshold) {
98
+ // @ts-ignore
99
+ return this.$_addRule({ name: 'lt', args: { threshold, equal: true } });
100
+ },
101
+ },
102
+ greater: {
103
+ alias: 'gt',
104
+ method(threshold) {
105
+ // @ts-ignore
106
+ return this.$_addRule({ name: 'gt', args: { threshold, equal: false } });
107
+ },
108
+ },
109
+ less: {
110
+ alias: 'lt',
111
+ method(threshold) {
112
+ // @ts-ignore
113
+ return this.$_addRule({ name: 'lt', args: { threshold, equal: false } });
114
+ },
115
+ },
116
+ positive: {
117
+ method() {
118
+ // @ts-ignore
119
+ return this.$_addRule({ name: 'gt', args: { threshold: 0, equal: false } });
120
+ },
121
+ },
122
+ negative: {
123
+ method() {
124
+ // @ts-ignore
125
+ return this.$_addRule({ name: 'lt', args: { threshold: 0, equal: false } });
126
+ },
127
+ },
128
+ },
129
+ };
130
+ }
@@ -0,0 +1,77 @@
1
+ import { Root, StringSchema } from 'joi';
2
+ import { KeyType, HashType, RoleType } from '@ocap/mcrypto';
3
+ import { DIDTypeShortcut } from '@arcblock/did';
4
+ export interface DIDSchema extends StringSchema {
5
+ wallet(type: DIDTypeShortcut): this;
6
+ pk(type: KeyType): this;
7
+ hash(type: HashType): this;
8
+ role(type: RoleType): this;
9
+ prefix(str?: string): this;
10
+ }
11
+ export declare function DIDExtension(root: Root): {
12
+ type: string;
13
+ base: StringSchema<string>;
14
+ messages: {
15
+ 'did.empty': string;
16
+ 'did.invalid': string;
17
+ 'did.wallet': string;
18
+ 'did.pk': string;
19
+ 'did.hash': string;
20
+ 'did.role': string;
21
+ 'did.prefix': string;
22
+ };
23
+ validate(value: any, helpers: any): {
24
+ errors: any;
25
+ value?: undefined;
26
+ } | {
27
+ value: string;
28
+ errors?: undefined;
29
+ };
30
+ rules: {
31
+ type: {
32
+ args: ({
33
+ name: string;
34
+ ref: boolean;
35
+ assert: (v: string) => boolean;
36
+ message: string;
37
+ } | {
38
+ name: string;
39
+ assert: (v: string) => boolean;
40
+ message: string;
41
+ ref?: undefined;
42
+ })[];
43
+ validate(value: string, helpers: any, args: any): any;
44
+ };
45
+ pk: {
46
+ method(type: KeyType): DIDSchema;
47
+ };
48
+ hash: {
49
+ method(type: HashType): DIDSchema;
50
+ };
51
+ role: {
52
+ method(type: RoleType): DIDSchema;
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
+ };
76
+ };
77
+ };
@@ -0,0 +1,136 @@
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';
4
+ const ruleTypes = {
5
+ pk: Object.keys(types.KeyType),
6
+ hash: Object.keys(types.HashType),
7
+ role: Object.keys(types.RoleType),
8
+ };
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, got "{{#value}}"',
15
+ 'did.invalid': 'Expect {{#label}} to be valid did, got "{{#value}}"',
16
+ 'did.wallet': 'Expect wallet type of {{#label}} to be "{{#expected}}" wallet, got "{{#actual}}"',
17
+ 'did.pk': 'Expect pk type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
18
+ 'did.hash': 'Expect hash type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
19
+ 'did.role': 'Expect role type of {{#label}} to be "{{#expected}}", got "{{#actual}}"',
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
+ };
136
+ }
package/esm/index.d.ts ADDED
@@ -0,0 +1,51 @@
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;
7
+ }
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>;
48
+ };
49
+ export declare const patterns: {
50
+ txHash: RegExp;
51
+ };
package/esm/index.js ADDED
@@ -0,0 +1,133 @@
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);
5
+ const txHash = /^(0x)?([A-Fa-f0-9]{64})$/;
6
+ 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(''),
11
+ });
12
+ const tokenInput = Joi.object({
13
+ address: Joi.DID().prefix().role('ROLE_TOKEN').required(),
14
+ value: Joi.BN().positive().required(),
15
+ });
16
+ 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),
21
+ });
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'));
23
+ 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([]),
27
+ }));
28
+ 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(),
34
+ });
35
+ 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(),
41
+ });
42
+ 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
47
+ });
48
+ 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'),
51
+ });
52
+ const nftIssuer = Joi.object({
53
+ id: Joi.DID().prefix().required(),
54
+ pk: Joi.string().required(),
55
+ name: Joi.string().min(1).max(256).required(),
56
+ });
57
+ 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(),
69
+ };
70
+ 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(),
114
+ };
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,
133
+ };
@@ -42,12 +42,12 @@ export declare function BNExtension(root: Root): {
42
42
  args: ({
43
43
  name: string;
44
44
  ref: boolean;
45
- assert: (v: any) => boolean;
45
+ assert: (v: any) => v is BN;
46
46
  message: string;
47
47
  normalize: (v: any) => BN;
48
48
  } | {
49
49
  name: string;
50
- assert: (v: any) => boolean;
50
+ assert: (v: any) => v is boolean;
51
51
  message: string;
52
52
  ref?: undefined;
53
53
  normalize?: undefined;
@@ -58,12 +58,12 @@ export declare function BNExtension(root: Root): {
58
58
  args: ({
59
59
  name: string;
60
60
  ref: boolean;
61
- assert: (v: any) => boolean;
61
+ assert: (v: any) => v is BN;
62
62
  message: string;
63
63
  normalize: (v: any) => BN;
64
64
  } | {
65
65
  name: string;
66
- assert: (v: any) => boolean;
66
+ assert: (v: any) => v is boolean;
67
67
  message: string;
68
68
  ref?: undefined;
69
69
  normalize?: undefined;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BNExtension = void 0;
6
+ exports.BNExtension = BNExtension;
7
7
  const bn_js_1 = __importDefault(require("bn.js"));
8
8
  function BNExtension(root) {
9
9
  return {
@@ -134,4 +134,3 @@ function BNExtension(root) {
134
134
  },
135
135
  };
136
136
  }
137
- exports.BNExtension = BNExtension;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DIDExtension = void 0;
6
+ exports.DIDExtension = DIDExtension;
7
7
  const isEqual_1 = __importDefault(require("lodash/isEqual"));
8
8
  const mcrypto_1 = require("@ocap/mcrypto");
9
9
  const did_1 = require("@arcblock/did");
@@ -93,7 +93,7 @@ function DIDExtension(root) {
93
93
  {
94
94
  name: 'type',
95
95
  ref: true,
96
- assert: (v) => ['arcblock', 'ethereum', 'default', 'eth'].includes(v),
96
+ assert: (v) => ['arcblock', 'ethereum', 'default', 'eth', 'passkey'].includes(v),
97
97
  message: 'must be a string',
98
98
  normalize: (v) => v.trim(),
99
99
  },
@@ -107,6 +107,9 @@ function DIDExtension(root) {
107
107
  if (['arcblock', 'default'].includes(args.type) && (0, isEqual_1.default)(type, did_1.DID_TYPE_ARCBLOCK) === false) {
108
108
  return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
109
109
  }
110
+ if (['passkey'].includes(args.type) && (0, isEqual_1.default)(type, did_1.DID_TYPE_PASSKEY) === false) {
111
+ return helpers.error('did.wallet', { expected: args.type, actual: JSON.stringify(typeStr) });
112
+ }
110
113
  return value;
111
114
  },
112
115
  },
@@ -137,4 +140,3 @@ function DIDExtension(root) {
137
140
  },
138
141
  };
139
142
  }
140
- exports.DIDExtension = DIDExtension;
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ const variableInput = exports.Joi.object({
25
25
  description: exports.Joi.string().min(1).max(256).optional().allow(''),
26
26
  required: exports.Joi.boolean().optional().default(false),
27
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().role('ROLE_BLOCKLET'), exports.Joi.DID().prefix().wallet('ethereum'));
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().role('ROLE_BLOCKLET'), exports.Joi.DID().prefix().wallet('ethereum'), exports.Joi.DID().prefix().wallet('passkey'));
29
29
  const multiInput = exports.Joi.array().items(exports.Joi.object({
30
30
  owner: tokenHolder.required(),
31
31
  tokensList: exports.Joi.array().items(tokenInput).default([]),
@@ -52,7 +52,7 @@ const nftDisplay = exports.Joi.object({
52
52
  .when('type', { is: 'url', then: exports.Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required() }), // prettier-ignore
53
53
  });
54
54
  const nftEndpoint = exports.Joi.object({
55
- id: exports.Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required(),
55
+ id: exports.Joi.string().max(2048).uri({ scheme: ['http', 'https'] }).required(), // prettier-ignore
56
56
  scope: exports.Joi.string().valid('public', 'private').default('public'),
57
57
  });
58
58
  const nftIssuer = exports.Joi.object({
@@ -103,8 +103,8 @@ const factoryProps = {
103
103
  readonly: exports.Joi.boolean().default(false),
104
104
  transferrable: exports.Joi.boolean().default(false),
105
105
  ttl: exports.Joi.number().min(0).default(0),
106
- parent: exports.Joi.string().max(255).required(),
107
- issuer: exports.Joi.string().max(255).required(),
106
+ parent: exports.Joi.string().max(255).required(), // should be template
107
+ issuer: exports.Joi.string().max(255).required(), // should be template
108
108
  endpoint: nftEndpoint.optional(),
109
109
  display: nftDisplay.optional(),
110
110
  tags: exports.Joi.array().items(exports.Joi.string().min(1).max(64)).max(4).optional(),
@@ -113,7 +113,7 @@ const factoryProps = {
113
113
  .items(exports.Joi.object({
114
114
  name: exports.Joi.string().valid('mint', 'postMint', 'preMint').required(),
115
115
  type: exports.Joi.string().valid('url', 'contract').required(),
116
- hook: exports.Joi.string().min(1).max(4096).required(),
116
+ hook: exports.Joi.string().min(1).max(4096).required(), // due to amazon qldb limit, 32 transfers
117
117
  compiled: exports.Joi.array().items(exports.Joi.object()).optional(),
118
118
  }))
119
119
  .optional(),
package/package.json CHANGED
@@ -3,27 +3,38 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.166",
6
+ "version": "1.19.0",
7
7
  "description": "",
8
- "main": "lib/index.js",
9
- "typings": "lib/index.d.ts",
8
+ "main": "./lib/index.js",
9
+ "module": "./lib/index.js",
10
+ "types": "./esm/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./esm/index.js",
14
+ "require": "./lib/index.js",
15
+ "default": "./esm/index.js"
16
+ }
17
+ },
10
18
  "files": [
11
- "lib"
19
+ "lib",
20
+ "esm"
12
21
  ],
13
22
  "scripts": {
14
23
  "lint": "eslint tests src",
15
24
  "lint:fix": "eslint --fix tests src",
16
25
  "test": "jest --forceExit --detectOpenHandles",
17
26
  "coverage": "npm run test -- --coverage",
18
- "clean": "rm -fr lib",
27
+ "clean": "rm -fr lib esm",
19
28
  "prebuild": "npm run clean",
20
29
  "build:watch": "npm run build -- -w",
21
- "build": "tsc"
30
+ "build:cjs": "tsc -p tsconfig.cjs.json",
31
+ "build:esm": "tsc -p tsconfig.esm.json",
32
+ "build": "npm run build:cjs && npm run build:esm"
22
33
  },
23
34
  "dependencies": {
24
- "@arcblock/did": "1.18.166",
25
- "@ocap/mcrypto": "1.18.166",
26
- "@ocap/util": "1.18.166",
35
+ "@arcblock/did": "1.19.0",
36
+ "@ocap/mcrypto": "1.19.0",
37
+ "@ocap/util": "1.19.0",
27
38
  "bn.js": "5.2.1",
28
39
  "joi": "^17.7.0",
29
40
  "lodash": "^4.17.21"
@@ -32,15 +43,15 @@
32
43
  "bn.js": "5.2.1"
33
44
  },
34
45
  "devDependencies": {
35
- "@arcblock/eslint-config-ts": "0.2.3",
36
- "eslint": "^8.25.0",
46
+ "@arcblock/eslint-config-ts": "0.3.3",
47
+ "eslint": "^8.57.0",
37
48
  "jest": "^29.7.0",
38
49
  "ts-jest": "^29.2.5",
39
50
  "type-fest": "^3.1.0",
40
- "typescript": "^4.8.4"
51
+ "typescript": "^5.6.2"
41
52
  },
42
53
  "keywords": [],
43
54
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
44
55
  "license": "MIT",
45
- "gitHead": "58c8356b3b8c238728560e4c3fef6ed1704d3ac4"
56
+ "gitHead": "1b6fac03988fb18507c8ef4c21de282762005f87"
46
57
  }