@bsv/expo-wallet-toolbox 0.11.8 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/core/backup/erase.ts +7 -1
  3. package/core/backup/preference.ts +12 -4
  4. package/core/backup/push.ts +8 -1
  5. package/core/backup/status.ts +6 -2
  6. package/core/config.tsx +1 -1
  7. package/core/context/WalletContext.tsx +904 -184
  8. package/core/i18n/translations.tsx +496 -12
  9. package/core/identity/handleRegistry/registration.ts +57 -3
  10. package/core/index.ts +26 -1
  11. package/core/mandala/createRuntime.ts +3 -3
  12. package/core/mandala/runtime.ts +7 -2
  13. package/core/mnemonicWallet.ts +46 -40
  14. package/core/monitor/MonitorSupervisor.ts +35 -1
  15. package/core/monitor/TaskCreditInbox.ts +24 -0
  16. package/core/pay/beefRepair.ts +8 -3
  17. package/core/pay/rails/address.ts +43 -3
  18. package/core/pay/rails/handle.ts +5 -3
  19. package/core/pay/sweeper.ts +39 -4
  20. package/core/peerpay/outbox.ts +11 -1
  21. package/core/profiles/assertProfileEmpty.ts +287 -0
  22. package/core/profiles/discovery.ts +84 -0
  23. package/core/profiles/profileLabel.ts +13 -0
  24. package/core/profiles/profileStore.ts +265 -0
  25. package/core/profiles/purgeProfile.ts +76 -0
  26. package/core/profiles/removeProfile.ts +257 -0
  27. package/core/push/events.ts +189 -0
  28. package/core/push/identities.ts +55 -0
  29. package/core/push/profilePush.ts +143 -0
  30. package/core/push/pushAdvisory.ts +33 -0
  31. package/core/push/registration.ts +391 -0
  32. package/core/push/types.ts +35 -0
  33. package/core/services/arcTokenStorage.ts +17 -2
  34. package/core/services/vault/transfers.ts +6 -1
  35. package/core/services/vault/vaultStore.ts +16 -3
  36. package/core/stores/ConnectionStore.ts +11 -7
  37. package/core/toolboxConfig.ts +31 -4
  38. package/core/userAvatar.ts +12 -5
  39. package/core/walletDbRegistry.ts +73 -0
  40. package/package.json +1 -1
  41. package/ui/backupShares.ts +2 -3
  42. package/ui/components/pay/HandleReceive.tsx +141 -16
  43. package/ui/components/pay/MessageBoxConfig.tsx +6 -5
  44. package/ui/components/pay/NotificationAdvisoryModal.tsx +124 -0
  45. package/ui/components/ui/PencilEditField.tsx +5 -2
  46. package/ui/components/wallet/Balance.tsx +3 -1
  47. package/ui/components/wallet/ProfileButton.tsx +92 -18
  48. package/ui/components/wallet/ProfileSwitcherPopover.tsx +247 -0
  49. package/ui/hooks/useOfflineNoticeActions.ts +2 -1
  50. package/ui/hooks/useSpendableBalance.ts +3 -1
  51. package/ui/index.ts +1 -0
  52. package/ui/printRecoveryShares.ts +6 -7
  53. package/ui/screens/PairScreen.tsx +2 -1
  54. package/ui/screens/PayScreen.tsx +53 -0
  55. package/ui/screens/ProfileScreen.tsx +195 -4
  56. package/ui/screens/SettingsScreen.tsx +80 -6
  57. package/ui/screens/VaultScreen.tsx +31 -2
  58. package/ui/screens/VaultTransferScreen.tsx +25 -2
  59. package/ui/screens/WalletCheckScreen.tsx +2 -1
  60. package/ui/screens/WalletConfigScreen.tsx +51 -21
  61. package/ui/screens/WalletHomeScreen.tsx +6 -3
  62. package/ui/tokenSeen.ts +13 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,164 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Breaking
