@ouro.bot/cli 0.1.0-alpha.671 → 0.1.0-alpha.673
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/changelog.json +13 -0
- package/dist/a2a/card.js +2 -1
- package/dist/a2a/client.js +37 -0
- package/dist/a2a/delegation-stores.js +56 -0
- package/dist/a2a/did-resolution.js +93 -0
- package/dist/a2a/identity.js +163 -0
- package/dist/a2a/inbound-share.js +107 -0
- package/dist/a2a/mission-result-wire.js +196 -0
- package/dist/a2a/onboarding.js +35 -3
- package/dist/a2a/pin-store.js +132 -0
- package/dist/a2a/seen-ledger.js +120 -0
- package/dist/a2a/server.js +111 -5
- package/dist/a2a/transport.js +45 -0
- package/dist/repertoire/tools-a2a.js +417 -0
- package/dist/senses/a2a-entry.js +31 -1
- package/package.json +2 -2
package/changelog.json
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.673",
|
|
6
|
+
"changes": [
|
|
7
|
+
"A2A connect + delegation layer (friends @ouro.bot/friends alpha.7), on the merged inbound-auth foundation. DID-keyed onboarding: a DID-bearing agent card keys the friend record on its verified did:key (externalId == DID, a2a.did == DID) after verifyCardDidBinding + parseDidKey, so an inbound sealed envelope resolves to that same record (the owner's own agent no longer collapses to stranger); a did-less legacy card stays URL-keyed (backward compatible). New owner-only connect_to tool, gated to the local management sense via authorizeConnect (network/group/internal senses are refused before any card fetch; closed-sense membership fails closed without the roster verifier) and linking at family via connectAgents. Outbound becomes signed+sealed over the direct rung: a new A2ATransport (relay/mailbox are a typed-but-stubbed seam naming ourostack/friends-relay), a2a_send_message seals via sendShare for DID-keyed peers (legacy text send preserved), and a full delegation round-trip — connect_to → coordinate(request, task) (prepareCoordination mints the requestId + first-party delegation, sealed to the peer; the recipient's receiveShare quarantines it under importedDelegations) → list_delegations → send_result (prepareMissionResult over the harness-owned mission_result DataPart wire, which routes to importMissionResult, NOT receiveShare, since mission-result is not a FriendsKind) → importMissionResult lands importedResults[B][requestId], assignee/correlation-gated (assignee_mismatch / no_delegation / no_mission / untrusted_source, fail-closed on a legacy assignee-less delegation). Imported delegations and results land quarantined + attributed, never seed trust, never overwrite first-party; deliver-back is explicit (autonomy is a non-goal).",
|
|
8
|
+
"Security fix (mission_result forgery): the harness-owned mission_result wire now authenticates the sender exactly like the inbound share path. Previously receiveInboundMissionResult trusted the envelope's self-asserted fromAgentId (openSealedEnvelope does AEAD decryption only — no signature verification) and called importMissionResult with no verifier (falling back to the no-op TOFU verifier), so a result signed with an attacker's own key but claiming a victim assignee's DID was accepted and stored under importedResults[victim][requestId] as if the victim delivered it (the recipient's X25519 pubkey is public, so AEAD is no barrier, and the assignee/correlation gates only checked the claimed plaintext DID). The wire now mirrors receiveShare: replay-dedups on the seal nonce (durable SeenLedger), rejects unless opened.signerDid === opened.fromAgentId (sender_binding_mismatch), resolves+pins the sender DID, and hands importMissionResult a real DidVerifier bound to the pinned key so the Ed25519 signature is verified against the pinned key (a non-matching signature is untrusted_source). All authorization gates remain enforced by the importer."
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"version": "0.1.0-alpha.672",
|
|
13
|
+
"changes": [
|
|
14
|
+
"A2A inbound authentication foundation (friends @ouro.bot/friends alpha.7): the agent mints/loads an Ed25519 did:key self-identity (machine-local vault seed) and serves it on its agent card; an inbound friends sealed DataPart is now unwrapped, unsealed, signature-verified, and replay-checked, and the turn runs keyed on the VERIFIED sender DID at that peer's real trust level (read from the friend store by DID, defaulting to stranger) — replacing the previous unauthenticated-a2a-peer collapse. Adds durable harness-owned PinStore (state/a2a/pins, TOFU + signed-rotation evaluation) and SeenLedger (state/a2a/seen, restart-safe replay defense). The legacy unsigned-text inbound path is behavior-preserved (stranger)."
|
|
15
|
+
]
|
|
16
|
+
},
|
|
4
17
|
{
|
|
5
18
|
"version": "0.1.0-alpha.671",
|
|
6
19
|
"changes": [
|
package/dist/a2a/card.js
CHANGED
|
@@ -9,6 +9,7 @@ function buildA2AAgentCard(options) {
|
|
|
9
9
|
name: options.agentName,
|
|
10
10
|
description: options.description ?? `Ouroboros agent ${options.agentName}`,
|
|
11
11
|
protocolVersion: config_1.A2A_DEFAULT_PROTOCOL_VERSION,
|
|
12
|
+
...(options.did ? { did: options.did } : {}),
|
|
12
13
|
url: endpoint,
|
|
13
14
|
preferredTransport: "JSONRPC",
|
|
14
15
|
supportedInterfaces: [{
|
|
@@ -50,7 +51,7 @@ function buildA2AAgentCard(options) {
|
|
|
50
51
|
component: "channels",
|
|
51
52
|
event: "channel.a2a_card_built",
|
|
52
53
|
message: "built A2A agent card",
|
|
53
|
-
meta: { agentName: options.agentName, endpoint },
|
|
54
|
+
meta: { agentName: options.agentName, endpoint, ...(options.did ? { did: options.did } : {}) },
|
|
54
55
|
});
|
|
55
56
|
return card;
|
|
56
57
|
}
|
package/dist/a2a/client.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.endpointForCard = endpointForCard;
|
|
4
4
|
exports.fetchA2AAgentCard = fetchA2AAgentCard;
|
|
5
5
|
exports.sendA2AMessage = sendA2AMessage;
|
|
6
|
+
exports.postA2AMessageEnvelope = postA2AMessageEnvelope;
|
|
6
7
|
exports.getA2ATask = getA2ATask;
|
|
7
8
|
const node_crypto_1 = require("node:crypto");
|
|
8
9
|
const runtime_1 = require("../nerves/runtime");
|
|
@@ -113,6 +114,42 @@ async function sendA2AMessage(input) {
|
|
|
113
114
|
});
|
|
114
115
|
return task;
|
|
115
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* POST a pre-built friends A2A message (a `wrapInDataPart` sealed-envelope message)
|
|
119
|
+
* to a peer endpoint as a JSON-RPC `message/send`. This is the `direct`-rung wire
|
|
120
|
+
* the harness `A2ATransport` uses: friends' `sendShare` builds the sealed message and
|
|
121
|
+
* hands it to the transport, which delivers it here. Unlike `sendA2AMessage` (which
|
|
122
|
+
* builds a text part), this carries the caller's exact `message` (the sealed DataPart)
|
|
123
|
+
* untouched. Throws on a non-2xx response (transport failure).
|
|
124
|
+
*/
|
|
125
|
+
async function postA2AMessageEnvelope(input) {
|
|
126
|
+
const fetchImpl = input.fetchImpl ?? fetch;
|
|
127
|
+
const request = {
|
|
128
|
+
jsonrpc: "2.0",
|
|
129
|
+
id: (0, node_crypto_1.randomUUID)(),
|
|
130
|
+
method: "message/send",
|
|
131
|
+
params: { message: input.message },
|
|
132
|
+
};
|
|
133
|
+
(0, runtime_1.emitNervesEvent)({
|
|
134
|
+
component: "channels",
|
|
135
|
+
event: "channel.a2a_envelope_post_start",
|
|
136
|
+
message: "posting sealed A2A message envelope (direct rung)",
|
|
137
|
+
meta: { endpointUrl: input.endpointUrl },
|
|
138
|
+
});
|
|
139
|
+
let rpc = await postJsonRpc(input.endpointUrl, request, fetchImpl, "0.3");
|
|
140
|
+
if (methodNotFound(rpc)) {
|
|
141
|
+
rpc = await postJsonRpc(input.endpointUrl, { ...request, method: "SendMessage" }, fetchImpl);
|
|
142
|
+
}
|
|
143
|
+
if ("error" in rpc) {
|
|
144
|
+
throw new Error(`A2A error ${rpc.error.code}: ${rpc.error.message}`);
|
|
145
|
+
}
|
|
146
|
+
(0, runtime_1.emitNervesEvent)({
|
|
147
|
+
component: "channels",
|
|
148
|
+
event: "channel.a2a_envelope_post_end",
|
|
149
|
+
message: "posted sealed A2A message envelope",
|
|
150
|
+
meta: { endpointUrl: input.endpointUrl },
|
|
151
|
+
});
|
|
152
|
+
}
|
|
116
153
|
async function getA2ATask(input) {
|
|
117
154
|
const fetchImpl = input.fetchImpl ?? fetch;
|
|
118
155
|
const metadata = senderMetadata(input);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.delegationStoresFor = delegationStoresFor;
|
|
37
|
+
const path = __importStar(require("node:path"));
|
|
38
|
+
const friends_1 = require("@ouro.bot/friends");
|
|
39
|
+
const runtime_1 = require("../nerves/runtime");
|
|
40
|
+
function delegationStoresFor(agentRoot) {
|
|
41
|
+
const friendsDir = path.join(agentRoot, "friends");
|
|
42
|
+
const missionsDir = (0, friends_1.missionsDirFor)(friendsDir);
|
|
43
|
+
const grantsDir = (0, friends_1.grantsDirFor)(friendsDir);
|
|
44
|
+
(0, runtime_1.emitNervesEvent)({
|
|
45
|
+
component: "channels",
|
|
46
|
+
event: "channel.a2a_delegation_stores_init",
|
|
47
|
+
message: "initialized A2A delegation stores (mission + grant)",
|
|
48
|
+
meta: { missionsDir, grantsDir },
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
missionStore: new friends_1.FileMissionStore(missionsDir),
|
|
52
|
+
grantStore: new friends_1.FileGrantStore(grantsDir),
|
|
53
|
+
missionsDir,
|
|
54
|
+
grantsDir,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeDidResolution = makeDidResolution;
|
|
4
|
+
const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
|
|
5
|
+
const runtime_1 = require("../nerves/runtime");
|
|
6
|
+
/**
|
|
7
|
+
* Build the friends `DidResolution` for did:key peers. `resolveAndPin` is the
|
|
8
|
+
* verify-and-pin core the inbound bridge consumes:
|
|
9
|
+
* parse the did:key → derive the presented Ed25519 key →
|
|
10
|
+
* first contact (no pin under `fromAgentId`) → TOFU `pinOnFirstContact`
|
|
11
|
+
* already pinned → `evaluateRotation` against the pin:
|
|
12
|
+
* unchanged → pin-hit, return the pinned key
|
|
13
|
+
* accepted → (re-pinned by evaluateRotation) return the NEW key
|
|
14
|
+
* rejected → loud security event, return null
|
|
15
|
+
*
|
|
16
|
+
* The pin is keyed by the STABLE `fromAgentId` (NOT the did:key string), so a
|
|
17
|
+
* rotation is "same `fromAgentId`, new (did, key)". An unparseable or empty DID is
|
|
18
|
+
* refused (null) and never matchable. The crypto is the friends primitives' — this
|
|
19
|
+
* only sequences them.
|
|
20
|
+
*/
|
|
21
|
+
function makeDidResolution(input) {
|
|
22
|
+
const { sodium, rotationProofFor } = input;
|
|
23
|
+
return {
|
|
24
|
+
async resolveAndPin(args) {
|
|
25
|
+
const { fromAgentId, did, pinStore, trustOfSource } = args;
|
|
26
|
+
// Empty DID is never a matchable key.
|
|
27
|
+
if (!did) {
|
|
28
|
+
(0, runtime_1.emitNervesEvent)({
|
|
29
|
+
component: "channels",
|
|
30
|
+
event: "channel.a2a_did_resolve_refused",
|
|
31
|
+
message: "A2A DID resolve refused (empty DID)",
|
|
32
|
+
meta: { fromAgentId, reason: "empty_did" },
|
|
33
|
+
});
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const parsed = (0, a2a_client_1.parseDidKey)(did);
|
|
37
|
+
if (!parsed) {
|
|
38
|
+
(0, runtime_1.emitNervesEvent)({
|
|
39
|
+
component: "channels",
|
|
40
|
+
event: "channel.a2a_did_resolve_refused",
|
|
41
|
+
message: "A2A DID resolve refused (unparseable did:key)",
|
|
42
|
+
meta: { fromAgentId, reason: "parse_failed" },
|
|
43
|
+
});
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const pinned = pinStore.get(fromAgentId);
|
|
47
|
+
if (!pinned) {
|
|
48
|
+
// First contact (TOFU): accept + pin the (did, key) under fromAgentId.
|
|
49
|
+
(0, a2a_client_1.pinOnFirstContact)({ pinStore, fromAgentId, did, ed25519Pub: parsed.ed25519Pub });
|
|
50
|
+
(0, runtime_1.emitNervesEvent)({
|
|
51
|
+
component: "channels",
|
|
52
|
+
event: "channel.a2a_pin_first_contact",
|
|
53
|
+
message: "A2A DID pinned on first contact",
|
|
54
|
+
meta: { fromAgentId, did },
|
|
55
|
+
});
|
|
56
|
+
return { ed25519Pub: parsed.ed25519Pub };
|
|
57
|
+
}
|
|
58
|
+
// Already pinned: evaluate the presented key against the pin.
|
|
59
|
+
const rotationProof = rotationProofFor?.(fromAgentId, did, parsed.ed25519Pub);
|
|
60
|
+
const decision = (0, a2a_client_1.evaluateRotation)({
|
|
61
|
+
sodium,
|
|
62
|
+
pinStore,
|
|
63
|
+
fromAgentId,
|
|
64
|
+
trustOfSource,
|
|
65
|
+
newDid: did,
|
|
66
|
+
newEd25519Pub: parsed.ed25519Pub,
|
|
67
|
+
rotationProof,
|
|
68
|
+
});
|
|
69
|
+
if (decision.decision === "unchanged") {
|
|
70
|
+
// Same key — pin-hit. (FileA2APinStore.get already emitted a2a_pin_hit.)
|
|
71
|
+
return { ed25519Pub: parsed.ed25519Pub };
|
|
72
|
+
}
|
|
73
|
+
if (decision.decision === "accepted") {
|
|
74
|
+
// evaluateRotation already re-pinned to the new key under fromAgentId.
|
|
75
|
+
(0, runtime_1.emitNervesEvent)({
|
|
76
|
+
component: "channels",
|
|
77
|
+
event: "channel.a2a_rotation_accepted",
|
|
78
|
+
message: "A2A signed key rotation accepted",
|
|
79
|
+
meta: { fromAgentId, newDid: did, trustOfSource },
|
|
80
|
+
});
|
|
81
|
+
return { ed25519Pub: parsed.ed25519Pub };
|
|
82
|
+
}
|
|
83
|
+
// Rejected — loud security signal (carries the reason).
|
|
84
|
+
(0, runtime_1.emitNervesEvent)({
|
|
85
|
+
component: "channels",
|
|
86
|
+
event: "channel.a2a_rotation_rejected",
|
|
87
|
+
message: "A2A key rotation rejected",
|
|
88
|
+
meta: { fromAgentId, newDid: did, trustOfSource, reason: decision.reason },
|
|
89
|
+
});
|
|
90
|
+
return null;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readStoredA2ASeed = readStoredA2ASeed;
|
|
37
|
+
exports.loadOrMintA2AIdentity = loadOrMintA2AIdentity;
|
|
38
|
+
exports.loadSelfA2AIdentity = loadSelfA2AIdentity;
|
|
39
|
+
const crypto = __importStar(require("node:crypto"));
|
|
40
|
+
const os = __importStar(require("node:os"));
|
|
41
|
+
const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
|
|
42
|
+
const runtime_1 = require("../nerves/runtime");
|
|
43
|
+
const runtime_credentials_1 = require("../heart/runtime-credentials");
|
|
44
|
+
const machine_identity_1 = require("../heart/machine-identity");
|
|
45
|
+
/** The number of raw bytes in an Ed25519 seed. */
|
|
46
|
+
const ED25519_SEED_BYTES = 32;
|
|
47
|
+
/** The machine-config key path for the persisted seed: `a2a.identity.ed25519Seed`. */
|
|
48
|
+
function a2aIdentityConfig(config) {
|
|
49
|
+
const a2a = config.a2a;
|
|
50
|
+
if (!a2a || typeof a2a !== "object" || Array.isArray(a2a))
|
|
51
|
+
return undefined;
|
|
52
|
+
const identity = a2a.identity;
|
|
53
|
+
if (!identity || typeof identity !== "object" || Array.isArray(identity))
|
|
54
|
+
return undefined;
|
|
55
|
+
return identity;
|
|
56
|
+
}
|
|
57
|
+
/** Read the stored Ed25519 seed string from a machine-config object, or undefined. */
|
|
58
|
+
function readStoredA2ASeed(config) {
|
|
59
|
+
const identity = a2aIdentityConfig(config);
|
|
60
|
+
const seed = identity?.ed25519Seed;
|
|
61
|
+
return typeof seed === "string" && seed.length > 0 ? seed : undefined;
|
|
62
|
+
}
|
|
63
|
+
/** Decode + validate a stored seed string into 32 raw bytes. Throws on malformed. */
|
|
64
|
+
function decodeSeed(seedString) {
|
|
65
|
+
let decoded;
|
|
66
|
+
try {
|
|
67
|
+
decoded = Buffer.from(seedString, "base64url");
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
/* v8 ignore next -- Buffer.from(base64url) does not throw on bad chars; this guards future decoders @preserve */
|
|
71
|
+
throw new Error("malformed A2A identity seed: not decodable");
|
|
72
|
+
}
|
|
73
|
+
// base64url is lenient (it silently drops invalid chars), so the length check is
|
|
74
|
+
// the real gate: a real Ed25519 seed is exactly 32 bytes.
|
|
75
|
+
if (decoded.length !== ED25519_SEED_BYTES) {
|
|
76
|
+
throw new Error(`malformed A2A identity seed: expected ${ED25519_SEED_BYTES}-byte seed, got ${decoded.length}`);
|
|
77
|
+
}
|
|
78
|
+
return new Uint8Array(decoded);
|
|
79
|
+
}
|
|
80
|
+
/** Mint a fresh 32-byte Ed25519 seed (Node keygen → JWK `d`, the raw seed). */
|
|
81
|
+
function mintSeed() {
|
|
82
|
+
const { privateKey } = crypto.generateKeyPairSync("ed25519");
|
|
83
|
+
const jwk = privateKey.export({ format: "jwk" });
|
|
84
|
+
/* v8 ignore next -- Node always emits the `d` field for an Ed25519 private JWK; guard protects future runtimes @preserve */
|
|
85
|
+
if (typeof jwk.d !== "string")
|
|
86
|
+
throw new Error("failed to mint A2A identity seed: missing JWK d");
|
|
87
|
+
return decodeSeed(jwk.d);
|
|
88
|
+
}
|
|
89
|
+
/** Derive the full did:key identity from a 32-byte seed (deterministic). */
|
|
90
|
+
function deriveIdentity(sodium, seed) {
|
|
91
|
+
const keypair = sodium.crypto_sign_seed_keypair(seed);
|
|
92
|
+
const didIdentity = (0, a2a_client_1.didKeyIdentityFromEd25519)({
|
|
93
|
+
sodium,
|
|
94
|
+
ed25519Pub: keypair.publicKey,
|
|
95
|
+
ed25519Priv: keypair.privateKey,
|
|
96
|
+
});
|
|
97
|
+
return { ...didIdentity, seed: Buffer.from(seed).toString("base64url") };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Load the agent's A2A identity from the machine-local config, or mint + persist
|
|
101
|
+
* one on first use. A malformed stored seed FAILS FAST (it never silently
|
|
102
|
+
* re-mints, which would change the agent's DID). The mint path persists the new
|
|
103
|
+
* seed via `upsert` before deriving; the load path performs no writes.
|
|
104
|
+
*/
|
|
105
|
+
async function loadOrMintA2AIdentity(input) {
|
|
106
|
+
const stored = readStoredA2ASeed(input.config);
|
|
107
|
+
if (stored) {
|
|
108
|
+
// Load path: a malformed seed throws (no re-mint).
|
|
109
|
+
const seed = decodeSeed(stored);
|
|
110
|
+
const identity = deriveIdentity(input.sodium, seed);
|
|
111
|
+
(0, runtime_1.emitNervesEvent)({
|
|
112
|
+
component: "channels",
|
|
113
|
+
event: "channel.a2a_identity_loaded",
|
|
114
|
+
message: "loaded A2A identity from machine config",
|
|
115
|
+
meta: { agentName: input.agentName, did: identity.did },
|
|
116
|
+
});
|
|
117
|
+
return identity;
|
|
118
|
+
}
|
|
119
|
+
// Mint path: generate a seed, persist it under a2a.identity.*, then derive.
|
|
120
|
+
const seed = mintSeed();
|
|
121
|
+
const seedString = Buffer.from(seed).toString("base64url");
|
|
122
|
+
const a2a = (input.config.a2a && typeof input.config.a2a === "object" && !Array.isArray(input.config.a2a)
|
|
123
|
+
? input.config.a2a
|
|
124
|
+
: {});
|
|
125
|
+
const identityBlock = (a2a.identity && typeof a2a.identity === "object" && !Array.isArray(a2a.identity)
|
|
126
|
+
? a2a.identity
|
|
127
|
+
: {});
|
|
128
|
+
const nextConfig = {
|
|
129
|
+
...input.config,
|
|
130
|
+
a2a: { ...a2a, identity: { ...identityBlock, ed25519Seed: seedString } },
|
|
131
|
+
};
|
|
132
|
+
await input.upsert(nextConfig);
|
|
133
|
+
const identity = deriveIdentity(input.sodium, seed);
|
|
134
|
+
(0, runtime_1.emitNervesEvent)({
|
|
135
|
+
component: "channels",
|
|
136
|
+
event: "channel.a2a_identity_minted",
|
|
137
|
+
message: "minted new A2A identity and persisted seed to machine config",
|
|
138
|
+
meta: { agentName: input.agentName, did: identity.did },
|
|
139
|
+
});
|
|
140
|
+
return identity;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Load (or mint-on-first-use) THIS agent's own A2A identity from the machine-local
|
|
144
|
+
* runtime config — the convenience entry the main-process tools use to obtain the
|
|
145
|
+
* self identity that signs outbound sealed envelopes. Mirrors the a2a sense
|
|
146
|
+
* entrypoint's load (read machine config → `loadOrMintA2AIdentity` → persist a fresh
|
|
147
|
+
* seed under the right machine id). Reads the in-memory machine-config cache (no
|
|
148
|
+
* remote vault round-trip per call). `sodium` is optional (defaults to `ready()`).
|
|
149
|
+
*/
|
|
150
|
+
async function loadSelfA2AIdentity(input) {
|
|
151
|
+
const sodium = input.sodium ?? await (0, a2a_client_1.ready)();
|
|
152
|
+
const machineId = (0, machine_identity_1.loadOrCreateMachineIdentity)({ homeDir: os.homedir() }).machineId;
|
|
153
|
+
const read = (0, runtime_credentials_1.readMachineRuntimeCredentialConfig)(input.agentName);
|
|
154
|
+
const config = read.ok ? read.config : {};
|
|
155
|
+
return loadOrMintA2AIdentity({
|
|
156
|
+
agentName: input.agentName,
|
|
157
|
+
sodium,
|
|
158
|
+
config,
|
|
159
|
+
upsert: async (next) => {
|
|
160
|
+
await (0, runtime_credentials_1.upsertMachineRuntimeCredentialConfig)(input.agentName, machineId, next);
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.receiveInboundShare = receiveInboundShare;
|
|
4
|
+
const a2a_client_1 = require("@ouro.bot/friends/a2a-client");
|
|
5
|
+
const friends_1 = require("@ouro.bot/friends");
|
|
6
|
+
const runtime_1 = require("../nerves/runtime");
|
|
7
|
+
/** Whether the inbound message carries a friends data part (kind:"data"). */
|
|
8
|
+
function hasDataPart(message) {
|
|
9
|
+
return Array.isArray(message.parts) && message.parts.some((p) => p && p.kind === "data");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Bridge an inbound A2A message through friends' `receiveShare`, keying the result
|
|
13
|
+
* on the VERIFIED sender DID.
|
|
14
|
+
*
|
|
15
|
+
* Ordering (the security-critical trap — `trustOfSource` is read from the store BY
|
|
16
|
+
* the just-verified DID, never defaulted, never from the envelope):
|
|
17
|
+
* 1. `unwrapDataPart` — no friends part ⇒ `not-a-share` (caller does text path).
|
|
18
|
+
* 2. `openSealedEnvelope` (pre-unseal) — extract the SIGNED sender DID. Unseal /
|
|
19
|
+
* recipient-mismatch failures ⇒ `rejected` (no turn). (This open does NOT
|
|
20
|
+
* verify the signature; the real auth gate is the `DidVerifier` inside
|
|
21
|
+
* `receiveShare`, so a forged-high-trust claim here is harmless — the forge is
|
|
22
|
+
* rejected by the verifier regardless of the trust we read.)
|
|
23
|
+
* 3. `findFriendByDid(store, verifiedDid)` — read trust off that record; an
|
|
24
|
+
* unknown DID ⇒ `stranger` (never a default-up).
|
|
25
|
+
* 4. `receiveShare({ ..., trustOfSource })` — re-unseal (deterministic) + resolve
|
|
26
|
+
* & pin + run `DidVerifier` (forge fails HERE) + replay-dedup + import.
|
|
27
|
+
* 5. Map the result. `completed` ⇒ run the turn at `verifiedDid`/`trust`.
|
|
28
|
+
*/
|
|
29
|
+
async function receiveInboundShare(message, deps) {
|
|
30
|
+
const friendsMessage = message;
|
|
31
|
+
const payload = (0, a2a_client_1.unwrapDataPart)(friendsMessage);
|
|
32
|
+
if (!payload) {
|
|
33
|
+
// No (valid) friends part. If there was a data part at all, it was a malformed
|
|
34
|
+
// friends attempt → reject; otherwise it's a legacy text message → not-a-share.
|
|
35
|
+
if (hasDataPart(message)) {
|
|
36
|
+
(0, runtime_1.emitNervesEvent)({
|
|
37
|
+
component: "channels",
|
|
38
|
+
event: "channel.a2a_inbound_rejected",
|
|
39
|
+
message: "rejected malformed inbound A2A data part",
|
|
40
|
+
meta: { reason: "malformed_message" },
|
|
41
|
+
});
|
|
42
|
+
return { outcome: "rejected", reason: "malformed_message" };
|
|
43
|
+
}
|
|
44
|
+
return { outcome: "not-a-share" };
|
|
45
|
+
}
|
|
46
|
+
const recipientIdentity = {
|
|
47
|
+
x25519Priv: deps.identity.x25519Priv,
|
|
48
|
+
x25519Pub: deps.identity.x25519Pub,
|
|
49
|
+
};
|
|
50
|
+
// Pre-unseal to learn the SIGNED sender DID before we can read its trust.
|
|
51
|
+
const opened = (0, a2a_client_1.openSealedEnvelope)({
|
|
52
|
+
sodium: deps.sodium,
|
|
53
|
+
sealedEnvelope: { v: payload.v, sealed: payload.sealed },
|
|
54
|
+
recipientDid: deps.identity.did,
|
|
55
|
+
recipientIdentity,
|
|
56
|
+
});
|
|
57
|
+
if (!opened.ok) {
|
|
58
|
+
(0, runtime_1.emitNervesEvent)({
|
|
59
|
+
component: "channels",
|
|
60
|
+
event: "channel.a2a_inbound_rejected",
|
|
61
|
+
message: "rejected inbound A2A envelope (unseal/recipient)",
|
|
62
|
+
meta: { reason: opened.error },
|
|
63
|
+
});
|
|
64
|
+
return { outcome: "rejected", reason: opened.error };
|
|
65
|
+
}
|
|
66
|
+
const verifiedDid = opened.fromAgentId;
|
|
67
|
+
// Read trust from the friend store BY the verified DID — never defaulted, never
|
|
68
|
+
// from the envelope. Unknown (or empty) DID ⇒ stranger. `findFriendByDid` itself
|
|
69
|
+
// refuses a falsy did (never matches a did-less record), so this is safe to call
|
|
70
|
+
// unconditionally.
|
|
71
|
+
const record = await (0, friends_1.findFriendByDid)(deps.store, verifiedDid);
|
|
72
|
+
const trust = record?.trustLevel ?? "stranger";
|
|
73
|
+
const result = await (0, a2a_client_1.receiveShare)({
|
|
74
|
+
sodium: deps.sodium,
|
|
75
|
+
store: deps.store,
|
|
76
|
+
missionStore: deps.missionStore,
|
|
77
|
+
pinStore: deps.pinStore,
|
|
78
|
+
didResolution: deps.didResolution,
|
|
79
|
+
seen: deps.seen,
|
|
80
|
+
a2aMessage: friendsMessage,
|
|
81
|
+
recipientDid: deps.identity.did,
|
|
82
|
+
recipientIdentity,
|
|
83
|
+
trustOfSource: trust,
|
|
84
|
+
});
|
|
85
|
+
if (result.state === "completed") {
|
|
86
|
+
(0, runtime_1.emitNervesEvent)({
|
|
87
|
+
component: "channels",
|
|
88
|
+
event: "channel.a2a_inbound_verified",
|
|
89
|
+
message: "verified inbound A2A share; keying turn on sender DID",
|
|
90
|
+
meta: { verifiedDid, trust, friendsKind: result.friendsKind, status: result.status },
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
outcome: "completed",
|
|
94
|
+
verifiedDid,
|
|
95
|
+
trust,
|
|
96
|
+
friendsKind: result.friendsKind,
|
|
97
|
+
status: result.status,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
(0, runtime_1.emitNervesEvent)({
|
|
101
|
+
component: "channels",
|
|
102
|
+
event: "channel.a2a_inbound_rejected",
|
|
103
|
+
message: "rejected inbound A2A share",
|
|
104
|
+
meta: { reason: result.reason, verifiedDid, trust },
|
|
105
|
+
});
|
|
106
|
+
return { outcome: "rejected", reason: result.reason };
|
|
107
|
+
}
|