Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Environment Configuration for Private Web3 SDK
# Copy this file to .env and customize as needed

# VPN Configuration
VPN_SERVER_IP=auto
VPN_PORT=51820
VPN_SUBNET=10.0.0.0/24

# Web3 Development Configuration
WEB3_NETWORK=development
WEB3_BLOCKCHAIN_PORT=8545
WEB3_WEBSOCKET_PORT=8546
WEB3_FRONTEND_PORT=3000

# Nextcloud Configuration (Optional)
NEXTCLOUD_DATADIR=/mnt/web3-sdk-data
NEXTCLOUD_MOUNT=/mnt/
SKIP_DOMAIN_VALIDATION=true
AIO_DISABLE_BACKUP_SECTION=false

# Privacy Settings
USE_CLOUDFLARE_DNS=true
ENABLE_VPN_KILLSWITCH=true
BLOCK_NON_VPN_TRAFFIC=true

# Development Settings
NODE_ENV=development
HARDHAT_NETWORK=development
ENABLE_DEBUG_LOGS=false

# Security Settings
DISABLE_TELEMETRY=true
ENABLE_FIREWALL=true
AUTO_UPDATE_CONTAINERS=false

# Windows Specific (only used in Windows SDK)
WINDOWS_DATA_DIR=C:\web3-sdk-data
WINDOWS_MOUNT_POINT=/run/desktop/mnt/host/c/

# Project Settings
COMPOSE_PROJECT_NAME=web3-private-sdk
DOCKER_NETWORK=web3-private-network
35 changes: 35 additions & 0 deletions .gitignore-web3
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# .gitignore additions for Web3 SDK
# Web3 Development
node_modules/
.env
.env.local
artifacts/
cache/
typechain/
typechain-types/

# VPN Keys (should be generated at runtime)
*.key
*.pub
private-keys/

# Local data directories
web3-sdk-data/
vpn-config/

# Logs
*.log
logs/

# IDE
.vscode/
.idea/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
36 changes: 36 additions & 0 deletions Containers/vpn/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM alpine:3.20

