@bsv/expo-wallet-toolbox 0.27.0 → 0.29.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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The wallet label for a payment's paymail address. It lives in its own file so
3
+ * `rails/handle.ts` can use it without importing `rails/paymail.ts`, which
4
+ * imports `handle.ts`.
5
+ */
6
+ export const PAYMAIL_LABEL_PREFIX = 'paymail:'
7
+
8
+ const MAX_ADDRESS_LENGTH = 254
9
+ const ADDRESS = /^[a-z0-9._+-]{1,64}@[a-z0-9.-]{1,190}\.[a-z]{2,}$/
10
+ // eslint-disable-next-line no-control-regex
11
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e\u2066-\u2069\ufeff]/
12
+
13
+ /**
14
+ * `paymail:<lower-case address>` for a valid address, else `undefined`. The
15
+ * value comes from a sender's token, so it is untrusted: anything that is not a
16
+ * short plain address gives no label.
17
+ */
18
+ export function incomingPaymailLabel(value: unknown): string | undefined {
19
+ if (typeof value !== 'string' || value.length > MAX_ADDRESS_LENGTH) return undefined
20
+ if (CONTROL.test(value)) return undefined
21
+ const address = value.toLowerCase()
22
+ if (!ADDRESS.test(address)) return undefined
23
+ return `${PAYMAIL_LABEL_PREFIX}${address}`
24
+ }
@@ -23,6 +23,7 @@ import {
23
23
  } from '../../peerpay/outbox'
24
24
  import type { CreditFailureKind } from '../creditErrors'
25
25
  import { abbreviateKey } from '../counterparty'
26
+ import { incomingPaymailLabel } from '../paymailLabel'
26
27
  import { cleanPeerPayNote } from '../../parsePeerPayURI'
27
28
  import { isDuplicateMessageError, sendControlMessage, type ResendReason } from '../../peerpay/control'
28
29
  import { TaskDrainOutbox } from '../../monitor/TaskDrainOutbox'
@@ -200,7 +201,7 @@ export type CreditOutcome = 'credited' | 'duplicate'
200
201
  * The recorded description is the note the sender attached to the token or,
201
202
  * failing that, the sender's abbreviated identity key: the same default the
202
203
  * sending wallet wrote for the recipient, so both sides name one payment the
203
- * same way. The sender is not added to the labels; the activity list recovers
204
+ * same way. The sender's key is not added to the labels; the activity list recovers
204
205
  * the counterparty from the output's senderIdentityKey instead.
205
206
  *
206
207
  * `repairBeef` is the second chance. The token's AtomicBEEF was minted at send
@@ -231,6 +232,10 @@ export async function internalizeIncoming(
231
232
 
232
233
  const description = creditDescription((payment.token as { note?: unknown }).note, payment.sender)
233
234
 
235
+ // A legacy sender's address, when the token carries a valid one. Never the
236
+ // bare `paymail` label: that one marks an outbox-protected outgoing action.
237
+ const paymailLabel = incomingPaymailLabel((payment.token as { paymail?: unknown }).paymail)
238
+
234
239
  const argsFor = (tx: number[] | typeof payment.token.transaction) => ({
235
240
  tx,
236
241
  outputs: [
@@ -244,7 +249,7 @@ export async function internalizeIncoming(
244
249
  protocol: 'wallet payment'
245
250
  }
246
251
  ],
247
- labels: ['peerpay'],
252
+ labels: ['peerpay', ...(paymailLabel ? [paymailLabel] : [])],
248
253
  description
249
254
  })
250
255
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.27.0",
3
+ "version": "0.29.0",
4
4
  "private": false,
5
5
  "description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
6
6
  "license": "Apache-2.0",