@bsv/expo-wallet-toolbox 0.11.3 → 0.11.5
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,52 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.5
|
|
4
|
+
|
|
5
|
+
### External wallet guard: BRC-29 and FT payments to another party
|
|
6
|
+
|
|
7
|
+
The guard refused every external call under the wallet's own payment-rail
|
|
8
|
+
namespaces (`[2,'3241645161d8']` for BRC-29/PeerPay and `[2,'mandala token']`
|
|
9
|
+
for the FT rail), including `getPublicKey`. That blocked the first step of
|
|
10
|
+
every BRC-29 payment a dApp makes (fast.brc.dev "Pay to Identity",
|
|
11
|
+
`@bsv/sdk` `BasicBRC29` / PeerPay settlements) with 'Wallet operation
|
|
12
|
+
"getPublicKey" is not permitted for origin "…"'.
|
|
13
|
+
|
|
14
|
+
- `getPublicKey` under those namespaces is now allowed when `counterparty` is
|
|
15
|
+
another party's identity key, with `forSelf` either way: the payer and payee
|
|
16
|
+
steps of a BRC-29 or FT payment. ECDH is symmetric, so that party can compute
|
|
17
|
+
the same public key itself.
|
|
18
|
+
- Still refused: `counterparty` `'anyone'` (the address rail, whose keyIDs are
|
|
19
|
+
guessable dates) or the wallet's own identity key (FT change), in any valid
|
|
20
|
+
encoding; `privileged` calls; any call if the wallet's identity key cannot be
|
|
21
|
+
read; and `createSignature`, `encrypt`, `decrypt`, `createHmac`,
|
|
22
|
+
`verifyHmac`, `verifySignature` and the key-linkage methods under these
|
|
23
|
+
namespaces, which are what could spend or expose the wallet's own funds.
|
|
24
|
+
- External `getPublicKey` arguments are now checked and used as one plain
|
|
25
|
+
copy, so a caller's object cannot present different values to the check and
|
|
26
|
+
to the derivation.
|
|
27
|
+
|
|
28
|
+
## 0.11.4
|
|
29
|
+
|
|
30
|
+
### dApp results the SDK rejected: noSend actions and identity discovery
|
|
31
|
+
|
|
32
|
+
Three wallet responses from `@bsv/wallet-toolbox-mobile` 2.14.3 fail
|
|
33
|
+
`@bsv/sdk` 2.8.8+ result validation in every dApp. `conformWalletResults`
|
|
34
|
+
(`core/services/conformWalletResults.ts`) wraps the permissions manager and
|
|
35
|
+
corrects them until the library ships the same fixes (bsv-blockchain/ts-stack#673):
|
|
36
|
+
|
|
37
|
+
- A `createAction` with `noSend` returned `noSendChange` outpoints on the
|
|
38
|
+
unsigned txid next to the signed `txid` (`noSendChange[0]: expected an
|
|
39
|
+
outpoint of the returned transaction`). They now name the signed transaction.
|
|
40
|
+
- That no-send action could not be released: the caller only has its `txid`,
|
|
41
|
+
and the permissions manager refused `abortAction` by txid from any non-admin
|
|
42
|
+
origin, so its inputs stayed locked until no-send expiry. The origin that
|
|
43
|
+
created it in this session may now abort it; another origin still cannot, and
|
|
44
|
+
a broadcast action is never abortable this way.
|
|
45
|
+
- `discoverByIdentityKey` and `discoverByAttributes` ignored `limit`/`offset`
|
|
46
|
+
(`certificates: expected at most the requested limit`). They now return the
|
|
47
|
+
requested page (10 when no limit is given); `totalCertificates` still counts
|
|
48
|
+
every match.
|
|
49
|
+
|
|
3
50
|
## 0.11.3
|
|
4
51
|
|
|
5
52
|
### Identity lookups: default certifier descriptions fit BRC-100
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from '@bsv/wallet-toolbox-mobile'
|
|
16
16
|
import { KeyDeriver, PrivateKey, MerklePath, Transaction, Utils } from '@bsv/sdk'
|
|
17
17
|
import { DEFAULT_SETTINGS } from './defaultWalletSettings'
|
|
18
|
+
import { conformWalletResults } from '../services/conformWalletResults'
|
|
18
19
|
import { VAULT_RETENTION_MS, ceremony as vaultCeremony } from '../services/vault/ceremonyHost'
|
|
19
20
|
import { getVaultDriver } from '../services/vault/driver'
|
|
20
21
|
import { backupAttestation } from '../services/vault/backupAttestation'
|
|
@@ -1768,7 +1769,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1768
1769
|
// rows unreadable rather than absent.
|
|
1769
1770
|
newManagers.permissionsManager = guardVaultAccess(
|
|
1770
1771
|
wrapAbortActionForSettlements(
|
|
1771
|
-
wrapCreateActionForTokenInputs(
|
|
1772
|
+
wrapCreateActionForTokenInputs(
|
|
1773
|
+
conformWalletResults(adminOriginator, permissionsManager),
|
|
1774
|
+
listMandalaTokenOutpoints,
|
|
1775
|
+
adminOriginator
|
|
1776
|
+
),
|
|
1772
1777
|
() => mandalaRef.current?.store,
|
|
1773
1778
|
() => mandalaEndpoints !== undefined
|
|
1774
1779
|
),
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brings two @bsv/wallet-toolbox-mobile 2.14.3 results in line with what
|
|
3
|
+
* @bsv/sdk 2.8.8+ accepts. Without this, every dApp using the SDK sees them as
|
|
4
|
+
* invalid wallet responses:
|
|
5
|
+
*
|
|
6
|
+
* - createAction: when the permissions manager signs a non-admin action
|
|
7
|
+
* itself, `noSendChange` still names the unsigned txid next to the signed
|
|
8
|
+
* `txid` ("noSendChange[0]: expected an outpoint of the returned
|
|
9
|
+
* transaction"). Signing never moves outputs, so only the txid changes.
|
|
10
|
+
* - discoverByIdentityKey / discoverByAttributes: every trusted match comes
|
|
11
|
+
* back regardless of `limit`/`offset` ("expected at most the requested
|
|
12
|
+
* limit"). `totalCertificates` keeps counting every match.
|
|
13
|
+
* - abortAction: that signed no-send action can only be released by its txid,
|
|
14
|
+
* which the manager refuses from any non-admin originator. The origin that
|
|
15
|
+
* created it in this session may abort it; the wrapper forwards that one
|
|
16
|
+
* abort as the admin. Any other reference goes through the manager's own
|
|
17
|
+
* check unchanged, and a broadcast action is never recorded.
|
|
18
|
+
*
|
|
19
|
+
* bsv-blockchain/ts-stack fixes all three in @bsv/wallet-toolbox 2.14.4; drop this
|
|
20
|
+
* wrapper once @bsv/wallet-toolbox-mobile ships that.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const DEFAULT_DISCOVERY_LIMIT = 10
|
|
24
|
+
|
|
25
|
+
interface CreateActionResultLike {
|
|
26
|
+
txid?: string
|
|
27
|
+
noSendChange?: string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface DiscoveryResultLike {
|
|
31
|
+
totalCertificates: number
|
|
32
|
+
certificates: unknown[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function noSendChangeOnTxid<R>(result: R): R {
|
|
36
|
+
const r = result as CreateActionResultLike | undefined
|
|
37
|
+
if (!r?.txid || !Array.isArray(r.noSendChange)) return result
|
|
38
|
+
const txid = r.txid
|
|
39
|
+
return {
|
|
40
|
+
...r,
|
|
41
|
+
noSendChange: r.noSendChange.map(outpoint => `${txid}.${outpoint.slice(outpoint.lastIndexOf('.') + 1)}`)
|
|
42
|
+
} as R
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function discoveryPage<R>(result: R, args: { limit?: number; offset?: number } | undefined): R {
|
|
46
|
+
const r = result as DiscoveryResultLike | undefined
|
|
47
|
+
if (!r || !Array.isArray(r.certificates)) return result
|
|
48
|
+
const offset = args?.offset ?? 0
|
|
49
|
+
const limit = args?.limit ?? DEFAULT_DISCOVERY_LIMIT
|
|
50
|
+
return { ...r, certificates: r.certificates.slice(offset, offset + limit) } as R
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function noSendKey(reference: unknown): string {
|
|
54
|
+
return typeof reference === 'string' ? reference.toLowerCase() : ''
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function conformWalletResults<T extends object>(adminOriginator: string, manager: T): T {
|
|
58
|
+
// txid of each signed no-send action → the originator that created it.
|
|
59
|
+
const noSendOriginators = new Map<string, string>()
|
|
60
|
+
return new Proxy(manager, {
|
|
61
|
+
get(target, prop, receiver) {
|
|
62
|
+
const value = Reflect.get(target, prop, receiver)
|
|
63
|
+
if (typeof value !== 'function') return value
|
|
64
|
+
if (prop === 'createAction') {
|
|
65
|
+
return async (args: { options?: { noSend?: boolean } } | undefined, originator?: string) => {
|
|
66
|
+
const result = noSendChangeOnTxid(await value.call(target, args, originator)) as CreateActionResultLike
|
|
67
|
+
if (args?.options?.noSend === true && result?.txid && originator !== adminOriginator) {
|
|
68
|
+
noSendOriginators.set(noSendKey(result.txid), originator ?? '')
|
|
69
|
+
}
|
|
70
|
+
return result
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (prop === 'abortAction') {
|
|
74
|
+
return async (args: { reference?: string } | undefined, originator?: string) => {
|
|
75
|
+
const key = noSendKey(args?.reference)
|
|
76
|
+
const owner = noSendOriginators.get(key)
|
|
77
|
+
if (owner === undefined || originator === adminOriginator) return await value.call(target, args, originator)
|
|
78
|
+
if (owner !== (originator ?? '')) throw new Error('The action reference belongs to a different originator.')
|
|
79
|
+
const result = await value.call(target, args, adminOriginator)
|
|
80
|
+
if ((result as { aborted?: boolean } | undefined)?.aborted === true) noSendOriginators.delete(key)
|
|
81
|
+
return result
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (prop === 'discoverByIdentityKey' || prop === 'discoverByAttributes') {
|
|
85
|
+
return async (...args: unknown[]) =>
|
|
86
|
+
discoveryPage(await value.apply(target, args), args[0] as { limit?: number; offset?: number })
|
|
87
|
+
}
|
|
88
|
+
return value.bind(target)
|
|
89
|
+
}
|
|
90
|
+
}) as T
|
|
91
|
+
}
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import {
|
|
26
26
|
LockingScript,
|
|
27
|
+
PrivateKey,
|
|
28
|
+
PublicKey,
|
|
27
29
|
Transaction,
|
|
28
30
|
Validation,
|
|
29
31
|
type ListActionsArgs,
|
|
@@ -121,9 +123,50 @@ const VAULT_PROTOCOL_NAMES = new Set(['vault', 'vault salt', 'vault marker', 'va
|
|
|
121
123
|
* core/localpay/build.ts proves createSignature+getPublicKey over them is
|
|
122
124
|
* sufficient to construct a valid spend -- so a connected origin must not be
|
|
123
125
|
* able to mint either primitive under these namespaces itself, exactly as
|
|
124
|
-
* for Vault's own namespaces.
|
|
126
|
+
* for Vault's own namespaces. The one exception is getPublicKey toward
|
|
127
|
+
* another party's identity key (see derivesTowardAnotherParty). */
|
|
125
128
|
const RESERVED_RAIL_PROTOCOL_NAMES = new Set(['3241645161d8', 'mandala token'])
|
|
126
129
|
|
|
130
|
+
/** The BRC-42 'anyone' counterparty (1·G), in canonical form. */
|
|
131
|
+
const ANYONE_PUBLIC_KEY = new PrivateKey(1).toPublicKey().toString()
|
|
132
|
+
|
|
133
|
+
/** Canonical (compressed) hex of a counterparty given as a public key;
|
|
134
|
+
* undefined for 'self', 'anyone', a non-string, or anything that is not a
|
|
135
|
+
* point on the curve. Parsing and re-encoding means another encoding of the
|
|
136
|
+
* same point cannot pass a comparison its canonical form would fail. */
|
|
137
|
+
function counterpartyPublicKey(counterparty: unknown): string | undefined {
|
|
138
|
+
if (typeof counterparty !== 'string') return undefined
|
|
139
|
+
try {
|
|
140
|
+
return PublicKey.fromString(counterparty).toString()
|
|
141
|
+
} catch {
|
|
142
|
+
return undefined
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** getPublicKey under a reserved rail namespace toward another party's
|
|
147
|
+
* identity key is the ordinary BRC-29 / FT payer (forSelf false) and payee
|
|
148
|
+
* (forSelf true) step every payment dApp takes. ECDH is symmetric, so that
|
|
149
|
+
* party can compute the same public key itself: revealing it neither signs
|
|
150
|
+
* nor tells anyone anything new. createSignature and the other private-key
|
|
151
|
+
* methods stay reserved, as do the two counterparties this wallet's own funds
|
|
152
|
+
* are locked to where a site could guess the keyID: 'anyone' (the address
|
|
153
|
+
* rail's date keyIDs) and the wallet's own identity key (FT change). Any
|
|
154
|
+
* failure to read the identity key counts as a match, so the call is refused. */
|
|
155
|
+
async function derivesTowardAnotherParty(
|
|
156
|
+
getPublicKey: (args: any, originator?: string) => Promise<{ publicKey: string }>,
|
|
157
|
+
args: any,
|
|
158
|
+
adminOriginator: string
|
|
159
|
+
): Promise<boolean> {
|
|
160
|
+
const counterparty = counterpartyPublicKey(args?.counterparty)
|
|
161
|
+
if (counterparty === undefined || counterparty === ANYONE_PUBLIC_KEY) return false
|
|
162
|
+
try {
|
|
163
|
+
const own = counterpartyPublicKey((await getPublicKey({ identityKey: true }, adminOriginator))?.publicKey)
|
|
164
|
+
return own !== undefined && counterparty !== own
|
|
165
|
+
} catch {
|
|
166
|
+
return false
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
127
170
|
/** XR-027: protocol namespace this package's own saved-pairing authority tag
|
|
128
171
|
* is derived under. A saved connection's approved (origin, topic, protocolID,
|
|
129
172
|
* backendIdentityKey) tuple is MAC'd with the admin-scoped wallet at approval
|
|
@@ -644,15 +687,28 @@ export function guardVaultAccess<T extends WalletInterface>(
|
|
|
644
687
|
|
|
645
688
|
if (!PRIVILEGED_CAPABLE.has(method) && !OUTPUT_NAMING.has(method)) return value.bind(target)
|
|
646
689
|
|
|
647
|
-
return async (
|
|
648
|
-
if (originator === adminOriginator) return await bound(
|
|
690
|
+
return async (rawArgs: any, originator?: string) => {
|
|
691
|
+
if (originator === adminOriginator) return await bound(rawArgs, originator)
|
|
692
|
+
// The reserved-rail getPublicKey check awaits before deriving. Decide
|
|
693
|
+
// on, and derive from, one plain copy so an accessor on the caller's
|
|
694
|
+
// object cannot answer the check with one counterparty and the
|
|
695
|
+
// derivation with another.
|
|
696
|
+
let args = rawArgs
|
|
697
|
+
if (method === 'getPublicKey' && rawArgs !== null && typeof rawArgs === 'object') {
|
|
698
|
+
try {
|
|
699
|
+
args = JSON.parse(JSON.stringify(rawArgs))
|
|
700
|
+
} catch {
|
|
701
|
+
return deny(String(method), originator)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
649
704
|
if (
|
|
650
705
|
PRIVILEGED_CAPABLE.has(method) &&
|
|
651
706
|
(args?.privileged ||
|
|
652
707
|
requestsVaultProtocol(args) ||
|
|
653
|
-
requestsReservedRailProtocol(args) ||
|
|
654
708
|
requestsConnectionAuthorityProtocol(args) ||
|
|
655
|
-
requestsPendingAbortAuthorityProtocol(args)
|
|
709
|
+
requestsPendingAbortAuthorityProtocol(args) ||
|
|
710
|
+
(requestsReservedRailProtocol(args) &&
|
|
711
|
+
!(method === 'getPublicKey' && (await derivesTowardAnotherParty(bound, args, adminOriginator)))))
|
|
656
712
|
) {
|
|
657
713
|
return deny(String(method), originator)
|
|
658
714
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
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",
|