@motebit/protocol 2.0.1 → 3.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.
Files changed (59) hide show
  1. package/README.md +6 -1
  2. package/dist/agent-revocation.d.ts +184 -0
  3. package/dist/agent-revocation.d.ts.map +1 -0
  4. package/dist/agent-revocation.js +108 -0
  5. package/dist/agent-revocation.js.map +1 -0
  6. package/dist/agent-settlement-anchor.d.ts +12 -0
  7. package/dist/agent-settlement-anchor.d.ts.map +1 -1
  8. package/dist/artifact-type.d.ts +25 -7
  9. package/dist/artifact-type.d.ts.map +1 -1
  10. package/dist/artifact-type.js +9 -0
  11. package/dist/artifact-type.js.map +1 -1
  12. package/dist/audience.d.ts +4 -1
  13. package/dist/audience.d.ts.map +1 -1
  14. package/dist/audience.js +3 -0
  15. package/dist/audience.js.map +1 -1
  16. package/dist/base58.d.ts +20 -0
  17. package/dist/base58.d.ts.map +1 -0
  18. package/dist/base58.js +47 -0
  19. package/dist/base58.js.map +1 -0
  20. package/dist/credential-anchor.d.ts +12 -0
  21. package/dist/credential-anchor.d.ts.map +1 -1
  22. package/dist/federation-settlement-anchor.d.ts +140 -0
  23. package/dist/federation-settlement-anchor.d.ts.map +1 -0
  24. package/dist/federation-settlement-anchor.js +22 -0
  25. package/dist/federation-settlement-anchor.js.map +1 -0
  26. package/dist/index.d.ts +179 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +6 -14
  29. package/dist/index.js.map +1 -1
  30. package/dist/memory-events.d.ts +5 -2
  31. package/dist/memory-events.d.ts.map +1 -1
  32. package/dist/merkle-tree-hash.d.ts +97 -0
  33. package/dist/merkle-tree-hash.d.ts.map +1 -0
  34. package/dist/merkle-tree-hash.js +78 -0
  35. package/dist/merkle-tree-hash.js.map +1 -0
  36. package/dist/money.d.ts +45 -0
  37. package/dist/money.d.ts.map +1 -1
  38. package/dist/money.js +50 -0
  39. package/dist/money.js.map +1 -1
  40. package/dist/retention-policy.d.ts +7 -8
  41. package/dist/retention-policy.d.ts.map +1 -1
  42. package/dist/retention-policy.js.map +1 -1
  43. package/dist/settlement-mode.d.ts +34 -0
  44. package/dist/settlement-mode.d.ts.map +1 -1
  45. package/dist/settlement-summary.d.ts +102 -0
  46. package/dist/settlement-summary.d.ts.map +1 -0
  47. package/dist/settlement-summary.js +28 -0
  48. package/dist/settlement-summary.js.map +1 -0
  49. package/dist/skills.d.ts +1 -2
  50. package/dist/skills.d.ts.map +1 -1
  51. package/dist/skills.js.map +1 -1
  52. package/dist/transparency.d.ts +2 -3
  53. package/dist/transparency.d.ts.map +1 -1
  54. package/dist/transparency.js.map +1 -1
  55. package/dist/trust-algebra.d.ts +0 -15
  56. package/dist/trust-algebra.d.ts.map +1 -1
  57. package/dist/trust-algebra.js +2 -15
  58. package/dist/trust-algebra.js.map +1 -1
  59. package/package.json +3 -3
@@ -5,6 +5,7 @@
5
5
  * for credential anchoring. Any implementation can produce and verify anchor
6
6
  * proofs using these types.
7
7
  */
8
+ import type { MerkleTreeVersion } from "./merkle-tree-hash.js";
8
9
  /** A batch of credential hashes anchored as a Merkle tree. */
