-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
64ddefe
commit cba860f
Showing
11 changed files
with
180 additions
and
131 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
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
8 changes: 8 additions & 0 deletions
8
docs/home/300-react-to-events/2-primitive-catalogue/5-meta/100-introduction.md
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,8 @@ | ||
# Primitive List | ||
|
||
Meta primitives are primitives built into Paima Engine that are trigger by engine-related functionality. | ||
|
||
They do not typically require explicitly being enabled your [configuration](../1-introduction.md#configuration). | ||
|
||
List of meta primitives: | ||
1. Wallet delegation ([docs](../../../700-multichain-support/2-wallet-layer/100-delegate-wallet/1-introduction.mdx)) |
3 changes: 3 additions & 0 deletions
3
docs/home/300-react-to-events/2-primitive-catalogue/5-meta/_category_.json
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,3 @@ | ||
{ | ||
"label": "Meta Primitives" | ||
} |
23 changes: 23 additions & 0 deletions
23
...me/700-multichain-support/2-wallet-layer/100-delegate-wallet/1-introduction.mdx
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,23 @@ | ||
# Introduction | ||
|
||
Delegate Wallet allows for a wallet address to be delegated to another wallet address. | ||
|
||
In practice, a user can use wallet address `A` to play, but their real wallet address is `B` | ||
|
||
Some use cases: | ||
* **Better UX**: By using a "Local Wallet" within the browser and sending transactions through the "Batcher", so each transaction gets signed automatically. | ||
* **Security**: Allowing players to have a "Burner Wallet" with limited funds to play on. | ||
* **Security**: Reduce interaction with real wallet. | ||
* **Account Recovery**: account can be re-delegated to a new wallet address. | ||
|
||
This feature is optional and you can implement at any time. | ||
However, it's good practice use `user_id` in the STF to identify the user, and not the wallet address in case you end up implementing wallet delegation later. | ||
|
||
Feature notes: | ||
- Delegation can be done after-the-fact (ex: you can play on a burner wallet, and connect it to a main wallet later) | ||
- Delegations can be cancelled | ||
- [Cycles](https://en.wikipedia.org/wiki/Cycle_(graph_theory)) are not allowed | ||
- Main wallet state can be delegated to multiple burner wallets (ex: playing on multiple devices at once) | ||
|
||
Security risk: | ||
- Somebody could trick you into delegating your game state to them (steal all your in-game progress). To avoid this, the delegation transaction uses human-readable strings so the user can easily see what they are signing. |
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
93 changes: 93 additions & 0 deletions
93
...home/700-multichain-support/2-wallet-layer/100-delegate-wallet/3-interfaces.mdx
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,93 @@ | ||
# Effect on Interfaces | ||
|
||
Enabling wallet delegation has implications on the interfaces of multiple different parts of your application. | ||
|
||
## Meta Primitive | ||
|
||
The user must (using a [concise](../../../200-read-write-L2-state/1-base-format.md) command) send a transaction to delegate their wallet address to another wallet address | ||
|
||
Wallet delegation provides the following [meta primitives](../../../300-react-to-events/2-primitive-catalogue/5-meta/100-introduction.md): | ||
``` | ||
delegate = &wd|from?|to?|from_signature|to_signature | ||
migrate = &wm|from?|to?|from_signature|to_signature | ||
cancelDelegations = &wc|to_signature | ||
``` | ||
|
||
## STF | ||
|
||
[STF](../../../200-read-write-L2-state/10-read-data.md#stf-function) data is slightly changed: | ||
* `userAddress`: contains the main wallet address. | ||
* `realAddress`: contains the real wallet address that sent the transaction. | ||
* `userId`: contains the user id, which is the same for all wallets of the same user. | ||
|
||
`userAddress` and `realAddress` will be the same for the main wallet or if there are no delegations. | ||
|
||
## Indexer Database | ||
|
||
There are 2 tables tracked in the indexer to manage delegations: | ||
* `addresses`: *(always present)* maps a unique user id to each wallet address. | ||
* `delegations`: *(new for delegations)* maps delegated wallet addresses using IDs from the *addresses* table. | ||
|
||
## Middleware | ||
|
||
There are multiple files part of `@paima/sdk/mw-core` to help integrate wallet delegation | ||
|
||
### Connect two wallets | ||
|
||
This function delegates `from` your main wallet `to` your burner wallet | ||
|
||
When delegating, you must sign the following message template in 2 steps: once for each key (`from` key & `to` key): | ||
``` | ||
DELEGATE-WALLET:<other-address-lowercase>:<env-contract-address> | ||
``` | ||
* `other-address-lowercase`: the address not signing this step | ||
* `env-contract-address`: is defined in [.env](../../../1-setup/4-environment-config-values.md) (`CONTRACT_ADDRESS`) | ||
* *Note:* the address signing for a given step is not explicitly added since its address & signature are implicitly part of the transaction | ||
|
||
|
||
```js | ||
function walletConnect( | ||
// If from/to are null | ||
// they gets replaced by the wallet that sends (or signs if using the batcher) the tx | ||
from: string | null, | ||
to: string | null, | ||
from_signature: string, | ||
to_signature: string | ||
): Promise<SuccessfulResult<PostDataResponse> | FailedResult> | ||
``` | ||
|
||
### Cancel delegation | ||
|
||
This function removes any current delegation to the sender address. | ||
The message has the format: | ||
```js | ||
DELEGATE-WALLET::<env-contract-address> | ||
``` | ||
|
||
*Note*: address is omitted. You can do this by using `buildMessageToSign` with an empty string (`buildMessageToSign('')`) | ||
|
||
```js | ||
function walletConnectCancelDelegations( | ||
to_signature: string | ||
): Promise<SuccessfulResult<PostDataResponse> | FailedResult> { | ||
``` | ||
### Migrate wallet | ||
This function migrates the address `from` to `to`. | ||
```js | ||
function walletConnectMigrate( | ||
// null gets replaced by the wallet that signs the tx | ||
from: string | null, | ||
to: string | null, | ||
from_signature: string, | ||
to_signature: string | ||
): Promise<SuccessfulResult<PostDataResponse> | FailedResult> | ||
``` | ||
|
||
### Helper | ||
|
||
The `WalletConnectHelper` class contains helper functions to sign with injected or generate the message for local wallets: | ||
1. `buildMessageToSign` to generate the correct concise notation to sign for an action | ||
2. `connectExternalWalletAndSign` to connect an external wallet and delegate from it at the same time. |
File renamed without changes.
16 changes: 0 additions & 16 deletions
16
docs/home/700-multichain-support/3-delegate-wallet/1-introduction.mdx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.