@novastera-oss/nitro-metamask 0.1.3

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 (52) hide show
  1. package/LICENSE +201 -0
  2. package/NitroMetamask.podspec +32 -0
  3. package/README.md +262 -0
  4. package/android/CMakeLists.txt +29 -0
  5. package/android/build.gradle +144 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/margelo/nitro/nitrometamask/HybridMetamaskConnector.kt +48 -0
  11. package/android/src/main/java/com/margelo/nitro/nitrometamask/NitroMetamaskPackage.kt +18 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/HybridMetamaskConnector.swift +58 -0
  14. package/lib/MetamaskConnector.nitro.d.ts +12 -0
  15. package/lib/MetamaskConnector.nitro.js +1 -0
  16. package/lib/index.d.ts +3 -0
  17. package/lib/index.js +2 -0
  18. package/lib/specs/Example.nitro.d.ts +0 -0
  19. package/lib/specs/Example.nitro.js +2 -0
  20. package/nitro.json +24 -0
  21. package/nitrogen/generated/android/NitroMetamask+autolinking.cmake +81 -0
  22. package/nitrogen/generated/android/NitroMetamask+autolinking.gradle +27 -0
  23. package/nitrogen/generated/android/NitroMetamaskOnLoad.cpp +44 -0
  24. package/nitrogen/generated/android/NitroMetamaskOnLoad.hpp +25 -0
  25. package/nitrogen/generated/android/c++/JConnectResult.hpp +61 -0
  26. package/nitrogen/generated/android/c++/JHybridMetamaskConnectorSpec.cpp +84 -0
  27. package/nitrogen/generated/android/c++/JHybridMetamaskConnectorSpec.hpp +66 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/ConnectResult.kt +41 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/HybridMetamaskConnectorSpec.kt +62 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/NitroMetamaskOnLoad.kt +35 -0
  31. package/nitrogen/generated/ios/NitroMetamask+autolinking.rb +60 -0
  32. package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.cpp +57 -0
  33. package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.hpp +157 -0
  34. package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Umbrella.hpp +48 -0
  35. package/nitrogen/generated/ios/NitroMetamaskAutolinking.mm +33 -0
  36. package/nitrogen/generated/ios/NitroMetamaskAutolinking.swift +25 -0
  37. package/nitrogen/generated/ios/c++/HybridMetamaskConnectorSpecSwift.cpp +11 -0
  38. package/nitrogen/generated/ios/c++/HybridMetamaskConnectorSpecSwift.hpp +87 -0
  39. package/nitrogen/generated/ios/swift/ConnectResult.swift +35 -0
  40. package/nitrogen/generated/ios/swift/Func_void_ConnectResult.swift +47 -0
  41. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  42. package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
  43. package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec.swift +57 -0
  44. package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec_cxx.swift +157 -0
  45. package/nitrogen/generated/shared/c++/ConnectResult.hpp +87 -0
  46. package/nitrogen/generated/shared/c++/HybridMetamaskConnectorSpec.cpp +22 -0
  47. package/nitrogen/generated/shared/c++/HybridMetamaskConnectorSpec.hpp +66 -0
  48. package/package.json +108 -0
  49. package/react-native.config.js +16 -0
  50. package/src/MetamaskConnector.nitro.ts +13 -0
  51. package/src/index.ts +8 -0
  52. package/src/specs/Example.nitro.ts +1 -0
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_ConnectResult.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ value: ConnectResult) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_ConnectResult {
16
+ public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
17
+
18
+ private let closure: (_ value: ConnectResult) -> Void
19
+
20
+ public init(_ closure: @escaping (_ value: ConnectResult) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(value: ConnectResult) -> Void {
26
+ self.closure(value)
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_ConnectResult`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_ConnectResult>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_ConnectResult {
45
+ return Unmanaged<Func_void_ConnectResult>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__exception_ptr.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ error: Error) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__exception_ptr {
16
+ public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
17
+
18
+ private let closure: (_ error: Error) -> Void
19
+
20
+ public init(_ closure: @escaping (_ error: Error) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(error: std.exception_ptr) -> Void {
26
+ self.closure(RuntimeError.from(cppError: error))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
45
+ return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__string.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * Wraps a Swift `(_ value: String) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__string {
16
+ public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
17
+
18
+ private let closure: (_ value: String) -> Void
19
+
20
+ public init(_ closure: @escaping (_ value: String) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(value: std.string) -> Void {
26
+ self.closure(String(value))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__string`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__string>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string {
45
+ return Unmanaged<Func_void_std__string>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -0,0 +1,57 @@
1
+ ///
2
+ /// HybridMetamaskConnectorSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /// See ``HybridMetamaskConnectorSpec``
12
+ public protocol HybridMetamaskConnectorSpec_protocol: HybridObject {
13
+ // Properties
14
+
15
+
16
+ // Methods
17
+ func connect() throws -> Promise<ConnectResult>
18
+ func signMessage(message: String) throws -> Promise<String>
19
+ }
20
+
21
+ public extension HybridMetamaskConnectorSpec_protocol {
22
+ /// Default implementation of ``HybridObject.toString``
23
+ func toString() -> String {
24
+ return "[HybridObject MetamaskConnector]"
25
+ }
26
+ }
27
+
28
+ /// See ``HybridMetamaskConnectorSpec``
29
+ open class HybridMetamaskConnectorSpec_base {
30
+ private weak var cxxWrapper: HybridMetamaskConnectorSpec_cxx? = nil
31
+ public init() { }
32
+ public func getCxxWrapper() -> HybridMetamaskConnectorSpec_cxx {
33
+ #if DEBUG
34
+ guard self is HybridMetamaskConnectorSpec else {
35
+ fatalError("`self` is not a `HybridMetamaskConnectorSpec`! Did you accidentally inherit from `HybridMetamaskConnectorSpec_base` instead of `HybridMetamaskConnectorSpec`?")
36
+ }
37
+ #endif
38
+ if let cxxWrapper = self.cxxWrapper {
39
+ return cxxWrapper
40
+ } else {
41
+ let cxxWrapper = HybridMetamaskConnectorSpec_cxx(self as! HybridMetamaskConnectorSpec)
42
+ self.cxxWrapper = cxxWrapper
43
+ return cxxWrapper
44
+ }
45
+ }
46
+ }
47
+
48
+ /**
49
+ * A Swift base-protocol representing the MetamaskConnector HybridObject.
50
+ * Implement this protocol to create Swift-based instances of MetamaskConnector.
51
+ * ```swift
52
+ * class HybridMetamaskConnector : HybridMetamaskConnectorSpec {
53
+ * // ...
54
+ * }
55
+ * ```
56
+ */
57
+ public typealias HybridMetamaskConnectorSpec = HybridMetamaskConnectorSpec_protocol & HybridMetamaskConnectorSpec_base
@@ -0,0 +1,157 @@
1
+ ///
2
+ /// HybridMetamaskConnectorSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridMetamaskConnectorSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridMetamaskConnectorSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::nitrometamask::bridge::swift`)
23
+ * from `NitroMetamask-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridMetamaskConnectorSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridMetamaskConnectorSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridMetamaskConnectorSpec_
37
+
38
+ /**
39
+ * Create a new `HybridMetamaskConnectorSpec_cxx` that wraps the given `HybridMetamaskConnectorSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridMetamaskConnectorSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridMetamaskConnectorSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridMetamaskConnectorSpec() -> any HybridMetamaskConnectorSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridMetamaskConnectorSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridMetamaskConnectorSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridMetamaskConnectorSpec_cxx {
70
+ return Unmanaged<HybridMetamaskConnectorSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridMetamaskConnectorSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridMetamaskConnectorSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridMetamaskConnectorSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridMetamaskConnectorSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+
118
+
119
+ // Methods
120
+ @inline(__always)
121
+ public final func connect() -> bridge.Result_std__shared_ptr_Promise_ConnectResult___ {
122
+ do {
123
+ let __result = try self.__implementation.connect()
124
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_ConnectResult__ in
125
+ let __promise = bridge.create_std__shared_ptr_Promise_ConnectResult__()
126
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_ConnectResult__(__promise)
127
+ __result
128
+ .then({ __result in __promiseHolder.resolve(__result) })
129
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
130
+ return __promise
131
+ }()
132
+ return bridge.create_Result_std__shared_ptr_Promise_ConnectResult___(__resultCpp)
133
+ } catch (let __error) {
134
+ let __exceptionPtr = __error.toCpp()
135
+ return bridge.create_Result_std__shared_ptr_Promise_ConnectResult___(__exceptionPtr)
136
+ }
137
+ }
138
+
139
+ @inline(__always)
140
+ public final func signMessage(message: std.string) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
141
+ do {
142
+ let __result = try self.__implementation.signMessage(message: String(message))
143
+ let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
144
+ let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
145
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
146
+ __result
147
+ .then({ __result in __promiseHolder.resolve(std.string(__result)) })
148
+ .catch({ __error in __promiseHolder.reject(__error.toCpp()) })
149
+ return __promise
150
+ }()
151
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
152
+ } catch (let __error) {
153
+ let __exceptionPtr = __error.toCpp()
154
+ return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
155
+ }
156
+ }
157
+ }
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// ConnectResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+ #include <string>
34
+
35
+ namespace margelo::nitro::nitrometamask {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (ConnectResult).
39
+ */
40
+ struct ConnectResult final {
41
+ public:
42
+ std::string address SWIFT_PRIVATE;
43
+ std::string chainId SWIFT_PRIVATE;
44
+
45
+ public:
46
+ ConnectResult() = default;
47
+ explicit ConnectResult(std::string address, std::string chainId): address(address), chainId(chainId) {}
48
+
49
+ public:
50
+ friend bool operator==(const ConnectResult& lhs, const ConnectResult& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::nitrometamask
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ ConnectResult <> JS ConnectResult (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::nitrometamask::ConnectResult> final {
60
+ static inline margelo::nitro::nitrometamask::ConnectResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::nitrometamask::ConnectResult(
63
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "address"))),
64
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "chainId")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrometamask::ConnectResult& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "address"), JSIConverter<std::string>::toJSI(runtime, arg.address));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "chainId"), JSIConverter<std::string>::toJSI(runtime, arg.chainId));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "address")))) return false;
82
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "chainId")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,22 @@
1
+ ///
2
+ /// HybridMetamaskConnectorSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridMetamaskConnectorSpec.hpp"
9
+
10
+ namespace margelo::nitro::nitrometamask {
11
+
12
+ void HybridMetamaskConnectorSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("connect", &HybridMetamaskConnectorSpec::connect);
18
+ prototype.registerHybridMethod("signMessage", &HybridMetamaskConnectorSpec::signMessage);
19
+ });
20
+ }
21
+
22
+ } // namespace margelo::nitro::nitrometamask
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// HybridMetamaskConnectorSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `ConnectResult` to properly resolve imports.
17
+ namespace margelo::nitro::nitrometamask { struct ConnectResult; }
18
+
19
+ #include "ConnectResult.hpp"
20
+ #include <NitroModules/Promise.hpp>
21
+ #include <string>
22
+
23
+ namespace margelo::nitro::nitrometamask {
24
+
25
+ using namespace margelo::nitro;
26
+
27
+ /**
28
+ * An abstract base class for `MetamaskConnector`
29
+ * Inherit this class to create instances of `HybridMetamaskConnectorSpec` in C++.
30
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
31
+ * @example
32
+ * ```cpp
33
+ * class HybridMetamaskConnector: public HybridMetamaskConnectorSpec {
34
+ * public:
35
+ * HybridMetamaskConnector(...): HybridObject(TAG) { ... }
36
+ * // ...
37
+ * };
38
+ * ```
39
+ */
40
+ class HybridMetamaskConnectorSpec: public virtual HybridObject {
41
+ public:
42
+ // Constructor
43
+ explicit HybridMetamaskConnectorSpec(): HybridObject(TAG) { }
44
+
45
+ // Destructor
46
+ ~HybridMetamaskConnectorSpec() override = default;
47
+
48
+ public:
49
+ // Properties
50
+
51
+
52
+ public:
53
+ // Methods
54
+ virtual std::shared_ptr<Promise<ConnectResult>> connect() = 0;
55
+ virtual std::shared_ptr<Promise<std::string>> signMessage(const std::string& message) = 0;
56
+
57
+ protected:
58
+ // Hybrid Setup
59
+ void loadHybridMethods() override;
60
+
61
+ protected:
62
+ // Tag for logging
63
+ static constexpr auto TAG = "MetamaskConnector";
64
+ };
65
+
66
+ } // namespace margelo::nitro::nitrometamask
package/package.json ADDED
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "@novastera-oss/nitro-metamask",
3
+ "version": "0.1.3",
4
+ "description": "nitro-metamask",
5
+ "main": "lib/index",
6
+ "module": "lib/index",
7
+ "types": "lib/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "react-native.config.js",
13
+ "lib",
14
+ "nitrogen",
15
+ "android/build.gradle",
16
+ "android/gradle.properties",
17
+ "android/fix-prefab.gradle",
18
+ "android/CMakeLists.txt",
19
+ "android/src",
20
+ "ios/**/*.h",
21
+ "ios/**/*.m",
22
+ "ios/**/*.mm",
23
+ "ios/**/*.cpp",
24
+ "ios/**/*.swift",
25
+ "app.plugin.js",
26
+ "nitro.json",
27
+ "*.podspec",
28
+ "README.md"
29
+ ],
30
+ "scripts": {
31
+ "postinstall": "tsc || exit 0;",
32
+ "typecheck": "tsc --noEmit",
33
+ "clean": "rm -rf android/build node_modules/**/android/build lib",
34
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
35
+ "lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
36
+ "typescript": "tsc",
37
+ "specs": "tsc --noEmit false && nitrogen --logLevel=\"debug\""
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "nitro"
42
+ ],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/mrousavy/nitro.git"
46
+ },
47
+ "author": "Marc Rousavy <me@mrousavy.com> (https://github.com/mrousavy)",
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/mrousavy/nitro/issues"
51
+ },
52
+ "homepage": "https://github.com/mrousavy/nitro#readme",
53
+ "publishConfig": {
54
+ "registry": "https://registry.npmjs.org/"
55
+ },
56
+ "devDependencies": {
57
+ "@react-native/eslint-config": "0.82.0",
58
+ "@types/react": "^19.1.03",
59
+ "eslint": "^9.39.0",
60
+ "eslint-config-prettier": "^10.1.0",
61
+ "eslint-plugin-prettier": "^5.2.1",
62
+ "nitrogen": "^0.32.0",
63
+ "prettier": "^3.3.3",
64
+ "react": "19.1.1",
65
+ "react-native": "0.82.0",
66
+ "react-native-nitro-modules": "^0.32.0",
67
+ "typescript": "^5.8.3"
68
+ },
69
+ "peerDependencies": {
70
+ "react": "*",
71
+ "react-native": "*",
72
+ "react-native-nitro-modules": "^0.32.0"
73
+ },
74
+ "eslintConfig": {
75
+ "root": true,
76
+ "extends": [
77
+ "@react-native",
78
+ "prettier"
79
+ ],
80
+ "plugins": [
81
+ "prettier"
82
+ ],
83
+ "rules": {
84
+ "prettier/prettier": [
85
+ "warn",
86
+ {
87
+ "quoteProps": "consistent",
88
+ "singleQuote": true,
89
+ "tabWidth": 2,
90
+ "trailingComma": "es5",
91
+ "useTabs": false
92
+ }
93
+ ]
94
+ }
95
+ },
96
+ "eslintIgnore": [
97
+ "node_modules/",
98
+ "lib/"
99
+ ],
100
+ "prettier": {
101
+ "quoteProps": "consistent",
102
+ "singleQuote": true,
103
+ "tabWidth": 2,
104
+ "trailingComma": "es5",
105
+ "useTabs": false,
106
+ "semi": false
107
+ }
108
+ }
@@ -0,0 +1,16 @@
1
+ // https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
2
+
3
+ module.exports = {
4
+ dependency: {
5
+ platforms: {
6
+ /**
7
+ * @type {import('@react-native-community/cli-types').IOSDependencyParams}
8
+ */
9
+ ios: {},
10
+ /**
11
+ * @type {import('@react-native-community/cli-types').AndroidDependencyParams}
12
+ */
13
+ android: {},
14
+ },
15
+ },
16
+ }
@@ -0,0 +1,13 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+
3
+ export interface ConnectResult {
4
+ address: string
5
+ chainId: string
6
+ }
7
+
8
+ export interface MetamaskConnector
9
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
10
+ connect(): Promise<ConnectResult>
11
+ signMessage(message: string): Promise<string>
12
+ }
13
+
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { NitroModules } from 'react-native-nitro-modules'
2
+
3
+ import type { ConnectResult, MetamaskConnector } from './MetamaskConnector.nitro'
4
+
5
+ export const metamaskConnector =
6
+ NitroModules.createHybridObject<MetamaskConnector>('MetamaskConnector')
7
+
8
+ export type { ConnectResult, MetamaskConnector }
@@ -0,0 +1 @@
1
+ // TODO: Export specs that extend HybridObject<...> here