@bsv/expo-wallet-toolbox 0.4.0 → 0.7.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 +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- 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/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- 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/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -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/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- 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 +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- 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 +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- 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 +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- 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 +100 -0
- package/ui/txStatus.ts +43 -5
- 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
package/core/pay/rails/handle.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { CreditFailureKind } from '../creditErrors'
|
|
|
23
23
|
import { abbreviateKey } from '../counterparty'
|
|
24
24
|
import { isDuplicateMessageError, sendControlMessage, type ResendReason } from '../../peerpay/control'
|
|
25
25
|
import { TaskDrainOutbox } from '../../monitor/TaskDrainOutbox'
|
|
26
|
+
import type { MandalaRuntime, TokenSendResult } from '../../mandala/runtime'
|
|
26
27
|
|
|
27
28
|
export const MESSAGE_BOX_URL_KEY = 'message_box_url'
|
|
28
29
|
export const DEFAULT_MESSAGE_BOX_URL = 'https://gmb.bsvblockchain.tech'
|
|
@@ -66,17 +67,31 @@ interface InternalizingWallet {
|
|
|
66
67
|
/**
|
|
67
68
|
* A shareable BRC-125 payment link for a handle.
|
|
68
69
|
*
|
|
69
|
-
* `peerpay:<key>[?sats=<n>][&url=<host>]
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* `peerpay:<key>[?sats=<n>][&url=<host>]` for BSV, or
|
|
71
|
+
* `peerpay:<key>?asset=<txid.vout>[&amount=<base units>][&url=<host>]` for a
|
|
72
|
+
* token — the same forms the app parses (parsePeerPayURI.ts) and routes
|
|
73
|
+
* (+native-intent.ts in the host app). A non-positive figure emits no
|
|
74
|
+
* `sats`/`amount` — a zero would be an invalid link, and an open request is
|
|
75
|
+
* exactly the absence of a figure. A token request never carries `sats`: the
|
|
76
|
+
* two are different money, and the parser refuses a link that names both.
|
|
77
|
+
* `url` is this app's extension: the payee's message-box host, so the payer
|
|
78
|
+
* can skip the overlay lookup. Omitted for the no-server sentinel and for blank.
|
|
75
79
|
*/
|
|
76
|
-
export function peerPayLinkFor(
|
|
80
|
+
export function peerPayLinkFor(
|
|
81
|
+
identityKey: string,
|
|
82
|
+
sats?: number,
|
|
83
|
+
messageBoxUrl?: string,
|
|
84
|
+
token?: { assetId: string; baseUnits?: number }
|
|
85
|
+
): string {
|
|
77
86
|
const params: string[] = []
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
if (token) {
|
|
88
|
+
params.push(`asset=${token.assetId.toLowerCase()}`)
|
|
89
|
+
const units = token.baseUnits !== undefined ? Math.round(Number(token.baseUnits)) : NaN
|
|
90
|
+
if (Number.isFinite(units) && units > 0) params.push(`amount=${units}`)
|
|
91
|
+
} else {
|
|
92
|
+
const amount = sats !== undefined ? Math.round(Number(sats)) : NaN
|
|
93
|
+
if (Number.isFinite(amount) && amount > 0) params.push(`sats=${amount}`)
|
|
94
|
+
}
|
|
80
95
|
const host = (messageBoxUrl ?? '').trim().replace(/\/+$/, '')
|
|
81
96
|
if (host && host !== NO_MESSAGE_BOX) params.push(`url=${encodeURIComponent(host)}`)
|
|
82
97
|
const base = `peerpay:${identityKey.toLowerCase()}`
|
|
@@ -567,6 +582,70 @@ export async function cancelOutboxPayment(args: {
|
|
|
567
582
|
return { aborted }
|
|
568
583
|
}
|
|
569
584
|
|
|
585
|
+
// ── The token half of the handle rail (offline-settlement spec §4.5) ──
|
|
586
|
+
//
|
|
587
|
+
// Same rail, different pipeline. A satoshi payment is minted here and delivered
|
|
588
|
+
// through the `payment_inbox` PeerPay box; a Mandala token payment is minted by
|
|
589
|
+
// `@bsv/mandala`'s own overlay-first transfer and delivered through the
|
|
590
|
+
// `'mandala-payments'` box — and unlike the nearby rail, the handle rail's
|
|
591
|
+
// SENDER is online by construction, so it submits before it notifies and can
|
|
592
|
+
// forward the tip's own σ_I in the body. That is why `TokenSendResult` carries
|
|
593
|
+
// `settled`: it is the difference between "sent · settling" and "sent · settled
|
|
594
|
+
// with {{issuer}}" on the payer's screen, decided by evidence rather than hope.
|
|
595
|
+
//
|
|
596
|
+
// Neither function reaches into the runtime's internals: both take the
|
|
597
|
+
// narrowest slice of `MandalaRuntime` they need, so this module keeps knowing
|
|
598
|
+
// nothing about overlays, baskets or settlement rows.
|
|
599
|
+
|
|
600
|
+
/** The slice of `MandalaRuntime` the handle rail uses. */
|
|
601
|
+
export type HandleTokenRuntime = Pick<
|
|
602
|
+
MandalaRuntime,
|
|
603
|
+
'available' | 'recipientRefusal' | 'sendToHandle' | 'receiveFromInbox'
|
|
604
|
+
>
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Send tokens to a handle.
|
|
608
|
+
*
|
|
609
|
+
* Every refusal this function can make itself is made BEFORE the runtime is
|
|
610
|
+
* touched — no runtime, wrong network, a recipient that is not an identity key
|
|
611
|
+
* — because each of those is a fact about the request, not about the overlay,
|
|
612
|
+
* and an overlay round-trip cannot change any of them.
|
|
613
|
+
*/
|
|
614
|
+
export async function sendTokenViaHandle(args: {
|
|
615
|
+
runtime: HandleTokenRuntime | undefined
|
|
616
|
+
recipient: string
|
|
617
|
+
assetId: string
|
|
618
|
+
baseUnits: number
|
|
619
|
+
}): Promise<TokenSendResult> {
|
|
620
|
+
const { runtime, recipient, assetId, baseUnits } = args
|
|
621
|
+
if (!runtime?.available) {
|
|
622
|
+
return { kind: 'unavailable', message: 'Stablecoins are not available on this network' }
|
|
623
|
+
}
|
|
624
|
+
const refusal = runtime.recipientRefusal(recipient)
|
|
625
|
+
if (refusal) return { kind: 'refused', code: 'ERR_RECIPIENT', message: refusal }
|
|
626
|
+
return await runtime.sendToHandle({ assetId, recipientIdentityKey: recipient, baseUnits })
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* The Mandala half of the handle rail's receive drain.
|
|
631
|
+
*
|
|
632
|
+
* Called beside `creditInboxOnce` on the same tick: the two inboxes are
|
|
633
|
+
* different message boxes on the same server, and a wallet that drained only
|
|
634
|
+
* one would leave real money sitting in the other. Never throws — a MessageBox
|
|
635
|
+
* that is down must not take the satoshi inbox down with it.
|
|
636
|
+
*/
|
|
637
|
+
export async function drainMandalaInbox(
|
|
638
|
+
runtime: HandleTokenRuntime | undefined
|
|
639
|
+
): Promise<{ credited: number; failed: number }> {
|
|
640
|
+
if (!runtime?.available) return { credited: 0, failed: 0 }
|
|
641
|
+
try {
|
|
642
|
+
return await runtime.receiveFromInbox()
|
|
643
|
+
} catch (e) {
|
|
644
|
+
console.warn('[mandala] the token inbox drain failed:', e instanceof Error ? e.message : String(e))
|
|
645
|
+
return { credited: 0, failed: 0 }
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
570
649
|
/**
|
|
571
650
|
* Whether an error from the handle rail means "the message box server could not
|
|
572
651
|
* be reached" rather than anything about the payment itself. The raw shapes —
|
package/core/pay/rails/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
validatePeerPayURI,
|
|
14
14
|
type PeerPayValidationResult,
|
|
15
15
|
peerPayValidationMessage,
|
|
16
|
+
peerPayHasErrors,
|
|
16
17
|
isCompressedPublicKey
|
|
17
18
|
} from '../../parsePeerPayURI'
|
|
18
19
|
|
|
@@ -21,10 +22,15 @@ export { isCompressedPublicKey }
|
|
|
21
22
|
|
|
22
23
|
export type RailId = 'nearby' | 'handle' | 'address'
|
|
23
24
|
|
|
24
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* How a counterparty was identified. Each variant carries only what its rail
|
|
27
|
+
* needs. A handle may carry a figure in exactly one money: `sats` (BSV), or
|
|
28
|
+
* `asset` (a token's genesis outpoint) with `amount` in its base units —
|
|
29
|
+
* `asset` alone is an open token request.
|
|
30
|
+
*/
|
|
25
31
|
export type PayTarget =
|
|
26
32
|
| { kind: 'nearby'; session: Session }
|
|
27
|
-
| { kind: 'handle'; identityKey: string; sats?: number; messageBoxUrl?: string }
|
|
33
|
+
| { kind: 'handle'; identityKey: string; sats?: number; asset?: string; amount?: number; messageBoxUrl?: string }
|
|
28
34
|
| { kind: 'address'; address: string; sats?: number }
|
|
29
35
|
|
|
30
36
|
/** Six cell names. Since the universal input, `pay-*` are deep-link aliases that all open the send form; `get-*` open one receive method directly. */
|
|
@@ -98,18 +104,20 @@ export type RecipientInput =
|
|
|
98
104
|
| { kind: 'empty' }
|
|
99
105
|
| { kind: 'address'; address: string }
|
|
100
106
|
| { kind: 'invalid_address' }
|
|
101
|
-
| { kind: 'handle'; identityKey: string; sats?: number; messageBoxUrl?: string }
|
|
107
|
+
| { kind: 'handle'; identityKey: string; sats?: number; asset?: string; amount?: number; messageBoxUrl?: string }
|
|
102
108
|
| { kind: 'invalid_link'; message: string }
|
|
103
109
|
| { kind: 'search'; query: string }
|
|
104
110
|
|
|
105
111
|
function handleFromPeerPay(result: PeerPayValidationResult): RecipientInput {
|
|
106
|
-
if (!result.identityKey || result
|
|
112
|
+
if (!result.identityKey || peerPayHasErrors(result)) {
|
|
107
113
|
return { kind: 'invalid_link', message: peerPayValidationMessage(result) ?? 'Invalid peerpay link' }
|
|
108
114
|
}
|
|
109
115
|
return {
|
|
110
116
|
kind: 'handle',
|
|
111
117
|
identityKey: result.identityKey,
|
|
112
118
|
...(result.sats !== undefined ? { sats: result.sats } : {}),
|
|
119
|
+
...(result.asset !== undefined ? { asset: result.asset } : {}),
|
|
120
|
+
...(result.amount !== undefined ? { amount: result.amount } : {}),
|
|
113
121
|
...(result.messageBoxUrl ? { messageBoxUrl: result.messageBoxUrl } : {})
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -151,11 +159,13 @@ export function classifyScan(raw: string): PayTarget | null {
|
|
|
151
159
|
|
|
152
160
|
if (text.toLowerCase().startsWith('peerpay:')) {
|
|
153
161
|
const result = validatePeerPayURI(text)
|
|
154
|
-
if (!result.identityKey || result
|
|
162
|
+
if (!result.identityKey || peerPayHasErrors(result)) return null
|
|
155
163
|
return {
|
|
156
164
|
kind: 'handle',
|
|
157
165
|
identityKey: result.identityKey,
|
|
158
|
-
sats: result.sats,
|
|
166
|
+
...(result.sats !== undefined ? { sats: result.sats } : {}),
|
|
167
|
+
...(result.asset !== undefined ? { asset: result.asset } : {}),
|
|
168
|
+
...(result.amount !== undefined ? { amount: result.amount } : {}),
|
|
159
169
|
...(result.messageBoxUrl ? { messageBoxUrl: result.messageBoxUrl } : {})
|
|
160
170
|
}
|
|
161
171
|
}
|
package/core/pay/rails/nearby.ts
CHANGED
|
@@ -42,16 +42,126 @@ export {
|
|
|
42
42
|
markSessionSpent,
|
|
43
43
|
processPending,
|
|
44
44
|
savePending,
|
|
45
|
-
type PendingPayment
|
|
45
|
+
type PendingPayment,
|
|
46
|
+
type TokenCreditedHook
|
|
46
47
|
} from '../../localpay/pending'
|
|
47
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The two settlement-durability hooks the rail's callers wire (§4.2, §4.3).
|
|
50
|
+
*
|
|
51
|
+
* `TokenHeldHook` runs BEFORE the receiver's `internalizeAction`, so the
|
|
52
|
+
* `token_settlements` row exists when guard #2 looks for it;
|
|
53
|
+
* `TokenHandedOverHook` runs at the payer's park/hold with the frame still in
|
|
54
|
+
* plaintext, so the payer's own row does not depend on a session key this
|
|
55
|
+
* process only holds in memory. Re-exported here because the rail is the single
|
|
56
|
+
* import site for nearby, and both are implemented by the Mandala runtime and
|
|
57
|
+
* consumed by `processPending` / `holdSentPaymentOffline` respectively.
|
|
58
|
+
*/
|
|
59
|
+
export type {
|
|
60
|
+
AdmissionVerifier,
|
|
61
|
+
EvidenceFrame,
|
|
62
|
+
EvidenceTokenBlock,
|
|
63
|
+
TokenHandedOverHook,
|
|
64
|
+
TokenHandoverState,
|
|
65
|
+
TokenHeldHook
|
|
66
|
+
} from '../../mandala/types'
|
|
67
|
+
export {
|
|
68
|
+
buildPaymentFrame,
|
|
69
|
+
finalizeDelivery,
|
|
70
|
+
selectTokenCoins,
|
|
71
|
+
type BuiltPayment,
|
|
72
|
+
type DeliveryOutcome,
|
|
73
|
+
type LockToPayee,
|
|
74
|
+
type SelectedTokenCoin,
|
|
75
|
+
type TokenBuildDeps
|
|
76
|
+
} from '../../localpay/build'
|
|
48
77
|
export {
|
|
49
78
|
FrameVerifyError,
|
|
79
|
+
declineReasonFor,
|
|
50
80
|
verifyFramePayment,
|
|
51
81
|
type DerivingWallet,
|
|
52
|
-
type FrameVerifyKind
|
|
82
|
+
type FrameVerifyKind,
|
|
83
|
+
type VerifiedPayment
|
|
53
84
|
} from '../../localpay/verify'
|
|
54
|
-
|
|
85
|
+
/**
|
|
86
|
+
* The token half of the rail (offline-settlement spec §9).
|
|
87
|
+
*
|
|
88
|
+
* Same three moves the BSV path makes — build, hand over, hold — with the
|
|
89
|
+
* evidence that makes them safe offline attached to each:
|
|
90
|
+
*
|
|
91
|
+
* · PAYER: `buildPaymentFrame` with `TokenBuildDeps` selects from
|
|
92
|
+
* `MANDALA_BASKET`, builds `noSend`, and attaches the AdmissionBundle
|
|
93
|
+
* `assembleBundle` collected. It submits NOTHING — hand-over comes first,
|
|
94
|
+
* unconditionally, so a face-to-face payment never waits on a network.
|
|
95
|
+
* `finalizeDelivery` then holds and returns `broadcast: 'pending'` for
|
|
96
|
+
* every token payment, online or off (guard #1): the drain is the only
|
|
97
|
+
* path to a real broadcast, and only after admission.
|
|
98
|
+
* · PAYEE: `verifyFramePayment` proves the output is ours and then runs
|
|
99
|
+
* `coverFromFrame` against the injected verifier; a frame that fails COVER
|
|
100
|
+
* is refused at hand-over with `'not_covered'`, exactly like a
|
|
101
|
+
* `not_mine`/`unparseable` decode failure. A frame that passes is credited
|
|
102
|
+
* by `processPending` as a basket insertion, and `onTokenCredited` is where
|
|
103
|
+
* the settlement row and the frame's evidence are persisted.
|
|
104
|
+
* · BOTH: `readSettlementAck` reads σ_I off the confirm channel — verified
|
|
105
|
+
* before it is believed, absent if it does not (FIX H) — and
|
|
106
|
+
* `tokenSendState` turns that into the payer's 'sent-settling' /
|
|
107
|
+
* 'sent-settled' copy.
|
|
108
|
+
*/
|
|
109
|
+
export {
|
|
110
|
+
SETTLEMENT_ACK_PREFIX,
|
|
111
|
+
decodeSettlementAck,
|
|
112
|
+
encodeSettlementAck,
|
|
113
|
+
readSettlementAck,
|
|
114
|
+
tokenSendState,
|
|
115
|
+
type SettlementAck,
|
|
116
|
+
type TokenSendState,
|
|
117
|
+
type VerifyAdmissionFn
|
|
118
|
+
} from '../../localpay/settlementAck'
|
|
119
|
+
export {
|
|
120
|
+
MANDALA_BASKET,
|
|
121
|
+
assembleBundle,
|
|
122
|
+
coverFromFrame,
|
|
123
|
+
tokenParentsOf,
|
|
124
|
+
type AdmissionBundle,
|
|
125
|
+
type BundleStore,
|
|
126
|
+
type CoverBundle,
|
|
127
|
+
type CoverTip,
|
|
128
|
+
type CoverVerifier
|
|
129
|
+
} from '../../mandala/bundle'
|
|
130
|
+
/**
|
|
131
|
+
* The session key the drain cannot hold for itself.
|
|
132
|
+
*
|
|
133
|
+
* A payer's `offline_actions.framePayload` is SEALED with the nearby session's
|
|
134
|
+
* PSK, and the drain deliberately never persists that key — so the flow that
|
|
135
|
+
* mints or scans a session hands it to `rememberSessionPsk` for this process's
|
|
136
|
+
* lifetime, and the drain's decoder tries the keys it was given. See
|
|
137
|
+
* `offline/tokenFrames.ts` for exactly what an unopened row costs (a race the
|
|
138
|
+
* payer is always safe to lose: the RECIPIENT submits).
|
|
139
|
+
*/
|
|
140
|
+
export {
|
|
141
|
+
MAX_REMEMBERED_SESSION_KEYS,
|
|
142
|
+
forgetSessionPsks,
|
|
143
|
+
rememberSessionPsk,
|
|
144
|
+
sealedFramePayloadDecoder
|
|
145
|
+
} from '../../offline/tokenFrames'
|
|
146
|
+
/**
|
|
147
|
+
* The payer's three durability moves, all from one place.
|
|
148
|
+
*
|
|
149
|
+
* `holdSentPaymentOffline` was the only one re-exported here while
|
|
150
|
+
* `parkSentPaymentOffline` and `releaseParkedPayment` were reached through the
|
|
151
|
+
* package root — which is the second implementation path this module exists to
|
|
152
|
+
* prevent. `holdSentPaymentOffline` and `parkSentPaymentOffline` take the same
|
|
153
|
+
* `{ frame, onTokenHandedOver }` deps (they create the settlement row from the
|
|
154
|
+
* plaintext frame); `releaseParkedPayment` takes none — the row already exists
|
|
155
|
+
* from the park, so it only advances it parked → handed_over. All three are the
|
|
156
|
+
* same fork of one decision (confirm now, keep for later, confirm later), so
|
|
157
|
+
* they belong on one import site.
|
|
158
|
+
*/
|
|
159
|
+
export {
|
|
160
|
+
holdSentPaymentOffline,
|
|
161
|
+
parkSentPaymentOffline,
|
|
162
|
+
releaseParkedPayment,
|
|
163
|
+
type TokenHandoverDeps
|
|
164
|
+
} from '../../offline/payerHold'
|
|
55
165
|
export { awdlTransport } from '../../localpay/transport/awdl'
|
|
56
166
|
export { nearbyTransport } from '../../localpay/transport/nearby'
|
|
57
167
|
export { bleTransport } from '../../localpay/transport/ble'
|
package/core/pay/recordProof.ts
CHANGED
|
@@ -10,12 +10,8 @@
|
|
|
10
10
|
* no req, the proof is written directly: a proven_tx row (the toolbox's own
|
|
11
11
|
* `findOrInsertProvenTx` shape) and the transaction promoted to `completed`.
|
|
12
12
|
*/
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
TableProvenTxReq,
|
|
16
|
-
TableTransaction
|
|
17
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/tables'
|
|
18
|
-
import type { UpdateProvenTxReqWithNewProvenTxArgs } from '@bsv/wallet-toolbox-mobile/out/src/sdk/WalletStorage.interfaces'
|
|
13
|
+
import type { TableProvenTx, TableProvenTxReq, TableTransaction } from '@bsv/wallet-toolbox-mobile'
|
|
14
|
+
import type { UpdateProvenTxReqWithNewProvenTxArgs } from '../toolboxTypes'
|
|
19
15
|
|
|
20
16
|
export interface ProofStorage {
|
|
21
17
|
findProvenTxReqs(args: {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Beef, Transaction, Utils } from '@bsv/sdk'
|
|
2
|
-
import type {
|
|
3
|
-
PostBeefResult,
|
|
4
|
-
PostTxResultForTxid
|
|
5
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/sdk'
|
|
2
|
+
import type { PostBeefResult, PostTxResultForTxid } from '../toolboxTypes'
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* ARC intermediate statuses that still mean "accepted for relay".
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Argument-size cap for wallets handed to EXTERNAL callers.
|
|
3
3
|
*
|
|
4
|
-
* Composed at each external surface exactly like guardVaultAccess
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* neither a permission prompt nor a storage touch.
|
|
4
|
+
* Composed at each external surface exactly like guardVaultAccess. The current
|
|
5
|
+
* app exposes desktop-pairing and saved-connection WalletClients; an embedding
|
|
6
|
+
* host must wrap any additional bridge it adds. Wrap outside the vault guard so
|
|
7
|
+
* a refusal costs neither a permission prompt nor a storage touch.
|
|
8
8
|
*
|
|
9
9
|
* WHERE THIS MUST NOT GO. Not in guardVaultAccess, not in SimpleWalletManager,
|
|
10
|
-
* not in WalletPermissionsManager, and not in the toolbox.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* any future tightening of these limits on the shared path.
|
|
10
|
+
* not in WalletPermissionsManager, and not in the toolbox. Vault transactions
|
|
11
|
+
* carry roughly 45 KB R1C locks and up to 2.5 KB unlocks per selected input;
|
|
12
|
+
* applying general bridge limits on the internal path could break them. The
|
|
13
|
+
* exemption keeps the vault insulated from future tightening of those limits.
|
|
15
14
|
*
|
|
16
15
|
* The vault is exempt STRUCTURALLY rather than by an originator comparison: it
|
|
17
16
|
* calls managers.permissionsManager directly and never receives a capped wallet.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BsvExchangeRate } from '@bsv/wallet-toolbox-mobile/out/src/sdk'
|
|
2
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import type { BsvExchangeRate } from '../toolboxTypes'
|
|
3
3
|
|
|
4
4
|
// Shared with context/ExchangeRateContext.tsx so a single cache serves both the
|
|
5
5
|
// fiat-display UI and the wallet-build seed. Same key + same { usdPerBsv } shape.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ADMIN_ORIGINATOR } from '../config'
|
|
2
|
+
|
|
3
|
+
export interface ExternalOrigin {
|
|
4
|
+
/** Canonical HTTPS origin used for relay discovery and persistence. */
|
|
5
|
+
origin: string
|
|
6
|
+
/** Canonical host (and non-default port) used by WalletClient permissions. */
|
|
7
|
+
originator: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Parse an untrusted pairing origin at the external/internal trust boundary.
|
|
12
|
+
*
|
|
13
|
+
* Pairing relies on TLS for control of the advertised origin, so accepting a
|
|
14
|
+
* fallback string, cleartext URL, credentials, or a URL with path/query data
|
|
15
|
+
* turns an authorization identity into attacker-controlled text. Every fresh
|
|
16
|
+
* pairing and reconnect must pass through this function before constructing a
|
|
17
|
+
* WalletClient or fetching relay metadata.
|
|
18
|
+
*/
|
|
19
|
+
export function parseExternalOrigin(raw: string): ExternalOrigin {
|
|
20
|
+
let url: URL
|
|
21
|
+
try {
|
|
22
|
+
url = new URL(raw)
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error('Origin URL is not valid')
|
|
25
|
+
}
|
|
26
|
+
if (url.protocol !== 'https:') throw new Error('Origin must use https://')
|
|
27
|
+
if (!url.hostname) throw new Error('Origin must include a hostname')
|
|
28
|
+
if (url.username || url.password) throw new Error('Origin must not include credentials')
|
|
29
|
+
if (url.pathname !== '/' || url.search || url.hash) {
|
|
30
|
+
throw new Error('Origin must be a bare HTTPS origin without a path, query, or fragment')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const originator = url.port ? `${url.hostname.toLowerCase()}:${url.port}` : url.hostname.toLowerCase()
|
|
34
|
+
// The wallet's own authority lives in the reserved `.invalid` TLD (see
|
|
35
|
+
// ADMIN_ORIGINATOR). No real origin can be served from it, so refuse the
|
|
36
|
+
// whole TLD rather than only the exact label.
|
|
37
|
+
const hostname = url.hostname.toLowerCase().replace(/\.$/, '')
|
|
38
|
+
if (hostname === 'invalid' || hostname.endsWith('.invalid') || originator === ADMIN_ORIGINATOR.toLowerCase()) {
|
|
39
|
+
throw new Error('Origin is reserved for the wallet')
|
|
40
|
+
}
|
|
41
|
+
return { origin: url.origin, originator }
|
|
42
|
+
}
|