@aztec/aztec.js 0.43.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/account/interface.d.ts +5 -19
- package/dest/account/interface.d.ts.map +1 -1
- package/dest/account/interface.js +1 -1
- package/dest/account/wallet.d.ts +5 -2
- package/dest/account/wallet.d.ts.map +1 -1
- package/dest/api/abi.d.ts +1 -1
- package/dest/api/abi.d.ts.map +1 -1
- package/dest/api/abi.js +2 -2
- package/dest/fee/private_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/private_fee_payment_method.js +12 -11
- package/dest/fee/public_fee_payment_method.d.ts.map +1 -1
- package/dest/fee/public_fee_payment_method.js +15 -12
- package/dest/index.d.ts +3 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -3
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
- package/dest/rpc_clients/pxe_client.js +3 -1
- package/dest/utils/abi_types.d.ts +4 -2
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/authwit.d.ts +45 -29
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +35 -17
- package/dest/wallet/account_wallet.d.ts +25 -72
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +65 -66
- package/dest/wallet/base_wallet.d.ts +4 -13
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +6 -3
- package/dest/wallet/signerless_wallet.d.ts +3 -1
- package/dest/wallet/signerless_wallet.d.ts.map +1 -1
- package/dest/wallet/signerless_wallet.js +2 -2
- package/package.json +16 -9
- package/src/account/interface.ts +5 -24
- package/src/account/wallet.ts +7 -2
- package/src/api/abi.ts +1 -1
- package/src/fee/private_fee_payment_method.ts +4 -8
- package/src/fee/public_fee_payment_method.ts +17 -16
- package/src/index.ts +4 -1
- package/src/rpc_clients/pxe_client.ts +2 -0
- package/src/utils/abi_types.ts +11 -2
- package/src/utils/authwit.ts +66 -21
- package/src/wallet/account_wallet.ts +76 -154
- package/src/wallet/base_wallet.ts +11 -21
- package/src/wallet/signerless_wallet.ts +2 -2
package/src/account/interface.ts
CHANGED
|
@@ -1,44 +1,25 @@
|
|
|
1
|
-
import { type AuthWitness, type CompleteAddress
|
|
1
|
+
import { type AuthWitness, type CompleteAddress } from '@aztec/circuit-types';
|
|
2
2
|
import { type AztecAddress } from '@aztec/circuits.js';
|
|
3
3
|
import { type Fq, type Fr } from '@aztec/foundation/fields';
|
|
4
4
|
|
|
5
|
-
import { type ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
6
5
|
import { type EntrypointInterface } from '../entrypoint/entrypoint.js';
|
|
7
6
|
|
|
8
7
|
// docs:start:account-interface
|
|
9
8
|
/** Creates authorization witnesses. */
|
|
10
9
|
export interface AuthWitnessProvider {
|
|
11
10
|
/**
|
|
12
|
-
* Computes an authentication witness from either a message hash
|
|
13
|
-
*
|
|
14
|
-
* Otherwise, it will compute the message hash using the caller and the action of the intent.
|
|
15
|
-
* @param messageHashOrIntent - The message hash or the intent (caller and action) to approve
|
|
16
|
-
* @param chainId - The chain id for the message, will default to the current chain id
|
|
17
|
-
* @param version - The version for the message, will default to the current protocol version
|
|
11
|
+
* Computes an authentication witness from either a message hash
|
|
12
|
+
* @param messageHash - The message hash to approve
|
|
18
13
|
* @returns The authentication witness
|
|
19
14
|
*/
|
|
20
|
-
createAuthWit(
|
|
21
|
-
messageHashOrIntent:
|
|
22
|
-
| Fr
|
|
23
|
-
| Buffer
|
|
24
|
-
| {
|
|
25
|
-
/** The caller to approve */
|
|
26
|
-
caller: AztecAddress;
|
|
27
|
-
/** The action to approve */
|
|
28
|
-
action: ContractFunctionInteraction | FunctionCall;
|
|
29
|
-
/** The chain id to approve */
|
|
30
|
-
chainId?: Fr;
|
|
31
|
-
/** The version to approve */
|
|
32
|
-
version?: Fr;
|
|
33
|
-
},
|
|
34
|
-
): Promise<AuthWitness>;
|
|
15
|
+
createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
|
|
35
16
|
}
|
|
36
17
|
|
|
37
18
|
/**
|
|
38
19
|
* Handler for interfacing with an account. Knows how to create transaction execution
|
|
39
20
|
* requests and authorize actions for its corresponding account.
|
|
40
21
|
*/
|
|
41
|
-
export interface AccountInterface extends
|
|
22
|
+
export interface AccountInterface extends EntrypointInterface, AuthWitnessProvider {
|
|
42
23
|
/** Returns the complete address for this account. */
|
|
43
24
|
getCompleteAddress(): CompleteAddress;
|
|
44
25
|
|
package/src/account/wallet.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { type PXE } from '@aztec/circuit-types';
|
|
1
|
+
import { type AuthWitness, type PXE } from '@aztec/circuit-types';
|
|
2
2
|
|
|
3
|
+
import { type IntentAction, type IntentInnerHash } from '../utils/authwit.js';
|
|
3
4
|
import { type AccountInterface, type AccountKeyRotationInterface } from './interface.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The wallet interface.
|
|
7
8
|
*/
|
|
8
|
-
export type Wallet = AccountInterface &
|
|
9
|
+
export type Wallet = AccountInterface &
|
|
10
|
+
PXE &
|
|
11
|
+
AccountKeyRotationInterface & {
|
|
12
|
+
createAuthWit(intent: IntentInnerHash | IntentAction): Promise<AuthWitness>;
|
|
13
|
+
};
|
package/src/api/abi.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
|
|
1
|
+
export { type ContractArtifact, type FunctionArtifact, EventSelector, FunctionSelector } from '@aztec/foundation/abi';
|
|
2
2
|
export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi';
|
|
3
3
|
export { type NoirCompiledContract } from '@aztec/types/noir';
|
|
@@ -6,7 +6,6 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
|
6
6
|
import { Fr } from '@aztec/foundation/fields';
|
|
7
7
|
|
|
8
8
|
import { type Wallet } from '../account/wallet.js';
|
|
9
|
-
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
10
9
|
import { type FeePaymentMethod } from './fee_payment_method.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -55,11 +54,9 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
55
54
|
async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
|
|
56
55
|
const nonce = Fr.random();
|
|
57
56
|
const maxFee = gasSettings.getFeeLimit();
|
|
58
|
-
|
|
59
|
-
this.paymentContract,
|
|
60
|
-
|
|
61
|
-
this.wallet.getVersion(),
|
|
62
|
-
{
|
|
57
|
+
await this.wallet.createAuthWit({
|
|
58
|
+
caller: this.paymentContract,
|
|
59
|
+
action: {
|
|
63
60
|
name: 'unshield',
|
|
64
61
|
args: [this.wallet.getCompleteAddress().address, this.paymentContract, maxFee, nonce],
|
|
65
62
|
selector: FunctionSelector.fromSignature('unshield((Field),(Field),Field,Field)'),
|
|
@@ -68,8 +65,7 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
68
65
|
to: this.asset,
|
|
69
66
|
returnTypes: [],
|
|
70
67
|
},
|
|
71
|
-
);
|
|
72
|
-
await this.wallet.createAuthWit(messageHash);
|
|
68
|
+
});
|
|
73
69
|
|
|
74
70
|
const secretHashForRebate = computeSecretHash(this.rebateSecret);
|
|
75
71
|
|
|
@@ -4,7 +4,6 @@ import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
|
|
|
4
4
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
|
|
7
|
-
import { computeAuthWitMessageHash } from '../utils/authwit.js';
|
|
8
7
|
import { type AccountWallet } from '../wallet/account_wallet.js';
|
|
9
8
|
import { type FeePaymentMethod } from './fee_payment_method.js';
|
|
10
9
|
|
|
@@ -47,23 +46,25 @@ export class PublicFeePaymentMethod implements FeePaymentMethod {
|
|
|
47
46
|
getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
|
|
48
47
|
const nonce = Fr.random();
|
|
49
48
|
const maxFee = gasSettings.getFeeLimit();
|
|
50
|
-
const messageHash = computeAuthWitMessageHash(
|
|
51
|
-
this.paymentContract,
|
|
52
|
-
this.wallet.getChainId(),
|
|
53
|
-
this.wallet.getVersion(),
|
|
54
|
-
{
|
|
55
|
-
name: 'transfer_public',
|
|
56
|
-
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
57
|
-
selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
|
|
58
|
-
type: FunctionType.PUBLIC,
|
|
59
|
-
isStatic: false,
|
|
60
|
-
to: this.asset,
|
|
61
|
-
returnTypes: [],
|
|
62
|
-
},
|
|
63
|
-
);
|
|
64
49
|
|
|
65
50
|
return Promise.resolve([
|
|
66
|
-
this.wallet
|
|
51
|
+
this.wallet
|
|
52
|
+
.setPublicAuthWit(
|
|
53
|
+
{
|
|
54
|
+
caller: this.paymentContract,
|
|
55
|
+
action: {
|
|
56
|
+
name: 'transfer_public',
|
|
57
|
+
args: [this.wallet.getAddress(), this.paymentContract, maxFee, nonce],
|
|
58
|
+
selector: FunctionSelector.fromSignature('transfer_public((Field),(Field),Field,Field)'),
|
|
59
|
+
type: FunctionType.PUBLIC,
|
|
60
|
+
isStatic: false,
|
|
61
|
+
to: this.asset,
|
|
62
|
+
returnTypes: [],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
true,
|
|
66
|
+
)
|
|
67
|
+
.request(),
|
|
67
68
|
{
|
|
68
69
|
name: 'fee_entrypoint_public',
|
|
69
70
|
to: this.paymentContract,
|
package/src/index.ts
CHANGED
|
@@ -41,16 +41,18 @@ export {
|
|
|
41
41
|
CheatCodes,
|
|
42
42
|
EthAddressLike,
|
|
43
43
|
EthCheatCodes,
|
|
44
|
+
EventSelectorLike,
|
|
44
45
|
FieldLike,
|
|
45
46
|
FunctionSelectorLike,
|
|
46
47
|
WrappedFieldLike,
|
|
47
48
|
computeAuthWitMessageHash,
|
|
49
|
+
computeInnerAuthWitHashFromAction,
|
|
48
50
|
computeInnerAuthWitHash,
|
|
49
|
-
computeOuterAuthWitHash,
|
|
50
51
|
generatePublicKey,
|
|
51
52
|
waitForAccountSynch,
|
|
52
53
|
waitForPXE,
|
|
53
54
|
} from './utils/index.js';
|
|
55
|
+
export { NoteSelector } from '@aztec/foundation/abi';
|
|
54
56
|
|
|
55
57
|
export { createPXEClient } from './rpc_clients/index.js';
|
|
56
58
|
|
|
@@ -97,6 +99,7 @@ export {
|
|
|
97
99
|
EncryptedLogHeader,
|
|
98
100
|
EncryptedNoteLogIncomingBody,
|
|
99
101
|
EncryptedLogOutgoingBody,
|
|
102
|
+
EventType,
|
|
100
103
|
ExtendedNote,
|
|
101
104
|
FunctionCall,
|
|
102
105
|
GrumpkinPrivateKey,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
GrumpkinScalar,
|
|
26
26
|
Point,
|
|
27
27
|
} from '@aztec/circuits.js';
|
|
28
|
+
import { NoteSelector } from '@aztec/foundation/abi';
|
|
28
29
|
import { createJsonRpcClient, makeFetch } from '@aztec/foundation/json-rpc/client';
|
|
29
30
|
|
|
30
31
|
/**
|
|
@@ -53,6 +54,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false)
|
|
|
53
54
|
Point,
|
|
54
55
|
TxExecutionRequest,
|
|
55
56
|
TxHash,
|
|
57
|
+
NoteSelector,
|
|
56
58
|
},
|
|
57
59
|
{ Tx, SimulatedTx, TxReceipt, EncryptedNoteL2BlockL2Logs, UnencryptedL2BlockL2Logs, NullifierMembershipWitness },
|
|
58
60
|
false,
|
package/src/utils/abi_types.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type AztecAddress,
|
|
3
|
+
type EthAddress,
|
|
4
|
+
type EventSelector,
|
|
5
|
+
type Fr,
|
|
6
|
+
type FunctionSelector,
|
|
7
|
+
} from '@aztec/circuits.js';
|
|
2
8
|
|
|
3
9
|
/** Any type that can be converted into a field for a contract call. */
|
|
4
10
|
export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr };
|
|
@@ -9,8 +15,11 @@ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | Eth
|
|
|
9
15
|
/** Any type that can be converted into an AztecAddress Aztec.nr struct. */
|
|
10
16
|
export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress;
|
|
11
17
|
|
|
12
|
-
/** Any type that can be converted into
|
|
18
|
+
/** Any type that can be converted into a FunctionSelector Aztec.nr struct. */
|
|
13
19
|
export type FunctionSelectorLike = FieldLike | FunctionSelector;
|
|
14
20
|
|
|
21
|
+
/** Any type that can be converted into an EventSelector Aztec.nr struct. */
|
|
22
|
+
export type EventSelectorLike = FieldLike | EventSelector;
|
|
23
|
+
|
|
15
24
|
/** Any type that can be converted into a struct with a single `inner` field. */
|
|
16
25
|
export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike;
|
package/src/utils/authwit.ts
CHANGED
|
@@ -1,32 +1,77 @@
|
|
|
1
1
|
import { type FunctionCall, PackedValues } from '@aztec/circuit-types';
|
|
2
|
-
import { type AztecAddress,
|
|
2
|
+
import { type AztecAddress, Fr, GeneratorIndex } from '@aztec/circuits.js';
|
|
3
3
|
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
4
|
|
|
5
|
+
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
6
|
+
|
|
7
|
+
/** Metadata for the intent */
|
|
8
|
+
export type IntentMetadata = {
|
|
9
|
+
/** The chain id to approve */
|
|
10
|
+
chainId: Fr;
|
|
11
|
+
/** The version to approve */
|
|
12
|
+
version: Fr;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Intent with an inner hash */
|
|
16
|
+
export type IntentInnerHash = {
|
|
17
|
+
/** The consumer */
|
|
18
|
+
consumer: AztecAddress;
|
|
19
|
+
/** The action to approve */
|
|
20
|
+
innerHash: Buffer | Fr;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** Intent with an action */
|
|
24
|
+
export type IntentAction = {
|
|
25
|
+
/** The caller to approve */
|
|
26
|
+
caller: AztecAddress;
|
|
27
|
+
/** The action to approve */
|
|
28
|
+
action: ContractFunctionInteraction | FunctionCall;
|
|
29
|
+
};
|
|
30
|
+
|
|
5
31
|
// docs:start:authwit_computeAuthWitMessageHash
|
|
6
32
|
/**
|
|
7
|
-
* Compute an authentication witness message hash from
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
33
|
+
* Compute an authentication witness message hash from an intent and metadata
|
|
34
|
+
*
|
|
35
|
+
* If using the `IntentInnerHash`, the consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
36
|
+
* The `innerHash` itself will be the message that a contract is allowed to execute.
|
|
37
|
+
* At the point of "approval checking", the validating contract (account for private and registry for public) will be computing the message hash
|
|
38
|
+
* (`H(consumer, chainid, version, inner_hash)`) where the all but the `inner_hash` is injected from the context (consumer = msg_sender),
|
|
39
|
+
* and use it for the authentication check.
|
|
40
|
+
* Therefore, any allowed `innerHash` will therefore also have information around where it can be spent (version, chainId) and who can spend it (consumer).
|
|
41
|
+
*
|
|
42
|
+
* If using the `IntentAction`, the caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
43
|
+
* The action is then used along with the `caller` to compute the `innerHash` and the consumer.
|
|
44
|
+
*
|
|
45
|
+
*
|
|
46
|
+
* @param intent - The intent to approve (consumer and innerHash or caller and action)
|
|
47
|
+
* The consumer is the address that can "consume" the authwit, for token approvals it is the token contract itself.
|
|
48
|
+
* The caller is the address that is making the call, for a token approval from Alice to Bob, this would be Bob.
|
|
49
|
+
* The caller becomes part of the `inner_hash` and is dealt with entirely in application logic.
|
|
50
|
+
* @param metadata - The metadata for the intent (chainId, version)
|
|
51
|
+
* @returns The message hash for the action
|
|
19
52
|
*/
|
|
20
|
-
export const computeAuthWitMessageHash = (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
53
|
+
export const computeAuthWitMessageHash = (intent: IntentInnerHash | IntentAction, metadata: IntentMetadata) => {
|
|
54
|
+
const chainId = metadata.chainId;
|
|
55
|
+
const version = metadata.version;
|
|
56
|
+
|
|
57
|
+
if ('caller' in intent) {
|
|
58
|
+
const action = intent.action instanceof ContractFunctionInteraction ? intent.action.request() : intent.action;
|
|
59
|
+
return computeOuterAuthWitHash(
|
|
60
|
+
action.to.toField(),
|
|
61
|
+
chainId,
|
|
62
|
+
version,
|
|
63
|
+
computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
64
|
+
);
|
|
65
|
+
} else {
|
|
66
|
+
const inner = Buffer.isBuffer(intent.innerHash) ? Fr.fromBuffer(intent.innerHash) : intent.innerHash;
|
|
67
|
+
return computeOuterAuthWitHash(intent.consumer, chainId, version, inner);
|
|
68
|
+
}
|
|
27
69
|
};
|
|
28
70
|
// docs:end:authwit_computeAuthWitMessageHash
|
|
29
71
|
|
|
72
|
+
export const computeInnerAuthWitHashFromAction = (caller: AztecAddress, action: FunctionCall) =>
|
|
73
|
+
computeInnerAuthWitHash([caller.toField(), action.selector.toField(), PackedValues.fromValues(action.args).hash]);
|
|
74
|
+
|
|
30
75
|
/**
|
|
31
76
|
* Compute the inner hash for an authentication witness.
|
|
32
77
|
* This is the "intent" of the message, before siloed with the consumer.
|
|
@@ -53,6 +98,6 @@ export const computeInnerAuthWitHash = (args: Fr[]) => {
|
|
|
53
98
|
* @param innerHash - The inner hash for the witness
|
|
54
99
|
* @returns The outer hash for the witness
|
|
55
100
|
*/
|
|
56
|
-
|
|
101
|
+
const computeOuterAuthWitHash = (consumer: AztecAddress, chainId: Fr, version: Fr, innerHash: Fr) => {
|
|
57
102
|
return pedersenHash([consumer.toField(), chainId, version, innerHash], GeneratorIndex.AUTHWIT_OUTER);
|
|
58
103
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AuthWitness, type
|
|
1
|
+
import { type AuthWitness, type PXE, type TxExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { AztecAddress, CANONICAL_KEY_REGISTRY_ADDRESS, Fq, Fr, derivePublicKeyFromSecretKey } from '@aztec/circuits.js';
|
|
3
3
|
import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/foundation/abi';
|
|
4
4
|
import { AuthRegistryAddress } from '@aztec/protocol-contracts/auth-registry';
|
|
@@ -6,7 +6,12 @@ import { AuthRegistryAddress } from '@aztec/protocol-contracts/auth-registry';
|
|
|
6
6
|
import { type AccountInterface } from '../account/interface.js';
|
|
7
7
|
import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
|
|
8
8
|
import { type ExecutionRequestInit } from '../entrypoint/entrypoint.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
type IntentAction,
|
|
11
|
+
type IntentInnerHash,
|
|
12
|
+
computeAuthWitMessageHash,
|
|
13
|
+
computeInnerAuthWitHashFromAction,
|
|
14
|
+
} from '../utils/authwit.js';
|
|
10
15
|
import { BaseWallet } from './base_wallet.js';
|
|
11
16
|
|
|
12
17
|
/**
|
|
@@ -30,28 +35,25 @@ export class AccountWallet extends BaseWallet {
|
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
33
|
-
* Computes an authentication witness from either a message or
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
38
|
+
* Computes an authentication witness from either a message hash or an intent.
|
|
39
|
+
*
|
|
40
|
+
* If a message hash is provided, it will create a witness for the hash directly.
|
|
41
|
+
* Otherwise, it will compute the message hash using the intent, along with the
|
|
42
|
+
* chain id and the version values provided by the wallet.
|
|
43
|
+
*
|
|
44
|
+
* @param messageHashOrIntent - The message hash of the intent to approve
|
|
37
45
|
* @returns The authentication witness
|
|
38
46
|
*/
|
|
39
|
-
async createAuthWit(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
chainId?: Fr;
|
|
50
|
-
/** The version to approve */
|
|
51
|
-
version?: Fr;
|
|
52
|
-
},
|
|
53
|
-
): Promise<AuthWitness> {
|
|
54
|
-
const messageHash = this.getMessageHash(messageHashOrIntent);
|
|
47
|
+
async createAuthWit(messageHashOrIntent: Fr | Buffer | IntentAction | IntentInnerHash): Promise<AuthWitness> {
|
|
48
|
+
let messageHash: Fr;
|
|
49
|
+
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
50
|
+
messageHash = Fr.fromBuffer(messageHashOrIntent);
|
|
51
|
+
} else if (messageHashOrIntent instanceof Fr) {
|
|
52
|
+
messageHash = messageHashOrIntent;
|
|
53
|
+
} else {
|
|
54
|
+
messageHash = this.getMessageHash(messageHashOrIntent);
|
|
55
|
+
}
|
|
56
|
+
|
|
55
57
|
const witness = await this.account.createAuthWit(messageHash);
|
|
56
58
|
await this.pxe.addAuthWitness(witness);
|
|
57
59
|
return witness;
|
|
@@ -59,129 +61,92 @@ export class AccountWallet extends BaseWallet {
|
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* Returns a function interaction to set a message hash as authorized or revoked in this account.
|
|
64
|
+
*
|
|
62
65
|
* Public calls can then consume this authorization.
|
|
63
|
-
*
|
|
66
|
+
*
|
|
67
|
+
* @param messageHashOrIntent - The message hash or intent to authorize/revoke
|
|
64
68
|
* @param authorized - True to authorize, false to revoke authorization.
|
|
65
69
|
* @returns - A function interaction.
|
|
66
70
|
*/
|
|
67
71
|
public setPublicAuthWit(
|
|
68
|
-
messageHashOrIntent:
|
|
69
|
-
| Fr
|
|
70
|
-
| Buffer
|
|
71
|
-
| {
|
|
72
|
-
/** The caller to approve */
|
|
73
|
-
caller: AztecAddress;
|
|
74
|
-
/** The action to approve */
|
|
75
|
-
action: ContractFunctionInteraction | FunctionCall;
|
|
76
|
-
/** The chain id to approve */
|
|
77
|
-
chainId?: Fr;
|
|
78
|
-
/** The version to approve */
|
|
79
|
-
version?: Fr;
|
|
80
|
-
},
|
|
72
|
+
messageHashOrIntent: Fr | Buffer | IntentInnerHash | IntentAction,
|
|
81
73
|
authorized: boolean,
|
|
82
74
|
): ContractFunctionInteraction {
|
|
83
|
-
|
|
75
|
+
let messageHash: Fr;
|
|
76
|
+
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
77
|
+
messageHash = Fr.fromBuffer(messageHashOrIntent);
|
|
78
|
+
} else if (messageHashOrIntent instanceof Fr) {
|
|
79
|
+
messageHash = messageHashOrIntent;
|
|
80
|
+
} else {
|
|
81
|
+
messageHash = this.getMessageHash(messageHashOrIntent);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
return new ContractFunctionInteraction(this, AuthRegistryAddress, this.getSetAuthorizedAbi(), [
|
|
85
|
-
|
|
85
|
+
messageHash,
|
|
86
86
|
authorized,
|
|
87
87
|
]);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/** The version to approve */
|
|
107
|
-
version?: Fr;
|
|
108
|
-
},
|
|
109
|
-
): ContractFunctionInteraction {
|
|
110
|
-
return this.setPublicAuthWit(messageHashOrIntent, false);
|
|
90
|
+
private getInnerHashAndConsumer(intent: IntentInnerHash | IntentAction): {
|
|
91
|
+
/** The inner hash */
|
|
92
|
+
innerHash: Fr;
|
|
93
|
+
/** The consumer of the authwit */
|
|
94
|
+
consumer: AztecAddress;
|
|
95
|
+
} {
|
|
96
|
+
if ('caller' in intent && 'action' in intent) {
|
|
97
|
+
const action = intent.action instanceof ContractFunctionInteraction ? intent.action.request() : intent.action;
|
|
98
|
+
return {
|
|
99
|
+
innerHash: computeInnerAuthWitHashFromAction(intent.caller, action),
|
|
100
|
+
consumer: action.to,
|
|
101
|
+
};
|
|
102
|
+
} else if (Buffer.isBuffer(intent.innerHash)) {
|
|
103
|
+
return { innerHash: Fr.fromBuffer(intent.innerHash), consumer: intent.consumer };
|
|
104
|
+
}
|
|
105
|
+
return { innerHash: intent.innerHash, consumer: intent.consumer };
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
/**
|
|
114
|
-
* Returns the message hash for the given
|
|
115
|
-
*
|
|
109
|
+
* Returns the message hash for the given intent
|
|
110
|
+
*
|
|
111
|
+
* @param intent - A tuple of (consumer and inner hash) or (caller and action)
|
|
116
112
|
* @returns The message hash
|
|
117
113
|
*/
|
|
118
|
-
private getMessageHash(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
| {
|
|
123
|
-
/** The caller to approve */
|
|
124
|
-
caller: AztecAddress;
|
|
125
|
-
/** The action to approve */
|
|
126
|
-
action: ContractFunctionInteraction | FunctionCall;
|
|
127
|
-
/** The chain id to approve */
|
|
128
|
-
chainId?: Fr;
|
|
129
|
-
/** The version to approve */
|
|
130
|
-
version?: Fr;
|
|
131
|
-
},
|
|
132
|
-
): Fr {
|
|
133
|
-
if (Buffer.isBuffer(messageHashOrIntent)) {
|
|
134
|
-
return Fr.fromBuffer(messageHashOrIntent);
|
|
135
|
-
} else if (messageHashOrIntent instanceof Fr) {
|
|
136
|
-
return messageHashOrIntent;
|
|
137
|
-
} else {
|
|
138
|
-
return computeAuthWitMessageHash(
|
|
139
|
-
messageHashOrIntent.caller,
|
|
140
|
-
messageHashOrIntent.chainId || this.getChainId(),
|
|
141
|
-
messageHashOrIntent.version || this.getVersion(),
|
|
142
|
-
messageHashOrIntent.action instanceof ContractFunctionInteraction
|
|
143
|
-
? messageHashOrIntent.action.request()
|
|
144
|
-
: messageHashOrIntent.action,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
114
|
+
private getMessageHash(intent: IntentInnerHash | IntentAction): Fr {
|
|
115
|
+
const chainId = this.getChainId();
|
|
116
|
+
const version = this.getVersion();
|
|
117
|
+
return computeAuthWitMessageHash(intent, { chainId, version });
|
|
147
118
|
}
|
|
148
119
|
|
|
149
120
|
/**
|
|
150
121
|
* Lookup the validity of an authwit in private and public contexts.
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
122
|
+
*
|
|
123
|
+
* Uses the chain id and version of the wallet.
|
|
124
|
+
*
|
|
125
|
+
* @param onBehalfOf - The address of the "approver"
|
|
126
|
+
* @param intent - The consumer and inner hash or the caller and action to lookup
|
|
127
|
+
*
|
|
154
128
|
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
155
129
|
*/
|
|
156
130
|
async lookupValidity(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
| Fr
|
|
160
|
-
| Buffer
|
|
161
|
-
| {
|
|
162
|
-
/** The caller to approve */
|
|
163
|
-
caller: AztecAddress;
|
|
164
|
-
/** The action to approve */
|
|
165
|
-
action: ContractFunctionInteraction | FunctionCall;
|
|
166
|
-
/** The chain id to approve */
|
|
167
|
-
chainId?: Fr;
|
|
168
|
-
/** The version to approve */
|
|
169
|
-
version?: Fr;
|
|
170
|
-
},
|
|
131
|
+
onBehalfOf: AztecAddress,
|
|
132
|
+
intent: IntentInnerHash | IntentAction,
|
|
171
133
|
): Promise<{
|
|
172
134
|
/** boolean flag indicating if the authwit is valid in private context */
|
|
173
135
|
isValidInPrivate: boolean;
|
|
174
136
|
/** boolean flag indicating if the authwit is valid in public context */
|
|
175
137
|
isValidInPublic: boolean;
|
|
176
138
|
}> {
|
|
177
|
-
const
|
|
139
|
+
const { innerHash, consumer } = this.getInnerHashAndConsumer(intent);
|
|
140
|
+
|
|
141
|
+
const messageHash = this.getMessageHash(intent);
|
|
178
142
|
const results = { isValidInPrivate: false, isValidInPublic: false };
|
|
179
143
|
|
|
180
144
|
// Check private
|
|
181
145
|
const witness = await this.getAuthWitness(messageHash);
|
|
182
146
|
if (witness !== undefined) {
|
|
183
|
-
results.isValidInPrivate = (await new ContractFunctionInteraction(this,
|
|
184
|
-
|
|
147
|
+
results.isValidInPrivate = (await new ContractFunctionInteraction(this, onBehalfOf, this.getLookupValidityAbi(), [
|
|
148
|
+
consumer,
|
|
149
|
+
innerHash,
|
|
185
150
|
]).simulate()) as boolean;
|
|
186
151
|
}
|
|
187
152
|
|
|
@@ -190,7 +155,7 @@ export class AccountWallet extends BaseWallet {
|
|
|
190
155
|
this,
|
|
191
156
|
AuthRegistryAddress,
|
|
192
157
|
this.getIsConsumableAbi(),
|
|
193
|
-
[
|
|
158
|
+
[onBehalfOf, messageHash],
|
|
194
159
|
).simulate()) as boolean;
|
|
195
160
|
|
|
196
161
|
return results;
|
|
@@ -220,31 +185,6 @@ export class AccountWallet extends BaseWallet {
|
|
|
220
185
|
await interaction.send().wait();
|
|
221
186
|
}
|
|
222
187
|
|
|
223
|
-
/**
|
|
224
|
-
* Returns a function interaction to cancel a message hash as authorized in this account.
|
|
225
|
-
* @param messageHashOrIntent - The message or the caller and action to authorize/revoke
|
|
226
|
-
* @returns - A function interaction.
|
|
227
|
-
*/
|
|
228
|
-
public cancelAuthWit(
|
|
229
|
-
messageHashOrIntent:
|
|
230
|
-
| Fr
|
|
231
|
-
| Buffer
|
|
232
|
-
| {
|
|
233
|
-
/** The caller to approve */
|
|
234
|
-
caller: AztecAddress;
|
|
235
|
-
/** The action to approve */
|
|
236
|
-
action: ContractFunctionInteraction | FunctionCall;
|
|
237
|
-
/** The chain id to approve */
|
|
238
|
-
chainId?: Fr;
|
|
239
|
-
/** The version to approve */
|
|
240
|
-
version?: Fr;
|
|
241
|
-
},
|
|
242
|
-
): ContractFunctionInteraction {
|
|
243
|
-
const message = this.getMessageHash(messageHashOrIntent);
|
|
244
|
-
const args = [message];
|
|
245
|
-
return new ContractFunctionInteraction(this, this.getAddress(), this.getCancelAuthwitAbi(), args);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
188
|
/** Returns the complete address of the account that implements this wallet. */
|
|
249
189
|
public getCompleteAddress() {
|
|
250
190
|
return this.account.getCompleteAddress();
|
|
@@ -278,24 +218,6 @@ export class AccountWallet extends BaseWallet {
|
|
|
278
218
|
};
|
|
279
219
|
}
|
|
280
220
|
|
|
281
|
-
private getCancelAuthwitAbi(): FunctionAbi {
|
|
282
|
-
return {
|
|
283
|
-
name: 'cancel_authwit',
|
|
284
|
-
isInitializer: false,
|
|
285
|
-
functionType: FunctionType.PRIVATE,
|
|
286
|
-
isInternal: true,
|
|
287
|
-
isStatic: false,
|
|
288
|
-
parameters: [
|
|
289
|
-
{
|
|
290
|
-
name: 'message_hash',
|
|
291
|
-
type: { kind: 'field' },
|
|
292
|
-
visibility: 'private' as ABIParameterVisibility,
|
|
293
|
-
},
|
|
294
|
-
],
|
|
295
|
-
returnTypes: [],
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
|
|
299
221
|
private getLookupValidityAbi(): FunctionAbi {
|
|
300
222
|
return {
|
|
301
223
|
name: 'lookup_validity',
|