@arcblock/validator 1.29.26 → 1.30.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.
- package/esm/index.d.mts +7 -49
- package/esm/index.mjs +7 -135
- package/esm/v/bn.d.mts +16 -0
- package/esm/v/bn.mjs +54 -0
- package/esm/v/did.d.mts +14 -0
- package/esm/v/did.mjs +41 -0
- package/esm/v/helpers.d.mts +15 -0
- package/esm/v/helpers.mjs +61 -0
- package/esm/v/index.d.mts +6 -0
- package/esm/v/index.mjs +8 -0
- package/esm/v/schemas.d.mts +245 -0
- package/esm/v/schemas.mjs +194 -0
- package/lib/index.cjs +31 -137
- package/lib/index.d.cts +6 -49
- package/lib/v/bn.cjs +67 -0
- package/lib/v/bn.d.cts +16 -0
- package/lib/v/did.cjs +43 -0
- package/lib/v/did.d.cts +14 -0
- package/lib/v/helpers.cjs +67 -0
- package/lib/v/helpers.d.cts +15 -0
- package/lib/v/index.cjs +30 -0
- package/lib/v/index.d.cts +6 -0
- package/lib/v/schemas.cjs +196 -0
- package/lib/v/schemas.d.cts +245 -0
- package/package.json +5 -6
- package/esm/extension/bn.d.mts +0 -100
- package/esm/extension/bn.mjs +0 -140
- package/esm/extension/did.d.mts +0 -81
- package/esm/extension/did.mjs +0 -155
- package/lib/extension/bn.cjs +0 -142
- package/lib/extension/bn.d.cts +0 -100
- package/lib/extension/did.cjs +0 -157
- package/lib/extension/did.d.cts +0 -81
package/esm/extension/did.mjs
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { DID_TYPE_ARCBLOCK, DID_TYPE_ETHEREUM, DID_TYPE_PASSKEY, isKnownDid, toAddress, toTypeInfo, toTypeInfoStr } from "@arcblock/did";
|
|
2
|
-
import { types } from "@ocap/mcrypto";
|
|
3
|
-
import isEqual from "lodash/isEqual.js";
|
|
4
|
-
|
|
5
|
-
//#region src/extension/did.ts
|
|
6
|
-
const ruleTypes = {
|
|
7
|
-
pk: Object.keys(types.KeyType),
|
|
8
|
-
hash: Object.keys(types.HashType),
|
|
9
|
-
role: Object.keys(types.RoleType)
|
|
10
|
-
};
|
|
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 (isKnownDid(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) => [
|
|
134
|
-
"",
|
|
135
|
-
"did:abt:",
|
|
136
|
-
"did:afs:",
|
|
137
|
-
"did:aos:",
|
|
138
|
-
"did:spaces:",
|
|
139
|
-
"did:name:"
|
|
140
|
-
].includes(v),
|
|
141
|
-
message: "must be a string",
|
|
142
|
-
normalize: (v) => v.trim()
|
|
143
|
-
}],
|
|
144
|
-
validate(value, helpers, args = {}) {
|
|
145
|
-
if (args.str && value.startsWith(args.str) === false) return helpers.error("did.prefix", { expected: args.str });
|
|
146
|
-
if (!args.str && toAddress(value) !== value) return helpers.error("did.prefix", { expected: args.str });
|
|
147
|
-
return value;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
export { DIDExtension };
|
package/lib/extension/bn.cjs
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let bn_js = require("bn.js");
|
|
3
|
-
bn_js = require_rolldown_runtime.__toESM(bn_js);
|
|
4
|
-
|
|
5
|
-
//#region src/extension/bn.ts
|
|
6
|
-
function BNExtension(root) {
|
|
7
|
-
return {
|
|
8
|
-
type: "BN",
|
|
9
|
-
base: root.any(),
|
|
10
|
-
messages: {
|
|
11
|
-
"bn.nan": "{{#label}} is not a big number",
|
|
12
|
-
"bn.max": "{{#label}} needs to be less than or equal to \"{{#threshold}}\"",
|
|
13
|
-
"bn.min": "{{#label}} needs to be greater than or equal to \"{{#threshold}}\"",
|
|
14
|
-
"bn.less": "{{#label}} needs to be less than \"{{#threshold}}\"",
|
|
15
|
-
"bn.greater": "{{#label}} needs to be greater than \"{{#threshold}}\"",
|
|
16
|
-
"bn.positive": "{{#label}} needs to be positive",
|
|
17
|
-
"bn.negative": "{{#label}} needs to be negative"
|
|
18
|
-
},
|
|
19
|
-
prepare(value, helpers) {
|
|
20
|
-
try {
|
|
21
|
-
return { value: new bn_js.default(value) };
|
|
22
|
-
} catch (_err) {
|
|
23
|
-
return { errors: helpers.error("bn.nan") };
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
coerce(value) {
|
|
27
|
-
return { value: value.toString(10) };
|
|
28
|
-
},
|
|
29
|
-
validate(value) {
|
|
30
|
-
return { value };
|
|
31
|
-
},
|
|
32
|
-
rules: {
|
|
33
|
-
gt: {
|
|
34
|
-
args: [{
|
|
35
|
-
name: "threshold",
|
|
36
|
-
ref: true,
|
|
37
|
-
assert: (v) => bn_js.default.isBN(v),
|
|
38
|
-
message: "must be a big number",
|
|
39
|
-
normalize: (v) => new bn_js.default(v)
|
|
40
|
-
}, {
|
|
41
|
-
name: "equal",
|
|
42
|
-
assert: (v) => typeof v === "boolean",
|
|
43
|
-
message: "must be a boolean"
|
|
44
|
-
}],
|
|
45
|
-
validate(value, helpers, args) {
|
|
46
|
-
const v = new bn_js.default(value);
|
|
47
|
-
if (args.equal && v.lt(args.threshold)) return helpers.error("bn.min", args);
|
|
48
|
-
if (!args.equal && v.lte(args.threshold)) return helpers.error("bn.greater", args);
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
lt: {
|
|
53
|
-
args: [{
|
|
54
|
-
name: "threshold",
|
|
55
|
-
ref: true,
|
|
56
|
-
assert: (v) => bn_js.default.isBN(v),
|
|
57
|
-
message: "must be a big number",
|
|
58
|
-
normalize: (v) => new bn_js.default(v)
|
|
59
|
-
}, {
|
|
60
|
-
name: "equal",
|
|
61
|
-
assert: (v) => typeof v === "boolean",
|
|
62
|
-
message: "must be a boolean"
|
|
63
|
-
}],
|
|
64
|
-
validate(value, helpers, args) {
|
|
65
|
-
const v = new bn_js.default(value);
|
|
66
|
-
if (args.equal && v.gt(args.threshold)) return helpers.error("bn.max", args);
|
|
67
|
-
if (!args.equal && v.gte(args.threshold)) return helpers.error("bn.less", args);
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
min: {
|
|
72
|
-
alias: "gte",
|
|
73
|
-
method(threshold) {
|
|
74
|
-
return this.$_addRule({
|
|
75
|
-
name: "gt",
|
|
76
|
-
args: {
|
|
77
|
-
threshold,
|
|
78
|
-
equal: true
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
max: {
|
|
84
|
-
alias: "lte",
|
|
85
|
-
method(threshold) {
|
|
86
|
-
return this.$_addRule({
|
|
87
|
-
name: "lt",
|
|
88
|
-
args: {
|
|
89
|
-
threshold,
|
|
90
|
-
equal: true
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
greater: {
|
|
96
|
-
alias: "gt",
|
|
97
|
-
method(threshold) {
|
|
98
|
-
return this.$_addRule({
|
|
99
|
-
name: "gt",
|
|
100
|
-
args: {
|
|
101
|
-
threshold,
|
|
102
|
-
equal: false
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
less: {
|
|
108
|
-
alias: "lt",
|
|
109
|
-
method(threshold) {
|
|
110
|
-
return this.$_addRule({
|
|
111
|
-
name: "lt",
|
|
112
|
-
args: {
|
|
113
|
-
threshold,
|
|
114
|
-
equal: false
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
positive: { method() {
|
|
120
|
-
return this.$_addRule({
|
|
121
|
-
name: "gt",
|
|
122
|
-
args: {
|
|
123
|
-
threshold: 0,
|
|
124
|
-
equal: false
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
} },
|
|
128
|
-
negative: { method() {
|
|
129
|
-
return this.$_addRule({
|
|
130
|
-
name: "lt",
|
|
131
|
-
args: {
|
|
132
|
-
threshold: 0,
|
|
133
|
-
equal: false
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
} }
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
//#endregion
|
|
142
|
-
exports.BNExtension = BNExtension;
|
package/lib/extension/bn.d.cts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
|
-
import { AnySchema, Root } from "joi";
|
|
3
|
-
|
|
4
|
-
//#region src/extension/bn.d.ts
|
|
5
|
-
interface BNSchema extends AnySchema {
|
|
6
|
-
min(threshold: any): this;
|
|
7
|
-
gte(threshold: any): this;
|
|
8
|
-
max(threshold: any): this;
|
|
9
|
-
lte(threshold: any): this;
|
|
10
|
-
greater(threshold: any): this;
|
|
11
|
-
gt(threshold: any): this;
|
|
12
|
-
less(threshold: any): this;
|
|
13
|
-
lt(threshold: any): this;
|
|
14
|
-
positive(): this;
|
|
15
|
-
negative(): this;
|
|
16
|
-
}
|
|
17
|
-
declare function BNExtension(root: Root): {
|
|
18
|
-
type: string;
|
|
19
|
-
base: AnySchema<any>;
|
|
20
|
-
messages: {
|
|
21
|
-
'bn.nan': string;
|
|
22
|
-
'bn.max': string;
|
|
23
|
-
'bn.min': string;
|
|
24
|
-
'bn.less': string;
|
|
25
|
-
'bn.greater': string;
|
|
26
|
-
'bn.positive': string;
|
|
27
|
-
'bn.negative': string;
|
|
28
|
-
};
|
|
29
|
-
prepare(value: any, helpers: any): {
|
|
30
|
-
value: BN;
|
|
31
|
-
errors?: undefined;
|
|
32
|
-
} | {
|
|
33
|
-
errors: any;
|
|
34
|
-
value?: undefined;
|
|
35
|
-
};
|
|
36
|
-
coerce(value: BN): {
|
|
37
|
-
value: string;
|
|
38
|
-
};
|
|
39
|
-
validate(value: any): {
|
|
40
|
-
value: any;
|
|
41
|
-
};
|
|
42
|
-
rules: {
|
|
43
|
-
gt: {
|
|
44
|
-
args: ({
|
|
45
|
-
name: string;
|
|
46
|
-
ref: boolean;
|
|
47
|
-
assert: (v: any) => v is BN;
|
|
48
|
-
message: string;
|
|
49
|
-
normalize: (v: any) => BN;
|
|
50
|
-
} | {
|
|
51
|
-
name: string;
|
|
52
|
-
assert: (v: any) => v is boolean;
|
|
53
|
-
message: string;
|
|
54
|
-
ref?: undefined;
|
|
55
|
-
normalize?: undefined;
|
|
56
|
-
})[];
|
|
57
|
-
validate(value: any, helpers: any, args: any): any;
|
|
58
|
-
};
|
|
59
|
-
lt: {
|
|
60
|
-
args: ({
|
|
61
|
-
name: string;
|
|
62
|
-
ref: boolean;
|
|
63
|
-
assert: (v: any) => v is BN;
|
|
64
|
-
message: string;
|
|
65
|
-
normalize: (v: any) => BN;
|
|
66
|
-
} | {
|
|
67
|
-
name: string;
|
|
68
|
-
assert: (v: any) => v is boolean;
|
|
69
|
-
message: string;
|
|
70
|
-
ref?: undefined;
|
|
71
|
-
normalize?: undefined;
|
|
72
|
-
})[];
|
|
73
|
-
validate(value: any, helpers: any, args: any): any;
|
|
74
|
-
};
|
|
75
|
-
min: {
|
|
76
|
-
alias: string;
|
|
77
|
-
method(threshold: any): BNSchema;
|
|
78
|
-
};
|
|
79
|
-
max: {
|
|
80
|
-
alias: string;
|
|
81
|
-
method(threshold: any): BNSchema;
|
|
82
|
-
};
|
|
83
|
-
greater: {
|
|
84
|
-
alias: string;
|
|
85
|
-
method(threshold: any): BNSchema;
|
|
86
|
-
};
|
|
87
|
-
less: {
|
|
88
|
-
alias: string;
|
|
89
|
-
method(threshold: any): BNSchema;
|
|
90
|
-
};
|
|
91
|
-
positive: {
|
|
92
|
-
method(): BNSchema;
|
|
93
|
-
};
|
|
94
|
-
negative: {
|
|
95
|
-
method(): BNSchema;
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
//#endregion
|
|
100
|
-
export { BNExtension, BNSchema };
|
package/lib/extension/did.cjs
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let _arcblock_did = require("@arcblock/did");
|
|
3
|
-
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
4
|
-
let lodash_isEqual = require("lodash/isEqual");
|
|
5
|
-
lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
6
|
-
|
|
7
|
-
//#region src/extension/did.ts
|
|
8
|
-
const ruleTypes = {
|
|
9
|
-
pk: Object.keys(_ocap_mcrypto.types.KeyType),
|
|
10
|
-
hash: Object.keys(_ocap_mcrypto.types.HashType),
|
|
11
|
-
role: Object.keys(_ocap_mcrypto.types.RoleType)
|
|
12
|
-
};
|
|
13
|
-
function DIDExtension(root) {
|
|
14
|
-
return {
|
|
15
|
-
type: "DID",
|
|
16
|
-
base: root.string().trim(),
|
|
17
|
-
messages: {
|
|
18
|
-
"did.empty": "Expect {{#label}} to be non-empty string",
|
|
19
|
-
"did.invalid": "Expect {{#label}} to be valid did",
|
|
20
|
-
"did.wallet": "Expect wallet type of {{#label}} to be \"{{#expected}}\" wallet",
|
|
21
|
-
"did.pk": "Expect pk type of {{#label}} to be \"{{#expected}}\"",
|
|
22
|
-
"did.hash": "Expect hash type of {{#label}} to be \"{{#expected}}\"",
|
|
23
|
-
"did.role": "Expect role type of {{#label}} to be \"{{#expected}}\"",
|
|
24
|
-
"did.prefix": "Expect prefix of {{#label}} to be \"{{#expected}}\""
|
|
25
|
-
},
|
|
26
|
-
validate(value, helpers) {
|
|
27
|
-
if (!value || typeof value !== "string") return { errors: helpers.error("did.empty", { value }) };
|
|
28
|
-
if ((0, _arcblock_did.isKnownDid)(value) === false) return { errors: helpers.error("did.invalid", { value }) };
|
|
29
|
-
return { value };
|
|
30
|
-
},
|
|
31
|
-
rules: {
|
|
32
|
-
type: {
|
|
33
|
-
args: [{
|
|
34
|
-
name: "key",
|
|
35
|
-
ref: true,
|
|
36
|
-
assert: (v) => Object.keys(ruleTypes).includes(v),
|
|
37
|
-
message: `must be one of ${Object.keys(ruleTypes).join(", ")}`
|
|
38
|
-
}, {
|
|
39
|
-
name: "expected",
|
|
40
|
-
assert: (v) => Object.keys(ruleTypes).some((x) => ruleTypes[x].includes(v)),
|
|
41
|
-
message: "must be valid type"
|
|
42
|
-
}],
|
|
43
|
-
validate(value, helpers, args) {
|
|
44
|
-
const typeStr = (0, _arcblock_did.toTypeInfoStr)(value);
|
|
45
|
-
if (args.key === "pk" && typeStr.pk !== args.expected) return helpers.error("did.pk", {
|
|
46
|
-
...args,
|
|
47
|
-
actual: typeStr.pk
|
|
48
|
-
});
|
|
49
|
-
if (args.key === "hash" && typeStr.hash !== args.expected) return helpers.error("did.hash", {
|
|
50
|
-
...args,
|
|
51
|
-
actual: typeStr.hash
|
|
52
|
-
});
|
|
53
|
-
if (args.key === "role" && typeStr.role !== args.expected) return helpers.error("did.role", {
|
|
54
|
-
...args,
|
|
55
|
-
actual: typeStr.role
|
|
56
|
-
});
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
pk: { method(type) {
|
|
61
|
-
return this.$_addRule({
|
|
62
|
-
name: "type",
|
|
63
|
-
args: {
|
|
64
|
-
key: "pk",
|
|
65
|
-
expected: type
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
} },
|
|
69
|
-
hash: { method(type) {
|
|
70
|
-
return this.$_addRule({
|
|
71
|
-
name: "type",
|
|
72
|
-
args: {
|
|
73
|
-
key: "hash",
|
|
74
|
-
expected: type
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
} },
|
|
78
|
-
role: { method(type) {
|
|
79
|
-
return this.$_addRule({
|
|
80
|
-
name: "type",
|
|
81
|
-
args: {
|
|
82
|
-
key: "role",
|
|
83
|
-
expected: type
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
} },
|
|
87
|
-
wallet: {
|
|
88
|
-
method(type) {
|
|
89
|
-
return this.$_addRule({
|
|
90
|
-
name: "wallet",
|
|
91
|
-
args: { type }
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
args: [{
|
|
95
|
-
name: "type",
|
|
96
|
-
ref: true,
|
|
97
|
-
assert: (v) => [
|
|
98
|
-
"arcblock",
|
|
99
|
-
"ethereum",
|
|
100
|
-
"default",
|
|
101
|
-
"eth",
|
|
102
|
-
"passkey"
|
|
103
|
-
].includes(v),
|
|
104
|
-
message: "must be a string",
|
|
105
|
-
normalize: (v) => v.trim()
|
|
106
|
-
}],
|
|
107
|
-
validate(value, helpers, args = {}) {
|
|
108
|
-
const type = (0, _arcblock_did.toTypeInfo)(value);
|
|
109
|
-
const typeStr = (0, _arcblock_did.toTypeInfoStr)(value);
|
|
110
|
-
if (["ethereum", "eth"].includes(args.type) && (0, lodash_isEqual.default)(type, _arcblock_did.DID_TYPE_ETHEREUM) === false) return helpers.error("did.wallet", {
|
|
111
|
-
expected: args.type,
|
|
112
|
-
actual: JSON.stringify(typeStr)
|
|
113
|
-
});
|
|
114
|
-
if (["arcblock", "default"].includes(args.type) && (0, lodash_isEqual.default)(type, _arcblock_did.DID_TYPE_ARCBLOCK) === false) return helpers.error("did.wallet", {
|
|
115
|
-
expected: args.type,
|
|
116
|
-
actual: JSON.stringify(typeStr)
|
|
117
|
-
});
|
|
118
|
-
if (["passkey"].includes(args.type) && (0, lodash_isEqual.default)(type, _arcblock_did.DID_TYPE_PASSKEY) === false) return helpers.error("did.wallet", {
|
|
119
|
-
expected: args.type,
|
|
120
|
-
actual: JSON.stringify(typeStr)
|
|
121
|
-
});
|
|
122
|
-
return value;
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
prefix: {
|
|
126
|
-
method(str = "") {
|
|
127
|
-
return this.$_addRule({
|
|
128
|
-
name: "prefix",
|
|
129
|
-
args: { str }
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
args: [{
|
|
133
|
-
name: "str",
|
|
134
|
-
ref: true,
|
|
135
|
-
assert: (v) => [
|
|
136
|
-
"",
|
|
137
|
-
"did:abt:",
|
|
138
|
-
"did:afs:",
|
|
139
|
-
"did:aos:",
|
|
140
|
-
"did:spaces:",
|
|
141
|
-
"did:name:"
|
|
142
|
-
].includes(v),
|
|
143
|
-
message: "must be a string",
|
|
144
|
-
normalize: (v) => v.trim()
|
|
145
|
-
}],
|
|
146
|
-
validate(value, helpers, args = {}) {
|
|
147
|
-
if (args.str && value.startsWith(args.str) === false) return helpers.error("did.prefix", { expected: args.str });
|
|
148
|
-
if (!args.str && (0, _arcblock_did.toAddress)(value) !== value) return helpers.error("did.prefix", { expected: args.str });
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
exports.DIDExtension = DIDExtension;
|
package/lib/extension/did.d.cts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Root, StringSchema } from "joi";
|
|
2
|
-
import { DIDTypeShortcut } from "@arcblock/did";
|
|
3
|
-
import { HashType, KeyType, RoleType } from "@ocap/mcrypto";
|
|
4
|
-
|
|
5
|
-
//#region src/extension/did.d.ts
|
|
6
|
-
interface DIDSchema extends StringSchema {
|
|
7
|
-
wallet(type: DIDTypeShortcut): this;
|
|
8
|
-
pk(type: KeyType): this;
|
|
9
|
-
hash(type: HashType): this;
|
|
10
|
-
role(type: RoleType): this;
|
|
11
|
-
prefix(str?: string): this;
|
|
12
|
-
}
|
|
13
|
-
declare function DIDExtension(root: Root): {
|
|
14
|
-
type: string;
|
|
15
|
-
base: StringSchema<string>;
|
|
16
|
-
messages: {
|
|
17
|
-
'did.empty': string;
|
|
18
|
-
'did.invalid': string;
|
|
19
|
-
'did.wallet': string;
|
|
20
|
-
'did.pk': string;
|
|
21
|
-
'did.hash': string;
|
|
22
|
-
'did.role': string;
|
|
23
|
-
'did.prefix': string;
|
|
24
|
-
};
|
|
25
|
-
validate(value: any, helpers: any): {
|
|
26
|
-
errors: any;
|
|
27
|
-
value?: undefined;
|
|
28
|
-
} | {
|
|
29
|
-
value: string;
|
|
30
|
-
errors?: undefined;
|
|
31
|
-
};
|
|
32
|
-
rules: {
|
|
33
|
-
type: {
|
|
34
|
-
args: ({
|
|
35
|
-
name: string;
|
|
36
|
-
ref: boolean;
|
|
37
|
-
assert: (v: string) => boolean;
|
|
38
|
-
message: string;
|
|
39
|
-
} | {
|
|
40
|
-
name: string;
|
|
41
|
-
assert: (v: string) => boolean;
|
|
42
|
-
message: string;
|
|
43
|
-
ref?: undefined;
|
|
44
|
-
})[];
|
|
45
|
-
validate(value: string, helpers: any, args: any): any;
|
|
46
|
-
};
|
|
47
|
-
pk: {
|
|
48
|
-
method(type: KeyType): DIDSchema;
|
|
49
|
-
};
|
|
50
|
-
hash: {
|
|
51
|
-
method(type: HashType): DIDSchema;
|
|
52
|
-
};
|
|
53
|
-
role: {
|
|
54
|
-
method(type: RoleType): DIDSchema;
|
|
55
|
-
};
|
|
56
|
-
wallet: {
|
|
57
|
-
method(type: DIDTypeShortcut): DIDSchema;
|
|
58
|
-
args: {
|
|
59
|
-
name: string;
|
|
60
|
-
ref: boolean;
|
|
61
|
-
assert: (v: any) => boolean;
|
|
62
|
-
message: string;
|
|
63
|
-
normalize: (v: any) => any;
|
|
64
|
-
}[];
|
|
65
|
-
validate(value: any, helpers: any, args?: any): any;
|
|
66
|
-
};
|
|
67
|
-
prefix: {
|
|
68
|
-
method(str?: string): DIDSchema;
|
|
69
|
-
args: {
|
|
70
|
-
name: string;
|
|
71
|
-
ref: boolean;
|
|
72
|
-
assert: (v: any) => boolean;
|
|
73
|
-
message: string;
|
|
74
|
-
normalize: (v: any) => any;
|
|
75
|
-
}[];
|
|
76
|
-
validate(value: any, helpers: any, args?: any): any;
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
//#endregion
|
|
81
|
-
export { DIDExtension, DIDSchema };
|