…stSpendPermission
When capabilities are provided, requestSpendPermission sends
mutableData: { fields: ['message.account'] }, allowing the wallet to
substitute account with a smart-wallet address. permissionHash is already
derived from the wallet-returned (post-substitution) message, but the
returned permission object used the original pre-substitution
typedData.message, so result.permission.account and result.permissionHash
described different permissions.
Hoist the returned message into permissionMessage, set from
signResult.signedData.message in the wallet_sign branch and from
typedData.message in the eth_signTypedData_v4 branch, so permission and
permissionHash stay consistent. Adds a test where the wallet substitutes
account with a different address; it fails before this change and passes
after.
Summary
requestSpendPermissionsendsmutableData: { fields: ['message.account'] }whencapabilitiesare provided, so the wallet may substituteaccountwith a smart-wallet address.permissionHashis already derived from the wallet-returned (post-substitution) message, but the returnedpermissionobject used the original pre-substitutiontypedData.message. As a resultresult.permission.accountandresult.permissionHashdescribed different permissions, and any consumer readingresult.permission.account(display, storage,prepareSpendCallData,fetchPermissions) saw the wrong account.This hoists the returned message into a
permissionMessagevariable, set fromsignResult.signedData.messagein thewallet_signbranch and fromtypedData.messagein theeth_signTypedData_v4branch, sopermissionandpermissionHashstay consistent. Theeth_signTypedData_v4path is unchanged in behavior.Fixes #324.
How did you test your changes?
Added a unit test in
requestSpendPermission.test.tswhere the wallet returnssignedData.message.accountset to a different address than the request; it assertsresult.permissionmatches the post-substitution message. The test fails on the current code (returns the original account) and passes with this change.requestSpendPermission.test.ts: 17 passed (the new test fails without the fix)spend-permissionsuite: 9 files, 137 tests passingtsc --noEmit: no new type errors from this change