@solana-mobile/mobile-wallet-adapter-walletlib 1.4.1 → 1.4.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/README.md +84 -78
- package/lib/esm/index.js +113 -1462
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/index.native.js +113 -1462
- package/lib/esm/index.native.js.map +1 -0
- package/lib/esm/package.json +1 -3
- package/lib/types/index.d.ts +124 -112
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/lib/types/index.native.d.ts +0 -226
- package/lib/types/index.native.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# `@solana-mobile/mobile-wallet-adapter-walletlib`
|
|
2
2
|
|
|
3
|
-
This is a package that provides React Native bridge for the native `mobile-wallet-adapter-walletlib` library and it is designed for
|
|
3
|
+
This is a package that provides React Native bridge for the native `mobile-wallet-adapter-walletlib` library and it is designed for _Wallet apps_ built in React Native. It provides an API to implement the wallet endpoint of the [mobile wallet adapter protocol](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/spec/spec.md).
|
|
4
4
|
|
|
5
5
|
Deep dive and read the full Mobile Wallet Adapter protocol [specification](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#mobile-wallet-adapter-specification).
|
|
6
6
|
|
|
7
7
|
## Note
|
|
8
|
-
This package is still in alpha and is not production ready. However, the API is stable and will not change drastically, so you can begin integration with your wallet.
|
|
9
8
|
|
|
9
|
+
This package is still in alpha and is not production ready. However, the API is stable and will not change drastically, so you can begin integration with your wallet.
|
|
10
10
|
|
|
11
11
|
## Quickstart
|
|
12
12
|
|
|
@@ -16,52 +16,53 @@ Use the following API to start listening for MWA requests and events, and regist
|
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
initializeMWAEventListener,
|
|
20
|
+
MWARequest,
|
|
21
|
+
MWASessionEvent,
|
|
22
22
|
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
23
23
|
|
|
24
24
|
const listener: EmitterSubscription = initializeMWAEventListener(
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
(request: MWARequest) => {
|
|
26
|
+
/* ... */
|
|
27
|
+
},
|
|
28
|
+
(sessionEvent: MWASessionEvent) => {
|
|
29
|
+
/* ... */
|
|
30
|
+
},
|
|
27
31
|
);
|
|
28
32
|
|
|
29
33
|
/* ... */
|
|
30
34
|
|
|
31
35
|
// Clean up the listener when it is out of scope
|
|
32
|
-
listener.remove()
|
|
36
|
+
listener.remove();
|
|
33
37
|
```
|
|
34
38
|
|
|
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).
|
|
39
|
+
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
40
|
|
|
37
41
|
### 2. Initialize the MWA session
|
|
38
42
|
|
|
39
|
-
Define your wallet config and use `initializeMWASession` to establish a session with the dApp endpoint and begin emission of MWA requests/events.
|
|
43
|
+
Define your wallet config and use `initializeMWASession` to establish a session with the dApp endpoint and begin emission of MWA requests/events.
|
|
40
44
|
|
|
41
|
-
> **Note:** This should be called
|
|
45
|
+
> **Note:** This should be called _after_ `initializeMWAEventListener` is called, to ensure no events are missed.
|
|
42
46
|
|
|
43
47
|
```ts
|
|
44
48
|
const config: MobileWalletAdapterConfig = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
supportsSignAndSendTransactions: true,
|
|
50
|
+
maxTransactionsPerSigningRequest: 10,
|
|
51
|
+
maxMessagesPerSigningRequest: 10,
|
|
52
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
53
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
54
|
+
optionalFeatures: ['solana:signInWithSolana'],
|
|
51
55
|
};
|
|
52
56
|
|
|
53
57
|
try {
|
|
54
|
-
|
|
55
|
-
'
|
|
56
|
-
config,
|
|
57
|
-
);
|
|
58
|
-
console.log('sessionId: ' + sessionId);
|
|
58
|
+
const sessionId = await initializeMobileWalletAdapterSession('Wallet Name', config);
|
|
59
|
+
console.log('sessionId: ' + sessionId);
|
|
59
60
|
} catch (e: any) {
|
|
60
61
|
if (e instanceof SolanaMWAWalletLibError) {
|
|
61
|
-
|
|
62
|
+
console.error(e.name, e.code, e.message);
|
|
62
63
|
} else {
|
|
63
|
-
|
|
64
|
-
}
|
|
64
|
+
console.error(e);
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
```
|
|
67
68
|
|
|
@@ -72,36 +73,37 @@ try {
|
|
|
72
73
|
```ts
|
|
73
74
|
// When your MWA entrypoint is loaded, call a `useEffect` to kick off the listener and session.
|
|
74
75
|
useEffect(() => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
console.error(e);
|
|
94
|
-
}
|
|
76
|
+
async function initializeMWASession() {
|
|
77
|
+
const config: MobileWalletAdapterConfig = {
|
|
78
|
+
supportsSignAndSendTransactions: true,
|
|
79
|
+
maxTransactionsPerSigningRequest: 10,
|
|
80
|
+
maxMessagesPerSigningRequest: 10,
|
|
81
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
82
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const sessionId = await initializeMobileWalletAdapterSession('Wallet Name', config);
|
|
86
|
+
console.log('sessionId: ' + sessionId);
|
|
87
|
+
} catch (e: any) {
|
|
88
|
+
if (e instanceof SolanaMWAWalletLibError) {
|
|
89
|
+
console.error(e.name, e.code, e.message);
|
|
90
|
+
} else {
|
|
91
|
+
console.error(e);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
const listener = initializeMWAEventListener(
|
|
96
|
+
(request: MWARequest) => {
|
|
97
|
+
/* ... */
|
|
98
|
+
},
|
|
99
|
+
(sessionEvent: MWASessionEvent) => {
|
|
100
|
+
/* ... */
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
initializeMWASession();
|
|
104
|
+
|
|
105
|
+
// When the component is unmounted, clean up the listener.
|
|
106
|
+
return () => listener.remove();
|
|
105
107
|
}, []);
|
|
106
108
|
```
|
|
107
109
|
|
|
@@ -110,35 +112,34 @@ useEffect(() => {
|
|
|
110
112
|
A `MWARequest` is handled by calling `resolve(request, response)` and each request have their appropriate response types.
|
|
111
113
|
|
|
112
114
|
An example of handling an `AuthorizationRequest`:
|
|
115
|
+
|
|
113
116
|
```typescript
|
|
114
|
-
import {
|
|
115
|
-
AuthorizeDappResponse
|
|
116
|
-
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
117
|
+
import { AuthorizeDappResponse } from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
117
118
|
|
|
118
119
|
const response = {
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
publicKey: Keypair.generate().publicKey.toBytes(),
|
|
121
|
+
label: 'Wallet Label',
|
|
121
122
|
} as AuthorizeDappResponse;
|
|
122
123
|
|
|
123
|
-
resolve(authorizationRequest, response)
|
|
124
|
+
resolve(authorizationRequest, response);
|
|
124
125
|
```
|
|
125
126
|
|
|
126
127
|
There are a a selection of "fail" responses that you can return to the dApp. These are for cases where the user declines, or an error occurs during signing, etc.
|
|
128
|
+
|
|
127
129
|
```typescript
|
|
128
|
-
import {
|
|
129
|
-
UserDeclinedResponse
|
|
130
|
-
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
130
|
+
import { UserDeclinedResponse } from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
131
131
|
|
|
132
132
|
const response = {
|
|
133
|
-
|
|
133
|
+
failReason: MWARequestFailReason.UserDeclined,
|
|
134
134
|
} as UserDeclinedResponse;
|
|
135
135
|
|
|
136
136
|
// Tells the dApp user has declined the authorization request
|
|
137
|
-
resolve(authorizationRequest, response)
|
|
137
|
+
resolve(authorizationRequest, response);
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
## Properties of an MWA Request
|
|
141
|
-
|
|
141
|
+
|
|
142
|
+
Each MWA Request is defined in [`resolve.ts`](https://github.com/solana-mobile/mobile-wallet-adapter/blob/main/js/packages/mobile-wallet-adapter-walletlib/src/resolve.ts#L38).
|
|
142
143
|
Each come with their own properties and completion response structures.
|
|
143
144
|
|
|
144
145
|
If you want to understand the dApp perspective and how a dApp would send these requests, see [MWA API Documentation](https://docs.solanamobile.com/reference/) for dAppstypescript/mobile-wallet-adapter.
|
|
@@ -146,21 +147,26 @@ If you want to understand the dApp perspective and how a dApp would send these r
|
|
|
146
147
|
## MWARequest Interfaces
|
|
147
148
|
|
|
148
149
|
### `IMWARequest`
|
|
150
|
+
|
|
149
151
|
This is the base interface that all MWARequsts inherit from. The fields defined here are used in the package's internal implementation and the package consumer will generally not use them.
|
|
150
152
|
|
|
151
153
|
Fields:
|
|
154
|
+
|
|
152
155
|
- `__type`: An enum defining the type of MWA Request it is.
|
|
153
156
|
- `requestId`: A unique identifier of this specific MWA Request
|
|
154
157
|
- `sessionId`: A unique identifier of the MWA Session this request belongs to.
|
|
155
158
|
|
|
156
159
|
### `IVerifiableIdentityRequest`
|
|
160
|
+
|
|
157
161
|
This an interface that describes MWA Requests that come with a verifiable identity and the following 3 fields.
|
|
158
162
|
|
|
159
163
|
Fields:
|
|
164
|
+
|
|
160
165
|
- `authorizationScope`: A byte representation of the authorization token granted to the dApp.
|
|
161
166
|
- `cluster`: The Solana RPC cluster that the dApp intends to use.
|
|
162
167
|
- `appIdentity`: An object containing 3 optional identity fields about the dApp:
|
|
163
168
|
- Note: The `iconRelativeUri` is a relative path, relative to `identityUri`.
|
|
169
|
+
|
|
164
170
|
```
|
|
165
171
|
{
|
|
166
172
|
identityName: 'dApp Name',
|
|
@@ -172,25 +178,25 @@ Fields:
|
|
|
172
178
|
### MWARequest Types
|
|
173
179
|
|
|
174
180
|
- `AuthorizeDappRequest`
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#authorize)
|
|
182
|
+
- Interfaces: `IMWARequest`
|
|
177
183
|
|
|
178
184
|
- `ReauthorizeDappRequest`
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#reauthorize)
|
|
186
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
181
187
|
|
|
182
188
|
- `DeauthorizeDappRequest`
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#deauthorize)
|
|
190
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
185
191
|
|
|
186
192
|
- `SignMessagesRequest`
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_messages)
|
|
194
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
189
195
|
|
|
190
196
|
- `SignTransactionsRequest`
|
|
191
|
-
|
|
192
|
-
|
|
197
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_transactions)
|
|
198
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
193
199
|
|
|
194
200
|
- `SignAndSendTransactionsRequest`
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_and_send_transactions)
|
|
202
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|