@opendatalabs/personal-server-ts-server 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-auth.d.ts.map +1 -1
- package/dist/api-auth.js +33 -44
- package/dist/api-auth.js.map +1 -1
- package/dist/routes/write-session.d.ts +4 -0
- package/dist/routes/write-session.d.ts.map +1 -1
- package/dist/routes/write-session.js +17 -91
- package/dist/routes/write-session.js.map +1 -1
- package/dist/ui/ps-lite-debug.js +5298 -4800
- package/package.json +3 -3
package/dist/api-auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-auth.d.ts","sourceRoot":"","sources":["../src/api-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EACV,yBAAyB,
|
|
1
|
+
{"version":3,"file":"api-auth.d.ts","sourceRoot":"","sources":["../src/api-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EACV,yBAAyB,EAG1B,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACvB,MAAM,6CAA6C,CAAC;AAMrD,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACxB,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACtC,WAAW,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,wBAAwB,CAAC;IACtC,WAAW,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IACjD,mBAAmB,CAAC,EAAE,uBAAuB,CAAC;IAC9C;;;;;;OAMG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AA6CD,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,iBAAiB,GACtB,yBAAyB,CAiI3B"}
|
package/dist/api-auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { authenticateRequest, } from "@opendatalabs/personal-server-ts-core/auth";
|
|
2
|
-
import { verifyDataReadPolicy
|
|
3
|
-
import { createInMemoryWriteProofReplayStore,
|
|
2
|
+
import { verifyDataReadPolicy } from "@opendatalabs/personal-server-ts-core/policy";
|
|
3
|
+
import { createInMemoryWriteProofReplayStore, createWriteSessionAuthorization, } from "@opendatalabs/personal-server-ts-core/write";
|
|
4
4
|
import { NotOwnerError, ProtocolError, UnregisteredBuilderError, } from "@opendatalabs/personal-server-ts-core/errors";
|
|
5
5
|
function serverNotConfigured() {
|
|
6
6
|
return new ProtocolError(500, "SERVER_NOT_CONFIGURED", "Server owner address not configured. Set VANA_MASTER_KEY_SIGNATURE environment variable.");
|
|
@@ -27,14 +27,24 @@ async function assertRegisteredBuilder(gateway, signer) {
|
|
|
27
27
|
return;
|
|
28
28
|
throw new UnregisteredBuilderError();
|
|
29
29
|
}
|
|
30
|
-
function bearerToken(request) {
|
|
31
|
-
const header = request.headers.get("authorization");
|
|
32
|
-
if (!header?.startsWith("Bearer "))
|
|
33
|
-
return null;
|
|
34
|
-
return header.slice(7);
|
|
35
|
-
}
|
|
36
30
|
export function createServerApiAuth(deps) {
|
|
37
31
|
const writeProofReplayStore = deps.writeProofReplayStore ?? createInMemoryWriteProofReplayStore();
|
|
32
|
+
// The write-session half of this port is protocol, not runtime: the browser
|
|
33
|
+
// build's adapters call the same factory, so a delegated write is checked
|
|
34
|
+
// identically wherever the Personal Server runs.
|
|
35
|
+
const writeSessions = createWriteSessionAuthorization({
|
|
36
|
+
serverOrigin: deps.serverOrigin,
|
|
37
|
+
serverOwner: deps.serverOwner,
|
|
38
|
+
sessionStore: deps.writeSessionStore,
|
|
39
|
+
replayStore: writeProofReplayStore,
|
|
40
|
+
policyPorts: {
|
|
41
|
+
authSessionVerifier: deps.gateway,
|
|
42
|
+
grantVerifier: deps.gateway,
|
|
43
|
+
runtimeAvailability: deps.runtimeAvailability,
|
|
44
|
+
// Fee seam intentionally not wired: builder writes are free in the
|
|
45
|
+
// demo slice (write fee mechanics undecided).
|
|
46
|
+
},
|
|
47
|
+
});
|
|
38
48
|
async function authorizeOwner(request) {
|
|
39
49
|
const result = await authenticate(request, deps);
|
|
40
50
|
if (result.isPolicyBypass)
|
|
@@ -58,47 +68,26 @@ export function createServerApiAuth(deps) {
|
|
|
58
68
|
* unknown bearer) falls through to the owner path unchanged.
|
|
59
69
|
*/
|
|
60
70
|
async function authorizeWrite(input) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
if (session) {
|
|
65
|
-
if (!deps.serverOwner)
|
|
66
|
-
throw serverNotConfigured();
|
|
67
|
-
const grant = await verifyDataWritePolicy({
|
|
68
|
-
signer: session.builderAddress,
|
|
69
|
-
grantId: session.grantId,
|
|
70
|
-
requestedScope: input.scope,
|
|
71
|
-
serverOwner: deps.serverOwner,
|
|
72
|
-
}, {
|
|
73
|
-
authSessionVerifier: deps.gateway,
|
|
74
|
-
grantVerifier: deps.gateway,
|
|
75
|
-
runtimeAvailability: deps.runtimeAvailability,
|
|
76
|
-
// Fee seam intentionally not wired: builder writes are free in
|
|
77
|
-
// the demo slice (write fee mechanics undecided).
|
|
78
|
-
});
|
|
79
|
-
// releaseProof is a rollback hook for the handler, never part of the
|
|
80
|
-
// stored attribution record.
|
|
81
|
-
const { releaseProof, ...attribution } = await verifyWriterAttribution({
|
|
82
|
-
request: input.request,
|
|
83
|
-
builderAddress: session.builderAddress,
|
|
84
|
-
grantId: grant.id,
|
|
85
|
-
serverOrigin: deps.serverOrigin,
|
|
86
|
-
replayStore: writeProofReplayStore,
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
builder: session.builderAddress,
|
|
90
|
-
grantId: grant.id,
|
|
91
|
-
grantScopes: grant.scopes ?? [],
|
|
92
|
-
attribution,
|
|
93
|
-
releaseProof,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
}
|
|
71
|
+
const delegated = await writeSessions.authorizeSessionWrite(input);
|
|
72
|
+
if (delegated)
|
|
73
|
+
return delegated;
|
|
97
74
|
await authorizeOwner(input.request);
|
|
98
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Identity-only recognition of a write-session caller: the bearer must
|
|
78
|
+
* resolve to a live session and the request must carry that builder's
|
|
79
|
+
* valid proof, but NO grant policy runs (there is no scope to run it
|
|
80
|
+
* against). Callers use it only to choose between error shapes, never to
|
|
81
|
+
* release data, so a revoked or narrowed grant getting a 404 instead of a
|
|
82
|
+
* 401 discloses nothing. Returns undefined for any other credential.
|
|
83
|
+
*/
|
|
84
|
+
async function authorizeWriteSession(request) {
|
|
85
|
+
return writeSessions.recognizeWriteSession(request);
|
|
86
|
+
}
|
|
99
87
|
return {
|
|
100
88
|
authorizeOwner,
|
|
101
89
|
authorizeWrite,
|
|
90
|
+
authorizeWriteSession,
|
|
102
91
|
async authorizeBuilderList(request) {
|
|
103
92
|
const result = await authenticate(request, deps);
|
|
104
93
|
if (result.isPolicyBypass ||
|
package/dist/api-auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-auth.js","sourceRoot":"","sources":["../src/api-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAGpB,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"api-auth.js","sourceRoot":"","sources":["../src/api-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,CAAC,IAAI,CAAC,WAAW;gBAAE,MAAM,mBAAmB,EAAE,CAAC;YAEnD,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC;gBAChD,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,oBAAoB,CACtC;gBACE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM;gBAC1B,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO;gBACrD,cAAc,EAAE,KAAK,CAAC,KAAK;gBAC3B,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,aAAa,EAAE,MAAM,IAAI,SAAS;gBAC1D,WAAW,EAAE,IAAI,CAAC,WAAW;aAC9B,EACD;gBACE,mBAAmB,EAAE,IAAI,CAAC,OAAO;gBACjC,aAAa,EAAE,IAAI,CAAC,OAAO;gBAC3B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;aAC9C,CACF,CAAC;YACF,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC5D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* the EXISTING ingest endpoint (POST /v1/data/:scope) — see api-auth.ts
|
|
8
8
|
* authorizeWrite. The PS keeps signing AddData as the owner; the builder
|
|
9
9
|
* never holds the owner key.
|
|
10
|
+
*
|
|
11
|
+
* The handshake itself is runtime-agnostic and lives in core
|
|
12
|
+
* (write/route.ts), so the browser build mounts the identical logic. This file
|
|
13
|
+
* is only the Hono mounting and this build's dependency wiring.
|
|
10
14
|
*/
|
|
11
15
|
import { Hono } from "hono";
|
|
12
16
|
import type { Logger } from "pino";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-session.d.ts","sourceRoot":"","sources":["../../src/routes/write-session.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"write-session.d.ts","sourceRoot":"","sources":["../../src/routes/write-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACvB,MAAM,6CAA6C,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACtC,WAAW,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5B,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,iBAAiB,CAAC;IAChC,sDAAsD;IACtD,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI,CAqBpE"}
|
|
@@ -7,102 +7,28 @@
|
|
|
7
7
|
* the EXISTING ingest endpoint (POST /v1/data/:scope) — see api-auth.ts
|
|
8
8
|
* authorizeWrite. The PS keeps signing AddData as the owner; the builder
|
|
9
9
|
* never holds the owner key.
|
|
10
|
+
*
|
|
11
|
+
* The handshake itself is runtime-agnostic and lives in core
|
|
12
|
+
* (write/route.ts), so the browser build mounts the identical logic. This file
|
|
13
|
+
* is only the Hono mounting and this build's dependency wiring.
|
|
10
14
|
*/
|
|
11
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
12
15
|
import { Hono } from "hono";
|
|
13
|
-
import {
|
|
14
|
-
import { ProtocolError } from "@opendatalabs/personal-server-ts-core/errors";
|
|
15
|
-
import { createInMemoryWriteProofReplayStore, createWriteSession, } from "@opendatalabs/personal-server-ts-core/write";
|
|
16
|
-
function jsonError(status, errorCode, message) {
|
|
17
|
-
return {
|
|
18
|
-
error: { code: status, errorCode, message },
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Only ProtocolErrors are client-facing. Anything else (gateway, store,
|
|
23
|
-
* runtime failures) is logged with its cause and answered generically so
|
|
24
|
-
* internal details never reach the caller. Same mapping as the core data
|
|
25
|
-
* handler.
|
|
26
|
-
*/
|
|
27
|
-
function internalError(logger, err, stage) {
|
|
28
|
-
logger.error({ err, stage }, "Write session handshake failed with an unexpected error");
|
|
29
|
-
return jsonError(500, "INTERNAL_ERROR", "Internal server error");
|
|
30
|
-
}
|
|
16
|
+
import { createInMemoryWriteProofReplayStore, handleWriteSessionRequest, } from "@opendatalabs/personal-server-ts-core/write";
|
|
31
17
|
export function writeSessionRoutes(deps) {
|
|
32
18
|
const app = new Hono();
|
|
33
19
|
const proofReplayStore = deps.proofReplayStore ?? createInMemoryWriteProofReplayStore();
|
|
34
|
-
app.post("/session",
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
accessToken: deps.accessToken,
|
|
47
|
-
sessionTokenVerifier: deps.tokenStore,
|
|
48
|
-
serverOwner: deps.serverOwner,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
if (!(err instanceof ProtocolError)) {
|
|
53
|
-
return c.json(internalError(deps.logger, err, "authenticate"), 500);
|
|
54
|
-
}
|
|
55
|
-
return c.json(jsonError(401, "WRITE_SESSION_AUTH_FAILED", err.message), 401);
|
|
56
|
-
}
|
|
57
|
-
if (authResult.mechanism !== "web3-signed") {
|
|
58
|
-
return c.json(jsonError(401, "WRITE_SESSION_PROOF_REQUIRED", "POST /v1/write/session requires a Web3Signed proof signed by the builder key"), 401);
|
|
59
|
-
}
|
|
60
|
-
const grantId = authResult.auth.payload.grantId;
|
|
61
|
-
if (!grantId) {
|
|
62
|
-
return c.json(jsonError(400, "GRANT_ID_REQUIRED", "The Web3Signed proof must carry a grantId (the write-grant issued to the builder)"), 400);
|
|
63
|
-
}
|
|
64
|
-
// Replay guard: bind to a digest of the exact proof header, remembered
|
|
65
|
-
// until the proof's own expiry (a replay only matters while still valid).
|
|
66
|
-
const proofHeader = c.req.raw.headers.get("authorization") ?? "";
|
|
67
|
-
const proofId = createHash("sha256").update(proofHeader).digest("hex");
|
|
68
|
-
const expSec = authResult.auth.payload.exp;
|
|
69
|
-
const expiresAtMs = (typeof expSec === "number"
|
|
70
|
-
? expSec
|
|
71
|
-
: Math.floor(Date.now() / 1000) + 300) * 1000;
|
|
72
|
-
try {
|
|
73
|
-
const session = await createWriteSession({
|
|
74
|
-
builderAddress: authResult.auth.signer,
|
|
75
|
-
grantId,
|
|
76
|
-
proof: { id: proofId, expiresAtMs },
|
|
77
|
-
}, {
|
|
78
|
-
store: deps.sessionStore,
|
|
79
|
-
authSessionVerifier: deps.gateway,
|
|
80
|
-
grantVerifier: deps.gateway,
|
|
81
|
-
serverOwner: deps.serverOwner,
|
|
82
|
-
randomToken: () => `vana_write_${randomBytes(32).toString("hex")}`,
|
|
83
|
-
replayStore: proofReplayStore,
|
|
84
|
-
});
|
|
85
|
-
deps.logger.info({
|
|
86
|
-
builder: authResult.auth.signer,
|
|
87
|
-
grantId: session.grantId,
|
|
88
|
-
writeScopes: session.writeScopes,
|
|
89
|
-
}, "Write session minted");
|
|
90
|
-
return c.json({
|
|
91
|
-
access_token: session.accessToken,
|
|
92
|
-
token_type: "Bearer",
|
|
93
|
-
expires_in: session.expiresInSeconds,
|
|
94
|
-
// Write patterns, prefix stripped — what POST /v1/data/:scope will
|
|
95
|
-
// accept under this token.
|
|
96
|
-
scope: session.writeScopes.join(" "),
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
if (err instanceof ProtocolError) {
|
|
101
|
-
return c.json(err.toJSON(), err.code);
|
|
102
|
-
}
|
|
103
|
-
return c.json(internalError(deps.logger, err, "create-session"), 500);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
20
|
+
app.post("/session", (c) => handleWriteSessionRequest(c.req.raw, {
|
|
21
|
+
serverOrigin: deps.serverOrigin,
|
|
22
|
+
serverOwner: deps.serverOwner,
|
|
23
|
+
sessionStore: deps.sessionStore,
|
|
24
|
+
replayStore: proofReplayStore,
|
|
25
|
+
authSessionVerifier: deps.gateway,
|
|
26
|
+
grantVerifier: deps.gateway,
|
|
27
|
+
devToken: deps.devToken,
|
|
28
|
+
accessToken: deps.accessToken,
|
|
29
|
+
tokenStore: deps.tokenStore,
|
|
30
|
+
logger: deps.logger,
|
|
31
|
+
}));
|
|
106
32
|
return app;
|
|
107
33
|
}
|
|
108
34
|
//# sourceMappingURL=write-session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-session.js","sourceRoot":"","sources":["../../src/routes/write-session.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"write-session.js","sourceRoot":"","sources":["../../src/routes/write-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG5B,OAAO,EACL,mCAAmC,EACnC,yBAAyB,GAG1B,MAAM,6CAA6C,CAAC;AAoBrD,MAAM,UAAU,kBAAkB,CAAC,IAA2B;IAC5D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,gBAAgB,GACpB,IAAI,CAAC,gBAAgB,IAAI,mCAAmC,EAAE,CAAC;IAEjE,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CACzB,yBAAyB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE;QACnC,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,WAAW,EAAE,gBAAgB;QAC7B,mBAAmB,EAAE,IAAI,CAAC,OAAO;QACjC,aAAa,EAAE,IAAI,CAAC,OAAO;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CACH,CAAC;IAEF,OAAO,GAAG,CAAC;AACb,CAAC"}
|