@arcblock/did-connect-js 1.29.22 → 4.0.0-beta.1
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 +221 -0
- package/dist/authenticator/wallet.d.ts.map +1 -0
- package/dist/authenticator/wallet.js +588 -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 +812 -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 +10 -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 +17 -0
- package/dist/schema/claims.d.ts.map +1 -0
- package/dist/schema/claims.js +205 -0
- package/dist/schema/claims.js.map +1 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +49 -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/package.json +48 -106
- 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/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/package.mjs +0 -120
- package/esm/protocol.d.mts +0 -15
- package/esm/protocol.mjs +0 -40
- package/esm/schema/claims.d.mts +0 -18
- package/esm/schema/claims.mjs +0 -154
- package/esm/schema/index.d.mts +0 -9
- package/esm/schema/index.mjs +0 -49
- 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 -564
- package/lib/authenticator/wallet.d.cts +0 -270
- package/lib/handlers/base.cjs +0 -40
- package/lib/handlers/base.d.cts +0 -32
- package/lib/handlers/util.cjs +0 -760
- 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/package.cjs +0 -123
- package/lib/protocol.cjs +0 -46
- package/lib/protocol.d.cts +0 -15
- package/lib/schema/claims.cjs +0 -156
- package/lib/schema/claims.d.cts +0 -18
- package/lib/schema/index.cjs +0 -52
- package/lib/schema/index.d.cts +0 -9
- 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/schema/index.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import claims_default from "./claims.mjs";
|
|
2
|
-
import { Joi } from "@arcblock/validator";
|
|
3
|
-
|
|
4
|
-
//#region src/schema/index.ts
|
|
5
|
-
const chainInfo = Joi.object({
|
|
6
|
-
type: Joi.string().optional().valid("arcblock", "ethereum", "solona").default("arcblock"),
|
|
7
|
-
id: Joi.any().when("type", {
|
|
8
|
-
is: "arcblock",
|
|
9
|
-
then: Joi.string().optional().default("none")
|
|
10
|
-
}).when("type", {
|
|
11
|
-
is: "ethereum",
|
|
12
|
-
then: Joi.string().required().pattern(/^[0-9]+$/, "numbers")
|
|
13
|
-
}).when("type", {
|
|
14
|
-
is: "solona",
|
|
15
|
-
then: Joi.string().required().pattern(/^[0-9]+$/, "numbers")
|
|
16
|
-
}),
|
|
17
|
-
host: Joi.string().when("type", {
|
|
18
|
-
is: "ethereum",
|
|
19
|
-
then: Joi.string().optional().allow("")
|
|
20
|
-
}).when("type", {
|
|
21
|
-
is: "solona",
|
|
22
|
-
then: Joi.string().optional().allow("")
|
|
23
|
-
}).when("type", {
|
|
24
|
-
is: "arcblock",
|
|
25
|
-
then: Joi.string().uri({ scheme: ["http", "https"] }).allow("none").default("none")
|
|
26
|
-
})
|
|
27
|
-
}).options({
|
|
28
|
-
stripUnknown: true,
|
|
29
|
-
noDefaults: false
|
|
30
|
-
});
|
|
31
|
-
const appInfo = Joi.object({
|
|
32
|
-
name: Joi.string().required(),
|
|
33
|
-
description: Joi.string().required(),
|
|
34
|
-
icon: Joi.string().uri({ scheme: ["http", "https"] }).required(),
|
|
35
|
-
link: Joi.string().uri({ scheme: ["http", "https"] }).optional(),
|
|
36
|
-
path: Joi.string().uri({ scheme: ["http", "https"] }).default("https://abtwallet.io/i/"),
|
|
37
|
-
publisher: Joi.DID().optional(),
|
|
38
|
-
updateSubEndpoint: Joi.boolean().optional(),
|
|
39
|
-
subscriptionEndpoint: Joi.string().optional(),
|
|
40
|
-
nodeDid: Joi.DID().optional(),
|
|
41
|
-
agentDid: Joi.DID().optional()
|
|
42
|
-
}).options({
|
|
43
|
-
stripUnknown: false,
|
|
44
|
-
noDefaults: false
|
|
45
|
-
});
|
|
46
|
-
const claims = claims_default(chainInfo);
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { appInfo, chainInfo, claims };
|
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;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ConnectRequest, ConnectResponse, NextFunction } from "../types.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/adapters/express.d.ts
|
|
4
|
-
interface ExpressLikeApp {
|
|
5
|
-
use(path: string, ...handlers: any[]): void;
|
|
6
|
-
get(path: string, ...handlers: any[]): void;
|
|
7
|
-
post(path: string, ...handlers: any[]): void;
|
|
8
|
-
}
|
|
9
|
-
interface HandlerFunctions {
|
|
10
|
-
generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
11
|
-
checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
12
|
-
expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
13
|
-
onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
14
|
-
onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
15
|
-
ensureContext: (req: ConnectRequest, res: ConnectResponse, next: NextFunction) => Promise<void>;
|
|
16
|
-
ensureSignedJson: (req: ConnectRequest, res: ConnectResponse, next: NextFunction) => void;
|
|
17
|
-
}
|
|
18
|
-
interface AttachExpressOptions {
|
|
19
|
-
app: ExpressLikeApp;
|
|
20
|
-
prefix: string;
|
|
21
|
-
action: string;
|
|
22
|
-
handlers: HandlerFunctions;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Register DID Connect routes on an Express-compatible app.
|
|
26
|
-
*
|
|
27
|
-
* Routes registered:
|
|
28
|
-
* - GET/POST `{prefix}/{action}/token` — generate session
|
|
29
|
-
* - GET `{prefix}/{action}/status` — check session status
|
|
30
|
-
* - GET `{prefix}/{action}/timeout` — expire session
|
|
31
|
-
* - GET `{prefix}/{action}/auth` — wallet fetches auth request
|
|
32
|
-
* - POST `{prefix}/{action}/auth` — wallet submits auth response
|
|
33
|
-
* - GET `{prefix}/{action}/auth/submit` — web wallet submit
|
|
34
|
-
*/
|
|
35
|
-
declare function attachExpress({
|
|
36
|
-
app,
|
|
37
|
-
prefix,
|
|
38
|
-
action,
|
|
39
|
-
handlers
|
|
40
|
-
}: AttachExpressOptions): {
|
|
41
|
-
generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
42
|
-
expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
43
|
-
checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
44
|
-
onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
45
|
-
onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
46
|
-
};
|
|
47
|
-
//#endregion
|
|
48
|
-
export { AttachExpressOptions, ExpressLikeApp, HandlerFunctions, attachExpress };
|
package/lib/adapters/hono.cjs
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/adapters/hono.ts
|
|
3
|
-
/**
|
|
4
|
-
* Parse a raw Cookie header string into a key-value map.
|
|
5
|
-
*/
|
|
6
|
-
function parseCookieHeader(header) {
|
|
7
|
-
const cookies = {};
|
|
8
|
-
if (!header) return cookies;
|
|
9
|
-
for (const pair of header.split(";")) {
|
|
10
|
-
const idx = pair.indexOf("=");
|
|
11
|
-
if (idx > 0) {
|
|
12
|
-
const key = pair.slice(0, idx).trim();
|
|
13
|
-
const val = pair.slice(idx + 1).trim();
|
|
14
|
-
cookies[key] = decodeURIComponent(val);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return cookies;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Simple Accept-Language negotiation matching Express's req.acceptsLanguages().
|
|
21
|
-
* Only needs to handle the two languages used by DID Connect: 'en-US' and 'zh-CN'.
|
|
22
|
-
*/
|
|
23
|
-
function negotiateLanguage(acceptHeader, ...langs) {
|
|
24
|
-
if (!acceptHeader || langs.length === 0) return langs[0] || false;
|
|
25
|
-
const lower = acceptHeader.toLowerCase();
|
|
26
|
-
for (const lang of langs) {
|
|
27
|
-
const prefix = lang.toLowerCase().split("-")[0];
|
|
28
|
-
if (lower.includes(lang.toLowerCase()) || lower.includes(prefix)) return lang;
|
|
29
|
-
}
|
|
30
|
-
return langs[0] || false;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a ConnectRequest from a Hono-like Context.
|
|
34
|
-
*
|
|
35
|
-
* @param c - Hono Context object
|
|
36
|
-
* @param bodyCache - Pre-parsed request body (since c.req.json() is async)
|
|
37
|
-
*/
|
|
38
|
-
function createHonoRequest(c, bodyCache = {}) {
|
|
39
|
-
const url = new URL(c.req.url);
|
|
40
|
-
const rawHeaders = {};
|
|
41
|
-
if (c.req.raw?.headers) c.req.raw.headers.forEach((value, key) => {
|
|
42
|
-
rawHeaders[key.toLowerCase()] = value;
|
|
43
|
-
});
|
|
44
|
-
return {
|
|
45
|
-
body: bodyCache,
|
|
46
|
-
query: Object.fromEntries(url.searchParams.entries()),
|
|
47
|
-
params: typeof c.req.param === "function" ? c.req.param() : {},
|
|
48
|
-
headers: rawHeaders,
|
|
49
|
-
cookies: parseCookieHeader(rawHeaders.cookie || ""),
|
|
50
|
-
protocol: url.protocol.replace(":", ""),
|
|
51
|
-
originalUrl: url.pathname + url.search,
|
|
52
|
-
get(name) {
|
|
53
|
-
return rawHeaders[name.toLowerCase()];
|
|
54
|
-
},
|
|
55
|
-
acceptsLanguages(...langs) {
|
|
56
|
-
return negotiateLanguage(rawHeaders["accept-language"] || "", ...langs);
|
|
57
|
-
},
|
|
58
|
-
raw: c
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create a ConnectResponse that buffers the handler's response.
|
|
63
|
-
* The Hono route wrapper reads the buffer via _getResult() to return c.json().
|
|
64
|
-
*/
|
|
65
|
-
function createHonoResponse() {
|
|
66
|
-
let result = null;
|
|
67
|
-
return {
|
|
68
|
-
jsonp(data) {
|
|
69
|
-
result = {
|
|
70
|
-
statusCode: 200,
|
|
71
|
-
body: data
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
json(data) {
|
|
75
|
-
result = {
|
|
76
|
-
statusCode: 200,
|
|
77
|
-
body: data
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
status(code) {
|
|
81
|
-
return { json(data) {
|
|
82
|
-
result = {
|
|
83
|
-
statusCode: code,
|
|
84
|
-
body: data
|
|
85
|
-
};
|
|
86
|
-
} };
|
|
87
|
-
},
|
|
88
|
-
_getResult() {
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Wrap a middleware chain + handler into a single Hono route handler.
|
|
95
|
-
* Runs middlewares sequentially with manual next() control,
|
|
96
|
-
* then runs the handler, then returns the buffered response.
|
|
97
|
-
*/
|
|
98
|
-
function wrapHandler(middlewares, handler) {
|
|
99
|
-
return async (c) => {
|
|
100
|
-
let body = {};
|
|
101
|
-
try {
|
|
102
|
-
const text = await c.req.text();
|
|
103
|
-
if (text) {
|
|
104
|
-
const contentType = c.req.header("content-type") || "";
|
|
105
|
-
if (contentType.includes("json")) body = JSON.parse(text);
|
|
106
|
-
else if (contentType.includes("urlencoded")) body = Object.fromEntries(new URLSearchParams(text).entries());
|
|
107
|
-
}
|
|
108
|
-
} catch {}
|
|
109
|
-
const req = createHonoRequest(c, body);
|
|
110
|
-
const res = createHonoResponse();
|
|
111
|
-
for (const mw of middlewares) {
|
|
112
|
-
let nextCalled = false;
|
|
113
|
-
await mw(req, res, () => {
|
|
114
|
-
nextCalled = true;
|
|
115
|
-
});
|
|
116
|
-
if (!nextCalled) {
|
|
117
|
-
const r$1 = res._getResult();
|
|
118
|
-
if (r$1) return c.json(r$1.body, r$1.statusCode);
|
|
119
|
-
return c.json({ error: "Unknown error" }, 500);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
await handler(req, res);
|
|
123
|
-
const r = res._getResult();
|
|
124
|
-
return c.json(r?.body ?? {}, r?.statusCode ?? 200);
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Register DID Connect routes on a Hono-compatible app.
|
|
129
|
-
*
|
|
130
|
-
* Routes registered are the same as attachExpress:
|
|
131
|
-
* - GET/POST `{prefix}/{action}/token`
|
|
132
|
-
* - GET `{prefix}/{action}/status`
|
|
133
|
-
* - GET `{prefix}/{action}/timeout`
|
|
134
|
-
* - GET `{prefix}/{action}/auth`
|
|
135
|
-
* - POST `{prefix}/{action}/auth`
|
|
136
|
-
* - GET `{prefix}/{action}/auth/submit`
|
|
137
|
-
*/
|
|
138
|
-
function attachHono({ app, prefix, action, handlers }) {
|
|
139
|
-
const pathname = `${prefix}/${action}/auth`;
|
|
140
|
-
const { generateSession, checkSession, expireSession, onAuthRequest, onAuthResponse, ensureContext, ensureSignedJson } = handlers;
|
|
141
|
-
app.use(`${prefix}/${action}/*`, async (c, next) => {
|
|
142
|
-
c.header("Access-Control-Allow-Origin", "*");
|
|
143
|
-
c.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
144
|
-
c.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
145
|
-
if (c.req.method === "OPTIONS") return c.text("", 204);
|
|
146
|
-
await next();
|
|
147
|
-
});
|
|
148
|
-
app.get(`${prefix}/${action}/token`, wrapHandler([], generateSession));
|
|
149
|
-
app.post(`${prefix}/${action}/token`, wrapHandler([], generateSession));
|
|
150
|
-
app.get(`${prefix}/${action}/status`, wrapHandler([ensureContext], checkSession));
|
|
151
|
-
app.get(`${prefix}/${action}/timeout`, wrapHandler([ensureContext], expireSession));
|
|
152
|
-
app.get(pathname, wrapHandler([ensureContext, ensureSignedJson], onAuthRequest));
|
|
153
|
-
app.post(pathname, wrapHandler([ensureContext, ensureSignedJson], onAuthResponse));
|
|
154
|
-
app.get(`${pathname}/submit`, wrapHandler([ensureContext, ensureSignedJson], onAuthResponse));
|
|
155
|
-
return {
|
|
156
|
-
generateSession,
|
|
157
|
-
expireSession,
|
|
158
|
-
checkSession,
|
|
159
|
-
onAuthRequest,
|
|
160
|
-
onAuthResponse
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
//#endregion
|
|
165
|
-
exports.attachHono = attachHono;
|
|
166
|
-
exports.createHonoRequest = createHonoRequest;
|
|
167
|
-
exports.createHonoResponse = createHonoResponse;
|
package/lib/adapters/hono.d.cts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ConnectRequest, ConnectResponse } from "../types.cjs";
|
|
2
|
-
import { HandlerFunctions } from "./express.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/hono.d.ts
|
|
5
|
-
interface HonoLikeApp {
|
|
6
|
-
get(path: string, handler: (c: any) => any): void;
|
|
7
|
-
post(path: string, handler: (c: any) => any): void;
|
|
8
|
-
use(path: string, handler: any): void;
|
|
9
|
-
}
|
|
10
|
-
interface AttachHonoOptions {
|
|
11
|
-
app: HonoLikeApp;
|
|
12
|
-
prefix: string;
|
|
13
|
-
action: string;
|
|
14
|
-
handlers: HandlerFunctions;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create a ConnectRequest from a Hono-like Context.
|
|
18
|
-
*
|
|
19
|
-
* @param c - Hono Context object
|
|
20
|
-
* @param bodyCache - Pre-parsed request body (since c.req.json() is async)
|
|
21
|
-
*/
|
|
22
|
-
declare function createHonoRequest(c: any, bodyCache?: any): ConnectRequest;
|
|
23
|
-
/**
|
|
24
|
-
* Create a ConnectResponse that buffers the handler's response.
|
|
25
|
-
* The Hono route wrapper reads the buffer via _getResult() to return c.json().
|
|
26
|
-
*/
|
|
27
|
-
declare function createHonoResponse(): ConnectResponse & {
|
|
28
|
-
_getResult(): {
|
|
29
|
-
statusCode: number;
|
|
30
|
-
body: any;
|
|
31
|
-
} | null;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Register DID Connect routes on a Hono-compatible app.
|
|
35
|
-
*
|
|
36
|
-
* Routes registered are the same as attachExpress:
|
|
37
|
-
* - GET/POST `{prefix}/{action}/token`
|
|
38
|
-
* - GET `{prefix}/{action}/status`
|
|
39
|
-
* - GET `{prefix}/{action}/timeout`
|
|
40
|
-
* - GET `{prefix}/{action}/auth`
|
|
41
|
-
* - POST `{prefix}/{action}/auth`
|
|
42
|
-
* - GET `{prefix}/{action}/auth/submit`
|
|
43
|
-
*/
|
|
44
|
-
declare function attachHono({
|
|
45
|
-
app,
|
|
46
|
-
prefix,
|
|
47
|
-
action,
|
|
48
|
-
handlers
|
|
49
|
-
}: AttachHonoOptions): {
|
|
50
|
-
generateSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
51
|
-
expireSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
52
|
-
checkSession: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
53
|
-
onAuthRequest: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
54
|
-
onAuthResponse: (req: ConnectRequest, res: ConnectResponse) => Promise<void>;
|
|
55
|
-
};
|
|
56
|
-
//#endregion
|
|
57
|
-
export { AttachHonoOptions, HonoLikeApp, attachHono, createHonoRequest, createHonoResponse };
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
3
|
-
const require_package$1 = require('../package.cjs');
|
|
4
|
-
let _ocap_wallet = require("@ocap/wallet");
|
|
5
|
-
let _arcblock_jwt = require("@arcblock/jwt");
|
|
6
|
-
_arcblock_jwt = require_rolldown_runtime.__toESM(_arcblock_jwt);
|
|
7
|
-
|
|
8
|
-
//#region src/authenticator/base.ts
|
|
9
|
-
const debug = require("debug")(`${require_package$1.default.name}:authenticator:base`);
|
|
10
|
-
const DEFAULT_CHAIN_INFO = {
|
|
11
|
-
id: "none",
|
|
12
|
-
host: "none",
|
|
13
|
-
type: "arcblock"
|
|
14
|
-
};
|
|
15
|
-
var BaseAuthenticator = class {
|
|
16
|
-
_validateWallet(wallet, canSign = true) {
|
|
17
|
-
if (!wallet) throw new Error("WalletAuthenticator cannot work without wallet");
|
|
18
|
-
if (typeof wallet === "function") return wallet;
|
|
19
|
-
if ((0, _ocap_wallet.isValid)(wallet, canSign)) {
|
|
20
|
-
if (!wallet.pk && wallet.publicKey) wallet.pk = wallet.publicKey;
|
|
21
|
-
if (!wallet.sk && wallet.secretKey) wallet.sk = wallet.secretKey;
|
|
22
|
-
return wallet;
|
|
23
|
-
}
|
|
24
|
-
if (canSign && !wallet.sk) throw new Error("WalletAuthenticator cannot work without wallet.sk");
|
|
25
|
-
if (!wallet.pk) throw new Error("WalletAuthenticator cannot work without wallet.pk");
|
|
26
|
-
if (!wallet.address) throw new Error("WalletAuthenticator cannot work without wallet.address");
|
|
27
|
-
try {
|
|
28
|
-
const fullWallet = (0, _ocap_wallet.fromJSON)(wallet);
|
|
29
|
-
if (!fullWallet.pk && fullWallet.publicKey) fullWallet.pk = fullWallet.publicKey;
|
|
30
|
-
if (!fullWallet.sk && fullWallet.secretKey) fullWallet.sk = fullWallet.secretKey;
|
|
31
|
-
return fullWallet;
|
|
32
|
-
} catch (_err) {
|
|
33
|
-
return wallet;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Verify a DID auth response sent from DID Wallet
|
|
38
|
-
*
|
|
39
|
-
* @method
|
|
40
|
-
* @param {object} data
|
|
41
|
-
* @param {string} [locale=en]
|
|
42
|
-
* @param {boolean} [enforceTimestamp=true]
|
|
43
|
-
* @returns Promise<boolean>
|
|
44
|
-
*/
|
|
45
|
-
async _verify(data, fieldPk, fieldInfo, locale = "en", enforceTimestamp = true) {
|
|
46
|
-
debug("verify", data, locale);
|
|
47
|
-
const errors = {
|
|
48
|
-
pkMissing: {
|
|
49
|
-
en: `${fieldPk} is required to complete auth`,
|
|
50
|
-
zh: `${fieldPk} 参数缺失`
|
|
51
|
-
},
|
|
52
|
-
tokenMissing: {
|
|
53
|
-
en: `${fieldInfo} is required to complete auth`,
|
|
54
|
-
zh: "JWT Token 参数缺失"
|
|
55
|
-
},
|
|
56
|
-
pkFormat: {
|
|
57
|
-
en: `${fieldPk} should be either base58 or base16 format`,
|
|
58
|
-
zh: `${fieldPk} 无法解析`
|
|
59
|
-
},
|
|
60
|
-
tokenInvalid: {
|
|
61
|
-
en: "Invalid JWT token",
|
|
62
|
-
zh: "签名无效"
|
|
63
|
-
},
|
|
64
|
-
timeInvalid: {
|
|
65
|
-
en: "JWT token expired, make sure your device time in sync with network",
|
|
66
|
-
zh: "签名中的时间戳无效,请确保设备和网络时间同步"
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const pk = data[fieldPk];
|
|
70
|
-
const info = data[fieldInfo];
|
|
71
|
-
if (!pk) throw new Error(errors.pkMissing[locale]);
|
|
72
|
-
if (!info) throw new Error(errors.tokenMissing[locale]);
|
|
73
|
-
if (!pk) throw new Error(errors.pkFormat[locale]);
|
|
74
|
-
if (!await _arcblock_jwt.verify(info, pk)) {
|
|
75
|
-
const isValidSig = await _arcblock_jwt.verify(info, pk, {
|
|
76
|
-
tolerance: 0,
|
|
77
|
-
enforceTimestamp: false
|
|
78
|
-
});
|
|
79
|
-
if (enforceTimestamp) {
|
|
80
|
-
const error = isValidSig ? errors.timeInvalid[locale] : errors.tokenInvalid[locale];
|
|
81
|
-
throw new Error(error);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return _arcblock_jwt.decode(info);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var base_default = BaseAuthenticator;
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
exports.DEFAULT_CHAIN_INFO = DEFAULT_CHAIN_INFO;
|
|
91
|
-
exports.default = base_default;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as Jwt from "@arcblock/jwt";
|
|
2
|
-
|
|
3
|
-
//#region src/authenticator/base.d.ts
|
|
4
|
-
declare const DEFAULT_CHAIN_INFO: {
|
|
5
|
-
id: string;
|
|
6
|
-
host: string;
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
|
-
declare class BaseAuthenticator {
|
|
10
|
-
_validateWallet(wallet: any, canSign?: boolean): any;
|
|
11
|
-
/**
|
|
12
|
-
* Verify a DID auth response sent from DID Wallet
|
|
13
|
-
*
|
|
14
|
-
* @method
|
|
15
|
-
* @param {object} data
|
|
16
|
-
* @param {string} [locale=en]
|
|
17
|
-
* @param {boolean} [enforceTimestamp=true]
|
|
18
|
-
* @returns Promise<boolean>
|
|
19
|
-
*/
|
|
20
|
-
_verify(data: any, fieldPk: string, fieldInfo: string, locale?: string, enforceTimestamp?: boolean): Promise<Jwt.JwtBody>;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { DEFAULT_CHAIN_INFO, BaseAuthenticator as default };
|