@bsv/expo-wallet-toolbox 0.21.0 → 0.22.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 +114 -0
- package/README.md +78 -13
- package/core/contacts/contactActivity.ts +48 -28
- package/core/contacts/contactsStore.ts +2 -2
- package/core/context/WalletContext.tsx +166 -219
- package/core/demo/demoAssets.ts +8 -10
- package/core/demo/demoLedger.ts +32 -38
- package/core/demo/demoMandalaRuntime.ts +67 -49
- package/core/demo/index.ts +1 -1
- package/core/i18n/translations.tsx +72 -0
- package/core/index.ts +55 -37
- package/core/localpay/build.ts +110 -569
- package/core/localpay/codec.ts +190 -93
- package/core/localpay/pending.ts +217 -202
- package/core/localpay/session.ts +99 -25
- package/core/localpay/types.ts +6 -5
- package/core/localpay/verify.ts +118 -173
- package/core/mandala/abortGuard.ts +97 -120
- package/core/mandala/accessPolicy.ts +133 -0
- package/core/mandala/assets.ts +370 -0
- package/core/mandala/colorGuard.ts +178 -0
- package/core/mandala/colorModule.ts +82 -0
- package/core/mandala/createRuntime.ts +483 -2392
- package/core/mandala/handle.ts +694 -0
- package/core/mandala/kvStore.ts +105 -0
- package/core/mandala/nearby.ts +185 -0
- package/core/mandala/receipt.ts +121 -0
- package/core/mandala/runtime.ts +166 -312
- package/core/mandala/settle.ts +540 -0
- package/core/mandala/transferJournal.ts +395 -0
- package/core/mandala/types.ts +61 -311
- package/core/networks.ts +5 -5
- package/core/offline/cancelParked.ts +80 -63
- package/core/offline/payerHold.ts +52 -118
- package/core/parsePeerPayURI.ts +25 -12
- package/core/pay/rails/handle.ts +15 -14
- package/core/pay/rails/index.ts +5 -3
- package/core/pay/rails/nearby.ts +25 -87
- package/core/profiles/assertProfileEmpty.ts +19 -10
- package/core/services/vault/guard.ts +5 -4
- package/core/storage/StorageExpoSQLite.ts +93 -229
- package/core/storage/methods/processOfflineActions.ts +86 -136
- package/core/storage/schema/createTables.ts +9 -184
- package/package.json +6 -5
- package/ui/components/pay/AssetPicker.tsx +2 -2
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/pay/NearbyFlow.tsx +324 -239
- package/ui/components/pay/RequestHub.tsx +10 -0
- package/ui/components/pay/UniversalSend.tsx +31 -28
- package/ui/components/pay/useRecipientInput.ts +2 -2
- package/ui/components/ui/PermissionSheet.tsx +94 -160
- package/ui/components/ui/colorPrompt.ts +236 -0
- package/ui/components/wallet/AmountInput.tsx +9 -6
- package/ui/components/wallet/AssetAmount.tsx +6 -6
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +26 -7
- package/ui/components/wallet/Balance.tsx +3 -1
- package/ui/components/wallet/ContactActivityList.tsx +10 -13
- package/ui/components/wallet/tokenEviction.ts +9 -9
- package/ui/hooks/useMandala.ts +6 -6
- package/ui/hooks/useSpendableBalance.ts +3 -1
- package/ui/importDatabases.ts +1 -1
- package/ui/screens/PayScreen.tsx +14 -20
- package/ui/screens/SettingsScreen.tsx +3 -1
- package/ui/screens/WalletCheckScreen.tsx +7 -2
- package/ui/screens/WalletHomeScreen.tsx +40 -14
- package/ui/screens/tokenRowTitle.ts +28 -15
- package/ui/tokenFormat.ts +133 -69
- package/ui/tokenStatus.ts +5 -8
- package/core/localpay/settlementAck.ts +0 -155
- package/core/mandala/basketMigration.ts +0 -166
- package/core/mandala/bundle.ts +0 -244
- package/core/mandala/drain.ts +0 -754
- package/core/mandala/inboxPrehold.ts +0 -193
- package/core/mandala/permissionModule.ts +0 -931
- package/core/mandala/resendTransfer.ts +0 -178
- package/core/mandala/settlementStore.ts +0 -434
- package/core/mandala/token.ts +0 -45
- package/core/offline/tokenFrames.ts +0 -197
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,119 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.22.0
|
|
4
|
+
|
|
5
|
+
1Color / BRC-207 tokens through `@bsv/color-permission-module`. There is no
|
|
6
|
+
compatibility with `@bsv/mandala` 0.4: its assets, `'p mandala'` outputs,
|
|
7
|
+
`[2, 'p mandala token']` derivations, settlement tables and journals, frame
|
|
8
|
+
versions below 7, session version 1 and MessageBox bodies v1-v3 are all gone.
|
|
9
|
+
Built on design Amendment B7: the module transports no token history; the
|
|
10
|
+
host verifies hand-overs with `@bsv/mandala` and a host ledger.
|
|
11
|
+
|
|
12
|
+
### Breaking
|
|
13
|
+
|
|
14
|
+
- **Peers.** New: `@bsv/color-permission-module` ^0.2.0 and `@bsv/mandala`
|
|
15
|
+
^0.5.0. Raised: `@bsv/sdk` ^4.0.0, `@bsv/wallet-toolbox-mobile` ^2.15.0
|
|
16
|
+
(both from npm), `@bsv/templates` ^2.2.0. Hosts copy
|
|
17
|
+
`patches/@bsv+sdk+4.0.1.patch` (the color module 0.2.0 needs sdk ^4.0.1) and
|
|
18
|
+
`patches/@bsv+wallet-toolbox-mobile+2.15.0.patch` (regenerated against the
|
|
19
|
+
published 2.15.0) in place of the 2.8.11 / 2.14.9 patches and drop the
|
|
20
|
+
`@bsv+mandala+0.4.1` patch. The module's `@bsv/wallet-toolbox-client` peer
|
|
21
|
+
is satisfied by an npm alias of `-mobile` (README).
|
|
22
|
+
- **Metro and Jest.** Alias `@bsv/wallet-toolbox-client` to
|
|
23
|
+
`@bsv/wallet-toolbox-mobile` and enable package `exports` with `.mjs`/`.cjs`
|
|
24
|
+
source extensions (Metro). Transform `.mjs` with `babel-jest`, map
|
|
25
|
+
`@bsv/wallet-toolbox-client` and `@bsv/color-permission-module`, and allow
|
|
26
|
+
`@bsv/color-permission-module|@bsv/templates|@bsv/mandala` through
|
|
27
|
+
`transformIgnorePatterns` (Jest). See the README.
|
|
28
|
+
- **Token custody.** The `'p mandala'` P-module (`MandalaTokenModule`), the
|
|
29
|
+
basket migration and `wrapCreateActionForTokenInputs` are deleted.
|
|
30
|
+
WalletContext registers the BRC-207 color module as
|
|
31
|
+
`permissionModules.color` (the Mandala issuer-v1 profile only, over a
|
|
32
|
+
Mandala host ledger in `key_value_store`; a Mandala overlay provider; a
|
|
33
|
+
`ColorModuleStore` over `key_value_store`) only when the chain has Mandala
|
|
34
|
+
endpoints; otherwise `p color` calls fail closed. `BuiltColorModule` adds
|
|
35
|
+
`ledger`. `configureMandala` no longer takes a basket.
|
|
36
|
+
- **Storage.** A one-time guarded migration drops `token_settlements`,
|
|
37
|
+
`token_admissions`, `token_admission_edges` and `token_linkage_payloads` and
|
|
38
|
+
the old lib's `mandala.*` key-value journals, and creates the
|
|
39
|
+
`color_transfers` journal. The broadcast hold applies only where this
|
|
40
|
+
wallet's token custody is in a 1Color tx (a journal row, a Mandala
|
|
41
|
+
host-ledger record, or an input spent from one of its `p color` baskets)
|
|
42
|
+
and holds it until its row reads `settled`; a 1Color output with no custody
|
|
43
|
+
of ours (a payer's decoy) never parks a credit, on any rail. The abort
|
|
44
|
+
refusal keys on the journal: a `handed_over` or `settled` transfer is never
|
|
45
|
+
aborted. A pre-1Color backup
|
|
46
|
+
that still carries a settlement table is refused on import.
|
|
47
|
+
`ensureTokenSettlementColumns`, `createMandalaSettlementTables`,
|
|
48
|
+
`createSettlementStore`, `TokenTransactionRepair` and `OfflineTokenDeps` are
|
|
49
|
+
removed.
|
|
50
|
+
- **Exact amounts.** Token amounts are `bigint` in every API (per output
|
|
51
|
+
`1..18446744073709551615`) and canonical decimal strings on every wire and
|
|
52
|
+
in SQLite. `TokenBalance`, `TokenActivityRow`, `TokenAssetStatus` and the
|
|
53
|
+
`ui/tokenFormat` helpers take `bigint` units (`baseUnits` becomes `units`).
|
|
54
|
+
The `'reversed'` activity status is gone.
|
|
55
|
+
- **Runtime.** `MandalaRuntime` is the host over the color module (only its
|
|
56
|
+
host-only `markSettled(txid)`), `@bsv/mandala` 0.5.0 with the host ledger,
|
|
57
|
+
and the journal. `CreateMandalaRuntimeArgs` takes `color`
|
|
58
|
+
(`Pick<ColorPermissionModule, 'markSettled'>`), `ledger` and `hostWallet`
|
|
59
|
+
(the underlying wallet; hand-over envelopes are built from its custody);
|
|
60
|
+
`refetchBeef` is gone. Settlement is the host's: a delivered own hand-over
|
|
61
|
+
goes through lib `settleHandover`, a pending receipt through
|
|
62
|
+
`settleReceipts`, and both end in `markSettled` then the journal row.
|
|
63
|
+
Balances read the `p color balance <assetTag>` view; `offlineUnits` is the
|
|
64
|
+
same view filtered to `color_offline` (pending), the rest settled. Asset
|
|
65
|
+
metadata comes from the deploy tx (`readDeploy`). `tick()` redelivers
|
|
66
|
+
undelivered hand-overs, settles and reconciles held receipts, and the
|
|
67
|
+
offline drain runs it first.
|
|
68
|
+
- **Handle rail.** MessageBox box `mandala-color`, hand-over body `v: 4`
|
|
69
|
+
(receipt fields, σ `admission`/`admissions[]`, envelope `linkage[]`). A
|
|
70
|
+
hand-over's body is kept (`bsvwallet.color.handover.<txid>`) and its row
|
|
71
|
+
journaled `handed_over` before delivery; the tick redelivers the kept body.
|
|
72
|
+
Receive runs the lib's recipient path with the host ledger (online submit,
|
|
73
|
+
or offline COVER with the S1 hop checks) before the plain receipt is
|
|
74
|
+
internalized; a verified credit is journaled `settled`, a COVER one `held`.
|
|
75
|
+
- **Nearby.** Session version 2 (token units as a decimal string in `a`, no
|
|
76
|
+
overlay url/key) and localpay frame version 7 (IC §7.3: token block
|
|
77
|
+
`assetId`, decimal `amount`, `senderMode`, `admission?`, `admissions`,
|
|
78
|
+
`linkage`, `certificates`; frames below 7 are a `CodecError`). The payer
|
|
79
|
+
frames the v4 body of its hand-over; the payee pre-checks the evidence by
|
|
80
|
+
COVER against its own overlay key (`verifyFramePayment` opts gain
|
|
81
|
+
`overlayIdentityKey`; failures decline `not_covered`), and `processPending`
|
|
82
|
+
hands a token frame to the runtime's new `nearby.accept` (lib
|
|
83
|
+
`acceptHandover`) instead of internalizing it; `processPending` takes it as
|
|
84
|
+
a sixth argument and `NearbyTokenDeps.onReceived` reports `offline`. The
|
|
85
|
+
σI pieces are removed: `offline/tokenFrames`, `localpay/settlementAck`,
|
|
86
|
+
`mandala/drain`, `mandala/bundle` (`coverFromFrame`, `assembleBundle`,
|
|
87
|
+
`tokenParentsOf`) and their exports. A nearby BSV frame carrying a 1Color
|
|
88
|
+
output is no longer declined: the custody-scoped hold does not park it.
|
|
89
|
+
- **Hosted payer renderers.** On a token session `NearbyConfirm`,
|
|
90
|
+
`NearbySending` and `NearbyShowCode` carry the exact figure as `units`
|
|
91
|
+
(bigint) and `amountText`, and `NearbyConfirm` adds `fixedUnits`. The
|
|
92
|
+
number-shaped `amount` is 0 and `fixedAmount` is undefined there, and
|
|
93
|
+
`NearbyDone.amount` is 0 on a token payment. `NearbyConfirm.holding` is a
|
|
94
|
+
bigint, and `setAmount` takes a bigint (token base units) or a number
|
|
95
|
+
(satoshis). Hosts gate Send on `canSend` and read the payee's figure from
|
|
96
|
+
`fixedUnits` on a token session, never from `amount` / `fixedAmount`.
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
|
|
100
|
+
- Core barrel: `buildColorModule`, `createColorModuleStore`,
|
|
101
|
+
`createColorAccessPolicy`, `colorPromptType`, `COLOR_PROMPT_TYPES`,
|
|
102
|
+
`createTransferJournal`, `migrateMandalaToColor`, `colorHeldTxids`,
|
|
103
|
+
`txHasColorOutput`, the inventory readers (`readInventory`,
|
|
104
|
+
`readAvailable`, `readPending`, `offlineUnitsOf`, `createAssetMetadata`),
|
|
105
|
+
the v7 frame helpers (`bodyFromFrame`, `tokenPaymentOfHandover`), the
|
|
106
|
+
receipt failure classifiers and `createHandoverBodies`.
|
|
107
|
+
- The permission sheet renders the color module's consent messages
|
|
108
|
+
(`color_send`, `color_signature`, `color_access`, `color_relinquish`) with
|
|
109
|
+
exact amounts and the full asset id. The wallet's own screens are approved
|
|
110
|
+
for every type; a connected app prompts, and a read approval lasts 30
|
|
111
|
+
minutes for that app only. The removed `color_receive_offline` type is
|
|
112
|
+
unknown and refused.
|
|
113
|
+
- The services for the scaling teratestnet (`scaletest`, toolbox chain
|
|
114
|
+
`'regtest'`) now build on toolbox 2.15.0. The network stays out of the
|
|
115
|
+
picker.
|
|
116
|
+
|
|
3
117
|
## 0.21.0
|
|
4
118
|
|
|
5
119
|
### Breaking
|
package/README.md
CHANGED
|
@@ -55,17 +55,30 @@ Expo SDK line.
|
|
|
55
55
|
|
|
56
56
|
### BSV SDK & protocol libraries (required)
|
|
57
57
|
|
|
58
|
-
| Package
|
|
59
|
-
|
|
|
60
|
-
| `@bsv/sdk`
|
|
61
|
-
| `@bsv/wallet-toolbox-mobile`
|
|
62
|
-
| `@bsv/btms-permission-module`
|
|
63
|
-
| `@bsv/
|
|
64
|
-
| `@bsv/
|
|
65
|
-
| `@bsv/
|
|
66
|
-
| `@bsv/
|
|
67
|
-
| `@
|
|
68
|
-
| `
|
|
58
|
+
| Package | Version |
|
|
59
|
+
| ------------------------------ | ------- |
|
|
60
|
+
| `@bsv/sdk` | ^4.0.0 |
|
|
61
|
+
| `@bsv/wallet-toolbox-mobile` | ^2.15.0 |
|
|
62
|
+
| `@bsv/btms-permission-module` | ^1.2.1 |
|
|
63
|
+
| `@bsv/color-permission-module` | ^0.2.0 |
|
|
64
|
+
| `@bsv/mandala` | ^0.5.0 |
|
|
65
|
+
| `@bsv/air-gap` | ^0.1.3 |
|
|
66
|
+
| `@bsv/backup-cache-client` | ^0.1.0 |
|
|
67
|
+
| `@bsv/message-box-client` | ^2.5.3 |
|
|
68
|
+
| `@bsv/templates` | ^2.2.0 |
|
|
69
|
+
| `@noble/curves` | ^2.3.0 |
|
|
70
|
+
| `qrcode` | ^1.5.4 |
|
|
71
|
+
|
|
72
|
+
`@bsv/color-permission-module` is the BRC-207 color module that holds every
|
|
73
|
+
1Color token output; `@bsv/mandala` builds and reads Mandala hand-overs.
|
|
74
|
+
`@bsv/color-permission-module` imports `@bsv/wallet-toolbox-client`, which a
|
|
75
|
+
React Native app must alias to `@bsv/wallet-toolbox-mobile` (see
|
|
76
|
+
[`metro.config.js`](#metroconfigjs) and [Jest configuration](#jest-configuration)).
|
|
77
|
+
The module also declares `@bsv/wallet-toolbox-client` as a peer; satisfy it
|
|
78
|
+
with an npm alias of the mobile toolbox, e.g.
|
|
79
|
+
`"@bsv/wallet-toolbox-client": "npm:@bsv/wallet-toolbox-mobile@^2.15.0"`, so no
|
|
80
|
+
second toolbox is installed. That copy is never loaded (the bundler and Jest
|
|
81
|
+
map the name to `-mobile`), so `patch-package` patches only `-mobile`.
|
|
69
82
|
|
|
70
83
|
### Expo native modules (required — each needs its own autolinking/config)
|
|
71
84
|
|
|
@@ -462,6 +475,17 @@ config.resolver.extraNodeModules = {
|
|
|
462
475
|
...config.resolver.extraNodeModules
|
|
463
476
|
}
|
|
464
477
|
|
|
478
|
+
// The 1Color packages (@bsv/color-permission-module, @bsv/mandala,
|
|
479
|
+
// @bsv/templates) resolve through package `exports` to .mjs/.cjs entries.
|
|
480
|
+
config.resolver.unstable_enablePackageExports = true
|
|
481
|
+
for (const ext of ['mjs', 'cjs']) {
|
|
482
|
+
if (!config.resolver.sourceExts.includes(ext)) config.resolver.sourceExts.push(ext)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// @bsv/color-permission-module imports @bsv/wallet-toolbox-client; on React
|
|
486
|
+
// Native that is the same toolbox as -mobile (one toolbox in the bundle).
|
|
487
|
+
const MODULE_ALIASES = { '@bsv/wallet-toolbox-client': '@bsv/wallet-toolbox-mobile' }
|
|
488
|
+
|
|
465
489
|
const emptyShim = path.resolve(__dirname, 'metro-shims/empty.js') // module.exports = {}
|
|
466
490
|
const quickCryptoMain = require.resolve('react-native-quick-crypto')
|
|
467
491
|
|
|
@@ -473,6 +497,9 @@ config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
|
473
497
|
if (moduleName === 'node:buffer' || moduleName === 'node:process') {
|
|
474
498
|
return { type: 'sourceFile', filePath: emptyShim }
|
|
475
499
|
}
|
|
500
|
+
if (Object.prototype.hasOwnProperty.call(MODULE_ALIASES, moduleName)) {
|
|
501
|
+
moduleName = MODULE_ALIASES[moduleName]
|
|
502
|
+
}
|
|
476
503
|
if (typeof upstream === 'function') return upstream(context, moduleName, platform)
|
|
477
504
|
return context.resolveRequest(context, moduleName, platform)
|
|
478
505
|
}
|
|
@@ -496,7 +523,7 @@ are required — both hard-won during this package's extraction:
|
|
|
496
523
|
|
|
497
524
|
```
|
|
498
525
|
transformIgnorePatterns: [
|
|
499
|
-
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|react-native-reanimated|react-native-gesture-handler|react-native-worklets|expo-modules-core|@noble/secp256k1|@noble/curves|@noble/hashes|@bsv/backup-cache-client|@bsv/auth|@bsv/expo-wallet-toolbox|@bsv/react-native-localpay-transport)/)",
|
|
526
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|react-native-reanimated|react-native-gesture-handler|react-native-worklets|expo-modules-core|@noble/secp256k1|@noble/curves|@noble/hashes|@bsv/backup-cache-client|@bsv/auth|@bsv/expo-wallet-toolbox|@bsv/color-permission-module|@bsv/templates|@bsv/mandala|@bsv/react-native-localpay-transport|@bsv/webrtpay)/)",
|
|
500
527
|
"/node_modules/react-native-reanimated/plugin/"
|
|
501
528
|
]
|
|
502
529
|
```
|
|
@@ -510,7 +537,11 @@ are required — both hard-won during this package's extraction:
|
|
|
510
537
|
`@bsv/expo-wallet-toolbox`, `@bsv/react-native-localpay-transport`
|
|
511
538
|
(also raw TypeScript — `core/localpay/transport/select.ts` imports it
|
|
512
539
|
directly), and `@bsv/backup-cache-client` (see below) must be in
|
|
513
|
-
whatever pattern you end up with.
|
|
540
|
+
whatever pattern you end up with. Since 0.21.0 the allowlist must also
|
|
541
|
+
name `@bsv/color-permission-module`, `@bsv/templates` and `@bsv/mandala`:
|
|
542
|
+
they ship ES modules (`.mjs`) that Jest's CJS runtime must transform.
|
|
543
|
+
(`@bsv/webrtpay` is this repo's own optional peer; add it only if you
|
|
544
|
+
install it.)
|
|
514
545
|
|
|
515
546
|
`@urbit/sigil-js`, the peer added with the activity-row sigil avatars,
|
|
516
547
|
needs no entry here: the `./core` entry this package imports ships CJS,
|
|
@@ -526,6 +557,12 @@ are required — both hard-won during this package's extraction:
|
|
|
526
557
|
moduleNameMapper: {
|
|
527
558
|
'^@bsv/backup-cache-client$':
|
|
528
559
|
'<rootDir>/node_modules/@bsv/backup-cache-client/dist/index.js',
|
|
560
|
+
'^@bsv/wallet-toolbox-client$':
|
|
561
|
+
'<rootDir>/node_modules/@bsv/wallet-toolbox-mobile/out/index.mobile.cjs',
|
|
562
|
+
'^@bsv/wallet-toolbox-mobile$':
|
|
563
|
+
'<rootDir>/node_modules/@bsv/wallet-toolbox-mobile/out/index.mobile.cjs',
|
|
564
|
+
'^@bsv/color-permission-module$':
|
|
565
|
+
'<rootDir>/node_modules/@bsv/color-permission-module/dist/index.mjs',
|
|
529
566
|
'^react-native-reanimated$': '<rootDir>/__tests__/__mocks__/reanimated.js',
|
|
530
567
|
'^react-native-worklets$':
|
|
531
568
|
'<rootDir>/node_modules/react-native-worklets/lib/module/mock.js',
|
|
@@ -548,6 +585,23 @@ are required — both hard-won during this package's extraction:
|
|
|
548
585
|
entries below, which only bite once a test actually exercises that
|
|
549
586
|
native API.
|
|
550
587
|
|
|
588
|
+
The three 1Color entries (since 0.21.0):
|
|
589
|
+
- `@bsv/wallet-toolbox-client` → the mobile toolbox's CJS entry. The color
|
|
590
|
+
module imports `-client`; this is the same alias as in Metro, so tests
|
|
591
|
+
and the app run one toolbox.
|
|
592
|
+
- `@bsv/wallet-toolbox-mobile` → the same CJS entry, so both names resolve
|
|
593
|
+
to one module instance.
|
|
594
|
+
- `@bsv/color-permission-module` → `dist/index.mjs`. Its `exports` carries
|
|
595
|
+
only an `import` condition, which Jest's require-side resolver never
|
|
596
|
+
matches.
|
|
597
|
+
|
|
598
|
+
Add a transform for `.mjs` beside the preset's, so those `.mjs` entries go
|
|
599
|
+
through Babel:
|
|
600
|
+
|
|
601
|
+
```js
|
|
602
|
+
transform: { '\\.mjs$': 'babel-jest' }
|
|
603
|
+
```
|
|
604
|
+
|
|
551
605
|
`expo-sqlite`/`expo-audio` need hand-written mocks (see this repo's
|
|
552
606
|
`__tests__/__mocks__/` for working examples) since they wrap native
|
|
553
607
|
modules with no official Jest mock; `async-storage` and
|
|
@@ -562,6 +616,17 @@ are required — both hard-won during this package's extraction:
|
|
|
562
616
|
|
|
563
617
|
## Breaking changes
|
|
564
618
|
|
|
619
|
+
**0.21.0:** tokens are 1Color (BRC-162) assets held by the BRC-207 color
|
|
620
|
+
module, with no compatibility with `@bsv/mandala` 0.4 assets, outputs or the
|
|
621
|
+
`'p mandala'` basket. Install the new peers (`@bsv/color-permission-module`
|
|
622
|
+
^0.2.0, `@bsv/mandala` ^0.5.0) and the raised ones (`@bsv/sdk` ^4.0.0,
|
|
623
|
+
`@bsv/wallet-toolbox-mobile` ^2.15.0, `@bsv/templates` ^2.2.0). Copy
|
|
624
|
+
`patches/@bsv+sdk+4.0.1.patch` and `patches/@bsv+wallet-toolbox-mobile+2.15.0.patch`
|
|
625
|
+
in place of the 2.8.11/2.14.9 patches, and delete any `@bsv+mandala+0.4.1`
|
|
626
|
+
patch. Add the Metro alias and `exports` settings and the Jest `.mjs`
|
|
627
|
+
transform, mappers and allowlist entries above. Token amounts are `bigint`
|
|
628
|
+
everywhere. See the CHANGELOG's 0.21.0 entry for the full list.
|
|
629
|
+
|
|
565
630
|
**0.10.0:** `verifyFramePayment` takes `{ wallet, chainTracker }`
|
|
566
631
|
(`FrameVerifyDeps`) as its first argument instead of a single wallet, and
|
|
567
632
|
`DerivingWallet` no longer includes `getServices()`. Pass the permissions
|
|
@@ -13,13 +13,19 @@
|
|
|
13
13
|
* window, not full history: an old inbound payment outside it will not
|
|
14
14
|
* surface here. Documented limitation (see the 2026-09-18 spec) rather
|
|
15
15
|
* than a silent one.
|
|
16
|
-
* 3. Token transfers — EXACT, via `
|
|
17
|
-
*
|
|
16
|
+
* 3. Token transfers — EXACT, via the `color_transfers` journal's
|
|
17
|
+
* `counterpartyKey` (plan 07 W1). Units are exact `bigint`s read from the
|
|
18
|
+
* journal's canonical decimal TEXT, never a number. A received row's key
|
|
19
|
+
* is the sender's key as the hand-over named it (blinded A′ by default,
|
|
20
|
+
* spec D2), so an inbound blinded payment matches no contact; that is the
|
|
21
|
+
* blinding working, not a gap.
|
|
18
22
|
*
|
|
19
23
|
* The address rail is never attributable to a contact (no key in its label)
|
|
20
24
|
* and is excluded here the same way it is everywhere else in the app.
|
|
21
25
|
*/
|
|
26
|
+
import { parseDecimalAmount } from '@bsv/mandala'
|
|
22
27
|
import { counterpartyOf } from '../pay/counterparty'
|
|
28
|
+
import type { ColorTransferRole, ColorTransferState } from '../mandala/types'
|
|
23
29
|
|
|
24
30
|
/** The recent-window size for source (2) above. */
|
|
25
31
|
export const RECENT_WINDOW = 200
|
|
@@ -44,14 +50,15 @@ export interface ContactActivityWallet {
|
|
|
44
50
|
): Promise<{ actions: ContactBsvAction[] }>
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
/** The slice of `
|
|
48
|
-
export interface
|
|
53
|
+
/** The slice of a `color_transfers` row this module reads. */
|
|
54
|
+
export interface ContactTransferRow {
|
|
49
55
|
txid: string
|
|
50
|
-
role:
|
|
56
|
+
role: ColorTransferRole
|
|
51
57
|
assetId: string
|
|
52
|
-
state:
|
|
58
|
+
state: ColorTransferState
|
|
53
59
|
counterpartyKey?: string
|
|
54
|
-
|
|
60
|
+
/** Exact token units; absent when the stored text does not read back exactly (no figure beats a wrong one). */
|
|
61
|
+
units?: bigint
|
|
55
62
|
createdAt: string
|
|
56
63
|
}
|
|
57
64
|
|
|
@@ -59,7 +66,7 @@ export interface ContactSettlementsDb {
|
|
|
59
66
|
getAllAsync(sql: string, params: (string | number | null)[]): Promise<unknown[]>
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
export type ContactActivityItem = ({ kind: 'bsv' } & ContactBsvAction) | ({ kind: 'token' } &
|
|
69
|
+
export type ContactActivityItem = ({ kind: 'bsv' } & ContactBsvAction) | ({ kind: 'token' } & ContactTransferRow)
|
|
63
70
|
|
|
64
71
|
function timeOf(item: ContactActivityItem): number {
|
|
65
72
|
const raw = item.kind === 'bsv' ? item.created_at : item.createdAt
|
|
@@ -68,40 +75,53 @@ function timeOf(item: ContactActivityItem): number {
|
|
|
68
75
|
return Number.isNaN(ts) ? 0 : ts
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
/** How many journal rows one contact page reads; the newest are the ones a person looks for. */
|
|
79
|
+
export const TRANSFER_WINDOW = 500
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Token transfers with this counterparty, newest first, from the
|
|
83
|
+
* `color_transfers` journal. A cancelled send is left out: that money never
|
|
84
|
+
* moved (the same rule the runtime's activity list keeps). Exported separately
|
|
85
|
+
* so it can be unit-tested against a real in-memory SQLite without a wallet in
|
|
86
|
+
* the loop.
|
|
87
|
+
*/
|
|
88
|
+
export async function listTokenTransfersByCounterparty(
|
|
75
89
|
db: ContactSettlementsDb,
|
|
76
90
|
counterpartyKey: string
|
|
77
|
-
): Promise<
|
|
91
|
+
): Promise<ContactTransferRow[]> {
|
|
78
92
|
const rows = (await db.getAllAsync(
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
`SELECT txid, role, assetId, units, state, counterpartyKey, createdAt FROM color_transfers
|
|
94
|
+
WHERE counterpartyKey = ? AND state <> 'cancelled' ORDER BY createdAt DESC, rowid DESC LIMIT ?`,
|
|
95
|
+
[counterpartyKey, TRANSFER_WINDOW]
|
|
81
96
|
)) as {
|
|
82
97
|
txid: string
|
|
83
98
|
role: string
|
|
84
99
|
assetId: string
|
|
100
|
+
units: unknown
|
|
85
101
|
state: string
|
|
86
102
|
counterpartyKey: string | null
|
|
87
|
-
amountBaseUnits: number | null
|
|
88
103
|
createdAt: string
|
|
89
104
|
}[]
|
|
90
|
-
return rows.map(r =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
return rows.map(r => {
|
|
106
|
+
const row: ContactTransferRow = {
|
|
107
|
+
txid: r.txid,
|
|
108
|
+
role: r.role as ColorTransferRole,
|
|
109
|
+
assetId: r.assetId,
|
|
110
|
+
state: r.state as ColorTransferState,
|
|
111
|
+
createdAt: r.createdAt
|
|
112
|
+
}
|
|
113
|
+
if (r.counterpartyKey) row.counterpartyKey = r.counterpartyKey
|
|
114
|
+
const units = parseDecimalAmount(r.units)
|
|
115
|
+
if (units !== null) row.units = units
|
|
116
|
+
return row
|
|
117
|
+
})
|
|
99
118
|
}
|
|
100
119
|
|
|
101
120
|
/**
|
|
102
121
|
* Every activity item with `identityKey`, merged and sorted newest first.
|
|
103
122
|
*
|
|
104
|
-
* `wallet` and `settlementsDb`
|
|
123
|
+
* `wallet` and `settlementsDb` (the wallet database holding `color_transfers`)
|
|
124
|
+
* are both optional so a caller that only has
|
|
105
125
|
* one half built (e.g. a token-less wallet) still gets what it can — same
|
|
106
126
|
* fail-open posture as `resolveIdentity.ts`.
|
|
107
127
|
*/
|
|
@@ -142,8 +162,8 @@ export async function getContactActivity(args: {
|
|
|
142
162
|
|
|
143
163
|
if (settlementsDb) {
|
|
144
164
|
try {
|
|
145
|
-
const
|
|
146
|
-
for (const row of
|
|
165
|
+
const transfers = await listTokenTransfersByCounterparty(settlementsDb, identityKey)
|
|
166
|
+
for (const row of transfers) items.push({ kind: 'token', ...row })
|
|
147
167
|
} catch {
|
|
148
168
|
// Same posture as above.
|
|
149
169
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `ContactsStore` over the toolbox's own SQLite connection.
|
|
3
3
|
*
|
|
4
|
-
* Deliberately logic-free, same spirit as `mandala/
|
|
4
|
+
* Deliberately logic-free, same spirit as `mandala/transferJournal.ts`: every
|
|
5
5
|
* decision (what counts as a match, how activity is aggregated) lives in the
|
|
6
6
|
* callers of this module. What is here is statements.
|
|
7
7
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `renameContact`, which exists for exactly that. A background identity
|
|
11
11
|
* refresh calls `refreshContactCache` instead, which never touches `name`.
|
|
12
12
|
*
|
|
13
|
-
* Access pattern matches `
|
|
13
|
+
* Access pattern matches `transferJournal.ts`: the caller hands in
|
|
14
14
|
* `storage.sqliteDb` and this module only ever issues parameterised statements
|
|
15
15
|
* against it.
|
|
16
16
|
*/
|