@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.
Files changed (68) hide show
  1. package/LICENSE +122 -0
  2. package/NitroHashcashNative.podspec +56 -0
  3. package/README.md +24 -0
  4. package/android/CMakeLists.txt +29 -0
  5. package/android/build.gradle +141 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/margelo/nitro/hashcashnative/HybridHashcash.kt +113 -0
  11. package/android/src/main/java/com/margelo/nitro/hashcashnative/NitroHashcashNativePackage.kt +18 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/HybridHashcash.swift +133 -0
  14. package/lib/benchmark.d.ts +74 -0
  15. package/lib/benchmark.d.ts.map +1 -0
  16. package/lib/benchmark.js +92 -0
  17. package/lib/benchmark.js.map +1 -0
  18. package/lib/index.d.ts +11 -0
  19. package/lib/index.d.ts.map +1 -0
  20. package/lib/index.js +10 -0
  21. package/lib/index.js.map +1 -0
  22. package/lib/specs/Hashcash.nitro.d.ts +59 -0
  23. package/lib/specs/Hashcash.nitro.d.ts.map +1 -0
  24. package/lib/specs/Hashcash.nitro.js +2 -0
  25. package/lib/specs/Hashcash.nitro.js.map +1 -0
  26. package/nitro.json +18 -0
  27. package/nitrogen/generated/.gitattributes +1 -0
  28. package/nitrogen/generated/android/NitroHashcashNative+autolinking.cmake +81 -0
  29. package/nitrogen/generated/android/NitroHashcashNative+autolinking.gradle +27 -0
  30. package/nitrogen/generated/android/NitroHashcashNativeOnLoad.cpp +44 -0
  31. package/nitrogen/generated/android/NitroHashcashNativeOnLoad.hpp +25 -0
  32. package/nitrogen/generated/android/c++/JFindProofParams.hpp +68 -0
  33. package/nitrogen/generated/android/c++/JHashcashChallenge.hpp +69 -0
  34. package/nitrogen/generated/android/c++/JHashcashProofResult.hpp +69 -0
  35. package/nitrogen/generated/android/c++/JHybridHashcashSpec.cpp +81 -0
  36. package/nitrogen/generated/android/c++/JHybridHashcashSpec.hpp +66 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/FindProofParams.kt +44 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashChallenge.kt +47 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HashcashProofResult.kt +47 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/HybridHashcashSpec.kt +62 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/hashcashnative/NitroHashcashNativeOnLoad.kt +35 -0
  42. package/nitrogen/generated/ios/NitroHashcashNative+autolinking.rb +60 -0
  43. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.cpp +49 -0
  44. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Bridge.hpp +154 -0
  45. package/nitrogen/generated/ios/NitroHashcashNative-Swift-Cxx-Umbrella.hpp +55 -0
  46. package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.mm +33 -0
  47. package/nitrogen/generated/ios/NitroHashcashNativeAutolinking.swift +25 -0
  48. package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.cpp +11 -0
  49. package/nitrogen/generated/ios/c++/HybridHashcashSpecSwift.hpp +92 -0
  50. package/nitrogen/generated/ios/swift/FindProofParams.swift +82 -0
  51. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  52. package/nitrogen/generated/ios/swift/Func_void_std__optional_HashcashProofResult_.swift +47 -0
  53. package/nitrogen/generated/ios/swift/HashcashChallenge.swift +69 -0
  54. package/nitrogen/generated/ios/swift/HashcashProofResult.swift +69 -0
  55. package/nitrogen/generated/ios/swift/HybridHashcashSpec.swift +57 -0
  56. package/nitrogen/generated/ios/swift/HybridHashcashSpec_cxx.swift +155 -0
  57. package/nitrogen/generated/shared/c++/FindProofParams.hpp +85 -0
  58. package/nitrogen/generated/shared/c++/HashcashChallenge.hpp +87 -0
  59. package/nitrogen/generated/shared/c++/HashcashProofResult.hpp +87 -0
  60. package/nitrogen/generated/shared/c++/HybridHashcashSpec.cpp +22 -0
  61. package/nitrogen/generated/shared/c++/HybridHashcashSpec.hpp +69 -0
  62. package/package.json +73 -1
  63. package/react-native.config.js +16 -0
  64. package/src/benchmark.ts +152 -0
  65. package/src/index.ts +23 -0
  66. package/src/specs/Hashcash.nitro.ts +64 -0
  67. package/index.d.ts +0 -1
  68. package/index.js +0 -1
