@solana-mobile/mobile-wallet-adapter-protocol 2.1.3 → 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.
- package/android/build.gradle +15 -3
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterModule.kt +133 -110
- package/android/src/main/java/com/solanamobile/mobilewalletadapter/reactnative/SolanaMobileWalletAdapterPackage.kt +35 -16
- package/android/src/newarch/SolanaMobileWalletAdapter.kt +7 -0
- package/android/src/oldarch/SolanaMobileWalletAdapter.kt +16 -0
- package/lib/cjs/index.browser.js +266 -5
- package/lib/cjs/index.js +266 -5
- package/lib/cjs/index.native.js +5 -2
- package/lib/esm/index.browser.js +266 -6
- package/lib/esm/index.js +266 -6
- package/lib/types/index.browser.d.ts +17 -1
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.ts +17 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts +17 -1
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +10 -2
- package/src/__forks__/react-native/transact.ts +14 -15
- package/src/codegenSpec/NativeSolanaMobileWalletAdapter.ts +13 -0
- package/src/errors.ts +4 -0
- package/src/getAssociateAndroidIntentURL.ts +21 -0
- package/src/reflectorId.ts +31 -0
- package/src/startSession.ts +130 -94
- package/src/transact.ts +237 -4
- package/src/types.ts +11 -0
package/android/build.gradle
CHANGED
|
@@ -8,7 +8,7 @@ buildscript {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
dependencies {
|
|
11
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
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 {
|
|
@@ -132,9 +144,9 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
|
132
144
|
dependencies {
|
|
133
145
|
//noinspection GradleDynamicVersion
|
|
134
146
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
135
|
-
implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.
|
|
147
|
+
implementation "com.solanamobile:mobile-wallet-adapter-clientlib:2.0.5"
|
|
136
148
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
137
|
-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.
|
|
149
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0"
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
if (isNewArchitectureEnabled()) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
|
4
4
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
5
|
zipStorePath=wrapper/dists
|
|
@@ -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
|
-
|
|
24
|
+
SolanaMobileWalletAdapterSpec(reactContext), CoroutineScope {
|
|
25
25
|
|
|
26
26
|
data class SessionState(
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
val client: MobileWalletAdapterClient,
|
|
28
|
+
val localAssociation: LocalAssociationScenario,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
override val coroutineContext =
|
|
32
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
64
|
+
return NAME
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
@ReactMethod
|
|
67
|
-
fun startSession(config: ReadableMap?, promise: Promise)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
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.
|
|
4
|
-
import com.facebook.react.bridge.NativeModule
|
|
5
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
-
import com.facebook.react.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|