react-native-rgb 0.2.0

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 (44) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +165 -0
  3. package/Rgb.podspec +23 -0
  4. package/android/build.gradle +80 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/rgb/AppConstants.kt +57 -0
  8. package/android/src/main/java/com/rgb/RgbModule.kt +1959 -0
  9. package/android/src/main/java/com/rgb/RgbPackage.kt +33 -0
  10. package/android/src/main/java/com/rgb/WalletStore.kt +49 -0
  11. package/ios/AppConstants.swift +71 -0
  12. package/ios/Rgb.h +5 -0
  13. package/ios/Rgb.mm +1740 -0
  14. package/ios/Rgb.swift +1916 -0
  15. package/ios/RgbLib.swift +7615 -0
  16. package/ios/WalletStore.swift +61 -0
  17. package/lib/module/Interfaces.js +65 -0
  18. package/lib/module/Interfaces.js.map +1 -0
  19. package/lib/module/NativeRgb.js +5 -0
  20. package/lib/module/NativeRgb.js.map +1 -0
  21. package/lib/module/RgbError.js +65 -0
  22. package/lib/module/RgbError.js.map +1 -0
  23. package/lib/module/Wallet.js +854 -0
  24. package/lib/module/Wallet.js.map +1 -0
  25. package/lib/module/index.js +39 -0
  26. package/lib/module/index.js.map +1 -0
  27. package/lib/module/package.json +1 -0
  28. package/lib/typescript/package.json +1 -0
  29. package/lib/typescript/src/Interfaces.d.ts +390 -0
  30. package/lib/typescript/src/Interfaces.d.ts.map +1 -0
  31. package/lib/typescript/src/NativeRgb.d.ts +417 -0
  32. package/lib/typescript/src/NativeRgb.d.ts.map +1 -0
  33. package/lib/typescript/src/RgbError.d.ts +28 -0
  34. package/lib/typescript/src/RgbError.d.ts.map +1 -0
  35. package/lib/typescript/src/Wallet.d.ts +648 -0
  36. package/lib/typescript/src/Wallet.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +28 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -0
  39. package/package.json +174 -0
  40. package/src/Interfaces.ts +376 -0
  41. package/src/NativeRgb.ts +630 -0
  42. package/src/RgbError.ts +84 -0
  43. package/src/Wallet.ts +1118 -0
  44. package/src/index.tsx +46 -0
@@ -0,0 +1,33 @@
1
+ package com.rgb
2
+
3
+ import com.facebook.react.BaseReactPackage
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 RgbPackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == RgbModule.NAME) {
13
+ RgbModule(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[RgbModule.NAME] = ReactModuleInfo(
23
+ RgbModule.NAME,
24
+ RgbModule.NAME,
25
+ false, // canOverrideExistingModule
26
+ false, // needsEagerInit
27
+ false, // isCxxModule
28
+ true // isTurboModule
29
+ )
30
+ moduleInfos
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,49 @@
1
+ package com.rgb
2
+
3
+ import android.util.Log
4
+ import kotlinx.coroutines.sync.Mutex
5
+ import kotlinx.coroutines.sync.withLock
6
+ import org.rgbtools.Online
7
+ import org.rgbtools.Wallet
8
+
9
+ data class WalletSession(
10
+ val wallet: Wallet,
11
+ var online: Online?
12
+ )
13
+
14
+ object WalletStore {
15
+ private const val TAG = "WalletStore"
16
+ private val mutex = Mutex()
17
+ private val sessions = mutableMapOf<Int, WalletSession>()
18
+ private var nextId = 1
19
+
20
+ suspend fun create(wallet: Wallet): Int = mutex.withLock {
21
+ val id = nextId++
22
+ sessions[id] = WalletSession(wallet, null)
23
+ Log.d(TAG, "Created wallet session with id: $id")
24
+ return id
25
+ }
26
+
27
+ suspend fun get(id: Int): WalletSession? = mutex.withLock {
28
+ return sessions[id]
29
+ }
30
+
31
+ suspend fun setOnline(id: Int, online: Online) = mutex.withLock {
32
+ sessions[id]?.online = online
33
+ Log.d(TAG, "Set online for wallet session id: $id")
34
+ }
35
+
36
+ suspend fun remove(id: Int) = mutex.withLock {
37
+ val session = sessions.remove(id)
38
+ if (session != null) {
39
+ Log.d(TAG, "Removed wallet session with id: $id")
40
+ }
41
+ }
42
+
43
+ suspend fun clear() = mutex.withLock {
44
+ sessions.clear()
45
+ nextId = 1
46
+ Log.d(TAG, "Cleared all wallet sessions")
47
+ }
48
+ }
49
+
@@ -0,0 +1,71 @@
1
+ import Foundation
2
+
3
+ @objc
4
+ @objcMembers
5
+ public class AppConstants: NSObject {
6
+ @objc public static let shared = AppConstants()
7
+
8
+ let rgbDirName = ""
9
+ var appContext: Any? = nil
10
+ var rgbDir: URL? = nil
11
+ let backupName = "%s.rgb_backup"
12
+
13
+ let testnetElectrumURL = "ssl://electrum.iriswallet.com:50013"
14
+ let testnet4ElectrumURL = "ssl://electrum.iriswallet.com:50053"
15
+
16
+ let regtestElectrumURL = "electrum.rgbtools.org:50041"
17
+ let mainnetElectrumUrl = "ssl://electrum.iriswallet.com:50003"
18
+
19
+ let proxyConsignmentEndpoint = "rpcs://proxy.iriswallet.com/0.2/json-rpc"
20
+ let rgbDefaultPrecision: UInt8 = 0
21
+ let defaultFeeRate: Float = 50.0
22
+
23
+ private let mainnetUrls = [
24
+ "ssl://electrum.iriswallet.com:50003",
25
+ "https://blockstream.info/api"
26
+ ]
27
+ private var callCount = 0
28
+
29
+ private override init() {
30
+ super.init()
31
+ }
32
+
33
+ @objc public func initContext() {
34
+ let fileManager = FileManager.default
35
+ let documentsPath = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
36
+ rgbDir = documentsPath.appendingPathComponent(rgbDirName)
37
+
38
+ // Create directory if it doesn't exist
39
+ if let rgbDir = rgbDir {
40
+ try? fileManager.createDirectory(at: rgbDir, withIntermediateDirectories: true, attributes: nil)
41
+ }
42
+ }
43
+
44
+ @objc public func ensureInitialized() {
45
+ if rgbDir == nil {
46
+ initContext()
47
+ }
48
+ }
49
+
50
+ @objc public func getElectrumUrl(network: String) -> String {
51
+ switch network.uppercased() {
52
+ case "TESTNET":
53
+ return testnetElectrumURL
54
+ case "TESTNET4":
55
+ return testnet4ElectrumURL
56
+ case "REGTEST":
57
+ return regtestElectrumURL
58
+ case "MAINNET":
59
+ return getNextMainnetUrl()
60
+ default:
61
+ return testnetElectrumURL
62
+ }
63
+ }
64
+
65
+ private func getNextMainnetUrl() -> String {
66
+ let url = mainnetUrls[callCount % mainnetUrls.count]
67
+ callCount += 1
68
+ return url
69
+ }
70
+ }
71
+
package/ios/Rgb.h ADDED
@@ -0,0 +1,5 @@
1
+ #import <RgbSpec/RgbSpec.h>
2
+
3
+ @interface Rgb : NSObject <NativeRgbSpec>
4
+
5
+ @end