-
Notifications
You must be signed in to change notification settings - Fork 615
feat(docs): Authwit how tos #6220
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1baa335
initial docs
catmcgee 4070694
include_code
catmcgee d063f2f
added arbitrary data in authwits
catmcgee 76d141c
Merge branch 'master' into docs/authwit-how-to
catmcgee d3f5198
fix test reference
critesjosh 7d223ee
Merge branch 'master' into docs/authwit-how-to
catmcgee 178dc0c
fix sidebar
catmcgee 4c63569
suggestions
catmcgee 08a096f
conflicts
catmcgee 9d78d4a
tidy up
catmcgee 0c96b81
link fixes
catmcgee 1b23d0c
link fixes
catmcgee 2548879
Merge branch 'master' into docs/authwit-how-to
catmcgee e2a66ff
Apply suggestions from code review
catmcgee 8a3b2fb
typo
catmcgee 4b812e9
Merge branch 'master' into docs/authwit-how-to
catmcgee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,110 @@ | ||
| --- | ||
| title: How to use authentication witnesses (authwit) | ||
| --- | ||
|
|
||
| This page assumes you have authwit set up correctly in your contract. To learn how to do that, [go here](../../contracts/writing_contracts/accounts/how_to_authwit.md). | ||
|
|
||
| For an introduction to authentication witnesses on Aztec, [read this explainer](../../../learn/concepts/accounts/authwit.md). | ||
|
|
||
| ## Import libraries | ||
|
|
||
| These are all the libraries you will need for the various ways of using authwits in Aztec.js: | ||
|
|
||
| ```typescript | ||
| import { computeAuthWitMessageHash, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/aztec.js'; | ||
| ``` | ||
|
|
||
| You may not need all of these. | ||
|
|
||
| ## Publicly deploy accounts | ||
|
|
||
| :::note | ||
| This is only required if you are using authwits in public | ||
| :::note | ||
|
|
||
| If you are using public authwit (ie using `assert_current_call_valid_authwit_public` in your contract), you will need to deploy the following accounts publicly: | ||
|
|
||
| 1. The account that is giving permission to an account to act on behalf of it (authwit giver) | ||
| 2. The account that does the action (authwit receiver) | ||
|
|
||
| Here is an example implementation: | ||
|
|
||
| #include_code public_deploy_accounts yarn-project/end-to-end/src/fixtures/utils.ts typescript | ||
|
|
||
| You would then call this like so: | ||
|
|
||
| #include_code public_deploy_accounts yarn-project/end-to-end/src/e2e_authwit_test.ts typescript | ||
|
|
||
| ## Define the action | ||
|
|
||
| When creating an authwit, you will need to pass the authwit givier, the authwit receiver (who will perform the action), and the action that is being authorized. The action can be a smart contract function call, or alternatively arbitrary data. | ||
|
|
||
| ### When the action is a function call | ||
|
|
||
| You can define the action like this: | ||
|
|
||
| #include_code authwit_computeAuthWitMessageHash yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts typescript | ||
|
|
||
| In this example, | ||
| * `asset` refers to a token contract | ||
| * `withWallet(wallets[1])` is specifying the authwit receiver (`wallets[1]`) will do this action | ||
| * `.methods.transfer()` is specifying that the action is calling the `transfer` method on the token contract | ||
| * `(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce);` are the args of this method - it will send the `amount` from `wallets[0]` to `wallets[1]` | ||
|
|
||
| ### Arbitrary message | ||
|
|
||
| You can hash your own authwit message by creating an inner hash with the data, like this: | ||
|
|
||
| #include_code compute_inner_authwit_hash yarn-project/end-to-end/src/e2e_authwit.test.ts typescript | ||
|
|
||
| Then create the outer hash by hashing the inner hash with the authwit receiver address, chainId, and version: | ||
|
|
||
| #include_code compute_outer_authwit_hash yarn-project/end-to-end/src/e2e_authwit.test.ts typescript | ||
|
|
||
| ## Create the authwit | ||
|
|
||
| These are slightly different interfaces depending on whether your contract is checking the authwit in private or public. As public authwits are stored in the account contract and batched with the authwit action call, it is done with one transaction. Private execution uses oracles, so the authwit needs to be created by the authwit giver and then added to the receiver's wallet. | ||
|
|
||
| ### Private | ||
|
|
||
| This is expected to be used alongside [private authwits in Aztec.nr contract](../../contracts/writing_contracts/accounts/how_to_authwit.md#private-functions). | ||
|
|
||
| Create a private authwit like this: | ||
|
|
||
| #include_code create_authwit yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts typescript | ||
|
|
||
| In this example, | ||
| * `wallets[0]` is the authwit giver | ||
| * `wallets[1]` is the authwit reciever and caller of the function | ||
| * `action` was [defined previously](#define-the-action) | ||
|
|
||
| If you created an artbitrary message, you can create the authwit by replacing these params with the outer hash: | ||
|
|
||
| #include_code compute_outer_authwit_hash yarn-project/end-to-end/src/e2e_authwit.test.ts typescript | ||
|
|
||
| Then add it to the wallet of the authwit receiver (the caller of the transaction): | ||
|
|
||
| #include_code add_authwit yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts typescript | ||
|
|
||
| ### Public | ||
|
|
||
| This is expected to be used alongside [public authwits in Aztec.nr contract](../../contracts/writing_contracts/accounts/how_to_authwit.md#public-functions). | ||
|
|
||
| Set a public authwit like this: | ||
|
|
||
| #include_code set_public_authwit yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_public.test.ts typescript | ||
|
|
||
| Remember it is a transaction and calls a method in the account contract. In this example, | ||
| * `wallets[0]` is the authwit giver | ||
| * `wallets[1]` is the authwit reciever and caller of the function | ||
| * `action` was [defined previously](#define-the-action) | ||
| * `true` sets the `authorized` boolean (`false` would revoke this authwit) | ||
|
|
||
| If you created an arbitrary message, you would replace the first param struct with the outer hash: | ||
|
|
||
| #include_code set_public_authwit yarn-project/end-to-end/src/e2e_authwit.test.ts typescript | ||
|
|
||
| # Further reading | ||
|
catmcgee marked this conversation as resolved.
Outdated
|
||
|
|
||
| * [An explainer of authentication witnesses](../../../learn/concepts/accounts/authwit.md) | ||
| * [Authwits in Aztec.nr](../../contracts/writing_contracts/accounts/how_to_authwit.md) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.