@arcblock/did-connect-js 1.29.27 → 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/authenticator/base.mjs +1 -1
- package/esm/authenticator/wallet.mjs +5 -5
- package/esm/{package.mjs → did/did-connect/package.mjs} +1 -1
- package/esm/handlers/util.mjs +1 -1
- package/esm/handlers/wallet.mjs +1 -1
- package/esm/node_modules/valibot/dist/index.mjs +736 -0
- package/esm/schema/claims.d.mts +11 -13
- package/esm/schema/claims.mjs +194 -132
- package/esm/schema/index.d.mts +24 -4
- package/esm/schema/index.mjs +68 -42
- package/lib/authenticator/base.cjs +1 -1
- package/lib/authenticator/wallet.cjs +5 -4
- package/lib/{package.cjs → did/did-connect/package.cjs} +1 -1
- package/lib/handlers/util.cjs +1 -1
- package/lib/handlers/wallet.cjs +1 -1
- package/lib/node_modules/valibot/dist/index.cjs +756 -0
- package/lib/schema/claims.cjs +193 -131
- package/lib/schema/claims.d.cts +11 -13
- package/lib/schema/index.cjs +68 -41
- package/lib/schema/index.d.cts +24 -4
- package/package.json +9 -9
package/esm/schema/claims.d.mts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { ObjectSchema } from "joi";
|
|
2
|
-
|
|
3
1
|
//#region src/schema/claims.d.ts
|
|
4
2
|
interface ClaimsSchema {
|
|
5
|
-
authPrincipal:
|
|
6
|
-
profile:
|
|
7
|
-
signature:
|
|
8
|
-
prepareTx:
|
|
9
|
-
agreement:
|
|
10
|
-
verifiableCredential:
|
|
11
|
-
asset:
|
|
12
|
-
assetOrVC:
|
|
13
|
-
keyPair:
|
|
14
|
-
encryptionKey:
|
|
3
|
+
authPrincipal: any;
|
|
4
|
+
profile: any;
|
|
5
|
+
signature: any;
|
|
6
|
+
prepareTx: any;
|
|
7
|
+
agreement: any;
|
|
8
|
+
verifiableCredential: any;
|
|
9
|
+
asset: any;
|
|
10
|
+
assetOrVC: any;
|
|
11
|
+
keyPair: any;
|
|
12
|
+
encryptionKey: any;
|
|
15
13
|
}
|
|
16
|
-
declare const _default: (chainInfo:
|
|
14
|
+
declare const _default: (chainInfo: any) => ClaimsSchema;
|
|
17
15
|
//#endregion
|
|
18
16
|
export { ClaimsSchema, _default as default };
|
package/esm/schema/claims.mjs
CHANGED
|
@@ -1,150 +1,212 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { any, array, boolean, check, literal, looseObject, maxValue, minLength, minValue, number, object, optional, picklist, pipe, rawTransform, regex, string, transform, union } from "../node_modules/valibot/dist/index.mjs";
|
|
2
|
+
import { vBNPositive, vDID } from "@arcblock/validator";
|
|
2
3
|
import { types } from "@ocap/mcrypto";
|
|
3
4
|
|
|
4
5
|
//#region src/schema/claims.ts
|
|
5
|
-
const trustedIssuerSchema =
|
|
6
|
-
did:
|
|
7
|
-
endpoint:
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
6
|
+
const trustedIssuerSchema = union([object({
|
|
7
|
+
did: vDID(),
|
|
8
|
+
endpoint: pipe(string(), check((s) => {
|
|
9
|
+
try {
|
|
10
|
+
const url = new URL(s);
|
|
11
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}, "Must be a valid HTTP/HTTPS URL"))
|
|
16
|
+
}), vDID()]);
|
|
17
|
+
const optionalUrlSchema = optional(pipe(string(), check((s) => {
|
|
18
|
+
if (s === "") return true;
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(s);
|
|
21
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
22
|
+
} catch {
|
|
23
|
+
return s.startsWith("/");
|
|
24
|
+
}
|
|
25
|
+
}, "Must be a valid URL")), "");
|
|
26
|
+
const requirementSchema = object({
|
|
27
|
+
tokens: array(object({
|
|
28
|
+
address: vDID(),
|
|
29
|
+
value: vBNPositive()
|
|
30
|
+
})),
|
|
31
|
+
assets: optional(object({
|
|
32
|
+
address: optional(array(vDID())),
|
|
33
|
+
parent: optional(array(vDID())),
|
|
34
|
+
issuer: optional(array(vDID())),
|
|
35
|
+
amount: optional(pipe(number(), check((n) => n > 0, "Must be positive"), minValue(1)))
|
|
36
|
+
}))
|
|
24
37
|
});
|
|
25
|
-
const targetTypeSchema =
|
|
26
|
-
key:
|
|
27
|
-
hash:
|
|
28
|
-
role:
|
|
29
|
-
encoding:
|
|
30
|
-
})
|
|
38
|
+
const targetTypeSchema = optional(object({
|
|
39
|
+
key: optional(picklist(Object.keys(types.KeyType).map((x) => x.toLowerCase())), "ed25519"),
|
|
40
|
+
hash: optional(picklist(Object.keys(types.HashType).map((x) => x.toLowerCase())), "sha3"),
|
|
41
|
+
role: optional(picklist(Object.keys(types.RoleType).map((x) => x.toLowerCase().split("_").pop())), "account"),
|
|
42
|
+
encoding: optional(picklist(Object.keys(types.EncodingType).map((x) => x.toLowerCase())), "base58")
|
|
43
|
+
}));
|
|
31
44
|
var claims_default = (chainInfo) => {
|
|
32
|
-
const options = {
|
|
33
|
-
stripUnknown: true,
|
|
34
|
-
noDefaults: false
|
|
35
|
-
};
|
|
36
45
|
const createStandardFields = (type, description) => ({
|
|
37
|
-
type:
|
|
38
|
-
description:
|
|
39
|
-
chainInfo,
|
|
40
|
-
mfaCode:
|
|
41
|
-
meta:
|
|
46
|
+
type: optional(literal(type), type),
|
|
47
|
+
description: optional(pipe(string(), minLength(1)), description),
|
|
48
|
+
chainInfo: optional(chainInfo),
|
|
49
|
+
mfaCode: optional(array(optional(pipe(number(), minValue(10), maxValue(99)))), []),
|
|
50
|
+
meta: optional(any(), {})
|
|
42
51
|
});
|
|
43
|
-
const authPrincipal =
|
|
52
|
+
const authPrincipal = object({
|
|
44
53
|
...createStandardFields("authPrincipal", "Please continue with your account"),
|
|
45
|
-
target:
|
|
46
|
-
supervised:
|
|
54
|
+
target: optional(union([literal(""), vDID()]), ""),
|
|
55
|
+
supervised: optional(boolean(), false),
|
|
47
56
|
targetType: targetTypeSchema
|
|
48
|
-
})
|
|
49
|
-
const keyPair =
|
|
57
|
+
});
|
|
58
|
+
const keyPair = object({
|
|
50
59
|
...createStandardFields("keyPair", "Please create account to continue."),
|
|
51
|
-
moniker:
|
|
52
|
-
declare:
|
|
53
|
-
migrateFrom:
|
|
60
|
+
moniker: pipe(string(), regex(/^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/)),
|
|
61
|
+
declare: optional(boolean(), true),
|
|
62
|
+
migrateFrom: optional(union([literal(""), vDID()]), ""),
|
|
54
63
|
targetType: targetTypeSchema
|
|
55
|
-
})
|
|
56
|
-
const encryptionKey =
|
|
64
|
+
});
|
|
65
|
+
const encryptionKey = object({
|
|
57
66
|
...createStandardFields("encryptionKey", "Please provide encryptionKey to continue."),
|
|
58
|
-
salt:
|
|
59
|
-
delegation:
|
|
60
|
-
})
|
|
67
|
+
salt: string(),
|
|
68
|
+
delegation: optional(union([literal(""), string()]), "")
|
|
69
|
+
});
|
|
70
|
+
const profileItemValues = [
|
|
71
|
+
"did",
|
|
72
|
+
"fullName",
|
|
73
|
+
"email",
|
|
74
|
+
"phone",
|
|
75
|
+
"signature",
|
|
76
|
+
"avatar",
|
|
77
|
+
"birthday",
|
|
78
|
+
"url"
|
|
79
|
+
];
|
|
80
|
+
const profile = pipe(looseObject({ ...createStandardFields("profile", "Please provide your profile to continue.") }), transform((obj) => {
|
|
81
|
+
const { fields, ...rest } = obj;
|
|
82
|
+
if (fields !== void 0) return {
|
|
83
|
+
...rest,
|
|
84
|
+
items: fields
|
|
85
|
+
};
|
|
86
|
+
return rest;
|
|
87
|
+
}), rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
88
|
+
const obj = dataset.value;
|
|
89
|
+
const items = obj.items ?? ["fullName"];
|
|
90
|
+
if (!Array.isArray(items) || items.length < 1) {
|
|
91
|
+
addIssue({ message: "\"items\" must contain at least 1 items" });
|
|
92
|
+
return NEVER;
|
|
93
|
+
}
|
|
94
|
+
const validSet = new Set(profileItemValues);
|
|
95
|
+
for (let i = 0; i < items.length; i++) if (!validSet.has(items[i])) {
|
|
96
|
+
addIssue({ message: `"items[${i}]" must be one of [${[...profileItemValues].join(", ")}]` });
|
|
97
|
+
return NEVER;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...obj,
|
|
101
|
+
items
|
|
102
|
+
};
|
|
103
|
+
}));
|
|
104
|
+
const signature = object({
|
|
105
|
+
...createStandardFields("signature", "Sign this transaction or message to continue."),
|
|
106
|
+
typeUrl: picklist([
|
|
107
|
+
"fg:x:delegation",
|
|
108
|
+
"fg:t:transaction",
|
|
109
|
+
"mime:text/plain",
|
|
110
|
+
"mime:text/html",
|
|
111
|
+
"eth:transaction",
|
|
112
|
+
"eth:standard-data",
|
|
113
|
+
"eth:personal-data",
|
|
114
|
+
"eth:typed-data",
|
|
115
|
+
"eth:legacy-data"
|
|
116
|
+
]),
|
|
117
|
+
display: optional(union([literal(""), string()]), ""),
|
|
118
|
+
method: optional(picklist(["none", ...Object.keys(types.HashType).map((x) => x.toLowerCase())]), "sha3"),
|
|
119
|
+
digest: optional(union([literal(""), string()]), ""),
|
|
120
|
+
origin: optional(union([literal(""), string()]), ""),
|
|
121
|
+
nonce: optional(union([literal(""), string()]), ""),
|
|
122
|
+
requirement: optional(requirementSchema)
|
|
123
|
+
});
|
|
124
|
+
const prepareTx = object({
|
|
125
|
+
...createStandardFields("prepareTx", "Prepare and sign this transaction to continue."),
|
|
126
|
+
display: optional(union([literal(""), string()]), ""),
|
|
127
|
+
partialTx: string(),
|
|
128
|
+
nonce: optional(union([literal(""), string()]), ""),
|
|
129
|
+
requirement: requirementSchema
|
|
130
|
+
});
|
|
131
|
+
const agreement = object({
|
|
132
|
+
...createStandardFields("agreement", "Confirm your agreement to continue."),
|
|
133
|
+
uri: union([literal(""), pipe(string(), check((s) => {
|
|
134
|
+
try {
|
|
135
|
+
const url = new URL(s);
|
|
136
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
137
|
+
} catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}, "Must be a valid HTTP/HTTPS URL"))]),
|
|
141
|
+
method: optional(picklist(Object.keys(types.HashType).map((x) => x.toLowerCase())), "sha2"),
|
|
142
|
+
digest: string()
|
|
143
|
+
});
|
|
144
|
+
const vcFilterSchema = object({
|
|
145
|
+
type: optional(pipe(array(pipe(string(), minLength(1))), minLength(1))),
|
|
146
|
+
target: optional(vDID()),
|
|
147
|
+
trustedIssuers: optional(pipe(array(trustedIssuerSchema), minLength(1))),
|
|
148
|
+
tag: optional(pipe(string(), check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
149
|
+
ownerDid: optional(array(vDID()), []),
|
|
150
|
+
claimUrl: optionalUrlSchema,
|
|
151
|
+
acquireUrl: optionalUrlSchema
|
|
152
|
+
});
|
|
153
|
+
const verifiableCredential = object({
|
|
154
|
+
...createStandardFields("verifiableCredential", "Please present a verifiable credential to continue."),
|
|
155
|
+
optional: optional(boolean(), false),
|
|
156
|
+
claimUrl: optionalUrlSchema,
|
|
157
|
+
acquireUrl: optionalUrlSchema,
|
|
158
|
+
item: optional(pipe(array(pipe(string(), minLength(1))), minLength(1))),
|
|
159
|
+
target: optional(vDID()),
|
|
160
|
+
trustedIssuers: optional(pipe(array(trustedIssuerSchema), minLength(1))),
|
|
161
|
+
tag: optional(pipe(string(), check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
162
|
+
ownerDid: optional(array(vDID()), []),
|
|
163
|
+
filters: optional(array(vcFilterSchema))
|
|
164
|
+
});
|
|
165
|
+
const assetFilterSchema = object({
|
|
166
|
+
address: optional(vDID()),
|
|
167
|
+
trustedIssuers: optional(pipe(array(trustedIssuerSchema), minLength(1))),
|
|
168
|
+
trustedParents: optional(pipe(array(vDID()), minLength(1))),
|
|
169
|
+
tag: optional(pipe(string(), check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
170
|
+
ownerDid: optional(array(vDID()), []),
|
|
171
|
+
consumed: optional(boolean()),
|
|
172
|
+
acquireUrl: optionalUrlSchema
|
|
173
|
+
});
|
|
174
|
+
const asset = object({
|
|
175
|
+
...createStandardFields("asset", "Please present an on chain asset to continue."),
|
|
176
|
+
optional: optional(boolean(), false),
|
|
177
|
+
address: optional(vDID()),
|
|
178
|
+
trustedIssuers: optional(pipe(array(trustedIssuerSchema), minLength(1))),
|
|
179
|
+
trustedParents: optional(pipe(array(vDID()), minLength(1))),
|
|
180
|
+
tag: optional(pipe(string(), check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
181
|
+
ownerDid: optional(array(vDID()), []),
|
|
182
|
+
consumed: optional(boolean()),
|
|
183
|
+
acquireUrl: optionalUrlSchema,
|
|
184
|
+
filters: optional(array(assetFilterSchema))
|
|
185
|
+
});
|
|
186
|
+
const assetOrVCFilterSchema = object({
|
|
187
|
+
type: optional(pipe(array(pipe(string(), minLength(1))), minLength(1))),
|
|
188
|
+
address: optional(vDID()),
|
|
189
|
+
trustedIssuers: optional(pipe(array(trustedIssuerSchema), minLength(1))),
|
|
190
|
+
trustedParents: optional(pipe(array(vDID()), minLength(1))),
|
|
191
|
+
tag: optional(pipe(string(), check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
192
|
+
ownerDid: optional(array(vDID()), []),
|
|
193
|
+
consumed: optional(boolean()),
|
|
194
|
+
claimUrl: optionalUrlSchema,
|
|
195
|
+
acquireUrl: optionalUrlSchema
|
|
196
|
+
});
|
|
61
197
|
return {
|
|
62
198
|
authPrincipal,
|
|
63
|
-
profile
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
signature: Joi.object({
|
|
71
|
-
...createStandardFields("signature", "Sign this transaction or message to continue."),
|
|
72
|
-
typeUrl: Joi.string().valid("fg:x:delegation", "fg:t:transaction", "mime:text/plain", "mime:text/html", "eth:transaction", "eth:standard-data", "eth:personal-data", "eth:typed-data", "eth:legacy-data").required(),
|
|
73
|
-
display: Joi.string().allow("").default(""),
|
|
74
|
-
method: Joi.string().allow("none", ...Object.keys(types.HashType).map((x) => x.toLowerCase())).optional().default("sha3"),
|
|
75
|
-
digest: Joi.string().allow("").default(""),
|
|
76
|
-
origin: Joi.string().allow("").default(""),
|
|
77
|
-
nonce: Joi.string().allow("").default(""),
|
|
78
|
-
requirement: requirementSchema.optional()
|
|
79
|
-
}).options(options),
|
|
80
|
-
prepareTx: Joi.object({
|
|
81
|
-
...createStandardFields("prepareTx", "Prepare and sign this transaction to continue."),
|
|
82
|
-
display: Joi.string().allow("").default(""),
|
|
83
|
-
partialTx: Joi.string().required(),
|
|
84
|
-
nonce: Joi.string().allow("").default(""),
|
|
85
|
-
requirement: requirementSchema.required()
|
|
86
|
-
}).options(options),
|
|
87
|
-
agreement: Joi.object({
|
|
88
|
-
...createStandardFields("agreement", "Confirm your agreement to continue."),
|
|
89
|
-
uri: Joi.string().uri({ scheme: ["http", "https"] }).required().allow(""),
|
|
90
|
-
method: Joi.string().allow(...Object.keys(types.HashType).map((x) => x.toLowerCase())).optional().default("sha2"),
|
|
91
|
-
digest: Joi.string().required()
|
|
92
|
-
}).options(options),
|
|
93
|
-
verifiableCredential: Joi.object({
|
|
94
|
-
...createStandardFields("verifiableCredential", "Please present a verifiable credential to continue."),
|
|
95
|
-
optional: Joi.boolean().default(false),
|
|
96
|
-
claimUrl: optionalUrlSchema,
|
|
97
|
-
acquireUrl: optionalUrlSchema,
|
|
98
|
-
item: Joi.array().items(Joi.string().min(1).required()).min(1).optional(),
|
|
99
|
-
target: Joi.DID().optional(),
|
|
100
|
-
trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
|
|
101
|
-
tag: Joi.string().min(1).allow("").default(""),
|
|
102
|
-
ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
|
|
103
|
-
filters: Joi.array().items(Joi.object({
|
|
104
|
-
type: Joi.array().items(Joi.string().min(1).required()).min(1).optional(),
|
|
105
|
-
target: Joi.DID().optional(),
|
|
106
|
-
trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
|
|
107
|
-
tag: Joi.string().min(1).allow("").default(""),
|
|
108
|
-
ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
|
|
109
|
-
claimUrl: optionalUrlSchema,
|
|
110
|
-
acquireUrl: optionalUrlSchema
|
|
111
|
-
})).optional()
|
|
112
|
-
}).options(options),
|
|
113
|
-
asset: Joi.object({
|
|
114
|
-
...createStandardFields("asset", "Please present an on chain asset to continue."),
|
|
115
|
-
optional: Joi.boolean().default(false),
|
|
116
|
-
address: Joi.DID().optional(),
|
|
117
|
-
trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
|
|
118
|
-
trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
|
|
119
|
-
tag: Joi.string().min(1).allow("").default(""),
|
|
120
|
-
ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
|
|
121
|
-
consumed: Joi.boolean().optional(),
|
|
122
|
-
acquireUrl: optionalUrlSchema,
|
|
123
|
-
filters: Joi.array().items(Joi.object({
|
|
124
|
-
address: Joi.DID().optional(),
|
|
125
|
-
trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
|
|
126
|
-
trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
|
|
127
|
-
tag: Joi.string().min(1).allow("").default(""),
|
|
128
|
-
ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
|
|
129
|
-
consumed: Joi.boolean().optional(),
|
|
130
|
-
acquireUrl: optionalUrlSchema
|
|
131
|
-
})).optional()
|
|
132
|
-
}).options(options),
|
|
133
|
-
assetOrVC: Joi.object({
|
|
199
|
+
profile,
|
|
200
|
+
signature,
|
|
201
|
+
prepareTx,
|
|
202
|
+
agreement,
|
|
203
|
+
verifiableCredential,
|
|
204
|
+
asset,
|
|
205
|
+
assetOrVC: object({
|
|
134
206
|
...createStandardFields("assetOrVC", "Please present NFT to continue."),
|
|
135
|
-
filters:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
trustedIssuers: Joi.array().items(trustedIssuerSchema).min(1).optional(),
|
|
139
|
-
trustedParents: Joi.array().items(Joi.DID().required()).min(1).optional(),
|
|
140
|
-
tag: Joi.string().min(1).allow("").default(""),
|
|
141
|
-
ownerDid: Joi.array().items(Joi.DID()).optional().default([]),
|
|
142
|
-
consumed: Joi.boolean().optional(),
|
|
143
|
-
claimUrl: optionalUrlSchema,
|
|
144
|
-
acquireUrl: optionalUrlSchema
|
|
145
|
-
})).required().min(1),
|
|
146
|
-
optional: Joi.boolean().default(false)
|
|
147
|
-
}).options(options),
|
|
207
|
+
filters: pipe(array(assetOrVCFilterSchema), minLength(1)),
|
|
208
|
+
optional: optional(boolean(), false)
|
|
209
|
+
}),
|
|
148
210
|
keyPair,
|
|
149
211
|
encryptionKey
|
|
150
212
|
};
|
package/esm/schema/index.d.mts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { ClaimsSchema } from "./claims.mjs";
|
|
2
|
-
import
|
|
2
|
+
import { vValidate } from "@arcblock/validator";
|
|
3
|
+
import * as v from "valibot";
|
|
3
4
|
|
|
4
5
|
//#region src/schema/index.d.ts
|
|
5
|
-
declare const chainInfo:
|
|
6
|
-
|
|
6
|
+
declare const chainInfo: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
7
|
+
readonly type: v.OptionalSchema<v.PicklistSchema<["arcblock", "ethereum", "solona"], undefined>, "arcblock">;
|
|
8
|
+
readonly id: v.OptionalSchema<v.AnySchema, undefined>;
|
|
9
|
+
readonly host: v.OptionalSchema<v.AnySchema, undefined>;
|
|
10
|
+
}, undefined>, v.RawTransformAction<{
|
|
11
|
+
type: "arcblock" | "ethereum" | "solona";
|
|
12
|
+
id?: any;
|
|
13
|
+
host?: any;
|
|
14
|
+
}, any>]>;
|
|
15
|
+
declare const appInfo: v.LooseObjectSchema<{
|
|
16
|
+
readonly name: v.StringSchema<undefined>;
|
|
17
|
+
readonly description: v.StringSchema<undefined>;
|
|
18
|
+
readonly icon: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be a valid HTTP/HTTPS URL">]>;
|
|
19
|
+
readonly link: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be a valid HTTP/HTTPS URL">]>, undefined>;
|
|
20
|
+
readonly path: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "Must be a valid HTTP/HTTPS URL">]>, "https://abtwallet.io/i/">;
|
|
21
|
+
readonly publisher: v.OptionalSchema<any, undefined>;
|
|
22
|
+
readonly updateSubEndpoint: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
23
|
+
readonly subscriptionEndpoint: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
24
|
+
readonly nodeDid: v.OptionalSchema<any, undefined>;
|
|
25
|
+
readonly agentDid: v.OptionalSchema<any, undefined>;
|
|
26
|
+
}, undefined>;
|
|
7
27
|
declare const claims: ClaimsSchema;
|
|
8
28
|
//#endregion
|
|
9
|
-
export { appInfo, chainInfo, claims };
|
|
29
|
+
export { appInfo, chainInfo, claims, vValidate };
|
package/esm/schema/index.mjs
CHANGED
|
@@ -1,49 +1,75 @@
|
|
|
1
|
+
import { any, boolean, check, literal, looseObject, object, optional, picklist, pipe, rawTransform, regex, safeParse, string } from "../node_modules/valibot/dist/index.mjs";
|
|
1
2
|
import claims_default from "./claims.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { vDID, vValidate } from "@arcblock/validator";
|
|
3
4
|
|
|
4
5
|
//#region src/schema/index.ts
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
6
|
+
const isHttpUrl = (s) => {
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(s);
|
|
9
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const chainInfo = pipe(object({
|
|
15
|
+
type: optional(picklist([
|
|
16
|
+
"arcblock",
|
|
17
|
+
"ethereum",
|
|
18
|
+
"solona"
|
|
19
|
+
]), "arcblock"),
|
|
20
|
+
id: optional(any()),
|
|
21
|
+
host: optional(any())
|
|
22
|
+
}), rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
23
|
+
const obj = dataset.value;
|
|
24
|
+
let typeSchema;
|
|
25
|
+
switch (obj.type) {
|
|
26
|
+
case "arcblock":
|
|
27
|
+
typeSchema = object({
|
|
28
|
+
type: literal("arcblock"),
|
|
29
|
+
id: optional(string(), "none"),
|
|
30
|
+
host: optional(pipe(string(), check((s) => s === "none" || isHttpUrl(s), "must be a valid uri with a scheme matching the http|https pattern")), "none")
|
|
31
|
+
});
|
|
32
|
+
break;
|
|
33
|
+
case "ethereum":
|
|
34
|
+
typeSchema = object({
|
|
35
|
+
type: literal("ethereum"),
|
|
36
|
+
id: pipe(string(), regex(/^[0-9]+$/, "fails to match the numbers pattern")),
|
|
37
|
+
host: optional(string())
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
case "solona":
|
|
41
|
+
typeSchema = object({
|
|
42
|
+
type: literal("solona"),
|
|
43
|
+
id: pipe(string(), regex(/^[0-9]+$/, "fails to match the numbers pattern")),
|
|
44
|
+
host: optional(string())
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const result = safeParse(typeSchema, obj);
|
|
49
|
+
if (!result.success) {
|
|
50
|
+
for (const issue of result.issues) addIssue({
|
|
51
|
+
message: issue.message,
|
|
52
|
+
path: issue.path
|
|
53
|
+
});
|
|
54
|
+
return NEVER;
|
|
55
|
+
}
|
|
56
|
+
const output = {};
|
|
57
|
+
for (const [k, val] of Object.entries(result.output)) if (val !== void 0) output[k] = val;
|
|
58
|
+
return output;
|
|
59
|
+
}));
|
|
60
|
+
const appInfo = looseObject({
|
|
61
|
+
name: string(),
|
|
62
|
+
description: string(),
|
|
63
|
+
icon: pipe(string(), check(isHttpUrl, "Must be a valid HTTP/HTTPS URL")),
|
|
64
|
+
link: optional(pipe(string(), check(isHttpUrl, "Must be a valid HTTP/HTTPS URL"))),
|
|
65
|
+
path: optional(pipe(string(), check(isHttpUrl, "Must be a valid HTTP/HTTPS URL")), "https://abtwallet.io/i/"),
|
|
66
|
+
publisher: optional(vDID()),
|
|
67
|
+
updateSubEndpoint: optional(boolean()),
|
|
68
|
+
subscriptionEndpoint: optional(string()),
|
|
69
|
+
nodeDid: optional(vDID()),
|
|
70
|
+
agentDid: optional(vDID())
|
|
45
71
|
});
|
|
46
72
|
const claims = claims_default(chainInfo);
|
|
47
73
|
|
|
48
74
|
//#endregion
|
|
49
|
-
export { appInfo, chainInfo, claims };
|
|
75
|
+
export { appInfo, chainInfo, claims, vValidate };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
-
const require_package$1 = require('../package.cjs');
|
|
3
|
+
const require_package$1 = require('../did/did-connect/package.cjs');
|
|
4
4
|
let _ocap_wallet = require("@ocap/wallet");
|
|
5
5
|
let _arcblock_jwt = require("@arcblock/jwt");
|
|
6
6
|
_arcblock_jwt = require_rolldown_runtime.__toESM(_arcblock_jwt);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
-
const require_package$1 = require('../package.cjs');
|
|
3
|
+
const require_package$1 = require('../did/did-connect/package.cjs');
|
|
4
4
|
const require_authenticator_base = require('./base.cjs');
|
|
5
5
|
const require_schema_index = require('../schema/index.cjs');
|
|
6
6
|
let node_querystring = require("node:querystring");
|
|
@@ -20,6 +20,7 @@ let lodash_random = require("lodash/random");
|
|
|
20
20
|
lodash_random = require_rolldown_runtime.__toESM(lodash_random);
|
|
21
21
|
let lodash_shuffle = require("lodash/shuffle");
|
|
22
22
|
lodash_shuffle = require_rolldown_runtime.__toESM(lodash_shuffle);
|
|
23
|
+
let _arcblock_validator = require("@arcblock/validator");
|
|
23
24
|
|
|
24
25
|
//#region src/authenticator/wallet.ts
|
|
25
26
|
const debug = require("debug")(`${require_package$1.default.name}:authenticator:wallet`);
|
|
@@ -369,7 +370,7 @@ var WalletAuthenticator = class WalletAuthenticator extends require_authenticato
|
|
|
369
370
|
}
|
|
370
371
|
result.mfaCode = (0, lodash_shuffle.default)(result.mfaCode);
|
|
371
372
|
}
|
|
372
|
-
const { value, error } = require_schema_index.claims[name]
|
|
373
|
+
const { value, error } = (0, _arcblock_validator.vValidate)(require_schema_index.claims[name], result);
|
|
373
374
|
if (error) throw new Error(`Invalid ${name} claim: ${error.message}`);
|
|
374
375
|
return value;
|
|
375
376
|
}));
|
|
@@ -528,12 +529,12 @@ var WalletAuthenticator = class WalletAuthenticator extends require_authenticato
|
|
|
528
529
|
if (allowEmpty === false) throw new Error("Wallet authenticator can not work with invalid appInfo: empty");
|
|
529
530
|
return null;
|
|
530
531
|
}
|
|
531
|
-
const { value, error } = require_schema_index.appInfo
|
|
532
|
+
const { value, error } = (0, _arcblock_validator.vValidate)(require_schema_index.appInfo, info);
|
|
532
533
|
if (error) throw new Error(`Wallet authenticator can not work with invalid appInfo: ${error.message}`);
|
|
533
534
|
return value;
|
|
534
535
|
}
|
|
535
536
|
_isValidChainInfo(x) {
|
|
536
|
-
const { error } = require_schema_index.chainInfo
|
|
537
|
+
const { error } = (0, _arcblock_validator.vValidate)(require_schema_index.chainInfo, x);
|
|
537
538
|
return !error;
|
|
538
539
|
}
|
|
539
540
|
tryWithTimeout(asyncFn, label = "") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
|
|
3
3
|
//#region package.json
|
|
4
4
|
var require_package = /* @__PURE__ */ require_rolldown_runtime.__commonJSMin(((exports, module) => {
|
package/lib/handlers/util.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
-
const require_package$1 = require('../package.cjs');
|
|
3
|
+
const require_package$1 = require('../did/did-connect/package.cjs');
|
|
4
4
|
const require_protocol = require('../protocol.cjs');
|
|
5
5
|
let _arcblock_did = require("@arcblock/did");
|
|
6
6
|
let _ocap_util = require("@ocap/util");
|
package/lib/handlers/wallet.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const require_package$1 = require('../package.cjs');
|
|
2
|
+
const require_package$1 = require('../did/did-connect/package.cjs');
|
|
3
3
|
const require_adapters_detect = require('../adapters/detect.cjs');
|
|
4
4
|
const require_adapters_express = require('../adapters/express.cjs');
|
|
5
5
|
const require_adapters_hono = require('../adapters/hono.cjs');
|