Skip to content

PermissionGrant

Permissions for a session key or account to act for a user, as wallet_grantPermissions exchanges them (ERC-7715, a draft): what the app asks for, and what the wallet granted.

import { Effect } from "effect";
import { type PermissionGrant, Wallet } from "@ethect/core/rpc";
const payload: PermissionGrant.Payload = {
// a Unix timestamp, in seconds
expiry: 1716846083,
permissions: [
{
type: "native-token-transfer",
data: { ticker: "ETH" },
policies: [{ type: "token-allowance", data: { allowance: "0xde0b6b3a7640000" } }],
},
],
signer: {
type: "key",
data: { id: "did:key:zDnaerDaTF5BXEavCrfRZEk316dpbLsfPDZ3WJ5hRTPFU2169" },
},
};
const context = Wallet.grantPermissions(payload).pipe(
// grant: PermissionGrant.PermissionGrant
Effect.map((grant) => grant.permissionsContext),
);
Schema Type Describes Used by
PermissionGrant.payloadSchema PermissionGrant.Payload what to grant, until when and to whom passed to Wallet.grantPermissions
PermissionGrant.schema PermissionGrant.PermissionGrant what the wallet granted returned by Wallet.grantPermissions
PermissionGrant.permissionSchema PermissionGrant.Permission one permission, with its policies the entries of permissions and of grantedPermissions

PermissionGrant.Payload, what the app asks for.

Field Type Notes
expiry number a Unix timestamp in seconds
permissions ReadonlyArray<PermissionGrant.Permission> each in the shape below
signer { type: string, data?: unknown } (optional) who gets the permissions: a key, several keys, an account, or the wallet itself

PermissionGrant.PermissionGrant, what the wallet answers.

Field Type Notes
expiry number a Unix timestamp in seconds
grantedPermissions ReadonlyArray<PermissionGrant.Permission> each in the shape below
permissionsContext string identifies the grant when using it
factory Address (optional) deploys the account that holds the grant, if it is not deployed yet
factoryData string (optional) the calldata for factory
signerData { userOpBuilder?: Address, submitToAddress?: Address } (optional)

PermissionGrant.Permission, one entry of permissions or of grantedPermissions.

import type { PermissionGrant } from "@ethect/core/rpc";
const kind = (permission: PermissionGrant.Permission) => permission.type;
/** The kinds of permission a wallet granted. */
const kinds = (grant: PermissionGrant.PermissionGrant) =>
grant.grantedPermissions.map(kind);
Field Type Notes
type string the kind of permission
data unknown what it holds depends on type
policies ReadonlyArray<{ type: string, data: unknown }> the limits that narrow the permission
required boolean (optional)
  • A draft, in its earlier shape. The ERC has since been rewritten around another method, wallet_requestExecutionPermissions. This type is the shape that wallets serving wallet_grantPermissions speak.
  • Only the envelope is typed. What a permission, a policy or a signer holds is unknown: it is sent as you wrote it, and comes back as the wallet sent it.
  • Less than asked. grantedPermissions is what the wallet granted, which may be less than the permissions of the payload.
  • Timestamps are numbers. expiry is a JSON number, not a hex quantity.
  • Not an EIP-2255 permission. The permissions on a wallet’s methods are another type: see Permission.