From c45319babcf43983d5ee06498f533a20981c8d8e Mon Sep 17 00:00:00 2001 From: Mikko Ohtamaa Date: Thu, 18 Jan 2024 18:54:38 +0100 Subject: [PATCH] More docstring --- README.md | 51 ++++++++++++++++++++++---- foundry.toml | 2 + scripts/set-terms-of-service.sh | 14 +++++++ terms_of_service/acceptance_message.py | 10 ++--- 4 files changed, 63 insertions(+), 14 deletions(-) create mode 100755 scripts/set-terms-of-service.sh diff --git a/README.md b/README.md index ad20ad4..4872a74 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Using Foundry. Compile: ```shell +foundry up forge build ``` @@ -123,15 +124,22 @@ Get the hash of the message: ipython ``` +Then type `%cpaste` and copy-paste in: + ```python from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash -print(get_signing_hash(INITIAL_ACCEPTANCE_MESSAGE).hex()) -``` +new_line_escaped_msg = INITIAL_ACCEPTANCE_MESSAGE.replace("\n", "\\n") +print("Paste to your shell:") +print("") +print(f"""export ACCEPTANCE_MESSAGE_HASH={get_signing_hash(INITIAL_ACCEPTANCE_MESSAGE).hex()}""") +print(f"""export ACCEPTANCE_MESSAGE="{new_line_escaped_msg}" """) +```` ```shell -export ACCEPTANCE_MESSAGE_HASH=808318f1c18ddfb861cd9755fe5005e3028f816039dc42a1b52e4f5031b645a4 +export ACCEPTANCE_MESSAGE_HASH= # Copy from above output +export ACCEPTANCE_MESSAGE= # Copy from above output export TERMS_OF_SERVICE_VERSION=1 -export CONTRACT_ADDRESS=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d +export CONTRACT_ADDRESS=0xDCD7C644a6AA72eb2f86781175b18ADc30Aa4f4d # Set your deployed contract ``` Then set the initial version: @@ -141,9 +149,38 @@ cast send \ --private-key $DEPLOY_PRIVATE_KEY \ --rpc-url $JSON_RPC_POLYGON \ $CONTRACT_ADDRESS \ - "updateTermsOfService(uint16,bytes32)" \ - $TERMS_OF_SERVICE_VERSION \ - $ACCEPTANCE_MESSAGE_HASH + "updateTermsOfService(uint16,bytes32,string)" \ + "$TERMS_OF_SERVICE_VERSION" \ + "$ACCEPTANCE_MESSAGE_HASH" \ + "$ACCEPTANCE_MESSAGE" +``` + +You can also run the above command using [scripts/set-terms-of-service.sh](./scripts/set-terms-of-service.sh). +The script will complain if you have some variables unset. + +## Updating terms of service version + +With `ipython`: + +```python +from terms_of_service.acceptance_message import INITIAL_ACCEPTANCE_MESSAGE, get_signing_hash + +NEW_ACCEPTANCE_MESSAGE="""Update: December 23th, 2023 + +In our ongoing commitment to adhere to legal regulations, we will restrict IP addresses located in certain jurisdictions from accessing our application’s frontend user interface. These jurisdictions include: United States, United Kingdom, Cuba, Iran, North Korea, Syria and Russia. Thank you for your understanding and ongoing support + +Last Modified: December 23rd, 2023""" + +new_line_escaped_msg = NEW_ACCEPTANCE_MESSAGE.replace("\n", "\\n") +print("Paste to your shell:") +print("") +print(f"""export ACCEPTANCE_MESSAGE_HASH={get_signing_hash(NEW_ACCEPTANCE_MESSAGE).hex()}""") +print(f"""export ACCEPTANCE_MESSAGE="{new_line_escaped_msg}" """) +print(f"""export TERMS_OF_SERVICE_VERSION=2""") +``` + +```shell +scripts/set-terms-of-service.sh ``` ## Deployment diff --git a/foundry.toml b/foundry.toml index 25b918f..1b481bd 100644 --- a/foundry.toml +++ b/foundry.toml @@ -3,4 +3,6 @@ src = "src" out = "out" libs = ["lib"] +solc_version = "0.8.23" + # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/scripts/set-terms-of-service.sh b/scripts/set-terms-of-service.sh new file mode 100755 index 0000000..dea306f --- /dev/null +++ b/scripts/set-terms-of-service.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -x +set -e +set -u + +cast send \ + --private-key $DEPLOY_PRIVATE_KEY \ + --rpc-url $JSON_RPC_POLYGON \ + $CONTRACT_ADDRESS \ + "updateTermsOfService(uint16,bytes32,string)" \ + "$TERMS_OF_SERVICE_VERSION" \ + "$ACCEPTANCE_MESSAGE_HASH" \ + "$ACCEPTANCE_MESSAGE" \ No newline at end of file diff --git a/terms_of_service/acceptance_message.py b/terms_of_service/acceptance_message.py index 2f0f49e..9293d65 100644 --- a/terms_of_service/acceptance_message.py +++ b/terms_of_service/acceptance_message.py @@ -1,5 +1,8 @@ """The default terms of service message that is signed. +- The terms of service itself is not signed as it is too big to fit to small input boxes of the wallet. + Instead, we sign a message that refers to the terms of service. + - Uses EIP-151 - See `EthAccout.sign_message implementation `__. @@ -10,13 +13,6 @@ from eth_account.messages import encode_defunct, _hash_eip191_message from eth_account.signers.local import LocalAccount -DEFAULT_ACCEPTANCE_MESSAGE_TEMPLATE = """ -I read and agree on terms of service (version {version}) to use -smart contract software deployed on a blockchain. - -The terms of service text was published {human_date} at {link}. -The unique identifier hash for this terms of service text was {hash}. -""".strip() INITIAL_ACCEPTANCE_MESSAGE = """ I read and agree on terms of service (version 1) to use