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,61 @@
1
+ import Foundation
2
+
3
+ class WalletSession {
4
+ let wallet: Wallet
5
+ var online: Online?
6
+
7
+ init(wallet: Wallet, online: Online? = nil) {
8
+ self.wallet = wallet
9
+ self.online = online
10
+ }
11
+ }
12
+
13
+ class WalletStore {
14
+ static let shared = WalletStore()
15
+
16
+ private var sessions: [Int: WalletSession] = [:]
17
+ private var nextId: Int = 1
18
+ private let queue = DispatchQueue(label: "com.rgb.walletstore")
19
+
20
+ private init() {}
21
+
22
+ func create(wallet: Wallet) -> Int {
23
+ return queue.sync {
24
+ let id = nextId
25
+ nextId += 1
26
+ sessions[id] = WalletSession(wallet: wallet)
27
+ print("WalletStore: Created wallet session with id: \(id)")
28
+ return id
29
+ }
30
+ }
31
+
32
+ func get(id: Int) -> WalletSession? {
33
+ return queue.sync {
34
+ return sessions[id]
35
+ }
36
+ }
37
+
38
+ func setOnline(id: Int, online: Online) {
39
+ queue.sync {
40
+ sessions[id]?.online = online
41
+ print("WalletStore: Set online for wallet session id: \(id)")
42
+ }
43
+ }
44
+
45
+ func remove(id: Int) {
46
+ queue.sync {
47
+ if sessions.removeValue(forKey: id) != nil {
48
+ print("WalletStore: Removed wallet session with id: \(id)")
49
+ }
50
+ }
51
+ }
52
+
53
+ func clear() {
54
+ queue.sync {
55
+ sessions.removeAll()
56
+ nextId = 1
57
+ print("WalletStore: Cleared all wallet sessions")
58
+ }
59
+ }
60
+ }
61
+
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ export const BitcoinNetwork = {
4
+ MAINNET: 'MAINNET',
5
+ TESTNET: 'TESTNET',
6
+ TESTNET4: 'TESTNET4',
7
+ REGTEST: 'REGTEST',
8
+ SIGNET: 'SIGNET'
9
+ };
10
+ export const AssetSchema = {
11
+ NIA: 'NIA',
12
+ UDA: 'UDA',
13
+ CFA: 'CFA',
14
+ IFA: 'IFA'
15
+ };
16
+
17
+ /**
18
+ * Error types that can be returned by RGB library methods.
19
+ * These correspond to the RgbLibError
20
+ * Errors with associated values are represented as objects with the error name and associated data.
21
+ */
22
+
23
+ /**
24
+ * Constants for all RGB library errors.
25
+ * Use these for error code comparison and type safety.
26
+ */
27
+ export const RgbLibErrors = {
28
+ AllocationsAlreadyAvailable: 'AllocationsAlreadyAvailable',
29
+ BitcoinNetworkMismatch: 'BitcoinNetworkMismatch',
30
+ CannotChangeOnline: 'CannotChangeOnline',
31
+ CannotDeleteBatchTransfer: 'CannotDeleteBatchTransfer',
32
+ CannotEstimateFees: 'CannotEstimateFees',
33
+ CannotFailBatchTransfer: 'CannotFailBatchTransfer',
34
+ CannotFinalizePsbt: 'CannotFinalizePsbt',
35
+ CannotUseIfaOnMainnet: 'CannotUseIfaOnMainnet',
36
+ FingerprintMismatch: 'FingerprintMismatch',
37
+ InexistentDataDir: 'InexistentDataDir',
38
+ InsufficientAllocationSlots: 'InsufficientAllocationSlots',
39
+ InvalidAmountZero: 'InvalidAmountZero',
40
+ InvalidAssignment: 'InvalidAssignment',
41
+ InvalidBitcoinKeys: 'InvalidBitcoinKeys',
42
+ InvalidConsignment: 'InvalidConsignment',
43
+ InvalidEstimationBlocks: 'InvalidEstimationBlocks',
44
+ InvalidFingerprint: 'InvalidFingerprint',
45
+ InvalidRecipientId: 'InvalidRecipientId',
46
+ InvalidRecipientNetwork: 'InvalidRecipientNetwork',
47
+ InvalidTxid: 'InvalidTxid',
48
+ InvalidVanillaKeychain: 'InvalidVanillaKeychain',
49
+ NoConsignment: 'NoConsignment',
50
+ NoInflationAmounts: 'NoInflationAmounts',
51
+ NoIssuanceAmounts: 'NoIssuanceAmounts',
52
+ NoSupportedSchemas: 'NoSupportedSchemas',
53
+ NoValidTransportEndpoint: 'NoValidTransportEndpoint',
54
+ Offline: 'Offline',
55
+ OnlineNeeded: 'OnlineNeeded',
56
+ OutputBelowDustLimit: 'OutputBelowDustLimit',
57
+ RecipientIdAlreadyUsed: 'RecipientIdAlreadyUsed',
58
+ RecipientIdDuplicated: 'RecipientIdDuplicated',
59
+ TooHighInflationAmounts: 'TooHighInflationAmounts',
60
+ TooHighIssuanceAmounts: 'TooHighIssuanceAmounts',
61
+ UnsupportedTransportType: 'UnsupportedTransportType',
62
+ WatchOnly: 'WatchOnly',
63
+ WrongPassword: 'WrongPassword'
64
+ };
65
+ //# sourceMappingURL=Interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BitcoinNetwork","MAINNET","TESTNET","TESTNET4","REGTEST","SIGNET","AssetSchema","NIA","UDA","CFA","IFA","RgbLibErrors","AllocationsAlreadyAvailable","BitcoinNetworkMismatch","CannotChangeOnline","CannotDeleteBatchTransfer","CannotEstimateFees","CannotFailBatchTransfer","CannotFinalizePsbt","CannotUseIfaOnMainnet","FingerprintMismatch","InexistentDataDir","InsufficientAllocationSlots","InvalidAmountZero","InvalidAssignment","InvalidBitcoinKeys","InvalidConsignment","InvalidEstimationBlocks","InvalidFingerprint","InvalidRecipientId","InvalidRecipientNetwork","InvalidTxid","InvalidVanillaKeychain","NoConsignment","NoInflationAmounts","NoIssuanceAmounts","NoSupportedSchemas","NoValidTransportEndpoint","Offline","OnlineNeeded","OutputBelowDustLimit","RecipientIdAlreadyUsed","RecipientIdDuplicated","TooHighInflationAmounts","TooHighIssuanceAmounts","UnsupportedTransportType","WatchOnly","WrongPassword"],"sourceRoot":"../../src","sources":["Interfaces.ts"],"mappings":";;AAOA,OAAO,MAAMA,cAAc,GAAG;EAC5BC,OAAO,EAAE,SAAkB;EAC3BC,OAAO,EAAE,SAAkB;EAC3BC,QAAQ,EAAE,UAAmB;EAC7BC,OAAO,EAAE,SAAkB;EAC3BC,MAAM,EAAE;AACV,CAAU;AAuBV,OAAO,MAAMC,WAAW,GAAG;EACzBC,GAAG,EAAE,K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AAE;AACjB,CAAU","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('Rgb');
5
+ //# sourceMappingURL=NativeRgb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRgb.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAqnBpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,KAAK,CAAC","ignoreList":[]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Custom error class for RGB library errors.
5
+ * Provides structured error information with error codes and messages.
6
+ */
7
+ export class RgbError extends Error {
8
+ /**
9
+ * Error code from the native module.
10
+ * This helps identify which operation failed.
11
+ */
12
+
13
+ /**
14
+ * Original error message from the native module.
15
+ */
16
+
17
+ constructor(code, message, originalError) {
18
+ super(message);
19
+ this.originalError = originalError;
20
+ this.name = 'RgbError';
21
+ this.code = code;
22
+ this.nativeMessage = message;
23
+ if (Error.captureStackTrace) {
24
+ Error.captureStackTrace(this, RgbError);
25
+ }
26
+ }
27
+ isCode(code) {
28
+ if (typeof this.code === 'string' && typeof code === 'string') {
29
+ return this.code === code;
30
+ }
31
+ if (typeof this.code === 'object' && typeof code === 'object' && code !== null) {
32
+ return 'type' in this.code && 'type' in code && this.code.type === code.type;
33
+ }
34
+ return false;
35
+ }
36
+ toString() {
37
+ const codeStr = typeof this.code === 'string' ? this.code : `[${this.code.type}] ${JSON.stringify(this.code)}`;
38
+ return `[${codeStr}] ${this.message}`;
39
+ }
40
+
41
+ /**
42
+ * Converts a React Native error to an RgbError.
43
+ * React Native errors from native modules typically have a code and message.
44
+ * @param error - The error from React Native
45
+ * @returns An RgbError instance, or the original error if it cannot be converted
46
+ */
47
+ static fromReactNativeError(error) {
48
+ // Check if it's already an RgbError
49
+ if (error instanceof RgbError) {
50
+ return error;
51
+ }
52
+ if (error instanceof Error && 'code' in error) {
53
+ const code = error.code;
54
+ const message = error.message || 'Unknown error';
55
+ if (typeof code === 'string') {
56
+ return new RgbError(code, message, error);
57
+ }
58
+ }
59
+ if (error instanceof Error) {
60
+ return error;
61
+ }
62
+ return new Error(String(error));
63
+ }
64
+ }
65
+ //# sourceMappingURL=RgbError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["RgbError","Error","constructor","code","message","originalError","name","nativeMessage","captureStackTrace","isCode","type","toString","codeStr","JSON","stringify","fromReactNativeError","error","String"],"sourceRoot":"../../src","sources":["RgbError.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,SAASC,KAAK,CAAC;EAClC;AACF;AACA;AACA;;EAGE;AACF;AACA;;EAGEC,WAAWA,CACTC,IAAkB,EAClBC,OAAe,EACCC,aAAuB,EACvC;IACA,KAAK,CAACD,OAAO,CAAC;IAAC,KAFCC,aAAuB,GAAvBA,aAAuB;IAGvC,IAAI,CAACC,IAAI,GAAG,UAAU;IACtB,IAAI,CAACH,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACI,aAAa,GAAGH,OAAO;IAE5B,IAAIH,KAAK,CAACO,iBAAiB,EAAE;MAC3BP,KAAK,CAACO,iBAAiB,CAAC,IAAI,EAAER,QAAQ,CAAC;IACzC;EACF;EAEOS,MAAMA,CAACN,IAAkB,EAAW;IACzC,IAAI,OAAO,IAAI,CAACA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC7D,OAAO,IAAI,CAACA,IAAI,KAAKA,IAAI;IAC3B;IACA,IACE,OAAO,IAAI,CAACA,IAAI,KAAK,QAAQ,IAC7B,OAAOA,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;MACA,OACE,MAAM,IAAI,IAAI,CAACA,IAAI,IAAI,MAAM,IAAIA,IAAI,IAAI,IAAI,CAACA,IAAI,CAACO,IAAI,KAAKP,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