@solana-mobile/mobile-wallet-adapter-protocol 2.1.4 → 2.2.0-new-arch-beta

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 (41) hide show
  1. package/.gitignore +2 -0
  2. package/android/.gitignore +14 -0
  3. package/android/build.gradle +13 -1
  4. package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterModule.kt +133 -110
  5. package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterPackage.kt +35 -16
  6. package/android/src/newarch/SolanaMobileWalletAdapter.kt +7 -0
  7. package/android/src/oldarch/SolanaMobileWalletAdapter.kt +16 -0
  8. package/lib/cjs/index.browser.js +8 -4
  9. package/lib/cjs/index.js +8 -4
  10. package/lib/cjs/index.native.js +4 -2
  11. package/lib/esm/index.browser.js +8 -4
  12. package/lib/esm/index.js +8 -4
  13. package/lib/types/index.native.d.ts.map +1 -1
  14. package/package.json +9 -1
  15. package/src/__forks__/react-native/base64Utils.ts +1 -0
  16. package/src/__forks__/react-native/transact.ts +91 -0
  17. package/src/arrayBufferToBase64String.ts +10 -0
  18. package/src/associationPort.ts +19 -0
  19. package/src/base64Utils.ts +3 -0
  20. package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +13 -0
  21. package/src/createHelloReq.ts +12 -0
  22. package/src/createMobileWalletProxy.ts +175 -0
  23. package/src/createSIWSMessage.ts +14 -0
  24. package/src/createSequenceNumberVector.ts +11 -0
  25. package/src/encryptedMessage.ts +60 -0
  26. package/src/errors.ts +99 -0
  27. package/src/generateAssociationKeypair.ts +10 -0
  28. package/src/generateECDHKeypair.ts +10 -0
  29. package/src/getAssociateAndroidIntentURL.ts +78 -0
  30. package/src/getJWS.ts +19 -0
  31. package/src/getStringWithURLUnsafeBase64CharactersReplaced.ts +11 -0
  32. package/src/index.ts +3 -0
  33. package/src/jsonRpcMessage.ts +38 -0
  34. package/src/parseHelloRsp.ts +46 -0
  35. package/src/parseSessionProps.ts +33 -0
  36. package/src/reflectorId.ts +31 -0
  37. package/src/startSession.ts +130 -0
  38. package/src/transact.ts +499 -0
  39. package/src/types.ts +192 -0
  40. package/tsconfig.cjs.json +7 -0
  41. package/tsconfig.json +8 -0
package/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ lib/
2
+ android/build
@@ -0,0 +1,14 @@
1
+ # OSX
2
+ #
3
+ .DS_Store
4
+
5
+ # Android/IJ
6
+ #
7
+ .classpath
8
+ .cxx
9
+ .gradle
10
+ .idea
11
+ .project
12
+ .settings
13
+ local.properties
14
+ android.iml
@@ -8,7 +8,7 @@ buildscript {
8
8
  }
9
9
 
10
10
  dependencies {
11
- classpath 'com.android.tools.build:gradle:8.7.1'
11
+ classpath 'com.android.tools.build:gradle:8.7.2'
12
12
  // noinspection DifferentKotlinGradleVersion
13
13
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
14
  }
@@ -55,6 +55,18 @@ android {
55
55
  sourceCompatibility JavaVersion.VERSION_1_8
56
56
  targetCompatibility JavaVersion.VERSION_1_8
57
57
  }
58
+
59
+ sourceSets {
60
+ main {
61
+ if (isNewArchitectureEnabled()) {
62
+ java.srcDirs += [
63
+ "src/newarch"
64
+ ]
65
+ } else {
66
+ java.srcDirs += ["src/oldarch"]
67
+ }
68
+ }
69
+ }
58
70
  }
59
71
 
