@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.
- package/LICENSE +201 -0
- package/NitroMetamask.podspec +32 -0
- package/README.md +262 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +144 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrometamask/HybridMetamaskConnector.kt +48 -0
- package/android/src/main/java/com/margelo/nitro/nitrometamask/NitroMetamaskPackage.kt +18 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridMetamaskConnector.swift +58 -0
- package/lib/MetamaskConnector.nitro.d.ts +12 -0
- package/lib/MetamaskConnector.nitro.js +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +2 -0
- package/lib/specs/Example.nitro.d.ts +0 -0
- package/lib/specs/Example.nitro.js +2 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/android/NitroMetamask+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroMetamask+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroMetamaskOnLoad.cpp +44 -0
- package/nitrogen/generated/android/NitroMetamaskOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JConnectResult.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridMetamaskConnectorSpec.cpp +84 -0
- package/nitrogen/generated/android/c++/JHybridMetamaskConnectorSpec.hpp +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/ConnectResult.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/HybridMetamaskConnectorSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/NitroMetamaskOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroMetamask+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.cpp +57 -0
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.hpp +157 -0
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Umbrella.hpp +48 -0
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridMetamaskConnectorSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMetamaskConnectorSpecSwift.hpp +87 -0
- package/nitrogen/generated/ios/swift/ConnectResult.swift +35 -0
- package/nitrogen/generated/ios/swift/Func_void_ConnectResult.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec_cxx.swift +157 -0
- package/nitrogen/generated/shared/c++/ConnectResult.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridMetamaskConnectorSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridMetamaskConnectorSpec.hpp +66 -0
- package/package.json +108 -0
- package/react-native.config.js +16 -0
- package/src/MetamaskConnector.nitro.ts +13 -0
- package/src/index.ts +8 -0
- package/src/specs/Example.nitro.ts +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ConnectResult.kt
|
|
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
|
+
package com.margelo.nitro.nitrometamask
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "ConnectResult".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class ConnectResult(
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
val address: String,
|
|
23
|
+
@DoNotStrip
|
|
24
|
+
@Keep
|
|
25
|
+
val chainId: String
|
|
26
|
+
) {
|
|
27
|
+
/* primary constructor */
|
|
28
|
+
|
|
29
|
+
companion object {
|
|
30
|
+
/**
|
|
31
|
+
* Constructor called from C++
|
|
32
|
+
*/
|
|
33
|
+
@DoNotStrip
|
|
34
|
+
@Keep
|
|
35
|
+
@Suppress("unused")
|
|
36
|
+
@JvmStatic
|
|
37
|
+
private fun fromCpp(address: String, chainId: String): ConnectResult {
|
|
38
|
+
return ConnectResult(address, chainId)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMetamaskConnectorSpec.kt
|
|
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
|
+
package com.margelo.nitro.nitrometamask
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
import com.margelo.nitro.core.HybridObject
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Kotlin class representing the MetamaskConnector HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of MetamaskConnector.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress(
|
|
23
|
+
"KotlinJniMissingFunction", "unused",
|
|
24
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
|
+
)
|
|
27
|
+
abstract class HybridMetamaskConnectorSpec: HybridObject() {
|
|
28
|
+
@DoNotStrip
|
|
29
|
+
private var mHybridData: HybridData = initHybrid()
|
|
30
|
+
|
|
31
|
+
init {
|
|
32
|
+
super.updateNative(mHybridData)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun updateNative(hybridData: HybridData) {
|
|
36
|
+
mHybridData = hybridData
|
|
37
|
+
super.updateNative(hybridData)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Default implementation of `HybridObject.toString()`
|
|
41
|
+
override fun toString(): String {
|
|
42
|
+
return "[HybridObject MetamaskConnector]"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Properties
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// Methods
|
|
49
|
+
@DoNotStrip
|
|
50
|
+
@Keep
|
|
51
|
+
abstract fun connect(): Promise<ConnectResult>
|
|
52
|
+
|
|
53
|
+
@DoNotStrip
|
|
54
|
+
@Keep
|
|
55
|
+
abstract fun signMessage(message: String): Promise<String>
|
|
56
|
+
|
|
57
|
+
private external fun initHybrid(): HybridData
|
|
58
|
+
|
|
59
|
+
companion object {
|
|
60
|
+
protected const val TAG = "HybridMetamaskConnectorSpec"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/NitroMetamaskOnLoad.kt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamaskOnLoad.kt
|
|
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
|
+
package com.margelo.nitro.nitrometamask
|
|
9
|
+
|
|
10
|
+
import android.util.Log
|
|
11
|
+
|
|
12
|
+
internal class NitroMetamaskOnLoad {
|
|
13
|
+
companion object {
|
|
14
|
+
private const val TAG = "NitroMetamaskOnLoad"
|
|
15
|
+
private var didLoad = false
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the native part of "NitroMetamask".
|
|
18
|
+
* This method is idempotent and can be called more than once.
|
|
19
|
+
*/
|
|
20
|
+
@JvmStatic
|
|
21
|
+
fun initializeNative() {
|
|
22
|
+
if (didLoad) return
|
|
23
|
+
try {
|
|
24
|
+
Log.i(TAG, "Loading NitroMetamask C++ library...")
|
|
25
|
+
System.loadLibrary("NitroMetamask")
|
|
26
|
+
Log.i(TAG, "Successfully loaded NitroMetamask C++ library!")
|
|
27
|
+
didLoad = true
|
|
28
|
+
} catch (e: Error) {
|
|
29
|
+
Log.e(TAG, "Failed to load NitroMetamask C++ library! Is it properly installed and linked? " +
|
|
30
|
+
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroMetamask+autolinking.rb
|
|
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
|
+
# This is a Ruby script that adds all files generated by Nitrogen
|
|
9
|
+
# to the given podspec.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your .podspec:
|
|
12
|
+
# ```ruby
|
|
13
|
+
# Pod::Spec.new do |spec|
|
|
14
|
+
# # ...
|
|
15
|
+
#
|
|
16
|
+
# # Add all files generated by Nitrogen
|
|
17
|
+
# load 'nitrogen/generated/ios/NitroMetamask+autolinking.rb'
|
|
18
|
+
# add_nitrogen_files(spec)
|
|
19
|
+
# end
|
|
20
|
+
# ```
|
|
21
|
+
|
|
22
|
+
def add_nitrogen_files(spec)
|
|
23
|
+
Pod::UI.puts "[NitroModules] 🔥 NitroMetamask is boosted by nitro!"
|
|
24
|
+
|
|
25
|
+
spec.dependency "NitroModules"
|
|
26
|
+
|
|
27
|
+
current_source_files = Array(spec.attributes_hash['source_files'])
|
|
28
|
+
spec.source_files = current_source_files + [
|
|
29
|
+
# Generated cross-platform specs
|
|
30
|
+
"nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
|
|
31
|
+
# Generated bridges for the cross-platform specs
|
|
32
|
+
"nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
current_public_header_files = Array(spec.attributes_hash['public_header_files'])
|
|
36
|
+
spec.public_header_files = current_public_header_files + [
|
|
37
|
+
# Generated specs
|
|
38
|
+
"nitrogen/generated/shared/**/*.{h,hpp}",
|
|
39
|
+
# Swift to C++ bridging helpers
|
|
40
|
+
"nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.hpp"
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
current_private_header_files = Array(spec.attributes_hash['private_header_files'])
|
|
44
|
+
spec.private_header_files = current_private_header_files + [
|
|
45
|
+
# iOS specific specs
|
|
46
|
+
"nitrogen/generated/ios/c++/**/*.{h,hpp}",
|
|
47
|
+
# Views are framework-specific and should be private
|
|
48
|
+
"nitrogen/generated/shared/**/views/**/*"
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
|
|
52
|
+
spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
|
|
53
|
+
# Use C++ 20
|
|
54
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
|
55
|
+
# Enables C++ <-> Swift interop (by default it's only ObjC)
|
|
56
|
+
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
|
|
57
|
+
# Enables stricter modular headers
|
|
58
|
+
"DEFINES_MODULE" => "YES",
|
|
59
|
+
})
|
|
60
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamask-Swift-Cxx-Bridge.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 "NitroMetamask-Swift-Cxx-Bridge.hpp"
|
|
9
|
+
|
|
10
|
+
// Include C++ implementation defined types
|
|
11
|
+
#include "HybridMetamaskConnectorSpecSwift.hpp"
|
|
12
|
+
#include "NitroMetamask-Swift-Cxx-Umbrella.hpp"
|
|
13
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::nitrometamask::bridge::swift {
|
|
16
|
+
|
|
17
|
+
// pragma MARK: std::function<void(const ConnectResult& /* result */)>
|
|
18
|
+
Func_void_ConnectResult create_Func_void_ConnectResult(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
19
|
+
auto swiftClosure = NitroMetamask::Func_void_ConnectResult::fromUnsafe(swiftClosureWrapper);
|
|
20
|
+
return [swiftClosure = std::move(swiftClosure)](const ConnectResult& result) mutable -> void {
|
|
21
|
+
swiftClosure.call(result);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
|
|
26
|
+
Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
27
|
+
auto swiftClosure = NitroMetamask::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
|
|
28
|
+
return [swiftClosure = std::move(swiftClosure)](const std::exception_ptr& error) mutable -> void {
|
|
29
|
+
swiftClosure.call(error);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// pragma MARK: std::function<void(const std::string& /* result */)>
|
|
34
|
+
Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
35
|
+
auto swiftClosure = NitroMetamask::Func_void_std__string::fromUnsafe(swiftClosureWrapper);
|
|
36
|
+
return [swiftClosure = std::move(swiftClosure)](const std::string& result) mutable -> void {
|
|
37
|
+
swiftClosure.call(result);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// pragma MARK: std::shared_ptr<HybridMetamaskConnectorSpec>
|
|
42
|
+
std::shared_ptr<HybridMetamaskConnectorSpec> create_std__shared_ptr_HybridMetamaskConnectorSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
43
|
+
NitroMetamask::HybridMetamaskConnectorSpec_cxx swiftPart = NitroMetamask::HybridMetamaskConnectorSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
44
|
+
return std::make_shared<margelo::nitro::nitrometamask::HybridMetamaskConnectorSpecSwift>(swiftPart);
|
|
45
|
+
}
|
|
46
|
+
void* NON_NULL get_std__shared_ptr_HybridMetamaskConnectorSpec_(std__shared_ptr_HybridMetamaskConnectorSpec_ cppType) {
|
|
47
|
+
std::shared_ptr<margelo::nitro::nitrometamask::HybridMetamaskConnectorSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::nitrometamask::HybridMetamaskConnectorSpecSwift>(cppType);
|
|
48
|
+
#ifdef NITRO_DEBUG
|
|
49
|
+
if (swiftWrapper == nullptr) [[unlikely]] {
|
|
50
|
+
throw std::runtime_error("Class \"HybridMetamaskConnectorSpec\" is not implemented in Swift!");
|
|
51
|
+
}
|
|
52
|
+
#endif
|
|
53
|
+
NitroMetamask::HybridMetamaskConnectorSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
54
|
+
return swiftPart.toUnsafe();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
} // namespace margelo::nitro::nitrometamask::bridge::swift
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamask-Swift-Cxx-Bridge.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
|
+
// Forward declarations of C++ defined types
|
|
11
|
+
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
13
|
+
// Forward declaration of `HybridMetamaskConnectorSpec` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrometamask { class HybridMetamaskConnectorSpec; }
|
|
15
|
+
|
|
16
|
+
// Forward declarations of Swift defined types
|
|
17
|
+
// Forward declaration of `HybridMetamaskConnectorSpec_cxx` to properly resolve imports.
|
|
18
|
+
namespace NitroMetamask { class HybridMetamaskConnectorSpec_cxx; }
|
|
19
|
+
|
|
20
|
+
// Include C++ defined types
|
|
21
|
+
#include "ConnectResult.hpp"
|
|
22
|
+
#include "HybridMetamaskConnectorSpec.hpp"
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include <NitroModules/PromiseHolder.hpp>
|
|
25
|
+
#include <NitroModules/Result.hpp>
|
|
26
|
+
#include <exception>
|
|
27
|
+
#include <functional>
|
|
28
|
+
#include <memory>
|
|
29
|
+
#include <string>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Contains specialized versions of C++ templated types so they can be accessed from Swift,
|
|
33
|
+
* as well as helper functions to interact with those C++ types from Swift.
|
|
34
|
+
*/
|
|
35
|
+
namespace margelo::nitro::nitrometamask::bridge::swift {
|
|
36
|
+
|
|
37
|
+
// pragma MARK: std::shared_ptr<Promise<ConnectResult>>
|
|
38
|
+
/**
|
|
39
|
+
* Specialized version of `std::shared_ptr<Promise<ConnectResult>>`.
|
|
40
|
+
*/
|
|
41
|
+
using std__shared_ptr_Promise_ConnectResult__ = std::shared_ptr<Promise<ConnectResult>>;
|
|
42
|
+
inline std::shared_ptr<Promise<ConnectResult>> create_std__shared_ptr_Promise_ConnectResult__() noexcept {
|
|
43
|
+
return Promise<ConnectResult>::create();
|
|
44
|
+
}
|
|
45
|
+
inline PromiseHolder<ConnectResult> wrap_std__shared_ptr_Promise_ConnectResult__(std::shared_ptr<Promise<ConnectResult>> promise) noexcept {
|
|
46
|
+
return PromiseHolder<ConnectResult>(std::move(promise));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// pragma MARK: std::function<void(const ConnectResult& /* result */)>
|
|
50
|
+
/**
|
|
51
|
+
* Specialized version of `std::function<void(const ConnectResult&)>`.
|
|
52
|
+
*/
|
|
53
|
+
using Func_void_ConnectResult = std::function<void(const ConnectResult& /* result */)>;
|
|
54
|
+
/**
|
|
55
|
+
* Wrapper class for a `std::function<void(const ConnectResult& / * result * /)>`, this can be used from Swift.
|
|
56
|
+
*/
|
|
57
|
+
class Func_void_ConnectResult_Wrapper final {
|
|
58
|
+
public:
|
|
59
|
+
explicit Func_void_ConnectResult_Wrapper(std::function<void(const ConnectResult& /* result */)>&& func): _function(std::make_unique<std::function<void(const ConnectResult& /* result */)>>(std::move(func))) {}
|
|
60
|
+
inline void call(ConnectResult result) const noexcept {
|
|
61
|
+
_function->operator()(result);
|
|
62
|
+
}
|
|
63
|
+
private:
|
|
64
|
+
std::unique_ptr<std::function<void(const ConnectResult& /* result */)>> _function;
|
|
65
|
+
} SWIFT_NONCOPYABLE;
|
|
66
|
+
Func_void_ConnectResult create_Func_void_ConnectResult(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
67
|
+
inline Func_void_ConnectResult_Wrapper wrap_Func_void_ConnectResult(Func_void_ConnectResult value) noexcept {
|
|
68
|
+
return Func_void_ConnectResult_Wrapper(std::move(value));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
|
|
72
|
+
/**
|
|
73
|
+
* Specialized version of `std::function<void(const std::exception_ptr&)>`.
|
|
74
|
+
*/
|
|
75
|
+
using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
|
|
76
|
+
/**
|
|
77
|
+
* Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
|
|
78
|
+
*/
|
|
79
|
+
class Func_void_std__exception_ptr_Wrapper final {
|
|
80
|
+
public:
|
|
81
|
+
explicit Func_void_std__exception_ptr_Wrapper(std::function<void(const std::exception_ptr& /* error */)>&& func): _function(std::make_unique<std::function<void(const std::exception_ptr& /* error */)>>(std::move(func))) {}
|
|
82
|
+
inline void call(std::exception_ptr error) const noexcept {
|
|
83
|
+
_function->operator()(error);
|
|
84
|
+
}
|
|
85
|
+
private:
|
|
86
|
+
std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
|
|
87
|
+
} SWIFT_NONCOPYABLE;
|
|
88
|
+
Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
89
|
+
inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
|
|
90
|
+
return Func_void_std__exception_ptr_Wrapper(std::move(value));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// pragma MARK: std::shared_ptr<Promise<std::string>>
|
|
94
|
+
/**
|
|
95
|
+
* Specialized version of `std::shared_ptr<Promise<std::string>>`.
|
|
96
|
+
*/
|
|
97
|
+
using std__shared_ptr_Promise_std__string__ = std::shared_ptr<Promise<std::string>>;
|
|
98
|
+
inline std::shared_ptr<Promise<std::string>> create_std__shared_ptr_Promise_std__string__() noexcept {
|
|
99
|
+
return Promise<std::string>::create();
|
|
100
|
+
}
|
|
101
|
+
inline PromiseHolder<std::string> wrap_std__shared_ptr_Promise_std__string__(std::shared_ptr<Promise<std::string>> promise) noexcept {
|
|
102
|
+
return PromiseHolder<std::string>(std::move(promise));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// pragma MARK: std::function<void(const std::string& /* result */)>
|
|
106
|
+
/**
|
|
107
|
+
* Specialized version of `std::function<void(const std::string&)>`.
|
|
108
|
+
*/
|
|
109
|
+
using Func_void_std__string = std::function<void(const std::string& /* result */)>;
|
|
110
|
+
/**
|
|
111
|
+
* Wrapper class for a `std::function<void(const std::string& / * result * /)>`, this can be used from Swift.
|
|
112
|
+
*/
|
|
113
|
+
class Func_void_std__string_Wrapper final {
|
|
114
|
+
public:
|
|
115
|
+
explicit Func_void_std__string_Wrapper(std::function<void(const std::string& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::string& /* result */)>>(std::move(func))) {}
|
|
116
|
+
inline void call(std::string result) const noexcept {
|
|
117
|
+
_function->operator()(result);
|
|
118
|
+
}
|
|
119
|
+
private:
|
|
120
|
+
std::unique_ptr<std::function<void(const std::string& /* result */)>> _function;
|
|
121
|
+
} SWIFT_NONCOPYABLE;
|
|
122
|
+
Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
123
|
+
inline Func_void_std__string_Wrapper wrap_Func_void_std__string(Func_void_std__string value) noexcept {
|
|
124
|
+
return Func_void_std__string_Wrapper(std::move(value));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// pragma MARK: std::shared_ptr<HybridMetamaskConnectorSpec>
|
|
128
|
+
/**
|
|
129
|
+
* Specialized version of `std::shared_ptr<HybridMetamaskConnectorSpec>`.
|
|
130
|
+
*/
|
|
131
|
+
using std__shared_ptr_HybridMetamaskConnectorSpec_ = std::shared_ptr<HybridMetamaskConnectorSpec>;
|
|
132
|
+
std::shared_ptr<HybridMetamaskConnectorSpec> create_std__shared_ptr_HybridMetamaskConnectorSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
133
|
+
void* NON_NULL get_std__shared_ptr_HybridMetamaskConnectorSpec_(std__shared_ptr_HybridMetamaskConnectorSpec_ cppType);
|
|
134
|
+
|
|
135
|
+
// pragma MARK: std::weak_ptr<HybridMetamaskConnectorSpec>
|
|
136
|
+
using std__weak_ptr_HybridMetamaskConnectorSpec_ = std::weak_ptr<HybridMetamaskConnectorSpec>;
|
|
137
|
+
inline std__weak_ptr_HybridMetamaskConnectorSpec_ weakify_std__shared_ptr_HybridMetamaskConnectorSpec_(const std::shared_ptr<HybridMetamaskConnectorSpec>& strong) noexcept { return strong; }
|
|
138
|
+
|
|
139
|
+
// pragma MARK: Result<std::shared_ptr<Promise<ConnectResult>>>
|
|
140
|
+
using Result_std__shared_ptr_Promise_ConnectResult___ = Result<std::shared_ptr<Promise<ConnectResult>>>;
|
|
141
|
+
inline Result_std__shared_ptr_Promise_ConnectResult___ create_Result_std__shared_ptr_Promise_ConnectResult___(const std::shared_ptr<Promise<ConnectResult>>& value) noexcept {
|
|
142
|
+
return Result<std::shared_ptr<Promise<ConnectResult>>>::withValue(value);
|
|
143
|
+
}
|
|
144
|
+
inline Result_std__shared_ptr_Promise_ConnectResult___ create_Result_std__shared_ptr_Promise_ConnectResult___(const std::exception_ptr& error) noexcept {
|
|
145
|
+
return Result<std::shared_ptr<Promise<ConnectResult>>>::withError(error);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
|
|
149
|
+
using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
|
|
150
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
|
|
151
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
|
|
152
|
+
}
|
|
153
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
|
|
154
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} // namespace margelo::nitro::nitrometamask::bridge::swift
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamask-Swift-Cxx-Umbrella.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
|
+
// Forward declarations of C++ defined types
|
|
11
|
+
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
13
|
+
// Forward declaration of `HybridMetamaskConnectorSpec` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrometamask { class HybridMetamaskConnectorSpec; }
|
|
15
|
+
|
|
16
|
+
// Include C++ defined types
|
|
17
|
+
#include "ConnectResult.hpp"
|
|
18
|
+
#include "HybridMetamaskConnectorSpec.hpp"
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
20
|
+
#include <NitroModules/Result.hpp>
|
|
21
|
+
#include <exception>
|
|
22
|
+
#include <memory>
|
|
23
|
+
#include <string>
|
|
24
|
+
|
|
25
|
+
// C++ helpers for Swift
|
|
26
|
+
#include "NitroMetamask-Swift-Cxx-Bridge.hpp"
|
|
27
|
+
|
|
28
|
+
// Common C++ types used in Swift
|
|
29
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
30
|
+
#include <NitroModules/AnyMapUtils.hpp>
|
|
31
|
+
#include <NitroModules/RuntimeError.hpp>
|
|
32
|
+
#include <NitroModules/DateToChronoDate.hpp>
|
|
33
|
+
|
|
34
|
+
// Forward declarations of Swift defined types
|
|
35
|
+
// Forward declaration of `HybridMetamaskConnectorSpec_cxx` to properly resolve imports.
|
|
36
|
+
namespace NitroMetamask { class HybridMetamaskConnectorSpec_cxx; }
|
|
37
|
+
|
|
38
|
+
// Include Swift defined types
|
|
39
|
+
#if __has_include("NitroMetamask-Swift.h")
|
|
40
|
+
// This header is generated by Xcode/Swift on every app build.
|
|
41
|
+
// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroMetamask".
|
|
42
|
+
#include "NitroMetamask-Swift.h"
|
|
43
|
+
// Same as above, but used when building with frameworks (`use_frameworks`)
|
|
44
|
+
#elif __has_include(<NitroMetamask/NitroMetamask-Swift.h>)
|
|
45
|
+
#include <NitroMetamask/NitroMetamask-Swift.h>
|
|
46
|
+
#else
|
|
47
|
+
#error NitroMetamask's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroMetamask", and try building the app first.
|
|
48
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamaskAutolinking.mm
|
|
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/Foundation.h>
|
|
9
|
+
#import <NitroModules/HybridObjectRegistry.hpp>
|
|
10
|
+
#import "NitroMetamask-Swift-Cxx-Umbrella.hpp"
|
|
11
|
+
#import <type_traits>
|
|
12
|
+
|
|
13
|
+
#include "HybridMetamaskConnectorSpecSwift.hpp"
|
|
14
|
+
|
|
15
|
+
@interface NitroMetamaskAutolinking : NSObject
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@implementation NitroMetamaskAutolinking
|
|
19
|
+
|
|
20
|
+
+ (void) load {
|
|
21
|
+
using namespace margelo::nitro;
|
|
22
|
+
using namespace margelo::nitro::nitrometamask;
|
|
23
|
+
|
|
24
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
25
|
+
"MetamaskConnector",
|
|
26
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
27
|
+
std::shared_ptr<HybridMetamaskConnectorSpec> hybridObject = NitroMetamask::NitroMetamaskAutolinking::createMetamaskConnector();
|
|
28
|
+
return hybridObject;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroMetamaskAutolinking.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
|
+
public final class NitroMetamaskAutolinking {
|
|
9
|
+
public typealias bridge = margelo.nitro.nitrometamask.bridge.swift
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of a Swift class that implements `HybridMetamaskConnectorSpec`,
|
|
13
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridMetamaskConnectorSpec_cxx`)
|
|
14
|
+
*
|
|
15
|
+
* This is generated by Nitrogen and will initialize the class specified
|
|
16
|
+
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridMetamaskConnector`).
|
|
17
|
+
*/
|
|
18
|
+
public static func createMetamaskConnector() -> bridge.std__shared_ptr_HybridMetamaskConnectorSpec_ {
|
|
19
|
+
let hybridObject = HybridMetamaskConnector()
|
|
20
|
+
return { () -> bridge.std__shared_ptr_HybridMetamaskConnectorSpec_ in
|
|
21
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
22
|
+
return __cxxWrapped.getCxxPart()
|
|
23
|
+
}()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMetamaskConnectorSpecSwift.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 "HybridMetamaskConnectorSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrometamask {
|
|
11
|
+
} // namespace margelo::nitro::nitrometamask
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridMetamaskConnectorSpecSwift.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
|
+
#include "HybridMetamaskConnectorSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridMetamaskConnectorSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace NitroMetamask { class HybridMetamaskConnectorSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
17
|
+
|
|
18
|
+
#include "ConnectResult.hpp"
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
20
|
+
#include <string>
|
|
21
|
+
|
|
22
|
+
#include "NitroMetamask-Swift-Cxx-Umbrella.hpp"
|
|
23
|
+
|
|
24
|
+
namespace margelo::nitro::nitrometamask {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The C++ part of HybridMetamaskConnectorSpec_cxx.swift.
|
|
28
|
+
*
|
|
29
|
+
* HybridMetamaskConnectorSpecSwift (C++) accesses HybridMetamaskConnectorSpec_cxx (Swift), and might
|
|
30
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
31
|
+
*
|
|
32
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
33
|
+
* the future, HybridMetamaskConnectorSpec_cxx can directly inherit from the C++ class HybridMetamaskConnectorSpec
|
|
34
|
+
* to simplify the whole structure and memory management.
|
|
35
|
+
*/
|
|
36
|
+
class HybridMetamaskConnectorSpecSwift: public virtual HybridMetamaskConnectorSpec {
|
|
37
|
+
public:
|
|
38
|
+
// Constructor from a Swift instance
|
|
39
|
+
explicit HybridMetamaskConnectorSpecSwift(const NitroMetamask::HybridMetamaskConnectorSpec_cxx& swiftPart):
|
|
40
|
+
HybridObject(HybridMetamaskConnectorSpec::TAG),
|
|
41
|
+
_swiftPart(swiftPart) { }
|
|
42
|
+
|
|
43
|
+
public:
|
|
44
|
+
// Get the Swift part
|
|
45
|
+
inline NitroMetamask::HybridMetamaskConnectorSpec_cxx& getSwiftPart() noexcept {
|
|
46
|
+
return _swiftPart;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
51
|
+
return _swiftPart.getMemorySize();
|
|
52
|
+
}
|
|
53
|
+
void dispose() noexcept override {
|
|
54
|
+
_swiftPart.dispose();
|
|
55
|
+
}
|
|
56
|
+
std::string toString() override {
|
|
57
|
+
return _swiftPart.toString();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
// Properties
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
// Methods
|
|
66
|
+
inline std::shared_ptr<Promise<ConnectResult>> connect() override {
|
|
67
|
+
auto __result = _swiftPart.connect();
|
|
68
|
+
if (__result.hasError()) [[unlikely]] {
|
|
69
|
+
std::rethrow_exception(__result.error());
|
|
70
|
+
}
|
|
71
|
+
auto __value = std::move(__result.value());
|
|
72
|
+
return __value;
|
|
73
|
+
}
|
|
74
|
+
inline std::shared_ptr<Promise<std::string>> signMessage(const std::string& message) override {
|
|
75
|
+
auto __result = _swiftPart.signMessage(message);
|
|
76
|
+
if (__result.hasError()) [[unlikely]] {
|
|
77
|
+
std::rethrow_exception(__result.error());
|
|
78
|
+
}
|
|
79
|
+
auto __value = std::move(__result.value());
|
|
80
|
+
return __value;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private:
|
|
84
|
+
NitroMetamask::HybridMetamaskConnectorSpec_cxx _swiftPart;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro::nitrometamask
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// 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
|
+
* Represents an instance of `ConnectResult`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias ConnectResult = margelo.nitro.nitrometamask.ConnectResult
|
|
15
|
+
|
|
16
|
+
public extension ConnectResult {
|
|
17
|
+
private typealias bridge = margelo.nitro.nitrometamask.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `ConnectResult`.
|
|
21
|
+
*/
|
|
22
|
+
init(address: String, chainId: String) {
|
|
23
|
+
self.init(std.string(address), std.string(chainId))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@inline(__always)
|
|
27
|
+
var address: String {
|
|
28
|
+
return String(self.__address)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@inline(__always)
|
|
32
|
+
var chainId: String {
|
|
33
|
+
return String(self.__chainId)
|
|
34
|
+
}
|
|
35
|
+
}
|