Adds new @metamask/x402 package#236
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning MetaMask internal reviewing guidelines:
Ignoring alerts on:
|
f4ed2b3 to
ecb5428
Compare
|
@SocketSecurity ignore npm/@x402/evm@2.12.0 |
ecb5428 to
3911f5c
Compare
f49f5c6 to
6c810d6
Compare
6c810d6 to
30085fa
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 66cc06a. Configure here.
mj-kiwi
left a comment
There was a problem hiding this comment.
I think we need to fix the cursor raised issues
There was a problem hiding this comment.
Should we put the license content here? Other packages do the same.
There was a problem hiding this comment.
Should we put the license content here? Other packages do the same.
| */ | ||
| function validateFacilitatorAddresses( | ||
| publishedAddresses: unknown, | ||
| ): string[] | undefined { |
There was a problem hiding this comment.
The Hex type for address fields here will cause loss of type safety.
There was a problem hiding this comment.
I've updated to Address type (which is functionally equivalent to Hex)
|
Ran a local package-level pass on the new corepack yarn workspace @metamask/smart-accounts-kit-x402 test
corepack yarn workspace @metamask/smart-accounts-kit-x402 lint
corepack yarn workspace @metamask/smart-accounts-kit-x402 buildOne integration issue looks worth fixing before publishing the package: For the normal Base USDC shape, Minimal repro after import { x402ExactEvmErc7710ServerScheme } from './packages/smart-accounts-kit-x402/dist/index.mjs';
const scheme = new x402ExactEvmErc7710ServerScheme();
const result = await scheme.enhancePaymentRequirements(
{
scheme: 'exact',
network: 'eip155:8453',
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
amount: '10000',
payTo: '0x1111111111111111111111111111111111111111',
maxTimeoutSeconds: 300,
extra: {},
},
{
x402Version: 2,
scheme: 'exact',
network: 'eip155:8453',
extra: { facilitatorAddresses: ['0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] },
},
[],
);
console.log(result.extra);
// actual: {}
// expected for this wrapper: { assetTransferMethod: 'erc7710', facilitatorAddresses: [...] }The current tests miss this because Patch shape: either make this wrapper always apply the ERC-7710 server enhancer after the base exact scheme runs, or gate on an explicit Smaller packaging note: |
|
One post-merge heads-up since this shipped in Fresh npm repro against the published package: TMPDIR=$(mktemp -d)
cd "$TMPDIR"
npm init -y >/dev/null
npm i @metamask/x402@0.1.0 @x402/core@2.12.0 @x402/evm@2.12.0
node --input-type=module <<'NODE'
import { x402ExactEvmErc7710ServerScheme } from '@metamask/x402';
const scheme = new x402ExactEvmErc7710ServerScheme();
const result = await scheme.enhancePaymentRequirements(
{
scheme: 'exact',
network: 'eip155:8453',
asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
amount: '10000',
payTo: '0x1111111111111111111111111111111111111111',
maxTimeoutSeconds: 300,
extra: {},
},
{
x402Version: 2,
scheme: 'exact',
network: 'eip155:8453',
extra: { facilitatorAddresses: ['0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] },
},
[],
);
console.log(JSON.stringify(result.extra ?? {}, null, 2));
NODEObserved output: {}Expected for the ERC-7710 wrapper path would be something like: {
"assetTransferMethod": "erc7710",
"facilitatorAddresses": ["0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa"]
}The current unit test still mocks |

📝 Description
In this PR I propose a new package @metamask/x402 that implements ERC-7710 payment utilities for both client and server.
By moving this into a separate package, rather than exposing it via a package level export such as
@metamask/smart-accounts-kit/x402, we don't add the x402 dependencies for every@metamask/smart-accounts-kitconsumer.In the client, where the
x402Erc7710Clientis instantiated, adelegationProvideris specified. Ideally, the caller would be able to instantiate aDelegationProviderfrom the smart accounts kit that would abstract most of this complexity away, but I haven't implemented that layer yet. I would love to be able to do something like this:And the
RedelegatingProviderwould create a delegation specific to thePaymentRequirementsredelegating the authority fromparentPermissionContext.Note
Medium Risk
Mostly additive, but it introduces a new workspace package plus new
@x402/*/transitive dependencies (e.g., newerviem,zod) viayarn.lock, which could impact monorepo installs/builds if dependency resolution changes.Overview
Adds a new workspace package,
@metamask/smart-accounts-kit-x402, providing x402 adapters for ERC-7710: a client (x402Erc7710Client) that builds delegation-based payment payloads (with validation/normalization and optional fallback handling), a server helper (x402Erc7710Server) that injectsassetTransferMethod: "erc7710"and validates/normalizesfacilitatorAddresses, and anExactEvmSchemewrapper (x402ExactEvmErc7710ServerScheme) that conditionally applies the ERC-7710 enhancements.Wires up package scaffolding (README, dual-license files, tsup/tsconfig, eslint naming exceptions for
x402*, Vitest coverage tests) and updates.github/CODEOWNERSandyarn.lockto include the new workspace and its dependencies.Reviewed by Cursor Bugbot for commit f3a5070. Bugbot is set up for automated code reviews on this repo. Configure here.