@solana-mobile/mobile-wallet-adapter-walletlib 1.0.2 → 1.1.0
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 +159 -100
- package/lib/esm/index.js +175 -0
- package/lib/esm/index.native.js +175 -0
- package/lib/esm/package.json +3 -0
- package/lib/types/index.d.ts +211 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.native.d.ts +211 -0
- package/lib/types/index.native.d.ts.map +1 -0
- package/package.json +39 -69
- package/android/build.gradle +0 -151
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradle.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/android/src/main/AndroidManifest.xml +0 -23
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/Extensions.kt +0 -99
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/JsonSerializationUtils.kt +0 -110
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterBottomSheetActivity.kt +0 -55
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterWalletLibReactNativePackage.kt +0 -19
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileDigitalAssetLinksModule.kt +0 -65
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +0 -390
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterConfig.kt +0 -60
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterRequest.kt +0 -83
- package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterResponse.kt +0 -49
- package/android/src/main/res/drawable/background_bottom_sheet_dialog.xml +0 -11
- package/android/src/main/res/values/styles.xml +0 -9
- package/lib/commonjs/index.js +0 -50
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/mwaSessionEvents.js +0 -24
- package/lib/commonjs/mwaSessionEvents.js.map +0 -1
- package/lib/commonjs/resolve.js +0 -49
- package/lib/commonjs/resolve.js.map +0 -1
- package/lib/commonjs/useDigitalAssetLinks.js +0 -29
- package/lib/commonjs/useDigitalAssetLinks.js.map +0 -1
- package/lib/commonjs/useMobileWalletAdapterSession.js +0 -54
- package/lib/commonjs/useMobileWalletAdapterSession.js.map +0 -1
- package/lib/module/index.js +0 -5
- package/lib/module/index.js.map +0 -1
- package/lib/module/mwaSessionEvents.js +0 -17
- package/lib/module/mwaSessionEvents.js.map +0 -1
- package/lib/module/resolve.js +0 -48
- package/lib/module/resolve.js.map +0 -1
- package/lib/module/useDigitalAssetLinks.js +0 -20
- package/lib/module/useDigitalAssetLinks.js.map +0 -1
- package/lib/module/useMobileWalletAdapterSession.js +0 -48
- package/lib/module/useMobileWalletAdapterSession.js.map +0 -1
- package/lib/typescript/index.d.ts +0 -5
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/mwaSessionEvents.d.ts +0 -48
- package/lib/typescript/mwaSessionEvents.d.ts.map +0 -1
- package/lib/typescript/resolve.d.ts +0 -97
- package/lib/typescript/resolve.d.ts.map +0 -1
- package/lib/typescript/useDigitalAssetLinks.d.ts +0 -5
- package/lib/typescript/useDigitalAssetLinks.d.ts.map +0 -1
- package/lib/typescript/useMobileWalletAdapterSession.d.ts +0 -12
- package/lib/typescript/useMobileWalletAdapterSession.d.ts.map +0 -1
- package/src/index.ts +0 -4
- package/src/mwaSessionEvents.ts +0 -75
- package/src/resolve.ts +0 -171
- package/src/useDigitalAssetLinks.ts +0 -41
- package/src/useMobileWalletAdapterSession.ts +0 -87
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,100 +1,159 @@
|
|
|
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
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
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
|
+
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
### 1. Start listening and handling MWA requests
|
|
14
|
+
|
|
15
|
+
Use this API to start a session and start handling requests:
|
|
16
|
+
```typescript
|
|
17
|
+
import {
|
|
18
|
+
MobileWalletAdapterConfig,
|
|
19
|
+
MWARequest,
|
|
20
|
+
MWASessionEvent,
|
|
21
|
+
useMobileWalletAdapterSession,
|
|
22
|
+
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
|
|
23
|
+
|
|
24
|
+
const config: MobileWalletAdapterConfig = useMemo(() => {
|
|
25
|
+
return {
|
|
26
|
+
supportsSignAndSendTransactions: true,
|
|
27
|
+
maxTransactionsPerSigningRequest: 10,
|
|
28
|
+
maxMessagesPerSigningRequest: 10,
|
|
29
|
+
supportedTransactionVersions: [0, 'legacy'],
|
|
30
|
+
noConnectionWarningTimeoutMs: 3000,
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
// MWA Session Handlers
|
|
35
|
+
const handleRequest = useCallback((request: MWARequest) => {
|
|
36
|
+
/* ... */
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
39
|
+
const handleSessionEvent = useCallback((sessionEvent: MWASessionEvent) => {
|
|
40
|
+
/* ... */
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
// Connect to the calling dApp and begin handling dApp requests
|
|
44
|
+
useMobileWalletAdapterSession(
|
|
45
|
+
'Example Wallet Label',
|
|
46
|
+
config,
|
|
47
|
+
handleRequest,
|
|
48
|
+
handleSessionEvent,
|
|
49
|
+
);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Handling requests
|
|
53
|
+
|
|
54
|
+
A `MWARequest` is handled by calling `resolve(request, response)` and each request have their appropriate response types.
|
|
55
|
+
|
|
56
|
+
An example of handling an `AuthorizationRequest`:
|
|
57
|
+
```typescript
|
|
58
|
+
import {
|
|
59
|
+
AuthorizeDappResponse
|
|
60
|
+
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
|
|
61
|
+
|
|
62
|
+
const response = {
|
|
63
|
+
publicKey: Keypair.generate().publicKey.toBytes(),
|
|
64
|
+
label: 'Wallet Label',
|
|
65
|
+
} as AuthorizeDappResponse;
|
|
66
|
+
|
|
67
|
+
resolve(authorizationRequest, response)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
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.
|
|
71
|
+
```typescript
|
|
72
|
+
import {
|
|
73
|
+
UserDeclinedResponse
|
|
74
|
+
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
|
|
75
|
+
|
|
76
|
+
const response = {
|
|
77
|
+
failReason: MWARequestFailReason.UserDeclined,
|
|
78
|
+
} as UserDeclinedResponse;
|
|
79
|
+
|
|
80
|
+
// Tells the dApp user has declined the authorization request
|
|
81
|
+
resolve(authorizationRequest, response)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Properties of an MWA Request
|
|
85
|
+
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).
|
|
86
|
+
Each come with their own properties and completion response structures.
|
|
87
|
+
|
|
88
|
+
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.
|
|
89
|
+
|
|
90
|
+
## MWARequest Interfaces
|
|
91
|
+
|
|
92
|
+
### `IMWARequest`
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
Fields:
|
|
96
|
+
- `__type`: An enum defining the type of MWA Request it is.
|
|
97
|
+
- `requestId`: A unique identifier of this specific MWA Request
|
|
98
|
+
- `sessionId`: A unique identifier of the MWA Session this request belongs to.
|
|
99
|
+
|
|
100
|
+
### `IVerifiableIdentityRequest`
|
|
101
|
+
This an interface that describes MWA Requests that come with a verifiable identity and the following 3 fields.
|
|
102
|
+
|
|
103
|
+
Fields:
|
|
104
|
+
- `authorizationScope`: A byte representation of the authorization token granted to the dApp.
|
|
105
|
+
- `cluster`: The Solana RPC cluster that the dApp intends to use.
|
|
106
|
+
- `appIdentity`: An object containing 3 optional identity fields about the dApp:
|
|
107
|
+
- Note: The `iconRelativeUri` is a relative path, relative to `identityUri`.
|
|
108
|
+
```
|
|
109
|
+
{
|
|
110
|
+
identityName: 'dApp Name',
|
|
111
|
+
identityUri: 'https://yourdapp.com'
|
|
112
|
+
iconRelativeUri: "favicon.ico", // Full path resolves to https://yourdapp.com/favicon.ico
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### MWARequest Types
|
|
117
|
+
|
|
118
|
+
- `AuthorizeDappRequest`
|
|
119
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#authorize)
|
|
120
|
+
- Interfaces: `IMWARequest`
|
|
121
|
+
|
|
122
|
+
- `ReauthorizeDappRequest`
|
|
123
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#reauthorize)
|
|
124
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
125
|
+
|
|
126
|
+
- `DeauthorizeDappRequest`
|
|
127
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#deauthorize)
|
|
128
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
129
|
+
|
|
130
|
+
- `SignMessagesRequest`
|
|
131
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_messages)
|
|
132
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
133
|
+
|
|
134
|
+
- `SignTransactionsRequest`
|
|
135
|
+
- [Spec](https://solana-mobile.github.io/mobile-wallet-adapter/spec/spec.html#sign_transactions)
|
|
136
|
+
- Interfaces: `IMWARequest`, `IVerifiableIdentityRequest`
|
|
137
|
+
|
|
138
|
+
- `SignAndSendTransactionsRequest`
|
|
139
|
+
- [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
|
+
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Platform, NativeModules, NativeEventEmitter, Linking } from 'react-native';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mobile Wallet Adapter Session Events are notifications and events
|
|
6
|
+
* about the underlying session between the wallet and the dApp.
|
|
7
|
+
*/
|
|
8
|
+
var MWASessionEventType;
|
|
9
|
+
(function (MWASessionEventType) {
|
|
10
|
+
MWASessionEventType["SessionStartEvent"] = "SESSION_START";
|
|
11
|
+
MWASessionEventType["SessionReadyEvent"] = "SESSION_READY";
|
|
12
|
+
MWASessionEventType["SessionTerminatedEvent"] = "SESSION_TERMINATED";
|
|
13
|
+
MWASessionEventType["SessionServingClientsEvent"] = "SESSION_SERVING_CLIENTS";
|
|
14
|
+
MWASessionEventType["SessionServingCompleteEvent"] = "SESSION_SERVING_COMPLETE";
|
|
15
|
+
MWASessionEventType["SessionCompleteEvent"] = "SESSION_COMPLETE";
|
|
16
|
+
MWASessionEventType["SessionErrorEvent"] = "SESSION_ERROR";
|
|
17
|
+
MWASessionEventType["SessionTeardownCompleteEvent"] = "SESSION_TEARDOWN_COMPLETE";
|
|
18
|
+
MWASessionEventType["LowPowerNoConnectionEvent"] = "LOW_POWER_NO_CONNECTION";
|
|
19
|
+
})(MWASessionEventType || (MWASessionEventType = {}));
|
|
20
|
+
|
|
21
|
+
const LINKING_ERROR$2 = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
22
|
+
'- You rebuilt the app after installing the package\n' +
|
|
23
|
+
'- If you are using Lerna workspaces\n' +
|
|
24
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
25
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
26
|
+
'- You are not using Expo managed workflow\n';
|
|
27
|
+
const SolanaMobileWalletAdapterWalletLib$1 = Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
28
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
29
|
+
: new Proxy({}, {
|
|
30
|
+
get() {
|
|
31
|
+
throw new Error(Platform.OS !== 'android'
|
|
32
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
33
|
+
: LINKING_ERROR$2);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
var MWARequestType;
|
|
37
|
+
(function (MWARequestType) {
|
|
38
|
+
MWARequestType["AuthorizeDappRequest"] = "AUTHORIZE_DAPP";
|
|
39
|
+
MWARequestType["ReauthorizeDappRequest"] = "REAUTHORIZE_DAPP";
|
|
40
|
+
MWARequestType["DeauthorizeDappRequest"] = "DEAUTHORIZE_DAPP";
|
|
41
|
+
MWARequestType["SignMessagesRequest"] = "SIGN_MESSAGES";
|
|
42
|
+
MWARequestType["SignTransactionsRequest"] = "SIGN_TRANSACTIONS";
|
|
43
|
+
MWARequestType["SignAndSendTransactionsRequest"] = "SIGN_AND_SEND_TRANSACTIONS";
|
|
44
|
+
})(MWARequestType || (MWARequestType = {}));
|
|
45
|
+
/* Failure Responses */
|
|
46
|
+
var MWARequestFailReason;
|
|
47
|
+
(function (MWARequestFailReason) {
|
|
48
|
+
MWARequestFailReason["UserDeclined"] = "USER_DECLINED";
|
|
49
|
+
MWARequestFailReason["TooManyPayloads"] = "TOO_MANY_PAYLOADS";
|
|
50
|
+
MWARequestFailReason["InvalidSignatures"] = "INVALID_SIGNATURES";
|
|
51
|
+
MWARequestFailReason["AuthorizationNotValid"] = "AUTHORIZATION_NOT_VALID";
|
|
52
|
+
})(MWARequestFailReason || (MWARequestFailReason = {}));
|
|
53
|
+
function resolve(request, response) {
|
|
54
|
+
SolanaMobileWalletAdapterWalletLib$1.resolve(JSON.stringify(request), JSON.stringify(response));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/******************************************************************************
|
|
58
|
+
Copyright (c) Microsoft Corporation.
|
|
59
|
+
|
|
60
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
61
|
+
purpose with or without fee is hereby granted.
|
|
62
|
+
|
|
63
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
64
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
66
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
67
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
68
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
69
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
70
|
+
***************************************************************************** */
|
|
71
|
+
|
|
72
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
73
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
74
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
75
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
76
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
77
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
78
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const LINKING_ERROR$1 = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
83
|
+
'- You rebuilt the app after installing the package\n' +
|
|
84
|
+
'- If you are using Lerna workspaces\n' +
|
|
85
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
86
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
87
|
+
'- You are not using Expo managed workflow\n';
|
|
88
|
+
const SolanaMobileWalletAdapterWalletLib = Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
89
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
90
|
+
: new Proxy({}, {
|
|
91
|
+
get() {
|
|
92
|
+
throw new Error(Platform.OS !== 'android'
|
|
93
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
94
|
+
: LINKING_ERROR$1);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = 'MobileWalletAdapterServiceRequestBridge';
|
|
98
|
+
function useMobileWalletAdapterSession(walletName, config, handleRequest, handleSessionEvent) {
|
|
99
|
+
// Start native event listeners
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const mwaEventEmitter = new NativeEventEmitter();
|
|
102
|
+
const listener = mwaEventEmitter.addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {
|
|
103
|
+
if (isMWARequest(nativeEvent)) {
|
|
104
|
+
handleRequest(nativeEvent);
|
|
105
|
+
}
|
|
106
|
+
else if (isMWASessionEvent(nativeEvent)) {
|
|
107
|
+
handleSessionEvent(nativeEvent);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.warn('Unexpected native event type');
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
initializeScenario(walletName, config);
|
|
114
|
+
return () => {
|
|
115
|
+
listener.remove();
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
}
|
|
119
|
+
function initializeScenario(walletName, walletConfig) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
// Get initial URL
|
|
122
|
+
const initialUrl = yield Linking.getInitialURL();
|
|
123
|
+
// Create Scenario and establish session with dapp
|
|
124
|
+
if (initialUrl) {
|
|
125
|
+
SolanaMobileWalletAdapterWalletLib.createScenario(walletName, initialUrl, JSON.stringify(walletConfig));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
console.warn('Initial URL is unexpectedly uninitialized');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function isMWARequest(nativeEvent) {
|
|
133
|
+
return Object.values(MWARequestType).includes(nativeEvent.__type);
|
|
134
|
+
}
|
|
135
|
+
function isMWASessionEvent(nativeEvent) {
|
|
136
|
+
return Object.values(MWASessionEventType).includes(nativeEvent.__type);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
140
|
+
'- You rebuilt the app after installing the package\n' +
|
|
141
|
+
'- If you are using Lerna workspaces\n' +
|
|
142
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
143
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
144
|
+
'- You are not using Expo managed workflow\n';
|
|
145
|
+
const SolanaMobileDigitalAssetLinks = Platform.OS === 'android' && NativeModules.SolanaMobileDigitalAssetLinks
|
|
146
|
+
? NativeModules.SolanaMobileDigitalAssetLinks
|
|
147
|
+
: new Proxy({}, {
|
|
148
|
+
get() {
|
|
149
|
+
throw new Error(Platform.OS !== 'android'
|
|
150
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
151
|
+
: LINKING_ERROR);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
function getCallingPackage() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
return yield SolanaMobileDigitalAssetLinks.getCallingPackage();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function verifyCallingPackage(clientIdentityUri) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
return yield SolanaMobileDigitalAssetLinks.verifyCallingPackage(clientIdentityUri);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function getCallingPackageUid() {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
return yield SolanaMobileDigitalAssetLinks.getCallingPackageUid();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function getUidForPackage(packageName) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
return yield SolanaMobileDigitalAssetLinks.getUidForPackage(packageName);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { MWARequestFailReason, MWARequestType, MWASessionEventType, getCallingPackage, getCallingPackageUid, getUidForPackage, resolve, useMobileWalletAdapterSession, verifyCallingPackage };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Platform, NativeModules, NativeEventEmitter, Linking } from 'react-native';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mobile Wallet Adapter Session Events are notifications and events
|
|
6
|
+
* about the underlying session between the wallet and the dApp.
|
|
7
|
+
*/
|
|
8
|
+
var MWASessionEventType;
|
|
9
|
+
(function (MWASessionEventType) {
|
|
10
|
+
MWASessionEventType["SessionStartEvent"] = "SESSION_START";
|
|
11
|
+
MWASessionEventType["SessionReadyEvent"] = "SESSION_READY";
|
|
12
|
+
MWASessionEventType["SessionTerminatedEvent"] = "SESSION_TERMINATED";
|
|
13
|
+
MWASessionEventType["SessionServingClientsEvent"] = "SESSION_SERVING_CLIENTS";
|
|
14
|
+
MWASessionEventType["SessionServingCompleteEvent"] = "SESSION_SERVING_COMPLETE";
|
|
15
|
+
MWASessionEventType["SessionCompleteEvent"] = "SESSION_COMPLETE";
|
|
16
|
+
MWASessionEventType["SessionErrorEvent"] = "SESSION_ERROR";
|
|
17
|
+
MWASessionEventType["SessionTeardownCompleteEvent"] = "SESSION_TEARDOWN_COMPLETE";
|
|
18
|
+
MWASessionEventType["LowPowerNoConnectionEvent"] = "LOW_POWER_NO_CONNECTION";
|
|
19
|
+
})(MWASessionEventType || (MWASessionEventType = {}));
|
|
20
|
+
|
|
21
|
+
const LINKING_ERROR$2 = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
22
|
+
'- You rebuilt the app after installing the package\n' +
|
|
23
|
+
'- If you are using Lerna workspaces\n' +
|
|
24
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
25
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
26
|
+
'- You are not using Expo managed workflow\n';
|
|
27
|
+
const SolanaMobileWalletAdapterWalletLib$1 = Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
28
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
29
|
+
: new Proxy({}, {
|
|
30
|
+
get() {
|
|
31
|
+
throw new Error(Platform.OS !== 'android'
|
|
32
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
33
|
+
: LINKING_ERROR$2);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
var MWARequestType;
|
|
37
|
+
(function (MWARequestType) {
|
|
38
|
+
MWARequestType["AuthorizeDappRequest"] = "AUTHORIZE_DAPP";
|
|
39
|
+
MWARequestType["ReauthorizeDappRequest"] = "REAUTHORIZE_DAPP";
|
|
40
|
+
MWARequestType["DeauthorizeDappRequest"] = "DEAUTHORIZE_DAPP";
|
|
41
|
+
MWARequestType["SignMessagesRequest"] = "SIGN_MESSAGES";
|
|
42
|
+
MWARequestType["SignTransactionsRequest"] = "SIGN_TRANSACTIONS";
|
|
43
|
+
MWARequestType["SignAndSendTransactionsRequest"] = "SIGN_AND_SEND_TRANSACTIONS";
|
|
44
|
+
})(MWARequestType || (MWARequestType = {}));
|
|
45
|
+
/* Failure Responses */
|
|
46
|
+
var MWARequestFailReason;
|
|
47
|
+
(function (MWARequestFailReason) {
|
|
48
|
+
MWARequestFailReason["UserDeclined"] = "USER_DECLINED";
|
|
49
|
+
MWARequestFailReason["TooManyPayloads"] = "TOO_MANY_PAYLOADS";
|
|
50
|
+
MWARequestFailReason["InvalidSignatures"] = "INVALID_SIGNATURES";
|
|
51
|
+
MWARequestFailReason["AuthorizationNotValid"] = "AUTHORIZATION_NOT_VALID";
|
|
52
|
+
})(MWARequestFailReason || (MWARequestFailReason = {}));
|
|
53
|
+
function resolve(request, response) {
|
|
54
|
+
SolanaMobileWalletAdapterWalletLib$1.resolve(JSON.stringify(request), JSON.stringify(response));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/******************************************************************************
|
|
58
|
+
Copyright (c) Microsoft Corporation.
|
|
59
|
+
|
|
60
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
61
|
+
purpose with or without fee is hereby granted.
|
|
62
|
+
|
|
63
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
64
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
66
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
67
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
68
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
69
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
70
|
+
***************************************************************************** */
|
|
71
|
+
|
|
72
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
73
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
74
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
75
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
76
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
77
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
78
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const LINKING_ERROR$1 = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
83
|
+
'- You rebuilt the app after installing the package\n' +
|
|
84
|
+
'- If you are using Lerna workspaces\n' +
|
|
85
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
86
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
87
|
+
'- You are not using Expo managed workflow\n';
|
|
88
|
+
const SolanaMobileWalletAdapterWalletLib = Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
89
|
+
? NativeModules.SolanaMobileWalletAdapterWalletLib
|
|
90
|
+
: new Proxy({}, {
|
|
91
|
+
get() {
|
|
92
|
+
throw new Error(Platform.OS !== 'android'
|
|
93
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
94
|
+
: LINKING_ERROR$1);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = 'MobileWalletAdapterServiceRequestBridge';
|
|
98
|
+
function useMobileWalletAdapterSession(walletName, config, handleRequest, handleSessionEvent) {
|
|
99
|
+
// Start native event listeners
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const mwaEventEmitter = new NativeEventEmitter();
|
|
102
|
+
const listener = mwaEventEmitter.addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {
|
|
103
|
+
if (isMWARequest(nativeEvent)) {
|
|
104
|
+
handleRequest(nativeEvent);
|
|
105
|
+
}
|
|
106
|
+
else if (isMWASessionEvent(nativeEvent)) {
|
|
107
|
+
handleSessionEvent(nativeEvent);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.warn('Unexpected native event type');
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
initializeScenario(walletName, config);
|
|
114
|
+
return () => {
|
|
115
|
+
listener.remove();
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
}
|
|
119
|
+
function initializeScenario(walletName, walletConfig) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
// Get initial URL
|
|
122
|
+
const initialUrl = yield Linking.getInitialURL();
|
|
123
|
+
// Create Scenario and establish session with dapp
|
|
124
|
+
if (initialUrl) {
|
|
125
|
+
SolanaMobileWalletAdapterWalletLib.createScenario(walletName, initialUrl, JSON.stringify(walletConfig));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
console.warn('Initial URL is unexpectedly uninitialized');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function isMWARequest(nativeEvent) {
|
|
133
|
+
return Object.values(MWARequestType).includes(nativeEvent.__type);
|
|
134
|
+
}
|
|
135
|
+
function isMWASessionEvent(nativeEvent) {
|
|
136
|
+
return Object.values(MWASessionEventType).includes(nativeEvent.__type);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
|
|
140
|
+
'- You rebuilt the app after installing the package\n' +
|
|
141
|
+
'- If you are using Lerna workspaces\n' +
|
|
142
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
|
|
143
|
+
' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
|
|
144
|
+
'- You are not using Expo managed workflow\n';
|
|
145
|
+
const SolanaMobileDigitalAssetLinks = Platform.OS === 'android' && NativeModules.SolanaMobileDigitalAssetLinks
|
|
146
|
+
? NativeModules.SolanaMobileDigitalAssetLinks
|
|
147
|
+
: new Proxy({}, {
|
|
148
|
+
get() {
|
|
149
|
+
throw new Error(Platform.OS !== 'android'
|
|
150
|
+
? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
|
|
151
|
+
: LINKING_ERROR);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
function getCallingPackage() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
return yield SolanaMobileDigitalAssetLinks.getCallingPackage();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function verifyCallingPackage(clientIdentityUri) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
return yield SolanaMobileDigitalAssetLinks.verifyCallingPackage(clientIdentityUri);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function getCallingPackageUid() {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
return yield SolanaMobileDigitalAssetLinks.getCallingPackageUid();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function getUidForPackage(packageName) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
return yield SolanaMobileDigitalAssetLinks.getUidForPackage(packageName);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { MWARequestFailReason, MWARequestType, MWASessionEventType, getCallingPackage, getCallingPackageUid, getUidForPackage, resolve, useMobileWalletAdapterSession, verifyCallingPackage };
|