# Install WireGuard and necessary tools for VPN functionality
RUN apk update && apk add --no-cache \
wireguard-tools \
iptables \
iproute2 \
bash \
curl \
openssl \
dnsmasq \
ca-certificates \
supervisor \
&& rm -rf /var/cache/apk/*

# Create VPN directories
RUN mkdir -p /etc/wireguard /var/log/supervisor /opt/vpn-sdk

# Copy configuration files
COPY wg0.conf /etc/wireguard/
COPY entrypoint.sh /opt/vpn-sdk/
COPY supervisord.conf /etc/supervisor/conf.d/
COPY vpn-manager.sh /opt/vpn-sdk/

# Make scripts executable
RUN chmod +x /opt/vpn-sdk/entrypoint.sh /opt/vpn-sdk/vpn-manager.sh

# Expose ports for VPN
EXPOSE 51820/udp 53/udp

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD /opt/vpn-sdk/vpn-manager.sh status || exit 1

ENTRYPOINT ["/opt/vpn-sdk/entrypoint.sh"]
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
30 changes: 30 additions & 0 deletions Containers/vpn/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

echo "Starting VPN container for private Web3 development SDK..."

# Generate WireGuard keys if they don't exist
if [ ! -f /etc/wireguard/privatekey ]; then
echo "Generating WireGuard keys..."
wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey
chmod 600 /etc/wireguard/privatekey
fi

# Set up iptables rules for VPN
echo "Setting up iptables rules..."
iptables -A INPUT -p udp --dport 51820 -j ACCEPT
iptables -A FORWARD -i wg0 -j ACCEPT
iptables -A FORWARD -o wg0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Configure DNS for privacy
echo "nameserver 1.1.1.1" > /etc/resolv.conf
echo "nameserver 1.0.0.1" >> /etc/resolv.conf

echo "VPN container initialized successfully"

# Execute the command
exec "$@"
18 changes: 18 additions & 0 deletions Containers/vpn/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:dnsmasq]
command=dnsmasq --no-daemon --log-facility=-
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/dnsmasq.log
stderr_logfile=/var/log/supervisor/dnsmasq.log

[program:wireguard]
command=/opt/vpn-sdk/vpn-manager.sh start
autostart=true
autorestart=false
stdout_logfile=/var/log/supervisor/wireguard.log
stderr_logfile=/var/log/supervisor/wireguard.log
94 changes: 94 additions & 0 deletions Containers/vpn/vpn-manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

# VPN Manager for Web3 SDK
# Manages WireGuard VPN connection for privacy

VPN_CONFIG="/etc/wireguard/wg0.conf"
VPN_INTERFACE="wg0"

start_vpn() {
echo "Starting VPN interface $VPN_INTERFACE..."
if wg-quick up "$VPN_INTERFACE"; then
echo "VPN started successfully"
return 0
else
echo "Failed to start VPN"
return 1
fi
}

stop_vpn() {
echo "Stopping VPN interface $VPN_INTERFACE..."
if wg-quick down "$VPN_INTERFACE"; then
echo "VPN stopped successfully"
return 0
else
echo "Failed to stop VPN"
return 1
fi
}

status_vpn() {
if wg show "$VPN_INTERFACE" > /dev/null 2>&1; then
echo "VPN is running"
wg show "$VPN_INTERFACE"
return 0
else
echo "VPN is not running"
return 1
fi
}

generate_client_config() {
local client_name="$1"
if [ -z "$client_name" ]; then
echo "Usage: generate_client_config <client_name>"
return 1
fi

echo "Generating client configuration for $client_name..."
# Generate client keys
client_private_key=$(wg genkey)
client_public_key=$(echo "$client_private_key" | wg pubkey)

# Output client configuration
cat > "/tmp/${client_name}-wg.conf" << EOF
[Interface]
PrivateKey = $client_private_key
Address = 10.0.0.2/24
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = $(cat /etc/wireguard/publickey)
Endpoint = \${SERVER_IP}:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
EOF

echo "Client configuration saved to /tmp/${client_name}-wg.conf"
echo "Client public key: $client_public_key"
}

case "$1" in
start)
start_vpn
;;
stop)
stop_vpn
;;
status)
status_vpn
;;
restart)
stop_vpn
sleep 2
start_vpn
;;
generate-client)
generate_client_config "$2"
;;
*)
echo "Usage: $0 {start|stop|status|restart|generate-client <name>}"
exit 1
;;
esac
11 changes: 11 additions & 0 deletions Containers/vpn/wg0.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Interface]
PrivateKey = %PRIVATE_KEY%
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

# Add peers here
# [Peer]
# PublicKey = CLIENT_PUBLIC_KEY
# AllowedIPs = 10.0.0.2/32
66 changes: 66 additions & 0 deletions Containers/web3-dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
FROM node:20-alpine

# Install system dependencies for Web3 development
RUN apk add --no-cache \
git \
python3 \
py3-pip \
build-base \
linux-headers \
libc6-compat \
curl \
bash \
supervisor \
&& rm -rf /var/cache/apk/*

# Install global Web3 development tools
RUN npm install -g \
@truffle/truffle \
@ganache/cli \
hardhat \
@foundry-rs/foundry \
web3 \
ethers \
@openzeppelin/contracts \
solhint \
prettier \
prettier-plugin-solidity

# Install Python Web3 tools
RUN pip3 install \
web3 \
brownie-eth \
eth-ape

# Create workspace directory
RUN mkdir -p /workspace /var/log/supervisor
WORKDIR /workspace

# Copy configuration files
COPY supervisord.conf /etc/supervisor/conf.d/
COPY entrypoint.sh /usr/local/bin/
COPY web3-setup.sh /usr/local/bin/

# Make scripts executable
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/web3-setup.sh

# Create sample Web3 project structure
RUN mkdir -p /workspace/contracts /workspace/scripts /workspace/test /workspace/artifacts

# Copy sample files
COPY sample-contract.sol /workspace/contracts/
COPY hardhat.config.js /workspace/
COPY package.json /workspace/

# Install project dependencies
RUN npm install

# Expose ports
EXPOSE 8545 8546 3000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8545/ || exit 1

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
26 changes: 26 additions & 0 deletions Containers/web3-dev/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

echo "Starting Web3 Development Environment..."

# Initialize project if not already done
if [ ! -f /workspace/.initialized ]; then
echo "Initializing Web3 project..."
/usr/local/bin/web3-setup.sh
touch /workspace/.initialized
fi

# Set up development environment
export HARDHAT_NETWORK="development"
export NODE_ENV="development"

echo "Web3 development environment ready!"
echo "Available tools:"
echo " - Hardhat: npx hardhat"
echo " - Truffle: truffle"
echo " - Ganache: ganache"
echo " - Foundry: forge"
echo " - Web3.js and Ethers.js available"

# Execute the command
exec "$@"
Loading