@qntx/nostr-native 0.0.0-stage → 0.12.1

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 (106) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/NostrNative.podspec +37 -0
  4. package/README.md +30 -2
  5. package/android/CMakeLists.txt +38 -0
  6. package/android/build.gradle +136 -0
  7. package/android/gradle.properties +4 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +7 -0
  10. package/android/src/main/java/com/margelo/nitro/nostrnative/NostrNativePackage.java +29 -0
  11. package/cpp/HybridNostrNative.cpp +52 -0
  12. package/cpp/HybridNostrNative.hpp +22 -0
  13. package/cpp/nostr_core.c +128 -0
  14. package/cpp/nostr_core.h +65 -0
  15. package/cpp/nostr_native.c +54 -0
  16. package/cpp/nostr_native.h +47 -0
  17. package/dist/index.d.mts +15 -0
  18. package/dist/index.mjs +26 -0
  19. package/dist/index.mjs.map +1 -0
  20. package/nitro.json +19 -0
  21. package/nitrogen/generated/.gitattributes +1 -0
  22. package/nitrogen/generated/android/NostrNative+autolinking.cmake +81 -0
  23. package/nitrogen/generated/android/NostrNative+autolinking.gradle +27 -0
  24. package/nitrogen/generated/android/NostrNativeOnLoad.cpp +49 -0
  25. package/nitrogen/generated/android/NostrNativeOnLoad.hpp +34 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nostrnative/NostrNativeOnLoad.kt +35 -0
  27. package/nitrogen/generated/ios/NostrNative+autolinking.rb +62 -0
  28. package/nitrogen/generated/ios/NostrNative-Swift-Cxx-Bridge.cpp +17 -0
  29. package/nitrogen/generated/ios/NostrNative-Swift-Cxx-Bridge.hpp +27 -0
  30. package/nitrogen/generated/ios/NostrNative-Swift-Cxx-Umbrella.hpp +38 -0
  31. package/nitrogen/generated/ios/NostrNativeAutolinking.mm +35 -0
  32. package/nitrogen/generated/ios/NostrNativeAutolinking.swift +16 -0
  33. package/nitrogen/generated/shared/c++/HybridNostrNativeSpec.cpp +23 -0
  34. package/nitrogen/generated/shared/c++/HybridNostrNativeSpec.hpp +64 -0
  35. package/package.json +86 -4
  36. package/react-native.config.js +12 -0
  37. package/vendor/secp256k1/COPYING +19 -0
  38. package/vendor/secp256k1/include/secp256k1.h +931 -0
  39. package/vendor/secp256k1/include/secp256k1_ecdh.h +63 -0
  40. package/vendor/secp256k1/include/secp256k1_ellswift.h +200 -0
  41. package/vendor/secp256k1/include/secp256k1_extrakeys.h +250 -0
  42. package/vendor/secp256k1/include/secp256k1_musig.h +588 -0
  43. package/vendor/secp256k1/include/secp256k1_preallocated.h +134 -0
  44. package/vendor/secp256k1/include/secp256k1_recovery.h +123 -0
  45. package/vendor/secp256k1/include/secp256k1_schnorrsig.h +179 -0
  46. package/vendor/secp256k1/include/secp256k1_silentpayments.h +396 -0
  47. package/vendor/secp256k1/src/assumptions.h +87 -0
  48. package/vendor/secp256k1/src/checkmem.h +117 -0
  49. package/vendor/secp256k1/src/ecdsa.h +21 -0
  50. package/vendor/secp256k1/src/ecdsa_impl.h +309 -0
  51. package/vendor/secp256k1/src/eckey.h +28 -0
  52. package/vendor/secp256k1/src/eckey_impl.h +94 -0
  53. package/vendor/secp256k1/src/ecmult.h +64 -0
  54. package/vendor/secp256k1/src/ecmult_compute_table.h +16 -0
  55. package/vendor/secp256k1/src/ecmult_compute_table_impl.h +49 -0
  56. package/vendor/secp256k1/src/ecmult_const.h +38 -0
  57. package/vendor/secp256k1/src/ecmult_const_impl.h +402 -0
  58. package/vendor/secp256k1/src/ecmult_gen.h +145 -0
  59. package/vendor/secp256k1/src/ecmult_gen_compute_table.h +14 -0
  60. package/vendor/secp256k1/src/ecmult_gen_compute_table_impl.h +108 -0
  61. package/vendor/secp256k1/src/ecmult_gen_impl.h +347 -0
  62. package/vendor/secp256k1/src/ecmult_impl.h +869 -0
  63. package/vendor/secp256k1/src/field.h +351 -0
  64. package/vendor/secp256k1/src/field_10x26.h +57 -0
  65. package/vendor/secp256k1/src/field_10x26_impl.h +1210 -0
  66. package/vendor/secp256k1/src/field_5x52.h +62 -0
  67. package/vendor/secp256k1/src/field_5x52_impl.h +496 -0
  68. package/vendor/secp256k1/src/field_5x52_int128_impl.h +274 -0
  69. package/vendor/secp256k1/src/field_impl.h +457 -0
  70. package/vendor/secp256k1/src/group.h +218 -0
  71. package/vendor/secp256k1/src/group_impl.h +1014 -0
  72. package/vendor/secp256k1/src/hash.h +56 -0
  73. package/vendor/secp256k1/src/hash_impl.h +397 -0
  74. package/vendor/secp256k1/src/hsort.h +33 -0
  75. package/vendor/secp256k1/src/hsort_impl.h +125 -0
  76. package/vendor/secp256k1/src/int128.h +90 -0
  77. package/vendor/secp256k1/src/int128_impl.h +18 -0
  78. package/vendor/secp256k1/src/int128_native.h +19 -0
  79. package/vendor/secp256k1/src/int128_native_impl.h +94 -0
  80. package/vendor/secp256k1/src/int128_struct.h +14 -0
  81. package/vendor/secp256k1/src/int128_struct_impl.h +205 -0
  82. package/vendor/secp256k1/src/modinv32.h +43 -0
  83. package/vendor/secp256k1/src/modinv32_impl.h +725 -0
  84. package/vendor/secp256k1/src/modinv64.h +47 -0
  85. package/vendor/secp256k1/src/modinv64_impl.h +780 -0
  86. package/vendor/secp256k1/src/modules/extrakeys/main_impl.h +292 -0
  87. package/vendor/secp256k1/src/modules/schnorrsig/main_impl.h +256 -0
  88. package/vendor/secp256k1/src/precomputed_ecmult.c +16456 -0
  89. package/vendor/secp256k1/src/precomputed_ecmult.h +40 -0
  90. package/vendor/secp256k1/src/precomputed_ecmult_gen.c +1779 -0
  91. package/vendor/secp256k1/src/precomputed_ecmult_gen.h +28 -0
  92. package/vendor/secp256k1/src/scalar.h +105 -0
  93. package/vendor/secp256k1/src/scalar_4x64.h +19 -0
  94. package/vendor/secp256k1/src/scalar_4x64_impl.h +1005 -0
  95. package/vendor/secp256k1/src/scalar_8x32.h +19 -0
  96. package/vendor/secp256k1/src/scalar_8x32_impl.h +820 -0
  97. package/vendor/secp256k1/src/scalar_impl.h +321 -0
  98. package/vendor/secp256k1/src/scalar_low.h +24 -0
  99. package/vendor/secp256k1/src/scalar_low_impl.h +217 -0
  100. package/vendor/secp256k1/src/scratch.h +44 -0
  101. package/vendor/secp256k1/src/scratch_impl.h +99 -0
  102. package/vendor/secp256k1/src/secp256k1.c +855 -0
  103. package/vendor/secp256k1/src/selftest.h +41 -0
  104. package/vendor/secp256k1/src/util.h +479 -0
  105. package/vendor/secp256k1/src/util_local_visibility.h +12 -0
  106. package/vendor/secp256k1/vendored.json +6 -0
