Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add token as query param #1666

Merged
merged 2 commits into from
Nov 27, 2023
Merged

add token as query param #1666

merged 2 commits into from
Nov 27, 2023

Conversation

zkokelj
Copy link
Contributor

@zkokelj zkokelj commented Nov 27, 2023

Why this change is needed

With introduction of encryptionToken it doesn't make sense to have u as query parameter.
We decided to add token as an option in query parameters and keep u for now to prevent things from breaking.
We will deprecate u in the future.

What changes were made as part of this PR

  • changed function that parses userID (encryptionToken)
  • replace ?u= with ?token=
  • rename a few things from Obscuro to Ten

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

@zkokelj zkokelj marked this pull request as ready for review November 27, 2023 08:54
Copy link

coderabbitai bot commented Nov 27, 2023

Walkthrough

The changes across the codebase reflect a significant rebranding effort, shifting from "Obscuro" to "Ten" as the primary identifier. This includes updates to chain IDs, variable names, function calls, and URL parameters. A notable shift is the replacement of user IDs with encryption tokens for authentication purposes. The updates are consistent and thorough, affecting test configurations, library functions, network setups, and documentation to align with the new naming convention and authentication strategy.

Changes

File Path Change Summary
design/ux/Ten_Gateway.md Renamed project from "OG" to "TG", updated user ID references to encryption tokens, and modified endpoint URLs.
integration/.../constants.go Updated constants to reflect the new "Ten" naming convention and changed ObscuroChainID to TenChainID.
integration/.../contract_deployer_test.go Updated ChainID references from ObscuroChainID to TenChainID.
integration/.../faucet_test.go Updated ChainID references and changed function parameters to use TenChainID.
integration/.../connection_test.go Replaced NewObscuroGatewayLibrary with NewTenGatewayLibrary.
integration/.../setup_actions.go Updated wallet generation to use TenChainID.
integration/.../env/testnet.go Updated testnetConnector to use TenChainID.
integration/.../userwallet/userwallet.go Changed default chainID to TenChainID in NewUserWallet and ChainID functions.
integration/.../gateway_user.go Renamed ogClient to tgClient and updated query parameters from "u" to "token".
integration/.../tengateway_test.go Comprehensive renaming from "obscurogateway" to "tengateway" and updated chain IDs.
integration/.../obscuroscan_test.go Updated test setup and configuration to reflect the "Tenscan" naming and TenChainID.
integration/.../devnetwork/... Updated various configurations and functions to use TenChainID.
integration/.../simulation/... Updated simulation tests and network configurations to use TenChainID.
tools/gateway-js/gateway-lib/gateway.js Updated authentication URL and methods to use "token" instead of "u".
tools/walletextension/README.md Updated HTTP endpoints to expect "token" query parameter instead of "u".
tools/walletextension/api/staticOG/javascript.js Changed URL parameters from "u" to "token" for user authentication functions.
tools/walletextension/api/utils.go Modified getUserID function to prioritize "token" parameter over "u".
tools/walletextension/common/constants.go Added EncryptedTokenQueryParameter and removed several constants.
tools/walletextension/lib/client_lib.go Renamed library from OGLib to TGLib and updated associated functions and URLs.
tools/walletextension/test/utils.go Updated URL construction in makeHTTPEthJSONReqWithUserID to use "token".

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 28

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 378aec6 and 53867de.
Files selected for processing (25)
  • design/ux/Ten_Gateway.md (12 hunks)
  • integration/constants.go (1 hunks)
  • integration/contractdeployer/contract_deployer_test.go (5 hunks)
  • integration/faucet/faucet_test.go (3 hunks)
  • integration/manualtests/connection_test.go (1 hunks)
  • integration/networktest/actions/setup_actions.go (1 hunks)
  • integration/networktest/env/testnet.go (1 hunks)
  • integration/networktest/userwallet/userwallet.go (2 hunks)
  • integration/obscurogateway/gateway_user.go (2 hunks)
  • integration/obscurogateway/tengateway_test.go (16 hunks)
  • integration/obscuroscan/obscuroscan_test.go (3 hunks)
  • integration/simulation/devnetwork/config.go (2 hunks)
  • integration/simulation/devnetwork/dev_network.go (1 hunks)
  • integration/simulation/devnetwork/node.go (2 hunks)
  • integration/simulation/network/network_utils.go (1 hunks)
  • integration/simulation/simulation_full_network_test.go (1 hunks)
  • integration/simulation/simulation_geth_in_mem_test.go (1 hunks)
  • integration/simulation/simulation_in_mem_test.go (1 hunks)
  • tools/gateway-js/gateway-lib/gateway.js (2 hunks)
  • tools/walletextension/README.md (1 hunks)
  • tools/walletextension/api/staticOG/javascript.js (4 hunks)
  • tools/walletextension/api/utils.go (1 hunks)
  • tools/walletextension/common/constants.go (1 hunks)
  • tools/walletextension/lib/client_lib.go (4 hunks)
  • tools/walletextension/test/utils.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/api/staticOG/javascript.js
