@bsv/expo-wallet-toolbox 0.12.0 → 0.14.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 (57) hide show
  1. package/CHANGELOG.md +118 -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/context/WalletContext.tsx +855 -238
  7. package/core/i18n/translations.tsx +376 -0
  8. package/core/identity/handleRegistry/registration.ts +57 -3
  9. package/core/index.ts +24 -1
  10. package/core/mandala/createRuntime.ts +3 -3
  11. package/core/mandala/runtime.ts +7 -2
  12. package/core/mnemonicWallet.ts +46 -40
  13. package/core/monitor/MonitorSupervisor.ts +35 -1
  14. package/core/monitor/TaskCreditInbox.ts +24 -0
  15. package/core/pay/rails/handle.ts +4 -2
  16. package/core/peerpay/outbox.ts +11 -1
  17. package/core/profiles/assertProfileEmpty.ts +287 -0
  18. package/core/profiles/discovery.ts +84 -0
  19. package/core/profiles/profileLabel.ts +13 -0
  20. package/core/profiles/profileStore.ts +265 -0
  21. package/core/profiles/purgeProfile.ts +76 -0
  22. package/core/profiles/removeProfile.ts +257 -0
  23. package/core/push/events.ts +52 -5
  24. package/core/push/identities.ts +55 -0
  25. package/core/push/profilePush.ts +143 -0
  26. package/core/push/registration.ts +362 -24
  27. package/core/push/types.ts +5 -1
  28. package/core/services/arcTokenStorage.ts +17 -2
  29. package/core/services/signingPermissionPolicy.ts +258 -0
  30. package/core/services/vault/guard.ts +55 -14
  31. package/core/services/vault/transfers.ts +6 -1
  32. package/core/services/vault/vaultStore.ts +16 -3
  33. package/core/stores/ConnectionStore.ts +11 -7
  34. package/core/toolboxConfig.ts +7 -3
  35. package/core/userAvatar.ts +12 -5
  36. package/core/walletDbRegistry.ts +73 -0
  37. package/package.json +1 -1
  38. package/ui/backupShares.ts +2 -3
  39. package/ui/components/pay/MessageBoxConfig.tsx +6 -5
  40. package/ui/components/ui/PencilEditField.tsx +5 -2
  41. package/ui/components/ui/PermissionSheet.tsx +15 -7
  42. package/ui/components/ui/protocolPrompt.ts +118 -0
  43. package/ui/components/wallet/Balance.tsx +3 -1
  44. package/ui/components/wallet/ProfileButton.tsx +92 -18
  45. package/ui/components/wallet/ProfileSwitcherPopover.tsx +247 -0
  46. package/ui/hooks/useOfflineNoticeActions.ts +2 -1
  47. package/ui/hooks/useSpendableBalance.ts +3 -1
  48. package/ui/printRecoveryShares.ts +6 -7
  49. package/ui/screens/PairScreen.tsx +2 -1
  50. package/ui/screens/ProfileScreen.tsx +195 -4
  51. package/ui/screens/SettingsScreen.tsx +8 -4
  52. package/ui/screens/VaultScreen.tsx +31 -2
  53. package/ui/screens/VaultTransferScreen.tsx +25 -2
  54. package/ui/screens/WalletCheckScreen.tsx +2 -1
  55. package/ui/screens/WalletConfigScreen.tsx +51 -21
  56. package/ui/screens/WalletHomeScreen.tsx +6 -3
  57. package/ui/tokenSeen.ts +13 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,123 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Fixed
