diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9397fe5f..142d8342 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,40 +47,11 @@ jobs: cache: 'npm' cache-dependency-path: '**/package-lock.json' - - name: Download binary artifact - run: | - mkdir -p ${{ env.RUNNER_BIN_DIR }} - CHEQD_NODE_VERSION="$(cut -c2- <<< "$(curl -s "https://api.github.com/repos/cheqd/cheqd-node/tags" | jq -r '.[0].name')")" - wget -c "https://github.com/cheqd/cheqd-node/releases/download/v${CHEQD_NODE_VERSION}/cheqd-noded-${CHEQD_NODE_VERSION}-linux-amd64.tar.gz" - tar -xvf "cheqd-noded-${CHEQD_NODE_VERSION}-linux-amd64.tar.gz" -C ${{ env.RUNNER_BIN_DIR }} - sudo chmod +x ${{ env.RUNNER_BIN_DIR }}/cheqd-noded - - - name: Restore binary permissions - run: sudo chmod +x ${{ env.RUNNER_BIN_DIR }}/cheqd-noded - - - name: Generate localnet configs - working-directory: ./docker/localnet - run: | - bash gen-network-config.sh - sudo chown -R 1000:1000 network-config - - - name: Set up Docker localnet - working-directory: ./docker/localnet - run: | - CHEQD_NODE_VERSION="$(cut -c2- <<< "$(curl -s "https://api.github.com/repos/cheqd/cheqd-node/tags" | jq -r '.[0].name')")" - BUILD_IMAGE="ghcr.io/cheqd/cheqd-node:$CHEQD_NODE_VERSION" - export BUILD_IMAGE - docker compose up --detach - - - name: Import keys - working-directory: ./docker/localnet - run: | - bash import-keys.sh + - name: Start cheqd localnet + run: docker run --rm -d -p 26657:26657 ghcr.io/cheqd/cheqd-testnet:latest - name: "Clean install dependencies" run: npm ci - name: Run Tests - run: | - sleep 1m - npm test + run: npm test diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 0826fbf0..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,55 +0,0 @@ -############################################################### -### STAGE 1: Build node binary pre-requisites ### -############################################################### - -FROM golang:1.18-alpine AS builder - -# Install minimum necessary dependencies -ENV PACKAGES curl make git libc-dev bash gcc linux-headers -RUN apk update && apk add --no-cache $PACKAGES - -# Set working directory for the build -WORKDIR /go/src/github.com/cheqd/cheqd-node - -# Add source files -COPY . . - -# Make node binary -RUN make build - -############################################################### -### STAGE 2: Build cheqd-node image ### -############################################################### - -FROM alpine:3.17 AS runner - -# Install pre-requisites -RUN apk update && apk add --no-cache bash ca-certificates - -# Copy over binaries from the build-env -COPY --from=builder /go/src/github.com/cheqd/cheqd-node/build/cheqd-noded /bin/cheqd-noded - -# Set user directory and details -ARG HOME_DIR="/home/cheqd" -ARG USER="cheqd" -ARG GROUP=${USER} -ARG UID=1000 -ARG GID=${UID} - -# Add cheqd user to use in the container -RUN addgroup --system ${GROUP} --gid ${GID} \ - && adduser ${USER} --uid ${UID} -G ${GROUP} --system --home ${HOME_DIR} --shell /bin/bash - -# Set entrypoint script -COPY --chown=${USER}:${GROUP} docker/entrypoint.sh /bin/node-start -RUN chmod +rx /bin/node-start - -# Set working directory & bash defaults -WORKDIR ${HOME_DIR} -USER ${USER} -SHELL ["/bin/bash", "-euo", "pipefail", "-c"] - -EXPOSE 26656 26657 26660 1317 9090 9091 - -# Set plain vanilla default entrypoint/command -CMD [ "cheqd-noded" ] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100644 index ce591517..00000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Inits node configuration and runs the node. -# e -> exit immediately, u -> treat unset variables as errors and immediately, o -> sets the exit code to the rightmost command -set -euo pipefail - -# within the container, $HOME=/home/cheqd -CHEQD_ROOT_DIR="$HOME/.cheqdnode" - -# Init node config directory -if [ ! -d "${CHEQD_ROOT_DIR}/config" ] -then - echo "Node config not found. Initializing." - cheqd-noded init "moniker-placeholder" -else - echo "Node config exists. Skipping initialization." -fi - -# Check if a genesis file has been passed in config -if [ -f "/genesis" ] -then - echo "Genesis file passed. Adding/replacing current genesis file." - cp /genesis "${CHEQD_ROOT_DIR}/config/genesis.json" -else - echo "No genesis file passed. Skipping and retaining existing genesis." -fi - -# Check if a seeds file has been passed in config -if [ -f "/seeds" ] -then - echo "Seeds file passed. Overriding current seeds." - cp /seeds "${CHEQD_ROOT_DIR}/config/seeds.txt" - CHEQD_NODED_P2P_SEEDS="$(cat "${CHEQD_ROOT_DIR}/config/seeds.txt")" - export CHEQD_NODED_P2P_SEEDS -else - echo "No seeds file passed. Skipping and retaining existing seeds." -fi - -# Check if a node_key file has been passed in config -if [ -f "/node_key" ] -then - echo "Node key file passed. Overriding current key." - cp /node_key "${CHEQD_ROOT_DIR}/config/node_key.json" -else - echo "No node key file passed. Skipping and retaining existing node key." -fi - -# Check if a priv_validator_key file has been passed in config -if [ -f "/priv_validator_key" ] -then - echo "Private validator key file passed. Replacing current key." - cp /priv_validator_key "${CHEQD_ROOT_DIR}/config/priv_validator_key.json" -else - echo "No private validator key file passed. Skipping and retaining existing key." -fi - -# Run node -cheqd-noded start diff --git a/docker/localnet/build-latest.env b/docker/localnet/build-latest.env deleted file mode 100644 index 41744458..00000000 --- a/docker/localnet/build-latest.env +++ /dev/null @@ -1,7 +0,0 @@ -# Environment variables used by Docker Compose - -############################################################### -### REQUIRED: Node/network selection ### -############################################################### -# Define cheqd-noded image source. Change if using your own build. -BUILD_IMAGE="ghcr.io/cheqd/cheqd-node:1.0.4-develop.1" diff --git a/docker/localnet/container-env/observer-0.env b/docker/localnet/container-env/observer-0.env deleted file mode 100644 index 2851f7d7..00000000 --- a/docker/localnet/container-env/observer-0.env +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="observer-0" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/container-env/seed-0.env b/docker/localnet/container-env/seed-0.env deleted file mode 100644 index 856a997a..00000000 --- a/docker/localnet/container-env/seed-0.env +++ /dev/null @@ -1,17 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="seed-0" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" - -# Seed specific -CHEQD_NODED_P2P_SEED_MODE - -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/container-env/validator-0.env b/docker/localnet/container-env/validator-0.env deleted file mode 100644 index 841c2f8c..00000000 --- a/docker/localnet/container-env/validator-0.env +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="validator-0" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/container-env/validator-1.env b/docker/localnet/container-env/validator-1.env deleted file mode 100644 index 6ddd7b14..00000000 --- a/docker/localnet/container-env/validator-1.env +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="validator-1" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/container-env/validator-2.env b/docker/localnet/container-env/validator-2.env deleted file mode 100644 index 392af9f5..00000000 --- a/docker/localnet/container-env/validator-2.env +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="validator-2" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/container-env/validator-3.env b/docker/localnet/container-env/validator-3.env deleted file mode 100644 index 5a9d44be..00000000 --- a/docker/localnet/container-env/validator-3.env +++ /dev/null @@ -1,13 +0,0 @@ -# Environment variables used by the container - -# General -CHEQD_NODED_MONIKER="validator-3" -CHEQD_NODED_RPC_LADDR="tcp://0.0.0.0:26657" -CHEQD_NODED_API_ENABLE="true" -CHEQD_NODED_MINIMUM_GAS_PRICES="25ncheq" -# Consensus -CHEQD_NODED_CONSENSUS_TIMEOUT_PROPOSE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PREVOTE="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_PRECOMMIT="500ms" -CHEQD_NODED_CONSENSUS_TIMEOUT_COMMIT="500ms" -CHEQD_NODED_CREATE_EMPTY_BLOCKS="false" diff --git a/docker/localnet/docker-compose.yml b/docker/localnet/docker-compose.yml deleted file mode 100644 index 17ef4615..00000000 --- a/docker/localnet/docker-compose.yml +++ /dev/null @@ -1,281 +0,0 @@ -version: '3.8' - -services: - validator-0: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 26656 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 26657 # Tendermint RPC port - - target: 1317 - published: 1317 # Cosmos REST API port - - target: 9090 - published: 9090 # gRPC port - - target: 9091 - published: 9091 # gRPC-Gateway port - - target: 26660 - published: 26660 # Prometheus metrics port - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:26657/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - volumes: - - type: volume - source: validator-0-data - target: /home/cheqd - env_file: - - container-env/validator-0.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: validator-0-node-key - target: /node_key - - source: validator-0-priv-val-key - target: /priv_validator_key - - validator-1: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 26756 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 26757 # Tendermint RPC port - - target: 1317 - published: 1417 # Cosmos REST API port - - target: 9090 - published: 9190 # gRPC port - - target: 9091 - published: 9191 # gRPC-Gateway port - - target: 26660 - published: 26760 # Prometheus metrics port - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:26757/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - volumes: - - type: volume - source: validator-1-data - target: /home/cheqd - env_file: - - container-env/validator-1.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: validator-1-node-key - target: /node_key - - source: validator-1-priv-val-key - target: /priv_validator_key - - validator-2: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 26856 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 26857 # Tendermint RPC port - - target: 1317 - published: 1517 # Cosmos REST API port - - target: 9090 - published: 9290 # gRPC port - - target: 9091 - published: 9291 # gRPC-Gateway port - - target: 26660 - published: 26860 # Prometheus metrics port - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:26857/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - volumes: - - type: volume - source: validator-2-data - target: /home/cheqd - env_file: - - container-env/validator-2.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: validator-2-node-key - target: /node_key - - source: validator-2-priv-val-key - target: /priv_validator_key - - validator-3: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 26956 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 26957 # Tendermint RPC port - - target: 1317 - published: 1617 # Cosmos REST API port - - target: 9090 - published: 9390 # gRPC port - - target: 9091 - published: 9391 # gRPC-Gateway port - - target: 26660 - published: 26960 # Prometheus metrics port - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:26957/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - volumes: - - type: volume - source: validator-3-data - target: /home/cheqd - env_file: - - container-env/validator-3.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: validator-3-node-key - target: /node_key - - source: validator-3-priv-val-key - target: /priv_validator_key - - seed-0: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 27056 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 27057 # Tendermint RPC port - - target: 1317 - published: 1717 # Cosmos REST API port - - target: 9090 - published: 9490 # gRPC port - - target: 9091 - published: 9491 # gRPC-Gateway port - - target: 26660 - published: 27060 # Prometheus metrics port - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:27057/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - volumes: - - type: volume - source: seed-0-data - target: /home/cheqd - env_file: - - container-env/seed-0.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: seed-0-node-key - target: /node_key - - source: seed-0-priv-val-key - target: /priv_validator_key - - observer-0: - image: ${BUILD_IMAGE} - ports: - - target: 26656 - published: 27156 # Tendermint peer-to-peer (P2P) port - - target: 26657 - published: 27157 # Tendermint RPC port - - target: 1317 - published: 1817 # Cosmos REST API port - - target: 9090 - published: 9590 # gRPC port - - target: 9091 - published: 9591 # gRPC-Gateway port - - target: 26660 - published: 27160 # Prometheus metrics port - volumes: - - type: volume - source: observer-0-data - target: /home/cheqd - entrypoint: [ "node-start", "--chain-id cheqd" ] - healthcheck: - test: curl -s http://localhost:27157/status | grep -c true - interval: 10s - timeout: 2s - retries: 6 - start_period: 15s - env_file: - - container-env/observer-0.env - configs: - - source: genesis - target: /genesis - - source: seeds - target: /seeds - - source: observer-0-node-key - target: /node_key - - source: observer-0-priv-val-key - target: /priv_validator_key - -configs: - # Genesis and seeds - genesis: - file: network-config/genesis.json - seeds: - file: network-config/seeds.txt - - # Validator 0 - validator-0-node-key: - file: network-config/validator-0/config/node_key.json - validator-0-priv-val-key: - file: network-config/validator-0/config/priv_validator_key.json - - # Validator 1 - validator-1-node-key: - file: network-config/validator-1/config/node_key.json - validator-1-priv-val-key: - file: network-config/validator-1/config/priv_validator_key.json - - # Validator 2 - validator-2-node-key: - file: network-config/validator-2/config/node_key.json - validator-2-priv-val-key: - file: network-config/validator-2/config/priv_validator_key.json - - # Validator 3 - validator-3-node-key: - file: network-config/validator-3/config/node_key.json - validator-3-priv-val-key: - file: network-config/validator-3/config/priv_validator_key.json - - # Seed 0 - seed-0-node-key: - file: network-config/seed-0/config/node_key.json - seed-0-priv-val-key: - file: network-config/seed-0/config/priv_validator_key.json - - # Observer 0 - observer-0-node-key: - file: network-config/observer-0/config/node_key.json - observer-0-priv-val-key: - file: network-config/observer-0/config/priv_validator_key.json - -volumes: - validator-0-data: - validator-1-data: - validator-2-data: - validator-3-data: - seed-0-data: - observer-0-data: diff --git a/docker/localnet/gen-network-config.sh b/docker/localnet/gen-network-config.sh deleted file mode 100644 index f291d56e..00000000 --- a/docker/localnet/gen-network-config.sh +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/bash - -# Generates network configuration for an arbitrary amount of validators, observers, and seeds. - -set -euo pipefail - -# sed in macos requires extra argument -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - SED_EXT='' -elif [[ "$OSTYPE" == "darwin"* ]]; then - SED_EXT='.orig' -fi - -# Params -CHAIN_ID=${1:-"cheqd"} # First parameter, default is "cheqd" - -VALIDATORS_COUNT=${2:-4} # Second parameter, default is 4 -SEEDS_COUNT=${3:-1} # Third parameter, default is 1 -OBSERVERS_COUNT=${4:-1} # Fourth parameter, default is 1 - -function init_node() { - NODE_HOME=$1 - NODE_MONIKER=$2 - - echo "[${NODE_MONIKER}] Initializing" - - cheqd-noded init "${NODE_MONIKER}" --chain-id "${CHAIN_ID}" --home "${NODE_HOME}" 2> /dev/null - cheqd-noded tendermint show-node-id --home "${NODE_HOME}" > "${NODE_HOME}/node_id.txt" - cheqd-noded tendermint show-validator --home "${NODE_HOME}" > "${NODE_HOME}/node_val_pubkey.txt" -} - -function configure_node() { - NODE_HOME=$1 - NODE_MONIKER=$2 - - echo "[${NODE_MONIKER}] Configuring app.toml and config.toml" - - APP_TOML="${NODE_HOME}/config/app.toml" - CONFIG_TOML="${NODE_HOME}/config/config.toml" - - sed -i $SED_EXT 's/minimum-gas-prices = ""/minimum-gas-prices = "25ncheq"/g' "${APP_TOML}" - sed -i $SED_EXT 's/enable = false/enable = true/g' "${APP_TOML}" - - sed -i $SED_EXT 's|laddr = "tcp://127.0.0.1:26657"|laddr = "tcp://0.0.0.0:26657"|g' "${CONFIG_TOML}" - sed -i $SED_EXT 's|addr_book_strict = true|addr_book_strict = false|g' "${CONFIG_TOML}" - - sed -i $SED_EXT 's/timeout_propose = "3s"/timeout_propose = "500ms"/g' "${CONFIG_TOML}" - sed -i $SED_EXT 's/timeout_prevote = "1s"/timeout_prevote = "500ms"/g' "${CONFIG_TOML}" - sed -i $SED_EXT 's/timeout_precommit = "1s"/timeout_precommit = "500ms"/g' "${CONFIG_TOML}" - sed -i $SED_EXT 's/timeout_commit = "5s"/timeout_commit = "500ms"/g' "${CONFIG_TOML}" -} - -function configure_genesis() { - NODE_HOME=$1 - NODE_MONIKER=$2 - - echo "[${NODE_MONIKER}] Configuring genesis" - - GENESIS="${NODE_HOME}/config/genesis.json" - GENESIS_TMP="${NODE_HOME}/config/genesis_tmp.json" - - # Default denom - sed -i $SED_EXT 's/"stake"/"ncheq"/' "${GENESIS}" - - # Short voting period - sed -i $SED_EXT 's/"voting_period": "172800s"/"voting_period": "12s"/' "${GENESIS}" - - # Test accounts - BASE_ACCOUNT_1="cheqd1rnr5jrt4exl0samwj0yegv99jeskl0hsxmcz96" - # Mnemonic: sketch mountain erode window enact net enrich smoke claim kangaroo another visual write meat latin bacon pulp similar forum guilt father state erase bright - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_1}'", "coins": [{"denom": "ncheq", "amount": "100001000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_1}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_ACCOUNT_2="cheqd1l9sq0se0jd3vklyrrtjchx4ua47awug5vsyeeh" - # Mnemonic: ugly dirt sorry girl prepare argue door man that manual glow scout bomb pigeon matter library transfer flower clown cat miss pluck drama dizzy - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_2}'", "coins": [{"denom": "ncheq", "amount": "100001000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_2}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_ACCOUNT_3="cheqd14wymr6h8a0rvynwayytssy5rhn3evltcpxh0zh" - # Mnemonic: fix wheel picnic about army scan table fence device trust alter erupt wear donkey wood slender gold reunion grant quiz absurd tragic reform attitude - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_3}'", "coins": [{"denom": "ncheq", "amount": "100"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_3}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_ACCOUNT_4="cheqd1c8tq9wcfwtunkunng5pe442jlmwns9sgve42mf" - # Mnemonic: horn slim pigeon winner capable piano soul find ignore crawl arrow genuine magnet nasty basic lamp scissors treat stick arm dress elbow trash naive - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_4}'", "coins": [{"denom": "ncheq", "amount": "100001000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_4}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_ACCOUNT_5="cheqd1xnx6fe4fg4etlaxm0ty25j3ae5thhadraskplv" - # Mnemonic: blue town hobby lens hawk deputy father tissue state choose another liquid license start push iron limb visa taste mother cause history tackle fiber - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_5}'", "coins": [{"denom": "ncheq", "amount": "100001000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_5}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_ACCOUNT_6="cheqd1makysw7c788c7fzkfzn7al80wyfl4at6jtjyg4" - # Mnemonic: gallery hospital vicious demand orient piano melody vanish remind pistol elephant bracket olive kitten caution apart capital protect junior endorse run drama tiny patrol - jq '.app_state.bank.balances += [{"address": "'${BASE_ACCOUNT_6}'", "coins": [{"denom": "ncheq", "amount": "100"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.auth.v1beta1.BaseAccount","address": "'${BASE_ACCOUNT_6}'", "pub_key": null,"account_number": "0","sequence": "0"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - BASE_VESTING_ACCOUNT="cheqd1lkqddnapqvz2hujx2trpj7xj6c9hmuq7uhl0md" - # Mnemonic: coach index fence broken very cricket someone casino dial truth fitness stay habit such three jump exotic spawn planet fragile walk enact angry great - # shellcheck disable=SC2089 - BASE_VESTING_COIN="{\"denom\":\"ncheq\",\"amount\":\"10001000000000000\"}" - jq '.app_state.bank.balances += [{"address": "'${BASE_VESTING_ACCOUNT}'", "coins": [{"denom": "ncheq", "amount": "5000000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.vesting.v1beta1.BaseVestingAccount", "base_account": {"address": "'${BASE_VESTING_ACCOUNT}'","pub_key": null,"account_number": "0","sequence": "0"}, "original_vesting": ['"${BASE_VESTING_COIN}"'], "delegated_free": [], "delegated_vesting": [], "end_time": "1672531199"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - CONTINUOUS_VESTING_ACCOUNT="cheqd1353p46macvn444rupg2jstmx3tmz657yt9gl4l" - # Mnemonic: phone worry flame safe panther dirt picture pepper purchase tiny search theme issue genre orange merit stove spoil surface color garment mind chuckle image - jq '.app_state.bank.balances += [{"address": "'${CONTINUOUS_VESTING_ACCOUNT}'", "coins": [{"denom": "ncheq", "amount": "5000000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.vesting.v1beta1.ContinuousVestingAccount", "base_vesting_account": { "base_account": {"address": "'${CONTINUOUS_VESTING_ACCOUNT}'","pub_key": null,"account_number": "0","sequence": "0"}, "original_vesting": ['"${BASE_VESTING_COIN}"'], "delegated_free": [], "delegated_vesting": [], "end_time": "1672531199"}, "start_time": "1630352459"}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - DELAYED_VESTING_ACCOUNT="cheqd1njwu33lek5jt4kzlmljkp366ny4qpqusahpyrj" - # Mnemonic: pilot text keen deal economy donkey use artist divide foster walk pink breeze proud dish brown icon shaft infant level labor lift will tomorrow - jq '.app_state.bank.balances += [{"address": "'${DELAYED_VESTING_ACCOUNT}'", "coins": [{"denom": "ncheq", "amount": "5000000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.vesting.v1beta1.DelayedVestingAccount", "base_vesting_account": { "base_account": {"address": "'${DELAYED_VESTING_ACCOUNT}'","pub_key": null,"account_number": "0","sequence": "0"}, "original_vesting": ['"${BASE_VESTING_COIN}"'], "delegated_free": [], "delegated_vesting": [], "end_time": "1672531199"}}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - - PERIODIC_VESTING_ACCOUNT="cheqd1uyngr0l3xtyj07js9sdew9mk50tqeq8lghhcfr" - # Mnemonic: want merge flame plate trouble moral submit wing whale sick meat lonely yellow lens enable oyster slight health vast weird radar mesh grab olive - jq '.app_state.bank.balances += [{"address": "'${PERIODIC_VESTING_ACCOUNT}'", "coins": [{"denom": "ncheq", "amount": "5000000000000000"}] }]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" - jq '.app_state.auth.accounts += [{"@type": "/cosmos.vesting.v1beta1.PeriodicVestingAccount", "base_vesting_account": { "base_account": {"address": "'${PERIODIC_VESTING_ACCOUNT}'","pub_key": null,"account_number": "0","sequence": "0"}, "original_vesting": ['"${BASE_VESTING_COIN}"'], "delegated_free": [], "delegated_vesting": [], "end_time": "1672531199"}, "start_time": "1672531179", "vesting_periods": [{"length": "20", "amount": ['"${BASE_VESTING_COIN}"']}]}]' "$GENESIS" > "$GENESIS_TMP" && \ - mv "${GENESIS_TMP}" "${GENESIS}" -} - - -NETWORK_CONFIG_DIR="network-config" -rm -rf $NETWORK_CONFIG_DIR -mkdir $NETWORK_CONFIG_DIR - - -# Generating node configurations -for ((i=0 ; i "${NETWORK_CONFIG_DIR}/seeds.txt" - -# We don't need the tmp node anymore -rm -rf "${TMP_NODE_HOME}" diff --git a/docker/localnet/import-keys.sh b/docker/localnet/import-keys.sh deleted file mode 100644 index 80c84e4a..00000000 --- a/docker/localnet/import-keys.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -euox pipefail - -KEYRING_BACKEND="test" - -function import_key() { - ALIAS=${1} - MNEMONIC=${2} - - echo "Importing key: ${ALIAS}" - - if cheqd-noded keys show "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} - then - echo "Key ${ALIAS} already exists" - return 0 - fi - - echo "${MNEMONIC}" | cheqd-noded keys add "${ALIAS}" --keyring-backend ${KEYRING_BACKEND} --recover -} - -import_key "base_account_1" "sketch mountain erode window enact net enrich smoke claim kangaroo another visual write meat latin bacon pulp similar forum guilt father state erase bright" -import_key "base_account_2" "ugly dirt sorry girl prepare argue door man that manual glow scout bomb pigeon matter library transfer flower clown cat miss pluck drama dizzy" -import_key "base_account_3" "fix wheel picnic about army scan table fence device trust alter erupt wear donkey wood slender gold reunion grant quiz absurd tragic reform attitude" -import_key "base_account_4" "horn slim pigeon winner capable piano soul find ignore crawl arrow genuine magnet nasty basic lamp scissors treat stick arm dress elbow trash naive" -import_key "base_account_5" "blue town hobby lens hawk deputy father tissue state choose another liquid license start push iron limb visa taste mother cause history tackle fiber" -import_key "base_account_6" "gallery hospital vicious demand orient piano melody vanish remind pistol elephant bracket olive kitten caution apart capital protect junior endorse run drama tiny patrol" -import_key "base_vesting_account" "coach index fence broken very cricket someone casino dial truth fitness stay habit such three jump exotic spawn planet fragile walk enact angry great" -import_key "continuous_vesting_account" "phone worry flame safe panther dirt picture pepper purchase tiny search theme issue genre orange merit stove spoil surface color garment mind chuckle image" -import_key "delayed_vesting_account" "pilot text keen deal economy donkey use artist divide foster walk pink breeze proud dish brown icon shaft infant level labor lift will tomorrow" -import_key "periodic_vesting_account" "want merge flame plate trouble moral submit wing whale sick meat lonely yellow lens enable oyster slight health vast weird radar mesh grab olive" diff --git a/src/utils.ts b/src/utils.ts index a4e2828e..f77d3b9f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -25,12 +25,17 @@ import { generateKeyPairFromSeed, KeyPair } from '@stablelib/ed25519' -import { sha256 } from '@cosmjs/crypto' +import { DirectSecp256k1HdWallet, DirectSecp256k1Wallet } from '@cosmjs/proto-signing' +import { EnglishMnemonic as _, sha256 } from '@cosmjs/crypto' import { v4 } from 'uuid' import { VerificationMethod as ProtoVerificationMethod, Service as ProtoService, + MsgCreateDidDocPayload, + MsgDeactivateDidDocPayload, } from "@cheqd/ts-proto/cheqd/did/v2" +import { MsgCreateResourcePayload } from "@cheqd/ts-proto/cheqd/resource/v2" +import { DIDModule } from "./modules/did" export type TImportableEd25519Key = { publicKeyHex: string @@ -45,6 +50,10 @@ export function isEqualKeyValuePair(kv1: IKeyValuePair[], kv2: IKeyValuePair[]): return kv1.every((item, index) => item.key === kv2[index].key && item.value === kv2[index].value) } +export class EnglishMnemonic extends _ { + public static readonly _mnemonicMatcher = /^[a-z]+( [a-z]+)*$/ +} + export function createSignInputsFromImportableEd25519Key(key: TImportableEd25519Key, verificationMethod: VerificationMethod[]): ISignInputs { if (verificationMethod?.length === 0) throw new Error('No verification methods provided') @@ -236,6 +245,12 @@ export function validateSpecCompliantPayload(didDocument: DIDDocument): SpecVali return { valid: true, protobufVerificationMethod: protoVerificationMethod, protobufService: protoService } } +export function createCosmosPayerWallet(cosmosPayerSeed: string) : Promise { + return EnglishMnemonic._mnemonicMatcher.test(cosmosPayerSeed) + ? DirectSecp256k1HdWallet.fromMnemonic(cosmosPayerSeed, { prefix: 'cheqd' }) + : DirectSecp256k1Wallet.fromKey(fromString(cosmosPayerSeed.replace(/^0x/, ''), 'hex'), 'cheqd') +} + function toMultibaseRaw(key: Uint8Array) { const multibase = new Uint8Array(MULTICODEC_ED25519_HEADER.length + key.length); @@ -244,3 +259,40 @@ function toMultibaseRaw(key: Uint8Array) { return bases['base58btc'].encode(multibase); } + +export async function createMsgCreateDidDocPayloadToSign(didPayload: DIDDocument, versionId: string) { + const { protobufVerificationMethod, protobufService } = await DIDModule.validateSpecCompliantPayload(didPayload) + return MsgCreateDidDocPayload.encode( + MsgCreateDidDocPayload.fromPartial({ + context: didPayload?.['@context'], + id: didPayload.id, + controller: didPayload.controller, + verificationMethod: protobufVerificationMethod, + authentication: didPayload.authentication, + assertionMethod: didPayload.assertionMethod, + capabilityInvocation: didPayload.capabilityInvocation, + capabilityDelegation: didPayload.capabilityDelegation, + keyAgreement: didPayload.keyAgreement, + service: protobufService, + alsoKnownAs: didPayload.alsoKnownAs, + versionId, + }) + ).finish() +} + +export const createMsgUpdateDidDocPayloadToSign = createMsgCreateDidDocPayloadToSign + +export function createMsgDeactivateDidDocPayloadToSign(didPayload: DIDDocument, versionId?: string) { + return MsgDeactivateDidDocPayload.encode( + MsgDeactivateDidDocPayload.fromPartial({ + id: didPayload.id, + versionId, + }) + ).finish() +} + +export function createMsgResourcePayloadToSign(payload: Partial | MsgCreateResourcePayload) { + return MsgCreateResourcePayload.encode( + MsgCreateResourcePayload.fromPartial(payload) + ).finish() +} \ No newline at end of file