@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
@@ -1,157 +1,157 @@
1
- package com.solanamobile.mobilewalletadapterwalletlib.reactnative
2
-
3
- import android.util.Base64
4
- import com.solana.mobilewalletadapter.common.signin.SignInWithSolana
5
- import com.solana.mobilewalletadapter.walletlib.scenario.SignInResult
6
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.AuthorizeDappResponse
7
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.DeauthorizeDappResponse
8
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterFailureResponse
9
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterRequest
10
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterResponse
11
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.ReauthorizeDappResponse
12
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.SignedAndSentTransactions
13
- import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.SignedPayloads
14
- import kotlinx.serialization.DeserializationStrategy
15
- import kotlinx.serialization.KSerializer
16
- import kotlinx.serialization.builtins.ByteArraySerializer
17
- import kotlinx.serialization.builtins.ListSerializer
18
- import kotlinx.serialization.builtins.MapSerializer
19
- import kotlinx.serialization.builtins.serializer
20
- import kotlinx.serialization.descriptors.SerialDescriptor
21
- import kotlinx.serialization.encoding.Decoder
22
- import kotlinx.serialization.encoding.Encoder
23
- import kotlinx.serialization.json.Json
24
- import kotlinx.serialization.json.JsonContentPolymorphicSerializer
25
- import kotlinx.serialization.json.JsonElement
26
- import kotlinx.serialization.json.JsonNull
27
- import kotlinx.serialization.json.JsonObject
28
- import kotlinx.serialization.json.JsonTransformingSerializer
29
- import kotlinx.serialization.json.buildJsonObject
30
- import kotlinx.serialization.json.jsonObject
31
- import kotlinx.serialization.json.jsonPrimitive
32
- import kotlinx.serialization.json.put
33
- import org.json.JSONObject
34
-
35
- internal open class TypeTransformingSerializer<T: Any>(serializer: KSerializer<T>) : JsonTransformingSerializer<T>(serializer) {
36
- override fun transformSerialize(element: JsonElement): JsonElement =
37
- if ((element as? JsonObject)?.containsKey("type") == true)
38
- JsonObject(element.toMutableMap().apply {
39
- this["__type"] = this.remove("type")!!
40
- })
41
- else element
42
-
43
- override fun transformDeserialize(element: JsonElement): JsonElement =
44
- if ((element as? JsonObject)?.containsKey("__type") == true)
45
- JsonObject(element.toMutableMap().apply {
46
- this["type"] = this.remove("__type")!!
47
- })
48
- else element
49
- }
50
-
51
- internal object AppIdentityTransformingSerializer : JsonTransformingSerializer<MobileWalletAdapterRequest>(MobileWalletAdapterRequest.serializer()) {
52
- override fun transformSerialize(element: JsonElement): JsonElement =
53
- if ((element as? JsonObject)?.containsKey("identityUri") == true)
54
- JsonObject(element.toMutableMap().apply {
55
- this["appIdentity"] = buildJsonObject {
56
- put("identityName", this@apply.remove("identityName") ?: JsonNull)
57
- put("identityUri", this@apply.remove("identityUri") ?: JsonNull)
58
- put("iconRelativeUri", this@apply.remove("iconRelativeUri") ?: JsonNull)
59
- }
60
- })
61
- else element
62
-
63
- override fun transformDeserialize(element: JsonElement): JsonElement =
64
- if ((element as? JsonObject)?.containsKey("appIdentity") == true)
65
- JsonObject(element.toMutableMap().apply {
66
- val appIdentity = this.remove("appIdentity")!! as JsonObject
67
- put("identityName", appIdentity["identityName"] ?: JsonNull)
68
- put("identityUri", appIdentity["identityUri"] ?: JsonNull)
69
- put("iconRelativeUri", appIdentity["iconRelativeUri"] ?: JsonNull)
70
- })
71
- else element
72
- }
73
-
74
- internal object FailReasonTransformingSerializer
75
- : JsonTransformingSerializer<MobileWalletAdapterFailureResponse>(MobileWalletAdapterFailureResponse.serializer()) {
76
- override fun transformDeserialize(element: JsonElement): JsonElement =
77
- if ((element as? JsonObject)?.containsKey("failReason") == true)
78
- JsonObject(element.toMutableMap().apply {
79
- this["type"] = this.remove("failReason")!!
80
- })
81
- else element
82
- }
83
-
84
- internal object MobileWalletAdapterResponseSerializer : JsonContentPolymorphicSerializer<MobileWalletAdapterResponse>(MobileWalletAdapterResponse::class) {
85
- override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out MobileWalletAdapterResponse> =
86
- if ((element as? JsonObject)?.containsKey("failReason") == true) FailReasonTransformingSerializer
87
- else if ((element as? JsonObject)?.containsKey("accounts") == true) AuthorizeDappResponse.serializer()
88
- else if ((element as? JsonObject)?.containsKey("authorizationScope") == true) ReauthorizeDappResponse.serializer()
89
- else if ((element as? JsonObject)?.containsKey("signedPayloads") == true) SignedPayloads.serializer()
90
- else if ((element as? JsonObject)?.containsKey("signedTransactions") == true) SignedAndSentTransactions.serializer()
91
- else if ((element as? JsonObject)?.isEmpty() == true) DeauthorizeDappResponse.serializer()
92
- else MobileWalletAdapterResponse.serializer()
93
- }
94
-
95
- internal object MobileWalletAdapterRequestSerializer : TypeTransformingSerializer<MobileWalletAdapterRequest>(AppIdentityTransformingSerializer)
96
-
97
- internal object ByteArrayAsMapSerializer : KSerializer<ByteArray> {
98
- override val descriptor: SerialDescriptor = ByteArraySerializer().descriptor
99
-
100
- override fun deserialize(decoder: Decoder): ByteArray =
101
- try {
102
- decoder.decodeSerializableValue(MapSerializer(String.serializer(), Int.serializer())).values.map { it.toByte() }.toByteArray()
103
- } catch (e: Exception) {
104
- decoder.decodeSerializableValue(ByteArraySerializer())
105
- }
106
-
107
- override fun serialize(encoder: Encoder, value: ByteArray) {
108
- TODO("Not yet implemented")
109
- }
110
- }
111
-
112
- object ByteArrayCollectionAsMapCollectionSerializer : KSerializer<List<ByteArray>> {
113
- override val descriptor: SerialDescriptor = ListSerializer(ByteArraySerializer()).descriptor
114
-
115
- override fun deserialize(decoder: Decoder): List<ByteArray> =
116
- decoder.decodeSerializableValue(ListSerializer(ByteArrayAsMapSerializer))
117
-
118
- override fun serialize(encoder: Encoder, value: List<ByteArray>) =
119
- encoder.encodeSerializableValue(ListSerializer(ByteArrayAsMapSerializer), value)
120
- }
121
-
122
- object SignInPayloadSerializer : KSerializer<SignInWithSolana.Payload> {
123
- override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
124
-
125
- val json = Json { ignoreUnknownKeys = true }
126
-
127
- override fun deserialize(decoder: Decoder): SignInWithSolana.Payload =
128
- SignInWithSolana.Payload.fromJson(
129
- JSONObject(decoder.decodeSerializableValue(JsonElement.serializer()).toString())
130
- )
131
-
132
- override fun serialize(encoder: Encoder, value: SignInWithSolana.Payload) =
133
- encoder.encodeSerializableValue(JsonElement.serializer(),
134
- json.decodeFromString(JsonElement.serializer(), value.toJson().toString()))
135
- }
136
-
137
- object SignInResultSerializer : KSerializer<SignInResult> {
138
- override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
139
-
140
- override fun deserialize(decoder: Decoder): SignInResult =
141
- decoder.decodeSerializableValue(JsonObject.serializer()).let { json ->
142
- SignInResult(
143
- Base64.decode(json["address"]!!.jsonPrimitive.content, Base64.NO_WRAP),
144
- Base64.decode(json["signed_message"]!!.jsonPrimitive.content, Base64.NO_WRAP),
145
- Base64.decode(json["signature"]!!.jsonPrimitive.content, Base64.NO_WRAP),
146
- json["signature_type"]?.jsonPrimitive?.content
147
- )
148
- }
149
-
150
- override fun serialize(encoder: Encoder, value: SignInResult) =
151
- encoder.encodeSerializableValue(JsonElement.serializer(), buildJsonObject {
152
- put("address", Base64.encodeToString(value.publicKey, Base64.NO_WRAP))
153
- put("signed_message", Base64.encodeToString(value.signedMessage, Base64.NO_WRAP))
154
- put("signature", Base64.encodeToString(value.signature, Base64.NO_WRAP))
155
- put("signature_type", value.signatureType)
156
- })
1
+ package com.solanamobile.mobilewalletadapterwalletlib.reactnative
2
+
3
+ import android.util.Base64
4
+ import com.solana.mobilewalletadapter.common.signin.SignInWithSolana
5
+ import com.solana.mobilewalletadapter.walletlib.scenario.SignInResult
6
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.AuthorizeDappResponse
7
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.DeauthorizeDappResponse
8
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterFailureResponse
9
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterRequest
10
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.MobileWalletAdapterResponse
11
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.ReauthorizeDappResponse
12
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.SignedAndSentTransactions
13
+ import com.solanamobile.mobilewalletadapterwalletlib.reactnative.model.SignedPayloads
14
+ import kotlinx.serialization.DeserializationStrategy
15
+ import kotlinx.serialization.KSerializer
16
+ import kotlinx.serialization.builtins.ByteArraySerializer
17
+ import kotlinx.serialization.builtins.ListSerializer
18
+ import kotlinx.serialization.builtins.MapSerializer
19
+ import kotlinx.serialization.builtins.serializer
20
+ import kotlinx.serialization.descriptors.SerialDescriptor
21
+ import kotlinx.serialization.encoding.Decoder
22
+ import kotlinx.serialization.encoding.Encoder
23
+ import kotlinx.serialization.json.Json
24
+ import kotlinx.serialization.json.JsonContentPolymorphicSerializer
25
+ import kotlinx.serialization.json.JsonElement
26
+ import kotlinx.serialization.json.JsonNull
27
+ import kotlinx.serialization.json.JsonObject
28
+ import kotlinx.serialization.json.JsonTransformingSerializer
29
+ import kotlinx.serialization.json.buildJsonObject
30
+ import kotlinx.serialization.json.jsonObject
31
+ import kotlinx.serialization.json.jsonPrimitive
32
+ import kotlinx.serialization.json.put
33
+ import org.json.JSONObject
34
+
35
+ internal open class TypeTransformingSerializer<T: Any>(serializer: KSerializer<T>) : JsonTransformingSerializer<T>(serializer) {
36
+ override fun transformSerialize(element: JsonElement): JsonElement =
37
+ if ((element as? JsonObject)?.containsKey("type") == true)
38
+ JsonObject(element.toMutableMap().apply {
39
+ this["__type"] = this.remove("type")!!
40
+ })
41
+ else element
42
+
43
+ override fun transformDeserialize(element: JsonElement): JsonElement =
44
+ if ((element as? JsonObject)?.containsKey("__type") == true)
45
+ JsonObject(element.toMutableMap().apply {
46
+ this["type"] = this.remove("__type")!!
47
+ })
48
+ else element
49
+ }
50
+
51
+ internal object AppIdentityTransformingSerializer : JsonTransformingSerializer<MobileWalletAdapterRequest>(MobileWalletAdapterRequest.serializer()) {
52
+ override fun transformSerialize(element: JsonElement): JsonElement =
53
+ if ((element as? JsonObject)?.containsKey("identityUri") == true)
54
+ JsonObject(element.toMutableMap().apply {
55
+ this["appIdentity"] = buildJsonObject {
56
+ put("identityName", this@apply.remove("identityName") ?: JsonNull)
57
+ put("identityUri", this@apply.remove("identityUri") ?: JsonNull)
58
+ put("iconRelativeUri", this@apply.remove("iconRelativeUri") ?: JsonNull)
59
+ }
60
+ })
61
+ else element
62
+
63
+ override fun transformDeserialize(element: JsonElement): JsonElement =
64
+ if ((element as? JsonObject)?.containsKey("appIdentity") == true)
65
+ JsonObject(element.toMutableMap().apply {
66
+ val appIdentity = this.remove("appIdentity")!! as JsonObject
67
+ put("identityName", appIdentity["identityName"] ?: JsonNull)
68
+ put("identityUri", appIdentity["identityUri"] ?: JsonNull)
69
+ put("iconRelativeUri", appIdentity["iconRelativeUri"] ?: JsonNull)
70
+ })
71
+ else element
72
+ }
73
+
74
+ internal object FailReasonTransformingSerializer
75
+ : JsonTransformingSerializer<MobileWalletAdapterFailureResponse>(MobileWalletAdapterFailureResponse.serializer()) {
76
+ override fun transformDeserialize(element: JsonElement): JsonElement =
77
+ if ((element as? JsonObject)?.containsKey("failReason") == true)
78
+ JsonObject(element.toMutableMap().apply {
79
+ this["type"] = this.remove("failReason")!!
80
+ })
81
+ else element
82
+ }
83
+
84
+ internal object MobileWalletAdapterResponseSerializer : JsonContentPolymorphicSerializer<MobileWalletAdapterResponse>(MobileWalletAdapterResponse::class) {
85
+ override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out MobileWalletAdapterResponse> =
86
+ if ((element as? JsonObject)?.containsKey("failReason") == true) FailReasonTransformingSerializer
87
+ else if ((element as? JsonObject)?.containsKey("accounts") == true) AuthorizeDappResponse.serializer()
88
+ else if ((element as? JsonObject)?.containsKey("authorizationScope") == true) ReauthorizeDappResponse.serializer()
89
+ else if ((element as? JsonObject)?.containsKey("signedPayloads") == true) SignedPayloads.serializer()
90
+ else if ((element as? JsonObject)?.containsKey("signedTransactions") == true) SignedAndSentTransactions.serializer()
91
+ else if ((element as? JsonObject)?.isEmpty() == true) DeauthorizeDappResponse.serializer()
92
+ else MobileWalletAdapterResponse.serializer()
93
+ }
94
+
95
+ internal object MobileWalletAdapterRequestSerializer : TypeTransformingSerializer<MobileWalletAdapterRequest>(AppIdentityTransformingSerializer)
96
+
97
+ internal object ByteArrayAsMapSerializer : KSerializer<ByteArray> {
98
+ override val descriptor: SerialDescriptor = ByteArraySerializer().descriptor
99
+
100
+ override fun deserialize(decoder: Decoder): ByteArray =
101
+ try {
102
+ decoder.decodeSerializableValue(MapSerializer(String.serializer(), Int.serializer())).values.map { it.toByte() }.toByteArray()
103
+ } catch (e: Exception) {
104
+ decoder.decodeSerializableValue(ByteArraySerializer())
105
+ }
106
+
107
+ override fun serialize(encoder: Encoder, value: ByteArray) {
108
+ TODO("Not yet implemented")
109
+ }
110
+ }
111
+
112
+ object ByteArrayCollectionAsMapCollectionSerializer : KSerializer<List<ByteArray>> {
113
+ override val descriptor: SerialDescriptor = ListSerializer(ByteArraySerializer()).descriptor
114
+
115
+ override fun deserialize(decoder: Decoder): List<ByteArray> =
116
+ decoder.decodeSerializableValue(ListSerializer(ByteArrayAsMapSerializer))
117
+
118
+ override fun serialize(encoder: Encoder, value: List<ByteArray>) =
119
+ encoder.encodeSerializableValue(ListSerializer(ByteArrayAsMapSerializer), value)
120
+ }
121
+
122
+ object SignInPayloadSerializer : KSerializer<SignInWithSolana.Payload> {
123
+ override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
124
+
125
+ val json = Json { ignoreUnknownKeys = true }
126
+
127
+ override fun deserialize(decoder: Decoder): SignInWithSolana.Payload =
128
+ SignInWithSolana.Payload.fromJson(
129
+ JSONObject(decoder.decodeSerializableValue(JsonElement.serializer()).toString())
130
+ )
131
+
132
+ override fun serialize(encoder: Encoder, value: SignInWithSolana.Payload) =
133
+ encoder.encodeSerializableValue(JsonElement.serializer(),
134
+ json.decodeFromString(JsonElement.serializer(), value.toJson().toString()))
135
+ }
136
+
137
+ object SignInResultSerializer : KSerializer<SignInResult> {
138
+ override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
139
+
140
+ override fun deserialize(decoder: Decoder): SignInResult =
141
+ decoder.decodeSerializableValue(JsonObject.serializer()).let { json ->
142
+ SignInResult(
143
+ Base64.decode(json["address"]!!.jsonPrimitive.content, Base64.NO_WRAP),
144
+ Base64.decode(json["signed_message"]!!.jsonPrimitive.content, Base64.NO_WRAP),
145
+ Base64.decode(json["signature"]!!.jsonPrimitive.content, Base64.NO_WRAP),
146
+ json["signature_type"]?.jsonPrimitive?.content
147
+ )
148
+ }
149
+
150
+ override fun serialize(encoder: Encoder, value: SignInResult) =
151
+ encoder.encodeSerializableValue(JsonElement.serializer(), buildJsonObject {
152
+ put("address", Base64.encodeToString(value.publicKey, Base64.NO_WRAP))
153
+ put("signed_message", Base64.encodeToString(value.signedMessage, Base64.NO_WRAP))
154
+ put("signature", Base64.encodeToString(value.signature, Base64.NO_WRAP))
155
+ put("signature_type", value.signatureType)
156
+ })
157
157
  }
@@ -1,19 +1,19 @@
1
- package com.solanamobile.mobilewalletadapterwalletlib.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 MobileWalletAdapterWalletLibReactNativePackage : ReactPackage {
9
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
- return listOf(
11
- SolanaMobileWalletAdapterWalletLibModule(reactContext),
12
- SolanaMobileDigitalAssetLinksModule(reactContext)
13
- )
14
- }
15
-
16
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
17
- return emptyList()
18
- }
1
+ package com.solanamobile.mobilewalletadapterwalletlib.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 MobileWalletAdapterWalletLibReactNativePackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(
11
+ SolanaMobileWalletAdapterWalletLibModule(reactContext),
12
+ SolanaMobileDigitalAssetLinksModule(reactContext)
13
+ )
14
+ }
15
+
16
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
17
+ return emptyList()
18
+ }
19
19
  }