Repository navigation
Conversation
Signed-off-by: lwin <lwin.kyaw@consensys.net>
🛑 Files requiring codeowner reviewTo merge this PR, you'll need to get approvals from the following owners. @MetaMask/web3auth (14 files)
ℹ️ Files co-owned by
|
The mismatch repair migrates every secret to v2, so the changelog no longer says a v1 backup is rewritten as v1. Co-authored-by: Cursor <cursoragent@cursor.com>
…zero-arg function The metadata-service fake's fetch method takes the SDK parameters, so it cannot be the implementation of the service's parameterless fetch callback. Co-authored-by: Cursor <cursoragent@cursor.com>
| }, | ||
| }); | ||
| this.#primarySrpBackupRepair = new PrimarySrpBackupRepair({ | ||
| this.#primarySrpBackupRepairService = new PrimarySrpBackupRepairService({ |
There was a problem hiding this comment.
Same vault-cache concern as #11748 (still on this stack)
#planRepair still calls fetchAllSecretData, which reads #cachedDecryptedVaultData as DeserializedVaultData outside withRepairContext (constructor options just below).
#pendingRun fixes same-client overlap, but not “cache cleared / locked mid-plan.” Can planning re-unlock (or share the write-path vault resolution) before fetch + export?
|
|
||
| const toprfClient = this.#getToprfClient(); | ||
|
|
||
| if (retag.length === 1) { |
There was a problem hiding this comment.
Partial failure window: demoted primary, no new primary
If step 1 (retag / demote) succeeds and step 2 (promote/add, ~L337–355) fails, the remote backup has no PrimarySrp until the next unlock repairs it as Missing.
That’s worse than mismatch for any cross-device restore in that window.
The design doc calls this out — thanks. A few asks:
- Immediate in-process retry of step 2 before giving up?
- Distinct analytics for
retag_ok_primary_write_failed? - Any client guidance if restore is attempted in that window?
| this.#assertIsUnlocked(); | ||
|
|
||
| await this.#primarySrpBackupRepair.run(password); | ||
| await this.#primarySrpBackupRepairService.run(password); |
There was a problem hiding this comment.
Public method name vs behavior
identifyIncompleteMetadataBackup now identifies and repairs (awaits run(), which writes). Clients may still treat this as telemetry-only.
Options:
- Rename / add an explicit
repairPrimarySrpBackupand keep identify read-only, or - Document this as an intentional breaking behavior change in the changelog and ping mobile/extension callers.
I’d lean toward a clear repair API so “identify” stays non-mutating.
|
|
||
| const retag: PrimarySrpRepairWrites['retag'] = []; | ||
| for (const secret of secretMetadata) { | ||
| if (secret === localCopy || !secret.itemId) { |
There was a problem hiding this comment.
Rows without itemId are skipped on retag
if (secret === localCopy || !secret.itemId) {
continue;
}If the current remote primary (or another primary candidate) has no itemId, we never demote it, then step 2 add (~L350) can fail forever with “Only one PRIMARY_SRP.”
Can we log/count these, fail the plan explicitly, or otherwise surface “unrepairable without itemId” instead of silently no-opping the demotion?
| await this.#withRepairContext( | ||
| async ({ toprfEncryptionKey, toprfAuthKeyPair }) => { | ||
| // The identity may have changed since the repair was planned. | ||
| assertIdentityUnchanged(this.#getIdentity(), expectedIdentity); |
There was a problem hiding this comment.
Under the write lock we only assert identity, not that the plan is still valid
Between #planRepair and #repairPrimarySrpBackup, another client can change metadata. promote especially can target a stale itemId.
Suggestion: under withRepairContext, cheap re-check (or re-plan) before retag/promote — e.g. confirm mismatch/missing still holds and primary.itemId still exists when promoting.
…eat/seedless-repair-mismatch-primary-srp-backup Keep the repair service test in place of the removed repair test, and await the vault callback so the return-await lint stays fixed. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort 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 1b17f33. Configure here.
| itemId: secret.itemId, | ||
| dataType: EncAccountDataType.ImportedPrivateKey, | ||
| }); | ||
| } |
There was a problem hiding this comment.
Repair retags password-backup rows
Medium Severity
#getWrites retags every primary candidate and every untagged non-candidate, including PW_BACKUP and unknown-type rows. getDataTypeMigrationUpdates skips those items. A PW_BACKUP row tagged PrimarySrp sorts first, so a healthy backup is planned as a mismatch and those rows are rewritten as imported secrets.
Reviewed by Cursor Bugbot for commit 1b17f33. Configure here.
…epair run Co-authored-by: Cursor <cursoragent@cursor.com>
…eat/seedless-repair-mismatch-primary-srp-backup


Explanation
#11748 writes a missing primary SRP and only reports a mismatch. A mismatch leaves the wrong mnemonic as the remote primary, so a restore on another device rehydrates the wrong wallet. That PR also keeps a v1 backup on the legacy schema.
This PR repairs both a missing and a mismatched primary SRP in
PrimarySrpBackupRepairService. The service is still internal to the controller. One run plans from a single remote fetch and a single local export, emits the analytics event, then writes in two steps:ImportedSrp, which demotes the old primary. An untagged private key becomesImportedPrivateKey. Items that are already imported are left alone. An update stores the item as v2 and does not change the encrypted data.PrimarySrp, or add the local primary SRP as a new v2PrimarySrpitem when there is no copy.The two steps cannot be one request. The metadata service rejects a new
PrimarySrpwhile anotherPrimarySrprow is stored, and that check ignores a demotion in the same batch. Seemetadata-servicesrc/routes/encAccountData.ts.submitPassworddoes not await the repair, so a fast second unlock can start another run. Runs for the same user share one in-memory pending promise, so the second call does not fetch or write again. A different user gets a new run, and the first run aborts if the identity changed. No controller state is added.A failed retag writes nothing. A failed primary write leaves the backup with no primary SRP, and the next unlock repairs that as a missing primary. There is no public API change.
The behaviour is described in
docs/seedless-onboarding-remediation-implementation-design.md.References
Checklist
Note
Medium Risk
Changes which mnemonic is labeled
PrimarySrpin remote backups (wallet restore), though writes are best-effort, identity-guarded, and heavily tested with no public API surface change.Overview
Extends post-unlock primary SRP backup remediation so it fixes mismatches as well as missing primaries, not just telemetry for mismatches.
PrimarySrpBackupRepairis replaced byPrimarySrpBackupRepairService, wired fromsubmitPasswordandidentifyIncompleteMetadataBackup.When the remote primary does not match the local one, repair runs in two metadata steps: retag every other secret as imported (demotes the wrong primary and upgrades legacy items to v2 without re-encrypting), then promote the remote copy of the local SRP to
PrimarySrpor add it as a new v2 item. Concurrent runs for the same user share one in-flight promise; identity changes abort the write.Planning moves from exported
planPrimarySrpRepairinto the service; changelog and a new remediation design doc describe the flow and edge cases.Reviewed by Cursor Bugbot for commit 54d4bc7. Bugbot is set up for automated code reviews on this repo. Configure here.