fix: refuse an unsupported method with EIP-1193 code 4200 (closes #279)
handleRpc() answered a method it does not implement with "Unsupported method: <method>" and no code, so a site probing for an optional method could not tell "not implemented" from "the call failed" and fall back. It now carries code 4200, which EIP-1193 defines for this case; the message is unchanged. The provider already passes any code through to the page. The new test hands the real background's reply to the provider and checks the page sees 4200. Model: opus-5-5
This commit was merged in pull request #421.
This commit is contained in:
@@ -932,7 +932,9 @@ async function handleRpc(method, params, origin) {
|
||||
}
|
||||
}
|
||||
|
||||
return { error: { message: "Unsupported method: " + method } };
|
||||
// EIP-1193 4200 lets a site tell "this wallet does not implement that"
|
||||
// from "that call failed", and fall back.
|
||||
return { error: { code: 4200, message: "Unsupported method: " + method } };
|
||||
}
|
||||
|
||||
// The body of eth_sendTransaction, from the connection check through to the
|
||||
|
||||
@@ -31,11 +31,12 @@
|
||||
// an error instead of accepting the refusal.
|
||||
//
|
||||
// Whatever code arrived is passed through verbatim rather than being
|
||||
// matched against a list: the extension emits 4001, 4100 and 4902 today,
|
||||
// and a code this file has never heard of is still the truth about what
|
||||
// happened. An error reported with no code at all stays a plain Error —
|
||||
// a ProviderRpcError whose `code` is undefined would advertise a
|
||||
// conformance it does not have. `message` is untouched in every case.
|
||||
// matched against a list: the extension emits codes such as 4001, 4100,
|
||||
// 4200 and 4902, and a code this file has never heard of is still the
|
||||
// truth about what happened. An error reported with no code at all stays
|
||||
// a plain Error — a ProviderRpcError whose `code` is undefined would
|
||||
// advertise a conformance it does not have. `message` is untouched in
|
||||
// every case.
|
||||
function toPageError(error) {
|
||||
const message = (error && error.message) || "Request failed";
|
||||
if (error && error.code !== undefined && error.code !== null) {
|
||||
|
||||
Reference in New Issue
Block a user