### C Usage: start_key Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/eckey.md Example C usage of start_key, getting a key index for the mainnet. ```c int key_id = start_key(false); ``` -------------------------------- ### Setup script with depends flag Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/scripts/README-scripts.md Alternative setup that builds dependencies instead of using basic package installation. ```bash ./contrib/scripts/setup.sh --host x86_64-pc-linux-gnu --depends ``` -------------------------------- ### Setup script with host triplet Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/scripts/README-scripts.md Sets up the development environment for the specified host triplet by fetching package updates and installing required dependencies. ```bash ./contrib/scripts/setup.sh --host x86_64-pc-linux-gnu ``` -------------------------------- ### Build example program with gcc Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/sweep.md Builds the example program from contrib/examples/example.c. Run from the repo root after make. ```bash gcc contrib/examples/example.c .libs/libdogecoin.a -Iinclude/dogecoin -o example ``` -------------------------------- ### SMPV client usage example with transaction callback Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Complete example that creates an SMPV client, adds two watched addresses, starts monitoring, processes a raw transaction hex string, retrieves statistics, and cleans up. Includes a callback that prints transaction ID and size. The raw_tx_hex is a placeholder; in real usage it would come from a mempool feed. ```c #include #include #include /* Callback function for transaction notifications */ static void tx_callback(const dogecoin_smpv_tx* tx, const char* address, void* user_data) { (void)user_data; printf("New transaction for %s: %s\n", address, tx->txid); printf("Size: %llu bytes\n", (unsigned long long)tx->size); } int main(void) { /* Create SMPV client */ dogecoin_smpv_client* client = dogecoin_smpv_client_new(&dogecoin_chainparams_main); if (!client) { printf("Failed to create SMPV client\n"); return 1; } /* Add addresses to watch */ dogecoin_smpv_add_watcher(client, "D7Y55vD8nNtW7VnT9Xr6Qc4vB8hN3jK2mP"); dogecoin_smpv_add_watcher(client, "D8Y66wE9nOtW8WnU0Xs7Rd5cC9i4kL3nQ"); /* Start monitoring */ if (!dogecoin_smpv_start(client)) { printf("Failed to start SMPV\n"); dogecoin_smpv_client_free(client); return 1; } /* * Process a transaction. * In a real integration, raw_tx_hex would typically come from a mempool feed * (e.g. inv/tx messages from a peer connection). */ const char* raw_tx_hex = "0100000001..."; /* Raw transaction hex */ dogecoin_smpv_process_tx(client, raw_tx_hex, tx_callback, NULL); /* Get statistics */ uint32_t total_txs = 0; uint32_t watched_addresses = 0; dogecoin_smpv_get_stats(client, &total_txs, &watched_addresses); printf("Watched addresses: %u\n", watched_addresses); printf("Mempool transactions: %u\n", total_txs); /* Clean up */ dogecoin_smpv_stop(client); dogecoin_smpv_client_free(client); return 0; } ``` -------------------------------- ### dogecoin_smpv_start() Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Starts SMPV monitoring. ```APIDOC ## dogecoin_smpv_start() ### Description Starts SMPV monitoring. ### Function Signature ```c dogecoin_bool dogecoin_smpv_start(dogecoin_smpv_client* client); ``` ### Parameters - `client` (dogecoin_smpv_client*) - Required - SMPV client ### Returns - `true` on success - `false` on failure ``` -------------------------------- ### Install Docker and clone libdogecoin Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Installs Docker, clones the libdogecoin repository, and prepares the build environment. Requires Ubuntu 20.04 or later, Docker, and libdogecoin. ```sh sudo apt-get install docker.io mkdir -p /doge cd /doge git clone https://github.com/dogecoinfoundation/libdogecoin.git cd libdogecoin ``` -------------------------------- ### Autoconf build and install Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/libevent/README.md Standard Autoconf build sequence: configure, make, optional verify, and install. Run from the top-level source directory. ```shell $ ./configure $ make $ make verify # (optional) $ sudo make install ``` -------------------------------- ### dogecoin_smpv_start Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Starts the SMPV monitoring process for the client. ```APIDOC ## dogecoin_smpv_start ### Description Starts the SMPV monitoring process for the client. ### Signature ```c dogecoin_bool dogecoin_smpv_start(dogecoin_smpv_client* client); ``` ### Parameters - **client** (dogecoin_smpv_client*) - Required - The SMPV client instance. ### Returns - **dogecoin_bool** - `true` on success, `false` on failure. ### Example ```c if (!dogecoin_smpv_start(client)) { printf("Failed to start SMPV\n"); } ``` ``` -------------------------------- ### Manual snarkjs workflow for circuit compilation, setup, proof, and verification Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/zk_carrier/circuits/README.md Commands to manually drive snarkjs: compile the circuit, generate a local ptau and Groth16 setup, create a proof for a concrete witness, and verify off-box. Requires circom and snarkjs installed. ```bash # 1. Compile the circuit. mkdir -p build/circ_inc ln -sfn "$(npm root -g)/circomlib/circuits" build/circ_inc/circomlib circom range_proof.circom --r1cs --wasm --sym --output build \ -l ./build/circ_inc # 2. Generate a local ptau and trusted-setup phase 2. snarkjs powersoftau new bn128 12 build/pot12_0000.ptau -v echo "demo entropy" | snarkjs powersoftau contribute \ build/pot12_0000.ptau build/pot12_0001.ptau --name="demo" -v snarkjs powersoftau prepare phase2 build/pot12_0001.ptau build/pot12_final.ptau -v snarkjs groth16 setup build/range_proof.r1cs build/pot12_final.ptau build/range_proof_0000.zkey snarkjs zkey contribute build/range_proof_0000.zkey build/range_proof.zkey \ --name="demo contributor" -e="$(head -c 32 /dev/urandom | xxd -p)" snarkjs zkey export verificationkey build/range_proof.zkey build/verification_key.json # 3. Generate a proof for a concrete witness. cat > input.json <<'JSON' { "low": "0", "high": "1000000", "amount": "42000" } JSON snarkjs groth16 fullprove input.json \ build/range_proof_js/range_proof.wasm \ build/range_proof.zkey \ proof.json public.json # 4. Verify off-box. snarkjs groth16 verify build/verification_key.json public.json proof.json ``` -------------------------------- ### Example output from C usage Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction.md Example output from the C usage snippet for one generated key, showing the address, hash160, scriptPubKey, and the round-trip address that equals the original. ```text address : DNNS2bcM8LhqEe2FNnziawRiXPRKSqetoQ hash160 : bcffd06893440814119018952af32315dad83c7c scriptPubKey: 76a914bcffd06893440814119018952af32315dad83c7c88ac round trip : DNNS2bcM8LhqEe2FNnziawRiXPRKSqetoQ ``` -------------------------------- ### End-to-End PSBT Example in C with Build Commands Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/psbt.md Complete BIP174 pipeline for a single-signer P2PKH transaction: create a PSBT, attach the UTXO, sign, finalize, and extract the signed transaction. The shell commands build the example against the static library and run it. ```c #include "libdogecoin.h" #include #include int main(void) { dogecoin_ecc_start(); /* ── 1. Creator: generate a keypair and build the previous tx ── */ dogecoin_key priv; dogecoin_privkey_init(&priv); dogecoin_privkey_gen(&priv); dogecoin_pubkey pub; dogecoin_pubkey_init(&pub); pub.compressed = true; dogecoin_pubkey_from_key(&priv, &pub); char addr[P2PKHLEN]; dogecoin_pubkey_getaddr_p2pkh(&pub, &dogecoin_chainparams_main, addr); /* Build a fake UTXO: 10 DOGE P2PKH output to our address */ dogecoin_tx* prev_tx = dogecoin_tx_new(); dogecoin_tx_add_address_out(prev_tx, &dogecoin_chainparams_main, 1000000000LL /* 10 DOGE */, addr); /* Build the unsigned spending tx via the transaction builder */ const char* dest = "D6a52RGbfvKDzKTh8carkGd1vNdAurHmaS"; int tix = start_transaction(); add_utxo(tix, "b4455e7b7b7acb51fb6feba7a2702c42a5100f61f61abafa31851ed6ae076074", 0); add_output(tix, dest, "9.9"); char* unsigned_hex = finalize_transaction(tix, dest, "0.1", "10", addr); size_t hlen = strlen(unsigned_hex); unsigned char* buf = dogecoin_uchar_vla(hlen / 2 + 1); size_t blen = 0; utils_hex_to_bin(unsigned_hex, buf, hlen, &blen); dogecoin_tx* spend_tx = dogecoin_tx_new(); dogecoin_tx_deserialize(buf, blen, spend_tx, NULL); dogecoin_free(buf); remove_all(); dogecoin_psbt* psbt = dogecoin_psbt_create(spend_tx); dogecoin_tx_free(spend_tx); /* ── 2. Serialize for transport ── */ char* b64 = dogecoin_psbt_to_base64(psbt); printf("Unsigned PSBT: %s\n\n", b64); dogecoin_free(b64); /* ── 3. Updater: attach the UTXO ── */ dogecoin_psbt_input_set_utxo(psbt, 0, prev_tx); dogecoin_tx_free(prev_tx); /* ── 4. Signer: add partial signature ── */ dogecoin_psbt_sign(psbt, &priv); /* ── 5. Finalizer: build final_script_sig ── */ dogecoin_psbt_finalize(psbt); /* ── 6. Extractor: pull out the signed tx ── */ dogecoin_tx* signed_tx = dogecoin_psbt_extract(psbt); uint256_t txhash; dogecoin_tx_hash(signed_tx, txhash); char txhash_hex[65]; utils_bin_to_hex(txhash, 32, txhash_hex); printf("Signed tx hash: %s\n", txhash_hex); dogecoin_tx_free(signed_tx); dogecoin_psbt_free(psbt); dogecoin_pubkey_cleanse(&pub); dogecoin_privkey_cleanse(&priv); dogecoin_ecc_stop(); return 0; } ``` ```sh gcc example.c .libs/libdogecoin.a \ -I./include/dogecoin -lpthread -levent -levent_core -levent_extra -lm \ -o psbt_example ./psbt_example ``` -------------------------------- ### Install dependencies on Debian/Ubuntu Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Install required dependencies for building libdogecoin on Debian/Ubuntu systems. ```bash sudo apt-get install autoconf automake libtool build-essential libevent-dev ``` -------------------------------- ### Compile example.c with gcc Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Compile the example.c file with gcc, linking the built libdogecoin static library. ```c gcc ./contrib/examples/example.c ./.libs/libdogecoin.a -I./include/dogecoin -L./.libs -ldogecoin -o example ``` -------------------------------- ### C Usage: remove_eckey Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/eckey.md Example C usage of remove_eckey, starting a key, finding it, and removing it from the hash table. ```c int key_id = start_key(false); eckey* key = find_eckey(key_id); remove_eckey(key) ``` -------------------------------- ### GET /getAddresses - curl example and sample response Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves all addresses associated with the wallet. Each line contains one address. ```bash curl http://localhost:/getAddresses ``` ```text address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU ``` -------------------------------- ### Build OP-TEE SDK and Client for QEMU (qemu_v8.xml) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Runs a Docker container to build the OP-TEE SDK (version 4.0.0) and client for ARMv8 QEMU. Replace '4.0.0' with the desired version and 'qemu_v8.xml' with the desired platform. The command installs dependencies, syncs the OP-TEE manifest, patches common.mk, generates RSA keys, signs subkeys, and builds the OS and client. ```sh 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" ``` -------------------------------- ### GET /getBalance - curl example and sample response Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves the total wallet balance. The response is plain text with the balance in Dogecoin. ```bash curl http://localhost:/getBalance ``` ```text Wallet balance: 123.45678900 ``` -------------------------------- ### GET /getUTXOs - curl example and sample response Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves all unspent transaction outputs (UTXOs) associated with the wallet. The response includes each UTXO and the total unspent balance. ```bash curl http://localhost:/getUTXOs ``` ```text ---------------------- Unspent UTXO: txid: b1fea5241c4a1d7d1e6c6d619fbf3bb8b1ec3f1f1d2f4c5b6a7c8d9e0f1a2b3c vout: 1 address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU script_pubkey: 76a9145d6a7f3b4ebbaee4e2d8c10eafbf1ccbc9c0a88ac amount: 75.00000000 confirmations: 100 height: 5123456 spendable: 1 solvable: 1 Total Unspent: 75.00000000 ``` -------------------------------- ### Build and run libdogecoin with GNU Make on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Build and run the libdogecoin sample on Linux using GNU Make with pkg-config. ```bash cd libdogecoin make build make run ``` -------------------------------- ### Guix time-machine error message Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/guix/README.md Example error output when Savannah's git redirect causes a libgit2 bug in some Guix versions, failing before building starts. ```text guix time-machine: error: Git error: cannot redirect from 'git.savannah.gnu.org' to ... ``` -------------------------------- ### Build and run libdogecoin with CMake on Windows Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Build and run the libdogecoin sample on Windows using CMake with Ninja. Requires setting NUGET_PACKAGE_PATH to the Open Enclave prerequisites. ```cmd mkdir build && cd build cmake .. -G Ninja -DNUGET_PACKAGE_PATH=C:\oe_prereqs ninja ninja run ``` -------------------------------- ### GET /getTransactions - curl example and sample response Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Retrieves spent external receipts (non-spendable UTXOs from external senders). Change from the wallet's own outgoing txs is skipped. The response includes each spent UTXO and the total spent balance. ```bash curl http://localhost:/getTransactions ``` ```text ---------------------- txid: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 vout: 0 address: DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L script_pubkey: 76a9144621d6a7f3b4ebbaee4e2d8c10eafbf1ccbc9c0a88ac amount: 50.00000000 confirmations: 100 height: 5123450 spendable: 0 solvable: 1 Spent Balance: 50.00000000 ``` -------------------------------- ### Using dogecoin_psbt_create Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/psbt.md Shows how to create a PSBT from an unsigned transaction, free the original transaction (the PSBT owns its own copy), and handle a NULL return on failure. ```c dogecoin_tx* tx = dogecoin_tx_new(); /* ... add inputs and outputs ... */ dogecoin_psbt* psbt = dogecoin_psbt_create(tx); dogecoin_tx_free(tx); /* PSBT owns its own copy */ if (!psbt) { /* handle error */ } ``` -------------------------------- ### Install LVI mitigation dependencies Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Install LVI mitigation dependencies using the install_lvi_mitigation_bindir script. The script prompts for confirmation and installs to the current directory by default. ```bash ~/openenclave/share/openenclave/samples$ /opt/openenclave/bin/scripts/lvi-mitigation/install_lvi_mitigation_bindir Do you want to install in current directory? [yes/no]: yes ... Installed: /home/yourname/openenclave/share/openenclave/samples/lvi_mitigation_bin ``` -------------------------------- ### Run libdogecoin in simulation mode on Windows Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Run the libdogecoin sample in OE simulation mode on Windows. ```cmd .\host\host .\enclave\enclave.signed --simulate ``` -------------------------------- ### Install dependencies on macOS Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Install command line tools and fix Homebrew permissions on macOS before building. ```bash xcode_select --install sudo chown -R $(whoami) $(brew --prefix)/* ``` -------------------------------- ### Build OP-TEE Libdogecoin Key Manager Enclave (QEMU or NanoPC) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Runs a Docker container to build the enclave for QEMU ARMv8 or NanoPC-T6. It builds libdogecoin twice (host and OP-TEE), compiles the host application and enclave, and creates a disk image at /doge/libdogecoin/optee/out/bin/libdogecoin.img. Uses CFLAGS=-Wp,-D_FORTIFY_SOURCE=0 to disable fortify source checks unsupported by OP-TEE. ```sh 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 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\" \ 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-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\" \ 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" ``` -------------------------------- ### Get balance with dogecoin_sweep_get_balance Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/sweep.md Get the balance from the local wallet DB (requires WITH_WALLET). This is not a chain indexer. ```c uint64_t bal; dogecoin_sweep_get_balance("D…", chain, &bal); ``` -------------------------------- ### Install YubiKey dependencies on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/yubikey.md Install the required packages for YubiKey integration: libykpiv, libykpiv-dev, pcscd, and libpcsclite-dev. ```sh sudo apt-get update sudo apt-get install libykpiv libykpiv-dev pcscd libpcsclite-dev ``` -------------------------------- ### Sample response for GET /getChaintip Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Sample plain-text response from GET /getChaintip showing the latest block height. ```text Chain tip: 3500000 ``` -------------------------------- ### Run QEMU with Docker for OP-TEE Libdogecoin Enclave Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/enclaves.md Launches a QEMU ARMv8 emulator via Docker with USB passthrough for a YubiKey. The -device usb-host flag passes the YubiKey to the VM; replace vendorid and productid with your device's IDs. ```sh 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" ``` -------------------------------- ### Using dogecoin_psbt_new Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/psbt.md Shows how to allocate a new PSBT, populate its fields, and free it with dogecoin_psbt_free. ```c dogecoin_psbt* psbt = dogecoin_psbt_new(); /* ... populate fields ... */ dogecoin_psbt_free(psbt); ``` -------------------------------- ### Sample response for GET /getTimestamp Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Sample plain-text response from GET /getTimestamp showing the node's current date and local time. ```text 2024-10-26 15:30:00 ``` -------------------------------- ### start_key: Create and Add Key Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/eckey.md Creates a new eckey, adds it to the hash table, and returns its assigned index. Indexes start at 1 and increase with each call. ```c int start_key(dogecoin_bool is_testnet) { eckey* key = new_eckey(is_testnet); int index = key->idx; add_eckey(key); return index; } ``` -------------------------------- ### Download Linux build sources (make download-linux) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/depends/README.md Run 'make download-linux' to fetch all sources needed for Linux builds without building them. ```makefile make download-linux ``` -------------------------------- ### Install TSS2 dependencies on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/seal.md Install the userspace TSS2 stack and a TPM (real hardware or an emulator) on Linux. Some distros package Esys headers/libs as libtss2-esys-dev. ```sh # Build dependencies sudo apt-get install -y libtss2-dev pkg-config # Some distros package Esys headers/libs as: # libtss2-esys-dev # For local testing without real hardware sudo apt-get install -y swtpm tpm2-tools ``` -------------------------------- ### Run libdogecoin in simulation mode on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Run the libdogecoin sample in OE simulation mode on Linux. ```bash ./host/host ./enclave/enclave.signed --simulate ``` -------------------------------- ### Sample response for GET /getLastBlockInfo Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Sample plain-text response from GET /getLastBlockInfo showing the last block's size, transaction count, and total transaction size. ```text Block size: 4130 Tx count: 11 Total tx size: 3355 ``` -------------------------------- ### Download Windows build sources (make download-win) Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/depends/README.md Run 'make download-win' to fetch all sources needed for Windows builds without building them. ```makefile make download-win ``` -------------------------------- ### Build full library with autoconf Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/README.md Build the full libdogecoin library including the 'such' and 'sendtx' CLI tools using autoconf. ```bash ./autogen.sh ./configure make ``` -------------------------------- ### Sign a raw transaction with sign_raw_transaction_ex Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction.md Use sign_raw_transaction_ex to sign a single input with a two-step interface. In query mode, pass signedrawtx == NULL to get the required buffer size in *signed_size and return 1. In write mode, allocate at least that many bytes, pass the buffer with *signed_size set to its capacity, and call again; on success it writes the signed hex plus null terminator and returns 1, on failure returns 0. The example shows both stages, including error handling and freeing the allocated buffer. ```c int sign_raw_transaction_ex(int inputindex, const char* incomingrawtx, char* signedrawtx, size_t* signed_size, const char* scripthex, int sighashtype, const char* privkey); ``` ```c // Stage 1: query required size size_t need = 0; if (!sign_raw_transaction_ex(0, rawhex, NULL, &need, scripthex, 1, wif)) { // error } // Stage 2: allocate and sign char *out = malloc(need); if (!out) { /* OOM */ } if (!sign_raw_transaction_ex(0, rawhex, out, &need, scripthex, 1, wif)) { // error } printf("Signed transaction: %s\n", out); free(out); ``` -------------------------------- ### Sample response for GET /getSpends Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/rest.md Sample plain-text response from GET /getSpends showing one outgoing transaction with two outputs: one external (is_mine: 0) and one change (is_mine: 1). ```text ---------------------- txid: a1b2c3d4e5f60718293a4b5c6d7e8f90a1b2c3d4e5f60718293a4b5c6d7e8f90 height: 5123456 total_in: 100.00000000 total_out: 99.99000000 sent: 60.00000000 change: 39.99000000 fee: 0.01000000 output: vout: 0 address: DQe1QeG4FxhEgvfuvGfC7oL5G2G87huuxU amount: 60.00000000 is_mine: 0 output: vout: 1 address: DH1ApGRY3p2Q6S9HpkjJjqg1JpyZ9HMyaR amount: 39.99000000 is_mine: 1 ---------------------- Outgoing transactions: 1 Total Sent (excl. change): 60.00000000 ``` -------------------------------- ### Python entry point for run_full_zk_carrier_demo.py Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/contrib/zk_carrier/scripts/README.md Importable wrapper around the shell script. Use this to run the demo programmatically with the given flags: --testnet, --skip-broadcast, --low 0, --high 1000000, --amount 42000. ```python from contrib.zk_carrier.scripts.run_full_zk_carrier_demo import run_demo run_demo(["--testnet", "--skip-broadcast", "--low", "0", "--high", "1000000", "--amount", "42000"]) ``` -------------------------------- ### Build and run libdogecoin with LVI mitigation using CMake on Windows Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Build and run the libdogecoin sample on Windows with LVI mitigation using CMake and Ninja. Requires NUGET_PACKAGE_PATH and the LVI mitigation flag. ```bash mkdir build && cd build cmake .. -G Ninja -DNUGET_PACKAGE_PATH=C:\oe_prereqs -DLVI_MITIGATION=ControlFlow ninja ninja run ``` -------------------------------- ### getAddrFromScriptPubKey Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction.md Gets an address from a scriptPubKey. ```APIDOC ## getAddrFromScriptPubKey ### Description Gets an address from a scriptPubKey. ### Method N/A (C function) ### Endpoint N/A ### Parameters No parameters documented. ### Request Example N/A ### Response #### Success Response - **address** (string) - The address. #### Response Example N/A ``` -------------------------------- ### Build and run libdogecoin with LVI mitigation using GNU Make on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Build and run the libdogecoin sample on Linux with LVI mitigation using GNU Make. Requires the LVI mitigation bindir installed by the script. ```bash make LVI_MITIGATION=ControlFlow \ LVI_MITIGATION_BINDIR=/home/yourname/openenclave/share/openenclave/samples/lvi_mitigation_bin \ build make run ``` -------------------------------- ### get_raw_transaction Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction.md Gets the raw transaction. ```APIDOC ## get_raw_transaction ### Description Gets the raw transaction. ### Method N/A (C function) ### Endpoint N/A ### Parameters No parameters documented. ### Request Example N/A ### Response #### Success Response - **raw_transaction** (string) - The raw transaction in hex format. #### Response Example N/A ``` -------------------------------- ### Build and run libdogecoin with CMake on Linux Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/src/openenclave/README.md Build and run the libdogecoin sample on Linux using CMake. Requires the Open Enclave SDK and its CMake package. ```bash cd libdogecoin mkdir build && cd build cmake .. make run ``` -------------------------------- ### dogecoin_smpv_get_stats() Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Gets mempool statistics. ```APIDOC ## dogecoin_smpv_get_stats() ### Description Gets mempool statistics. ### Function Signature ```c void dogecoin_smpv_get_stats( const dogecoin_smpv_client* client, uint32_t* total_txs, uint32_t* watched_addresses ); ``` ### Parameters - `client` (const dogecoin_smpv_client*) - Required - SMPV client - `total_txs` (uint32_t*) - Required - Output parameter for total transactions - `watched_addresses` (uint32_t*) - Required - Output parameter for watched addresses ``` -------------------------------- ### Generate keys and compressed pubkeys with such Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction_extended.md Generate a private key and two compressed public keys on testnet using the `such` CLI. Replace `` and `` with the WIFs from the generated private key. ```bash ./such -c generate_private_key -t ./such -c generate_public_key -p -t ./such -c generate_public_key -p -t ``` -------------------------------- ### dogecoin_smpv_get_tx() Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/smpv.md Gets a transaction by its ID. ```APIDOC ## dogecoin_smpv_get_tx() ### Description Gets a transaction by its ID. ### Function Signature ```c dogecoin_smpv_tx* dogecoin_smpv_get_tx(const dogecoin_smpv_client* client, const char* txid); ``` ### Parameters - `client` (const dogecoin_smpv_client*) - Required - SMPV client - `txid` (const char*) - Required - Transaction ID ### Returns - Pointer to transaction ``` -------------------------------- ### Using dogecoin_psbt_free Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/psbt.md Shows how to free a PSBT with dogecoin_psbt_free. ```c dogecoin_psbt_free(psbt); ``` -------------------------------- ### start_transaction Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/transaction.md Starts a new transaction. ```APIDOC ## start_transaction ### Description Starts a new transaction. ### Method N/A (C function) ### Endpoint N/A ### Parameters No parameters documented. ### Request Example N/A ### Response #### Success Response - **result** (int) - Status code indicating success or failure. #### Response Example N/A ``` -------------------------------- ### Build and run tests with make check Source: https://github.com/dogecoinfoundation/libdogecoin/blob/0.1.5-dev/doc/getting_started.md Build the library and run basic unit tests. When compiling with net enabled, this may appear to hang for a couple of seconds after test_tool(), but it is running. ```sh make check ```