agent-passport-system 1.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 +194 -0
- package/dist/src/cli/index.d.ts +3 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +569 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/contract.d.ts +97 -0
- package/dist/src/contract.d.ts.map +1 -0
- package/dist/src/contract.js +161 -0
- package/dist/src/contract.js.map +1 -0
- package/dist/src/core/attribution.d.ts +71 -0
- package/dist/src/core/attribution.d.ts.map +1 -0
- package/dist/src/core/attribution.js +277 -0
- package/dist/src/core/attribution.js.map +1 -0
- package/dist/src/core/canonical.d.ts +2 -0
- package/dist/src/core/canonical.d.ts.map +1 -0
- package/dist/src/core/canonical.js +23 -0
- package/dist/src/core/canonical.js.map +1 -0
- package/dist/src/core/delegation.d.ts +41 -0
- package/dist/src/core/delegation.d.ts.map +1 -0
- package/dist/src/core/delegation.js +173 -0
- package/dist/src/core/delegation.js.map +1 -0
- package/dist/src/core/index.d.ts +3 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +3 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/passport.d.ts +9 -0
- package/dist/src/core/passport.d.ts.map +1 -0
- package/dist/src/core/passport.js +76 -0
- package/dist/src/core/passport.js.map +1 -0
- package/dist/src/core/values.d.ts +49 -0
- package/dist/src/core/values.d.ts.map +1 -0
- package/dist/src/core/values.js +320 -0
- package/dist/src/core/values.js.map +1 -0
- package/dist/src/crypto/index.d.ts +2 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +2 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/keys.d.ts +6 -0
- package/dist/src/crypto/keys.d.ts.map +1 -0
- package/dist/src/crypto/keys.js +63 -0
- package/dist/src/crypto/keys.js.map +1 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types/index.d.ts +2 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +2 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/passport.d.ts +260 -0
- package/dist/src/types/passport.d.ts.map +1 -0
- package/dist/src/types/passport.js +3 -0
- package/dist/src/types/passport.js.map +1 -0
- package/dist/src/verification/index.d.ts +3 -0
- package/dist/src/verification/index.d.ts.map +1 -0
- package/dist/src/verification/index.js +3 -0
- package/dist/src/verification/index.js.map +1 -0
- package/dist/src/verification/reputation.d.ts +4 -0
- package/dist/src/verification/reputation.d.ts.map +1 -0
- package/dist/src/verification/reputation.js +43 -0
- package/dist/src/verification/reputation.js.map +1 -0
- package/dist/src/verification/verify.d.ts +5 -0
- package/dist/src/verification/verify.d.ts.map +1 -0
- package/dist/src/verification/verify.js +69 -0
- package/dist/src/verification/verify.js.map +1 -0
- package/package.json +59 -0
- package/values/floor.yaml +204 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { SignedPassport, KeyPair, FloorAttestation, ActionReceipt, Delegation, ValuesFloor, BeneficiaryInfo, MerkleProof, AttributionReport, ComplianceReport, BeneficiaryTrace } from './types/passport.js';
|
|
2
|
+
export interface JoinOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
mission: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
capabilities: string[];
|
|
7
|
+
platform: string;
|
|
8
|
+
models: string[];
|
|
9
|
+
floor?: ValuesFloor | string;
|
|
10
|
+
floorExtensions?: string[];
|
|
11
|
+
beneficiary?: {
|
|
12
|
+
id: string;
|
|
13
|
+
relationship: 'creator' | 'employer' | 'delegator' | 'owner';
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface SocialContractAgent {
|
|
17
|
+
passport: SignedPassport;
|
|
18
|
+
keyPair: KeyPair;
|
|
19
|
+
attestation: FloorAttestation | null;
|
|
20
|
+
agentId: string;
|
|
21
|
+
publicKey: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Join the Agent Social Contract.
|
|
25
|
+
*
|
|
26
|
+
* One call. Creates identity, attests to values, registers beneficiary.
|
|
27
|
+
* Returns everything an agent needs to participate.
|
|
28
|
+
*/
|
|
29
|
+
export declare function joinSocialContract(opts: JoinOptions): SocialContractAgent;
|
|
30
|
+
export interface TrustVerification {
|
|
31
|
+
identity: {
|
|
32
|
+
valid: boolean;
|
|
33
|
+
errors: string[];
|
|
34
|
+
};
|
|
35
|
+
values: {
|
|
36
|
+
attested: boolean;
|
|
37
|
+
valid: boolean;
|
|
38
|
+
errors: string[];
|
|
39
|
+
} | null;
|
|
40
|
+
overall: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify another agent's standing in the social contract.
|
|
44
|
+
*
|
|
45
|
+
* One call. Checks identity, attestation, gives you a trust decision.
|
|
46
|
+
*/
|
|
47
|
+
export declare function verifySocialContract(passport: SignedPassport, attestation?: FloorAttestation | null): TrustVerification;
|
|
48
|
+
export interface DelegateOptions {
|
|
49
|
+
from: SocialContractAgent;
|
|
50
|
+
toPublicKey: string;
|
|
51
|
+
scope: string[];
|
|
52
|
+
spendLimit?: number;
|
|
53
|
+
maxDepth?: number;
|
|
54
|
+
expiresInHours?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Delegate authority from one agent (or human) to another.
|
|
58
|
+
*/
|
|
59
|
+
export declare function delegate(opts: DelegateOptions): Delegation;
|
|
60
|
+
export interface WorkOptions {
|
|
61
|
+
type: string;
|
|
62
|
+
target: string;
|
|
63
|
+
scope: string;
|
|
64
|
+
spend?: number;
|
|
65
|
+
currency?: string;
|
|
66
|
+
result: 'success' | 'failure' | 'partial';
|
|
67
|
+
summary: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Record a unit of work under a delegation.
|
|
71
|
+
*
|
|
72
|
+
* Returns a signed, verifiable receipt.
|
|
73
|
+
*/
|
|
74
|
+
export declare function recordWork(agent: SocialContractAgent, delegation: Delegation, delegationChain: string[], work: WorkOptions): ActionReceipt;
|
|
75
|
+
export interface ContributionProof {
|
|
76
|
+
attribution: AttributionReport;
|
|
77
|
+
merkleRoot: string;
|
|
78
|
+
proofs: Map<string, MerkleProof>;
|
|
79
|
+
traces: BeneficiaryTrace[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Generate cryptographic proof of an agent's contributions.
|
|
83
|
+
*
|
|
84
|
+
* Returns attribution report + Merkle proofs for every receipt +
|
|
85
|
+
* beneficiary traces. A third party can verify any individual
|
|
86
|
+
* receipt without seeing the others.
|
|
87
|
+
*/
|
|
88
|
+
export declare function proveContributions(agent: SocialContractAgent, receipts: ActionReceipt[], delegations: Delegation[], beneficiary: string, beneficiaryMap?: Map<string, BeneficiaryInfo>): ContributionProof;
|
|
89
|
+
/**
|
|
90
|
+
* Audit an agent's compliance. Requires a verifier keypair
|
|
91
|
+
* (the auditor signs the report).
|
|
92
|
+
*/
|
|
93
|
+
export declare function auditCompliance(agentId: string, receipts: ActionReceipt[], floor: ValuesFloor, delegations: Map<string, {
|
|
94
|
+
scope: string[];
|
|
95
|
+
revoked: boolean;
|
|
96
|
+
}>, verifierKeyPair: KeyPair): ComplianceReport;
|
|
97
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/contract.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EACK,cAAc,EAAE,OAAO,EAAE,gBAAgB,EACxD,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EACvD,WAAW,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EACnE,MAAM,qBAAqB,CAAA;AAM5B,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;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,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,EAC/D,eAAe,EAAE,OAAO,GACvB,gBAAgB,CAElB"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// ══════════════════════════════════════════════════════════════
|
|
2
|
+
// The Agent Social Contract — High-Level API
|
|
3
|
+
// ══════════════════════════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// Everything below is one function call.
|
|
6
|
+
//
|
|
7
|
+
// To JOIN the social contract:
|
|
8
|
+
// const agent = joinSocialContract({ name, mission, ... })
|
|
9
|
+
//
|
|
10
|
+
// To VERIFY another agent:
|
|
11
|
+
// const trust = verifySocialContract(agent.passport)
|
|
12
|
+
//
|
|
13
|
+
// To RECORD work:
|
|
14
|
+
// const receipt = recordWork(agent, { action, result })
|
|
15
|
+
//
|
|
16
|
+
// To PROVE your contributions:
|
|
17
|
+
// const proof = proveContribution(agent, receipts)
|
|
18
|
+
//
|
|
19
|
+
// That's it. Four functions. The rest is implementation detail.
|
|
20
|
+
import { createPassport } from './core/passport.js';
|
|
21
|
+
import { verifyPassport } from './verification/verify.js';
|
|
22
|
+
import { attestFloor, verifyAttestation, loadFloor, evaluateCompliance } from './core/values.js';
|
|
23
|
+
import { createDelegation, createReceipt } from './core/delegation.js';
|
|
24
|
+
import { hashReceipt, traceBeneficiary, computeAttribution, generateMerkleProof } from './core/attribution.js';
|
|
25
|
+
/**
|
|
26
|
+
* Join the Agent Social Contract.
|
|
27
|
+
*
|
|
28
|
+
* One call. Creates identity, attests to values, registers beneficiary.
|
|
29
|
+
* Returns everything an agent needs to participate.
|
|
30
|
+
*/
|
|
31
|
+
export function joinSocialContract(opts) {
|
|
32
|
+
const agentId = `agent-${opts.name.toLowerCase().replace(/[^a-z0-9]/g, '-')}-${Date.now().toString(36)}`;
|
|
33
|
+
const { signedPassport, keyPair } = createPassport({
|
|
34
|
+
agentId,
|
|
35
|
+
agentName: opts.name,
|
|
36
|
+
ownerAlias: opts.owner,
|
|
37
|
+
mission: opts.mission,
|
|
38
|
+
capabilities: opts.capabilities,
|
|
39
|
+
runtime: {
|
|
40
|
+
platform: opts.platform,
|
|
41
|
+
models: opts.models,
|
|
42
|
+
toolsCount: opts.capabilities.length,
|
|
43
|
+
memoryType: 'persistent'
|
|
44
|
+
},
|
|
45
|
+
beneficiary: opts.beneficiary ? {
|
|
46
|
+
principalId: opts.beneficiary.id,
|
|
47
|
+
relationship: opts.beneficiary.relationship,
|
|
48
|
+
registeredAt: new Date().toISOString()
|
|
49
|
+
} : undefined
|
|
50
|
+
});
|
|
51
|
+
// Attest to floor if provided
|
|
52
|
+
let attestation = null;
|
|
53
|
+
if (opts.floor) {
|
|
54
|
+
const floor = typeof opts.floor === 'string' ? loadFloor(opts.floor) : opts.floor;
|
|
55
|
+
attestation = attestFloor(agentId, signedPassport.passport.publicKey, floor.version, opts.floorExtensions || [], keyPair.privateKey);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
passport: signedPassport,
|
|
59
|
+
keyPair,
|
|
60
|
+
attestation,
|
|
61
|
+
agentId,
|
|
62
|
+
publicKey: signedPassport.passport.publicKey
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verify another agent's standing in the social contract.
|
|
67
|
+
*
|
|
68
|
+
* One call. Checks identity, attestation, gives you a trust decision.
|
|
69
|
+
*/
|
|
70
|
+
export function verifySocialContract(passport, attestation) {
|
|
71
|
+
const identity = verifyPassport(passport);
|
|
72
|
+
let values = null;
|
|
73
|
+
if (attestation) {
|
|
74
|
+
const attResult = verifyAttestation(attestation);
|
|
75
|
+
values = {
|
|
76
|
+
attested: true,
|
|
77
|
+
valid: attResult.valid,
|
|
78
|
+
errors: attResult.errors
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
identity: { valid: identity.valid, errors: identity.errors },
|
|
83
|
+
values,
|
|
84
|
+
overall: identity.valid && (!values || values.valid)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Delegate authority from one agent (or human) to another.
|
|
89
|
+
*/
|
|
90
|
+
export function delegate(opts) {
|
|
91
|
+
return createDelegation({
|
|
92
|
+
delegatedTo: opts.toPublicKey,
|
|
93
|
+
delegatedBy: opts.from.publicKey,
|
|
94
|
+
scope: opts.scope,
|
|
95
|
+
spendLimit: opts.spendLimit,
|
|
96
|
+
maxDepth: opts.maxDepth ?? 1,
|
|
97
|
+
expiresInHours: opts.expiresInHours ?? 24,
|
|
98
|
+
privateKey: opts.from.keyPair.privateKey
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Record a unit of work under a delegation.
|
|
103
|
+
*
|
|
104
|
+
* Returns a signed, verifiable receipt.
|
|
105
|
+
*/
|
|
106
|
+
export function recordWork(agent, delegation, delegationChain, work) {
|
|
107
|
+
return createReceipt({
|
|
108
|
+
agentId: agent.agentId,
|
|
109
|
+
delegationId: delegation.delegationId,
|
|
110
|
+
delegation,
|
|
111
|
+
action: {
|
|
112
|
+
type: work.type,
|
|
113
|
+
target: work.target,
|
|
114
|
+
scopeUsed: work.scope,
|
|
115
|
+
spend: work.spend ? { amount: work.spend, currency: work.currency || 'USD' } : undefined
|
|
116
|
+
},
|
|
117
|
+
result: { status: work.result, summary: work.summary },
|
|
118
|
+
delegationChain,
|
|
119
|
+
privateKey: agent.keyPair.privateKey
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Generate cryptographic proof of an agent's contributions.
|
|
124
|
+
*
|
|
125
|
+
* Returns attribution report + Merkle proofs for every receipt +
|
|
126
|
+
* beneficiary traces. A third party can verify any individual
|
|
127
|
+
* receipt without seeing the others.
|
|
128
|
+
*/
|
|
129
|
+
export function proveContributions(agent, receipts, delegations, beneficiary, beneficiaryMap) {
|
|
130
|
+
// Attribution report
|
|
131
|
+
const attribution = computeAttribution(receipts, agent.agentId, beneficiary, agent.keyPair.privateKey);
|
|
132
|
+
// Merkle proofs for each receipt
|
|
133
|
+
const agentReceipts = receipts.filter(r => r.agentId === agent.agentId);
|
|
134
|
+
const hashes = agentReceipts.map(r => hashReceipt(r));
|
|
135
|
+
const proofs = new Map();
|
|
136
|
+
for (let i = 0; i < agentReceipts.length; i++) {
|
|
137
|
+
const proof = generateMerkleProof(hashes, hashes[i]);
|
|
138
|
+
if (proof)
|
|
139
|
+
proofs.set(agentReceipts[i].receiptId, proof);
|
|
140
|
+
}
|
|
141
|
+
// Beneficiary traces
|
|
142
|
+
const bMap = beneficiaryMap || new Map();
|
|
143
|
+
const traces = agentReceipts.map(r => traceBeneficiary(r, delegations, bMap));
|
|
144
|
+
return {
|
|
145
|
+
attribution,
|
|
146
|
+
merkleRoot: attribution.merkleRoot,
|
|
147
|
+
proofs,
|
|
148
|
+
traces
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// ══════════════════════════════════════
|
|
152
|
+
// AUDIT — Check compliance against the Floor
|
|
153
|
+
// ══════════════════════════════════════
|
|
154
|
+
/**
|
|
155
|
+
* Audit an agent's compliance. Requires a verifier keypair
|
|
156
|
+
* (the auditor signs the report).
|
|
157
|
+
*/
|
|
158
|
+
export function auditCompliance(agentId, receipts, floor, delegations, verifierKeyPair) {
|
|
159
|
+
return evaluateCompliance(agentId, receipts, floor, delegations, verifierKeyPair.privateKey);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/contract.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,6CAA6C;AAC7C,iEAAiE;AACjE,EAAE;AACF,yCAAyC;AACzC,EAAE;AACF,+BAA+B;AAC/B,6DAA6D;AAC7D,EAAE;AACF,2BAA2B;AAC3B,uDAAuD;AACvD,EAAE;AACF,kBAAkB;AAClB,0DAA0D;AAC1D,EAAE;AACF,+BAA+B;AAC/B,qDAAqD;AACrD,EA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AAQ,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,CAAC,UAAU,CAAC,CAAA;AAC9F,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ActionReceipt, Delegation, BeneficiaryTrace, AttributionReport, MerkleProof, BeneficiaryInfo } from '../types/passport.js';
|
|
2
|
+
export declare function hashReceipt(receipt: ActionReceipt): string;
|
|
3
|
+
/**
|
|
4
|
+
* Follow the cryptographic chain from an action receipt back
|
|
5
|
+
* to the human who authorized it.
|
|
6
|
+
*
|
|
7
|
+
* This is the fundamental primitive: every agent action resolves
|
|
8
|
+
* to a human. Not through policy. Through math.
|
|
9
|
+
*/
|
|
10
|
+
export declare function traceBeneficiary(receipt: ActionReceipt, delegations: Delegation[], beneficiaryMap: Map<string, BeneficiaryInfo>): BeneficiaryTrace;
|
|
11
|
+
/**
|
|
12
|
+
* Default scope weights. These are DEFAULTS, not universal truth.
|
|
13
|
+
*
|
|
14
|
+
* A healthcare protocol might weight data_analysis at 2.0.
|
|
15
|
+
* A creative protocol might weight coordination at 1.5.
|
|
16
|
+
* The protocol provides the mechanism; the community provides the values.
|
|
17
|
+
*
|
|
18
|
+
* If you don't provide custom weights, these are reasonable.
|
|
19
|
+
* If you do, yours override completely.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_SCOPE_WEIGHTS: Record<string, number>;
|
|
22
|
+
export interface AttributionConfig {
|
|
23
|
+
scopeWeights?: Record<string, number>;
|
|
24
|
+
defaultScopeWeight?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compute attribution with configurable weights.
|
|
28
|
+
*
|
|
29
|
+
* Formula: weight = scope_weight × result × (1 + ln(1 + spend))
|
|
30
|
+
*
|
|
31
|
+
* The logarithm on spend is the one opinion we hardcode,
|
|
32
|
+
* because it's a mechanism design choice, not a value judgment:
|
|
33
|
+
* linear spend weighting creates an arms race. Logarithmic doesn't.
|
|
34
|
+
* This is game theory, not preference.
|
|
35
|
+
*/
|
|
36
|
+
export declare function computeAttribution(receipts: ActionReceipt[], agentId: string, beneficiary: string, privateKey: string, config?: AttributionConfig): AttributionReport;
|
|
37
|
+
export declare function verifyAttributionReport(report: AttributionReport, publicKey: string): {
|
|
38
|
+
valid: boolean;
|
|
39
|
+
errors: string[];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Build a Merkle root from leaf hashes.
|
|
43
|
+
* Leaves are sorted for determinism — same set always produces same root.
|
|
44
|
+
* Odd levels duplicate the last node (standard Bitcoin-style).
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildMerkleRoot(leafHashes: string[]): string;
|
|
47
|
+
/**
|
|
48
|
+
* Generate an inclusion proof for one receipt in the tree.
|
|
49
|
+
* Returns the sibling hashes needed to recompute the root.
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateMerkleProof(leafHashes: string[], targetHash: string): MerkleProof | null;
|
|
52
|
+
/**
|
|
53
|
+
* Verify a Merkle inclusion proof.
|
|
54
|
+
* Recompute the root from the leaf + proof, compare against claimed root.
|
|
55
|
+
*/
|
|
56
|
+
export declare function verifyMerkleProof(proof: MerkleProof): boolean;
|
|
57
|
+
export interface CollaborationAttribution {
|
|
58
|
+
collaborationId: string;
|
|
59
|
+
participants: {
|
|
60
|
+
agentId: string;
|
|
61
|
+
beneficiary: string;
|
|
62
|
+
weight: number;
|
|
63
|
+
percentage: number;
|
|
64
|
+
receiptCount: number;
|
|
65
|
+
}[];
|
|
66
|
+
totalWeight: number;
|
|
67
|
+
merkleRoot: string;
|
|
68
|
+
generatedAt: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function computeCollaborationAttribution(allReceipts: ActionReceipt[], beneficiaryMap: Map<string, string>, config?: AttributionConfig): CollaborationAttribution;
|
|
71
|
+
//# sourceMappingURL=attribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../../../src/core/attribution.ts"],"names":[],"mappings":"AAaA,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MAAM,WAAW,wBAAwB;IACvC,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,WAAW,EAAE,MAAM,CAAA;QACnB,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,EAAE,MAAM,CAAA;QAClB,YAAY,EAAE,MAAM,CAAA;KACrB,EAAE,CAAA;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,aAAa,EAAE,EAC5B,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,MAAM,CAAC,EAAE,iBAAiB,GACzB,wBAAwB,CA6C1B"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// Beneficiary Attribution Protocol — Trace, Attribute, Prove
|
|
2
|
+
// Layer 3 of the Agent Social Contract
|
|
3
|
+
//
|
|
4
|
+
// Design philosophy:
|
|
5
|
+
// This system produces EVIDENCE and PROOFS.
|
|
6
|
+
// Attribution weights are configurable, not hardcoded gospel.
|
|
7
|
+
// The Merkle tree is the real innovation — everything else is plumbing.
|
|
8
|
+
// Keep the plumbing clean so the innovation shines.
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { sign, verify } from '../crypto/keys.js';
|
|
12
|
+
import { canonicalize } from './canonical.js';
|
|
13
|
+
// ══════════════════════════════════════
|
|
14
|
+
// HASH PRIMITIVES
|
|
15
|
+
// ══════════════════════════════════════
|
|
16
|
+
function sha256(data) {
|
|
17
|
+
return createHash('sha256').update(data, 'utf8').digest('hex');
|
|
18
|
+
}
|
|
19
|
+
export function hashReceipt(receipt) {
|
|
20
|
+
return sha256(canonicalize(receipt));
|
|
21
|
+
}
|
|
22
|
+
// ══════════════════════════════════════
|
|
23
|
+
// BENEFICIARY TRACING
|
|
24
|
+
// ══════════════════════════════════════
|
|
25
|
+
/**
|
|
26
|
+
* Follow the cryptographic chain from an action receipt back
|
|
27
|
+
* to the human who authorized it.
|
|
28
|
+
*
|
|
29
|
+
* This is the fundamental primitive: every agent action resolves
|
|
30
|
+
* to a human. Not through policy. Through math.
|
|
31
|
+
*/
|
|
32
|
+
export function traceBeneficiary(receipt, delegations, beneficiaryMap) {
|
|
33
|
+
const chain = [];
|
|
34
|
+
const keyChain = receipt.delegationChain;
|
|
35
|
+
for (let i = 0; i < keyChain.length - 1; i++) {
|
|
36
|
+
const from = keyChain[i];
|
|
37
|
+
const to = keyChain[i + 1];
|
|
38
|
+
const del = delegations.find(d => d.delegatedBy === from && d.delegatedTo === to);
|
|
39
|
+
chain.push({
|
|
40
|
+
from, to,
|
|
41
|
+
delegationId: del?.delegationId || 'unknown',
|
|
42
|
+
scope: del?.scope || [],
|
|
43
|
+
depth: i
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const principalKey = keyChain[0];
|
|
47
|
+
const beneficiary = beneficiaryMap.get(principalKey);
|
|
48
|
+
return {
|
|
49
|
+
traceId: 'trace_' + uuidv4().slice(0, 12),
|
|
50
|
+
receiptId: receipt.receiptId,
|
|
51
|
+
executorAgent: receipt.agentId,
|
|
52
|
+
beneficiary: beneficiary?.principalId || principalKey,
|
|
53
|
+
chain,
|
|
54
|
+
totalDepth: chain.length,
|
|
55
|
+
verified: !!beneficiary && chain.every(h => h.delegationId !== 'unknown')
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// ══════════════════════════════════════
|
|
59
|
+
// ATTRIBUTION WEIGHTS — CONFIGURABLE, NOT GOSPEL
|
|
60
|
+
// ══════════════════════════════════════
|
|
61
|
+
/**
|
|
62
|
+
* Default scope weights. These are DEFAULTS, not universal truth.
|
|
63
|
+
*
|
|
64
|
+
* A healthcare protocol might weight data_analysis at 2.0.
|
|
65
|
+
* A creative protocol might weight coordination at 1.5.
|
|
66
|
+
* The protocol provides the mechanism; the community provides the values.
|
|
67
|
+
*
|
|
68
|
+
* If you don't provide custom weights, these are reasonable.
|
|
69
|
+
* If you do, yours override completely.
|
|
70
|
+
*/
|
|
71
|
+
export const DEFAULT_SCOPE_WEIGHTS = {
|
|
72
|
+
code_execution: 1.0,
|
|
73
|
+
system_control: 0.9,
|
|
74
|
+
data_analysis: 0.8,
|
|
75
|
+
git_operations: 0.7,
|
|
76
|
+
coordination: 0.6,
|
|
77
|
+
file_management: 0.5,
|
|
78
|
+
browser_automation: 0.5,
|
|
79
|
+
email_management: 0.4,
|
|
80
|
+
web_search: 0.3
|
|
81
|
+
};
|
|
82
|
+
const RESULT_MULTIPLIER = {
|
|
83
|
+
success: 1.0,
|
|
84
|
+
partial: 0.5,
|
|
85
|
+
failure: 0.0
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Compute attribution with configurable weights.
|
|
89
|
+
*
|
|
90
|
+
* Formula: weight = scope_weight × result × (1 + ln(1 + spend))
|
|
91
|
+
*
|
|
92
|
+
* The logarithm on spend is the one opinion we hardcode,
|
|
93
|
+
* because it's a mechanism design choice, not a value judgment:
|
|
94
|
+
* linear spend weighting creates an arms race. Logarithmic doesn't.
|
|
95
|
+
* This is game theory, not preference.
|
|
96
|
+
*/
|
|
97
|
+
export function computeAttribution(receipts, agentId, beneficiary, privateKey, config) {
|
|
98
|
+
const weights = config?.scopeWeights || DEFAULT_SCOPE_WEIGHTS;
|
|
99
|
+
const defaultWeight = config?.defaultScopeWeight ?? 0.3;
|
|
100
|
+
const agentReceipts = receipts.filter(r => r.agentId === agentId);
|
|
101
|
+
const entries = agentReceipts.map(receipt => {
|
|
102
|
+
const sw = weights[receipt.action.scopeUsed] ?? defaultWeight;
|
|
103
|
+
const rm = RESULT_MULTIPLIER[receipt.result.status] ?? 0;
|
|
104
|
+
const spend = receipt.action.spend?.amount || 0;
|
|
105
|
+
const weight = sw * rm * (1 + Math.log(1 + spend));
|
|
106
|
+
return {
|
|
107
|
+
receiptId: receipt.receiptId,
|
|
108
|
+
agentId: receipt.agentId,
|
|
109
|
+
action: receipt.action.type,
|
|
110
|
+
scopeUsed: receipt.action.scopeUsed,
|
|
111
|
+
spend,
|
|
112
|
+
resultStatus: receipt.result.status,
|
|
113
|
+
weight: Math.round(weight * 1000) / 1000,
|
|
114
|
+
timestamp: receipt.timestamp
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
const totalWeight = entries.reduce((sum, e) => sum + e.weight, 0);
|
|
118
|
+
const timestamps = entries.map(e => e.timestamp).sort();
|
|
119
|
+
const receiptHashes = agentReceipts.map(r => hashReceipt(r));
|
|
120
|
+
const merkleRoot = buildMerkleRoot(receiptHashes);
|
|
121
|
+
const entriesHash = sha256(canonicalize(entries));
|
|
122
|
+
const report = {
|
|
123
|
+
reportId: 'attr_' + uuidv4().slice(0, 12),
|
|
124
|
+
beneficiary,
|
|
125
|
+
agentId,
|
|
126
|
+
period: {
|
|
127
|
+
from: timestamps[0] || new Date().toISOString(),
|
|
128
|
+
to: timestamps[timestamps.length - 1] || new Date().toISOString()
|
|
129
|
+
},
|
|
130
|
+
entries,
|
|
131
|
+
totalWeight: Math.round(totalWeight * 1000) / 1000,
|
|
132
|
+
receiptCount: agentReceipts.length,
|
|
133
|
+
merkleRoot,
|
|
134
|
+
entriesHash,
|
|
135
|
+
generatedAt: new Date().toISOString()
|
|
136
|
+
};
|
|
137
|
+
const canonical = canonicalize(report);
|
|
138
|
+
const signature = sign(canonical, privateKey);
|
|
139
|
+
return { ...report, signature };
|
|
140
|
+
}
|
|
141
|
+
export function verifyAttributionReport(report, publicKey) {
|
|
142
|
+
const errors = [];
|
|
143
|
+
const { signature, ...unsigned } = report;
|
|
144
|
+
if (!verify(canonicalize(unsigned), signature, publicKey)) {
|
|
145
|
+
errors.push('Invalid attribution report signature');
|
|
146
|
+
}
|
|
147
|
+
if (report.receiptCount !== report.entries.length) {
|
|
148
|
+
errors.push(`Receipt count mismatch: ${report.receiptCount} vs ${report.entries.length} entries`);
|
|
149
|
+
}
|
|
150
|
+
const expectedWeight = report.entries.reduce((sum, e) => sum + e.weight, 0);
|
|
151
|
+
if (Math.abs(report.totalWeight - Math.round(expectedWeight * 1000) / 1000) > 0.001) {
|
|
152
|
+
errors.push('Total weight does not match entry weights');
|
|
153
|
+
}
|
|
154
|
+
if (report.entriesHash) {
|
|
155
|
+
const expected = sha256(canonicalize(report.entries));
|
|
156
|
+
if (report.entriesHash !== expected) {
|
|
157
|
+
errors.push('Entries hash mismatch — weights may have been tampered');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { valid: errors.length === 0, errors };
|
|
161
|
+
}
|
|
162
|
+
// ══════════════════════════════════════
|
|
163
|
+
// MERKLE TREE
|
|
164
|
+
// ══════════════════════════════════════
|
|
165
|
+
// This is the real contribution. Everything above is plumbing.
|
|
166
|
+
// The Merkle tree lets you commit to N receipts in 32 bytes
|
|
167
|
+
// and prove any individual receipt in O(log N) hashes.
|
|
168
|
+
// This is how you scale attribution to millions of actions.
|
|
169
|
+
/**
|
|
170
|
+
* Build a Merkle root from leaf hashes.
|
|
171
|
+
* Leaves are sorted for determinism — same set always produces same root.
|
|
172
|
+
* Odd levels duplicate the last node (standard Bitcoin-style).
|
|
173
|
+
*/
|
|
174
|
+
export function buildMerkleRoot(leafHashes) {
|
|
175
|
+
if (leafHashes.length === 0)
|
|
176
|
+
return sha256('empty');
|
|
177
|
+
if (leafHashes.length === 1)
|
|
178
|
+
return leafHashes[0];
|
|
179
|
+
const sorted = [...leafHashes].sort();
|
|
180
|
+
let level = sorted;
|
|
181
|
+
while (level.length > 1) {
|
|
182
|
+
const next = [];
|
|
183
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
184
|
+
const left = level[i];
|
|
185
|
+
const right = i + 1 < level.length ? level[i + 1] : left;
|
|
186
|
+
next.push(sha256(left + right));
|
|
187
|
+
}
|
|
188
|
+
level = next;
|
|
189
|
+
}
|
|
190
|
+
return level[0];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Generate an inclusion proof for one receipt in the tree.
|
|
194
|
+
* Returns the sibling hashes needed to recompute the root.
|
|
195
|
+
*/
|
|
196
|
+
export function generateMerkleProof(leafHashes, targetHash) {
|
|
197
|
+
if (leafHashes.length === 0)
|
|
198
|
+
return null;
|
|
199
|
+
const sorted = [...leafHashes].sort();
|
|
200
|
+
const targetIndex = sorted.indexOf(targetHash);
|
|
201
|
+
if (targetIndex === -1)
|
|
202
|
+
return null;
|
|
203
|
+
const proof = [];
|
|
204
|
+
let level = sorted;
|
|
205
|
+
let index = targetIndex;
|
|
206
|
+
while (level.length > 1) {
|
|
207
|
+
const next = [];
|
|
208
|
+
const sibling = index % 2 === 0 ? index + 1 : index - 1;
|
|
209
|
+
if (sibling < level.length && sibling !== index) {
|
|
210
|
+
proof.push({ hash: level[sibling], position: index % 2 === 0 ? 'right' : 'left' });
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
proof.push({ hash: level[index], position: 'right' });
|
|
214
|
+
}
|
|
215
|
+
for (let i = 0; i < level.length; i += 2) {
|
|
216
|
+
const left = level[i];
|
|
217
|
+
const right = i + 1 < level.length ? level[i + 1] : left;
|
|
218
|
+
next.push(sha256(left + right));
|
|
219
|
+
}
|
|
220
|
+
level = next;
|
|
221
|
+
index = Math.floor(index / 2);
|
|
222
|
+
}
|
|
223
|
+
return { receiptHash: targetHash, root: level[0], proof, index: targetIndex };
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Verify a Merkle inclusion proof.
|
|
227
|
+
* Recompute the root from the leaf + proof, compare against claimed root.
|
|
228
|
+
*/
|
|
229
|
+
export function verifyMerkleProof(proof) {
|
|
230
|
+
let hash = proof.receiptHash;
|
|
231
|
+
for (const node of proof.proof) {
|
|
232
|
+
hash = node.position === 'left'
|
|
233
|
+
? sha256(node.hash + hash)
|
|
234
|
+
: sha256(hash + node.hash);
|
|
235
|
+
}
|
|
236
|
+
return hash === proof.root;
|
|
237
|
+
}
|
|
238
|
+
export function computeCollaborationAttribution(allReceipts, beneficiaryMap, config) {
|
|
239
|
+
const weights = config?.scopeWeights || DEFAULT_SCOPE_WEIGHTS;
|
|
240
|
+
const defaultWeight = config?.defaultScopeWeight ?? 0.3;
|
|
241
|
+
const byAgent = new Map();
|
|
242
|
+
for (const r of allReceipts) {
|
|
243
|
+
const list = byAgent.get(r.agentId) || [];
|
|
244
|
+
list.push(r);
|
|
245
|
+
byAgent.set(r.agentId, list);
|
|
246
|
+
}
|
|
247
|
+
const participants = [];
|
|
248
|
+
let totalWeight = 0;
|
|
249
|
+
for (const [agentId, receipts] of byAgent) {
|
|
250
|
+
const w = receipts.reduce((sum, r) => {
|
|
251
|
+
const sw = weights[r.action.scopeUsed] ?? defaultWeight;
|
|
252
|
+
const rm = RESULT_MULTIPLIER[r.result.status] ?? 0;
|
|
253
|
+
const spend = r.action.spend?.amount || 0;
|
|
254
|
+
return sum + sw * rm * (1 + Math.log(1 + spend));
|
|
255
|
+
}, 0);
|
|
256
|
+
totalWeight += w;
|
|
257
|
+
participants.push({
|
|
258
|
+
agentId,
|
|
259
|
+
beneficiary: beneficiaryMap.get(agentId) || 'unknown',
|
|
260
|
+
weight: Math.round(w * 1000) / 1000,
|
|
261
|
+
percentage: 0,
|
|
262
|
+
receiptCount: receipts.length
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
for (const p of participants) {
|
|
266
|
+
p.percentage = totalWeight > 0 ? Math.round((p.weight / totalWeight) * 10000) / 100 : 0;
|
|
267
|
+
}
|
|
268
|
+
participants.sort((a, b) => b.percentage - a.percentage);
|
|
269
|
+
return {
|
|
270
|
+
collaborationId: 'collab_' + uuidv4().slice(0, 12),
|
|
271
|
+
participants,
|
|
272
|
+
totalWeight: Math.round(totalWeight * 1000) / 1000,
|
|
273
|
+
merkleRoot: buildMerkleRoot(allReceipts.map(r => hashReceipt(r))),
|
|
274
|
+
generatedAt: new Date().toISOString()
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=attribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../../src/core/attribution.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,uCAAuC;AACvC,EAAE;AACF,qBAAqB;AACrB,8CAA8C;AAC9C,gEAAgE;AAChE,0EAA0E;AAC1E,sDAAsD;AAEtD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAS7C,yCAAyC;AACzC,kBAAkB;AAClB,yCAAyC;AAEzC,SAAS,MAAM,CAAC,IAAY;IAC1B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAChE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAsB;IAChD,OAAO,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;AACtC,CAAC;AAED,yCAAyC;AACzC,sBAAsB;AACtB,yCAAyC;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAsB,EACtB,WAAyB,EACzB,cAA4C;IAE5C,MAAM,KAAK,GAAoB,EAAE,CAAA;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAA;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACxB,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC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