@techdigger/humanode-agentlink 0.2.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,963 @@
1
+ import { z } from 'zod';
2
+ import { ResourceServerExtension, Price, Network, SchemeNetworkServer } from '@x402/core/types';
3
+ import { PublicClient, TypedDataDomain, Hex } from 'viem';
4
+ import { x402ResourceServer, FacilitatorClient, x402HTTPResourceServer as x402HTTPResourceServer$1, PaywallConfig as PaywallConfig$1, PaywallProvider as PaywallProvider$1 } from '@x402/core/server';
5
+ import { x402HTTPResourceServer, RouteConfig, DynamicPrice, DynamicPayTo, RoutesConfig, PaywallConfig, PaywallProvider } from '@x402/core/http';
6
+
7
+ declare const AGENTLINK = "agentlink";
8
+ type SignatureScheme = 'eip191' | 'eip1271';
9
+ type SignatureType = 'eip191' | 'eip1271';
10
+ interface SupportedChain {
11
+ chainId: string;
12
+ type: SignatureType;
13
+ signatureScheme?: SignatureScheme;
14
+ }
15
+ interface AgentLinkExtensionInfo {
16
+ domain: string;
17
+ uri: string;
18
+ statement?: string;
19
+ version: string;
20
+ nonce: string;
21
+ issuedAt: string;
22
+ expirationTime?: string;
23
+ notBefore?: string;
24
+ requestId?: string;
25
+ resources?: string[];
26
+ }
27
+ interface AgentLinkExtensionSchema {
28
+ $schema: string;
29
+ type: 'object';
30
+ properties: {
31
+ domain: {
32
+ type: 'string';
33
+ };
34
+ address: {
35
+ type: 'string';
36
+ };
37
+ statement?: {
38
+ type: 'string';
39
+ };
40
+ uri: {
41
+ type: 'string';
42
+ format: 'uri';
43
+ };
44
+ version: {
45
+ type: 'string';
46
+ };
47
+ chainId: {
48
+ type: 'string';
49
+ };
50
+ type: {
51
+ type: 'string';
52
+ };
53
+ nonce: {
54
+ type: 'string';
55
+ };
56
+ issuedAt: {
57
+ type: 'string';
58
+ format: 'date-time';
59
+ };
60
+ expirationTime?: {
61
+ type: 'string';
62
+ format: 'date-time';
63
+ };
64
+ notBefore?: {
65
+ type: 'string';
66
+ format: 'date-time';
67
+ };
68
+ requestId?: {
69
+ type: 'string';
70
+ };
71
+ resources?: {
72
+ type: 'array';
73
+ items: {
74
+ type: 'string';
75
+ format: 'uri';
76
+ };
77
+ };
78
+ signature: {
79
+ type: 'string';
80
+ };
81
+ };
82
+ required: string[];
83
+ }
84
+ interface AgentLinkExtension {
85
+ info: AgentLinkExtensionInfo;
86
+ supportedChains: SupportedChain[];
87
+ schema: AgentLinkExtensionSchema;
88
+ mode?: AgentLinkMode;
89
+ }
90
+ interface AgentLinkUsageContext {
91
+ platformAccountId?: string;
92
+ workspaceId?: string;
93
+ }
94
+ interface AgentLinkEntitlement extends AgentLinkUsageContext {
95
+ endpoint: string;
96
+ owner: string;
97
+ generationPtr: bigint;
98
+ }
99
+ declare const AgentLinkPayloadSchema: z.ZodObject<{
100
+ domain: z.ZodString;
101
+ address: z.ZodString;
102
+ statement: z.ZodOptional<z.ZodString>;
103
+ uri: z.ZodString;
104
+ version: z.ZodString;
105
+ chainId: z.ZodString;
106
+ type: z.ZodEnum<["eip191", "eip1271"]>;
107
+ nonce: z.ZodString;
108
+ issuedAt: z.ZodString;
109
+ expirationTime: z.ZodOptional<z.ZodString>;
110
+ notBefore: z.ZodOptional<z.ZodString>;
111
+ requestId: z.ZodOptional<z.ZodString>;
112
+ resources: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
113
+ signatureScheme: z.ZodOptional<z.ZodEnum<["eip191", "eip1271"]>>;
114
+ signature: z.ZodString;
115
+ }, "strip", z.ZodTypeAny, {
116
+ uri: string;
117
+ domain: string;
118
+ address: string;
119
+ version: string;
120
+ chainId: string;
121
+ type: "eip191" | "eip1271";
122
+ nonce: string;
123
+ issuedAt: string;
124
+ signature: string;
125
+ statement?: string | undefined;
126
+ expirationTime?: string | undefined;
127
+ notBefore?: string | undefined;
128
+ requestId?: string | undefined;
129
+ resources?: string[] | undefined;
130
+ signatureScheme?: "eip191" | "eip1271" | undefined;
131
+ }, {
132
+ uri: string;
133
+ domain: string;
134
+ address: string;
135
+ version: string;
136
+ chainId: string;
137
+ type: "eip191" | "eip1271";
138
+ nonce: string;
139
+ issuedAt: string;
140
+ signature: string;
141
+ statement?: string | undefined;
142
+ expirationTime?: string | undefined;
143
+ notBefore?: string | undefined;
144
+ requestId?: string | undefined;
145
+ resources?: string[] | undefined;
146
+ signatureScheme?: "eip191" | "eip1271" | undefined;
147
+ }>;
148
+ type AgentLinkPayload = z.infer<typeof AgentLinkPayloadSchema>;
149
+ type AgentLinkMode = {
150
+ type: 'linked-only';
151
+ reason?: string;
152
+ } | {
153
+ type: 'free';
154
+ } | {
155
+ type: 'free-trial';
156
+ uses?: number;
157
+ } | {
158
+ type: 'discount';
159
+ percent: number;
160
+ uses?: number;
161
+ };
162
+ interface DeclareAgentLinkOptions {
163
+ domain?: string;
164
+ resourceUri?: string;
165
+ statement?: string;
166
+ version?: string;
167
+ network?: string | string[];
168
+ expirationSeconds?: number;
169
+ mode?: AgentLinkMode;
170
+ }
171
+ interface AgentLinkValidationResult {
172
+ valid: boolean;
173
+ error?: string;
174
+ }
175
+ interface AgentLinkValidationOptions {
176
+ maxAge?: number;
177
+ checkNonce?: (nonce: string) => boolean | Promise<boolean>;
178
+ }
179
+ interface AgentLinkVerifyResult {
180
+ valid: boolean;
181
+ address?: string;
182
+ error?: string;
183
+ }
184
+ type CompleteAgentLinkInfo = AgentLinkExtensionInfo & {
185
+ chainId: string;
186
+ type: SignatureType;
187
+ signatureScheme?: SignatureScheme;
188
+ };
189
+
190
+ interface AgentLinkDeclaration extends AgentLinkExtension {
191
+ _options: DeclareAgentLinkOptions;
192
+ }
193
+ declare function declareAgentLinkExtension(options?: DeclareAgentLinkOptions): Record<string, AgentLinkDeclaration>;
194
+
195
+ declare const agentlinkResourceServerExtension: ResourceServerExtension;
196
+
197
+ declare function parseAgentLinkHeader(header: string): AgentLinkPayload;
198
+
199
+ declare function validateAgentLinkMessage(message: AgentLinkPayload, expectedResourceUri: string, options?: AgentLinkValidationOptions): Promise<AgentLinkValidationResult>;
200
+
201
+ declare function verifyAgentLinkSignature(payload: AgentLinkPayload, rpcUrl?: string): Promise<AgentLinkVerifyResult>;
202
+
203
+ declare function buildAgentLinkSchema(): AgentLinkExtensionSchema;
204
+
205
+ declare function extractEVMChainId(chainId: string): number;
206
+ declare function formatSIWEMessage(info: CompleteAgentLinkInfo, address: string): string;
207
+ /**
208
+ * Verify an EVM signature using ERC-1271 (smart wallets) with ecrecover fallback (EOA).
209
+ * Uses viem's publicClient.verifyMessage which handles both automatically.
210
+ */
211
+ declare function verifyEVMSignature(message: string, address: string, signature: string, chainId: string, rpcUrl?: string): Promise<boolean>;
212
+
213
+ type BiomapperRegistryNetwork = 'base' | 'base-sepolia';
214
+ interface BiomapperAgentStatus {
215
+ owner: `0x${string}` | null;
216
+ generationPtr: bigint;
217
+ active: boolean;
218
+ }
219
+ declare const BIOMAPPER_AGENT_REGISTRY_ABI$1: readonly [{
220
+ readonly inputs: readonly [{
221
+ readonly internalType: "address";
222
+ readonly name: "agent";
223
+ readonly type: "address";
224
+ }];
225
+ readonly name: "agentNonce";
226
+ readonly outputs: readonly [{
227
+ readonly internalType: "uint256";
228
+ readonly name: "nonce";
229
+ readonly type: "uint256";
230
+ }];
231
+ readonly stateMutability: "view";
232
+ readonly type: "function";
233
+ }, {
234
+ readonly inputs: readonly [{
235
+ readonly internalType: "address";
236
+ readonly name: "agent";
237
+ readonly type: "address";
238
+ }];
239
+ readonly name: "getAgentStatus";
240
+ readonly outputs: readonly [{
241
+ readonly internalType: "address";
242
+ readonly name: "owner";
243
+ readonly type: "address";
244
+ }, {
245
+ readonly internalType: "uint256";
246
+ readonly name: "generationPtr";
247
+ readonly type: "uint256";
248
+ }, {
249
+ readonly internalType: "bool";
250
+ readonly name: "active";
251
+ readonly type: "bool";
252
+ }];
253
+ readonly stateMutability: "view";
254
+ readonly type: "function";
255
+ }, {
256
+ readonly inputs: readonly [{
257
+ readonly internalType: "address";
258
+ readonly name: "agent";
259
+ readonly type: "address";
260
+ }];
261
+ readonly name: "linkedOwner";
262
+ readonly outputs: readonly [{
263
+ readonly internalType: "address";
264
+ readonly name: "owner";
265
+ readonly type: "address";
266
+ }];
267
+ readonly stateMutability: "view";
268
+ readonly type: "function";
269
+ }, {
270
+ readonly inputs: readonly [{
271
+ readonly internalType: "address";
272
+ readonly name: "agent";
273
+ readonly type: "address";
274
+ }, {
275
+ readonly internalType: "uint256";
276
+ readonly name: "deadline";
277
+ readonly type: "uint256";
278
+ }, {
279
+ readonly internalType: "bytes";
280
+ readonly name: "signature";
281
+ readonly type: "bytes";
282
+ }];
283
+ readonly name: "linkAgent";
284
+ readonly outputs: readonly [];
285
+ readonly stateMutability: "nonpayable";
286
+ readonly type: "function";
287
+ }];
288
+ interface BiomapperRegistryOptions {
289
+ client?: PublicClient;
290
+ contractAddress?: `0x${string}`;
291
+ rpcUrl?: string;
292
+ network?: BiomapperRegistryNetwork;
293
+ }
294
+ declare function createBiomapperRegistryVerifier(options?: BiomapperRegistryOptions): {
295
+ getAgentStatus(address: string, chainId: string): Promise<BiomapperAgentStatus | null>;
296
+ };
297
+ type BiomapperRegistryVerifier = ReturnType<typeof createBiomapperRegistryVerifier>;
298
+
299
+ type BiomapperBridgeNetwork = 'base' | 'base-sepolia';
300
+ declare const BRIDGED_BIOMAPPER_ADDRESSES: Record<BiomapperBridgeNetwork, `0x${string}`>;
301
+ declare const BIOMAPPER_APP_URLS: Record<BiomapperBridgeNetwork, string>;
302
+ declare const BRIDGED_BIOMAPPER_READ_ABI: readonly [{
303
+ readonly inputs: readonly [];
304
+ readonly name: "generationsHead";
305
+ readonly outputs: readonly [{
306
+ readonly internalType: "uint256";
307
+ readonly name: "";
308
+ readonly type: "uint256";
309
+ }];
310
+ readonly stateMutability: "view";
311
+ readonly type: "function";
312
+ }, {
313
+ readonly inputs: readonly [{
314
+ readonly internalType: "address";
315
+ readonly name: "owner";
316
+ readonly type: "address";
317
+ }, {
318
+ readonly internalType: "uint256";
319
+ readonly name: "generationPtr";
320
+ readonly type: "uint256";
321
+ }];
322
+ readonly name: "lookupBiomappingPtr";
323
+ readonly outputs: readonly [{
324
+ readonly internalType: "uint256";
325
+ readonly name: "";
326
+ readonly type: "uint256";
327
+ }];
328
+ readonly stateMutability: "view";
329
+ readonly type: "function";
330
+ }];
331
+
332
+ declare const BiomapperNetworkSchema: z.ZodEnum<["base", "base-sepolia"]>;
333
+ type BiomapperQueryNetwork = z.infer<typeof BiomapperNetworkSchema>;
334
+ declare const CHECK_AGENT_STATUS_TOOL_NAME = "check_agent_status";
335
+ declare const GET_CURRENT_GENERATION_TOOL_NAME = "get_current_generation";
336
+ declare const GET_BIOMAPPER_INFO_TOOL_NAME = "get_biomapper_info";
337
+ declare const CHECK_AGENT_STATUS_TOOL_DESCRIPTION = "Check if an agent wallet is linked to a biomapped human and whether the link is currently active. Returns the owner address, current Biomapper generation pointer, and active status.";
338
+ declare const GET_CURRENT_GENERATION_TOOL_DESCRIPTION = "Get the current Biomapper generation pointer from the Bridged Biomapper contract. Generations represent verification periods \u2014 when a generation ends, usage quotas reset.";
339
+ declare const GET_BIOMAPPER_INFO_TOOL_DESCRIPTION = "Get Biomapper network metadata \u2014 contract addresses, app URLs, and supported networks. Useful for discovering where to point registry queries or where users can verify their identity.";
340
+ declare const CheckAgentStatusInputSchema: z.ZodObject<{
341
+ agentAddress: z.ZodString;
342
+ network: z.ZodOptional<z.ZodEnum<["base", "base-sepolia"]>>;
343
+ registryAddress: z.ZodOptional<z.ZodString>;
344
+ rpcUrl: z.ZodOptional<z.ZodString>;
345
+ }, "strip", z.ZodTypeAny, {
346
+ agentAddress: string;
347
+ network?: "base" | "base-sepolia" | undefined;
348
+ registryAddress?: string | undefined;
349
+ rpcUrl?: string | undefined;
350
+ }, {
351
+ agentAddress: string;
352
+ network?: "base" | "base-sepolia" | undefined;
353
+ registryAddress?: string | undefined;
354
+ rpcUrl?: string | undefined;
355
+ }>;
356
+ declare const GetCurrentGenerationInputSchema: z.ZodObject<{
357
+ network: z.ZodOptional<z.ZodEnum<["base", "base-sepolia"]>>;
358
+ rpcUrl: z.ZodOptional<z.ZodString>;
359
+ }, "strip", z.ZodTypeAny, {
360
+ network?: "base" | "base-sepolia" | undefined;
361
+ rpcUrl?: string | undefined;
362
+ }, {
363
+ network?: "base" | "base-sepolia" | undefined;
364
+ rpcUrl?: string | undefined;
365
+ }>;
366
+ declare const GetBiomapperInfoInputSchema: z.ZodObject<{
367
+ network: z.ZodOptional<z.ZodEnum<["base", "base-sepolia"]>>;
368
+ }, "strip", z.ZodTypeAny, {
369
+ network?: "base" | "base-sepolia" | undefined;
370
+ }, {
371
+ network?: "base" | "base-sepolia" | undefined;
372
+ }>;
373
+ declare const BiomapperNetworkInfoSchema: z.ZodObject<{
374
+ network: z.ZodEnum<["base", "base-sepolia"]>;
375
+ bridgedBiomapper: z.ZodString;
376
+ biomapperAppUrl: z.ZodString;
377
+ chainId: z.ZodNumber;
378
+ caip2: z.ZodString;
379
+ }, "strip", z.ZodTypeAny, {
380
+ chainId: number;
381
+ network: "base" | "base-sepolia";
382
+ bridgedBiomapper: string;
383
+ biomapperAppUrl: string;
384
+ caip2: string;
385
+ }, {
386
+ chainId: number;
387
+ network: "base" | "base-sepolia";
388
+ bridgedBiomapper: string;
389
+ biomapperAppUrl: string;
390
+ caip2: string;
391
+ }>;
392
+ declare const CheckAgentStatusResultSchema: z.ZodObject<{
393
+ linked: z.ZodBoolean;
394
+ active: z.ZodBoolean;
395
+ agentAddress: z.ZodString;
396
+ owner: z.ZodNullable<z.ZodString>;
397
+ generationPtr: z.ZodNullable<z.ZodString>;
398
+ network: z.ZodEnum<["base", "base-sepolia"]>;
399
+ message: z.ZodString;
400
+ }, "strip", z.ZodTypeAny, {
401
+ owner: string | null;
402
+ generationPtr: string | null;
403
+ message: string;
404
+ active: boolean;
405
+ agentAddress: string;
406
+ network: "base" | "base-sepolia";
407
+ linked: boolean;
408
+ }, {
409
+ owner: string | null;
410
+ generationPtr: string | null;
411
+ message: string;
412
+ active: boolean;
413
+ agentAddress: string;
414
+ network: "base" | "base-sepolia";
415
+ linked: boolean;
416
+ }>;
417
+ declare const GetCurrentGenerationResultSchema: z.ZodObject<{
418
+ generationsHead: z.ZodString;
419
+ network: z.ZodEnum<["base", "base-sepolia"]>;
420
+ bridgedBiomapper: z.ZodString;
421
+ biomapperAppUrl: z.ZodString;
422
+ }, "strip", z.ZodTypeAny, {
423
+ generationsHead: string;
424
+ network: "base" | "base-sepolia";
425
+ bridgedBiomapper: string;
426
+ biomapperAppUrl: string;
427
+ }, {
428
+ generationsHead: string;
429
+ network: "base" | "base-sepolia";
430
+ bridgedBiomapper: string;
431
+ biomapperAppUrl: string;
432
+ }>;
433
+ declare const GetBiomapperInfoResultSchema: z.ZodObject<{
434
+ networks: z.ZodArray<z.ZodObject<{
435
+ network: z.ZodEnum<["base", "base-sepolia"]>;
436
+ bridgedBiomapper: z.ZodString;
437
+ biomapperAppUrl: z.ZodString;
438
+ chainId: z.ZodNumber;
439
+ caip2: z.ZodString;
440
+ }, "strip", z.ZodTypeAny, {
441
+ chainId: number;
442
+ network: "base" | "base-sepolia";
443
+ bridgedBiomapper: string;
444
+ biomapperAppUrl: string;
445
+ caip2: string;
446
+ }, {
447
+ chainId: number;
448
+ network: "base" | "base-sepolia";
449
+ bridgedBiomapper: string;
450
+ biomapperAppUrl: string;
451
+ caip2: string;
452
+ }>, "many">;
453
+ }, "strip", z.ZodTypeAny, {
454
+ networks: {
455
+ chainId: number;
456
+ network: "base" | "base-sepolia";
457
+ bridgedBiomapper: string;
458
+ biomapperAppUrl: string;
459
+ caip2: string;
460
+ }[];
461
+ }, {
462
+ networks: {
463
+ chainId: number;
464
+ network: "base" | "base-sepolia";
465
+ bridgedBiomapper: string;
466
+ biomapperAppUrl: string;
467
+ caip2: string;
468
+ }[];
469
+ }>;
470
+ type CheckAgentStatusInput = z.infer<typeof CheckAgentStatusInputSchema>;
471
+ type GetCurrentGenerationInput = z.infer<typeof GetCurrentGenerationInputSchema>;
472
+ type GetBiomapperInfoInput = z.infer<typeof GetBiomapperInfoInputSchema>;
473
+ type BiomapperNetworkInfo = z.infer<typeof BiomapperNetworkInfoSchema>;
474
+ type CheckAgentStatusResult = z.infer<typeof CheckAgentStatusResultSchema>;
475
+ type GetCurrentGenerationResult = z.infer<typeof GetCurrentGenerationResultSchema>;
476
+ type GetBiomapperInfoResult = z.infer<typeof GetBiomapperInfoResultSchema>;
477
+ type BiomapperQueryErrorCode = 'invalid_input' | 'missing_network' | 'missing_registry' | 'query_failed';
478
+ declare class BiomapperQueryError extends Error {
479
+ readonly code: BiomapperQueryErrorCode;
480
+ constructor(code: BiomapperQueryErrorCode, message: string, options?: {
481
+ cause?: unknown;
482
+ });
483
+ }
484
+ interface CreateBiomapperQueryClientOptions {
485
+ client?: PublicClient;
486
+ network?: BiomapperQueryNetwork;
487
+ registryAddress?: `0x${string}`;
488
+ rpcUrl?: string;
489
+ }
490
+ declare function createBiomapperQueryClient(defaults?: CreateBiomapperQueryClientOptions): {
491
+ checkAgentStatus(input: CheckAgentStatusInput): Promise<CheckAgentStatusResult>;
492
+ getCurrentGeneration(input?: GetCurrentGenerationInput): Promise<GetCurrentGenerationResult>;
493
+ getBiomapperInfo(input?: GetBiomapperInfoInput): Promise<GetBiomapperInfoResult>;
494
+ };
495
+ type BiomapperQueryClient = ReturnType<typeof createBiomapperQueryClient>;
496
+
497
+ declare const BIOMAPPER_AGENT_REGISTRY_NAME = "BiomapperAgentRegistry";
498
+ declare const BIOMAPPER_AGENT_REGISTRY_VERSION = "1";
499
+ declare const AGENT_LINK_TYPES: {
500
+ readonly AgentLink: readonly [{
501
+ readonly name: "agent";
502
+ readonly type: "address";
503
+ }, {
504
+ readonly name: "owner";
505
+ readonly type: "address";
506
+ }, {
507
+ readonly name: "nonce";
508
+ readonly type: "uint256";
509
+ }, {
510
+ readonly name: "deadline";
511
+ readonly type: "uint256";
512
+ }];
513
+ };
514
+ interface AgentLinkAuthorization {
515
+ agent: `0x${string}`;
516
+ owner: `0x${string}`;
517
+ registry: `0x${string}`;
518
+ chainId: number;
519
+ nonce: bigint;
520
+ deadline: bigint;
521
+ signature?: `0x${string}`;
522
+ }
523
+ interface AgentLinkConsentOutput {
524
+ type: 'biomapper-agent-link';
525
+ network: BiomapperBridgeNetwork;
526
+ chainId: number;
527
+ agent: `0x${string}`;
528
+ owner: `0x${string}`;
529
+ registry: `0x${string}`;
530
+ nonce: string;
531
+ deadline: string;
532
+ typedData: {
533
+ domain: {
534
+ name: string;
535
+ version: string;
536
+ chainId: number;
537
+ verifyingContract: `0x${string}`;
538
+ };
539
+ types: typeof AGENT_LINK_TYPES;
540
+ primaryType: 'AgentLink';
541
+ message: {
542
+ agent: `0x${string}`;
543
+ owner: `0x${string}`;
544
+ nonce: string;
545
+ deadline: string;
546
+ };
547
+ };
548
+ signature: `0x${string}`;
549
+ }
550
+ interface AgentLinkConsentSigner {
551
+ address: `0x${string}`;
552
+ signTypedData(input: ReturnType<typeof buildAgentLinkTypedData>): Promise<`0x${string}`>;
553
+ }
554
+ interface CreateAgentLinkConsentOptions {
555
+ owner: `0x${string}`;
556
+ registry: `0x${string}`;
557
+ deadline: bigint;
558
+ network: BiomapperBridgeNetwork;
559
+ privateKey?: Hex;
560
+ signer?: AgentLinkConsentSigner;
561
+ client?: AgentLinkConsentClient;
562
+ rpcUrl?: string;
563
+ }
564
+ interface AgentLinkConsentClient {
565
+ getChainId?(): Promise<number>;
566
+ readContract(input: {
567
+ address: `0x${string}`;
568
+ abi: typeof BIOMAPPER_AGENT_REGISTRY_ABI;
569
+ functionName: 'agentNonce';
570
+ args: [`0x${string}`];
571
+ }): Promise<bigint>;
572
+ }
573
+ declare const BIOMAPPER_AGENT_REGISTRY_ABI: readonly [{
574
+ readonly inputs: readonly [{
575
+ readonly internalType: "address";
576
+ readonly name: "agent";
577
+ readonly type: "address";
578
+ }];
579
+ readonly name: "agentNonce";
580
+ readonly outputs: readonly [{
581
+ readonly internalType: "uint256";
582
+ readonly name: "nonce";
583
+ readonly type: "uint256";
584
+ }];
585
+ readonly stateMutability: "view";
586
+ readonly type: "function";
587
+ }];
588
+ declare function buildAgentLinkTypedData(input: AgentLinkAuthorization): {
589
+ domain: TypedDataDomain;
590
+ types: typeof AGENT_LINK_TYPES;
591
+ primaryType: 'AgentLink';
592
+ message: {
593
+ agent: `0x${string}`;
594
+ owner: `0x${string}`;
595
+ nonce: bigint;
596
+ deadline: bigint;
597
+ };
598
+ };
599
+ declare function createAgentLinkConsent(options: CreateAgentLinkConsentOptions): Promise<AgentLinkConsentOutput>;
600
+
601
+ interface AgentLinkStorage {
602
+ hasUsedNonce(nonce: string): Promise<boolean>;
603
+ recordNonce(nonce: string): Promise<void>;
604
+ getUsageCount?(endpoint: string, owner: string, generationPtr: bigint, context?: AgentLinkUsageContext): Promise<number>;
605
+ incrementUsage?(endpoint: string, owner: string, generationPtr: bigint, context?: AgentLinkUsageContext): Promise<void>;
606
+ }
607
+ declare function buildAgentLinkUsageKey(input: AgentLinkEntitlement): string;
608
+ declare class InMemoryAgentLinkStorage implements AgentLinkStorage {
609
+ private usage;
610
+ private nonces;
611
+ getUsageCount(endpoint: string, owner: string, generationPtr: bigint, context?: AgentLinkUsageContext): Promise<number>;
612
+ incrementUsage(endpoint: string, owner: string, generationPtr: bigint, context?: AgentLinkUsageContext): Promise<void>;
613
+ hasUsedNonce(nonce: string): Promise<boolean>;
614
+ recordNonce(nonce: string): Promise<void>;
615
+ }
616
+
617
+ interface AgentLinkScopedEvent extends AgentLinkUsageContext {
618
+ resource: string;
619
+ endpoint: string;
620
+ }
621
+ type AgentLinkHookEvent = ({
622
+ type: 'agent_verified';
623
+ address: string;
624
+ owner: string;
625
+ generationPtr: bigint;
626
+ } & AgentLinkScopedEvent) | ({
627
+ type: 'agent_not_verified';
628
+ address: string;
629
+ } & AgentLinkScopedEvent) | ({
630
+ type: 'validation_failed';
631
+ error?: string;
632
+ } & AgentLinkScopedEvent) | ({
633
+ type: 'discount_applied';
634
+ address: string;
635
+ owner: string;
636
+ generationPtr: bigint;
637
+ } & AgentLinkScopedEvent) | ({
638
+ type: 'discount_exhausted';
639
+ address: string;
640
+ owner: string;
641
+ generationPtr: bigint;
642
+ } & AgentLinkScopedEvent) | ({
643
+ type: 'link.activated';
644
+ address: string;
645
+ owner: string;
646
+ generationPtr: bigint;
647
+ } & AgentLinkScopedEvent) | ({
648
+ type: 'link.deactivated';
649
+ address: string;
650
+ owner: string;
651
+ generationPtr: bigint;
652
+ reason: 'inactive';
653
+ } & AgentLinkScopedEvent) | ({
654
+ type: 'link.unlinked';
655
+ address: string;
656
+ previousOwner: string;
657
+ generationPtr: bigint;
658
+ } & AgentLinkScopedEvent) | ({
659
+ type: 'relink.required';
660
+ address: string;
661
+ owner: string;
662
+ generationPtr: bigint;
663
+ reason: 'inactive_owner';
664
+ } & AgentLinkScopedEvent) | ({
665
+ type: 'usage.threshold_reached';
666
+ address: string;
667
+ owner: string;
668
+ generationPtr: bigint;
669
+ count: number;
670
+ threshold: number;
671
+ mode: Extract<AgentLinkMode['type'], 'free-trial' | 'discount'>;
672
+ } & AgentLinkScopedEvent);
673
+ interface AgentLinkSessionEvent extends AgentLinkUsageContext {
674
+ type: 'link.created';
675
+ sessionId: string;
676
+ network: BiomapperBridgeNetwork;
677
+ redirectUrl?: string;
678
+ registry?: `0x${string}`;
679
+ platformName?: string;
680
+ }
681
+ type AgentLinkEvent = AgentLinkHookEvent | AgentLinkSessionEvent;
682
+ type AgentLinkEventHandler<TEvent extends AgentLinkEvent = AgentLinkEvent> = (event: TEvent) => void | Promise<void>;
683
+ interface AgentLinkEntitlementContext extends AgentLinkUsageContext {
684
+ endpoint?: string;
685
+ }
686
+ interface ResolveAgentLinkEntitlementInput {
687
+ request: {
688
+ adapter: {
689
+ getHeader(name: string): string | undefined;
690
+ getUrl(): string;
691
+ };
692
+ path: string;
693
+ };
694
+ payload: AgentLinkPayload;
695
+ address: string;
696
+ status: {
697
+ owner: `0x${string}` | null;
698
+ generationPtr: bigint;
699
+ active: boolean;
700
+ } | null;
701
+ }
702
+ type AgentLinkEntitlementResolver = (input: ResolveAgentLinkEntitlementInput) => AgentLinkEntitlementContext | void | Promise<AgentLinkEntitlementContext | void>;
703
+
704
+ interface CreateAgentLinkHooksOptions {
705
+ registry: BiomapperRegistryVerifier;
706
+ mode?: AgentLinkMode;
707
+ /** Required in all modes so replayed nonces are rejected. */
708
+ storage: AgentLinkStorage;
709
+ /** Custom RPC URL for EVM signature verification. Uses the chain's default public RPC if omitted. */
710
+ rpcUrl?: string;
711
+ onEvent?: (event: AgentLinkHookEvent) => void | Promise<void>;
712
+ entitlements?: AgentLinkEntitlementContext | AgentLinkEntitlementResolver;
713
+ usageThresholds?: number[];
714
+ }
715
+ declare function createAgentLinkHooks(options: CreateAgentLinkHooksOptions): {
716
+ requestHook: (context: {
717
+ adapter: {
718
+ getHeader(name: string): string | undefined;
719
+ getUrl(): string;
720
+ };
721
+ path: string;
722
+ }) => Promise<void | {
723
+ grantAccess: true;
724
+ } | {
725
+ abort: true;
726
+ reason: string;
727
+ }>;
728
+ verifyFailureHook: ((context: {
729
+ paymentPayload: {
730
+ resource: {
731
+ url: string;
732
+ };
733
+ payload: Record<string, unknown>;
734
+ };
735
+ requirements: {
736
+ amount: string;
737
+ };
738
+ error: Error;
739
+ }) => Promise<void | {
740
+ recovered: true;
741
+ result: {
742
+ isValid: boolean;
743
+ payer?: string;
744
+ };
745
+ }>) | undefined;
746
+ };
747
+
748
+ interface AgentLinkSessionBranding {
749
+ platformName?: string;
750
+ logoUrl?: string;
751
+ accentColor?: string;
752
+ supportUrl?: string;
753
+ }
754
+ interface AgentLinkSession {
755
+ id: string;
756
+ createdAt: string;
757
+ platformAccountId: string;
758
+ workspaceId?: string;
759
+ network: BiomapperBridgeNetwork;
760
+ registry: `0x${string}`;
761
+ redirectUrl?: string;
762
+ consent: AgentLinkConsentOutput;
763
+ branding?: AgentLinkSessionBranding;
764
+ metadata?: Record<string, string>;
765
+ expiresAt?: string;
766
+ }
767
+ interface CreateLinkSessionInput {
768
+ platformAccountId: string;
769
+ workspaceId?: string;
770
+ network: BiomapperBridgeNetwork;
771
+ registry: `0x${string}`;
772
+ redirectUrl?: string;
773
+ consent: AgentLinkConsentOutput;
774
+ branding?: AgentLinkSessionBranding;
775
+ metadata?: Record<string, string>;
776
+ expiresAt?: string;
777
+ }
778
+ interface AgentLinkSessionStore {
779
+ set(session: AgentLinkSession): Promise<void>;
780
+ get(id: string): Promise<AgentLinkSession | null>;
781
+ }
782
+ interface CreateLinkSessionOptions {
783
+ id?: string;
784
+ now?: Date;
785
+ store?: AgentLinkSessionStore;
786
+ onEvent?: AgentLinkEventHandler<AgentLinkSessionEvent>;
787
+ allowedRedirectOrigins?: readonly string[];
788
+ }
789
+ interface LinkSessionValidationOptions {
790
+ now?: Date;
791
+ allowedRedirectOrigins?: readonly string[];
792
+ }
793
+ type LinkSessionValidationResult = {
794
+ valid: true;
795
+ session: AgentLinkSession;
796
+ } | {
797
+ valid: false;
798
+ error: string;
799
+ };
800
+ declare class InMemoryLinkSessionStore implements AgentLinkSessionStore {
801
+ private sessions;
802
+ set(session: AgentLinkSession): Promise<void>;
803
+ get(id: string): Promise<AgentLinkSession | null>;
804
+ }
805
+ declare function validateLinkSession(session: unknown, options?: LinkSessionValidationOptions): LinkSessionValidationResult;
806
+ declare function createLinkSession(input: CreateLinkSessionInput, options?: CreateLinkSessionOptions): Promise<AgentLinkSession>;
807
+ declare function getLinkSession(id: string, options: {
808
+ store: AgentLinkSessionStore;
809
+ }): Promise<AgentLinkSession | null>;
810
+ declare function encodeLinkSession(session: AgentLinkSession): string;
811
+ declare function decodeLinkSession(value: string): AgentLinkSession;
812
+ declare function buildHostedLinkUrl(baseUrl: string, session: AgentLinkSession): string;
813
+ declare function buildEmbeddedHostedLinkUrl(baseUrl: string, session: AgentLinkSession): string;
814
+
815
+ interface BiomapperLinkProtectedRoute extends Omit<RouteConfig, 'accepts'> {
816
+ price: Price | DynamicPrice;
817
+ payTo: string | DynamicPayTo;
818
+ network?: Network;
819
+ scheme?: 'exact';
820
+ maxTimeoutSeconds?: number;
821
+ extra?: Record<string, unknown>;
822
+ }
823
+ interface BiomapperLinkSchemeRegistration {
824
+ network: Network;
825
+ server: SchemeNetworkServer;
826
+ }
827
+ /** Generic middleware signature compatible with Hono and similar frameworks. */
828
+ type AgentLinkMiddleware<TContext = unknown> = (context: TContext, next: () => Promise<void>) => Promise<Response | void>;
829
+ interface BiomapperLinkCallable {
830
+ <TContext = unknown>(context: TContext, next: () => Promise<void>): Promise<Response | void>;
831
+ }
832
+ interface BiomapperLinkOptions {
833
+ /** "base" or "base-sepolia" */
834
+ network: BiomapperRegistryNetwork;
835
+ /** Deployed BiomapperAgentRegistry contract address. */
836
+ registry: `0x${string}`;
837
+ /** Access mode for linked agents. Defaults to "free". */
838
+ mode?: AgentLinkMode;
839
+ /** Storage backend for nonce replay protection and usage tracking. In production, this must be explicit. */
840
+ storage?: AgentLinkStorage;
841
+ /** Event handler for hook events (agent_verified, link.activated, etc.) */
842
+ onEvent?: AgentLinkEventHandler;
843
+ /** Usage count thresholds that trigger usage.threshold_reached events. */
844
+ usageThresholds?: number[];
845
+ /** Custom RPC URL for contract reads and signature verification. */
846
+ rpcUrl?: string;
847
+ /** Static or dynamic entitlement resolver for multi-tenant usage scoping. */
848
+ entitlements?: AgentLinkEntitlementContext | AgentLinkEntitlementResolver;
849
+ /** Forward hook events to a webhook endpoint. */
850
+ webhook?: {
851
+ url: string | string[];
852
+ secret?: string;
853
+ headers?: Record<string, string>;
854
+ };
855
+ /** Statement shown in the agent's SIWE signing prompt. */
856
+ statement?: string;
857
+ /** Domain for the SIWE message. Derived from request URL if omitted. */
858
+ domain?: string;
859
+ /** Simplified x402 route config for the ready-to-use middleware path. */
860
+ protect?: Record<string, BiomapperLinkProtectedRoute>;
861
+ /** Full x402 routes config for the ready-to-use middleware path. */
862
+ routes?: RoutesConfig;
863
+ /** Custom facilitator client(s) for the ready-to-use middleware path. */
864
+ facilitator?: FacilitatorClient | FacilitatorClient[];
865
+ /** Override the default x402 facilitator URL for the ready-to-use middleware path. */
866
+ facilitatorUrl?: string;
867
+ /** Override automatic exact-EVM scheme registration for the ready-to-use middleware path. */
868
+ schemes?: BiomapperLinkSchemeRegistration[];
869
+ /** Built-in paywall config for the ready-to-use middleware path. */
870
+ paywallConfig?: PaywallConfig;
871
+ /** Custom paywall provider for the ready-to-use middleware path. */
872
+ paywall?: PaywallProvider;
873
+ }
874
+ interface BiomapperLinkControlSurface {
875
+ extension: typeof agentlinkResourceServerExtension;
876
+ declare(overrides?: Partial<DeclareAgentLinkOptions>): ReturnType<typeof declareAgentLinkExtension>;
877
+ requestHook: ReturnType<typeof createAgentLinkHooks>['requestHook'];
878
+ verifyFailureHook: ReturnType<typeof createAgentLinkHooks>['verifyFailureHook'];
879
+ middleware: AgentLinkMiddleware;
880
+ initialize(): Promise<void>;
881
+ resourceServer?: x402ResourceServer;
882
+ httpServer?: x402HTTPResourceServer;
883
+ }
884
+ /**
885
+ * One-call setup for Biomapper Link.
886
+ *
887
+ * Collapses registry verifier, storage, hooks, extension declaration,
888
+ * and webhook wiring into a single factory. When `protect` or `routes`
889
+ * is provided, the returned value is also a ready-to-use middleware.
890
+ *
891
+ * @example
892
+ * ```ts
893
+ * const link = createBiomapperLink({
894
+ * network: "base-sepolia",
895
+ * registry: "0xYourRegistry",
896
+ * protect: {
897
+ * "GET /data": {
898
+ * price: "$0.01",
899
+ * payTo: "0xYourPayoutAddress",
900
+ * },
901
+ * },
902
+ * });
903
+ *
904
+ * app.use(link);
905
+ * ```
906
+ */
907
+ declare function createBiomapperLink(options: BiomapperLinkOptions): BiomapperLink;
908
+ type BiomapperLink = BiomapperLinkCallable & BiomapperLinkControlSurface;
909
+
910
+ /** A Next.js App Router route handler: `(request: Request) => Promise<Response>` */
911
+ type NextRouteHandler = (request: Request) => Promise<Response>;
912
+ interface NextPaymentMiddleware {
913
+ /**
914
+ * Wraps a Next.js route handler with x402 payment protection.
915
+ *
916
+ * @example
917
+ * ```ts
918
+ * export const GET = payment.wrap(async (req) => Response.json({ ok: true }))
919
+ * ```
920
+ */
921
+ wrap(handler: NextRouteHandler): NextRouteHandler;
922
+ initialize(): Promise<void>;
923
+ }
924
+ declare function createNextPaymentHandlerFromHTTPServer(httpServer: x402HTTPResourceServer$1, paywallConfig?: PaywallConfig$1, paywall?: PaywallProvider$1): NextPaymentMiddleware;
925
+
926
+ type HonoLikeMiddleware<TContext = unknown> = (context: TContext, next: () => Promise<void>) => Promise<Response | void>;
927
+ interface HonoPaymentMiddleware {
928
+ middleware: HonoLikeMiddleware;
929
+ initialize(): Promise<void>;
930
+ }
931
+ declare function createHonoPaymentMiddlewareFromHTTPServer(httpServer: x402HTTPResourceServer$1, paywallConfig?: PaywallConfig$1, paywall?: PaywallProvider$1): HonoPaymentMiddleware;
932
+
933
+ interface AgentLinkWebhookEnvelope<TEvent extends AgentLinkEvent = AgentLinkEvent> {
934
+ id: string;
935
+ createdAt: string;
936
+ type: TEvent['type'];
937
+ event: TEvent;
938
+ }
939
+ interface AgentLinkWebhookDispatcherOptions {
940
+ url: string | string[];
941
+ headers?: Record<string, string>;
942
+ secret?: string;
943
+ includeLegacySecretHeader?: boolean;
944
+ fetchImpl?: typeof fetch;
945
+ }
946
+ interface VerifyAgentLinkWebhookSignatureOptions {
947
+ secret: string;
948
+ timestamp: string;
949
+ signature: string;
950
+ body: string | Uint8Array | ArrayBuffer | ArrayBufferView;
951
+ now?: Date;
952
+ toleranceSeconds?: number;
953
+ }
954
+ interface AgentLinkWebhookSignatureVerificationResult {
955
+ valid: boolean;
956
+ error?: string;
957
+ }
958
+ declare function createAgentLinkWebhookEnvelope<TEvent extends AgentLinkEvent>(event: TEvent): AgentLinkWebhookEnvelope<TEvent>;
959
+ declare function verifyAgentLinkWebhookSignature(options: VerifyAgentLinkWebhookSignatureOptions): Promise<AgentLinkWebhookSignatureVerificationResult>;
960
+ declare function dispatchAgentLinkWebhook<TEvent extends AgentLinkEvent>(event: TEvent, options: AgentLinkWebhookDispatcherOptions): Promise<AgentLinkWebhookEnvelope<TEvent>>;
961
+ declare function createAgentLinkWebhookDispatcher(options: AgentLinkWebhookDispatcherOptions): AgentLinkEventHandler;
962
+
963
+ export { AGENTLINK, AGENT_LINK_TYPES, type AgentLinkAuthorization, type AgentLinkConsentClient, type AgentLinkConsentOutput, type AgentLinkConsentSigner, type AgentLinkEntitlement, type AgentLinkEntitlementContext, type AgentLinkEntitlementResolver, type AgentLinkEvent, type AgentLinkEventHandler, type AgentLinkExtension, type AgentLinkExtensionInfo, type AgentLinkExtensionSchema, type AgentLinkHookEvent, type AgentLinkMiddleware, type AgentLinkMode, type AgentLinkPayload, AgentLinkPayloadSchema, type AgentLinkSession, type AgentLinkSessionBranding, type AgentLinkSessionEvent, type AgentLinkSessionStore, type AgentLinkStorage, type AgentLinkUsageContext, type AgentLinkValidationOptions, type AgentLinkValidationResult, type AgentLinkVerifyResult, type AgentLinkWebhookDispatcherOptions, type AgentLinkWebhookEnvelope, type AgentLinkWebhookSignatureVerificationResult, BIOMAPPER_AGENT_REGISTRY_ABI$1 as BIOMAPPER_AGENT_REGISTRY_ABI, BIOMAPPER_AGENT_REGISTRY_NAME, BIOMAPPER_AGENT_REGISTRY_VERSION, BIOMAPPER_APP_URLS, BRIDGED_BIOMAPPER_ADDRESSES, BRIDGED_BIOMAPPER_READ_ABI, type BiomapperAgentStatus, type BiomapperBridgeNetwork, type BiomapperLink, type BiomapperLinkControlSurface, type BiomapperLinkOptions, type BiomapperLinkProtectedRoute, type BiomapperLinkSchemeRegistration, type BiomapperNetworkInfo, BiomapperNetworkSchema, type BiomapperQueryClient, BiomapperQueryError, type BiomapperQueryErrorCode, type BiomapperQueryNetwork, type BiomapperRegistryNetwork, type BiomapperRegistryOptions, type BiomapperRegistryVerifier, CHECK_AGENT_STATUS_TOOL_DESCRIPTION, CHECK_AGENT_STATUS_TOOL_NAME, type CheckAgentStatusInput, CheckAgentStatusInputSchema, type CheckAgentStatusResult, CheckAgentStatusResultSchema, type CompleteAgentLinkInfo, type CreateAgentLinkConsentOptions, type CreateAgentLinkHooksOptions, type CreateBiomapperQueryClientOptions, type CreateLinkSessionInput, type CreateLinkSessionOptions, type DeclareAgentLinkOptions, GET_BIOMAPPER_INFO_TOOL_DESCRIPTION, GET_BIOMAPPER_INFO_TOOL_NAME, GET_CURRENT_GENERATION_TOOL_DESCRIPTION, GET_CURRENT_GENERATION_TOOL_NAME, type GetBiomapperInfoInput, GetBiomapperInfoInputSchema, type GetBiomapperInfoResult, GetBiomapperInfoResultSchema, type GetCurrentGenerationInput, GetCurrentGenerationInputSchema, type GetCurrentGenerationResult, GetCurrentGenerationResultSchema, type HonoLikeMiddleware, type HonoPaymentMiddleware, InMemoryAgentLinkStorage, InMemoryLinkSessionStore, type LinkSessionValidationOptions, type LinkSessionValidationResult, type NextPaymentMiddleware, type NextRouteHandler, type ResolveAgentLinkEntitlementInput, type SignatureScheme, type SignatureType, type SupportedChain, type VerifyAgentLinkWebhookSignatureOptions, agentlinkResourceServerExtension, buildAgentLinkSchema, buildAgentLinkTypedData, buildAgentLinkUsageKey, buildEmbeddedHostedLinkUrl, buildHostedLinkUrl, createAgentLinkConsent, createAgentLinkHooks, createAgentLinkWebhookDispatcher, createAgentLinkWebhookEnvelope, createBiomapperLink, createBiomapperQueryClient, createBiomapperRegistryVerifier, createHonoPaymentMiddlewareFromHTTPServer, createLinkSession, createNextPaymentHandlerFromHTTPServer, declareAgentLinkExtension, decodeLinkSession, dispatchAgentLinkWebhook, encodeLinkSession, extractEVMChainId, formatSIWEMessage, getLinkSession, parseAgentLinkHeader, validateAgentLinkMessage, validateLinkSession, verifyAgentLinkSignature, verifyAgentLinkWebhookSignature, verifyEVMSignature };