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.
- package/LICENSE +20 -0
- package/README.md +165 -0
- package/Rgb.podspec +23 -0
- package/android/build.gradle +80 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rgb/AppConstants.kt +57 -0
- package/android/src/main/java/com/rgb/RgbModule.kt +1959 -0
- package/android/src/main/java/com/rgb/RgbPackage.kt +33 -0
- package/android/src/main/java/com/rgb/WalletStore.kt +49 -0
- package/ios/AppConstants.swift +71 -0
- package/ios/Rgb.h +5 -0
- package/ios/Rgb.mm +1740 -0
- package/ios/Rgb.swift +1916 -0
- package/ios/RgbLib.swift +7615 -0
- package/ios/WalletStore.swift +61 -0
- package/lib/module/Interfaces.js +65 -0
- package/lib/module/Interfaces.js.map +1 -0
- package/lib/module/NativeRgb.js +5 -0
- package/lib/module/NativeRgb.js.map +1 -0
- package/lib/module/RgbError.js +65 -0
- package/lib/module/RgbError.js.map +1 -0
- package/lib/module/Wallet.js +854 -0
- package/lib/module/Wallet.js.map +1 -0
- package/lib/module/index.js +39 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Interfaces.d.ts +390 -0
- package/lib/typescript/src/Interfaces.d.ts.map +1 -0
- package/lib/typescript/src/NativeRgb.d.ts +417 -0
- package/lib/typescript/src/NativeRgb.d.ts.map +1 -0
- package/lib/typescript/src/RgbError.d.ts +28 -0
- package/lib/typescript/src/RgbError.d.ts.map +1 -0
- package/lib/typescript/src/Wallet.d.ts +648 -0
- package/lib/typescript/src/Wallet.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +28 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +174 -0
- package/src/Interfaces.ts +376 -0
- package/src/NativeRgb.ts +630 -0
- package/src/RgbError.ts +84 -0
- package/src/Wallet.ts +1118 -0
- package/src/index.tsx +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Orbis1
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# react-native-rgb
|
|
2
|
+
|
|
3
|
+
A React Native Turbo Module for the Bitcoin RGB Protocol. This library provides a high-level TypeScript API to manage RGB assets, keys, and wallets. It wraps the native [rgb-lib-swift](https://github.com/RGB-Tools/rgb-lib-swift) and [rgb-lib-kotlin](https://github.com/RGB-Tools/rgb-lib-kotlin) libraries.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Quick Start](#quick-start)
|
|
9
|
+
- [API Reference](#api-reference)
|
|
10
|
+
- [Running the Example](#running-the-example)
|
|
11
|
+
- [Project Structure](#project-structure)
|
|
12
|
+
- [Troubleshooting](#troubleshooting)
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Full Asset Support**: Handle NIA, UDA, CFA, and IFA.
|
|
17
|
+
- **Key Management**: BIP39 mnemonic support for key generation and restoration.
|
|
18
|
+
- **Performance**: Built as a Turbo Module for efficient native communication.
|
|
19
|
+
- **Type Safety**: Written in TypeScript.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
yarn add react-native-rgb
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### iOS Setup
|
|
28
|
+
|
|
29
|
+
The native Rust framework (`rgb_libFFI.xcframework`) is automatically downloaded during `postinstall`.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
cd ios && pod install
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Android Setup
|
|
36
|
+
|
|
37
|
+
The library requires `minSdkVersion` 24. Make sure your `android/build.gradle` includes JitPack if necessary for transitive dependencies:
|
|
38
|
+
|
|
39
|
+
```gradle
|
|
40
|
+
allprojects {
|
|
41
|
+
repositories {
|
|
42
|
+
maven { url 'https://jitpack.io' }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### 1. Setup Keys
|
|
50
|
+
```typescript
|
|
51
|
+
import { generateKeys, BitcoinNetwork } from 'react-native-rgb';
|
|
52
|
+
|
|
53
|
+
const keys = await generateKeys(BitcoinNetwork.TESTNET4);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Initialize Wallet
|
|
57
|
+
```typescript
|
|
58
|
+
import { Wallet } from 'react-native-rgb';
|
|
59
|
+
|
|
60
|
+
const wallet = new Wallet(keys, { network: BitcoinNetwork.TESTNET4 });
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Basic Operations
|
|
64
|
+
```typescript
|
|
65
|
+
// Bring the wallet online
|
|
66
|
+
await wallet.goOnline('ssl://electrum.iriswallet.com:50053');
|
|
67
|
+
|
|
68
|
+
// Issue a new NIA asset
|
|
69
|
+
const asset = await wallet.issueAssetNia('TICKER', 'Name', 2, [1000]);
|
|
70
|
+
|
|
71
|
+
// Check your balance
|
|
72
|
+
const btcBalance = await wallet.getBtcBalance();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Error Handling
|
|
76
|
+
|
|
77
|
+
The library uses structured error handling with error codes for better error management. All methods that can fail will throw an `RgbError` with a specific error code.
|
|
78
|
+
|
|
79
|
+
### Using RgbError
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Wallet, RgbError, RgbErrorCode } from 'react-native-rgb';
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
await wallet.goOnline('ssl://indexer.example.com:50053');
|
|
86
|
+
} catch (error) {
|
|
87
|
+
// Convert React Native error to RgbError
|
|
88
|
+
const rgbError = RgbError.fromReactNativeError(error);
|
|
89
|
+
|
|
90
|
+
if (rgbError instanceof RgbError) {
|
|
91
|
+
// Handle specific error codes
|
|
92
|
+
switch (rgbError.code) {
|
|
93
|
+
case RgbErrorCode.GO_ONLINE_ERROR:
|
|
94
|
+
console.error('Failed to connect:', rgbError.message);
|
|
95
|
+
// Handle connection error
|
|
96
|
+
break;
|
|
97
|
+
case RgbErrorCode.INITIALIZE_WALLET_ERROR:
|
|
98
|
+
console.error('Wallet initialization failed:', rgbError.message);
|
|
99
|
+
// Handle initialization error
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
console.error(`Error [${rgbError.code}]:`, rgbError.message);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
// Handle generic errors
|
|
106
|
+
console.error('Unexpected error:', error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## API Reference
|
|
113
|
+
|
|
114
|
+
### Keys & Wallet Setup
|
|
115
|
+
- `generateKeys(network)` / `restoreKeys(network, mnemonic)`
|
|
116
|
+
- `new Wallet(keys, options)`: Options include `network`, `maxAllocationsPerUtxo`, and `vanillaKeychain`.
|
|
117
|
+
|
|
118
|
+
### Wallet
|
|
119
|
+
- `goOnline(indexerUrl, skipSync?)`: Connect to infrastructure.
|
|
120
|
+
- `sync()`: Manually trigger a blockchain sync.
|
|
121
|
+
- `close()`: Shut down the wallet and free native resources.
|
|
122
|
+
|
|
123
|
+
### Balance & Assets
|
|
124
|
+
- `getBtcBalance()`: Returns `{ vanilla: Balance, colored: Balance }`.
|
|
125
|
+
- `getAddress()`: Returns the funding address.
|
|
126
|
+
- `getAssetBalance(assetId)` / `getAssetMetadata(assetId)`
|
|
127
|
+
- `listAssets(filter[])`: List assets by schema (NIA, UDA, CFA, IFA).
|
|
128
|
+
|
|
129
|
+
### Asset Issuance
|
|
130
|
+
- `issueAssetNia(ticker, name, precision, amounts)`
|
|
131
|
+
- `issueAssetCfa(name, details, precision, amounts, filePath?)`
|
|
132
|
+
- `issueAssetUda(ticker, name, details, precision, mediaPath, attachments[])`
|
|
133
|
+
- `issueAssetIfa(ticker, name, precision, amounts, ...)`
|
|
134
|
+
|
|
135
|
+
### Sending & Receiving
|
|
136
|
+
- `blindReceive(assetId, amount, duration, endpoints, confirmations)`: Get a blinded invoice.
|
|
137
|
+
- `witnessReceive(...)`: Get a witness invoice.
|
|
138
|
+
- `send(recipientMap, donation, feeRate, confirmations)`: Send RGB assets.
|
|
139
|
+
- `sendBtc(address, amount, feeRate)`: Send regular Bitcoin.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## Project Structure
|
|
143
|
+
|
|
144
|
+
- `src/`: TypeScript source (Wallet class, Interfaces).
|
|
145
|
+
- `android/` & `ios/`: Native Turbo Module implementations.
|
|
146
|
+
- `scripts/`: Build and setup scripts.
|
|
147
|
+
- `example/`: Sample React Native app.
|
|
148
|
+
|
|
149
|
+
## Running the Example
|
|
150
|
+
|
|
151
|
+
1. `yarn install` (root)
|
|
152
|
+
2. `yarn prepare` (build library)
|
|
153
|
+
3. `cd example && yarn install`
|
|
154
|
+
4. `cd ios && pod install`
|
|
155
|
+
5. `yarn ios` or `yarn android`
|
|
156
|
+
|
|
157
|
+
## Troubleshooting
|
|
158
|
+
|
|
159
|
+
- **iOS framework**: If a postinstall fails, run `node scripts/download-rgb-lib-ios.js` manually.
|
|
160
|
+
- **Linker issues**: Ensure you use the `.xcworkspace` on iOS.
|
|
161
|
+
- **Android SDK**: Must have `minSdkVersion >= 24`.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
MIT
|
package/Rgb.podspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "Rgb"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://www.github.com/Orbis-1/react-native-rgb.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
s.vendored_frameworks = "ios/rgb_libFFI.xcframework"
|
|
20
|
+
s.preserve_paths = "ios/rgb_libFFI.xcframework"
|
|
21
|
+
|
|
22
|
+
install_modules_dependencies(s)
|
|
23
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Rgb_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
apply plugin: "com.facebook.react"
|
|
23
|
+
|
|
24
|
+
def getExtOrIntegerDefault(name) {
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Rgb_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
android {
|
|
29
|
+
namespace "com.rgb"
|
|
30
|
+
|
|
31
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
32
|
+
|
|
33
|
+
defaultConfig {
|
|
34
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
35
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buildFeatures {
|
|
39
|
+
buildConfig true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
buildTypes {
|
|
43
|
+
release {
|
|
44
|
+
minifyEnabled false
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
lintOptions {
|
|
49
|
+
disable "GradleCompatible"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
compileOptions {
|
|
53
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
54
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
sourceSets {
|
|
58
|
+
main {
|
|
59
|
+
java.srcDirs += [
|
|
60
|
+
"generated/java",
|
|
61
|
+
"generated/jni"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
repositories {
|
|
68
|
+
mavenCentral()
|
|
69
|
+
google()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
73
|
+
|
|
74
|
+
dependencies {
|
|
75
|
+
implementation "com.facebook.react:react-android"
|
|
76
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
77
|
+
implementation("org.rgbtools:rgb-lib-android:0.3.0-beta.4")
|
|
78
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
|
|
79
|
+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1"
|
|
80
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package com.rgb
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import java.io.File
|
|
5
|
+
|
|
6
|
+
object AppConstants {
|
|
7
|
+
const val rgbDirName = ""
|
|
8
|
+
var appContext: Context? = null
|
|
9
|
+
var rgbDir: File? = null
|
|
10
|
+
const val backupName = "%s.rgb_backup"
|
|
11
|
+
|
|
12
|
+
const val testnetElectrumURL = "ssl://electrum.iriswallet.com:50013"
|
|
13
|
+
const val testnet4ElectrumURL = "ssl://electrum.iriswallet.com:50053"
|
|
14
|
+
|
|
15
|
+
const val regtestElectrumURL = "electrum.rgbtools.org:50041"
|
|
16
|
+
const val mainnetElectrumUrl = "ssl://electrum.iriswallet.com:50003"
|
|
17
|
+
|
|
18
|
+
const val proxyConsignmentEndpoint = "rpcs://proxy.iriswallet.com/0.2/json-rpc"
|
|
19
|
+
const val rgbDefaultPrecision: UByte = 0U
|
|
20
|
+
const val defaultFeeRate = 50.0F
|
|
21
|
+
|
|
22
|
+
private val mainnetUrls = listOf(
|
|
23
|
+
"ssl://electrum.iriswallet.com:50003",
|
|
24
|
+
"https://blockstream.info/api"
|
|
25
|
+
)
|
|
26
|
+
private var callCount = 0
|
|
27
|
+
|
|
28
|
+
@JvmStatic
|
|
29
|
+
fun initContext(context: Context) {
|
|
30
|
+
appContext = context
|
|
31
|
+
rgbDir = File(context.filesDir, rgbDirName)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@JvmStatic
|
|
35
|
+
fun ensureInitialized(context: Context) {
|
|
36
|
+
if (appContext == null || rgbDir == null) {
|
|
37
|
+
initContext(context)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fun getElectrumUrl(network: String): String {
|
|
42
|
+
return when (network.uppercase()) {
|
|
43
|
+
"TESTNET" -> testnetElectrumURL
|
|
44
|
+
"TESTNET4" -> testnet4ElectrumURL
|
|
45
|
+
"REGTEST" -> regtestElectrumURL
|
|
46
|
+
"MAINNET" -> getNextMainnetUrl()
|
|
47
|
+
else -> testnetElectrumURL
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private fun getNextMainnetUrl(): String {
|
|
52
|
+
val url = mainnetUrls[callCount % mainnetUrls.size]
|
|
53
|
+
callCount++
|
|
54
|
+
return url
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|