6
+
7
+ - **External apps can sign under BRC-29 again.** The vault guard refused every
8
+ external `createSignature`, `encrypt`, `decrypt`, `createHmac`,
9
+ `verifyHmac`, `verifySignature` and key-linkage call under
10
+ `[2, '3241645161d8']` (XR-020), so payment apps that sign BRC-29 outputs
11
+ did not work. The namespace is no longer reserved. Because it also derives
12
+ this wallet's own address-rail keys, `seekProtocolPermissionsForSigning` is
13
+ now `true`: a connected app is asked before it first signs under a
14
+ security level 1 or 2 protocol (level 2 per counterparty), BRC-29
15
+ included. This differs from Metanet Desktop, which does not ask.
16
+ `[2, 'mandala token']` stays reserved, and privileged calls are still
17
+ refused. So are the address rail's own key IDs: a BRC-29 call from a
18
+ connected origin whose key ID is `base64(YYYY-MM-DD) + ' ' +
19
+ base64('legacy')` is refused for every key-using method and counterparty
20
+ (`isAddressRailKeyID`, exported from the vault guard).
21
+ - **BRC-29 signing asks every time.** An approval under `3241645161d8` is
22
+ never reused: each signature gets its own prompt, and one app's concurrent
23
+ calls are asked one at a time so a single tap cannot approve a batch. Each
24
+ approval is still recorded as a permission token, tagged
25
+ `keyid <hex of the key ID>` (or `keyidhash <sha256>` when too long), as a
26
+ history of what was approved; BRC-29 tokens, cache entries and the
27
+ recent-grant cover are never read back. BRC-29 entries in a site's
28
+ manifest `groupPermissions`/`counterpartyPermissions` are ignored, so the
29
+ grouped sheet never offers them and is not raised again before each
30
+ signature. A grant is keyed by origin, protocol and counterparty, never key
31
+ ID, so a reused one would cover the wallet's BSV address receipts and
32
+ change too. Each recorded approval is a 1-satoshi token output plus its
33
+ transaction fee.
34
+ - Signing under `[2, 'auth message signature']` (BRC-103 mutual auth and its
35
+ BRC-104 HTTP transport) is exempt from the prompt, so authenticated
36
+ requests never ask. Both rules live in `SigningPolicyPermissionsManager`
37
+ (`core/services/signingPermissionPolicy.ts`).
38
+ - A non-privileged `verifySignature` is never prompted: it reveals nothing
39
+ and spends nothing.
40
+ - The permission sheet no longer shows BRC-29 as `3241645161d8`. Its prompt
41
+ is titled "Payment Key Signature", says coins paid to the key (or the
42
+ wallet's change, for counterparty self) could be spent with the signature,
43
+ and its details name the protocol "Payments (BRC-29)" and show the key ID,
44
+ decoded from base64 when it is readable text. Other protocols are
45
+ unchanged.
46
+ - `getPublicKey`, `encrypt`, `decrypt`, HMAC and key-linkage calls under
47
+ BRC-29 with an app's key ID are not prompted (their `seek*` flags stay
48
+ off).
49
+
50
+ ## 0.13.0
51
+
52
+ ### Breaking
53
+
54
+ - **The privileged key is no longer the BIP32 master.** A mnemonic wallet's
55
+ `PrivilegedKeyManager` now gets profile *n*'s own key at `m/1'/n'` (`m/1'/0'`
56
+ for the default profile) instead of the master key `m`, so no two profiles
57
+ share key material. Anything a host derived with `privileged: true` under an
58
+ existing wallet derives differently after upgrading. A recovered-key (WIF)
59
+ wallet is unchanged.
60
+ - `generateMnemonicWallet()` / `recoverMnemonicWallet()` no longer return
61
+ `rootKey`; they return `privilegedKey` (the `m/1'/n'` key) next to
62
+ `primaryKey` and `identityKey`, and `recoverMnemonicWallet` takes an optional
63
+ third argument, `profileIndex` (default 0).
64
+ - `isVaultAvailable(chain, profileIndex)` takes the active profile index; the
65
+ vault exists only on profile 0. Pass `useActiveProfileIndex()` (or
66
+ `useWallet().activeProfile`).
67
+ - Per-profile device state: for profile 1 and above, the AsyncStorage keys for
68
+ the balance cache, avatar, paired connections, ARC and MessageBox overrides,
69
+ auto-approve threshold and ledger, seen-token markers and the remote-backup
70
+ preference gain a `__p<n>` suffix (`profileScopedKey`). Profile 0 keeps the
71
+ existing keys, so a single-profile host sees no change.
72
+ - The push registration marker (`push_registration_v1`) now holds one entry per
73
+ registered identity, so an existing install registers once more after
74
+ upgrading.
75
+
76
+ - **Recovery shares print as one three-page job again (XR-110 reverted).**
77
+ `printRecoveryShares()` had sent each share as its own `Print.printAsync`
78
+ job. Users saw one dialog with one page and did not know two more would
79
+ follow (on Android the three dialogs stacked at once), so they kept only one
80
+ share. Every share is now a page of a single job, so the user gets one
81
+ dialog and, when saving, one PDF. The owner accepts the risk that a
82
+ retained print job holds the full 2-of-3 threshold: these sheets are
83
+ printed on home hardware the user controls. `generatePrintHTML()` keeps its
84
+ optional `only` parameter; the package no longer calls it.
85
+
86
+ ### Wallet profiles
87
+
88
+ One mnemonic now backs any number of independent wallet profiles, each with its
89
+ own identity key, balance, history, contacts, handle and network (the primary
90
+ key is `m/0'/n'` and the privileged key `m/1'/n'`). A recovered-key wallet has
91
+ no profiles. Switching profiles is a full wallet teardown and rebuild under a
92
+ full-screen cover.
93
+
94
+ - `useWallet()` gains `profiles`, `activeProfile`, `profilesSupported`,
95
+ `switchProfile(n)`, `addProfile()`, `switchingProfile`, `removingProfile`,
96
+ `checkProfileRemoval()` and `removeProfile()`.
97
+ - New exports: `getActiveProfile`, `getActiveProfileIndex`, `getProfilesState`,
98
+ `liveProfiles`, `profileScopedKey`, `subscribeProfiles`, `useActiveProfileIndex`,
99
+ `useProfiles`, `PROFILES_STORAGE_KEY`, `profileLabel`, `deriveProfileKeys`,
100
+ `hdFromMnemonic`, `profilePaths`, and the types `ProfileRecord`,
101
+ `ProfilesState`, `RemovalBlocker`, `ProfileRemovalCheck`, `RemoveProfileResult`
102
+ and `RemoveRefusal`.
103
+ - A profile can be given a private name (at most 24 characters, kept only on the
104
+ device); `profileLabel(record, t)` is the label to show, the name or
105
+ `profile<N>`. The remote-backup preference is now per profile.
106
+ - A profile can be removed once it is provably empty: no spendable output in any
107
+ basket, no unfinished transaction, queued payment or token settlement, nothing
108
+ waiting to be credited from either MessageBox box, and nothing in its databases
109
+ for any other network. Removing releases the profile's handle, switches to
110
+ profile 0, then tombstones the record (its index is never reused) and purges
111
+ its databases and keys; a purge that did not finish is repeated at every
112
+ startup. Profile 0 can never be removed.
113
+ - Push: every live profile registers the install's FCM token under its own
114
+ identity and at its own MessageBox host, and a tap on a push for another profile
115
+ switches to it. Removing a profile and Delete Wallet withdraw the registration
116
+ (`POST /unregisterDevice`, which needs a server with the multi-identity change;
117
+ an older server answers 404 and is tolerated). A withdrawal that did not get
118
+ through is retried at the next build.
119
+ - Delete Wallet erases every profile, tombstoned ones included.
120
+
3
121
  ## 0.12.0
4
122
 
5
123
  ### Payment push notifications
@@ -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)