@bsv/expo-wallet-toolbox 0.11.7 → 0.11.8
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,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.8
|
|
4
|
+
|
|
5
|
+
### Grouped permission prompt
|
|
6
|
+
|
|
7
|
+
A site whose `manifest.json` declares `metanet.groupPermissions` is now asked
|
|
8
|
+
for them in one drawer when it connects (`waitForAuthentication`), the same
|
|
9
|
+
sheet and buttons as a spending prompt, listing the spending allowance and each
|
|
10
|
+
protocol, basket and certificate the site says it needs.
|
|
11
|
+
|
|
12
|
+
- Authorize grants exactly that set (`grantGroupedPermission`), minting its
|
|
13
|
+
permission tokens, and the site carries on without further prompts for them.
|
|
14
|
+
- Reject, or swiping the drawer away, grants nothing and lets the site carry
|
|
15
|
+
on; each permission is then prompted for on its own when used. A hard deny
|
|
16
|
+
would make the site's `waitForAuthentication` throw.
|
|
17
|
+
- The request holds the origin's permission lock until answered, which is why
|
|
18
|
+
0.11.7 turned grouped seeking off; it is back on now that it is answered.
|
|
19
|
+
- A spending prompt already open is shown first.
|
|
20
|
+
|
|
3
21
|
## 0.11.7
|
|
4
22
|
|
|
5
23
|
### Sites with a grouped-permission manifest no longer hang
|
|
@@ -368,12 +368,14 @@ export interface WalletContextValue {
|
|
|
368
368
|
certificateRequests: CertificateAccessRequest[]
|
|
369
369
|
protocolRequests: ProtocolAccessRequest[]
|
|
370
370
|
spendingRequests: SpendingRequest[]
|
|
371
|
+
groupRequests: GroupPermissionRequest[]
|
|
371
372
|
btmsRequests: BtmsRequest[]
|
|
372
373
|
mandalaRequests: MandalaRequest[]
|
|
373
374
|
advanceBasketQueue: () => void
|
|
374
375
|
advanceCertificateQueue: () => void
|
|
375
376
|
advanceProtocolQueue: () => void
|
|
376
377
|
advanceSpendingQueue: () => void
|
|
378
|
+
advanceGroupQueue: () => void
|
|
377
379
|
advanceBtmsQueue: (approved: boolean) => void
|
|
378
380
|
advanceMandalaQueue: (approved: boolean) => void
|
|
379
381
|
finalizeConfig: (wabConfig: WABConfig) => boolean
|
|
@@ -477,12 +479,14 @@ export const WalletContext = createContext<WalletContextValue>({
|
|
|
477
479
|
certificateRequests: [],
|
|
478
480
|
protocolRequests: [],
|
|
479
481
|
spendingRequests: [],
|
|
482
|
+
groupRequests: [],
|
|
480
483
|
btmsRequests: [],
|
|
481
484
|
mandalaRequests: [],
|
|
482
485
|
advanceBasketQueue: () => {},
|
|
483
486
|
advanceCertificateQueue: () => {},
|
|
484
487
|
advanceProtocolQueue: () => {},
|
|
485
488
|
advanceSpendingQueue: () => {},
|
|
489
|
+
advanceGroupQueue: () => {},
|
|
486
490
|
advanceBtmsQueue: () => {},
|
|
487
491
|
advanceMandalaQueue: () => {},
|
|
488
492
|
finalizeConfig: () => false,
|
|
@@ -585,6 +589,19 @@ type SpendingRequest = {
|
|
|
585
589
|
lineItems: any[]
|
|
586
590
|
}
|
|
587
591
|
|
|
592
|
+
/** A site's grouped permission request, from its manifest's
|
|
593
|
+
* `metanet.groupPermissions` (WalletPermissionsManager.waitForAuthentication). */
|
|
594
|
+
export type GroupPermissionRequest = {
|
|
595
|
+
requestID: string
|
|
596
|
+
originator: string
|
|
597
|
+
permissions: {
|
|
598
|
+
spendingAuthorization?: { amount: number; description?: string }
|
|
599
|
+
protocolPermissions?: Array<{ protocolID: [number, string]; counterparty?: string; description?: string }>
|
|
600
|
+
basketAccess?: Array<{ basket: string; description?: string }>
|
|
601
|
+
certificateAccess?: Array<{ type: string; verifierPublicKey?: string; fields?: string[]; description?: string }>
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
588
605
|
type BtmsRequest = {
|
|
589
606
|
/** The originator (dApp domain) requesting BTMS token access */
|
|
590
607
|
originator: string
|
|
@@ -918,6 +935,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
918
935
|
...focusOpts,
|
|
919
936
|
openModal: setSpendingAuthorizationModalOpen
|
|
920
937
|
})
|
|
938
|
+
// Shown by the permission sheet whenever it has a head, like BTMS/Mandala.
|
|
939
|
+
const groupQueue = usePermissionQueue<GroupPermissionRequest>(focusOpts)
|
|
921
940
|
const btmsQueue = usePermissionQueue<BtmsRequest>(focusOpts)
|
|
922
941
|
|
|
923
942
|
const advanceBtmsQueue = useCallback(
|
|
@@ -1101,6 +1120,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1101
1120
|
[spendingQueue.enqueue]
|
|
1102
1121
|
)
|
|
1103
1122
|
|
|
1123
|
+
const groupedPermissionCallback = useCallback(
|
|
1124
|
+
async (args: GroupPermissionRequest): Promise<void> => {
|
|
1125
|
+
const { requestID, originator, permissions } = args ?? ({} as GroupPermissionRequest)
|
|
1126
|
+
if (!requestID || !permissions) return
|
|
1127
|
+
groupQueue.enqueue({ requestID, originator, permissions })
|
|
1128
|
+
},
|
|
1129
|
+
[groupQueue.enqueue]
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1104
1132
|
// ---- WAB + network + storage configuration ----
|
|
1105
1133
|
const [selectedMethod, setSelectedMethod] = useState<string>('')
|
|
1106
1134
|
const [selectedNetwork, setSelectedNetwork] = useState<AppChain>(DEFAULT_CHAIN)
|
|
@@ -1708,14 +1736,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1708
1736
|
seekCertificateDisclosurePermissions: false,
|
|
1709
1737
|
seekCertificateRelinquishmentPermissions: false,
|
|
1710
1738
|
seekCertificateListingPermissions: false,
|
|
1711
|
-
//
|
|
1712
|
-
//
|
|
1713
|
-
//
|
|
1714
|
-
//
|
|
1715
|
-
|
|
1716
|
-
// appeared either (fast.brc.dev). Every request still gets its own
|
|
1717
|
-
// prompt. Turn this back on together with a grouped prompt.
|
|
1718
|
-
seekGroupedPermission: false,
|
|
1739
|
+
// A site whose manifest declares metanet.groupPermissions is asked
|
|
1740
|
+
// for them all in one sheet during waitForAuthentication. The request
|
|
1741
|
+
// holds that origin's permission lock until answered, so it MUST be
|
|
1742
|
+
// handled (onGroupedPermissionRequested, below) or the site hangs.
|
|
1743
|
+
seekGroupedPermission: true,
|
|
1719
1744
|
seekPermissionsForIdentityKeyRevelation: false,
|
|
1720
1745
|
seekPermissionsForIdentityResolution: false,
|
|
1721
1746
|
seekPermissionsForKeyLinkageRevelation: false,
|
|
@@ -1738,6 +1763,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1738
1763
|
if (spendingAuthorizationCallback) {
|
|
1739
1764
|
permissionsManager.bindCallback('onSpendingAuthorizationRequested', spendingAuthorizationCallback)
|
|
1740
1765
|
}
|
|
1766
|
+
permissionsManager.bindCallback('onGroupedPermissionRequested', groupedPermissionCallback as any)
|
|
1741
1767
|
if (certificateAccessCallback) {
|
|
1742
1768
|
permissionsManager.bindCallback('onCertificateAccessRequested', certificateAccessCallback)
|
|
1743
1769
|
}
|
|
@@ -2364,6 +2390,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2364
2390
|
basketAccessCallback,
|
|
2365
2391
|
spendingAuthorizationCallback,
|
|
2366
2392
|
certificateAccessCallback,
|
|
2393
|
+
groupedPermissionCallback,
|
|
2367
2394
|
btmsPromptHandler,
|
|
2368
2395
|
mandalaPromptHandler,
|
|
2369
2396
|
runHeaderSync,
|
|
@@ -3678,12 +3705,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3678
3705
|
certificateRequests: certificateQueue.requests,
|
|
3679
3706
|
protocolRequests: protocolQueue.requests,
|
|
3680
3707
|
spendingRequests: spendingQueue.requests,
|
|
3708
|
+
groupRequests: groupQueue.requests,
|
|
3681
3709
|
btmsRequests: btmsQueue.requests,
|
|
3682
3710
|
mandalaRequests: mandalaQueue.requests,
|
|
3683
3711
|
advanceBasketQueue: basketQueue.advance,
|
|
3684
3712
|
advanceCertificateQueue: certificateQueue.advance,
|
|
3685
3713
|
advanceProtocolQueue: protocolQueue.advance,
|
|
3686
3714
|
advanceSpendingQueue: spendingQueue.advance,
|
|
3715
|
+
advanceGroupQueue: groupQueue.advance,
|
|
3687
3716
|
advanceBtmsQueue,
|
|
3688
3717
|
advanceMandalaQueue,
|
|
3689
3718
|
finalizeConfig,
|
|
@@ -3727,12 +3756,14 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3727
3756
|
certificateQueue.requests,
|
|
3728
3757
|
protocolQueue.requests,
|
|
3729
3758
|
spendingQueue.requests,
|
|
3759
|
+
groupQueue.requests,
|
|
3730
3760
|
btmsQueue.requests,
|
|
3731
3761
|
mandalaQueue.requests,
|
|
3732
3762
|
basketQueue.advance,
|
|
3733
3763
|
certificateQueue.advance,
|
|
3734
3764
|
protocolQueue.advance,
|
|
3735
3765
|
spendingQueue.advance,
|
|
3766
|
+
groupQueue.advance,
|
|
3736
3767
|
advanceBtmsQueue,
|
|
3737
3768
|
advanceMandalaQueue,
|
|
3738
3769
|
finalizeConfig,
|
|
@@ -3828,12 +3859,14 @@ export interface WalletQueuesSlice {
|
|
|
3828
3859
|
certificateRequests: CertificateAccessRequest[]
|
|
3829
3860
|
protocolRequests: ProtocolAccessRequest[]
|
|
3830
3861
|
spendingRequests: SpendingRequest[]
|
|
3862
|
+
groupRequests: GroupPermissionRequest[]
|
|
3831
3863
|
btmsRequests: BtmsRequest[]
|
|
3832
3864
|
mandalaRequests: MandalaRequest[]
|
|
3833
3865
|
advanceBasketQueue: () => void
|
|
3834
3866
|
advanceCertificateQueue: () => void
|
|
3835
3867
|
advanceProtocolQueue: () => void
|
|
3836
3868
|
advanceSpendingQueue: () => void
|
|
3869
|
+
advanceGroupQueue: () => void
|
|
3837
3870
|
advanceBtmsQueue: (approved: boolean) => void
|
|
3838
3871
|
advanceMandalaQueue: (approved: boolean) => void
|
|
3839
3872
|
}
|
|
@@ -3845,12 +3878,14 @@ export const useWalletQueues = (): WalletQueuesSlice => {
|
|
|
3845
3878
|
certificateRequests: ctx.certificateRequests,
|
|
3846
3879
|
protocolRequests: ctx.protocolRequests,
|
|
3847
3880
|
spendingRequests: ctx.spendingRequests,
|
|
3881
|
+
groupRequests: ctx.groupRequests,
|
|
3848
3882
|
btmsRequests: ctx.btmsRequests,
|
|
3849
3883
|
mandalaRequests: ctx.mandalaRequests,
|
|
3850
3884
|
advanceBasketQueue: ctx.advanceBasketQueue,
|
|
3851
3885
|
advanceCertificateQueue: ctx.advanceCertificateQueue,
|
|
3852
3886
|
advanceProtocolQueue: ctx.advanceProtocolQueue,
|
|
3853
3887
|
advanceSpendingQueue: ctx.advanceSpendingQueue,
|
|
3888
|
+
advanceGroupQueue: ctx.advanceGroupQueue,
|
|
3854
3889
|
advanceBtmsQueue: ctx.advanceBtmsQueue,
|
|
3855
3890
|
advanceMandalaQueue: ctx.advanceMandalaQueue
|
|
3856
3891
|
}),
|
|
@@ -3859,12 +3894,14 @@ export const useWalletQueues = (): WalletQueuesSlice => {
|
|
|
3859
3894
|
ctx.certificateRequests,
|
|
3860
3895
|
ctx.protocolRequests,
|
|
3861
3896
|
ctx.spendingRequests,
|
|
3897
|
+
ctx.groupRequests,
|
|
3862
3898
|
ctx.btmsRequests,
|
|
3863
3899
|
ctx.mandalaRequests,
|
|
3864
3900
|
ctx.advanceBasketQueue,
|
|
3865
3901
|
ctx.advanceCertificateQueue,
|
|
3866
3902
|
ctx.advanceProtocolQueue,
|
|
3867
3903
|
ctx.advanceSpendingQueue,
|
|
3904
|
+
ctx.advanceGroupQueue,
|
|
3868
3905
|
ctx.advanceBtmsQueue,
|
|
3869
3906
|
ctx.advanceMandalaQueue
|
|
3870
3907
|
]
|
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.8",
|
|
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",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useContext, useState, useCallback, useMemo, useEffect, useRef } from 'react'
|
|
2
2
|
import { View, Text, StyleSheet, TouchableOpacity, ScrollView } from 'react-native'
|
|
3
|
+
import type { WalletPermissionsManager } from '@bsv/wallet-toolbox-mobile'
|
|
3
4
|
import Sheet from './Sheet'
|
|
4
5
|
import PressableScale from './PressableScale'
|
|
5
6
|
import { useTranslation } from 'react-i18next'
|
|
@@ -70,6 +71,8 @@ interface GroupPermissions {
|
|
|
70
71
|
spendingAuthorization?: GroupSpending
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
type GrantedGroupPermissions = Parameters<WalletPermissionsManager['grantGroupedPermission']>[0]['granted']
|
|
75
|
+
|
|
73
76
|
/** Common shape derived from the four existing modals. */
|
|
74
77
|
export interface ActivePermission {
|
|
75
78
|
kind: PermissionKind
|
|
@@ -152,6 +155,7 @@ export function deriveActive(
|
|
|
152
155
|
basketRequests: any[]
|
|
153
156
|
certificateRequests: any[]
|
|
154
157
|
spendingRequests: any[]
|
|
158
|
+
groupRequests?: any[]
|
|
155
159
|
btmsRequests: any[]
|
|
156
160
|
mandalaRequests: any[]
|
|
157
161
|
protocolAccessModalOpen: boolean
|
|
@@ -207,6 +211,21 @@ export function deriveActive(
|
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
213
|
|
|
214
|
+
// A site's grouped request (its manifest's metanet.groupPermissions) is the
|
|
215
|
+
// whole set it will use, asked once when it connects.
|
|
216
|
+
if (ctx.groupRequests && ctx.groupRequests.length > 0) {
|
|
217
|
+
const r = ctx.groupRequests[0]
|
|
218
|
+
return {
|
|
219
|
+
kind: 'group',
|
|
220
|
+
requestID: r.requestID,
|
|
221
|
+
originator: r.originator,
|
|
222
|
+
title: 'Permissions',
|
|
223
|
+
description: 'wants these permissions',
|
|
224
|
+
details: [],
|
|
225
|
+
groupPermissions: r.permissions
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
210
229
|
if (ctx.certificateAccessModalOpen && ctx.certificateRequests.length > 0) {
|
|
211
230
|
const r = ctx.certificateRequests[0]
|
|
212
231
|
const certType = r.certificate?.certType ?? r.certificateType
|
|
@@ -456,12 +475,14 @@ const PermissionSheet: React.FC = () => {
|
|
|
456
475
|
basketRequests,
|
|
457
476
|
certificateRequests,
|
|
458
477
|
spendingRequests,
|
|
478
|
+
groupRequests,
|
|
459
479
|
btmsRequests,
|
|
460
480
|
mandalaRequests,
|
|
461
481
|
advanceProtocolQueue,
|
|
462
482
|
advanceBasketQueue,
|
|
463
483
|
advanceCertificateQueue,
|
|
464
484
|
advanceSpendingQueue,
|
|
485
|
+
advanceGroupQueue,
|
|
465
486
|
advanceBtmsQueue,
|
|
466
487
|
advanceMandalaQueue,
|
|
467
488
|
managers,
|
|
@@ -516,6 +537,7 @@ const PermissionSheet: React.FC = () => {
|
|
|
516
537
|
basketRequests,
|
|
517
538
|
certificateRequests,
|
|
518
539
|
spendingRequests,
|
|
540
|
+
groupRequests,
|
|
519
541
|
btmsRequests,
|
|
520
542
|
mandalaRequests,
|
|
521
543
|
protocolAccessModalOpen,
|
|
@@ -530,6 +552,7 @@ const PermissionSheet: React.FC = () => {
|
|
|
530
552
|
basketRequests,
|
|
531
553
|
certificateRequests,
|
|
532
554
|
spendingRequests,
|
|
555
|
+
groupRequests,
|
|
533
556
|
btmsRequests,
|
|
534
557
|
mandalaRequests,
|
|
535
558
|
protocolAccessModalOpen,
|
|
@@ -580,6 +603,16 @@ const PermissionSheet: React.FC = () => {
|
|
|
580
603
|
} else if (active.kind === 'mandala') {
|
|
581
604
|
// Mandala uses its own promise-based resolution too — no permissionsManager.denyPermission
|
|
582
605
|
advanceMandalaQueue(false)
|
|
606
|
+
} else if (active.kind === 'group') {
|
|
607
|
+
// Grant none of the set, but let the site carry on: each permission is
|
|
608
|
+
// then asked for on its own when used. A hard deny would make the
|
|
609
|
+
// site's waitForAuthentication throw.
|
|
610
|
+
try {
|
|
611
|
+
await managers.permissionsManager?.dismissGroupedPermission(active.requestID)
|
|
612
|
+
} catch {
|
|
613
|
+
// Already settled (e.g. the site went away) -- nothing left to answer.
|
|
614
|
+
}
|
|
615
|
+
advanceGroupQueue()
|
|
583
616
|
} else {
|
|
584
617
|
try {
|
|
585
618
|
await managers.permissionsManager?.denyPermission(active.requestID)
|
|
@@ -614,6 +647,7 @@ const PermissionSheet: React.FC = () => {
|
|
|
614
647
|
advanceBasketQueue,
|
|
615
648
|
advanceCertificateQueue,
|
|
616
649
|
advanceSpendingQueue,
|
|
650
|
+
advanceGroupQueue,
|
|
617
651
|
advanceBtmsQueue,
|
|
618
652
|
advanceMandalaQueue,
|
|
619
653
|
setProtocolAccessModalOpen,
|
|
@@ -636,6 +670,18 @@ const PermissionSheet: React.FC = () => {
|
|
|
636
670
|
advanceBtmsQueue(true)
|
|
637
671
|
} else if (request.kind === 'mandala') {
|
|
638
672
|
advanceMandalaQueue(true)
|
|
673
|
+
} else if (request.kind === 'group') {
|
|
674
|
+
// Grants exactly the set shown. The manager mints the permission
|
|
675
|
+
// tokens, then resolves the site's waitForAuthentication; if minting
|
|
676
|
+
// fails it rejects that call itself.
|
|
677
|
+
managers.permissionsManager
|
|
678
|
+
?.grantGroupedPermission({
|
|
679
|
+
requestID: request.requestID,
|
|
680
|
+
// The manager's own request object, passed back unchanged.
|
|
681
|
+
granted: (request.groupPermissions ?? {}) as GrantedGroupPermissions
|
|
682
|
+
})
|
|
683
|
+
.catch((error: unknown) => console.warn('[permissions] grouped grant failed', error))
|
|
684
|
+
advanceGroupQueue()
|
|
639
685
|
} else if (request.kind === 'spending') {
|
|
640
686
|
managers.permissionsManager?.grantPermission({
|
|
641
687
|
requestID: request.requestID,
|
|
@@ -674,6 +720,7 @@ const PermissionSheet: React.FC = () => {
|
|
|
674
720
|
advanceBasketQueue,
|
|
675
721
|
advanceCertificateQueue,
|
|
676
722
|
advanceSpendingQueue,
|
|
723
|
+
advanceGroupQueue,
|
|
677
724
|
advanceBtmsQueue,
|
|
678
725
|
advanceMandalaQueue,
|
|
679
726
|
setProtocolAccessModalOpen,
|
|
@@ -704,10 +751,10 @@ const PermissionSheet: React.FC = () => {
|
|
|
704
751
|
}, [active, granted, executeGrant])
|
|
705
752
|
|
|
706
753
|
return (
|
|
707
|
-
<Sheet visible={visible} onClose={handleDeny} heightPercent={0.92} fitContent
|
|
754
|
+
<Sheet visible={visible} onClose={handleDeny} heightPercent={0.92} fitContent>
|
|
708
755
|
{active && (
|
|
709
|
-
<View
|
|
710
|
-
<View style={
|
|
756
|
+
<View>
|
|
757
|
+
<View style={styles.content}>
|
|
711
758
|
{/* -------- Originator / domain -------- */}
|
|
712
759
|
<View style={styles.originatorRow}>
|
|
713
760
|
<View
|
|
@@ -916,10 +963,6 @@ const PermissionSheet: React.FC = () => {
|
|
|
916
963
|
// ---------------------------------------------------------------------------
|
|
917
964
|
|
|
918
965
|
const styles = StyleSheet.create({
|
|
919
|
-
sheetInnerGroup: {
|
|
920
|
-
flex: 1,
|
|
921
|
-
justifyContent: 'flex-end'
|
|
922
|
-
},
|
|
923
966
|
content: {
|
|
924
967
|
paddingHorizontal: spacing.xl,
|
|
925
968
|
paddingTop: spacing.lg,
|
|
@@ -1042,8 +1085,10 @@ const styles = StyleSheet.create({
|
|
|
1042
1085
|
},
|
|
1043
1086
|
|
|
1044
1087
|
// Group permissions
|
|
1088
|
+
// Sized to its rows like every other prompt; a long set scrolls instead
|
|
1089
|
+
// of pushing the buttons off screen.
|
|
1045
1090
|
groupScroll: {
|
|
1046
|
-
|
|
1091
|
+
maxHeight: 420
|
|
1047
1092
|
},
|
|
1048
1093
|
groupSection: {
|
|
1049
1094
|
borderTopWidth: StyleSheet.hairlineWidth,
|