@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.
Files changed (63) hide show
  1. package/LICENSE +12 -12
  2. package/README.md +159 -100
  3. package/lib/esm/index.js +175 -0
  4. package/lib/esm/index.native.js +175 -0
  5. package/lib/esm/package.json +3 -0
  6. package/lib/types/index.d.ts +211 -0
  7. package/lib/types/index.d.ts.map +1 -0
  8. package/lib/types/index.native.d.ts +211 -0
  9. package/lib/types/index.native.d.ts.map +1 -0
  10. package/package.json +39 -69
  11. package/android/build.gradle +0 -151
  12. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  13. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  14. package/android/gradle.properties +0 -5
  15. package/android/gradlew +0 -185
  16. package/android/gradlew.bat +0 -89
  17. package/android/src/main/AndroidManifest.xml +0 -23
  18. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/Extensions.kt +0 -99
  19. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/JsonSerializationUtils.kt +0 -110
  20. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterBottomSheetActivity.kt +0 -55
  21. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterWalletLibReactNativePackage.kt +0 -19
  22. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileDigitalAssetLinksModule.kt +0 -65
  23. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +0 -390
  24. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterConfig.kt +0 -60
  25. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterRequest.kt +0 -83
  26. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterResponse.kt +0 -49
  27. package/android/src/main/res/drawable/background_bottom_sheet_dialog.xml +0 -11
  28. package/android/src/main/res/values/styles.xml +0 -9
  29. package/lib/commonjs/index.js +0 -50
  30. package/lib/commonjs/index.js.map +0 -1
  31. package/lib/commonjs/mwaSessionEvents.js +0 -24
  32. package/lib/commonjs/mwaSessionEvents.js.map +0 -1
  33. package/lib/commonjs/resolve.js +0 -49
  34. package/lib/commonjs/resolve.js.map +0 -1
  35. package/lib/commonjs/useDigitalAssetLinks.js +0 -29
  36. package/lib/commonjs/useDigitalAssetLinks.js.map +0 -1
  37. package/lib/commonjs/useMobileWalletAdapterSession.js +0 -54
  38. package/lib/commonjs/useMobileWalletAdapterSession.js.map +0 -1
  39. package/lib/module/index.js +0 -5
  40. package/lib/module/index.js.map +0 -1
  41. package/lib/module/mwaSessionEvents.js +0 -17
  42. package/lib/module/mwaSessionEvents.js.map +0 -1
  43. package/lib/module/resolve.js +0 -48
  44. package/lib/module/resolve.js.map +0 -1
  45. package/lib/module/useDigitalAssetLinks.js +0 -20
  46. package/lib/module/useDigitalAssetLinks.js.map +0 -1
  47. package/lib/module/useMobileWalletAdapterSession.js +0 -48
  48. package/lib/module/useMobileWalletAdapterSession.js.map +0 -1
  49. package/lib/typescript/index.d.ts +0 -5
  50. package/lib/typescript/index.d.ts.map +0 -1
  51. package/lib/typescript/mwaSessionEvents.d.ts +0 -48
  52. package/lib/typescript/mwaSessionEvents.d.ts.map +0 -1
  53. package/lib/typescript/resolve.d.ts +0 -97
  54. package/lib/typescript/resolve.d.ts.map +0 -1
  55. package/lib/typescript/useDigitalAssetLinks.d.ts +0 -5
  56. package/lib/typescript/useDigitalAssetLinks.d.ts.map +0 -1
  57. package/lib/typescript/useMobileWalletAdapterSession.d.ts +0 -12
  58. package/lib/typescript/useMobileWalletAdapterSession.d.ts.map +0 -1
  59. package/src/index.ts +0 -4
  60. package/src/mwaSessionEvents.ts +0 -75
  61. package/src/resolve.ts +0 -171
  62. package/src/useDigitalAssetLinks.ts +0 -41
  63. 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
- ## TODO
8
- - Implement dApp identity verification/reauthorization
9
- - Separate bottom sheet signing experience or make optional
10
-
11
- ## Note
12
- 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.
13
-
14
-
15
- ## Quickstart
16
-
17
- ### 1. Define your MWA entrypoint
18
-
19
- To support bottom sheet signing flow, you need to define a React component to be the entrypoint for MWA. When the dApp sends out an intent for `solana-wallet://`, this entrypoint component will be rendered.
20
-
21
- Define your entrypoint component in `index.js`:
22
- ```typescript
23
- AppRegistry.registerComponent(
24
- 'MobileWalletAdapterEntrypoint', // Constant
25
- () => YourMWAComponent,
26
- );
27
- ```
28
-
29
- ### 1. Start listening and handling MWA requests
30
-
31
- Use this API to start a session and start handling requests:
32
- ```typescript
33
- import {
34
- MobileWalletAdapterConfig,
35
- MWARequest,
36
- MWASessionEvent,
37
- useMobileWalletAdapterSession,
38
- } from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
39
-
40
- const config: MobileWalletAdapterConfig = useMemo(() => {
41
- return {
42
- supportsSignAndSendTransactions: true,
43
- maxTransactionsPerSigningRequest: 10,
44
- maxMessagesPerSigningRequest: 10,
45
- supportedTransactionVersions: [0, 'legacy'],
46
- noConnectionWarningTimeoutMs: 3000,
47
- };
48
- }, []);
49
-
50
- // MWA Session Handlers
51
- const handleRequest = useCallback((request: MWARequest) => {
52
- /* ... */
53
- }, []);
54
-
55
- const handleSessionEvent = useCallback((sessionEvent: MWASessionEvent) => {
56
- /* ... */
57
- }, []);
58
-
59
- // Connect to the calling dApp and begin handling dApp requests
60
- useMobileWalletAdapterSession(
61
- 'Example Wallet Label',
62
- config,
63
- handleRequest,
64
- handleSessionEvent,
65
- );
66
- ```
67
-
68
- ### 3. Handling requests
69
-
70
- A `MWARequest` is handled by calling `resolve(request, response)` and each request have their appropriate response types.
71
-
72
- An example of handling an `AuthorizationRequest`:
73
- ```typescript
74
- import {
75
- AuthorizeDappResponse
76
- } from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
77
-
78
- const response = {
79
- publicKey: Keypair.generate().publicKey.toBytes(),
80
- label: 'Wallet Label',
81
- } as AuthorizeDappResponse;
82
-
83
- resolve(authorizationRequest, response)
84
- ```
85
-
86
- There are a a selection of "fail" responses that you can return to the dApp. These are for cases where the user
87
- ```typescript
88
- import {
89
- UserDeclinedResponse
90
- } from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
91
-
92
- const response = {
93
- failReason: MWARequestFailReason.UserDeclined,
94
- } as UserDeclinedResponse;
95
-
96
- // Tells the dApp user has declined the authorization request
97
- resolve(authorizationRequest, response)
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
+
@@ -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 };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }