@solana-mobile/mobile-wallet-adapter-protocol 2.1.4 → 2.1.5

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.
@@ -1,146 +1,158 @@
1
- buildscript {
2
- // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
- def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SolanaMobileWalletAdapterModule_kotlinVersion']
4
-
5
- repositories {
6
- google()
7
- mavenCentral()
8
- }
9
-
10
- dependencies {
11
- classpath 'com.android.tools.build:gradle:8.7.1'
12
- // noinspection DifferentKotlinGradleVersion
13
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
- }
15
- }
16
-
17
- def isNewArchitectureEnabled() {
18
- return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
- }
20
-
21
- apply plugin: 'com.android.library'
22
- apply plugin: 'kotlin-android'
23
-
24
- if (isNewArchitectureEnabled()) {
25
- apply plugin: 'com.facebook.react'
26
- }
27
-
28
- def getExtOrDefault(name) {
29
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SolanaMobileWalletAdapterModule_' + name]
30
- }
31
-
32
- def getExtOrIntegerDefault(name) {
33
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SolanaMobileWalletAdapterModule_' + name]).toInteger()
34
- }
35
-
36
- android {
37
- compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
38
-
39
- defaultConfig {
40
- minSdkVersion getExtOrIntegerDefault('minSdkVersion')
41
- targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
42
- buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
43
- }
44
- buildTypes {
45
- release {
46
- minifyEnabled false
47
- }
48
- }
49
-
50
- lintOptions {
51
- disable 'GradleCompatible'
52
- }
53
-
54
- compileOptions {
55
- sourceCompatibility JavaVersion.VERSION_1_8
56
- targetCompatibility JavaVersion.VERSION_1_8
57
- }
58
- }
59
-
60
- repositories {
61
- mavenCentral()
62
- google()
63
-
64
- def found = false
65
- def defaultDir = null
66
- def androidSourcesName = 'React Native sources'
67
-
68
- if (rootProject.ext.has('reactNativeAndroidRoot')) {
69
- defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
70
- } else {
71
- defaultDir = new File(
72
- projectDir,
73
- '/../../../node_modules/react-native/android'
74
- )
75
- }
76
-
77
- if (defaultDir.exists()) {
78
- maven {
79
- url defaultDir.toString()
80
- name androidSourcesName
81
- }
82
-
83
- logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
84
- found = true
85
- } else {
86
- def parentDir = rootProject.projectDir
87
-
88
- 1.upto(5, {
89
- if (found) return true
90
- parentDir = parentDir.parentFile
91
-
92
- def androidSourcesDir = new File(
93
- parentDir,
94
- 'node_modules/react-native'
95
- )
96
-
97
- def androidPrebuiltBinaryDir = new File(
98
- parentDir,
99
- 'node_modules/react-native/android'
100
- )
101
-
102
- if (androidPrebuiltBinaryDir.exists()) {
103
- maven {
104
- url androidPrebuiltBinaryDir.toString()
105
- name androidSourcesName
106
- }
107
-
108
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
109
- found = true
110
- } else if (androidSourcesDir.exists()) {
111
- maven {
112
- url androidSourcesDir.toString()
113
- name androidSourcesName
114
- }
115
-
116
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
117
- found = true
118
- }
119
- })
120
- }
121
-
122
- if (!found) {
123
- throw new GradleException(
124
- "${project.name}: unable to locate React Native android sources. " +
125
- "Ensure you have you installed React Native as a dependency in your project and try again."
126
- )
127
- }
128
- }
129
-
130
- def kotlin_version = getExtOrDefault('kotlinVersion')
131
-
132
- dependencies {
133
- //noinspection GradleDynamicVersion
134
- implementation "com.facebook.react:react-native:+" // From node_modules
135
- implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.5"
136
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
137
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0"
138
- }
139
-
140
- if (isNewArchitectureEnabled()) {
141
- react {
142
- jsRootDir = file("../src/")
143
- libraryName = "SolanaMobileWalletAdapterModule"
144
- codegenJavaPackageName = "com.solanamobile.mobilewalletadapter.reactnative"
145
- }
146
- }
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['SolanaMobileWalletAdapterModule_kotlinVersion']
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath 'com.android.tools.build:gradle:8.8.0'
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+ apply plugin: 'kotlin-android'
23
+
24
+ if (isNewArchitectureEnabled()) {
25
+ apply plugin: 'com.facebook.react'
26
+ }
27
+
28
+ def getExtOrDefault(name) {
29
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SolanaMobileWalletAdapterModule_' + name]
30
+ }
31
+
32
+ def getExtOrIntegerDefault(name) {
33
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SolanaMobileWalletAdapterModule_' + name]).toInteger()
34
+ }
35
+
36
+ android {
37
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
38
+
39
+ defaultConfig {
40
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion')
41
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
42
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
43
+ }
44
+ buildTypes {
45
+ release {
46
+ minifyEnabled false
47
+ }
48
+ }
49
+
50
+ lintOptions {
51
+ disable 'GradleCompatible'
52
+ }
53
+
54
+ compileOptions {
55
+ sourceCompatibility JavaVersion.VERSION_1_8
56
+ targetCompatibility JavaVersion.VERSION_1_8
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
+ }
70
+ }
71
+
72
+ repositories {
73
+ mavenCentral()
74
+ google()
75
+
76
+ def found = false
77
+ def defaultDir = null
78
+ def androidSourcesName = 'React Native sources'
79
+
80
+ if (rootProject.ext.has('reactNativeAndroidRoot')) {
81
+ defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
82
+ } else {
83
+ defaultDir = new File(
84
+ projectDir,
85
+ '/../../../node_modules/react-native/android'
86
+ )
87
+ }
88
+
89
+ if (defaultDir.exists()) {
90
+ maven {
91
+ url defaultDir.toString()
92
+ name androidSourcesName
93
+ }
94
+
95
+ logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
96
+ found = true
97
+ } else {
98
+ def parentDir = rootProject.projectDir
99
+
100
+ 1.upto(5, {
101
+ if (found) return true
102
+ parentDir = parentDir.parentFile
103
+
104
+ def androidSourcesDir = new File(
105
+ parentDir,
106
+ 'node_modules/react-native'
107
+ )
108
+
109
+ def androidPrebuiltBinaryDir = new File(
110
+ parentDir,
111
+ 'node_modules/react-native/android'
112
+ )
113
+
114
+ if (androidPrebuiltBinaryDir.exists()) {
115
+ maven {
116
+ url androidPrebuiltBinaryDir.toString()
117
+ name androidSourcesName
118
+ }
119
+
120
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
121
+ found = true
122
+ } else if (androidSourcesDir.exists()) {
123
+ maven {
124
+ url androidSourcesDir.toString()
125
+ name androidSourcesName
126
+ }
127
+
128
+ logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
129
+ found = true
130
+ }
131
+ })
132
+ }
133
+
134
+ if (!found) {
135
+ throw new GradleException(
136
+ "${project.name}: unable to locate React Native android sources. " +
137
+ "Ensure you have you installed React Native as a dependency in your project and try again."
138
+ )
139
+ }
140
+ }
141
+
142
+ def kotlin_version = getExtOrDefault('kotlinVersion')
143
+
144
+ dependencies {
145
+ //noinspection GradleDynamicVersion
146
+ implementation "com.facebook.react:react-native:+" // From node_modules
147
+ implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.5"
148
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
149
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0"
150
+ }
151
+
152
+ if (isNewArchitectureEnabled()) {
153
+ react {
154
+ jsRootDir = file("../src/")
155
+ libraryName = "SolanaMobileWalletAdapterModule"
156
+ codegenJavaPackageName = "com.solanamobile.mobilewalletadapter.reactnative"
157
+ }
158
+ }
@@ -1,5 +1,5 @@
1
- distributionBase=GRADLE_USER_HOME
2
- distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4
- zipStoreBase=GRADLE_USER_HOME
5
- zipStorePath=wrapper/dists
1
+ distributionBase=GRADLE_USER_HOME
2
+ distributionPath=wrapper/dists
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
4
+ zipStoreBase=GRADLE_USER_HOME
5
+ zipStorePath=wrapper/dists
@@ -1,5 +1,5 @@
1
- SolanaMobileWalletAdapterModule_kotlinVersion=1.9.0
2
- SolanaMobileWalletAdapterModule_minSdkVersion=21
3
- SolanaMobileWalletAdapterModule_targetSdkVersion=33
4
- SolanaMobileWalletAdapterModule_compileSdkVersion=33
5
- SolanaMobileWalletAdapterModule_ndkversion=21.4.7075529
1
+ SolanaMobileWalletAdapterModule_kotlinVersion=1.9.0
2
+ SolanaMobileWalletAdapterModule_minSdkVersion=21
3
+ SolanaMobileWalletAdapterModule_targetSdkVersion=33
4
+ SolanaMobileWalletAdapterModule_compileSdkVersion=33
5
+ SolanaMobileWalletAdapterModule_ndkversion=21.4.7075529
@@ -29,16 +29,18 @@ object JSONSerializationUtils {
29
29
  }
30
30
 
31
31
  @Throws(JSONException::class)
32
- private fun convertArrayToJson(readableArray: ReadableArray): JSONArray {
32
+ private fun convertArrayToJson(readableArray: ReadableArray?): JSONArray {
33
33
  val array = JSONArray()
34
- for (i in 0 until readableArray.size()) {
35
- when (readableArray.getType(i)) {
36
- ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
37
- ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
38
- ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
39
- ReadableType.Null -> {}
40
- ReadableType.Number -> array.put(readableArray.getDouble(i))
41
- ReadableType.String -> array.put(readableArray.getString(i))
34
+ readableArray?.let {
35
+ for (i in 0 until readableArray.size()) {
36
+ when (readableArray.getType(i)) {
37
+ ReadableType.Array -> array.put(convertArrayToJson(readableArray.getArray(i)))
38
+ ReadableType.Boolean -> array.put(readableArray.getBoolean(i))
39
+ ReadableType.Map -> array.put(convertMapToJson(readableArray.getMap(i)))
40
+ ReadableType.Null -> {}
41
+ ReadableType.Number -> array.put(readableArray.getDouble(i))
42
+ ReadableType.String -> array.put(readableArray.getString(i))
43
+ }
42
44
  }
43
45
  }
44
46
  return array
@@ -1,178 +1,201 @@
1
- package com.solanamobile.mobilewalletadapter.reactnative
2
-
3
- import android.app.Activity
4
- import android.content.ActivityNotFoundException
5
- import android.content.Intent
6
- import android.net.Uri
7
- import android.util.Log
8
- import com.facebook.react.bridge.*
9
- import com.solana.mobilewalletadapter.clientlib.protocol.JsonRpc20Client
10
- import com.solana.mobilewalletadapter.clientlib.protocol.MobileWalletAdapterClient
11
- import com.solana.mobilewalletadapter.clientlib.scenario.LocalAssociationIntentCreator
12
- import com.solana.mobilewalletadapter.clientlib.scenario.LocalAssociationScenario
13
- import com.solana.mobilewalletadapter.common.protocol.SessionProperties.ProtocolVersion
14
- import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertJsonToMap
15
- import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertMapToJson
16
- import kotlinx.coroutines.*
17
- import kotlinx.coroutines.sync.Mutex
18
- import org.json.JSONObject
19
- import java.util.concurrent.ExecutionException
20
- import java.util.concurrent.TimeUnit
21
- import java.util.concurrent.TimeoutException
22
-
23
- class SolanaMobileWalletAdapterModule(reactContext: ReactApplicationContext) :
24
- ReactContextBaseJavaModule(reactContext), CoroutineScope {
25
-
26
- data class SessionState(
27
- val client: MobileWalletAdapterClient,
28
- val localAssociation: LocalAssociationScenario,
29
- )
30
-
31
- override val coroutineContext =
32
- Dispatchers.IO + CoroutineName("SolanaMobileWalletAdapterModuleScope") + SupervisorJob()
33
-
34
- companion object {
35
- private const val ASSOCIATION_TIMEOUT_MS = 10000
36
- private const val CLIENT_TIMEOUT_MS = 90000
37
- private const val REQUEST_LOCAL_ASSOCIATION = 0
38
-
39
- // Used to ensure that you can't start more than one session at a time.
40
- private val mutex: Mutex = Mutex()
41
- private var sessionState: SessionState? = null
42
- private var associationResultCallback: ((Int) -> Unit)? = null
43
- }
44
-
45
- 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)
55
- }
56
- }
57
-
58
- init {
59
- reactContext.addActivityEventListener(mActivityEventListener)
60
- }
61
-
62
- override fun getName(): String {
63
- return "SolanaMobileWalletAdapter"
64
- }
65
-
66
- @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()
86
- }
87
- }
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
- }
121
- }
122
-
123
- @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
143
- }
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")
149
-
150
- @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)
167
- }
168
- }
169
- } ?: throw NullPointerException("Tried to end a session without an active session")
170
-
171
- private fun cleanup() {
172
- sessionState = null
173
- associationResultCallback = null
174
- if (mutex.isLocked) {
175
- mutex.unlock()
176
- }
177
- }
178
- }
1
+ package com.solanamobile.mobilewalletadapter.reactnative
2
+
3
+ import android.app.Activity
4
+ import android.content.ActivityNotFoundException
5
+ import android.content.Intent
6
+ import android.net.Uri
7
+ import android.util.Log
8
+ import com.facebook.react.bridge.*
9
+ import com.solana.mobilewalletadapter.clientlib.protocol.JsonRpc20Client
10
+ import com.solana.mobilewalletadapter.clientlib.protocol.MobileWalletAdapterClient
11
+ import com.solana.mobilewalletadapter.clientlib.scenario.LocalAssociationIntentCreator
12
+ import com.solana.mobilewalletadapter.clientlib.scenario.LocalAssociationScenario
13
+ import com.solana.mobilewalletadapter.common.protocol.SessionProperties.ProtocolVersion
14
+ import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertJsonToMap
15
+ import com.solanamobile.mobilewalletadapter.reactnative.JSONSerializationUtils.convertMapToJson
16
+ import java.util.concurrent.ExecutionException
17
+ import java.util.concurrent.TimeUnit
18
+ import java.util.concurrent.TimeoutException
19
+ import kotlinx.coroutines.*
20
+ import kotlinx.coroutines.sync.Mutex
21
+ import org.json.JSONObject
22
+
23
+ class SolanaMobileWalletAdapterModule(reactContext: ReactApplicationContext) :
24
+ SolanaMobileWalletAdapterSpec(reactContext), CoroutineScope {
25
+
26
+ data class SessionState(
27
+ val client: MobileWalletAdapterClient,
28
+ val localAssociation: LocalAssociationScenario,
29
+ )
30
+
31
+ override val coroutineContext =
32
+ Dispatchers.IO + CoroutineName("SolanaMobileWalletAdapterModuleScope") + SupervisorJob()
33
+
34
+ companion object {
35
+ const val NAME = "SolanaMobileWalletAdapter"
36
+ private const val ASSOCIATION_TIMEOUT_MS = 10000
37
+ private const val CLIENT_TIMEOUT_MS = 90000
38
+ private const val REQUEST_LOCAL_ASSOCIATION = 0
39
+
40
+ // Used to ensure that you can't start more than one session at a time.
41
+ private val mutex: Mutex = Mutex()
42
+ private var sessionState: SessionState? = null
43
+ private var associationResultCallback: ((Int) -> Unit)? = null
44
+ }
45
+
46
+ private val mActivityEventListener: ActivityEventListener =
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
+ }
57
+ }
58
+
59
+ init {
60
+ reactContext.addActivityEventListener(mActivityEventListener)
61
+ }
62
+
63
+ override fun getName(): String {
64
+ return NAME
65
+ }
66
+
67
+ @ReactMethod
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
+ }
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)
134
+ }
135
+ }
136
+ }
137
+
138
+ @ReactMethod
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
+ }
164
+ }
165
+ ?: throw NullPointerException(
166
+ "Tried to invoke `$method` without an active session"
167
+ )
168
+
169
+ @ReactMethod
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
+ }
189
+ }
190
+ }
191
+ ?: throw NullPointerException("Tried to end a session without an active session")
192
+ }
193
+
194
+ private fun cleanup() {
195
+ sessionState = null
196
+ associationResultCallback = null
197
+ if (mutex.isLocked) {
198
+ mutex.unlock()
199
+ }
200
+ }
201
+ }
@@ -1,16 +1,35 @@
1
1
  package com.solanamobile.mobilewalletadapter.reactnative
2
2
 
3
- import com.facebook.react.ReactPackage
3
+ import com.facebook.react.TurboReactPackage
4
4
  import com.facebook.react.bridge.NativeModule
5
5
  import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.uimanager.ViewManager
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
7
9
 
8
- class SolanaMobileWalletAdapterPackage : ReactPackage {
9
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
- return listOf(SolanaMobileWalletAdapterModule(reactContext))
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
+ }
11
17
  }
12
18
 
13
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
- return emptyList()
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
+ }
15
34
  }
16
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,58 +1,70 @@
1
- {
2
- "name": "@solana-mobile/mobile-wallet-adapter-protocol",
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",
5
- "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
- "repository": "https://github.com/solana-mobile/mobile-wallet-adapter",
7
- "license": "Apache-2.0",
8
- "type": "module",
9
- "sideEffects": false,
10
- "main": "lib/cjs/index.js",
11
- "react-native": "lib/cjs/index.native.js",
12
- "module": "lib/esm/index.js",
13
- "types": "lib/types/index.d.ts",
14
- "browser": {
15
- "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
16
- "./lib/esm/index.js": "./lib/esm/index.browser.js"
17
- },
18
- "exports": {
19
- "./package.json": "./package.json",
20
- ".": {
21
- "import": "./lib/esm/index.js",
22
- "require": "./lib/cjs/index.js"
23
- }
24
- },
25
- "files": [
26
- "android",
27
- "!android/build",
28
- "lib",
29
- "LICENSE"
30
- ],
31
- "publishConfig": {
32
- "access": "public"
33
- },
34
- "scripts": {
35
- "clean": "shx rm -rf lib/*",
36
- "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
37
- "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
38
- "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
39
- "prepublishOnly": "agadoo"
40
- },
41
- "dependencies": {
42
- "@solana/wallet-standard": "^1.1.2",
43
- "@solana/wallet-standard-util": "^1.1.1",
44
- "@wallet-standard/core": "^1.0.3",
45
- "js-base64": "^3.7.5"
46
- },
47
- "devDependencies": {
48
- "@solana/web3.js": "^1.91.7",
49
- "@types/react-native": "^0.69.3",
50
- "agadoo": "^3.0.0",
51
- "cross-env": "^7.0.3",
52
- "shx": "^0.3.4"
53
- },
54
- "peerDependencies": {
55
- "@solana/web3.js": "^1.58.0",
56
- "react-native": ">0.69"
57
- }
58
- }
1
+ {
2
+ "name": "@solana-mobile/mobile-wallet-adapter-protocol",
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.5",
5
+ "author": "Steven Luscher <steven.luscher@solanamobile.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/solana-mobile/mobile-wallet-adapter.git"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "type": "module",
12
+ "sideEffects": false,
13
+ "main": "lib/cjs/index.js",
14
+ "react-native": "lib/cjs/index.native.js",
15
+ "module": "lib/esm/index.js",
16
+ "types": "lib/types/index.d.ts",
17
+ "browser": {
18
+ "./lib/cjs/index.js": "./lib/cjs/index.browser.js",
19
+ "./lib/esm/index.js": "./lib/esm/index.browser.js"
20
+ },
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "import": "./lib/esm/index.js",
25
+ "require": "./lib/cjs/index.js",
26
+ "types": "./lib/types/index.d.ts"
27
+ }
28
+ },
29
+ "files": [
30
+ "android",
31
+ "!android/build",
32
+ "lib",
33
+ "LICENSE"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "clean": "shx rm -rf lib/*",
40
+ "build": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts",
41
+ "build:watch": "yarn clean && rollup --config ../../rollup.config.ts --configPlugin rollup-plugin-ts --watch",
42
+ "postbuild": "cross-env echo {\\\"type\\\":\\\"commonjs\\\"} | npx json > lib/cjs/package.json && echo {\\\"type\\\":\\\"module\\\"} | npx json > lib/esm/package.json",
43
+ "prepublishOnly": "agadoo"
44
+ },
45
+ "dependencies": {
46
+ "@solana/wallet-standard": "^1.1.2",
47
+ "@solana/wallet-standard-util": "^1.1.1",
48
+ "@wallet-standard/core": "^1.0.3",
49
+ "js-base64": "^3.7.5"
50
+ },
51
+ "devDependencies": {
52
+ "@solana/web3.js": "^1.91.7",
53
+ "@types/react-native": "^0.69.3",
54
+ "agadoo": "^3.0.0",
55
+ "cross-env": "^7.0.3",
56
+ "shx": "^0.3.4"
57
+ },
58
+ "peerDependencies": {
59
+ "@solana/web3.js": "^1.58.0",
60
+ "react-native": ">0.69"
61
+ },
62
+ "codegenConfig": {
63
+ "name": "SolanaMobileWalletAdapter",
64
+ "type": "all",
65
+ "jsSrcsDir": "./src/codegenSpec",
66
+ "android": {
67
+ "javaPackageName": "com.solanamobile.mobilewalletadapter.reactnative"
68
+ }
69
+ }
70
+ }