-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add pre-commit hook for detecting private keys in staged files
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |