@techdigger/humanode-agentlink 0.2.0 → 0.3.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/dist/cjs/index.d.ts +12 -12
- package/dist/cjs/index.js +16 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +12 -12
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.d.mts
CHANGED
|
@@ -812,7 +812,7 @@ declare function decodeLinkSession(value: string): AgentLinkSession;
|
|
|
812
812
|
declare function buildHostedLinkUrl(baseUrl: string, session: AgentLinkSession): string;
|
|
813
813
|
declare function buildEmbeddedHostedLinkUrl(baseUrl: string, session: AgentLinkSession): string;
|
|
814
814
|
|
|
815
|
-
interface
|
|
815
|
+
interface AgentLinkProtectedRoute extends Omit<RouteConfig, 'accepts'> {
|
|
816
816
|
price: Price | DynamicPrice;
|
|
817
817
|
payTo: string | DynamicPayTo;
|
|
818
818
|
network?: Network;
|
|
@@ -820,16 +820,16 @@ interface BiomapperLinkProtectedRoute extends Omit<RouteConfig, 'accepts'> {
|
|
|
820
820
|
maxTimeoutSeconds?: number;
|
|
821
821
|
extra?: Record<string, unknown>;
|
|
822
822
|
}
|
|
823
|
-
interface
|
|
823
|
+
interface AgentLinkSchemeRegistration {
|
|
824
824
|
network: Network;
|
|
825
825
|
server: SchemeNetworkServer;
|
|
826
826
|
}
|
|
827
827
|
/** Generic middleware signature compatible with Hono and similar frameworks. */
|
|
828
828
|
type AgentLinkMiddleware<TContext = unknown> = (context: TContext, next: () => Promise<void>) => Promise<Response | void>;
|
|
829
|
-
interface
|
|
829
|
+
interface AgentLinkCallable {
|
|
830
830
|
<TContext = unknown>(context: TContext, next: () => Promise<void>): Promise<Response | void>;
|
|
831
831
|
}
|
|
832
|
-
interface
|
|
832
|
+
interface AgentLinkOptions {
|
|
833
833
|
/** "base" or "base-sepolia" */
|
|
834
834
|
network: BiomapperRegistryNetwork;
|
|
835
835
|
/** Deployed BiomapperAgentRegistry contract address. */
|
|
@@ -857,7 +857,7 @@ interface BiomapperLinkOptions {
|
|
|
857
857
|
/** Domain for the SIWE message. Derived from request URL if omitted. */
|
|
858
858
|
domain?: string;
|
|
859
859
|
/** Simplified x402 route config for the ready-to-use middleware path. */
|
|
860
|
-
protect?: Record<string,
|
|
860
|
+
protect?: Record<string, AgentLinkProtectedRoute>;
|
|
861
861
|
/** Full x402 routes config for the ready-to-use middleware path. */
|
|
862
862
|
routes?: RoutesConfig;
|
|
863
863
|
/** Custom facilitator client(s) for the ready-to-use middleware path. */
|
|
@@ -865,13 +865,13 @@ interface BiomapperLinkOptions {
|
|
|
865
865
|
/** Override the default x402 facilitator URL for the ready-to-use middleware path. */
|
|
866
866
|
facilitatorUrl?: string;
|
|
867
867
|
/** Override automatic exact-EVM scheme registration for the ready-to-use middleware path. */
|
|
868
|
-
schemes?:
|
|
868
|
+
schemes?: AgentLinkSchemeRegistration[];
|
|
869
869
|
/** Built-in paywall config for the ready-to-use middleware path. */
|
|
870
870
|
paywallConfig?: PaywallConfig;
|
|
871
871
|
/** Custom paywall provider for the ready-to-use middleware path. */
|
|
872
872
|
paywall?: PaywallProvider;
|
|
873
873
|
}
|
|
874
|
-
interface
|
|
874
|
+
interface AgentLinkControlSurface {
|
|
875
875
|
extension: typeof agentlinkResourceServerExtension;
|
|
876
876
|
declare(overrides?: Partial<DeclareAgentLinkOptions>): ReturnType<typeof declareAgentLinkExtension>;
|
|
877
877
|
requestHook: ReturnType<typeof createAgentLinkHooks>['requestHook'];
|
|
@@ -882,7 +882,7 @@ interface BiomapperLinkControlSurface {
|
|
|
882
882
|
httpServer?: x402HTTPResourceServer;
|
|
883
883
|
}
|
|
884
884
|
/**
|
|
885
|
-
* One-call setup for
|
|
885
|
+
* One-call setup for Humanode Agentlink.
|
|
886
886
|
*
|
|
887
887
|
* Collapses registry verifier, storage, hooks, extension declaration,
|
|
888
888
|
* and webhook wiring into a single factory. When `protect` or `routes`
|
|
@@ -890,7 +890,7 @@ interface BiomapperLinkControlSurface {
|
|
|
890
890
|
*
|
|
891
891
|
* @example
|
|
892
892
|
* ```ts
|
|
893
|
-
* const link =
|
|
893
|
+
* const link = createAgentLink({
|
|
894
894
|
* network: "base-sepolia",
|
|
895
895
|
* registry: "0xYourRegistry",
|
|
896
896
|
* protect: {
|
|
@@ -904,8 +904,8 @@ interface BiomapperLinkControlSurface {
|
|
|
904
904
|
* app.use(link);
|
|
905
905
|
* ```
|
|
906
906
|
*/
|
|
907
|
-
declare function
|
|
908
|
-
type
|
|
907
|
+
declare function createAgentLink(options: AgentLinkOptions): AgentLink;
|
|
908
|
+
type AgentLink = AgentLinkCallable & AgentLinkControlSurface;
|
|
909
909
|
|
|
910
910
|
/** A Next.js App Router route handler: `(request: Request) => Promise<Response>` */
|
|
911
911
|
type NextRouteHandler = (request: Request) => Promise<Response>;
|
|
@@ -960,4 +960,4 @@ declare function verifyAgentLinkWebhookSignature(options: VerifyAgentLinkWebhook
|
|
|
960
960
|
declare function dispatchAgentLinkWebhook<TEvent extends AgentLinkEvent>(event: TEvent, options: AgentLinkWebhookDispatcherOptions): Promise<AgentLinkWebhookEnvelope<TEvent>>;
|
|
961
961
|
declare function createAgentLinkWebhookDispatcher(options: AgentLinkWebhookDispatcherOptions): AgentLinkEventHandler;
|
|
962
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
|
|
963
|
+
export { AGENTLINK, AGENT_LINK_TYPES, type AgentLink, type AgentLinkAuthorization, type AgentLinkCallable, type AgentLinkConsentClient, type AgentLinkConsentOutput, type AgentLinkConsentSigner, type AgentLinkControlSurface, type AgentLinkEntitlement, type AgentLinkEntitlementContext, type AgentLinkEntitlementResolver, type AgentLinkEvent, type AgentLinkEventHandler, type AgentLinkExtension, type AgentLinkExtensionInfo, type AgentLinkExtensionSchema, type AgentLinkHookEvent, type AgentLinkMiddleware, type AgentLinkMode, type AgentLinkOptions, type AgentLinkPayload, AgentLinkPayloadSchema, type AgentLinkProtectedRoute, type AgentLinkSchemeRegistration, 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 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, createAgentLink, createAgentLinkConsent, createAgentLinkHooks, createAgentLinkWebhookDispatcher, createAgentLinkWebhookEnvelope, createBiomapperQueryClient, createBiomapperRegistryVerifier, createHonoPaymentMiddlewareFromHTTPServer, createLinkSession, createNextPaymentHandlerFromHTTPServer, declareAgentLinkExtension, decodeLinkSession, dispatchAgentLinkWebhook, encodeLinkSession, extractEVMChainId, formatSIWEMessage, getLinkSession, parseAgentLinkHeader, validateAgentLinkMessage, validateLinkSession, verifyAgentLinkSignature, verifyAgentLinkWebhookSignature, verifyEVMSignature };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1565,7 +1565,7 @@ function buildEmbeddedHostedLinkUrl(baseUrl, session) {
|
|
|
1565
1565
|
return url.toString();
|
|
1566
1566
|
}
|
|
1567
1567
|
|
|
1568
|
-
// src/
|
|
1568
|
+
// src/agentlink.ts
|
|
1569
1569
|
import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
1570
1570
|
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
|
|
1571
1571
|
import {
|
|
@@ -1621,10 +1621,12 @@ function encodeHex(bytes) {
|
|
|
1621
1621
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1622
1622
|
}
|
|
1623
1623
|
function constantTimeEqual(left, right) {
|
|
1624
|
-
|
|
1625
|
-
let mismatch =
|
|
1626
|
-
for (let index = 0; index <
|
|
1627
|
-
|
|
1624
|
+
const maxLength = Math.max(left.length, right.length);
|
|
1625
|
+
let mismatch = left.length ^ right.length;
|
|
1626
|
+
for (let index = 0; index < maxLength; index += 1) {
|
|
1627
|
+
const leftCode = index < left.length ? left.charCodeAt(index) : 0;
|
|
1628
|
+
const rightCode = index < right.length ? right.charCodeAt(index) : 0;
|
|
1629
|
+
mismatch |= leftCode ^ rightCode;
|
|
1628
1630
|
}
|
|
1629
1631
|
return mismatch === 0;
|
|
1630
1632
|
}
|
|
@@ -1682,8 +1684,8 @@ async function dispatchAgentLinkWebhook(event, options) {
|
|
|
1682
1684
|
const body = stringifyWebhookEnvelope(envelope);
|
|
1683
1685
|
const timestamp = Math.floor(Date.now() / 1e3).toString();
|
|
1684
1686
|
const signature = options.secret ? await createHmacSignature(options.secret, timestamp, body) : void 0;
|
|
1687
|
+
const includeLegacySecretHeader = options.includeLegacySecretHeader ?? false;
|
|
1685
1688
|
for (const url of urls) {
|
|
1686
|
-
const includeLegacySecretHeader = options.includeLegacySecretHeader ?? true;
|
|
1687
1689
|
const response = await fetchImpl(url, {
|
|
1688
1690
|
method: "POST",
|
|
1689
1691
|
headers: {
|
|
@@ -1825,14 +1827,14 @@ function createHonoPaymentMiddlewareFromHTTPServer(httpServer, paywallConfig, pa
|
|
|
1825
1827
|
return { middleware, initialize };
|
|
1826
1828
|
}
|
|
1827
1829
|
|
|
1828
|
-
// src/
|
|
1830
|
+
// src/agentlink.ts
|
|
1829
1831
|
var NETWORK_TO_CHAIN_ID = {
|
|
1830
1832
|
base: "eip155:8453",
|
|
1831
1833
|
"base-sepolia": "eip155:84532"
|
|
1832
1834
|
};
|
|
1833
1835
|
var DEFAULT_X402_FACILITATOR_URL = "https://x402.org/facilitator";
|
|
1834
1836
|
var hasWarnedAboutInMemoryStorageDefault = false;
|
|
1835
|
-
function
|
|
1837
|
+
function createAgentLink(options) {
|
|
1836
1838
|
const chainId = NETWORK_TO_CHAIN_ID[options.network];
|
|
1837
1839
|
const storage = options.storage ?? resolveDefaultStorage();
|
|
1838
1840
|
const registry = createBiomapperRegistryVerifier({
|
|
@@ -1873,7 +1875,7 @@ function createBiomapperLink(options) {
|
|
|
1873
1875
|
let httpServer;
|
|
1874
1876
|
let middleware = async () => {
|
|
1875
1877
|
throw new Error(
|
|
1876
|
-
"
|
|
1878
|
+
"createAgentLink was used as middleware without x402 route configuration. Pass `protect` or `routes` to enable the one-call middleware path."
|
|
1877
1879
|
);
|
|
1878
1880
|
};
|
|
1879
1881
|
let initialize = async () => {
|
|
@@ -1926,20 +1928,20 @@ function createBiomapperLink(options) {
|
|
|
1926
1928
|
function resolveDefaultStorage() {
|
|
1927
1929
|
if (process.env.NODE_ENV === "production") {
|
|
1928
1930
|
throw new Error(
|
|
1929
|
-
"
|
|
1931
|
+
"createAgentLink requires an explicit storage backend in production. Pass persistent/shared storage instead of relying on the in-memory development default."
|
|
1930
1932
|
);
|
|
1931
1933
|
}
|
|
1932
1934
|
if (!hasWarnedAboutInMemoryStorageDefault) {
|
|
1933
1935
|
hasWarnedAboutInMemoryStorageDefault = true;
|
|
1934
1936
|
console.warn(
|
|
1935
|
-
"[agentlink]
|
|
1937
|
+
"[agentlink] createAgentLink is using InMemoryAgentLinkStorage because no storage backend was provided. This is only safe for local development and tests."
|
|
1936
1938
|
);
|
|
1937
1939
|
}
|
|
1938
1940
|
return new InMemoryAgentLinkStorage();
|
|
1939
1941
|
}
|
|
1940
1942
|
function buildRoutes(options, agentlinkExtensions, defaultNetwork) {
|
|
1941
1943
|
if (options.routes && options.protect) {
|
|
1942
|
-
throw new Error("Pass either `routes` or `protect` to
|
|
1944
|
+
throw new Error("Pass either `routes` or `protect` to createAgentLink, not both.");
|
|
1943
1945
|
}
|
|
1944
1946
|
if (options.routes) {
|
|
1945
1947
|
return mergeAgentLinkExtensions(options.routes, agentlinkExtensions);
|
|
@@ -2185,11 +2187,11 @@ export {
|
|
|
2185
2187
|
buildAgentLinkUsageKey,
|
|
2186
2188
|
buildEmbeddedHostedLinkUrl,
|
|
2187
2189
|
buildHostedLinkUrl,
|
|
2190
|
+
createAgentLink,
|
|
2188
2191
|
createAgentLinkConsent,
|
|
2189
2192
|
createAgentLinkHooks,
|
|
2190
2193
|
createAgentLinkWebhookDispatcher,
|
|
2191
2194
|
createAgentLinkWebhookEnvelope,
|
|
2192
|
-
createBiomapperLink,
|
|
2193
2195
|
createBiomapperQueryClient,
|
|
2194
2196
|
createBiomapperRegistryVerifier,
|
|
2195
2197
|
createHonoPaymentMiddlewareFromHTTPServer,
|