@bsv/expo-wallet-toolbox 0.2.0 → 0.3.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/README.md +26 -1
- package/core/amountFormatHelpers.ts +16 -30
- package/core/context/WalletContext.tsx +15 -3
- package/core/i18n/translations.tsx +12 -0
- package/core/index.ts +16 -5
- package/core/localpay/build.ts +4 -1
- package/core/localpay/pending.ts +5 -2
- package/core/pay/counterparty.ts +159 -0
- package/core/pay/creditInbox.ts +0 -3
- package/core/pay/patp.ts +181 -0
- package/core/pay/rails/address.ts +47 -7
- package/core/pay/rails/handle.ts +24 -14
- package/core/peerpay/handleResendRequests.ts +1 -2
- package/core/storage/StorageExpoSQLite.ts +37 -0
- package/core/storage/methods/listActionsSql.ts +9 -0
- package/core/theme/sigilPalette.ts +83 -0
- package/package.json +3 -1
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/pay/OfflineNotice.tsx +8 -0
- package/ui/components/ui/AppLogo.tsx +9 -1
- package/ui/components/ui/Sigil.tsx +62 -0
- package/ui/components/wallet/ActivityRow.tsx +87 -24
- package/ui/isImageUrl.ts +16 -3
- package/ui/screens/TrustScreen.tsx +105 -23
- package/ui/screens/WalletCheckScreen.tsx +3 -3
package/core/pay/patp.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Urbit `@p` names for 32-bit integers, e.g. 15663360 -> '~nidsut-tomdun'.
|
|
3
|
+
*
|
|
4
|
+
* Faithful port of urbit-ob 5.0.1 (src/internal/co.js, ob.js, muk.js),
|
|
5
|
+
* restricted to the 32-bit domain we need: one syllable for n < 256 (galaxy),
|
|
6
|
+
* two for n < 65536 (star), four for everything else (planet). Planets are
|
|
7
|
+
* Feistel-scrambled exactly as in Urbit so that neighbouring seeds do not get
|
|
8
|
+
* neighbouring names, and so the output matches what any other @p tooling
|
|
9
|
+
* (sigil-js, urbit-ob, Landscape) would show for the same number.
|
|
10
|
+
*
|
|
11
|
+
* urbit-ob is not a dependency: it pulls in bn.js and lodash for arithmetic
|
|
12
|
+
* that fits comfortably in a JS double once the domain is 2^32. Everything
|
|
13
|
+
* here is plain numbers; `Math.imul` and `>>> 0` supply the 32-bit wrap the
|
|
14
|
+
* hash needs.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// ++po in hoon.hoon: 256 prefix and 256 suffix syllables, 3 chars each.
|
|
18
|
+
const PREFIX_TABLE =
|
|
19
|
+
'dozmarbinwansamlitsighidfidlissogdirwacsabwissib' +
|
|
20
|
+
'rigsoldopmodfoglidhopdardorlorhodfolrintogsilmir' +
|
|
21
|
+
'holpaslacrovlivdalsatlibtabhanticpidtorbolfosdot' +
|
|
22
|
+
'losdilforpilramtirwintadbicdifrocwidbisdasmidlop' +
|
|
23
|
+
'rilnardapmolsanlocnovsitnidtipsicropwitnatpanmin' +
|
|
24
|
+
'ritpodmottamtolsavposnapnopsomfinfonbanmorworsip' +
|
|
25
|
+
'ronnorbotwicsocwatdolmagpicdavbidbaltimtasmallig' +
|
|
26
|
+
'sivtagpadsaldivdactansidfabtarmonranniswolmispal' +
|
|
27
|
+
'lasdismaprabtobrollatlonnodnavfignomnibpagsopral' +
|
|
28
|
+
'bilhaddocridmocpacravripfaltodtiltinhapmicfanpat' +
|
|
29
|
+
'taclabmogsimsonpinlomrictapfirhasbosbatpochactid' +
|
|
30
|
+
'havsaplindibhosdabbitbarracparloddosbortochilmac' +
|
|
31
|
+
'tomdigfilfasmithobharmighinradmashalraglagfadtop' +
|
|
32
|
+
'mophabnilnosmilfopfamdatnoldinhatnacrisfotribhoc' +
|
|
33
|
+
'nimlarfitwalrapsarnalmoslandondanladdovrivbacpol' +
|
|
34
|
+
'laptalpitnambonrostonfodponsovnocsorlavmatmipfip'
|
|
35
|
+
|
|
36
|
+
const SUFFIX_TABLE =
|
|
37
|
+
'zodnecbudwessevpersutletfulpensytdurwepserwylsun' +
|
|
38
|
+
'rypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnex' +
|
|
39
|
+
'lunmeplutseppesdelsulpedtemledtulmetwenbynhexfeb' +
|
|
40
|
+
'pyldulhetmevruttylwydtepbesdexsefwycburderneppur' +
|
|
41
|
+
'rysrebdennutsubpetrulsynregtydsupsemwynrecmegnet' +
|
|
42
|
+
'secmulnymtevwebsummutnyxrextebfushepbenmuswyxsym' +
|
|
43
|
+
'selrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpel' +
|
|
44
|
+
'syptermebsetdutdegtexsurfeltudnuxruxrenwytnubmed' +
|
|
45
|
+
'lytdusnebrumtynseglyxpunresredfunrevrefmectedrus' +
|
|
46
|
+
'bexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermer' +
|
|
47
|
+
'tenlusnussyltecmexpubrymtucfyllepdebbermughuttun' +
|
|
48
|
+
'bylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmyl' +
|
|
49
|
+
'wedducfurfexnulluclennerlexrupnedlecrydlydfenwel' +
|
|
50
|
+
'nydhusrelrudneshesfetdesretdunlernyrsebhulryllud' +
|
|
51
|
+
'remlysfynwerrycsugnysnyllyndyndemluxfedsedbecmun' +
|
|
52
|
+
'lyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes'
|
|
53
|
+
|
|
54
|
+
const PREFIXES = PREFIX_TABLE.match(/.{3}/g) as string[]
|
|
55
|
+
const SUFFIXES = SUFFIX_TABLE.match(/.{3}/g) as string[]
|
|
56
|
+
|
|
57
|
+
/** Per-round hash seeds ("raku") from ++ob in hoon.hoon. */
|
|
58
|
+
const RAKU = [0xb76d5eed, 0xee281300, 0x85bcae01, 0x4b387af7]
|
|
59
|
+
|
|
60
|
+
// Feistel parameters: 4 rounds over the domain 65535 x 65536, which is exactly
|
|
61
|
+
// the 0xffff0000 planet numbers between 0x10000 and 0xffffffff.
|
|
62
|
+
const ROUNDS = 4
|
|
63
|
+
const A = 65535
|
|
64
|
+
const B = 65536
|
|
65
|
+
const K = 0xffffffff
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* MurmurHash3 (32-bit, Austin Appleby's x86 variant) over a short byte array.
|
|
69
|
+
* urbit-ob's `muk` feeds it a 2-byte string; the general loop is kept so the
|
|
70
|
+
* function reads as the well-known algorithm rather than a special case.
|
|
71
|
+
*/
|
|
72
|
+
function murmur3(bytes: number[], seed: number): number {
|
|
73
|
+
const c1 = 0xcc9e2d51
|
|
74
|
+
const c2 = 0x1b873593
|
|
75
|
+
let h1 = seed | 0
|
|
76
|
+
const blockEnd = bytes.length & ~3
|
|
77
|
+
let i = 0
|
|
78
|
+
for (; i < blockEnd; i += 4) {
|
|
79
|
+
let k1 = bytes[i] | (bytes[i + 1] << 8) | (bytes[i + 2] << 16) | (bytes[i + 3] << 24)
|
|
80
|
+
k1 = Math.imul(k1, c1)
|
|
81
|
+
k1 = (k1 << 15) | (k1 >>> 17)
|
|
82
|
+
k1 = Math.imul(k1, c2)
|
|
83
|
+
h1 ^= k1
|
|
84
|
+
h1 = (h1 << 13) | (h1 >>> 19)
|
|
85
|
+
h1 = (Math.imul(h1, 5) + 0xe6546b64) | 0
|
|
86
|
+
}
|
|
87
|
+
const rem = bytes.length & 3
|
|
88
|
+
if (rem > 0) {
|
|
89
|
+
let k1 = 0
|
|
90
|
+
if (rem === 3) k1 ^= bytes[i + 2] << 16
|
|
91
|
+
if (rem >= 2) k1 ^= bytes[i + 1] << 8
|
|
92
|
+
k1 ^= bytes[i]
|
|
93
|
+
k1 = Math.imul(k1, c1)
|
|
94
|
+
k1 = (k1 << 15) | (k1 >>> 17)
|
|
95
|
+
k1 = Math.imul(k1, c2)
|
|
96
|
+
h1 ^= k1
|
|
97
|
+
}
|
|
98
|
+
h1 ^= bytes.length
|
|
99
|
+
h1 ^= h1 >>> 16
|
|
100
|
+
h1 = Math.imul(h1, 0x85ebca6b)
|
|
101
|
+
h1 ^= h1 >>> 13
|
|
102
|
+
h1 = Math.imul(h1, 0xc2b2ae35)
|
|
103
|
+
h1 ^= h1 >>> 16
|
|
104
|
+
return h1 >>> 0
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** ++muk: murmur3 of the key's low two bytes, little-endian, with the given seed. */
|
|
108
|
+
function muk(seed: number, key: number): number {
|
|
109
|
+
return murmur3([key & 0xff, (key >>> 8) & 0xff], seed)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The round function: a PRF indexed by round number. */
|
|
113
|
+
function F(round: number, arg: number): number {
|
|
114
|
+
return muk(RAKU[round], arg)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* One pass of the generalised Feistel cipher (Black and Rogaway 2002, as
|
|
119
|
+
* adjusted in hoon.hoon). The final recombination is asymmetric when the
|
|
120
|
+
* round count is even: that quirk is what makes urbit-ob's `feis` agree with
|
|
121
|
+
* the ship names Urbit has already handed out, so it is kept verbatim.
|
|
122
|
+
*/
|
|
123
|
+
function fe(m: number): number {
|
|
124
|
+
let ell = m % A
|
|
125
|
+
let arr = Math.floor(m / A)
|
|
126
|
+
for (let j = 1; j <= ROUNDS; j++) {
|
|
127
|
+
const eff = F(j - 1, arr)
|
|
128
|
+
const tmp = j % 2 !== 0 ? (ell + eff) % A : (ell + eff) % B
|
|
129
|
+
ell = arr
|
|
130
|
+
arr = tmp
|
|
131
|
+
}
|
|
132
|
+
if (ROUNDS % 2 !== 0) return A * arr + ell
|
|
133
|
+
return arr === A ? A * arr + ell : A * ell + arr
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** `Fe`: cycle-walk once more if the first pass lands outside the domain. */
|
|
137
|
+
function feis(m: number): number {
|
|
138
|
+
const c = fe(m)
|
|
139
|
+
return c < K ? c : fe(c)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** ++fein: scramble planets only; galaxies and stars keep their raw number. */
|
|
143
|
+
function fein(n: number): number {
|
|
144
|
+
return n >= 0x10000 && n <= 0xffffffff ? 0x10000 + feis(n - 0x10000) : n
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Canonical Urbit @p for an unsigned 32-bit integer, '~'-prefixed.
|
|
149
|
+
* Throws a RangeError for anything outside that domain: moons and comets
|
|
150
|
+
* need 64 and 128 bits and are deliberately out of scope here.
|
|
151
|
+
*/
|
|
152
|
+
export function patp(n: number): string {
|
|
153
|
+
if (!Number.isInteger(n) || n < 0 || n > 0xffffffff) {
|
|
154
|
+
throw new RangeError(`patp: expected an integer in [0, 2^32), got ${String(n)}`)
|
|
155
|
+
}
|
|
156
|
+
const sxz = fein(n)
|
|
157
|
+
if (sxz < 256) return '~' + SUFFIXES[sxz]
|
|
158
|
+
// Each 16-bit chunk becomes prefix+suffix; the high chunk is spoken first.
|
|
159
|
+
const words: string[] = []
|
|
160
|
+
let rest = sxz
|
|
161
|
+
while (rest > 0) {
|
|
162
|
+
const chunk = rest % 65536
|
|
163
|
+
words.unshift(PREFIXES[chunk >>> 8] + SUFFIXES[chunk & 0xff])
|
|
164
|
+
rest = Math.floor(rest / 65536)
|
|
165
|
+
}
|
|
166
|
+
return '~' + words.join('-')
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The last eight hex digits of a hex string as an unsigned 32-bit integer.
|
|
171
|
+
* Meant for txids and compressed public keys, whose tails are already
|
|
172
|
+
* uniformly distributed, so no further mixing is needed before `patp`.
|
|
173
|
+
* Throws when the input is not hex or is shorter than eight digits, so a
|
|
174
|
+
* caller that hands over the wrong field finds out immediately.
|
|
175
|
+
*/
|
|
176
|
+
export function u32FromHexTail(hex: string): number {
|
|
177
|
+
if (!/^[0-9a-fA-F]{8,}$/.test(hex)) {
|
|
178
|
+
throw new Error(`u32FromHexTail: expected at least 8 hex digits, got ${hex.length} chars`)
|
|
179
|
+
}
|
|
180
|
+
return Number.parseInt(hex.slice(-8), 16)
|
|
181
|
+
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
type WalletProtocol
|
|
23
23
|
} from '@bsv/sdk'
|
|
24
24
|
import type { AppChain } from '../../config'
|
|
25
|
+
import { abbreviateKey, addressLabel, FROM_ADDRESS_LABEL_PREFIX, TO_ADDRESS_LABEL_PREFIX } from '../counterparty'
|
|
25
26
|
import { isValidBsvAddress } from './index'
|
|
26
27
|
|
|
27
28
|
export const BRC29_PROTOCOL_ID: WalletProtocol = [2, '3241645161d8']
|
|
@@ -215,14 +216,41 @@ export function parseWocBeefBody(resp: { ok: boolean; text: string }): number[]
|
|
|
215
216
|
}
|
|
216
217
|
}
|
|
217
218
|
|
|
219
|
+
/**
|
|
220
|
+
* The address a conventional wallet paid from, read off the zeroth input's
|
|
221
|
+
* P2PKH unlocking script: a signature push followed by a 33-byte compressed
|
|
222
|
+
* key. That is the only place the sweep can learn anything about the payer,
|
|
223
|
+
* since the remittance carries a sentinel sender rather than a real one.
|
|
224
|
+
* Anything else (coinbase, unsigned, multisig, a key that will not parse)
|
|
225
|
+
* yields undefined so the caller falls back to a generic description instead
|
|
226
|
+
* of guessing at a face; a throw here would count a good payment as failed.
|
|
227
|
+
*/
|
|
228
|
+
export function payerAddressOf(tx: Transaction, network: 'mainnet' | 'testnet' = 'mainnet'): string | undefined {
|
|
229
|
+
const chunks = tx.inputs[0]?.unlockingScript?.chunks
|
|
230
|
+
if (chunks === undefined || chunks.length !== 2) return undefined
|
|
231
|
+
const key = chunks[1].data
|
|
232
|
+
if (key === undefined || key.length !== 33 || (key[0] !== 0x02 && key[0] !== 0x03)) return undefined
|
|
233
|
+
try {
|
|
234
|
+
return PublicKey.fromString(Utils.toHex(key)).toAddress(network)
|
|
235
|
+
} catch {
|
|
236
|
+
return undefined
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
218
240
|
/**
|
|
219
241
|
* The sweep. Ported from legacy-payments.tsx's handleImportFunds with one
|
|
220
|
-
* change
|
|
242
|
+
* change to its trigger. What it writes has since grown a payer-facing
|
|
243
|
+
* description and a `from:` label so the activity list can name and draw the
|
|
244
|
+
* payer; both are additive and derived, and the dedup contract below is
|
|
245
|
+
* untouched. The label carries the address as hex (see addressLabel): the
|
|
246
|
+
* wallet lower-cases labels on the way in, which base58 does not survive.
|
|
221
247
|
*
|
|
222
248
|
* The sentinel sender key (PrivateKey(1)'s public key) and the label list are
|
|
223
249
|
* both load-bearing: the labels are how getInternalizedUtxos recognises what
|
|
224
|
-
* has already been imported, and the address label in particular is what
|
|
225
|
-
* a second sweep a no-op instead of a double credit.
|
|
250
|
+
* has already been imported, and the bare address label in particular is what
|
|
251
|
+
* makes a second sweep a no-op instead of a double credit. The `from:` label
|
|
252
|
+
* is a different string from the bare address, so the `labelQueryMode: 'all'`
|
|
253
|
+
* lookups and the `ts:` parse in getProcessedTransactions never see it.
|
|
226
254
|
*
|
|
227
255
|
* Each UTXO is fetched and internalized in its own try/catch so one bad BEEF
|
|
228
256
|
* cannot skip the rest of the address.
|
|
@@ -275,11 +303,21 @@ export async function sweepAddress(args: {
|
|
|
275
303
|
derivationSuffix: LEGACY_DERIVATION_SUFFIX
|
|
276
304
|
}
|
|
277
305
|
}))
|
|
306
|
+
// Same network the rail derives its own receive addresses on, so payer
|
|
307
|
+
// and payee addresses read consistently in one history.
|
|
308
|
+
const payerAddress = payerAddressOf(tx, woc.network)
|
|
278
309
|
const internalizeArgs: InternalizeActionArgs = {
|
|
279
310
|
tx: tx.toAtomicBEEF(),
|
|
280
|
-
description: 'Payment to your address',
|
|
311
|
+
description: payerAddress !== undefined ? abbreviateKey(payerAddress) : 'Payment to your address',
|
|
281
312
|
outputs,
|
|
282
|
-
labels: [
|
|
313
|
+
labels: [
|
|
314
|
+
'legacy',
|
|
315
|
+
'inbound',
|
|
316
|
+
'bsvbrowser',
|
|
317
|
+
address,
|
|
318
|
+
`ts:${nowSeconds}`,
|
|
319
|
+
...(payerAddress !== undefined ? [addressLabel(FROM_ADDRESS_LABEL_PREFIX, payerAddress)] : [])
|
|
320
|
+
]
|
|
283
321
|
}
|
|
284
322
|
const response = await wallet.internalizeAction(internalizeArgs, adminOriginator)
|
|
285
323
|
if (response?.accepted) importedSatoshis += relevant.reduce((sum, o) => sum + o.satoshis, 0)
|
|
@@ -313,9 +351,11 @@ export async function sendToAddress(args: {
|
|
|
313
351
|
const isSendMax = sats === 2099999999999999
|
|
314
352
|
const result = (await wallet.createAction(
|
|
315
353
|
{
|
|
316
|
-
|
|
354
|
+
// The recipient's address is the description so the activity list has a
|
|
355
|
+
// name for the row without a lookup; the to: label is what lets it draw a face.
|
|
356
|
+
description: abbreviateKey(address),
|
|
317
357
|
outputs: [{ lockingScript, satoshis: sats, outputDescription: 'BSV for recipient address' }],
|
|
318
|
-
labels: ['legacy', 'outbound'],
|
|
358
|
+
labels: ['legacy', 'outbound', addressLabel(TO_ADDRESS_LABEL_PREFIX, address)],
|
|
319
359
|
...(isSendMax ? { options: { randomizeOutputs: false } } : {})
|
|
320
360
|
},
|
|
321
361
|
adminOriginator
|
package/core/pay/rails/handle.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
type OutboxEntry
|
|
21
21
|
} from '../../peerpay/outbox'
|
|
22
22
|
import type { CreditFailureKind } from '../creditErrors'
|
|
23
|
+
import { abbreviateKey } from '../counterparty'
|
|
23
24
|
import { isDuplicateMessageError, sendControlMessage, type ResendReason } from '../../peerpay/control'
|
|
24
25
|
import { TaskDrainOutbox } from '../../monitor/TaskDrainOutbox'
|
|
25
26
|
|
|
@@ -85,6 +86,12 @@ export function peerPayLinkFor(identityKey: string, sats?: number, messageBoxUrl
|
|
|
85
86
|
/**
|
|
86
87
|
* Credit an incoming payment, then acknowledge it. Never acknowledge first.
|
|
87
88
|
*
|
|
89
|
+
* The recorded description is the note the sender attached to the token or,
|
|
90
|
+
* failing that, the sender's abbreviated identity key: the same default the
|
|
91
|
+
* sending wallet wrote for the recipient, so both sides name one payment the
|
|
92
|
+
* same way. The sender is not added to the labels; the activity list recovers
|
|
93
|
+
* the counterparty from the output's senderIdentityKey instead.
|
|
94
|
+
*
|
|
88
95
|
* `repairBeef` is the second chance. The token's AtomicBEEF was minted at send
|
|
89
96
|
* time, and a reorg between then and now invalidates its merkle path without
|
|
90
97
|
* touching the transaction itself — the toolbox reports that as
|
|
@@ -97,13 +104,16 @@ export async function internalizeIncoming(
|
|
|
97
104
|
client: Pick<PeerPayClient, 'acknowledgeMessage'>,
|
|
98
105
|
adminOriginator: string,
|
|
99
106
|
payment: IncomingPayment,
|
|
100
|
-
description: string,
|
|
101
107
|
repairBeef?: (txid: string) => Promise<number[] | undefined>
|
|
102
108
|
): Promise<void> {
|
|
103
109
|
// A note the sender attached to the token becomes the description the
|
|
104
|
-
// recipient's wallet records
|
|
110
|
+
// recipient's wallet records, the same field the sender's action carries.
|
|
105
111
|
const note = (payment.token as { note?: unknown }).note
|
|
106
112
|
const noted = typeof note === 'string' && note.trim().length > 0 ? note.trim().slice(0, 500) : undefined
|
|
113
|
+
// Same rule as the sender's side: the note verbatim, space-padded to the
|
|
114
|
+
// 5-byte validation floor when it is shorter. The abbreviated key is 13
|
|
115
|
+
// characters, so it never needs padding.
|
|
116
|
+
const description = noted ? noted.padEnd(5) : abbreviateKey(payment.sender)
|
|
107
117
|
|
|
108
118
|
const argsFor = (tx: number[] | typeof payment.token.transaction) => ({
|
|
109
119
|
tx,
|
|
@@ -119,9 +129,7 @@ export async function internalizeIncoming(
|
|
|
119
129
|
}
|
|
120
130
|
],
|
|
121
131
|
labels: ['peerpay'],
|
|
122
|
-
|
|
123
|
-
// 5-byte validation floor when it is shorter.
|
|
124
|
-
description: noted ? noted.padEnd(5) : description
|
|
132
|
+
description
|
|
125
133
|
})
|
|
126
134
|
|
|
127
135
|
try {
|
|
@@ -185,15 +193,14 @@ export async function acceptWithRetry(
|
|
|
185
193
|
client: Pick<PeerPayClient, 'listIncomingPayments'>,
|
|
186
194
|
messageBoxUrl: string,
|
|
187
195
|
payment: IncomingPayment,
|
|
188
|
-
|
|
189
|
-
internalize: (p: IncomingPayment, d: string) => Promise<void>
|
|
196
|
+
internalize: (p: IncomingPayment) => Promise<void>
|
|
190
197
|
): Promise<void> {
|
|
191
198
|
void client
|
|
192
199
|
void messageBoxUrl
|
|
193
200
|
try {
|
|
194
|
-
await internalize(payment
|
|
201
|
+
await internalize(payment)
|
|
195
202
|
} catch {
|
|
196
|
-
await internalize(payment
|
|
203
|
+
await internalize(payment)
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
206
|
|
|
@@ -403,12 +410,15 @@ export async function sendViaHandle(args: {
|
|
|
403
410
|
// advertised host when there is one and otherwise falls back to the host this
|
|
404
411
|
// wallet is configured for, which is where both parties' apps look by default.
|
|
405
412
|
|
|
406
|
-
// The note IS the description when one was given
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
413
|
+
// The note IS the description when one was given, verbatim; otherwise the
|
|
414
|
+
// recipient's name, or their abbreviated key. No "Pay" prefix: the activity
|
|
415
|
+
// row already shows the direction, and the receive side records the sender
|
|
416
|
+
// the same way, so both wallets name one payment alike. BRC-100 requires
|
|
417
|
+
// 5-2000 bytes and the validator does not trim, so a very short note is
|
|
418
|
+
// padded with trailing spaces rather than decorated, and everything is
|
|
419
|
+
// clamped at the top end.
|
|
410
420
|
const note = args.note?.trim() || undefined
|
|
411
|
-
const description = (note ??
|
|
421
|
+
const description = (note ?? (recipientName?.trim() || abbreviateKey(recipient))).slice(0, 500).padEnd(5)
|
|
412
422
|
|
|
413
423
|
// Standard BRC-29: fresh prefix/suffix, key derived toward the recipient.
|
|
414
424
|
const derivationPrefix = Utils.toBase64(Random(8))
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Beef } from '@bsv/sdk'
|
|
2
|
+
import { PUBKEY_LABEL } from '../pay/counterparty'
|
|
2
3
|
import {
|
|
3
4
|
ackControlMessages,
|
|
4
5
|
isDuplicateMessageError,
|
|
@@ -14,8 +15,6 @@ const PAYMENT_INBOX = 'payment_inbox'
|
|
|
14
15
|
/** Stored unanswered `resend_request`s so Home can show a banner without re-listing. */
|
|
15
16
|
export const UNANSWERED_RESENDS_KEY = 'peerpay_unanswered_resends'
|
|
16
17
|
|
|
17
|
-
const PUBKEY_LABEL = /^(02|03)[0-9a-fA-F]{64}$/
|
|
18
|
-
|
|
19
18
|
/**
|
|
20
19
|
* Rail labels an outbound payment can carry. Both are resendable: each writes
|
|
21
20
|
* the payee's identity key as a label and BRC-29 derivation data as the
|
|
@@ -103,6 +103,13 @@ export interface StorageExpoSQLiteOptions extends StorageProviderOptions {
|
|
|
103
103
|
/** Per-connection wait before a lock contention becomes "database is locked". */
|
|
104
104
|
export const BUSY_TIMEOUT_MS = 5000
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* The lowest SQLITE_MAX_VARIABLE_NUMBER a shipped SQLite still enforces. Any
|
|
108
|
+
* IN (...) list built from caller data is split at this size so a large page
|
|
109
|
+
* can never turn into "too many SQL variables".
|
|
110
|
+
*/
|
|
111
|
+
const SQLITE_MAX_BOUND_VARIABLES = 999
|
|
112
|
+
|
|
106
113
|
/**
|
|
107
114
|
* The token `transaction()` hands its scope. Carrying the connection on the
|
|
108
115
|
* token is what lets `getDB(trx)` route a statement to the transaction without
|
|
@@ -1687,6 +1694,36 @@ export class StorageExpoSQLite extends StorageProvider {
|
|
|
1687
1694
|
return this.validateEntities(rows, undefined, ['isDeleted'])
|
|
1688
1695
|
}
|
|
1689
1696
|
|
|
1697
|
+
/**
|
|
1698
|
+
* The payer's identity key for each of a page of transactions, keyed by
|
|
1699
|
+
* transactionId. The key is recorded per output, not per transaction, so this
|
|
1700
|
+
* reads the whole page's outputs in one round trip and keeps the lowest-vout
|
|
1701
|
+
* non-empty key per transaction; transactions with no keyed output are absent
|
|
1702
|
+
* from the map. The sentinel key the address sweep writes is deliberately NOT
|
|
1703
|
+
* filtered here: what counts as a real counterparty is a presentation
|
|
1704
|
+
* decision that belongs to the caller.
|
|
1705
|
+
*/
|
|
1706
|
+
async getSenderIdentityKeysForTransactionIds(transactionIds: number[], trx?: TrxToken): Promise<Map<number, string>> {
|
|
1707
|
+
const keys = new Map<number, string>()
|
|
1708
|
+
if (transactionIds.length === 0) return keys
|
|
1709
|
+
const db = this.getDB(trx)
|
|
1710
|
+
type Row = { transactionId: number; senderIdentityKey: string }
|
|
1711
|
+
for (let i = 0; i < transactionIds.length; i += SQLITE_MAX_BOUND_VARIABLES) {
|
|
1712
|
+
const chunk = transactionIds.slice(i, i + SQLITE_MAX_BOUND_VARIABLES)
|
|
1713
|
+
const rows = (await db.getAllAsync(
|
|
1714
|
+
`SELECT transactionId, senderIdentityKey FROM outputs
|
|
1715
|
+
WHERE transactionId IN (${chunk.map(() => '?').join(',')})
|
|
1716
|
+
AND senderIdentityKey IS NOT NULL AND senderIdentityKey != ''
|
|
1717
|
+
ORDER BY transactionId, vout`,
|
|
1718
|
+
chunk
|
|
1719
|
+
)) as Row[]
|
|
1720
|
+
for (const row of rows) {
|
|
1721
|
+
if (!keys.has(row.transactionId)) keys.set(row.transactionId, row.senderIdentityKey)
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return keys
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1690
1727
|
async getTagsForOutputId(outputId: number, trx?: TrxToken): Promise<TableOutputTag[]> {
|
|
1691
1728
|
const rows = await this.getDB(trx).getAllAsync(
|
|
1692
1729
|
`SELECT t.* FROM output_tags_map m JOIN output_tags t ON t.outputTagId = m.outputTagId
|
|
@@ -109,6 +109,11 @@ export async function listActionsSql(
|
|
|
109
109
|
await specOp.postProcess(storage, auth, vargs, specOpLabels, txs)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// The activity list identifies who paid us from the key stored on the
|
|
113
|
+
// transaction's outputs. One read covers the whole page rather than a
|
|
114
|
+
// findOutputs round trip per row.
|
|
115
|
+
const senderIdentityKeys = await storage.getSenderIdentityKeysForTransactionIds(txs.map(tx => tx.transactionId))
|
|
116
|
+
|
|
112
117
|
// Build action objects
|
|
113
118
|
for (const tx of txs) {
|
|
114
119
|
const wtx: any = {
|
|
@@ -126,6 +131,10 @@ export async function listActionsSql(
|
|
|
126
131
|
// `reference` already is.
|
|
127
132
|
created_at: tx.created_at
|
|
128
133
|
}
|
|
134
|
+
// Another extra, set only when a keyed output exists so consumers can tell
|
|
135
|
+
// "no sender recorded" from an empty string.
|
|
136
|
+
const senderIdentityKey = senderIdentityKeys.get(tx.transactionId)
|
|
137
|
+
if (senderIdentityKey !== undefined) wtx.senderIdentityKey = senderIdentityKey
|
|
129
138
|
r.actions.push(wtx)
|
|
130
139
|
}
|
|
131
140
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colour for a counterparty's sigil tile. Every sigil used to be drawn in the
|
|
3
|
+
* text colour on a neutral tile, and at 38pt the shapes alone are too alike
|
|
4
|
+
* to tell one row from the next. A hue per counterparty gives each face its
|
|
5
|
+
* own tint, so the eye can pick out "the blue one" before it reads the glyph.
|
|
6
|
+
*
|
|
7
|
+
* The hue is whatever the caller derives (see counterpartyHue); this module
|
|
8
|
+
* only turns it into a pair of solids that stay readable at every hue in
|
|
9
|
+
* both themes. Saturation and lightness are fixed per theme rather than
|
|
10
|
+
* varied with the hue, so the tiles read as one family and not as a random
|
|
11
|
+
* scatter of swatches down the list.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type SigilPalette = {
|
|
15
|
+
/** Symbol colour, six-digit lower-case hex. */
|
|
16
|
+
foreground: string
|
|
17
|
+
/**
|
|
18
|
+
* Tile colour, six-digit lower-case hex. Solid on purpose: sigil-js draws
|
|
19
|
+
* the cut-lines inside each glyph in this colour, so alpha would leave gaps.
|
|
20
|
+
*/
|
|
21
|
+
background: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Tone = { s: number; l: number }
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Per-theme saturation and lightness, in percent. Light theme: a pale tint
|
|
28
|
+
* under a deep symbol. Dark theme: a deep tint under a bright symbol.
|
|
29
|
+
*
|
|
30
|
+
* The lightness values are pinned by the WCAG floor of 4.5:1 across all 360
|
|
31
|
+
* hues, which the palette test enforces. The weak spots are the hues whose
|
|
32
|
+
* luminance moves furthest for a given lightness: yellow (hue 60) is the
|
|
33
|
+
* brightest thing a light-theme symbol can be, so the foreground sits at 28%
|
|
34
|
+
* rather than 30% to keep 4.75:1 there; blue (hue 240) is the darkest thing a
|
|
35
|
+
* dark-theme symbol can be and clears 5.8:1 at 78%.
|
|
36
|
+
*/
|
|
37
|
+
const LIGHT: { background: Tone; foreground: Tone } = {
|
|
38
|
+
background: { s: 45, l: 92 },
|
|
39
|
+
foreground: { s: 55, l: 28 }
|
|
40
|
+
}
|
|
41
|
+
const DARK: { background: Tone; foreground: Tone } = {
|
|
42
|
+
background: { s: 35, l: 24 },
|
|
43
|
+
foreground: { s: 65, l: 78 }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Standard HSL to sRGB (CSS Color 3, section 4.2.4), then to `#rrggbb`. */
|
|
47
|
+
function hslToHex(hue: number, saturation: number, lightness: number): string {
|
|
48
|
+
const s = saturation / 100
|
|
49
|
+
const l = lightness / 100
|
|
50
|
+
const chroma = (1 - Math.abs(2 * l - 1)) * s
|
|
51
|
+
const sector = hue / 60
|
|
52
|
+
const x = chroma * (1 - Math.abs((sector % 2) - 1))
|
|
53
|
+
let r = 0
|
|
54
|
+
let g = 0
|
|
55
|
+
let b = 0
|
|
56
|
+
if (sector < 1) [r, g, b] = [chroma, x, 0]
|
|
57
|
+
else if (sector < 2) [r, g, b] = [x, chroma, 0]
|
|
58
|
+
else if (sector < 3) [r, g, b] = [0, chroma, x]
|
|
59
|
+
else if (sector < 4) [r, g, b] = [0, x, chroma]
|
|
60
|
+
else if (sector < 5) [r, g, b] = [x, 0, chroma]
|
|
61
|
+
else [r, g, b] = [chroma, 0, x]
|
|
62
|
+
const m = l - chroma / 2
|
|
63
|
+
const channel = (v: number) =>
|
|
64
|
+
Math.round((v + m) * 255)
|
|
65
|
+
.toString(16)
|
|
66
|
+
.padStart(2, '0')
|
|
67
|
+
return '#' + channel(r) + channel(g) + channel(b)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The symbol and tile colours for a hue in degrees. Any finite number is
|
|
72
|
+
* accepted and wrapped onto [0, 360), so -30 and 330 are the same tint; a
|
|
73
|
+
* non-finite hue (a NaN from a bad upstream parse) falls back to 0 rather than
|
|
74
|
+
* producing `#NaNNaNNaN` and a transparent tile.
|
|
75
|
+
*/
|
|
76
|
+
export function sigilPalette(hue: number, isDark: boolean): SigilPalette {
|
|
77
|
+
const h = Number.isFinite(hue) ? ((hue % 360) + 360) % 360 : 0
|
|
78
|
+
const tone = isDark ? DARK : LIGHT
|
|
79
|
+
return {
|
|
80
|
+
foreground: hslToHex(h, tone.foreground.s, tone.foreground.l),
|
|
81
|
+
background: hslToHex(h, tone.background.s, tone.background.l)
|
|
82
|
+
}
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
42
42
|
"@react-native-clipboard/clipboard": "^1.16.2",
|
|
43
43
|
"@react-native-community/netinfo": "^11.5.2",
|
|
44
|
+
"@urbit/sigil-js": "^2.2.0",
|
|
44
45
|
"date-fns": "^4.1.0",
|
|
45
46
|
"expo-audio": "~55.0.16",
|
|
46
47
|
"expo-blur": "~55.0.14",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"expo-document-picker": "~55.0.13",
|
|
52
53
|
"expo-file-system": "~55.0.20",
|
|
53
54
|
"expo-haptics": "~55.0.14",
|
|
55
|
+
"expo-image": "~55.0.11",
|
|
54
56
|
"expo-local-authentication": "~55.0.14",
|
|
55
57
|
"expo-localization": "~55.0.15",
|
|
56
58
|
"expo-print": "~55.0.15",
|
|
@@ -42,7 +42,7 @@ import { wocConfigFor } from '../../../core/pay/rails/address'
|
|
|
42
42
|
import { makeCreditClassifier } from '../../../core/pay/creditErrors'
|
|
43
43
|
import { satoshisFromToken } from '../../../core/pay/tokenAmount'
|
|
44
44
|
import { userFacingPayError } from '../../../core/pay/userError'
|
|
45
|
-
import { creditInboxOnce,
|
|
45
|
+
import { creditInboxOnce, type CreditInboxResult } from '../../../core/pay/creditInbox'
|
|
46
46
|
import { setReceiveInboxFocused } from '../../../core/pay/receiveFocus'
|
|
47
47
|
import { TaskCreditInbox } from '../../../core/monitor/TaskCreditInbox'
|
|
48
48
|
import { useOnline } from '../../hooks/useOnline'
|
|
@@ -468,10 +468,10 @@ export default function HandleReceive({
|
|
|
468
468
|
)
|
|
469
469
|
|
|
470
470
|
const internalize = useCallback(
|
|
471
|
-
async (payment: IncomingPayment
|
|
471
|
+
async (payment: IncomingPayment) => {
|
|
472
472
|
const client = peerPayClient
|
|
473
473
|
if (!client || !wallet) throw new Error(t('wallet_not_ready'))
|
|
474
|
-
await internalizeIncoming(wallet as any, client, adminOriginator, payment,
|
|
474
|
+
await internalizeIncoming(wallet as any, client, adminOriginator, payment, repairBeef)
|
|
475
475
|
},
|
|
476
476
|
[peerPayClient, wallet, adminOriginator, t, repairBeef]
|
|
477
477
|
)
|
|
@@ -510,7 +510,7 @@ export default function HandleReceive({
|
|
|
510
510
|
storage: storage ?? undefined,
|
|
511
511
|
force,
|
|
512
512
|
classify,
|
|
513
|
-
accept: payment => acceptWithRetry(client, messageBoxUrl, payment,
|
|
513
|
+
accept: payment => acceptWithRetry(client, messageBoxUrl, payment, internalize)
|
|
514
514
|
})
|
|
515
515
|
applyCreditResult(outcome)
|
|
516
516
|
return outcome
|
|
@@ -234,6 +234,14 @@ export default function OfflineNotice({
|
|
|
234
234
|
<Ionicons name="alert-circle-outline" size={18} color={colors.warning} />
|
|
235
235
|
<View style={styles.text}>
|
|
236
236
|
<Text style={[styles.title, { color: colors.textPrimary }]}>{t('pay_offline_kv_corrupt')}</Text>
|
|
237
|
+
{/* The queue was cleared to repair it, but the raw blob is kept under a
|
|
238
|
+
timestamped `localpay_pending_corrupt_*` key. Say so: the payments were
|
|
239
|
+
incoming money, and a bare "damaged data" title reads as "my queued
|
|
240
|
+
payments vanished". Steer away from blind re-sends — a quarantined entry
|
|
241
|
+
may already have been credited. */}
|
|
242
|
+
<Text style={[styles.body, { color: colors.textSecondary }]}>
|
|
243
|
+
{t('pay_offline_kv_corrupt_body')}
|
|
244
|
+
</Text>
|
|
237
245
|
</View>
|
|
238
246
|
</View>
|
|
239
247
|
)}
|
|
@@ -23,7 +23,15 @@ const AppLogo: React.FC<AppLogoProps> = ({ size = 150, color = '#2196F3', rotate
|
|
|
23
23
|
toValue: 1,
|
|
24
24
|
duration: 10000,
|
|
25
25
|
easing: Easing.linear,
|
|
26
|
-
useNativeDriver: true
|
|
26
|
+
useNativeDriver: true,
|
|
27
|
+
// A looped animation never ends, so without this the interaction
|
|
28
|
+
// handle Animated.timing registers is held for as long as this
|
|
29
|
+
// component is mounted — and while any handle is held,
|
|
30
|
+
// InteractionManager.runAfterInteractions never fires for anyone,
|
|
31
|
+
// process-wide. Balance renders this spinner whenever a balance is
|
|
32
|
+
// loading, so the deferred proof sweep in PayScreen (and any host
|
|
33
|
+
// that defers work the same way) would simply never run.
|
|
34
|
+
isInteraction: false
|
|
27
35
|
})
|
|
28
36
|
).start()
|
|
29
37
|
}
|