@kubun/plugin-p2p 0.10.0 → 0.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/lib/context/delegation.js +130 -1
- package/lib/context/group.js +1319 -1
- package/lib/context/hub.js +150 -1
- package/lib/context/join.js +80 -1
- package/lib/context/sync.js +19 -1
- package/lib/context/types.d.ts +12 -3
- package/lib/context/types.js +28 -1
- package/lib/groups/admin-roster.d.ts +130 -0
- package/lib/groups/admin-roster.js +184 -0
- package/lib/groups/broadcast-codec.js +6 -1
- package/lib/groups/broadcast.d.ts +122 -38
- package/lib/groups/broadcast.js +627 -1
- package/lib/groups/circle-projection.d.ts +122 -0
- package/lib/groups/circle-projection.js +288 -0
- package/lib/groups/circle-reducers.d.ts +178 -0
- package/lib/groups/circle-reducers.js +198 -0
- package/lib/groups/events.d.ts +7 -2
- package/lib/groups/events.js +10 -1
- package/lib/groups/group-anchor.d.ts +63 -0
- package/lib/groups/group-anchor.js +107 -0
- package/lib/groups/group-crypto.d.ts +19 -0
- package/lib/groups/group-crypto.js +85 -0
- package/lib/groups/group-handle-registry.d.ts +69 -2
- package/lib/groups/group-handle-registry.js +243 -1
- package/lib/groups/group-handlers.d.ts +29 -0
- package/lib/groups/group-handlers.js +92 -0
- package/lib/groups/group-health-monitor.d.ts +56 -0
- package/lib/groups/group-health-monitor.js +139 -0
- package/lib/groups/group-mls.d.ts +35 -0
- package/lib/groups/group-mls.js +164 -0
- package/lib/groups/group-peer-manager.d.ts +108 -0
- package/lib/groups/group-peer-manager.js +344 -0
- package/lib/groups/group-protocols.d.ts +297 -0
- package/lib/groups/group-protocols.js +174 -0
- package/lib/groups/invite-payload.d.ts +1 -1
- package/lib/groups/invite-payload.js +26 -1
- package/lib/groups/join-utils.d.ts +1 -0
- package/lib/groups/join-utils.js +104 -1
- package/lib/groups/ledger-affected-events.d.ts +15 -0
- package/lib/groups/ledger-affected-events.js +96 -0
- package/lib/groups/ledger-entry.d.ts +37 -0
- package/lib/groups/ledger-entry.js +56 -0
- package/lib/groups/ledger-fold.d.ts +56 -0
- package/lib/groups/ledger-fold.js +53 -0
- package/lib/groups/manager.d.ts +29 -71
- package/lib/groups/manager.js +281 -1
- package/lib/groups/mls-codec.d.ts +1 -1
- package/lib/groups/mls-codec.js +18 -1
- package/lib/groups/mls-encryptor.d.ts +2 -2
- package/lib/groups/mls-encryptor.js +30 -1
- package/lib/groups/mls-group-handle.d.ts +1 -1
- package/lib/groups/mls-group-handle.js +10 -1
- package/lib/groups/mls-json.js +17 -1
- package/lib/groups/mls-receive-errors.d.ts +29 -0
- package/lib/groups/mls-receive-errors.js +42 -0
- package/lib/groups/mls-state.d.ts +1 -1
- package/lib/groups/mls-state.js +56 -1
- package/lib/groups/store-received-grant.d.ts +4 -1
- package/lib/groups/store-received-grant.js +116 -1
- package/lib/groups/store-received-revocation.d.ts +3 -3
- package/lib/groups/store-received-revocation.js +82 -1
- package/lib/hub/ack-backoff.d.ts +22 -0
- package/lib/hub/ack-backoff.js +88 -0
- package/lib/hub/did-observing-transport.d.ts +13 -2
- package/lib/hub/did-observing-transport.js +126 -1
- package/lib/hub/errors.d.ts +4 -8
- package/lib/hub/errors.js +33 -1
- package/lib/hub/http-client.d.ts +28 -3
- package/lib/hub/http-client.js +32 -1
- package/lib/hub/hub-like.d.ts +24 -0
- package/lib/hub/hub-like.js +535 -0
- package/lib/hub/manager.d.ts +5 -4
- package/lib/hub/manager.js +198 -1
- package/lib/hub/wiring.d.ts +28 -41
- package/lib/hub/wiring.js +132 -1
- package/lib/index.d.ts +29 -13
- package/lib/index.js +392 -1
- package/lib/protocol.d.ts +8 -1
- package/lib/protocol.js +251 -1
- package/lib/schema.d.ts +2 -1
- package/lib/schema.js +471 -2
- package/lib/sync/authorize.d.ts +25 -0
- package/lib/sync/authorize.js +73 -0
- package/lib/sync/broadcast-queue.js +183 -1
- package/lib/sync/broadcast-sender.js +179 -1
- package/lib/sync/catalog-scope.js +68 -1
- package/lib/sync/errors.d.ts +12 -0
- package/lib/sync/errors.js +19 -0
- package/lib/sync/forwarder.js +277 -1
- package/lib/sync/handlers.d.ts +3 -22
- package/lib/sync/handlers.js +160 -1
- package/lib/sync/hub-tunnel-sync-listener.d.ts +9 -3
- package/lib/sync/hub-tunnel-sync-listener.js +172 -1
- package/lib/sync/hub-tunnel-sync-provider.d.ts +14 -14
- package/lib/sync/hub-tunnel-sync-provider.js +64 -1
- package/lib/sync/merkle-apply.d.ts +5 -0
- package/lib/sync/merkle-apply.js +194 -1
- package/lib/sync/merkle-channel.d.ts +19 -0
- package/lib/sync/merkle-channel.js +182 -1
- package/lib/sync/merkle-tree.js +120 -1
- package/lib/sync/peer-registry.d.ts +8 -1
- package/lib/sync/peer-registry.js +107 -1
- package/lib/sync/receive-access-gate.js +24 -1
- package/lib/sync/scope-resolver.js +41 -1
- package/lib/sync/sync-client.d.ts +5 -3
- package/lib/sync/sync-client.js +192 -1
- package/lib/sync/sync-manager.d.ts +2 -2
- package/lib/sync/sync-manager.js +272 -1
- package/lib/types.d.ts +41 -0
- package/lib/types.js +2 -1
- package/lib/util/mutex.js +10 -1
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +21 -0
- package/package.json +48 -41
- package/lib/groups/broadcast-service.d.ts +0 -189
- package/lib/groups/broadcast-service.js +0 -1
- package/lib/groups/wire-frame.d.ts +0 -32
- package/lib/groups/wire-frame.js +0 -1
- package/lib/hub/connection-pool.d.ts +0 -43
- package/lib/hub/connection-pool.js +0 -1
- package/lib/hub/forward-remote-broadcast.d.ts +0 -15
- package/lib/hub/forward-remote-broadcast.js +0 -1
- package/lib/hub/group-channel.d.ts +0 -67
- package/lib/hub/group-channel.js +0 -1
- package/lib/hub/hub-connection.d.ts +0 -96
- package/lib/hub/hub-connection.js +0 -1
- package/lib/hub/receive-handler.d.ts +0 -33
- package/lib/hub/receive-handler.js +0 -1
- package/lib/hub/relay-manager.d.ts +0 -127
- package/lib/hub/relay-manager.js +0 -1
- package/lib/hub/send-handler.d.ts +0 -40
- package/lib/hub/send-handler.js +0 -1
- package/lib/hub/tunnel-inbox.d.ts +0 -20
- package/lib/hub/tunnel-inbox.js +0 -1
- package/lib/hub/wait-for-gate.d.ts +0 -14
- package/lib/hub/wait-for-gate.js +0 -1
|
@@ -1 +1,130 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { getDelegationStore as resolveDelegationStore } from '@kubun/store-delegation';
|
|
2
|
+
import { getGraphStore as resolveGraphStore } from '@kubun/store-graph';
|
|
3
|
+
import { getP2PStore as resolveP2PStore } from '@kubun/store-p2p';
|
|
4
|
+
import { GraphQLError } from 'graphql';
|
|
5
|
+
export function createDelegationContext(_ctx, deps) {
|
|
6
|
+
let p2pStorePromise = null;
|
|
7
|
+
let delegationStorePromise = null;
|
|
8
|
+
let graphStorePromise = null;
|
|
9
|
+
const getP2PStore = ()=>p2pStorePromise ??= resolveP2PStore(deps.stores);
|
|
10
|
+
const getDelegationStore = ()=>delegationStorePromise ??= resolveDelegationStore(deps.stores);
|
|
11
|
+
const getGraphStore = ()=>graphStorePromise ??= resolveGraphStore(deps.stores);
|
|
12
|
+
return {
|
|
13
|
+
listOwnTokens: async ({ viewerDID, grantor, covers })=>{
|
|
14
|
+
const delegationStore = await getDelegationStore();
|
|
15
|
+
const atTime = Math.floor(Date.now() / 1000);
|
|
16
|
+
const rows = await delegationStore.getHeldTokens({
|
|
17
|
+
audience: viewerDID,
|
|
18
|
+
atTime
|
|
19
|
+
});
|
|
20
|
+
const filteredByGrantor = grantor != null ? rows.filter((row)=>row.grantor === grantor) : rows;
|
|
21
|
+
let coverageFiltered = filteredByGrantor;
|
|
22
|
+
if (covers != null && (covers.docID != null || covers.modelID != null)) {
|
|
23
|
+
coverageFiltered = await applyCoverageFilter(filteredByGrantor, covers, getGraphStore);
|
|
24
|
+
}
|
|
25
|
+
return coverageFiltered.map(rowToData);
|
|
26
|
+
},
|
|
27
|
+
listOwnRevokedTokens: async ({ viewerDID, grantor })=>{
|
|
28
|
+
const [delegationStore, p2pStore] = await Promise.all([
|
|
29
|
+
getDelegationStore(),
|
|
30
|
+
getP2PStore()
|
|
31
|
+
]);
|
|
32
|
+
const rows = await delegationStore.getHeldRevocations({
|
|
33
|
+
audience: viewerDID
|
|
34
|
+
});
|
|
35
|
+
const filtered = grantor != null ? rows.filter((row)=>row.grantor === grantor) : rows;
|
|
36
|
+
// The core revocation row carries no group; enrich each with the group the
|
|
37
|
+
// cap was granted in via the p2p `jti` edge. A held revocation always has
|
|
38
|
+
// a locally-held cap, and every locally-stored cap wrote an edge at grant
|
|
39
|
+
// time, so the lookup resolves; a row with no edge is dropped rather than
|
|
40
|
+
// reported with an unknown group.
|
|
41
|
+
const jtis = filtered.map((row)=>row.jti);
|
|
42
|
+
const groupByJTI = await p2pStore.getGroupIDsByJTIs(jtis);
|
|
43
|
+
const enriched = filtered.map((row)=>{
|
|
44
|
+
const groupID = groupByJTI.get(row.jti);
|
|
45
|
+
return groupID != null ? revocationRowToData(row, groupID) : null;
|
|
46
|
+
});
|
|
47
|
+
return enriched.filter((data)=>data != null);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function revocationRowToData(row, groupID) {
|
|
52
|
+
return {
|
|
53
|
+
jti: row.jti,
|
|
54
|
+
grantor: row.grantor,
|
|
55
|
+
audience: row.audience,
|
|
56
|
+
revokerDID: row.revoker_did,
|
|
57
|
+
revokedAt: row.revoked_iat,
|
|
58
|
+
verifiedAt: row.verified_at,
|
|
59
|
+
capExp: row.cap_exp,
|
|
60
|
+
groupID
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function applyCoverageFilter(rows, covers, getGraphStore) {
|
|
64
|
+
// Resolve concrete model. When `docID` is supplied it wins (its derived model
|
|
65
|
+
// is authoritative); when both are supplied, the doc's model must match the
|
|
66
|
+
// hint or the caller's intent is ambiguous — reject with an explicit error.
|
|
67
|
+
let modelID = null;
|
|
68
|
+
let docID = null;
|
|
69
|
+
if (covers.docID != null) {
|
|
70
|
+
docID = covers.docID;
|
|
71
|
+
const graphStore = await getGraphStore();
|
|
72
|
+
// A malformed docID — one the document store cannot parse — is treated the
|
|
73
|
+
// same as a doc that does not exist locally: no token can cover it, so
|
|
74
|
+
// the result is empty.
|
|
75
|
+
let doc = null;
|
|
76
|
+
try {
|
|
77
|
+
doc = await graphStore.getDocument(covers.docID);
|
|
78
|
+
} catch {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
if (doc == null) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
modelID = doc.model;
|
|
85
|
+
if (covers.modelID != null && covers.modelID !== modelID) {
|
|
86
|
+
throw new GraphQLError(`Document ${docID} has model ${modelID}, not ${covers.modelID}`, {
|
|
87
|
+
extensions: {
|
|
88
|
+
code: 'DELEGATION_TOKEN_COVERS_MISMATCH'
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
} else if (covers.modelID != null) {
|
|
93
|
+
modelID = covers.modelID;
|
|
94
|
+
}
|
|
95
|
+
if (modelID == null) {
|
|
96
|
+
return rows;
|
|
97
|
+
}
|
|
98
|
+
// Per-call interface cache. Single model in this resolver call, but the
|
|
99
|
+
// cache keeps the shape consistent if the API grows multi-model later.
|
|
100
|
+
const interfaceCache = new Map();
|
|
101
|
+
const graphStore = await getGraphStore();
|
|
102
|
+
let interfaceIDs = interfaceCache.get(modelID);
|
|
103
|
+
if (interfaceIDs == null) {
|
|
104
|
+
interfaceIDs = await graphStore.getModelInterfaces(modelID);
|
|
105
|
+
interfaceCache.set(modelID, interfaceIDs);
|
|
106
|
+
}
|
|
107
|
+
const modelResources = new Set();
|
|
108
|
+
modelResources.add(`urn:kubun:model:${modelID}`);
|
|
109
|
+
for (const id of interfaceIDs){
|
|
110
|
+
modelResources.add(`urn:kubun:model:${id}`);
|
|
111
|
+
}
|
|
112
|
+
const docResource = docID != null ? `urn:kubun:document:${docID}` : null;
|
|
113
|
+
return rows.filter((row)=>{
|
|
114
|
+
if (row.resource === '*') return true;
|
|
115
|
+
if (row.resource === `urn:kubun:user:${row.grantor}`) return true;
|
|
116
|
+
if (modelResources.has(row.resource)) return true;
|
|
117
|
+
if (docResource != null && row.resource === docResource) return true;
|
|
118
|
+
return false;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function rowToData(row) {
|
|
122
|
+
return {
|
|
123
|
+
jwt: row.token,
|
|
124
|
+
jti: row.jti,
|
|
125
|
+
grantor: row.grantor,
|
|
126
|
+
audience: row.audience,
|
|
127
|
+
resource: row.resource,
|
|
128
|
+
exp: row.exp
|
|
129
|
+
};
|
|
130
|
+
}
|