@authon/react-native-wallet 0.0.0-stage → 0.4.0

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 (183) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +251 -2
  3. package/android/build.gradle +40 -0
  4. package/android/consumer-rules.pro +10 -0
  5. package/android/src/main/AndroidManifest.xml +8 -0
  6. package/android/src/main/java/dev/authon/reactnative/wallet/AuthonWalletModule.kt +235 -0
  7. package/android/src/vendor/GENERATED.md +4 -0
  8. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AndroidCapabilityProbe.kt +86 -0
  9. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/AuthonWallet.kt +218 -0
  10. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bitcoin.kt +296 -0
  11. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Bytes.kt +74 -0
  12. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Chains.kt +157 -0
  13. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/CredentialManagerPasskeys.kt +192 -0
  14. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Der.kt +17 -0
  15. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DeviceStore.kt +170 -0
  16. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/DialogWalletApprover.kt +141 -0
  17. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Eip712.kt +176 -0
  18. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Encodings.kt +133 -0
  19. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmAccount.kt +45 -0
  20. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/EvmTransaction.kt +180 -0
  21. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/GfTables.kt +44 -0
  22. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/HdWallet.kt +130 -0
  23. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Http.kt +86 -0
  24. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/JsValues.kt +83 -0
  25. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/KeystoreDeviceStore.kt +236 -0
  26. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Prf.kt +111 -0
  27. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Proof.kt +134 -0
  28. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Shamir.kt +106 -0
  29. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/SignSummary.kt +335 -0
  30. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Solana.kt +195 -0
  31. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Tron.kt +184 -0
  32. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletApi.kt +361 -0
  33. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletCapabilities.kt +91 -0
  34. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletError.kt +74 -0
  35. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletOps.kt +551 -0
  36. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/WalletTypes.kt +78 -0
  37. package/android/src/vendor/kotlin/dev/authon/sdk/wallet/Xrp.kt +193 -0
  38. package/build/authonContext.d.ts +19 -0
  39. package/build/authonContext.d.ts.map +1 -0
  40. package/build/authonContext.js +20 -0
  41. package/build/authonContext.js.map +1 -0
  42. package/build/client.d.ts +92 -0
  43. package/build/client.d.ts.map +1 -0
  44. package/build/client.js +431 -0
  45. package/build/client.js.map +1 -0
  46. package/build/errors.d.ts +25 -0
  47. package/build/errors.d.ts.map +1 -0
  48. package/build/errors.js +15 -0
  49. package/build/errors.js.map +1 -0
  50. package/build/index.d.ts +7 -0
  51. package/build/index.d.ts.map +1 -0
  52. package/build/index.js +4 -0
  53. package/build/index.js.map +1 -0
  54. package/build/native.d.ts +43 -0
  55. package/build/native.d.ts.map +1 -0
  56. package/build/native.js +12 -0
  57. package/build/native.js.map +1 -0
  58. package/build/types.d.ts +167 -0
  59. package/build/types.d.ts.map +1 -0
  60. package/build/types.js +3 -0
  61. package/build/types.js.map +1 -0
  62. package/build/useAuthonWallet.d.ts +25 -0
  63. package/build/useAuthonWallet.d.ts.map +1 -0
  64. package/build/useAuthonWallet.js +77 -0
  65. package/build/useAuthonWallet.js.map +1 -0
  66. package/expo-module.config.json +9 -0
  67. package/ios/AuthonReactNativeWallet.podspec +41 -0
  68. package/ios/AuthonWalletModule.swift +233 -0
  69. package/ios/vendor/AuthonWallet/AuthonWallet.swift +232 -0
  70. package/ios/vendor/AuthonWallet/Capabilities.swift +149 -0
  71. package/ios/vendor/AuthonWallet/Chains/Bitcoin.swift +296 -0
  72. package/ios/vendor/AuthonWallet/Chains/Solana.swift +207 -0
  73. package/ios/vendor/AuthonWallet/Chains/Tron.swift +181 -0
  74. package/ios/vendor/AuthonWallet/Chains/XRP.swift +191 -0
  75. package/ios/vendor/AuthonWallet/Crypto/BIP39Wordlist.swift +262 -0
  76. package/ios/vendor/AuthonWallet/Crypto/Chains.swift +278 -0
  77. package/ios/vendor/AuthonWallet/Crypto/HDKey.swift +108 -0
  78. package/ios/vendor/AuthonWallet/Crypto/Secp256k1.swift +128 -0
  79. package/ios/vendor/AuthonWallet/Crypto/Shamir.swift +123 -0
  80. package/ios/vendor/AuthonWallet/EVM/Address.swift +57 -0
  81. package/ios/vendor/AuthonWallet/EVM/EvmAccount.swift +48 -0
  82. package/ios/vendor/AuthonWallet/EVM/Transaction.swift +165 -0
  83. package/ios/vendor/AuthonWallet/EVM/TypedData.swift +193 -0
  84. package/ios/vendor/AuthonWallet/Support/BigInteger.swift +220 -0
  85. package/ios/vendor/AuthonWallet/Support/Bytes.swift +89 -0
  86. package/ios/vendor/AuthonWallet/Support/JSONValue.swift +341 -0
  87. package/ios/vendor/AuthonWallet/UI/WalletApprover.swift +250 -0
  88. package/ios/vendor/AuthonWallet/Wallet/Backup.swift +69 -0
  89. package/ios/vendor/AuthonWallet/Wallet/DeviceStore.swift +351 -0
  90. package/ios/vendor/AuthonWallet/Wallet/Passkeys.swift +190 -0
  91. package/ios/vendor/AuthonWallet/Wallet/Proof.swift +143 -0
  92. package/ios/vendor/AuthonWallet/Wallet/Shares.swift +116 -0
  93. package/ios/vendor/AuthonWallet/Wallet/Summary.swift +342 -0
  94. package/ios/vendor/AuthonWallet/Wallet/WalletAPI.swift +361 -0
  95. package/ios/vendor/AuthonWallet/Wallet/WalletOps.swift +654 -0
  96. package/ios/vendor/AuthonWallet/WalletError.swift +84 -0
  97. package/ios/vendor/CKeccak/LICENSE +22 -0
  98. package/ios/vendor/CKeccak/README.md +30 -0
  99. package/ios/vendor/CKeccak/byte_order.h +59 -0
  100. package/ios/vendor/CKeccak/include/ckeccak.h +13 -0
  101. package/ios/vendor/CKeccak/memzero.c +75 -0
  102. package/ios/vendor/CKeccak/memzero.h +8 -0
  103. package/ios/vendor/CKeccak/options.h +99 -0
  104. package/ios/vendor/CKeccak/ripemd160.c +343 -0
  105. package/ios/vendor/CKeccak/ripemd160.h +22 -0
  106. package/ios/vendor/CKeccak/sha3.c +413 -0
  107. package/ios/vendor/CKeccak/sha3.h +89 -0
  108. package/ios/vendor/CMonocypher/LICENCE.md +173 -0
  109. package/ios/vendor/CMonocypher/README.md +27 -0
  110. package/ios/vendor/CMonocypher/include/monocypher-ed25519.h +140 -0
  111. package/ios/vendor/CMonocypher/include/monocypher.h +321 -0
  112. package/ios/vendor/CMonocypher/monocypher-ed25519.c +500 -0
  113. package/ios/vendor/CMonocypher/monocypher.c +2956 -0
  114. package/ios/vendor/CSecp256k1/COPYING +19 -0
  115. package/ios/vendor/CSecp256k1/README.md +35 -0
  116. package/ios/vendor/CSecp256k1/build/precomputed_ecmult.c +3 -0
  117. package/ios/vendor/CSecp256k1/build/precomputed_ecmult_gen.c +3 -0
  118. package/ios/vendor/CSecp256k1/build/secp256k1.c +3 -0
  119. package/ios/vendor/CSecp256k1/include/secp256k1.h +899 -0
  120. package/ios/vendor/CSecp256k1/include/secp256k1_preallocated.h +134 -0
  121. package/ios/vendor/CSecp256k1/include/secp256k1_recovery.h +113 -0
  122. package/ios/vendor/CSecp256k1/src/assumptions.h +87 -0
  123. package/ios/vendor/CSecp256k1/src/checkmem.h +102 -0
  124. package/ios/vendor/CSecp256k1/src/ecdsa.h +21 -0
  125. package/ios/vendor/CSecp256k1/src/ecdsa_impl.h +304 -0
  126. package/ios/vendor/CSecp256k1/src/eckey.h +25 -0
  127. package/ios/vendor/CSecp256k1/src/eckey_impl.h +92 -0
  128. package/ios/vendor/CSecp256k1/src/ecmult.h +61 -0
  129. package/ios/vendor/CSecp256k1/src/ecmult_const.h +38 -0
  130. package/ios/vendor/CSecp256k1/src/ecmult_const_impl.h +399 -0
  131. package/ios/vendor/CSecp256k1/src/ecmult_gen.h +143 -0
  132. package/ios/vendor/CSecp256k1/src/ecmult_gen_impl.h +341 -0
  133. package/ios/vendor/CSecp256k1/src/ecmult_impl.h +853 -0
  134. package/ios/vendor/CSecp256k1/src/field.h +350 -0
  135. package/ios/vendor/CSecp256k1/src/field_10x26.h +57 -0
  136. package/ios/vendor/CSecp256k1/src/field_10x26_impl.h +1232 -0
  137. package/ios/vendor/CSecp256k1/src/field_5x52.h +62 -0
  138. package/ios/vendor/CSecp256k1/src/field_5x52_impl.h +522 -0
  139. package/ios/vendor/CSecp256k1/src/field_5x52_int128_impl.h +274 -0
  140. package/ios/vendor/CSecp256k1/src/field_impl.h +457 -0
  141. package/ios/vendor/CSecp256k1/src/group.h +212 -0
  142. package/ios/vendor/CSecp256k1/src/group_impl.h +974 -0
  143. package/ios/vendor/CSecp256k1/src/hash.h +44 -0
  144. package/ios/vendor/CSecp256k1/src/hash_impl.h +299 -0
  145. package/ios/vendor/CSecp256k1/src/hsort.h +33 -0
  146. package/ios/vendor/CSecp256k1/src/hsort_impl.h +125 -0
  147. package/ios/vendor/CSecp256k1/src/int128.h +90 -0
  148. package/ios/vendor/CSecp256k1/src/int128_impl.h +18 -0
  149. package/ios/vendor/CSecp256k1/src/int128_native.h +19 -0
  150. package/ios/vendor/CSecp256k1/src/int128_native_impl.h +94 -0
  151. package/ios/vendor/CSecp256k1/src/int128_struct.h +14 -0
  152. package/ios/vendor/CSecp256k1/src/int128_struct_impl.h +205 -0
  153. package/ios/vendor/CSecp256k1/src/modinv32.h +43 -0
  154. package/ios/vendor/CSecp256k1/src/modinv32_impl.h +725 -0
  155. package/ios/vendor/CSecp256k1/src/modinv64.h +47 -0
  156. package/ios/vendor/CSecp256k1/src/modinv64_impl.h +780 -0
  157. package/ios/vendor/CSecp256k1/src/modules/recovery/main_impl.h +159 -0
  158. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.c +16456 -0
  159. package/ios/vendor/CSecp256k1/src/precomputed_ecmult.h +38 -0
  160. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.c +1779 -0
  161. package/ios/vendor/CSecp256k1/src/precomputed_ecmult_gen.h +26 -0
  162. package/ios/vendor/CSecp256k1/src/scalar.h +105 -0
  163. package/ios/vendor/CSecp256k1/src/scalar_4x64.h +19 -0
  164. package/ios/vendor/CSecp256k1/src/scalar_4x64_impl.h +1000 -0
  165. package/ios/vendor/CSecp256k1/src/scalar_8x32.h +19 -0
  166. package/ios/vendor/CSecp256k1/src/scalar_8x32_impl.h +816 -0
  167. package/ios/vendor/CSecp256k1/src/scalar_impl.h +321 -0
  168. package/ios/vendor/CSecp256k1/src/scalar_low.h +24 -0
  169. package/ios/vendor/CSecp256k1/src/scalar_low_impl.h +206 -0
  170. package/ios/vendor/CSecp256k1/src/scratch.h +44 -0
  171. package/ios/vendor/CSecp256k1/src/scratch_impl.h +99 -0
  172. package/ios/vendor/CSecp256k1/src/secp256k1.c +831 -0
  173. package/ios/vendor/CSecp256k1/src/selftest.h +32 -0
  174. package/ios/vendor/CSecp256k1/src/util.h +451 -0
  175. package/ios/vendor/GENERATED.md +4 -0
  176. package/package.json +66 -3
  177. package/src/authonContext.ts +30 -0
  178. package/src/client.ts +459 -0
  179. package/src/errors.ts +58 -0
  180. package/src/index.ts +26 -0
  181. package/src/native.ts +52 -0
  182. package/src/types.ts +171 -0
  183. package/src/useAuthonWallet.ts +103 -0
