Permission
A wallet permission (EIP-2255): a method the user lets an app call, with the caveats that restrict it. The module also holds the request an app makes to get or give back permissions.
import { Effect } from "effect";import { Wallet } from "@ethect/core/rpc";
const methods = Effect.gen(function* () { const permissions = yield* Wallet.getPermissions(); // permissions: ReadonlyArray<Permission.Permission> return permissions.map((permission) => permission.parentCapability);});Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
Permission.schema |
Permission.Permission |
a permission to call one method | returned by Wallet.getPermissions and Wallet.requestPermissions |
Permission.caveatSchema |
Permission.Caveat |
a restriction on a permitted method | the caveats of a permission |
Permission.requestSchema |
Permission.Request |
the permissions to ask for or to revoke | passed to Wallet.requestPermissions and Wallet.revokePermissions |
Permission fields
Section titled “Permission fields”| Field | Type | Notes |
|---|---|---|
parentCapability |
string |
the method the permission is for, such as "eth_accounts" |
invoker |
string (optional) |
the origin of the app the permission was given to |
caveats |
ReadonlyArray<Permission.Caveat> (optional) |
the restrictions on the method |
id |
string (optional) |
|
date |
number (optional) |
the time of the request, as a timestamp |
Caveat fields
Section titled “Caveat fields”| Field | Type | Notes |
|---|---|---|
type |
string |
the kind of restriction |
value |
unknown |
what it holds depends on type |
Request
Section titled “Request”A Permission.Request is a record: by method name, the caveats wanted on it, by caveat name.
import { type Permission, Wallet } from "@ethect/core/rpc";
// the accounts, with no caveatconst request: Permission.Request = { eth_accounts: {} };
const asked = Wallet.requestPermissions(request);Behavior
Section titled “Behavior”- A wallet tells what it wants. Only
parentCapabilityis required. MetaMask sends every field, with the permitted accounts in arestrictReturnedAccountscaveat. Rabby only names the method. - Caveat values are open.
valueis typedunknown: decode it with a schema of your own before use. - Unknown fields are dropped. A field the schema does not know is not in the result.
- Not a grant. The permissions a session key gets through
wallet_grantPermissionsare another type: seePermissionGrant.
Decode the accounts of a restrictReturnedAccounts caveat with Address.wireSchema.
import { Effect, Schema } from "effect";import { Address } from "@ethect/core";import { Wallet } from "@ethect/core/rpc";
const permitted = Effect.gen(function* () { const permissions = yield* Wallet.getPermissions(); const caveat = permissions .flatMap((permission) => permission.caveats ?? []) .find((caveat) => caveat.type === "restrictReturnedAccounts"); const decode = Schema.decodeUnknownEffect(Schema.Array(Address.wireSchema)); return yield* decode(caveat?.value ?? []);});