@@ -0,0 +1,68 @@
1
+ ///
2
+ /// JFindProofParams.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 <fbjni/fbjni.h>
11
+ #include "FindProofParams.hpp"
12
+
13
+ #include "HashcashChallenge.hpp"
14
+ #include "JHashcashChallenge.hpp"
15
+ #include <optional>
16
+ #include <string>
17
+
18
+ namespace margelo::nitro::hashcashnative {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * The C++ JNI bridge between the C++ struct "FindProofParams" and the the Kotlin data class "FindProofParams".
24
+ */
25
+ struct JFindProofParams final: public jni::JavaClass<JFindProofParams> {
26
+ public:
27
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/hashcashnative/FindProofParams;";
28
+
29
+ public:
30
+ /**
31
+ * Convert this Java/Kotlin-based struct to the C++ struct FindProofParams by copying all values to C++.
32
+ */
33
+ [[maybe_unused]]
34
+ [[nodiscard]]
35
+ FindProofParams toCpp() const {
36
+ static const auto clazz = javaClassStatic();
37
+ static const auto fieldChallenge = clazz->getField<JHashcashChallenge>("challenge");
38
+ jni::local_ref<JHashcashChallenge> challenge = this->getFieldValue(fieldChallenge);
39
+ static const auto fieldRangeStart = clazz->getField<jni::JDouble>("rangeStart");
40
+ jni::local_ref<jni::JDouble> rangeStart = this->getFieldValue(fieldRangeStart);
41
+ static const auto fieldRangeSize = clazz->getField<jni::JDouble>("rangeSize");
42
+ jni::local_ref<jni::JDouble> rangeSize = this->getFieldValue(fieldRangeSize);
43
+ return FindProofParams(
44
+ challenge->toCpp(),
45
+ rangeStart != nullptr ? std::make_optional(rangeStart->value()) : std::nullopt,
46
+ rangeSize != nullptr ? std::make_optional(rangeSize->value()) : std::nullopt
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JFindProofParams::javaobject> fromCpp(const FindProofParams& value) {
56
+ using JSignature = JFindProofParams(jni::alias_ref<JHashcashChallenge>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ JHashcashChallenge::fromCpp(value.challenge),
62
+ value.rangeStart.has_value() ? jni::JDouble::valueOf(value.rangeStart.value()) : nullptr,
63
+ value.rangeSize.has_value() ? jni::JDouble::valueOf(value.rangeSize.value()) : nullptr
64
+ );
65
+ }
66
+ };
67
+
68
+ } // namespace margelo::nitro::hashcashnative
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// JHashcashChallenge.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 <fbjni/fbjni.h>
11
+ #include "HashcashChallenge.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::hashcashnative {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "HashcashChallenge" and the the Kotlin data class "HashcashChallenge".
21
+ */
22
+ struct JHashcashChallenge final: public jni::JavaClass<JHashcashChallenge> {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/hashcashnative/HashcashChallenge;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct HashcashChallenge by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ HashcashChallenge toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldDifficulty = clazz->getField<double>("difficulty");
35
+ double difficulty = this->getFieldValue(fieldDifficulty);
36
+ static const auto fieldSubject = clazz->getField<jni::JString>("subject");
37
+ jni::local_ref<jni::JString> subject = this->getFieldValue(fieldSubject);
38
+ static const auto fieldNonce = clazz->getField<jni::JString>("nonce");
39
+ jni::local_ref<jni::JString> nonce = this->getFieldValue(fieldNonce);
40
+ static const auto fieldMaxProofLength = clazz->getField<double>("maxProofLength");
41
+ double maxProofLength = this->getFieldValue(fieldMaxProofLength);
42
+ return HashcashChallenge(
43
+ difficulty,
44
+ subject->toStdString(),
45
+ nonce->toStdString(),
46
+ maxProofLength
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JHashcashChallenge::javaobject> fromCpp(const HashcashChallenge& value) {
56
+ using JSignature = JHashcashChallenge(double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ value.difficulty,
62
+ jni::make_jstring(value.subject),
63
+ jni::make_jstring(value.nonce),
64
+ value.maxProofLength
65
+ );
66
+ }
67
+ };
68
+
69
+ } // namespace margelo::nitro::hashcashnative
@@ -0,0 +1,69 @@
1
+ ///
2
+ /// JHashcashProofResult.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 <fbjni/fbjni.h>
11
+ #include "HashcashProofResult.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::hashcashnative {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "HashcashProofResult" and the the Kotlin data class "HashcashProofResult".
21
+ */
22
+ struct JHashcashProofResult final: public jni::JavaClass<JHashcashProofResult> {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/hashcashnative/HashcashProofResult;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct HashcashProofResult by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ HashcashProofResult toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldCounter = clazz->getField<jni::JString>("counter");
35
+ jni::local_ref<jni::JString> counter = this->getFieldValue(fieldCounter);
36
+ static const auto fieldHashBase64 = clazz->getField<jni::JString>("hashBase64");
37
+ jni::local_ref<jni::JString> hashBase64 = this->getFieldValue(fieldHashBase64);
38
+ static const auto fieldAttempts = clazz->getField<double>("attempts");
39
+ double attempts = this->getFieldValue(fieldAttempts);
40
+ static const auto fieldTimeMs = clazz->getField<double>("timeMs");
41
+ double timeMs = this->getFieldValue(fieldTimeMs);
42
+ return HashcashProofResult(
43
+ counter->toStdString(),
44
+ hashBase64->toStdString(),
45
+ attempts,
46
+ timeMs
47
+ );
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
53
+ */
54
+ [[maybe_unused]]
55
+ static jni::local_ref<JHashcashProofResult::javaobject> fromCpp(const HashcashProofResult& value) {
56
+ using JSignature = JHashcashProofResult(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, double, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
61
+ jni::make_jstring(value.counter),
62
+ jni::make_jstring(value.hashBase64),
63
+ value.attempts,
64
+ value.timeMs
65
+ );
66
+ }
67
+ };
68
+
69
+ } // namespace margelo::nitro::hashcashnative
@@ -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