@l.x/hashcash-native 1.0.2 → 1.0.4
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 +122 -0
- package/NitroHashcashNative.podspec +56 -0
- package/README.md +24 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +141 -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/hashcashnative/HybridHashcash.kt +113 -0
- package/android/src/main/java/com/margelo/nitro/hashcashnative/NitroHashcashNativePackage.kt +18 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridHashcash.swift +133 -0
- package/lib/benchmark.d.ts +74 -0
- package/lib/benchmark.d.ts.map +1 -0
- package/lib/benchmark.js +92 -0
- package/lib/benchmark.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +10 -0
- package/lib/index.js.map +1 -0
- package/lib/specs/Hashcash.nitro.d.ts +59 -0
- package/lib/specs/Hashcash.nitro.d.ts.map +1 -0
- package/lib/specs/Hashcash.nitro.js +2 -0
- package/lib/specs/Hashcash.nitro.js.map +1 -0
- package/nitro.json +18 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroHashcashNative+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroHashcashNative+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroHashcashNativeOnLoad.cpp +44 -0
- package/nitrogen/generated/android/NitroHashcashNativeOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JFindProofParams.hpp +68 -0
- package/nitrogen/generated/android/c++/JHashcashChallenge.hpp +69 -0
- package/nitrogen/generated/android/c++/JHashcashProofResult.hpp +69 -0
- package/nitrogen/generated/android/c++/JHybridHashcashSpec.cpp +81 -0
- package/nitrogen/generated/android/c++/JHybridHashcashSpec.hpp +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/FindProofParams.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashChallenge.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashProofResult.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HybridHashcashSpec.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/NitroHashcashNativeOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroHashcashNative+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.hpp +154 -0
- package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Umbrella.hpp +55 -0
- package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/swift/FindProofParams.swift +82 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_HashcashProofResult_.swift +47 -0
- package/nitrogen/generated/ios/swift/HashcashChallenge.swift +69 -0
- package/nitrogen/generated/ios/swift/HashcashProofResult.swift +69 -0
- package/nitrogen/generated/ios/swift/HybridHashcashSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridHashcashSpec_cxx.swift +155 -0
- package/nitrogen/generated/shared/c++/FindProofParams.hpp +85 -0
- package/nitrogen/generated/shared/c++/HashcashChallenge.hpp +87 -0
- package/nitrogen/generated/shared/c++/HashcashProofResult.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridHashcashSpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridHashcashSpec.hpp +69 -0
- package/package.json +73 -1
- package/react-native.config.js +16 -0
- package/src/benchmark.ts +152 -0
- package/src/index.ts +23 -0
- package/src/specs/Hashcash.nitro.ts +64 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -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
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroHashcashNative-Swift-Cxx-Umbrella.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 `FindProofParams` to properly resolve imports.
|
|
12
|
+
namespace margelo::nitro::hashcashnative { struct FindProofParams; }
|
|
13
|
+
// Forward declaration of `HashcashChallenge` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::hashcashnative { struct HashcashChallenge; }
|
|
15
|
+
// Forward declaration of `HashcashProofResult` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::hashcashnative { struct HashcashProofResult; }
|
|
17
|
+
// Forward declaration of `HybridHashcashSpec` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::hashcashnative { class HybridHashcashSpec; }
|
|
19
|
+
|
|
20
|
+
// Include C++ defined types
|
|
21
|
+
#include "FindProofParams.hpp"
|
|
22
|
+
#include "HashcashChallenge.hpp"
|
|
23
|
+
#include "HashcashProofResult.hpp"
|
|
24
|
+
#include "HybridHashcashSpec.hpp"
|
|
25
|
+
#include <NitroModules/Promise.hpp>
|
|
26
|
+
#include <NitroModules/Result.hpp>
|
|
27
|
+
#include <exception>
|
|
28
|
+
#include <memory>
|
|
29
|
+
#include <optional>
|
|
30
|
+
#include <string>
|
|
31
|
+
|
|
32
|
+
// C++ helpers for Swift
|
|
33
|
+
#include "NitroHashcashNative-Swift-Cxx-Bridge.hpp"
|
|
34
|
+
|
|
35
|
+
// Common C++ types used in Swift
|
|
36
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
37
|
+
#include <NitroModules/AnyMapUtils.hpp>
|
|
38
|
+
#include <NitroModules/RuntimeError.hpp>
|
|
39
|
+
#include <NitroModules/DateToChronoDate.hpp>
|
|
40
|
+
|
|
41
|
+
// Forward declarations of Swift defined types
|
|
42
|
+
// Forward declaration of `HybridHashcashSpec_cxx` to properly resolve imports.
|
|
43
|
+
namespace NitroHashcashNative { class HybridHashcashSpec_cxx; }
|
|
44
|
+
|
|
45
|
+
// Include Swift defined types
|
|
46
|
+
#if __has_include("NitroHashcashNative-Swift.h")
|
|
47
|
+
// This header is generated by Xcode/Swift on every app build.
|
|
48
|
+
// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroHashcashNative".
|
|
49
|
+
#include "NitroHashcashNative-Swift.h"
|
|
50
|
+
// Same as above, but used when building with frameworks (`use_frameworks`)
|
|
51
|
+
#elif __has_include(<NitroHashcashNative/NitroHashcashNative-Swift.h>)
|
|
52
|
+
#include <NitroHashcashNative/NitroHashcashNative-Swift.h>
|
|
53
|
+
#else
|
|
54
|
+
#error NitroHashcashNative's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroHashcashNative", and try building the app first.
|
|
55
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroHashcashNativeAutolinking.mm
|
|
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
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <NitroModules/HybridObjectRegistry.hpp>
|
|
10
|
+
#import "NitroHashcashNative-Swift-Cxx-Umbrella.hpp"
|
|
11
|
+
#import <type_traits>
|
|
12
|
+
|
|
13
|
+
#include "HybridHashcashSpecSwift.hpp"
|
|
14
|
+
|
|
15
|
+
@interface NitroHashcashNativeAutolinking : NSObject
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
@implementation NitroHashcashNativeAutolinking
|
|
19
|
+
|
|
20
|
+
+ (void) load {
|
|
21
|
+
using namespace margelo::nitro;
|
|
22
|
+
using namespace margelo::nitro::hashcashnative;
|
|
23
|
+
|
|
24
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
25
|
+
"Hashcash",
|
|
26
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
27
|
+
std::shared_ptr<HybridHashcashSpec> hybridObject = NitroHashcashNative::NitroHashcashNativeAutolinking::createHashcash();
|
|
28
|
+
return hybridObject;
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroHashcashNativeAutolinking.swift
|
|
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
|
+
public final class NitroHashcashNativeAutolinking {
|
|
9
|
+
public typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of a Swift class that implements `HybridHashcashSpec`,
|
|
13
|
+
* and wraps it in a Swift class that can directly interop with C++ (`HybridHashcashSpec_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, `HybridHashcash`).
|
|
17
|
+
*/
|
|
18
|
+
public static func createHashcash() -> bridge.std__shared_ptr_HybridHashcashSpec_ {
|
|
19
|
+
let hybridObject = HybridHashcash()
|
|
20
|
+
return { () -> bridge.std__shared_ptr_HybridHashcashSpec_ in
|
|
21
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
22
|
+
return __cxxWrapped.getCxxPart()
|
|
23
|
+
}()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridHashcashSpecSwift.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 "HybridHashcashSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::hashcashnative {
|
|
11
|
+
} // namespace margelo::nitro::hashcashnative
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridHashcashSpecSwift.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 "HybridHashcashSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridHashcashSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace NitroHashcashNative { class HybridHashcashSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `HashcashProofResult` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::hashcashnative { struct HashcashProofResult; }
|
|
17
|
+
// Forward declaration of `FindProofParams` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::hashcashnative { struct FindProofParams; }
|
|
19
|
+
// Forward declaration of `HashcashChallenge` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::hashcashnative { struct HashcashChallenge; }
|
|
21
|
+
|
|
22
|
+
#include "HashcashProofResult.hpp"
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <NitroModules/Promise.hpp>
|
|
25
|
+
#include <string>
|
|
26
|
+
#include "FindProofParams.hpp"
|
|
27
|
+
#include "HashcashChallenge.hpp"
|
|
28
|
+
|
|
29
|
+
#include "NitroHashcashNative-Swift-Cxx-Umbrella.hpp"
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::hashcashnative {
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The C++ part of HybridHashcashSpec_cxx.swift.
|
|
35
|
+
*
|
|
36
|
+
* HybridHashcashSpecSwift (C++) accesses HybridHashcashSpec_cxx (Swift), and might
|
|
37
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
38
|
+
*
|
|
39
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
40
|
+
* the future, HybridHashcashSpec_cxx can directly inherit from the C++ class HybridHashcashSpec
|
|
41
|
+
* to simplify the whole structure and memory management.
|
|
42
|
+
*/
|
|
43
|
+
class HybridHashcashSpecSwift: public virtual HybridHashcashSpec {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor from a Swift instance
|
|
46
|
+
explicit HybridHashcashSpecSwift(const NitroHashcashNative::HybridHashcashSpec_cxx& swiftPart):
|
|
47
|
+
HybridObject(HybridHashcashSpec::TAG),
|
|
48
|
+
_swiftPart(swiftPart) { }
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
// Get the Swift part
|
|
52
|
+
inline NitroHashcashNative::HybridHashcashSpec_cxx& getSwiftPart() noexcept {
|
|
53
|
+
return _swiftPart;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
58
|
+
return _swiftPart.getMemorySize();
|
|
59
|
+
}
|
|
60
|
+
void dispose() noexcept override {
|
|
61
|
+
_swiftPart.dispose();
|
|
62
|
+
}
|
|
63
|
+
std::string toString() override {
|
|
64
|
+
return _swiftPart.toString();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public:
|
|
68
|
+
// Properties
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
public:
|
|
72
|
+
// Methods
|
|
73
|
+
inline std::shared_ptr<Promise<std::optional<HashcashProofResult>>> findProof(const FindProofParams& params) override {
|
|
74
|
+
auto __result = _swiftPart.findProof(std::forward<decltype(params)>(params));
|
|
75
|
+
if (__result.hasError()) [[unlikely]] {
|
|
76
|
+
std::rethrow_exception(__result.error());
|
|
77
|
+
}
|
|
78
|
+
auto __value = std::move(__result.value());
|
|
79
|
+
return __value;
|
|
80
|
+
}
|
|
81
|
+
inline void cancel() override {
|
|
82
|
+
auto __result = _swiftPart.cancel();
|
|
83
|
+
if (__result.hasError()) [[unlikely]] {
|
|
84
|
+
std::rethrow_exception(__result.error());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private:
|
|
89
|
+
NitroHashcashNative::HybridHashcashSpec_cxx _swiftPart;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
} // namespace margelo::nitro::hashcashnative
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// FindProofParams.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents an instance of `FindProofParams`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias FindProofParams = margelo.nitro.hashcashnative.FindProofParams
|
|
15
|
+
|
|
16
|
+
public extension FindProofParams {
|
|
17
|
+
private typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `FindProofParams`.
|
|
21
|
+
*/
|
|
22
|
+
init(challenge: HashcashChallenge, rangeStart: Double?, rangeSize: Double?) {
|
|
23
|
+
self.init(challenge, { () -> bridge.std__optional_double_ in
|
|
24
|
+
if let __unwrappedValue = rangeStart {
|
|
25
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
26
|
+
} else {
|
|
27
|
+
return .init()
|
|
28
|
+
}
|
|
29
|
+
}(), { () -> bridge.std__optional_double_ in
|
|
30
|
+
if let __unwrappedValue = rangeSize {
|
|
31
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
32
|
+
} else {
|
|
33
|
+
return .init()
|
|
34
|
+
}
|
|
35
|
+
}())
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var challenge: HashcashChallenge {
|
|
39
|
+
@inline(__always)
|
|
40
|
+
get {
|
|
41
|
+
return self.__challenge
|
|
42
|
+
}
|
|
43
|
+
@inline(__always)
|
|
44
|
+
set {
|
|
45
|
+
self.__challenge = newValue
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var rangeStart: Double? {
|
|
50
|
+
@inline(__always)
|
|
51
|
+
get {
|
|
52
|
+
return self.__rangeStart.value
|
|
53
|
+
}
|
|
54
|
+
@inline(__always)
|
|
55
|
+
set {
|
|
56
|
+
self.__rangeStart = { () -> bridge.std__optional_double_ in
|
|
57
|
+
if let __unwrappedValue = newValue {
|
|
58
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
59
|
+
} else {
|
|
60
|
+
return .init()
|
|
61
|
+
}
|
|
62
|
+
}()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var rangeSize: Double? {
|
|
67
|
+
@inline(__always)
|
|
68
|
+
get {
|
|
69
|
+
return self.__rangeSize.value
|
|
70
|
+
}
|
|
71
|
+
@inline(__always)
|
|
72
|
+
set {
|
|
73
|
+
self.__rangeSize = { () -> bridge.std__optional_double_ in
|
|
74
|
+
if let __unwrappedValue = newValue {
|
|
75
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
76
|
+
} else {
|
|
77
|
+
return .init()
|
|
78
|
+
}
|
|
79
|
+
}()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__exception_ptr.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ error: Error) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__exception_ptr {
|
|
16
|
+
public typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ error: Error) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ error: Error) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(error: std.exception_ptr) -> Void {
|
|
26
|
+
self.closure(RuntimeError.from(cppError: error))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
|
|
45
|
+
return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__optional_HashcashProofResult_.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ value: HashcashProofResult?) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__optional_HashcashProofResult_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ value: HashcashProofResult?) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ value: HashcashProofResult?) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(value: bridge.std__optional_HashcashProofResult_) -> Void {
|
|
26
|
+
self.closure(value.value)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_std__optional_HashcashProofResult_`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__optional_HashcashProofResult_>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_HashcashProofResult_ {
|
|
45
|
+
return Unmanaged<Func_void_std__optional_HashcashProofResult_>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HashcashChallenge.swift
|
|
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
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents an instance of `HashcashChallenge`, backed by a C++ struct.
|
|
13
|
+
*/
|
|
14
|
+
public typealias HashcashChallenge = margelo.nitro.hashcashnative.HashcashChallenge
|
|
15
|
+
|
|
16
|
+
public extension HashcashChallenge {
|
|
17
|
+
private typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of `HashcashChallenge`.
|
|
21
|
+
*/
|
|
22
|
+
init(difficulty: Double, subject: String, nonce: String, maxProofLength: Double) {
|
|
23
|
+
self.init(difficulty, std.string(subject), std.string(nonce), maxProofLength)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var difficulty: Double {
|
|
27
|
+
@inline(__always)
|
|
28
|
+
get {
|
|
29
|
+
return self.__difficulty
|
|
30
|
+
}
|
|
31
|
+
@inline(__always)
|
|
32
|
+
set {
|
|
33
|
+
self.__difficulty = newValue
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var subject: String {
|
|
38
|
+
@inline(__always)
|
|
39
|
+
get {
|
|
40
|
+
return String(self.__subject)
|
|
41
|
+
}
|
|
42
|
+
@inline(__always)
|
|
43
|
+
set {
|
|
44
|
+
self.__subject = std.string(newValue)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var nonce: String {
|
|
49
|
+
@inline(__always)
|
|
50
|
+
get {
|
|
51
|
+
return String(self.__nonce)
|
|
52
|
+
}
|
|
53
|
+
@inline(__always)
|
|
54
|
+
set {
|
|
55
|
+
self.__nonce = std.string(newValue)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var maxProofLength: Double {
|
|
60
|
+
@inline(__always)
|
|
61
|
+
get {
|
|
62
|
+
return self.__maxProofLength
|
|
63
|
+
}
|
|
64
|
+
@inline(__always)
|
|
65
|
+
set {
|
|
66
|
+
self.__maxProofLength = newValue
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|