Additional comments: 56
design/ux/Ten_Gateway.md (2)
  • 306-306: Consider elaborating on the privacy and security implications of allowing other addresses to view certain data.

  • 317-318: Publishing revocations on a ledger is a good practice for transparency and could prevent abuse by the TG operator. Ensure that this mechanism is implemented securely and efficiently.

integration/constants.go (1)
  • 12-35: The renaming of constants from Obscuro to Ten is consistent with the summary and the pull request details. Ensure that all references to these constants throughout the codebase have been updated to reflect the new names.
integration/contractdeployer/contract_deployer_test.go (2)
  • 56-62: The configuration for deploying the Layer2ERC20Contract has been updated to use the TenChainID. Ensure that the ChainID is correctly set in all environments where this test will run.

  • 106-112: The configuration for deploying the Layer2ERC20Contract within the TestFaucetSendsFundsOnlyIfNeeded test has been updated to use the TenChainID. Verify that the ChainID is correctly set in all environments where this test will run.

integration/faucet/faucet_test.go (2)
  • 52-57: The update of the ChainID from integration.ObscuroChainID to integration.TenChainID in the faucet configuration is consistent with the overall changes in the pull request.

  • 69-71: The use of integration.TenChainID in the RandomWallet function call aligns with the changes described in the summary and pull request.

integration/manualtests/connection_test.go (1)
  • 22-28: The WebSocket address ogWSAddress is still using the obscu.ro domain. Verify if this is intentional or if it should be updated to reflect the transition to the Ten chain.
integration/networktest/actions/setup_actions.go (2)
  • 24-24: The update from integration.ObscuroChainID to integration.TenChainID aligns with the overall transition from Obscuro to Ten chain as described in the summary.

  • 22-27: Verify that all instances where integration.ObscuroChainID was used have been updated to integration.TenChainID across the entire codebase to maintain consistency.

integration/networktest/env/testnet.go (2)
  • 52-62: The changes to the testnetConnector struct and methods to support the Ten chain appear to be correct. Ensure that all other parts of the codebase that interact with this struct or its methods are updated accordingly to handle the new chain ID and any other related changes.

  • 64-64: Ensure that the AllocateFaucetFunds method is updated to be consistent with the new Ten chain ID and any other related changes, even though the actual implementation is not shown here.

integration/networktest/userwallet/userwallet.go (2)
  • 70-73: The default chain ID has been updated to TenChainID. Ensure that all relevant parts of the system that depend on the chain ID are aware of this change to avoid any inconsistencies.

  • 84-85: The ChainID function has been updated to return TenChainID. Verify that this change is reflected wherever the ChainID function is used to ensure compatibility with the new chain.

integration/obscurogateway/gateway_user.go (3)
  • 19-19: The change from lib.OGLib to lib.TGLib for the ogClient field in the GatewayUser struct is consistent with the transition from Obscuro to Ten chain. Ensure that all methods and functionalities of lib.TGLib are compatible with the existing code that uses ogClient.

  • 23-23: The initialization of ogClient with lib.NewTenGatewayLibrary aligns with the transition to the Ten chain. Verify that lib.NewTenGatewayLibrary is properly implemented and tested to ensure it works as expected in the context of NewUser.

  • 32-32: The update to append "?token=" + ogClient.UserID() to the server addresses for both HTTP and WebSocket clients is consistent with the new token-based user identification mechanism. Ensure that the server endpoints are expecting this new query parameter and that the UserID method of ogClient is correctly retrieving the user's token.

Also applies to: 36-36

integration/obscurogateway/tengateway_test.go (8)
  • 40-51: The renaming of the test type and related constants appears to be consistent and correctly updated.

  • 40-47: The use of the init function is acknowledged with a directive to suppress lint warnings. Ensure that the use of init is necessary and that the code within it cannot be initialized in a more predictable manner elsewhere.

  • 54-55: The createTenNetwork function is called without error handling in the test function, but it handles errors internally by panicking. Ensure that this behavior is acceptable for the test setup.

  • 540-550: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [529-548]

