@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault sealing crypto — pure functions, no I/O, no logging.
|
|
3
|
+
*
|
|
4
|
+
* Scheme (`bsvb-vault-seal-v1`, the age-plugin-yubikey / systemd-cryptenroll
|
|
5
|
+
* PKCS#11 pattern):
|
|
6
|
+
*
|
|
7
|
+
* seal : ephemeral P-256 keypair e/E; S = ECDH(e, yubiPub);
|
|
8
|
+
* KEK = HKDF-SHA256(S, salt, info); C = AES-256-GCM(KEK, V)
|
|
9
|
+
* unseal : S = on-token ECDH(slot, E) ← the touch-gated step;
|
|
10
|
+
* KEK = HKDF(S, salt, info); V = AES-GCM-decrypt(KEK, C)
|
|
11
|
+
*
|
|
12
|
+
* The token returns the 32-byte x-coordinate of the shared point (PIV
|
|
13
|
+
* KeyAgreement semantics); softwareEcdh mirrors that exactly so both sides
|
|
14
|
+
* derive the same KEK.
|
|
15
|
+
*
|
|
16
|
+
* SECURITY: never log inputs or outputs of these functions.
|
|
17
|
+
*/
|
|
18
|
+
import { p256 } from '@noble/curves/nist.js'
|
|
19
|
+
import { Hash, SymmetricKey, Utils } from '@bsv/sdk'
|
|
20
|
+
import { SealedBlob, VaultError } from './types'
|
|
21
|
+
import { randomBytes } from './random'
|
|
22
|
+
import { hkdfSha256 } from '../secrets/hkdf'
|
|
23
|
+
|
|
24
|
+
export const SEAL_INFO = 'bsvb-vault-seal-v1'
|
|
25
|
+
|
|
26
|
+
/** ECDH over P-256 returning the hex x-coordinate (32 bytes) — the same value
|
|
27
|
+
* a YubiKey's PIV KeyAgreement operation produces. */
|
|
28
|
+
export function softwareEcdh(privHex: string, pubHex: string): string {
|
|
29
|
+
const priv = Uint8Array.from(Utils.toArray(privHex, 'hex'))
|
|
30
|
+
const pub = Uint8Array.from(Utils.toArray(pubHex, 'hex'))
|
|
31
|
+
const shared = p256.getSharedSecret(priv, pub, false) // 65B uncompressed point
|
|
32
|
+
return Utils.toHex(Array.from(shared.slice(1, 33)))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Generate a fresh ephemeral P-256 scalar from our own entropy source
|
|
36
|
+
* (avoids depending on a WebCrypto global under React Native). */
|
|
37
|
+
function ephemeralKeypair(): { privHex: string; pubHex: string } {
|
|
38
|
+
// Rejection-sample until the scalar is valid for the curve (overwhelmingly
|
|
39
|
+
// first-try; the loop is belt-and-braces).
|
|
40
|
+
for (;;) {
|
|
41
|
+
const candidate = Uint8Array.from(randomBytes(32))
|
|
42
|
+
try {
|
|
43
|
+
const pub = p256.getPublicKey(candidate, false)
|
|
44
|
+
return { privHex: Utils.toHex(Array.from(candidate)), pubHex: Utils.toHex(Array.from(pub)) }
|
|
45
|
+
} catch {
|
|
46
|
+
// invalid scalar (zero or >= order) — draw again
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Seal the vault key V to a YubiKey's PIV public key. Software-only —
|
|
52
|
+
* requires no token present, so re-sealing and enrollment never need touch. */
|
|
53
|
+
export function sealVaultKey(
|
|
54
|
+
v: number[],
|
|
55
|
+
yubiPubHex: string,
|
|
56
|
+
meta: { slot: number; serial: string }
|
|
57
|
+
): SealedBlob {
|
|
58
|
+
const { privHex: ePriv, pubHex: ePub } = ephemeralKeypair()
|
|
59
|
+
const salt = randomBytes(32)
|
|
60
|
+
const shared = softwareEcdh(ePriv, yubiPubHex)
|
|
61
|
+
const kek = hkdfSha256(Utils.toArray(shared, 'hex'), salt, SEAL_INFO)
|
|
62
|
+
const c = new SymmetricKey(kek).encrypt(v) as number[]
|
|
63
|
+
return {
|
|
64
|
+
v: 1,
|
|
65
|
+
slot: meta.slot,
|
|
66
|
+
ePub,
|
|
67
|
+
salt: Utils.toHex(salt),
|
|
68
|
+
c: Utils.toHex(c),
|
|
69
|
+
yubiSerial: meta.serial,
|
|
70
|
+
yubiPubSha256: Utils.toHex(Hash.sha256(Utils.toArray(yubiPubHex, 'hex')))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Recover V from a seal given the token-computed shared secret (hex
|
|
75
|
+
* x-coordinate from the ceremony's ECDH). Throws `seal-corrupt` on any
|
|
76
|
+
* mismatch — wrong secret, tampered ciphertext, malformed blob. */
|
|
77
|
+
export function unsealVaultKey(blob: SealedBlob, sharedSecretHex: string): number[] {
|
|
78
|
+
try {
|
|
79
|
+
const kek = hkdfSha256(Utils.toArray(sharedSecretHex, 'hex'), Utils.toArray(blob.salt, 'hex'), SEAL_INFO)
|
|
80
|
+
return new SymmetricKey(kek).decrypt(Utils.toArray(blob.c, 'hex')) as number[]
|
|
81
|
+
} catch {
|
|
82
|
+
throw new VaultError('seal-corrupt', 'Vault seal could not be opened')
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run a block of token operations against a live key connection, hiding the
|
|
3
|
+
* transport difference:
|
|
4
|
+
*
|
|
5
|
+
* - **session-based (iOS NFC):** the scan sheet is a system modal that covers
|
|
6
|
+
* the app, so you cannot collect a PIN while it is up. Callers MUST gather all
|
|
7
|
+
* user input (PIN, new PIN, nickname) BEFORE calling this; then this opens the
|
|
8
|
+
* NFC session, waits for the tap to connect, runs every token op in that one
|
|
9
|
+
* tap, and always closes the session afterwards (dismissing the sheet).
|
|
10
|
+
* - **persistent (Android USB / mock):** the key is already on the reader, so
|
|
11
|
+
* `work` runs immediately; the reader's lifecycle is left untouched
|
|
12
|
+
* (WalletContext owns it for relock-on-unplug).
|
|
13
|
+
*
|
|
14
|
+
* `onWaiting` fires when we begin waiting for the tap, so the UI can prompt
|
|
15
|
+
* "hold your key to the top of your phone".
|
|
16
|
+
*/
|
|
17
|
+
import { VaultDriver } from './driver'
|
|
18
|
+
|
|
19
|
+
interface Deferred<T> {
|
|
20
|
+
promise: Promise<T>
|
|
21
|
+
resolve: (v: T) => void
|
|
22
|
+
reject: (e: unknown) => void
|
|
23
|
+
}
|
|
24
|
+
function defer<T>(): Deferred<T> {
|
|
25
|
+
let resolve!: (v: T) => void
|
|
26
|
+
let reject!: (e: unknown) => void
|
|
27
|
+
const promise = new Promise<T>((res, rej) => {
|
|
28
|
+
resolve = res
|
|
29
|
+
reject = rej
|
|
30
|
+
})
|
|
31
|
+
return { promise, resolve, reject }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function withKeySession<T>(
|
|
35
|
+
driver: VaultDriver,
|
|
36
|
+
work: () => Promise<T>,
|
|
37
|
+
onWaiting?: () => void
|
|
38
|
+
): Promise<T> {
|
|
39
|
+
if (!driver.sessionBased) {
|
|
40
|
+
return work()
|
|
41
|
+
}
|
|
42
|
+
const connected = defer<void>()
|
|
43
|
+
const off = driver.onKeyEvent(e => {
|
|
44
|
+
if (e.type === 'attached') connected.resolve()
|
|
45
|
+
})
|
|
46
|
+
onWaiting?.()
|
|
47
|
+
driver.start()
|
|
48
|
+
try {
|
|
49
|
+
await connected.promise
|
|
50
|
+
return await work()
|
|
51
|
+
} finally {
|
|
52
|
+
off()
|
|
53
|
+
try {
|
|
54
|
+
driver.stop()
|
|
55
|
+
} catch {
|
|
56
|
+
/* stop is best-effort — dismissing the sheet must never throw */
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|