@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,413 @@
1
+ /* sha3.c - an implementation of Secure Hash Algorithm 3 (Keccak).
2
+ * based on the
3
+ * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
4
+ * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
5
+ *
6
+ * Copyright: 2013 Aleksey Kravchenko <rhash.admin@gmail.com>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a
9
+ * copy of this software and associated documentation files (the "Software"),
10
+ * to deal in the Software without restriction, including without limitation
11
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the
13
+ * Software is furnished to do so.
14
+ *
15
+ * This program is distributed in the hope that it will be useful, but
16
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
+ * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
18
+ */
19
+
20
+ #include <assert.h>
21
+ #include <string.h>
22
+
23
+ #include "sha3.h"
24
+ #include "memzero.h"
25
+ #include "byte_order.h"
26
+
27
+ #define I64(x) x##LL
28
+ #define ROTL64(qword, n) ((qword) << (n) ^ ((qword) >> (64 - (n))))
29
+ #define le2me_64(x) (x)
30
+ #define IS_ALIGNED_64(p) (0 == (((uintptr_t)(const void *)(p) & 0x7)))
31
+ # define me64_to_le_str(to, from, length) memcpy((to), (from), (length))
32
+
33
+ /* constants */
34
+ #define NumberOfRounds 24
35
+
36
+ /* SHA3 (Keccak) constants for 24 rounds */
37
+ static uint64_t keccak_round_constants[NumberOfRounds] = {
38
+ I64(0x0000000000000001), I64(0x0000000000008082), I64(0x800000000000808A), I64(0x8000000080008000),
39
+ I64(0x000000000000808B), I64(0x0000000080000001), I64(0x8000000080008081), I64(0x8000000000008009),
40
+ I64(0x000000000000008A), I64(0x0000000000000088), I64(0x0000000080008009), I64(0x000000008000000A),
41
+ I64(0x000000008000808B), I64(0x800000000000008B), I64(0x8000000000008089), I64(0x8000000000008003),
42
+ I64(0x8000000000008002), I64(0x8000000000000080), I64(0x000000000000800A), I64(0x800000008000000A),
43
+ I64(0x8000000080008081), I64(0x8000000000008080), I64(0x0000000080000001), I64(0x8000000080008008)
44
+ };
45
+
46
+ /* Initializing a sha3 context for given number of output bits */
47
+ static void keccak_Init(SHA3_CTX *ctx, unsigned bits)
48
+ {
49
+ /* NB: The Keccak capacity parameter = bits * 2 */
50
+ unsigned rate = 1600 - bits * 2;
51
+
52
+ memzero(ctx, sizeof(SHA3_CTX));
53
+ ctx->block_size = rate / 8;
54
+ assert(rate <= 1600 && (rate % 64) == 0);
55
+ }
56
+
57
+ /**
58
+ * Initialize context before calculating hash.
59
+ *
60
+ * @param ctx context to initialize
61
+ */
62
+ void sha3_224_Init(SHA3_CTX *ctx)
63
+ {
64
+ keccak_Init(ctx, 224);
65
+ }
66
+
67
+ /**
68
+ * Initialize context before calculating hash.
69
+ *
70
+ * @param ctx context to initialize
71
+ */
72
+ void sha3_256_Init(SHA3_CTX *ctx)
73
+ {
74
+ keccak_Init(ctx, 256);
75
+ }
76
+
77
+ /**
78
+ * Initialize context before calculating hash.
79
+ *
80
+ * @param ctx context to initialize
81
+ */
82
+ void sha3_384_Init(SHA3_CTX *ctx)
83
+ {
84
+ keccak_Init(ctx, 384);
85
+ }
86
+
87
+ /**
88
+ * Initialize context before calculating hash.
89
+ *
90
+ * @param ctx context to initialize
91
+ */
92
+ void sha3_512_Init(SHA3_CTX *ctx)
93
+ {
94
+ keccak_Init(ctx, 512);
95
+ }
96
+
97
+ /* Keccak theta() transformation */
98
+ static void keccak_theta(uint64_t *A)
99
+ {
100
+ unsigned int x = 0;
101
+ uint64_t C[5] = {0}, D[5] = {0};
102
+
103
+ for (x = 0; x < 5; x++) {
104
+ C[x] = A[x] ^ A[x + 5] ^ A[x + 10] ^ A[x + 15] ^ A[x + 20];
105
+ }
106
+ D[0] = ROTL64(C[1], 1) ^ C[4];
107
+ D[1] = ROTL64(C[2], 1) ^ C[0];
108
+ D[2] = ROTL64(C[3], 1) ^ C[1];
109
+ D[3] = ROTL64(C[4], 1) ^ C[2];
110
+ D[4] = ROTL64(C[0], 1) ^ C[3];
111
+
112
+ for (x = 0; x < 5; x++) {
113
+ A[x] ^= D[x];
114
+ A[x + 5] ^= D[x];
115
+ A[x + 10] ^= D[x];
116
+ A[x + 15] ^= D[x];
117
+ A[x + 20] ^= D[x];
118
+ }
119
+ }
120
+
121
+ /* Keccak pi() transformation */
122
+ static void keccak_pi(uint64_t *A)
123
+ {
124
+ uint64_t A1 = 0;
125
+ A1 = A[1];
126
+ A[ 1] = A[ 6];
127
+ A[ 6] = A[ 9];
128
+ A[ 9] = A[22];
129
+ A[22] = A[14];
130
+ A[14] = A[20];
131
+ A[20] = A[ 2];
132
+ A[ 2] = A[12];
133
+ A[12] = A[13];
134
+ A[13] = A[19];
135
+ A[19] = A[23];
136
+ A[23] = A[15];
137
+ A[15] = A[ 4];
138
+ A[ 4] = A[24];
139
+ A[24] = A[21];
140
+ A[21] = A[ 8];
141
+ A[ 8] = A[16];
142
+ A[16] = A[ 5];
143
+ A[ 5] = A[ 3];
144
+ A[ 3] = A[18];
145
+ A[18] = A[17];
146
+ A[17] = A[11];
147
+ A[11] = A[ 7];
148
+ A[ 7] = A[10];
149
+ A[10] = A1;
150
+ /* note: A[ 0] is left as is */
151
+ }
152
+
153
+ /* Keccak chi() transformation */
154
+ static void keccak_chi(uint64_t *A)
155
+ {
156
+ int i = 0;
157
+ for (i = 0; i < 25; i += 5) {
158
+ uint64_t A0 = A[0 + i], A1 = A[1 + i];
159
+ A[0 + i] ^= ~A1 & A[2 + i];
160
+ A[1 + i] ^= ~A[2 + i] & A[3 + i];
161
+ A[2 + i] ^= ~A[3 + i] & A[4 + i];
162
+ A[3 + i] ^= ~A[4 + i] & A0;
163
+ A[4 + i] ^= ~A0 & A1;
164
+ }
165
+ }
166
+
167
+ static void sha3_permutation(uint64_t *state)
168
+ {
169
+ #if BYTE_ORDER == BIG_ENDIAN
170
+ int i;
171
+ for (i = 0; i < 25; i++)
172
+ {
173
+ REVERSE64(state[i], state[i]);
174
+ }
175
+ #endif
176
+ int round = 0;
177
+ for (round = 0; round < NumberOfRounds; round++)
178
+ {
179
+ keccak_theta(state);
180
+
181
+ /* apply Keccak rho() transformation */
182
+ state[ 1] = ROTL64(state[ 1], 1);
183
+ state[ 2] = ROTL64(state[ 2], 62);
184
+ state[ 3] = ROTL64(state[ 3], 28);
185
+ state[ 4] = ROTL64(state[ 4], 27);
186
+ state[ 5] = ROTL64(state[ 5], 36);
187
+ state[ 6] = ROTL64(state[ 6], 44);
188
+ state[ 7] = ROTL64(state[ 7], 6);
189
+ state[ 8] = ROTL64(state[ 8], 55);
190
+ state[ 9] = ROTL64(state[ 9], 20);
191
+ state[10] = ROTL64(state[10], 3);
192
+ state[11] = ROTL64(state[11], 10);
193
+ state[12] = ROTL64(state[12], 43);
194
+ state[13] = ROTL64(state[13], 25);
195
+ state[14] = ROTL64(state[14], 39);
196
+ state[15] = ROTL64(state[15], 41);
197
+ state[16] = ROTL64(state[16], 45);
198
+ state[17] = ROTL64(state[17], 15);
199
+ state[18] = ROTL64(state[18], 21);
200
+ state[19] = ROTL64(state[19], 8);
201
+ state[20] = ROTL64(state[20], 18);
202
+ state[21] = ROTL64(state[21], 2);
203
+ state[22] = ROTL64(state[22], 61);
204
+ state[23] = ROTL64(state[23], 56);
205
+ state[24] = ROTL64(state[24], 14);
206
+
207
+ keccak_pi(state);
208
+ keccak_chi(state);
209
+
210
+ /* apply iota(state, round) */
211
+ *state ^= keccak_round_constants[round];
212
+ }
213
+ #if BYTE_ORDER == BIG_ENDIAN
214
+ for (i = 0; i < 25; i++)
215
+ {
216
+ REVERSE64(state[i], state[i]);
217
+ }
218
+ #endif
219
+ }
220
+
221
+ /**
222
+ * The core transformation. Process the specified block of data.
223
+ *
224
+ * @param hash the algorithm state
225
+ * @param block the message block to process
226
+ * @param block_size the size of the processed block in bytes
227
+ */
228
+ static void sha3_process_block(uint64_t hash[25], const uint64_t *block, size_t block_size)
229
+ {
230
+ /* expanded loop */
231
+ hash[ 0] ^= le2me_64(block[ 0]);
232
+ hash[ 1] ^= le2me_64(block[ 1]);
233
+ hash[ 2] ^= le2me_64(block[ 2]);
234
+ hash[ 3] ^= le2me_64(block[ 3]);
235
+ hash[ 4] ^= le2me_64(block[ 4]);
236
+ hash[ 5] ^= le2me_64(block[ 5]);
237
+ hash[ 6] ^= le2me_64(block[ 6]);
238
+ hash[ 7] ^= le2me_64(block[ 7]);
239
+ hash[ 8] ^= le2me_64(block[ 8]);
240
+ /* if not sha3-512 */
241
+ if (block_size > 72) {
242
+ hash[ 9] ^= le2me_64(block[ 9]);
243
+ hash[10] ^= le2me_64(block[10]);
244
+ hash[11] ^= le2me_64(block[11]);
245
+ hash[12] ^= le2me_64(block[12]);
246
+ /* if not sha3-384 */
247
+ if (block_size > 104) {
248
+ hash[13] ^= le2me_64(block[13]);
249
+ hash[14] ^= le2me_64(block[14]);
250
+ hash[15] ^= le2me_64(block[15]);
251
+ hash[16] ^= le2me_64(block[16]);
252
+ /* if not sha3-256 */
253
+ if (block_size > 136) {
254
+ hash[17] ^= le2me_64(block[17]);
255
+ #ifdef FULL_SHA3_FAMILY_SUPPORT
256
+ /* if not sha3-224 */
257
+ if (block_size > 144) {
258
+ hash[18] ^= le2me_64(block[18]);
259
+ hash[19] ^= le2me_64(block[19]);
260
+ hash[20] ^= le2me_64(block[20]);
261
+ hash[21] ^= le2me_64(block[21]);
262
+ hash[22] ^= le2me_64(block[22]);
263
+ hash[23] ^= le2me_64(block[23]);
264
+ hash[24] ^= le2me_64(block[24]);
265
+ }
266
+ #endif
267
+ }
268
+ }
269
+ }
270
+ /* make a permutation of the hash */
271
+ sha3_permutation(hash);
272
+ }
273
+
274
+ #define SHA3_FINALIZED 0x80000000
275
+
276
+ /**
277
+ * Calculate message hash.
278
+ * Can be called repeatedly with chunks of the message to be hashed.
279
+ *
280
+ * @param ctx the algorithm context containing current hashing state
281
+ * @param msg message chunk
282
+ * @param size length of the message chunk
283
+ */
284
+ void sha3_Update(SHA3_CTX *ctx, const unsigned char *msg, size_t size)
285
+ {
286
+ if (size == 0) return;
287
+
288
+ size_t idx = (size_t)ctx->rest;
289
+ size_t block_size = (size_t)ctx->block_size;
290
+
291
+ if (ctx->rest & SHA3_FINALIZED) return; /* too late for additional input */
292
+ ctx->rest = (unsigned)((ctx->rest + size) % block_size);
293
+
294
+ /* fill partial block */
295
+ if (idx) {
296
+ size_t left = block_size - idx;
297
+ memcpy((char*)ctx->message + idx, msg, (size < left ? size : left));
298
+ if (size < left) return;
299
+
300
+ /* process partial block */
301
+ sha3_process_block(ctx->hash, ctx->message, block_size);
302
+ msg += left;
303
+ size -= left;
304
+ }
305
+ while (size >= block_size) {
306
+ uint64_t *aligned_message_block = NULL;
307
+ if (IS_ALIGNED_64(msg)) {
308
+ /* the most common case is processing of an already aligned message
309
+ without copying it */
310
+ aligned_message_block = (uint64_t*)(void*)msg;
311
+ } else {
312
+ memcpy(ctx->message, msg, block_size);
313
+ aligned_message_block = ctx->message;
314
+ }
315
+
316
+ sha3_process_block(ctx->hash, aligned_message_block, block_size);
317
+ msg += block_size;
318
+ size -= block_size;
319
+ }
320
+ if (size) {
321
+ memcpy(ctx->message, msg, size); /* save leftovers */
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Store calculated hash into the given array.
327
+ *
328
+ * @param ctx the algorithm context containing current hashing state
329
+ * @param result calculated hash in binary form
330
+ */
331
+ void sha3_Final(SHA3_CTX *ctx, unsigned char* result)
332
+ {
333
+ size_t digest_length = 100 - ctx->block_size / 2;
334
+ const size_t block_size = ctx->block_size;
335
+
336
+ if (!(ctx->rest & SHA3_FINALIZED))
337
+ {
338
+ /* clear the rest of the data queue */
339
+ memzero((char*)ctx->message + ctx->rest, block_size - ctx->rest);
340
+ ((char*)ctx->message)[ctx->rest] |= 0x06;
341
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
342
+
343
+ /* process final block */
344
+ sha3_process_block(ctx->hash, ctx->message, block_size);
345
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
346
+ }
347
+
348
+ assert(block_size > digest_length);
349
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
350
+ memzero(ctx, sizeof(SHA3_CTX));
351
+ }
352
+
353
+ #if USE_KECCAK
354
+ /**
355
+ * Store calculated hash into the given array.
356
+ *
357
+ * @param ctx the algorithm context containing current hashing state
358
+ * @param result calculated hash in binary form
359
+ */
360
+ void keccak_Final(SHA3_CTX *ctx, unsigned char* result)
361
+ {
362
+ size_t digest_length = 100 - ctx->block_size / 2;
363
+ const size_t block_size = ctx->block_size;
364
+
365
+ if (!(ctx->rest & SHA3_FINALIZED))
366
+ {
367
+ /* clear the rest of the data queue */
368
+ memzero((char*)ctx->message + ctx->rest, block_size - ctx->rest);
369
+ ((char*)ctx->message)[ctx->rest] |= 0x01;
370
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
371
+
372
+ /* process final block */
373
+ sha3_process_block(ctx->hash, ctx->message, block_size);
374
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
375
+ }
376
+
377
+ assert(block_size > digest_length);
378
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
379
+ memzero(ctx, sizeof(SHA3_CTX));
380
+ }
381
+
382
+ void keccak_256(const unsigned char* data, size_t len, unsigned char* digest)
383
+ {
384
+ SHA3_CTX ctx = {0};
385
+ keccak_256_Init(&ctx);
386
+ keccak_Update(&ctx, data, len);
387
+ keccak_Final(&ctx, digest);
388
+ }
389
+
390
+ void keccak_512(const unsigned char* data, size_t len, unsigned char* digest)
391
+ {
392
+ SHA3_CTX ctx = {0};
393
+ keccak_512_Init(&ctx);
394
+ keccak_Update(&ctx, data, len);
395
+ keccak_Final(&ctx, digest);
396
+ }
397
+ #endif /* USE_KECCAK */
398
+
399
+ void sha3_256(const unsigned char* data, size_t len, unsigned char* digest)
400
+ {
401
+ SHA3_CTX ctx = {0};
402
+ sha3_256_Init(&ctx);
403
+ sha3_Update(&ctx, data, len);
404
+ sha3_Final(&ctx, digest);
405
+ }
406
+
407
+ void sha3_512(const unsigned char* data, size_t len, unsigned char* digest)
408
+ {
409
+ SHA3_CTX ctx = {0};
410
+ sha3_512_Init(&ctx);
411
+ sha3_Update(&ctx, data, len);
412
+ sha3_Final(&ctx, digest);
413
+ }
@@ -0,0 +1,89 @@
1
+ /* sha3.h - an implementation of Secure Hash Algorithm 3 (Keccak).
2
+ * based on the
3
+ * The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
4
+ * by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
5
+ *
6
+ * Copyright: 2013 Aleksey Kravchenko <rhash.admin@gmail.com>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a
9
+ * copy of this software and associated documentation files (the "Software"),
10
+ * to deal in the Software without restriction, including without limitation
11
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
+ * and/or sell copies of the Software, and to permit persons to whom the
13
+ * Software is furnished to do so.
14
+ *
15
+ * This program is distributed in the hope that it will be useful, but
16
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
+ * or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
18
+ */
19
+
20
+ #ifndef __SHA3_H__
21
+ #define __SHA3_H__
22
+
23
+ #include <stdint.h>
24
+ #include "options.h"
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ #define sha3_224_hash_size 28
31
+ #define sha3_256_hash_size 32
32
+ #define sha3_384_hash_size 48
33
+ #define sha3_512_hash_size 64
34
+ #define sha3_max_permutation_size 25
35
+ #define sha3_max_rate_in_qwords 24
36
+
37
+ #define SHA3_224_BLOCK_LENGTH 144
38
+ #define SHA3_256_BLOCK_LENGTH 136
39
+ #define SHA3_384_BLOCK_LENGTH 104
40
+ #define SHA3_512_BLOCK_LENGTH 72
41
+
42
+ #define SHA3_224_DIGEST_LENGTH sha3_224_hash_size
43
+ #define SHA3_256_DIGEST_LENGTH sha3_256_hash_size
44
+ #define SHA3_384_DIGEST_LENGTH sha3_384_hash_size
45
+ #define SHA3_512_DIGEST_LENGTH sha3_512_hash_size
46
+
47
+ /**
48
+ * SHA3 Algorithm context.
49
+ */
50
+ typedef struct SHA3_CTX
51
+ {
52
+ /* 1600 bits algorithm hashing state */
53
+ uint64_t hash[sha3_max_permutation_size];
54
+ /* 1536-bit buffer for leftovers */
55
+ uint64_t message[sha3_max_rate_in_qwords];
56
+ /* count of bytes in the message[] buffer */
57
+ unsigned rest;
58
+ /* size of a message block processed at once */
59
+ unsigned block_size;
60
+ } SHA3_CTX;
61
+
62
+ /* methods for calculating the hash function */
63
+
64
+ void sha3_224_Init(SHA3_CTX *ctx);
65
+ void sha3_256_Init(SHA3_CTX *ctx);
66
+ void sha3_384_Init(SHA3_CTX *ctx);
67
+ void sha3_512_Init(SHA3_CTX *ctx);
68
+ void sha3_Update(SHA3_CTX *ctx, const unsigned char* msg, size_t size);
69
+ void sha3_Final(SHA3_CTX *ctx, unsigned char* result);
70
+
71
+ #if USE_KECCAK
72
+ #define keccak_224_Init sha3_224_Init
73
+ #define keccak_256_Init sha3_256_Init
74
+ #define keccak_384_Init sha3_384_Init
75
+ #define keccak_512_Init sha3_512_Init
76
+ #define keccak_Update sha3_Update
77
+ void keccak_Final(SHA3_CTX *ctx, unsigned char* result);
78
+ void keccak_256(const unsigned char* data, size_t len, unsigned char* digest);
79
+ void keccak_512(const unsigned char* data, size_t len, unsigned char* digest);
80
+ #endif
81
+
82
+ void sha3_256(const unsigned char* data, size_t len, unsigned char* digest);
83
+ void sha3_512(const unsigned char* data, size_t len, unsigned char* digest);
84
+
85
+ #ifdef __cplusplus
86
+ } /* extern "C" */
87
+ #endif /* __cplusplus */
88
+
89
+ #endif /* __SHA3_H__ */
@@ -0,0 +1,173 @@
1
+ Monocypher as a whole is dual-licensed. Choose whichever licence you
2
+ want from the two licences listed below.
3
+
4
+ The first licence is a regular 2-clause BSD licence. The second licence
5
+ is the CC-0 from Creative Commons. It is intended to release Monocypher
6
+ to the public domain. The BSD licence serves as a fallback option.
7
+
8
+ See the individual files for specific information about who contributed
9
+ to what file during which years. See below for special notes.
10
+
11
+ Licence 1 (2-clause BSD)
12
+ ------------------------
13
+
14
+ Copyright (c) 2017-2023, Loup Vaillant
15
+ Copyright (c) 2017-2019, Michael Savage
16
+ Copyright (c) 2017-2023, Fabio Scotoni
17
+ All rights reserved.
18
+
19
+ Redistribution and use in source and binary forms, with or without
20
+ modification, are permitted provided that the following conditions are
21
+ met:
22
+
23
+ 1. Redistributions of source code must retain the above copyright
24
+ notice, this list of conditions and the following disclaimer.
25
+
26
+ 2. Redistributions in binary form must reproduce the above copyright
27
+ notice, this list of conditions and the following disclaimer in the
28
+ documentation and/or other materials provided with the
29
+ distribution.
30
+
31
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
+
43
+
44
+ Licence 2 (CC-0)
45
+ ----------------
46
+
47
+ > CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
48
+ > LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
49
+ > ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
50
+ > INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
51
+ > REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
52
+ > PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
53
+ > THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
54
+ > HEREUNDER.
55
+
56
+ ### Statement of Purpose
57
+
58
+ The laws of most jurisdictions throughout the world automatically confer
59
+ exclusive Copyright and Related Rights (defined below) upon the creator
60
+ and subsequent owner(s) (each and all, an "owner") of an original work
61
+ of authorship and/or a database (each, a "Work").
62
+
63
+ Certain owners wish to permanently relinquish those rights to a Work for
64
+ the purpose of contributing to a commons of creative, cultural and
65
+ scientific works ("Commons") that the public can reliably and without
66
+ fear of later claims of infringement build upon, modify, incorporate in
67
+ other works, reuse and redistribute as freely as possible in any form
68
+ whatsoever and for any purposes, including without limitation commercial
69
+ purposes. These owners may contribute to the Commons to promote the
70
+ ideal of a free culture and the further production of creative, cultural
71
+ and scientific works, or to gain reputation or greater distribution for
72
+ their Work in part through the use and efforts of others.
73
+
74
+ For these and/or other purposes and motivations, and without any
75
+ expectation of additional consideration or compensation, the person
76
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or
77
+ she is an owner of Copyright and Related Rights in the Work, voluntarily
78
+ elects to apply CC0 to the Work and publicly distribute the Work under
79
+ its terms, with knowledge of his or her Copyright and Related Rights in
80
+ the Work and the meaning and intended legal effect of CC0 on those
81
+ rights.
82
+
83
+ 1. **Copyright and Related Rights.** A Work made available under CC0 may
84
+ be protected by copyright and related or neighboring rights
85
+ ("Copyright and Related Rights"). Copyright and Related Rights
86
+ include, but are not limited to, the following:
87
+
88
+ - the right to reproduce, adapt, distribute, perform, display,
89
+ communicate, and translate a Work;
90
+ - moral rights retained by the original author(s) and/or
91
+ performer(s); publicity and privacy rights pertaining to a person's
92
+ image or likeness depicted in a Work;
93
+ - rights protecting against unfair competition in regards to a Work,
94
+ subject to the limitations in paragraph 4(a), below;
95
+ - rights protecting the extraction, dissemination, use and reuse of
96
+ data in a Work;
97
+ - database rights (such as those arising under Directive 96/9/EC of
98
+ the European Parliament and of the Council of 11 March 1996 on the
99
+ legal protection of databases, and under any national
100
+ implementation thereof, including any amended or successor version
101
+ of such directive); and
102
+ - other similar, equivalent or corresponding rights throughout the
103
+ world based on applicable law or treaty, and any national
104
+ implementations thereof.
105
+
106
+ 2. **Waiver.** To the greatest extent permitted by, but not in
107
+ contravention of, applicable law, Affirmer hereby overtly, fully,
108
+ permanently, irrevocably and unconditionally waives, abandons, and
109
+ surrenders all of Affirmer's Copyright and Related Rights and
110
+ associated claims and causes of action, whether now known or unknown
111
+ (including existing as well as future claims and causes of action),
112
+ in the Work (i) in all territories worldwide, (ii) for the maximum
113
+ duration provided by applicable law or treaty (including future time
114
+ extensions), (iii) in any current or future medium and for any number
115
+ of copies, and (iv) for any purpose whatsoever, including without
116
+ limitation commercial, advertising or promotional purposes (the
117
+ "Waiver"). Affirmer makes the Waiver for the benefit of each member
118
+ of the public at large and to the detriment of Affirmer's heirs and
119
+ successors, fully intending that such Waiver shall not be subject to
120
+ revocation, rescission, cancellation, termination, or any other legal
121
+ or equitable action to disrupt the quiet enjoyment of the Work by the
122
+ public as contemplated by Affirmer's express Statement of Purpose.
123
+
124
+ 3. **Public License Fallback.** Should any part of the Waiver for any
125
+ reason be judged legally invalid or ineffective under applicable law,
126
+ then the Waiver shall be preserved to the maximum extent permitted
127
+ taking into account Affirmer's express Statement of Purpose. In
128
+ addition, to the extent the Waiver is so judged Affirmer hereby
129
+ grants to each affected person a royalty-free, non transferable, non
130
+ sublicensable, non exclusive, irrevocable and unconditional license
131
+ to exercise Affirmer's Copyright and Related Rights in the Work (i)
132
+ in all territories worldwide, (ii) for the maximum duration provided
133
+ by applicable law or treaty (including future time extensions), (iii)
134
+ in any current or future medium and for any number of copies, and
135
+ (iv) for any purpose whatsoever, including without limitation
136
+ commercial, advertising or promotional purposes (the "License"). The
137
+ License shall be deemed effective as of the date CC0 was applied by
138
+ Affirmer to the Work. Should any part of the License for any reason
139
+ be judged legally invalid or ineffective under applicable law, such
140
+ partial invalidity or ineffectiveness shall not invalidate the
141
+ remainder of the License, and in such case Affirmer hereby affirms
142
+ that he or she will not (i) exercise any of his or her remaining
143
+ Copyright and Related Rights in the Work or (ii) assert any
144
+ associated claims and causes of action with respect to the Work, in
145
+ either case contrary to Affirmer's express Statement of Purpose.
146
+
147
+ 4. **Limitations and Disclaimers.**
148
+
149
+ - No trademark or patent rights held by Affirmer are waived,
150
+ abandoned, surrendered, licensed or otherwise affected by this
151
+ document.
152
+ - Affirmer offers the Work as-is and makes no representations or
153
+ warranties of any kind concerning the Work, express, implied,
154
+ statutory or otherwise, including without limitation warranties of
155
+ title, merchantability, fitness for a particular purpose, non
156
+ infringement, or the absence of latent or other defects, accuracy,
157
+ or the present or absence of errors, whether or not discoverable,
158
+ all to the greatest extent permissible under applicable law.
159
+ - Affirmer disclaims responsibility for clearing rights of other
160
+ persons that may apply to the Work or any use thereof, including
161
+ without limitation any person's Copyright and Related Rights in the
162
+ Work. Further, Affirmer disclaims responsibility for obtaining any
163
+ necessary consents, permissions or other rights required for any
164
+ use of the Work.
165
+ - Affirmer understands and acknowledges that Creative Commons is not
166
+ a party to this document and has no duty or obligation with respect
167
+ to this CC0 or use of the Work.
168
+
169
+ Special notes
170
+ -------------
171
+
172
+ The files in `tests/externals/` were placed in the public domain by
173
+ their respective authors. See the `AUTHORS.md` files in each directory.
@@ -0,0 +1,27 @@
1
+ # CMonocypher
2
+
3
+ Monocypher **4.0.2** (BSD-2-Clause or CC0, see LICENCE.md; audited by Cure53 in 2017), vendored for
4
+ deterministic Ed25519 (RFC 8032) Solana signatures. CryptoKit's `Curve25519.Signing` is not used for
5
+ signing because its signatures are randomized, so they would not equal the web frame's byte for byte;
6
+ CryptoKit still derives and verifies the public keys.
7
+
8
+ - Source tarball: https://github.com/LoupVaillant/Monocypher/archive/refs/tags/4.0.2.tar.gz
9
+ - Tarball SHA-256: `bc1ca30b1b2654e4e7daf2492c0d204200e55137f23fda6b7142fd7d523bd6b4`
10
+ - Copied unchanged:
11
+
12
+ | File | From | SHA-256 |
13
+ |---|---|---|
14
+ | monocypher.c | src/monocypher.c | 02174117935699d418443c75a558a287deb06ef8cf7c1adced61d9047d2f323d |
15
+ | monocypher-ed25519.c | src/optional/monocypher-ed25519.c | 97d581639dfa72be08a6d57deb7d79b736be001cb416819cab196d22559d242b |
16
+ | include/monocypher.h | src/monocypher.h | fcaf6ed771358bb4f40fba016f6518ae86ec02b1b877d2cc35ad92d3a26fd7b3 |
17
+ | include/monocypher-ed25519.h | src/optional/monocypher-ed25519.h | 3a3035181f991a158d0e1c7567258f0bae8ba0f1f23c5512b4a1db1b3c9730ce |
18
+ | LICENCE.md | LICENCE.md | a5781770269d2516e52ba4863f790c10a16da4089a1e81823aee19ff1e9026b0 |
19
+
20
+ ## Building outside SwiftPM (CocoaPods)
21
+
22
+ Self-contained; no defines, flags or header search paths.
23
+
24
+ ```ruby
25
+ s.source_files = 'CMonocypher/*.c', 'CMonocypher/include/*.h'
26
+ s.public_header_files = 'CMonocypher/include/*.h'
27
+ ```