The createTenNetwork function uses a panic to handle errors during network creation. This is an acceptable way to fail fast in test setup if the environment cannot be established.

  • 106-107: The tenGwContainer.Stop() function is called with error checking using assert.NoError, which is appropriate for test code to ensure graceful shutdown.

  • 482-484: The re-establishment of the websocket connection uses a hardcoded path and query parameter. Verify that this is correct and consider making it configurable if necessary.

  • 525-526: The transferRandomAddr function is marked as unused with nolint: unused. Ensure that this function is indeed used elsewhere in the test suite and that the directive is appropriate.

  • 438-439: The subscribeToEvents function has a nolint:unparam directive. Verify that the function's design is intentionally generic and that the parameters are indeed used in some cases.

integration/obscuroscan/obscuroscan_test.go (12)
  • 206-206: Verify if the obsclient.NewAuthObsClient function has been renamed to align with the Tenscan naming convention and update the test code accordingly.

  • 206-206: The integration.EthereumChainID constant is used here. Verify that this constant is still relevant after the transition to Tenscan and update if necessary.

  • 206-206: The integration.TenChainID constant is correctly used here, reflecting the new chain ID after the transition to Tenscan.

  • 208-209: The AvgBlockDuration is set to 1 * time.Second. Ensure that this value is appropriate for the new Tenscan network's expected block time.

  • 208-209: The MgmtContractLib and ERC20ContractLib are mocked here. Confirm that these mocks are still valid and reflect any new logic or interfaces introduced with the Tenscan transition.

  • 73-77: The issueTransactions function is called with integration.TenChainID, which is correct and reflects the new chain ID after the transition to Tenscan.

  • 73-77: The issueTransactions function is called with genesis.TestnetPrefundedPK. Verify that this private key is still relevant and has the necessary funds in the new Tenscan testnet.

  • 50-57: The configuration for obsScanConfig has been updated with the new server addresses and ports. Confirm that these values are correct for the Tenscan environment.

  • 50-57: The LogPath is set to "sys_out". Ensure that this is the intended log path for the Tenscan environment and update if necessary.

  • 58-58: The serverAddress variable is constructed using the updated obsScanConfig.ServerAddress. Confirm that this address is correct for the Tenscan environment.

  • 58-58: The serverAddress is used to construct URLs for HTTP requests. Verify that the endpoints being called are updated to reflect the new Tenscan naming convention and functionality.

  • 58-58: The endpoint /info/obscuro/ might need to be updated to /info/tenscan/ or a similar endpoint that reflects the new Tenscan naming convention.

integration/simulation/devnetwork/config.go (3)
  • 40-41: The update from ObscuroChainID to TenChainID in the DefaultDevNetwork function aligns with the overall transition from the Obscuro chain to the Ten chain.

  • 74-74: The update from ObscuroChainID to TenChainID in the LiveL1DevNetwork function aligns with the overall transition from the Obscuro chain to the Ten chain.

  • 38-44: The ObscuroConfig struct is still being used despite the transition to the Ten chain. Please verify if this is intentional for backward compatibility or if it should be updated or removed.

integration/simulation/devnetwork/dev_network.go (1)
  • 61-62: The change from ObscuroChainID to TenChainID is consistent with the pull request's intention to transition from using the Obscuro chain to the Ten chain.
integration/simulation/devnetwork/node.go (3)
  • 125-127: The L1StartHash field is still using n.l1Data.ObscuroStartBlock. If this field is meant to represent the starting block for the Ten chain, it should be renamed to reflect the new chain's context.

  • 123-129: The update of ObscuroChainID to integration.TenChainID is consistent with the overall changes in the pull request. Ensure that all references to the Obscuro chain are updated across the entire codebase.

  • 167-173: The update of ObscuroChainID to integration.TenChainID in the createEnclaveContainer function is consistent with the changes in the createHostContainer function and the overall pull request.

integration/simulation/network/network_utils.go (2)
  • 86-86: The change from ObscuroChainID to TenChainID aligns with the overall pull request's goal of transitioning from Obscuro to Ten chain components.

  • 83-89: Ensure that all references to the chain ID throughout the codebase have been updated to use TenChainID instead of ObscuroChainID to maintain consistency.

integration/simulation/simulation_full_network_test.go (1)
  • 23-23: The update of the chain ID in the wallets initialization from integration.ObscuroChainID to integration.TenChainID is consistent with the overall transition from the Obscuro chain to the Ten chain as described in the pull request overview. Ensure that all related configurations and tests are updated accordingly.
