@solana-mobile/mobile-wallet-adapter-walletlib 1.2.0 → 1.4.0-beta1
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/README.md +86 -49
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +453 -171
- package/lib/esm/index.js +70 -30
- package/lib/esm/index.native.js +70 -30
- package/lib/types/index.d.ts +16 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +16 -2
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,46 +10,102 @@ This package is still in alpha and is not production ready. However, the API is
|
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
13
|
-
### 1.
|
|
13
|
+
### 1. Initialize the MWA event listener
|
|
14
14
|
|
|
15
|
-
Use
|
|
16
|
-
|
|
15
|
+
Use the following API to start listening for MWA requests and events, and register request handlers.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
17
18
|
import {
|
|
18
|
-
|
|
19
|
+
initializeMWAEventListener,
|
|
19
20
|
MWARequest,
|
|
20
21
|
MWASessionEvent,
|
|
21
|
-
useMobileWalletAdapterSession,
|
|
22
22
|
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
maxMessagesPerSigningRequest: 10,
|
|
29
|
-
supportedTransactionVersions: [0, 'legacy'],
|
|
30
|
-
noConnectionWarningTimeoutMs: 3000,
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
24
|
+
const listener: EmitterSubscription = initializeMWAEventListener(
|
|
25
|
+
(request: MWARequest) => { /* ... */ },
|
|
26
|
+
(sessionEvent: MWASessionEvent) => { /* ... */ },
|
|
27
|
+
);
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
const handleRequest = useCallback((request: MWARequest) => {
|
|
36
|
-
/* ... */
|
|
37
|
-
}, []);
|
|
29
|
+
/* ... */
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
// Clean up the listener when it is out of scope
|
|
32
|
+
listener.remove()
|
|
33
|
+
```
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
You should ensure the listener is cleaned up with `listener.remove()` when it goes out of scope (e.g `listener.remove()` on component lifecycle unmount).
|
|
36
|
+
|
|
37
|
+
### 2. Initialize the MWA session
|
|
38
|
+
|
|
39
|
+
Define your wallet config and use `initializeMWASession` to establish a session with the dApp endpoint and begin emission of MWA requests/events.
|
|
40
|
+
|
|
41
|
+
> **Note:** This should be called *after* `initializeMWAEventListener` is called, to ensure no events are missed.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const config: MobileWalletAdapterConfig = {
|
|
45
|
+
supportsSignAndSendTransactions: true,
|
|
46
|
+
maxTransactionsPerSigningRequest: 10,
|
|
47
|
+
maxMessagesPerSigningRequest: 10,
|
|
48
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
49
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
50
|
+
optionalFeatures: ['solana:signInWithSolana']
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const sessionId = await initializeMobileWalletAdapterSession(
|
|
55
|
+
'Wallet Name',
|
|
56
|
+
config,
|
|
57
|
+
);
|
|
58
|
+
console.log('sessionId: ' + sessionId);
|
|
59
|
+
} catch (e: any) {
|
|
60
|
+
if (e instanceof SolanaMWAWalletLibError) {
|
|
61
|
+
console.error(e.name, e.code, e.message);
|
|
62
|
+
} else {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> **Note**: Although, the `initializeMobileWalletAdapterSession` method returns a `sessionId`, this library only supports one active session for now.
|
|
69
|
+
|
|
70
|
+
### Example usage:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// When your MWA entrypoint is loaded, call a `useEffect` to kick off the listener and session.
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
async function initializeMWASession() {
|
|
76
|
+
const config: MobileWalletAdapterConfig = {
|
|
77
|
+
supportsSignAndSendTransactions: true,
|
|
78
|
+
maxTransactionsPerSigningRequest: 10,
|
|
79
|
+
maxMessagesPerSigningRequest: 10,
|
|
80
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
81
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const sessionId = await initializeMobileWalletAdapterSession(
|
|
85
|
+
'Wallet Name',
|
|
86
|
+
config,
|
|
87
|
+
);
|
|
88
|
+
console.log('sessionId: ' + sessionId);
|
|
89
|
+
} catch (e: any) {
|
|
90
|
+
if (e instanceof SolanaMWAWalletLibError) {
|
|
91
|
+
console.error(e.name, e.code, e.message);
|
|
92
|
+
} else {
|
|
93
|
+
console.error(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const listener = initializeMWAEventListener(
|
|
98
|
+
(request: MWARequest) => { /* ... */ },
|
|
99
|
+
(sessionEvent: MWASessionEvent) => { /* ... */ },
|
|
100
|
+
);
|
|
101
|
+
initializeMWASession();
|
|
102
|
+
|
|
103
|
+
// When the component is unmounted, clean up the listener.
|
|
104
|
+
return () => listener.remove();
|
|
105
|
+
}, []);
|
|
50
106
|
```
|
|
51
107
|
|
|
52
|
-
###
|
|
108
|
+
### 3. Handling requests and events
|
|
53
109
|
|
|
54
110
|
A `MWARequest` is handled by calling `resolve(request, response)` and each request have their appropriate response types.
|
|
55
111
|
|
|
@@ -137,23 +193,4 @@ Fields:
|
|
|
137
193
|
|
|
138
194
|
- `SignAndSendTransactionsRequest`
|
|
139
195
|
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_and_send_transactions)
|
|
140
|
-
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
# Changelog
|
|
144
|
-
|
|
145
|
-
## 1.0.3
|
|
146
|
-
- Fixed a rerender bug within `useMobileWalletAdapterSession` where `initializeScenario` was needlessly called on rerender.
|
|
147
|
-
|
|
148
|
-
- Added `DeauthorizeDappRequest` type, so Javascript side now knows when a dApp requests for deauthorization.
|
|
149
|
-
|
|
150
|
-
- Added `ReauthorizeDappRequest` type, so Javascript side now knows when a dApp requests for reauthorization.
|
|
151
|
-
|
|
152
|
-
- Refactored `IMWARequest` to only include fields `requestId`, `sessionId`, and `__type`.
|
|
153
|
-
|
|
154
|
-
- Added `IVerifableIdentityRequest` to take on the fields `authorizationScope`, `cluster`, and `appIdentity`.
|
|
155
|
-
|
|
156
|
-
- `AuthorizeDappRequest` now no longer includes `authorizationScope`. This was mistakenly included previously.
|
|
157
|
-
|
|
158
|
-
- Updated documentation in the README. See "Properties of an MWA Request".
|
|
159
|
-
|
|
196
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|