### Compile Example with GCC Source: https://lib.dogecoin.org/docs/what Command to compile the provided example file by linking against the static library. ```bash gcc ./contrib/examples/example.c ./.libs/libdogecoin.a -I./include/dogecoin -L./.libs -ldogecoin -lunistring -o example ``` -------------------------------- ### Install Dependencies and Clone Repository Source: https://lib.dogecoin.org/docs/enclaves Commands to install Docker and clone the libdogecoin repository for the build process. ```bash sudo apt-get install docker.io mkdir -p /doge cd /doge git clone https://github.com/dogecoinfoundation/libdogecoin.git cd libdogecoin ``` -------------------------------- ### C Example for generatePrivPubKeypair Source: https://lib.dogecoin.org/docs/address A practical C code example demonstrating how to use the `generatePrivPubKeypair` function from the Libdogecoin library to generate Dogecoin keys for the mainnet. ```APIDOC ## C Example: Generating Dogecoin Keys ### Description This C code snippet shows how to initialize the Libdogecoin cryptographic context, generate a mainnet private and public key pair using `generatePrivPubKeypair`, and then clean up the context. ### Method N/A (Illustrative C Code) ### Endpoint N/A (Libdogecoin Function Call) ### Parameters N/A ### Request Example ```c #include "libdogecoin.h" #include int main() { int privkeyLen = PRIVKEYWIFLEN; int pubkeyLen = P2PKHLEN; char privKey[privkeyLen]; char pubKey[pubkeyLen]; dogecoin_ecc_start(); generatePrivPubKeypair(privKey, pubKey, false); // generating a mainnet pair dogecoin_ecc_stop(); printf("My private key for mainnet is: %s\n", privKey); printf("My public key for mainnet is: %s\n", pubKey); return 0; } ``` ### Response N/A (Prints to console) ### Compilation Instructions Ensure `libdogecoin` and `libunistring` are installed. Compile using: `gcc -o example example.c -ldogecoin -lunistring` ``` -------------------------------- ### Install Dependencies on MacOS Source: https://lib.dogecoin.org/docs/what Command line tools and permissions setup for MacOS builds. ```bash xcode_select --install sudo chown -R $(whoami) $(brew --prefix)/* ``` -------------------------------- ### Configure Build Options Source: https://lib.dogecoin.org/docs/getting-started Examples of configuring the library build with various flags. ```bash ./configure ./configure --disable-net --disable-tools ./configure LD_LIBRARY_PATH='path/to/additional/libraries' ./configure CFLAGS='-Ipath/to/additional/include/files' ``` -------------------------------- ### Build and Test Output Source: https://lib.dogecoin.org/docs/getting-started Example output from running the make check command. ```text make[1]: Entering directory '/home/username/libdogecoin' make check-TESTS make[2]: Entering directory '/home/username/libdogecoin' PASSED - test_address() PASSED - test_aes() PASSED - test_base58() PASSED - test_bip32() ... PASSED - test_tool() PASSED - test_net_basics_plus_download_block() PASSED - test_protocol() PASS: tests ============= 1 test passed ============= make[2]: Leaving directory '/home/username/libdogecoin' make[1]: Leaving directory '/home/username/libdogecoin' ``` -------------------------------- ### Configure Build with CMake Source: https://lib.dogecoin.org/docs/getting-started Initial setup for building the library using CMake on Windows. ```bash mkdir build cd build cmake .. ``` -------------------------------- ### Install Dependencies on Linux Source: https://lib.dogecoin.org/docs/getting-started Commands to install required build dependencies on Ubuntu and Debian systems. ```bash sudo apt-get update sudo apt-get install autoconf automake libtool libevent-dev libunistring-dev build-essential ``` -------------------------------- ### Install YubiKey Dependencies on Linux Source: https://lib.dogecoin.org/docs/yubikey Commands to install the necessary YubiKey and PC/SC libraries on Debian-based Linux distributions. ```bash sudo apt-get update sudo apt-get install libykpiv libykpiv-dev pcscd libpcsclite-dev ``` -------------------------------- ### Setup and Run Libdogecoin TA in QEMU Source: https://lib.dogecoin.org/docs/enclaves Commands to mount the drive, copy the libdogecoin TA and host application, run the enclave, and then copy data back. This sequence is performed within the QEMU environment. ```bash # Mount the drive and copy the TA, host application, and data if needed mkdir /mnt/libdogecoin && \ mount /dev/vda /mnt/libdogecoin && \ cp /mnt/libdogecoin/62d95dc0-7fc2-4cb3-a7f3-c13ae4e633c4.ta /lib/optee_armtz/ && \ cp /mnt/libdogecoin/optee_libdogecoin /usr/bin/ && \ if [ "$(ls -A /mnt/libdogecoin/data/tee/)" ]; then cp /mnt/libdogecoin/data/tee/* /data/tee/ && \ chown tee:tee /data/tee/*; \ fi cd /usr/bin/ && \ chmod 777 optee_libdogecoin chmod 644 /lib/optee_armtz/62d95dc0-7fc2-4cb3-a7f3-c13ae4e633c4.ta # Run the OP-TEE Libdogecoin Key Manager Enclave (see tutorial for commands) optee_libdogecoin -c generate_mnemonic # When finished, copy the data back to the drive cp -r /data/tee/* /mnt/libdogecoin/data/tee/ # Unmount the drive and power off the system umount /mnt/libdogecoin poweroff ``` -------------------------------- ### Start New ECKey Source: https://lib.dogecoin.org/docs/eckey Creates a new eckey, adds it to the hash table, and returns its index. ```C int start_key(dogecoin_bool is_testnet) { eckey* key = new_eckey(is_testnet); int index = key->idx; add_eckey(key); return index; } ``` ```C int key_id = start_key(false); ``` -------------------------------- ### Build OP-TEE SDK and Client with Docker Source: https://lib.dogecoin.org/docs/enclaves This command pulls the OP-TEE OS CI Docker image and runs a container to set up the environment, download the OP-TEE manifest, configure build options, generate RSA keys, sign subkeys, build the OP-TEE OS with Linux modules, and compile the OP-TEE client. Ensure you have Docker installed and the necessary permissions. ```bash docker pull jforissier/optee_os_ci:qemu_check docker run -v "$(pwd):/src" -w /src jforissier/optee_os_ci:qemu_check /bin/bash -c "\ # Set up the environment and build the OP-TEE SDK set -e && \ apt update && \ apt -y upgrade && \ apt -y install libusb-1.0-0-dev swig python3-dev python3-setuptools e2tools && \ curl https://storage.googleapis.com/git-repo-downloads/repo > /bin/repo && chmod a+x /bin/repo && \ mkdir -p optee && \ cd optee && \ # repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml -b 4.0.0 repo init -u https://github.com/OP-TEE/manifest.git -m nanopc-t6.xml -b master && \ export FORCE_UNSAFE_CONFIGURE=1 && \ repo sync -j 4 --force-sync && \ cd build && \ make toolchains -j 4 && \ export CFG_TEE_CORE_LOG_LEVEL=0 && \ export CFG_ATTESTATION_PTA=y && \ export CFG_ATTESTATION_PTA_KEY_SIZE=1024 && \ export CFG_WITH_USER_TA=y && \ export CFG_WITH_SOFTWARE_PRNG=n && \ # Generate RSA private key and overwrite the default TA key openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048 && \ mv rsa_private.pem /src/optee/optee_os/keys/default_ta.pem && \ # Generate subkeys openssl genrsa -out /src/optee/optee_test/ta/top_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/mid_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/identity_subkey2.pem && \ # Sign the top-level subkey with the root key /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid f04fa996-148a-453c-b037-1dcfbad120a6 \ --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/top_level_subkey.pem \ --out /src/optee/optee_test/ta/top_level_subkey.bin --max-depth 4 --name-size 64 \ --subkey-version 1 && \ # Generate UUID for the mid-level subkey /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/top_level_subkey.bin \ --name mid_level_subkey && \ # Sign the mid-level subkey with the top-level subkey /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid 1a5948c5-1aa0-518c-86f4-be6f6a057b16 \ --key /src/optee/optee_test/ta/top_level_subkey.pem --subkey /src/optee/optee_test/ta/top_level_subkey.bin \ --name-size 64 --subkey-version 1 \ --name mid_level_subkey \ --in /src/optee/optee_test/ta/mid_level_subkey.pem --out /src/optee/optee_test/ta/mid_level_subkey.bin && \ # Generate UUID for subkey1_ta /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/mid_level_subkey.bin \ --name subkey1_ta && \ # Sign the identity subkey2 with the root key /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid a720ccbb-51da-417d-b82e-e5445d474a7a \ --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/identity_subkey2.pem \ --out /src/optee/optee_test/ta/identity_subkey2.bin --max-depth 0 --name-size 0 \ --subkey-version 1 && \ # Build and test the OP-TEE OS and client # make -j 4 check make LINUX_MODULES=y -j 4 && \ cd /src && \ [ ! -d optee_client ] && git clone https://github.com/OP-TEE/optee_client.git && \ cd optee_client && \ mkdir -p build && \ cd build && \ export PATH=/src/optee/toolchains/aarch64/bin:$PATH && \ export CC=aarch64-linux-gnu-gcc && \ cmake .. -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_INSTALL_PREFIX=/src/optee/toolchains/aarch64 && \ make -j 4 VERBOSE=1 && \ make install" ``` -------------------------------- ### Install Dependencies on Debian/Ubuntu Source: https://lib.dogecoin.org/docs/what Required system packages for building Libdogecoin on Debian-based distributions. ```bash sudo apt-get install autoconf automake libtool build-essential libevent-dev libunistring-dev ``` -------------------------------- ### Advanced spvnode Sync Examples Source: https://lib.dogecoin.org/docs/tools Complex command combinations for syncing, debugging, and managing memory-only operations. ```bash ./spvnode scan ``` ```bash ./spvnode -d scan ``` ```bash ./spvnode -d -f 0 -c -b scan ``` ```bash ./spvnode -d -f 0 -c -a "DSVw8wkkTXccdq78etZ3UwELrmpfvAiVt1" -b scan ``` -------------------------------- ### Raw ScriptPubKey Example Source: https://lib.dogecoin.org/docs/transaction-extended Provides a raw byte representation of a scriptPubKey, demonstrating the opcodes and data pushes involved. ```plaintext 76 A9 14 OP_DUP OP_HASH160 Bytes to push 89 AB CD EF AB BA AB BA AB BA AB BA AB BA AB BA AB BA AB BA 88 AC Data to push OP_EQUALVERIFY OP_CHECKSIG ``` -------------------------------- ### Generate Key Pair in C Source: https://lib.dogecoin.org/docs/address Example usage of generatePrivPubKeypair to create a mainnet private and public key pair. ```c #include "libdogecoin.h" #include int main() { int privkeyLen = PRIVKEYWIFLEN; int pubkeyLen = P2PKHLEN; char privKey[privkeyLen]; char pubKey[pubkeyLen]; dogecoin_ecc_start(); generatePrivPubKeypair(privKey, pubKey, false); // generating a mainnet pair dogecoin_ecc_stop(); printf("My private key for mainnet is: %s\n", privKey); printf("My public key for mainnet is: %s\n", pubKey); } ``` -------------------------------- ### Build OP-TEE SDK and Client in Docker Source: https://lib.dogecoin.org/docs/enclaves Executes the full build pipeline including environment setup, repository synchronization, key generation, and compilation within a containerized environment. ```bash docker pull jforissier/optee_os_ci:qemu_check docker run -v "$(pwd):/src" -w /src jforissier/optee_os_ci:qemu_check /bin/bash -c "\ # Set up the environment and build the OP-TEE SDK set -e && \ apt update && \ apt -y upgrade && \ apt -y install libusb-1.0-0-dev swig python3-dev python3-setuptools e2tools && \ curl https://storage.googleapis.com/git-repo-downloads/repo > /bin/repo && chmod a+x /bin/repo && \ mkdir -p optee && \ cd optee && \ repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml -b 4.0.0 && \ export FORCE_UNSAFE_CONFIGURE=1 && \ repo sync -j 4 --force-sync && \ patch -N -F 4 /src/optee/build/common.mk < /src/src/optee/common.mk.patch && \ cd build && \ make toolchains -j 4 && \ export CFG_TEE_CORE_LOG_LEVEL=0 && \ export CFG_ATTESTATION_PTA=y && \ export CFG_ATTESTATION_PTA_KEY_SIZE=1024 && \ export CFG_WITH_USER_TA=y && \ # Generate RSA private key and overwrite the default TA key openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048 && \ mv rsa_private.pem /src/optee/optee_os/keys/default_ta.pem && \ # Generate subkeys openssl genrsa -out /src/optee/optee_test/ta/top_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/mid_level_subkey.pem && \ openssl genrsa -out /src/optee/optee_test/ta/identity_subkey2.pem && \ # Sign the top-level subkey with the root key /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid f04fa996-148a-453c-b037-1dcfbad120a6 \ --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/top_level_subkey.pem \ --out /src/optee/optee_test/ta/top_level_subkey.bin --max-depth 4 --name-size 64 \ --subkey-version 1 && \ # Generate UUID for the mid-level subkey /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/top_level_subkey.bin \ --name mid_level_subkey && \ # Sign the mid-level subkey with the top-level subkey /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid 1a5948c5-1aa0-518c-86f4-be6f6a057b16 \ --key /src/optee/optee_test/ta/top_level_subkey.pem --subkey /src/optee/optee_test/ta/top_level_subkey.bin \ --name-size 64 --subkey-version 1 \ --name mid_level_subkey \ --in /src/optee/optee_test/ta/mid_level_subkey.pem --out /src/optee/optee_test/ta/mid_level_subkey.bin && \ # Generate UUID for subkey1_ta /src/optee/optee_os/scripts/sign_encrypt.py subkey-uuid --in /src/optee/optee_test/ta/mid_level_subkey.bin \ --name subkey1_ta && \ # Sign the identity subkey2 with the root key /src/optee/optee_os/scripts/sign_encrypt.py sign-subkey \ --uuid a720ccbb-51da-417d-b82e-e5445d474a7a \ --key /src/optee/optee_os/keys/default_ta.pem --in /src/optee/optee_test/ta/identity_subkey2.pem \ --out /src/optee/optee_test/ta/identity_subkey2.bin --max-depth 0 --name-size 0 \ --subkey-version 1 && \ # Build and test the OP-TEE OS and client make -j 4 check cd /src && \ [ ! -d optee_client ] && git clone https://github.com/OP-TEE/optee_client.git && \ cd optee_client && \ mkdir -p build && \ cd build && \ export PATH=/src/optee/toolchains/aarch64/bin:$PATH && \ export CC=aarch64-linux-gnu-gcc && \ cmake .. -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_INSTALL_PREFIX=/src/optee/toolchains/aarch64 && \ make -j 4 VERBOSE=1 && \ make install" ``` -------------------------------- ### Start a New Transaction Source: https://lib.dogecoin.org/docs/transaction Instantiates a new working transaction and returns its index. Remember to clear the transaction using `clear_transaction()` to prevent memory leaks. ```c #include "libdogecoin.h" int main() { int index = start_transaction(); // build onto the working transaction here clear_transaction(index); } ``` -------------------------------- ### Send Raw Transactions via sendtx Source: https://lib.dogecoin.org/docs/tools Examples of sending raw transactions using different network configurations and peer settings. ```bash ./sendtx -d -t ``` ```bash ./sendtx -d -s 5 -i 192.168.1.110:22556,127.0.0.1:22556 ``` ```bash ./sendtx -m 5 ``` -------------------------------- ### Run OP-TEE Libdogecoin Enclave in QEMU Source: https://lib.dogecoin.org/docs/enclaves Launches the QEMU emulator with OP-TEE OS and configures it to boot the libdogecoin TA. Ensure your YubiKey's vendor and product IDs are correctly specified. ```bash docker run --privileged -v /dev/bus/usb:/dev/bus/usb -it -v "$(pwd):/src" -w /src jforissier/optee_os_ci:qemu_check /bin/bash -c "\ chmod 777 /src/optee/qemu/build/aarch64-softmmu/qemu-system-aarch64 && \ cd /src/optee/out/bin && \ /src/optee/qemu/build/aarch64-softmmu/qemu-system-aarch64 \ -L /src/optee/qemu/pc-bios \ -nographic \ -serial mon:stdio \ -serial file:/src/optee/serial1.log \ -smp 2 \ -machine virt,secure=on,mte=off,gic-version=3 \ -cpu max,pauth-impdef=on \ -d unimp \ -semihosting-config enable=on,target=native \ -m 1057 \ -bios bl1.bin \ -initrd rootfs.cpio.gz \ -kernel Image \ -no-acpi \ -drive file=libdogecoin.img,format=raw,id=libdogecoin,if=none \ -device virtio-blk-device,drive=libdogecoin \ -append 'console=ttyAMA0,38400 keep_bootcon root=/dev/vda2' \ -usb \ -device pci-ohci,id=ohci \ -device usb-host,vendorid=0x1050,productid=0x0407" ``` -------------------------------- ### GET /getLastBlockInfo Source: https://lib.dogecoin.org/docs/rest Retrieves information about the last block. ```APIDOC ## GET /getLastBlockInfo ### Description Retrieves information about the last block. ### Method GET ### Endpoint /getLastBlockInfo ``` -------------------------------- ### GET /getAddresses Source: https://lib.dogecoin.org/docs/rest Retrieves all addresses associated with the wallet. ```APIDOC ## GET /getAddresses ### Description Retrieves all addresses associated with the wallet. ### Method GET ### Endpoint /getAddresses ### Response #### Success Response (200) - **Content-Type**: text/plain - **Body**: address: address: ... ### Request Example ```bash curl http://localhost:/getAddresses ``` ### Response Example ``` address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU ``` ``` -------------------------------- ### GET /getBalance Source: https://lib.dogecoin.org/docs/rest Retrieves the total balance of the wallet. ```APIDOC ## GET /getBalance ### Description Retrieves the total balance of the wallet. ### Method GET ### Endpoint /getBalance ### Response #### Success Response (200) - **Content-Type**: text/plain - **Body**: Wallet balance: ### Request Example ```bash curl http://localhost:/getBalance ``` ### Response Example ``` Wallet balance: 123.45678900 ``` ``` -------------------------------- ### GET /getWallet Source: https://lib.dogecoin.org/docs/rest Downloads the wallet file associated with the node. ```APIDOC ## GET /getWallet ### Description Downloads the wallet file associated with the node. ### Method GET ### Endpoint /getWallet ### Response #### Success Response (200) - **Content-Type**: application/octet-stream - **Body**: Binary data of the wallet file. ### Request Example ```bash curl -O http://localhost:/getWallet ``` ### Notes - The response is a binary file. - Ensure that it's secure as it contains sensitive information. ``` -------------------------------- ### Initialize Build Environment Source: https://lib.dogecoin.org/docs/getting-started Run the autogen script to prepare the build environment. ```bash ./autogen.sh ``` -------------------------------- ### GET /getHeaders Source: https://lib.dogecoin.org/docs/rest Downloads the headers file used by the SPV node. ```APIDOC ## GET /getHeaders ### Description Downloads the headers file used by the SPV node. ### Method GET ### Endpoint /getHeaders ### Response #### Success Response (200) - **Content-Type**: application/octet-stream - **Body**: Binary data of the headers file. ### Request Example ```bash curl -O http://localhost:/getHeaders ``` ### Notes - The response is a binary file containing blockchain headers. - Useful for debugging or analysis purposes. ``` -------------------------------- ### GET /getTransactions Source: https://lib.dogecoin.org/docs/rest Retrieves all spent (non-spendable) transactions associated with the wallet. ```APIDOC ## GET /getTransactions ### Description Retrieves all spent (non-spendable) transactions associated with the wallet. ### Method GET ### Endpoint /getTransactions ### Response #### Success Response (200) - **Content-Type**: text/plain - **Body**: Information about each spent transaction (UTXO) and the total spent balance. ### Request Example ```bash curl http://localhost:/getTransactions ``` ### Response Example ``` ---------------------- txid: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 vout: 0 address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L script_pubkey: 76a9144621d6a7f3b4ebbaee4e2d8c10eafbf1ccbc9c0a88ac amount: 50.00000000 confirmations: 100 spendable: 0 solvable: 1 Spent Balance: 50.00000000 ``` ``` -------------------------------- ### start_key Source: https://lib.dogecoin.org/docs/eckey Creates a new eckey, adds it to the hash table, and returns its index. ```APIDOC ## start_key ### Description Creates a new eckey, places it in the hash table, and returns the index of the new eckey. ### Parameters #### Path Parameters - **is_testnet** (dogecoin_bool) - Required - Boolean flag for network selection. ### Response - **index** (int) - The index of the new eckey. ``` -------------------------------- ### Build OP-TEE Libdogecoin Enclave with Docker Source: https://lib.dogecoin.org/docs/enclaves This command builds the OP-TEE Libdogecoin Key Manager Enclave for QEMU ARMv8 or NanoPC-T6. It includes setting up the environment, building libdogecoin for both host and OP-TEE, and constructing the enclave image. The CFLAGS=-Wp,-D_FORTIFY_SOURCE=0 flag is used to disable fortify source checks, which are not supported by OP-TEE. ```bash docker run --privileged -v "$(pwd):/src" -w /src jforissier/optee_os_ci:qemu_check /bin/bash -c " # Set up the environment and build libdogecoin apt-get update && \ apt-get install -y autoconf automake libtool-bin build-essential curl python3 valgrind g++-aarch64-linux-gnu qemu-user-static qemu-user && \ # Build libdogecoin for Host make -j 4 -C depends HOST=aarch64-linux-gnu && \ ./autogen.sh && \ ./configure --prefix=/src/depends/aarch64-linux-gnu LIBS=-levent_pthreads --enable-static --disable-shared --enable-test-passwd HOST=aarch64-linux-gnu && \ make -j 4 && \ make install && \ export PATH=/src/optee/toolchains/aarch64/bin:$PATH && \ export CC=aarch64-linux-gnu-gcc && \ # Build the Host cd /src/src/optee/host && \ make -j 4 \ CROSS_COMPILE=aarch64-linux-gnu- \ LDFLAGS=\"-L/src/optee/toolchains/aarch64/lib -L/src/depends/aarch64-linux-gnu/lib -ldogecoin -lunistring\" \ CFLAGS=\"-I/src/optee/toolchains/aarch64/include -I/src/src/optee/ta/include -I/src/depends/aarch64-linux-gnu/include -I/src/depends/aarch64-linux-gnu/include/ykpers-1 -I/src/depends/aarch64-linux-gnu/include/dogecoin\" && \ # Build libdogecoin for OP-TEE cd /src/ && \ make -j 4 -C depends CFLAGS=-Wp,-D_FORTIFY_SOURCE=0 HOST=aarch64-linux-gnu && \ ./configure --prefix=/src/depends/aarch64-linux-gnu LIBS=-levent_pthreads --enable-static --disable-shared --enable-test-passwd --enable-optee CFLAGS=-Wp,-D_FORTIFY_SOURCE=0 HOST=aarch64-linux-gnu && \ make -j 4 && \ make install && \ # Build the Enclave cd /src/src/optee/ta && \ make -j 4 \ CROSS_COMPILE=aarch64-linux-gnu- \ LIBDIR=/src/depends/aarch64-linux-gnu/lib \ LDFLAGS=\"-L/src/depends/aarch64-linux-gnu/lib -ldogecoin -lunistring\" \ CFLAGS=\"-I/src/depends/aarch64-linux-gnu/include -I/src/depends/aarch64-linux-gnu/include/dogecoin\" \ PLATFORM=vexpress-qemu_armv8a \ TA_DEV_KIT_DIR=/src/optee/optee_os/out/arm/export-ta_arm64 && \ # Create symbolic links and prepare image mkdir -p /src/optee/out/bin && \ cd /src/optee/out/bin && \ ln -sf ../../linux/arch/arm64/boot/Image Image && \ ln -sf ../../trusted-firmware-a/build/qemu/release/bl1.bin bl1.bin && \ ln -sf ../../trusted-firmware-a/build/qemu/release/bl2.bin bl2.bin && \ ln -sf ../../trusted-firmware-a/build/qemu/release/bl31.bin bl31.bin && \ ln -sf ../../optee_os/out/arm/core/tee-header_v2.bin bl32.bin && \ ln -sf ../../optee_os/out/arm/core/tee-pager_v2.bin bl32_extra1.bin && \ ln -sf ../../optee_os/out/arm/core/tee-pageable_v2.bin bl32_extra2.bin && \ ln -sf ../../edk2/Build/ArmVirtQemuKernel-AARCH64/RELEASE_GCC5/FV/QEMU_EFI.fd bl33.bin && \ ln -sf ../../out-br/images/rootfs.cpio.gz rootfs.cpio.gz && \ dd if=/dev/zero of=/src/optee/out/bin/libdogecoin.img bs=1M count=32 && \ mkfs.ext4 /src/optee/out/bin/libdogecoin.img && \ mkdir -p /src/optee/out-br/mnt && \ mount -o loop /src/optee/out/bin/libdogecoin.img /src/optee/out-br/mnt && \ cp /src/src/optee/ta/*.ta /src/optee/out-br/mnt && \ cp /src/src/optee/host/optee_libdogecoin /src/optee/out-br/mnt && \ cp /src/spvnode /src/optee/out-br/mnt && \ cp /src/sendtx /src/optee/out-br/mnt && \ cp /src/such /src/optee/out-br/mnt && \ cp /src/tests /src/optee/out-br/mnt && \ cp /src/bench /src/optee/out-br/mnt && \ mkdir -p /src/optee/out-br/mnt/data/tee && \ umount /src/optee/out-br/mnt && \ exit" ``` -------------------------------- ### Build and Test Library Source: https://lib.dogecoin.org/docs/getting-started Commands to compile the library and execute unit tests. ```bash make ``` ```bash make check ``` -------------------------------- ### GET /getTimestamp Source: https://lib.dogecoin.org/docs/rest Retrieves the current date and local time of the SPV node. ```APIDOC ## GET /getTimestamp ### Description Retrieves the current timestamp of the SPV node. ### Method GET ### Endpoint /getTimestamp ### Response #### Success Response (200) - **Body** (text/plain) - Timestamp: #### Response Example 2024-10-26 15:30:00 ``` -------------------------------- ### Run OP-TEE Libdogecoin Enclave on NanoPC-T6 Source: https://lib.dogecoin.org/docs/enclaves This section describes how to copy the built enclave image to a NanoPC-T6, mount it, and execute the `optee_libdogecoin` command to generate a mnemonic. Ensure the enclave image is transferred via scp and mounted correctly before execution. ```bash mkdir /media/libdogecoin mount /root/libdogecoin.img /media/libdogecoin cd /media/libdogecoin cp /media/libdogecoin/62d95dc0-7fc2-4cb3-a7f3-c13ae4e633c4.ta /lib/optee_armtz/ ./optee_libdogecoin -c generate_mnemonic ``` -------------------------------- ### GET /getChaintip Source: https://lib.dogecoin.org/docs/rest Retrieves the height of the latest block known to the SPV node. ```APIDOC ## GET /getChaintip ### Description Retrieves the height of the latest block known to the SPV node. ### Method GET ### Endpoint /getChaintip ### Response #### Success Response (200) - **Body** (text/plain) - Chain tip: #### Response Example Chain tip: 3500000 ``` -------------------------------- ### GET /getUTXOs Source: https://lib.dogecoin.org/docs/rest Retrieves all unspent transaction outputs (UTXOs) associated with the wallet. ```APIDOC ## GET /getUTXOs ### Description Retrieves all unspent transaction outputs (UTXOs) associated with the wallet. ### Method GET ### Endpoint /getUTXOs ### Response #### Success Response (200) - **Content-Type**: text/plain - **Body**: Information about each unspent transaction output and the total unspent balance. ### Request Example ```bash curl http://localhost:/getUTXOs ``` ### Response Example ``` ---------------------- Unspent UTXO: txid: b1fea5241c4a1d7d1e6c6d619fbf3bb8b1ec3f1f1d2f4c5b6a7c8d9e0f1a2b3c vout: 1 address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU script_pubkey: 76a9145d6a7f3b4ebbaee4e2d8c10eafbf1ccbc9c0a88ac amount: 75.00000000 confirmations: 100 spendable: 1 solvable: 1 Total Unspent: 75.00000000 ``` ``` -------------------------------- ### Build Libdogecoin with CMake Source: https://lib.dogecoin.org/docs/what Alternative build process using CMake from the project root. ```bash mkdir build cd build cmake .. cmake --build . ``` -------------------------------- ### Build Libdogecoin with Autoconf Source: https://lib.dogecoin.org/docs/what Standard build sequence for the full library including CLI tools. ```bash ./autogen.sh ./configure make ``` -------------------------------- ### Get Timestamp Request Source: https://lib.dogecoin.org/docs/rest Retrieves the current date and local time of the SPV node. ```text Timestamp: ``` ```bash curl http://localhost:/getTimestamp ``` ```text 2024-10-26 15:30:00 ``` -------------------------------- ### Get Chaintip Request Source: https://lib.dogecoin.org/docs/rest Retrieves the height of the latest block known to the SPV node. ```text Chain tip: ``` ```bash curl http://localhost:/getChaintip ``` ```text Chain tip: 3500000 ``` -------------------------------- ### Display Such Tool Version Source: https://lib.dogecoin.org/docs/tools Run this command to display the version of the 'such' tool. This command overrides any previously specified options. ```bash ./such -v ``` -------------------------------- ### Get Wallet Addresses Source: https://lib.dogecoin.org/docs/rest Retrieves all addresses associated with the wallet. Each address is on a new line. ```bash curl http://localhost:/getAddresses ``` ```text address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU ``` -------------------------------- ### Get Wallet Balance Source: https://lib.dogecoin.org/docs/rest Retrieves the total balance of the wallet. The response is plain text. ```bash curl http://localhost:/getBalance ``` ```text Wallet balance: 123.45678900 ``` -------------------------------- ### Basic Libdogecoin C Program Source: https://lib.dogecoin.org/docs/getting-started A C program demonstrating the initialization and basic usage of Libdogecoin functions, including key pair generation, transaction construction, signing, and broadcasting. Ensure Libdogecoin is properly linked during compilation. ```c #include "libdogecoin.h" #include int main() { dogecoin_ecc_start(); // establish existing info (utxo is worth 2 doge) char *oldPrivKey = "ci5prbqz7jXyFPVWKkHhPq4a9N8Dag3TpeRfuqqC2Nfr7gSqx1fy"; char *oldPubKey = "031dc1e49cfa6ae15edd6fa871a91b1f768e6f6cab06bf7a87ac0d8beb9229075b"; char *oldScriptPubKey = "76a914d8c43e6f68ca4ea1e9b93da2d1e3a95118fa4a7c88ac"; char* utxo_id = "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074"; int utxo_vout = 1; char* amt_total = "2.0"; // generate new key pair to send to char newPrivKey[PRIVKEYWIFLEN]; char newPubKey[P2PKHLEN]; generatePrivPubKeypair(newPrivKey, newPubKey, false); // build and sign the transaction int idx = start_transaction(); add_utxo(idx, utxo_id, utxo_vout); add_output(idx, newPubKey, "0.69"); finalize_transaction(idx, newPubKey, "0.00226", amt_total, oldPubKey); sign_transaction(idx, oldScriptPubKey, oldPrivKey); // print result printf("\nFinal signed transaction hex: %s\n\n", get_raw_transaction(idx)); dogecoin_ecc_stop(); } ``` -------------------------------- ### Error Handling Response Source: https://lib.dogecoin.org/docs/rest Example of an HTTP 404 error response when a requested resource is not found. ```http HTTP/1.1 404 Not Found Content-Type: text/plain Wallet file not found ``` -------------------------------- ### GET /getChaintip Source: https://lib.dogecoin.org/docs/rest Retrieves the current chain tip (the latest block height known to the node). ```APIDOC ## GET /getChaintip ### Description Retrieves the current chain tip (the latest block height known to the node). ### Method GET ### Endpoint /getChaintip ``` -------------------------------- ### start_transaction Source: https://lib.dogecoin.org/docs/transaction Instantiates a new working transaction structure and returns its index. ```APIDOC ## start_transaction ### Description Instantiates a new working_transaction structure and returns its index for future retrieval as an integer. This new working_transaction will contain an empty hex. ### Parameters None ### Response - **index** (int) - The index of the created working transaction. ``` -------------------------------- ### Sign a Transaction in C Source: https://lib.dogecoin.org/docs/transaction Demonstrates signing all inputs of a transaction using dogecoin_ecc_start and dogecoin_ecc_stop to manage the secp256k1 context. ```C #include "libdogecoin.h" #include int main() { char* prev_output_txid_2 = "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074"; // worth 2 dogecoin char* prev_output_txid_10 = "42113bdc65fc2943cf0359ea1a24ced0b6b0b5290db4c63a3329c6601c4616e2"; // worth 10 dogecoin int prev_output_n_2 = 1; int prev_output_n_10 = 1; char* external_address = "nbGfXLskPh7eM1iG5zz5EfDkkNTo9TRmde"; char* my_address = "noxKJyGPugPRN4wqvrwsrtYXuQCk7yQEsy"; char* my_script_pubkey = "76a914d8c43e6f68ca4ea1e9b93da2d1e3a95118fa4a7c88ac"; char* my_privkey = "ci5prbqz7jXyFPVWKkHhPq4a9N8Dag3TpeRfuqqC2Nfr7gSqx1fy"; int index = start_transaction(); add_utxo(index, prev_output_txid_2, prev_output_n_2); add_utxo(index, prev_output_txid_10, prev_output_n_10); add_output(index, external_address, "5.0"); finalize_transaction(index, external_address, "0.00226", "12.0", my_address); //sign both inputs of the current finalized transaction dogecoin_ecc_start(); if (!sign_transaction(index, my_script_pubkey, my_privkey)) { // error handling here } dogecoin_ecc_stop(); printf("The final signed transaction hex is: %s\n", get_raw_transaction(index)); clear_transaction(index); } ``` -------------------------------- ### spvnode Flag Usage Source: https://lib.dogecoin.org/docs/tools Examples of using specific flags to configure spvnode behavior during the scan process. ```bash ./spvnode -t scan ``` ```bash ./spvnode -r scan ``` ```bash ./spvnode -i 127.0.0.1:22556 scan ``` ```bash ./spvnode -d scan ``` ```bash ./spvnode -m 8 scan ``` ```bash ./spvnode -a "your address here" scan ``` ```bash ./spvnode -n "your mnemonic here" scan ``` ```bash ./spvnode -s scan ``` ```bash ./spvnode -f 0 scan ``` ```bash ./spvnode -c scan ``` ```bash ./spvnode -b scan ``` ```bash ./spvnode -p scan ``` ```bash ./spvnode -w "./wallet.db" scan ``` ```bash ./spvnode -h "./headers.db" scan ``` ```bash ./spvnode -l scan ``` ```bash ./spvnode -y 0 scan ``` ```bash ./spvnode -j scan ``` ```bash ./spvnode -k scan ``` ```bash ./spvnode -z scan ``` -------------------------------- ### Sync with Wallet, No Headers File Source: https://lib.dogecoin.org/docs/tools Syncs the SPV node using a specified wallet file. Does not store headers in a file and waits for new blocks. Debug info is shown. ```bash ./spvnode -d -f 0 -c -w "./main_wallet.db" -b scan ``` -------------------------------- ### Link Libdogecoin in Custom Projects Source: https://lib.dogecoin.org/docs/what GCC command to link the static library and required dependencies into a custom project. ```bash gcc main.c -ldogecoin -levent -lunistring -o myprojectname ``` -------------------------------- ### GET /getLastBlockInfo Source: https://lib.dogecoin.org/docs/rest Retrieves information about the last block processed by the SPV node, including size and transaction counts. ```APIDOC ## GET /getLastBlockInfo ### Description Retrieves information about the last block processed by the SPV node. ### Method GET ### Endpoint /getLastBlockInfo ### Response #### Success Response (200) - **Body** (text/plain) - Block size: , Tx count: , Total tx size: #### Response Example Block size: 4130 Tx count: 11 Total tx size: 3355 ``` -------------------------------- ### Get Last Block Info Request Source: https://lib.dogecoin.org/docs/rest Retrieves size and transaction statistics for the last block processed by the SPV node. ```text Block size: Tx count: Total tx size: ``` ```bash curl http://localhost:/getLastBlockInfo ``` ```text Block size: 4130 Tx count: 11 Total tx size: 3355 ``` -------------------------------- ### Sign All Transaction Inputs via Helper Source: https://lib.dogecoin.org/docs/transaction Iterates over all inputs of a transaction to sign them and outputs the result to a buffer. ```C int sign_transaction_ex(int txindex, const char* script_pubkey, const char* privkey, char* buf, size_t buf_cap); ``` ```C char finalhex[TXHEXMAXLEN + 1]; if (!sign_transaction_ex(idx, scripthex, wif, finalhex, sizeof finalhex)) { /* signing failed */ } printf("fully-signed tx:\n%s\n", finalhex); ```