6
+
7
+ - **The privileged key is no longer the BIP32 master.** A mnemonic wallet's
8
+ `PrivilegedKeyManager` now gets profile *n*'s own key at `m/1'/n'` (`m/1'/0'`
9
+ for the default profile) instead of the master key `m`, so no two profiles
10
+ share key material. Anything a host derived with `privileged: true` under an
11
+ existing wallet derives differently after upgrading. A recovered-key (WIF)
12
+ wallet is unchanged.
13
+ - `generateMnemonicWallet()` / `recoverMnemonicWallet()` no longer return
14
+ `rootKey`; they return `privilegedKey` (the `m/1'/n'` key) next to
15
+ `primaryKey` and `identityKey`, and `recoverMnemonicWallet` takes an optional
16
+ third argument, `profileIndex` (default 0).
17
+ - `isVaultAvailable(chain, profileIndex)` takes the active profile index; the
18
+ vault exists only on profile 0. Pass `useActiveProfileIndex()` (or
19
+ `useWallet().activeProfile`).
20
+ - Per-profile device state: for profile 1 and above, the AsyncStorage keys for
21
+ the balance cache, avatar, paired connections, ARC and MessageBox overrides,
22
+ auto-approve threshold and ledger, seen-token markers and the remote-backup
23
+ preference gain a `__p<n>` suffix (`profileScopedKey`). Profile 0 keeps the
24
+ existing keys, so a single-profile host sees no change.
25
+ - The push registration marker (`push_registration_v1`) now holds one entry per
26
+ registered identity, so an existing install registers once more after
27
+ upgrading.
28
+
29
+ - **Recovery shares print as one three-page job again (XR-110 reverted).**
30
+ `printRecoveryShares()` had sent each share as its own `Print.printAsync`
31
+ job. Users saw one dialog with one page and did not know two more would
32
+ follow (on Android the three dialogs stacked at once), so they kept only one
33
+ share. Every share is now a page of a single job, so the user gets one
34
+ dialog and, when saving, one PDF. The owner accepts the risk that a
35
+ retained print job holds the full 2-of-3 threshold: these sheets are
36
+ printed on home hardware the user controls. `generatePrintHTML()` keeps its
37
+ optional `only` parameter; the package no longer calls it.
38
+
39
+ ### Wallet profiles
40
+
41
+ One mnemonic now backs any number of independent wallet profiles, each with its
42
+ own identity key, balance, history, contacts, handle and network (the primary
43
+ key is `m/0'/n'` and the privileged key `m/1'/n'`). A recovered-key wallet has
44
+ no profiles. Switching profiles is a full wallet teardown and rebuild under a
45
+ full-screen cover.
46
+
47
+ - `useWallet()` gains `profiles`, `activeProfile`, `profilesSupported`,
48
+ `switchProfile(n)`, `addProfile()`, `switchingProfile`, `removingProfile`,
49
+ `checkProfileRemoval()` and `removeProfile()`.
50
+ - New exports: `getActiveProfile`, `getActiveProfileIndex`, `getProfilesState`,
51
+ `liveProfiles`, `profileScopedKey`, `subscribeProfiles`, `useActiveProfileIndex`,
52
+ `useProfiles`, `PROFILES_STORAGE_KEY`, `profileLabel`, `deriveProfileKeys`,
53
+ `hdFromMnemonic`, `profilePaths`, and the types `ProfileRecord`,
54
+ `ProfilesState`, `RemovalBlocker`, `ProfileRemovalCheck`, `RemoveProfileResult`
55
+ and `RemoveRefusal`.
56
+ - A profile can be given a private name (at most 24 characters, kept only on the
57
+ device); `profileLabel(record, t)` is the label to show, the name or
58
+ `profile<N>`. The remote-backup preference is now per profile.
59
+ - A profile can be removed once it is provably empty: no spendable output in any
60
+ basket, no unfinished transaction, queued payment or token settlement, nothing
61
+ waiting to be credited from either MessageBox box, and nothing in its databases
62
+ for any other network. Removing releases the profile's handle, switches to
63
+ profile 0, then tombstones the record (its index is never reused) and purges
64
+ its databases and keys; a purge that did not finish is repeated at every
65
+ startup. Profile 0 can never be removed.
66
+ - Push: every live profile registers the install's FCM token under its own
67
+ identity and at its own MessageBox host, and a tap on a push for another profile
68
+ switches to it. Removing a profile and Delete Wallet withdraw the registration
69
+ (`POST /unregisterDevice`, which needs a server with the multi-identity change;
70
+ an older server answers 404 and is tolerated). A withdrawal that did not get
71
+ through is retried at the next build.
72
+ - Delete Wallet erases every profile, tombstoned ones included.
73
+
74
+ ## 0.12.0
75
+
76
+ ### Payment push notifications
77
+
78
+ A payment to the user's MessageBox handle can now wake the phone, through a
79
+ push adapter the host supplies. The package never imports a push SDK (its
80
+ native module would have to be linked by every host that merely installs the
81
+ package); the host wraps whichever one it ships and passes it in:
82
+
83
+ ```ts
84
+ configureToolbox({ push: myPushAdapter })
85
+ ```
86
+
87
+ - New exports: `getPushAdapter` and the types `PushAdapter`, `PushPermission`
88
+ and `PushOpenedEvent`. A host that passes no adapter keeps every push
89
+ feature off (no registration, no advisory, no Settings row), and
90
+ `getPushAdapter()` returns `undefined` rather than throwing when the toolbox
91
+ is unconfigured.
92
+ - Members added to `PushAdapter` later will be optional, so an adapter written
93
+ against this version keeps compiling and working.
94
+ - Device registration: once the wallet is up, and again on foreground and on
95
+ token refresh, the FCM token is registered (`registerDevice`) with the
96
+ MessageBox host the inbox reads, bound to the identity the inbox reads for.
97
+ A cached marker of the last registered host, identity and token makes the
98
+ common case no network call at all. Nothing happens without an adapter or
99
+ without notification permission, and a failure is logged (the error message
100
+ only, never the token or identity key) and contained. A sync that hangs is
101
+ given up on after 30 s so it cannot block the ones after it.
102
+ - A tap on a payment notification opens Activity and runs an inbox pass. A push
103
+ that arrives while the app is in the foreground only triggers an inbox pass,
104
+ so the existing credit toast shows and no system banner does. A push never
105
+ credits anything itself.
106
+
107
+ ### Notification advisory and Settings row
108
+
109
+ - The first time the user picks Share remote link on Get paid, an in-app modal
110
+ (`NotificationAdvisoryModal`, new export) explains the OS prompt that
111
+ follows: it lets BSV Wallet tell them about a payment while the app is in the
112
+ background. Continue asks the OS; Not now does not. It is shown once, and
113
+ only while the permission is still undetermined.
114
+ - Settings has a Payment notifications row, On or Off. Pressing it turns
115
+ notifications on (the OS prompt) or, once the OS has been asked, opens the OS
116
+ settings. A denial is not forgotten when the screen re-reads the permission.
117
+ The advisory and the row appear only when the host passed a push adapter.
118
+
119
+ ### Receive screen: live payments
120
+
121
+ The Receive (handle) screen now listens for payments on a live MessageBox
122
+ connection and keeps polling as a fallback.
123
+
124
+ - While the connection is up, the satoshi inbox is re-read every 15 s and
125
+ immediately when a live payment arrives; the token inbox stays on its 5 s
126
+ tick. Without a live connection both poll every 5 s as before.
127
+ - Each listening session uses a fresh client. A `MessageBoxClient` remembers
128
+ the rooms it joined across a disconnect, so reusing one would reconnect the
129
+ socket without re-joining the room and slow the poll for nothing.
130
+ - The listener runs only while the screen is focused and the app is active.
131
+
132
+ ### Address payments: faster sweep
133
+
134
+ An address payment reaches no one, so there is nothing to push; the wallet
135
+ finds it by looking.
136
+
137
+ - The address sweep now runs every 5 s instead of every 30 s (foreground
138
+ only, as before).
139
+ - `WocConfig` gains an optional `apiKey`, and the new `wocRequestInit(woc)`
140
+ export turns it into the `woc-api-key` request header. The header is sent
141
+ only when a caller sets `apiKey`; the key is never logged. `wocConfigFor`
142
+ does not set it, so the address sweep, BEEF repair, recovery and the other
143
+ address-rail calls stay on WhatsOnChain's unauthenticated limit: the host's
144
+ app-wide key is shared with broadcast, and a 5 s poll across every install
145
+ would drain it.
146
+ - HTTP 429 from WhatsOnChain throws the new `WocRateLimited` error (exported
147
+ from the address rail), which stops the pass and makes the sweep sit out the
148
+ next 30 s instead of retrying on every tick.
149
+ - New sweeper exports: `SWEEP_BACKOFF_TICKS`, `consumeBackoff` and
150
+ `backoffAfterSweepError`.
151
+
152
+ ### Translations
153
+
154
+ New strings in all 12 locales: the advisory title, body and buttons, and the
155
+ Settings row and its On and Off values.
156
+
157
+ ### Default MessageBox host
158
+
159
+ - The default MessageBox host is now https://messagebox.bsvblockchain.tech
160
+ (was gmb.bsvblockchain.tech). A saved custom host is unchanged.
161
+
3
162
  ## 0.11.8
