Skip to content

Implement x402-extensions crate with generic Extension<T>, bazaar, and sign-in-with-x extensions#10

Merged
takasaki404 merged 4 commits intomainfrom
copilot/implement-x402-extensions-crate
Mar 11, 2026
Merged

Implement x402-extensions crate with generic Extension<T>, bazaar, and sign-in-with-x extensions#10
takasaki404 merged 4 commits intomainfrom
copilot/implement-x402-extensions-crate

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

Per the x402 v2 spec, extensions are a key-value map in PaymentRequired/PaymentPayload where each value has info, schema, and optional extra fields. This PR introduces a typed extension system and implements the bazaar (resource discovery) and sign-in-with-x extensions.

x402-core — Extension type refactoring

  • Extension becomes Extension<T = AnyJson> — backward compatible, transport types unchanged
  • Added extra: Record<AnyJson> with custom Serialize/Deserialize that flattens extra fields alongside info/schema
  • ExtensionInfo trait: const ID for map key + fn schema() for compile-time JSON Schema generation
  • ExtensionMapInsert trait: ergonomic insert_typed() on Record<Extension>
  • Conversion methods: Extension::typed(), into_pair(), into_typed(), with_extra()

x402-extensions — New crate

  • bazaar: BazaarInfo with discriminated union BazaarInput (Http | Mcp tagged on type), BazaarHttpInput (all HTTP methods), BazaarMcpInput (tool name, inputSchema, transport), BazaarOutput. Schema auto-generated via schemars 1.0.
  • sign_in_with_x: SignInWithXInfo (domain, uri, nonce, timestamps, etc.) + SupportedChain helper for the supportedChains extra field.

x402-kit — Re-export

  • pub mod extensions re-exports x402-extensions.

Usage

use x402_extensions::bazaar::*;
use x402_core::types::{Extension, ExtensionMapInsert, Record};

// Typed construction with auto-generated schema
let ext = Extension::typed(BazaarInfo::builder()
    .input(BazaarInput::Mcp(BazaarMcpInput::builder()
        .tool("financial_analysis")
        .input_schema(json!({"type": "object", "properties": {"ticker": {"type": "string"}}}))
        .build()))
    .build());

// Insert into transport map
let mut extensions: Record<Extension> = Record::new();
extensions.insert_typed(ext);

// Extra fields (e.g. supportedChains) flatten during serialization
let ext = Extension::typed(sign_in_info)
    .with_extra("supportedChains", json!([{"chainId": "eip155:8453", "type": "eip191"}]));

Users can implement their own extensions without upstream changes by implementing ExtensionInfo on any Clone + 'static type.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 4, 2026 11:31
…sionInfo trait, bazaar and sign-in-with-x extensions

Co-authored-by: takasaki404 <193405421+takasaki404@users.noreply.github.com>
…ound and better panic messages

Co-authored-by: takasaki404 <193405421+takasaki404@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement x402 extensions crate for PaymentRequirement Implement x402-extensions crate with generic Extension<T>, bazaar, and sign-in-with-x extensions Mar 4, 2026
@takasaki404 takasaki404 marked this pull request as ready for review March 11, 2026 16:21
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@takasaki404 takasaki404 merged commit d8272ec into main Mar 11, 2026
19 checks passed
@takasaki404 takasaki404 deleted the copilot/implement-x402-extensions-crate branch March 11, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants