@agimon-ai/po-identity 0.0.2-alpha.92 → 0.0.2-alpha.94
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
let _agimon_ai_po_core = require("@agimon-ai/po-core");
|
|
2
|
+
let _agimon_ai_po_web_security_deviceProof = require("@agimon-ai/po-web-security/deviceProof");
|
|
2
3
|
//#region src/services/identityHome/globalTier.ts
|
|
3
4
|
var GlobalTierRefusal = class extends Error {
|
|
4
5
|
status;
|
|
@@ -16,7 +17,7 @@ async function settingsHash(yaml) {
|
|
|
16
17
|
* Issuer-held global tier: per-membership settings and host visibility. Visibility lives beside the
|
|
17
18
|
* signed C6 host entries and never changes their bytes; it only filters what discovery returns.
|
|
18
19
|
*/
|
|
19
|
-
function createGlobalTier(database, now, membership) {
|
|
20
|
+
function createGlobalTier(database, now, membership, issuer) {
|
|
20
21
|
async function readMemberSettings(subject, org) {
|
|
21
22
|
return database.transaction(async (tx) => {
|
|
22
23
|
await membership(tx, subject, org);
|
|
@@ -85,8 +86,8 @@ function createGlobalTier(database, now, membership) {
|
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
|
-
/**
|
|
89
|
-
async function setHostVisibility(subject, org, hostId, visibility) {
|
|
89
|
+
/** Role checks and a one-use authorization from the hub's live pinned owner device are both required. */
|
|
90
|
+
async function setHostVisibility(subject, org, hostId, visibility, authorization) {
|
|
90
91
|
if (visibility !== "org" && visibility !== "member") throw new GlobalTierRefusal(400, "Invalid visibility");
|
|
91
92
|
return database.transaction(async (tx) => {
|
|
92
93
|
const role = await membership(tx, subject, org);
|
|
@@ -94,6 +95,13 @@ function createGlobalTier(database, now, membership) {
|
|
|
94
95
|
const manager = role === "owner" || role === "admin";
|
|
95
96
|
if (!host || !manager && host.subject !== subject) throw new GlobalTierRefusal(404, "Host unavailable");
|
|
96
97
|
if (visibility === "org" && !manager) throw new GlobalTierRefusal(403, "Owner or admin required");
|
|
98
|
+
const proof = authorization;
|
|
99
|
+
const p = proof?.payload;
|
|
100
|
+
const device = p && typeof p.deviceKeyId === "string" && await tx.get("SELECT d.publicKey,h.enrollmentGeneration FROM identity_hub h JOIN identity_device d ON d.id=h.deviceKeyId AND d.subject=h.subject WHERE h.hostId=? AND h.subject=? AND h.revoked=0 AND d.revoked=0 AND d.id=? AND (d.organizationId IS NULL OR d.organizationId=?)", hostId, subject, p.deviceKeyId, org);
|
|
101
|
+
if (!p || !device || p.issuer !== issuer || p.subject !== subject || p.networkId !== org || p.hostId !== hostId || p.visibility !== visibility || p.enrollmentGeneration !== device.enrollmentGeneration || typeof p.nonce !== "string" || !/^[A-Za-z0-9_-]{16,128}$/.test(p.nonce) || p.expiresAt - p.issuedAt > 6e4 || !(0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(device.publicKey, "po/host-visibility/v1", proof, now())) throw new GlobalTierRefusal(403, "Pinned-device visibility authorization required");
|
|
102
|
+
if (await tx.get("SELECT nonce FROM identity_nonce WHERE subject=? AND nonce=?", subject, p.nonce)) throw new GlobalTierRefusal(403, "Visibility authorization replay");
|
|
103
|
+
await tx.run("DELETE FROM identity_nonce WHERE expiresAt<?", now() - 3e4);
|
|
104
|
+
await tx.run("INSERT INTO identity_nonce VALUES (?,?,?)", subject, p.nonce, p.expiresAt);
|
|
97
105
|
const updatedAt = now();
|
|
98
106
|
await tx.run("INSERT INTO host_visibility (org, hostId, visibility, setBy, updatedAt) VALUES (?, ?, ?, ?, ?) ON CONFLICT(org, hostId) DO UPDATE SET visibility = excluded.visibility, setBy = excluded.setBy, updatedAt = excluded.updatedAt", org, hostId, visibility, subject, updatedAt);
|
|
99
107
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { nonPortableConfigYaml } from "@agimon-ai/po-core";
|
|
2
|
+
import { verifyEnvelope } from "@agimon-ai/po-web-security/deviceProof";
|
|
2
3
|
//#region src/services/identityHome/globalTier.ts
|
|
3
4
|
var GlobalTierRefusal = class extends Error {
|
|
4
5
|
status;
|
|
@@ -16,7 +17,7 @@ async function settingsHash(yaml) {
|
|
|
16
17
|
* Issuer-held global tier: per-membership settings and host visibility. Visibility lives beside the
|
|
17
18
|
* signed C6 host entries and never changes their bytes; it only filters what discovery returns.
|
|
18
19
|
*/
|
|
19
|
-
function createGlobalTier(database, now, membership) {
|
|
20
|
+
function createGlobalTier(database, now, membership, issuer) {
|
|
20
21
|
async function readMemberSettings(subject, org) {
|
|
21
22
|
return database.transaction(async (tx) => {
|
|
22
23
|
await membership(tx, subject, org);
|
|
@@ -85,8 +86,8 @@ function createGlobalTier(database, now, membership) {
|
|
|
85
86
|
}
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
|
-
/**
|
|
89
|
-
async function setHostVisibility(subject, org, hostId, visibility) {
|
|
89
|
+
/** Role checks and a one-use authorization from the hub's live pinned owner device are both required. */
|
|
90
|
+
async function setHostVisibility(subject, org, hostId, visibility, authorization) {
|
|
90
91
|
if (visibility !== "org" && visibility !== "member") throw new GlobalTierRefusal(400, "Invalid visibility");
|
|
91
92
|
return database.transaction(async (tx) => {
|
|
92
93
|
const role = await membership(tx, subject, org);
|
|
@@ -94,6 +95,13 @@ function createGlobalTier(database, now, membership) {
|
|
|
94
95
|
const manager = role === "owner" || role === "admin";
|
|
95
96
|
if (!host || !manager && host.subject !== subject) throw new GlobalTierRefusal(404, "Host unavailable");
|
|
96
97
|
if (visibility === "org" && !manager) throw new GlobalTierRefusal(403, "Owner or admin required");
|
|
98
|
+
const proof = authorization;
|
|
99
|
+
const p = proof?.payload;
|
|
100
|
+
const device = p && typeof p.deviceKeyId === "string" && await tx.get("SELECT d.publicKey,h.enrollmentGeneration FROM identity_hub h JOIN identity_device d ON d.id=h.deviceKeyId AND d.subject=h.subject WHERE h.hostId=? AND h.subject=? AND h.revoked=0 AND d.revoked=0 AND d.id=? AND (d.organizationId IS NULL OR d.organizationId=?)", hostId, subject, p.deviceKeyId, org);
|
|
101
|
+
if (!p || !device || p.issuer !== issuer || p.subject !== subject || p.networkId !== org || p.hostId !== hostId || p.visibility !== visibility || p.enrollmentGeneration !== device.enrollmentGeneration || typeof p.nonce !== "string" || !/^[A-Za-z0-9_-]{16,128}$/.test(p.nonce) || p.expiresAt - p.issuedAt > 6e4 || !verifyEnvelope(device.publicKey, "po/host-visibility/v1", proof, now())) throw new GlobalTierRefusal(403, "Pinned-device visibility authorization required");
|
|
102
|
+
if (await tx.get("SELECT nonce FROM identity_nonce WHERE subject=? AND nonce=?", subject, p.nonce)) throw new GlobalTierRefusal(403, "Visibility authorization replay");
|
|
103
|
+
await tx.run("DELETE FROM identity_nonce WHERE expiresAt<?", now() - 3e4);
|
|
104
|
+
await tx.run("INSERT INTO identity_nonce VALUES (?,?,?)", subject, p.nonce, p.expiresAt);
|
|
97
105
|
const updatedAt = now();
|
|
98
106
|
await tx.run("INSERT INTO host_visibility (org, hostId, visibility, setBy, updatedAt) VALUES (?, ?, ?, ?, ?) ON CONFLICT(org, hostId) DO UPDATE SET visibility = excluded.visibility, setBy = excluded.setBy, updatedAt = excluded.updatedAt", org, hostId, visibility, subject, updatedAt);
|
|
99
107
|
return {
|
|
@@ -240,7 +240,7 @@ async function createIdentityHome(config, ports) {
|
|
|
240
240
|
database: require_index$1.poAdapter(database)
|
|
241
241
|
});
|
|
242
242
|
const roster = await require_roster.createIssuerRoster(database, config.issuer, config.jwtKeyWrap, now, membership);
|
|
243
|
-
const globalTier = require_globalTier.createGlobalTier(database, now, membership);
|
|
243
|
+
const globalTier = require_globalTier.createGlobalTier(database, now, membership, config.issuer);
|
|
244
244
|
async function membership(tx, subject, org) {
|
|
245
245
|
const person = await tx.get("SELECT id FROM user WHERE id = ?", subject);
|
|
246
246
|
const member = await tx.get("SELECT role FROM member WHERE userId = ? AND organizationId = ?", subject, org);
|
|
@@ -1051,7 +1051,7 @@ async function createIdentityHome(config, ports) {
|
|
|
1051
1051
|
if (visibility && request.method === "PUT") {
|
|
1052
1052
|
const subject = await requestSubject(request, visibility[1], true);
|
|
1053
1053
|
const body = await readBody(request);
|
|
1054
|
-
return Response.json(await globalTier.setHostVisibility(subject, visibility[1], visibility[2], body?.visibility));
|
|
1054
|
+
return Response.json(await globalTier.setHostVisibility(subject, visibility[1], visibility[2], body?.visibility, body?.authorization));
|
|
1055
1055
|
}
|
|
1056
1056
|
if (visible || visibility) return new Response("Method not allowed", { status: 405 });
|
|
1057
1057
|
if (!match && !own && !remove) return new Response("not found", { status: 404 });
|
|
@@ -1071,6 +1071,23 @@ async function createIdentityHome(config, ports) {
|
|
|
1071
1071
|
if (error instanceof SyntaxError || error instanceof TypeError) return Response.json({ error: "Invalid roster request" }, { status: 400 });
|
|
1072
1072
|
throw error;
|
|
1073
1073
|
}
|
|
1074
|
+
if (path === "/api/auth/account-status" && request.method === "GET") {
|
|
1075
|
+
const origin = request.headers.get("origin");
|
|
1076
|
+
if (origin && origin !== config.issuer && origin !== "po://") return Response.json({ signedIn: false }, {
|
|
1077
|
+
status: 403,
|
|
1078
|
+
headers: { "cache-control": "no-store" }
|
|
1079
|
+
});
|
|
1080
|
+
const session = await auth.api.getSession({ headers: request.headers });
|
|
1081
|
+
return Response.json(session ? {
|
|
1082
|
+
signedIn: true,
|
|
1083
|
+
issuer: config.issuer,
|
|
1084
|
+
email: session.user.email,
|
|
1085
|
+
org: await personalOrg(session.user.id)
|
|
1086
|
+
} : { signedIn: false }, {
|
|
1087
|
+
status: session ? 200 : 401,
|
|
1088
|
+
headers: { "cache-control": "no-store" }
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1074
1091
|
if (path === "/api/account/settings") try {
|
|
1075
1092
|
const query = new URL(request.url).searchParams;
|
|
1076
1093
|
const org = query.get("org") ?? "";
|
|
@@ -240,7 +240,7 @@ async function createIdentityHome(config, ports) {
|
|
|
240
240
|
database: poAdapter(database)
|
|
241
241
|
});
|
|
242
242
|
const roster = await createIssuerRoster(database, config.issuer, config.jwtKeyWrap, now, membership);
|
|
243
|
-
const globalTier = createGlobalTier(database, now, membership);
|
|
243
|
+
const globalTier = createGlobalTier(database, now, membership, config.issuer);
|
|
244
244
|
async function membership(tx, subject, org) {
|
|
245
245
|
const person = await tx.get("SELECT id FROM user WHERE id = ?", subject);
|
|
246
246
|
const member = await tx.get("SELECT role FROM member WHERE userId = ? AND organizationId = ?", subject, org);
|
|
@@ -1051,7 +1051,7 @@ async function createIdentityHome(config, ports) {
|
|
|
1051
1051
|
if (visibility && request.method === "PUT") {
|
|
1052
1052
|
const subject = await requestSubject(request, visibility[1], true);
|
|
1053
1053
|
const body = await readBody(request);
|
|
1054
|
-
return Response.json(await globalTier.setHostVisibility(subject, visibility[1], visibility[2], body?.visibility));
|
|
1054
|
+
return Response.json(await globalTier.setHostVisibility(subject, visibility[1], visibility[2], body?.visibility, body?.authorization));
|
|
1055
1055
|
}
|
|
1056
1056
|
if (visible || visibility) return new Response("Method not allowed", { status: 405 });
|
|
1057
1057
|
if (!match && !own && !remove) return new Response("not found", { status: 404 });
|
|
@@ -1071,6 +1071,23 @@ async function createIdentityHome(config, ports) {
|
|
|
1071
1071
|
if (error instanceof SyntaxError || error instanceof TypeError) return Response.json({ error: "Invalid roster request" }, { status: 400 });
|
|
1072
1072
|
throw error;
|
|
1073
1073
|
}
|
|
1074
|
+
if (path === "/api/auth/account-status" && request.method === "GET") {
|
|
1075
|
+
const origin = request.headers.get("origin");
|
|
1076
|
+
if (origin && origin !== config.issuer && origin !== "po://") return Response.json({ signedIn: false }, {
|
|
1077
|
+
status: 403,
|
|
1078
|
+
headers: { "cache-control": "no-store" }
|
|
1079
|
+
});
|
|
1080
|
+
const session = await auth.api.getSession({ headers: request.headers });
|
|
1081
|
+
return Response.json(session ? {
|
|
1082
|
+
signedIn: true,
|
|
1083
|
+
issuer: config.issuer,
|
|
1084
|
+
email: session.user.email,
|
|
1085
|
+
org: await personalOrg(session.user.id)
|
|
1086
|
+
} : { signedIn: false }, {
|
|
1087
|
+
status: session ? 200 : 401,
|
|
1088
|
+
headers: { "cache-control": "no-store" }
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1074
1091
|
if (path === "/api/account/settings") try {
|
|
1075
1092
|
const query = new URL(request.url).searchParams;
|
|
1076
1093
|
const org = query.get("org") ?? "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-identity",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.94",
|
|
4
4
|
"description": "Portable identity home for Po",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@agimon-ai/po-core": "0.0.0-alpha.
|
|
51
|
-
"@agimon-ai/po-web-security": "0.0.0-alpha.
|
|
50
|
+
"@agimon-ai/po-core": "0.0.0-alpha.147",
|
|
51
|
+
"@agimon-ai/po-web-security": "0.0.0-alpha.147",
|
|
52
52
|
"@better-auth/expo": "1.7.12",
|
|
53
53
|
"@better-auth/passkey": "1.7.12",
|
|
54
54
|
"@better-auth/sso": "1.7.12",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"jose": "6.2.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@agimon-ai/po-network": "0.0.2-alpha.
|
|
62
|
-
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.
|
|
61
|
+
"@agimon-ai/po-network": "0.0.2-alpha.94",
|
|
62
|
+
"@agimon-ai/vibe-lint-plugin-po-core": "0.0.0-alpha.147",
|
|
63
63
|
"@types/node": "26.4.1",
|
|
64
64
|
"tsdown": "0.23.0",
|
|
65
65
|
"typescript": "7.0.2",
|