@novastera-oss/nitro-metamask 0.2.7 → 0.3.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.
- package/LICENSE +21 -201
- package/NitroMetamask.podspec +1 -1
- package/README.md +16 -249
- package/android/CMakeLists.txt +3 -0
- package/android/build.gradle +25 -19
- package/android/fix-prefab.gradle +1 -1
- package/android/gradle.properties +2 -2
- package/android/src/main/java/com/{margelo/nitro/nitrometamask/HybridMetamaskConnector.kt → nitrometamask/HybridNitroMetamask.kt} +40 -20
- package/android/src/main/java/com/nitrometamask/MetamaskContextHolder.kt +15 -0
- package/android/src/main/java/com/nitrometamask/NitroMetamaskPackage.kt +53 -0
- package/ios/Bridge.h +2 -2
- package/ios/{HybridMetamaskConnector.swift → HybridNitroMetamask.swift} +1 -2
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/nitro-metamask.nitro.js +6 -0
- package/lib/commonjs/specs/nitro-metamask.nitro.js.map +1 -0
- package/lib/module/index.js +16 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/nitro-metamask.nitro.js +4 -0
- package/lib/module/specs/nitro-metamask.nitro.js.map +1 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/{MetamaskConnector.nitro.d.ts → typescript/src/specs/nitro-metamask.nitro.d.ts} +3 -2
- package/lib/typescript/src/specs/nitro-metamask.nitro.d.ts.map +1 -0
- package/nitro.json +4 -4
- package/nitrogen/generated/android/NitroMetamask+autolinking.cmake +2 -2
- package/nitrogen/generated/android/NitroMetamaskOnLoad.cpp +4 -4
- package/nitrogen/generated/android/c++/{JHybridMetamaskConnectorSpec.cpp → JHybridNitroMetamaskSpec.cpp} +10 -10
- package/nitrogen/generated/android/c++/{JHybridMetamaskConnectorSpec.hpp → JHybridNitroMetamaskSpec.hpp} +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/{HybridMetamaskConnectorSpec.kt → HybridNitroMetamaskSpec.kt} +6 -6
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.cpp +9 -9
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.hpp +13 -13
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Umbrella.hpp +5 -5
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.mm +3 -3
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.swift +6 -6
- package/nitrogen/generated/ios/c++/{HybridMetamaskConnectorSpecSwift.cpp → HybridNitroMetamaskSpecSwift.cpp} +2 -2
- package/nitrogen/generated/ios/c++/{HybridMetamaskConnectorSpecSwift.hpp → HybridNitroMetamaskSpecSwift.hpp} +12 -12
- package/nitrogen/generated/ios/swift/HybridNitroMetamaskSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/{HybridMetamaskConnectorSpec_cxx.swift → HybridNitroMetamaskSpec_cxx.swift} +18 -18
- package/nitrogen/generated/shared/c++/{HybridMetamaskConnectorSpec.cpp → HybridNitroMetamaskSpec.cpp} +5 -5
- package/nitrogen/generated/shared/c++/{HybridMetamaskConnectorSpec.hpp → HybridNitroMetamaskSpec.hpp} +9 -9
- package/package.json +55 -39
- package/react-native.config.js +4 -1
- package/src/index.ts +14 -5
- package/src/specs/nitro-metamask.nitro.ts +11 -0
- package/android/src/main/java/com/margelo/nitro/nitrometamask/MetamaskContextHolder.kt +0 -36
- package/android/src/main/java/com/margelo/nitro/nitrometamask/NitroMetamaskPackage.kt +0 -24
- package/lib/MetamaskConnector.nitro.js +0 -1
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -2
- package/lib/specs/Example.nitro.d.ts +0 -0
- package/lib/specs/Example.nitro.js +0 -2
- package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec.swift +0 -57
- package/src/MetamaskConnector.nitro.ts +0 -13
- package/src/specs/Example.nitro.ts +0 -1
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
11
|
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
12
12
|
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
13
|
-
// Forward declaration of `
|
|
14
|
-
namespace margelo::nitro::nitrometamask { class
|
|
13
|
+
// Forward declaration of `HybridNitroMetamaskSpec` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrometamask { class HybridNitroMetamaskSpec; }
|
|
15
15
|
|
|
16
16
|
// Include C++ defined types
|
|
17
17
|
#include "ConnectResult.hpp"
|
|
18
|
-
#include "
|
|
18
|
+
#include "HybridNitroMetamaskSpec.hpp"
|
|
19
19
|
#include <NitroModules/Promise.hpp>
|
|
20
20
|
#include <NitroModules/Result.hpp>
|
|
21
21
|
#include <exception>
|
|
@@ -32,8 +32,8 @@ namespace margelo::nitro::nitrometamask { class HybridMetamaskConnectorSpec; }
|
|
|
32
32
|
#include <NitroModules/DateToChronoDate.hpp>
|
|
33
33
|
|
|
34
34
|
// Forward declarations of Swift defined types
|
|
35
|
-
// Forward declaration of `
|
|
36
|
-
namespace NitroMetamask { class
|
|
35
|
+
// Forward declaration of `HybridNitroMetamaskSpec_cxx` to properly resolve imports.
|
|
36
|
+
namespace NitroMetamask { class HybridNitroMetamaskSpec_cxx; }
|
|
37
37
|
|
|
38
38
|
// Include Swift defined types
|
|
39
39
|
#if __has_include("NitroMetamask-Swift.h")
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#import "NitroMetamask-Swift-Cxx-Umbrella.hpp"
|
|
11
11
|
#import <type_traits>
|
|
12
12
|
|
|
13
|
-
#include "
|
|
13
|
+
#include "HybridNitroMetamaskSpecSwift.hpp"
|
|
14
14
|
|
|
15
15
|
@interface NitroMetamaskAutolinking : NSObject
|
|
16
16
|
@end
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
using namespace margelo::nitro::nitrometamask;
|
|
23
23
|
|
|
24
24
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
25
|
-
"
|
|
25
|
+
"NitroMetamask",
|
|
26
26
|
[]() -> std::shared_ptr<HybridObject> {
|
|
27
|
-
std::shared_ptr<
|
|
27
|
+
std::shared_ptr<HybridNitroMetamaskSpec> hybridObject = NitroMetamask::NitroMetamaskAutolinking::createNitroMetamask();
|
|
28
28
|
return hybridObject;
|
|
29
29
|
}
|
|
30
30
|
);
|
|
@@ -9,15 +9,15 @@ public final class NitroMetamaskAutolinking {
|
|
|
9
9
|
public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Creates an instance of a Swift class that implements `
|
|
13
|
-
* and wraps it in a Swift class that can directly interop with C++ (`
|
|
12
|
+
* Creates an instance of a Swift class that implements `HybridNitroMetamaskSpec`,
|
|
13
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridNitroMetamaskSpec_cxx`)
|
|
14
14
|
*
|
|
15
15
|
* This is generated by Nitrogen and will initialize the class specified
|
|
16
|
-
* in the `"autolinking"` property of `nitro.json` (in this case, `
|
|
16
|
+
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridNitroMetamask`).
|
|
17
17
|
*/
|
|
18
|
-
public static func
|
|
19
|
-
let hybridObject =
|
|
20
|
-
return { () -> bridge.
|
|
18
|
+
public static func createNitroMetamask() -> bridge.std__shared_ptr_HybridNitroMetamaskSpec_ {
|
|
19
|
+
let hybridObject = HybridNitroMetamask()
|
|
20
|
+
return { () -> bridge.std__shared_ptr_HybridNitroMetamaskSpec_ in
|
|
21
21
|
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
22
22
|
return __cxxWrapped.getCxxPart()
|
|
23
23
|
}()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpecSwift.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "HybridNitroMetamaskSpecSwift.hpp"
|
|
9
9
|
|
|
10
10
|
namespace margelo::nitro::nitrometamask {
|
|
11
11
|
} // namespace margelo::nitro::nitrometamask
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpecSwift.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
|
-
#include "
|
|
10
|
+
#include "HybridNitroMetamaskSpec.hpp"
|
|
11
11
|
|
|
12
|
-
// Forward declaration of `
|
|
13
|
-
namespace NitroMetamask { class
|
|
12
|
+
// Forward declaration of `HybridNitroMetamaskSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace NitroMetamask { class HybridNitroMetamaskSpec_cxx; }
|
|
14
14
|
|
|
15
15
|
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
16
16
|
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
@@ -24,25 +24,25 @@ namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
|
24
24
|
namespace margelo::nitro::nitrometamask {
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* The C++ part of
|
|
27
|
+
* The C++ part of HybridNitroMetamaskSpec_cxx.swift.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
29
|
+
* HybridNitroMetamaskSpecSwift (C++) accesses HybridNitroMetamaskSpec_cxx (Swift), and might
|
|
30
30
|
* contain some additional bridging code for C++ <> Swift interop.
|
|
31
31
|
*
|
|
32
32
|
* Since this obviously introduces an overhead, I hope at some point in
|
|
33
|
-
* the future,
|
|
33
|
+
* the future, HybridNitroMetamaskSpec_cxx can directly inherit from the C++ class HybridNitroMetamaskSpec
|
|
34
34
|
* to simplify the whole structure and memory management.
|
|
35
35
|
*/
|
|
36
|
-
class
|
|
36
|
+
class HybridNitroMetamaskSpecSwift: public virtual HybridNitroMetamaskSpec {
|
|
37
37
|
public:
|
|
38
38
|
// Constructor from a Swift instance
|
|
39
|
-
explicit
|
|
40
|
-
HybridObject(
|
|
39
|
+
explicit HybridNitroMetamaskSpecSwift(const NitroMetamask::HybridNitroMetamaskSpec_cxx& swiftPart):
|
|
40
|
+
HybridObject(HybridNitroMetamaskSpec::TAG),
|
|
41
41
|
_swiftPart(swiftPart) { }
|
|
42
42
|
|
|
43
43
|
public:
|
|
44
44
|
// Get the Swift part
|
|
45
|
-
inline NitroMetamask::
|
|
45
|
+
inline NitroMetamask::HybridNitroMetamaskSpec_cxx& getSwiftPart() noexcept {
|
|
46
46
|
return _swiftPart;
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -81,7 +81,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
private:
|
|
84
|
-
NitroMetamask::
|
|
84
|
+
NitroMetamask::HybridNitroMetamaskSpec_cxx _swiftPart;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
} // namespace margelo::nitro::nitrometamask
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroMetamaskSpec.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 ``HybridNitroMetamaskSpec``
|
|
12
|
+
public protocol HybridNitroMetamaskSpec_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 HybridNitroMetamaskSpec_protocol {
|
|
22
|
+
/// Default implementation of ``HybridObject.toString``
|
|
23
|
+
func toString() -> String {
|
|
24
|
+
return "[HybridObject NitroMetamask]"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// See ``HybridNitroMetamaskSpec``
|
|
29
|
+
open class HybridNitroMetamaskSpec_base {
|
|
30
|
+
private weak var cxxWrapper: HybridNitroMetamaskSpec_cxx? = nil
|
|
31
|
+
public init() { }
|
|
32
|
+
public func getCxxWrapper() -> HybridNitroMetamaskSpec_cxx {
|
|
33
|
+
#if DEBUG
|
|
34
|
+
guard self is HybridNitroMetamaskSpec else {
|
|
35
|
+
fatalError("`self` is not a `HybridNitroMetamaskSpec`! Did you accidentally inherit from `HybridNitroMetamaskSpec_base` instead of `HybridNitroMetamaskSpec`?")
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
39
|
+
return cxxWrapper
|
|
40
|
+
} else {
|
|
41
|
+
let cxxWrapper = HybridNitroMetamaskSpec_cxx(self as! HybridNitroMetamaskSpec)
|
|
42
|
+
self.cxxWrapper = cxxWrapper
|
|
43
|
+
return cxxWrapper
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A Swift base-protocol representing the NitroMetamask HybridObject.
|
|
50
|
+
* Implement this protocol to create Swift-based instances of NitroMetamask.
|
|
51
|
+
* ```swift
|
|
52
|
+
* class HybridNitroMetamask : HybridNitroMetamaskSpec {
|
|
53
|
+
* // ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
public typealias HybridNitroMetamaskSpec = HybridNitroMetamaskSpec_protocol & HybridNitroMetamaskSpec_base
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpec_cxx.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
@@ -9,7 +9,7 @@ import Foundation
|
|
|
9
9
|
import NitroModules
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* A class implementation that bridges
|
|
12
|
+
* A class implementation that bridges HybridNitroMetamaskSpec over to C++.
|
|
13
13
|
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
14
|
*
|
|
15
15
|
* Also, some Swift types need to be bridged with special handling:
|
|
@@ -17,7 +17,7 @@ import NitroModules
|
|
|
17
17
|
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
18
|
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
19
|
*/
|
|
20
|
-
open class
|
|
20
|
+
open class HybridNitroMetamaskSpec_cxx {
|
|
21
21
|
/**
|
|
22
22
|
* The Swift <> C++ bridge's namespace (`margelo::nitro::nitrometamask::bridge::swift`)
|
|
23
23
|
* from `NitroMetamask-Swift-Cxx-Bridge.hpp`.
|
|
@@ -26,30 +26,30 @@ open class HybridMetamaskConnectorSpec_cxx {
|
|
|
26
26
|
public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* Holds an instance of the `
|
|
29
|
+
* Holds an instance of the `HybridNitroMetamaskSpec` Swift protocol.
|
|
30
30
|
*/
|
|
31
|
-
private var __implementation: any
|
|
31
|
+
private var __implementation: any HybridNitroMetamaskSpec
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
35
|
*/
|
|
36
|
-
private var __cxxPart: bridge.
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridNitroMetamaskSpec_
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Create a new `
|
|
39
|
+
* Create a new `HybridNitroMetamaskSpec_cxx` that wraps the given `HybridNitroMetamaskSpec`.
|
|
40
40
|
* All properties and methods bridge to C++ types.
|
|
41
41
|
*/
|
|
42
|
-
public init(_ implementation: any
|
|
42
|
+
public init(_ implementation: any HybridNitroMetamaskSpec) {
|
|
43
43
|
self.__implementation = implementation
|
|
44
44
|
self.__cxxPart = .init()
|
|
45
45
|
/* no base class */
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Get the actual `
|
|
49
|
+
* Get the actual `HybridNitroMetamaskSpec` instance this class wraps.
|
|
50
50
|
*/
|
|
51
51
|
@inline(__always)
|
|
52
|
-
public func
|
|
52
|
+
public func getHybridNitroMetamaskSpec() -> any HybridNitroMetamaskSpec {
|
|
53
53
|
return __implementation
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -62,25 +62,25 @@ open class HybridMetamaskConnectorSpec_cxx {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* Casts an unsafe pointer to a `
|
|
66
|
-
* The pointer has to be a retained opaque `Unmanaged<
|
|
65
|
+
* Casts an unsafe pointer to a `HybridNitroMetamaskSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridNitroMetamaskSpec_cxx>`.
|
|
67
67
|
* This removes one strong reference from the object!
|
|
68
68
|
*/
|
|
69
|
-
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) ->
|
|
70
|
-
return Unmanaged<
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNitroMetamaskSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridNitroMetamaskSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
-
* The C++ part is a `std::shared_ptr<
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridNitroMetamaskSpec>`.
|
|
76
76
|
*/
|
|
77
|
-
public func getCxxPart() -> bridge.
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridNitroMetamaskSpec_ {
|
|
78
78
|
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
79
|
if Bool(fromCxx: cachedCxxPart) {
|
|
80
80
|
return cachedCxxPart
|
|
81
81
|
} else {
|
|
82
|
-
let newCxxPart = bridge.
|
|
83
|
-
__cxxPart = bridge.
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridNitroMetamaskSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridNitroMetamaskSpec_(newCxxPart)
|
|
84
84
|
return newCxxPart
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "HybridNitroMetamaskSpec.hpp"
|
|
9
9
|
|
|
10
10
|
namespace margelo::nitro::nitrometamask {
|
|
11
11
|
|
|
12
|
-
void
|
|
12
|
+
void HybridNitroMetamaskSpec::loadHybridMethods() {
|
|
13
13
|
// load base methods/properties
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
-
prototype.registerHybridMethod("connect", &
|
|
18
|
-
prototype.registerHybridMethod("signMessage", &
|
|
17
|
+
prototype.registerHybridMethod("connect", &HybridNitroMetamaskSpec::connect);
|
|
18
|
+
prototype.registerHybridMethod("signMessage", &HybridNitroMetamaskSpec::signMessage);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
@@ -25,25 +25,25 @@ namespace margelo::nitro::nitrometamask {
|
|
|
25
25
|
using namespace margelo::nitro;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* An abstract base class for `
|
|
29
|
-
* Inherit this class to create instances of `
|
|
28
|
+
* An abstract base class for `NitroMetamask`
|
|
29
|
+
* Inherit this class to create instances of `HybridNitroMetamaskSpec` in C++.
|
|
30
30
|
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
31
31
|
* @example
|
|
32
32
|
* ```cpp
|
|
33
|
-
* class
|
|
33
|
+
* class HybridNitroMetamask: public HybridNitroMetamaskSpec {
|
|
34
34
|
* public:
|
|
35
|
-
*
|
|
35
|
+
* HybridNitroMetamask(...): HybridObject(TAG) { ... }
|
|
36
36
|
* // ...
|
|
37
37
|
* };
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
class
|
|
40
|
+
class HybridNitroMetamaskSpec: public virtual HybridObject {
|
|
41
41
|
public:
|
|
42
42
|
// Constructor
|
|
43
|
-
explicit
|
|
43
|
+
explicit HybridNitroMetamaskSpec(): HybridObject(TAG) { }
|
|
44
44
|
|
|
45
45
|
// Destructor
|
|
46
|
-
~
|
|
46
|
+
~HybridNitroMetamaskSpec() override = default;
|
|
47
47
|
|
|
48
48
|
public:
|
|
49
49
|
// Properties
|
|
@@ -60,7 +60,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
60
60
|
|
|
61
61
|
protected:
|
|
62
62
|
// Tag for logging
|
|
63
|
-
static constexpr auto TAG = "
|
|
63
|
+
static constexpr auto TAG = "NitroMetamask";
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
} // namespace margelo::nitro::nitrometamask
|
package/package.json
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novastera-oss/nitro-metamask",
|
|
3
|
-
"version": "0.2
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "lib/index",
|
|
6
|
-
"module": "lib/index",
|
|
7
|
-
"types": "lib/index.d.ts",
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"description": "Novastera metamask authentication with native mobile libraries",
|
|
5
|
+
"main": "./lib/commonjs/index.js",
|
|
6
|
+
"module": "./lib/module/index.js",
|
|
7
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
8
8
|
"react-native": "src/index",
|
|
9
9
|
"source": "src/index",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"clean": "git clean -dfX",
|
|
13
|
+
"release": "semantic-release",
|
|
14
|
+
"build": "npm run typecheck && bob build",
|
|
15
|
+
"codegen": "nitrogen --logLevel=\"debug\" && npm run build && node post-script.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react-native",
|
|
19
|
+
"@novastera-oss/nitro-metamask",
|
|
20
|
+
"metamask",
|
|
21
|
+
"novastera"
|
|
22
|
+
],
|
|
10
23
|
"files": [
|
|
11
24
|
"src",
|
|
12
25
|
"react-native.config.js",
|
|
13
26
|
"lib",
|
|
14
27
|
"nitrogen",
|
|
28
|
+
"cpp",
|
|
29
|
+
"nitro.json",
|
|
15
30
|
"android/build.gradle",
|
|
16
|
-
"android/gradle.properties",
|
|
17
31
|
"android/fix-prefab.gradle",
|
|
32
|
+
"android/gradle.properties",
|
|
18
33
|
"android/CMakeLists.txt",
|
|
19
34
|
"android/src",
|
|
20
35
|
"ios/**/*.h",
|
|
@@ -23,53 +38,40 @@
|
|
|
23
38
|
"ios/**/*.cpp",
|
|
24
39
|
"ios/**/*.swift",
|
|
25
40
|
"app.plugin.js",
|
|
26
|
-
"nitro.json",
|
|
27
41
|
"*.podspec",
|
|
28
42
|
"README.md"
|
|
29
43
|
],
|
|
30
|
-
"
|
|
31
|
-
"
|
|
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"
|
|
44
|
+
"workspaces": [
|
|
45
|
+
"example"
|
|
42
46
|
],
|
|
43
|
-
"repository":
|
|
44
|
-
|
|
45
|
-
"url": "https://github.com/novastera/nitro-metamask"
|
|
46
|
-
},
|
|
47
|
-
"author": "Novastera <hassan@novastera.com>",
|
|
47
|
+
"repository": "https://github.com/darksorrow/@novastera-oss/nitro-metamask.git",
|
|
48
|
+
"author": "DarkSorrow",
|
|
48
49
|
"license": "MIT",
|
|
49
|
-
"bugs":
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
"homepage": "https://novastera.com",
|
|
50
|
+
"bugs": "https://github.com/darksorrow/@novastera-oss/nitro-metamask/issues",
|
|
51
|
+
"homepage": "https://github.com/darksorrow/@novastera-oss/nitro-metamask#readme",
|
|
53
52
|
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
54
|
"registry": "https://registry.npmjs.org/"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"nitrogen": "
|
|
63
|
-
"
|
|
64
|
-
"react": "
|
|
65
|
-
"react-native": "0.
|
|
66
|
-
"react-native-nitro-modules": "
|
|
57
|
+
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
|
|
58
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
59
|
+
"@semantic-release/git": "^10.0.1",
|
|
60
|
+
"@types/jest": "^29.5.12",
|
|
61
|
+
"@types/react": "19.2.0",
|
|
62
|
+
"nitrogen": "0.32.0",
|
|
63
|
+
"react": "19.2.0",
|
|
64
|
+
"react-native": "0.83",
|
|
65
|
+
"react-native-builder-bob": "^0.40.17",
|
|
66
|
+
"react-native-nitro-modules": "0.32.0",
|
|
67
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
68
|
+
"semantic-release": "^25.0.2",
|
|
67
69
|
"typescript": "^5.8.3"
|
|
68
70
|
},
|
|
69
71
|
"peerDependencies": {
|
|
70
72
|
"react": "*",
|
|
71
73
|
"react-native": "*",
|
|
72
|
-
"react-native-nitro-modules": "
|
|
74
|
+
"react-native-nitro-modules": "*"
|
|
73
75
|
},
|
|
74
76
|
"eslintConfig": {
|
|
75
77
|
"root": true,
|
|
@@ -104,5 +106,19 @@
|
|
|
104
106
|
"trailingComma": "es5",
|
|
105
107
|
"useTabs": false,
|
|
106
108
|
"semi": false
|
|
109
|
+
},
|
|
110
|
+
"react-native-builder-bob": {
|
|
111
|
+
"source": "src",
|
|
112
|
+
"output": "lib",
|
|
113
|
+
"targets": [
|
|
114
|
+
"commonjs",
|
|
115
|
+
"module",
|
|
116
|
+
[
|
|
117
|
+
"typescript",
|
|
118
|
+
{
|
|
119
|
+
"project": "tsconfig.json"
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
]
|
|
107
123
|
}
|
|
108
124
|
}
|
package/react-native.config.js
CHANGED
|
@@ -10,7 +10,10 @@ module.exports = {
|
|
|
10
10
|
/**
|
|
11
11
|
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
12
|
*/
|
|
13
|
-
android: {
|
|
13
|
+
android: {
|
|
14
|
+
packageImportPath: 'import com.nitrometamask.NitroMetamaskPackage;',
|
|
15
|
+
packageInstance: 'new NitroMetamaskPackage()',
|
|
16
|
+
},
|
|
14
17
|
},
|
|
15
18
|
},
|
|
16
19
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { NitroMetamask as NitroMetamaskSpec, ConnectResult } from './specs/nitro-metamask.nitro'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* NitroMetamask - MetaMask connector for React Native
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { NitroMetamask } from '@novastera-oss/nitro-metamask'
|
|
10
|
+
*
|
|
11
|
+
* const result = await NitroMetamask.connect()
|
|
12
|
+
* const signature = await NitroMetamask.signMessage('Hello')
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const NitroMetamask = NitroModules.createHybridObject<NitroMetamaskSpec>('NitroMetamask')
|
|
4
16
|
|
|
5
|
-
export
|
|
6
|
-
NitroModules.createHybridObject<MetamaskConnector>('MetamaskConnector')
|
|
7
|
-
|
|
8
|
-
export type { ConnectResult, MetamaskConnector }
|
|
17
|
+
export type { ConnectResult, NitroMetamaskSpec }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HybridObject } from 'react-native-nitro-modules'
|
|
2
|
+
|
|
3
|
+
export interface ConnectResult {
|
|
4
|
+
address: string
|
|
5
|
+
chainId: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface NitroMetamask extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
|
|
9
|
+
connect(): Promise<ConnectResult>
|
|
10
|
+
signMessage(message: string): Promise<string>
|
|
11
|
+
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
package com.margelo.nitro.nitrometamask
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Context holder for MetaMask SDK initialization.
|
|
7
|
-
*
|
|
8
|
-
* Nitro does not provide Android Context access, so we must manage it ourselves.
|
|
9
|
-
* This pattern is used by all Nitro modules that need Context (VisionCamera, MMKV, etc.)
|
|
10
|
-
*
|
|
11
|
-
* The context is initialized from NitroMetamaskPackage when React Native loads the module.
|
|
12
|
-
*/
|
|
13
|
-
object MetamaskContextHolder {
|
|
14
|
-
@Volatile
|
|
15
|
-
private var appContext: Context? = null
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Initialize the context holder with the React Native application context.
|
|
19
|
-
* This should be called once from NitroMetamaskPackage.getModule()
|
|
20
|
-
*/
|
|
21
|
-
fun initialize(context: Context) {
|
|
22
|
-
appContext = context.applicationContext
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get the application context.
|
|
27
|
-
* Throws if not initialized - this ensures we fail fast if the package wasn't loaded correctly.
|
|
28
|
-
*/
|
|
29
|
-
fun get(): Context {
|
|
30
|
-
return appContext
|
|
31
|
-
?: throw IllegalStateException(
|
|
32
|
-
"MetamaskContextHolder not initialized. " +
|
|
33
|
-
"Make sure NitroMetamaskPackage is properly registered in your React Native app."
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
package com.margelo.nitro.nitrometamask
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.NativeModule
|
|
4
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
-
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
6
|
-
import com.facebook.react.BaseReactPackage
|
|
7
|
-
|
|
8
|
-
class NitroMetamaskPackage : BaseReactPackage() {
|
|
9
|
-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
10
|
-
// Initialize MetamaskContextHolder with React Native application context
|
|
11
|
-
// This is the ONLY way to get Context in Nitro modules - Nitro doesn't provide Context APIs
|
|
12
|
-
// The context is stored in our own holder and accessed by HybridMetamaskConnector
|
|
13
|
-
MetamaskContextHolder.initialize(reactContext)
|
|
14
|
-
return null
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
|
|
18
|
-
|
|
19
|
-
companion object {
|
|
20
|
-
init {
|
|
21
|
-
NitroMetamaskOnLoad.initializeNative()
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/index.d.ts
DELETED
package/lib/index.js
DELETED
|
File without changes
|