MPP.Methods.USDC (mpp v0.19.0)

Copy Markdown View Source

usdc charge method for direct Circle USDC.

v00 implements the EVM EIP-3009 profile and the Solana legacy-SPL profile from draft-usdc-charge-00. methodDetails.type selects the profile, and exactly one nested profile object is accepted. Stacks and Gateway register in profiles/0 without changing the EVM or Solana modules.

Configuration

plug MPP.Plug,
  secret_key: "hmac-secret",
  realm: "api.example.com",
  method: MPP.Methods.USDC,
  amount: "1000000",
  currency: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
  recipient: "0xrecipient",
  method_config: %{
    "profile" => "evm",
    "rpc_url" => "https://ethereum-sepolia-rpc.publicnode.com",
    "chain_id" => 11_155_111,
    "private_key" => "0x..."
  }

Solana uses "profile" => "solana", "network" (mainnet or devnet), and the Circle USDC mint as currency. Set "fee_payer" => true with "fee_payer_private_key" and "fee_payer_key" when the server pays the Solana fee.

Server config stays out of the challenge. The advertised methodDetails are the nested profile object from the draft.

API Functions

FunctionArityDescriptionParam Kinds
challenge_method_details1Return the nested USDC methodDetails for the configured profile.charge: value
verify2Verify a USDC credential for the selected direct profile.payload: value, charge: value
validate_config!1Validate USDC method_config. Requires profile plus that profile's keys.config: value
profiles0Return implemented USDC profile modules keyed by methodDetails.type.-
credential_types0Return the USDC payload types: authorization and transaction.-
method_name0Return the payment method identifier for USDC.-

Summary

Functions

Return the nested USDC methodDetails for the configured profile.

Return the USDC payload types: authorization and transaction.

Return the payment method identifier for USDC.

Return implemented USDC profile modules keyed by methodDetails.type.

Validate USDC method_config. Requires profile plus that profile's keys.

Verify a USDC credential for the selected direct profile.

Functions

challenge_method_details(charge)

@spec challenge_method_details(MPP.Method.intent()) :: map() | nil
@spec challenge_method_details(MPP.Method.intent()) :: map() | nil

Return the nested USDC methodDetails for the configured profile.

Parameters

  • charge - Charge carrying server method_config in method_details (value)

Returns

Public methodDetails with type and exactly one profile object (map)

# descripex:contract
%{
  params: %{
    charge: %{
      description: "Charge carrying server method_config in method_details",
      kind: :value
    }
  },
  returns: %{
    type: :map,
    description: "Public methodDetails with type and exactly one profile object"
  }
}

credential_types()

@spec credential_types() :: [String.t()]
@spec credential_types() :: [String.t()]

Return the USDC payload types: authorization and transaction.

# descripex:contract
%{}

method_name()

@spec method_name() :: String.t()

Return the payment method identifier for USDC.

# descripex:contract
%{}

profiles()

@spec profiles() :: %{optional(String.t()) => module()}

Return implemented USDC profile modules keyed by methodDetails.type.

# descripex:contract
%{}

validate_config!(config)

@spec validate_config!(map()) :: :ok
@spec validate_config!(map()) :: :ok

Validate USDC method_config. Requires profile plus that profile's keys.

Parameters

  • config - method_config map, including profile (value)

Returns

:ok, or raises ArgumentError (atom)

# descripex:contract
%{
  params: %{
    config: %{description: "method_config map, including profile", kind: :value}
  },
  returns: %{type: :atom, description: "`:ok`, or raises ArgumentError"}
}

verify(payload, charge)

@spec verify(map(), MPP.Method.intent()) ::
  {:ok, MPP.Receipt.t()} | {:error, MPP.Errors.t()}

Verify a USDC credential for the selected direct profile.

Parameters

  • payload - Credential payload map for the active profile (value)
  • charge - Charge whose method_details select the USDC profile (value)

Returns

{:ok, receipt} or {:error, error} (tagged_tuple)

Errors

  • :invalid_payload
  • :verification_failed
# descripex:contract
%{
  params: %{
    payload: %{
      description: "Credential payload map for the active profile",
      kind: :value
    },
    charge: %{
      description: "Charge whose method_details select the USDC profile",
      kind: :value
    }
  },
  errors: [:invalid_payload, :verification_failed],
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, receipt}` or `{:error, error}`"
  }
}