src/me/sources.ts exports the Me package's sources, merged into the dispatcher in app.ts (The data module). src/me/logic.ts holds the parts with "No clock, no randomness" so they can be tested alone.
Reply shape
Most mutations answer MeReply: {ok, error, value}. ok(value) and refuse(error) build the two cases. A refusal is a normal answer, not a thrown error, so the screen can show the message.
Sources
Source | Arguments | Answer |
|---|---|---|
none |
| |
|
| |
|
| |
none |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Creating and importing
meCreateIdentity re-checks the phrase and refuses anything that is not a valid mnemonic with The recovery phrase is not valid. meImportIdentity branches on the check: a key file goes through parseSeedKey and keeps the file's createTime when present; a phrase goes through addFromMnemonic.
addFromMnemonic awaits keyPairFromMnemonicAsync, which yields during PBKDF2 for the 100 ms turn budget. The uniqueness check then runs after the derivation, in keepIdentity: "the check and save then execute in one synchronous turn", so two concurrent imports cannot both take one name. keepIdentity calls nameError and saveKey from Identity and turns an IdentityStorageError into its display message; any other failure becomes Could not save this identity.
Re-importing an identity already on the device succeeds and changes nothing, because saveKey is idempotent per account.
Removing
meRemoveIdentity calls removeKey, which leaves the {removed: true} marker the vault needs. The reply's value keeps current when it still exists and was not the one removed; otherwise it is the oldest remaining identity, or '' when none is left.
Network reads
fetchJson(url, ms) passes exactTimeout to fetch. The comment explains: "Source timers only run after native fetch settles. Give the transport the deadline so an unresponsive server cannot leave this source pending."
Call | Timeout | Use |
|---|---|---|
| 8,000 ms |
|
| 10,000 ms |
|
Both endpoints are described in Seed site read API.
logic.ts
normalizeWords(text): lowercase, split on whitespace and commas, strip non-letters, drop empties.
checkImport(text): the live check behind the import field.
Input | Result |
|---|---|
empty |
|
starts with |
|
unknown words |
|
not 12 or 24 words |
|
bad checksum |
|
valid |
|
parseServerUrl(input): trims, prepends https:// when there is no scheme, accepts only http: and https:, rejects user names and passwords, and keeps only the origin. Errors: Enter a server address. and Invalid URL. Enter a valid server address.
hostOf(url): the host name, or the input when it does not parse.
readAccount(server, body): reads {name, icon} from an Account response, unwrapping the superjson json envelope. An ipfs:// icon becomes {server}/hm/api/image/{cid}?size=S; an https:// icon is kept; anything else is dropped. account-not-found yields empty strings.
Tests
sources.test.ts, 6 tests: name trimming and uniqueness, idempotent re-import, concurrent imports racing for one name, key-file text refused by create, the next-current rule on removal, and the two exactTimeout values (10000 and 8000).
logic.test.ts, 11 tests: six for checkImport, three for parseServerUrl (including credentials and non-hierarchical schemes), two for readAccount.
Both are part of the Bun unit tests.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime