Skip to content

Commit 4644ea1

Browse files
update delegation API reference
1 parent 7f22b72 commit 4644ea1

File tree

2 files changed

+124
-20
lines changed
  • gator_versioned_docs/version-0.1.0/reference/delegation
  • smart-accounts-kit/reference/delegation

2 files changed

+124
-20
lines changed

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)