@arcblock/validator 1.27.16 → 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.
- package/esm/extension/bn.d.ts +93 -89
- package/esm/extension/bn.js +139 -129
- package/esm/extension/did.d.ts +76 -72
- package/esm/extension/did.js +145 -133
- package/esm/index.d.ts +52 -48
- package/esm/index.js +115 -109
- package/esm/lodash.d.ts +2 -0
- package/lib/_virtual/rolldown_runtime.js +29 -0
- package/lib/extension/bn.d.ts +93 -89
- package/lib/extension/bn.js +140 -134
- package/lib/extension/did.d.ts +76 -72
- package/lib/extension/did.js +146 -138
- package/lib/index.d.ts +52 -48
- package/lib/index.js +128 -124
- package/lib/lodash.d.d.ts +0 -0
- package/lib/lodash.d.ts +2 -0
- package/package.json +22 -11
package/lib/extension/did.js
CHANGED
|
@@ -1,142 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const mcrypto_1 = require("@ocap/mcrypto");
|
|
9
|
-
const did_1 = require("@arcblock/did");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
let lodash_isEqual = require("lodash/isEqual");
|
|
3
|
+
lodash_isEqual = require_rolldown_runtime.__toESM(lodash_isEqual);
|
|
4
|
+
let _ocap_mcrypto = require("@ocap/mcrypto");
|
|
5
|
+
let _arcblock_did = require("@arcblock/did");
|
|
6
|
+
|
|
7
|
+
//#region src/extension/did.ts
|
|
10
8
|
const ruleTypes = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
pk: Object.keys(_ocap_mcrypto.types.KeyType),
|
|
10
|
+
hash: Object.keys(_ocap_mcrypto.types.HashType),
|
|
11
|
+
role: Object.keys(_ocap_mcrypto.types.RoleType)
|
|
14
12
|
};
|
|
15
13
|
function DIDExtension(root) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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.isValid)(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) => ["", _arcblock_did.DID_PREFIX].includes(v),
|
|
136
|
+
message: "must be a string",
|
|
137
|
+
normalize: (v) => v.trim()
|
|
138
|
+
}],
|
|
139
|
+
validate(value, helpers, args = {}) {
|
|
140
|
+
if (args.str && value.startsWith(args.str) === false) return helpers.error("did.prefix", { expected: args.str });
|
|
141
|
+
if (!args.str && (0, _arcblock_did.toAddress)(value) !== value) return helpers.error("did.prefix", { expected: args.str });
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
142
147
|
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
exports.DIDExtension = DIDExtension;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
+
declare const patterns: {
|
|
52
|
+
txHash: RegExp;
|
|
51
53
|
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ExtendedRoot, Joi, patterns, schemas };
|