-
Notifications
You must be signed in to change notification settings - Fork 37
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
Session Keys on Ten Gateway #2024
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,48 +20,45 @@ The TG already manages VKs on behalf of users, so adding SKs is relatively strai | |
|
||
The advantage of the TG managing SKs is that it can return the funds to the EOA anytime. | ||
|
||
|
||
Another advantage is that they can be reused between sessions to avoid unnecessary transactions. | ||
|
||
|
||
### The flow | ||
|
||
The logic of the game UI (javascript) will call an endpoint on the TG that will return a value transfer transaction that the user must sign in their wallet, together with the address of the SK. | ||
#### Create | ||
The logic of the game UI (javascript) will call an `/session_key/create` endpoint on the TG, which will return the account address corresponding to the SK. | ||
The game UI will create a value transfer transaction from the main account to this address with enough money to prepay for the moves. The user must sign it with their wallet. | ||
|
||
The game will call `/session_key/activate/${sk_account}` | ||
|
||
After the initialisation, the game will create unsigned move transactions and submit them to the TG. | ||
The TG will sign these transactions with the active SK and submit them to the network. | ||
|
||
#### Reuse | ||
|
||
If the user already has a session key, the game can retrieve it with `/session_key/list`. This will return a list of `address, amount`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just realised there's a bit of a security issue here. We have an rpc method that returns the user ID, which means if someone makes a webpage with a 'Connect wallet' button then it can:
Possible solutions that spring to mind:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh I think number 1 needs to be seriously considered because even without session keys this means that whenever you connect your wallet to an app you risk them snooping through your 'private' tx data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is that userIDs could be sessioned. If you make a request to a user ID from a different IP or after a long period of time then you're forced to re-authenticate with your EOA signature... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, totally. I was thinking the same |
||
The game has the option to top up the value, or activate it. | ||
|
||
The value transfer is required to prepay for the moves. | ||
#### Ending the game | ||
|
||
*Note: If the user authenticates with a service that is happy to prepay (a paymaster), then the signing step is not required.* | ||
The game can create transactions to move the values accumulated by the Sk to the main account, and submit them to the TG. | ||
|
||
The game will create unsigned move transactions and submit them to the gateway. | ||
The TG will sign these transactions with the SK and submit them to the network. | ||
When that is finished: `/session_key/deactivate`, which returns `address, amount`. | ||
|
||
#### Deleting a SK | ||
|
||
## Data ownership | ||
SKs need to be stored on the TG to allow the user to query in the future | ||
|
||
The SKs are a proxy for the EOA, so we want the EOA to read all data belonging to the SKs. | ||
The SKs are tx signers so the platform will treat them as EOAs. | ||
#### Exporting the SKs | ||
|
||
We need to introduce platform level support for SKs. | ||
`/session_key/export/${sk_account}` - returns the private key | ||
|
||
### The main place will the `externally_owned_account` table: | ||
|
||
``` | ||
create table if not exists obsdb.externally_owned_account | ||
( | ||
id INTEGER AUTO_INCREMENT, | ||
address binary(20) NOT NULL, | ||
owner INTEGER, // this is a new field that will be populated for SKs and will point to the main account | ||
primary key (id), | ||
INDEX USING HASH (address) | ||
); | ||
``` | ||
### Implementation on the Ten Gateway | ||
|
||
Todo : | ||
- Query for events: | ||
- Query for receipts: | ||
- T | ||
1. Store SKs in the database and manage them via the `session_key` endpoints | ||
2. Sign the SK account with the vk of the user | ||
3. Mark a session active per user and sign transactions with the SK | ||
4. When the user queries data, also include the SKs as candidates. Todo: think about when the data needs concatenation | ||
|
||
### RPC endpoint on Node - Register session key | ||
|
||
- Receives a session key signed by a VK signed by the EOA. | ||
- Stores it to the `externally_owned_account` table and points to the true EOA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth saying explicitly how that tx part works, I guess it's like /session_key/submit_tx or something? And the payload is similar to eth_sendRawTransaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my mind it would be a normal transaction, sent via the normal rpc. Only that the signature fields are 0 or something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok fair, yeah if the wallets let you do that then that'd work nicely