@@ -0,0 +1,134 @@
1
+ #ifndef SECP256K1_PREALLOCATED_H
2
+ #define SECP256K1_PREALLOCATED_H
3
+
4
+ #include "secp256k1.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ /* The module provided by this header file is intended for settings in which it
11
+ * is not possible or desirable to rely on dynamic memory allocation. It provides
12
+ * functions for creating, cloning, and destroying secp256k1 context objects in a
13
+ * contiguous fixed-size block of memory provided by the caller.
14
+ *
15
+ * Context objects created by functions in this module can be used like contexts
16
+ * objects created by functions in secp256k1.h, i.e., they can be passed to any
17
+ * API function that expects a context object (see secp256k1.h for details). The
18
+ * only exception is that context objects created by functions in this module
19
+ * must be destroyed using secp256k1_context_preallocated_destroy (in this
20
+ * module) instead of secp256k1_context_destroy (in secp256k1.h).
21
+ *
22
+ * It is guaranteed that functions in this module will not call malloc or its
23
+ * friends realloc, calloc, and free.
24
+ */
25
+
26
+ /** Determine the memory size of a secp256k1 context object to be created in
27
+ * caller-provided memory.
28
+ *
29
+ * The purpose of this function is to determine how much memory must be provided
30
+ * to secp256k1_context_preallocated_create.
31
+ *
32
+ * Returns: the required size of the caller-provided memory block
33
+ * In: flags: which parts of the context to initialize.
34
+ */
35
+ SECP256K1_API size_t secp256k1_context_preallocated_size(
36
+ unsigned int flags
37
+ ) SECP256K1_WARN_UNUSED_RESULT;
38
+
39
+ /** Create a secp256k1 context object in caller-provided memory.
40
+ *
41
+ * The caller must provide a pointer to a rewritable contiguous block of memory
42
+ * of size at least secp256k1_context_preallocated_size(flags) bytes, suitably
43
+ * aligned to hold an object of any type.
44
+ *
45
+ * The block of memory is exclusively owned by the created context object during
46
+ * the lifetime of this context object, which begins with the call to this
47
+ * function and ends when a call to secp256k1_context_preallocated_destroy
48
+ * (which destroys the context object again) returns. During the lifetime of the
49
+ * context object, the caller is obligated not to access this block of memory,
50
+ * i.e., the caller may not read or write the memory, e.g., by copying the memory
51
+ * contents to a different location or trying to create a second context object
52
+ * in the memory. In simpler words, the prealloc pointer (or any pointer derived
53
+ * from it) should not be used during the lifetime of the context object.
54
+ *
55
+ * Returns: pointer to newly created context object.
56
+ * In: prealloc: pointer to a rewritable contiguous block of memory of
57
+ * size at least secp256k1_context_preallocated_size(flags)
58
+ * bytes, as detailed above.
59
+ * flags: which parts of the context to initialize.
60
+ *
61
+ * See secp256k1_context_create (in secp256k1.h) for further details.
62
+ *
63
+ * See also secp256k1_context_randomize (in secp256k1.h)
64
+ * and secp256k1_context_preallocated_destroy.
65
+ */
66
+ SECP256K1_API secp256k1_context *secp256k1_context_preallocated_create(
67
+ void *prealloc,
68
+ unsigned int flags
69
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
70
+
71
+ /** Determine the memory size of a secp256k1 context object to be copied into
72
+ * caller-provided memory.
73
+ *
74
+ * Returns: the required size of the caller-provided memory block.
75
+ * In: ctx: pointer to a context to copy.
76
+ */
77
+ SECP256K1_API size_t secp256k1_context_preallocated_clone_size(
78
+ const secp256k1_context *ctx
79
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT;
80
+
81
+ /** Copy a secp256k1 context object into caller-provided memory.
82
+ *
83
+ * The caller must provide a pointer to a rewritable contiguous block of memory
84
+ * of size at least secp256k1_context_preallocated_size(flags) bytes, suitably
85
+ * aligned to hold an object of any type.
86
+ *
87
+ * The block of memory is exclusively owned by the created context object during
88
+ * the lifetime of this context object, see the description of
89
+ * secp256k1_context_preallocated_create for details.
90
+ *
91
+ * Cloning secp256k1_context_static is not possible, and should not be emulated by
92
+ * the caller (e.g., using memcpy). Create a new context instead.
93
+ *
94
+ * Returns: pointer to a newly created context object.
95
+ * Args: ctx: pointer to a context to copy (not secp256k1_context_static).
96
+ * In: prealloc: pointer to a rewritable contiguous block of memory of
97
+ * size at least secp256k1_context_preallocated_size(flags)
98
+ * bytes, as detailed above.
99
+ */
100
+ SECP256K1_API secp256k1_context *secp256k1_context_preallocated_clone(
101
+ const secp256k1_context *ctx,
102
+ void *prealloc
103
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_WARN_UNUSED_RESULT;
104
+
105
+ /** Destroy a secp256k1 context object that has been created in
106
+ * caller-provided memory.
107
+ *
108
+ * The context pointer may not be used afterwards.
109
+ *
110
+ * The context to destroy must have been created using
111
+ * secp256k1_context_preallocated_create or secp256k1_context_preallocated_clone.
112
+ * If the context has instead been created using secp256k1_context_create or
113
+ * secp256k1_context_clone, the behaviour is undefined. In that case,
114
+ * secp256k1_context_destroy must be used instead.
115
+ *
116
+ * If required, it is the responsibility of the caller to deallocate the block
117
+ * of memory properly after this function returns, e.g., by calling free on the
118
+ * preallocated pointer given to secp256k1_context_preallocated_create or
119
+ * secp256k1_context_preallocated_clone.
120
+ *
121
+ * Args: ctx: pointer to a context to destroy, constructed using
122
+ * secp256k1_context_preallocated_create or
123
+ * secp256k1_context_preallocated_clone
124
+ * (i.e., not secp256k1_context_static).
125
+ */
126
+ SECP256K1_API void secp256k1_context_preallocated_destroy(
127
+ secp256k1_context *ctx
128
+ ) SECP256K1_ARG_NONNULL(1);
129
+
130
+ #ifdef __cplusplus
131
+ }
132
+ #endif
133
+
134
+ #endif /* SECP256K1_PREALLOCATED_H */
@@ -0,0 +1,113 @@
1
+ #ifndef SECP256K1_RECOVERY_H
2
+ #define SECP256K1_RECOVERY_H
3
+
4
+ #include "secp256k1.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ /** Opaque data structure that holds a parsed ECDSA signature,
11
+ * supporting pubkey recovery.
12
+ *
13
+ * The exact representation of data inside is implementation defined and not
14
+ * guaranteed to be portable between different platforms or versions. It is
15
+ * however guaranteed to be 65 bytes in size, and can be safely copied/moved.
16
+ * If you need to convert to a format suitable for storage or transmission, use
17
+ * the secp256k1_ecdsa_signature_serialize_* and
18
+ * secp256k1_ecdsa_signature_parse_* functions.
19
+ *
20
+ * Furthermore, it is guaranteed that identical signatures (including their
21
+ * recoverability) will have identical representation, so they can be
22
+ * memcmp'ed.
23
+ */
24
+ typedef struct secp256k1_ecdsa_recoverable_signature {
25
+ unsigned char data[65];
26
+ } secp256k1_ecdsa_recoverable_signature;
27
+
28
+ /** Parse a compact ECDSA signature (64 bytes + recovery id).
29
+ *
30
+ * Returns: 1 when the signature could be parsed, 0 otherwise
31
+ * Args: ctx: pointer to a context object
32
+ * Out: sig: pointer to a signature object
33
+ * In: input64: pointer to a 64-byte compact signature
34
+ * recid: the recovery id (0, 1, 2 or 3)
35
+ */
36
+ SECP256K1_API int secp256k1_ecdsa_recoverable_signature_parse_compact(
37
+ const secp256k1_context *ctx,
38
+ secp256k1_ecdsa_recoverable_signature *sig,
39
+ const unsigned char *input64,
40
+ int recid
41
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
42
+
43
+ /** Convert a recoverable signature into a normal signature.
44
+ *
45
+ * Returns: 1
46
+ * Args: ctx: pointer to a context object.
47
+ * Out: sig: pointer to a normal signature.
48
+ * In: sigin: pointer to a recoverable signature.
49
+ */
50
+ SECP256K1_API int secp256k1_ecdsa_recoverable_signature_convert(
51
+ const secp256k1_context *ctx,
52
+ secp256k1_ecdsa_signature *sig,
53
+ const secp256k1_ecdsa_recoverable_signature *sigin
54
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3);
55
+
56
+ /** Serialize an ECDSA signature in compact format (64 bytes + recovery id).
57
+ *
58
+ * Returns: 1
59
+ * Args: ctx: pointer to a context object.
60
+ * Out: output64: pointer to a 64-byte array of the compact signature.
61
+ * recid: pointer to an integer to hold the recovery id.
62
+ * In: sig: pointer to an initialized signature object.
63
+ */
64
+ SECP256K1_API int secp256k1_ecdsa_recoverable_signature_serialize_compact(
65
+ const secp256k1_context *ctx,
66
+ unsigned char *output64,
67
+ int *recid,
68
+ const secp256k1_ecdsa_recoverable_signature *sig
69
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
70
+
71
+ /** Create a recoverable ECDSA signature.
72
+ *
73
+ * Returns: 1: signature created
74
+ * 0: the nonce generation function failed, or the secret key was invalid.
75
+ * Args: ctx: pointer to a context object (not secp256k1_context_static).
76
+ * Out: sig: pointer to an array where the signature will be placed.
77
+ * In: msghash32: the 32-byte message hash being signed.
78
+ * seckey: pointer to a 32-byte secret key.
79
+ * noncefp: pointer to a nonce generation function. If NULL,
80
+ * secp256k1_nonce_function_default is used.
81
+ * ndata: pointer to arbitrary data used by the nonce generation function
82
+ * (can be NULL for secp256k1_nonce_function_default).
83
+ */
84
+ SECP256K1_API int secp256k1_ecdsa_sign_recoverable(
85
+ const secp256k1_context *ctx,
86
+ secp256k1_ecdsa_recoverable_signature *sig,
87
+ const unsigned char *msghash32,
88
+ const unsigned char *seckey,
89
+ secp256k1_nonce_function noncefp,
90
+ const void *ndata
91
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
92
+
93
+ /** Recover an ECDSA public key from a signature.
94
+ *
95
+ * Returns: 1: public key successfully recovered (which guarantees a correct signature).
96
+ * 0: otherwise.
97
+ * Args: ctx: pointer to a context object.
98
+ * Out: pubkey: pointer to the recovered public key.
99
+ * In: sig: pointer to initialized signature that supports pubkey recovery.
100
+ * msghash32: the 32-byte message hash assumed to be signed.
101
+ */
102
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdsa_recover(
103
+ const secp256k1_context *ctx,
104
+ secp256k1_pubkey *pubkey,
105
+ const secp256k1_ecdsa_recoverable_signature *sig,
106
+ const unsigned char *msghash32
107
+ ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
108
+
109
+ #ifdef __cplusplus
110
+ }
111
+ #endif
112
+
113
+ #endif /* SECP256K1_RECOVERY_H */
@@ -0,0 +1,87 @@
1
+ /***********************************************************************
2
+ * Copyright (c) 2020 Pieter Wuille *
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_ASSUMPTIONS_H
8
+ #define SECP256K1_ASSUMPTIONS_H
9
+
10
+ #include <limits.h>
11
+
12
+ #include "util.h"
13
+ #if defined(SECP256K1_INT128_NATIVE)
14
+ #include "int128_native.h"
15
+ #endif
16
+
17
+ /* This library, like most software, relies on a number of compiler implementation defined (but not undefined)
18
+ behaviours. Although the behaviours we require are essentially universal we test them specifically here to
19
+ reduce the odds of experiencing an unwelcome surprise.
20
+ */
21
+
22
+ #if defined(__has_attribute)
23
+ # if __has_attribute(__unavailable__)
24
+ __attribute__((__unavailable__("Don't call this function. It only exists because STATIC_ASSERT cannot be used outside a function.")))
25
+ # endif
26
+ #endif
27
+ static void secp256k1_assumption_checker(void) {
28
+ /* Bytes are 8 bits. */
29
+ STATIC_ASSERT(CHAR_BIT == 8);
30
+
31
+ /* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32
32
+ without signed overflow, which would be undefined behaviour. */
33
+ STATIC_ASSERT(UINT_MAX <= UINT32_MAX);
34
+
35
+ /* Conversions from unsigned to signed outside of the bounds of the signed type are
36
+ implementation-defined. Verify that they function as reinterpreting the lower
37
+ bits of the input in two's complement notation. Do this for conversions:
38
+ - from uint(N)_t to int(N)_t with negative result
39
+ - from uint(2N)_t to int(N)_t with negative result
40
+ - from int(2N)_t to int(N)_t with negative result
41
+ - from int(2N)_t to int(N)_t with positive result */
42
+
43
+ /* To int8_t. */
44
+ STATIC_ASSERT(((int8_t)(uint8_t)0xAB == (int8_t)-(int8_t)0x55));
45
+ STATIC_ASSERT((int8_t)(uint16_t)0xABCD == (int8_t)-(int8_t)0x33);
46
+ STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0xCDEF == (int8_t)(uint8_t)0xEF);
47
+ STATIC_ASSERT((int8_t)(int16_t)(uint16_t)0x9234 == (int8_t)(uint8_t)0x34);
48
+
49
+ /* To int16_t. */
50
+ STATIC_ASSERT((int16_t)(uint16_t)0xBCDE == (int16_t)-(int16_t)0x4322);
51
+ STATIC_ASSERT((int16_t)(uint32_t)0xA1B2C3D4 == (int16_t)-(int16_t)0x3C2C);
52
+ STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0xC1D2E3F4 == (int16_t)(uint16_t)0xE3F4);
53
+ STATIC_ASSERT((int16_t)(int32_t)(uint32_t)0x92345678 == (int16_t)(uint16_t)0x5678);
54
+
55
+ /* To int32_t. */
56
+ STATIC_ASSERT((int32_t)(uint32_t)0xB2C3D4E5 == (int32_t)-(int32_t)0x4D3C2B1B);
57
+ STATIC_ASSERT((int32_t)(uint64_t)0xA123B456C789D012ULL == (int32_t)-(int32_t)0x38762FEE);
58
+ STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xC1D2E3F4A5B6C7D8ULL == (int32_t)(uint32_t)0xA5B6C7D8);
59
+ STATIC_ASSERT((int32_t)(int64_t)(uint64_t)0xABCDEF0123456789ULL == (int32_t)(uint32_t)0x23456789);
60
+
61
+ /* To int64_t. */
62
+ STATIC_ASSERT((int64_t)(uint64_t)0xB123C456D789E012ULL == (int64_t)-(int64_t)0x4EDC3BA928761FEEULL);
63
+ #if defined(SECP256K1_INT128_NATIVE)
64
+ STATIC_ASSERT((int64_t)(((uint128_t)0xA1234567B8901234ULL << 64) + 0xC5678901D2345678ULL) == (int64_t)-(int64_t)0x3A9876FE2DCBA988ULL);
65
+ STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xB1C2D3E4F5A6B7C8ULL << 64) + 0xD9E0F1A2B3C4D5E6ULL)) == (int64_t)(uint64_t)0xD9E0F1A2B3C4D5E6ULL);
66
+ STATIC_ASSERT(((int64_t)(int128_t)(((uint128_t)0xABCDEF0123456789ULL << 64) + 0x0123456789ABCDEFULL)) == (int64_t)(uint64_t)0x0123456789ABCDEFULL);
67
+
68
+ /* To int128_t. */
69
+ STATIC_ASSERT((int128_t)(((uint128_t)0xB1234567C8901234ULL << 64) + 0xD5678901E2345678ULL) == (int128_t)(-(int128_t)0x8E1648B3F50E80DCULL * 0x8E1648B3F50E80DDULL + 0x5EA688D5482F9464ULL));
70
+ #endif
71
+
72
+ /* Right shift on negative signed values is implementation defined. Verify that it
73
+ acts as a right shift in two's complement with sign extension (i.e duplicating
74
+ the top bit into newly added bits). */
75
+ STATIC_ASSERT((((int8_t)0xE8) >> 2) == (int8_t)(uint8_t)0xFA);
76
+ STATIC_ASSERT((((int16_t)0xE9AC) >> 4) == (int16_t)(uint16_t)0xFE9A);
77
+ STATIC_ASSERT((((int32_t)0x937C918A) >> 9) == (int32_t)(uint32_t)0xFFC9BE48);
78
+ STATIC_ASSERT((((int64_t)0xA8B72231DF9CF4B9ULL) >> 19) == (int64_t)(uint64_t)0xFFFFF516E4463BF3ULL);
79
+ #if defined(SECP256K1_INT128_NATIVE)
80
+ STATIC_ASSERT((((int128_t)(((uint128_t)0xCD833A65684A0DBCULL << 64) + 0xB349312F71EA7637ULL)) >> 39) == (int128_t)(((uint128_t)0xFFFFFFFFFF9B0674ULL << 64) + 0xCAD0941B79669262ULL));
81
+ #endif
82
+
83
+ /* This function is not supposed to be called. */
84
+ VERIFY_CHECK(0);
85
+ }
86
+
87
+ #endif /* SECP256K1_ASSUMPTIONS_H */
@@ -0,0 +1,102 @@
1
+ /***********************************************************************
2
+ * Copyright (c) 2022 Pieter Wuille *
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
+ /* The code here is inspired by Kris Kwiatkowski's approach in
8
+ * https://github.com/kriskwiatkowski/pqc/blob/main/src/common/ct_check.h
9
+ * to provide a general interface for memory-checking mechanisms, primarily
10
+ * for constant-time checking.
11
+ */
12
+
13
+ /* These macros are defined by this header file:
14
+ *
15
+ * - SECP256K1_CHECKMEM_ENABLED:
16
+ * - 1 if memory-checking integration is available, 0 otherwise.
17
+ * This is just a compile-time macro. Use the next macro to check it is actually
18
+ * available at runtime.
19
+ * - SECP256K1_CHECKMEM_RUNNING():
20
+ * - Acts like a function call, returning 1 if memory checking is available
21
+ * at runtime.
22
+ * - SECP256K1_CHECKMEM_CHECK(p, len):
23
+ * - Assert or otherwise fail in case the len-byte memory block pointed to by p is
24
+ * not considered entirely defined.
25
+ * - SECP256K1_CHECKMEM_CHECK_VERIFY(p, len):
26
+ * - Like SECP256K1_CHECKMEM_CHECK, but only works in VERIFY mode.
27
+ * - SECP256K1_CHECKMEM_UNDEFINE(p, len):
28
+ * - marks the len-byte memory block pointed to by p as undefined data (secret data,
29
+ * in the context of constant-time checking).
30
+ * - SECP256K1_CHECKMEM_DEFINE(p, len):
31
+ * - marks the len-byte memory pointed to by p as defined data (public data, in the
32
+ * context of constant-time checking).
33
+ * - SECP256K1_CHECKMEM_MSAN_DEFINE(p, len):
34
+ * - Like SECP256K1_CHECKMEM_DEFINE, but applies only to memory_sanitizer.
35
+ *
36
+ */
37
+
38
+ #ifndef SECP256K1_CHECKMEM_H
39
+ #define SECP256K1_CHECKMEM_H
40
+
41
+ /* Define a statement-like macro that ignores the arguments. */
42
+ #define SECP256K1_CHECKMEM_NOOP(p, len) do { (void)(p); (void)(len); } while(0)
43
+
44
+ /* If compiling under msan, map the SECP256K1_CHECKMEM_* functionality to msan.
45
+ * Choose this preferentially, even when VALGRIND is defined, as msan-compiled
46
+ * binaries can't be run under valgrind anyway. */
47
+ #if defined(__has_feature)
48
+ # if __has_feature(memory_sanitizer)
49
+ # include <sanitizer/msan_interface.h>
50
+ # define SECP256K1_CHECKMEM_ENABLED 1
51
+ # define SECP256K1_CHECKMEM_UNDEFINE(p, len) __msan_allocated_memory((p), (len))
52
+ # define SECP256K1_CHECKMEM_DEFINE(p, len) __msan_unpoison((p), (len))
53
+ # define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) __msan_unpoison((p), (len))
54
+ # define SECP256K1_CHECKMEM_CHECK(p, len) __msan_check_mem_is_initialized((p), (len))
55
+ # define SECP256K1_CHECKMEM_RUNNING() (1)
56
+ # endif
57
+ #endif
58
+
59
+ #if !defined SECP256K1_CHECKMEM_MSAN_DEFINE
60
+ # define SECP256K1_CHECKMEM_MSAN_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))
61
+ #endif
62
+
63
+ /* If valgrind integration is desired (through the VALGRIND define), implement the
64
+ * SECP256K1_CHECKMEM_* macros using valgrind. */
65
+ #if !defined SECP256K1_CHECKMEM_ENABLED
66
+ # if defined VALGRIND
67
+ # include <stddef.h>
68
+ # if defined(__clang__) && defined(__APPLE__)
69
+ # pragma clang diagnostic push
70
+ # pragma clang diagnostic ignored "-Wreserved-identifier"
71
+ # endif
72
+ # include <valgrind/memcheck.h>
73
+ # if defined(__clang__) && defined(__APPLE__)
74
+ # pragma clang diagnostic pop
75
+ # endif
76
+ # define SECP256K1_CHECKMEM_ENABLED 1
77
+ # define SECP256K1_CHECKMEM_UNDEFINE(p, len) VALGRIND_MAKE_MEM_UNDEFINED((p), (len))
78
+ # define SECP256K1_CHECKMEM_DEFINE(p, len) VALGRIND_MAKE_MEM_DEFINED((p), (len))
79
+ # define SECP256K1_CHECKMEM_CHECK(p, len) VALGRIND_CHECK_MEM_IS_DEFINED((p), (len))
80
+ /* VALGRIND_MAKE_MEM_DEFINED returns 0 iff not running on memcheck.
81
+ * This is more precise than the RUNNING_ON_VALGRIND macro, which
82
+ * checks for valgrind in general instead of memcheck specifically. */
83
+ # define SECP256K1_CHECKMEM_RUNNING() (VALGRIND_MAKE_MEM_DEFINED(NULL, 0) != 0)
84
+ # endif
85
+ #endif
86
+
87
+ /* As a fall-back, map these macros to dummy statements. */
88
+ #if !defined SECP256K1_CHECKMEM_ENABLED
89
+ # define SECP256K1_CHECKMEM_ENABLED 0
90
+ # define SECP256K1_CHECKMEM_UNDEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))
91
+ # define SECP256K1_CHECKMEM_DEFINE(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))
92
+ # define SECP256K1_CHECKMEM_CHECK(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))
93
+ # define SECP256K1_CHECKMEM_RUNNING() (0)
94
+ #endif
95
+
96
+ #if defined VERIFY
97
+ #define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_CHECK((p), (len))
98
+ #else
99
+ #define SECP256K1_CHECKMEM_CHECK_VERIFY(p, len) SECP256K1_CHECKMEM_NOOP((p), (len))
100
+ #endif
101
+
102
+ #endif /* SECP256K1_CHECKMEM_H */
@@ -0,0 +1,21 @@
1
+ /***********************************************************************
2
+ * Copyright (c) 2013, 2014 Pieter Wuille *
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_ECDSA_H
8
+ #define SECP256K1_ECDSA_H
9
+
10
+ #include <stddef.h>
11
+
12
+ #include "scalar.h"
13
+ #include "group.h"
14
+ #include "ecmult.h"
15
+
16
+ static int secp256k1_ecdsa_sig_parse(secp256k1_scalar *r, secp256k1_scalar *s, const unsigned char *sig, size_t size);
17
+ static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, size_t *size, const secp256k1_scalar *r, const secp256k1_scalar *s);
18
+ static int secp256k1_ecdsa_sig_verify(const secp256k1_scalar* r, const secp256k1_scalar* s, const secp256k1_ge *pubkey, const secp256k1_scalar *message);
19
+ static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, secp256k1_scalar* r, secp256k1_scalar* s, const secp256k1_scalar *seckey, const secp256k1_scalar *message, const secp256k1_scalar *nonce, int *recid);
20
+
21
+ #endif /* SECP256K1_ECDSA_H */