fix(accounts): restore persisted id in AndroidNativeAccount.fromJSON#87
Merged
Conversation
`AndroidNativeAccount.fromJSON` creates a new account but never restores the
persisted `id`, so every reload mints a fresh `nanoid(8)`. This breaks the
serialize/restore round-trip: a caller that persists the active account's id
(e.g. `localStorage['active'] = account.id` → `manager.setActive(storedId)` on
startup) hits `getAccount()` miss → `throw new Error("Cant find account with
that ID")` because the rehydrated account's id no longer matches the stored one.
In practice this means a native Android signer (Amber / NIP-55) login cannot
survive an app restart — the app throws during restore and blank-screens.
It's the only account type that omits the restore: every sibling
(`ReadonlyAccount`, `PrivateKeyAccount`, `ExtensionAccount`, `NostrConnectAccount`,
`PasswordAccount`, `AmberClipboardAccount`, `SerialPortAccount`) calls
`super.loadCommonFields(account, json)`. This mirrors that pattern.
**Repro:** create an `AndroidNativeAccount` via `fromApp()`, persist with
`toJSON()` + `manager.setActive(account.id)`, reload, call
`manager.fromJSON(json)` + `manager.setActive(storedId)` → throws.
**Fix:** 2-line change matching the sibling idiom.
🦋 Changeset detectedLatest commit: 4441639 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Allow AndroidNativeSigner to receive an existing pubkey via constructor, avoiding a redundant call to NostrSignerPlugin.getPublicKey on connect. This improves performance when restoring accounts from serialized state.
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.
AndroidNativeAccount.fromJSONcreates a new account but never restores thepersisted
id, so every reload mints a freshnanoid(8). This breaks theserialize/restore round-trip: a caller that persists the active account's id
(e.g.
localStorage['active'] = account.id→manager.setActive(storedId)onstartup) hits
getAccount()miss →throw new Error("Cant find account with that ID")because the rehydrated account's id no longer matches the stored one.In practice this means a native Android signer (Amber / NIP-55) login cannot
survive an app restart — the app throws during restore and blank-screens.
It's the only account type that omits the restore: every sibling
(
ReadonlyAccount,PrivateKeyAccount,ExtensionAccount,NostrConnectAccount,PasswordAccount,AmberClipboardAccount,SerialPortAccount) callssuper.loadCommonFields(account, json). This mirrors that pattern.Repro: create an
AndroidNativeAccountviafromApp(), persist withtoJSON()+manager.setActive(account.id), reload, callmanager.fromJSON(json)+manager.setActive(storedId)→ throws.Fix: 2-line change matching the sibling idiom.