@bsv/expo-wallet-toolbox 0.15.0 → 0.15.2

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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.15.2
4
+
5
+ ### Fixed
6
+
7
+ - **Sending Mandala tokens to yourself works.** Requires `@bsv/mandala`
8
+ 0.4.1, which no longer blinds a send to the wallet's own identity key (the
9
+ wallet refuses the root shared secret with itself, so these sends failed
10
+ before `createAction`). The output is locked like change and kept in the
11
+ token basket; no MessageBox message is sent. This covers the in-app handle
12
+ rail as well as connected apps.
13
+ - **The spend prompt shows a send to yourself as sent.** `MandalaTokenModule`
14
+ counted every `'p mandala'`-basketed output as change, so a send to yourself
15
+ read "wants to spend 0". A basketed output whose `customInstructions` mark
16
+ it `direction: 'sent'` now counts as sent. An unbasketed output always
17
+ counts as sent, so an app can only make the prompt show more, never less.
18
+
19
+ ## 0.15.1
20
+
21
+ ### Fixed
22
+
23
+ - **Connected apps can issue and send Mandala tokens.** `MandalaTokenModule`
24
+ forced `includeCustomInstructions` off on every `listOutputs` call from a
25
+ connected app, but the Mandala lib finds the issuer's admin assets and the
26
+ coins it can spend by the `keyID`/`counterparty` stored there, so the
27
+ console found nothing to issue from or send. After the token access prompt
28
+ the instructions are now returned as asked. The redaction dates from before
29
+ `createSignature` was bound to approved transactions; knowing a coin's
30
+ derivation no longer lets an app spend it.
31
+
3
32
  ## 0.15.0
4
33
 
5
34
  ### Changed
@@ -27,8 +27,13 @@
27
27
  * Source of truth: offline-settlement-final.md §8.3, plus a set of
28
28
  * adversarial-review findings closed here (see the inline notes tagged
29
29
  * "adversarial-review finding" throughout this file):
30
- * 1. [critical] listOutputs no longer lets a paired app read back
31
- * `customInstructions` (keyID/counterparty/blinding derivation data).
30
+ * 1. [critical] listOutputs used to withhold `customInstructions`
31
+ * (keyID/counterparty/blinding derivation data), because knowing a
32
+ * coin's derivation was enough to sign a spend of it. Reverted: the
33
+ * Mandala lib finds admin assets and spendable coins by those
34
+ * instructions, so withholding them broke issuing and sending from a
35
+ * connected app, and `createSignature` is now bound to approved
36
+ * transactions (see above), so the derivation alone no longer spends.
32
37
  * 2. [medium/high] createAction that only SPENDS `'p mandala'` INPUTS (no
33
38
  * basketed change output) is now gated too — see `anyInputIsTokenCoin`
34
39
  * and the `wrapCreateActionForTokenInputs` wrapper below.
