generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
266 additions
and
64 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
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
"workspaces": { | ||
"packages": [ | ||
"packages/hardhat", | ||
"packages/nextjs" | ||
"packages/nextjs", | ||
"packages/nillion" | ||
] | ||
}, | ||
"scripts": { | ||
|
@@ -28,7 +29,9 @@ | |
"postinstall": "husky install", | ||
"precommit": "lint-staged", | ||
"vercel": "yarn workspace @se-2/nextjs vercel", | ||
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo" | ||
"vercel:yolo": "yarn workspace @se-2/nextjs vercel:yolo", | ||
"nillion": "yarn workspace @se-2/nillion nillion", | ||
"run-local-cluster": "yarn workspace @se-2/nillion run-local-cluster" | ||
}, | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
|
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
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
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
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
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
export const nillionConfig = { | ||
websockets: ["/ip4/127.0.0.1/tcp/55693/ws/p2p/12D3KooWSqDTmdKdJ6AWaVMgUKdLBBVeF6mRo2sLuqbgjjCFEtDK"], | ||
cluster_id: "798d89ce-37f4-4d7d-aab9-ba511ae67ccc", | ||
websockets: [process.env.NEXT_PUBLIC_NILLION_WEBSOCKETS], | ||
cluster_id: process.env.NEXT_PUBLIC_NILLION_CLUSTER_ID, | ||
payments_config: { | ||
rpc_endpoint: "http://localhost:55501", | ||
rpc_endpoint: process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT, | ||
smart_contract_addresses: { | ||
blinding_factors_manager: "a513e6e4b8f2a923d98304ec87f64353c4d5c853", | ||
payments: "5fc8d32690cc91d4c39d9d3abcbd16989f875707", | ||
blinding_factors_manager: process.env.NEXT_PUBLIC_NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS, | ||
payments: process.env.NEXT_PUBLIC_NILLION_PAYMENTS_SC_ADDRESS, | ||
}, | ||
signer: { | ||
wallet: { | ||
chain_id: 31337, | ||
private_key: "df57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e", | ||
// @ts-ignore | ||
chain_id: parseInt(process.env.NEXT_PUBLIC_NILLION_CHAIN_ID || 0), | ||
private_key: process.env.NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
console.log; |
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,16 @@ | ||
export const retrieveSecretCommand = ( | ||
user_key: any, | ||
store_id: any, | ||
secret_name: any, | ||
) => `yarn nillion --user-key ${user_key} \ | ||
--node-key ${process.env.NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_1} \ | ||
-b ${process.env.NEXT_PUBLIC_NILLION_BOOTNODE_MULTIADDRESS} \ | ||
--payments-private-key ${process.env.NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY} \ | ||
--payments-chain-id ${process.env.NEXT_PUBLIC_NILLION_CHAIN_ID} \ | ||
--payments-rpc-endpoint ${process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT} \ | ||
--payments-sc-address ${process.env.NEXT_PUBLIC_NILLION_PAYMENTS_SC_ADDRESS} \ | ||
--blinding-factors-manager-sc-address ${process.env.NEXT_PUBLIC_NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS} \ | ||
retrieve-secret \ | ||
--cluster-id ${process.env.NEXT_PUBLIC_NILLION_CLUSTER_ID} \ | ||
--store-id ${store_id} \ | ||
--secret-id ${secret_name}`; |
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 @@ | ||
.env |
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,160 @@ | ||
#!/usr/bin/env bash | ||
|
||
RUN_LOCAL_CLUSTER="./run-local-cluster" | ||
USER_KEYGEN="./user-keygen" | ||
NODE_KEYGEN="./node-keygen" | ||
|
||
echo $RUN_LOCAL_CLUSTER | ||
# kill any other run-local-cluster processes | ||
pkill -9 -f $RUN_LOCAL_CLUSTER | ||
|
||
for var in RUN_LOCAL_CLUSTER USER_KEYGEN NODE_KEYGEN; do | ||
printf "ℹ️ found bin %-18s -> [${!var:?Failed to discover $var}]\n" "$var" | ||
done | ||
|
||
OUTFILE=$(mktemp); | ||
PIDFILE=$(mktemp); | ||
|
||
echo $OUTFILE | ||
|
||
# Create node keys | ||
NODEKEY_FILE_PARTY_1=$(mktemp); | ||
NODEKEY_FILE_PARTY_2=$(mktemp); | ||
NODEKEY_FILE_PARTY_3=$(mktemp); | ||
NODEKEY_FILE_PARTY_4=$(mktemp); | ||
NODEKEY_FILE_PARTY_5=$(mktemp); | ||
|
||
# Crete user keys | ||
USERKEY_FILE_PARTY_1=$(mktemp); | ||
USERKEY_FILE_PARTY_2=$(mktemp); | ||
USERKEY_FILE_PARTY_3=$(mktemp); | ||
USERKEY_FILE_PARTY_4=$(mktemp); | ||
USERKEY_FILE_PARTY_5=$(mktemp); | ||
|
||
"$RUN_LOCAL_CLUSTER" >"$OUTFILE" & echo $! >"$PIDFILE"; | ||
ENV_TO_UPDATE=".env ../nextjs/.env" | ||
echo "--------------------" | ||
echo "Updating your ${ENV_TO_UPDATE} files with run-local-cluster environment info... This may take a minute." | ||
echo "--------------------" | ||
time_limit=160 | ||
while true; do | ||
# Use 'wait' to check if the log file contains the string | ||
if grep "cluster is running, bootnode is at" "$OUTFILE"; then | ||
break | ||
fi | ||
|
||
# If the time limit has been reached, print an error message and exit | ||
if [[ $SECONDS -ge $time_limit ]]; then | ||
echo "Timeout reached while waiting for cluster to be ready in '$OUTFILE'" >&2 | ||
exit 1 | ||
fi | ||
sleep 5 | ||
done | ||
|
||
echo "ℹ️ Cluster has been STARTED (see $OUTFILE)" | ||
cat "$OUTFILE" | ||
|
||
CLUSTER_ID=$(grep "cluster id is" "$OUTFILE" | awk '{print $4}'); | ||
WEBSOCKET=$(grep "websocket:" "$OUTFILE" | awk '{print $2}'); | ||
BOOT_MULTIADDR=$(grep "cluster is running, bootnode is at" "$OUTFILE" | awk '{print $7}'); | ||
PAYMENTS_CONFIG_FILE=$(grep "payments configuration written to" "$OUTFILE" | awk '{print $5}'); | ||
WALLET_KEYS_FILE=$(grep "wallet keys written to" "$OUTFILE" | awk '{print $5}'); | ||
PAYMENTS_RPC=$(grep "blockchain_rpc_endpoint:" "$PAYMENTS_CONFIG_FILE" | awk '{print $2}'); | ||
PAYMENTS_CHAIN=$(grep "chain_id:" "$PAYMENTS_CONFIG_FILE" | awk '{print $2}'); | ||
PAYMENTS_SC_ADDR=$(grep "payments_sc_address:" "$PAYMENTS_CONFIG_FILE" | awk '{print $2}'); | ||
PAYMENTS_BF_ADDR=$(grep "blinding_factors_manager_sc_address:" "$PAYMENTS_CONFIG_FILE" | awk '{print $2}'); | ||
WALLET_PRIVATE_KEY=$(tail -n1 "$WALLET_KEYS_FILE") | ||
|
||
# Generate multiple node keys | ||
"$NODE_KEYGEN" "$NODEKEY_FILE_PARTY_1" | ||
"$NODE_KEYGEN" "$NODEKEY_FILE_PARTY_2" | ||
"$NODE_KEYGEN" "$NODEKEY_FILE_PARTY_3" | ||
"$NODE_KEYGEN" "$NODEKEY_FILE_PARTY_4" | ||
"$NODE_KEYGEN" "$NODEKEY_FILE_PARTY_5" | ||
|
||
# Generate multiple user keys | ||
"$USER_KEYGEN" "$USERKEY_FILE_PARTY_1" | ||
"$USER_KEYGEN" "$USERKEY_FILE_PARTY_2" | ||
"$USER_KEYGEN" "$USERKEY_FILE_PARTY_3" | ||
"$USER_KEYGEN" "$USERKEY_FILE_PARTY_4" | ||
"$USER_KEYGEN" "$USERKEY_FILE_PARTY_5" | ||
|
||
echo "🔑 Node key and user keys have been generated" | ||
|
||
# Function to update or add an environment variable | ||
update_env() { | ||
local key=$1 | ||
local value=$2 | ||
# Skip the first two arguments to get the file paths | ||
local files=("${@:3}") | ||
|
||
for file in "${files[@]}"; do | ||
if [ -f "$file" ]; then # Check if file exists | ||
# Check if the key exists in the file and remove it | ||
if grep -q "^$key=" "$file"; then | ||
# Key exists, remove it | ||
grep -v "^$key=" "$file" > temp.txt && mv temp.txt "$file" | ||
fi | ||
|
||
# Append the new key-value pair to the file | ||
echo "$key=$value" >> "$file" | ||
else | ||
echo "File $file not found. Creating $file" | ||
touch $file | ||
echo "$key=$value" >> "$file" | ||
fi | ||
done | ||
} | ||
|
||
log_file_contents() { | ||
local file_path=$1 # Direct path to the target file | ||
|
||
# Check if the file exists at the path | ||
if [[ ! -f "$file_path" ]]; then | ||
echo "File $file_path does not exist." | ||
return 1 # Exit the function with an error status if the file does not exist | ||
fi | ||
|
||
# If the file exists, cat its contents | ||
cat "$file_path" | ||
} | ||
|
||
# Add environment variables to .env | ||
update_env "NEXT_PUBLIC_NILLION_WEBSOCKETS" "$WEBSOCKET" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_CLUSTER_ID" "$CLUSTER_ID" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT" "$PAYMENTS_RPC" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS" "$PAYMENTS_BF_ADDR" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_PAYMENTS_SC_ADDRESS" "$PAYMENTS_SC_ADDR" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_CHAIN_ID" "$PAYMENTS_CHAIN" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY" "$WALLET_PRIVATE_KEY" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_BOOTNODE_MULTIADDRESS" "$BOOT_MULTIADDR" $ENV_TO_UPDATE | ||
|
||
# Add user key paths and user keys to .env | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_1" "$USERKEY_FILE_PARTY_1" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_1" $(log_file_contents $USERKEY_FILE_PARTY_1) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_2" "$USERKEY_FILE_PARTY_2" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_2" $(log_file_contents $USERKEY_FILE_PARTY_2) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_3" "$USERKEY_FILE_PARTY_3" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_3" $(log_file_contents $USERKEY_FILE_PARTY_3) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_4" "$USERKEY_FILE_PARTY_4" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_4" $(log_file_contents $USERKEY_FILE_PARTY_4) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_5" "$USERKEY_FILE_PARTY_5" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_5" $(log_file_contents $USERKEY_FILE_PARTY_5) $ENV_TO_UPDATE | ||
|
||
# Add node key paths and node keys to .env | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_1" "$NODEKEY_FILE_PARTY_1" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_1" $(log_file_contents $NODEKEY_FILE_PARTY_1) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_2" "$NODEKEY_FILE_PARTY_2" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_2" $(log_file_contents $NODEKEY_FILE_PARTY_2) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_3" "$NODEKEY_FILE_PARTY_3" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_3" $(log_file_contents $NODEKEY_FILE_PARTY_3) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_4" "$NODEKEY_FILE_PARTY_4" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_4" $(log_file_contents $NODEKEY_FILE_PARTY_4) $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_5" "$NODEKEY_FILE_PARTY_5" $ENV_TO_UPDATE | ||
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_5" $(log_file_contents $NODEKEY_FILE_PARTY_5) $ENV_TO_UPDATE | ||
|
||
echo "--------------------" | ||
echo "ℹ️ Updated your $ENV_TO_UPDATE file configurations with variables: websocket, cluster id, keys, blockchain info" | ||
echo "💻 Your Nillion local cluster is still running - process pid: $(pgrep -f $RUN_LOCAL_CLUSTER)" | ||
|
||
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,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
curl -L https://foundry.paradigm.xyz | bash | ||
|
||
FOUNDRY_PATH="$HOME/.foundry/bin" | ||
echo "Add $FOUNDRY_PATH to your PATH to have the foundryup available in your shell." | ||
|
||
# The foundryup command uses its "latest" tag when no args are specified. We | ||
# previously tried to pin the tag to a specific nightly release, but it turns | ||
# out the foundry project deletes those tags periodically. | ||
$FOUNDRY_PATH/foundryup |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.