@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.
Files changed (23) hide show
  1. package/LICENSE +12 -12
  2. package/README.md +202 -196
  3. package/android/build.gradle +151 -151
  4. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  5. package/android/gradle.properties +5 -5
  6. package/android/gradlew +185 -185
  7. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/Extensions.kt +98 -98
  8. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/JsonSerializationUtils.kt +156 -156
  9. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/MobileWalletAdapterWalletLibReactNativePackage.kt +18 -18
  10. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/SolanaMobileWalletAdapterWalletLibModule.kt +691 -691
  11. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterConfig.kt +59 -59
  12. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterRequest.kt +97 -97
  13. package/android/src/main/java/com/solanamobile/mobilewalletadapterwalletlib/reactnative/model/MobileWalletAdapterResponse.kt +68 -68
  14. package/lib/esm/index.js +119 -194
  15. package/lib/esm/index.js.map +1 -0
  16. package/lib/esm/index.native.js +119 -194
  17. package/lib/esm/index.native.js.map +1 -0
  18. package/lib/esm/package.json +1 -3
  19. package/lib/types/index.d.ts +124 -112
  20. package/lib/types/index.d.ts.map +1 -1
  21. package/package.json +49 -46
  22. package/lib/types/index.native.d.ts +0 -226
  23. package/lib/types/index.native.d.ts.map +0 -1
package/lib/esm/index.js CHANGED
@@ -1,215 +1,140 @@
1
- import { Platform, NativeModules, NativeEventEmitter } from 'react-native';
2
- import { useEffect } from 'react';
3
-
1
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
2
+ import { useEffect } from "react";
3
+ //#region src/mwaSessionEvents.ts
4
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 = {}));
5
+ * Mobile Wallet Adapter Session Events are notifications and events
6
+ * about the underlying session between the wallet and the dApp.
7
+ */
8
+ let MWASessionEventType = /* @__PURE__ */ function(MWASessionEventType) {
9
+ MWASessionEventType["SessionStartEvent"] = "SESSION_START";
10
+ MWASessionEventType["SessionReadyEvent"] = "SESSION_READY";
11
+ MWASessionEventType["SessionTerminatedEvent"] = "SESSION_TERMINATED";
12
+ MWASessionEventType["SessionServingClientsEvent"] = "SESSION_SERVING_CLIENTS";
13
+ MWASessionEventType["SessionServingCompleteEvent"] = "SESSION_SERVING_COMPLETE";
14
+ MWASessionEventType["SessionCompleteEvent"] = "SESSION_COMPLETE";
15
+ MWASessionEventType["SessionErrorEvent"] = "SESSION_ERROR";
16
+ MWASessionEventType["SessionTeardownCompleteEvent"] = "SESSION_TEARDOWN_COMPLETE";
17
+ MWASessionEventType["LowPowerNoConnectionEvent"] = "LOW_POWER_NO_CONNECTION";
18
+ return MWASessionEventType;
19
+ }({});
20
+ //#endregion
21
+ //#region src/resolve.ts
22
+ const LINKING_ERROR$2 = "The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n- You rebuilt the app after installing the package\n- If you are using Lerna workspaces\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n- You are not using Expo managed workflow\n";
23
+ const SolanaMobileWalletAdapterWalletLib$1 = Platform.OS === "android" && NativeModules.SolanaMobileWalletAdapterWalletLib ? NativeModules.SolanaMobileWalletAdapterWalletLib : new Proxy({}, { get() {
24
+ throw new Error(Platform.OS !== "android" ? "The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android" : LINKING_ERROR$2);
25
+ } });
26
+ let MWARequestType = /* @__PURE__ */ function(MWARequestType) {
27
+ MWARequestType["AuthorizeDappRequest"] = "AUTHORIZE_DAPP";
28
+ MWARequestType["ReauthorizeDappRequest"] = "REAUTHORIZE_DAPP";
29
+ MWARequestType["DeauthorizeDappRequest"] = "DEAUTHORIZE_DAPP";
30
+ MWARequestType["SignMessagesRequest"] = "SIGN_MESSAGES";
31
+ MWARequestType["SignTransactionsRequest"] = "SIGN_TRANSACTIONS";
32
+ MWARequestType["SignAndSendTransactionsRequest"] = "SIGN_AND_SEND_TRANSACTIONS";
33
+ return MWARequestType;
34
+ }({});
35
+ let MWARequestFailReason = /* @__PURE__ */ function(MWARequestFailReason) {
36
+ MWARequestFailReason["UserDeclined"] = "USER_DECLINED";
37
+ MWARequestFailReason["TooManyPayloads"] = "TOO_MANY_PAYLOADS";
38
+ MWARequestFailReason["InvalidSignatures"] = "INVALID_SIGNATURES";
39
+ MWARequestFailReason["AuthorizationNotValid"] = "AUTHORIZATION_NOT_VALID";
40
+ return MWARequestFailReason;
41
+ }({});
53
42
  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
