docs: add browser dApp guide for levelPrivateStateProvider with canary password verification#1126
Open
pplmaverick wants to merge 1 commit into
Open
docs: add browser dApp guide for levelPrivateStateProvider with canary password verification#1126pplmaverick wants to merge 1 commit into
pplmaverick wants to merge 1 commit into
Conversation
…y password verification Signed-off-by: pplmaverick <95532618+pplmaverick@users.noreply.github.com>
|
@pplmaverick is attempting to deploy a commit to the Midnight Foundation Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Adds a browser usage guide for
levelPrivateStateProvider, covering:cryptoBackendauto-detection works in browser environmentsresetStorage()for production UXMotivation
Browser compatibility was added in midnight-js #827, but no documentation or example
exists showing how to use
levelPrivateStateProviderin a browser dApp.Additionally, the SDK's internal
verifyPassword()only performs an in-memory cacheconsistency check — it does not validate the password against stored encrypted data.
On first unlock (or after page reload), there is no password verification at all.
A wrong password causes an AES-GCM auth tag failure deep inside a later operation,
producing an opaque WebCrypto
OperationErrorinstead of a clear message at unlock time.The canary pattern below provides fail-fast password validation at unlock time.
Proposed content
Using levelPrivateStateProvider in browser dApps
Canary pattern for early password validation
Without a canary, a wrong password isn't caught until the app attempts to decrypt
real private state data. AES-GCM auth tag verification then throws an opaque
OperationErrordeep inside a transaction flow rather than at unlock time.A canary value written on first unlock lets you catch this at the earliest possible
point with a meaningful error message:
Resetting private state
No built-in reset method exists in the official
PrivateStateProviderinterface.If you need to clear all private state for an account (e.g. after a failed unlock),
implement a
resetStorage()method in your provider wrapper that clears theunderlying storage for that
accountId.Tested in
@midnight-ntwrk/midnight-js-level-private-state-provider@4.1.1