60
72
  repositories {
@@ -13,25 +13,26 @@ import com.solana.mobilewalletadapter.clientlib.scenario.LocalAssociationScenari
13
13
  import com.solana.mobilewalletadapter.common.protocol.SessionProperties.ProtocolVersion
14
14
  import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertJsonToMap
15
15
  import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertMapToJson
16
- import kotlinx.coroutines.*
17
- import kotlinx.coroutines.sync.Mutex
18
- import org.json.JSONObject
19
16
  import java.util.concurrent.ExecutionException
20
17
  import java.util.concurrent.TimeUnit
21
18
  import java.util.concurrent.TimeoutException
19
+ import kotlinx.coroutines.*
20
+ import kotlinx.coroutines.sync.Mutex
21
+ import org.json.JSONObject
22
22
 
23
23
  class SolanaMobileWalletAdapterModule(reactContext: ReactApplicationContext) :
24
- ReactContextBaseJavaModule(reactContext), CoroutineScope {
24
+ SolanaMobileWalletAdapterSpec(reactContext), CoroutineScope {
25
25
 
26
26
  data class SessionState(
27
- val client: MobileWalletAdapterClient,
28
- val localAssociation: LocalAssociationScenario,
27
+ val client: MobileWalletAdapterClient,
28
+ val localAssociation: LocalAssociationScenario,
29
29
  )
30
30
 
31
31
  override val coroutineContext =
32
- Dispatchers.IO + CoroutineName("SolanaMobileWalletAdapterModuleScope") + SupervisorJob()
32
+ Dispatchers.IO + CoroutineName("SolanaMobileWalletAdapterModuleScope") + SupervisorJob()
33
33
 
34
34
  companion object {
35
+ const val NAME = "SolanaMobileWalletAdapter"
35
36
  private const val ASSOCIATION_TIMEOUT_MS = 10000
36
37
  private const val CLIENT_TIMEOUT_MS = 90000
37
38
  private const val REQUEST_LOCAL_ASSOCIATION = 0
@@ -43,130 +44,152 @@ class SolanaMobileWalletAdapterModule(reactContext: ReactApplicationContext) :
43
44
  }
44
45
 
45
46
  private val mActivityEventListener: ActivityEventListener =
46
- object : BaseActivityEventListener() {
47
- override fun onActivityResult(
48
- activity: Activity?,
49
- requestCode: Int,
50
- resultCode: Int,
51
- data: Intent?
52
- ) {
53
- if (requestCode == REQUEST_LOCAL_ASSOCIATION)
54
- associationResultCallback?.invoke(resultCode)
47
+ object : BaseActivityEventListener() {
48
+ override fun onActivityResult(
49
+ activity: Activity?,
50
+ requestCode: Int,
51
+ resultCode: Int,
52
+ data: Intent?
53
+ ) {
54
+ if (requestCode == REQUEST_LOCAL_ASSOCIATION)
55
+ associationResultCallback?.invoke(resultCode)
56
+ }
55
57
  }
56
- }
57
58
 
58
59
  init {
59
60
  reactContext.addActivityEventListener(mActivityEventListener)
60
61
  }
61
62
 
62
63
  override fun getName(): String {
63
- return "SolanaMobileWalletAdapter"
64
+ return NAME
64
65
  }
65
66
 
66
67
  @ReactMethod
67
- fun startSession(config: ReadableMap?, promise: Promise) = launch {
68
- mutex.lock()
69
- Log.d(name, "startSession with config $config")
70
- try {
71
- val uriPrefix = config?.getString("baseUri")?.let { Uri.parse(it) }
72
- val localAssociation = LocalAssociationScenario(
73
- CLIENT_TIMEOUT_MS,
74
- )
75
- val intent = LocalAssociationIntentCreator.createAssociationIntent(
76
- uriPrefix,
77
- localAssociation.port,
78
- localAssociation.session
79
- )
80
- associationResultCallback = { resultCode ->
81
- if (resultCode == Activity.RESULT_CANCELED) {
82
- Log.d(name, "Local association cancelled by user, ending session")
83
- promise.reject("Session not established: Local association cancelled by user",
84
- LocalAssociationScenario.ConnectionFailedException("Local association cancelled by user"))
85
- localAssociation.close()
68
+ override fun startSession(config: ReadableMap?, promise: Promise): Unit {
69
+ launch {
70
+ mutex.lock()
71
+ Log.d(name, "startSession with config $config")
72
+ try {
73
+ val uriPrefix = config?.getString("baseUri")?.let { Uri.parse(it) }
74
+ val localAssociation =
75
+ LocalAssociationScenario(
76
+ CLIENT_TIMEOUT_MS,
77
+ )
78
+ val intent =
79
+ LocalAssociationIntentCreator.createAssociationIntent(
80
+ uriPrefix,
81
+ localAssociation.port,
82
+ localAssociation.session
83
+ )
84
+ associationResultCallback = { resultCode ->
85
+ if (resultCode == Activity.RESULT_CANCELED) {
86
+ Log.d(name, "Local association cancelled by user, ending session")
87
+ promise.reject(
88
+ "Session not established: Local association cancelled by user",
89
+ LocalAssociationScenario.ConnectionFailedException(
90
+ "Local association cancelled by user"
91
+ )
92
+ )
93
+ localAssociation.close()
94
+ }
86
95
  }
96
+ currentActivity?.startActivityForResult(intent, REQUEST_LOCAL_ASSOCIATION)
97
+ ?: throw NullPointerException(
98
+ "Could not find a current activity from which to launch a local association"
99
+ )
100
+ val client =
101
+ localAssociation
102
+ .start()
103
+ .get(ASSOCIATION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
104
+ sessionState = SessionState(client, localAssociation)
105
+ val sessionPropertiesMap: WritableMap = WritableNativeMap()
106
+ sessionPropertiesMap.putString(
107
+ "protocol_version",
108
+ when (localAssociation.session.sessionProperties.protocolVersion) {
109
+ ProtocolVersion.LEGACY -> "legacy"
110
+ ProtocolVersion.V1 -> "v1"
111
+ }
112
+ )
113
+ promise.resolve(sessionPropertiesMap)
114
+ } catch (e: ActivityNotFoundException) {
115
+ Log.e(name, "Found no installed wallet that supports the mobile wallet protocol", e)
116
+ cleanup()
117
+ promise.reject("ERROR_WALLET_NOT_FOUND", e)
118
+ } catch (e: TimeoutException) {
119
+ Log.e(name, "Timed out waiting for local association to be ready", e)
120
+ cleanup()
121
+ promise.reject("Timed out waiting for local association to be ready", e)
122
+ } catch (e: InterruptedException) {
123
+ Log.w(name, "Interrupted while waiting for local association to be ready", e)
124
+ cleanup()
125
+ promise.reject(e)
126
+ } catch (e: ExecutionException) {
127
+ Log.e(name, "Failed establishing local association with wallet", e.cause)
128
+ cleanup()
129
+ promise.reject(e)
130
+ } catch (e: Throwable) {
131
+ Log.e(name, "Failed to start session", e)
132
+ cleanup()
133
+ promise.reject(e)
87
134
  }
88
- currentActivity?.startActivityForResult(intent, REQUEST_LOCAL_ASSOCIATION)
89
- ?: throw NullPointerException("Could not find a current activity from which to launch a local association")
90
- val client =
91
- localAssociation.start().get(ASSOCIATION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
92
- sessionState = SessionState(client, localAssociation)
93
- val sessionPropertiesMap: WritableMap = WritableNativeMap()
94
- sessionPropertiesMap.putString("protocol_version",
95
- when (localAssociation.session.sessionProperties.protocolVersion) {
96
- ProtocolVersion.LEGACY -> "legacy"
97
- ProtocolVersion.V1 -> "v1"
98
- })
99
- promise.resolve(sessionPropertiesMap)
100
- } catch (e: ActivityNotFoundException) {
101
- Log.e(name, "Found no installed wallet that supports the mobile wallet protocol", e)
102
- cleanup()
103
- promise.reject("ERROR_WALLET_NOT_FOUND", e)
104
- } catch (e: TimeoutException) {
105
- Log.e(name, "Timed out waiting for local association to be ready", e)
106
- cleanup()
107
- promise.reject("Timed out waiting for local association to be ready", e)
108
- } catch (e: InterruptedException) {
109
- Log.w(name, "Interrupted while waiting for local association to be ready", e)
110
- cleanup()
111
- promise.reject(e)
112
- } catch (e: ExecutionException) {
113
- Log.e(name, "Failed establishing local association with wallet", e.cause)
114
- cleanup()
115
- promise.reject(e)
116
- } catch (e: Throwable) {
117
- Log.e(name, "Failed to start session", e)
118
- cleanup()
119
- promise.reject(e)
120
135
  }
121
136
  }
122
137
 
123
138
  @ReactMethod
124
- fun invoke(method: String, params: ReadableMap, promise: Promise) = sessionState?.let {
125
- Log.d(name, "invoke `$method` with params $params")
126
- try {
127
- val result = it.client.methodCall(
128
- method,
129
- convertMapToJson(params),
130
- CLIENT_TIMEOUT_MS
131
- ).get() as JSONObject
132
- promise.resolve(convertJsonToMap(result))
133
- } catch (e: ExecutionException) {
134
- val cause = e.cause
135
- if (cause is JsonRpc20Client.JsonRpc20RemoteException) {
136
- val userInfo = Arguments.createMap()
137
- userInfo.putInt("jsonRpcErrorCode", cause.code)
138
- promise.reject("JSON_RPC_ERROR", cause, userInfo)
139
- } else if (cause is TimeoutException) {
140
- promise.reject("Timed out waiting for response", e)
141
- } else {
142
- throw e
139
+ override fun invoke(method: String, params: ReadableMap?, promise: Promise): Unit =
140
+ sessionState?.let {
141
+ Log.d(name, "invoke `$method` with params $params")
142
+ try {
143
+ val result =
144
+ it.client
145
+ .methodCall(method, convertMapToJson(params), CLIENT_TIMEOUT_MS)
146
+ .get() as
147
+ JSONObject
148
+ promise.resolve(convertJsonToMap(result))
149
+ } catch (e: ExecutionException) {
150
+ val cause = e.cause
151
+ if (cause is JsonRpc20Client.JsonRpc20RemoteException) {
152
+ val userInfo = Arguments.createMap()
153
+ userInfo.putInt("jsonRpcErrorCode", cause.code)
154
+ promise.reject("JSON_RPC_ERROR", cause, userInfo)
155
+ } else if (cause is TimeoutException) {
156
+ promise.reject("Timed out waiting for response", e)
157
+ } else {
158
+ throw e
159
+ }
160
+ } catch (e: Throwable) {
161
+ Log.e(name, "Failed to invoke `$method` with params $params", e)
162
+ promise.reject(e)
163
+ }
143
164
  }
144
- } catch (e: Throwable) {
145
- Log.e(name, "Failed to invoke `$method` with params $params", e)
146
- promise.reject(e)
147
- }
148
- } ?: throw NullPointerException("Tried to invoke `$method` without an active session")
165
+ ?: throw NullPointerException(
166
+ "Tried to invoke `$method` without an active session"
167
+ )
149
168
 
150
169
  @ReactMethod
151
- fun endSession(promise: Promise) = sessionState?.let {
152
- launch {
153
- Log.d(name, "endSession")
154
- try {
155
- it.localAssociation.close()
156
- .get(ASSOCIATION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
157
- cleanup()
158
- promise.resolve(true)
159
- } catch (e: TimeoutException) {
160
- Log.e(name, "Timed out waiting for local association to close", e)
161
- cleanup()
162
- promise.reject("Failed to end session", e)
163
- } catch (e: Throwable) {
164
- Log.e(name, "Failed to end session", e)
165
- cleanup()
166
- promise.reject("Failed to end session", e)
170
+ override fun endSession(promise: Promise): Unit {
171
+ sessionState?.let {
172
+ launch {
173
+ Log.d(name, "endSession")
174
+ try {
175
+ it.localAssociation
176
+ .close()
177
+ .get(ASSOCIATION_TIMEOUT_MS.toLong(), TimeUnit.MILLISECONDS)
178
+ cleanup()
179
+ promise.resolve(true)
180
+ } catch (e: TimeoutException) {
181
+ Log.e(name, "Timed out waiting for local association to close", e)
182
+ cleanup()
183
+ promise.reject("Failed to end session", e)
184
+ } catch (e: Throwable) {
185
+ Log.e(name, "Failed to end session", e)
186
+ cleanup()
187
+ promise.reject("Failed to end session", e)
188
+ }
167
189
  }
168
190
  }
169
- } ?: throw NullPointerException("Tried to end a session without an active session")
191
+ ?: throw NullPointerException("Tried to end a session without an active session")
192
+ }
170
193
 
171
194
  private fun cleanup() {
172
195
  sessionState = null
@@ -1,16 +1,35 @@
1
- package com.solanamobile.mobilewalletadapter.reactnative
2
-
3
- import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.NativeModule
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.uimanager.ViewManager
7
-
8
- class SolanaMobileWalletAdapterPackage : ReactPackage {
9
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
- return listOf(SolanaMobileWalletAdapterModule(reactContext))
11
- }
12
-
13
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
- return emptyList()
15
- }
16
- }
1
+ package com.solanamobile.mobilewalletadapter.reactnative
2
+
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
9
+
10
+ class SolanaMobileWalletAdapterModulePackage : TurboReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == SolanaMobileWalletAdapterModule.NAME) {
13
+ SolanaMobileWalletAdapterModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ moduleInfos[SolanaMobileWalletAdapterModule.NAME] =
23
+ ReactModuleInfo(
24
+ SolanaMobileWalletAdapterModule.NAME,
25
+ SolanaMobileWalletAdapterModule.NAME,
26
+ false, // canOverrideExistingModule
27
+ false, // needsEagerInit
28
+ true, // hasConstants
29
+ false, // isCxxModule
30
+ true // isTurboModule
31
+ )
32
+ moduleInfos
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ package com.solanamobile.mobilewalletadapter.reactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+
5
+ abstract class SolanaMobileWalletAdapterSpec
6
+ internal constructor(context: ReactApplicationContext) :
7
+ NativeSolanaMobileWalletAdapterSpec(context) {}
@@ -0,0 +1,16 @@
1
+ package com.solanamobile.mobilewalletadapter.reactnative
2
+
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReadableMap
7
+
8
+ abstract class SolanaMobileWalletAdapterSpec
9
+ internal constructor(context: ReactApplicationContext) : ReactContextBaseJavaModule(context) {
10
+
11
+ abstract fun startSession(config: ReadableMap?, promise: Promise)
12
+
13
+ abstract fun invoke(method: String, params: ReadableMap?, promise: Promise)
14
+
15
+ abstract fun endSession(promise: Promise)
16
+ }
@@ -950,10 +950,14 @@ function transactRemote(callback, config) {
950
950
  try {
951
951
  resolve(yield callback(new Proxy(wallet, {
952
952
  get(target, p) {
953
- if (p === 'terminateSession') {
954
- disposeSocket();
955
- socket.close();
956
- return;
953
+ if (p == 'terminateSession') {
954
+ return function () {
955
+ return __awaiter(this, void 0, void 0, function* () {
956
+ disposeSocket();
957
+ socket.close();
958
+ return;
959
+ });
960
+ };
957
961
  }
958
962
  else
959
963
  return target[p];
package/lib/cjs/index.js CHANGED
@@ -950,10 +950,14 @@ function transactRemote(callback, config) {
950
950
  try {
951
951
  resolve(yield callback(new Proxy(wallet, {
952
952
  get(target, p) {
953
- if (p === 'terminateSession') {
954
- disposeSocket();
955
- socket.close();
956
- return;
953
+ if (p == 'terminateSession') {
954
+ return function () {
955
+ return __awaiter(this, void 0, void 0, function* () {
956
+ disposeSocket();
957
+ socket.close();
958
+ return;
959
+ });
960
+ };
957
961
  }
958
962
  else
959
963
  return target[p];
@@ -72,6 +72,8 @@ function __awaiter(thisArg, _arguments, P, generator) {
72
72
  });
73
73
  }
74
74
 
75
+ var NativeSolanaMobileWalletAdapter = reactNative.TurboModuleRegistry.getEnforcing('SolanaMobileWalletAdapter');
76
+
75
77
  function createSIWSMessage(payload) {
76
78
  return walletStandardUtil.createSignInMessageText(payload);
77
79
  }
@@ -243,8 +245,8 @@ const LINKING_ERROR = `The package 'solana-mobile-wallet-adapter-protocol' doesn
243
245
  ' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` as an explicit dependency, and\n' +
244
246
  ' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n' +
245
247
  '- You are not using Expo managed workflow\n';
246
- const SolanaMobileWalletAdapter = reactNative.Platform.OS === 'android' && reactNative.NativeModules.SolanaMobileWalletAdapter
247
- ? reactNative.NativeModules.SolanaMobileWalletAdapter
248
+ const SolanaMobileWalletAdapter = reactNative.Platform.OS === 'android' && NativeSolanaMobileWalletAdapter
249
+ ? NativeSolanaMobileWalletAdapter
248
250
  : new Proxy({}, {
249
251
  get() {
250
252
  throw new Error(reactNative.Platform.OS !== 'android'
@@ -946,10 +946,14 @@ function transactRemote(callback, config) {
946
946
  try {
947
947
  resolve(yield callback(new Proxy(wallet, {
948
948
  get(target, p) {
949
- if (p === 'terminateSession') {
950
- disposeSocket();
951
- socket.close();
952
- return;
949
+ if (p == 'terminateSession') {
950
+ return function () {
951
+ return __awaiter(this, void 0, void 0, function* () {
952
+ disposeSocket();
953
+ socket.close();
954
+ return;
955
+ });
956
+ };
953
957
  }
954
958
  else
955
959
  return target[p];
package/lib/esm/index.js CHANGED
@@ -946,10 +946,14 @@ function transactRemote(callback, config) {
946
946
  try {
947
947
  resolve(yield callback(new Proxy(wallet, {
948
948
  get(target, p) {
949
- if (p === 'terminateSession') {
950
- disposeSocket();
951
- socket.close();
952
- return;
949
+ if (p == 'terminateSession') {
950
+ return function () {
951
+ return __awaiter(this, void 0, void 0, function* () {
952
+ disposeSocket();
953
+ socket.close();
954
+ return;
955
+ });
956
+ };
953
957
  }
954
958
  else
955
959
  return target[p];
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/types.ts","../../src/base64Utils.ts","../../src/createSIWSMessage.ts","../../src/createMobileWalletProxy.ts","../../src/createSequenceNumberVector.ts","../../src/parseHelloRsp.ts","../../src/encryptedMessage.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/jsonRpcMessage.ts","../../src/parseSessionProps.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/reflectorId.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/transact.ts","../../src/__forks__/react-native/transact.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/errors.ts","../../src/createHelloReq.ts","../../src/types.ts","../../src/base64Utils.ts","../../src/createSIWSMessage.ts","../../src/createMobileWalletProxy.ts","../../src/createSequenceNumberVector.ts","../../src/parseHelloRsp.ts","../../src/encryptedMessage.ts","../../src/generateAssociationKeypair.ts","../../src/generateECDHKeypair.ts","../../src/jsonRpcMessage.ts","../../src/parseSessionProps.ts","../../src/associationPort.ts","../../src/arrayBufferToBase64String.ts","../../src/getStringWithURLUnsafeBase64CharactersReplaced.ts","../../src/reflectorId.ts","../../src/getAssociateAndroidIntentURL.ts","../../src/startSession.ts","../../src/transact.ts","../../src/codegenSpec/NativeSolanaMobileWalletAdapter.ts","../../src/__forks__/react-native/transact.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solana-mobile/mobile-wallet-adapter-protocol",
3
3
  "description": "An implementation of the Solana Mobile Mobile Wallet Adapter protocol. Use this to open a session with a mobile wallet app, and to issue API calls to it.",
4
- "version": "2.1.4",
4
+ "version": "2.2.0-new-arch-beta",
5
5
  "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
6
  "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
7
  "license": "Apache-2.0",
@@ -54,5 +54,13 @@
54
54
  "peerDependencies": {
55
55
  "@solana/web3.js": "^1.58.0",
56
56
  "react-native": ">0.69"
57
+ },
58
+ "codegenConfig": {
59
+ "name": "SolanaMobileWalletAdapter",
60
+ "type": "all",
61
+ "jsSrcsDir": "./src/codegenSpec",
62
+ "android": {
63
+ "javaPackageName": "com.solanamobile.mobilewalletadapter.reactnative"
64
+ }
57
65
  }
58
66
  }
@@ -0,0 +1 @@
1
+ export { encode } from 'js-base64';
@@ -0,0 +1,91 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ import NativeSolanaMobileWalletAdapter from '../../codegenSpec/NativeSolanaMobileWalletAdapter.js';
4
+ import createMobileWalletProxy from '../../createMobileWalletProxy.js';
5
+ import { SolanaMobileWalletAdapterError, SolanaMobileWalletAdapterProtocolError } from '../../errors.js';
6
+ import { MobileWallet, SessionProperties, WalletAssociationConfig } from '../../types.js';
7
+
8
+ type ReactNativeError = Error & { code?: string; userInfo?: Record<string, unknown> };
9
+
10
+ const LINKING_ERROR =
11
+ `The package 'solana-mobile-wallet-adapter-protocol' doesn't seem to be linked. Make sure: \n\n` +
12
+ '- You rebuilt the app after installing the package\n' +
13
+ '- If you are using Lerna workspaces\n' +
14
+ ' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` as an explicit dependency, and\n' +
15
+ ' - You have added `@solana-mobile/mobile-wallet-adapter-protocol` to the `nohoist` section of your package.json\n' +
16
+ '- You are not using Expo managed workflow\n';
17
+
18
+ const SolanaMobileWalletAdapter =
19
+ Platform.OS === 'android' && NativeSolanaMobileWalletAdapter
20
+ ? NativeSolanaMobileWalletAdapter
21
+ : (new Proxy(
22
+ {},
23
+ {
24
+ get() {
25
+ throw new Error(
26
+ Platform.OS !== 'android'
27
+ ? 'The package `solana-mobile-wallet-adapter-protocol` is only compatible with React Native Android'
28
+ : LINKING_ERROR,
29
+ );
30
+ },
31
+ },
32
+ ) as typeof NativeSolanaMobileWalletAdapter);
33
+
34
+ function getErrorMessage(e: ReactNativeError): string {
35
+ switch (e.code) {
36
+ case 'ERROR_WALLET_NOT_FOUND':
37
+ return 'Found no installed wallet that supports the mobile wallet protocol.';
38
+ default:
39
+ return e.message;
40
+ }
41
+ }
42
+
43
+ function handleError(e: any): never {
44
+ if (e instanceof Error) {
45
+ const reactNativeError: ReactNativeError = e;
46
+ switch (reactNativeError.code) {
47
+ case undefined:
48
+ throw e;
49
+ case 'JSON_RPC_ERROR': {
50
+ const details = reactNativeError.userInfo as Readonly<{ jsonRpcErrorCode: number }>;
51
+ throw new SolanaMobileWalletAdapterProtocolError(
52
+ 0 /* jsonRpcMessageId */,
53
+ details.jsonRpcErrorCode,
54
+ e.message,
55
+ );
56
+ }
57
+ default:
58
+ throw new SolanaMobileWalletAdapterError<any>(
59
+ reactNativeError.code,
60
+ getErrorMessage(reactNativeError),
61
+ reactNativeError.userInfo,
62
+ );
63
+ }
64
+ }
65
+ throw e;
66
+ }
67
+
68
+ export async function transact<TReturn>(
69
+ callback: (wallet: MobileWallet) => TReturn,
70
+ config?: WalletAssociationConfig,
71
+ ): Promise<TReturn> {
72
+ let didSuccessfullyConnect = false;
73
+ try {
74
+ const sessionProperties: SessionProperties = await SolanaMobileWalletAdapter.startSession(config);
75
+ didSuccessfullyConnect = true;
76
+ const wallet = createMobileWalletProxy(sessionProperties.protocol_version, async (method, params) => {
77
+ try {
78
+ return SolanaMobileWalletAdapter.invoke(method, params);
79
+ } catch (e) {
80
+ return handleError(e);
81
+ }
82
+ });
83
+ return await callback(wallet);
84
+ } catch (e) {
85
+ return handleError(e);
86
+ } finally {
87
+ if (didSuccessfullyConnect) {
88
+ await SolanaMobileWalletAdapter.endSession();
89
+ }
90
+ }
91
+ }