@bondedhq/shared 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +17 -2
- package/dist/abis.d.ts +8639 -0
- package/dist/abis.js +11234 -0
- package/dist/actuarial.d.ts +158 -0
- package/dist/actuarial.js +210 -0
- package/dist/agent-url.d.ts +172 -0
- package/dist/agent-url.js +248 -0
- package/dist/agent.d.ts +184 -0
- package/dist/agent.js +133 -0
- package/dist/allowances.d.ts +54 -0
- package/dist/allowances.js +68 -0
- package/dist/bounty-example.d.ts +6 -0
- package/dist/bounty-example.js +23 -0
- package/dist/bounty-spec.d.ts +36 -0
- package/dist/bounty-spec.js +111 -0
- package/dist/canonical.d.ts +8 -0
- package/dist/canonical.js +44 -0
- package/dist/chains.d.ts +58 -0
- package/dist/chains.js +123 -0
- package/dist/deployments.d.ts +32 -0
- package/dist/deployments.js +41 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +33 -0
- package/dist/leaderboard.d.ts +105 -0
- package/dist/leaderboard.js +85 -0
- package/dist/llm.d.ts +121 -0
- package/dist/llm.js +105 -0
- package/dist/mandate-rules.d.ts +54 -0
- package/dist/mandate-rules.js +69 -0
- package/dist/module-install.d.ts +145 -0
- package/dist/module-install.js +133 -0
- package/dist/notifications.d.ts +48 -0
- package/dist/notifications.js +45 -0
- package/dist/observed-rates.d.ts +125 -0
- package/dist/observed-rates.js +158 -0
- package/dist/problems.d.ts +44 -0
- package/dist/problems.js +148 -0
- package/dist/quote.d.ts +123 -0
- package/dist/quote.js +167 -0
- package/dist/report-fixes.d.ts +89 -0
- package/dist/report-fixes.js +159 -0
- package/dist/runner.d.ts +376 -0
- package/dist/runner.js +353 -0
- package/dist/schemas/attack.d.ts +121 -0
- package/dist/schemas/attack.js +142 -0
- package/dist/schemas/attestation.d.ts +284 -0
- package/dist/schemas/attestation.js +175 -0
- package/dist/schemas/common.d.ts +22 -0
- package/dist/schemas/common.js +53 -0
- package/dist/schemas/mandate-commitment.d.ts +13 -0
- package/dist/schemas/mandate-commitment.js +37 -0
- package/dist/schemas/mandate.d.ts +170 -0
- package/dist/schemas/mandate.js +113 -0
- package/dist/self-serve.d.ts +133 -0
- package/dist/self-serve.js +110 -0
- package/dist/sentinel-cascade.d.ts +64 -0
- package/dist/sentinel-cascade.js +64 -0
- package/dist/sentinel.d.ts +133 -0
- package/dist/sentinel.js +101 -0
- package/dist/suggested-mandate.d.ts +81 -0
- package/dist/suggested-mandate.js +112 -0
- package/dist/tee.d.ts +61 -0
- package/dist/tee.js +93 -0
- package/dist/tiers.d.ts +19 -0
- package/dist/tiers.js +23 -0
- package/dist/troubleshooting-doc.d.ts +11 -0
- package/dist/troubleshooting-doc.js +46 -0
- package/package.json +59 -3
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { type TypedDataDomain } from "viem";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* Signed messages from the Arena's attester. See docs/SPECIFICATION.md Section 6.4.
|
|
5
|
+
* Attestations are posted to every chain's BondedRegistry; quotes are accepted by CoverManager.
|
|
6
|
+
* The EIP-712 type strings below must match the Solidity typehashes in `BondedTypes.sol`.
|
|
7
|
+
*/
|
|
8
|
+
/** Model family of the agent's brain, used for correlation caps. Codes are uint8 on-chain. */
|
|
9
|
+
export declare const ModelFamily: z.ZodEnum<{
|
|
10
|
+
unknown: "unknown";
|
|
11
|
+
"anthropic-claude": "anthropic-claude";
|
|
12
|
+
"openai-gpt": "openai-gpt";
|
|
13
|
+
"google-gemini": "google-gemini";
|
|
14
|
+
"meta-llama": "meta-llama";
|
|
15
|
+
mistral: "mistral";
|
|
16
|
+
deepseek: "deepseek";
|
|
17
|
+
qwen: "qwen";
|
|
18
|
+
"xai-grok": "xai-grok";
|
|
19
|
+
"decision-model": "decision-model";
|
|
20
|
+
other: "other";
|
|
21
|
+
}>;
|
|
22
|
+
export type ModelFamily = z.infer<typeof ModelFamily>;
|
|
23
|
+
export declare const MODEL_FAMILY_CODE: Record<ModelFamily, number>;
|
|
24
|
+
export declare const ZERO_BYTES32: `0x${string}`;
|
|
25
|
+
export declare const Attestation: z.ZodObject<{
|
|
26
|
+
agentId: z.ZodString;
|
|
27
|
+
score: z.ZodNumber;
|
|
28
|
+
expectedLossBps: z.ZodNumber;
|
|
29
|
+
reportHash: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
30
|
+
mandateHash: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
31
|
+
codeHash: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
32
|
+
teeMeasurement: z.ZodDefault<z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>>;
|
|
33
|
+
modelFamily: z.ZodEnum<{
|
|
34
|
+
unknown: "unknown";
|
|
35
|
+
"anthropic-claude": "anthropic-claude";
|
|
36
|
+
"openai-gpt": "openai-gpt";
|
|
37
|
+
"google-gemini": "google-gemini";
|
|
38
|
+
"meta-llama": "meta-llama";
|
|
39
|
+
mistral: "mistral";
|
|
40
|
+
deepseek: "deepseek";
|
|
41
|
+
qwen: "qwen";
|
|
42
|
+
"xai-grok": "xai-grok";
|
|
43
|
+
"decision-model": "decision-model";
|
|
44
|
+
other: "other";
|
|
45
|
+
}>;
|
|
46
|
+
issuedAt: z.ZodNumber;
|
|
47
|
+
expiresAt: z.ZodNumber;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
export type Attestation = z.infer<typeof Attestation>;
|
|
50
|
+
export declare const Quote: z.ZodObject<{
|
|
51
|
+
agentId: z.ZodString;
|
|
52
|
+
vault: z.ZodPipe<z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>, z.ZodTransform<`0x${string}`, `0x${string}`>>;
|
|
53
|
+
coverAmount: z.ZodString;
|
|
54
|
+
premiumRateBps: z.ZodNumber;
|
|
55
|
+
score: z.ZodNumber;
|
|
56
|
+
modelFamily: z.ZodEnum<{
|
|
57
|
+
unknown: "unknown";
|
|
58
|
+
"anthropic-claude": "anthropic-claude";
|
|
59
|
+
"openai-gpt": "openai-gpt";
|
|
60
|
+
"google-gemini": "google-gemini";
|
|
61
|
+
"meta-llama": "meta-llama";
|
|
62
|
+
mistral: "mistral";
|
|
63
|
+
deepseek: "deepseek";
|
|
64
|
+
qwen: "qwen";
|
|
65
|
+
"xai-grok": "xai-grok";
|
|
66
|
+
"decision-model": "decision-model";
|
|
67
|
+
other: "other";
|
|
68
|
+
}>;
|
|
69
|
+
mandateHash: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
70
|
+
reportHash: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
71
|
+
minBond: z.ZodString;
|
|
72
|
+
expiresAt: z.ZodNumber;
|
|
73
|
+
nonce: z.ZodString;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export type Quote = z.infer<typeof Quote>;
|
|
76
|
+
export declare const EIP712_DOMAIN_NAME = "Bonded";
|
|
77
|
+
export declare const EIP712_DOMAIN_VERSION = "1";
|
|
78
|
+
export declare function bondedDomain(chainId: number, verifyingContract: `0x${string}`): TypedDataDomain;
|
|
79
|
+
export declare const ATTESTATION_TYPES: {
|
|
80
|
+
readonly Attestation: readonly [{
|
|
81
|
+
readonly name: "agentId";
|
|
82
|
+
readonly type: "uint256";
|
|
83
|
+
}, {
|
|
84
|
+
readonly name: "score";
|
|
85
|
+
readonly type: "uint16";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "expectedLossBps";
|
|
88
|
+
readonly type: "uint32";
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "reportHash";
|
|
91
|
+
readonly type: "bytes32";
|
|
92
|
+
}, {
|
|
93
|
+
readonly name: "mandateHash";
|
|
94
|
+
readonly type: "bytes32";
|
|
95
|
+
}, {
|
|
96
|
+
readonly name: "codeHash";
|
|
97
|
+
readonly type: "bytes32";
|
|
98
|
+
}, {
|
|
99
|
+
readonly name: "teeMeasurement";
|
|
100
|
+
readonly type: "bytes32";
|
|
101
|
+
}, {
|
|
102
|
+
readonly name: "modelFamily";
|
|
103
|
+
readonly type: "uint8";
|
|
104
|
+
}, {
|
|
105
|
+
readonly name: "issuedAt";
|
|
106
|
+
readonly type: "uint64";
|
|
107
|
+
}, {
|
|
108
|
+
readonly name: "expiresAt";
|
|
109
|
+
readonly type: "uint64";
|
|
110
|
+
}];
|
|
111
|
+
};
|
|
112
|
+
export declare const QUOTE_TYPES: {
|
|
113
|
+
readonly Quote: readonly [{
|
|
114
|
+
readonly name: "agentId";
|
|
115
|
+
readonly type: "uint256";
|
|
116
|
+
}, {
|
|
117
|
+
readonly name: "vault";
|
|
118
|
+
readonly type: "address";
|
|
119
|
+
}, {
|
|
120
|
+
readonly name: "coverAmount";
|
|
121
|
+
readonly type: "uint256";
|
|
122
|
+
}, {
|
|
123
|
+
readonly name: "premiumRateBps";
|
|
124
|
+
readonly type: "uint32";
|
|
125
|
+
}, {
|
|
126
|
+
readonly name: "score";
|
|
127
|
+
readonly type: "uint16";
|
|
128
|
+
}, {
|
|
129
|
+
readonly name: "modelFamily";
|
|
130
|
+
readonly type: "uint8";
|
|
131
|
+
}, {
|
|
132
|
+
readonly name: "mandateHash";
|
|
133
|
+
readonly type: "bytes32";
|
|
134
|
+
}, {
|
|
135
|
+
readonly name: "reportHash";
|
|
136
|
+
readonly type: "bytes32";
|
|
137
|
+
}, {
|
|
138
|
+
readonly name: "minBond";
|
|
139
|
+
readonly type: "uint256";
|
|
140
|
+
}, {
|
|
141
|
+
readonly name: "expiresAt";
|
|
142
|
+
readonly type: "uint64";
|
|
143
|
+
}, {
|
|
144
|
+
readonly name: "nonce";
|
|
145
|
+
readonly type: "uint256";
|
|
146
|
+
}];
|
|
147
|
+
};
|
|
148
|
+
/** The EIP-712 type strings. Solidity typehashes are keccak256 of these exact strings. */
|
|
149
|
+
export declare const ATTESTATION_TYPE_STRING: string;
|
|
150
|
+
export declare const QUOTE_TYPE_STRING: string;
|
|
151
|
+
export declare const ATTESTATION_TYPEHASH: `0x${string}`;
|
|
152
|
+
export declare const QUOTE_TYPEHASH: `0x${string}`;
|
|
153
|
+
/** Converts a validated attestation into the message shape viem signs. */
|
|
154
|
+
export declare function attestationMessage(input: Attestation): {
|
|
155
|
+
agentId: bigint;
|
|
156
|
+
score: number;
|
|
157
|
+
expectedLossBps: number;
|
|
158
|
+
reportHash: `0x${string}`;
|
|
159
|
+
mandateHash: `0x${string}`;
|
|
160
|
+
codeHash: `0x${string}`;
|
|
161
|
+
teeMeasurement: `0x${string}`;
|
|
162
|
+
modelFamily: number;
|
|
163
|
+
issuedAt: bigint;
|
|
164
|
+
expiresAt: bigint;
|
|
165
|
+
};
|
|
166
|
+
/** Converts a validated quote into the message shape viem signs. */
|
|
167
|
+
export declare function quoteMessage(input: Quote): {
|
|
168
|
+
agentId: bigint;
|
|
169
|
+
vault: `0x${string}`;
|
|
170
|
+
coverAmount: bigint;
|
|
171
|
+
premiumRateBps: number;
|
|
172
|
+
score: number;
|
|
173
|
+
modelFamily: number;
|
|
174
|
+
mandateHash: `0x${string}`;
|
|
175
|
+
reportHash: `0x${string}`;
|
|
176
|
+
minBond: bigint;
|
|
177
|
+
expiresAt: bigint;
|
|
178
|
+
nonce: bigint;
|
|
179
|
+
};
|
|
180
|
+
/** Full typed-data payload for signing or verifying an attestation with viem. */
|
|
181
|
+
export declare function attestationTypedData(domain: TypedDataDomain, attestation: Attestation): {
|
|
182
|
+
domain: TypedDataDomain;
|
|
183
|
+
types: {
|
|
184
|
+
readonly Attestation: readonly [{
|
|
185
|
+
readonly name: "agentId";
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}, {
|
|
188
|
+
readonly name: "score";
|
|
189
|
+
readonly type: "uint16";
|
|
190
|
+
}, {
|
|
191
|
+
readonly name: "expectedLossBps";
|
|
192
|
+
readonly type: "uint32";
|
|
193
|
+
}, {
|
|
194
|
+
readonly name: "reportHash";
|
|
195
|
+
readonly type: "bytes32";
|
|
196
|
+
}, {
|
|
197
|
+
readonly name: "mandateHash";
|
|
198
|
+
readonly type: "bytes32";
|
|
199
|
+
}, {
|
|
200
|
+
readonly name: "codeHash";
|
|
201
|
+
readonly type: "bytes32";
|
|
202
|
+
}, {
|
|
203
|
+
readonly name: "teeMeasurement";
|
|
204
|
+
readonly type: "bytes32";
|
|
205
|
+
}, {
|
|
206
|
+
readonly name: "modelFamily";
|
|
207
|
+
readonly type: "uint8";
|
|
208
|
+
}, {
|
|
209
|
+
readonly name: "issuedAt";
|
|
210
|
+
readonly type: "uint64";
|
|
211
|
+
}, {
|
|
212
|
+
readonly name: "expiresAt";
|
|
213
|
+
readonly type: "uint64";
|
|
214
|
+
}];
|
|
215
|
+
};
|
|
216
|
+
primaryType: "Attestation";
|
|
217
|
+
message: {
|
|
218
|
+
agentId: bigint;
|
|
219
|
+
score: number;
|
|
220
|
+
expectedLossBps: number;
|
|
221
|
+
reportHash: `0x${string}`;
|
|
222
|
+
mandateHash: `0x${string}`;
|
|
223
|
+
codeHash: `0x${string}`;
|
|
224
|
+
teeMeasurement: `0x${string}`;
|
|
225
|
+
modelFamily: number;
|
|
226
|
+
issuedAt: bigint;
|
|
227
|
+
expiresAt: bigint;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
/** Full typed-data payload for signing or verifying a quote with viem. */
|
|
231
|
+
export declare function quoteTypedData(domain: TypedDataDomain, quote: Quote): {
|
|
232
|
+
domain: TypedDataDomain;
|
|
233
|
+
types: {
|
|
234
|
+
readonly Quote: readonly [{
|
|
235
|
+
readonly name: "agentId";
|
|
236
|
+
readonly type: "uint256";
|
|
237
|
+
}, {
|
|
238
|
+
readonly name: "vault";
|
|
239
|
+
readonly type: "address";
|
|
240
|
+
}, {
|
|
241
|
+
readonly name: "coverAmount";
|
|
242
|
+
readonly type: "uint256";
|
|
243
|
+
}, {
|
|
244
|
+
readonly name: "premiumRateBps";
|
|
245
|
+
readonly type: "uint32";
|
|
246
|
+
}, {
|
|
247
|
+
readonly name: "score";
|
|
248
|
+
readonly type: "uint16";
|
|
249
|
+
}, {
|
|
250
|
+
readonly name: "modelFamily";
|
|
251
|
+
readonly type: "uint8";
|
|
252
|
+
}, {
|
|
253
|
+
readonly name: "mandateHash";
|
|
254
|
+
readonly type: "bytes32";
|
|
255
|
+
}, {
|
|
256
|
+
readonly name: "reportHash";
|
|
257
|
+
readonly type: "bytes32";
|
|
258
|
+
}, {
|
|
259
|
+
readonly name: "minBond";
|
|
260
|
+
readonly type: "uint256";
|
|
261
|
+
}, {
|
|
262
|
+
readonly name: "expiresAt";
|
|
263
|
+
readonly type: "uint64";
|
|
264
|
+
}, {
|
|
265
|
+
readonly name: "nonce";
|
|
266
|
+
readonly type: "uint256";
|
|
267
|
+
}];
|
|
268
|
+
};
|
|
269
|
+
primaryType: "Quote";
|
|
270
|
+
message: {
|
|
271
|
+
agentId: bigint;
|
|
272
|
+
vault: `0x${string}`;
|
|
273
|
+
coverAmount: bigint;
|
|
274
|
+
premiumRateBps: number;
|
|
275
|
+
score: number;
|
|
276
|
+
modelFamily: number;
|
|
277
|
+
mandateHash: `0x${string}`;
|
|
278
|
+
reportHash: `0x${string}`;
|
|
279
|
+
minBond: bigint;
|
|
280
|
+
expiresAt: bigint;
|
|
281
|
+
nonce: bigint;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=attestation.d.ts.map
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { keccak256, stringToBytes } from "viem";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { bytes32, evmAddress, uintString, unixSeconds } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Signed messages from the Arena's attester. See docs/SPECIFICATION.md Section 6.4.
|
|
6
|
+
* Attestations are posted to every chain's BondedRegistry; quotes are accepted by CoverManager.
|
|
7
|
+
* The EIP-712 type strings below must match the Solidity typehashes in `BondedTypes.sol`.
|
|
8
|
+
*/
|
|
9
|
+
/** Model family of the agent's brain, used for correlation caps. Codes are uint8 on-chain. */
|
|
10
|
+
export const ModelFamily = z.enum([
|
|
11
|
+
"unknown",
|
|
12
|
+
"anthropic-claude",
|
|
13
|
+
"openai-gpt",
|
|
14
|
+
"google-gemini",
|
|
15
|
+
"meta-llama",
|
|
16
|
+
"mistral",
|
|
17
|
+
"deepseek",
|
|
18
|
+
"qwen",
|
|
19
|
+
"xai-grok",
|
|
20
|
+
"decision-model",
|
|
21
|
+
"other",
|
|
22
|
+
]);
|
|
23
|
+
export const MODEL_FAMILY_CODE = {
|
|
24
|
+
unknown: 0,
|
|
25
|
+
"anthropic-claude": 1,
|
|
26
|
+
"openai-gpt": 2,
|
|
27
|
+
"google-gemini": 3,
|
|
28
|
+
"meta-llama": 4,
|
|
29
|
+
mistral: 5,
|
|
30
|
+
deepseek: 6,
|
|
31
|
+
qwen: 7,
|
|
32
|
+
"xai-grok": 8,
|
|
33
|
+
/** Typed decision models such as Laya or Jev. */
|
|
34
|
+
"decision-model": 9,
|
|
35
|
+
other: 255,
|
|
36
|
+
};
|
|
37
|
+
export const ZERO_BYTES32 = `0x${"0".repeat(64)}`;
|
|
38
|
+
export const Attestation = z
|
|
39
|
+
.object({
|
|
40
|
+
agentId: uintString,
|
|
41
|
+
/** Bonded Score, 0–100. */
|
|
42
|
+
score: z.number().int().min(0).max(100),
|
|
43
|
+
/** Expected annual loss as a fraction of cover, in basis points. */
|
|
44
|
+
expectedLossBps: z.number().int().min(0).max(10_000),
|
|
45
|
+
/** Hash of the full Arena report. */
|
|
46
|
+
reportHash: bytes32,
|
|
47
|
+
/** Hash of the mandate the agent was rated under. */
|
|
48
|
+
mandateHash: bytes32,
|
|
49
|
+
/** Hash of the agent's code/config version that was rated. */
|
|
50
|
+
codeHash: bytes32,
|
|
51
|
+
/** TEE measurement of the running agent, or zero when not in a TEE. */
|
|
52
|
+
teeMeasurement: bytes32.default(ZERO_BYTES32),
|
|
53
|
+
modelFamily: ModelFamily,
|
|
54
|
+
issuedAt: unixSeconds,
|
|
55
|
+
expiresAt: unixSeconds,
|
|
56
|
+
})
|
|
57
|
+
.refine((a) => a.expiresAt > a.issuedAt, {
|
|
58
|
+
message: "expiresAt must be after issuedAt",
|
|
59
|
+
path: ["expiresAt"],
|
|
60
|
+
});
|
|
61
|
+
export const Quote = z.object({
|
|
62
|
+
agentId: uintString,
|
|
63
|
+
vault: evmAddress,
|
|
64
|
+
/** Cover amount in base-asset units (USDC has 6 decimals). */
|
|
65
|
+
coverAmount: uintString,
|
|
66
|
+
/** Annual premium rate in basis points of cover. */
|
|
67
|
+
premiumRateBps: z.number().int().min(0).max(10_000),
|
|
68
|
+
score: z.number().int().min(0).max(100),
|
|
69
|
+
modelFamily: ModelFamily,
|
|
70
|
+
mandateHash: bytes32,
|
|
71
|
+
reportHash: bytes32,
|
|
72
|
+
/** Minimum operator bond in base-asset units. */
|
|
73
|
+
minBond: uintString,
|
|
74
|
+
expiresAt: unixSeconds,
|
|
75
|
+
nonce: uintString,
|
|
76
|
+
});
|
|
77
|
+
export const EIP712_DOMAIN_NAME = "Bonded";
|
|
78
|
+
export const EIP712_DOMAIN_VERSION = "1";
|
|
79
|
+
export function bondedDomain(chainId, verifyingContract) {
|
|
80
|
+
return {
|
|
81
|
+
name: EIP712_DOMAIN_NAME,
|
|
82
|
+
version: EIP712_DOMAIN_VERSION,
|
|
83
|
+
chainId,
|
|
84
|
+
verifyingContract,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export const ATTESTATION_TYPES = {
|
|
88
|
+
Attestation: [
|
|
89
|
+
{ name: "agentId", type: "uint256" },
|
|
90
|
+
{ name: "score", type: "uint16" },
|
|
91
|
+
{ name: "expectedLossBps", type: "uint32" },
|
|
92
|
+
{ name: "reportHash", type: "bytes32" },
|
|
93
|
+
{ name: "mandateHash", type: "bytes32" },
|
|
94
|
+
{ name: "codeHash", type: "bytes32" },
|
|
95
|
+
{ name: "teeMeasurement", type: "bytes32" },
|
|
96
|
+
{ name: "modelFamily", type: "uint8" },
|
|
97
|
+
{ name: "issuedAt", type: "uint64" },
|
|
98
|
+
{ name: "expiresAt", type: "uint64" },
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
export const QUOTE_TYPES = {
|
|
102
|
+
Quote: [
|
|
103
|
+
{ name: "agentId", type: "uint256" },
|
|
104
|
+
{ name: "vault", type: "address" },
|
|
105
|
+
{ name: "coverAmount", type: "uint256" },
|
|
106
|
+
{ name: "premiumRateBps", type: "uint32" },
|
|
107
|
+
{ name: "score", type: "uint16" },
|
|
108
|
+
{ name: "modelFamily", type: "uint8" },
|
|
109
|
+
{ name: "mandateHash", type: "bytes32" },
|
|
110
|
+
{ name: "reportHash", type: "bytes32" },
|
|
111
|
+
{ name: "minBond", type: "uint256" },
|
|
112
|
+
{ name: "expiresAt", type: "uint64" },
|
|
113
|
+
{ name: "nonce", type: "uint256" },
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
/** The EIP-712 type strings. Solidity typehashes are keccak256 of these exact strings. */
|
|
117
|
+
export const ATTESTATION_TYPE_STRING = encodeTypeString("Attestation", ATTESTATION_TYPES.Attestation);
|
|
118
|
+
export const QUOTE_TYPE_STRING = encodeTypeString("Quote", QUOTE_TYPES.Quote);
|
|
119
|
+
export const ATTESTATION_TYPEHASH = keccak256(stringToBytes(ATTESTATION_TYPE_STRING));
|
|
120
|
+
export const QUOTE_TYPEHASH = keccak256(stringToBytes(QUOTE_TYPE_STRING));
|
|
121
|
+
function encodeTypeString(name, fields) {
|
|
122
|
+
return `${name}(${fields.map((field) => `${field.type} ${field.name}`).join(",")})`;
|
|
123
|
+
}
|
|
124
|
+
/** Converts a validated attestation into the message shape viem signs. */
|
|
125
|
+
export function attestationMessage(input) {
|
|
126
|
+
const a = Attestation.parse(input);
|
|
127
|
+
return {
|
|
128
|
+
agentId: BigInt(a.agentId),
|
|
129
|
+
score: a.score,
|
|
130
|
+
expectedLossBps: a.expectedLossBps,
|
|
131
|
+
reportHash: a.reportHash,
|
|
132
|
+
mandateHash: a.mandateHash,
|
|
133
|
+
codeHash: a.codeHash,
|
|
134
|
+
teeMeasurement: a.teeMeasurement,
|
|
135
|
+
modelFamily: MODEL_FAMILY_CODE[a.modelFamily],
|
|
136
|
+
issuedAt: BigInt(a.issuedAt),
|
|
137
|
+
expiresAt: BigInt(a.expiresAt),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Converts a validated quote into the message shape viem signs. */
|
|
141
|
+
export function quoteMessage(input) {
|
|
142
|
+
const q = Quote.parse(input);
|
|
143
|
+
return {
|
|
144
|
+
agentId: BigInt(q.agentId),
|
|
145
|
+
vault: q.vault,
|
|
146
|
+
coverAmount: BigInt(q.coverAmount),
|
|
147
|
+
premiumRateBps: q.premiumRateBps,
|
|
148
|
+
score: q.score,
|
|
149
|
+
modelFamily: MODEL_FAMILY_CODE[q.modelFamily],
|
|
150
|
+
mandateHash: q.mandateHash,
|
|
151
|
+
reportHash: q.reportHash,
|
|
152
|
+
minBond: BigInt(q.minBond),
|
|
153
|
+
expiresAt: BigInt(q.expiresAt),
|
|
154
|
+
nonce: BigInt(q.nonce),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** Full typed-data payload for signing or verifying an attestation with viem. */
|
|
158
|
+
export function attestationTypedData(domain, attestation) {
|
|
159
|
+
return {
|
|
160
|
+
domain,
|
|
161
|
+
types: ATTESTATION_TYPES,
|
|
162
|
+
primaryType: "Attestation",
|
|
163
|
+
message: attestationMessage(attestation),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Full typed-data payload for signing or verifying a quote with viem. */
|
|
167
|
+
export function quoteTypedData(domain, quote) {
|
|
168
|
+
return {
|
|
169
|
+
domain,
|
|
170
|
+
types: QUOTE_TYPES,
|
|
171
|
+
primaryType: "Quote",
|
|
172
|
+
message: quoteMessage(quote),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=attestation.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** EVM address, normalised to its EIP-55 checksum form. */
|
|
3
|
+
export declare const evmAddress: z.ZodPipe<z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>, z.ZodTransform<`0x${string}`, `0x${string}`>>;
|
|
4
|
+
/** Number of bytes a base58 string decodes to (each leading "1" is one zero byte). */
|
|
5
|
+
export declare function base58DecodedLength(value: string): number;
|
|
6
|
+
/** Solana address: base58 text that decodes to exactly 32 bytes. */
|
|
7
|
+
export declare const solanaAddress: z.ZodString;
|
|
8
|
+
/** 4-byte EVM function selector, e.g. 0xa9059cbb. Normalised to lowercase. */
|
|
9
|
+
export declare const selector: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
10
|
+
/** 32-byte hex value (hashes, measurements). Normalised to lowercase. */
|
|
11
|
+
export declare const bytes32: z.ZodPipe<z.ZodString, z.ZodTransform<`0x${string}`, string>>;
|
|
12
|
+
/** Unsigned integer carried as a decimal string (JSON-safe bigint). */
|
|
13
|
+
export declare const uintString: z.ZodString;
|
|
14
|
+
/** Unix timestamp in seconds. */
|
|
15
|
+
export declare const unixSeconds: z.ZodNumber;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true when the list has no duplicates. Compares exactly, because Solana base58
|
|
18
|
+
* addresses are case-sensitive. Normalise values first (EVM addresses are checksummed and
|
|
19
|
+
* selectors lowercased by their schemas before this runs).
|
|
20
|
+
*/
|
|
21
|
+
export declare function isUnique(values: readonly string[]): boolean;
|
|
22
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getAddress, isAddress } from "viem";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** EVM address, normalised to its EIP-55 checksum form. */
|
|
4
|
+
export const evmAddress = z
|
|
5
|
+
.string()
|
|
6
|
+
.refine((value) => isAddress(value, { strict: false }), "invalid EVM address")
|
|
7
|
+
.transform((value) => getAddress(value));
|
|
8
|
+
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
9
|
+
/** Number of bytes a base58 string decodes to (each leading "1" is one zero byte). */
|
|
10
|
+
export function base58DecodedLength(value) {
|
|
11
|
+
let number = 0n;
|
|
12
|
+
for (const char of value) {
|
|
13
|
+
const digit = BASE58_ALPHABET.indexOf(char);
|
|
14
|
+
if (digit === -1)
|
|
15
|
+
throw new Error(`invalid base58 character: ${char}`);
|
|
16
|
+
number = number * 58n + BigInt(digit);
|
|
17
|
+
}
|
|
18
|
+
const leadingZeros = value.length - value.replace(/^1+/, "").length;
|
|
19
|
+
const bodyLength = number === 0n ? 0 : Math.ceil(number.toString(16).length / 2);
|
|
20
|
+
return leadingZeros + bodyLength;
|
|
21
|
+
}
|
|
22
|
+
const BASE58_ADDRESS = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
23
|
+
/** Solana address: base58 text that decodes to exactly 32 bytes. */
|
|
24
|
+
export const solanaAddress = z
|
|
25
|
+
.string()
|
|
26
|
+
.regex(BASE58_ADDRESS, "invalid Solana address")
|
|
27
|
+
// Zod runs every check, so guard the decode against text the regex already rejected.
|
|
28
|
+
.refine((value) => !BASE58_ADDRESS.test(value) || base58DecodedLength(value) === 32, "Solana address must decode to 32 bytes");
|
|
29
|
+
/** 4-byte EVM function selector, e.g. 0xa9059cbb. Normalised to lowercase. */
|
|
30
|
+
export const selector = z
|
|
31
|
+
.string()
|
|
32
|
+
.regex(/^0x[0-9a-fA-F]{8}$/, "selector must be 0x followed by 8 hex chars")
|
|
33
|
+
.transform((value) => value.toLowerCase());
|
|
34
|
+
/** 32-byte hex value (hashes, measurements). Normalised to lowercase. */
|
|
35
|
+
export const bytes32 = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^0x[0-9a-fA-F]{64}$/, "expected 0x followed by 64 hex chars")
|
|
38
|
+
.transform((value) => value.toLowerCase());
|
|
39
|
+
/** Unsigned integer carried as a decimal string (JSON-safe bigint). */
|
|
40
|
+
export const uintString = z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(/^(0|[1-9][0-9]*)$/, "expected an unsigned integer as a decimal string");
|
|
43
|
+
/** Unix timestamp in seconds. */
|
|
44
|
+
export const unixSeconds = z.number().int().nonnegative();
|
|
45
|
+
/**
|
|
46
|
+
* Returns true when the list has no duplicates. Compares exactly, because Solana base58
|
|
47
|
+
* addresses are case-sensitive. Normalise values first (EVM addresses are checksummed and
|
|
48
|
+
* selectors lowercased by their schemas before this runs).
|
|
49
|
+
*/
|
|
50
|
+
export function isUnique(values) {
|
|
51
|
+
return new Set(values).size === values.length;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EvmMandateParams } from "./mandate.js";
|
|
2
|
+
/**
|
|
3
|
+
* On-chain commitment to the rules a mandate enforces: keccak256 of the ABI-encoded params with
|
|
4
|
+
* `mandateHash` set to zero. Matches `BondedTypes.mandateCommitment` in Solidity.
|
|
5
|
+
*
|
|
6
|
+
* MandateModuleFactory refuses a module whose `mandateHash` isn't this value, so a module's
|
|
7
|
+
* mandate hash proves what it enforces. Ratings, quotes and cover for a module-protected agent
|
|
8
|
+
* use this commitment as the mandate hash (vaults still use the hash of the mandate JSON).
|
|
9
|
+
*/
|
|
10
|
+
export declare function mandateCommitment(params: EvmMandateParams): `0x${string}`;
|
|
11
|
+
/** The params with `mandateHash` replaced by their commitment, ready for `createModule`. */
|
|
12
|
+
export declare function withMandateCommitment(params: EvmMandateParams): EvmMandateParams;
|
|
13
|
+
//# sourceMappingURL=mandate-commitment.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256, zeroHash } from "viem";
|
|
2
|
+
/** ABI type of the Solidity struct `BondedTypes.MandateParams`. */
|
|
3
|
+
const MANDATE_PARAMS_ABI = [
|
|
4
|
+
{
|
|
5
|
+
type: "tuple",
|
|
6
|
+
components: [
|
|
7
|
+
{ name: "mandateHash", type: "bytes32" },
|
|
8
|
+
{ name: "mode", type: "uint8" },
|
|
9
|
+
{ name: "baseAsset", type: "address" },
|
|
10
|
+
{ name: "assets", type: "address[]" },
|
|
11
|
+
{ name: "targets", type: "address[]" },
|
|
12
|
+
{ name: "selectors", type: "bytes4[][]" },
|
|
13
|
+
{ name: "destinations", type: "address[]" },
|
|
14
|
+
{ name: "maxTxNotionalUsd6", type: "uint256" },
|
|
15
|
+
{ name: "maxDailyNotionalUsd6", type: "uint256" },
|
|
16
|
+
{ name: "maxDrawdownBps", type: "uint16" },
|
|
17
|
+
{ name: "maxSlippageBps", type: "uint16" },
|
|
18
|
+
{ name: "freezeOnBreach", type: "bool" },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* On-chain commitment to the rules a mandate enforces: keccak256 of the ABI-encoded params with
|
|
24
|
+
* `mandateHash` set to zero. Matches `BondedTypes.mandateCommitment` in Solidity.
|
|
25
|
+
*
|
|
26
|
+
* MandateModuleFactory refuses a module whose `mandateHash` isn't this value, so a module's
|
|
27
|
+
* mandate hash proves what it enforces. Ratings, quotes and cover for a module-protected agent
|
|
28
|
+
* use this commitment as the mandate hash (vaults still use the hash of the mandate JSON).
|
|
29
|
+
*/
|
|
30
|
+
export function mandateCommitment(params) {
|
|
31
|
+
return keccak256(encodeAbiParameters(MANDATE_PARAMS_ABI, [{ ...params, mandateHash: zeroHash }]));
|
|
32
|
+
}
|
|
33
|
+
/** The params with `mandateHash` replaced by their commitment, ready for `createModule`. */
|
|
34
|
+
export function withMandateCommitment(params) {
|
|
35
|
+
return { ...params, mandateHash: mandateCommitment(params) };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=mandate-commitment.js.map
|