@solana-mobile/mobile-wallet-adapter-walletlib 1.4.0 → 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/LICENSE +12 -12
- package/README.md +202 -196
- package/android/build.gradle +151 -151
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
- package/android/gradle.properties +5 -5
- package/android/gradlew +185 -185
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/Extensions.kt +98 -98
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/JsonSerializationUtils.kt +156 -156
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterWalletLibReactNativePackage.kt +18 -18
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +691 -691
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterConfig.kt +59 -59
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterRequest.kt +97 -97
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterResponse.kt +68 -68
- package/lib/esm/index.js +119 -194
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/index.native.js +119 -194
- 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 +49 -46
- package/lib/types/index.native.d.ts +0 -226
- package/lib/types/index.native.d.ts.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
Copyright 2022 Solana Mobile Inc.
|
|
2
|
-
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
|
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
See the License for the specific language governing permissions and
|
|
1
|
+
Copyright 2022 Solana Mobile Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
13
|
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,196 +1,202 @@
|
|
|
1
|
-
# `@solana-mobile/mobile-wallet-adapter-walletlib`
|
|
2
|
-
|
|
3
|
-
This is a package that provides React Native bridge for the native `mobile-wallet-adapter-walletlib` library and it is designed for
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
## Note
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Quickstart
|
|
12
|
-
|
|
13
|
-
### 1. Initialize the MWA event listener
|
|
14
|
-
|
|
15
|
-
Use the following API to start listening for MWA requests and events, and register request handlers.
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
23
|
-
|
|
24
|
-
const listener: EmitterSubscription = initializeMWAEventListener(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/* ... */
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
useEffect
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
131
|
-
|
|
132
|
-
const response = {
|
|
133
|
-
|
|
134
|
-
} as UserDeclinedResponse;
|
|
135
|
-
|
|
136
|
-
// Tells the dApp user has declined the authorization request
|
|
137
|
-
resolve(authorizationRequest, response)
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Properties of an MWA Request
|
|
141
|
-
|
|
142
|
-
Each
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
- `
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
- `
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
- `
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
- `
|
|
195
|
-
|
|
196
|
-
|
|
1
|
+
# `@solana-mobile/mobile-wallet-adapter-walletlib`
|
|
2
|
+
|
|
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
|
+
|
|
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
|
+
|
|
7
|
+
## Note
|
|
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
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### 1. Initialize the MWA event listener
|
|
14
|
+
|
|
15
|
+
Use the following API to start listening for MWA requests and events, and register request handlers.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
initializeMWAEventListener,
|
|
20
|
+
MWARequest,
|
|
21
|
+
MWASessionEvent,
|
|
22
|
+
} from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
23
|
+
|
|
24
|
+
const listener: EmitterSubscription = initializeMWAEventListener(
|
|
25
|
+
(request: MWARequest) => {
|
|
26
|
+
/* ... */
|
|
27
|
+
},
|
|
28
|
+
(sessionEvent: MWASessionEvent) => {
|
|
29
|
+
/* ... */
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/* ... */
|
|
34
|
+
|
|
35
|
+
// Clean up the listener when it is out of scope
|
|
36
|
+
listener.remove();
|
|
37
|
+
```
|
|
38
|
+
|
|
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).
|
|
40
|
+
|
|
41
|
+
### 2. Initialize the MWA session
|
|
42
|
+
|
|
43
|
+
Define your wallet config and use `initializeMWASession` to establish a session with the dApp endpoint and begin emission of MWA requests/events.
|
|
44
|
+
|
|
45
|
+
> **Note:** This should be called _after_ `initializeMWAEventListener` is called, to ensure no events are missed.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const config: MobileWalletAdapterConfig = {
|
|
49
|
+
supportsSignAndSendTransactions: true,
|
|
50
|
+
maxTransactionsPerSigningRequest: 10,
|
|
51
|
+
maxMessagesPerSigningRequest: 10,
|
|
52
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
53
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
54
|
+
optionalFeatures: ['solana:signInWithSolana'],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const sessionId = await initializeMobileWalletAdapterSession('Wallet Name', config);
|
|
59
|
+
console.log('sessionId: ' + sessionId);
|
|
60
|
+
} catch (e: any) {
|
|
61
|
+
if (e instanceof SolanaMWAWalletLibError) {
|
|
62
|
+
console.error(e.name, e.code, e.message);
|
|
63
|
+
} else {
|
|
64
|
+
console.error(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> **Note**: Although, the `initializeMobileWalletAdapterSession` method returns a `sessionId`, this library only supports one active session for now.
|
|
70
|
+
|
|
71
|
+
### Example usage:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// When your MWA entrypoint is loaded, call a `useEffect` to kick off the listener and session.
|
|
75
|
+
useEffect(() => {
|
|
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
|
+
}
|
|
94
|
+
}
|
|
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();
|
|
107
|
+
}, []);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. Handling requests and events
|
|
111
|
+
|
|
112
|
+
A `MWARequest` is handled by calling `resolve(request, response)` and each request have their appropriate response types.
|
|
113
|
+
|
|
114
|
+
An example of handling an `AuthorizationRequest`:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { AuthorizeDappResponse } from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
118
|
+
|
|
119
|
+
const response = {
|
|
120
|
+
publicKey: Keypair.generate().publicKey.toBytes(),
|
|
121
|
+
label: 'Wallet Label',
|
|
122
|
+
} as AuthorizeDappResponse;
|
|
123
|
+
|
|
124
|
+
resolve(authorizationRequest, response);
|
|
125
|
+
```
|
|
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
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { UserDeclinedResponse } from '@solana-mobile/mobile-wallet-adapter-walletlib';
|
|
131
|
+
|
|
132
|
+
const response = {
|
|
133
|
+
failReason: MWARequestFailReason.UserDeclined,
|
|
134
|
+
} as UserDeclinedResponse;
|
|
135
|
+
|
|
136
|
+
// Tells the dApp user has declined the authorization request
|
|
137
|
+
resolve(authorizationRequest, response);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Properties of an MWA Request
|
|
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).
|
|
143
|
+
Each come with their own properties and completion response structures.
|
|
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
|
+
|
|
147
|
+
## MWARequest Interfaces
|
|
148
|
+
|
|
149
|
+
### `IMWARequest`
|
|
150
|
+
|
|
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.
|
|
152
|
+
|
|
153
|
+
Fields:
|
|
154
|
+
|
|
155
|
+
- `__type`: An enum defining the type of MWA Request it is.
|
|
156
|
+
- `requestId`: A unique identifier of this specific MWA Request
|
|
157
|
+
- `sessionId`: A unique identifier of the MWA Session this request belongs to.
|
|
158
|
+
|
|
159
|
+
### `IVerifiableIdentityRequest`
|
|
160
|
+
|
|
161
|
+
This an interface that describes MWA Requests that come with a verifiable identity and the following 3 fields.
|
|
162
|
+
|
|
163
|
+
Fields:
|
|
164
|
+
|
|
165
|
+
- `authorizationScope`: A byte representation of the authorization token granted to the dApp.
|
|
166
|
+
- `cluster`: The Solana RPC cluster that the dApp intends to use.
|
|
167
|
+
- `appIdentity`: An object containing 3 optional identity fields about the dApp:
|
|
168
|
+
- Note: The `iconRelativeUri` is a relative path, relative to `identityUri`.
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
{
|
|
172
|
+
identityName: 'dApp Name',
|
|
173
|
+
identityUri: 'https://yourdapp.com'
|
|
174
|
+
iconRelativeUri: "favicon.ico", // Full path resolves to https://yourdapp.com/favicon.ico
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### MWARequest Types
|
|
179
|
+
|
|
180
|
+
- `AuthorizeDappRequest`
|
|
181
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#authorize)
|
|
182
|
+
- Interfaces: `IMWARequest`
|
|
183
|
+
|
|
184
|
+
- `ReauthorizeDappRequest`
|
|
185
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#reauthorize)
|
|
186
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
187
|
+
|
|
188
|
+
- `DeauthorizeDappRequest`
|
|
189
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#deauthorize)
|
|
190
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
191
|
+
|
|
192
|
+
- `SignMessagesRequest`
|
|
193
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_messages)
|
|
194
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
195
|
+
|
|
196
|
+
- `SignTransactionsRequest`
|
|
197
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_transactions)
|
|
198
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
199
|
+
|
|
200
|
+
- `SignAndSendTransactionsRequest`
|
|
201
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_and_send_transactions)
|
|
202
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|