-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: wallet authwit management (#8128)
Added the ability of authorizing actions to be performed on behalf of our accounts, both in public and private. Also revamped tests so they're easier to follow and read their results. ## New commands For private authwits - `create-authwit [options] <functionName> <caller>`: Creates an authorization witness that can be privately sent to a caller so they can perform an action on behalf of the provided account. - `add-authwit [options] <authwit> <authorizer>`: Adds an authorization witness to the provided account, granting PXE access to the notes of the authorizer so that it can be verified Test showcasing usage `./yarn-project/cli-wallet/test/flows/private_authwit_transfer.sh` For public authwits - `authorize-action [options] <functionName> <caller>`: Authorizes a public call on the caller, so they can perform an action on behalf of the provided account Test showcasing usage `./yarn-project/cli-wallet/test/flows/public_authwit_transfer.sh` ## Breaking changes - `add-note` command now uses `-t, --transaction-hash` instead of `-h` to not confuse it with the `--help` option. (thanks for the heads up, @signorecello!) ## Other changes - `bridge-fee-juice` now allows a `--no-wait` option to avoid polling the network for the L2 messages to appear, and alternatively an `--interval <seconds>` option to set polling interval (60s by default). --------- Co-authored-by: esau <152162806+sklppy88@users.noreply.github.com>
- Loading branch information
Showing
21 changed files
with
532 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { type AccountWalletWithSecretKey, type AuthWitness, type AztecAddress } from '@aztec/aztec.js'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function addAuthwit( | ||
wallet: AccountWalletWithSecretKey, | ||
authwit: AuthWitness, | ||
authorizer: AztecAddress, | ||
log: LogFn, | ||
) { | ||
await wallet.addAuthWitness(authwit); | ||
|
||
log(`Added authorization witness from ${authorizer}`); | ||
} |
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,35 @@ | ||
import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js'; | ||
import { prepTx } from '@aztec/cli/utils'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function authorizeAction( | ||
wallet: AccountWalletWithSecretKey, | ||
functionName: string, | ||
caller: AztecAddress, | ||
functionArgsIn: any[], | ||
contractArtifactPath: string, | ||
contractAddress: AztecAddress, | ||
log: LogFn, | ||
) { | ||
const { functionArgs, contractArtifact, isPrivate } = await prepTx( | ||
contractArtifactPath, | ||
functionName, | ||
functionArgsIn, | ||
log, | ||
); | ||
|
||
if (isPrivate) { | ||
throw new Error( | ||
'Cannot authorize private function. To allow a third party to call a private function, please create an authorization witness via the create-authwit command', | ||
); | ||
} | ||
|
||
const contract = await Contract.at(contractAddress, contractArtifact, wallet); | ||
const action = contract.methods[functionName](...functionArgs); | ||
|
||
const witness = await wallet.setPublicAuthWit({ caller, action }, true).send().wait(); | ||
|
||
log(`Authorized action ${functionName} on contract ${contractAddress} for caller ${caller}`); | ||
|
||
return witness; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js'; | ||
import { prepTx } from '@aztec/cli/utils'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
export async function createAuthwit( | ||
wallet: AccountWalletWithSecretKey, | ||
functionName: string, | ||
caller: AztecAddress, | ||
functionArgsIn: any[], | ||
contractArtifactPath: string, | ||
contractAddress: AztecAddress, | ||
log: LogFn, | ||
) { | ||
const { functionArgs, contractArtifact, isPrivate } = await prepTx( | ||
contractArtifactPath, | ||
functionName, | ||
functionArgsIn, | ||
log, | ||
); | ||
|
||
if (!isPrivate) { | ||
throw new Error( | ||
'Cannot create an authwit for a public function. To allow a third party to call a public function, please authorize the action via the authorize-action command', | ||
); | ||
} | ||
|
||
const contract = await Contract.at(contractAddress, contractArtifact, wallet); | ||
const action = contract.methods[functionName](...functionArgs); | ||
|
||
const witness = await wallet.createAuthWit({ caller, action }); | ||
|
||
log(`Created authorization witness for action ${functionName} on contract ${contractAddress} for caller ${caller}`); | ||
|
||
return witness; | ||
} |
Oops, something went wrong.