Skip to content

Commit

Permalink
Update eth-demls.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsesfv committed Oct 18, 2024
1 parent ce1728e commit 8c8aeca
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions vac/raw/eth-demls.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ allowing the dynamic management of group membership.

### SIWE Message Structure

```
```text
STRUCTURE SIWEMessage:
domain: STRING # The domain requesting the signing
address: ADDRESS # The user's Ethereum address
Expand All @@ -1053,7 +1053,7 @@ STRUCTURE SIWEMessage:

This contract handles authentication, group management, and session management

```
```text
CLASS EthereumStyleAuthWithTimeWindow:
# State variables
groupMembers: MAP<ADDRESS, BOOLEAN> # Stores group membership status
Expand All @@ -1062,7 +1062,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
sessions: MAP<ADDRESS, MAP<BYTES32, INTEGER>> # Stores session expiration times
sessionHashes: MAP<ADDRESS, MAP<BYTES32, STRING>> # Maps session IDs to IPFS hashes
```

Check failure on line 1064 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1064 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1064 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1064 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
```
```text

Check failure on line 1065 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1065 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1065 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1065 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
# State variables for failed attempt tracking
failedAttempts: MAP<ADDRESS, INTEGER>
lastFailedAttemptTime: MAP<ADDRESS, TIMESTAMP>
Expand All @@ -1076,7 +1076,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
CONSTANT MAX_FAILED_ATTEMPTS = 5
CONSTANT LOCKOUT_DURATION = 15 minutes
```

Check failure on line 1078 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1078 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1078 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1078 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
```
```text

Check failure on line 1079 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1079 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1079 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1079 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
# Constructor: Initializes the contract state
CONSTRUCTOR():
groupMembers = EMPTY_MAP()
Expand All @@ -1086,7 +1086,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
allowedPurposes["Authenticate to create session"] = TRUE
EMIT GroupMemberAdded(admin)
```

Check failure on line 1088 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1088 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1088 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1088 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
```
```text

Check failure on line 1089 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1089 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1089 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1089 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
# Adds a new member to the group (admin only)
FUNCTION addGroupMember(memberAddress: ADDRESS):
REQUIRE(TRANSACTION_SENDER() == admin, "Only admin can perform this action")
Expand All @@ -1095,7 +1095,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
groupMembers[memberAddress] = TRUE
EMIT GroupMemberAdded(memberAddress)
```

Check failure on line 1097 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1097 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1097 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1097 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
```
```text