@@ -216,6 +221,19 @@ export interface MandalaTokenModuleDeps {
216
221
  interface MandalaCreateActionOutputLike {
217
222
  lockingScript?: string
218
223
  basket?: string
224
+ customInstructions?: string
225
+ }
226
+
227
+ /** True for an output the Mandala lib marks as the payment itself
228
+ * (customInstructions `direction: 'sent'`). In a send to yourself that
229
+ * output stays in the basket, so the basket alone would show it as change. */
230
+ function isMarkedSent(output: MandalaCreateActionOutputLike): boolean {
231
+ if (typeof output?.customInstructions !== 'string') return false
232
+ try {
233
+ return (JSON.parse(output.customInstructions) as { direction?: unknown })?.direction === 'sent'
234
+ } catch {
235
+ return false
236
+ }
219
237
  }
220
238
  /** The slice of `RelinquishOutputArgs` this module reads. */
221
239
  interface MandalaRelinquishOutputArgsLike {
@@ -243,13 +261,6 @@ interface MandalaInternalizeActionArgsLike {
243
261
  outputs?: MandalaInternalizeOutputLike[]
244
262
  }
245
263
 
246
- /** The slice of `ListOutputsArgs` this module reads/rewrites. */
247
- interface MandalaListOutputsArgsLike {
248
- basket?: string
249
- includeCustomInstructions?: boolean
250
- [key: string]: unknown
251
- }
252
-
253
264
  export interface DecodedMandalaOutput {
254
265
  assetId: string
255
266
  amount: number
@@ -473,15 +484,9 @@ export class MandalaTokenModule implements PermissionsModule {
473
484
 
474
485
  switch (method) {
475
486
  case 'listOutputs': {
487
+ // customInstructions come back when asked for: see finding (1).
476
488
  await this.promptOnceForAccess(originator, 'listOutputs')
477
- // Adversarial-review finding (1): WalletPermissionsManager forwards
478
- // the ARGS THIS METHOD RETURNS to the underlying listOutputs call
479
- // (delegateToPModuleIfNeeded), so redacting here genuinely prevents
480
- // the underlying wallet from ever including customInstructions in
481
- // its response — this is not merely filtering our own mirror of it
482
- // afterward, which would be too late for a caller that reads the
483
- // result directly.
484
- return { args: this.redactListOutputsArgs(args as MandalaListOutputsArgsLike) }
489
+ break
485
490
  }
486
491
  case 'listActions':
487
492
  // Adversarial-review finding (3): same once-per-session gate as
@@ -611,16 +616,6 @@ export class MandalaTokenModule implements PermissionsModule {
611
616
  }
612
617
  }
613
618
 
614
- /**
615
- * Forces `includeCustomInstructions` off regardless of what the caller
616
- * asked for. `customInstructions` is where a Mandala coin's `keyID`/
617
- * `counterparty`/blinding derivation lives (see the module doc) — a paired
618
- * app has no legitimate use for it, and no other `ListOutputsArgs` field
619
- * exposes anything equivalent.
620
- */
621
- private redactListOutputsArgs(args: MandalaListOutputsArgsLike): MandalaListOutputsArgsLike {
622
- return { ...args, includeCustomInstructions: false }
623
- }
624
619
 
625
620
  /**
626
621
  * createAction with an output in `'p mandala'` — always prompts (mirrors
@@ -732,8 +727,9 @@ export class MandalaTokenModule implements PermissionsModule {
732
727
  * assetId (adversarial-review finding 4 — a createAction touching more
733
728
  * than one asset previously collapsed every asset's amounts into one
734
729
  * running total under whichever assetId was seen first). An output that
735
- * carries the `'p mandala'` basket is change (stays with us); one that
736
- * does not is the recipient's (Mandala payer outputs are never basketed).
730
+ * carries the `'p mandala'` basket is change (stays with us) unless the lib
731
+ * marks it as the payment (a send to yourself); one that does not is the
732
+ * recipient's (Mandala payer outputs are otherwise never basketed).
737
733
  * A script that fails to decode is silently skipped, not fatal —
738
734
  * `tryDecodeMandalaOutput` never throws.
739
735
  */
@@ -746,7 +742,9 @@ export class MandalaTokenModule implements PermissionsModule {
746
742
  const decoded = tryDecodeMandalaOutput(output?.lockingScript)
747
743
  if (!decoded) continue
748
744
  const entry = totals.get(decoded.assetId) ?? { sendAmount: 0, changeAmount: 0 }
749
- if (output.basket === MANDALA_BASKET) {
745
+ // An app can only make the prompt show MORE as sent this way, never less:
746
+ // an unbasketed output always counts as sent.
747
+ if (output.basket === MANDALA_BASKET && !isMarkedSent(output)) {
750
748
  entry.changeAmount += decoded.amount
751
749
  } else {
752
750
  entry.sendAmount += decoded.amount
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
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",
@@ -32,7 +32,7 @@
32
32
  "@bsv/air-gap": "^0.1.3",
33
33
  "@bsv/backup-cache-client": "^0.1.0",
34
34
  "@bsv/btms-permission-module": "^1.2.1",
35
- "@bsv/mandala": "^0.4.0",
35
+ "@bsv/mandala": "^0.4.1",
36
36
  "@bsv/message-box-client": "^2.5.3",
37
37
  "@bsv/react-native-localpay-transport": "*",
38
38
  "@bsv/sdk": "^2.8.11",