- var SolanaMWAWalletLibErrorCode;
83
- (function (SolanaMWAWalletLibErrorCode) {
84
- SolanaMWAWalletLibErrorCode["ERROR_INTENT_DATA_NOT_FOUND"] = "ERROR_INTENT_DATA_NOT_FOUND";
85
- SolanaMWAWalletLibErrorCode["ERROR_SESSION_ALREADY_CREATED"] = "ERROR_SESSION_ALREADY_CREATED";
86
- SolanaMWAWalletLibErrorCode["ERROR_UNSUPPORTED_ASSOCIATION_URI"] = "ERROR_UNSUPPORTED_ASSOCIATION_URI";
87
- SolanaMWAWalletLibErrorCode["ERROR_UNSUPPORTED_ASSOCIATION_TYPE"] = "ERROR_UNSUPPORTED_ASSOCIATION_TYPE";
88
- })(SolanaMWAWalletLibErrorCode || (SolanaMWAWalletLibErrorCode = {}));
89
- class SolanaMWAWalletLibError extends Error {
90
- constructor(code, message) {
91
- super(message);
92
- this.name = 'SolanaMWAWalletLibError';
93
- this.code = code;
94
- }
43
+ SolanaMobileWalletAdapterWalletLib$1.resolve(JSON.stringify(request), JSON.stringify(response));
95
44
  }
96
-
97
- const LINKING_ERROR$1 = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
98
- '- You rebuilt the app after installing the package\n' +
99
- '- If you are using Lerna workspaces\n' +
100
- ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
101
- ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
102
- '- You are not using Expo managed workflow\n';
103
- const SolanaMobileWalletAdapterWalletLib = Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib
104
- ? NativeModules.SolanaMobileWalletAdapterWalletLib
105
- : new Proxy({}, {
106
- get() {
107
- throw new Error(Platform.OS !== 'android'
108
- ? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
109
- : LINKING_ERROR$1);
110
- },
111
- });
45
+ //#endregion
46
+ //#region src/errors.ts
47
+ let SolanaMWAWalletLibErrorCode = /* @__PURE__ */ function(SolanaMWAWalletLibErrorCode) {
48
+ SolanaMWAWalletLibErrorCode["ERROR_INTENT_DATA_NOT_FOUND"] = "ERROR_INTENT_DATA_NOT_FOUND";
49
+ SolanaMWAWalletLibErrorCode["ERROR_SESSION_ALREADY_CREATED"] = "ERROR_SESSION_ALREADY_CREATED";
50
+ SolanaMWAWalletLibErrorCode["ERROR_UNSUPPORTED_ASSOCIATION_URI"] = "ERROR_UNSUPPORTED_ASSOCIATION_URI";
51
+ SolanaMWAWalletLibErrorCode["ERROR_UNSUPPORTED_ASSOCIATION_TYPE"] = "ERROR_UNSUPPORTED_ASSOCIATION_TYPE";
52
+ return SolanaMWAWalletLibErrorCode;
53
+ }({});
54
+ var SolanaMWAWalletLibError = class extends Error {
55
+ code;
56
+ constructor(code, message) {
57
+ super(message);
58
+ this.name = "SolanaMWAWalletLibError";
59
+ this.code = code;
60
+ }
61
+ };
62
+ //#endregion
63
+ //#region src/initializeMobileWalletAdapterSession.ts
64
+ const LINKING_ERROR$1 = "The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n- You rebuilt the app after installing the package\n- If you are using Lerna workspaces\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n- You are not using Expo managed workflow\n";
65
+ const SolanaMobileWalletAdapterWalletLib = Platform.OS === "android" && NativeModules.SolanaMobileWalletAdapterWalletLib ? NativeModules.SolanaMobileWalletAdapterWalletLib : new Proxy({}, { get() {
66
+ throw new Error(Platform.OS !== "android" ? "The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android" : LINKING_ERROR$1);
67
+ } });
112
68
  function handleError(e) {
113
- if (e instanceof Error) {
114
- const { code, message } = e;
115
- if (code && code in SolanaMWAWalletLibErrorCode) {
116
- throw new SolanaMWAWalletLibError(code, message);
117
- }
118
- }
119
- throw e;
69
+ if (e instanceof Error) {
70
+ const { code, message } = e;
71
+ if (code && code in SolanaMWAWalletLibErrorCode) throw new SolanaMWAWalletLibError(code, message);
72
+ }
73
+ throw e;
120
74
  }
