Skip to content

Commit

Permalink
feat: add PlatformIO Example (#35)
Browse files Browse the repository at this point in the history
* fix:  Update PIO manifest

Updated PIO manifest with dependencies and additional include directories.

* feat:  Add PIO example

* chore:  Rename extras to examples.

* chore:  update to new examples path

* chore:  Clean up non-existent directory references

* chore:  update examples

Renamed PIO example to INO extension.
Added explicit examples path to manifest.

* fix:  Update script with new examples path
  • Loading branch information
ciband authored and faustbrian committed Dec 14, 2018
1 parent b0cc3aa commit 54969a3
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .circleci/script_desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake . -DCMAKE_BUILD_TYPE=Coverage
cmake --build .

# build examples
cd ./extras/cmake_example
cd ./examples/cmake_example
cmake .
cmake --build .

Expand Down
34 changes: 17 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
/INSTALL.vcxproj
/src/Debug
/test/Debug
/extras/cmake_example/ZERO_CHECK.vcxproj.filters
/extras/cmake_example/Win32/Debug
/extras/cmake_example/cmake_example.vcxproj.filters
/extras/cmake_example/cmake_example.vcxproj
/extras/cmake_example/cmake_example.sln
/extras/cmake_example/cmake_example.dir/Debug
/extras/cmake_example/Debug
/extras/cmake_example/cmake_install.cmake
/extras/cmake_example/CMakeFiles
/extras/cmake_example/CMakeCache.txt
/extras/cmake_example/ALL_BUILD.vcxproj.filters
/extras/cmake_example/ALL_BUILD.vcxproj
/extras/cmake_example/ZERO_CHECK.vcxproj
/extras/cmake_example/Cpp-Crypto-Example.dir/Debug
/extras/cmake_example/Cpp-Crypto-Example.vcxproj.filters
/extras/cmake_example/Cpp-Crypto-Example.vcxproj
/extras/cmake_example/Cpp-Crypto-Example.sln
/examples/cmake_example/ZERO_CHECK.vcxproj.filters
/examples/cmake_example/Win32/Debug
/examples/cmake_example/cmake_example.vcxproj.filters
/examples/cmake_example/cmake_example.vcxproj
/examples/cmake_example/cmake_example.sln
/examples/cmake_example/cmake_example.dir/Debug
/examples/cmake_example/Debug
/examples/cmake_example/cmake_install.cmake
/examples/cmake_example/CMakeFiles
/examples/cmake_example/CMakeCache.txt
/examples/cmake_example/ALL_BUILD.vcxproj.filters
/examples/cmake_example/ALL_BUILD.vcxproj
/examples/cmake_example/ZERO_CHECK.vcxproj
/examples/cmake_example/Cpp-Crypto-Example.dir/Debug
/examples/cmake_example/Cpp-Crypto-Example.vcxproj.filters
/examples/cmake_example/Cpp-Crypto-Example.vcxproj
/examples/cmake_example/Cpp-Crypto-Example.sln
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
[submodule "test/lib/googletest"]
path = test/lib/googletest
url = https://github.com/google/googletest.git
[submodule "extras/cmake_example/lib/cpp-crypto"]
path = extras/cmake_example/lib/cpp-crypto
[submodule "examples/cmake_example/lib/cpp-crypto"]
path = examples/cmake_example/lib/cpp-crypto
url = https://github.com/ArkEcosystem/cpp-crypto.git
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions examples/cmake_example/lib/cpp-crypto
Submodule cpp-crypto added at 5ad957
File renamed without changes.
26 changes: 26 additions & 0 deletions examples/platformio_example/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html


[platformio]

[env:esp8266]
lib_deps = Ark-Cpp-Crypto
platform = espressif8266
board = huzzah
framework = arduino
upload_speed = 921600

[env:esp32]
lib_deps = Ark-Cpp-Crypto
platform = espressif32
board = esp32dev
framework = arduino
upload_speed = 921600
119 changes: 119 additions & 0 deletions examples/platformio_example/src/main.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include "arkCrypto.h"

#include <string>
#include <vector>
#include <cstdint>

#include <arduino.h>

void setup() {
Serial.begin(115200);

while (!Serial) { delay(100); };
// ^for the Arduino Leonardo/Micro only
}

void loop() {
const auto text = "Computer science is no more about computers than astronomy is about telescopes.";
const auto passphrase = "viable weasel wage promote praise inflict jaguar tackle color unusual exclude direct";

// Message - sign
Ark::Crypto::Utils::Message message;
message.sign(text, passphrase);

Serial.println("Message");
Serial.print("\tText: "); Serial.print(text); Serial.println();
Serial.print("\tPassphrase: "); Serial.print(passphrase); Serial.println();
Serial.print("\tJson: "); Serial.print(message.toJson().c_str()); Serial.println();
Serial.println();

// Message - verify
auto publicKey = PublicKey::fromHex("0275776018638e5c40f1b922901e96cac2caa734585ef302b4a2801ee9a338a456");
auto signature = HexToBytes("3044022021704f2adb2e4a10a3ddc1d7d64552b8061c05f6d12a168c69091c75581d611402200edf37689d2786fc690af9f0f6fa1f629c95695039f648a6d455484302402e93");

message = Ark::Crypto::Utils::Message(
text,
publicKey,
signature
);

Serial.println("Message");
Serial.print("\tJson: "); Serial.print(message.toJson().c_str()); Serial.println();
Serial.print("\tVerified: "); Serial.print(message.verify()); Serial.println();
Serial.println();

// Mnemonic
const auto new_passphrase = Ark::Crypto::Identities::Mnemonic::generate();
Serial.print("Generated Mnemonic: "); Serial.print(new_passphrase.c_str()); Serial.println();
Serial.println();

// Address - from passphrase
const uint8_t networkVersion = 0x1E;
auto address = Address::fromPassphrase(passphrase, networkVersion);
Serial.println("Address from passphrase");
Serial.print("\tPassphrase: "); Serial.print(passphrase); Serial.println();
Serial.print("\tNetwork Version: 0x"); Serial.print(static_cast<uint16_t>(networkVersion)); Serial.println();
Serial.print("\tAddress: "); Serial.print(address.toString().c_str()); Serial.println();
Serial.println();

// Address - from publickey
publicKey = PublicKey("029fdf41a7d69d8efc7b236c21b9509a23d862ea4ed8b13a56e31eee58dbfd97b4");
address = Address::fromPublicKey(publicKey, networkVersion);
Serial.println("Address from public key");
Serial.print("\tPublic Key: "); Serial.print(publicKey.toString().c_str()); Serial.println();
Serial.print("\tAddress: "); Serial.print(address.toString().c_str()); Serial.println();
Serial.println();

// Address - from privatekey
PrivateKey privateKey("950981ce17df662dbc1d25305f8597a71309fb8f7232203a0944477e2534b021");
address = Address::fromPrivateKey(privateKey, networkVersion);
Serial.println("Address from private key");
Serial.print("\tPrivate Key: "); Serial.print(privateKey.toString().c_str()); Serial.println();
Serial.print("\tAddress: "); Serial.print(address.toString().c_str()); Serial.println();
Serial.println();

// Address - validate
address = Address("DStZXkgpEjxbG355nQ26vnkp95p24U9tsV");
auto isValidAddress = Address::validate(address, networkVersion);
Serial.println("Valid Address");
Serial.print("\tAddress: "); Serial.print(address.toString().c_str()); Serial.println();
Serial.print("\t Valid Address: "); Serial.print(isValidAddress); Serial.println();
Serial.println();

// Private Key - from passphrase
privateKey = PrivateKey::fromPassphrase(passphrase);
Serial.println("Private Key from passprase");
Serial.print("\tPassphrase: "); Serial.print(passphrase); Serial.println();
Serial.print("\tPrivate Key: "); Serial.print(privateKey.toString().c_str()); Serial.println();
Serial.println();

// Private Key - object from hex
privateKey = PrivateKey::fromHex("950981ce17df662dbc1d25305f8597a71309fb8f7232203a0944477e2534b021");
Serial.println("Private Key from hex");
Serial.println("\tHex: 950981ce17df662dbc1d25305f8597a71309fb8f7232203a0944477e2534b021");
Serial.print("\tPrivate Key: "); Serial.print(privateKey.toString().c_str()); Serial.println();
Serial.println();

// Public Key - from passphrase
publicKey = PublicKey::fromPassphrase(passphrase);
Serial.println("Public Key from passprase");
Serial.print("\tPassphrase: "); Serial.print(passphrase); Serial.println();
Serial.print("\tPublic Key: "); Serial.print(publicKey.toString().c_str()); Serial.println();
Serial.println();

// Public Key - object from hex
publicKey = PublicKey::fromHex("029fdf41a7d69d8efc7b236c21b9509a23d862ea4ed8b13a56e31eee58dbfd97b4");
Serial.println("Public Key from hex");
Serial.println("\tHex: 029fdf41a7d69d8efc7b236c21b9509a23d862ea4ed8b13a56e31eee58dbfd97b4");
Serial.print("\tPublic Key: "); Serial.print(publicKey.toString().c_str()); Serial.println();
Serial.println();

// WIF - from passphrase
const uint8_t wifByte = 0xaa;
auto wif = WIF::fromPassphrase(passphrase, wifByte);
Serial.println("WIF from passphrase");
Serial.print("\tPassphrase: "); Serial.print(passphrase); Serial.println();
Serial.print("\tWIF Byte: "); Serial.print(static_cast<uint16_t>(wifByte)); Serial.println();
Serial.print("\tWIF: "); Serial.print(wif.toString().c_str()); Serial.println();

}
1 change: 0 additions & 1 deletion extras/cmake_example/lib/cpp-crypto
Submodule cpp-crypto deleted from 8d0c6c
73 changes: 48 additions & 25 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
{
"name": "Ark-Cpp-Crypto",
"keywords": "ark ecosystem, crypto, blockchain, arduino",
"description": "Cpp Wrapper for the Ark Ecosystem",
"homepage": "https://github.com/ArkEcosystem/Cpp-Crypto",
"repository": {
"type": "git",
"url": "https://github.com/ArkEcosystem/Cpp-Crypto.git"
"name": "Ark-Cpp-Crypto",
"keywords": "ark ecosystem, crypto, blockchain, arduino",
"description": "Cpp Wrapper for the Ark Ecosystem",
"homepage": "https://github.com/ArkEcosystem/Cpp-Crypto",
"repository": {
"type": "git",
"url": "https://github.com/ArkEcosystem/Cpp-Crypto.git"
},
"version": "0.1.0",
"authors": [
{
"name": "Simon Downey",
"email": "simon@ark.io",
"url": "https://github.com/sleepdefic1t"
},
"version": "0.1.0",
"authors": [
{
"name": "Simon Downey",
"email": "simon@ark.io",
"url": "https://github.com/sleepdefic1t"
},
{
"name": "Chris Johnson",
"url": "https://github.com/ciband"
},
{
"name": "supaiku0",
"url": "https://github.com/supaiku0"
}
],
"frameworks": "arduino",
"platforms": "*"
{
"name": "Chris Johnson",
"url": "https://github.com/ciband"
},
{
"name": "supaiku0",
"url": "https://github.com/supaiku0"
}
],
"frameworks": "arduino",
"platforms": "*",
"dependencies": [
{
"name": "micro-ecc"
},
{
"name": "bip39"
}
],
"export": {
"include": [
"src/*"
]
},
"build": {
"flags": [
"-I src/include/cpp-crypto"
]
},
"examples": [
"[Ee]xamples/platformio_example/*.ino",
"[Ee]xamples/platformio_example/*.cpp",
"[Ee]xamples/platformio_example/*.c"
]
}
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ platform = espressif8266
board = huzzah
framework = arduino
build_flags = -I./src/ -I./src/bcl -I./src/include/cpp-crypto
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<extras> -<lib> -<CMakeFiles>
src_filter = +<*> -<.git/> -<examples/> -<lib> -<CMakeFiles>
upload_speed = 921600

[env:esp32]
Expand All @@ -26,5 +26,5 @@ platform = espressif32
board = esp32dev
framework = arduino
build_flags = -I./src/ -I./src/bcl -I./src/include/cpp-crypto
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<extras> -<lib> -<CMakeFiles>
src_filter = +<*> -<.git/> -<examples/> -<lib> -<CMakeFiles>
upload_speed = 921600
2 changes: 1 addition & 1 deletion src/lib/bip39
4 changes: 2 additions & 2 deletions test/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ platform = espressif8266
board = huzzah
framework = arduino
build_flags = -I../test/iot/ -I../src -I../src/bcl -I../src/include/cpp-crypto -DUNIT_TEST
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<bin> -<extras> -<lib> -<_3rdParty> -<CMakeFiles> -<src/CMakeFiles> -<test/CMakeFiles> -<src/lib> -<test/lib/googletest>
src_filter = +<*> -<.git/> -<examples/> -<bin> -<lib> -<_3rdParty> -<CMakeFiles> -<src/CMakeFiles> -<test/CMakeFiles> -<src/lib> -<test/lib/googletest>
upload_speed = 921600

[env:esp32]
Expand All @@ -29,5 +29,5 @@ platform = espressif32
board = esp32dev
framework = arduino
build_flags = -I../test/iot/ -I../src -I../src/bcl -I../src/include/cpp-crypto -DUNIT_TEST
src_filter = +<*> -<.git/> -<svn/> -<example/> -<examples/> -<bin> -<extras> -<lib> -<_3rdParty> -<CMakeFiles> -<src/CMakeFiles> -<test/CMakeFiles> -<src/lib/> -<test/lib/googletest>
src_filter = +<*> -<.git/> -<examples/> -<bin> -<lib> -<_3rdParty> -<CMakeFiles> -<src/CMakeFiles> -<test/CMakeFiles> -<src/lib/> -<test/lib/googletest>
upload_speed = 921600

0 comments on commit 54969a3

Please sign in to comment.