integration/simulation/simulation_geth_in_mem_test.go (1)
  • 26-26: The change from integration.ObscuroChainID to integration.TenChainID is consistent with the overall transition from the Obscuro chain to the Ten chain. Ensure that all dependent configurations, network behaviors, and test assertions are updated to align with the new chain ID.
integration/simulation/simulation_in_mem_test.go (1)
  • 21-27: The change from integration.ObscuroChainID to integration.TenChainID is consistent with the overall pull request's goal of transitioning from the Obscuro chain to the Ten chain. Ensure that this change is reflected in all parts of the codebase where the chain ID is relevant.
tools/walletextension/README.md (1)
  • 38-38: The documentation link provided at the top of the README might need to be updated to reflect the new Ten chain documentation if it has changed.
tools/walletextension/common/constants.go (4)
  • 41-41: The addition of EncryptedTokenQueryParameter is consistent with the pull request's transition to using an encryption token for user identification.

  • 38-47: Ensure that the removal of previously used constants does not affect any existing functionality that may still rely on them. Verify that all references to these constants have been removed or updated throughout the codebase.

  • 40-40: Verify whether the presence of the old UserQueryParameter is intentional and ensure it does not conflict with the new EncryptedTokenQueryParameter.

  • 38-47: The renaming of components related to the Obscuro chain to the Ten chain, as mentioned in the pull request summary, is not reflected in this hunk. Ensure that all necessary renamings are consistently applied throughout the codebase.

tools/walletextension/lib/client_lib.go (1)
  • 49-49: The RegisterAccount method uses integration.TenChainID directly. Ensure that this constant is correctly defined in the integration package to match the new Ten chain ID.
tools/walletextension/test/utils.go (1)
  • 126-130: The change from "u" to "token" in the query parameter is consistent with the system-wide update to use an encryption token for user identification. Ensure that all parts of the system that interact with this function are updated to use the new "token" parameter.