121
- function initializeMobileWalletAdapterSession(walletName, config) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- try {
124
- return yield initializeScenario(walletName, config);
125
- }
126
- catch (e) {
127
- handleError(e);
128
- }
129
- });
75
+ async function initializeMobileWalletAdapterSession(walletName, config) {
76
+ try {
77
+ return await initializeScenario(walletName, config);
78
+ } catch (e) {
79
+ handleError(e);
80
+ }
130
81
  }
131
- // Create Scenario and establish session with dapp
132
82
  function initializeScenario(walletName, walletConfig) {
133
- return SolanaMobileWalletAdapterWalletLib.createScenario(walletName, JSON.stringify(walletConfig));
83
+ return SolanaMobileWalletAdapterWalletLib.createScenario(walletName, JSON.stringify(walletConfig));
134
84
  }
135
-
136
- const MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = 'MobileWalletAdapterServiceRequestBridge';
85
+ //#endregion
86
+ //#region src/initializeMWAEventListener.ts
87
+ const MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = "MobileWalletAdapterServiceRequestBridge";
137
88
  function initializeMWAEventListener(handleRequest, handleSessionEvent) {
138
- const mwaEventEmitter = new NativeEventEmitter();
139
- const listener = mwaEventEmitter.addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {
140
- if (isMWARequest(nativeEvent)) {
141
- handleRequest(nativeEvent);
142
- }
143
- else if (isMWASessionEvent(nativeEvent)) {
144
- handleSessionEvent(nativeEvent);
145
- }
146
- else {
147
- console.warn('Unexpected native event type');
148
- }
149
- });
150
- return listener;
89
+ return new NativeEventEmitter().addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {
90
+ if (isMWARequest(nativeEvent)) handleRequest(nativeEvent);
91
+ else if (isMWASessionEvent(nativeEvent)) handleSessionEvent(nativeEvent);
92
+ else console.warn("Unexpected native event type");
93
+ });
151
94
  }
152
95
  function isMWARequest(nativeEvent) {
153
- return Object.values(MWARequestType).includes(nativeEvent.__type);
96
+ return Object.values(MWARequestType).includes(nativeEvent.__type);
154
97
  }
155
98
  function isMWASessionEvent(nativeEvent) {
156
- return Object.values(MWASessionEventType).includes(nativeEvent.__type);
99
+ return Object.values(MWASessionEventType).includes(nativeEvent.__type);
157
100
  }
158
-
101
+ //#endregion
102
+ //#region src/useMobileWalletAdapterSession.ts
159
103
  function useMobileWalletAdapterSession(walletName, config, handleRequest, handleSessionEvent) {
160
- useEffect(() => {
161
- function startSession() {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- try {
164
- yield initializeMobileWalletAdapterSession(walletName, config);
165
- }
166
- catch (e) {
167
- console.error(e);
168
- }
169
- });
170
- }
171
- const listener = initializeMWAEventListener(handleRequest, handleSessionEvent);
172
- startSession();
173
- return () => {
174
- listener.remove();
175
- };
176
- }, []);
104
+ useEffect(() => {
105
+ async function startSession() {
106
+ try {
107
+ await initializeMobileWalletAdapterSession(walletName, config);
108
+ } catch (e) {
109
+ console.error(e);
110
+ }
111
+ }
112
+ const listener = initializeMWAEventListener(handleRequest, handleSessionEvent);
113
+ startSession();
114
+ return () => {
115
+ listener.remove();
116
+ };
117
+ }, []);
177
118
  }
