@arcblock/did-connect-js 1.30.0 → 4.0.0-beta.10
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/{lib/adapters/detect.d.cts → dist/adapters/detect.d.ts} +3 -5
- package/dist/adapters/detect.d.ts.map +1 -0
- package/dist/adapters/detect.js +13 -0
- package/dist/adapters/detect.js.map +1 -0
- package/dist/adapters/express.d.ts +40 -0
- package/dist/adapters/express.d.ts.map +1 -0
- package/dist/adapters/express.js +30 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/hono.d.ts +49 -0
- package/dist/adapters/hono.d.ts.map +1 -0
- package/dist/adapters/hono.js +176 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/authenticator/base.d.ts +21 -0
- package/dist/authenticator/base.d.ts.map +1 -0
- package/dist/authenticator/base.js +109 -0
- package/dist/authenticator/base.js.map +1 -0
- package/dist/authenticator/wallet.d.ts +252 -0
- package/dist/authenticator/wallet.d.ts.map +1 -0
- package/dist/authenticator/wallet.js +590 -0
- package/dist/authenticator/wallet.js.map +1 -0
- package/dist/handlers/base.d.ts +25 -0
- package/dist/handlers/base.d.ts.map +1 -0
- package/dist/handlers/base.js +48 -0
- package/dist/handlers/base.js.map +1 -0
- package/dist/handlers/util.d.ts +48 -0
- package/dist/handlers/util.d.ts.map +1 -0
- package/dist/handlers/util.js +805 -0
- package/dist/handlers/util.js.map +1 -0
- package/dist/handlers/wallet.d.ts +96 -0
- package/dist/handlers/wallet.d.ts.map +1 -0
- package/dist/handlers/wallet.js +129 -0
- package/dist/handlers/wallet.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +14 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +37 -0
- package/dist/protocol.js.map +1 -0
- package/dist/schema/claims.d.ts +11 -0
- package/dist/schema/claims.d.ts.map +1 -0
- package/dist/schema/claims.js +226 -0
- package/dist/schema/claims.js.map +1 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +89 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/storage/kv.d.ts +31 -0
- package/dist/storage/kv.d.ts.map +1 -0
- package/dist/storage/kv.js +54 -0
- package/dist/storage/kv.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/helpers.d.ts +19 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +77 -0
- package/dist/utils/helpers.js.map +1 -0
- package/package.json +51 -107
- package/LICENSE +0 -13
- package/README.md +0 -210
- package/esm/_virtual/rolldown_runtime.mjs +0 -8
- package/esm/adapters/detect.d.mts +0 -11
- package/esm/adapters/detect.mjs +0 -16
- package/esm/adapters/express.d.mts +0 -48
- package/esm/adapters/express.mjs +0 -39
- package/esm/adapters/hono.d.mts +0 -57
- package/esm/adapters/hono.mjs +0 -164
- package/esm/authenticator/base.d.mts +0 -23
- package/esm/authenticator/base.mjs +0 -88
- package/esm/authenticator/wallet.d.mts +0 -270
- package/esm/authenticator/wallet.mjs +0 -556
- package/esm/did/did-connect/package.mjs +0 -118
- package/esm/handlers/base.d.mts +0 -32
- package/esm/handlers/base.mjs +0 -37
- package/esm/handlers/util.d.mts +0 -70
- package/esm/handlers/util.mjs +0 -739
- package/esm/handlers/wallet.d.mts +0 -120
- package/esm/handlers/wallet.mjs +0 -139
- package/esm/index.d.mts +0 -8
- package/esm/index.mjs +0 -8
- package/esm/node_modules/valibot/dist/index.mjs +0 -736
- package/esm/protocol.d.mts +0 -15
- package/esm/protocol.mjs +0 -40
- package/esm/schema/claims.d.mts +0 -16
- package/esm/schema/claims.mjs +0 -216
- package/esm/schema/index.d.mts +0 -29
- package/esm/schema/index.mjs +0 -75
- package/esm/storage/kv.d.mts +0 -33
- package/esm/storage/kv.mjs +0 -55
- package/esm/types.d.mts +0 -55
- package/esm/types.mjs +0 -1
- package/lib/_virtual/rolldown_runtime.cjs +0 -31
- package/lib/adapters/detect.cjs +0 -18
- package/lib/adapters/express.cjs +0 -41
- package/lib/adapters/express.d.cts +0 -48
- package/lib/adapters/hono.cjs +0 -167
- package/lib/adapters/hono.d.cts +0 -57
- package/lib/authenticator/base.cjs +0 -91
- package/lib/authenticator/base.d.cts +0 -23
- package/lib/authenticator/wallet.cjs +0 -565
- package/lib/authenticator/wallet.d.cts +0 -270
- package/lib/did/did-connect/package.cjs +0 -121
- package/lib/handlers/base.cjs +0 -40
- package/lib/handlers/base.d.cts +0 -32
- package/lib/handlers/util.cjs +0 -759
- package/lib/handlers/util.d.cts +0 -70
- package/lib/handlers/wallet.cjs +0 -139
- package/lib/handlers/wallet.d.cts +0 -119
- package/lib/index.cjs +0 -16
- package/lib/index.d.cts +0 -8
- package/lib/node_modules/valibot/dist/index.cjs +0 -756
- package/lib/protocol.cjs +0 -46
- package/lib/protocol.d.cts +0 -15
- package/lib/schema/claims.cjs +0 -218
- package/lib/schema/claims.d.cts +0 -16
- package/lib/schema/index.cjs +0 -79
- package/lib/schema/index.d.cts +0 -29
- package/lib/storage/kv.cjs +0 -57
- package/lib/storage/kv.d.cts +0 -33
- package/lib/types.cjs +0 -0
- package/lib/types.d.cts +0 -55
package/esm/protocol.d.mts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/protocol.d.ts
|
|
2
|
-
declare const VERSION = "1.0.0";
|
|
3
|
-
declare const decrypt: (data: any, config?: any, dataKey?: string) => any;
|
|
4
|
-
declare const encrypt: (data: any, config?: any, dataKey?: string) => any;
|
|
5
|
-
declare const PROTECTED_KEYS: string[];
|
|
6
|
-
declare const SESSION_STATUS: {
|
|
7
|
-
readonly CREATED: "created";
|
|
8
|
-
readonly SUCCEED: "succeed";
|
|
9
|
-
readonly ERROR: "error";
|
|
10
|
-
readonly BUSY: "busy";
|
|
11
|
-
readonly SCANNED: "scanned";
|
|
12
|
-
readonly FORBIDDEN: "forbidden";
|
|
13
|
-
};
|
|
14
|
-
//#endregion
|
|
15
|
-
export { PROTECTED_KEYS, SESSION_STATUS, VERSION, decrypt, encrypt };
|
package/esm/protocol.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { fromBase58 } from "@ocap/util";
|
|
2
|
-
import { decode } from "@arcblock/jwt";
|
|
3
|
-
import AES from "@ocap/mcrypto/lib/crypter/aes";
|
|
4
|
-
|
|
5
|
-
//#region src/protocol.ts
|
|
6
|
-
const VERSION = "1.0.0";
|
|
7
|
-
const decrypt = (data, config = {}, dataKey = "userInfo") => {
|
|
8
|
-
try {
|
|
9
|
-
decode(data[dataKey]);
|
|
10
|
-
return data;
|
|
11
|
-
} catch {}
|
|
12
|
-
if (config.sharedKey && data.version === VERSION) data[dataKey] = AES.decrypt(fromBase58(data[dataKey]), config.sharedKey, "buffer").toString("utf8");
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
const encrypt = (data, config = {}, dataKey = "authInfo") => {
|
|
16
|
-
const { clientVersion, sharedKey } = config || {};
|
|
17
|
-
if (data.sensitive && sharedKey && clientVersion === VERSION) {
|
|
18
|
-
data.version = VERSION;
|
|
19
|
-
data[dataKey] = AES.encrypt(data[dataKey], sharedKey, "base58");
|
|
20
|
-
}
|
|
21
|
-
delete data.sensitive;
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
const PROTECTED_KEYS = [
|
|
25
|
-
"challenge",
|
|
26
|
-
"nonce",
|
|
27
|
-
"sharedKey",
|
|
28
|
-
"encryptionKey"
|
|
29
|
-
];
|
|
30
|
-
const SESSION_STATUS = {
|
|
31
|
-
CREATED: "created",
|
|
32
|
-
SUCCEED: "succeed",
|
|
33
|
-
ERROR: "error",
|
|
34
|
-
BUSY: "busy",
|
|
35
|
-
SCANNED: "scanned",
|
|
36
|
-
FORBIDDEN: "forbidden"
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export { PROTECTED_KEYS, SESSION_STATUS, VERSION, decrypt, encrypt };
|
package/esm/schema/claims.d.mts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/schema/claims.d.ts
|
|
2
|
-
interface ClaimsSchema {
|
|
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;
|
|
13
|
-
}
|
|
14
|
-
declare const _default: (chainInfo: any) => ClaimsSchema;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { ClaimsSchema, _default as default };
|
package/esm/schema/claims.mjs
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
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";
|
|
3
|
-
import { types } from "@ocap/mcrypto";
|
|
4
|
-
|
|
5
|
-
//#region src/schema/claims.ts
|
|
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
|
-
}))
|
|
37
|
-
});
|
|
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
|
-
}));
|
|
44
|
-
var claims_default = (chainInfo) => {
|
|
45
|
-
const createStandardFields = (type, description) => ({
|
|
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(), {})
|
|
51
|
-
});
|
|
52
|
-
const authPrincipal = object({
|
|
53
|
-
...createStandardFields("authPrincipal", "Please continue with your account"),
|
|
54
|
-
target: optional(union([literal(""), vDID()]), ""),
|
|
55
|
-
supervised: optional(boolean(), false),
|
|
56
|
-
targetType: targetTypeSchema
|
|
57
|
-
});
|
|
58
|
-
const keyPair = object({
|
|
59
|
-
...createStandardFields("keyPair", "Please create account to continue."),
|
|
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()]), ""),
|
|
63
|
-
targetType: targetTypeSchema
|
|
64
|
-
});
|
|
65
|
-
const encryptionKey = object({
|
|
66
|
-
...createStandardFields("encryptionKey", "Please provide encryptionKey to continue."),
|
|
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
|
-
});
|
|
197
|
-
return {
|
|
198
|
-
authPrincipal,
|
|
199
|
-
profile,
|
|
200
|
-
signature,
|
|
201
|
-
prepareTx,
|
|
202
|
-
agreement,
|
|
203
|
-
verifiableCredential,
|
|
204
|
-
asset,
|
|
205
|
-
assetOrVC: object({
|
|
206
|
-
...createStandardFields("assetOrVC", "Please present NFT to continue."),
|
|
207
|
-
filters: pipe(array(assetOrVCFilterSchema), minLength(1)),
|
|
208
|
-
optional: optional(boolean(), false)
|
|
209
|
-
}),
|
|
210
|
-
keyPair,
|
|
211
|
-
encryptionKey
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
//#endregion
|
|
216
|
-
export { claims_default as default };
|
package/esm/schema/index.d.mts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ClaimsSchema } from "./claims.mjs";
|
|
2
|
-
import { vValidate } from "@arcblock/validator";
|
|
3
|
-
import * as v from "valibot";
|
|
4
|
-
|
|
5
|
-
//#region src/schema/index.d.ts
|
|
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>;
|
|
27
|
-
declare const claims: ClaimsSchema;
|
|
28
|
-
//#endregion
|
|
29
|
-
export { appInfo, chainInfo, claims, vValidate };
|
package/esm/schema/index.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { any, boolean, check, literal, looseObject, object, optional, picklist, pipe, rawTransform, regex, safeParse, string } from "../node_modules/valibot/dist/index.mjs";
|
|
2
|
-
import claims_default from "./claims.mjs";
|
|
3
|
-
import { vDID, vValidate } from "@arcblock/validator";
|
|
4
|
-
|
|
5
|
-
//#region src/schema/index.ts
|
|
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())
|
|
71
|
-
});
|
|
72
|
-
const claims = claims_default(chainInfo);
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
export { appInfo, chainInfo, claims, vValidate };
|
package/esm/storage/kv.d.mts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/kv.d.ts
|
|
4
|
-
interface KVNamespace {
|
|
5
|
-
get(key: string): Promise<string | null>;
|
|
6
|
-
put(key: string, value: string, options?: {
|
|
7
|
-
expirationTtl?: number;
|
|
8
|
-
}): Promise<void>;
|
|
9
|
-
delete(key: string): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
interface CloudflareKVStorageOptions {
|
|
12
|
-
/** TTL in seconds for KV entries. Default: 300 (5 minutes) */
|
|
13
|
-
ttl?: number;
|
|
14
|
-
/** Key prefix for KV entries. Default: '' */
|
|
15
|
-
prefix?: string;
|
|
16
|
-
}
|
|
17
|
-
declare class CloudflareKVStorage extends EventEmitter {
|
|
18
|
-
private kv;
|
|
19
|
-
private ttl;
|
|
20
|
-
private prefix;
|
|
21
|
-
constructor(kv: KVNamespace, options?: CloudflareKVStorageOptions);
|
|
22
|
-
private key;
|
|
23
|
-
create(token: string, status?: string): Promise<{
|
|
24
|
-
token: string;
|
|
25
|
-
status: string;
|
|
26
|
-
}>;
|
|
27
|
-
read(token: string): Promise<any>;
|
|
28
|
-
update(token: string, updates: Record<string, any>): Promise<any>;
|
|
29
|
-
delete(token: string): Promise<void>;
|
|
30
|
-
exist(token: string, did?: string): Promise<boolean>;
|
|
31
|
-
}
|
|
32
|
-
//#endregion
|
|
33
|
-
export { CloudflareKVStorage as default };
|
package/esm/storage/kv.mjs
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/kv.ts
|
|
4
|
-
var CloudflareKVStorage = class extends EventEmitter {
|
|
5
|
-
constructor(kv, options = {}) {
|
|
6
|
-
super();
|
|
7
|
-
this.kv = kv;
|
|
8
|
-
this.ttl = options.ttl ?? 300;
|
|
9
|
-
this.prefix = options.prefix ?? "";
|
|
10
|
-
}
|
|
11
|
-
key(token) {
|
|
12
|
-
return `${this.prefix}${token}`;
|
|
13
|
-
}
|
|
14
|
-
async create(token, status = "created") {
|
|
15
|
-
const record = {
|
|
16
|
-
token,
|
|
17
|
-
status
|
|
18
|
-
};
|
|
19
|
-
await this.kv.put(this.key(token), JSON.stringify(record), { expirationTtl: this.ttl });
|
|
20
|
-
this.emit("create", record);
|
|
21
|
-
return record;
|
|
22
|
-
}
|
|
23
|
-
async read(token) {
|
|
24
|
-
const raw = await this.kv.get(this.key(token));
|
|
25
|
-
if (!raw) return null;
|
|
26
|
-
return JSON.parse(raw);
|
|
27
|
-
}
|
|
28
|
-
async update(token, updates) {
|
|
29
|
-
const existing = await this.read(token);
|
|
30
|
-
if (!existing) return null;
|
|
31
|
-
delete updates.token;
|
|
32
|
-
const merged = {
|
|
33
|
-
...existing,
|
|
34
|
-
...updates
|
|
35
|
-
};
|
|
36
|
-
await this.kv.put(this.key(token), JSON.stringify(merged), { expirationTtl: this.ttl });
|
|
37
|
-
this.emit("update", merged);
|
|
38
|
-
return merged;
|
|
39
|
-
}
|
|
40
|
-
async delete(token) {
|
|
41
|
-
const existing = await this.read(token);
|
|
42
|
-
if (existing) this.emit("destroy", existing);
|
|
43
|
-
await this.kv.delete(this.key(token));
|
|
44
|
-
}
|
|
45
|
-
async exist(token, did) {
|
|
46
|
-
const record = await this.read(token);
|
|
47
|
-
if (!record) return false;
|
|
48
|
-
if (did) return record.did === did;
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var kv_default = CloudflareKVStorage;
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
export { kv_default as default };
|
package/esm/types.d.mts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Framework-agnostic request interface for DID Connect handlers.
|
|
4
|
-
*
|
|
5
|
-
* Designed to match Express's `req` shape so that Express requests
|
|
6
|
-
* satisfy it natively (zero-wrapping). Hono adapter creates a wrapper
|
|
7
|
-
* that maps Hono Context to this interface.
|
|
8
|
-
*/
|
|
9
|
-
interface ConnectRequest {
|
|
10
|
-
/** Parsed request body (from body-parser or Hono) */
|
|
11
|
-
body: Record<string, any>;
|
|
12
|
-
/** Parsed query string parameters */
|
|
13
|
-
query: Record<string, any>;
|
|
14
|
-
/** URL path parameters (e.g. :action) */
|
|
15
|
-
params: Record<string, any>;
|
|
16
|
-
/** Raw request headers */
|
|
17
|
-
headers: Record<string, string | string[] | undefined>;
|
|
18
|
-
/** Parsed cookies (from cookie-parser or manual parsing) */
|
|
19
|
-
cookies: Record<string, string>;
|
|
20
|
-
/** Request protocol ('http' or 'https') */
|
|
21
|
-
protocol: string;
|
|
22
|
-
/** Full original URL including query string */
|
|
23
|
-
originalUrl: string;
|
|
24
|
-
/** Session context, populated by ensureContext middleware */
|
|
25
|
-
context?: any;
|
|
26
|
-
/** Flag to prevent double monkey-patching in ensureSignedJson */
|
|
27
|
-
ensureSignedJson?: boolean;
|
|
28
|
-
/** Case-insensitive header getter (matches Express req.get) */
|
|
29
|
-
get(name: string): string | undefined;
|
|
30
|
-
/** Content negotiation for locale (matches Express req.acceptsLanguages) */
|
|
31
|
-
acceptsLanguages(...languages: string[]): string | false;
|
|
32
|
-
/** Original framework-specific request object (Express req or Hono Context) */
|
|
33
|
-
raw?: any;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Framework-agnostic response interface for DID Connect handlers.
|
|
37
|
-
*
|
|
38
|
-
* Express: maps directly to res.jsonp/res.json/res.status().json().
|
|
39
|
-
* Hono: uses a buffer pattern — calls are captured, then the outer
|
|
40
|
-
* Hono handler reads the buffer to return c.json().
|
|
41
|
-
*/
|
|
42
|
-
interface ConnectResponse {
|
|
43
|
-
/** Send JSON response (Express JSONP, Hono json) */
|
|
44
|
-
jsonp(data: any): void;
|
|
45
|
-
/** Send JSON response */
|
|
46
|
-
json(data: any): void;
|
|
47
|
-
/** Set status code and return object with json() method */
|
|
48
|
-
status(code: number): {
|
|
49
|
-
json(data: any): void;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/** Middleware next() callback */
|
|
53
|
-
type NextFunction = () => void;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { ConnectRequest, ConnectResponse, NextFunction };
|
package/esm/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
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 __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
-
value: mod,
|
|
25
|
-
enumerable: true
|
|
26
|
-
}) : target, mod));
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
|
|
30
|
-
exports.__commonJSMin = __commonJSMin;
|
|
31
|
-
exports.__toESM = __toESM;
|
package/lib/adapters/detect.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/adapters/detect.ts
|
|
3
|
-
/**
|
|
4
|
-
* Detect whether an app object is Express or Hono.
|
|
5
|
-
*
|
|
6
|
-
* Express: has set(), engine(), and lazyrouter() or _router
|
|
7
|
-
* Hono: has fetch() method + basePath property, no Express set/engine
|
|
8
|
-
*/
|
|
9
|
-
function isExpressApp(app) {
|
|
10
|
-
return typeof app?.set === "function" && typeof app?.engine === "function";
|
|
11
|
-
}
|
|
12
|
-
function isHonoApp(app) {
|
|
13
|
-
return typeof app?.fetch === "function" && !isExpressApp(app);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.isExpressApp = isExpressApp;
|
|
18
|
-
exports.isHonoApp = isHonoApp;
|
package/lib/adapters/express.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let cors = require("cors");
|
|
3
|
-
cors = require_rolldown_runtime.__toESM(cors);
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/express.ts
|
|
6
|
-
/**
|
|
7
|
-
* Register DID Connect routes on an Express-compatible app.
|
|
8
|
-
*
|
|
9
|
-
* Routes registered:
|
|
10
|
-
* - GET/POST `{prefix}/{action}/token` — generate session
|
|
11
|
-
* - GET `{prefix}/{action}/status` — check session status
|
|
12
|
-
* - GET `{prefix}/{action}/timeout` — expire session
|
|
13
|
-
* - GET `{prefix}/{action}/auth` — wallet fetches auth request
|
|
14
|
-
* - POST `{prefix}/{action}/auth` — wallet submits auth response
|
|
15
|
-
* - GET `{prefix}/{action}/auth/submit` — web wallet submit
|
|
16
|
-
*/
|
|
17
|
-
function attachExpress({ app, prefix, action, handlers }) {
|
|
18
|
-
const pathname = `${prefix}/${action}/auth`;
|
|
19
|
-
const { generateSession, checkSession, expireSession, onAuthRequest, onAuthResponse, ensureContext, ensureSignedJson } = handlers;
|
|
20
|
-
app.use(`${prefix}/${action}`, (0, cors.default)({
|
|
21
|
-
origin: "*",
|
|
22
|
-
optionsSuccessStatus: 204
|
|
23
|
-
}));
|
|
24
|
-
app.get(`${prefix}/${action}/token`, generateSession);
|
|
25
|
-
app.post(`${prefix}/${action}/token`, generateSession);
|
|
26
|
-
app.get(`${prefix}/${action}/status`, ensureContext, checkSession);
|
|
27
|
-
app.get(`${prefix}/${action}/timeout`, ensureContext, expireSession);
|
|
28
|
-
app.get(pathname, ensureContext, ensureSignedJson, onAuthRequest);
|
|
29
|
-
app.post(pathname, ensureContext, ensureSignedJson, onAuthResponse);
|
|
30
|
-
app.get(`${pathname}/submit`, ensureContext, ensureSignedJson, onAuthResponse);
|
|
31
|
-
return {
|
|
32
|
-
generateSession,
|
|
33
|
-
expireSession,
|
|
34
|
-
checkSession,
|
|
35
|
-
onAuthRequest,
|
|
36
|
-
onAuthResponse
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
exports.attachExpress = attachExpress;
|