9
10
  export interface CredentialAnchorBatch {
10
11
  /** UUID v4 batch identifier. */
@@ -79,6 +80,17 @@ export interface CredentialAnchorProof {
79
80
  batch_signature: string;
80
81
  /** Onchain anchor metadata, or null if not yet submitted. */
81
82
  anchor: CredentialChainAnchor | null;
83
+ /**
84
+ * Tree-hash recipe for the Merkle path (leaf-domain / node-domain tags +
85
+ * hash). A `MerkleTreeVersion` from `merkle-tree-hash.ts`. **Absent ⇒
86
+ * `merkle-sha256-plain-v1`** — every proof minted before this axis existed
87
+ * still verifies offline. Verifiers resolve absent to the default and reject
88
+ * an unknown value fail-closed (never silently downgrade); a v2 producer MUST
89
+ * emit it rather than rely on the default. Separate axis from `suite` (the
90
+ * batch-signature recipe). See
91
+ * `docs/doctrine/merkle-tree-hash-versioning.md`.
92
+ */
93
+ tree_hash_version?: MerkleTreeVersion;
82
94
  }
83
95
  /**
84
96
  * Chain-agnostic interface for submitting Merkle roots onchain.
@@ -1 +1 @@
1
- {"version":3,"file":"credential-anchor.d.ts","sourceRoot":"","sources":["../src/credential-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,KAAK,EAAE,4BAA4B,CAAC;IACpC,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACtC;AAED,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,oFAAoF;AACpF,MAAM,WAAW,qBAAqB;IACpC,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,eAAe,EAAE,MAAM,CAAC;IACxB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,eAAe,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,cAAc,EAAE,MAAM,CAAC;IACvB,8DAA8D;IAC9D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MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iCAAiC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChG,8EAA8E;IAC9E,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Federation settlement anchor types — motebit/relay-federation@1.2 §7.6.
3
+ *
4
+ * Permissive floor (Apache-2.0): these types define the interoperable format
5
+ * for inter-relay settlement anchoring — peer audit between federated relays.
6
+ *
7
+ * Audience-distinct from per-agent settlement anchoring (agent-settlement-anchor-v1.md,
8
+ * worker audit of relay-as-counterparty) and credential anchoring
9
+ * (credential-anchor-v1.md, agent reputation portability). Same Merkle
10
+ * primitive, different proof endpoint and source table — see
11
+ * spec/agent-settlement-anchor-v1.md §9.
12
+ *
13
+ * Convergence (spec/agent-settlement-anchor-v1.md §9.1, the arc-closer): the
14
+ * federation leaf is now `canonicalLeaf(the WHOLE signed FederationSettlementRecord)`
15
+ * — the verbatim-artifact hash the per-agent and credential streams already
16
+ * use — never a hand-typed column projection. The relay signs a canonical
17
+ * record of each settlement it books, persists it verbatim, and anchors the
18
+ * exact bytes; a peer who holds that signed record reproduces the leaf with
19
+ * `@motebit/crypto` alone (`verifyFederationSettlementAnchor`).
20
+ */
21
+ import type { MerkleTreeVersion } from "./merkle-tree-hash.js";
22
+ /**
23
+ * A relay's signed record of one federation settlement it booked — the exact
24
+ * artifact whose canonical bytes become the Merkle leaf (the "verbatim-leaf"
25
+ * shape per spec/agent-settlement-anchor-v1.md §9.1). Each relay signs and
26
+ * anchors its OWN copy of a settlement (the issuer is whichever relay booked
27
+ * the row), so the leaf reproduces from the bytes a peer holds — no
28
+ * re-projection of a sibling's database.
29
+ *
30
+ * The signing "floor" mirrors the per-agent `SettlementRecord` (settlement-v1.md
31
+ * §3): the issuing relay commits to the (gross, fee, net, rate) tuple, so it
32
+ * cannot issue inconsistent records to different observers. The Merkle anchor
33
+ * (relay-federation-v1.md §7.6) is the "ceiling" on top.
34
+ */
35
+ export interface FederationSettlementRecord {
36
+ /** UUID settlement identifier (unique per booking relay). */
37
+ settlement_id: string;
38
+ /** Task this settlement pays for. */
39
+ task_id: string;
40
+ /** MotebitId of the upstream (origin) relay in the federation hop. */
41
+ upstream_relay_id: string;
42
+ /** MotebitId of the downstream relay, or null when this relay is the origin. */
43
+ downstream_relay_id: string | null;
44
+ /** MotebitId of the executing agent, or null when not attributed. */
45
+ agent_id: string | null;
46
+ /** Gross amount in micro-units before the platform fee. */
47
+ gross_amount: number;
48
+ /** Platform fee extracted by the relay, in micro-units. */
49
+ fee_amount: number;
50
+ /** Net amount forwarded, in micro-units (`gross_amount - fee_amount`). */
51
+ net_amount: number;
52
+ /** Fee rate applied (e.g. 0.05 = 5%). Recorded per-settlement for auditability. */
53
+ fee_rate: number;
54
+ /** Hash of the execution receipt this settlement pays against. */
55
+ receipt_hash: string;
56
+ /** Millisecond timestamp when this relay booked the settlement. */
57
+ settled_at: number;
58
+ /** x402 payment transaction hash (when paid on-chain). */
59
+ x402_tx_hash?: string;
60
+ /** x402 network used for payment (CAIP-2 identifier). */
61
+ x402_network?: string;
62
+ /** MotebitId of the relay that signed this record (the booking relay). */
63
+ issuer_relay_id: string;
64
+ /**
65
+ * Cryptosuite discriminator for `signature`. Always
66
+ * `"motebit-jcs-ed25519-b64-v1"` — JCS canonicalization of the unsigned
67
+ * record, Ed25519 primitive, base64url signature encoding (matching the
68
+ * per-agent `SettlementRecord` suite). Verifiers reject missing or unknown
69
+ * suite values fail-closed.
70
+ */
71
+ suite: "motebit-jcs-ed25519-b64-v1";
72
+ /** Base64url-encoded Ed25519 signature over the canonical unsigned record. */
73
+ signature: string;
74
+ }
75
+ /** Onchain anchor reference — chain-agnostic. */
76
+ export interface FederationSettlementChainAnchor {
77
+ /** Chain identifier (e.g., "eip155"). */
78
+ chain: string;
79
+ /** CAIP-2 network identifier (e.g., "eip155:8453" for Base). */
80
+ network: string;
81
+ /** Transaction hash on the target chain. */
82
+ tx_hash: string;
83
+ /** Millisecond timestamp when the anchor was confirmed. */
84
+ anchored_at: number;
85
+ }
86
+ /** Self-verifiable Merkle inclusion proof for a federation settlement in an anchored batch. */
87
+ export interface FederationSettlementAnchorProof {
88
+ /** Settlement identifier. */
89
+ settlement_id: string;
90
+ /**
91
+ * Hex-encoded SHA-256 hash of the canonical signed `FederationSettlementRecord`
92
+ * (the exact bytes a peer holds, signature included) — the verbatim-artifact
93
+ * leaf per spec/agent-settlement-anchor-v1.md §9.1.
94
+ */
95
+ settlement_hash: string;
96
+ /** Batch containing this settlement. */
97
+ batch_id: string;
98
+ /** Hex-encoded Merkle root of the batch. */
99
+ merkle_root: string;
100
+ /** Number of settlements in this batch (needed for batch signature verification). */
101
+ leaf_count: number;
102
+ /** Millisecond timestamp of the earliest settlement in the batch. */
103
+ first_settled_at: number;
104
+ /** Millisecond timestamp of the latest settlement in the batch. */
105
+ last_settled_at: number;
106
+ /** Position of this settlement's leaf in the sorted array. */
107
+ leaf_index: number;
108
+ /** Hex-encoded sibling hashes for Merkle path verification. */
109
+ siblings: string[];
110
+ /** Layer sizes for odd-leaf promotion detection. */
111
+ layer_sizes: number[];
112
+ /** MotebitId of the relay that created the batch. */
113
+ relay_id: string;
114
+ /** Hex-encoded Ed25519 public key of the relay (for batch_signature verification). */
115
+ relay_public_key: string;
116
+ /**
117
+ * Cryptosuite discriminator for `batch_signature`. Always
118
+ * `"motebit-jcs-ed25519-hex-v1"` — JCS canonicalization of the batch
119
+ * payload, Ed25519 primitive, hex signature encoding, hex public-key
120
+ * encoding. Suite-bound (cryptosuite-agility: part of the signed payload).
121
+ * Verifiers reject missing or unknown suite values fail-closed.
122
+ */
123
+ suite: "motebit-jcs-ed25519-hex-v1";
124
+ /** Hex-encoded Ed25519 signature over the canonical batch payload. */
125
+ batch_signature: string;
126
+ /** Onchain anchor metadata, or null if not yet submitted. */
127
+ anchor: FederationSettlementChainAnchor | null;
128
+ /**
129
+ * Tree-hash recipe for the Merkle path (leaf-domain / node-domain tags +
130
+ * hash). A `MerkleTreeVersion` from `merkle-tree-hash.ts`. **Absent ⇒
131
+ * `merkle-sha256-plain-v1`** — every proof minted before this axis existed
132
+ * still verifies offline. Verifiers resolve absent to the default and reject
133
+ * an unknown value fail-closed (never silently downgrade); a v2 producer MUST
134
+ * emit it rather than rely on the default. Separate axis from `suite` (the
135
+ * batch-signature recipe). See
136
+ * `docs/doctrine/merkle-tree-hash-versioning.md`.
137
+ */
138
+ tree_hash_version?: MerkleTreeVersion;
139
+ }
140
+ //# sourceMappingURL=federation-settlement-anchor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"federation-settlement-anchor.d.ts","sourceRoot":"","sources":["../src/federation-settlement-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI/D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,0BAA0B;IACzC,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gFAAgF;IAChF,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,qEAAqE;IACrE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACn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AAK,EAAE,4BAA4B,CAAC;IACpC,sEAAsE;IACtE,eAAe,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;IAC/C;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Federation settlement anchor types — motebit/relay-federation@1.2 §7.6.
3
+ *
4
+ * Permissive floor (Apache-2.0): these types define the interoperable format
5
+ * for inter-relay settlement anchoring — peer audit between federated relays.
6
+ *
7
+ * Audience-distinct from per-agent settlement anchoring (agent-settlement-anchor-v1.md,
8
+ * worker audit of relay-as-counterparty) and credential anchoring
9
+ * (credential-anchor-v1.md, agent reputation portability). Same Merkle
10
+ * primitive, different proof endpoint and source table — see
11
+ * spec/agent-settlement-anchor-v1.md §9.
12
+ *
13
+ * Convergence (spec/agent-settlement-anchor-v1.md §9.1, the arc-closer): the
14
+ * federation leaf is now `canonicalLeaf(the WHOLE signed FederationSettlementRecord)`
15
+ * — the verbatim-artifact hash the per-agent and credential streams already
16
+ * use — never a hand-typed column projection. The relay signs a canonical
17
+ * record of each settlement it books, persists it verbatim, and anchors the
18
+ * exact bytes; a peer who holds that signed record reproduces the leaf with
19
+ * `@motebit/crypto` alone (`verifyFederationSettlementAnchor`).
20
+ */
21
+ export {};
22
+ //# sourceMappingURL=federation-settlement-anchor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"federation-settlement-anchor.js","sourceRoot":"","sources":["../src/federation-settlement-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { MerkleTreeVersion } from "./merkle-tree-hash.js";
1
2
  declare const __brand: unique symbol;
2
3
  type Brand<T, B extends string> = T & {
3
4
  readonly [__brand]?: B;
@@ -81,6 +82,14 @@ export interface AgentTrustRecord {
81
82
  successful_tasks?: number;
82
83
  failed_tasks?: number;
83
84
  notes?: string;
85
+ /**
86
+ * First-person local nickname for this peer — what *I* call them, in my own
87
+ * namespace. Local-only: never on the wire, never sent to a peer or the relay.
88
+ * Naming is first-person (the petname resolution to Zooko's triangle — see
89
+ * `docs/doctrine/agents-as-first-person-trust-graph.md` §3), distinct from the
90
+ * peer's squattable self-asserted listing name. Optional; absent ⇒ no petname.
91
+ */
92
+ petname?: string;
84
93
  /** Exponential moving average of result quality [0, 1]. */
85
94
  avg_quality?: number;
86
95
  /** Number of quality samples collected. */
@@ -849,6 +858,74 @@ export interface ToolInvocationReceipt {
849
858
  suite: "motebit-jcs-ed25519-b64-v1";
850
859
  signature: string;
851
860
  }
861
+ /**
862
+ * Signed human-consent decision over a tool call that governance gated for
863
+ * approval (the middle band: `require_approval_above < risk <= deny_above`).
864
+ *
865
+ * The third governance band made verifiable. The auto band proves itself with
866
+ * a `ToolInvocationReceipt`; the deny band proves itself with an agent-signed
867
+ * `ExecutionReceipt{status:"denied"}` (the delegation policy refusal path). The
868
+ * approve band was the only one whose decision was unsigned — a plaintext DB
869
+ * row + event. This artifact closes that asymmetry: when a human approves (or
870
+ * denies) a gated act, the verdict becomes a self-verifiable fact — "this
871
+ * approver consented to THIS tool call with THESE args at THIS time" — that any
872
+ * third party can check offline with the approver's public key, no relay
873
+ * contact required.
874
+ *
875
+ * Signed by the APPROVER's device key (the human consenting), mirroring how the
876
+ * worker signs its own refusal: consent is the approver's assertion, not the
877
+ * system's word for it. Prior art for signed approval votes: the key-rotation
878
+ * guardian quorum (`relay_approval_votes.signature`) — this lifts that shape
879
+ * from the narrow key-rotation case to the general agentic tool-consent path.
880
+ *
881
+ * Privacy: commits to `args_hash` (SHA-256 of the canonical args), never the
882
+ * raw args — same discipline as `ToolInvocationReceipt`. A verifier holding the
883
+ * raw args recomputes and matches; one holding only the decision still proves a
884
+ * verdict was rendered over *some* call at *some* time.
885
+ *
886
+ * Member of the JCS + Ed25519 + suite-dispatch signed-artifact family
887
+ * (`docs/doctrine/receipts-unified.md`). Verify with `verifyApprovalDecision`.
888
+ */
889
+ export interface ApprovalDecision {
890
+ /**
891
+ * Binds the decision to the specific gated call — the `tool_call_id` from the
892
+ * `approval_request`. Part of the signed body, so a verdict cannot be
893
+ * replayed onto a different call (the binding breaks the signature).
894
+ */
895
+ approval_id: string;
896
+ /** The motebit whose governance gated the call (the executor being approved). */
897
+ motebit_id: MotebitId;
898
+ /** Signer's (approver's) Ed25519 public key (hex). Enables offline verification without a key lookup. */
899
+ public_key?: string;
900
+ /** The approver's device that rendered the verdict and holds the signing key. */
901
+ device_id: DeviceId;
902
+ /** Tool the verdict authorizes (or refuses). */
903
+ tool_name: string;
904
+ /**
905
+ * SHA-256 hex of the canonical JSON of the tool's arguments — never the raw
906
+ * args. Binds consent to the exact call shape the approver saw.
907
+ */
908
+ args_hash: string;
909
+ /** The `RiskLevel` numeric that triggered the approval gate. */
910
+ risk_level: number;
911
+ /** The human's verdict. `denied` carries an optional `denied_reason`. */
912
+ verdict: "approved" | "denied";
913
+ /** Unix ms when the approval was requested (the gate fired). */
914
+ requested_at: number;
915
+ /** Unix ms when the human rendered the verdict. */
916
+ resolved_at: number;
917
+ /** Free-text reason, present only on `denied`. */
918
+ denied_reason?: string;
919
+ /** The turn/run the gated call belongs to, when known. */
920
+ run_id?: string;
921
+ /**
922
+ * Cryptosuite discriminator. Always `"motebit-jcs-ed25519-b64-v1"` today.
923
+ * Widening requires a `SuiteId` registry change + a new dispatch arm in
924
+ * `@motebit/crypto`, not a wire-format break.
925
+ */
926
+ suite: "motebit-jcs-ed25519-b64-v1";
927
+ signature: string;
928
+ }
852
929
  /**
853
930
  * Signed proof that the motebit performed a consolidation cycle. The
854
931
  * receipt commits to structural facts only — counts of memories merged,
@@ -962,6 +1039,16 @@ export interface ConsolidationAnchor {
962
1039
  * `"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"` for mainnet). Paired
963
1040
  * with `tx_hash` — absent when `tx_hash` is absent. */
964
1041
  network?: string;
1042
+ /**
1043
+ * Tree-hash recipe for the receipts' Merkle root (leaf-domain / node-domain
1044
+ * tags + hash). A `MerkleTreeVersion`. **Absent ⇒ `merkle-sha256-plain-v1`** —
1045
+ * every anchor produced before this axis existed still recomputes offline.
1046
+ * Verifiers resolve absent to the default and reject an unknown value
1047
+ * fail-closed (never silently downgrade); a v2 producer MUST emit it rather
1048
+ * than rely on the default. See
1049
+ * `docs/doctrine/merkle-tree-hash-versioning.md`.
1050
+ */
1051
+ tree_hash_version?: MerkleTreeVersion;
965
1052
  }
966
1053
  /**
967
1054
  * Provenance discriminator on `ExecutionReceipt.invocation_origin` and on
@@ -1381,6 +1468,18 @@ export declare const PLATFORM_FEE_RATE = 0.05;
1381
1468
  export interface SettlementRecord {
1382
1469
  settlement_id: SettlementId;
1383
1470
  allocation_id: AllocationId;
1471
+ /**
1472
+ * The payee — the `motebit_id` of the worker this settlement pays. A
1473
+ * settlement receipt names *who was paid* in its signed body, not only
1474
+ * the relay-internal `allocation_id` (which is an opaque bookkeeping
1475
+ * handle a sovereign verifier cannot resolve offline). This makes the
1476
+ * receipt self-contained: a worker proves "I (W) was paid X for receipt
1477
+ * H by relay R" from the signed bytes alone, with no relay-side
1478
+ * allocation→payee join. Carried in the signed body so the payee is part
1479
+ * of the relay's attestation and cannot be re-pointed after the fact.
1480
+ * Equals the executing agent's `ExecutionReceipt.motebit_id`.
1481
+ */
1482
+ motebit_id: MotebitId;
1384
1483
  receipt_hash: string;
1385
1484
  ledger_hash: string | null;
1386
1485
  /** Amount paid to the executing agent (after platform fee deduction). */
@@ -1684,6 +1783,74 @@ export interface SovereignRail extends SettlementRail {
1684
1783
  /** Current balance in micro-units (1e6 = 1 unit of asset). */
1685
1784
  getBalance(): Promise<bigint>;
1686
1785
  }
1786
+ /**
1787
+ * Outcome of a sovereign-rail value transfer. Chain-neutral shape — a tx
1788
+ * identifier, the slot/height it landed in (0 if not yet confirmed), and
1789
+ * whether the configured commitment level was reached.
1790
+ */
1791
+ export interface SovereignSendResult {
1792
+ /** Transaction identifier (base58 signature on Solana). */
1793
+ signature: string;
1794
+ /** Slot / block height the transaction landed in (0 if not yet confirmed). */
1795
+ slot: number;
1796
+ /** Whether the network reached the configured commitment level. */
1797
+ confirmed: boolean;
1798
+ }
1799
+ /**
1800
+ * The sovereign wallet rail as the interior CONSUMES it — the port the runtime
1801
+ * depends on, not the concrete rail. Extends `SovereignRail` (address +
1802
+ * getBalance) with the send + liveness operations the runtime invokes. A
1803
+ * concrete rail (`@motebit/wallet-solana`'s `SolanaWalletRail`) satisfies this
1804
+ * structurally; the runtime imports this port, never the provider. "The interior
1805
+ * defines the port; the provider implements it" — the adapter principle as a type.
1806
+ */
1807
+ /**
1808
+ * A request to build a sovereign P2P payment proof — the delegator's atomic
1809
+ * multi-leg onchain settlement that lets a PAID direct delegation satisfy the
1810
+ * relay's P2P-proof gate (`requiresP2pProof`, Arc 3.5). The interior assembles
1811
+ * this from discovery (the worker's `settlement_address`, the relay's treasury
1812
+ * address) plus fee math (`computeGrossAmount` in `@motebit/market`); the rail
1813
+ * broadcasts the legs in ONE transaction and returns the verifiable
1814
+ * `P2pPaymentProof`.
1815
+ *
1816
+ * Single-operator P2P uses the worker + relay-fee legs only. Cross-operator
1817
+ * federated P2P adds the executor-relay (B) fee leg — see `P2pPaymentProof`'s
1818
+ * `b_fee_*` fields.
1819
+ */
1820
+ export interface SovereignP2pPaymentRequest {
1821
+ /** Worker's declared settlement address (base58 for Solana). */
1822
+ workerAddress: string;
1823
+ /** Worker leg amount in micro-units — the listing unit_cost, what the worker earns net. */
1824
+ amountMicro: number;
1825
+ /** Relay treasury address (base58) — `deriveSolanaAddress(relayPublicKey)`. */
1826
+ treasuryAddress: string;
1827
+ /** Fee leg amount in micro-units — `computeGrossAmount(amountMicro) - amountMicro`. */
1828
+ feeAmountMicro: number;
1829
+ /** Executor-relay (B) treasury address (base58) — cross-operator federated P2P only. */
1830
+ executorTreasuryAddress?: string;
1831
+ /** Executor-relay (B) fee leg amount in micro-units — federated P2P only. */
1832
+ executorFeeAmountMicro?: number;
1833
+ /** CAIP-2 network identifier (defaults to the rail's chain mainnet). */
1834
+ network?: string;
1835
+ }
1836
+ export interface SovereignWalletRail extends SovereignRail {
1837
+ /** Send `microAmount` (micro-units) of the rail's asset to `toAddress`. */
1838
+ send(toAddress: string, microAmount: bigint): Promise<SovereignSendResult>;
1839
+ /** Whether the rail can currently reach its chain (RPC liveness). */
1840
+ isAvailable(): Promise<boolean>;
1841
+ /**
1842
+ * Build a P2P payment proof by broadcasting the delegator's atomic
1843
+ * multi-leg settlement (worker leg + relay-fee leg[s]) in a SINGLE
1844
+ * transaction and returning the verifiable `P2pPaymentProof`.
1845
+ *
1846
+ * OPTIONAL: a rail that cannot atomically pay multiple recipients omits
1847
+ * this, and the interior degrades honestly (paid direct delegation is
1848
+ * unavailable on that rail) — it MUST NOT split the legs across separate
1849
+ * transactions, because the relay verifier walks ONE `tx_hash`. The
1850
+ * reference `SolanaWalletRail` implements it via `buildP2pPaymentProof`.
1851
+ */
1852
+ buildP2pPayment?(request: SovereignP2pPaymentRequest): Promise<P2pPaymentProof>;
1853
+ }
1687
1854
  export interface CollaborativePlanProposal {
1688
1855
  proposal_id: ProposalId;
1689
1856
  plan_id: PlanId;
@@ -2136,9 +2303,10 @@ export { TrustSemiring, CostSemiring, LatencySemiring, BottleneckSemiring, Relia
2136
2303
  export type { Edge } from "./graph.js";
2137
2304
  export { WeightedDigraph } from "./graph.js";
2138
2305
  export { optimalPaths, optimalPath, transitiveClosure, optimalPathTrace } from "./traversal.js";
2139
- export { TRUST_LEVEL_SCORES, trustLevelToScore, TRUST_ZERO, TRUST_ONE, trustAdd, trustMultiply, composeTrustChain, joinParallelRoutes, REFERENCE_TRUST_THRESHOLDS, DEFAULT_TRUST_THRESHOLDS, } from "./trust-algebra.js";
2306
+ export { TRUST_LEVEL_SCORES, trustLevelToScore, TRUST_ZERO, TRUST_ONE, trustAdd, trustMultiply, composeTrustChain, joinParallelRoutes, REFERENCE_TRUST_THRESHOLDS, } from "./trust-algebra.js";
2140
2307
  export type { CredentialAnchorBatch, CredentialChainAnchor, CredentialAnchorProof, ChainAnchorSubmitter, } from "./credential-anchor.js";
2141
2308
  export type { AgentSettlementAnchorBatch, AgentSettlementChainAnchor, AgentSettlementAnchorProof, } from "./agent-settlement-anchor.js";
2309
+ export type { FederationSettlementRecord, FederationSettlementChainAnchor, FederationSettlementAnchorProof, } from "./federation-settlement-anchor.js";
2142
2310
  export type { RelayMetadata, RelayMetadataPeer, AgentResolutionResult } from "./discovery.js";
2143
2311
  export type { MigrationState, MigrationRequest, MigrationToken, DepartureAttestation, CredentialBundle, BalanceWaiver, MigrationPresentation, } from "./migration.js";
2144
2312
  export type { DisputeState, DisputeOutcome, DisputeCategory, DisputeFundAction, DisputeRequest, DisputeEvidence, DisputeEvidenceType, AdjudicatorVote, VoteRequest, DisputeResolution, DisputeAppeal, WitnessOmissionDispute, WitnessOmissionEvidence, WitnessOmissionInclusionProofEvidence, WitnessOmissionAlternativePeeringEvidence, } from "./dispute.js";
@@ -2146,8 +2314,11 @@ export type { SettlementMode, WritableSettlementMode, P2pPaymentProof, PaymentVe
2146
2314
  export { ALL_SETTLEMENT_MODES, isSettlementMode } from "./settlement-mode.js";
2147
2315
  export type { SettlementAsset } from "./settlement-asset.js";
2148
2316
  export { ALL_SETTLEMENT_ASSETS, isSettlementAsset } from "./settlement-asset.js";
2317
+ export { base58Encode } from "./base58.js";
2149
2318
  export type { SuiteId, SuiteEntry, SuiteStatus, SuiteAlgorithm, SuiteCanonicalization, SuiteSignatureEncoding, SuitePublicKeyEncoding, } from "./crypto-suite.js";
2150
2319
  export { SUITE_REGISTRY, ALL_SUITE_IDS, isSuiteId, getSuiteEntry } from "./crypto-suite.js";
2320
+ export type { MerkleTreeVersion, MerkleTreeVersionEntry, MerkleTreeVersionStatus, MerkleHashFunction, } from "./merkle-tree-hash.js";
2321
+ export { MERKLE_TREE_VERSION_REGISTRY, ALL_MERKLE_TREE_VERSIONS, DEFAULT_MERKLE_TREE_VERSION, isMerkleTreeVersion, getMerkleTreeVersionEntry, } from "./merkle-tree-hash.js";
2151
2322
  export { MAX_RETENTION_DAYS_BY_SENSITIVITY, REFERENCE_RETENTION_DAYS_BY_SENSITIVITY, RUNTIME_RETENTION_REGISTRY, EMPTY_FEDERATION_GRAPH_ANCHOR, } from "./retention-policy.js";
2152
2323
  export type { RetentionCeilingDays, RetentionShape, RetentionShapeDeclaration, RetentionStoreDeclaration, RetentionManifest, RuntimeStoreId, DeletionCertificate, DeletionReason, HorizonSubject, HorizonWitness, HorizonWitnessRequestBody, WitnessSolicitationRequest, WitnessSolicitationResponse, FederationGraphAnchor, MerkleAlgo, MerkleInclusionProof, SubjectSignature, OperatorSignature, DelegateSignature, GuardianSignature, SensitivityLevelString, } from "./retention-policy.js";
2153
2324
  export type { MemoryDecayedPayload, MemoryFormedPayload, MemoryAccessedPayload, MemoryPinnedPayload, MemoryDeletedPayload, MemoryConsolidatedPayload, MemoryAuditPayload, MemoryPromotedPayload, } from "./memory-events.js";
@@ -2164,17 +2335,21 @@ export { resolveDropTarget } from "./perception.js";
2164
2335
  export { rankSensitivity, maxSensitivity, sensitivityPermits, ALL_SENSITIVITY_LEVELS, isSensitivityLevel, } from "./sensitivity.js";
2165
2336
  export type { SensitivityCleared } from "./sensitivity.js";
2166
2337
  export { ALL_EVENT_TYPES, isEventType } from "./event-type.js";
2167
- export { MICRO, CENTS, toMicro, fromMicro, toCents, fromCents } from "./money.js";
2338
+ export { MICRO, CENTS, toMicro, fromMicro, toCents, fromCents, computeP2pFeeMicro, computeFederatedFeeSplit, } from "./money.js";
2339
+ export type { FederatedFeeSplit } from "./money.js";
2168
2340
  export type { InferenceHost, ModelLab, Jurisdiction, TaskShape, ProviderCapability, RoutingConstraint, RoutingDecision, } from "./routing.js";
2169
2341
  export { ALL_TASK_SHAPES, isTaskShape, QUICK_TASK_SHAPE, CHAT_TASK_SHAPE, REASONING_TASK_SHAPE, CODE_TASK_SHAPE, RESEARCH_TASK_SHAPE, CREATIVE_TASK_SHAPE, MATH_TASK_SHAPE, } from "./routing.js";
2170
2342
  export type { TokenAudience } from "./audience.js";
2171
2343
  export { ALL_TOKEN_AUDIENCES, isTokenAudience, SYNC_AUDIENCE, DEVICE_AUTH_AUDIENCE, PAIR_AUDIENCE, ROTATE_KEY_AUDIENCE, PUSH_REGISTER_AUDIENCE, TASK_SUBMIT_AUDIENCE, ADMIN_QUERY_AUDIENCE, PROPOSAL_AUDIENCE, ACCOUNT_BALANCE_AUDIENCE, ACCOUNT_DEPOSIT_AUDIENCE, ACCOUNT_WITHDRAW_AUDIENCE, ACCOUNT_WITHDRAWALS_AUDIENCE, ACCOUNT_CHECKOUT_AUDIENCE, BROWSER_SANDBOX_GRANT_AUDIENCE, BROWSER_SANDBOX_AUDIENCE, } from "./audience.js";
2172
2344
  export type { ContentArtifactType } from "./artifact-type.js";
2173
- export { ALL_CONTENT_ARTIFACT_TYPES, isContentArtifactType, STATE_SNAPSHOT_ARTIFACT, MEMORY_EXPORT_ARTIFACT, GOAL_LIST_ARTIFACT, CONVERSATION_LIST_ARTIFACT, CONVERSATION_MESSAGES_ARTIFACT, DEVICE_LIST_ARTIFACT, AUDIT_TRAIL_ARTIFACT, PLAN_LIST_ARTIFACT, PLAN_DETAIL_ARTIFACT, GRADIENT_HISTORY_ARTIFACT, SYNC_PULL_ARTIFACT, EXECUTION_LEDGER_ARTIFACT, GOAL_RESULT_ARTIFACT, } from "./artifact-type.js";
2345
+ export { ALL_CONTENT_ARTIFACT_TYPES, isContentArtifactType, STATE_SNAPSHOT_ARTIFACT, MEMORY_EXPORT_ARTIFACT, GOAL_LIST_ARTIFACT, CONVERSATION_LIST_ARTIFACT, CONVERSATION_MESSAGES_ARTIFACT, DEVICE_LIST_ARTIFACT, AUDIT_TRAIL_ARTIFACT, PLAN_LIST_ARTIFACT, PLAN_DETAIL_ARTIFACT, GRADIENT_HISTORY_ARTIFACT, SYNC_PULL_ARTIFACT, EXECUTION_LEDGER_ARTIFACT, GOAL_RESULT_ARTIFACT, SETTLEMENT_SUMMARY_ARTIFACT, } from "./artifact-type.js";
2346
+ export type { SettlementSummaryExport, SettlementSummaryPeer, SettlementSummaryUnattributed, } from "./settlement-summary.js";
2174
2347
  export type { SignedTransparencyDeclaration, TransparencySignedPayload, TransparencyAnchorRecord, } from "./transparency.js";
2175
2348
  export { TRANSPARENCY_SUITE, TRANSPARENCY_ANCHOR_MEMO_PREFIX, TRANSPARENCY_SPEC_ID, isSignedTransparencyDeclaration, } from "./transparency.js";
2349
+ export type { AgentRevocationReason, AgentRevocationActor, AgentRevocationRecord, AgentRevocationSignedPayload, AgentRevocationFeed, } from "./agent-revocation.js";
2350
+ export { ALL_AGENT_REVOCATION_REASONS, isAgentRevocationReason, AGENT_REVOCATION_SUITE, AGENT_REVOCATION_SPEC_ID, } from "./agent-revocation.js";
2176
2351
  import type { ToolMode } from "./tool-mode.js";
2177
- import type { SettlementMode } from "./settlement-mode.js";
2352
+ import type { SettlementMode, P2pPaymentProof } from "./settlement-mode.js";
2178
2353
  import type { SettlementAsset } from "./settlement-asset.js";
2179
2354
  export type { SkillSensitivity, SkillPlatform, SkillHardwareAttestationGate, SkillSignature, SkillManifestMetadata, SkillManifestMotebit, SkillManifest, SkillEnvelopeFile, SkillEnvelopeSkillRef, SkillEnvelope, SkillLoadPayload, } from "./skills.js";
2180
2355
  export { SKILL_SENSITIVITY_TIERS, SKILL_AUTO_LOADABLE_TIERS, SKILL_PLATFORMS } from "./skills.js";