@@ -0,0 +1,99 @@
1
+ /***********************************************************************
2
+ * Copyright (c) 2017 Andrew Poelstra *
3
+ * Distributed under the MIT software license, see the accompanying *
4
+ * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5
+ ***********************************************************************/
6
+
7
+ #ifndef SECP256K1_SCRATCH_IMPL_H
8
+ #define SECP256K1_SCRATCH_IMPL_H
9
+
10
+ #include "util.h"
11
+ #include "scratch.h"
12
+
13
+ static nostr_native_secp256k1_scratch* nostr_native_secp256k1_scratch_create(const nostr_native_secp256k1_callback* error_callback, size_t size) {
14
+ const size_t base_alloc = ROUND_TO_ALIGN(sizeof(nostr_native_secp256k1_scratch));
15
+ void *alloc = checked_malloc(error_callback, base_alloc + size);
16
+ nostr_native_secp256k1_scratch* ret = (nostr_native_secp256k1_scratch *)alloc;
17
+ if (ret != NULL) {
18
+ memset(ret, 0, sizeof(*ret));
19
+ memcpy(ret->magic, "scratch", 8);
20
+ ret->data = (void *) ((char *) alloc + base_alloc);
21
+ ret->max_size = size;
22
+ }
23
+ return ret;
24
+ }
25
+
26
+ static void nostr_native_secp256k1_scratch_destroy(const nostr_native_secp256k1_callback* error_callback, nostr_native_secp256k1_scratch* scratch) {
27
+ if (scratch != NULL) {
28
+ if (nostr_native_secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
29
+ nostr_native_secp256k1_callback_call(error_callback, "invalid scratch space");
30
+ return;
31
+ }
32
+ VERIFY_CHECK(scratch->alloc_size == 0); /* all checkpoints should be applied */
33
+ memset(scratch->magic, 0, sizeof(scratch->magic));
34
+ free(scratch);
35
+ }
36
+ }
37
+
38
+ static size_t nostr_native_secp256k1_scratch_checkpoint(const nostr_native_secp256k1_callback* error_callback, const nostr_native_secp256k1_scratch* scratch) {
39
+ if (nostr_native_secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
40
+ nostr_native_secp256k1_callback_call(error_callback, "invalid scratch space");
41
+ return 0;
42
+ }
43
+ return scratch->alloc_size;
44
+ }
45
+
46
+ static void nostr_native_secp256k1_scratch_apply_checkpoint(const nostr_native_secp256k1_callback* error_callback, nostr_native_secp256k1_scratch* scratch, size_t checkpoint) {
47
+ if (nostr_native_secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
48
+ nostr_native_secp256k1_callback_call(error_callback, "invalid scratch space");
49
+ return;
50
+ }
51
+ if (checkpoint > scratch->alloc_size) {
52
+ nostr_native_secp256k1_callback_call(error_callback, "invalid checkpoint");
53
+ return;
54
+ }
55
+ scratch->alloc_size = checkpoint;
56
+ }
57
+
58
+ static size_t nostr_native_secp256k1_scratch_max_allocation(const nostr_native_secp256k1_callback* error_callback, const nostr_native_secp256k1_scratch* scratch, size_t objects) {
59
+ if (nostr_native_secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
60
+ nostr_native_secp256k1_callback_call(error_callback, "invalid scratch space");
61
+ return 0;
62
+ }
63
+ /* Ensure that multiplication will not wrap around */
64
+ if (ALIGNMENT > 1 && objects > SIZE_MAX/(ALIGNMENT - 1)) {
65
+ return 0;
66
+ }
67
+ if (scratch->max_size - scratch->alloc_size <= objects * (ALIGNMENT - 1)) {
68
+ return 0;
69
+ }
70
+ return scratch->max_size - scratch->alloc_size - objects * (ALIGNMENT - 1);
71
+ }
72
+
73
+ static void *nostr_native_secp256k1_scratch_alloc(const nostr_native_secp256k1_callback* error_callback, nostr_native_secp256k1_scratch* scratch, size_t size) {
74
+ void *ret;
75
+ size_t rounded_size;
76
+
77
+ rounded_size = ROUND_TO_ALIGN(size);
78
+ /* Check that rounding did not wrap around */
79
+ if (rounded_size < size) {
80
+ return NULL;
81
+ }
82
+ size = rounded_size;
83
+
84
+ if (nostr_native_secp256k1_memcmp_var(scratch->magic, "scratch", 8) != 0) {
85
+ nostr_native_secp256k1_callback_call(error_callback, "invalid scratch space");
86
+ return NULL;
87
+ }
88
+
89
+ if (size > scratch->max_size - scratch->alloc_size) {
90
+ return NULL;
91
+ }
92
+ ret = (void *) ((char *) scratch->data + scratch->alloc_size);
93
+ memset(ret, 0, size);
94
+ scratch->alloc_size += size;
95
+
96
+ return ret;
97
+ }
98
+
99
+ #endif