Commit ef48273
authored
feat: improve chomp upgrade process (#9387)
# PR: GET-first address association for the Money Account upgrade flow
**Repos:** MetaMask/core → metamask-mobile (adoption to follow)
**Packages:** `@metamask/chomp-api-service` (breaking → 4.0.0),
`@metamask/money-account-upgrade-controller` (breaking → 3.0.0)
## Explanation
The `associate-address` step of the Money Account upgrade flow currently
signs a
`CHOMP Authentication` message and POSTs it to `/v1/auth/address` on
every run,
relying on the response to discover that the address was already
associated. That
means a keyring signing operation happens even when there is nothing to
do.
This PR makes the step check first and sign only when needed:
- **`@metamask/chomp-api-service`**: adds `getAssociatedAddresses()`
(`GET /v1/auth/address`), which returns the authenticated profile's
active
address associations. Results are parsed into canonical form (lowercased
addresses, `status` guaranteed `'active'`) and are never served from
cache,
since the response is scoped to the authenticated profile and consumers
use it
to decide whether to sign.
- **`@metamask/money-account-upgrade-controller`**: the
`associate-address` step
now calls the new action first and reports `already-done` — without
touching
the keyring — when the address is already associated. The lookup is an
optimization: if it fails, the step falls through to the previous
sign-and-submit behaviour.
While verifying the endpoint's semantics against the CHOMP API source, I
found
that the existing 409 handling was wrong. CHOMP returns
**201 + `status: 'active'`** when the address is already associated with
the
authenticated profile; a **409** means the address is associated with a
*different* profile (or, rarely, that two same-profile requests raced on
the
initial create). The old code treated 409 as a success case and tried to
parse
its error body as an association result, which would have failed with a
confusing validation error. Now:
- `associateAddress` throws an `HttpError` on any non-OK response
(**breaking**).
- The step disambiguates a 409 by re-fetching the associations: a
same-profile
race resolves to `already-done`; a genuine cross-profile conflict fails
the
step with a clear error.
The controller change is **breaking** because
`MoneyAccountUpgradeControllerMessenger`
consumers must now grant `ChompApiService:getAssociatedAddresses` and
pair it
with `@metamask/chomp-api-service` >= 4.0.0.
## References
<!-- Add issue/consumer-PR links here — mobile adoption PR to follow -->
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Breaking API and messenger contract changes affect all Chomp
`associateAddress` callers and upgrade-controller integrators; behavior
touches authenticated profile–address binding and upgrade flow failure
modes.
>
> **Overview**
> Adds **`getAssociatedAddresses`** (`GET /v1/auth/address`) to
`@metamask/chomp-api-service`, with messenger action
`ChompApiService:getAssociatedAddresses`, **`ProfileAddressEntry`**
typing, lowercase address parsing, and **no durable cache**
(profile-scoped query key via SHA-256 of the bearer token so tokens are
not exposed in cache events).
>
> **Breaking:** **`associateAddress`** now **throws `HttpError` on 409**
instead of treating it as success; same-profile “already associated”
remains **201 + `status: 'active'`**.
>
> The **`associate-address`** upgrade step calls the GET first and
returns **`already-done` without keyring signing** when the address is
already linked; lookup failures still fall through to sign-and-submit.
On POST **409**, it **re-fetches associations** to distinguish a benign
same-profile race from a real cross-profile conflict.
>
> **Breaking for consumers:** `MoneyAccountUpgradeController` must
delegate **`ChompApiService:getAssociatedAddresses`** and use
**`@metamask/chomp-api-service` >= 4.0.0**.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cba10e0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 1a36bb6 commit ef48273
11 files changed
Lines changed: 536 additions & 34 deletions
File tree
- packages
- chomp-api-service
- src
- money-account-upgrade-controller
- src
- steps
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
| 19 | + | |
| 20 | + | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
| |||
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
22 | 44 | | |
23 | 45 | | |
24 | 46 | | |
| |||
120 | 142 | | |
121 | 143 | | |
122 | 144 | | |
| 145 | + | |
123 | 146 | | |
124 | 147 | | |
125 | 148 | | |
| |||
Lines changed: 192 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
| |||
84 | 96 | | |
85 | 97 | | |
86 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
87 | 270 | | |
88 | 271 | | |
89 | 272 | | |
| |||
663 | 846 | | |
664 | 847 | | |
665 | 848 | | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
666 | 852 | | |
667 | 853 | | |
668 | 854 | | |
669 | 855 | | |
| 856 | + | |
670 | 857 | | |
671 | 858 | | |
| 859 | + | |
672 | 860 | | |
673 | 861 | | |
674 | 862 | | |
| |||
677 | 865 | | |
678 | 866 | | |
679 | 867 | | |
680 | | - | |
| 868 | + | |
681 | 869 | | |
682 | 870 | | |
683 | 871 | | |
| |||
0 commit comments