@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.
- 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,155 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridHashcashSpec_cxx.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
|
+
* A class implementation that bridges HybridHashcashSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridHashcashSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::hashcashnative::bridge::swift`)
|
|
23
|
+
* from `NitroHashcashNative-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.hashcashnative.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridHashcashSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridHashcashSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridHashcashSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridHashcashSpec_cxx` that wraps the given `HybridHashcashSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridHashcashSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridHashcashSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridHashcashSpec() -> any HybridHashcashSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridHashcashSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridHashcashSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridHashcashSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridHashcashSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridHashcashSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridHashcashSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridHashcashSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridHashcashSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Call dispose() on the Swift class.
|
|
101
|
+
* This _may_ be called manually from JS.
|
|
102
|
+
*/
|
|
103
|
+
@inline(__always)
|
|
104
|
+
public func dispose() {
|
|
105
|
+
self.__implementation.dispose()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Call toString() on the Swift class.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func toString() -> String {
|
|
113
|
+
return self.__implementation.toString()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Properties
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
// Methods
|
|
120
|
+
@inline(__always)
|
|
121
|
+
public final func findProof(params: FindProofParams) -> bridge.Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____ {
|
|
122
|
+
do {
|
|
123
|
+
let __result = try self.__implementation.findProof(params: params)
|
|
124
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__optional_HashcashProofResult___ in
|
|
125
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__optional_HashcashProofResult___()
|
|
126
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__optional_HashcashProofResult___(__promise)
|
|
127
|
+
__result
|
|
128
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__optional_HashcashProofResult_ in
|
|
129
|
+
if let __unwrappedValue = __result {
|
|
130
|
+
return bridge.create_std__optional_HashcashProofResult_(__unwrappedValue)
|
|
131
|
+
} else {
|
|
132
|
+
return .init()
|
|
133
|
+
}
|
|
134
|
+
}()) })
|
|
135
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
136
|
+
return __promise
|
|
137
|
+
}()
|
|
138
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____(__resultCpp)
|
|
139
|
+
} catch (let __error) {
|
|
140
|
+
let __exceptionPtr = __error.toCpp()
|
|
141
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_HashcashProofResult____(__exceptionPtr)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@inline(__always)
|
|
146
|
+
public final func cancel() -> bridge.Result_void_ {
|
|
147
|
+
do {
|
|
148
|
+
try self.__implementation.cancel()
|
|
149
|
+
return bridge.create_Result_void_()
|
|
150
|
+
} catch (let __error) {
|
|
151
|
+
let __exceptionPtr = __error.toCpp()
|
|
152
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// FindProofParams.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
// Forward declaration of `HashcashChallenge` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::hashcashnative { struct HashcashChallenge; }
|
|
28
|
+
|
|
29
|
+
#include "HashcashChallenge.hpp"
|
|
30
|
+
#include <optional>
|
|
31
|
+
|
|
32
|
+
namespace margelo::nitro::hashcashnative {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A struct which can be represented as a JavaScript object (FindProofParams).
|
|
36
|
+
*/
|
|
37
|
+
struct FindProofParams {
|
|
38
|
+
public:
|
|
39
|
+
HashcashChallenge challenge SWIFT_PRIVATE;
|
|
40
|
+
std::optional<double> rangeStart SWIFT_PRIVATE;
|
|
41
|
+
std::optional<double> rangeSize SWIFT_PRIVATE;
|
|
42
|
+
|
|
43
|
+
public:
|
|
44
|
+
FindProofParams() = default;
|
|
45
|
+
explicit FindProofParams(HashcashChallenge challenge, std::optional<double> rangeStart, std::optional<double> rangeSize): challenge(challenge), rangeStart(rangeStart), rangeSize(rangeSize) {}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
} // namespace margelo::nitro::hashcashnative
|
|
49
|
+
|
|
50
|
+
namespace margelo::nitro {
|
|
51
|
+
|
|
52
|
+
// C++ FindProofParams <> JS FindProofParams (object)
|
|
53
|
+
template <>
|
|
54
|
+
struct JSIConverter<margelo::nitro::hashcashnative::FindProofParams> final {
|
|
55
|
+
static inline margelo::nitro::hashcashnative::FindProofParams fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
56
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
57
|
+
return margelo::nitro::hashcashnative::FindProofParams(
|
|
58
|
+
JSIConverter<margelo::nitro::hashcashnative::HashcashChallenge>::fromJSI(runtime, obj.getProperty(runtime, "challenge")),
|
|
59
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "rangeStart")),
|
|
60
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "rangeSize"))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::hashcashnative::FindProofParams& arg) {
|
|
64
|
+
jsi::Object obj(runtime);
|
|
65
|
+
obj.setProperty(runtime, "challenge", JSIConverter<margelo::nitro::hashcashnative::HashcashChallenge>::toJSI(runtime, arg.challenge));
|
|
66
|
+
obj.setProperty(runtime, "rangeStart", JSIConverter<std::optional<double>>::toJSI(runtime, arg.rangeStart));
|
|
67
|
+
obj.setProperty(runtime, "rangeSize", JSIConverter<std::optional<double>>::toJSI(runtime, arg.rangeSize));
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isObject()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
jsi::Object obj = value.getObject(runtime);
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<margelo::nitro::hashcashnative::HashcashChallenge>::canConvert(runtime, obj.getProperty(runtime, "challenge"))) return false;
|
|
79
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "rangeStart"))) return false;
|
|
80
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "rangeSize"))) return false;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HashcashChallenge.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <string>
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::hashcashnative {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A struct which can be represented as a JavaScript object (HashcashChallenge).
|
|
34
|
+
*/
|
|
35
|
+
struct HashcashChallenge {
|
|
36
|
+
public:
|
|
37
|
+
double difficulty SWIFT_PRIVATE;
|
|
38
|
+
std::string subject SWIFT_PRIVATE;
|
|
39
|
+
std::string nonce SWIFT_PRIVATE;
|
|
40
|
+
double maxProofLength SWIFT_PRIVATE;
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
HashcashChallenge() = default;
|
|
44
|
+
explicit HashcashChallenge(double difficulty, std::string subject, std::string nonce, double maxProofLength): difficulty(difficulty), subject(subject), nonce(nonce), maxProofLength(maxProofLength) {}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} // namespace margelo::nitro::hashcashnative
|
|
48
|
+
|
|
49
|
+
namespace margelo::nitro {
|
|
50
|
+
|
|
51
|
+
// C++ HashcashChallenge <> JS HashcashChallenge (object)
|
|
52
|
+
template <>
|
|
53
|
+
struct JSIConverter<margelo::nitro::hashcashnative::HashcashChallenge> final {
|
|
54
|
+
static inline margelo::nitro::hashcashnative::HashcashChallenge fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
55
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
56
|
+
return margelo::nitro::hashcashnative::HashcashChallenge(
|
|
57
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "difficulty")),
|
|
58
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "subject")),
|
|
59
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "nonce")),
|
|
60
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "maxProofLength"))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::hashcashnative::HashcashChallenge& arg) {
|
|
64
|
+
jsi::Object obj(runtime);
|
|
65
|
+
obj.setProperty(runtime, "difficulty", JSIConverter<double>::toJSI(runtime, arg.difficulty));
|
|
66
|
+
obj.setProperty(runtime, "subject", JSIConverter<std::string>::toJSI(runtime, arg.subject));
|
|
67
|
+
obj.setProperty(runtime, "nonce", JSIConverter<std::string>::toJSI(runtime, arg.nonce));
|
|
68
|
+
obj.setProperty(runtime, "maxProofLength", JSIConverter<double>::toJSI(runtime, arg.maxProofLength));
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
72
|
+
if (!value.isObject()) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
jsi::Object obj = value.getObject(runtime);
|
|
76
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "difficulty"))) return false;
|
|
80
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "subject"))) return false;
|
|
81
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "nonce"))) return false;
|
|
82
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "maxProofLength"))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HashcashProofResult.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
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
#include <string>
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::hashcashnative {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A struct which can be represented as a JavaScript object (HashcashProofResult).
|
|
34
|
+
*/
|
|
35
|
+
struct HashcashProofResult {
|
|
36
|
+
public:
|
|
37
|
+
std::string counter SWIFT_PRIVATE;
|
|
38
|
+
std::string hashBase64 SWIFT_PRIVATE;
|
|
39
|
+
double attempts SWIFT_PRIVATE;
|
|
40
|
+
double timeMs SWIFT_PRIVATE;
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
HashcashProofResult() = default;
|
|
44
|
+
explicit HashcashProofResult(std::string counter, std::string hashBase64, double attempts, double timeMs): counter(counter), hashBase64(hashBase64), attempts(attempts), timeMs(timeMs) {}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} // namespace margelo::nitro::hashcashnative
|
|
48
|
+
|
|
49
|
+
namespace margelo::nitro {
|
|
50
|
+
|
|
51
|
+
// C++ HashcashProofResult <> JS HashcashProofResult (object)
|
|
52
|
+
template <>
|
|
53
|
+
struct JSIConverter<margelo::nitro::hashcashnative::HashcashProofResult> final {
|
|
54
|
+
static inline margelo::nitro::hashcashnative::HashcashProofResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
55
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
56
|
+
return margelo::nitro::hashcashnative::HashcashProofResult(
|
|
57
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "counter")),
|
|
58
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "hashBase64")),
|
|
59
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "attempts")),
|
|
60
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timeMs"))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::hashcashnative::HashcashProofResult& arg) {
|
|
64
|
+
jsi::Object obj(runtime);
|
|
65
|
+
obj.setProperty(runtime, "counter", JSIConverter<std::string>::toJSI(runtime, arg.counter));
|
|
66
|
+
obj.setProperty(runtime, "hashBase64", JSIConverter<std::string>::toJSI(runtime, arg.hashBase64));
|
|
67
|
+
obj.setProperty(runtime, "attempts", JSIConverter<double>::toJSI(runtime, arg.attempts));
|
|
68
|
+
obj.setProperty(runtime, "timeMs", JSIConverter<double>::toJSI(runtime, arg.timeMs));
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
72
|
+
if (!value.isObject()) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
jsi::Object obj = value.getObject(runtime);
|
|
76
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "counter"))) return false;
|
|
80
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "hashBase64"))) return false;
|
|
81
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "attempts"))) return false;
|
|
82
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timeMs"))) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridHashcashSpec.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 "HybridHashcashSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::hashcashnative {
|
|
11
|
+
|
|
12
|
+
void HybridHashcashSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("findProof", &HybridHashcashSpec::findProof);
|
|
18
|
+
prototype.registerHybridMethod("cancel", &HybridHashcashSpec::cancel);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::hashcashnative
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `HashcashProofResult` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::hashcashnative { struct HashcashProofResult; }
|
|
18
|
+
// Forward declaration of `FindProofParams` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::hashcashnative { struct FindProofParams; }
|
|
20
|
+
|
|
21
|
+
#include "HashcashProofResult.hpp"
|
|
22
|
+
#include <optional>
|
|
23
|
+
#include <NitroModules/Promise.hpp>
|
|
24
|
+
#include "FindProofParams.hpp"
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::hashcashnative {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `Hashcash`
|
|
32
|
+
* Inherit this class to create instances of `HybridHashcashSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridHashcash: public HybridHashcashSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridHashcash(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridHashcashSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridHashcashSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridHashcashSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
virtual std::shared_ptr<Promise<std::optional<HashcashProofResult>>> findProof(const FindProofParams& params) = 0;
|
|
58
|
+
virtual void cancel() = 0;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Hybrid Setup
|
|
62
|
+
void loadHybridMethods() override;
|
|
63
|
+
|
|
64
|
+
protected:
|
|
65
|
+
// Tag for logging
|
|
66
|
+
static constexpr auto TAG = "Hashcash";
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::hashcashnative
|
package/package.json
CHANGED
|
@@ -1 +1,73 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@l.x/hashcash-native",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Native hashcash proof-of-work solver for React Native",
|
|
5
|
+
"author": "Lux Industries",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/Lux/universe",
|
|
8
|
+
"main": "lib/index",
|
|
9
|
+
"module": "lib/index",
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"react-native": "src/index",
|
|
12
|
+
"source": "src/index",
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"react-native.config.js",
|
|
16
|
+
"lib",
|
|
17
|
+
"nitrogen",
|
|
18
|
+
"android/build.gradle",
|
|
19
|
+
"android/gradle.properties",
|
|
20
|
+
"android/fix-prefab.gradle",
|
|
21
|
+
"android/CMakeLists.txt",
|
|
22
|
+
"android/src",
|
|
23
|
+
"ios/**/*.h",
|
|
24
|
+
"ios/**/*.m",
|
|
25
|
+
"ios/**/*.mm",
|
|
26
|
+
"ios/**/*.cpp",
|
|
27
|
+
"ios/**/*.swift",
|
|
28
|
+
"app.plugin.js",
|
|
29
|
+
"nitro.json",
|
|
30
|
+
"*.podspec",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"postinstall": "tsc || exit 0;",
|
|
35
|
+
"typecheck": "nx typecheck hashcash-native",
|
|
36
|
+
"typecheck:tsgo": "nx typecheck:tsgo hashcash-native",
|
|
37
|
+
"build": "nx build hashcash-native",
|
|
38
|
+
"clean": "nx clean hashcash-native",
|
|
39
|
+
"lint": "nx lint hashcash-native",
|
|
40
|
+
"lint:fix": "nx lint:fix hashcash-native",
|
|
41
|
+
"lint:biome": "nx lint:biome hashcash-native",
|
|
42
|
+
"lint:biome:fix": "nx lint:biome:fix hashcash-native",
|
|
43
|
+
"lint:eslint": "nx lint:eslint hashcash-native",
|
|
44
|
+
"lint:eslint:fix": "nx lint:eslint:fix hashcash-native",
|
|
45
|
+
"check:deps:usage": "nx check:deps:usage hashcash-native",
|
|
46
|
+
"lint-ci": "nx lint-ci hashcash-native",
|
|
47
|
+
"specs": "nx specs hashcash-native",
|
|
48
|
+
"codegen": "nx codegen hashcash-native",
|
|
49
|
+
"codegen:clean": "nx codegen:clean hashcash-native"
|
|
50
|
+
},
|
|
51
|
+
"nx": {
|
|
52
|
+
"includedScripts": []
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"registry": "https://registry.npmjs.org/"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@typescript/native-preview": "7.0.0-dev.20260311.1",
|
|
59
|
+
"@luxfi/eslint-config": "workspace:^",
|
|
60
|
+
"eslint": "8.57.1",
|
|
61
|
+
"nitrogen": "0.31.10",
|
|
62
|
+
"react": "19.0.3",
|
|
63
|
+
"react-native": "0.79.5",
|
|
64
|
+
"react-native-nitro-modules": "0.31.10",
|
|
65
|
+
"typescript": "5.8.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"react": ">=19.0.0",
|
|
69
|
+
"react-native": ">=0.79.0",
|
|
70
|
+
"react-native-nitro-modules": ">=0.31.0"
|
|
71
|
+
},
|
|
72
|
+
"private": false
|
|
73
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
dependency: {
|
|
5
|
+
platforms: {
|
|
6
|
+
/**
|
|
7
|
+
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
|
|
8
|
+
*/
|
|
9
|
+
ios: {},
|
|
10
|
+
/**
|
|
11
|
+
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
|
+
*/
|
|
13
|
+
android: {},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}
|