Comment on lines 84 to +85
func (s *UserWallet) ChainID() *big.Int {
return big.NewInt(integration.ObscuroChainID)
return big.NewInt(integration.TenChainID)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning the chainID field directly from the ChainID function to avoid creating a new big.Int instance on each call.

func (s *UserWallet) ChainID() *big.Int {
-   return big.NewInt(integration.TenChainID)
+   return s.chainID
}

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func (s *UserWallet) ChainID() *big.Int {
return big.NewInt(integration.ObscuroChainID)
return big.NewInt(integration.TenChainID)
func (s *UserWallet) ChainID() *big.Int {
return s.chainID
}

Comment on lines 38 to 39
It generates and returns userID which needs to be added as a query parameter "u" to the URL in your Metamask
(or another provider) as it identifies you.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description still mentions the old query parameter "u" which is inconsistent with the new changes to use "token". This should be updated to avoid confusion.

- It generates and returns userID which needs to be added as a query parameter "u" to the URL in your Metamask
+ It generates and returns userID which needs to be added as a query parameter "token" to the URL in your Metamask

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
It generates and returns userID which needs to be added as a query parameter "u" to the URL in your Metamask
(or another provider) as it identifies you.
It generates and returns userID which needs to be added as a query parameter "token" to the URL in your Metamask
(or another provider) as it identifies you.

userID, err := getQueryParameter(conn.ReadRequestParams(), common.EncryptedTokenQueryParameter)
if err == nil {
if len(userID) != common.MessageUserIDLen {
return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message construction is redundant. Simplify by removing fmt.Sprintf and directly using fmt.Errorf with formatting directives.

- return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
+ return "", fmt.Errorf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
return "", fmt.Errorf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen)

}

// try getting userID(`u`) from query parameters and return it if successful
userID, err = getQueryParameter(conn.ReadRequestParams(), common.UserQueryParameter)
if err == nil {
if len(userID) != common.MessageUserIDLen {
return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same issue as above. Simplify the error message construction.

- return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
+ return "", fmt.Errorf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return "", fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen))
return "", fmt.Errorf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen)


With this endpoint, you submit a signed message in the format `Register <userID> for <account>`
from that account which proves that you hold private keys for it, and it links that account with your userID.

- `GET /v1/query/address?u=$UserId&a=$Address`
- `GET /v1/query/address?token=$EncryptionToken&a=$Address`

This endpoint responds with a JSON of true or false if the address "a" is already registered for user "u"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The endpoint description incorrectly references the old "u" parameter instead of the new "token" parameter. This should be corrected to match the updated endpoint.

- This endpoint responds with a JSON of true or false if the address "a" is already registered for user "u"
+ This endpoint responds with a JSON of true or false if the address "a" is already registered for user "token"

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
This endpoint responds with a JSON of true or false if the address "a" is already registered for user "u"
This endpoint responds with a JSON of true or false if the address "a" is already registered for user "token"

@@ -44,7 +44,7 @@ class Gateway {
}

try {
const authenticateUserURL = pathAuthenticate+"?u="+this.userId
const authenticateUserURL = pathAuthenticate+"?token="+this.userId
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The authenticateUserURL is missing the base URL (this.httpURL) when concatenated, which will result in an incorrect URL.

- const authenticateUserURL = pathAuthenticate+"?token="+this.userId
+ const authenticateUserURL = `${this.httpURL}${pathAuthenticate}?token=${this.userId}`

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const authenticateUserURL = pathAuthenticate+"?token="+this.userId
const authenticateUserURL = `${this.httpURL}${pathAuthenticate}?token=${this.userId}`

There is a typo in the variable name this.userID should be this.userId.

- const message = `Register ${this.userID} for ${address.toLowerCase()}`;
+ const message = `Register ${this.userId} for ${address.toLowerCase()}`;

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const authenticateUserURL = pathAuthenticate+"?token="+this.userId
const authenticateUserURL = pathAuthenticate+"?token="+this.userId

Comment on lines 1 to 16
# The Ten Gateway - Design

The scope of this document is to design a hosted [Wallet Extension](wallet_extension.md) called the "Ten Gateway" (OG).
The scope of this document is to design a hosted [Wallet Extension](wallet_extension.md) called the "Ten Gateway" (TG).

The OG will be a superset of the WE functionality, so this document will only cover the additions.
The TG will be a superset of the WE functionality, so this document will only cover the additions.

## High level overview

The OG will be a [Confidential Web Service](https://medium.com/p/983a2a67fc08), running inside SGX.
The TG will be a [Confidential Web Service](https://medium.com/p/983a2a67fc08), running inside SGX.

The current WE is designed to be used by a single user holding multiple addresses accross potentially multiple wallets.

The OG must support mutiple users, each with multiple addresses. It can be seen as offering a WE per user.
The TG must support mutiple users, each with multiple addresses. It can be seen as offering a WE per user.

The Ten node has no concept of "User". It only authenticates based on the "blockchain address".
It expects to be supplied with a signed viewing key per address, so that it can respond encrypted with that VK.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [77-77]

The UX diagram filename "og_ux.png" should be updated to match the new project naming convention, such as "tg_ux.png".

@@ -44,7 +44,7 @@
}

try {
const authenticateUserURL = pathAuthenticate+"?u="+this.userId
const authenticateUserURL = pathAuthenticate+"?token="+this.userId
const authenticateFields = {"signature": signature, "message": message}
const authenticateResp = await axios.post(
authenticateUserURL,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The registerAccount function should await the authenticateResp.text() call to return the actual text instead of a promise.

- return await authenticateResp.text()
+ return (await authenticateResp.text())

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
authenticateUserURL,
authenticateUserURL,

Comment on lines 39 to 40
statusCode, userID, err := fasthttp.Get(nil, fmt.Sprintf("%s/v1/join/", o.httpURL))
if err != nil || statusCode != 200 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Join method, the error message construction uses fmt.Sprintf inside another fmt.Errorf, which is redundant. You can directly use fmt.Errorf with formatting directives.

- return fmt.Errorf(fmt.Sprintf("Failed to get userID. Status code: %d, err: %s", statusCode, err))
+ return fmt.Errorf("Failed to get userID. Status code: %d, err: %v", statusCode, err)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
statusCode, userID, err := fasthttp.Get(nil, fmt.Sprintf("%s/v1/join/", o.httpURL))
if err != nil || statusCode != 200 {

@@ -64,7 +64,7 @@
req, err := http.NewRequestWithContext(
context.Background(),
http.MethodPost,
o.httpURL+"/v1/authenticate/?u="+string(o.userID),
o.httpURL+"/v1/authenticate/?token="+string(o.userID),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the RegisterAccount method, the URL construction for the HTTP request is done by concatenating strings. Consider using a URL builder or proper query parameter encoding to avoid potential issues with special characters in the userID.

- o.httpURL+"/v1/authenticate/?token="+string(o.userID)
+ url := fmt.Sprintf("%s/v1/authenticate/", o.httpURL)
+ q := url.Values{}
+ q.Set("token", string(o.userID))
+ urlWithParams := url + "?" + q.Encode()

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
o.httpURL+"/v1/authenticate/?token="+string(o.userID),
url := fmt.Sprintf("%s/v1/authenticate/", o.httpURL)
q := url.Values{}
q.Set("token", string(o.userID))
urlWithParams := url + "?" + q.Encode(),

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 12

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 53867de and 2185d9d.
Files selected for processing (2)
  • integration/obscurogateway/gateway_user.go (3 hunks)
  • integration/obscurogateway/tengateway_test.go (15 hunks)
Additional comments: 1
integration/obscurogateway/gateway_user.go (1)
  • 49-58: The RegisterAccounts method has been correctly updated to use the tgClient.

@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@zkokelj zkokelj force-pushed the ziga/add_token_as_query_param branch from 2185d9d to 007a718 Compare November 27, 2023 10:02
@zkokelj zkokelj force-pushed the ziga/add_token_as_query_param branch from 007a718 to 4cdec6a Compare November 27, 2023 10:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 24

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3af59e7 and 4cdec6a.
Files selected for processing (25)
  • design/ux/Ten_Gateway.md (12 hunks)
  • integration/constants.go (1 hunks)
  • integration/contractdeployer/contract_deployer_test.go (5 hunks)
  • integration/faucet/faucet_test.go (3 hunks)
  • integration/manualtests/connection_test.go (1 hunks)
  • integration/networktest/actions/setup_actions.go (1 hunks)
  • integration/networktest/env/testnet.go (1 hunks)
  • integration/networktest/userwallet/userwallet.go (2 hunks)
  • integration/obscurogateway/gateway_user.go (3 hunks)
  • integration/obscurogateway/tengateway_test.go (15 hunks)
  • integration/obscuroscan/obscuroscan_test.go (3 hunks)
  • integration/simulation/devnetwork/config.go (2 hunks)
  • integration/simulation/devnetwork/dev_network.go (1 hunks)
  • integration/simulation/devnetwork/node.go (2 hunks)
  • integration/simulation/network/network_utils.go (1 hunks)
  • integration/simulation/simulation_full_network_test.go (1 hunks)
  • integration/simulation/simulation_geth_in_mem_test.go (1 hunks)
  • integration/simulation/simulation_in_mem_test.go (1 hunks)
  • tools/gateway-js/gateway-lib/gateway.js (2 hunks)
  • tools/walletextension/README.md (1 hunks)
  • tools/walletextension/api/staticOG/javascript.js (4 hunks)
  • tools/walletextension/api/utils.go (1 hunks)
  • tools/walletextension/common/constants.go (1 hunks)
  • tools/walletextension/lib/client_lib.go (4 hunks)
  • tools/walletextension/test/utils.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • integration/networktest/userwallet/userwallet.go
  • tools/walletextension/api/staticOG/javascript.js
  • tools/walletextension/test/utils.go
Additional comments: 27
integration/constants.go (2)
  • 12-30: The changes to the port offsets and the renaming of the constants are consistent with the rebranding effort and do not appear to introduce any conflicts with existing port offsets. Ensure that all references to these constants throughout the codebase have been updated accordingly.

  • 33-34: The update of the chain ID constant from ObscuroChainID to TenChainID is in line with the rebranding. Verify that this new chain ID does not conflict with any existing chain IDs in use and that all references to the chain ID in the codebase have been updated.

integration/contractdeployer/contract_deployer_test.go (5)
  • 56-62: The update of ChainID from ObscuroChainID to TenChainID in the contract deployment configuration is consistent with the summary and the broader changes in the codebase.

  • 69-71: The wallet and client initialization for the contract deployer now correctly uses integration.TenChainID, aligning with the updated chain ID across the codebase.

  • 88-94: The wallet initialization for the faucet and the contract deployer within the TestFaucetSendsFundsOnlyIfNeeded test function has been updated to use integration.TenChainID, which is consistent with the changes described in the summary.

  • 106-112: The contract deployment configuration within the TestFaucetSendsFundsOnlyIfNeeded test function has been updated to use integration.TenChainID, which is in line with the changes to the chain ID across the codebase.

  • 136-136: The wallets initialization in the createObscuroNetwork function has been updated to use integration.TenChainID instead of integration.ObscuroChainID. This change is consistent with the summary and the broader changes in the codebase.

integration/faucet/faucet_test.go (3)
  • 55-55: The update of ChainID from integration.ObscuroChainID to integration.TenChainID is consistent with the changes described in the summary and pull request.

  • 69-69: The use of integration.TenChainID in the RandomWallet function call aligns with the changes described in the summary and pull request.

  • 91-97: The function createObscuroNetwork still references "Obscuro" in its name and comments, but it now uses integration.TenChainID. Consider renaming the function and updating comments to reflect the new context if the Obscuro network is no longer relevant.

integration/manualtests/connection_test.go (1)
  • 25-25: The change from NewObscuroGatewayLibrary to NewTenGatewayLibrary aligns with the project's rebranding efforts and the pull request description. Ensure that the NewTenGatewayLibrary function provides the same or improved functionality as the previous library.
integration/networktest/actions/setup_actions.go (1)
  • 22-27: The change from integration.ObscuroChainID to integration.TenChainID in the wallet generation process is consistent with the broader rebranding efforts described in the summary. Ensure that integration.TenChainID is correctly defined and that all related functionality works as expected with this new chain ID.
integration/networktest/env/testnet.go (1)
  • 52-62: The changes to the testnetConnector struct and the ChainID method are consistent with the transition from the Obscuro chain to the Ten chain. Ensure that all dependent systems and configurations are updated to accommodate the new chain ID.
integration/obscurogateway/gateway_user.go (2)
  • 19-19: The renaming of ogClient to tgClient in the GatewayUser struct aligns with the rebranding efforts described in the summary.

  • 49-58: The RegisterAccounts function correctly uses the new tgClient variable name for method calls.

integration/simulation/devnetwork/config.go (2)
  • 40-44: The change from integration.ObscuroChainID to integration.TenChainID is consistent with the renaming process and appears to be correctly implemented in the DefaultDevNetwork function.

  • 74-77: The change from integration.ObscuroChainID to integration.TenChainID is consistent with the renaming process and appears to be correctly implemented in the LiveL1DevNetwork function.

integration/simulation/devnetwork/dev_network.go (2)
  • 61-62: The update of the ChainID function to return integration.TenChainID aligns with the rebranding efforts described in the summary. Ensure that all references and dependencies throughout the codebase that rely on the ChainID function are compatible with this change.

  • 59-65: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-68]

While the provided hunk correctly updates the ChainID, it is important to ensure that all comments, print statements, and documentation within the file and the rest of the codebase are updated to reflect the rebranding from Obscuro to Ten.

integration/simulation/devnetwork/node.go (1)
  • 125-126: The change from ObscuroChainID to TenChainID is consistent with the rebranding efforts mentioned in the pull request summary. Ensure that all references to the chain ID throughout the codebase have been updated accordingly.
integration/simulation/network/network_utils.go (1)
  • 85-86: The change from integration.ObscuroChainID to integration.TenChainID in the createInMemObscuroNode function should be carefully reviewed to ensure it aligns with the intended behavior of the system, as it changes the blockchain network context for the node.
integration/simulation/simulation_full_network_test.go (1)
  • 23-23: The change in chain ID from integration.ObscuroChainID to integration.TenChainID should be verified across the entire codebase to ensure consistency and that all references to the old chain ID have been updated.
integration/simulation/simulation_geth_in_mem_test.go (1)
  • 26-26: The change from integration.ObscuroChainID to integration.TenChainID in the NewSimWallets function call is consistent with the rebranding efforts described in the pull request summary. Ensure that TenChainID is correctly defined and used throughout the entire codebase.
integration/simulation/simulation_in_mem_test.go (1)
  • 24-24: The update of the chain ID from integration.ObscuroChainID to integration.TenChainID in the wallets initialization is consistent with the broader changes described in the pull request summary. Ensure that this change aligns with the intended blockchain configuration for the simulation.
tools/walletextension/common/constants.go (3)
  • 41-41: The addition of the EncryptedTokenQueryParameter constant is consistent with the changes described in the summary and pull request.

  • 43-43: Verify that the removal of MessageUserIDLen does not affect any parts of the codebase that may still rely on this constant.

  • 43-43: Verify that the removal of SignatureLen and PersonalSignMessagePrefix constants is intentional and does not impact any existing functionality that may depend on them.

Comment on lines 47 to 58
)

func TestObscuroscan(t *testing.T) {
startPort := integration.StartPortObscuroscanUnitTest
startPort := integration.StartPortTenscanUnitTest
createObscuroNetwork(t, startPort)

obsScanConfig := &config.Config{
NodeHostAddress: fmt.Sprintf("http://127.0.0.1:%d", startPort+integration.DefaultHostRPCHTTPOffset),
ServerAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultObscuroscanHTTPPortOffset),
ServerAddress: fmt.Sprintf("127.0.0.1:%d", startPort+integration.DefaultTenscanHTTPPortOffset),
LogPath: "sys_out",
}
serverAddress := fmt.Sprintf("http://%s", obsScanConfig.ServerAddress)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [59-59]

The variable obsScanContainer should be renamed to reflect the Tenscan context, such as tenScanContainer.

@@ -203,7 +203,7 @@
// Creates a single-node Obscuro network for testing.
func createObscuroNetwork(t *testing.T, startPort int) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function createObscuroNetwork should be renamed to reflect the Tenscan context, such as createTenscanNetwork.

@@ -203,7 +203,7 @@
// Creates a single-node Obscuro network for testing.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be updated to reflect the new context, replacing "Obscuro" with "Tenscan".

Comment on lines 70 to +71
http() {
return `${this.httpURL}/v1/?u=${this.userId}`;
return `${this.httpURL}/v1/?token=${this.userId}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The http and ws methods should use the obscuroGatewayVersion variable instead of the hardcoded "v1" to maintain consistency and ease of updates.

- return `${this.httpURL}/v1/?token=${this.userId}`;
+ return `${this.httpURL}/${obscuroGatewayVersion}/?token=${this.userId}`;
- return `${this.wsURL}/v1/?token=${this.userId}`;
+ return `${this.wsURL}/${obscuroGatewayVersion}/?token=${this.userId}`;

Also applies to: 74-75


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
http() {
return `${this.httpURL}/v1/?u=${this.userId}`;
return `${this.httpURL}/v1/?token=${this.userId}`;
http() {
return `${this.httpURL}/${obscuroGatewayVersion}/?token=${this.userId}`;

func (o *OGLib) HTTP() string {
return fmt.Sprintf("%s/v1/?u=%s", o.httpURL, o.userID)
func (o *TGLib) HTTP() string {
return fmt.Sprintf("%s/v1/?token=%s", o.httpURL, o.userID)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The userID is a byte slice and should be converted to a string before being used in URL construction to avoid potential issues.

- return fmt.Sprintf("%s/v1/?token=%s", o.httpURL, o.userID)
+ return fmt.Sprintf("%s/v1/?token=%s", o.httpURL, string(o.userID))

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return fmt.Sprintf("%s/v1/?token=%s", o.httpURL, o.userID)
return fmt.Sprintf("%s/v1/?token=%s", o.httpURL, string(o.userID))


## User interactions

The key reason for the OG is to allow implementing a 3-click user onboarding process.
The key reason for the TG is to allow implementing a 3-click user onboarding process.

### User on-boarding
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UX diagram filename "og_ux.png" should be updated to match the new project naming convention, such as "tg_ux.png".

@@ -151,36 +151,36 @@
chainId: obscuroChainIDDecimal,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chainId in the EIP-712 message format should be updated to reflect the new TenChainID.

Alice -> OG: Create User\n(ajax call behind the scenes)
OG -> OG: Generate and record VK\nand record against UserId
Alice -> TG: Create User\n(ajax call behind the scenes)
TG -> TG: Generate and record VK\nand record against UserId
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term "UserId" should be replaced with "Encryption Token" to maintain consistency with the new identification mechanism.

@@ -304,14 +305,14 @@

This could be used for tax purposes, or to prove holdings.

## Revocation of userId
## Revocation of encryption token

Users might suspect someone else knows their UserdId.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term "UserId" should be replaced with "Encryption Token" to maintain consistency with the new identification mechanism.

@@ -42,17 +42,17 @@
Wallets: wallets,
HTTPClient: httpClient,
WSClient: wsClient,
ogClient: ogClient,
tgClient: ogClient,
Copy link

@coderabbitai coderabbitai bot Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GatewayUser struct initialization should assign the renamed tgClient variable to the tgClient field.

- tgClient:   ogClient,
+ tgClient:   tgClient,

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
tgClient: ogClient,
tgClient: tgClient,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zkokelj Understood, I'm pausing the actions. Please let me know how you would like to proceed or if there's anything specific you need assistance with.

@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
@ten-protocol ten-protocol deleted a comment from coderabbitai bot Nov 27, 2023
Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
🔥🔥

@zkokelj zkokelj merged commit f6c7c1b into main Nov 27, 2023
2 checks passed
@zkokelj zkokelj deleted the ziga/add_token_as_query_param branch November 27, 2023 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants