@telaro/middleware 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # `@telaro/middleware`
2
+
3
+ > Generic Telaro trust-gate wrapper. Wraps any TypeScript SDK to enforce
4
+ > on-chain bond + score policy before tx-emitting methods.
5
+
6
+ Use this when:
7
+ - You're integrating Telaro into a DApp/SDK that has **no hook system**
8
+ (unlike idolly-acp, where you'd use [`@telaro/idolly-acp-hook`](../idolly-acp-hook)).
9
+ - You want a **one-line wrap** without forking the SDK.
10
+ - You're a **bot operator** wanting to refuse delegations to under-bonded
11
+ agents your code might receive from external sources.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @telaro/middleware @telaro/sdk
17
+ ```
18
+
19
+ ## Pattern
20
+
21
+ ```ts
22
+ import { TelaroGate, TelaroPolicyError } from "@telaro/middleware";
23
+ import { SomeClient } from "some-sdk";
24
+
25
+ const sdk = new SomeClient({...});
26
+
27
+ const gated = TelaroGate.wrap(sdk, {
28
+ // Which methods to gate
29
+ methods: ["placeOrder", "deposit"],
30
+ // Where to find the agent pubkey in the call args
31
+ resolveAgent: (args) => args[0]?.agentPubkey,
32
+ // Policy enforced before each call
33
+ policy: { minBond: 10_000_000n, minScore: 700 },
34
+ // Optional telemetry
35
+ onDecision: (e) => metrics.record(e),
36
+ });
37
+
38
+ try {
39
+ await gated.placeOrder({ agentPubkey: "Abc...", marketIndex: 0, ... });
40
+ } catch (err) {
41
+ if (err instanceof TelaroPolicyError) {
42
+ // err.code is one of: NOT_BONDED, BOND_BELOW_MIN, SCORE_BELOW_MIN, FROZEN, LOOKUP_FAILED
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## Real examples
48
+
49
+ ### Drift perpetuals
50
+
51
+ ```ts
52
+ import { DriftClient } from "@drift-labs/sdk";
53
+ import { TelaroGate } from "@telaro/middleware";
54
+
55
+ const drift = new DriftClient({...});
56
+
57
+ const gated = TelaroGate.wrap(drift, {
58
+ methods: ["placePerpOrder", "placeSpotOrder", "deposit"],
59
+ resolveAgent: (args) => args[0]?.subAccountId?.toString(),
60
+ policy: { minBond: 50_000_000n, minScore: 800 }, // perp = high VAR
61
+ });
62
+
63
+ await gated.placePerpOrder({...});
64
+ ```
65
+
66
+ ### MarginFi lending
67
+
68
+ ```ts
69
+ import { MarginfiClient, MarginfiAccountWrapper } from "@mrgnlabs/marginfi-client-v2";
70
+ import { TelaroGate } from "@telaro/middleware";
71
+
72
+ const account = await client.fetchOrCreateMarginfiAccount();
73
+
74
+ const gated = TelaroGate.wrap(account, {
75
+ methods: ["deposit", "borrow", "repay", "withdraw"],
76
+ resolveAgent: () => MY_AGENT_PUBKEY,
77
+ policy: { minBond: 10_000_000n, minScore: 700 },
78
+ });
79
+ ```
80
+
81
+ ### Custom REST API client
82
+
83
+ ```ts
84
+ class MyDexClient {
85
+ async swap(args: { agent: string; from: string; to: string; amount: bigint }) {...}
86
+ }
87
+
88
+ const gated = TelaroGate.wrap(new MyDexClient(), {
89
+ methods: ["swap"],
90
+ resolveAgent: (args) => (args[0] as { agent: string }).agent,
91
+ policy: { minBond: 1_000_000n, minScore: 500 },
92
+ });
93
+ ```
94
+
95
+ ## API
96
+
97
+ ### `TelaroGate.wrap(sdk, config)`
98
+
99
+ Wraps `sdk` in place. Returns the same reference. Idempotent.
100
+
101
+ | Field | Type | Default | Notes |
102
+ |---|---|---|---|
103
+ | `methods` | `string[]` | required | Method names to gate |
104
+ | `resolveAgent` | `(args) => string \| undefined` | required | Returns agent pubkey from args; `undefined` skips the gate |
105
+ | `policy.minBond` | `bigint` (atomic USDC, 6dp) | required | E.g., `10_000_000n` = 10 USDC |
106
+ | `policy.minScore` | `number` (0..1000) | required | E.g., `700` |
107
+ | `policy.allowOnLookupFailure` | `boolean` | `false` | If `true`, network errors don't block |
108
+ | `apiBase` | `string` | `https://telaro.xyz` | Telaro REST API |
109
+ | `apiKey` | `string` | none | For higher rate-limit tiers |
110
+ | `cacheTtlMs` | `number` | `30_000` | Trust profile cache TTL. Set 0 to disable |
111
+ | `onDecision` | `(event) => void` | none | Telemetry hook |
112
+
113
+ ### `TelaroPolicyError`
114
+
115
+ Thrown by gated methods when policy fails. Has `.code`, `.agentPubkey`, `.method`.
116
+
117
+ ```ts
118
+ catch (err) {
119
+ if (err instanceof TelaroPolicyError) {
120
+ switch (err.code) {
121
+ case "NOT_BONDED": /* agent never bonded */ break;
122
+ case "BOND_BELOW_MIN": /* bond too low */ break;
123
+ case "SCORE_BELOW_MIN": /* score too low */ break;
124
+ case "FROZEN": /* agent frozen (open dispute or bond fell below floor) */ break;
125
+ case "LOOKUP_FAILED": /* network or API error */ break;
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## Performance
132
+
133
+ - **Cached**: 30s TTL by default. Repeated calls to the same agent
134
+ in the same window cost 1 RPC.
135
+ - **Async**: gate adds ~50-200ms on the first call to a new agent
136
+ (REST fetch from Telaro API), <1ms on cached calls.
137
+ - **No on-chain RPC**: this is a REST-based gate, not a CPI gate. For
138
+ atomic gating in the same tx, see the Anchor `view_bond` CPI in the
139
+ `telaro` Rust crate.
140
+
141
+ ## When to use what
142
+
143
+ | Need | Use |
144
+ |---|---|
145
+ | Quick TS wrap, no hooks in target SDK | **`@telaro/middleware`** (this) |
146
+ | Hook-based SDK (idolly-acp etc.) | `@telaro/idolly-acp-hook` |
147
+ | Atomic on-chain CPI gate | `telaro` Rust crate (`view_bond`) |
148
+ | Drop-in DApp UI modal | `@telaro/react-presign` |
149
+ | Building from a framework (Sendai, LangChain, etc.) | `@telaro/{sendai,langchain,...}` |
150
+
151
+ ## License
152
+
153
+ MIT
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @telaro/middleware — generic trust-gate wrapper for any TypeScript SDK.
3
+ *
4
+ * Pattern: pick which methods on a third-party SDK should be gated by
5
+ * Telaro bond + score policy. The wrapper proxies those methods so the
6
+ * call throws *before* the underlying tx is built, if the agent doesn't
7
+ * meet the policy.
8
+ *
9
+ * Use this when:
10
+ * - You're integrating Telaro into a DApp/SDK that has no hook system
11
+ * (unlike idolly-acp, which we use @telaro/idolly-acp-hook for).
12
+ * - You want a one-line wrap without forking the SDK.
13
+ *
14
+ * Usage:
15
+ *
16
+ * import { TelaroGate } from "@telaro/middleware";
17
+ * import { DriftClient } from "@drift-labs/sdk";
18
+ *
19
+ * const drift = new DriftClient({...});
20
+ *
21
+ * const gated = TelaroGate.wrap(drift, {
22
+ * methods: ["placePerpOrder", "deposit"],
23
+ * resolveAgent: (args) => args[0]?.agentPubkey,
24
+ * policy: { minBond: 10_000_000n, minScore: 700 },
25
+ * });
26
+ *
27
+ * await gated.placePerpOrder({ agentPubkey, marketIndex: 0, ... });
28
+ * // → Throws TelaroPolicyError if agent below threshold,
29
+ * // else passes through to drift.placePerpOrder().
30
+ */
31
+ import { TelaroApi } from "@telaro/sdk";
32
+ export declare class TelaroPolicyError extends Error {
33
+ readonly code: TelaroPolicyCode;
34
+ readonly agentPubkey: string;
35
+ readonly method: string;
36
+ constructor(opts: {
37
+ code: TelaroPolicyCode;
38
+ agentPubkey: string;
39
+ method: string;
40
+ message: string;
41
+ });
42
+ }
43
+ export type TelaroPolicyCode = "NOT_BONDED" | "BOND_BELOW_MIN" | "SCORE_BELOW_MIN" | "FROZEN" | "LOOKUP_FAILED";
44
+ export interface TelaroPolicy {
45
+ /** Minimum USDC bond required (atomic, 6dp). */
46
+ minBond: bigint;
47
+ /** Minimum score required (0..1000). */
48
+ minScore: number;
49
+ /** If true, allow the call when Telaro lookup fails (network, etc.).
50
+ * Default: false (fail closed). */
51
+ allowOnLookupFailure?: boolean;
52
+ }
53
+ export interface GateConfig<T> {
54
+ /** Method names on the wrapped SDK to gate. */
55
+ methods: Array<keyof T>;
56
+ /** Policy enforced before each gated call. */
57
+ policy: TelaroPolicy;
58
+ /** Function that extracts the agent pubkey from the call args. */
59
+ resolveAgent: (args: unknown[]) => string | undefined;
60
+ /** Telaro REST API base. Default https://telaro.xyz. */
61
+ apiBase?: string;
62
+ /** API key for higher rate-limit tiers. */
63
+ apiKey?: string;
64
+ /** Optional pre-fetched API client (use this to share across many
65
+ * wrappers for fewer connections). */
66
+ api?: TelaroApi;
67
+ /** Optional cache TTL for trust profile lookups, in ms. Default 30s.
68
+ * Set 0 to disable caching. Set 60_000 for a typical bot. */
69
+ cacheTtlMs?: number;
70
+ /** Hook fired after every gate decision. Useful for telemetry. */
71
+ onDecision?: (event: GateDecisionEvent) => void;
72
+ }
73
+ export interface GateDecisionEvent {
74
+ agentPubkey: string;
75
+ method: string;
76
+ decision: "pass" | "abort";
77
+ code?: TelaroPolicyCode;
78
+ trust?: {
79
+ score: number;
80
+ bondAtomic: bigint;
81
+ frozen: boolean;
82
+ successRate: number;
83
+ };
84
+ durationMs: number;
85
+ }
86
+ /**
87
+ * Wraps an SDK instance such that calls to `config.methods` are gated
88
+ * by Telaro policy. Returns the same instance reference (mutated in
89
+ * place via Proxy-shadowing on the methods).
90
+ *
91
+ * Idempotent: re-wrapping is a no-op.
92
+ */
93
+ export declare class TelaroGate {
94
+ static wrap<T extends object>(sdk: T, config: GateConfig<T>): T;
95
+ }
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAC;AAE7D,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBACZ,IAAI,EAAE;QAChB,IAAI,EAAE,gBAAgB,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,O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;IACrB,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC;CA6DhE"}
package/dist/index.js ADDED
@@ -0,0 +1,159 @@
1
+ /**
2
+ * @telaro/middleware — generic trust-gate wrapper for any TypeScript SDK.
3
+ *
4
+ * Pattern: pick which methods on a third-party SDK should be gated by
5
+ * Telaro bond + score policy. The wrapper proxies those methods so the
6
+ * call throws *before* the underlying tx is built, if the agent doesn't
7
+ * meet the policy.
8
+ *
9
+ * Use this when:
10
+ * - You're integrating Telaro into a DApp/SDK that has no hook system
11
+ * (unlike idolly-acp, which we use @telaro/idolly-acp-hook for).
12
+ * - You want a one-line wrap without forking the SDK.
13
+ *
14
+ * Usage:
15
+ *
16
+ * import { TelaroGate } from "@telaro/middleware";
17
+ * import { DriftClient } from "@drift-labs/sdk";
18
+ *
19
+ * const drift = new DriftClient({...});
20
+ *
21
+ * const gated = TelaroGate.wrap(drift, {
22
+ * methods: ["placePerpOrder", "deposit"],
23
+ * resolveAgent: (args) => args[0]?.agentPubkey,
24
+ * policy: { minBond: 10_000_000n, minScore: 700 },
25
+ * });
26
+ *
27
+ * await gated.placePerpOrder({ agentPubkey, marketIndex: 0, ... });
28
+ * // → Throws TelaroPolicyError if agent below threshold,
29
+ * // else passes through to drift.placePerpOrder().
30
+ */
31
+ import { TelaroApi } from "@telaro/sdk";
32
+ export class TelaroPolicyError extends Error {
33
+ code;
34
+ agentPubkey;
35
+ method;
36
+ constructor(opts) {
37
+ super(opts.message);
38
+ this.name = "TelaroPolicyError";
39
+ this.code = opts.code;
40
+ this.agentPubkey = opts.agentPubkey;
41
+ this.method = opts.method;
42
+ }
43
+ }
44
+ /**
45
+ * Wraps an SDK instance such that calls to `config.methods` are gated
46
+ * by Telaro policy. Returns the same instance reference (mutated in
47
+ * place via Proxy-shadowing on the methods).
48
+ *
49
+ * Idempotent: re-wrapping is a no-op.
50
+ */
51
+ export class TelaroGate {
52
+ static wrap(sdk, config) {
53
+ if (sdk[WRAPPED])
54
+ return sdk;
55
+ const api = config.api ?? new TelaroApi(config.apiBase ?? "https://telaro.xyz", { apiKey: config.apiKey });
56
+ const cache = new TrustCache(config.cacheTtlMs ?? 30_000);
57
+ for (const key of config.methods) {
58
+ const method = sdk[key];
59
+ if (typeof method !== "function")
60
+ continue;
61
+ const original = method;
62
+ sdk[key] = async (...args) => {
63
+ const t0 = Date.now();
64
+ const agentPubkey = config.resolveAgent(args);
65
+ if (!agentPubkey) {
66
+ // Resolver couldn't find an agent in the args. Pass through;
67
+ // assumption: not every call needs gating.
68
+ return original.apply(sdk, args);
69
+ }
70
+ let trust;
71
+ try {
72
+ trust = await cache.get(agentPubkey, () => api.agent(agentPubkey));
73
+ }
74
+ catch (err) {
75
+ if (config.policy.allowOnLookupFailure) {
76
+ config.onDecision?.({
77
+ agentPubkey, method: String(key), decision: "pass",
78
+ durationMs: Date.now() - t0,
79
+ });
80
+ return original.apply(sdk, args);
81
+ }
82
+ throw new TelaroPolicyError({
83
+ code: "LOOKUP_FAILED", agentPubkey, method: String(key),
84
+ message: `[telaro] failed to verify trust: ${err instanceof Error ? err.message : err}`,
85
+ });
86
+ }
87
+ const decision = evaluate(trust, config.policy);
88
+ if (decision.code) {
89
+ config.onDecision?.({
90
+ agentPubkey, method: String(key), decision: "abort",
91
+ code: decision.code, trust: decision.trust,
92
+ durationMs: Date.now() - t0,
93
+ });
94
+ throw new TelaroPolicyError({
95
+ code: decision.code, agentPubkey, method: String(key),
96
+ message: decision.message,
97
+ });
98
+ }
99
+ config.onDecision?.({
100
+ agentPubkey, method: String(key), decision: "pass",
101
+ trust: decision.trust, durationMs: Date.now() - t0,
102
+ });
103
+ return original.apply(sdk, args);
104
+ };
105
+ }
106
+ sdk[WRAPPED] = true;
107
+ return sdk;
108
+ }
109
+ }
110
+ const WRAPPED = Symbol.for("@telaro/middleware/wrapped");
111
+ function evaluate(detail, policy) {
112
+ if (!detail) {
113
+ return { code: "NOT_BONDED", message: `[telaro] agent has no on-chain bond` };
114
+ }
115
+ const a = detail.agent;
116
+ const trust = {
117
+ score: a.score,
118
+ bondAtomic: BigInt(a.bond_atomic),
119
+ frozen: a.frozen,
120
+ successRate: a.success_rate,
121
+ };
122
+ if (a.frozen) {
123
+ return { code: "FROZEN", message: `[telaro] agent is frozen`, trust };
124
+ }
125
+ if (trust.bondAtomic < policy.minBond) {
126
+ return {
127
+ code: "BOND_BELOW_MIN",
128
+ message: `[telaro] bond ${trust.bondAtomic} below required ${policy.minBond}`,
129
+ trust,
130
+ };
131
+ }
132
+ if (a.score < policy.minScore) {
133
+ return {
134
+ code: "SCORE_BELOW_MIN",
135
+ message: `[telaro] score ${a.score} below required ${policy.minScore}`,
136
+ trust,
137
+ };
138
+ }
139
+ return { message: "pass", trust };
140
+ }
141
+ class TrustCache {
142
+ ttlMs;
143
+ store = new Map();
144
+ constructor(ttlMs) {
145
+ this.ttlMs = ttlMs;
146
+ }
147
+ async get(key, loader) {
148
+ if (this.ttlMs <= 0)
149
+ return loader();
150
+ const entry = this.store.get(key);
151
+ const now = Date.now();
152
+ if (entry && entry.expires > now)
153
+ return entry.value;
154
+ const value = await loader();
155
+ this.store.set(key, { value, expires: now + this.ttlMs });
156
+ return value;
157
+ }
158
+ }
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAC;AAE7D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAmB;IACvB,WAAW,CAAS;IACpB,MAAM,CAAS;IACxB,YAAY,IAKX;QACC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC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B,KAAK,CAAC,UAAU,mBAAmB,MAAM,CAAC,OAAO,EAAE;YAC7E,KAAK;SACN,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC9B,OAAO;YACL,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,kBAAkB,CAAC,CAAC,KAAK,mBAAmB,MAAM,CAAC,QAAQ,EAAE;YACtE,KAAK;SACN,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,UAAU;IAEM;IADZ,KAAK,GAAG,IAAI,GAAG,EAA6D,CAAC;IACrF,YAAoB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAErC,KAAK,CAAC,GAAG,CACP,GAAW,EACX,MAA4C;QAE5C,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;YAAE,OAAO,MAAM,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,GAAG,GAAG;YAAE,OAAO,KAAK,CAAC,KAAK,CAAC;QACrD,MAAM,KAAK,GAAG,MAAM,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@telaro/middleware",
3
+ "version": "0.1.0",
4
+ "description": "Generic Telaro trust-gate middleware. Wraps any TypeScript SDK to enforce on-chain bond + score policy before tx-emitting methods.",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "clean": "rm -rf dist",
22
+ "test": "node --import tsx/esm --test tests/*.test.ts",
23
+ "prepublishOnly": "pnpm clean && pnpm build"
24
+ },
25
+ "dependencies": {
26
+ "@telaro/sdk": "workspace:*",
27
+ "@solana/web3.js": "^1.95.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.0.0",
31
+ "tsx": "^4.16.0",
32
+ "typescript": "^5.5.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/Telaro-Protocol/Telaro-Protocol.git",
41
+ "directory": "packages/middleware"
42
+ },
43
+ "homepage": "https://telaro.xyz",
44
+ "bugs": {
45
+ "url": "https://github.com/Telaro-Protocol/Telaro-Protocol/issues"
46
+ },
47
+ "engines": {
48
+ "node": ">=20"
49
+ },
50
+ "keywords": [
51
+ "solana",
52
+ "telaro",
53
+ "middleware",
54
+ "trust-gate",
55
+ "ai-agents",
56
+ "reputation"
57
+ ]
58
+ }