@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,84 @@
1
+ // GENERATED by scripts/sync-native-wallet.mjs from swift/Sources/AuthonWallet/WalletError.swift. Do not edit: change the source and run the script.
2
+ import Foundation
3
+
4
+ /// Error codes shared with the web wallet frame (`apps/wallet/src/errors.ts`).
5
+ public enum WalletErrorCode: String, Sendable, CaseIterable {
6
+ case notFound = "NOT_FOUND"
7
+ case needsRestore = "NEEDS_RESTORE"
8
+ case notProtected = "NOT_PROTECTED"
9
+ /// The OS or authenticator cannot evaluate the passkey PRF extension, so the wallet cannot be protected or restored here.
10
+ case prfUnsupported = "PRF_UNSUPPORTED"
11
+ case originNotAllowed = "ORIGIN_NOT_ALLOWED"
12
+ case userCancelled = "USER_CANCELLED"
13
+ case needsPopup = "NEEDS_POPUP"
14
+ case invalidRequest = "INVALID_REQUEST"
15
+ case unsupportedType = "UNSUPPORTED_TYPE"
16
+ case unauthorized = "UNAUTHORIZED"
17
+ case forbidden = "FORBIDDEN"
18
+ case alreadyExists = "ALREADY_EXISTS"
19
+ case rateLimited = "RATE_LIMITED"
20
+ case addressMismatch = "ADDRESS_MISMATCH"
21
+ case storageUnavailable = "STORAGE_UNAVAILABLE"
22
+ case apiError = "API_ERROR"
23
+ case `internal` = "INTERNAL"
24
+ case lastDevice = "LAST_DEVICE"
25
+ case sessionRequired = "SESSION_REQUIRED"
26
+ case walletPending = "WALLET_PENDING"
27
+ case confirmWindowBlocked = "CONFIRM_WINDOW_BLOCKED"
28
+ case confirmWindowClosed = "CONFIRM_WINDOW_CLOSED"
29
+ case messageTooLarge = "MESSAGE_TOO_LARGE"
30
+ /// The API no longer serves this SDK's protocol version; update the SDK.
31
+ case frameOutdated = "FRAME_OUTDATED"
32
+ case backupKeyRequired = "BACKUP_KEY_REQUIRED"
33
+ case alreadyUpgraded = "ALREADY_UPGRADED"
34
+ case accountUnavailable = "ACCOUNT_UNAVAILABLE"
35
+ }
36
+
37
+ extension WalletErrorCode {
38
+ /// Whether retrying the same call can succeed (docs/wallet/NATIVE.md section 10).
39
+ public var retryable: Bool {
40
+ switch self {
41
+ case .apiError, .rateLimited, .walletPending: return true
42
+ default: return false
43
+ }
44
+ }
45
+ }
46
+
47
+ public struct WalletError: Error, Equatable, CustomStringConvertible, LocalizedError {
48
+ public let code: WalletErrorCode
49
+ public let message: String
50
+ /// The server's request ID (`requestId` in the error body, else the `X-Request-Id` header)
51
+ /// when the error came from an API response; nil otherwise. Safe to log and to show support.
52
+ public let diagnosticId: String?
53
+ /// No response from the API (reported as API_ERROR, like the web frame).
54
+ let isNetworkFailure: Bool
55
+
56
+ public init(_ code: WalletErrorCode, _ message: String? = nil, diagnosticId: String? = nil) {
57
+ self.code = code
58
+ self.message = message ?? code.rawValue
59
+ self.diagnosticId = diagnosticId
60
+ isNetworkFailure = false
61
+ }
62
+
63
+ private init(networkFailure message: String) {
64
+ code = .apiError
65
+ self.message = message
66
+ diagnosticId = nil
67
+ isNetworkFailure = true
68
+ }
69
+
70
+ static func network() -> WalletError { WalletError(networkFailure: "network error") }
71
+
72
+ public var retryable: Bool { code.retryable }
73
+
74
+ public var description: String {
75
+ "WalletError(\(code.rawValue)): \(message)" + (diagnosticId.map { " [\($0)]" } ?? "")
76
+ }
77
+ public var errorDescription: String? { message }
78
+
79
+ public static func == (a: WalletError, b: WalletError) -> Bool { a.code == b.code }
80
+
81
+ static func wrap(_ error: Error) -> WalletError {
82
+ error as? WalletError ?? WalletError(.internal, "unexpected error")
83
+ }
84
+ }
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Tomas Dzetkulic
4
+ Copyright (c) 2013 Pavol Rusnak
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # CKeccak
2
+
3
+ Keccak-256 (original Keccak padding, as used by Ethereum) and RIPEMD-160 (Bitcoin/XRP hash160)
4
+ for AuthonWallet.
5
+
6
+ Vendored unchanged from trezor-crypto, MIT (see LICENSE):
7
+
8
+ | File | Source | SHA-256 |
9
+ |---|---|---|
10
+ | sha3.c | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/sha3.c | f877c5f62bb2a63653bc363e0995f0bdfe70206c52f5a508d50d04aa373ce767 |
11
+ | sha3.h | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/sha3.h | 3b48be872bfeecf352140c4956482e88e60d76776d06cd22d828d3d89e4e8a5b |
12
+ | memzero.c | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/memzero.c | 2f014e8d03420b42fb7b9df39f9150a33ac96d1c48a065f5a908a967561bca02 |
13
+ | memzero.h | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/memzero.h | ffec031a236dde8df1c0b95cd0c3bd28ca046f6dc62faff36be8401ba82b214a |
14
+ | byte_order.h | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/byte_order.h | 496a5a80346a0fb48ef3fbf53c0da2b69399e1de224d67962342657a9dfd77d1 |
15
+ | options.h | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/options.h | 02884451075e84c7d9099a2fd295f1fcd87f7df0f3c7812ecba98b398ebe7a4e |
16
+ | ripemd160.c | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/ripemd160.c | cdb95bc4dc735063ea8d45d57d76ea0b81838693a7199b0772f0adb47b47b934 |
17
+ | ripemd160.h | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/ripemd160.h | e06d618b788918e52f37ceb0249f2752364e7932437d0b6972946213dba011fc |
18
+ | LICENSE | https://github.com/trezor/trezor-firmware/blob/core/v2.8.0/crypto/LICENSE | b53d2eb93806f3d618370726f27eafeb6c279c7a90351297f79e073e49e569be |
19
+
20
+ `include/ckeccak.h` is ours: it only declares `keccak_256` and `ripemd160` for Swift.
21
+
22
+ ## Building outside SwiftPM (CocoaPods)
23
+
24
+ Self-contained; no defines or flags (`options.h` already sets `USE_KECCAK 1`) and no header search paths.
25
+ Compile `sha3.c`, `ripemd160.c` and `memzero.c`; the public header is `include/ckeccak.h`.
26
+
27
+ ```ruby
28
+ s.source_files = 'CKeccak/*.{c,h}', 'CKeccak/include/ckeccak.h'
29
+ s.public_header_files = 'CKeccak/include/ckeccak.h'
30
+ ```
@@ -0,0 +1,59 @@
1
+ #ifndef __BYTE_ORDER_H__
2
+ #define __BYTE_ORDER_H__
3
+
4
+ // FROM sha2.h:
5
+ /*
6
+ * BYTE_ORDER NOTE:
7
+ *
8
+ * Please make sure that your system defines BYTE_ORDER. If your
9
+ * architecture is little-endian, make sure it also defines
10
+ * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
11
+ * equivalent.
12
+ *
13
+ * If your system does not define the above, then you can do so by
14
+ * hand like this:
15
+ *
16
+ * #define LITTLE_ENDIAN 1234
17
+ * #define BIG_ENDIAN 4321
18
+ *
19
+ * And for little-endian machines, add:
20
+ *
21
+ * #define BYTE_ORDER LITTLE_ENDIAN
22
+ *
23
+ * Or for big-endian machines:
24
+ *
25
+ * #define BYTE_ORDER BIG_ENDIAN
26
+ *
27
+ * The FreeBSD machine this was written on defines BYTE_ORDER
28
+ * appropriately by including <sys/types.h> (which in turn includes
29
+ * <machine/endian.h> where the appropriate definitions are actually
30
+ * made).
31
+ */
32
+
33
+ #ifndef LITTLE_ENDIAN
34
+ #define LITTLE_ENDIAN 1234
35
+ #define BIG_ENDIAN 4321
36
+ #endif
37
+
38
+ #ifndef BYTE_ORDER
39
+ #define BYTE_ORDER LITTLE_ENDIAN
40
+ #endif
41
+
42
+ #define REVERSE32(w, x) \
43
+ { \
44
+ uint32_t tmp = (w); \
45
+ tmp = (tmp >> 16) | (tmp << 16); \
46
+ (x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
47
+ }
48
+
49
+ #define REVERSE64(w, x) \
50
+ { \
51
+ uint64_t tmp = (w); \
52
+ tmp = (tmp >> 32) | (tmp << 32); \
53
+ tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
54
+ ((tmp & 0x00ff00ff00ff00ffULL) << 8); \
55
+ (x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
56
+ ((tmp & 0x0000ffff0000ffffULL) << 16); \
57
+ }
58
+
59
+ #endif
@@ -0,0 +1,13 @@
1
+ #ifndef CKECCAK_H
2
+ #define CKECCAK_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ /* Original Keccak-256 (Ethereum), implemented in ../sha3.c. */
8
+ void keccak_256(const unsigned char *data, size_t len, unsigned char *digest);
9
+
10
+ /* RIPEMD-160, implemented in ../ripemd160.c. */
11
+ void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[20]);
12
+
13
+ #endif
@@ -0,0 +1,75 @@
1
+ #ifndef __STDC_WANT_LIB_EXT1__
2
+ #define __STDC_WANT_LIB_EXT1__ 1 // C11's bounds-checking interface.
3
+ #endif
4
+ #include <string.h>
5
+
6
+ #ifdef _WIN32
7
+ #include <windows.h>
8
+ #endif
9
+
10
+ #ifdef __unix__
11
+ #include <strings.h>
12
+ #include <sys/param.h>
13
+ #endif
14
+
15
+ // C11's bounds-checking interface.
16
+ #if defined(__STDC_LIB_EXT1__)
17
+ #define HAVE_MEMSET_S 1
18
+ #endif
19
+
20
+ // GNU C Library version 2.25 or later.
21
+ #if defined(__GLIBC__) && \
22
+ (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
23
+ #define HAVE_EXPLICIT_BZERO 1
24
+ #endif
25
+
26
+ // Newlib
27
+ #if defined(__NEWLIB__)
28
+ #define HAVE_EXPLICIT_BZERO 1
29
+ #endif
30
+
31
+ // FreeBSD version 11.0 or later.
32
+ #if defined(__FreeBSD__) && __FreeBSD_version >= 1100037
33
+ #define HAVE_EXPLICIT_BZERO 1
34
+ #endif
35
+
36
+ // OpenBSD version 5.5 or later.
37
+ #if defined(__OpenBSD__) && OpenBSD >= 201405
38
+ #define HAVE_EXPLICIT_BZERO 1
39
+ #endif
40
+
41
+ // NetBSD version 7.2 or later.
42
+ #if defined(__NetBSD__) && __NetBSD_Version__ >= 702000000
43
+ #define HAVE_EXPLICIT_MEMSET 1
44
+ #endif
45
+
46
+ // Adapted from
47
+ // https://github.com/jedisct1/libsodium/blob/1647f0d53ae0e370378a9195477e3df0a792408f/src/libsodium/sodium/utils.c#L102-L130
48
+
49
+ void memzero(void *const pnt, const size_t len) {
50
+ #ifdef _WIN32
51
+ SecureZeroMemory(pnt, len);
52
+ #elif defined(HAVE_MEMSET_S)
53
+ memset_s(pnt, (rsize_t)len, 0, (rsize_t)len);
54
+ #elif defined(HAVE_EXPLICIT_BZERO)
55
+ explicit_bzero(pnt, len);
56
+ #elif defined(HAVE_EXPLICIT_MEMSET)
57
+ explicit_memset(pnt, 0, len);
58
+ #else
59
+ volatile unsigned char *volatile pnt_ = (volatile unsigned char *volatile)pnt;
60
+ size_t i = (size_t)0U;
61
+
62
+ while (i < len) {
63
+ pnt_[i++] = 0U;
64
+ }
65
+ #endif
66
+
67
+ // explicitly mark the memory as overwritten for the Clang MemorySanitizer
68
+ // this is only included at compile time if MemorySanitizer is enabled and
69
+ // should not come with any downsides during regular builds
70
+ #if defined(__has_feature)
71
+ #if __has_feature(memory_sanitizer)
72
+ memset(pnt, 0, len);
73
+ #endif
74
+ #endif
75
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef __MEMZERO_H__
2
+ #define __MEMZERO_H__
3
+
4
+ #include <stddef.h>
5
+
6
+ void memzero(void* const pnt, const size_t len);
7
+
8
+ #endif
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Copyright (c) 2013-2014 Pavol Rusnak
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the "Software"),
6
+ * to deal in the Software without restriction, including without limitation
7
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the
9
+ * Software is furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included
12
+ * in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
18
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ * OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+
23
+ #ifndef __OPTIONS_H__
24
+ #define __OPTIONS_H__
25
+
26
+ // use precomputed Curve Points (some scalar multiples of curve base point G)
27
+ #ifndef USE_PRECOMPUTED_CP
28
+ #define USE_PRECOMPUTED_CP 1
29
+ #endif
30
+
31
+ // use fast inverse method
32
+ #ifndef USE_INVERSE_FAST
33
+ #define USE_INVERSE_FAST 1
34
+ #endif
35
+
36
+ // support for printing bignum256 structures via printf
37
+ #ifndef USE_BN_PRINT
38
+ #define USE_BN_PRINT 0
39
+ #endif
40
+
41
+ // use deterministic signatures
42
+ #ifndef USE_RFC6979
43
+ #define USE_RFC6979 1
44
+ #endif
45
+
46
+ // implement BIP32 caching
47
+ #ifndef USE_BIP32_CACHE
48
+ #define USE_BIP32_CACHE 1
49
+ #define BIP32_CACHE_SIZE 10
50
+ #define BIP32_CACHE_MAXDEPTH 8
51
+ #endif
52
+
53
+ // support constructing BIP32 nodes from ed25519 and curve25519 curves.
54
+ #ifndef USE_BIP32_25519_CURVES
55
+ #define USE_BIP32_25519_CURVES 1
56
+ #endif
57
+
58
+ // implement BIP39 caching
59
+ #ifndef USE_BIP39_CACHE
60
+ #define USE_BIP39_CACHE 1
61
+ #define BIP39_CACHE_SIZE 4
62
+ #endif
63
+
64
+ // support Ethereum operations
65
+ #ifndef USE_ETHEREUM
66
+ #define USE_ETHEREUM 0
67
+ #endif
68
+
69
+ // support NEM operations
70
+ #ifndef USE_NEM
71
+ #define USE_NEM 0
72
+ #endif
73
+
74
+ // support MONERO operations
75
+ #ifndef USE_MONERO
76
+ #define USE_MONERO 0
77
+ #endif
78
+
79
+ // support CARDANO operations
80
+ #ifndef USE_CARDANO
81
+ #define USE_CARDANO 0
82
+ #endif
83
+
84
+ // support Keccak hashing
85
+ #ifndef USE_KECCAK
86
+ #define USE_KECCAK 1
87
+ #endif
88
+
89
+ // add way how to mark confidential data
90
+ #ifndef CONFIDENTIAL
91
+ #define CONFIDENTIAL
92
+ #endif
93
+
94
+ // add way to mark functions whose return value should always be checked
95
+ #ifndef __wur
96
+ #define __wur __attribute__((warn_unused_result))
97
+ #endif
98
+
99
+ #endif