@atrib/verify 0.1.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/LICENSE +190 -0
- package/README.md +177 -0
- package/dist/calculate.d.ts +32 -0
- package/dist/calculate.d.ts.map +1 -0
- package/dist/calculate.js +495 -0
- package/dist/calculate.js.map +1 -0
- package/dist/graph-fetch.d.ts +22 -0
- package/dist/graph-fetch.d.ts.map +1 -0
- package/dist/graph-fetch.js +60 -0
- package/dist/graph-fetch.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/policy-builder.d.ts +26 -0
- package/dist/policy-builder.d.ts.map +1 -0
- package/dist/policy-builder.js +49 -0
- package/dist/policy-builder.js.map +1 -0
- package/dist/recommendation.d.ts +29 -0
- package/dist/recommendation.d.ts.map +1 -0
- package/dist/recommendation.js +91 -0
- package/dist/recommendation.js.map +1 -0
- package/dist/resolve-identity.d.ts +84 -0
- package/dist/resolve-identity.d.ts.map +1 -0
- package/dist/resolve-identity.js +121 -0
- package/dist/resolve-identity.js.map +1 -0
- package/dist/revocations.d.ts +73 -0
- package/dist/revocations.d.ts.map +1 -0
- package/dist/revocations.js +83 -0
- package/dist/revocations.js.map +1 -0
- package/dist/types.d.ts +200 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +25 -0
- package/dist/types.js.map +1 -0
- package/dist/verifier.d.ts +54 -0
- package/dist/verifier.d.ts.map +1 -0
- package/dist/verifier.js +213 -0
- package/dist/verifier.js.map +1 -0
- package/dist/verify-record.d.ts +149 -0
- package/dist/verify-record.d.ts.map +1 -0
- package/dist/verify-record.js +136 -0
- package/dist/verify-record.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* §4.6.1 / §4.2 / §4.5.2 Rule 6: validate a policy document.
|
|
4
|
+
* Returns true iff the policy is structurally usable for calculation.
|
|
5
|
+
*
|
|
6
|
+
* Reasons a policy fails validation:
|
|
7
|
+
* - missing or wrong spec_version
|
|
8
|
+
* - contradictory constraints (minimum_share > maximum_share)
|
|
9
|
+
* - any negative constraint value
|
|
10
|
+
* - any negative edge weight
|
|
11
|
+
*/
|
|
12
|
+
export function isValidPolicy(policy) {
|
|
13
|
+
if (!policy || typeof policy !== 'object')
|
|
14
|
+
return false;
|
|
15
|
+
const p = policy;
|
|
16
|
+
if (p.spec_version !== 'atrib/1.0')
|
|
17
|
+
return false;
|
|
18
|
+
if (p.edge_weights !== undefined) {
|
|
19
|
+
if (typeof p.edge_weights !== 'object' || p.edge_weights === null)
|
|
20
|
+
return false;
|
|
21
|
+
for (const v of Object.values(p.edge_weights)) {
|
|
22
|
+
if (typeof v !== 'number' || v < 0 || Number.isNaN(v))
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (p.constraints !== undefined) {
|
|
27
|
+
if (typeof p.constraints !== 'object' || p.constraints === null)
|
|
28
|
+
return false;
|
|
29
|
+
const c = p.constraints;
|
|
30
|
+
for (const v of Object.values(c)) {
|
|
31
|
+
if (v !== undefined && (typeof v !== 'number' || v < 0 || Number.isNaN(v)))
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const minShare = c.minimum_share;
|
|
35
|
+
const maxShare = c.maximum_share;
|
|
36
|
+
if (minShare !== undefined && maxShare !== undefined && minShare > maxShare)
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
/** §4.3 default policy. */
|
|
42
|
+
export const DEFAULT_POLICY = {
|
|
43
|
+
spec_version: 'atrib/1.0',
|
|
44
|
+
policy_id: 'https://atrib.dev/policies/default/v1',
|
|
45
|
+
role: 'default',
|
|
46
|
+
edge_weights: {
|
|
47
|
+
CHAIN_PRECEDES: 1.0,
|
|
48
|
+
SESSION_PRECEDES: 1.0,
|
|
49
|
+
SESSION_PARALLEL: 1.0,
|
|
50
|
+
CONVERGES_ON: 1.0,
|
|
51
|
+
CROSS_SESSION: 1.0,
|
|
52
|
+
unsigned: 0.0,
|
|
53
|
+
},
|
|
54
|
+
modifiers: [],
|
|
55
|
+
distribution: 'proportional',
|
|
56
|
+
constraints: {},
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Run the full calculation pipeline (§4.6 closing pseudocode).
|
|
60
|
+
*
|
|
61
|
+
* @param graph. graph snapshot for the session
|
|
62
|
+
* @param policy. agreed policy document
|
|
63
|
+
* @param sessionPolicyRecord. optional; provides per-creator floors (§4.6.7)
|
|
64
|
+
* @returns final distribution (creator_key → share, sums to 1.0 ± 1e-9)
|
|
65
|
+
*/
|
|
66
|
+
export function calculate(graph, policy, sessionPolicyRecord) {
|
|
67
|
+
// §4.6.1: precondition. must have at least one transaction node
|
|
68
|
+
const txNode = graph.nodes.find((n) => n.event_type === 'transaction');
|
|
69
|
+
if (!txNode) {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
// §4.6.1: "P is a valid v1 policy document per the schema in §4.2. If
|
|
73
|
+
// validation fails, use the default policy."
|
|
74
|
+
const validatedPolicy = isValidPolicy(policy) ? policy : DEFAULT_POLICY;
|
|
75
|
+
// Step 1: identify contributing nodes
|
|
76
|
+
const contributing = identifyContributingNodes(graph);
|
|
77
|
+
// Step 2: compute raw scores
|
|
78
|
+
const rawScores = new Map();
|
|
79
|
+
for (const node of contributing) {
|
|
80
|
+
rawScores.set(node.id, rawScore(node, graph, validatedPolicy, txNode));
|
|
81
|
+
}
|
|
82
|
+
// Step 3: apply node-level constraints (per-node floor/cap on normalized fractions)
|
|
83
|
+
const constrained = applyConstraints(rawScores, validatedPolicy.constraints ?? {});
|
|
84
|
+
// Step 4: re-normalize
|
|
85
|
+
const normalized = finalNormalize(constrained);
|
|
86
|
+
// Step 5: aggregate by creator
|
|
87
|
+
const byCreator = aggregateByCreator(normalized, graph);
|
|
88
|
+
// Step 6: apply per-creator floors from session policy record
|
|
89
|
+
const creatorFloors = sessionPolicyRecord?.applied_constraints.minimum_floors ?? {};
|
|
90
|
+
const floored = applyCreatorFloors(byCreator, creatorFloors);
|
|
91
|
+
// Final renormalization, then convert Map → sorted plain object for determinism
|
|
92
|
+
return distributionFromMap(finalNormalize(floored));
|
|
93
|
+
}
|
|
94
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
95
|
+
// §4.6.2. Step 1: identify contributing nodes
|
|
96
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
97
|
+
function identifyContributingNodes(graph) {
|
|
98
|
+
// A contributing node is `tool_call` or `gap_node` (NOT transaction,
|
|
99
|
+
// observation, or extension) AND has an edge to a transaction node
|
|
100
|
+
// (CONVERGES_ON or CROSS_SESSION). observation and extension records
|
|
101
|
+
// are graph nodes but are NOT participants in §4.6 calculation in v1
|
|
102
|
+
// (spec §3.2.1, §4.6.2).
|
|
103
|
+
const txNodeIds = new Set(graph.nodes.filter((n) => n.event_type === 'transaction').map((n) => n.id));
|
|
104
|
+
const hasEdgeToTx = new Set();
|
|
105
|
+
for (const edge of graph.edges) {
|
|
106
|
+
if ((edge.type === 'CONVERGES_ON' || edge.type === 'CROSS_SESSION') &&
|
|
107
|
+
txNodeIds.has(edge.target)) {
|
|
108
|
+
hasEdgeToTx.add(edge.source);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Sort by id for deterministic iteration
|
|
112
|
+
return graph.nodes
|
|
113
|
+
.filter((n) => (n.event_type === 'tool_call' || n.event_type === 'gap_node') &&
|
|
114
|
+
hasEdgeToTx.has(n.id))
|
|
115
|
+
.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
116
|
+
}
|
|
117
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
118
|
+
// §4.6.3. Step 2: raw scores
|
|
119
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
120
|
+
function rawScore(node, graph, policy, txNode) {
|
|
121
|
+
const weights = policy.edge_weights ?? {};
|
|
122
|
+
// Step 2a: base weight from edge type
|
|
123
|
+
let base;
|
|
124
|
+
if (node.event_type === 'gap_node') {
|
|
125
|
+
base = weights.unsigned ?? 0.0;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// Collect all edge types on paths from this node leading to a transaction
|
|
129
|
+
const edgeTypes = collectEdgeTypesToTransaction(node.id, graph);
|
|
130
|
+
if (edgeTypes.size === 0) {
|
|
131
|
+
base = 0.0;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// §4.2.2 / §4.6.3: max() over all applicable edge weights
|
|
135
|
+
let max = -Infinity;
|
|
136
|
+
for (const t of edgeTypes) {
|
|
137
|
+
const w = weights[t] ?? 0.0;
|
|
138
|
+
if (w > max)
|
|
139
|
+
max = w;
|
|
140
|
+
}
|
|
141
|
+
base = max === -Infinity ? 0.0 : max;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Step 2b: apply modifiers in declared order
|
|
145
|
+
let score = base;
|
|
146
|
+
for (const modifier of policy.modifiers ?? []) {
|
|
147
|
+
score = applyModifier(modifier, score, node, graph, txNode);
|
|
148
|
+
}
|
|
149
|
+
return score < 0 ? 0 : score;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Collect every edge type that appears on any directed/undirected path from
|
|
153
|
+
* `nodeId` to any transaction node, including the direct CONVERGES_ON and
|
|
154
|
+
* CROSS_SESSION edges from the node itself.
|
|
155
|
+
*
|
|
156
|
+
* Per §4.6.3: "edge_types = {e.type for e in G.edges where e.source == n.id
|
|
157
|
+
* and G.nodes[e.target].event_type == 'transaction'}; also include
|
|
158
|
+
* CHAIN_PRECEDES and SESSION_* edges between non-transaction nodes that form
|
|
159
|
+
* a path leading to a transaction node"
|
|
160
|
+
*/
|
|
161
|
+
function collectEdgeTypesToTransaction(nodeId, graph) {
|
|
162
|
+
const txNodeIds = new Set(graph.nodes.filter((n) => n.event_type === 'transaction').map((n) => n.id));
|
|
163
|
+
const nodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
164
|
+
// Traversal: BFS from nodeId following ANY outgoing edge (including
|
|
165
|
+
// SESSION_PARALLEL undirected, plus reverse direction which we treat as
|
|
166
|
+
// outgoing for path-finding). Collect every edge type encountered on
|
|
167
|
+
// edges that participate in a path reaching a transaction node.
|
|
168
|
+
//
|
|
169
|
+
// Implementation strategy: do a forward reachability search to find which
|
|
170
|
+
// nodes can reach a transaction. Then any edge whose source is in that set
|
|
171
|
+
// and whose path continues toward a transaction contributes its type.
|
|
172
|
+
//
|
|
173
|
+
// Simpler exact approach: for any node N, the edge types on N's "path to
|
|
174
|
+
// transaction" are the union of:
|
|
175
|
+
// 1. types of edges directly from N (or undirected involving N) whose
|
|
176
|
+
// other endpoint can reach a transaction (or IS a transaction)
|
|
177
|
+
// 2. recursively, the path types from the next hop
|
|
178
|
+
//
|
|
179
|
+
// We compute this iteratively as a fixed-point set per node.
|
|
180
|
+
// Build adjacency: for each node, list (edgeType, neighborId) for both
|
|
181
|
+
// directed-out and undirected edges.
|
|
182
|
+
const adj = new Map();
|
|
183
|
+
for (const node of graph.nodes)
|
|
184
|
+
adj.set(node.id, []);
|
|
185
|
+
for (const edge of graph.edges) {
|
|
186
|
+
adj.get(edge.source)?.push({ type: edge.type, to: edge.target });
|
|
187
|
+
if (!edge.directed) {
|
|
188
|
+
adj.get(edge.target)?.push({ type: edge.type, to: edge.source });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// BFS forward from nodeId; collect edge types whose target either is a
|
|
192
|
+
// transaction node OR can reach a transaction.
|
|
193
|
+
// First compute "can reach transaction" set via reverse BFS from tx nodes.
|
|
194
|
+
const canReachTx = new Set(txNodeIds);
|
|
195
|
+
const reverseAdj = new Map();
|
|
196
|
+
for (const node of graph.nodes)
|
|
197
|
+
reverseAdj.set(node.id, []);
|
|
198
|
+
for (const edge of graph.edges) {
|
|
199
|
+
reverseAdj.get(edge.target)?.push(edge.source);
|
|
200
|
+
if (!edge.directed)
|
|
201
|
+
reverseAdj.get(edge.source)?.push(edge.target);
|
|
202
|
+
}
|
|
203
|
+
const reverseQueue = [...txNodeIds];
|
|
204
|
+
while (reverseQueue.length > 0) {
|
|
205
|
+
const curr = reverseQueue.shift();
|
|
206
|
+
for (const pred of reverseAdj.get(curr) ?? []) {
|
|
207
|
+
if (!canReachTx.has(pred)) {
|
|
208
|
+
canReachTx.add(pred);
|
|
209
|
+
reverseQueue.push(pred);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Now BFS forward from nodeId, collecting edge types on edges whose target
|
|
214
|
+
// can reach a transaction.
|
|
215
|
+
const collected = new Set();
|
|
216
|
+
const visited = new Set([nodeId]);
|
|
217
|
+
const queue = [nodeId];
|
|
218
|
+
while (queue.length > 0) {
|
|
219
|
+
const curr = queue.shift();
|
|
220
|
+
for (const { type, to } of adj.get(curr) ?? []) {
|
|
221
|
+
// Only count edges that participate in a transaction-reaching path
|
|
222
|
+
if (!canReachTx.has(to))
|
|
223
|
+
continue;
|
|
224
|
+
// Skip edges leading to non-transaction nodes that still can reach tx,
|
|
225
|
+
// but include the edge type. Also include edges directly to tx nodes.
|
|
226
|
+
// Per §4.6.3, we collect both direct CONVERGES_ON edges and chain/session
|
|
227
|
+
// edges on paths leading to tx.
|
|
228
|
+
const targetNode = nodeMap.get(to);
|
|
229
|
+
if (!targetNode)
|
|
230
|
+
continue;
|
|
231
|
+
collected.add(type);
|
|
232
|
+
if (targetNode.event_type !== 'transaction' && !visited.has(to)) {
|
|
233
|
+
visited.add(to);
|
|
234
|
+
queue.push(to);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return collected;
|
|
239
|
+
}
|
|
240
|
+
function applyModifier(modifier, score, node, graph, txNode) {
|
|
241
|
+
if (modifier.type === 'temporal_decay') {
|
|
242
|
+
const halfLifeMs = modifier.half_life_ms;
|
|
243
|
+
const deltaMs = txNode.timestamp - node.timestamp;
|
|
244
|
+
if (deltaMs < 0)
|
|
245
|
+
return 0.0;
|
|
246
|
+
return score * Math.pow(2.0, -(deltaMs / halfLifeMs));
|
|
247
|
+
}
|
|
248
|
+
if (modifier.type === 'chain_depth_penalty') {
|
|
249
|
+
const penaltyPerLevel = modifier.penalty_per_level;
|
|
250
|
+
const depth = shortestChainPath(node.id, graph);
|
|
251
|
+
const factor = Math.max(0.0, 1.0 - depth * penaltyPerLevel);
|
|
252
|
+
return score * factor;
|
|
253
|
+
}
|
|
254
|
+
if (modifier.type === 'call_count_boost') {
|
|
255
|
+
const m = modifier;
|
|
256
|
+
const count = countNodesWithSameContentId(node.content_id, graph);
|
|
257
|
+
const factor = Math.min(m.cap, 1.0 + (count - 1) * m.multiplier_per_call);
|
|
258
|
+
return score * factor;
|
|
259
|
+
}
|
|
260
|
+
// Unknown modifier types are ignored (§4.6.3)
|
|
261
|
+
return score;
|
|
262
|
+
}
|
|
263
|
+
function shortestChainPath(nodeId, graph) {
|
|
264
|
+
// Hops via CHAIN_PRECEDES from this node to nearest transaction.
|
|
265
|
+
// Build chain-only adjacency.
|
|
266
|
+
const chainAdj = new Map();
|
|
267
|
+
for (const node of graph.nodes)
|
|
268
|
+
chainAdj.set(node.id, []);
|
|
269
|
+
for (const edge of graph.edges) {
|
|
270
|
+
if (edge.type === 'CHAIN_PRECEDES') {
|
|
271
|
+
chainAdj.get(edge.source)?.push(edge.target);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const txIds = new Set(graph.nodes.filter((n) => n.event_type === 'transaction').map((n) => n.id));
|
|
275
|
+
// BFS
|
|
276
|
+
const visited = new Set([nodeId]);
|
|
277
|
+
const queue = [{ id: nodeId, depth: 0 }];
|
|
278
|
+
while (queue.length > 0) {
|
|
279
|
+
const { id, depth } = queue.shift();
|
|
280
|
+
if (txIds.has(id))
|
|
281
|
+
return depth;
|
|
282
|
+
for (const next of chainAdj.get(id) ?? []) {
|
|
283
|
+
if (!visited.has(next)) {
|
|
284
|
+
visited.add(next);
|
|
285
|
+
queue.push({ id: next, depth: depth + 1 });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// No chain path to a transaction. return a large depth to fully penalize
|
|
290
|
+
return Number.MAX_SAFE_INTEGER;
|
|
291
|
+
}
|
|
292
|
+
function countNodesWithSameContentId(contentId, graph) {
|
|
293
|
+
if (!contentId)
|
|
294
|
+
return 1;
|
|
295
|
+
let count = 0;
|
|
296
|
+
for (const n of graph.nodes) {
|
|
297
|
+
if (n.content_id === contentId)
|
|
298
|
+
count++;
|
|
299
|
+
}
|
|
300
|
+
return count;
|
|
301
|
+
}
|
|
302
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
303
|
+
// §4.6.4. Step 3: apply constraints
|
|
304
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
305
|
+
function applyConstraints(rawScores, constraints) {
|
|
306
|
+
// Filter to positive contributors
|
|
307
|
+
const contributors = new Map();
|
|
308
|
+
for (const [id, score] of rawScores) {
|
|
309
|
+
if (score > 0)
|
|
310
|
+
contributors.set(id, score);
|
|
311
|
+
}
|
|
312
|
+
if (contributors.size === 0)
|
|
313
|
+
return new Map();
|
|
314
|
+
// Initial proportional pass
|
|
315
|
+
let total = 0;
|
|
316
|
+
for (const s of contributors.values())
|
|
317
|
+
total += s;
|
|
318
|
+
let normalized = new Map();
|
|
319
|
+
for (const [id, s] of contributors)
|
|
320
|
+
normalized.set(id, s / total);
|
|
321
|
+
if (constraints.minimum_share !== undefined) {
|
|
322
|
+
normalized = applyMinimumFloor(normalized, constraints.minimum_share);
|
|
323
|
+
}
|
|
324
|
+
if (constraints.maximum_share !== undefined) {
|
|
325
|
+
normalized = applyMaximumCap(normalized, constraints.maximum_share);
|
|
326
|
+
}
|
|
327
|
+
return normalized;
|
|
328
|
+
}
|
|
329
|
+
function applyMinimumFloor(normalized, floor) {
|
|
330
|
+
const below = new Map();
|
|
331
|
+
const above = new Map();
|
|
332
|
+
for (const [id, s] of normalized) {
|
|
333
|
+
if (s < floor)
|
|
334
|
+
below.set(id, s);
|
|
335
|
+
else
|
|
336
|
+
above.set(id, s);
|
|
337
|
+
}
|
|
338
|
+
let boostNeeded = 0;
|
|
339
|
+
for (const s of below.values())
|
|
340
|
+
boostNeeded += floor - s;
|
|
341
|
+
let aboveTotal = 0;
|
|
342
|
+
for (const s of above.values())
|
|
343
|
+
aboveTotal += s;
|
|
344
|
+
const result = new Map();
|
|
345
|
+
if (aboveTotal <= boostNeeded) {
|
|
346
|
+
// Equal-distribution fallback
|
|
347
|
+
const equal = 1.0 / normalized.size;
|
|
348
|
+
for (const id of normalized.keys())
|
|
349
|
+
result.set(id, equal);
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
const scale = (aboveTotal - boostNeeded) / aboveTotal;
|
|
353
|
+
for (const id of below.keys())
|
|
354
|
+
result.set(id, floor);
|
|
355
|
+
for (const [id, s] of above)
|
|
356
|
+
result.set(id, s * scale);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
function applyMaximumCap(normalized, cap) {
|
|
360
|
+
// Iterate until no entries exceed cap. Each pass caps at least one new
|
|
361
|
+
// entry, so the loop terminates in at most N passes. A safety bound
|
|
362
|
+
// prevents infinite loops if redistribution ping-pongs between entries
|
|
363
|
+
// (possible when cap * N < 1.0 and excess can't be absorbed).
|
|
364
|
+
let current = normalized;
|
|
365
|
+
const maxIters = normalized.size + 1;
|
|
366
|
+
for (let iter = 0; iter < maxIters; iter++) {
|
|
367
|
+
const above = new Map();
|
|
368
|
+
const below = new Map();
|
|
369
|
+
for (const [id, s] of current) {
|
|
370
|
+
if (s > cap)
|
|
371
|
+
above.set(id, s);
|
|
372
|
+
else
|
|
373
|
+
below.set(id, s);
|
|
374
|
+
}
|
|
375
|
+
if (above.size === 0)
|
|
376
|
+
return current;
|
|
377
|
+
let excess = 0;
|
|
378
|
+
for (const s of above.values())
|
|
379
|
+
excess += s - cap;
|
|
380
|
+
let belowTotal = 0;
|
|
381
|
+
for (const s of below.values())
|
|
382
|
+
belowTotal += s;
|
|
383
|
+
const result = new Map();
|
|
384
|
+
for (const id of above.keys())
|
|
385
|
+
result.set(id, cap);
|
|
386
|
+
if (belowTotal > 0) {
|
|
387
|
+
const scale = (belowTotal + excess) / belowTotal;
|
|
388
|
+
for (const [id, s] of below)
|
|
389
|
+
result.set(id, s * scale);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
for (const [id, s] of below)
|
|
393
|
+
result.set(id, s);
|
|
394
|
+
}
|
|
395
|
+
current = result;
|
|
396
|
+
}
|
|
397
|
+
// Safety: if we exhaust iterations (ping-pong), cap everyone at cap
|
|
398
|
+
// and let finalNormalize handle the sum.
|
|
399
|
+
const result = new Map();
|
|
400
|
+
for (const [id, s] of current)
|
|
401
|
+
result.set(id, Math.min(s, cap));
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
405
|
+
// §4.6.5. Step 4: final normalize
|
|
406
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
407
|
+
function finalNormalize(shares) {
|
|
408
|
+
let total = 0;
|
|
409
|
+
for (const s of shares.values())
|
|
410
|
+
total += s;
|
|
411
|
+
// Guard against zero, near-zero (denormalized), and NaN totals
|
|
412
|
+
if (!Number.isFinite(total) || total <= 0)
|
|
413
|
+
return new Map();
|
|
414
|
+
const result = new Map();
|
|
415
|
+
for (const [k, s] of shares) {
|
|
416
|
+
const normalized = s / total;
|
|
417
|
+
// Guard against NaN/Infinity from division of very small numbers
|
|
418
|
+
result.set(k, Number.isFinite(normalized) ? normalized : 0);
|
|
419
|
+
}
|
|
420
|
+
return result;
|
|
421
|
+
}
|
|
422
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
423
|
+
// §4.6.6. Step 5: aggregate by creator
|
|
424
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
425
|
+
function aggregateByCreator(normalized, graph) {
|
|
426
|
+
const nodeMap = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
427
|
+
const byCreator = new Map();
|
|
428
|
+
// Sort node ids for deterministic accumulation order
|
|
429
|
+
const sortedIds = [...normalized.keys()].sort();
|
|
430
|
+
for (const id of sortedIds) {
|
|
431
|
+
const share = normalized.get(id);
|
|
432
|
+
const node = nodeMap.get(id);
|
|
433
|
+
if (!node)
|
|
434
|
+
continue;
|
|
435
|
+
const key = node.creator_key ?? '__unsigned__';
|
|
436
|
+
byCreator.set(key, (byCreator.get(key) ?? 0) + share);
|
|
437
|
+
}
|
|
438
|
+
return byCreator;
|
|
439
|
+
}
|
|
440
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
441
|
+
// §4.6.7. Step 6: apply creator floors
|
|
442
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
443
|
+
function applyCreatorFloors(byCreator, creatorFloors) {
|
|
444
|
+
const floorEntries = Object.entries(creatorFloors);
|
|
445
|
+
if (floorEntries.length === 0)
|
|
446
|
+
return byCreator;
|
|
447
|
+
const result = new Map(byCreator);
|
|
448
|
+
const flooredKeys = new Set();
|
|
449
|
+
// Identify creators below their floor (sorted for determinism)
|
|
450
|
+
for (const [key, floor] of floorEntries.sort((a, b) => (a[0] < b[0] ? -1 : 1))) {
|
|
451
|
+
if (!result.has(key))
|
|
452
|
+
continue;
|
|
453
|
+
if ((result.get(key) ?? 0) < floor)
|
|
454
|
+
flooredKeys.add(key);
|
|
455
|
+
}
|
|
456
|
+
if (flooredKeys.size === 0)
|
|
457
|
+
return result;
|
|
458
|
+
let boostNeeded = 0;
|
|
459
|
+
for (const k of flooredKeys)
|
|
460
|
+
boostNeeded += creatorFloors[k] - (result.get(k) ?? 0);
|
|
461
|
+
const nonFloored = new Map();
|
|
462
|
+
for (const [k, v] of result) {
|
|
463
|
+
if (!flooredKeys.has(k))
|
|
464
|
+
nonFloored.set(k, v);
|
|
465
|
+
}
|
|
466
|
+
let nonFlooredTotal = 0;
|
|
467
|
+
for (const v of nonFloored.values())
|
|
468
|
+
nonFlooredTotal += v;
|
|
469
|
+
if (nonFlooredTotal <= boostNeeded) {
|
|
470
|
+
// Cannot honor. should have been caught at negotiation. Return unchanged.
|
|
471
|
+
return result;
|
|
472
|
+
}
|
|
473
|
+
const scale = (nonFlooredTotal - boostNeeded) / nonFlooredTotal;
|
|
474
|
+
// Use sorted iteration to keep result construction deterministic
|
|
475
|
+
for (const k of [...flooredKeys].sort()) {
|
|
476
|
+
result.set(k, creatorFloors[k]);
|
|
477
|
+
}
|
|
478
|
+
for (const [k, v] of [...nonFloored.entries()].sort((a, b) => (a[0] < b[0] ? -1 : 1))) {
|
|
479
|
+
result.set(k, v * scale);
|
|
480
|
+
}
|
|
481
|
+
return result;
|
|
482
|
+
}
|
|
483
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
484
|
+
// Helpers for converting Map → plain Distribution object (for output)
|
|
485
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
486
|
+
/** Convert a Map<creator_key, share> to a sorted plain object distribution. */
|
|
487
|
+
function distributionFromMap(map) {
|
|
488
|
+
const result = {};
|
|
489
|
+
// Sort keys for deterministic JSON ordering
|
|
490
|
+
for (const k of [...map.keys()].sort()) {
|
|
491
|
+
result[k] = map.get(k);
|
|
492
|
+
}
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
495
|
+
//# sourceMappingURL=calculate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate.js","sourceRoot":"","sources":["../src/calculate.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAsBtC;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IAC3C,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACvD,MAAM,CAAC,GAAG,MAAiC,CAAA;IAC3C,IAAI,CAAC,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ChF,sEAAsE;AACtE,gFAAgF;AAEhF,+EAA+E;AAC/E,SAAS,mBAAmB,CAAC,GAAwB;IACnD,MAAM,MAAM,GAAiB,EAAE,CAAA;IAC/B,4CAA4C;IAC5C,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACvC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAE,CAAA;IACzB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP fetcher for graph snapshots and session policy records.
|
|
3
|
+
* Thin wrapper used by AtribVerifier.verify() / .calculate().
|
|
4
|
+
*/
|
|
5
|
+
import type { GraphResponse, SessionPolicyRecord, PolicyDocument } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Fetch a graph snapshot for a context_id at a specific tree size (§3.4.1).
|
|
8
|
+
*
|
|
9
|
+
* @param graphEndpoint. base URL, e.g. "https://graph.atrib.dev/v1"
|
|
10
|
+
* @param contextId
|
|
11
|
+
* @param treeSize. optional; if provided, pins the graph to that log tree size
|
|
12
|
+
*/
|
|
13
|
+
export declare function fetchGraph(graphEndpoint: string, contextId: string, treeSize?: number): Promise<GraphResponse>;
|
|
14
|
+
/**
|
|
15
|
+
* Fetch a session policy record by its record_id (§4.5.3).
|
|
16
|
+
*/
|
|
17
|
+
export declare function fetchSessionPolicyRecord(graphEndpoint: string, recordId: string): Promise<SessionPolicyRecord>;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch a policy document by URL (§4.4).
|
|
20
|
+
*/
|
|
21
|
+
export declare function fetchPolicyDocument(url: string): Promise<PolicyDocument>;
|
|
22
|
+
//# sourceMappingURL=graph-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-fetch.d.ts","sourceRoot":"","sources":["../src/graph-fetch.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIpF;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,CAAC,CAYxB;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,mBAAmB,CAAC,CAO9B;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAW9E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
3
|
+
/**
|
|
4
|
+
* Fetch a graph snapshot for a context_id at a specific tree size (§3.4.1).
|
|
5
|
+
*
|
|
6
|
+
* @param graphEndpoint. base URL, e.g. "https://graph.atrib.dev/v1"
|
|
7
|
+
* @param contextId
|
|
8
|
+
* @param treeSize. optional; if provided, pins the graph to that log tree size
|
|
9
|
+
*/
|
|
10
|
+
export async function fetchGraph(graphEndpoint, contextId, treeSize) {
|
|
11
|
+
const params = new URLSearchParams({
|
|
12
|
+
include_gap_nodes: 'true',
|
|
13
|
+
include_cross_session: 'true',
|
|
14
|
+
});
|
|
15
|
+
if (treeSize !== undefined)
|
|
16
|
+
params.set('tree_size', String(treeSize));
|
|
17
|
+
const url = `${graphEndpoint.replace(/\/$/, '')}/graph/${contextId}?${params.toString()}`;
|
|
18
|
+
const res = await fetchWithTimeout(url);
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
throw new Error(`fetchGraph failed: ${res.status} ${res.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
return (await res.json());
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetch a session policy record by its record_id (§4.5.3).
|
|
26
|
+
*/
|
|
27
|
+
export async function fetchSessionPolicyRecord(graphEndpoint, recordId) {
|
|
28
|
+
const url = `${graphEndpoint.replace(/\/$/, '')}/policy-records/${encodeURIComponent(recordId)}`;
|
|
29
|
+
const res = await fetchWithTimeout(url);
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new Error(`fetchSessionPolicyRecord failed: ${res.status} ${res.statusText}`);
|
|
32
|
+
}
|
|
33
|
+
return (await res.json());
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fetch a policy document by URL (§4.4).
|
|
37
|
+
*/
|
|
38
|
+
export async function fetchPolicyDocument(url) {
|
|
39
|
+
// Validate URL scheme to prevent SSRF via crafted agreed_policy URLs
|
|
40
|
+
const parsed = new URL(url);
|
|
41
|
+
if (parsed.protocol !== 'https:') {
|
|
42
|
+
throw new Error(`fetchPolicyDocument: only https: URLs are allowed, got ${parsed.protocol}`);
|
|
43
|
+
}
|
|
44
|
+
const res = await fetchWithTimeout(url);
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
throw new Error(`fetchPolicyDocument failed: ${res.status} ${res.statusText}`);
|
|
47
|
+
}
|
|
48
|
+
return (await res.json());
|
|
49
|
+
}
|
|
50
|
+
async function fetchWithTimeout(url, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
53
|
+
try {
|
|
54
|
+
return await fetch(url, { signal: controller.signal });
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=graph-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-fetch.js","sourceRoot":"","sources":["../src/graph-fetch.ts"],"names":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AAC;IACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAwB,CAAA;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAW;IACnD,qEAAqE;IACrE,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,0DAA0D,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC9F,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACvC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAmB,CAAA;AAC7C,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,GAAW,EAAE,SAAS,GAAG,kBAAkB;IACzE,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAA;IACxC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAA;IAC7D,IAAI,CAAC;QACH,OAAO,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA;IACxD,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { AtribVerifier } from './verifier.js';
|
|
2
|
+
export type { AtribVerifierOptions, CalculateOptions } from './verifier.js';
|
|
3
|
+
export { verifyRecord } from './verify-record.js';
|
|
4
|
+
export type { RecordVerificationResult, ProvenanceAnnotation, VerifyRecordOptions, } from './verify-record.js';
|
|
5
|
+
export { calculate, DEFAULT_POLICY, isValidPolicy } from './calculate.js';
|
|
6
|
+
export { signRecommendation, verifyRecommendationSignature, recommendationSigningInput, distributionsMatch, } from './recommendation.js';
|
|
7
|
+
export { buildPolicy, policyFrom } from './policy-builder.js';
|
|
8
|
+
export { fetchGraph, fetchSessionPolicyRecord, fetchPolicyDocument } from './graph-fetch.js';
|
|
9
|
+
export { buildRevocationRegistry, applyRevocation } from './revocations.js';
|
|
10
|
+
export type { RevocationEntry, RevocationReason, MinimalRecord } from './revocations.js';
|
|
11
|
+
export { resolveIdentity } from './resolve-identity.js';
|
|
12
|
+
export type { IdentityResolution, IdentityResolutionMethod, KeyRevocationStatus, ResolveIdentityOptions, IdentityClaim, CapabilityEnvelope, } from './resolve-identity.js';
|
|
13
|
+
export type { GraphNode, GraphEdge, GraphResponse, EventType, EdgeType, GapNode, VerificationState, PolicyDocument, PolicyConstraints, EdgeWeights, Modifier, DistributionMethod, CreatorPolicySnapshot, CreatorPolicyEntry, SessionPolicyRecord, Distribution, RecommendationDocument, VerificationResult, } from './types.js';
|
|
14
|
+
export { graphLabelFromEventTypeUri } from './types.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAO3E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EACV,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CA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