@arcblock/did-connect-js 4.0.1 → 4.0.3
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/dist/index.cjs +2472 -0
- package/dist/schema/index.cjs +413 -0
- package/dist/storage/kv.cjs +74 -0
- package/package.json +10 -6
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/schema/index.ts
|
|
31
|
+
var schema_exports = {};
|
|
32
|
+
__export(schema_exports, {
|
|
33
|
+
appInfo: () => appInfo,
|
|
34
|
+
chainInfo: () => chainInfo,
|
|
35
|
+
claims: () => claims
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(schema_exports);
|
|
38
|
+
var import_validator2 = require("@arcblock/validator");
|
|
39
|
+
var v2 = __toESM(require("valibot"), 1);
|
|
40
|
+
|
|
41
|
+
// src/schema/claims.ts
|
|
42
|
+
var import_validator = require("@arcblock/validator");
|
|
43
|
+
var import_mcrypto = require("@ocap/mcrypto");
|
|
44
|
+
var v = __toESM(require("valibot"), 1);
|
|
45
|
+
var isHttpUrl = (s) => {
|
|
46
|
+
try {
|
|
47
|
+
const url = new URL(s);
|
|
48
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var trustedIssuerSchema = v.union([
|
|
54
|
+
v.object({
|
|
55
|
+
did: (0, import_validator.vDID)(),
|
|
56
|
+
endpoint: v.pipe(v.string(), v.check(isHttpUrl, "Must be a valid HTTP/HTTPS URL"))
|
|
57
|
+
}),
|
|
58
|
+
(0, import_validator.vDID)()
|
|
59
|
+
]);
|
|
60
|
+
var optionalUrlSchema = v.optional(
|
|
61
|
+
v.pipe(
|
|
62
|
+
v.string(),
|
|
63
|
+
v.check((s) => {
|
|
64
|
+
if (s === "") return true;
|
|
65
|
+
try {
|
|
66
|
+
const url = new URL(s);
|
|
67
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
68
|
+
} catch {
|
|
69
|
+
return s.startsWith("/");
|
|
70
|
+
}
|
|
71
|
+
}, "Must be a valid URL")
|
|
72
|
+
),
|
|
73
|
+
""
|
|
74
|
+
);
|
|
75
|
+
var requirementSchema = v.object({
|
|
76
|
+
tokens: v.array(
|
|
77
|
+
v.object({
|
|
78
|
+
address: (0, import_validator.vDID)(),
|
|
79
|
+
value: (0, import_validator.vBNPositive)()
|
|
80
|
+
})
|
|
81
|
+
),
|
|
82
|
+
assets: v.optional(
|
|
83
|
+
v.object({
|
|
84
|
+
address: v.optional(v.array((0, import_validator.vDID)())),
|
|
85
|
+
parent: v.optional(v.array((0, import_validator.vDID)())),
|
|
86
|
+
issuer: v.optional(v.array((0, import_validator.vDID)())),
|
|
87
|
+
amount: v.optional(v.pipe(v.number(), v.check((n) => n > 0, "Must be positive"), v.minValue(1)))
|
|
88
|
+
})
|
|
89
|
+
)
|
|
90
|
+
});
|
|
91
|
+
var targetTypeSchema = v.optional(
|
|
92
|
+
v.object({
|
|
93
|
+
key: v.optional(
|
|
94
|
+
v.picklist(Object.keys(import_mcrypto.types.KeyType).map((x) => x.toLowerCase())),
|
|
95
|
+
"ed25519"
|
|
96
|
+
),
|
|
97
|
+
hash: v.optional(
|
|
98
|
+
v.picklist(Object.keys(import_mcrypto.types.HashType).map((x) => x.toLowerCase())),
|
|
99
|
+
"sha3"
|
|
100
|
+
),
|
|
101
|
+
role: v.optional(
|
|
102
|
+
v.picklist(Object.keys(import_mcrypto.types.RoleType).map((x) => x.toLowerCase().split("_").pop())),
|
|
103
|
+
"account"
|
|
104
|
+
),
|
|
105
|
+
encoding: v.optional(
|
|
106
|
+
v.picklist(Object.keys(import_mcrypto.types.EncodingType).map((x) => x.toLowerCase())),
|
|
107
|
+
"base58"
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
function withValidate(schema) {
|
|
112
|
+
return Object.assign(schema, {
|
|
113
|
+
validate: (data) => {
|
|
114
|
+
const { value, error } = (0, import_validator.vValidate)(schema, data);
|
|
115
|
+
if (error) error.toString = () => error.message;
|
|
116
|
+
return { value, error };
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
var profileItemValues = ["did", "fullName", "email", "phone", "signature", "avatar", "birthday", "url"];
|
|
121
|
+
var claims_default = (chainInfo2) => {
|
|
122
|
+
const createStandardFields = (type, description) => ({
|
|
123
|
+
type: v.optional(v.literal(type), type),
|
|
124
|
+
description: v.optional(v.pipe(v.string(), v.minLength(1)), description),
|
|
125
|
+
chainInfo: v.optional(chainInfo2),
|
|
126
|
+
mfaCode: v.optional(v.array(v.optional(v.pipe(v.number(), v.minValue(10), v.maxValue(99)))), []),
|
|
127
|
+
meta: v.optional(v.any(), {})
|
|
128
|
+
});
|
|
129
|
+
const authPrincipal = withValidate(
|
|
130
|
+
v.object({
|
|
131
|
+
...createStandardFields("authPrincipal", "Please continue with your account"),
|
|
132
|
+
target: v.optional(v.union([v.literal(""), (0, import_validator.vDID)()]), ""),
|
|
133
|
+
supervised: v.optional(v.boolean(), false),
|
|
134
|
+
targetType: targetTypeSchema
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
const keyPair = withValidate(
|
|
138
|
+
v.object({
|
|
139
|
+
...createStandardFields("keyPair", "Please create account to continue."),
|
|
140
|
+
moniker: v.pipe(v.string(), v.regex(/^[a-zA-Z0-9][-a-zA-Z0-9_]{2,128}$/)),
|
|
141
|
+
declare: v.optional(v.boolean(), true),
|
|
142
|
+
migrateFrom: v.optional(v.union([v.literal(""), (0, import_validator.vDID)()]), ""),
|
|
143
|
+
targetType: targetTypeSchema
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
const encryptionKey = withValidate(
|
|
147
|
+
v.object({
|
|
148
|
+
...createStandardFields("encryptionKey", "Please provide encryptionKey to continue."),
|
|
149
|
+
salt: v.string(),
|
|
150
|
+
delegation: v.optional(v.union([v.literal(""), v.string()]), "")
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
const profile = withValidate(
|
|
154
|
+
v.pipe(
|
|
155
|
+
v.looseObject({
|
|
156
|
+
...createStandardFields("profile", "Please provide your profile to continue.")
|
|
157
|
+
}),
|
|
158
|
+
// Rename fields → items (ignoreUndefined: true, override: true)
|
|
159
|
+
v.transform((obj) => {
|
|
160
|
+
const { fields, ...rest } = obj;
|
|
161
|
+
if (fields !== void 0) {
|
|
162
|
+
return { ...rest, items: fields };
|
|
163
|
+
}
|
|
164
|
+
return rest;
|
|
165
|
+
}),
|
|
166
|
+
v.rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
167
|
+
const obj = dataset.value;
|
|
168
|
+
const items = obj.items ?? ["fullName"];
|
|
169
|
+
if (!Array.isArray(items) || items.length < 1) {
|
|
170
|
+
addIssue({ message: '"items" must contain at least 1 items' });
|
|
171
|
+
return NEVER;
|
|
172
|
+
}
|
|
173
|
+
const validSet = new Set(profileItemValues);
|
|
174
|
+
for (let i = 0; i < items.length; i++) {
|
|
175
|
+
if (!validSet.has(items[i])) {
|
|
176
|
+
addIssue({
|
|
177
|
+
message: `"items[${i}]" must be one of [${[...profileItemValues].join(", ")}]`
|
|
178
|
+
});
|
|
179
|
+
return NEVER;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { ...obj, items };
|
|
183
|
+
})
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
const signature = withValidate(
|
|
187
|
+
v.object({
|
|
188
|
+
...createStandardFields("signature", "Sign this transaction or message to continue."),
|
|
189
|
+
typeUrl: v.picklist([
|
|
190
|
+
"fg:x:delegation",
|
|
191
|
+
"fg:t:transaction",
|
|
192
|
+
"mime:text/plain",
|
|
193
|
+
"mime:text/html",
|
|
194
|
+
"eth:transaction",
|
|
195
|
+
"eth:standard-data",
|
|
196
|
+
"eth:personal-data",
|
|
197
|
+
"eth:typed-data",
|
|
198
|
+
"eth:legacy-data"
|
|
199
|
+
]),
|
|
200
|
+
display: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
201
|
+
method: v.optional(
|
|
202
|
+
v.picklist(["none", ...Object.keys(import_mcrypto.types.HashType).map((x) => x.toLowerCase())]),
|
|
203
|
+
"sha3"
|
|
204
|
+
),
|
|
205
|
+
digest: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
206
|
+
origin: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
207
|
+
nonce: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
208
|
+
requirement: v.optional(requirementSchema)
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
const prepareTx = withValidate(
|
|
212
|
+
v.object({
|
|
213
|
+
...createStandardFields("prepareTx", "Prepare and sign this transaction to continue."),
|
|
214
|
+
display: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
215
|
+
partialTx: v.string(),
|
|
216
|
+
nonce: v.optional(v.union([v.literal(""), v.string()]), ""),
|
|
217
|
+
requirement: requirementSchema
|
|
218
|
+
})
|
|
219
|
+
);
|
|
220
|
+
const agreement = withValidate(
|
|
221
|
+
v.object({
|
|
222
|
+
...createStandardFields("agreement", "Confirm your agreement to continue."),
|
|
223
|
+
uri: v.union([
|
|
224
|
+
v.literal(""),
|
|
225
|
+
v.pipe(v.string(), v.check(isHttpUrl, "Must be a valid HTTP/HTTPS URL"))
|
|
226
|
+
]),
|
|
227
|
+
method: v.optional(
|
|
228
|
+
v.picklist(Object.keys(import_mcrypto.types.HashType).map((x) => x.toLowerCase())),
|
|
229
|
+
"sha2"
|
|
230
|
+
),
|
|
231
|
+
digest: v.string()
|
|
232
|
+
})
|
|
233
|
+
);
|
|
234
|
+
const vcFilterSchema = v.object({
|
|
235
|
+
type: v.optional(v.pipe(v.array(v.pipe(v.string(), v.minLength(1))), v.minLength(1))),
|
|
236
|
+
target: v.optional((0, import_validator.vDID)()),
|
|
237
|
+
trustedIssuers: v.optional(v.pipe(v.array(trustedIssuerSchema), v.minLength(1))),
|
|
238
|
+
tag: v.optional(v.pipe(v.string(), v.check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
239
|
+
ownerDid: v.optional(v.array((0, import_validator.vDID)()), []),
|
|
240
|
+
claimUrl: optionalUrlSchema,
|
|
241
|
+
acquireUrl: optionalUrlSchema
|
|
242
|
+
});
|
|
243
|
+
const verifiableCredential = withValidate(
|
|
244
|
+
v.object({
|
|
245
|
+
...createStandardFields("verifiableCredential", "Please present a verifiable credential to continue."),
|
|
246
|
+
optional: v.optional(v.boolean(), false),
|
|
247
|
+
claimUrl: optionalUrlSchema,
|
|
248
|
+
acquireUrl: optionalUrlSchema,
|
|
249
|
+
// v1
|
|
250
|
+
item: v.optional(v.pipe(v.array(v.pipe(v.string(), v.minLength(1))), v.minLength(1))),
|
|
251
|
+
target: v.optional((0, import_validator.vDID)()),
|
|
252
|
+
trustedIssuers: v.optional(v.pipe(v.array(trustedIssuerSchema), v.minLength(1))),
|
|
253
|
+
tag: v.optional(v.pipe(v.string(), v.check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
254
|
+
ownerDid: v.optional(v.array((0, import_validator.vDID)()), []),
|
|
255
|
+
// v2
|
|
256
|
+
filters: v.optional(v.array(vcFilterSchema))
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
const assetFilterSchema = v.object({
|
|
260
|
+
address: v.optional((0, import_validator.vDID)()),
|
|
261
|
+
trustedIssuers: v.optional(v.pipe(v.array(trustedIssuerSchema), v.minLength(1))),
|
|
262
|
+
trustedParents: v.optional(v.pipe(v.array((0, import_validator.vDID)()), v.minLength(1))),
|
|
263
|
+
tag: v.optional(v.pipe(v.string(), v.check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
264
|
+
ownerDid: v.optional(v.array((0, import_validator.vDID)()), []),
|
|
265
|
+
consumed: v.optional(v.boolean()),
|
|
266
|
+
acquireUrl: optionalUrlSchema
|
|
267
|
+
});
|
|
268
|
+
const asset = withValidate(
|
|
269
|
+
v.object({
|
|
270
|
+
...createStandardFields("asset", "Please present an on chain asset to continue."),
|
|
271
|
+
optional: v.optional(v.boolean(), false),
|
|
272
|
+
// v1
|
|
273
|
+
address: v.optional((0, import_validator.vDID)()),
|
|
274
|
+
trustedIssuers: v.optional(v.pipe(v.array(trustedIssuerSchema), v.minLength(1))),
|
|
275
|
+
trustedParents: v.optional(v.pipe(v.array((0, import_validator.vDID)()), v.minLength(1))),
|
|
276
|
+
tag: v.optional(v.pipe(v.string(), v.check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
277
|
+
ownerDid: v.optional(v.array((0, import_validator.vDID)()), []),
|
|
278
|
+
consumed: v.optional(v.boolean()),
|
|
279
|
+
acquireUrl: optionalUrlSchema,
|
|
280
|
+
// v2
|
|
281
|
+
filters: v.optional(v.array(assetFilterSchema))
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
const assetOrVCFilterSchema = v.object({
|
|
285
|
+
type: v.optional(v.pipe(v.array(v.pipe(v.string(), v.minLength(1))), v.minLength(1))),
|
|
286
|
+
address: v.optional((0, import_validator.vDID)()),
|
|
287
|
+
trustedIssuers: v.optional(v.pipe(v.array(trustedIssuerSchema), v.minLength(1))),
|
|
288
|
+
trustedParents: v.optional(v.pipe(v.array((0, import_validator.vDID)()), v.minLength(1))),
|
|
289
|
+
tag: v.optional(v.pipe(v.string(), v.check((s) => s === "" || s.length >= 1, "Must be non-empty or empty string")), ""),
|
|
290
|
+
ownerDid: v.optional(v.array((0, import_validator.vDID)()), []),
|
|
291
|
+
consumed: v.optional(v.boolean()),
|
|
292
|
+
claimUrl: optionalUrlSchema,
|
|
293
|
+
acquireUrl: optionalUrlSchema
|
|
294
|
+
});
|
|
295
|
+
const assetOrVC = withValidate(
|
|
296
|
+
v.object({
|
|
297
|
+
...createStandardFields("assetOrVC", "Please present NFT to continue."),
|
|
298
|
+
filters: v.pipe(v.array(assetOrVCFilterSchema), v.minLength(1)),
|
|
299
|
+
optional: v.optional(v.boolean(), false)
|
|
300
|
+
})
|
|
301
|
+
);
|
|
302
|
+
return {
|
|
303
|
+
authPrincipal,
|
|
304
|
+
profile,
|
|
305
|
+
signature,
|
|
306
|
+
prepareTx,
|
|
307
|
+
agreement,
|
|
308
|
+
verifiableCredential,
|
|
309
|
+
asset,
|
|
310
|
+
assetOrVC,
|
|
311
|
+
keyPair,
|
|
312
|
+
encryptionKey
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/schema/index.ts
|
|
317
|
+
var isHttpUrl2 = (s) => {
|
|
318
|
+
try {
|
|
319
|
+
const url = new URL(s);
|
|
320
|
+
return ["http:", "https:"].includes(url.protocol);
|
|
321
|
+
} catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
var chainInfoSchema = v2.pipe(
|
|
326
|
+
v2.object({
|
|
327
|
+
type: v2.optional(v2.picklist(["arcblock", "ethereum", "solona"]), "arcblock"),
|
|
328
|
+
id: v2.optional(v2.any()),
|
|
329
|
+
host: v2.optional(v2.any())
|
|
330
|
+
}),
|
|
331
|
+
v2.rawTransform(({ dataset, addIssue, NEVER }) => {
|
|
332
|
+
const obj = dataset.value;
|
|
333
|
+
let typeSchema;
|
|
334
|
+
switch (obj.type) {
|
|
335
|
+
case "arcblock":
|
|
336
|
+
typeSchema = v2.object({
|
|
337
|
+
type: v2.literal("arcblock"),
|
|
338
|
+
id: v2.optional(v2.string(), "none"),
|
|
339
|
+
host: v2.optional(
|
|
340
|
+
v2.pipe(
|
|
341
|
+
v2.string(),
|
|
342
|
+
v2.check(
|
|
343
|
+
(s) => s === "none" || isHttpUrl2(s),
|
|
344
|
+
"must be a valid uri with a scheme matching the http|https pattern"
|
|
345
|
+
)
|
|
346
|
+
),
|
|
347
|
+
"none"
|
|
348
|
+
)
|
|
349
|
+
});
|
|
350
|
+
break;
|
|
351
|
+
case "ethereum":
|
|
352
|
+
typeSchema = v2.object({
|
|
353
|
+
type: v2.literal("ethereum"),
|
|
354
|
+
id: v2.pipe(v2.string(), v2.regex(/^[0-9]+$/, "fails to match the numbers pattern")),
|
|
355
|
+
host: v2.optional(v2.string())
|
|
356
|
+
});
|
|
357
|
+
break;
|
|
358
|
+
case "solona":
|
|
359
|
+
typeSchema = v2.object({
|
|
360
|
+
type: v2.literal("solona"),
|
|
361
|
+
id: v2.pipe(v2.string(), v2.regex(/^[0-9]+$/, "fails to match the numbers pattern")),
|
|
362
|
+
host: v2.optional(v2.string())
|
|
363
|
+
});
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
const result = v2.safeParse(typeSchema, obj);
|
|
367
|
+
if (!result.success) {
|
|
368
|
+
for (const issue of result.issues) {
|
|
369
|
+
addIssue({ message: issue.message, path: issue.path });
|
|
370
|
+
}
|
|
371
|
+
return NEVER;
|
|
372
|
+
}
|
|
373
|
+
const output = {};
|
|
374
|
+
for (const [k, val] of Object.entries(result.output)) {
|
|
375
|
+
if (val !== void 0) output[k] = val;
|
|
376
|
+
}
|
|
377
|
+
return output;
|
|
378
|
+
})
|
|
379
|
+
);
|
|
380
|
+
var appInfoSchema = v2.looseObject({
|
|
381
|
+
name: v2.string(),
|
|
382
|
+
description: v2.string(),
|
|
383
|
+
icon: v2.pipe(v2.string(), v2.check(isHttpUrl2, "Must be a valid HTTP/HTTPS URL")),
|
|
384
|
+
link: v2.optional(v2.pipe(v2.string(), v2.check(isHttpUrl2, "Must be a valid HTTP/HTTPS URL"))),
|
|
385
|
+
path: v2.optional(v2.pipe(v2.string(), v2.check(isHttpUrl2, "Must be a valid HTTP/HTTPS URL")), "https://abtwallet.io/i/"),
|
|
386
|
+
publisher: v2.optional((0, import_validator2.vDID)()),
|
|
387
|
+
updateSubEndpoint: v2.optional(v2.boolean()),
|
|
388
|
+
subscriptionEndpoint: v2.optional(v2.string()),
|
|
389
|
+
nodeDid: v2.optional((0, import_validator2.vDID)()),
|
|
390
|
+
agentDid: v2.optional((0, import_validator2.vDID)())
|
|
391
|
+
});
|
|
392
|
+
function withValidate2(schema) {
|
|
393
|
+
return Object.assign(schema, {
|
|
394
|
+
validate: (data) => {
|
|
395
|
+
const { value, error } = (0, import_validator2.vValidate)(schema, data);
|
|
396
|
+
if (error) error.toString = () => error.message;
|
|
397
|
+
return { value, error };
|
|
398
|
+
},
|
|
399
|
+
validateAsync: (data) => {
|
|
400
|
+
const { value, error } = (0, import_validator2.vValidate)(schema, data);
|
|
401
|
+
return error ? Promise.reject(new Error(error.message)) : Promise.resolve(value);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
var chainInfo = withValidate2(chainInfoSchema);
|
|
406
|
+
var appInfo = withValidate2(appInfoSchema);
|
|
407
|
+
var claims = claims_default(chainInfoSchema);
|
|
408
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
409
|
+
0 && (module.exports = {
|
|
410
|
+
appInfo,
|
|
411
|
+
chainInfo,
|
|
412
|
+
claims
|
|
413
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/storage/kv.ts
|
|
21
|
+
var kv_exports = {};
|
|
22
|
+
__export(kv_exports, {
|
|
23
|
+
default: () => kv_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(kv_exports);
|
|
26
|
+
var import_events = require("events");
|
|
27
|
+
var CloudflareKVStorage = class extends import_events.EventEmitter {
|
|
28
|
+
kv;
|
|
29
|
+
ttl;
|
|
30
|
+
prefix;
|
|
31
|
+
constructor(kv, options = {}) {
|
|
32
|
+
super();
|
|
33
|
+
this.kv = kv;
|
|
34
|
+
this.ttl = options.ttl ?? 300;
|
|
35
|
+
this.prefix = options.prefix ?? "";
|
|
36
|
+
}
|
|
37
|
+
key(token) {
|
|
38
|
+
return `${this.prefix}${token}`;
|
|
39
|
+
}
|
|
40
|
+
async create(token, status = "created") {
|
|
41
|
+
const record = { token, status };
|
|
42
|
+
await this.kv.put(this.key(token), JSON.stringify(record), { expirationTtl: this.ttl });
|
|
43
|
+
this.emit("create", record);
|
|
44
|
+
return record;
|
|
45
|
+
}
|
|
46
|
+
async read(token) {
|
|
47
|
+
const raw = await this.kv.get(this.key(token));
|
|
48
|
+
if (!raw) return null;
|
|
49
|
+
return JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
async update(token, updates) {
|
|
52
|
+
const existing = await this.read(token);
|
|
53
|
+
if (!existing) return null;
|
|
54
|
+
delete updates.token;
|
|
55
|
+
const merged = { ...existing, ...updates };
|
|
56
|
+
await this.kv.put(this.key(token), JSON.stringify(merged), { expirationTtl: this.ttl });
|
|
57
|
+
this.emit("update", merged);
|
|
58
|
+
return merged;
|
|
59
|
+
}
|
|
60
|
+
async delete(token) {
|
|
61
|
+
const existing = await this.read(token);
|
|
62
|
+
if (existing) {
|
|
63
|
+
this.emit("destroy", existing);
|
|
64
|
+
}
|
|
65
|
+
await this.kv.delete(this.key(token));
|
|
66
|
+
}
|
|
67
|
+
async exist(token, did) {
|
|
68
|
+
const record = await this.read(token);
|
|
69
|
+
if (!record) return false;
|
|
70
|
+
if (did) return record.did === did;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var kv_default = CloudflareKVStorage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-connect-js",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Server-side DID Connect protocol — WalletAuthenticator, WalletHandlers, framework adapters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,15 +8,18 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
12
13
|
},
|
|
13
14
|
"./storage/kv": {
|
|
14
15
|
"types": "./dist/storage/kv.d.ts",
|
|
15
|
-
"import": "./dist/storage/kv.js"
|
|
16
|
+
"import": "./dist/storage/kv.js",
|
|
17
|
+
"require": "./dist/storage/kv.cjs"
|
|
16
18
|
},
|
|
17
19
|
"./schema": {
|
|
18
20
|
"types": "./dist/schema/index.d.ts",
|
|
19
|
-
"import": "./dist/schema/index.js"
|
|
21
|
+
"import": "./dist/schema/index.js",
|
|
22
|
+
"require": "./dist/schema/index.cjs"
|
|
20
23
|
}
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
@@ -32,7 +35,7 @@
|
|
|
32
35
|
"debug": "^4.4.3",
|
|
33
36
|
"fast-json-stable-stringify": "^2.1.0",
|
|
34
37
|
"valibot": "^1.3.1",
|
|
35
|
-
"@arcblock/did-connect-core": "^4.0.
|
|
38
|
+
"@arcblock/did-connect-core": "^4.0.3"
|
|
36
39
|
},
|
|
37
40
|
"devDependencies": {
|
|
38
41
|
"@arcblock/did-agent-storage-memory": "^1.8.0",
|
|
@@ -48,6 +51,7 @@
|
|
|
48
51
|
"axios": "^1.17.0",
|
|
49
52
|
"body-parser": "^2.2.2",
|
|
50
53
|
"cookie-parser": "^1.4.7",
|
|
54
|
+
"esbuild": "^0.25.12",
|
|
51
55
|
"express": "^5.2.1",
|
|
52
56
|
"hono": "^4.12.23",
|
|
53
57
|
"lodash": "^4.18.1",
|
|
@@ -62,7 +66,7 @@
|
|
|
62
66
|
},
|
|
63
67
|
"license": "Apache-2.0",
|
|
64
68
|
"scripts": {
|
|
65
|
-
"build": "tsc",
|
|
69
|
+
"build": "tsc && esbuild src/index.ts src/schema/index.ts src/storage/kv.ts --bundle --format=cjs --platform=node --target=node20 --packages=external --outdir=dist --outbase=src --out-extension:.js=.cjs",
|
|
66
70
|
"lint": "biome check src/",
|
|
67
71
|
"test": "vitest run",
|
|
68
72
|
"test:coverage": "vitest run --coverage",
|