Repository navigation
Conversation
|
|
|
@claude review this PR for correctness, code quality, and implementation. Flag any regressions and give an approval score |
|
Claude finished @s84krish's task in 41s —— View job Review of PR #10098: safes BYOK backup root supportApproval score: 8/10. I'd approve once the points below are addressed or acknowledged. I read the full source diff: sdk-core, sdk-lib-safes, key-card and express. I skimmed the tests and did not run them, so the unit suites and CI status are unverified on my side. What looks good
Issues and risks
Minor
Regression assessmentNo regression found for existing safes or keycards:
The main regression risk is the |
There was a problem hiding this comment.
🔴 A typo in one slot's BYOK key can burn a valid backup xpub supplied for the other slot. The safe is archived after that xpub is already registered. prepareExternalBackupPub runs inside each slot's ceremony, after initializeSafe. createSafeKeys starts all ceremonies in parallel (Promise.allSettled, safes.ts:267). Fix: validate and prepare every supplied multisigRoots entry (isValidPub, ed25519 StrKey/derivable format) in externalBackupSlotsOf/generateSafe before initialize and before any ceremony starts, using coinForRoot per slot. [also at: modules/sdk-core/src/bitgo/safe/safes.ts:160 - A malformed backupXpub is only caught after the safe is initialized and the other root ceremonies have run. Callers are left with an archived safe and orphaned keys.]
Why this was flagged
A caller passes a valid multisigRoots.secp256k1Multisig.backupXpub and a malformed multisigRoots.ed25519Multisig.backupXpub to generateSafe. externalBackupSlotsOf (safes.ts:65) only checks that each value is a non-empty string, so initializeSafe creates the safe. createSafeKeys (safes.ts:267) runs both multisig ceremonies at once. The ed25519 ceremony rejects in prepareExternalBackupPub (safes.ts:747). Meanwhile the secp256k1 ceremony calls keychains.add({ pub, source: 'backup', safeId }) (safes.ts:912) with the caller's xpub. The safe is then archived. The PR states that wallet platform rejects a pub already used as a safe root. If archived safes still hold that claim, the caller cannot retry with their own backup key and must make a new one. The comment at safes.ts:157, 'Validate before initialize so a bad option never leaves a half-created safe behind', does not hold for key-format errors. The base branch had no caller-supplied keys, so nothing like this could happen.
Verification: Trigger: a caller passes a valid slot-① backupXpub together with a malformed slot-④ backupXpub to generateSafe. externalBackupSlotsOf (safes.ts:65-85) only checks that each backupXpub is a non-empty string. It never checks the key format. createSafeKeys starts every ceremony at once (safes.ts:267). Because there is a failure, safes.ts:287-302 then archives the safe and throws.
There was a problem hiding this comment.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🔴
modules/sdk-core/src/bitgo/safe/keycard.ts— Callers can no longer rebuild a keycard for a BYOK safe: every buildSafeKeycardRoots call throwsuser/backup root is missing encryptedPrv.buildMultisigSlotstill requiresbackupKeychain.encryptedPrv, but this PR registers external backups as pub-only keys. Fix: inbuildMultisigSlot, treat a backup keychain that haspuband noencryptedPrvas external and pass it through untouched. Check the keycard passphrase against another envelope, or skip the check when no backup envelope exists. Keep throwing when a local backup is missing its envelope. [also at: modules/sdk-core/src/bitgo/safe/safes.ts:373 - Callers who build a keycard for a BYOK safe get a hard error, so a safe with a caller-supplied backup root can never get a keycard.]Why this was flagged
After this PR,
createMultisigRoot(modules/sdk-core/src/bitgo/safe/safes.ts:373) registers the external backup withkeychains.add({ pub, source: 'backup', safeId, enterprise }). That keychain has noencryptedPrv. The keycard flow isSafe.claimKeycardMaterial(safe.ts:510), thenbuildSafeKeycardRoots(keycard.ts:288), thenbuildMultisigSlot. That function throws at keycard.ts:137-139 wheneverbackupKeychain.encryptedPrvis falsy, so any safe with amultisigRootsslot cannot produce keycard roots. The new{kind:'external'}path in key-card'sselectBackupRootEntryis never reached from this documented flow. The same error happens if the triplets returned bygenerateSafeare passed throughbuildSafeKeycardRoots. Safes created on the base branch are not affected, because every multisig backup there came fromcreateBackupwith an encrypted prv.Verification: After this PR,
createMultisigRootin modules/sdk-core/src/bitgo/safe/safes.ts no longer callscreateBackup, so the backup keychain has noencryptedPrv.buildMultisigSlot, unchanged by this PR, throwssafe ${slot} user/backup root is missing encryptedPrv(keycard.ts:137-139). The regeneration flow is therefore always unavailable for BYOK safes.
| const backupKeychainPromise: Promise<Keychain> = | ||
| externalBackupPub === undefined | ||
| ? keychains.createBackup({ passphrase, safeId, originalPasscodeEncryptionCode: passcodeEncryptionCode }) | ||
| : keychains.add({ pub: externalBackupPub, source: 'backup', safeId, enterprise }); |
There was a problem hiding this comment.
🔴 BYOK callers can lose their backup xpub when any unrelated ceremony fails, and the error then tells them to retry with a new safe, which fails. The external backup is registered alongside the other ceremonies (Promise.allSettled, line 267). Any rejection, such as a transient DKLS/EdDSA MPC error or the slot's own user or BitGo key add, archives the safe with the xpub already bound to it. Fix: register the caller's backup pub only after every other ceremony and the slot's own user/BitGo keys succeed. For BYOK safes, also change the "create a new safe and retry" text (lines 298, 153).
Why this was flagged
Trigger: a caller runs generateSafe or Express handleV2GenerateSafe with multisigRoots.secp256k1Multisig.backupXpub while all four slots are enabled. createSafeKeys starts all ceremonies at once (safes.ts:267). createMultisigRoot posts keychains.add({ pub: externalBackupPub, source: 'backup', safeId, enterprise }) (safes.ts:373) in parallel with the MPC ceremonies (createMpcRoot) and with the slot's own keychains.add user key and createBitGo calls. If any of those rejects, the failure branch at safes.ts:287-302 archives the safe. The caller is then told the safe "has been archived; create a new safe and retry." The PR says wallet platform rejects a pub already used as a safe root, so retrying with the same slot-① xpub fails. On the base branch a failed run only throws away locally generated keys, so retrying always works. Checking multisigRoots before initialize, as the filed candidates propose, does not help here: the failing ceremony is unrelated to the BYOK input.
Verification: safes.ts:267 starts every enabled ceremony at once. The caller's pub is posted at line 373 alongside the user key add (363) and createBitGo (374). Lines 287-302 then archive the safe and throw "The safe (...) has been archived; create a new safe and retry." The base code only generated a fresh backup key each run (createBackup), so a retry always worked there.
|
@claude re-review checking if all feedback has been addressed |
|
Claude finished @s84krish's task in 29s —— View job Re-review: feedback statusI read the current code in Addressed in the code (HEAD
Still open
Summary: all three 🔴 blockers and the main smaller items are fixed. Only the |
Ticket: WCN-3880
Lets a caller create a safe whose multisig backup root is a public key they supply — the same way
backupXpubworks forWallets.generateWallet. The SDK never generates, encrypts,or sees the caller's backup private key. Covers the
secp256k1Multisig(①) anded25519Multisig(④) slots; MPC slots are rejected.sdk-core): newCreateSafeOptions.multisigRootskeyed by slot ({ backupXpub });generateSafe/initializeSafederive and sendexternalBackupSlots;createSafeKeysvalidates the supplied slots against the server declaration and archives the safe on mismatch;createMultisigRootregisters the caller's pub viakeychains.add({ source: 'backup' })instead of generating one. ① validates withcoin.isValidPub; ④ accepts an ed25519 StrKey and converts it to the derivable composite format.sdk-lib-safesgains an additive box-B entry{ kind: 'external', pub }(older cards still decode);key-cardrenders external slots as public-key-only in Box B, reading the declared slots from safe data.decryptSafeKeycardreturns external roots without decrypting; backup children derive from the public root (relative soft paths, so non-master HSM xpubs work); signed① recovery accepts the caller's
externalBackupRootPrv; ④ holders sign through the existingExternalEd25519Signer.multisigRootsforwarded through thegenerateSafe/generateSafeKeystyped routes, withgenerateSafeKeyschecking declared external slots against the supplied keys.Testing: unit coverage for create/keycard/recovery/express paths (multisig-root registration, StrKey conversion, malformed-key rejection, old-card decode round-trip, depth-3 xpub
child derivation, signed recovery with external prv). Existing safes and keycards are unaffected. Note: a backup xpub can back exactly one safe — wallet platform rejects a pub already
used as a safe root.