Skip to content

Commit 344bbb4

Browse files
Update API reference
* lock files for v0.1 * update delegation API reference
1 parent 1a5b875 commit 344bbb4

File tree

5 files changed

+144
-27
lines changed

5 files changed

+144
-27
lines changed

gator_versioned_docs/version-0.1.0/guides/advanced-permissions/execute-on-metamask-users-behalf.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ const sessionAccount = privateKeyToAccount("0x...");
9696

9797
### 4. Check the EOA account code
9898

99-
Currently, Advanced Permissions do not support automatically upgrading a MetaMask user's account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must
100-
ensure that the user is upgraded to a smart account before requesting Advanced Permissions.
99+
Advanced Permissions support the automatic upgrading of a MetaMask user's account to a [MetaMask smart account](../../concepts/smart-accounts.md),
100+
when using MetaMask Flask version 13.9.0 or later. For earlier versions, you must ensure that the
101+
user is upgraded to a smart account before requesting Advanced Permissions.
101102

102103
If the user has not yet been upgraded, you can handle the upgrade [programmatically](/wallet/how-to/send-transactions/send-batch-transactions/#about-atomic-batch-transactions) or ask the
103104
user to [switch to a smart account manually](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account).
@@ -139,9 +140,11 @@ if (code) {
139140

140141
### 5. Request Advanced Permissions
141142

142-
Request Advanced Permissions from the user. In this example, you'll request an
143-
[ERC-20 periodic permission](use-permissions/erc20-token.md#erc-20-periodic-permission) using the Wallet Client's
144-
[`requestExecutionPermissions`](../../reference/advanced-permissions/wallet-client.md#requestexecutionpermissions) action.
143+
Request Advanced Permissions from the user using the Wallet Client's `requestExecutionPermissions` action.
144+
In this example, you'll request an
145+
[ERC-20 periodic permission](use-permissions/erc20-token.md#erc-20-periodic-permission).
146+
147+
See the [`requestExecutionPermissions`](../../reference/advanced-permissions/wallet-client.md#requestexecutionpermissions) API reference for more information.
145148

146149
```typescript
147150
import { sepolia as chain } from "viem/chains";
@@ -233,8 +236,10 @@ const sessionAccountWalletClient = createWalletClient({
233236
The session account can now redeem the permissions. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.
234237

235238
To redeem the permissions, use the client action based on your session account type.
236-
A smart account uses the Bundler Client's [`sendUserOperationWithDelegation`](../../reference/advanced-permissions/bundler-client.md#senduseroperationwithdelegation) action,
237-
and an EOA uses the Wallet Client's [`sendTransactionWithDelegation`](../../reference/advanced-permissions/wallet-client.md#sendtransactionwithdelegation) action:
239+
A smart account uses the Bundler Client's `sendUserOperationWithDelegation` action,
240+
and an EOA uses the Wallet Client's `sendTransactionWithDelegation` action.
241+
242+
See the [`sendUserOperationWithDelegation`](../../reference/advanced-permissions/bundler-client.md#senduseroperationwithdelegation) and [`sendTransactionWithDelegation`](../../reference/advanced-permissions/wallet-client.md#sendtransactionwithdelegation) API reference for more information.
238243

239244
<Tabs>
240245
<TabItem value="Smart account">

gator_versioned_docs/version-0.1.0/guides/advanced-permissions/use-permissions/erc20-token.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ This permission type ensures a per-period limit for ERC-20 token transfers. At t
2424
For example, a user signs an ERC-7715 permission that lets a dapp spend up to 10 USDC on their behalf each day. The dapp can transfer a total of
2525
10 USDC per day; the limit resets at the beginning of the next day.
2626

27+
See the [ERC-20 periodic permission API reference](../../../reference/advanced-permissions/permissions.md#erc-20-periodic-permission) for more information.
28+
2729
<Tabs>
2830
<TabItem value="example.ts">
2931

@@ -92,6 +94,8 @@ configured rate, up to the maximum allowed amount.
9294
For example, a user signs an ERC-7715 permission that allows a dapp to spend 0.1 USDC per second, starting with an initial amount
9395
of 1 USDC, up to a maximum of 2 USDC.
9496

97+
See the [ERC-20 stream permission API reference](../../../reference/advanced-permissions/permissions.md#erc-20-stream-permission) for more information.
98+
9599
<Tabs>
96100
<TabItem value="example.ts">
97101

gator_versioned_docs/version-0.1.0/guides/advanced-permissions/use-permissions/native-token.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ This permission type ensures a per-period limit for native token transfers. At t
2424
For example, a user signs an ERC-7715 permission that lets a dapp spend up to 0.001 ETH on their behalf each day. The dapp can transfer a total of
2525
0.001 USDC per day; the limit resets at the beginning of the next day.
2626

27+
See the [native token periodic permission API reference](../../../reference/advanced-permissions/permissions.md#native-token-periodic-permission) for more information.
28+
2729
<Tabs>
2830
<TabItem value="example.ts">
2931

@@ -89,6 +91,8 @@ configured rate, up to the maximum allowed amount.
8991
For example, a user signs an ERC-7715 permission that allows a dapp to spend 0.0001 ETH per second, starting with an initial amount
9092
of 0.1 ETH, up to a maximum of 1 ETH.
9193

94+
See the [native token stream permission API reference](../../../reference/advanced-permissions/permissions.md#native-token-stream-permission) for more information.
95+
9296
<Tabs>
9397
<TabItem value="example.ts">
9498

gator_versioned_docs/version-0.1.0/reference/delegation/index.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,62 @@ export const delegation = createDelegation({
315315
</TabItem>
316316
</Tabs>
317317

318+
319+
## `getDelegationHashOffchain`
320+
321+
Returns the delegation hash.
322+
323+
### Parameters
324+
325+
| Name | Type | Required | Description |
326+
| --- | --- | --- | --- |
327+
| `input` | `Delegation` | Yes | The delegation object to hash. |
328+
329+
### Example
330+
331+
<Tabs>
332+
<TabItem value ="example.ts">
333+
334+
```ts
335+
import { getDelegationHashOffchain } from "@metamask/smart-accounts-kit/utils";
336+
import { delegation } from "./config.ts";
337+
338+
const delegationHash = getDelegationHashOffchain(delegation);
339+
```
340+
341+
</TabItem>
342+
<TabItem value ="config.ts">
343+
344+
```ts
345+
import {
346+
getSmartAccountsEnvironment,
347+
createDelegation,
348+
} from "@metamask/smart-accounts-kit";
349+
import { parseEther } from "viem";
350+
import { sepolia } from "viem/chains";
351+
352+
const environment = getSmartAccountsEnvironment(sepolia.id);
353+
354+
// The address to which the delegation is granted. It can be an EOA address, or
355+
// smart account address.
356+
const delegate = "0x2FcB88EC2359fA635566E66415D31dD381CF5585";
357+
358+
export const delegation = createDelegation({
359+
to: delegate,
360+
// Address that is granting the delegation.
361+
from: "0x7E48cA6b7fe6F3d57fdd0448B03b839958416fC1",
362+
environment,
363+
scope: {
364+
type: "nativeTokenTransferAmount",
365+
// 0.001 ETH in wei format.
366+
maxAmount: parseEther("0.001"),
367+
},
368+
});
369+
```
370+
371+
</TabItem>
372+
</Tabs>
373+
318374
## `getSmartAccountsEnvironment`
319375

320376
Resolves the `SmartAccountsEnvironment` for a chain.
@@ -419,12 +475,13 @@ Signs the delegation and returns the delegation signature.
419475

420476
| Name | Type | Required | Description |
421477
| --- | --- | --- | --- |
422-
| `signer` | `WalletClient` | Yes | [Viem Wallet Client](https://viem.sh/docs/clients/wallet#wallet-client) to sign the delegation. |
478+
| `privateKey` | `Hex` | Yes | The private key to use for signing the delegation. |
423479
| `delegation` | `Omit<Delegation, "signature">` | Yes | The unsigned delegation object to sign. |
424480
| `chainId` | `number` | Yes | The chain ID on which the delegation manager is deployed. |
425481
| `delegationManager` | `0x${string}` | Yes | The address of the Delegation Manager. |
426482
| `name` | `string` | No | The name of the domain of the Delegation Manager. The default is `DelegationManager`. |
427483
| `version` | `string` | No | The version of the domain of the Delegation Manager. The default is `1`. |
484+
| `allowInsecureUnrestrictedDelegation` | `boolean` | No | Whether to allow insecure unrestricted delegation with no caveats. The default is `false`. |
428485

429486
### Example
430487

@@ -433,11 +490,11 @@ Signs the delegation and returns the delegation signature.
433490

434491
```ts
435492
import { signDelegation } from "@metamask/smart-accounts-kit";
436-
import { walletClient, delegation, delegationManager } from "./config.ts";
493+
import { privateKey, delegation, delegationManager } from "./config.ts";
437494
import { sepolia } from "viem/chains";
438495

439496
const signature = signDelegation({
440-
signer: walletClient,
497+
privateKey,
441498
delegation,
442499
chainId: sepolia.id,
443500
delegationManager,
@@ -459,13 +516,8 @@ import { sepolia } from "viem/chains";
459516
const environment = getSmartAccountsEnvironment(sepolia.id);
460517
export const delegationManager = environment.DelegationManager;
461518

462-
const account = privateKeyToAccount(delegateWallet as `0x${string}`);
463-
464-
export const walletClient = createWalletClient({
465-
account,
466-
transport: http(),
467-
chain: sepolia,
468-
});
519+
export const privateKey = `0x12141..`;
520+
const account = privateKeyToAccount(privateKey);
469521

470522
// The address to which the delegation is granted. It can be an EOA address, or
471523
// smart account address.

smart-accounts-kit/reference/delegation/index.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,62 @@ export const delegation = createDelegation({
315315
</TabItem>
316316
</Tabs>
317317

318+
319+
## `getDelegationHashOffchain`
320+
321+
Returns the delegation hash.
322+
323+
### Parameters
324+
325+
| Name | Type | Required | Description |
326+
| --- | --- | --- | --- |
327+
| `input` | `Delegation` | Yes | The delegation object to hash. |
328+
329+
### Example
330+
331+
<Tabs>
332+
<TabItem value ="example.ts">
333+
334+
```ts
335+
import { getDelegationHashOffchain } from "@metamask/smart-accounts-kit/utils";
336+
import { delegation } from "./config.ts";
337+
338+
const delegationHash = getDelegationHashOffchain(delegation);
339+
```
340+
341+
</TabItem>
342+
<TabItem value ="config.ts">
343+
344+
```ts
345+
import {
346+
getSmartAccountsEnvironment,
347+
createDelegation,
348+
} from "@metamask/smart-accounts-kit";
349+
import { parseEther } from "viem";
350+
import { sepolia } from "viem/chains";
351+
352+
const environment = getSmartAccountsEnvironment(sepolia.id);
353+
354+
// The address to which the delegation is granted. It can be an EOA address, or
355+
// smart account address.
356+
const delegate = "0x2FcB88EC2359fA635566E66415D31dD381CF5585";
357+
358+
export const delegation = createDelegation({
359+
to: delegate,
360+
// Address that is granting the delegation.
361+
from: "0x7E48cA6b7fe6F3d57fdd0448B03b839958416fC1",
362+
environment,
363+
scope: {
364+
type: "nativeTokenTransferAmount",
365+
// 0.001 ETH in wei format.
366+
maxAmount: parseEther("0.001"),
367+
},
368+
});
369+
```
370+
371+
</TabItem>
372+
</Tabs>
373+
318374
## `getSmartAccountsEnvironment`
319375

320376
Resolves the `SmartAccountsEnvironment` for a chain.
@@ -419,12 +475,13 @@ Signs the delegation and returns the delegation signature.
419475

420476
| Name | Type | Required | Description |
421477
| --- | --- | --- | --- |
422-
| `signer` | `WalletClient` | Yes | [Viem Wallet Client](https://viem.sh/docs/clients/wallet#wallet-client) to sign the delegation. |
478+
| `privateKey` | `Hex` | Yes | The private key to use for signing the delegation. |
423479
| `delegation` | `Omit<Delegation, "signature">` | Yes | The unsigned delegation object to sign. |
424480
| `chainId` | `number` | Yes | The chain ID on which the delegation manager is deployed. |
425481
| `delegationManager` | `0x${string}` | Yes | The address of the Delegation Manager. |
426482
| `name` | `string` | No | The name of the domain of the Delegation Manager. The default is `DelegationManager`. |
427483
| `version` | `string` | No | The version of the domain of the Delegation Manager. The default is `1`. |
484+
| `allowInsecureUnrestrictedDelegation` | `boolean` | No | Whether to allow insecure unrestricted delegation with no caveats. The default is `false`. |
428485

429486
### Example
430487

@@ -433,11 +490,11 @@ Signs the delegation and returns the delegation signature.
433490

434491
```ts
435492
import { signDelegation } from "@metamask/smart-accounts-kit";
436-
import { walletClient, delegation, delegationManager } from "./config.ts";
493+
import { privateKey, delegation, delegationManager } from "./config.ts";
437494
import { sepolia } from "viem/chains";
438495

439496
const signature = signDelegation({
440-
signer: walletClient,
497+
privateKey,
441498
delegation,
442499
chainId: sepolia.id,
443500
delegationManager,
@@ -459,13 +516,8 @@ import { sepolia } from "viem/chains";
459516
const environment = getSmartAccountsEnvironment(sepolia.id);
460517
export const delegationManager = environment.DelegationManager;
461518

462-
const account = privateKeyToAccount(delegateWallet as `0x${string}`);
463-
464-
export const walletClient = createWalletClient({
465-
account,
466-
transport: http(),
467-
chain: sepolia,
468-
});
519+
export const privateKey = `0x12141..`;
520+
const account = privateKeyToAccount(privateKey);
469521

470522
// The address to which the delegation is granted. It can be an EOA address, or
471523
// smart account address.

0 commit comments

Comments
 (0)