@onekeyfe/react-native-lite-card 6.7.0-6 → 6.7.0-60
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.
- package/README.md +134 -43
- package/ReactNativeLiteCard.podspec +31 -2
- package/android/build.gradle +8 -0
- package/android/consumer-rules.pro +4 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +60 -49
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +117 -39
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +24 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +46 -19
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +38 -1
- package/ios/Classes/OKNFCBridge.mm +24 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +20 -10
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/ios/Classes/OKNFTLite/OKNFCManager.h +2 -2
- package/ios/Classes/OKNFTLite/OKNFCManager.m +110 -18
- package/ios/ReactNativeLiteCard.mm +23 -11
- package/lib/module/index.js +4 -4
- package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +4 -4
- package/lib/typescript/src/index.d.ts +2 -2
- package/package.json +9 -8
- package/sdk/CMakeLists.txt +121 -0
- package/sdk/README.md +190 -0
- package/sdk/android/implJni.cpp +216 -0
- package/sdk/deps/jsoncpp/LICENSE +55 -0
- package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
- package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
- package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
- package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
- package/sdk/deps/jsoncpp/include/json/config.h +187 -0
- package/sdk/deps/jsoncpp/include/json/features.h +61 -0
- package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
- package/sdk/deps/jsoncpp/include/json/json.h +15 -0
- package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
- package/sdk/deps/jsoncpp/include/json/value.h +888 -0
- package/sdk/deps/jsoncpp/include/json/version.h +20 -0
- package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
- package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
- package/sdk/deps/trezor-crypto/AUTHORS +2 -0
- package/sdk/deps/trezor-crypto/LICENSE +22 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
- package/sdk/deps/trezor-crypto/src/address.c +87 -0
- package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
- package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
- package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
- package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
- package/sdk/deps/trezor-crypto/src/base32.c +233 -0
- package/sdk/deps/trezor-crypto/src/base58.c +298 -0
- package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
- package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
- package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
- package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
- package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
- package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
- package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
- package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
- package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
- package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
- package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
- package/sdk/deps/trezor-crypto/src/curves.c +48 -0
- package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
- package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
- package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
- package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
- package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
- package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
- package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
- package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
- package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
- package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
- package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
- package/sdk/deps/trezor-crypto/src/nano.c +151 -0
- package/sdk/deps/trezor-crypto/src/nem.c +569 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/options.h +43 -0
- package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
- package/sdk/deps/trezor-crypto/src/rand.c +51 -0
- package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
- package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
- package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
- package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
- package/sdk/deps/trezor-crypto/src/script.c +64 -0
- package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/setup.py +38 -0
- package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
- package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
- package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
- package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
- package/sdk/gpc/include/scp03/scp03.hpp +80 -0
- package/sdk/gpc/include/scp11/scp11.hpp +492 -0
- package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
- package/sdk/gpc/include/tag.h +68 -0
- package/sdk/gpc/include/tlv.hpp +94 -0
- package/sdk/gpc/include/tlvparse.hpp +24 -0
- package/sdk/gpc/src/scp03.cpp +243 -0
- package/sdk/gpc/src/scp11.cpp +798 -0
- package/sdk/gpc/src/scp11c.cpp +136 -0
- package/sdk/gpc/src/tlv.cpp +159 -0
- package/sdk/gpc/src/tlvparse.c +174 -0
- package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
- package/sdk/include/GPChannelSDKCore.h +10 -0
- package/sdk/include/context/BaseContext.h +56 -0
- package/sdk/include/device/ApduBuilder.hpp +72 -0
- package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
- package/sdk/include/utility/Apdu.hpp +172 -0
- package/sdk/include/utility/Debug.hpp +3 -0
- package/sdk/include/utility/util.h +104 -0
- package/sdk/scripts/generate-source-id.rb +22 -0
- package/sdk/source-id-manifest.txt +19 -0
- package/sdk/source-id.cmake +31 -0
- package/sdk/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +258 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +3 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +124 -0
- package/sdk/tests/safety.cpp +757 -0
- package/sdk/tests/verify.py +284 -0
- package/src/NativeReactNativeLiteCard.ts +4 -2
- package/src/index.tsx +14 -3
- package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
- package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 Saleem Rashid
|
|
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, E1PRESS
|
|
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
|
+
#include <TrezorCrypto/nem.h>
|
|
24
|
+
|
|
25
|
+
#include <TrezorCrypto/base32.h>
|
|
26
|
+
#include <TrezorCrypto/ed25519-donna/ed25519-keccak.h>
|
|
27
|
+
#include <TrezorCrypto/memzero.h>
|
|
28
|
+
#include <TrezorCrypto/ripemd160.h>
|
|
29
|
+
#include <TrezorCrypto/sha3.h>
|
|
30
|
+
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
#define CAN_WRITE(NEEDED) ((ctx->offset + (NEEDED)) <= ctx->size)
|
|
34
|
+
|
|
35
|
+
#define SERIALIZE_U32(DATA) \
|
|
36
|
+
do { if (!nem_write_u32(ctx, (DATA))) return false; } while (0)
|
|
37
|
+
#define SERIALIZE_U64(DATA) \
|
|
38
|
+
do { if (!nem_write_u64(ctx, (DATA))) return false; } while (0)
|
|
39
|
+
#define SERIALIZE_TAGGED(DATA, LENGTH) \
|
|
40
|
+
do { if (!nem_write_tagged(ctx, (DATA), (LENGTH))) return false; } while (0)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const char *nem_network_name(uint8_t network) {
|
|
44
|
+
switch (network) {
|
|
45
|
+
case NEM_NETWORK_MAINNET:
|
|
46
|
+
return "NEM Mainnet";
|
|
47
|
+
case NEM_NETWORK_TESTNET:
|
|
48
|
+
return "NEM Testnet";
|
|
49
|
+
case NEM_NETWORK_MIJIN:
|
|
50
|
+
return "Mijin";
|
|
51
|
+
default:
|
|
52
|
+
return NULL;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static inline bool nem_write_checked(nem_transaction_ctx *ctx, const uint8_t *data, uint32_t length) {
|
|
57
|
+
if (!CAN_WRITE(length)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
memcpy(&ctx->buffer[ctx->offset], data, length);
|
|
62
|
+
ctx->offset += length;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static inline bool nem_write_u32(nem_transaction_ctx *ctx, uint32_t data) {
|
|
67
|
+
if (!CAN_WRITE(4)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ctx->buffer[ctx->offset++] = (data >> 0) & 0xff;
|
|
72
|
+
ctx->buffer[ctx->offset++] = (data >> 8) & 0xff;
|
|
73
|
+
ctx->buffer[ctx->offset++] = (data >> 16) & 0xff;
|
|
74
|
+
ctx->buffer[ctx->offset++] = (data >> 24) & 0xff;
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static inline bool nem_write_u64(nem_transaction_ctx *ctx, uint64_t data) {
|
|
80
|
+
SERIALIZE_U32((data >> 0) & 0xffffffff);
|
|
81
|
+
SERIALIZE_U32((data >> 32) & 0xffffffff);
|
|
82
|
+
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static inline bool nem_write_tagged(nem_transaction_ctx *ctx, const uint8_t *data, uint32_t length) {
|
|
87
|
+
SERIALIZE_U32(length);
|
|
88
|
+
|
|
89
|
+
return nem_write_checked(ctx, data, length);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static inline bool nem_write_mosaic_str(nem_transaction_ctx *ctx, const char *name, const char *value) {
|
|
93
|
+
uint32_t name_length = strlen(name);
|
|
94
|
+
uint32_t value_length = strlen(value);
|
|
95
|
+
|
|
96
|
+
SERIALIZE_U32(sizeof(uint32_t) + name_length + sizeof(uint32_t) + value_length);
|
|
97
|
+
SERIALIZE_TAGGED((const uint8_t *) name, name_length);
|
|
98
|
+
SERIALIZE_TAGGED((const uint8_t *) value, value_length);
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static inline bool nem_write_mosaic_bool(nem_transaction_ctx *ctx, const char *name, bool value) {
|
|
104
|
+
return nem_write_mosaic_str(ctx, name, value ? "true" : "false");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static inline bool nem_write_mosaic_u64(nem_transaction_ctx *ctx, const char *name, uint64_t value) {
|
|
108
|
+
char buffer[21];
|
|
109
|
+
|
|
110
|
+
if (bn_format_uint64(value, NULL, NULL, 0, 0, false, buffer, sizeof(buffer)) == 0) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return nem_write_mosaic_str(ctx, name, buffer);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void nem_get_address_raw(const ed25519_public_key public_key, uint8_t version, uint8_t *address) {
|
|
118
|
+
uint8_t hash[SHA3_256_DIGEST_LENGTH];
|
|
119
|
+
|
|
120
|
+
/* 1. Perform 256-bit Sha3 on the public key */
|
|
121
|
+
keccak_256(public_key, sizeof(ed25519_public_key), hash);
|
|
122
|
+
|
|
123
|
+
/* 2. Perform 160-bit Ripemd of hash resulting from step 1. */
|
|
124
|
+
ripemd160(hash, SHA3_256_DIGEST_LENGTH, &address[1]);
|
|
125
|
+
|
|
126
|
+
/* 3. Prepend version byte to Ripemd hash (either 0x68 or 0x98) */
|
|
127
|
+
address[0] = version;
|
|
128
|
+
|
|
129
|
+
/* 4. Perform 256-bit Sha3 on the result, take the first four bytes as a checksum */
|
|
130
|
+
keccak_256(address, 1 + RIPEMD160_DIGEST_LENGTH, hash);
|
|
131
|
+
|
|
132
|
+
/* 5. Concatenate output of step 3 and the checksum from step 4 */
|
|
133
|
+
memcpy(&address[1 + RIPEMD160_DIGEST_LENGTH], hash, 4);
|
|
134
|
+
|
|
135
|
+
memzero(hash, sizeof(hash));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
bool nem_get_address(const ed25519_public_key public_key, uint8_t version, char *address) {
|
|
139
|
+
uint8_t pubkeyhash[NEM_ADDRESS_SIZE_RAW];
|
|
140
|
+
|
|
141
|
+
nem_get_address_raw(public_key, version, pubkeyhash);
|
|
142
|
+
|
|
143
|
+
char *ret = base32_encode(pubkeyhash, sizeof(pubkeyhash), address, NEM_ADDRESS_SIZE + 1, BASE32_ALPHABET_RFC4648);
|
|
144
|
+
|
|
145
|
+
memzero(pubkeyhash, sizeof(pubkeyhash));
|
|
146
|
+
return (ret != NULL);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
bool nem_validate_address_raw(const uint8_t *address, uint8_t network) {
|
|
150
|
+
if (!nem_network_name(network) || address[0] != network) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
uint8_t hash[SHA3_256_DIGEST_LENGTH];
|
|
155
|
+
|
|
156
|
+
keccak_256(address, 1 + RIPEMD160_DIGEST_LENGTH, hash);
|
|
157
|
+
bool valid = (memcmp(&address[1 + RIPEMD160_DIGEST_LENGTH], hash, 4) == 0);
|
|
158
|
+
|
|
159
|
+
memzero(hash, sizeof(hash));
|
|
160
|
+
return valid;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
bool nem_validate_address(const char *address, uint8_t network) {
|
|
164
|
+
uint8_t pubkeyhash[NEM_ADDRESS_SIZE_RAW];
|
|
165
|
+
|
|
166
|
+
if (strlen(address) != NEM_ADDRESS_SIZE) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
uint8_t *ret = base32_decode(address, NEM_ADDRESS_SIZE, pubkeyhash, sizeof(pubkeyhash), BASE32_ALPHABET_RFC4648);
|
|
171
|
+
bool valid = (ret != NULL) && nem_validate_address_raw(pubkeyhash, network);
|
|
172
|
+
|
|
173
|
+
memzero(pubkeyhash, sizeof(pubkeyhash));
|
|
174
|
+
return valid;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
void nem_transaction_start(nem_transaction_ctx *ctx, const ed25519_public_key public_key, uint8_t *buffer, size_t size) {
|
|
178
|
+
memcpy(ctx->public_key, public_key, sizeof(ctx->public_key));
|
|
179
|
+
|
|
180
|
+
ctx->buffer = buffer;
|
|
181
|
+
ctx->offset = 0;
|
|
182
|
+
ctx->size = size;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
size_t nem_transaction_end(nem_transaction_ctx *ctx, const ed25519_secret_key private_key, ed25519_signature signature) {
|
|
186
|
+
if (private_key != NULL && signature != NULL) {
|
|
187
|
+
ed25519_sign_keccak(ctx->buffer, ctx->offset, private_key, ctx->public_key, signature);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return ctx->offset;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
bool nem_transaction_write_common(nem_transaction_ctx *ctx,
|
|
194
|
+
uint32_t type,
|
|
195
|
+
uint32_t version,
|
|
196
|
+
uint32_t timestamp,
|
|
197
|
+
const ed25519_public_key signer,
|
|
198
|
+
uint64_t fee,
|
|
199
|
+
uint32_t deadline) {
|
|
200
|
+
|
|
201
|
+
SERIALIZE_U32(type);
|
|
202
|
+
SERIALIZE_U32(version);
|
|
203
|
+
SERIALIZE_U32(timestamp);
|
|
204
|
+
SERIALIZE_TAGGED(signer, sizeof(ed25519_public_key));
|
|
205
|
+
SERIALIZE_U64(fee);
|
|
206
|
+
SERIALIZE_U32(deadline);
|
|
207
|
+
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
bool nem_transaction_create_transfer(nem_transaction_ctx *ctx,
|
|
212
|
+
uint8_t network,
|
|
213
|
+
uint32_t timestamp,
|
|
214
|
+
const ed25519_public_key signer,
|
|
215
|
+
uint64_t fee,
|
|
216
|
+
uint32_t deadline,
|
|
217
|
+
const char *recipient,
|
|
218
|
+
uint64_t amount,
|
|
219
|
+
const uint8_t *payload,
|
|
220
|
+
uint32_t length,
|
|
221
|
+
bool encrypted,
|
|
222
|
+
uint32_t mosaics) {
|
|
223
|
+
|
|
224
|
+
if (!signer) {
|
|
225
|
+
signer = ctx->public_key;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!payload) {
|
|
229
|
+
length = 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
233
|
+
NEM_TRANSACTION_TYPE_TRANSFER,
|
|
234
|
+
(uint32_t) network << 24 | (mosaics ? 2 : 1),
|
|
235
|
+
timestamp,
|
|
236
|
+
signer,
|
|
237
|
+
fee,
|
|
238
|
+
deadline);
|
|
239
|
+
if (!ret) return false;
|
|
240
|
+
|
|
241
|
+
SERIALIZE_TAGGED((const uint8_t *) recipient, NEM_ADDRESS_SIZE);
|
|
242
|
+
SERIALIZE_U64(amount);
|
|
243
|
+
|
|
244
|
+
if (length) {
|
|
245
|
+
SERIALIZE_U32(sizeof(uint32_t) + sizeof(uint32_t) + length);
|
|
246
|
+
SERIALIZE_U32(encrypted ? 0x02 : 0x01);
|
|
247
|
+
SERIALIZE_TAGGED(payload, length);
|
|
248
|
+
} else {
|
|
249
|
+
SERIALIZE_U32(0);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (mosaics) {
|
|
253
|
+
|
|
254
|
+
SERIALIZE_U32(mosaics);
|
|
255
|
+
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
bool nem_transaction_write_mosaic(nem_transaction_ctx *ctx,
|
|
262
|
+
const char *namespace,
|
|
263
|
+
const char *mosaic,
|
|
264
|
+
uint64_t quantity) {
|
|
265
|
+
|
|
266
|
+
size_t namespace_length = strlen(namespace);
|
|
267
|
+
size_t mosaic_length = strlen(mosaic);
|
|
268
|
+
size_t identifier_length = sizeof(uint32_t) + namespace_length + sizeof(uint32_t) + mosaic_length;
|
|
269
|
+
|
|
270
|
+
SERIALIZE_U32(sizeof(uint32_t) + sizeof(uint64_t) + identifier_length);
|
|
271
|
+
SERIALIZE_U32(identifier_length);
|
|
272
|
+
SERIALIZE_TAGGED((const uint8_t *) namespace, namespace_length);
|
|
273
|
+
SERIALIZE_TAGGED((const uint8_t *) mosaic, mosaic_length);
|
|
274
|
+
SERIALIZE_U64(quantity);
|
|
275
|
+
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
bool nem_transaction_create_multisig(nem_transaction_ctx *ctx,
|
|
280
|
+
uint8_t network,
|
|
281
|
+
uint32_t timestamp,
|
|
282
|
+
const ed25519_public_key signer,
|
|
283
|
+
uint64_t fee,
|
|
284
|
+
uint32_t deadline,
|
|
285
|
+
const nem_transaction_ctx *inner) {
|
|
286
|
+
|
|
287
|
+
if (!signer) {
|
|
288
|
+
signer = ctx->public_key;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
292
|
+
NEM_TRANSACTION_TYPE_MULTISIG,
|
|
293
|
+
(uint32_t) network << 24 | 1,
|
|
294
|
+
timestamp,
|
|
295
|
+
signer,
|
|
296
|
+
fee,
|
|
297
|
+
deadline);
|
|
298
|
+
if (!ret) return false;
|
|
299
|
+
|
|
300
|
+
SERIALIZE_TAGGED(inner->buffer, inner->offset);
|
|
301
|
+
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
bool nem_transaction_create_multisig_signature(nem_transaction_ctx *ctx,
|
|
306
|
+
uint8_t network,
|
|
307
|
+
uint32_t timestamp,
|
|
308
|
+
const ed25519_public_key signer,
|
|
309
|
+
uint64_t fee,
|
|
310
|
+
uint32_t deadline,
|
|
311
|
+
const nem_transaction_ctx *inner) {
|
|
312
|
+
|
|
313
|
+
if (!signer) {
|
|
314
|
+
signer = ctx->public_key;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
318
|
+
NEM_TRANSACTION_TYPE_MULTISIG_SIGNATURE,
|
|
319
|
+
(uint32_t) network << 24 | 1,
|
|
320
|
+
timestamp,
|
|
321
|
+
signer,
|
|
322
|
+
fee,
|
|
323
|
+
deadline);
|
|
324
|
+
if (!ret) return false;
|
|
325
|
+
|
|
326
|
+
char address[NEM_ADDRESS_SIZE + 1];
|
|
327
|
+
nem_get_address(inner->public_key, network, address);
|
|
328
|
+
|
|
329
|
+
uint8_t hash[SHA3_256_DIGEST_LENGTH];
|
|
330
|
+
keccak_256(inner->buffer, inner->offset, hash);
|
|
331
|
+
|
|
332
|
+
SERIALIZE_U32(sizeof(uint32_t) + SHA3_256_DIGEST_LENGTH);
|
|
333
|
+
SERIALIZE_TAGGED(hash, SHA3_256_DIGEST_LENGTH);
|
|
334
|
+
SERIALIZE_TAGGED((const uint8_t *) address, NEM_ADDRESS_SIZE);
|
|
335
|
+
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
bool nem_transaction_create_provision_namespace(nem_transaction_ctx *ctx,
|
|
340
|
+
uint8_t network,
|
|
341
|
+
uint32_t timestamp,
|
|
342
|
+
const ed25519_public_key signer,
|
|
343
|
+
uint64_t fee,
|
|
344
|
+
uint32_t deadline,
|
|
345
|
+
const char *namespace,
|
|
346
|
+
const char *parent,
|
|
347
|
+
const char *rental_sink,
|
|
348
|
+
uint64_t rental_fee) {
|
|
349
|
+
|
|
350
|
+
if (!signer) {
|
|
351
|
+
signer = ctx->public_key;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
355
|
+
NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE,
|
|
356
|
+
(uint32_t) network << 24 | 1,
|
|
357
|
+
timestamp,
|
|
358
|
+
signer,
|
|
359
|
+
fee,
|
|
360
|
+
deadline);
|
|
361
|
+
if (!ret) return false;
|
|
362
|
+
|
|
363
|
+
if (parent) {
|
|
364
|
+
SERIALIZE_TAGGED((const uint8_t *) rental_sink, NEM_ADDRESS_SIZE);
|
|
365
|
+
SERIALIZE_U64(rental_fee);
|
|
366
|
+
SERIALIZE_TAGGED((const uint8_t *) namespace, strlen(namespace));
|
|
367
|
+
SERIALIZE_TAGGED((const uint8_t *) parent, strlen(parent));
|
|
368
|
+
} else {
|
|
369
|
+
SERIALIZE_TAGGED((const uint8_t *) rental_sink, NEM_ADDRESS_SIZE);
|
|
370
|
+
SERIALIZE_U64(rental_fee);
|
|
371
|
+
SERIALIZE_TAGGED((const uint8_t *) namespace, strlen(namespace));
|
|
372
|
+
SERIALIZE_U32(0xffffffff);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
bool nem_transaction_create_mosaic_creation(nem_transaction_ctx *ctx,
|
|
379
|
+
uint8_t network,
|
|
380
|
+
uint32_t timestamp,
|
|
381
|
+
const ed25519_public_key signer,
|
|
382
|
+
uint64_t fee,
|
|
383
|
+
uint32_t deadline,
|
|
384
|
+
const char *namespace,
|
|
385
|
+
const char *mosaic,
|
|
386
|
+
const char *description,
|
|
387
|
+
uint32_t divisibility,
|
|
388
|
+
uint64_t supply,
|
|
389
|
+
bool mutable_supply,
|
|
390
|
+
bool transferable,
|
|
391
|
+
uint32_t levy_type,
|
|
392
|
+
uint64_t levy_fee,
|
|
393
|
+
const char *levy_address,
|
|
394
|
+
const char *levy_namespace,
|
|
395
|
+
const char *levy_mosaic,
|
|
396
|
+
const char *creation_sink,
|
|
397
|
+
uint64_t creation_fee) {
|
|
398
|
+
|
|
399
|
+
if (!signer) {
|
|
400
|
+
signer = ctx->public_key;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
404
|
+
NEM_TRANSACTION_TYPE_MOSAIC_CREATION,
|
|
405
|
+
(uint32_t) network << 24 | 1,
|
|
406
|
+
timestamp,
|
|
407
|
+
signer,
|
|
408
|
+
fee,
|
|
409
|
+
deadline);
|
|
410
|
+
if (!ret) return false;
|
|
411
|
+
|
|
412
|
+
size_t namespace_length = strlen(namespace);
|
|
413
|
+
size_t mosaic_length = strlen(mosaic);
|
|
414
|
+
size_t identifier_length = sizeof(uint32_t) + namespace_length + sizeof(uint32_t) + mosaic_length;
|
|
415
|
+
|
|
416
|
+
// This length will be rewritten later on
|
|
417
|
+
nem_transaction_ctx state;
|
|
418
|
+
memcpy(&state, ctx, sizeof(state));
|
|
419
|
+
|
|
420
|
+
SERIALIZE_U32(0);
|
|
421
|
+
SERIALIZE_TAGGED(signer, sizeof(ed25519_public_key));
|
|
422
|
+
SERIALIZE_U32(identifier_length);
|
|
423
|
+
SERIALIZE_TAGGED((const uint8_t *) namespace, namespace_length);
|
|
424
|
+
SERIALIZE_TAGGED((const uint8_t *) mosaic, mosaic_length);
|
|
425
|
+
SERIALIZE_TAGGED((const uint8_t *) description, strlen(description));
|
|
426
|
+
SERIALIZE_U32(4); // Number of properties
|
|
427
|
+
|
|
428
|
+
if (!nem_write_mosaic_u64(ctx, "divisibility", divisibility)) return false;
|
|
429
|
+
if (!nem_write_mosaic_u64(ctx, "initialSupply", supply)) return false;
|
|
430
|
+
if (!nem_write_mosaic_bool(ctx, "supplyMutable", mutable_supply)) return false;
|
|
431
|
+
if (!nem_write_mosaic_bool(ctx, "transferable", transferable)) return false;
|
|
432
|
+
|
|
433
|
+
if (levy_type) {
|
|
434
|
+
size_t levy_namespace_length = strlen(levy_namespace);
|
|
435
|
+
size_t levy_mosaic_length = strlen(levy_mosaic);
|
|
436
|
+
size_t levy_identifier_length = sizeof(uint32_t) + levy_namespace_length + sizeof(uint32_t) + levy_mosaic_length;
|
|
437
|
+
|
|
438
|
+
SERIALIZE_U32(sizeof(uint32_t) + sizeof(uint32_t) + NEM_ADDRESS_SIZE + sizeof(uint32_t) + levy_identifier_length + sizeof(uint64_t));
|
|
439
|
+
SERIALIZE_U32(levy_type);
|
|
440
|
+
SERIALIZE_TAGGED((const uint8_t *) levy_address, NEM_ADDRESS_SIZE);
|
|
441
|
+
SERIALIZE_U32(levy_identifier_length);
|
|
442
|
+
SERIALIZE_TAGGED((const uint8_t *) levy_namespace, levy_namespace_length);
|
|
443
|
+
SERIALIZE_TAGGED((const uint8_t *) levy_mosaic, levy_mosaic_length);
|
|
444
|
+
SERIALIZE_U64(levy_fee);
|
|
445
|
+
} else {
|
|
446
|
+
SERIALIZE_U32(0);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// Rewrite length
|
|
450
|
+
nem_write_u32(&state, ctx->offset - state.offset - sizeof(uint32_t));
|
|
451
|
+
|
|
452
|
+
SERIALIZE_TAGGED((const uint8_t *) creation_sink, NEM_ADDRESS_SIZE);
|
|
453
|
+
SERIALIZE_U64(creation_fee);
|
|
454
|
+
|
|
455
|
+
return true;
|
|
456
|
+
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
bool nem_transaction_create_mosaic_supply_change(nem_transaction_ctx *ctx,
|
|
460
|
+
uint8_t network,
|
|
461
|
+
uint32_t timestamp,
|
|
462
|
+
const ed25519_public_key signer,
|
|
463
|
+
uint64_t fee,
|
|
464
|
+
uint32_t deadline,
|
|
465
|
+
const char *namespace,
|
|
466
|
+
const char *mosaic,
|
|
467
|
+
uint32_t type,
|
|
468
|
+
uint64_t delta) {
|
|
469
|
+
|
|
470
|
+
if (!signer) {
|
|
471
|
+
signer = ctx->public_key;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
475
|
+
NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE,
|
|
476
|
+
(uint32_t) network << 24 | 1,
|
|
477
|
+
timestamp,
|
|
478
|
+
signer,
|
|
479
|
+
fee,
|
|
480
|
+
deadline);
|
|
481
|
+
if (!ret) return false;
|
|
482
|
+
|
|
483
|
+
size_t namespace_length = strlen(namespace);
|
|
484
|
+
size_t mosaic_length = strlen(mosaic);
|
|
485
|
+
size_t identifier_length = sizeof(uint32_t) + namespace_length + sizeof(uint32_t) + mosaic_length;
|
|
486
|
+
|
|
487
|
+
SERIALIZE_U32(identifier_length);
|
|
488
|
+
SERIALIZE_TAGGED((const uint8_t *) namespace, namespace_length);
|
|
489
|
+
SERIALIZE_TAGGED((const uint8_t *) mosaic, mosaic_length);
|
|
490
|
+
SERIALIZE_U32(type);
|
|
491
|
+
SERIALIZE_U64(delta);
|
|
492
|
+
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
bool nem_transaction_create_aggregate_modification(nem_transaction_ctx *ctx,
|
|
497
|
+
uint8_t network,
|
|
498
|
+
uint32_t timestamp,
|
|
499
|
+
const ed25519_public_key signer,
|
|
500
|
+
uint64_t fee,
|
|
501
|
+
uint32_t deadline,
|
|
502
|
+
uint32_t modifications,
|
|
503
|
+
bool relative_change) {
|
|
504
|
+
|
|
505
|
+
if (!signer) {
|
|
506
|
+
signer = ctx->public_key;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
510
|
+
NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION,
|
|
511
|
+
(uint32_t) network << 24 | (relative_change ? 2 : 1),
|
|
512
|
+
timestamp,
|
|
513
|
+
signer,
|
|
514
|
+
fee,
|
|
515
|
+
deadline);
|
|
516
|
+
if (!ret) return false;
|
|
517
|
+
|
|
518
|
+
SERIALIZE_U32(modifications);
|
|
519
|
+
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
bool nem_transaction_write_cosignatory_modification(nem_transaction_ctx *ctx,
|
|
524
|
+
uint32_t type,
|
|
525
|
+
const ed25519_public_key cosignatory) {
|
|
526
|
+
|
|
527
|
+
SERIALIZE_U32(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(ed25519_public_key));
|
|
528
|
+
SERIALIZE_U32(type);
|
|
529
|
+
SERIALIZE_TAGGED(cosignatory, sizeof(ed25519_public_key));
|
|
530
|
+
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
bool nem_transaction_write_minimum_cosignatories(nem_transaction_ctx *ctx,
|
|
535
|
+
int32_t relative_change) {
|
|
536
|
+
|
|
537
|
+
SERIALIZE_U32(sizeof(uint32_t));
|
|
538
|
+
SERIALIZE_U32((uint32_t) relative_change);
|
|
539
|
+
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
bool nem_transaction_create_importance_transfer(nem_transaction_ctx *ctx,
|
|
544
|
+
uint8_t network,
|
|
545
|
+
uint32_t timestamp,
|
|
546
|
+
const ed25519_public_key signer,
|
|
547
|
+
uint64_t fee,
|
|
548
|
+
uint32_t deadline,
|
|
549
|
+
uint32_t mode,
|
|
550
|
+
const ed25519_public_key remote) {
|
|
551
|
+
|
|
552
|
+
if (!signer) {
|
|
553
|
+
signer = ctx->public_key;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
bool ret = nem_transaction_write_common(ctx,
|
|
557
|
+
NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER,
|
|
558
|
+
(uint32_t) network << 24 | 1,
|
|
559
|
+
timestamp,
|
|
560
|
+
signer,
|
|
561
|
+
fee,
|
|
562
|
+
deadline);
|
|
563
|
+
if (!ret) return false;
|
|
564
|
+
|
|
565
|
+
SERIALIZE_U32(mode);
|
|
566
|
+
SERIALIZE_TAGGED(remote, sizeof(ed25519_public_key));
|
|
567
|
+
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2013-2014 Tomas Dzetkulic
|
|
3
|
+
* Copyright (c) 2013-2014 Pavol Rusnak
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
7
|
+
* to deal in the Software without restriction, including without limitation
|
|
8
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included
|
|
13
|
+
* in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
19
|
+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
20
|
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
21
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <TrezorCrypto/nist256p1.h>
|
|
25
|
+
|
|
26
|
+
const ecdsa_curve nist256p1 = {
|
|
27
|
+
/* .prime */ {
|
|
28
|
+
/*.val =*/ {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3f, 0x0, 0x0, 0x1000, 0x3fffc000, 0xffff}
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/* G */ {
|
|
32
|
+
/*.x =*/{/*.val =*/{0x1898c296, 0x1284e517, 0x1eb33a0f, 0xdf604b, 0x2440f277, 0x339b958e, 0x4247f8b, 0x347cb84b, 0x6b17}},
|
|
33
|
+
/*.y =*/{/*.val =*/{0x37bf51f5, 0x2ed901a0, 0x3315ecec, 0x338cd5da, 0xf9e162b, 0x1fad29f0, 0x27f9b8ee, 0x10b8bf86, 0x4fe3}}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/* order */ {
|
|
37
|
+
/*.val =*/{0x3c632551, 0xee72b0b, 0x3179e84f, 0x39beab69, 0x3fffffbc, 0x3fffffff, 0xfff, 0x3fffc000, 0xffff}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/* order_half */ {
|
|
41
|
+
/*.val =*/{0x3e3192a8, 0x27739585, 0x38bcf427, 0x1cdf55b4, 0x3fffffde, 0x3fffffff, 0x7ff, 0x3fffe000, 0x7fff}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/* a */ -3,
|
|
45
|
+
|
|
46
|
+
/* b */ {
|
|
47
|
+
/*.val =*/{0x27d2604b, 0x2f38f0f8, 0x53b0f63, 0x741ac33, 0x1886bc65, 0x2ef555da, 0x293e7b3e, 0xd762a8e, 0x5ac6}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
,
|
|
51
|
+
/* cp */ {
|
|
52
|
+
#include "nist256p1.table"
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const curve_info nist256p1_info = {
|
|
57
|
+
.bip32_name = "Nist256p1 seed",
|
|
58
|
+
.params = &nist256p1,
|
|
59
|
+
.hasher_base58 = HASHER_SHA2D,
|
|
60
|
+
.hasher_sign = HASHER_SHA2D,
|
|
61
|
+
.hasher_pubkey = HASHER_SHA2_RIPEMD,
|
|
62
|
+
.hasher_script = HASHER_SHA2,
|
|
63
|
+
};
|