Check failure on line 1098 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1098 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1098 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1098 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
# Removes a member from the group (admin only)
FUNCTION removeGroupMember(memberAddress: ADDRESS):
REQUIRE(TRANSACTION_SENDER() == admin, "Only admin can perform this action")
Expand All @@ -1105,7 +1105,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
groupMembers[memberAddress] = FALSE
EMIT GroupMemberRemoved(memberAddress)
```

Check failure on line 1107 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1107 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1107 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1107 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
```
```text

Check failure on line 1108 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1108 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md

Check failure on line 1108 in vac/raw/eth-demls.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

vac/raw/eth-demls.md:1108 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```text"] https://github.com/DavidAnson/markdownlint/blob/v0.33.0/doc/md031.md
# Transfers admin rights to a new address
FUNCTION transferAdmin(newAdminAddress: ADDRESS):
REQUIRE(TRANSACTION_SENDER() == admin, "Only current admin can transfer admin rights")
Expand All @@ -1114,7 +1114,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
EMIT AdminTransferred(admin, newAdminAddress)
admin = newAdminAddress
```
```
```text
# Authenticates a user based on their SIWE message and signature
FUNCTION authenticate(
domain: STRING,
Expand Down Expand Up @@ -1190,14 +1190,14 @@ CLASS EthereumStyleAuthWithTimeWindow:
EMIT AuthenticationSuccessful(signer, purpose)
RETURN TRUE
```
```
```text
# Helper function to record failed authentication attempts
FUNCTION recordFailedAttempt(signer: ADDRESS, currentTime: TIMESTAMP, reason: STRING):
failedAttempts[signer] = failedAttempts[signer] + 1
lastFailedAttemptTime[signer] = currentTime
EMIT AuthenticationFailed(signer, reason)
```
```
```text
# Helper function to verify the purpose
FUNCTION verifyPurpose(purpose: STRING) RETURNS (BOOLEAN):
# Implement logic to verify that the purpose is valid and expected
Expand All @@ -1207,7 +1207,7 @@ CLASS EthereumStyleAuthWithTimeWindow:

### Session management functions

```
```text
# Creates a new session for an authenticated user
FUNCTION createSession(sessionId: BYTES32, expirationBlock: INTEGER, ipfsHash: STRING):
REQUIRE(groupMembers[TRANSACTION_SENDER()] == TRUE, "Not a group member")
Expand All @@ -1218,7 +1218,7 @@ CLASS EthereumStyleAuthWithTimeWindow:
sessionHashes[TRANSACTION_SENDER()][sessionId] = ipfsHash
EMIT SessionCreated(TRANSACTION_SENDER(), sessionId, expirationBlock)
```
```
```text
# Retrieves the IPFS hash for a given session ID
FUNCTION getSessionHash(sessionId: BYTES32) VIEW RETURNS (STRING):
expirationBlock = sessions[TRANSACTION_SENDER()][sessionId]
Expand All @@ -1227,23 +1227,23 @@ CLASS EthereumStyleAuthWithTimeWindow:
RETURN sessionHashes[TRANSACTION_SENDER()][sessionId]
```
```
```text
# Extends the expiration time of an existing session
FUNCTION extendSession(sessionId: BYTES32, newExpirationBlock: INTEGER):
REQUIRE(sessions[TRANSACTION_SENDER()][sessionId] != NULL, "Session does not exist")
REQUIRE(newExpirationBlock > CURRENT_BLOCK_NUMBER(), "New expiration block must be in the future")
sessions[TRANSACTION_SENDER()][sessionId] = newExpirationBlock
EMIT SessionExtended(TRANSACTION_SENDER(), sessionId, newExpirationBlock)
```
```
```text
# Ends a session, removing it from storage
FUNCTION endSession(sessionId: BYTES32):
REQUIRE(sessions[TRANSACTION_SENDER()][sessionId] != NULL, "Session does not exist")
DELETE sessions[TRANSACTION_SENDER()][sessionId]
DELETE sessionHashes[TRANSACTION_SENDER()][sessionId]
EMIT SessionEnded(TRANSACTION_SENDER(), sessionId)
```
```
```text
# Cleans up expired sessions for the calling user
FUNCTION cleanUpExpiredSessions():
FOR EACH sessionId IN sessions[TRANSACTION_SENDER()]:
Expand All @@ -1256,7 +1256,7 @@ CLASS EthereumStyleAuthWithTimeWindow:

### Client side functions

```
```text
# Generates a new SIWE message for authentication
FUNCTION generateSIWEMessage(userAddress: ADDRESS):
domain = "example.com"
Expand All @@ -1268,14 +1268,14 @@ FUNCTION generateSIWEMessage(userAddress: ADDRESS):
RETURN NEW SIWEMessage(
domain, userAddress, uri, chainId, issuedAt, expirationTime, purpose)
```
```
```text
# Signs a SIWE message with the user's private key
FUNCTION signSIWEMessage(message: SIWEMessage, userAddress: ADDRESS):
messageHash = HASH_STRUCTURED_DATA(message)
signature = SIGN_MESSAGE_HASH(messageHash, userAddress)
RETURN signature
```
```
```text
# Main authentication function that calls the smart contract
FUNCTION authenticate():
userAddress = GET_CURRENT_USER_ADDRESS()
Expand All @@ -1299,13 +1299,13 @@ FUNCTION authenticate():
ELSE:
RETURN "Authentication failed"
```
```
```text
# Constants or configuration parameters
AVERAGE_BLOCK_TIME = 12 # in seconds
SESSION_DURATION_IN_SECONDS = 3600 # 1 hour
SESSION_DURATION_IN_BLOCKS = ROUND(SESSION_DURATION_IN_SECONDS / AVERAGE_BLOCK_TIME) # 300 blocks
```
```
```text
# Creates and stores a new session after successful authentication
FUNCTION createAndStoreSession(userAddress: ADDRESS):
sessionData = {
Expand All @@ -1325,7 +1325,7 @@ FUNCTION createAndStoreSession(userAddress: ADDRESS):
STORE_LOCALLY(sessionId)
RETURN sessionId
```
```
```text
# Restores a user's session using the stored session ID
FUNCTION restoreUserSession():
storedSessionId = RETRIEVE_LOCALLY_STORED_SESSION_ID()
Expand All @@ -1341,32 +1341,32 @@ FUNCTION restoreUserSession():
ELSE:
RETURN "No stored session found"
```
```
```text
# Encrypts session data for secure storage
FUNCTION encryptSessionData(sessionData: OBJECT, userPublicKey: PUBLIC_KEY):
encryptedData = ENCRYPT(JSON.stringify(sessionData), userPublicKey)
RETURN encryptedData
```
```
```text
# Decrypts session data retrieved from storage
FUNCTION decryptSessionData(encryptedData: STRING, userPrivateKey: PRIVATE_KEY):
decryptedData = DECRYPT(encryptedData, userPrivateKey)
RETURN JSON.parse(decryptedData)
```
```
```text
# Helper functions which hashes the SIWE message according to EIP-712 standards
FUNCTION HASH_STRUCTURED_DATA(message: SIWEMessage):
RETURN KECCAK256(ENCODED_STRUCTURED_DATA(message))
```
```
```text
# Helper functions which recovers the signer's address from a message hash and signature
FUNCTION RECOVER_SIGNER(messageHash: BYTES32, signature: BYTES):
RETURN ECRECOVER(messageHash, signature)
```

### Events

```
```text
EVENT AuthenticationSuccessful(user: ADDRESS, purpose: STRING)
EVENT GroupMemberAdded(member: ADDRESS)
EVENT GroupMemberRemoved(member: ADDRESS)
Expand Down

0 comments on commit 8c8aeca

Please sign in to comment.