@bsv/expo-wallet-toolbox 0.9.0 → 0.10.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 +45 -0
- package/README.md +7 -0
- package/core/context/WalletContext.tsx +22 -13
- package/core/headers/headerSyncTriggers.ts +65 -0
- package/core/i18n/translations.tsx +48 -0
- package/core/localpay/types.ts +9 -1
- package/core/localpay/verify.ts +54 -17
- package/core/pay/rails/nearby.ts +1 -0
- package/package.json +1 -1
- package/ui/components/pay/NearbyFlow.tsx +31 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### `verifyFramePayment` takes its chain tracker separately (breaking)
|
|
6
|
+
|
|
7
|
+
`verifyFramePayment(wallet, frame, originator, opts)` becomes
|
|
8
|
+
`verifyFramePayment({ wallet, chainTracker }, frame, originator, opts)`
|
|
9
|
+
(new `FrameVerifyDeps`), and `DerivingWallet` is back to `getPublicKey` only.
|
|
10
|
+
The 0.8.0 shape asked one "wallet" object for both key derivation and
|
|
11
|
+
`getServices().getChainTracker()`; the permissions manager has only the first,
|
|
12
|
+
and that mismatch is the bug below. A host calling `verifyFramePayment`
|
|
13
|
+
itself passes its permissions manager as `wallet` unchanged and
|
|
14
|
+
`await storage.getServices().getChainTracker()` as `chainTracker`. The
|
|
15
|
+
tracker is used only for BSV frames.
|
|
16
|
+
|
|
17
|
+
### Nearby receive: BSV frames verify again; the header window keeps up (#25)
|
|
18
|
+
|
|
19
|
+
- **Every Nearby BSV payment was declined on receive** (`NearbyFlow`).
|
|
20
|
+
`settleReceived` handed the permissions manager to `verifyFramePayment` as
|
|
21
|
+
the `DerivingWallet`, but the permissions manager has no `getServices()`,
|
|
22
|
+
so the SPV check threw a `TypeError` that went out as `decode_failed`.
|
|
23
|
+
NearbyFlow now passes the permissions manager unchanged, with the chain
|
|
24
|
+
tracker from `storage.getServices()`; if storage cannot supply one it
|
|
25
|
+
declines `save_failed` having queued nothing.
|
|
26
|
+
- **New decline kind `root_unverified`** (`core/localpay/verify.ts`,
|
|
27
|
+
`types.ts`). `tx.verify` returns false for a bad script or value and for a
|
|
28
|
+
merkle root the device cannot confirm alike, so an offline payee whose
|
|
29
|
+
header window did not reach the payment's block looked like a malformed
|
|
30
|
+
payment. The chain tracker is now observed during verification; a refused
|
|
31
|
+
root raises `FrameVerifyError('root_unverified')`, the payer is told
|
|
32
|
+
`root_unverified` (new `DeclineReason`), the request stays live, and the
|
|
33
|
+
payee sees `local_pay_root_unverified` (go online briefly, then retry).
|
|
34
|
+
Payers on older builds show the code verbatim. `FrameVerifyKind` and
|
|
35
|
+
`DeclineReason` gain the member, so a host switching exhaustively on either
|
|
36
|
+
needs a case for it.
|
|
37
|
+
- **The local header window is topped up while online, not only on
|
|
38
|
+
reconnect** (`core/headers/headerSyncTriggers.ts`,
|
|
39
|
+
`startHeaderSyncTriggers`). A phone that stayed on one network, or whose
|
|
40
|
+
NetInfo was silent while suspended, never saw a reconnect, so its window
|
|
41
|
+
trailed the chain by hours and it refused any coin mined since. The sync
|
|
42
|
+
now also runs on returning to the foreground and every
|
|
43
|
+
`HEADER_SYNC_INTERVAL_MS` (10 minutes) while online; each pass fetches only
|
|
44
|
+
the headers above the local tip.
|
|
45
|
+
- Copy: `local_pay_declined_root_unverified` and `local_pay_root_unverified`,
|
|
46
|
+
12 languages.
|
|
47
|
+
|
|
3
48
|
## 0.9.0
|
|
4
49
|
|
|
5
50
|
0.8.0 has release notes below but was never published to npm. Hosts upgrading
|
package/README.md
CHANGED
|
@@ -562,6 +562,13 @@ are required — both hard-won during this package's extraction:
|
|
|
562
562
|
|
|
563
563
|
## Breaking changes
|
|
564
564
|
|
|
565
|
+
**0.10.0:** `verifyFramePayment` takes `{ wallet, chainTracker }`
|
|
566
|
+
(`FrameVerifyDeps`) as its first argument instead of a single wallet, and
|
|
567
|
+
`DerivingWallet` no longer includes `getServices()`. Pass the permissions
|
|
568
|
+
manager as `wallet` and `await storage.getServices().getChainTracker()` as
|
|
569
|
+
`chainTracker`. The 0.8.0 note below about `DerivingWallet` gaining
|
|
570
|
+
`getServices()` no longer applies.
|
|
571
|
+
|
|
565
572
|
**0.9.0:** `useWallet().logout` now returns `Promise<boolean>` (it was
|
|
566
573
|
`() => void`). It resolves once teardown has finished, and resolves to
|
|
567
574
|
`false` when the secrets layer could not confirm erasure. Await it before
|
|
@@ -282,6 +282,7 @@ import { OfflineFirstChaintracks } from '../headers/OfflineFirstChaintracks'
|
|
|
282
282
|
import { prewarmOwnRoots } from '../headers/prewarm'
|
|
283
283
|
import { syncHeaders } from '../headers/syncHeaders'
|
|
284
284
|
import type { HeaderSource } from '../headers/syncHeaders'
|
|
285
|
+
import { startHeaderSyncTriggers } from '../headers/headerSyncTriggers'
|
|
285
286
|
|
|
286
287
|
// Auto-approve accounting (misc-p2-04). Previously a single global cooldown
|
|
287
288
|
// timer let multiple paired origins accidentally throttle each other while
|
|
@@ -2913,21 +2914,29 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2913
2914
|
// both refs fresh on every reconnect, independent of that init's own
|
|
2914
2915
|
// guarding, so it re-validates the pairing itself before syncing rather than
|
|
2915
2916
|
// trusting it was never broken.
|
|
2917
|
+
//
|
|
2918
|
+
// Reconnects alone left the window hours behind on a phone that stayed on
|
|
2919
|
+
// one network, which an offline payee then pays for by refusing any coin
|
|
2920
|
+
// mined since. So the same pass also runs on returning to the foreground and
|
|
2921
|
+
// every HEADER_SYNC_INTERVAL_MS while online (see headerSyncTriggers.ts).
|
|
2916
2922
|
useEffect(() => {
|
|
2917
2923
|
if (!walletBuilt) return
|
|
2918
|
-
return
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2924
|
+
return startHeaderSyncTriggers({
|
|
2925
|
+
sync: async () => {
|
|
2926
|
+
const ct = offlineChaintracksRef.current
|
|
2927
|
+
const store = headerStoreRef.current
|
|
2928
|
+
if (!ct || !store) return
|
|
2929
|
+
if (store.chain !== toWalletChain(selectedNetwork)) return
|
|
2930
|
+
await runHeaderSync(store, ct)
|
|
2931
|
+
},
|
|
2932
|
+
isOnline: getOnline,
|
|
2933
|
+
subscribeOnline,
|
|
2934
|
+
subscribeForeground: cb => {
|
|
2935
|
+
const sub = AppState.addEventListener('change', next => {
|
|
2936
|
+
if (next === 'active') cb()
|
|
2937
|
+
})
|
|
2938
|
+
return () => sub.remove()
|
|
2939
|
+
}
|
|
2931
2940
|
})
|
|
2932
2941
|
}, [walletBuilt, selectedNetwork, runHeaderSync])
|
|
2933
2942
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the local header window is topped up.
|
|
3
|
+
*
|
|
4
|
+
* An offline payee can only verify a nearby payment whose ancestry bottoms out
|
|
5
|
+
* at a block it already holds a header for, so the window has to keep up with
|
|
6
|
+
* the chain while the device has signal — not only at wallet build. Reconnects
|
|
7
|
+
* alone are not enough: a phone that stays on one Wi-Fi network never sees
|
|
8
|
+
* one, and on iOS NetInfo delivers nothing while the app is suspended, so a
|
|
9
|
+
* phone brought back to the foreground may not either.
|
|
10
|
+
*
|
|
11
|
+
* So a sync is attempted on each of:
|
|
12
|
+
* · coming online (every NetInfo event that reads online),
|
|
13
|
+
* · returning to the foreground,
|
|
14
|
+
* · a fixed interval while the app runs.
|
|
15
|
+
*
|
|
16
|
+
* Each attempt is gated on `isOnline()` and is cheap when there is nothing to
|
|
17
|
+
* do: `syncHeaders` asks for the present height and fetches only the headers
|
|
18
|
+
* above the local tip (one or two per ten minutes on mainnet). Overlap is the
|
|
19
|
+
* caller's `sync` to prevent (WalletContext's `runHeaderSync` single-flights).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** One block's worth of time: the window never trails the tip by more than about one block while online. */
|
|
23
|
+
export const HEADER_SYNC_INTERVAL_MS = 10 * 60 * 1000
|
|
24
|
+
|
|
25
|
+
export interface HeaderSyncTriggerDeps {
|
|
26
|
+
/** Runs one sync pass. Must not throw into the caller; rejections are swallowed here anyway. */
|
|
27
|
+
sync: () => Promise<unknown>
|
|
28
|
+
isOnline: () => Promise<boolean>
|
|
29
|
+
subscribeOnline: (cb: (online: boolean) => void) => () => void
|
|
30
|
+
subscribeForeground: (cb: () => void) => () => void
|
|
31
|
+
intervalMs?: number
|
|
32
|
+
setInterval?: (fn: () => void, ms: number) => unknown
|
|
33
|
+
clearInterval?: (handle: unknown) => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Starts every trigger; returns the function that stops them all. */
|
|
37
|
+
export function startHeaderSyncTriggers(deps: HeaderSyncTriggerDeps): () => void {
|
|
38
|
+
const schedule = deps.setInterval ?? ((fn, ms) => setInterval(fn, ms))
|
|
39
|
+
const cancel = deps.clearInterval ?? (handle => clearInterval(handle as ReturnType<typeof setInterval>))
|
|
40
|
+
let stopped = false
|
|
41
|
+
|
|
42
|
+
const attempt = async (knownOnline: boolean) => {
|
|
43
|
+
if (stopped) return
|
|
44
|
+
try {
|
|
45
|
+
if (!knownOnline && !(await deps.isOnline())) return
|
|
46
|
+
if (stopped) return
|
|
47
|
+
await deps.sync()
|
|
48
|
+
} catch {
|
|
49
|
+
// Best-effort. The next trigger retries.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const unsubscribeOnline = deps.subscribeOnline(online => {
|
|
54
|
+
if (online) void attempt(true)
|
|
55
|
+
})
|
|
56
|
+
const unsubscribeForeground = deps.subscribeForeground(() => void attempt(false))
|
|
57
|
+
const interval = schedule(() => void attempt(false), deps.intervalMs ?? HEADER_SYNC_INTERVAL_MS)
|
|
58
|
+
|
|
59
|
+
return () => {
|
|
60
|
+
stopped = true
|
|
61
|
+
unsubscribeOnline()
|
|
62
|
+
unsubscribeForeground()
|
|
63
|
+
cancel(interval)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1028,6 +1028,10 @@ const resources = {
|
|
|
1028
1028
|
local_pay_declined_decode: 'The recipient couldn’t read the payment. Nothing was sent — try again.',
|
|
1029
1029
|
local_pay_declined_not_covered:
|
|
1030
1030
|
'The recipient couldn’t verify this payment against the issuer’s records. Nothing was sent.',
|
|
1031
|
+
local_pay_declined_root_unverified:
|
|
1032
|
+
'The recipient’s device couldn’t check this payment against the blockchain. Nothing was sent. If they’re offline, they need to connect briefly, then try again.',
|
|
1033
|
+
local_pay_root_unverified:
|
|
1034
|
+
'This device couldn’t check the payment against the blockchain, so it wasn’t accepted. Connect to the internet briefly, then ask the payer to try again.',
|
|
1031
1035
|
local_pay_broadcast_pending: 'Sent. This device couldn’t get it processed yet — the recipient will.',
|
|
1032
1036
|
local_pay_any_amount: 'Any amount',
|
|
1033
1037
|
local_pay_choose_amount: 'Choose an amount',
|
|
@@ -2011,6 +2015,10 @@ const resources = {
|
|
|
2011
2015
|
local_pay_declined_save: '收款方无法保存这笔付款。本次未发送任何款项 — 请重试。',
|
|
2012
2016
|
local_pay_declined_decode: '收款方无法读取这笔付款。本次未发送任何款项 — 请重试。',
|
|
2013
2017
|
local_pay_declined_not_covered: '收款方无法根据发行方的记录核验这笔付款。本次未发送任何款项。',
|
|
2018
|
+
local_pay_declined_root_unverified:
|
|
2019
|
+
'收款方的设备无法在区块链上核验这笔付款。本次未发送任何款项。如果对方处于离线状态,请让其短暂联网后再试一次。',
|
|
2020
|
+
local_pay_root_unverified:
|
|
2021
|
+
'本设备无法在区块链上核验这笔付款,因此未接受。请短暂连接互联网,然后让付款方重试。',
|
|
2014
2022
|
local_pay_broadcast_pending: '已发送。本设备暂时无法完成处理 — 收款方会完成。',
|
|
2015
2023
|
local_pay_any_amount: '任意金额',
|
|
2016
2024
|
local_pay_choose_amount: '选择金额',
|
|
@@ -3047,6 +3055,10 @@ const resources = {
|
|
|
3047
3055
|
local_pay_declined_decode: 'प्राप्तकर्ता भुगतान पढ़ नहीं सका। कुछ भी नहीं भेजा गया — फिर से कोशिश करें।',
|
|
3048
3056
|
local_pay_declined_not_covered:
|
|
3049
3057
|
'प्राप्तकर्ता इस भुगतान को जारीकर्ता के रिकॉर्ड से सत्यापित नहीं कर सका। कुछ भी नहीं भेजा गया।',
|
|
3058
|
+
local_pay_declined_root_unverified:
|
|
3059
|
+
'प्राप्तकर्ता का डिवाइस ब्लॉकचेन से इस भुगतान की जाँच नहीं कर सका। कुछ भी नहीं भेजा गया। अगर वे ऑफ़लाइन हैं, तो उन्हें थोड़ी देर के लिए कनेक्ट होना होगा, फिर दोबारा कोशिश करें।',
|
|
3060
|
+
local_pay_root_unverified:
|
|
3061
|
+
'यह डिवाइस ब्लॉकचेन से भुगतान की जाँच नहीं कर सका, इसलिए इसे स्वीकार नहीं किया गया। थोड़ी देर के लिए इंटरनेट से कनेक्ट करें, फिर भुगतानकर्ता से दोबारा कोशिश करने को कहें।',
|
|
3050
3062
|
local_pay_broadcast_pending: 'भेज दिया गया। यह डिवाइस इसे अभी प्रोसेस नहीं करा सका — प्राप्तकर्ता करा देगा।',
|
|
3051
3063
|
local_pay_any_amount: 'कोई भी राशि',
|
|
3052
3064
|
local_pay_choose_amount: 'राशि चुनें',
|
|
@@ -4101,6 +4113,10 @@ const resources = {
|
|
|
4101
4113
|
local_pay_declined_decode: 'Quien recibe no pudo leer el pago. No se envió nada; inténtalo de nuevo.',
|
|
4102
4114
|
local_pay_declined_not_covered:
|
|
4103
4115
|
'Quien recibe no pudo verificar este pago con los registros del emisor. No se envió nada.',
|
|
4116
|
+
local_pay_declined_root_unverified:
|
|
4117
|
+
'El dispositivo del destinatario no pudo comprobar este pago en la blockchain. No se envió nada. Si no tiene conexión, debe conectarse un momento y volver a intentarlo.',
|
|
4118
|
+
local_pay_root_unverified:
|
|
4119
|
+
'Este dispositivo no pudo comprobar el pago en la blockchain, así que no se aceptó. Conéctate a internet un momento y pide al pagador que lo intente de nuevo.',
|
|
4104
4120
|
local_pay_broadcast_pending: 'Enviado. Este dispositivo aún no pudo procesarlo; quien recibe lo hará.',
|
|
4105
4121
|
local_pay_any_amount: 'Cualquier importe',
|
|
4106
4122
|
local_pay_choose_amount: 'Elige un importe',
|
|
@@ -5168,6 +5184,10 @@ const resources = {
|
|
|
5168
5184
|
local_pay_declined_decode: 'Le bénéficiaire n’a pas pu lire le paiement. Rien n’a été envoyé — réessayez.',
|
|
5169
5185
|
local_pay_declined_not_covered:
|
|
5170
5186
|
'Le bénéficiaire n’a pas pu vérifier ce paiement auprès des registres de l’émetteur. Rien n’a été envoyé.',
|
|
5187
|
+
local_pay_declined_root_unverified:
|
|
5188
|
+
'L’appareil du destinataire n’a pas pu vérifier ce paiement sur la blockchain. Rien n’a été envoyé. S’il est hors ligne, il doit se connecter un instant, puis réessayer.',
|
|
5189
|
+
local_pay_root_unverified:
|
|
5190
|
+
'Cet appareil n’a pas pu vérifier le paiement sur la blockchain, il n’a donc pas été accepté. Connectez-vous brièvement à Internet, puis demandez au payeur de réessayer.',
|
|
5171
5191
|
local_pay_broadcast_pending:
|
|
5172
5192
|
'Envoyé. Cet appareil n’a pas encore pu le faire traiter — le bénéficiaire s’en chargera.',
|
|
5173
5193
|
local_pay_any_amount: 'Montant libre',
|
|
@@ -6176,6 +6196,10 @@ const resources = {
|
|
|
6176
6196
|
local_pay_declined_decode: 'تعذّر على المستلم قراءة الدفعة. لم يُرسل أي شيء — حاول مرة أخرى.',
|
|
6177
6197
|
local_pay_declined_not_covered:
|
|
6178
6198
|
'تعذّر على المستلم التحقق من هذه الدفعة مقابل سجلات جهة الإصدار. لم يُرسل أي شيء.',
|
|
6199
|
+
local_pay_declined_root_unverified:
|
|
6200
|
+
'لم يتمكن جهاز المستلم من التحقق من هذه الدفعة على البلوكشين. لم يتم إرسال أي شيء. إذا كان غير متصل، فعليه الاتصال بالإنترنت لفترة قصيرة ثم المحاولة مرة أخرى.',
|
|
6201
|
+
local_pay_root_unverified:
|
|
6202
|
+
'لم يتمكن هذا الجهاز من التحقق من الدفعة على البلوكشين، لذا لم يتم قبولها. اتصل بالإنترنت لفترة قصيرة، ثم اطلب من الدافع المحاولة مرة أخرى.',
|
|
6179
6203
|
local_pay_broadcast_pending: 'تم الإرسال. لم يتمكن هذا الجهاز من معالجتها بعد — سيقوم المستلم بذلك.',
|
|
6180
6204
|
local_pay_any_amount: 'أي مبلغ',
|
|
6181
6205
|
local_pay_choose_amount: 'اختر المبلغ',
|
|
@@ -7225,6 +7249,10 @@ const resources = {
|
|
|
7225
7249
|
local_pay_declined_decode: 'Quem recebe não conseguiu ler o pagamento. Nada foi enviado — tente de novo.',
|
|
7226
7250
|
local_pay_declined_not_covered:
|
|
7227
7251
|
'Quem recebe não conseguiu verificar este pagamento nos registros do emissor. Nada foi enviado.',
|
|
7252
|
+
local_pay_declined_root_unverified:
|
|
7253
|
+
'O dispositivo do destinatário não conseguiu verificar este pagamento na blockchain. Nada foi enviado. Se estiver offline, tem de se ligar à internet por instantes e tentar novamente.',
|
|
7254
|
+
local_pay_root_unverified:
|
|
7255
|
+
'Este dispositivo não conseguiu verificar o pagamento na blockchain, por isso não foi aceite. Ligue-se à internet por instantes e peça ao pagador para tentar novamente.',
|
|
7228
7256
|
local_pay_broadcast_pending:
|
|
7229
7257
|
'Enviado. Este aparelho ainda não conseguiu processá-lo — quem recebe vai fazer isso.',
|
|
7230
7258
|
local_pay_any_amount: 'Qualquer valor',
|
|
@@ -8263,6 +8291,10 @@ const resources = {
|
|
|
8263
8291
|
local_pay_declined_decode: 'প্রাপক পেমেন্টটি পড়তে পারেননি। কিছুই পাঠানো হয়নি — আবার চেষ্টা করুন।',
|
|
8264
8292
|
local_pay_declined_not_covered:
|
|
8265
8293
|
'প্রাপক ইস্যুকারীর রেকর্ডের সঙ্গে এই পেমেন্টটি যাচাই করতে পারেননি। কিছুই পাঠানো হয়নি।',
|
|
8294
|
+
local_pay_declined_root_unverified:
|
|
8295
|
+
'প্রাপকের ডিভাইস ব্লকচেইনে এই পেমেন্ট যাচাই করতে পারেনি। কিছুই পাঠানো হয়নি। তারা অফলাইনে থাকলে কিছুক্ষণের জন্য সংযোগ করে আবার চেষ্টা করতে হবে।',
|
|
8296
|
+
local_pay_root_unverified:
|
|
8297
|
+
'এই ডিভাইস ব্লকচেইনে পেমেন্টটি যাচাই করতে পারেনি, তাই এটি গ্রহণ করা হয়নি। কিছুক্ষণের জন্য ইন্টারনেটে সংযোগ করুন, তারপর প্রেরককে আবার চেষ্টা করতে বলুন।',
|
|
8266
8298
|
local_pay_broadcast_pending: 'পাঠানো হয়েছে। এই ডিভাইসটি এখনও প্রসেস করাতে পারেনি — প্রাপক সেটি করবেন।',
|
|
8267
8299
|
local_pay_any_amount: 'যেকোনো পরিমাণ',
|
|
8268
8300
|
local_pay_choose_amount: 'পরিমাণ বেছে নিন',
|
|
@@ -9312,6 +9344,10 @@ const resources = {
|
|
|
9312
9344
|
local_pay_declined_decode: 'Получатель не смог прочитать платёж. Ничего не отправлено — попробуйте ещё раз.',
|
|
9313
9345
|
local_pay_declined_not_covered:
|
|
9314
9346
|
'Получатель не смог сверить этот платёж с записями эмитента. Ничего не отправлено.',
|
|
9347
|
+
local_pay_declined_root_unverified:
|
|
9348
|
+
'Устройство получателя не смогло проверить этот платёж по блокчейну. Ничего не отправлено. Если получатель офлайн, ему нужно ненадолго подключиться к интернету и повторить попытку.',
|
|
9349
|
+
local_pay_root_unverified:
|
|
9350
|
+
'Это устройство не смогло проверить платёж по блокчейну, поэтому он не принят. Ненадолго подключитесь к интернету и попросите плательщика повторить попытку.',
|
|
9315
9351
|
local_pay_broadcast_pending:
|
|
9316
9352
|
'Отправлено. Это устройство пока не смогло провести обработку — это сделает получатель.',
|
|
9317
9353
|
local_pay_any_amount: 'Любая сумма',
|
|
@@ -10361,6 +10397,10 @@ const resources = {
|
|
|
10361
10397
|
local_pay_declined_decode: 'Penerima tidak dapat membaca pembayaran. Tidak ada yang dikirim — coba lagi.',
|
|
10362
10398
|
local_pay_declined_not_covered:
|
|
10363
10399
|
'Penerima tidak dapat memverifikasi pembayaran ini dengan catatan penerbit. Tidak ada yang dikirim.',
|
|
10400
|
+
local_pay_declined_root_unverified:
|
|
10401
|
+
'Perangkat penerima tidak dapat memeriksa pembayaran ini di blockchain. Tidak ada yang dikirim. Jika penerima sedang offline, mereka perlu tersambung sebentar, lalu coba lagi.',
|
|
10402
|
+
local_pay_root_unverified:
|
|
10403
|
+
'Perangkat ini tidak dapat memeriksa pembayaran di blockchain, jadi pembayaran tidak diterima. Sambungkan ke internet sebentar, lalu minta pembayar mencoba lagi.',
|
|
10364
10404
|
local_pay_broadcast_pending: 'Terkirim. Perangkat ini belum bisa memprosesnya — penerima yang akan melakukannya.',
|
|
10365
10405
|
local_pay_any_amount: 'Jumlah bebas',
|
|
10366
10406
|
local_pay_choose_amount: 'Pilih jumlah',
|
|
@@ -11420,6 +11460,10 @@ const resources = {
|
|
|
11420
11460
|
'受取人が支払いを読み取れませんでした。何も送金されていません — もう一度お試しください。',
|
|
11421
11461
|
local_pay_declined_not_covered:
|
|
11422
11462
|
'受取人がこの支払いを発行者の記録と照合できませんでした。何も送金されていません。',
|
|
11463
|
+
local_pay_declined_root_unverified:
|
|
11464
|
+
'受取人の端末がブロックチェーンでこの支払いを確認できませんでした。何も送信されていません。受取人がオフラインの場合は、少しの間インターネットに接続してから、もう一度お試しください。',
|
|
11465
|
+
local_pay_root_unverified:
|
|
11466
|
+
'この端末はブロックチェーンで支払いを確認できなかったため、受け付けませんでした。少しの間インターネットに接続してから、支払者にもう一度試してもらってください。',
|
|
11423
11467
|
local_pay_broadcast_pending: '送金しました。この端末ではまだ処理できていません — 受取人が処理します。',
|
|
11424
11468
|
local_pay_any_amount: '金額は任意',
|
|
11425
11469
|
local_pay_choose_amount: '金額を選択',
|
|
@@ -12489,6 +12533,10 @@ const resources = {
|
|
|
12489
12533
|
local_pay_declined_decode: 'Odbiorca nie mógł odczytać płatności. Nic nie wysłano — spróbuj ponownie.',
|
|
12490
12534
|
local_pay_declined_not_covered:
|
|
12491
12535
|
'Odbiorca nie mógł zweryfikować tej płatności w rejestrach emitenta. Nic nie wysłano.',
|
|
12536
|
+
local_pay_declined_root_unverified:
|
|
12537
|
+
'Urządzenie odbiorcy nie mogło sprawdzić tej płatności w blockchainie. Nic nie zostało wysłane. Jeśli odbiorca jest offline, musi na chwilę połączyć się z internetem, a potem spróbować ponownie.',
|
|
12538
|
+
local_pay_root_unverified:
|
|
12539
|
+
'To urządzenie nie mogło sprawdzić płatności w blockchainie, więc jej nie przyjęło. Połącz się na chwilę z internetem, a potem poproś płacącego o ponowną próbę.',
|
|
12492
12540
|
local_pay_broadcast_pending: 'Wysłano. To urządzenie nie zdołało jeszcze tego przetworzyć — zrobi to odbiorca.',
|
|
12493
12541
|
local_pay_any_amount: 'Dowolna kwota',
|
|
12494
12542
|
local_pay_choose_amount: 'Wybierz kwotę',
|
package/core/localpay/types.ts
CHANGED
|
@@ -40,13 +40,21 @@ export type DeclineReason =
|
|
|
40
40
|
* their own chain admitted before this payment can be accepted by anyone.
|
|
41
41
|
*/
|
|
42
42
|
| 'not_covered'
|
|
43
|
+
/**
|
|
44
|
+
* The transaction's ancestry ends at a block whose merkle root this device
|
|
45
|
+
* could not confirm — usually an offline payee whose header window does not
|
|
46
|
+
* reach that block yet. Retryable once the PAYEE has been online long enough
|
|
47
|
+
* to sync headers. A payer on an older build shows this code verbatim.
|
|
48
|
+
*/
|
|
49
|
+
| 'root_unverified'
|
|
43
50
|
|
|
44
51
|
const DECLINE_REASONS: readonly string[] = [
|
|
45
52
|
'session_mismatch',
|
|
46
53
|
'already_paid',
|
|
47
54
|
'save_failed',
|
|
48
55
|
'decode_failed',
|
|
49
|
-
'not_covered'
|
|
56
|
+
'not_covered',
|
|
57
|
+
'root_unverified'
|
|
50
58
|
]
|
|
51
59
|
|
|
52
60
|
export function isDeclineReason(value: string): value is DeclineReason {
|
package/core/localpay/verify.ts
CHANGED
|
@@ -29,14 +29,17 @@ export type VerifiedPayment =
|
|
|
29
29
|
/**
|
|
30
30
|
* Why a frame could not be shown to pay this device.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
32
|
+
* Four kinds, because the payee's decline reason differs: bytes that are not a
|
|
33
33
|
* transaction are a decode problem the payer can retry from; a transaction that
|
|
34
|
-
* pays someone else is a frame that was never for us;
|
|
34
|
+
* pays someone else is a frame that was never for us; a token frame whose
|
|
35
35
|
* evidence does not COVER its own ancestry is a frame that pays us with a coin
|
|
36
|
-
* the issuer's overlay has never vouched for — retrying it will not help
|
|
37
|
-
*
|
|
36
|
+
* the issuer's overlay has never vouched for — retrying it will not help; and
|
|
37
|
+
* a transaction whose ancestry ends at a block root this device could not
|
|
38
|
+
* confirm, which is what an offline payee with no header for that block sees.
|
|
39
|
+
* That last one is fixed by the PAYEE getting online briefly, so the payer
|
|
40
|
+
* needs to hear which of the four it was.
|
|
38
41
|
*/
|
|
39
|
-
export type FrameVerifyKind = 'unparseable' | 'not_mine' | 'not_covered'
|
|
42
|
+
export type FrameVerifyKind = 'unparseable' | 'not_mine' | 'not_covered' | 'root_unverified'
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
45
|
* The decline code the payer is told, for each way verification can fail.
|
|
@@ -50,6 +53,7 @@ export type FrameVerifyKind = 'unparseable' | 'not_mine' | 'not_covered'
|
|
|
50
53
|
export function declineReasonFor(kind: FrameVerifyKind): DeclineReason {
|
|
51
54
|
if (kind === 'not_mine') return 'session_mismatch'
|
|
52
55
|
if (kind === 'not_covered') return 'not_covered'
|
|
56
|
+
if (kind === 'root_unverified') return 'root_unverified'
|
|
53
57
|
return 'decode_failed'
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -62,17 +66,29 @@ export class FrameVerifyError extends Error {
|
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
/** The wallet
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* `getServices` mirrors the toolbox's own `Wallet`/`WalletStorageManager`
|
|
69
|
-
* shape exactly (`wallet.getServices().getChainTracker()`, not a promise of
|
|
70
|
-
* an object) — the real object NearbyFlow passes in already implements this,
|
|
71
|
-
* so widening the interface needs no new wiring.
|
|
72
|
-
*/
|
|
69
|
+
/** The one wallet capability this module needs: BRC-42 derivation. The
|
|
70
|
+
* permissions manager satisfies it as is. */
|
|
73
71
|
export interface DerivingWallet {
|
|
74
72
|
getPublicKey(args: unknown, originator?: string): Promise<{ publicKey: string }>
|
|
75
|
-
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* What `verifyFramePayment` needs from this device, as two separate
|
|
77
|
+
* dependencies rather than one object that must happen to provide both: the
|
|
78
|
+
* permissions manager derives keys but holds no chain services, and a single
|
|
79
|
+
* "wallet" parameter asking for both is how a missing `getServices()` once
|
|
80
|
+
* reached production as a TypeError on every Nearby BSV payment.
|
|
81
|
+
*/
|
|
82
|
+
export interface FrameVerifyDeps {
|
|
83
|
+
wallet: DerivingWallet
|
|
84
|
+
/**
|
|
85
|
+
* The chain tracker the BSV branch's SPV check walks merkle paths against —
|
|
86
|
+
* the same one `internalizeAction` consults, i.e.
|
|
87
|
+
* `storage.getServices().getChainTracker()`. In the app that is the
|
|
88
|
+
* offline-first tracker over the local header window, so an offline payee
|
|
89
|
+
* can still verify. Not read for a token frame.
|
|
90
|
+
*/
|
|
91
|
+
chainTracker: ChainTracker
|
|
76
92
|
}
|
|
77
93
|
|
|
78
94
|
/**
|
|
@@ -91,7 +107,7 @@ export interface DerivingWallet {
|
|
|
91
107
|
* this module enforces on itself — a "queued nothing" decline, by construction.
|
|
92
108
|
*/
|
|
93
109
|
export async function verifyFramePayment(
|
|
94
|
-
wallet:
|
|
110
|
+
{ wallet, chainTracker }: FrameVerifyDeps,
|
|
95
111
|
frame: PaymentFrame,
|
|
96
112
|
originator: string,
|
|
97
113
|
/**
|
|
@@ -187,14 +203,35 @@ export async function verifyFramePayment(
|
|
|
187
203
|
// input, which is the desired refusal for an ancestor this device cannot
|
|
188
204
|
// actually verify. No feeModel is passed, so a legitimate low-fee frame
|
|
189
205
|
// is never refused on fee grounds — only on SPV/script/value grounds.
|
|
190
|
-
|
|
206
|
+
//
|
|
207
|
+
// The tracker is wrapped only to notice a refused merkle root, so that
|
|
208
|
+
// refusal can be told apart from a bad script or value: `tx.verify`
|
|
209
|
+
// returns false for both. A refused root is what an offline payee sees
|
|
210
|
+
// for a block its header window does not reach yet (and what anyone sees
|
|
211
|
+
// for a forged proof), and the remedy — the payee going online — is
|
|
212
|
+
// different from a malformed transaction's.
|
|
213
|
+
let rootRefused = false
|
|
214
|
+
const observed: ChainTracker = {
|
|
215
|
+
isValidRootForHeight: async (root, height) => {
|
|
216
|
+
const ok = await chainTracker.isValidRootForHeight(root, height)
|
|
217
|
+
if (!ok) rootRefused = true
|
|
218
|
+
return ok
|
|
219
|
+
},
|
|
220
|
+
currentHeight: async () => await chainTracker.currentHeight()
|
|
221
|
+
}
|
|
222
|
+
// A refused root surfaces as a throw ("Invalid merkle path"), so both exits
|
|
223
|
+
// check the flag.
|
|
224
|
+
const rootUnverified = () =>
|
|
225
|
+
new FrameVerifyError('root_unverified', 'a merkle root in the frame could not be confirmed on this device')
|
|
191
226
|
let verified: boolean
|
|
192
227
|
try {
|
|
193
|
-
verified = await tx.verify(
|
|
228
|
+
verified = await tx.verify(observed)
|
|
194
229
|
} catch (e) {
|
|
230
|
+
if (rootRefused) throw rootUnverified()
|
|
195
231
|
throw new FrameVerifyError('unparseable', `transaction failed SPV/script verification: ${messageOf(e)}`)
|
|
196
232
|
}
|
|
197
233
|
if (!verified) {
|
|
234
|
+
if (rootRefused) throw rootUnverified()
|
|
198
235
|
throw new FrameVerifyError('unparseable', 'transaction failed SPV/script verification')
|
|
199
236
|
}
|
|
200
237
|
|
package/core/pay/rails/nearby.ts
CHANGED
package/package.json
CHANGED
|
@@ -108,7 +108,7 @@ import {
|
|
|
108
108
|
import Animated, { FadeIn, FadeInDown, useReducedMotion } from 'react-native-reanimated'
|
|
109
109
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
110
110
|
import { useTranslation } from 'react-i18next'
|
|
111
|
-
import { Beef, createNonce, type WalletInterface } from '@bsv/sdk'
|
|
111
|
+
import { Beef, createNonce, type ChainTracker, type WalletInterface } from '@bsv/sdk'
|
|
112
112
|
import { finalizeDelivery } from '../../../core/localpay/build'
|
|
113
113
|
import { queuePendingAbort, queueDeclinedAbortWatch } from '../../../core/localpay/pendingAborts'
|
|
114
114
|
import type { PendingAbortTagWallet } from '../../../core/localpay/pendingAbortAuthority'
|
|
@@ -179,8 +179,8 @@ import {
|
|
|
179
179
|
type RadioKind,
|
|
180
180
|
type Session,
|
|
181
181
|
FrameVerifyError,
|
|
182
|
+
declineReasonFor,
|
|
182
183
|
verifyFramePayment,
|
|
183
|
-
type DerivingWallet,
|
|
184
184
|
type VerifiedPayment,
|
|
185
185
|
type CoverVerifier,
|
|
186
186
|
type SessionAsset
|
|
@@ -343,7 +343,8 @@ const DECLINE_KEYS: Record<DeclineReason, string> = {
|
|
|
343
343
|
already_paid: 'local_pay_declined_already_paid',
|
|
344
344
|
save_failed: 'local_pay_declined_save',
|
|
345
345
|
decode_failed: 'local_pay_declined_decode',
|
|
346
|
-
not_covered: 'local_pay_declined_not_covered'
|
|
346
|
+
not_covered: 'local_pay_declined_not_covered',
|
|
347
|
+
root_unverified: 'local_pay_declined_root_unverified'
|
|
347
348
|
}
|
|
348
349
|
|
|
349
350
|
/**
|
|
@@ -978,9 +979,26 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
978
979
|
// device derives — so it is both the real number and a proof the
|
|
979
980
|
// payment is ours to spend. Nothing has latched and nothing has been
|
|
980
981
|
// written, so every failure here is a provable "queued nothing".
|
|
982
|
+
//
|
|
983
|
+
// Keys come from the permissions manager; the BSV branch's SPV check
|
|
984
|
+
// takes its chain tracker from `storage`, the same services every
|
|
985
|
+
// other chain query here uses. Without either nothing can be shown
|
|
986
|
+
// to be ours, so the frame is declined having queued nothing.
|
|
987
|
+
let chainTracker: ChainTracker | null = null
|
|
988
|
+
try {
|
|
989
|
+
chainTracker = storage ? await storage.getServices().getChainTracker() : null
|
|
990
|
+
} catch {
|
|
991
|
+
chainTracker = null
|
|
992
|
+
}
|
|
993
|
+
if (!wallet || !chainTracker) {
|
|
994
|
+
void confirm?.(false, 'save_failed')
|
|
995
|
+
settlingRef.current = false
|
|
996
|
+
scanLatchRef.current = false
|
|
997
|
+
return
|
|
998
|
+
}
|
|
981
999
|
let verified: VerifiedPayment
|
|
982
1000
|
try {
|
|
983
|
-
verified = await verifyFramePayment(wallet
|
|
1001
|
+
verified = await verifyFramePayment({ wallet, chainTracker }, frame, adminOriginator, {
|
|
984
1002
|
// A token frame with no verifier is REFUSED, not credited: no
|
|
985
1003
|
// verifier is no evidence, and verify.ts enforces that. Absent on a
|
|
986
1004
|
// BSV request, where it is never read.
|
|
@@ -994,11 +1012,16 @@ function NearbyFlow({ role: initialRole, onExit, initialSession, initialRequest,
|
|
|
994
1012
|
} catch (e) {
|
|
995
1013
|
// `not_mine` is a frame that was never for this request; `unparseable`
|
|
996
1014
|
// is bytes that are not a transaction; `not_covered` is a token frame
|
|
997
|
-
// whose evidence does not cover its own ancestry
|
|
998
|
-
//
|
|
999
|
-
//
|
|
1015
|
+
// whose evidence does not cover its own ancestry; `root_unverified` is
|
|
1016
|
+
// a block this device could not confirm (offline, headers behind). All
|
|
1017
|
+
// four leave the request LIVE and unspent, exactly as a nonce mismatch
|
|
1018
|
+
// does, so the genuine payer can still complete.
|
|
1000
1019
|
const kind = e instanceof FrameVerifyError ? e.kind : 'unparseable'
|
|
1001
|
-
void confirm?.(false, kind
|
|
1020
|
+
void confirm?.(false, declineReasonFor(kind))
|
|
1021
|
+
if (kind === 'root_unverified') {
|
|
1022
|
+
// Not a scanning mistake either: the remedy is on THIS device.
|
|
1023
|
+
setNotice({ text: t('local_pay_root_unverified'), tone: 'warning' })
|
|
1024
|
+
}
|
|
1002
1025
|
if (kind === 'not_covered') {
|
|
1003
1026
|
// The one refusal that is about the ISSUER's records rather than
|
|
1004
1027
|
// about this pair of devices, so it says so instead of reading as a
|