178
-
179
- const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n` +
180
- '- You rebuilt the app after installing the package\n' +
181
- '- If you are using Lerna workspaces\n' +
182
- ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n' +
183
- ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n' +
184
- '- You are not using Expo managed workflow\n';
185
- const SolanaMobileDigitalAssetLinks = Platform.OS === 'android' && NativeModules.SolanaMobileDigitalAssetLinks
186
- ? NativeModules.SolanaMobileDigitalAssetLinks
187
- : new Proxy({}, {
188
- get() {
189
- throw new Error(Platform.OS !== 'android'
190
- ? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'
191
- : LINKING_ERROR);
192
- },
193
- });
194
- function getCallingPackage() {
195
- return __awaiter(this, void 0, void 0, function* () {
196
- return yield SolanaMobileDigitalAssetLinks.getCallingPackage();
197
- });
119
+ //#endregion
120
+ //#region src/useDigitalAssetLinks.ts
121
+ const LINKING_ERROR = "The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \n\n- You rebuilt the app after installing the package\n- If you are using Lerna workspaces\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\n - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\n- You are not using Expo managed workflow\n";
122
+ const SolanaMobileDigitalAssetLinks = Platform.OS === "android" && NativeModules.SolanaMobileDigitalAssetLinks ? NativeModules.SolanaMobileDigitalAssetLinks : new Proxy({}, { get() {
123
+ throw new Error(Platform.OS !== "android" ? "The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android" : LINKING_ERROR);
124
+ } });
125
+ async function getCallingPackage() {
126
+ return await SolanaMobileDigitalAssetLinks.getCallingPackage();
198
127
  }
199
- function verifyCallingPackage(clientIdentityUri) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- return yield SolanaMobileDigitalAssetLinks.verifyCallingPackage(clientIdentityUri);
202
- });
128
+ async function verifyCallingPackage(clientIdentityUri) {
129
+ return await SolanaMobileDigitalAssetLinks.verifyCallingPackage(clientIdentityUri);
203
130
  }
204
- function getCallingPackageUid() {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- return yield SolanaMobileDigitalAssetLinks.getCallingPackageUid();
207
- });
131
+ async function getCallingPackageUid() {
132
+ return await SolanaMobileDigitalAssetLinks.getCallingPackageUid();
208
133
  }
209
- function getUidForPackage(packageName) {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- return yield SolanaMobileDigitalAssetLinks.getUidForPackage(packageName);
212
- });
134
+ async function getUidForPackage(packageName) {
135
+ return await SolanaMobileDigitalAssetLinks.getUidForPackage(packageName);
213
136
  }
214
-
137
+ //#endregion
215
138
  export { MWARequestFailReason, MWARequestType, MWASessionEventType, SolanaMWAWalletLibError, SolanaMWAWalletLibErrorCode, getCallingPackage, getCallingPackageUid, getUidForPackage, initializeMWAEventListener, initializeMobileWalletAdapterSession, resolve, useMobileWalletAdapterSession, verifyCallingPackage };
139
+
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["LINKING_ERROR","SolanaMobileWalletAdapterWalletLib","LINKING_ERROR"],"sources":["../../src/mwaSessionEvents.ts","../../src/resolve.ts","../../src/errors.ts","../../src/initializeMobileWalletAdapterSession.ts","../../src/initializeMWAEventListener.ts","../../src/useMobileWalletAdapterSession.ts","../../src/useDigitalAssetLinks.ts"],"sourcesContent":["/**\n * Mobile Wallet Adapter Session Events are notifications and events\n * about the underlying session between the wallet and the dApp.\n */\nexport enum MWASessionEventType {\n SessionStartEvent = 'SESSION_START',\n SessionReadyEvent = 'SESSION_READY',\n SessionTerminatedEvent = 'SESSION_TERMINATED',\n SessionServingClientsEvent = 'SESSION_SERVING_CLIENTS',\n SessionServingCompleteEvent = 'SESSION_SERVING_COMPLETE',\n SessionCompleteEvent = 'SESSION_COMPLETE',\n SessionErrorEvent = 'SESSION_ERROR',\n SessionTeardownCompleteEvent = 'SESSION_TEARDOWN_COMPLETE',\n LowPowerNoConnectionEvent = 'LOW_POWER_NO_CONNECTION',\n}\nexport interface IMWASessionEvent {\n __type: MWASessionEventType;\n sessionId: string;\n}\n\nexport type SessionStartEvent = Readonly<{\n __type: MWASessionEventType.SessionStartEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionReadyEvent = Readonly<{\n __type: MWASessionEventType.SessionReadyEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionTerminatedEvent = Readonly<{\n __type: MWASessionEventType.SessionTerminatedEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionServingClientsEvent = Readonly<{\n __type: MWASessionEventType.SessionServingClientsEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionServingCompleteEvent = Readonly<{\n __type: MWASessionEventType.SessionServingCompleteEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionCompleteEvent = Readonly<{\n __type: MWASessionEventType.SessionCompleteEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionErrorEvent = Readonly<{\n __type: MWASessionEventType.SessionErrorEvent;\n}> &\n IMWASessionEvent;\n\nexport type SessionTeardownCompleteEvent = Readonly<{\n __type: MWASessionEventType.SessionTeardownCompleteEvent;\n}> &\n IMWASessionEvent;\n\nexport type LowPowerNoConnectionEvent = Readonly<{\n __type: MWASessionEventType.LowPowerNoConnectionEvent;\n}> &\n IMWASessionEvent;\n\nexport type MWASessionEvent =\n | SessionStartEvent\n | SessionReadyEvent\n | SessionTerminatedEvent\n | SessionServingClientsEvent\n | SessionServingCompleteEvent\n | SessionCompleteEvent\n | SessionErrorEvent\n | SessionTeardownCompleteEvent\n | LowPowerNoConnectionEvent;\n","import type { IdentifierArray } from '@wallet-standard/core';\nimport { NativeModules, Platform } from 'react-native';\n\nconst LINKING_ERROR =\n `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \\n\\n` +\n '- You rebuilt the app after installing the package\\n' +\n '- If you are using Lerna workspaces\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst SolanaMobileWalletAdapterWalletLib =\n Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib\n ? NativeModules.SolanaMobileWalletAdapterWalletLib\n : new Proxy(\n {},\n {\n get() {\n throw new Error(\n Platform.OS !== 'android'\n ? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'\n : LINKING_ERROR,\n );\n },\n },\n );\n\ntype AppIdentity = Readonly<{\n identityUri?: string;\n iconRelativeUri?: string;\n identityName?: string;\n}>;\n\nexport type SignInPayload = Readonly<{\n domain?: string;\n address?: string;\n statement?: string;\n uri?: string;\n version?: string;\n chainId?: string;\n nonce?: string;\n issuedAt?: string;\n expirationTime?: string;\n notBefore?: string;\n requestId?: string;\n resources?: readonly string[];\n}>;\n\nexport type Base64EncodedAddress = string;\nexport type Base64EncodedSignature = string;\ntype Base64EncodedSignedMessage = string;\n\n/**\n * Mobile Wallet Adapter Requests are remote requests coming from\n * the dApp for authorization, signing, and sending services.\n */\n\nexport type MWARequest =\n | SignMessagesRequest\n | SignTransactionsRequest\n | SignAndSendTransactionsRequest\n | AuthorizeDappRequest\n | ReauthorizeDappRequest\n | DeauthorizeDappRequest;\n\nexport enum MWARequestType {\n AuthorizeDappRequest = 'AUTHORIZE_DAPP',\n ReauthorizeDappRequest = 'REAUTHORIZE_DAPP',\n DeauthorizeDappRequest = 'DEAUTHORIZE_DAPP',\n SignMessagesRequest = 'SIGN_MESSAGES',\n SignTransactionsRequest = 'SIGN_TRANSACTIONS',\n SignAndSendTransactionsRequest = 'SIGN_AND_SEND_TRANSACTIONS',\n}\n\ninterface IMWARequest {\n __type: MWARequestType;\n requestId: string;\n sessionId: string;\n}\n\ninterface IVerifiableIdentityRequest {\n chain: string;\n authorizationScope: Uint8Array;\n appIdentity?: AppIdentity;\n}\n\nexport type AuthorizeDappRequest = Readonly<{\n __type: MWARequestType.AuthorizeDappRequest;\n chain: string;\n appIdentity?: AppIdentity;\n features?: IdentifierArray;\n addresses?: [string];\n signInPayload?: SignInPayload;\n}> &\n IMWARequest;\n\nexport type ReauthorizeDappRequest = Readonly<{\n __type: MWARequestType.ReauthorizeDappRequest;\n}> &\n IMWARequest &\n IVerifiableIdentityRequest;\n\nexport type DeauthorizeDappRequest = Readonly<{\n __type: MWARequestType.DeauthorizeDappRequest;\n}> &\n IMWARequest &\n IVerifiableIdentityRequest;\n\nexport type SignMessagesRequest = Readonly<{\n __type: MWARequestType.SignMessagesRequest;\n payloads: Uint8Array[];\n}> &\n IMWARequest &\n IVerifiableIdentityRequest;\n\nexport type SignTransactionsRequest = Readonly<{\n __type: MWARequestType.SignTransactionsRequest;\n payloads: Uint8Array[];\n}> &\n IMWARequest &\n IVerifiableIdentityRequest;\n\nexport type SignAndSendTransactionsRequest = Readonly<{\n __type: MWARequestType.SignAndSendTransactionsRequest;\n payloads: Uint8Array[];\n minContextSlot?: number;\n commitment?: string;\n skipPreflight?: boolean;\n maxRetries?: number;\n waitForCommitmentToSendNextTransaction?: boolean;\n}> &\n IMWARequest &\n IVerifiableIdentityRequest;\n\n/**\n * MWA Request Responses\n */\n\nexport type MWAResponse =\n | AuthorizeDappResponse\n | ReauthorizeDappResponse\n | DeauthorizeDappResponse\n | SignMessagesResponse\n | SignTransactionsResponse\n | SignAndSendTransactionsResponse;\n\n/* Failure Responses */\nexport enum MWARequestFailReason {\n UserDeclined = 'USER_DECLINED',\n TooManyPayloads = 'TOO_MANY_PAYLOADS',\n InvalidSignatures = 'INVALID_SIGNATURES',\n AuthorizationNotValid = 'AUTHORIZATION_NOT_VALID',\n}\n\nexport type UserDeclinedResponse = Readonly<{\n failReason: MWARequestFailReason.UserDeclined;\n}>;\n\nexport type TooManyPayloadsResponse = Readonly<{\n failReason: MWARequestFailReason.TooManyPayloads;\n}>;\n\nexport type AuthorizationNotValidResponse = Readonly<{\n failReason: MWARequestFailReason.AuthorizationNotValid;\n}>;\n\nexport type InvalidSignaturesResponse = Readonly<{\n failReason: MWARequestFailReason.InvalidSignatures;\n valid: boolean[];\n}>;\n\n/* Authorize Dapp */\nexport type AuthorizedAccount = Readonly<{\n publicKey: Uint8Array;\n accountLabel?: string;\n icon?: string;\n chains?: IdentifierArray;\n features?: IdentifierArray;\n}>;\nexport type SignInResult = Readonly<{\n address: Base64EncodedAddress;\n signed_message: Base64EncodedSignedMessage;\n signature: Base64EncodedSignature;\n signature_type?: string;\n}>;\nexport type AuthorizeDappCompleteResponse = Readonly<{\n accounts: Array<AuthorizedAccount>;\n walletUriBase?: string;\n authorizationScope?: Uint8Array;\n signInResult?: SignInResult;\n}>;\nexport type AuthorizeDappResponse = AuthorizeDappCompleteResponse | UserDeclinedResponse;\n\n/* Reauthorize Dapp */\nexport type ReauthorizeDappCompleteResponse = Readonly<{\n authorizationScope?: Uint8Array;\n}>;\nexport type ReauthorizeDappResponse = ReauthorizeDappCompleteResponse | AuthorizationNotValidResponse;\n\n/* Deauthorize Dapp */\nexport type DeauthorizeDappCompleteResponse = Readonly<{}>;\nexport type DeauthorizeDappResponse = DeauthorizeDappCompleteResponse | AuthorizationNotValidResponse;\n\n/* Sign Transactions/Messages */\nexport type SignPayloadsCompleteResponse = Readonly<{ signedPayloads: Uint8Array[] }>;\nexport type SignPayloadsFailResponse =\n | UserDeclinedResponse\n | TooManyPayloadsResponse\n | AuthorizationNotValidResponse\n | InvalidSignaturesResponse;\n\nexport type SignTransactionsResponse = SignPayloadsCompleteResponse | SignPayloadsFailResponse;\nexport type SignMessagesResponse = SignPayloadsCompleteResponse | SignPayloadsFailResponse;\n\n/* Sign and Send Transaction */\nexport type SignAndSendTransactionsCompleteResponse = Readonly<{ signedTransactions: Uint8Array[] }>;\nexport type SignAndSendTransactionsResponse =\n | SignAndSendTransactionsCompleteResponse\n | UserDeclinedResponse\n | TooManyPayloadsResponse\n | AuthorizationNotValidResponse\n | InvalidSignaturesResponse;\n\nexport function resolve(request: AuthorizeDappRequest, response: AuthorizeDappResponse): void;\nexport function resolve(request: ReauthorizeDappRequest, response: ReauthorizeDappResponse): void;\nexport function resolve(request: DeauthorizeDappRequest, response: DeauthorizeDappResponse): void;\nexport function resolve(request: SignMessagesRequest, response: SignMessagesResponse): void;\nexport function resolve(request: SignTransactionsRequest, response: SignTransactionsResponse): void;\nexport function resolve(request: SignAndSendTransactionsRequest, response: SignAndSendTransactionsResponse): void;\nexport function resolve(request: MWARequest, response: MWAResponse): void {\n SolanaMobileWalletAdapterWalletLib.resolve(JSON.stringify(request), JSON.stringify(response));\n}\n","export enum SolanaMWAWalletLibErrorCode {\n ERROR_INTENT_DATA_NOT_FOUND = 'ERROR_INTENT_DATA_NOT_FOUND',\n ERROR_SESSION_ALREADY_CREATED = 'ERROR_SESSION_ALREADY_CREATED',\n ERROR_UNSUPPORTED_ASSOCIATION_URI = 'ERROR_UNSUPPORTED_ASSOCIATION_URI',\n ERROR_UNSUPPORTED_ASSOCIATION_TYPE = 'ERROR_UNSUPPORTED_ASSOCIATION_TYPE',\n}\n\nexport class SolanaMWAWalletLibError extends Error {\n code: SolanaMWAWalletLibErrorCode;\n constructor(code: SolanaMWAWalletLibErrorCode, message: string) {\n super(message);\n this.name = 'SolanaMWAWalletLibError';\n this.code = code;\n }\n}\n","import type { TransactionVersion } from '@solana/web3.js';\nimport type { IdentifierArray } from '@wallet-standard/core';\nimport { NativeModules, Platform } from 'react-native';\n\nimport { SolanaMWAWalletLibError, SolanaMWAWalletLibErrorCode } from './errors.js';\n\nconst LINKING_ERROR =\n `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \\n\\n` +\n '- You rebuilt the app after installing the package\\n' +\n '- If you are using Lerna workspaces\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst SolanaMobileWalletAdapterWalletLib =\n Platform.OS === 'android' && NativeModules.SolanaMobileWalletAdapterWalletLib\n ? NativeModules.SolanaMobileWalletAdapterWalletLib\n : new Proxy(\n {},\n {\n get() {\n throw new Error(\n Platform.OS !== 'android'\n ? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'\n : LINKING_ERROR,\n );\n },\n },\n );\n\ntype ReactNativeError = Error & { code?: string; userInfo?: Record<string, unknown> };\n\nfunction handleError(e: any): never {\n if (e instanceof Error) {\n const { code, message } = e as ReactNativeError;\n if (code && code in SolanaMWAWalletLibErrorCode) {\n throw new SolanaMWAWalletLibError(code as SolanaMWAWalletLibErrorCode, message);\n }\n }\n throw e;\n}\n\nexport type MWASessionId = string;\n\nexport interface MobileWalletAdapterConfig {\n maxTransactionsPerSigningRequest: number;\n maxMessagesPerSigningRequest: number;\n supportedTransactionVersions: Array<TransactionVersion>;\n noConnectionWarningTimeoutMs: number;\n optionalFeatures: IdentifierArray;\n}\n\nexport async function initializeMobileWalletAdapterSession(\n walletName: string,\n config: MobileWalletAdapterConfig,\n): Promise<MWASessionId> {\n try {\n return await initializeScenario(walletName, config);\n } catch (e) {\n handleError(e);\n }\n}\n\n// Create Scenario and establish session with dapp\nfunction initializeScenario(walletName: string, walletConfig: MobileWalletAdapterConfig): Promise<MWASessionId> {\n return SolanaMobileWalletAdapterWalletLib.createScenario(walletName, JSON.stringify(walletConfig));\n}\n","import { EmitterSubscription, NativeEventEmitter } from 'react-native';\n\nimport { MWASessionEvent, MWASessionEventType } from './mwaSessionEvents.js';\nimport { MWARequest, MWARequestType } from './resolve.js';\n\nconst MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME = 'MobileWalletAdapterServiceRequestBridge';\n\nexport function initializeMWAEventListener(\n handleRequest: (request: MWARequest) => void,\n handleSessionEvent: (sessionEvent: MWASessionEvent) => void,\n): EmitterSubscription {\n const mwaEventEmitter = new NativeEventEmitter();\n const listener = mwaEventEmitter.addListener(MOBILE_WALLET_ADAPTER_EVENT_BRIDGE_NAME, (nativeEvent) => {\n if (isMWARequest(nativeEvent)) {\n handleRequest(nativeEvent as MWARequest);\n } else if (isMWASessionEvent(nativeEvent)) {\n handleSessionEvent(nativeEvent as MWASessionEvent);\n } else {\n console.warn('Unexpected native event type');\n }\n });\n\n return listener;\n}\n\nfunction isMWARequest(nativeEvent: any): boolean {\n return Object.values(MWARequestType).includes(nativeEvent.__type);\n}\n\nfunction isMWASessionEvent(nativeEvent: any) {\n return Object.values(MWASessionEventType).includes(nativeEvent.__type);\n}\n","import { useEffect } from 'react';\n\nimport {\n initializeMobileWalletAdapterSession,\n MobileWalletAdapterConfig,\n} from './initializeMobileWalletAdapterSession.js';\nimport { initializeMWAEventListener } from './initializeMWAEventListener.js';\nimport { MWASessionEvent } from './mwaSessionEvents.js';\nimport { MWARequest } from './resolve.js';\n\nexport function useMobileWalletAdapterSession(\n walletName: string,\n config: MobileWalletAdapterConfig,\n handleRequest: (request: MWARequest) => void,\n handleSessionEvent: (sessionEvent: MWASessionEvent) => void,\n) {\n useEffect(() => {\n async function startSession() {\n try {\n await initializeMobileWalletAdapterSession(walletName, config);\n } catch (e) {\n console.error(e);\n }\n }\n const listener = initializeMWAEventListener(handleRequest, handleSessionEvent);\n startSession();\n return () => {\n listener.remove();\n };\n }, []);\n}\n","import { NativeModules, Platform } from 'react-native';\n\nconst LINKING_ERROR =\n `The package 'solana-mobile-wallet-adapter-walletlib' doesn't seem to be linked. Make sure: \\n\\n` +\n '- You rebuilt the app after installing the package\\n' +\n '- If you are using Lerna workspaces\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` as an explicit dependency, and\\n' +\n ' - You have added `@solana-mobile/mobile-wallet-adapter-walletlib` to the `nohoist` section of your package.json\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst SolanaMobileDigitalAssetLinks =\n Platform.OS === 'android' && NativeModules.SolanaMobileDigitalAssetLinks\n ? NativeModules.SolanaMobileDigitalAssetLinks\n : new Proxy(\n {},\n {\n get() {\n throw new Error(\n Platform.OS !== 'android'\n ? 'The package `solana-mobile-wallet-adapter-walletlib` is only compatible with React Native Android'\n : LINKING_ERROR,\n );\n },\n },\n );\n\nexport async function getCallingPackage(): Promise<string | undefined> {\n return await SolanaMobileDigitalAssetLinks.getCallingPackage();\n}\n\nexport async function verifyCallingPackage(clientIdentityUri: string) {\n return await SolanaMobileDigitalAssetLinks.verifyCallingPackage(clientIdentityUri);\n}\n\nexport async function getCallingPackageUid() {\n return await SolanaMobileDigitalAssetLinks.getCallingPackageUid();\n}\n\nexport async function getUidForPackage(packageName: string) {\n return await SolanaMobileDigitalAssetLinks.getUidForPackage(packageName);\n}\n"],"mappings":"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"}