@bsv/expo-wallet-toolbox 0.25.0 → 0.26.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 +43 -0
- package/core/context/WalletContext.tsx +11 -15
- package/core/i18n/translations.tsx +221 -36
- package/core/identity/handleRegistry/client.ts +110 -16
- package/core/identity/handleRegistry/registration.ts +115 -17
- package/core/index.ts +8 -0
- package/core/net/wocLimiter.ts +133 -0
- package/core/pay/beefRepair.ts +3 -1
- package/core/pay/rails/address.ts +2 -2
- package/core/profiles/profileStore.ts +4 -1
- package/core/services/arcadeBroadcastProvider.ts +6 -0
- package/core/services/exchangeRate.ts +8 -1
- package/core/services/groupSpendingLimit.ts +26 -0
- package/core/services/signingPermissionPolicy.ts +14 -8
- package/core/services/vault/ceremony.ts +13 -0
- package/core/services/vault/ceremonyHost.ts +58 -0
- package/core/services/vault/failedVaultSpend.ts +40 -0
- package/core/services/vault/outputAuthority.ts +13 -6
- package/core/services/vault/transfers.ts +56 -12
- package/core/services/vault/wocLookup.ts +5 -2
- package/core/storage/encryptedDbImage.ts +11 -2
- package/core/theme/tokens.ts +26 -12
- package/package.json +2 -1
- package/ui/components/QRScanner.tsx +24 -22
- package/ui/components/pay/MessageBoxConfig.tsx +10 -16
- package/ui/components/pay/NearbyAdvisoryModal.tsx +6 -13
- package/ui/components/pay/NearbyFlow.tsx +72 -35
- package/ui/components/pay/PayForm.tsx +27 -19
- package/ui/components/pay/PaymentSuccessOverlay.tsx +8 -6
- package/ui/components/pay/UniversalSend.tsx +4 -1
- package/ui/components/ui/AlertCard.tsx +3 -2
- package/ui/components/ui/BalancedText.tsx +117 -0
- package/ui/components/ui/ErrorBoundary.tsx +31 -14
- package/ui/components/ui/GroupedList.tsx +28 -22
- package/ui/components/ui/ListRow.tsx +126 -35
- package/ui/components/ui/PermissionSheet.tsx +31 -24
- package/ui/components/ui/PresenceRow.tsx +15 -23
- package/ui/components/ui/Sheet.tsx +11 -17
- package/ui/components/ui/Toast.tsx +13 -17
- package/ui/components/vault/EnrollWizard.tsx +446 -196
- package/ui/components/vault/KeyChooser.tsx +7 -20
- package/ui/components/vault/VaultCeremonySheet.tsx +44 -36
- package/ui/components/wallet/AmountInput.tsx +11 -17
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +13 -17
- package/ui/index.ts +1 -1
- package/ui/screens/TrustScreen.tsx +49 -61
- package/ui/screens/VaultScreen.tsx +99 -60
- package/ui/screens/VaultTransferScreen.tsx +34 -27
- package/ui/screens/WalletCheckScreen.tsx +25 -24
- package/ui/screens/WalletConfigScreen.tsx +66 -72
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
2
|
import type { BsvExchangeRate } from '../toolboxTypes'
|
|
3
|
+
import { reserveWocSlot, waitWocSlot, wocRateLimited } from '../net/wocLimiter'
|
|
3
4
|
|
|
4
5
|
// Shared with context/ExchangeRateContext.tsx so a single cache serves both the
|
|
5
6
|
// fiat-display UI and the wallet-build seed. Same key + same { usdPerBsv } shape.
|
|
@@ -8,6 +9,7 @@ import type { BsvExchangeRate } from '../toolboxTypes'
|
|
|
8
9
|
export const CACHE_KEY = 'cached_exchange_rate'
|
|
9
10
|
export const FALLBACK_RATE = 16.75
|
|
10
11
|
const REFRESH_TIMEOUT_MS = 4000
|
|
12
|
+
const EXCHANGE_RATE_URL = 'https://api.whatsonchain.com/v1/bsv/main/exchangerate'
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* `getExchangeRate()`'s own return, plus a handle on the SAME background
|
|
@@ -31,12 +33,17 @@ export interface ExchangeRateSeed extends BsvExchangeRate {
|
|
|
31
33
|
*/
|
|
32
34
|
function refreshExchangeRateCache(): Promise<number | undefined> {
|
|
33
35
|
return (async () => {
|
|
36
|
+
// The limiter wait comes before the timeout starts, so time in the queue
|
|
37
|
+
// never counts against the request.
|
|
38
|
+
const wait = reserveWocSlot(EXCHANGE_RATE_URL)
|
|
39
|
+
if (wait > 0) await waitWocSlot(wait)
|
|
34
40
|
const controller = new AbortController()
|
|
35
41
|
const timeout = setTimeout(() => controller.abort(), REFRESH_TIMEOUT_MS)
|
|
36
42
|
try {
|
|
37
|
-
const res = await fetch(
|
|
43
|
+
const res = await fetch(EXCHANGE_RATE_URL, {
|
|
38
44
|
signal: controller.signal
|
|
39
45
|
})
|
|
46
|
+
if (res.status === 429) wocRateLimited(EXCHANGE_RATE_URL)
|
|
40
47
|
const data = await res.json()
|
|
41
48
|
const usdPerBsv = Number(data?.rate)
|
|
42
49
|
if (Number.isFinite(usdPerBsv) && usdPerBsv > 0) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import { AUTO_APPROVE_STORAGE_KEY, DEFAULT_AUTO_APPROVE_THRESHOLD } from '../constants'
|
|
3
|
+
import { profileScopedKey } from '../profiles/profileStore'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The most a site's one-time group grant may let it spend each month: what it could spend without asking,
|
|
7
|
+
* per payment (the stored auto-approve threshold). 0 means the user wants every payment asked about.
|
|
8
|
+
*/
|
|
9
|
+
export async function groupSpendingLimit(): Promise<number> {
|
|
10
|
+
const v = await AsyncStorage.getItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY)).catch(() => null)
|
|
11
|
+
return v === null ? DEFAULT_AUTO_APPROVE_THRESHOLD : Number(v) || 0
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The same group with its spending limited to `limit`; with a limit of 0 or less, with no spending at all. */
|
|
15
|
+
export function clampGroupSpending<T extends { spendingAuthorization?: { amount: number; description?: string } }>(
|
|
16
|
+
group: T,
|
|
17
|
+
limit: number
|
|
18
|
+
): T {
|
|
19
|
+
const spending = group.spendingAuthorization
|
|
20
|
+
if (!spending) return group
|
|
21
|
+
if (!(limit > 0)) {
|
|
22
|
+
const { spendingAuthorization: _removed, ...rest } = group
|
|
23
|
+
return rest as T
|
|
24
|
+
}
|
|
25
|
+
return spending.amount <= limit ? group : { ...group, spendingAuthorization: { ...spending, amount: limit } }
|
|
26
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Hash, Utils } from '@bsv/sdk'
|
|
2
2
|
import { WalletPermissionsManager, type GroupedPermissions } from '@bsv/wallet-toolbox-mobile'
|
|
3
|
+
import { groupSpendingLimit } from './groupSpendingLimit'
|
|
3
4
|
|
|
4
5
|
/** A site's manifest group request (BRC-73), as the Connect sheet shows it and `mintGroupedPermissions` mints it. */
|
|
5
6
|
export type GroupPermissions = GroupedPermissions
|
|
@@ -118,13 +119,13 @@ const isObject = (v: unknown): v is Record<string, any> => v !== null && typeof
|
|
|
118
119
|
* the manifest, so every entry is checked: one that does not have the shape the manager reads is
|
|
119
120
|
* left out, and what remains is both what the Connect sheet shows and what Connect mints.
|
|
120
121
|
*/
|
|
121
|
-
function sanitizeGroup(raw: unknown): GroupPermissions | null {
|
|
122
|
+
export function sanitizeGroup(raw: unknown, limit: number): GroupPermissions | null {
|
|
122
123
|
if (!isObject(raw)) return null
|
|
123
124
|
const group: GroupPermissions = {}
|
|
124
125
|
if (typeof raw.description === 'string') group.description = raw.description
|
|
125
126
|
const spending = raw.spendingAuthorization
|
|
126
|
-
if (isObject(spending) && Number.isSafeInteger(spending.amount) && spending.amount > 0) {
|
|
127
|
-
group.spendingAuthorization = { amount: spending.amount, description: str(spending.description) }
|
|
127
|
+
if (isObject(spending) && Number.isSafeInteger(spending.amount) && spending.amount > 0 && limit > 0) {
|
|
128
|
+
group.spendingAuthorization = { amount: Math.min(spending.amount, limit), description: str(spending.description) }
|
|
128
129
|
}
|
|
129
130
|
const list = (v: unknown): any[] => (Array.isArray(v) ? v.filter(isObject) : [])
|
|
130
131
|
group.protocolPermissions = list(raw.protocolPermissions)
|
|
@@ -327,7 +328,7 @@ export class SigningPolicyPermissionsManager extends WalletPermissionsManager {
|
|
|
327
328
|
try {
|
|
328
329
|
const { normalized } = this.internals.prepareOriginator(originator)
|
|
329
330
|
const { groupPermissions } = await this.internals.fetchManifestPermissions(normalized)
|
|
330
|
-
return sanitizeGroup(groupPermissions)
|
|
331
|
+
return sanitizeGroup(groupPermissions, await groupSpendingLimit())
|
|
331
332
|
} catch {
|
|
332
333
|
return null
|
|
333
334
|
}
|
|
@@ -347,19 +348,24 @@ export class SigningPolicyPermissionsManager extends WalletPermissionsManager {
|
|
|
347
348
|
protocolPermissions: (group.protocolPermissions ?? []).filter(p => !isAskEveryTimeProtocol(p.protocolID))
|
|
348
349
|
}
|
|
349
350
|
const todo = await i.filterAlreadyGrantedPermissions(normalized, wanted)
|
|
351
|
+
const limit = await groupSpendingLimit()
|
|
352
|
+
const spend =
|
|
353
|
+
todo.spendingAuthorization != null && limit > 0
|
|
354
|
+
? { ...todo.spendingAuthorization, amount: Math.min(todo.spendingAuthorization.amount, limit) }
|
|
355
|
+
: null
|
|
350
356
|
const lookup = i.buildOriginatorLookupValues(originator, normalized)
|
|
351
357
|
const toCreate: MintItem[] = []
|
|
352
358
|
const toRenew: MintItem[] = []
|
|
353
|
-
if (
|
|
359
|
+
if (spend != null) {
|
|
354
360
|
toCreate.push({
|
|
355
361
|
request: {
|
|
356
362
|
type: 'spending',
|
|
357
363
|
originator: normalized,
|
|
358
|
-
spending: { satoshis:
|
|
359
|
-
reason:
|
|
364
|
+
spending: { satoshis: spend.amount },
|
|
365
|
+
reason: spend.description
|
|
360
366
|
},
|
|
361
367
|
expiry: 0,
|
|
362
|
-
amount:
|
|
368
|
+
amount: spend.amount
|
|
363
369
|
})
|
|
364
370
|
}
|
|
365
371
|
for (const p of todo.protocolPermissions ?? []) {
|
|
@@ -269,6 +269,19 @@ export class CeremonyController {
|
|
|
269
269
|
return () => this.subscribers.delete(cb)
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/** Whether `signer` is still the armed one: not released by its caller, by
|
|
273
|
+
* cancel(), by a detach or by the retention ceiling. Read by a shared signer
|
|
274
|
+
* session (ceremonyHost.openVaultSignerSession) before it reuses a signer. */
|
|
275
|
+
holds(signer: VaultSigner): boolean {
|
|
276
|
+
return this.activeHandle === signer
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Whether cancel() ended the ceremony most recently asked for. requestSigner
|
|
280
|
+
* resets it, so it speaks only for that ceremony. */
|
|
281
|
+
get wasCancelled(): boolean {
|
|
282
|
+
return this.cancelled
|
|
283
|
+
}
|
|
284
|
+
|
|
272
285
|
/** Ask for the chosen key as a signer. Every overlapping request is refused:
|
|
273
286
|
* one caller must have sole ownership of both the signer and the process-wide
|
|
274
287
|
* native discovery/session object through release and teardown. */
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { CeremonyController, VaultProgress, VaultSigner } from './ceremony'
|
|
9
9
|
import { getVaultDriver } from './driver'
|
|
10
|
+
import { VaultError } from './types'
|
|
10
11
|
import { vaultStore } from './vaultStore'
|
|
11
12
|
|
|
12
13
|
/** How long an armed signer stays usable before it relocks — refreshed by
|
|
@@ -50,3 +51,60 @@ export function requestVaultSigner(reason: string, chosenSerial: string): Promis
|
|
|
50
51
|
export function noteVaultProgress(p: VaultProgress): void {
|
|
51
52
|
ceremony.noteProgress(p)
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* One key session for a whole spend that also creates a Vault output (a
|
|
57
|
+
* withdrawal with a re-vaulted remainder, a re-lock): one PIN entry and one
|
|
58
|
+
* tap cover both the new output's possession proof and the input signatures.
|
|
59
|
+
* Before this, each step opened its own ceremony, so the person entered the
|
|
60
|
+
* PIN and tapped twice for one transfer.
|
|
61
|
+
*
|
|
62
|
+
* The session is a local of ONE operation and is closed in that operation's
|
|
63
|
+
* finally. It is never module state (see VaultSigner).
|
|
64
|
+
*
|
|
65
|
+
* - `acquire` arms the chosen key the first time. Later calls return the same
|
|
66
|
+
* signer while it is still armed. If the key left or the retention window
|
|
67
|
+
* closed in between (the proof is signed before the transaction is built, so
|
|
68
|
+
* the session stays open through the build), it asks for a fresh ceremony:
|
|
69
|
+
* the old two-tap behaviour, never a failed transfer. A session the person
|
|
70
|
+
* cancelled stays cancelled (`user-cancelled`).
|
|
71
|
+
* - `close` releases the signer. Idempotent, as VaultSigner.release() is, so
|
|
72
|
+
* the spend may release the signer itself as soon as the last input is
|
|
73
|
+
* signed and the operation's finally may close again.
|
|
74
|
+
*/
|
|
75
|
+
export interface VaultSignerSession {
|
|
76
|
+
acquire(reason: string, chosenSerial: string): Promise<VaultSigner>
|
|
77
|
+
close(): void
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function openVaultSignerSession(
|
|
81
|
+
deps: {
|
|
82
|
+
request: (reason: string, chosenSerial: string) => Promise<VaultSigner>
|
|
83
|
+
holds: (signer: VaultSigner) => boolean
|
|
84
|
+
cancelled: () => boolean
|
|
85
|
+
} = {
|
|
86
|
+
request: requestVaultSigner,
|
|
87
|
+
holds: signer => ceremony.holds(signer),
|
|
88
|
+
cancelled: () => ceremony.wasCancelled
|
|
89
|
+
}
|
|
90
|
+
): VaultSignerSession {
|
|
91
|
+
let held: VaultSigner | undefined
|
|
92
|
+
return {
|
|
93
|
+
async acquire(reason, chosenSerial) {
|
|
94
|
+
if (held && held.serial === chosenSerial && deps.holds(held)) return held
|
|
95
|
+
if (held) {
|
|
96
|
+
const ended = held
|
|
97
|
+
held = undefined
|
|
98
|
+
ended.release()
|
|
99
|
+
if (deps.cancelled()) throw new VaultError('user-cancelled', 'Vault key session was cancelled')
|
|
100
|
+
}
|
|
101
|
+
held = await deps.request(reason, chosenSerial)
|
|
102
|
+
return held
|
|
103
|
+
},
|
|
104
|
+
close() {
|
|
105
|
+
const signer = held
|
|
106
|
+
held = undefined
|
|
107
|
+
signer?.release()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which FAILED Vault spends (withdrawals, re-locks) hold a pending key removal
|
|
3
|
+
* open in finalizeVaultKeyRemoval.
|
|
4
|
+
*
|
|
5
|
+
* The tombstone exists so that no output the removed key can still open is
|
|
6
|
+
* missed. A failed spend is a risk to that only if it may yet be on the
|
|
7
|
+
* network, creating an output committed to the old key set. Refusing on every
|
|
8
|
+
* failed spend ever recorded (the earlier rule) could never clear: a failed
|
|
9
|
+
* action stays in the wallet's history for good, so one aborted re-lock
|
|
10
|
+
* attempt, or one failed withdrawal months before, kept the removal pending
|
|
11
|
+
* after its re-lock was mined.
|
|
12
|
+
*
|
|
13
|
+
* A failed spend blocks only when BOTH hold:
|
|
14
|
+
*
|
|
15
|
+
* 1. It has a transaction ID. A Vault input is signed by the card and by
|
|
16
|
+
* nothing else, and the wallet assigns the ID at signAction. A spend with
|
|
17
|
+
* none was aborted before any signature: no transaction with its inputs can
|
|
18
|
+
* exist.
|
|
19
|
+
* 2. It began at or after the removal did. finalize clears the tombstone only
|
|
20
|
+
* with an ACCEPTED re-lock and two scans that find no output authorizing
|
|
21
|
+
* the removed key, so every output an earlier spend could have consumed is
|
|
22
|
+
* spent by an accepted transaction: the earlier one can no longer confirm.
|
|
23
|
+
* (Should an accepted re-lock still be dropped, its sources return as
|
|
24
|
+
* outputs committed to the removed key, which the coverage badge offers to
|
|
25
|
+
* re-lock: the owner decision recorded at ACCEPTED_ACTION_STATUSES.)
|
|
26
|
+
*
|
|
27
|
+
* Fail closed where the spend cannot be placed in time: a signed spend with no
|
|
28
|
+
* readable creation time, or a removal with no readable start, blocks.
|
|
29
|
+
*/
|
|
30
|
+
export function failedVaultSpendBlocksRemoval(
|
|
31
|
+
action: { txid?: string; created_at?: string | Date | number },
|
|
32
|
+
removalStartedAt: number
|
|
33
|
+
): boolean {
|
|
34
|
+
if (typeof action.txid !== 'string' || action.txid === '') return false
|
|
35
|
+
const at = action.created_at
|
|
36
|
+
const created =
|
|
37
|
+
at instanceof Date ? at.getTime() : typeof at === 'number' ? at : typeof at === 'string' ? Date.parse(at) : NaN
|
|
38
|
+
if (!Number.isFinite(created) || !Number.isFinite(removalStartedAt)) return true
|
|
39
|
+
return created >= removalStartedAt
|
|
40
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* to, for this exact output, before any funding action is created. */
|
|
5
5
|
import { Hash, Utils } from '@bsv/sdk'
|
|
6
6
|
import { p256 } from '@noble/curves/nist.js'
|
|
7
|
-
import { requestVaultSigner } from './ceremonyHost'
|
|
7
|
+
import { requestVaultSigner, type VaultSignerSession } from './ceremonyHost'
|
|
8
8
|
import { randomBytes } from './random'
|
|
9
9
|
import { VaultError } from './types'
|
|
10
10
|
import { vaultStore, type VaultMeta, type VaultScopeToken } from './vaultStore'
|
|
@@ -19,7 +19,11 @@ export async function requireVaultOutputKeyPossession(
|
|
|
19
19
|
meta: Pick<VaultMeta, 'vaultId' | 'revision' | 'createdAt' | 'keys' | 'lastUsedSerial'>,
|
|
20
20
|
scope: VaultScopeToken,
|
|
21
21
|
output: VaultOutputAuthorityContext,
|
|
22
|
-
chosenSerial?: string
|
|
22
|
+
chosenSerial?: string,
|
|
23
|
+
/** A spend's own key session: the proof is signed in it and the session
|
|
24
|
+
* stays open for the input signatures (one PIN, one tap). `reason` is the
|
|
25
|
+
* spend's, because the first ceremony fixes the NFC alert text. */
|
|
26
|
+
shared?: { session: VaultSignerSession; reason: string }
|
|
23
27
|
): Promise<void> {
|
|
24
28
|
vaultStore.assertScopeToken(scope)
|
|
25
29
|
const chosen =
|
|
@@ -46,7 +50,7 @@ export async function requireVaultOutputKeyPossession(
|
|
|
46
50
|
'utf8'
|
|
47
51
|
)
|
|
48
52
|
)
|
|
49
|
-
await proveKeyPossession(scope, chosen, digest, 'Verify vault key for new funds')
|
|
53
|
+
await proveKeyPossession(scope, chosen, digest, shared?.reason ?? 'Verify vault key for new funds', shared?.session)
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
/** Fresh hardware authority to promote a staged key (add-key, late-key) when
|
|
@@ -89,9 +93,12 @@ async function proveKeyPossession(
|
|
|
89
93
|
scope: VaultScopeToken,
|
|
90
94
|
chosen: VaultMeta['keys'][number],
|
|
91
95
|
digest: number[],
|
|
92
|
-
reason: string
|
|
96
|
+
reason: string,
|
|
97
|
+
/** When given, the signer belongs to the caller's session: it is not
|
|
98
|
+
* released here. The session's owner closes it, also when this throws. */
|
|
99
|
+
session?: VaultSignerSession
|
|
93
100
|
): Promise<void> {
|
|
94
|
-
const signer = await requestVaultSigner(reason, chosen.serial)
|
|
101
|
+
const signer = session ? await session.acquire(reason, chosen.serial) : await requestVaultSigner(reason, chosen.serial)
|
|
95
102
|
try {
|
|
96
103
|
vaultStore.assertScopeToken(scope)
|
|
97
104
|
if (signer.serial !== chosen.serial || signer.pubkey !== chosen.pubkey) {
|
|
@@ -116,6 +123,6 @@ async function proveKeyPossession(
|
|
|
116
123
|
}
|
|
117
124
|
if (!valid) throw new VaultError('wrong-key', 'Hardware failed the new vault output possession challenge')
|
|
118
125
|
} finally {
|
|
119
|
-
signer.release()
|
|
126
|
+
if (!session) signer.release()
|
|
120
127
|
}
|
|
121
128
|
}
|
|
@@ -45,7 +45,7 @@ import { Beef, Hash, LockingScript, OP, P2PKH, PublicKey, Script, Transaction, U
|
|
|
45
45
|
import { isBackupPushEnabled } from '../../backup/preference'
|
|
46
46
|
import { getBackupUrl, isVaultAvailable, isVaultEnabled } from '../../toolboxConfig'
|
|
47
47
|
import { sdk as toolboxSdk } from '@bsv/wallet-toolbox-mobile'
|
|
48
|
-
import { noteVaultProgress, requestVaultSigner } from './ceremonyHost'
|
|
48
|
+
import { noteVaultProgress, openVaultSignerSession, requestVaultSigner, type VaultSignerSession } from './ceremonyHost'
|
|
49
49
|
import {
|
|
50
50
|
MAX_DESCRIPTOR_CIPHERTEXT_BYTES,
|
|
51
51
|
R1C_LOCK_LEN,
|
|
@@ -72,6 +72,7 @@ import { VaultError } from './types'
|
|
|
72
72
|
import { metaFromVerifiedOutputs, VAULT_MAX_KEYS, VAULT_MIN_KEYS } from './VaultKeyService'
|
|
73
73
|
import { vaultStore, VaultKeyRecord, VaultMeta, type VaultScopeToken, type VaultStoreScope } from './vaultStore'
|
|
74
74
|
import { computeVaultMetaAuthorityTag, verifyVaultMetaAuthorityTag, type HmacCapableWallet } from './metaAuthority'
|
|
75
|
+
import { failedVaultSpendBlocksRemoval } from './failedVaultSpend'
|
|
75
76
|
import { requireVaultKeyChallenge, requireVaultOutputKeyPossession } from './outputAuthority'
|
|
76
77
|
import { planLockKeys, type LockKeyPlan } from './lockKeys'
|
|
77
78
|
import { forgetSerialsNoLongerEnrolledForIdentity } from './enrolledSerialRegistry'
|
|
@@ -380,6 +381,10 @@ function asHmacWallet(w: VaultWallet): HmacCapableWallet {
|
|
|
380
381
|
export interface VaultActionRow {
|
|
381
382
|
txid?: string
|
|
382
383
|
status: string
|
|
384
|
+
/** When the wallet recorded the action. Not part of BRC-100's listActions
|
|
385
|
+
* result; the wallet core returns it with each row. Read only by
|
|
386
|
+
* failedVaultSpendBlocksRemoval, which blocks when it is missing. */
|
|
387
|
+
created_at?: string | Date
|
|
383
388
|
reference?: string
|
|
384
389
|
labels?: string[]
|
|
385
390
|
inputs?: { sourceOutpoint?: string; sourceSatoshis?: number; sourceLockingScript?: string }[]
|
|
@@ -2316,7 +2321,11 @@ async function newVaultOutput(
|
|
|
2316
2321
|
outputDescription: string,
|
|
2317
2322
|
inventory: VaultSaltInventory,
|
|
2318
2323
|
scopeToken: VaultScopeToken,
|
|
2319
|
-
chosenSerial?: string
|
|
2324
|
+
chosenSerial?: string,
|
|
2325
|
+
/** A spend's key session and reason: the possession proof below is signed in
|
|
2326
|
+
* it, and spendVaultOutputs signs the inputs in the same session. A deposit
|
|
2327
|
+
* passes none (it signs no Vault input) and keeps its own ceremony. */
|
|
2328
|
+
shared?: { session: VaultSignerSession; reason: string }
|
|
2320
2329
|
): Promise<[vault: VaultOutputSpec, marker: VaultOutputSpec, descriptor: VaultOutputSpec]> {
|
|
2321
2330
|
// Every output-creating path (deposit, re-lock, partial-withdrawal
|
|
2322
2331
|
// remainder) comes through here. The key list may briefly hold one key more
|
|
@@ -2354,8 +2363,12 @@ async function newVaultOutput(
|
|
|
2354
2363
|
saltKeyId,
|
|
2355
2364
|
lockingScript: lockingScript.toHex()
|
|
2356
2365
|
},
|
|
2357
|
-
chosenSerial
|
|
2366
|
+
chosenSerial,
|
|
2367
|
+
shared
|
|
2358
2368
|
)
|
|
2369
|
+
// The shared session stays armed while the transaction is built: say so, and
|
|
2370
|
+
// restart its retention window. A no-op with nothing armed.
|
|
2371
|
+
if (shared) noteVaultProgress({ phase: 'preparing' })
|
|
2359
2372
|
const v7: VaultInstructionsV7 = {
|
|
2360
2373
|
v: 7,
|
|
2361
2374
|
type: 'R1C',
|
|
@@ -3249,7 +3262,11 @@ async function spendVaultOutputs(
|
|
|
3249
3262
|
reason: string,
|
|
3250
3263
|
plan: VaultSpendPlan,
|
|
3251
3264
|
opts?: VaultTransferOptions,
|
|
3252
|
-
scopeToken?: VaultScopeToken
|
|
3265
|
+
scopeToken?: VaultScopeToken,
|
|
3266
|
+
/** The operation's key session. When a new Vault output's possession proof
|
|
3267
|
+
* already armed the chosen key in it, the inputs are signed in that same
|
|
3268
|
+
* session: no second PIN entry or tap. */
|
|
3269
|
+
session?: VaultSignerSession
|
|
3253
3270
|
): Promise<VaultSpendResult> {
|
|
3254
3271
|
const { tx, reference, prepared } = await createSignableVaultTx(
|
|
3255
3272
|
w,
|
|
@@ -3271,7 +3288,9 @@ async function spendVaultOutputs(
|
|
|
3271
3288
|
const unlocks: { inputIndex: number; unlockingScript: UnlockingScript }[] = []
|
|
3272
3289
|
try {
|
|
3273
3290
|
// ── the tap(s): one on-card signature per input ────────────────────
|
|
3274
|
-
const signer =
|
|
3291
|
+
const signer = session
|
|
3292
|
+
? await session.acquire(reason, chosen.serial)
|
|
3293
|
+
: await requestVaultSigner(reason, chosen.serial)
|
|
3275
3294
|
assertVaultScope(scopeToken)
|
|
3276
3295
|
// The commitment check above ran against chosen.pubkey, but every unlock
|
|
3277
3296
|
// is built with signer.pubkey — they must be the same key, or the card
|
|
@@ -3516,6 +3535,9 @@ export async function withdrawFromVault(
|
|
|
3516
3535
|
const scopeToken = vaultStore.captureScopeToken()
|
|
3517
3536
|
return await withVaultMutation(async () => {
|
|
3518
3537
|
assertVaultScope(scopeToken)
|
|
3538
|
+
// One key session for the remainder's possession proof and the inputs.
|
|
3539
|
+
const session = openVaultSignerSession()
|
|
3540
|
+
try {
|
|
3519
3541
|
// Cheapest refusal first, as in depositToVault — see requireWithdrawalAmount.
|
|
3520
3542
|
requireWithdrawalAmount(amount)
|
|
3521
3543
|
// An offline user is never asked to present a key for a transfer that
|
|
@@ -3568,7 +3590,8 @@ export async function withdrawFromVault(
|
|
|
3568
3590
|
'Vault change',
|
|
3569
3591
|
sel.saltInventory,
|
|
3570
3592
|
scopeToken,
|
|
3571
|
-
chosenSerial
|
|
3593
|
+
chosenSerial,
|
|
3594
|
+
{ session, reason }
|
|
3572
3595
|
))
|
|
3573
3596
|
)
|
|
3574
3597
|
}
|
|
@@ -3584,10 +3607,15 @@ export async function withdrawFromVault(
|
|
|
3584
3607
|
description: 'Vault withdrawal'
|
|
3585
3608
|
},
|
|
3586
3609
|
opts,
|
|
3587
|
-
scopeToken
|
|
3610
|
+
scopeToken,
|
|
3611
|
+
session
|
|
3588
3612
|
)
|
|
3589
3613
|
if (remainderPlan?.changesKeySet) await commitPlannedKeySet(w, adminOriginator, scopeToken, remainderPlan)
|
|
3590
3614
|
return result
|
|
3615
|
+
} finally {
|
|
3616
|
+
// Also the way out when anything between the proof and the inputs throws.
|
|
3617
|
+
session.close()
|
|
3618
|
+
}
|
|
3591
3619
|
})
|
|
3592
3620
|
}
|
|
3593
3621
|
|
|
@@ -3660,6 +3688,9 @@ export async function relockVault(
|
|
|
3660
3688
|
const scopeToken = vaultStore.captureScopeToken()
|
|
3661
3689
|
return await withVaultMutation(async () => {
|
|
3662
3690
|
assertVaultScope(scopeToken)
|
|
3691
|
+
// One key session for the new lock's possession proof and the inputs.
|
|
3692
|
+
const session = openVaultSignerSession()
|
|
3693
|
+
try {
|
|
3663
3694
|
requireReleased(opts, scopeToken, 'Re-locking the vault')
|
|
3664
3695
|
await requireOnline(opts)
|
|
3665
3696
|
assertVaultScope(scopeToken)
|
|
@@ -3720,7 +3751,8 @@ export async function relockVault(
|
|
|
3720
3751
|
'Vault re-lock',
|
|
3721
3752
|
sel.saltInventory,
|
|
3722
3753
|
scopeToken,
|
|
3723
|
-
chosenSerial
|
|
3754
|
+
chosenSerial,
|
|
3755
|
+
{ session, reason }
|
|
3724
3756
|
),
|
|
3725
3757
|
labels: ['vault', 'vault-relock'],
|
|
3726
3758
|
inputDescription: 'Vault re-lock',
|
|
@@ -3730,7 +3762,8 @@ export async function relockVault(
|
|
|
3730
3762
|
description: 'Vault relock'
|
|
3731
3763
|
},
|
|
3732
3764
|
opts,
|
|
3733
|
-
scopeToken
|
|
3765
|
+
scopeToken,
|
|
3766
|
+
session
|
|
3734
3767
|
)
|
|
3735
3768
|
if (revokePubkey) {
|
|
3736
3769
|
// The tag covers pendingRemoval.state, so the 'broadcast' write must be
|
|
@@ -3748,6 +3781,10 @@ export async function relockVault(
|
|
|
3748
3781
|
}
|
|
3749
3782
|
if (plan.changesKeySet) await commitPlannedKeySet(w, adminOriginator, scopeToken, plan)
|
|
3750
3783
|
return result
|
|
3784
|
+
} finally {
|
|
3785
|
+
// Also the way out when anything between the proof and the inputs throws.
|
|
3786
|
+
session.close()
|
|
3787
|
+
}
|
|
3751
3788
|
})
|
|
3752
3789
|
}
|
|
3753
3790
|
|
|
@@ -4209,8 +4246,10 @@ async function isUnbroadcastPendingRemovalRelock(
|
|
|
4209
4246
|
/** Reconcile a durable pending removal. A bounded broadcast marker is inferred
|
|
4210
4247
|
* after a crash only from an authenticated matching re-lock action. The
|
|
4211
4248
|
* tombstone is cleared only when every Vault action is accepted by the network
|
|
4212
|
-
* (ACCEPTED_ACTION_STATUSES)
|
|
4213
|
-
*
|
|
4249
|
+
* (ACCEPTED_ACTION_STATUSES), is a failed deposit, or is a failed spend that
|
|
4250
|
+
* can no longer reach the network for this removal
|
|
4251
|
+
* (failedVaultSpendBlocksRemoval), a matching re-lock is accepted, and two
|
|
4252
|
+
* authenticated scans find no lock authorizing the key. */
|
|
4214
4253
|
export async function finalizeVaultKeyRemoval(w: VaultWallet, adminOriginator: string): Promise<boolean> {
|
|
4215
4254
|
const scopeToken = vaultStore.captureScopeToken()
|
|
4216
4255
|
return await withVaultMutation(async () => {
|
|
@@ -4284,7 +4323,12 @@ export async function finalizeVaultKeyRemoval(w: VaultWallet, adminOriginator: s
|
|
|
4284
4323
|
if (ACCEPTED_ACTION_STATUSES.has(action.status)) return
|
|
4285
4324
|
if (action.status === 'failed') {
|
|
4286
4325
|
const labels = new Set(action.labels ?? [])
|
|
4287
|
-
|
|
4326
|
+
// A failed deposit never blocks. A failed spend blocks only while it
|
|
4327
|
+
// may still reach the network for THIS removal: see failedVaultSpend.ts.
|
|
4328
|
+
if (
|
|
4329
|
+
!(labels.has('vault-deposit') && !labels.has('vault-withdraw') && !labels.has('vault-relock')) &&
|
|
4330
|
+
failedVaultSpendBlocksRemoval(action, pendingAtStart.startedAt)
|
|
4331
|
+
) {
|
|
4288
4332
|
actionStateBlocks = true
|
|
4289
4333
|
}
|
|
4290
4334
|
} else {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Utils } from '@bsv/sdk'
|
|
6
6
|
import { wocConfigFor, type WocConfig } from '../../pay/rails/address'
|
|
7
|
+
import { wocLimitedFetch } from '../../net/wocLimiter'
|
|
7
8
|
import type { AppChain } from '../../config'
|
|
8
9
|
import type { MarkerHistory, MarkerUnknownReason, VaultChainLookup } from './markerLookup'
|
|
9
10
|
|
|
@@ -49,9 +50,11 @@ export function wocChainLookup(chain: AppChain, requestInit?: RequestInit): Vaul
|
|
|
49
50
|
|
|
50
51
|
// `requestInit` (for example the app's WhatsOnChain key header) is merged
|
|
51
52
|
// into every request. Headers given per call win on a name clash.
|
|
53
|
+
// Every request goes through the shared WhatsOnChain limiter: a scan sends
|
|
54
|
+
// several requests per index, back to back.
|
|
52
55
|
const doFetch = (url: string, init?: RequestInit): Promise<Response> => {
|
|
53
|
-
if (!requestInit) return
|
|
54
|
-
return
|
|
56
|
+
if (!requestInit) return wocLimitedFetch(url, init)
|
|
57
|
+
return wocLimitedFetch(url, {
|
|
55
58
|
...requestInit,
|
|
56
59
|
...init,
|
|
57
60
|
headers: mergeHeaders(requestInit.headers, init?.headers)
|
|
@@ -147,9 +147,18 @@ function nativeCrypto(): NativeCrypto {
|
|
|
147
147
|
return backend
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/**
|
|
150
|
+
/**
|
|
151
|
+
* quick-crypto hands back ArrayBuffers and wants Buffers in; Node wants Buffers too.
|
|
152
|
+
*
|
|
153
|
+
* The result is always a PLAIN Uint8Array. quick-crypto's getAuthTag (and all of
|
|
154
|
+
* Node's crypto) answers with a Buffer, which is a Uint8Array subclass. A sink
|
|
155
|
+
* such as expo-file-system's writeBytes finds the array kind from
|
|
156
|
+
* `constructor.name` and ends the app on a name it does not know ("Buffer").
|
|
157
|
+
* The view shares the same memory: nothing is copied.
|
|
158
|
+
*/
|
|
151
159
|
function toU8(x: ArrayBuffer | Uint8Array): Uint8Array {
|
|
152
|
-
|
|
160
|
+
if (!(x instanceof Uint8Array)) return new Uint8Array(x)
|
|
161
|
+
return x.constructor === Uint8Array ? x : new Uint8Array(x.buffer, x.byteOffset, x.byteLength)
|
|
153
162
|
}
|
|
154
163
|
function toBuf(x: Uint8Array): Uint8Array {
|
|
155
164
|
const B = (globalThis as { Buffer?: { from(b: ArrayBufferLike, o: number, l: number): Uint8Array } }).Buffer
|
package/core/theme/tokens.ts
CHANGED
|
@@ -55,20 +55,34 @@ export const radii = {
|
|
|
55
55
|
* rounded to 44 to sit on the 4pt grid). It is for a single focal figure on a
|
|
56
56
|
* screen that has one — an amount being handed to another person — and nothing
|
|
57
57
|
* else. Two `display` elements on one view means the view has no focal point.
|
|
58
|
+
*
|
|
59
|
+
* Every ramp names the family as well as the metrics. Without it each ramp is
|
|
60
|
+
* a size and a weight on whatever face the platform happens to default to, so
|
|
61
|
+
* a screen built from these tokens renders in San Francisco (or Roboto) while
|
|
62
|
+
* the host app around it renders in its own face -- and the seam shows on any
|
|
63
|
+
* screen that has both, which is most of them. The host's family is the one
|
|
64
|
+
* correct answer here, so it is set once, here, rather than overridden per
|
|
65
|
+
* component: a component that forgets to override is the bug this prevents.
|
|
66
|
+
*
|
|
67
|
+
* Nunito ships embedded at build time (app.config.js, expo-font plugin), with
|
|
68
|
+
* one static file per weight below -- 400/600/700 -- so there is no window
|
|
69
|
+
* during startup where this family is unregistered and no flash of a fallback
|
|
70
|
+
* face. A weight with no embedded file falls back to the nearest one, so keep
|
|
71
|
+
* these three in step with that plugin's list.
|
|
58
72
|
*/
|
|
59
73
|
export const typography = {
|
|
60
|
-
display: { fontSize: 44, fontWeight: '700' as const, lineHeight: 52, letterSpacing: -0.5 },
|
|
61
|
-
largeTitle: { fontSize: 34, fontWeight: '700' as const, lineHeight: 41 },
|
|
62
|
-
title1: { fontSize: 28, fontWeight: '700' as const, lineHeight: 34 },
|
|
63
|
-
title2: { fontSize: 22, fontWeight: '700' as const, lineHeight: 28 },
|
|
64
|
-
title3: { fontSize: 20, fontWeight: '600' as const, lineHeight: 25 },
|
|
65
|
-
headline: { fontSize: 17, fontWeight: '600' as const, lineHeight: 22 },
|
|
66
|
-
body: { fontSize: 17, fontWeight: '400' as const, lineHeight: 22 },
|
|
67
|
-
callout: { fontSize: 16, fontWeight: '400' as const, lineHeight: 21 },
|
|
68
|
-
subhead: { fontSize: 15, fontWeight: '400' as const, lineHeight: 20 },
|
|
69
|
-
footnote: { fontSize: 13, fontWeight: '400' as const, lineHeight: 18 },
|
|
70
|
-
caption1: { fontSize: 12, fontWeight: '400' as const, lineHeight: 16 },
|
|
71
|
-
caption2: { fontSize: 11, fontWeight: '400' as const, lineHeight: 13 }
|
|
74
|
+
display: { fontFamily: 'Nunito', fontSize: 44, fontWeight: '700' as const, lineHeight: 52, letterSpacing: -0.5 },
|
|
75
|
+
largeTitle: { fontFamily: 'Nunito', fontSize: 34, fontWeight: '700' as const, lineHeight: 41 },
|
|
76
|
+
title1: { fontFamily: 'Nunito', fontSize: 28, fontWeight: '700' as const, lineHeight: 34 },
|
|
77
|
+
title2: { fontFamily: 'Nunito', fontSize: 22, fontWeight: '700' as const, lineHeight: 28 },
|
|
78
|
+
title3: { fontFamily: 'Nunito', fontSize: 20, fontWeight: '600' as const, lineHeight: 25 },
|
|
79
|
+
headline: { fontFamily: 'Nunito', fontSize: 17, fontWeight: '600' as const, lineHeight: 22 },
|
|
80
|
+
body: { fontFamily: 'Nunito', fontSize: 17, fontWeight: '400' as const, lineHeight: 22 },
|
|
81
|
+
callout: { fontFamily: 'Nunito', fontSize: 16, fontWeight: '400' as const, lineHeight: 21 },
|
|
82
|
+
subhead: { fontFamily: 'Nunito', fontSize: 15, fontWeight: '400' as const, lineHeight: 20 },
|
|
83
|
+
footnote: { fontFamily: 'Nunito', fontSize: 13, fontWeight: '400' as const, lineHeight: 18 },
|
|
84
|
+
caption1: { fontFamily: 'Nunito', fontSize: 12, fontWeight: '400' as const, lineHeight: 16 },
|
|
85
|
+
caption2: { fontFamily: 'Nunito', fontSize: 11, fontWeight: '400' as const, lineHeight: 13 }
|
|
72
86
|
} as const
|
|
73
87
|
|
|
74
88
|
/* --------------------------------- Colors -------------------------------- */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"expo-sqlite": "~57.0.3",
|
|
76
76
|
"expo-status-bar": "~57.0.1",
|
|
77
77
|
"i18next": "^25.2.1",
|
|
78
|
+
"lucide-react-native": "^1.27.0",
|
|
78
79
|
"mobx": "^6.13.7",
|
|
79
80
|
"mobx-react-lite": "^4.1.0",
|
|
80
81
|
"qrcode": "^1.5.4",
|