@nullclear/shared 0.0.0-stage → 1.0.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.
@@ -0,0 +1,414 @@
1
+ interface ChainConfig {
2
+ name: string;
3
+ chainId: number;
4
+ caip2: `eip155:${number}`;
5
+ erc8004Identity: `0x${string}`;
6
+ erc8004Reputation: `0x${string}`;
7
+ usdc: `0x${string}`;
8
+ usdcDomain: {
9
+ name: string;
10
+ version: string;
11
+ chainId: number;
12
+ verifyingContract: `0x${string}`;
13
+ };
14
+ rpcUrl: string;
15
+ blockExplorer: string;
16
+ }
17
+ declare const NULLCLEAR_TREASURY_ADDRESS: "0xB586eFcCa41dF27ad3873BEcA54da0c30bf04d5c";
18
+ declare const NULLCLEAR_ARBITER_ADDRESS: "0xfd74fF802EA0E735514C070AF04E0D6528deD145";
19
+ declare const BASE_MAINNET: ChainConfig;
20
+ declare const BASE_SEPOLIA: ChainConfig;
21
+ declare const SUPPORTED_CHAINS: Record<number, ChainConfig>;
22
+ declare const CAIP2_TO_CHAIN_ID: Record<string, number>;
23
+ declare function getChainConfig(chainIdOrCaip2: number | string): ChainConfig;
24
+
25
+ declare const ERC8004_IDENTITY_ABI: readonly [{
26
+ readonly name: "register";
27
+ readonly type: "function";
28
+ readonly stateMutability: "nonpayable";
29
+ readonly inputs: readonly [{
30
+ readonly type: "string";
31
+ readonly name: "agentURI";
32
+ }];
33
+ readonly outputs: readonly [{
34
+ readonly type: "uint256";
35
+ readonly name: "agentId";
36
+ }];
37
+ }, {
38
+ readonly name: "ownerOf";
39
+ readonly type: "function";
40
+ readonly stateMutability: "view";
41
+ readonly inputs: readonly [{
42
+ readonly type: "uint256";
43
+ readonly name: "tokenId";
44
+ }];
45
+ readonly outputs: readonly [{
46
+ readonly type: "address";
47
+ }];
48
+ }, {
49
+ readonly name: "tokenURI";
50
+ readonly type: "function";
51
+ readonly stateMutability: "view";
52
+ readonly inputs: readonly [{
53
+ readonly type: "uint256";
54
+ readonly name: "tokenId";
55
+ }];
56
+ readonly outputs: readonly [{
57
+ readonly type: "string";
58
+ }];
59
+ }, {
60
+ readonly name: "getAgentWallet";
61
+ readonly type: "function";
62
+ readonly stateMutability: "view";
63
+ readonly inputs: readonly [{
64
+ readonly type: "uint256";
65
+ readonly name: "agentId";
66
+ }];
67
+ readonly outputs: readonly [{
68
+ readonly type: "address";
69
+ }];
70
+ }, {
71
+ readonly name: "Registered";
72
+ readonly type: "event";
73
+ readonly inputs: readonly [{
74
+ readonly type: "uint256";
75
+ readonly name: "agentId";
76
+ readonly indexed: true;
77
+ }, {
78
+ readonly type: "string";
79
+ readonly name: "agentURI";
80
+ }, {
81
+ readonly type: "address";
82
+ readonly name: "owner";
83
+ readonly indexed: true;
84
+ }];
85
+ }];
86
+ declare const ERC8004_REPUTATION_ABI: readonly [{
87
+ readonly name: "giveFeedback";
88
+ readonly type: "function";
89
+ readonly stateMutability: "nonpayable";
90
+ readonly inputs: readonly [{
91
+ readonly type: "uint256";
92
+ readonly name: "agentId";
93
+ }, {
94
+ readonly type: "int128";
95
+ readonly name: "value";
96
+ }, {
97
+ readonly type: "uint8";
98
+ readonly name: "valueDecimals";
99
+ }, {
100
+ readonly type: "string";
101
+ readonly name: "tag1";
102
+ }, {
103
+ readonly type: "string";
104
+ readonly name: "tag2";
105
+ }, {
106
+ readonly type: "string";
107
+ readonly name: "endpoint";
108
+ }, {
109
+ readonly type: "string";
110
+ readonly name: "feedbackURI";
111
+ }, {
112
+ readonly type: "bytes32";
113
+ readonly name: "feedbackHash";
114
+ }];
115
+ readonly outputs: readonly [];
116
+ }, {
117
+ readonly name: "getSummary";
118
+ readonly type: "function";
119
+ readonly stateMutability: "view";
120
+ readonly inputs: readonly [{
121
+ readonly type: "uint256";
122
+ readonly name: "agentId";
123
+ }, {
124
+ readonly type: "address[]";
125
+ readonly name: "clientAddresses";
126
+ }, {
127
+ readonly type: "string";
128
+ readonly name: "tag1";
129
+ }, {
130
+ readonly type: "string";
131
+ readonly name: "tag2";
132
+ }];
133
+ readonly outputs: readonly [{
134
+ readonly type: "uint64";
135
+ readonly name: "count";
136
+ }, {
137
+ readonly type: "int128";
138
+ readonly name: "summaryValue";
139
+ }, {
140
+ readonly type: "uint8";
141
+ readonly name: "summaryValueDecimals";
142
+ }];
143
+ }, {
144
+ readonly name: "readFeedback";
145
+ readonly type: "function";
146
+ readonly stateMutability: "view";
147
+ readonly inputs: readonly [{
148
+ readonly type: "uint256";
149
+ readonly name: "agentId";
150
+ }, {
151
+ readonly type: "address";
152
+ readonly name: "clientAddress";
153
+ }, {
154
+ readonly type: "uint64";
155
+ readonly name: "feedbackIndex";
156
+ }];
157
+ readonly outputs: readonly [{
158
+ readonly type: "int128";
159
+ readonly name: "value";
160
+ }, {
161
+ readonly type: "uint8";
162
+ readonly name: "valueDecimals";
163
+ }, {
164
+ readonly type: "string";
165
+ readonly name: "tag1";
166
+ }, {
167
+ readonly type: "string";
168
+ readonly name: "tag2";
169
+ }, {
170
+ readonly type: "bool";
171
+ readonly name: "isRevoked";
172
+ }];
173
+ }, {
174
+ readonly name: "NewFeedback";
175
+ readonly type: "event";
176
+ readonly inputs: readonly [{
177
+ readonly type: "uint256";
178
+ readonly name: "agentId";
179
+ readonly indexed: true;
180
+ }, {
181
+ readonly type: "address";
182
+ readonly name: "clientAddress";
183
+ readonly indexed: true;
184
+ }, {
185
+ readonly type: "uint64";
186
+ readonly name: "feedbackIndex";
187
+ }, {
188
+ readonly type: "int128";
189
+ readonly name: "value";
190
+ }, {
191
+ readonly type: "uint8";
192
+ readonly name: "valueDecimals";
193
+ }, {
194
+ readonly type: "string";
195
+ readonly name: "indexedTag1";
196
+ readonly indexed: true;
197
+ }, {
198
+ readonly type: "string";
199
+ readonly name: "tag1";
200
+ }, {
201
+ readonly type: "string";
202
+ readonly name: "tag2";
203
+ }, {
204
+ readonly type: "string";
205
+ readonly name: "endpoint";
206
+ }, {
207
+ readonly type: "string";
208
+ readonly name: "feedbackURI";
209
+ }, {
210
+ readonly type: "bytes32";
211
+ readonly name: "feedbackHash";
212
+ }];
213
+ }];
214
+
215
+ declare const EIP3009_ABI: readonly [{
216
+ readonly name: "transferWithAuthorization";
217
+ readonly type: "function";
218
+ readonly stateMutability: "nonpayable";
219
+ readonly inputs: readonly [{
220
+ readonly type: "address";
221
+ readonly name: "from";
222
+ }, {
223
+ readonly type: "address";
224
+ readonly name: "to";
225
+ }, {
226
+ readonly type: "uint256";
227
+ readonly name: "value";
228
+ }, {
229
+ readonly type: "uint256";
230
+ readonly name: "validAfter";
231
+ }, {
232
+ readonly type: "uint256";
233
+ readonly name: "validBefore";
234
+ }, {
235
+ readonly type: "bytes32";
236
+ readonly name: "nonce";
237
+ }, {
238
+ readonly type: "uint8";
239
+ readonly name: "v";
240
+ }, {
241
+ readonly type: "bytes32";
242
+ readonly name: "r";
243
+ }, {
244
+ readonly type: "bytes32";
245
+ readonly name: "s";
246
+ }];
247
+ readonly outputs: readonly [];
248
+ }];
249
+ interface X402PaymentOption {
250
+ scheme: "exact";
251
+ network: "eip155:8453" | "eip155:84532";
252
+ amount: string;
253
+ asset: `0x${string}`;
254
+ payTo: `0x${string}`;
255
+ maxTimeoutSeconds: number;
256
+ extra?: {
257
+ name?: string;
258
+ version?: string;
259
+ feePayer?: `0x${string}`;
260
+ };
261
+ }
262
+ interface X402PaymentRequired {
263
+ x402Version: 2;
264
+ error?: string;
265
+ resource: {
266
+ url: string;
267
+ description?: string;
268
+ mimeType?: string;
269
+ };
270
+ accepts: X402PaymentOption[];
271
+ }
272
+ interface EIP3009Authorization {
273
+ from: `0x${string}`;
274
+ to: `0x${string}`;
275
+ value: string;
276
+ validAfter: string;
277
+ validBefore: string;
278
+ nonce: `0x${string}`;
279
+ }
280
+ interface X402PaymentSignaturePayload {
281
+ x402Version: 2;
282
+ resource?: {
283
+ url: string;
284
+ mimeType?: string;
285
+ };
286
+ accepted: X402PaymentOption;
287
+ payload: {
288
+ signature: `0x${string}`;
289
+ authorization: EIP3009Authorization;
290
+ };
291
+ }
292
+ declare const EIP3009_TYPES: {
293
+ readonly TransferWithAuthorization: readonly [{
294
+ readonly name: "from";
295
+ readonly type: "address";
296
+ }, {
297
+ readonly name: "to";
298
+ readonly type: "address";
299
+ }, {
300
+ readonly name: "value";
301
+ readonly type: "uint256";
302
+ }, {
303
+ readonly name: "validAfter";
304
+ readonly type: "uint256";
305
+ }, {
306
+ readonly name: "validBefore";
307
+ readonly type: "uint256";
308
+ }, {
309
+ readonly name: "nonce";
310
+ readonly type: "bytes32";
311
+ }];
312
+ };
313
+ interface X402PaymentResponse {
314
+ success: boolean;
315
+ transaction?: `0x${string}`;
316
+ network: "eip155:8453" | "eip155:84532";
317
+ payer: `0x${string}`;
318
+ errorReason?: string;
319
+ }
320
+ /**
321
+ * Universal base64 encoder that works in Node.js, Cloudflare Workers, and Browser
322
+ */
323
+ declare function encodeBase64Json(obj: unknown): string;
324
+ /**
325
+ * Universal base64 decoder that works in Node.js, Cloudflare Workers, and Browser
326
+ */
327
+ declare function decodeBase64Json<T>(base64: string): T;
328
+
329
+ interface KYAMandate {
330
+ corporateEntity: string;
331
+ entityRegistrationNumber: string;
332
+ agentId: string;
333
+ agentWallet: `0x${string}`;
334
+ maxTxLimitUsd: number;
335
+ liabilityCoverageUsd: number;
336
+ validUntil: number;
337
+ jurisdiction: string;
338
+ }
339
+ declare const KYA_MANDATE_TYPES: {
340
+ readonly CorporateMandate: readonly [{
341
+ readonly name: "corporateEntity";
342
+ readonly type: "string";
343
+ }, {
344
+ readonly name: "entityRegistrationNumber";
345
+ readonly type: "string";
346
+ }, {
347
+ readonly name: "agentId";
348
+ readonly type: "string";
349
+ }, {
350
+ readonly name: "agentWallet";
351
+ readonly type: "address";
352
+ }, {
353
+ readonly name: "maxTxLimitUsd";
354
+ readonly type: "uint256";
355
+ }, {
356
+ readonly name: "liabilityCoverageUsd";
357
+ readonly type: "uint256";
358
+ }, {
359
+ readonly name: "validUntil";
360
+ readonly type: "uint256";
361
+ }, {
362
+ readonly name: "jurisdiction";
363
+ readonly type: "string";
364
+ }];
365
+ };
366
+ declare const KYA_DOMAIN: {
367
+ readonly name: "NullClear KYA Registry";
368
+ readonly version: "1";
369
+ readonly chainId: 8453;
370
+ };
371
+ interface ClearingAttestation {
372
+ clearingId: string;
373
+ buyer: `0x${string}`;
374
+ sellerAgentId: string;
375
+ amountAtomic: string;
376
+ feeAtomic: string;
377
+ responseHash: `0x${string}`;
378
+ timestamp: number;
379
+ cleared: boolean;
380
+ }
381
+ declare const ARBITER_ATTESTATION_TYPES: {
382
+ readonly ClearingAttestation: readonly [{
383
+ readonly name: "clearingId";
384
+ readonly type: "string";
385
+ }, {
386
+ readonly name: "buyer";
387
+ readonly type: "address";
388
+ }, {
389
+ readonly name: "sellerAgentId";
390
+ readonly type: "string";
391
+ }, {
392
+ readonly name: "amountAtomic";
393
+ readonly type: "uint256";
394
+ }, {
395
+ readonly name: "feeAtomic";
396
+ readonly type: "uint256";
397
+ }, {
398
+ readonly name: "responseHash";
399
+ readonly type: "bytes32";
400
+ }, {
401
+ readonly name: "timestamp";
402
+ readonly type: "uint256";
403
+ }, {
404
+ readonly name: "cleared";
405
+ readonly type: "bool";
406
+ }];
407
+ };
408
+ declare const ARBITER_DOMAIN: {
409
+ readonly name: "NullClear Arbiter";
410
+ readonly version: "1";
411
+ readonly chainId: 8453;
412
+ };
413
+
414
+ export { ARBITER_ATTESTATION_TYPES, ARBITER_DOMAIN, BASE_MAINNET, BASE_SEPOLIA, CAIP2_TO_CHAIN_ID, type ChainConfig, type ClearingAttestation, type EIP3009Authorization, EIP3009_ABI, EIP3009_TYPES, ERC8004_IDENTITY_ABI, ERC8004_REPUTATION_ABI, type KYAMandate, KYA_DOMAIN, KYA_MANDATE_TYPES, NULLCLEAR_ARBITER_ADDRESS, NULLCLEAR_TREASURY_ADDRESS, SUPPORTED_CHAINS, type X402PaymentOption, type X402PaymentRequired, type X402PaymentResponse, type X402PaymentSignaturePayload, decodeBase64Json, encodeBase64Json, getChainConfig };
package/dist/index.js ADDED
@@ -0,0 +1,163 @@
1
+ // src/chains.ts
2
+ var NULLCLEAR_TREASURY_ADDRESS = "0xB586eFcCa41dF27ad3873BEcA54da0c30bf04d5c";
3
+ var NULLCLEAR_ARBITER_ADDRESS = "0xfd74fF802EA0E735514C070AF04E0D6528deD145";
4
+ var BASE_MAINNET = {
5
+ name: "Base Mainnet",
6
+ chainId: 8453,
7
+ caip2: "eip155:8453",
8
+ erc8004Identity: "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
9
+ erc8004Reputation: "0x8004BAa17C55a88189AE136b182e5fdA19dE9b63",
10
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
11
+ usdcDomain: {
12
+ name: "USD Coin",
13
+ version: "2",
14
+ chainId: 8453,
15
+ verifyingContract: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
16
+ },
17
+ rpcUrl: "https://mainnet.base.org",
18
+ blockExplorer: "https://basescan.org"
19
+ };
20
+ var BASE_SEPOLIA = {
21
+ name: "Base Sepolia",
22
+ chainId: 84532,
23
+ caip2: "eip155:84532",
24
+ erc8004Identity: "0x8004A818BFB912233c491871b3d84c89A494BD9e",
25
+ erc8004Reputation: "0x8004B663056A597Dffe9eCcC1965A193B7388713",
26
+ usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
27
+ usdcDomain: {
28
+ name: "USDC",
29
+ version: "2",
30
+ chainId: 84532,
31
+ verifyingContract: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
32
+ },
33
+ rpcUrl: "https://sepolia.base.org",
34
+ blockExplorer: "https://sepolia.basescan.org"
35
+ };
36
+ var SUPPORTED_CHAINS = {
37
+ 8453: BASE_MAINNET,
38
+ 84532: BASE_SEPOLIA
39
+ };
40
+ var CAIP2_TO_CHAIN_ID = {
41
+ "eip155:8453": 8453,
42
+ "eip155:84532": 84532
43
+ };
44
+ function getChainConfig(chainIdOrCaip2) {
45
+ let chainId;
46
+ if (typeof chainIdOrCaip2 === "string") {
47
+ if (chainIdOrCaip2.startsWith("eip155:")) {
48
+ chainId = CAIP2_TO_CHAIN_ID[chainIdOrCaip2] ?? parseInt(chainIdOrCaip2.slice(7), 10);
49
+ } else {
50
+ chainId = parseInt(chainIdOrCaip2, 10);
51
+ }
52
+ } else {
53
+ chainId = chainIdOrCaip2;
54
+ }
55
+ const config = SUPPORTED_CHAINS[chainId];
56
+ if (!config) {
57
+ throw new Error(`Unsupported chain ID or CAIP-2 identifier: ${chainIdOrCaip2}`);
58
+ }
59
+ return config;
60
+ }
61
+
62
+ // src/erc8004-abi.ts
63
+ import { parseAbi } from "viem";
64
+ var ERC8004_IDENTITY_ABI = parseAbi([
65
+ "function register(string agentURI) external returns (uint256 agentId)",
66
+ "function ownerOf(uint256 tokenId) external view returns (address)",
67
+ "function tokenURI(uint256 tokenId) external view returns (string)",
68
+ "function getAgentWallet(uint256 agentId) external view returns (address)",
69
+ "event Registered(uint256 indexed agentId, string agentURI, address indexed owner)"
70
+ ]);
71
+ var ERC8004_REPUTATION_ABI = parseAbi([
72
+ "function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash) external",
73
+ "function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) external view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)",
74
+ "function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) external view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)",
75
+ "event NewFeedback(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, int128 value, uint8 valueDecimals, string indexed indexedTag1, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)"
76
+ ]);
77
+
78
+ // src/x402-types.ts
79
+ import { parseAbi as parseAbi2 } from "viem";
80
+ var EIP3009_ABI = parseAbi2([
81
+ "function transferWithAuthorization(address from, address to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 nonce, uint8 v, bytes32 r, bytes32 s) external"
82
+ ]);
83
+ var EIP3009_TYPES = {
84
+ TransferWithAuthorization: [
85
+ { name: "from", type: "address" },
86
+ { name: "to", type: "address" },
87
+ { name: "value", type: "uint256" },
88
+ { name: "validAfter", type: "uint256" },
89
+ { name: "validBefore", type: "uint256" },
90
+ { name: "nonce", type: "bytes32" }
91
+ ]
92
+ };
93
+ function encodeBase64Json(obj) {
94
+ const json = JSON.stringify(obj);
95
+ if (typeof Buffer !== "undefined") {
96
+ return Buffer.from(json, "utf-8").toString("base64");
97
+ }
98
+ return btoa(unescape(encodeURIComponent(json)));
99
+ }
100
+ function decodeBase64Json(base64) {
101
+ let json;
102
+ if (typeof Buffer !== "undefined") {
103
+ json = Buffer.from(base64, "base64").toString("utf-8");
104
+ } else {
105
+ json = decodeURIComponent(escape(atob(base64)));
106
+ }
107
+ return JSON.parse(json);
108
+ }
109
+
110
+ // src/eip712-kya.ts
111
+ var KYA_MANDATE_TYPES = {
112
+ CorporateMandate: [
113
+ { name: "corporateEntity", type: "string" },
114
+ { name: "entityRegistrationNumber", type: "string" },
115
+ { name: "agentId", type: "string" },
116
+ { name: "agentWallet", type: "address" },
117
+ { name: "maxTxLimitUsd", type: "uint256" },
118
+ { name: "liabilityCoverageUsd", type: "uint256" },
119
+ { name: "validUntil", type: "uint256" },
120
+ { name: "jurisdiction", type: "string" }
121
+ ]
122
+ };
123
+ var KYA_DOMAIN = {
124
+ name: "NullClear KYA Registry",
125
+ version: "1",
126
+ chainId: 8453
127
+ };
128
+ var ARBITER_ATTESTATION_TYPES = {
129
+ ClearingAttestation: [
130
+ { name: "clearingId", type: "string" },
131
+ { name: "buyer", type: "address" },
132
+ { name: "sellerAgentId", type: "string" },
133
+ { name: "amountAtomic", type: "uint256" },
134
+ { name: "feeAtomic", type: "uint256" },
135
+ { name: "responseHash", type: "bytes32" },
136
+ { name: "timestamp", type: "uint256" },
137
+ { name: "cleared", type: "bool" }
138
+ ]
139
+ };
140
+ var ARBITER_DOMAIN = {
141
+ name: "NullClear Arbiter",
142
+ version: "1",
143
+ chainId: 8453
144
+ };
145
+ export {
146
+ ARBITER_ATTESTATION_TYPES,
147
+ ARBITER_DOMAIN,
148
+ BASE_MAINNET,
149
+ BASE_SEPOLIA,
150
+ CAIP2_TO_CHAIN_ID,
151
+ EIP3009_ABI,
152
+ EIP3009_TYPES,
153
+ ERC8004_IDENTITY_ABI,
154
+ ERC8004_REPUTATION_ABI,
155
+ KYA_DOMAIN,
156
+ KYA_MANDATE_TYPES,
157
+ NULLCLEAR_ARBITER_ADDRESS,
158
+ NULLCLEAR_TREASURY_ADDRESS,
159
+ SUPPORTED_CHAINS,
160
+ decodeBase64Json,
161
+ encodeBase64Json,
162
+ getChainConfig
163
+ };