@shroud-fi/agent-runtime 0.1.5 → 0.1.6

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/src/types.ts ADDED
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Public types for @shroud-fi/agent-runtime.
3
+ *
4
+ * The runtime composes @shroud-fi/core + @shroud-fi/payments + @shroud-fi/scanning
5
+ * + @shroud-fi/transport behind a single ShroudAgent class. Types stay narrow:
6
+ * no leaky internal shapes from scanner detector or payment receipt parsing.
7
+ */
8
+
9
+ import type { Address, Hex } from 'viem';
10
+ import type { ShroudFiTransport } from '@shroud-fi/transport';
11
+ import type { DetectedPayment, FinalityLevel } from '@shroud-fi/scanning';
12
+ import type { SweepReceipt } from '@shroud-fi/payments';
13
+
14
+ /**
15
+ * Configuration for createShroudAgent (Path 1 — server / AI agent).
16
+ *
17
+ * `masterSeed` is the deterministic 32-byte root. If omitted, the underlying
18
+ * createAgentIdentity generates a random seed — useful for ephemeral testing
19
+ * but not for production agents (they cannot recover funds after restart).
20
+ */
21
+ export interface ShroudAgentConfig {
22
+ readonly masterSeed?: Uint8Array;
23
+ readonly transport: ShroudFiTransport;
24
+ /** Defaults to getShroudFiStealth(chainId) from @shroud-fi/transport. */
25
+ readonly stealthContract?: Address;
26
+ /**
27
+ * ERC-5564 announcer contract address. Defaults to the canonical singleton
28
+ * exported from @shroud-fi/transport. Override only for local Anvil testing
29
+ * where the canonical address is absent — production paths should never
30
+ * touch this.
31
+ */
32
+ readonly announcer?: Address;
33
+ readonly startBlock: bigint;
34
+ readonly finality?: FinalityLevel;
35
+ /**
36
+ * M3 — when `true`, `agent.sendToWallet` calls `ensureRegistered()` before
37
+ * dispatching the payment. The agent will publish its stealth meta-address
38
+ * into the canonical ERC-6538 registry the first time `sendToWallet` runs,
39
+ * making the agent itself reachable as a recipient by anyone who knows the
40
+ * registrant wallet address.
41
+ *
42
+ * Default `false` — preserves the existing send/sendERC20/sweep behavior
43
+ * for agents that never want to be a *recipient* of stealth payments.
44
+ *
45
+ * Auto-registration requires `transport.walletClient` with an account; if
46
+ * the walletClient is missing the registration step throws
47
+ * `RegistrationRequiresWalletError` wrapped in `AutoRegistrationFailedError`.
48
+ */
49
+ readonly autoRegister?: boolean;
50
+ }
51
+
52
+ /**
53
+ * Start-time options.
54
+ *
55
+ * `backfillFrom` opt-in switches start() to hybrid mode: first iterates
56
+ * scanRange(backfillFrom, latestSafe), then transitions to live watch().
57
+ * Useful for recovering payments missed while the agent was offline.
58
+ */
59
+ export interface ShroudAgentStartOptions {
60
+ readonly backfillFrom?: bigint;
61
+ readonly signal?: AbortSignal;
62
+ }
63
+
64
+ /**
65
+ * EIP-1193-compatible browser wallet adapter.
66
+ *
67
+ * Intentionally narrow: only the surface the browser factory actually uses.
68
+ * Callers wrap window.ethereum into this in the demo app. The runtime never
69
+ * touches window.ethereum directly to keep this package Node-safe.
70
+ */
71
+ export interface BrowserWalletAdapter {
72
+ readonly address: Address;
73
+ signMessage(message: string): Promise<Hex>;
74
+ }
75
+
76
+ /**
77
+ * Result returned by agent.sweep(). Wraps the underlying SweepReceipt with
78
+ * the originating detection so callers can correlate sweeps to detections
79
+ * without keeping a separate map.
80
+ */
81
+ export interface AgentSweepResult {
82
+ readonly swept: SweepReceipt;
83
+ readonly detection: DetectedPayment;
84
+ }
85
+
86
+ /**
87
+ * Subset of @shroud-fi/relayer's `RelayerSweepOptions` that the agent-runtime
88
+ * forwards verbatim. Re-typed locally so the agent-runtime type surface stays
89
+ * decoupled from the relayer package — callers that never touch the relayer
90
+ * still get a clean type tree without the optional peer dep being resolved.
91
+ */
92
+ export interface AgentRelayerSweepOptions {
93
+ readonly deadlineSecs?: bigint;
94
+ readonly pollIntervalMs?: number;
95
+ readonly pollTimeoutMs?: number;
96
+ readonly gelatoApiKey?: string;
97
+ readonly signal?: AbortSignal;
98
+ /**
99
+ * If set, the agent dispatches the sweep to a self-hosted relayer service
100
+ * via HTTP POST instead of Gelato. The endpoint must implement the
101
+ * `/relay` contract from `@shroud-fi/self-host-relayer`.
102
+ *
103
+ * Self-host bypasses Gelato entirely — useful for anon-stack deployments
104
+ * or when Gelato Gas Tank is paywalled.
105
+ */
106
+ readonly selfHostEndpoint?: string;
107
+ }
108
+
109
+ /**
110
+ * Result returned by agent.sweepViaRelayer(). Mirrors AgentSweepResult shape
111
+ * but wraps the relayer's `RelayerSweepReceipt` instead of `SweepReceipt`.
112
+ *
113
+ * The relayer receipt has NO amount fields (privacy invariant); the demo and
114
+ * other consumers can re-query balance if a display number is required.
115
+ */
116
+ export interface AgentRelayerSweepResult {
117
+ readonly swept: {
118
+ readonly taskId: string;
119
+ readonly txHash: Hex;
120
+ readonly status: 'submitted' | 'pending' | 'success' | 'failed' | 'cancelled';
121
+ readonly relayerContract: Address;
122
+ readonly token: Address;
123
+ readonly destination: Address;
124
+ readonly blockNumber?: bigint;
125
+ };
126
+ readonly detection: DetectedPayment;
127
+ }
128
+
129
+ /**
130
+ * P5.1 — options forwarded to relayedSweepETH. Locally typed so the
131
+ * agent-runtime type tree stays decoupled from @shroud-fi/relayer.
132
+ */
133
+ export interface AgentRelayerEthSweepOptions {
134
+ readonly deadlineSecs?: bigint;
135
+ readonly pollTimeoutMs?: number;
136
+ readonly signal?: AbortSignal;
137
+ /**
138
+ * Self-host relayer service URL. Required — there's no third-party fallback
139
+ * for the EIP-7702 path. Endpoint must implement POST /relay-eth per
140
+ * @shroud-fi/self-host-relayer.
141
+ */
142
+ readonly selfHostEndpoint: string;
143
+ }
144
+
145
+ /**
146
+ * P5.1 — result of agent.sweepEthViaRelayer(). Mirrors AgentSweepResult shape
147
+ * with the relayer's ETH receipt. No amount fields.
148
+ */
149
+ export interface AgentRelayerEthSweepResult {
150
+ readonly swept: {
151
+ readonly txHash: Hex;
152
+ readonly status: 'success';
153
+ readonly blockNumber: bigint;
154
+ readonly ethRelayerContract: Address;
155
+ readonly destination: Address;
156
+ readonly stealthAddress: Address;
157
+ };
158
+ readonly detection: DetectedPayment;
159
+ }
160
+
161
+ /**
162
+ * v0.1.1 — address-book contact kind. 'wallet' = 20-byte EVM address (used
163
+ * with sendToWallet); 'meta' = `st:base:0x…` stealth meta-address (used with
164
+ * send).
165
+ */
166
+ export type ContactKind = 'wallet' | 'meta';
167
+
168
+ /**
169
+ * v0.1.1 — a single address-book entry. Fully local, never on-chain.
170
+ */
171
+ export interface Contact {
172
+ readonly label: string;
173
+ readonly kind: ContactKind;
174
+ readonly value: string;
175
+ readonly addedAt: string;
176
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "test", "examples", "node_modules"]
9
+ }