Security · Retrospective
Adding seed phrases to the TriveAsset SDK without stranding old addresses

Between 10 and 12 June I added seed-phrase support to the TriveAsset SDK, the JavaScript library we use to build, sign and send TriveAsset transactions on Trivechain. The new functions were the visible part. The more important change was a smaller commit the next day, which makes sure that twelve words restored through the new code can still reach the addresses people already hold.
What the SDK gained
Since late May the team has been building a second version of the SDK. The first version kept keys through our HD wallet library, which we open-sourced in March. The second is built on our core library, trivechaincore-lib.
My commits that week added three things:
- Mnemonic functions. From a twelve-word phrase, an account number and an index, the SDK returns an address, a one-key script (P2SH) address, or the private key behind them.
- Validation before derivation. The phrase must be twelve words, the account and index must be whole numbers within fixed bounds, and the network must be named as mainnet or testnet. Bad input is rejected before it reaches any key code.
- P2SH signing. Inputs held at one of those script addresses can now be signed with the matching redeem script.
Two paths from the same twelve words
A seed phrase is not a key. Under BIP39 the words become a seed, and under BIP32 that seed becomes a tree of keys. A derivation path says which branch to walk. Change the path and the same words produce different keys, different addresses and, from the holder's point of view, a different wallet.
Our HD wallet library follows the BIP44 layout, m/44'/0'/account'/0/index on mainnet. The new SDK functions walk m/44'/account'/index'/0/0. Both start from the same seed, and for the first address of the first account the two paths are identical. After that they part. Someone holding coins at their second address who restored through the new functions alone would see an empty balance.
Nothing would actually be lost. The coins stay where they are, and the key can still be derived by anyone who knows the old path. But "it can still be derived" is little comfort to someone looking at a zero.
Why backward compatibility is a security decision
So on 12 June I added the old derivation back: two functions that reproduce the first version's path and network settings, and return the old address and its private key. Both carry a DEPRECATED_ prefix, and the comment above them says they exist for the move from the first version to the second, and that callers should migrate as soon as possible because they will stop being supported.
It is tempting to treat this as a convenience. I think it is the opposite. A seed phrase is a backup, and a backup that restores to a different set of addresses has failed at its one job. Availability is part of security. When a restore comes up empty, some people go looking for recovery tools or ask strangers for help, and a few end up typing their twelve words into places they should not. The most sensitive thing a holder owns gets exposed because the software made a correct key look missing.
Keeping the old path also keeps the migration ordinary. If old addresses can be derived inside the same library, moving funds to a new-path address is a normal transaction. Without it, someone eventually writes a one-off script under pressure, and that is the worst moment to be handling private keys.
The naming matters too. Anyone calling a DEPRECATED_ function can see it is transitional. The right end state is that holders move to the new derivation and the old code is removed, not that two schemes live side by side indefinitely.
Failing loudly when a signature is missing
The next change I want to make, in the same spirit, is to the send function. It signs every input whose script matches one of the keys it is given. Before it builds the transaction, it should check each input and stop with an error naming the first unsigned one it finds, by transaction ID and output index. If a key is missing, I want the failure at the point where it can be identified, with the input named, rather than a vaguer error somewhere further along.
What a library cannot do
These functions take a seed phrase as an argument and return keys. They can check the input and derive the right addresses, old and new. They cannot decide where the calling application keeps the phrase, whether it writes it to a log, or whether it ever leaves the device. That responsibility belongs to whoever builds on the SDK, and the SDK's documentation should say so in plain words.