diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..38c59a3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: + - repo: local + hooks: + - id: detect-private-key + name: Detect Private Key + entry: script/detect_private_key.sh + language: script + types: [text] diff --git a/script/detect_private_key.sh b/script/detect_private_key.sh new file mode 100755 index 0000000..2da47a4 --- /dev/null +++ b/script/detect_private_key.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# https://gist.github.com/suhailkakar/1f29265dbe843bfa85227c34ed063e86 +# https://x.com/SuhailKakar/status/1825142639085109397 + +chmod +x script/detect_private_key.sh + +# Define patterns for Ethereum and Solana private keys +ETH_PATTERN="(0x)?[A-Fa-f0-9]{64}" +SOL_PATTERN="^[1-9A-HJ-NP-Za-km-z]{88}$" + +# Check for private keys in staged files +FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|sol|py|sh|txt|json)$') +if [ -z "$FILES" ]; then + exit 0 +fi + +for FILE in $FILES; do + if grep -Eq "$ETH_PATTERN" "$FILE" || grep -Eq "$SOL_PATTERN" "$FILE"; then + echo "Error: Detected a potential private key in $FILE" + exit 1 + fi +done + +exit 0 \ No newline at end of file diff --git a/script/generate_abi.sh b/script/generate_abi.sh new file mode 100755 index 0000000..2e12b81 --- /dev/null +++ b/script/generate_abi.sh @@ -0,0 +1,33 @@ +#!/bin/bash +chmod +x script/generate_abi.sh +if command -v forge > /dev/null; then + echo "forge command has found" +else + curl -L https://foundry.paradigm.xyz | bash + echo "forge command has installed" + source ~/.bashrc + foundryup + echo "forge command has started" +fi + +forge build --force + +if [ ! -d "abi" ]; then + mkdir abi +fi + +if [ ! -d "flattenContracts" ]; then + mkdir flattenContracts +fi + +# Loop through all .sol files in the src directory +for solfile in src/*.sol; do + # Get the base name of the .sol file (without directory and extension) + base=$(basename "$solfile" .sol) + + # Flatten the .sol file and generate the ABI + forge flatten "$solfile" -o "flattenContracts/${base}_flattened.sol" + forge inspect "flattenContracts/${base}_flattened.sol:$base" abi > "abi/${base}.json" +done + +echo "ABI files have generated" \ No newline at end of file