@l.x/hashcash-native 1.0.2 → 1.0.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 (67) hide show
  1. package/NitroHashcashNative.podspec +56 -0
  2. package/README.md +24 -0
  3. package/android/CMakeLists.txt +29 -0
  4. package/android/build.gradle +141 -0
  5. package/android/fix-prefab.gradle +51 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/hashcashnative/HybridHashcash.kt +113 -0
  10. package/android/src/main/java/com/margelo/nitro/hashcashnative/NitroHashcashNativePackage.kt +18 -0
  11. package/ios/Bridge.h +8 -0
  12. package/ios/HybridHashcash.swift +133 -0
  13. package/lib/benchmark.d.ts +74 -0
  14. package/lib/benchmark.d.ts.map +1 -0
  15. package/lib/benchmark.js +92 -0
  16. package/lib/benchmark.js.map +1 -0
  17. package/lib/index.d.ts +11 -0
  18. package/lib/index.d.ts.map +1 -0
  19. package/lib/index.js +10 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/specs/Hashcash.nitro.d.ts +59 -0
  22. package/lib/specs/Hashcash.nitro.d.ts.map +1 -0
  23. package/lib/specs/Hashcash.nitro.js +2 -0
  24. package/lib/specs/Hashcash.nitro.js.map +1 -0
  25. package/nitro.json +18 -0
  26. package/nitrogen/generated/.gitattributes +1 -0
  27. package/nitrogen/generated/android/NitroHashcashNative+autolinking.cmake +81 -0
  28. package/nitrogen/generated/android/NitroHashcashNative+autolinking.gradle +27 -0
  29. package/nitrogen/generated/android/NitroHashcashNativeOnLoad.cpp +44 -0
  30. package/nitrogen/generated/android/NitroHashcashNativeOnLoad.hpp +25 -0
  31. package/nitrogen/generated/android/c++/JFindProofParams.hpp +68 -0
  32. package/nitrogen/generated/android/c++/JHashcashChallenge.hpp +69 -0
  33. package/nitrogen/generated/android/c++/JHashcashProofResult.hpp +69 -0
  34. package/nitrogen/generated/android/c++/JHybridHashcashSpec.cpp +81 -0
  35. package/nitrogen/generated/android/c++/JHybridHashcashSpec.hpp +66 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/FindProofParams.kt +44 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashChallenge.kt +47 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashProofResult.kt +47 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HybridHashcashSpec.kt +62 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/NitroHashcashNativeOnLoad.kt +35 -0
  41. package/nitrogen/generated/ios/NitroHashcashNative+autolinking.rb +60 -0
  42. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.cpp +49 -0
  43. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.hpp +154 -0
  44. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Umbrella.hpp +55 -0
  45. package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.mm +33 -0
  46. package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.swift +25 -0
  47. package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.cpp +11 -0
  48. package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.hpp +92 -0
  49. package/nitrogen/generated/ios/swift/FindProofParams.swift +82 -0
  50. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  51. package/nitrogen/generated/ios/swift/Func_void_std__optional_HashcashProofResult_.swift +47 -0
  52. package/nitrogen/generated/ios/swift/HashcashChallenge.swift +69 -0
  53. package/nitrogen/generated/ios/swift/HashcashProofResult.swift +69 -0
  54. package/nitrogen/generated/ios/swift/HybridHashcashSpec.swift +57 -0
  55. package/nitrogen/generated/ios/swift/HybridHashcashSpec_cxx.swift +155 -0
  56. package/nitrogen/generated/shared/c++/FindProofParams.hpp +85 -0
  57. package/nitrogen/generated/shared/c++/HashcashChallenge.hpp +87 -0
  58. package/nitrogen/generated/shared/c++/HashcashProofResult.hpp +87 -0
  59. package/nitrogen/generated/shared/c++/HybridHashcashSpec.cpp +22 -0
  60. package/nitrogen/generated/shared/c++/HybridHashcashSpec.hpp +69 -0
  61. package/package.json +73 -1
  62. package/react-native.config.js +16 -0
  63. package/src/benchmark.ts +152 -0
  64. package/src/index.ts +23 -0
  65. package/src/specs/Hashcash.nitro.ts +64 -0
  66. package/index.d.ts +0 -1
  67. package/index.js +0 -1
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// JHybridHashcashSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "JHybridHashcashSpec.hpp"
9
+
10
+ // Forward declaration of `HashcashProofResult` to properly resolve imports.
11
+ namespace margelo::nitro::hashcashnative { struct HashcashProofResult; }
12
+ // Forward declaration of `FindProofParams` to properly resolve imports.
13
+ namespace margelo::nitro::hashcashnative { struct FindProofParams; }
14
+ // Forward declaration of `HashcashChallenge` to properly resolve imports.
15
+ namespace margelo::nitro::hashcashnative { struct HashcashChallenge; }
16
+
17
+ #include "HashcashProofResult.hpp"
18
+ #include <optional>
19
+ #include <NitroModules/Promise.hpp>
20
+ #include <NitroModules/JPromise.hpp>
21
+ #include "JHashcashProofResult.hpp"
22
+ #include <string>
23
+ #include "FindProofParams.hpp"
24
+ #include "JFindProofParams.hpp"
25
+ #include "HashcashChallenge.hpp"
26
+ #include "JHashcashChallenge.hpp"
27
+
28
+ namespace margelo::nitro::hashcashnative {
29
+
30
+ jni::local_ref<JHybridHashcashSpec::jhybriddata> JHybridHashcashSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
31
+ return makeCxxInstance(jThis);
32
+ }
33
+
34
+ void JHybridHashcashSpec::registerNatives() {
35
+ registerHybrid({
36
+ makeNativeMethod("initHybrid", JHybridHashcashSpec::initHybrid),
37
+ });
38
+ }
39
+
40
+ size_t JHybridHashcashSpec::getExternalMemorySize() noexcept {
41
+ static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
42
+ return method(_javaPart);
43
+ }
44
+
45
+ void JHybridHashcashSpec::dispose() noexcept {
46
+ static const auto method = javaClassStatic()->getMethod<void()>("dispose");
47
+ method(_javaPart);
48
+ }
49
+
50
+ std::string JHybridHashcashSpec::toString() {
51
+ static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
52
+ auto javaString = method(_javaPart);
53
+ return javaString->toStdString();
54
+ }
55
+
56
+ // Properties
57
+
58
+
59
+ // Methods
60
+ std::shared_ptr<Promise<std::optional<HashcashProofResult>>> JHybridHashcashSpec::findProof(const FindProofParams& params) {
61
+ static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JFindProofParams> /* params */)>("findProof");
62
+ auto __result = method(_javaPart, JFindProofParams::fromCpp(params));
63
+ return [&]() {
64
+ auto __promise = Promise<std::optional<HashcashProofResult>>::create();
65
+ __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
66
+ auto __result = jni::static_ref_cast<JHashcashProofResult>(__boxedResult);
67
+ __promise->resolve(__result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt);
68
+ });
69
+ __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
70
+ jni::JniException __jniError(__throwable);
71
+ __promise->reject(std::make_exception_ptr(__jniError));
72
+ });
73
+ return __promise;
74
+ }();
75
+ }
76
+ void JHybridHashcashSpec::cancel() {
77
+ static const auto method = javaClassStatic()->getMethod<void()>("cancel");
78
+ method(_javaPart);
79
+ }
80
+
81
+ } // namespace margelo::nitro::hashcashnative
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// HybridHashcashSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridHashcashSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::hashcashnative {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridHashcashSpec: public jni::HybridClass<JHybridHashcashSpec, JHybridObject>,
22
+ public virtual HybridHashcashSpec {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/hashcashnative/HybridHashcashSpec;";
25
+ static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
26
+ static void registerNatives();
27
+
28
+ protected:
29
+ // C++ constructor (called from Java via `initHybrid()`)
30
+ explicit JHybridHashcashSpec(jni::alias_ref<jhybridobject> jThis) :
31
+ HybridObject(HybridHashcashSpec::TAG),
32
+ HybridBase(jThis),
33
+ _javaPart(jni::make_global(jThis)) {}
34
+
35
+ public:
36
+ ~JHybridHashcashSpec() override {
37
+ // Hermes GC can destroy JS objects on a non-JNI Thread.
38
+ jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
39
+ }
40
+
41
+ public:
42
+ size_t getExternalMemorySize() noexcept override;
43
+ void dispose() noexcept override;
44
+ std::string toString() override;
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridHashcashSpec::javaobject>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ std::shared_ptr<Promise<std::optional<HashcashProofResult>>> findProof(const FindProofParams& params) override;
58
+ void cancel() override;
59
+
60
+ private:
61
+ friend HybridBase;
62
+ using HybridBase::HybridBase;
63
+ jni::global_ref<JHybridHashcashSpec::javaobject> _javaPart;
64
+ };
65
+
66
+ } // namespace margelo::nitro::hashcashnative
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// FindProofParams.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.hashcashnative
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "FindProofParams".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class FindProofParams(
20
+ @DoNotStrip
21
+ @Keep
22
+ val challenge: HashcashChallenge,
23
+ @DoNotStrip
24
+ @Keep
25
+ val rangeStart: Double?,
26
+ @DoNotStrip
27
+ @Keep
28
+ val rangeSize: Double?
29
+ ) {
30
+ /* primary constructor */
31
+
32
+ private companion object {
33
+ /**
34
+ * Constructor called from C++
35
+ */
36
+ @DoNotStrip
37
+ @Keep
38
+ @Suppress("unused")
39
+ @JvmStatic
40
+ private fun fromCpp(challenge: HashcashChallenge, rangeStart: Double?, rangeSize: Double?): FindProofParams {
41
+ return FindProofParams(challenge, rangeStart, rangeSize)
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// HashcashChallenge.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.hashcashnative
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "HashcashChallenge".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class HashcashChallenge(
20
+ @DoNotStrip
21
+ @Keep
22
+ val difficulty: Double,
23
+ @DoNotStrip
24
+ @Keep
25
+ val subject: String,
26
+ @DoNotStrip
27
+ @Keep
28
+ val nonce: String,
29
+ @DoNotStrip
30
+ @Keep
31
+ val maxProofLength: Double
32
+ ) {
33
+ /* primary constructor */
34
+
35
+ private companion object {
36
+ /**
37
+ * Constructor called from C++
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress("unused")
42
+ @JvmStatic
43
+ private fun fromCpp(difficulty: Double, subject: String, nonce: String, maxProofLength: Double): HashcashChallenge {
44
+ return HashcashChallenge(difficulty, subject, nonce, maxProofLength)
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// HashcashProofResult.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.hashcashnative
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "HashcashProofResult".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class HashcashProofResult(
20
+ @DoNotStrip
21
+ @Keep
22
+ val counter: String,
23
+ @DoNotStrip
24
+ @Keep
25
+ val hashBase64: String,
26
+ @DoNotStrip
27
+ @Keep
28
+ val attempts: Double,
29
+ @DoNotStrip
30
+ @Keep
31
+ val timeMs: Double
32
+ ) {
33
+ /* primary constructor */
34
+
35
+ private companion object {
36
+ /**
37
+ * Constructor called from C++
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress("unused")
42
+ @JvmStatic
43
+ private fun fromCpp(counter: String, hashBase64: String, attempts: Double, timeMs: Double): HashcashProofResult {
44
+ return HashcashProofResult(counter, hashBase64, attempts, timeMs)
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,62 @@
1
+ ///
2
+ /// HybridHashcashSpec.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.hashcashnative
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 Hashcash HybridObject.
18
+ * Implement this abstract class to create Kotlin-based instances of Hashcash.
19
+ */
20
+ @DoNotStrip
21
+ @Keep
22
+ @Suppress(
23
+ "KotlinJniMissingFunction", "unused",
24
+ "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
25
+ "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
26
+ )
27
+ abstract class HybridHashcashSpec: 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 Hashcash]"
43
+ }
44
+
45
+ // Properties
46
+
47
+
48
+ // Methods
49
+ @DoNotStrip
50
+ @Keep
51
+ abstract fun findProof(params: FindProofParams): Promise<HashcashProofResult?>
52
+
53
+ @DoNotStrip
54
+ @Keep
55
+ abstract fun cancel(): Unit
56
+
57
+ private external fun initHybrid(): HybridData
58
+
59
+ companion object {
60
+ protected const val TAG = "HybridHashcashSpec"
61
+ }
62
+ }
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroHashcashNativeOnLoad.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.hashcashnative
9
+
10
+ import android.util.Log
11
+
12
+ internal class NitroHashcashNativeOnLoad {
13
+ companion object {
14
+ private const val TAG = "NitroHashcashNativeOnLoad"
15
+ private var didLoad = false
16
+ /**
17
+ * Initializes the native part of "NitroHashcashNative".
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 NitroHashcashNative C++ library...")
25
+ System.loadLibrary("NitroHashcashNative")
26
+ Log.i(TAG, "Successfully loaded NitroHashcashNative C++ library!")
27
+ didLoad = true
28
+ } catch (e: Error) {
29
+ Log.e(TAG, "Failed to load NitroHashcashNative 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
+ # NitroHashcashNative+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © 2025 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/NitroHashcashNative+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 NitroHashcashNative 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/NitroHashcashNative-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 C)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ })
60
+ end
@@ -0,0 +1,49 @@
1
+ ///
2
+ /// NitroHashcashNative-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "NitroHashcashNative-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridHashcashSpecSwift.hpp"
12
+ #include "NitroHashcashNative-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
14
+
15
+ namespace margelo::nitro::hashcashnative::bridge::swift {
16
+
17
+ // pragma MARK: std::function<void(const std::optional<HashcashProofResult>& /* result */)>
18
+ Func_void_std__optional_HashcashProofResult_ create_Func_void_std__optional_HashcashProofResult_(void* NON_NULL swiftClosureWrapper) noexcept {
19
+ auto swiftClosure = NitroHashcashNative::Func_void_std__optional_HashcashProofResult_::fromUnsafe(swiftClosureWrapper);
20
+ return [swiftClosure = std::move(swiftClosure)](const std::optional<HashcashProofResult>& 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 = NitroHashcashNative::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::shared_ptr<HybridHashcashSpec>
34
+ std::shared_ptr<HybridHashcashSpec> create_std__shared_ptr_HybridHashcashSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
35
+ NitroHashcashNative::HybridHashcashSpec_cxx swiftPart = NitroHashcashNative::HybridHashcashSpec_cxx::fromUnsafe(swiftUnsafePointer);
36
+ return std::make_shared<margelo::nitro::hashcashnative::HybridHashcashSpecSwift>(swiftPart);
37
+ }
38
+ void* NON_NULL get_std__shared_ptr_HybridHashcashSpec_(std__shared_ptr_HybridHashcashSpec_ cppType) {
39
+ std::shared_ptr<margelo::nitro::hashcashnative::HybridHashcashSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::hashcashnative::HybridHashcashSpecSwift>(cppType);
40
+ #ifdef NITRO_DEBUG
41
+ if (swiftWrapper == nullptr) [[unlikely]] {
42
+ throw std::runtime_error("Class \"HybridHashcashSpec\" is not implemented in Swift!");
43
+ }
44
+ #endif
45
+ NitroHashcashNative::HybridHashcashSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
46
+ return swiftPart.toUnsafe();
47
+ }
48
+
49
+ } // namespace margelo::nitro::hashcashnative::bridge::swift
@@ -0,0 +1,154 @@
1
+ ///
2
+ /// NitroHashcashNative-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `HashcashProofResult` to properly resolve imports.
12
+ namespace margelo::nitro::hashcashnative { struct HashcashProofResult; }
13
+ // Forward declaration of `HybridHashcashSpec` to properly resolve imports.
14
+ namespace margelo::nitro::hashcashnative { class HybridHashcashSpec; }
15
+
16
+ // Forward declarations of Swift defined types
17
+ // Forward declaration of `HybridHashcashSpec_cxx` to properly resolve imports.
18
+ namespace NitroHashcashNative { class HybridHashcashSpec_cxx; }
19
+
20
+ // Include C++ defined types
21
+ #include "HashcashProofResult.hpp"
22
+ #include "HybridHashcashSpec.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 <optional>
30
+ #include <string>
31
+
32
+ /**
33
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
34
+ * as well as helper functions to interact with those C++ types from Swift.
35
+ */
36
+ namespace margelo::nitro::hashcashnative::bridge::swift {
37
+
38
+ // pragma MARK: std::optional<HashcashProofResult>
39
+ /**
40
+ * Specialized version of `std::optional<HashcashProofResult>`.
41
+ */
42
+ using std__optional_HashcashProofResult_ = std::optional<HashcashProofResult>;
43
+ inline std::optional<HashcashProofResult> create_std__optional_HashcashProofResult_(const HashcashProofResult& value) noexcept {
44
+ return std::optional<HashcashProofResult>(value);
45
+ }
46
+ inline bool has_value_std__optional_HashcashProofResult_(const std::optional<HashcashProofResult>& optional) noexcept {
47
+ return optional.has_value();
48
+ }
49
+ inline HashcashProofResult get_std__optional_HashcashProofResult_(const std::optional<HashcashProofResult>& optional) noexcept {
50
+ return *optional;
51
+ }
52
+
53
+ // pragma MARK: std::shared_ptr<Promise<std::optional<HashcashProofResult>>>
54
+ /**
55
+ * Specialized version of `std::shared_ptr<Promise<std::optional<HashcashProofResult>>>`.
56
+ */
57
+ using std__shared_ptr_Promise_std__optional_HashcashProofResult___ = std::shared_ptr<Promise<std::optional<HashcashProofResult>>>;
58
+ inline std::shared_ptr<Promise<std::optional<HashcashProofResult>>> create_std__shared_ptr_Promise_std__optional_HashcashProofResult___() noexcept {
59
+ return Promise<std::optional<HashcashProofResult>>::create();
60
+ }
61
+ inline PromiseHolder<std::optional<HashcashProofResult>> wrap_std__shared_ptr_Promise_std__optional_HashcashProofResult___(std::shared_ptr<Promise<std::optional<HashcashProofResult>>> promise) noexcept {
62
+ return PromiseHolder<std::optional<HashcashProofResult>>(std::move(promise));
63
+ }
64
+
65
+ // pragma MARK: std::function<void(const std::optional<HashcashProofResult>& /* result */)>
66
+ /**
67
+ * Specialized version of `std::function<void(const std::optional<HashcashProofResult>&)>`.
68
+ */
69
+ using Func_void_std__optional_HashcashProofResult_ = std::function<void(const std::optional<HashcashProofResult>& /* result */)>;
70
+ /**
71
+ * Wrapper class for a `std::function<void(const std::optional<HashcashProofResult>& / * result * /)>`, this can be used from Swift.
72
+ */
73
+ class Func_void_std__optional_HashcashProofResult__Wrapper final {
74
+ public:
75
+ explicit Func_void_std__optional_HashcashProofResult__Wrapper(std::function<void(const std::optional<HashcashProofResult>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::optional<HashcashProofResult>& /* result */)>>(std::move(func))) {}
76
+ inline void call(std::optional<HashcashProofResult> result) const noexcept {
77
+ _function->operator()(result);
78
+ }
79
+ private:
80
+ std::unique_ptr<std::function<void(const std::optional<HashcashProofResult>& /* result */)>> _function;
81
+ } SWIFT_NONCOPYABLE;
82
+ Func_void_std__optional_HashcashProofResult_ create_Func_void_std__optional_HashcashProofResult_(void* NON_NULL swiftClosureWrapper) noexcept;
83
+ inline Func_void_std__optional_HashcashProofResult__Wrapper wrap_Func_void_std__optional_HashcashProofResult_(Func_void_std__optional_HashcashProofResult_ value) noexcept {
84
+ return Func_void_std__optional_HashcashProofResult__Wrapper(std::move(value));
85
+ }
86
+
87
+ // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
88
+ /**
89
+ * Specialized version of `std::function<void(const std::exception_ptr&)>`.
90
+ */
91
+ using Func_void_std__exception_ptr = std::function<void(const std::exception_ptr& /* error */)>;
92
+ /**
93
+ * Wrapper class for a `std::function<void(const std::exception_ptr& / * error * /)>`, this can be used from Swift.
94
+ */
95
+ class Func_void_std__exception_ptr_Wrapper final {
96
+ public:
97
+ 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))) {}
98
+ inline void call(std::exception_ptr error) const noexcept {
99
+ _function->operator()(error);
100
+ }
101
+ private:
102
+ std::unique_ptr<std::function<void(const std::exception_ptr& /* error */)>> _function;
103
+ } SWIFT_NONCOPYABLE;
104
+ Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept;
105
+ inline Func_void_std__exception_ptr_Wrapper wrap_Func_void_std__exception_ptr(Func_void_std__exception_ptr value) noexcept {
106
+ return Func_void_std__exception_ptr_Wrapper(std::move(value));
107
+ }
108
+
109
+ // pragma MARK: std::optional<double>
110
+ /**
111
+ * Specialized version of `std::optional<double>`.
112
+ */
113
+ using std__optional_double_ = std::optional<double>;
114
+ inline std::optional<double> create_std__optional_double_(const double& value) noexcept {
115
+ return std::optional<double>(value);
116
+ }
117
+ inline bool has_value_std__optional_double_(const std::optional<double>& optional) noexcept {
118
+ return optional.has_value();
119
+ }
120
+ inline double get_std__optional_double_(const std::optional<double>& optional) noexcept {
121
+ return *optional;
122
+ }
123
+
124
+ // pragma MARK: std::shared_ptr<HybridHashcashSpec>
125
+ /**
126
+ * Specialized version of `std::shared_ptr<HybridHashcashSpec>`.
127
+ */
128
+ using std__shared_ptr_HybridHashcashSpec_ = std::shared_ptr<HybridHashcashSpec>;
129
+ std::shared_ptr<HybridHashcashSpec> create_std__shared_ptr_HybridHashcashSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
130
+ void* NON_NULL get_std__shared_ptr_HybridHashcashSpec_(std__shared_ptr_HybridHashcashSpec_ cppType);
131
+
132
+ // pragma MARK: std::weak_ptr<HybridHashcashSpec>
133
+ using std__weak_ptr_HybridHashcashSpec_ = std::weak_ptr<HybridHashcashSpec>;
134
+ inline std__weak_ptr_HybridHashcashSpec_ weakify_std__shared_ptr_HybridHashcashSpec_(const std::shared_ptr<HybridHashcashSpec>& strong) noexcept { return strong; }
135
+
136
+ // pragma MARK: Result<std::shared_ptr<Promise<std::optional<HashcashProofResult>>>>
137
+ using Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____ = Result<std::shared_ptr<Promise<std::optional<HashcashProofResult>>>>;
138
+ inline Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____ create_Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____(const std::shared_ptr<Promise<std::optional<HashcashProofResult>>>& value) noexcept {
139
+ return Result<std::shared_ptr<Promise<std::optional<HashcashProofResult>>>>::withValue(value);
140
+ }
141
+ inline Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____ create_Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____(const std::exception_ptr& error) noexcept {
142
+ return Result<std::shared_ptr<Promise<std::optional<HashcashProofResult>>>>::withError(error);
143
+ }
144
+
145
+ // pragma MARK: Result<void>
146
+ using Result_void_ = Result<void>;
147
+ inline Result_void_ create_Result_void_() noexcept {
148
+ return Result<void>::withValue();
149
+ }
150
+ inline Result_void_ create_Result_void_(const std::exception_ptr& error) noexcept {
151
+ return Result<void>::withError(error);
152
+ }
153
+
154
+ } // namespace margelo::nitro::hashcashnative::bridge::swift