4
163
 
5
164
  ### Grouped permission prompt
@@ -36,6 +36,12 @@ export interface EraseDeps {
36
36
  /** Supply exactly one of these. */
37
37
  baseUrl?: string
38
38
  client?: BackupClient
39
+ /**
40
+ * The profile whose backup is erased: only ITS opt-out is written, so erasing one
41
+ * profile's server copy never turns off another profile's backup. Defaults to the
42
+ * active profile.
43
+ */
44
+ profileIndex?: number
39
45
  }
40
46
 
41
47
  export interface EraseResult {
@@ -47,7 +53,7 @@ export async function eraseRemoteBackup (deps: EraseDeps): Promise<EraseResult>
47
53
  const client = resolveClient(deps)
48
54
 
49
55
  // Step 1 — before anything is deleted. See the module doc.
50
- await setBackupPushEnabled(false)
56
+ await setBackupPushEnabled(false, deps.profileIndex)
51
57
 
52
58
  // Step 2 — throws on any server refusal, leaving the local cursors intact.
53
59
  const { deleted } = await client.deleteAccount()
@@ -10,24 +10,32 @@
10
10
  * The opt-out stops pushing only. Restoring on a new device still works: a log already on
11
11
  * the server stays readable, and `restoreOnImport` never consults this.
12
12
  *
13
+ * Per profile: each profile pushes to its own server account, so the flag goes through
14
+ * `profileScopedKey` (profile 0 keeps the bare key, profile n appends `__p<n>`). Opting one
15
+ * profile out, or erasing its server copy, must never silence another profile's backup.
16
+ * Callers that hold a specific profile's key pass its index; anything else means "what the
17
+ * user is looking at" and takes the active profile.
18
+ *
13
19
  * Not stored in wallet settings: those live in the wallet database, which is itself what
14
20
  * gets backed up, and the flag has to be readable by a push pass that runs before/without
15
21
  * the settings manager.
16
22
  */
17
23
  import AsyncStorage from '@react-native-async-storage/async-storage'
24
+ import { profileScopedKey } from '../profiles/profileStore'
18
25
 
26
+ /** Profile 0's key; other profiles append `__p<n>` (see `profileScopedKey`). */
19
27
  export const BACKUP_PUSH_ENABLED_KEY = 'backupPushEnabled'
20
28
 
21
29
  /** True unless the user has explicitly opted out. Never throws. */
22
- export async function isBackupPushEnabled (): Promise<boolean> {
30
+ export async function isBackupPushEnabled (profileIndex?: number): Promise<boolean> {
23
31
  try {
24
- return (await AsyncStorage.getItem(BACKUP_PUSH_ENABLED_KEY)) !== 'false'
32
+ return (await AsyncStorage.getItem(profileScopedKey(BACKUP_PUSH_ENABLED_KEY, profileIndex))) !== 'false'
25
33
  } catch {
26
34
  // Fail towards backing up. The alternative silently abandons the user's history.
27
35
  return true
28
36
  }
29
37
  }
30
38
 
31
- export async function setBackupPushEnabled (enabled: boolean): Promise<void> {
32
- await AsyncStorage.setItem(BACKUP_PUSH_ENABLED_KEY, enabled ? 'true' : 'false')
39
+ export async function setBackupPushEnabled (enabled: boolean, profileIndex?: number): Promise<void> {
40
+ await AsyncStorage.setItem(profileScopedKey(BACKUP_PUSH_ENABLED_KEY, profileIndex), enabled ? 'true' : 'false')
33
41
  }
@@ -51,6 +51,13 @@ export interface PushDeps {
51
51
  baseUrl?: string
52
52
  client?: BackupClient
53
53
  deviceId?: string
54
+ /**
55
+ * The profile this pass belongs to; its opt-out is the one consulted. Pass the index the
56
+ * wallet was built for, so a pass that outlives a profile switch still reads the
57
+ * departing profile's flag rather than whichever is active by then. Defaults to the
58
+ * active profile.
59
+ */
60
+ profileIndex?: number
54
61
  }
55
62
 
56
63
  export interface PushResult {
@@ -80,7 +87,7 @@ export async function pushOnce (deps: PushDeps): Promise<PushResult> {
80
87
  // data leaves this device, and the cheapest way to guarantee that is to do nothing at
81
88
  // all. The cursor is left untouched, so opting back in resumes from where the log
82
89
  // stopped instead of skipping everything written while it was off.
83
- if (!(await isBackupPushEnabled())) {
90
+ if (!(await isBackupPushEnabled(deps.profileIndex))) {
84
91
  return { pushed: 0, bytes: 0, windowClosed: false, rotated: false, optedOut: true }
85
92
  }
86
93
 
@@ -26,8 +26,12 @@ export type BackupUploadState = {
26
26
  uploaded: boolean
27
27
  }
28
28
 
29
- export async function getBackupUploadState(chain: BackupChain, pseudonym: string): Promise<BackupUploadState> {
30
- const enabled = await isBackupPushEnabled()
29
+ export async function getBackupUploadState(
30
+ chain: BackupChain,
31
+ pseudonym: string,
32
+ profileIndex?: number
33
+ ): Promise<BackupUploadState> {
34
+ const enabled = await isBackupPushEnabled(profileIndex)
31
35
  let uploaded = false
32
36
  try {
33
37
  const prefix = cursorKeyPrefix(chain, pseudonym)
package/core/config.tsx CHANGED
@@ -19,7 +19,7 @@ export function toWalletChain(chain: AppChain): WalletChain {
19
19
 
20
20
  export const DEFAULT_WAB_URL = 'noWAB'
21
21
  export const DEFAULT_STORAGE_URL = 'local'
22
- export const DEFAULT_MESSAGEBOX_URL = 'https://gmb.bsvblockchain.tech'
22
+ export const DEFAULT_MESSAGEBOX_URL = 'https://messagebox.bsvblockchain.tech'
23
23
  /**
24
24
  * Encrypted wallet-backup log.
25
25
  *