@bsv/expo-wallet-toolbox 0.4.0 → 0.5.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.
- package/CHANGELOG.md +292 -0
- package/README.md +0 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/config.tsx +9 -1
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +409 -20
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +3368 -952
- package/core/index.ts +97 -14
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/externalOrigin.ts +39 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/storage/StorageExpoSQLite.ts +382 -56
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +0 -54
- package/core/storage/methods/listOutputsSql.ts +7 -3
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +263 -6
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +123 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +112 -1
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +25 -24
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
- package/ui/components/pay/RecipientField.tsx +49 -4
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/UniversalSend.tsx +534 -30
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +101 -17
- package/ui/components/wallet/AmountInput.tsx +77 -25
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +303 -0
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +50 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +130 -10
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +38 -16
- package/ui/screens/WalletHomeScreen.tsx +417 -86
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +79 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Vault domain types — shared by the
|
|
3
|
-
*
|
|
2
|
+
* Vault domain types — shared by the store, the ceremony controller, the
|
|
3
|
+
* transfers and the UI. No React, no I/O.
|
|
4
|
+
*
|
|
5
|
+
* There is no sealed private YubiKey material or seed-derived spending
|
|
6
|
+
* authority: the enrolled YubiKeys are the spending keys. The wallet root
|
|
7
|
+
* derives deterministic HMAC salts from the ordered serial list.
|
|
8
|
+
* Each output carries its salt in the locking script; customInstructions
|
|
9
|
+
* mirror it for indexed discovery and are accepted only after exact script and
|
|
10
|
+
* salt-derivation verification.
|
|
4
11
|
*/
|
|
5
12
|
|
|
6
|
-
/** Persisted seal: everything needed to recover the vault key EXCEPT the
|
|
7
|
-
* on-token ECDH. The blob alone is useless without the physical YubiKey. */
|
|
8
|
-
export interface SealedBlob {
|
|
9
|
-
v: 1
|
|
10
|
-
/** PIV slot holding the P-256 key (0x82, first "retired" slot). */
|
|
11
|
-
slot: number
|
|
12
|
-
/** Ephemeral P-256 public key, hex, 65-byte uncompressed SEC1 point. */
|
|
13
|
-
ePub: string
|
|
14
|
-
/** HKDF salt, hex, 32 bytes. */
|
|
15
|
-
salt: string
|
|
16
|
-
/** AES-256-GCM ciphertext of the vault key (SymmetricKey wire format), hex. */
|
|
17
|
-
c: string
|
|
18
|
-
/** Serial of the enrolled YubiKey — ceremony rejects other keys early. */
|
|
19
|
-
yubiSerial: string
|
|
20
|
-
/** sha256 of the token public key, hex — sanity check against slot rewrites. */
|
|
21
|
-
yubiPubSha256: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
13
|
export type VaultErrorCode =
|
|
25
14
|
| 'unsupported-platform'
|
|
26
15
|
| 'no-key'
|
|
@@ -28,19 +17,27 @@ export type VaultErrorCode =
|
|
|
28
17
|
| 'pin-required'
|
|
29
18
|
| 'pin-invalid'
|
|
30
19
|
| 'pin-locked'
|
|
20
|
+
| 'puk-invalid'
|
|
21
|
+
| 'puk-locked'
|
|
31
22
|
| 'touch-timeout'
|
|
32
23
|
| 'key-removed-mid-op'
|
|
24
|
+
/** Another transfer still owns the single process-wide hardware signer. */
|
|
25
|
+
| 'ceremony-active'
|
|
26
|
+
/** Wallet or chain changed while a scoped vault operation was in flight. */
|
|
27
|
+
| 'scope-changed'
|
|
33
28
|
| 'mgmt-key-custom'
|
|
29
|
+
/** Factory F9 or generated-slot manufacturer attestation was missing,
|
|
30
|
+
* malformed, mismatched, or outside the pinned Yubico production chains. */
|
|
31
|
+
| 'attestation-invalid'
|
|
34
32
|
| 'slot-occupied'
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* reclassify to 'nfc-lost'. */
|
|
33
|
+
/** A slot key exists, but management-key rotation did not confirm. The
|
|
34
|
+
* attached VaultEnrollmentPartialError record can be challenged/recovered;
|
|
35
|
+
* it must never be silently persisted as enrolled. */
|
|
36
|
+
| 'enrollment-partial'
|
|
37
|
+
/** A vault key digest, DER signature, pubkey or script failed a structural
|
|
38
|
+
* check (r1comb.ts throws it for malformed SEC1 points, DER, or a lock that
|
|
39
|
+
* is not an R1C lock). Distinct from 'wrong-key', which vaultErrorFromNative
|
|
40
|
+
* may reclassify to 'nfc-lost'. */
|
|
44
41
|
| 'template-invalid'
|
|
45
42
|
| 'serial-mismatch'
|
|
46
43
|
| 'user-cancelled'
|
|
@@ -51,16 +48,6 @@ export type VaultErrorCode =
|
|
|
51
48
|
| 'below-dust'
|
|
52
49
|
| 'no-transaction'
|
|
53
50
|
| 'nfc-lost'
|
|
54
|
-
/** Vault passphrase missing or empty — an empty one would collide with the
|
|
55
|
-
* main wallet's master key. */
|
|
56
|
-
| 'bad-passphrase'
|
|
57
|
-
/** Main wallet recovery phrase failed BIP39 validation. */
|
|
58
|
-
| 'bad-mnemonic'
|
|
59
|
-
/** Deposit index outside the non-hardened BIP32 range. */
|
|
60
|
-
| 'bad-derivation-index'
|
|
61
|
-
/** No backup attestation for this wallet — depositing would create funds
|
|
62
|
-
* with no recovery path. Advisory gate, not a security control. */
|
|
63
|
-
| 'backup-required'
|
|
64
51
|
/** More vault inputs would be needed than one transaction may safely carry.
|
|
65
52
|
* See VAULT_MAX_INPUTS — the remedy is a smaller withdrawal, which also
|
|
66
53
|
* consolidates the vault. */
|
|
@@ -68,17 +55,68 @@ export type VaultErrorCode =
|
|
|
68
55
|
/** The device is offline. Vault transfers never enter the offline queue — see
|
|
69
56
|
* VaultTransferOptions.isOnline. */
|
|
70
57
|
| 'requires-online'
|
|
58
|
+
// ── R1C (1-of-N comb vault) ──────────────────────────────────────────────
|
|
59
|
+
/** `vaultEnabled` is off in this build (spec §0 / D15): no enrollment,
|
|
60
|
+
* deposit, re-vault or re-lock may create a vault output. */
|
|
61
|
+
| 'not-released'
|
|
62
|
+
/** The wallet is on `test` or `teratest` and the vault is mainnet-only
|
|
63
|
+
* (task 11). Deliberately distinct from 'not-released': the copy that code
|
|
64
|
+
* maps to tells the user the BUILD is off, which is false here and would
|
|
65
|
+
* hide the one thing they can act on — switching network. */
|
|
66
|
+
| 'not-on-mainnet'
|
|
67
|
+
/** No private backup service is configured, or encrypted backup push is
|
|
68
|
+
* opted out. New Vault outputs retain recovery metadata in that backup. */
|
|
69
|
+
| 'backup-off'
|
|
70
|
+
/** Fewer than VAULT_MIN_KEYS keys — defensive; the wizard cannot persist it. */
|
|
71
|
+
| 'not-enough-keys'
|
|
72
|
+
/** The tapped serial is already in meta.keys or in the wizard's pending list.
|
|
73
|
+
* The message carries the serial. */
|
|
74
|
+
| 'key-already-enrolled'
|
|
75
|
+
/** Restored metadata exists, but this serial has not yet passed the fresh
|
|
76
|
+
* possession challenge on this device. */
|
|
77
|
+
| 'key-not-adopted'
|
|
78
|
+
/** VAULT_MAX_KEYS keys already enrolled. */
|
|
79
|
+
| 'too-many-keys'
|
|
80
|
+
/** Removing this key would leave fewer than VAULT_MIN_KEYS. */
|
|
81
|
+
| 'last-keys'
|
|
82
|
+
/** Removing this key would orphan an output only it can open — re-lock first.
|
|
83
|
+
* Strictly that meaning: a re-lock is the remedy the copy names, so a
|
|
84
|
+
* refusal that a re-lock cannot clear belongs on 'action-pending'. */
|
|
85
|
+
| 'relock-required'
|
|
86
|
+
/** An unfinished vault transaction is in the way — a signed but unbroadcast
|
|
87
|
+
* deposit still reserving its inputs, a pending or failed action holding a
|
|
88
|
+
* vault output, or a deposit whose state cannot be classified. Unlike
|
|
89
|
+
* 'relock-required' a re-lock is NOT the remedy (and is itself refused):
|
|
90
|
+
* the transaction has to settle, or be reconciled, first. */
|
|
91
|
+
| 'action-pending'
|
|
92
|
+
/** The chosen key is not among the commitments baked into an output's real
|
|
93
|
+
* lock (or no reachable output exists). The message names the outpoint. */
|
|
94
|
+
| 'key-not-committed'
|
|
95
|
+
/** The chosen key can open less than the requested amount while other keys
|
|
96
|
+
* could open more. */
|
|
97
|
+
| 'key-cannot-cover'
|
|
98
|
+
/** acc − feeEstimate < VAULT_DEPOSIT_MIN: nothing worth re-locking. */
|
|
99
|
+
| 'too-small-to-relock'
|
|
100
|
+
/** The signable transaction is not consensus-bound version 1 — refused
|
|
101
|
+
* before any signature. */
|
|
102
|
+
| 'bad-version'
|
|
71
103
|
|
|
72
104
|
export class VaultError extends Error {
|
|
73
105
|
code: VaultErrorCode
|
|
74
106
|
/** PIN attempts remaining, present on pin-invalid. */
|
|
75
107
|
retriesLeft?: number
|
|
108
|
+
/** Structured context for the specific failure — e.g. serial-mismatch's
|
|
109
|
+
* { tapped, chosen } or key-cannot-cover's { reachable, total } (see the
|
|
110
|
+
* Interfaces note above for the full convention). Additive: most codes
|
|
111
|
+
* leave it undefined, and no existing call site needs to change. */
|
|
112
|
+
details?: Record<string, string | number>
|
|
76
113
|
|
|
77
|
-
constructor(code: VaultErrorCode, message?: string, retriesLeft?: number) {
|
|
114
|
+
constructor(code: VaultErrorCode, message?: string, retriesLeft?: number, details?: Record<string, string | number>) {
|
|
78
115
|
super(message ?? code)
|
|
79
116
|
this.name = 'VaultError'
|
|
80
117
|
this.code = code
|
|
81
118
|
this.retriesLeft = retriesLeft
|
|
119
|
+
this.details = details
|
|
82
120
|
}
|
|
83
121
|
}
|
|
84
122
|
|
|
@@ -89,11 +127,30 @@ export class VaultError extends Error {
|
|
|
89
127
|
* description it doesn't specifically recognize, which includes this one. */
|
|
90
128
|
const NFC_LOST_PATTERN = /tag response error|no response|tag connection lost|session invalidated/i
|
|
91
129
|
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
130
|
+
/**
|
|
131
|
+
* Parse a native-module rejection (`VAULT_ERR:<code>:<detail>`) into a
|
|
132
|
+
* VaultError; anything unrecognized becomes a generic driver failure.
|
|
133
|
+
*
|
|
134
|
+
* The payload is SEARCHED for, not anchored to the start of the message. iOS
|
|
135
|
+
* rejects with an NSError, and what reaches JS is that error's `description`,
|
|
136
|
+
* not its `localizedDescription` — so the real payload arrives wrapped:
|
|
137
|
+
*
|
|
138
|
+
* Error Domain=YubiKeyPiv Code=1 "VAULT_ERR:attestation-invalid:…" UserInfo={…}
|
|
139
|
+
*
|
|
140
|
+
* An anchored `^VAULT_ERR:` never matched that, so EVERY iOS native vault error
|
|
141
|
+
* — wrong PIN, blocked PIN, occupied slot, failed attestation — collapsed into
|
|
142
|
+
* `driver-unavailable`, whose copy reads "YubiKey support is unavailable on
|
|
143
|
+
* this device." That told the user their phone lacked NFC when the real answer
|
|
144
|
+
* was on the card. Android is unaffected: it rejects with a bare string, which
|
|
145
|
+
* this still matches.
|
|
146
|
+
*
|
|
147
|
+
* The detail stops at a double quote so the NSError's trailing ` UserInfo={…}`
|
|
148
|
+
* does not get absorbed into it; an unwrapped Android message has no quote and
|
|
149
|
+
* runs to the end as before.
|
|
150
|
+
*/
|
|
94
151
|
export function vaultErrorFromNative(e: unknown): VaultError {
|
|
95
152
|
const msg = e instanceof Error ? e.message : String(e)
|
|
96
|
-
const m =
|
|
153
|
+
const m = /VAULT_ERR:([a-z-]+):?([^"]*)/.exec(msg)
|
|
97
154
|
if (m) {
|
|
98
155
|
let code = m[1] as VaultErrorCode
|
|
99
156
|
const detailMatch = /retries=(\d+)/.exec(m[2])
|