feat: add derivable ed25519 root pub encode/decode helpers - #9592
Open
davidkaplanbitgo wants to merge 1 commit into
Open
feat: add derivable ed25519 root pub encode/decode helpers#9592davidkaplanbitgo wants to merge 1 commit into
davidkaplanbitgo wants to merge 1 commit into
Conversation
Safe slot-4 (ed25519Multisig) root pubs are Stellar StrKeys, which have nowhere to carry the chain code that soft-deriving co-signer keys needs. Per TDD Part II-3 1.3 the chain code is concatenated onto pub: <56-char StrKey 'G...'> || <64 lowercase hex chain code> The 56-char split offset is a cross-repo contract shared with wallet-platform, modules/key-card and WRW, so every call site must go through these helpers rather than slicing inline. StrKey validation is implemented inline (base32 + version byte + CRC16-XModem) because sdk-core must not depend on a coin module. Tests assert against a fixture copied byte-identical from the wallet-platform implementation. TICKET: WCN-2485
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WCN-2485 · TDD Part II-3 §1.3
What
Safe slot-④ (
ed25519Multisig) root pubs are Stellar StrKeys — a bare 32-byte ed25519 point with nowhere to carry the chain code that soft-deriving the backup and BitGo co-signer keys requires. Per the TDD, the chain code is concatenated ontopubrather than added as a new field, mirroring the xpub for slot ① andcommonKeychainfor slots ②③:Adds
encodeDerivableEd25519Pub/decodeDerivableEd25519Pubtomodules/sdk-coreundersrc/bitgo/safe/, exported from the module's public surface somodules/key-cardcan import them. Also exportsisDerivableEd25519Pub,isValidEd25519ChainCode,isValidEd25519StrKeyPublicKey, and theDERIVABLE_ED25519_*constants.The 56-char split offset is a cross-repo contract shared with wallet-platform,
modules/key-cardand WRW.slice(56)is not hardcoded anywhere else — every call site goes through these helpers.Additive only. No existing behaviour changes.
Shared fixture
test/unit/bitgo/safe/fixtures/derivableEd25519Pub.jsonis copied byte-identical from the wallet-platform implementation (BitGo/bitgo-microservices#62429) and verified as such. Four independent implementations of this split will otherwise drift, and the failure mode is an unrecoverable wallet.Note on StrKey validation
sdk-corehas nostellar-sdkdependency and shouldn't take one on a coin module, so theG…half is validated inline: base32 decode → version byte0x30→ CRC16-XModem checksum. It agrees with wallet-platform'sStrKey.isValidEd25519PublicKeyon every fixture vector, including the bad-checksum, secret-seed, and halves-swapped cases. Happy to swap for a real dependency if reviewers prefer.There is no
assertDerivableEd25519Pubhere — that signature is wallet-platform-only (it takes anAbstractCoinand throwsapiErrors.Invalid, neither of which exists insdk-core).isDerivableEd25519Pub(composite)covers the equivalent need.Testing
47 tests, all driven off the shared fixture — round-trip, and rejection of a bare 56-char pub, non-hex suffix, uppercase and mixed-case hex, wrong total length, empty string, bad StrKey checksum, secret seed, and swapped halves. All pass.
tsc --noEmitandeslintare clean for the changed files. Onetsconfig.jsonline lists the fixture JSON, same pattern assdk-coin-dot.Heads up: the
sdk-corebarrel currently throws on import in my checkout (redpallasMPCv2KeyGenSender.tsbuilds an io-ts union from@bitgo/public-typesmembers the installed version doesn't export) — pre-existing on master, the untouchedtest/unit/bitgo/safe/safe.tsfails identically. Looks like stalesdk-lib-mpc/public-typesdists. To run the suite locally I pointed the import at the module path directly; the committed test imports from'../../../../src'per convention.Out of scope
createBackup,createMultisigRoot, and the keycard changes — WCN-2488 and WCN-2490, both blocked on this.