-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation wallet_grantPermissions based on Appkit spec (#723)
* refactor ContextBuilderUtil * chores: build fix * implement userOpBuilder service as per new spec * remove use of mockvalidator from contextBuilderUtils * add ContractCallPermissions types * add ERC5792 support for baseSepolia * update WalletConnectCosigner as per new spec * fix request/response types for UserOpBuilderService * fix: walletClient in grantPermissions impl * chores: remove comments * refactor ContextBuilderUtils * remove _middleware.ts * handle grantPermissions error response * change api to handle JSON rpc call for wallet_prepareCalls and wallet_sendPreparedCalls * add passkey dummy signature support for UserOpBuilder * chore: refactor and type fixes * add permissions capabilities for SCA * chores: rename and remove unused types. * chores: refactor and deps update * chores:fix names
- Loading branch information
1 parent
b6a244c
commit b7c1ec6
Showing
19 changed files
with
1,130 additions
and
888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 74 additions & 60 deletions
134
advanced/wallets/react-wallet-v2/src/data/EIP7715Data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,96 @@ | ||
import { Address } from 'viem' | ||
|
||
/** | ||
* EIP7715Method | ||
*/ | ||
export const EIP7715_METHOD = { | ||
WALLET_GRANT_PERMISSIONS: 'wallet_grantPermissions' | ||
} | ||
|
||
// `data` is not necessary for this signer type as the wallet is both the signer and grantor of these permissions | ||
export type WalletSigner = { | ||
type: 'wallet' | ||
data: {} | ||
} | ||
|
||
// A signer representing a single key. | ||
// `id` is a did:key identifier and can therefore represent both Secp256k1 or Secp256r1 keys, among other key types. | ||
export type KeySigner = { | ||
type: 'key' | ||
data: { | ||
id: string | ||
} | ||
export type Signer = MultiKeySigner | ||
export type KeyType = 'secp256k1' | 'secp256r1' | ||
// The types of keys that are supported for the following `key` and `keys` signer types. | ||
export enum SignerKeyType { | ||
SECP256K1 = 0, // EOA - k1 | ||
SECP256R1 = 1 // Passkey - r1 | ||
} | ||
|
||
// A signer representing a multisig signer. | ||
// Each element of `ids` is a did:key identifier just like the `key` signer. | ||
/* | ||
* A signer representing a multisig signer. | ||
* Each element of `publicKeys` are all explicitly the same `KeyType`, and the public keys are hex-encoded. | ||
*/ | ||
export type MultiKeySigner = { | ||
type: 'keys' | ||
data: { | ||
ids: string[] | ||
address?: Address | ||
keys: { | ||
type: KeyType | ||
publicKey: `0x${string}` | ||
}[] | ||
} | ||
} | ||
|
||
// An account that can be granted with permissions as in ERC-7710. | ||
export type AccountSigner = { | ||
type: 'account' | ||
data: { | ||
id: `0x${string}` | ||
} | ||
export type Policy = { | ||
type: string | ||
data: Record<string, unknown> | ||
} | ||
// Enum for parameter operators | ||
enum ParamOperator { | ||
EQUAL = 'EQUAL', | ||
GREATER_THAN = 'GREATER_THAN', | ||
LESS_THAN = 'LESS_THAN' | ||
// Add other operators as needed | ||
} | ||
|
||
export enum SignerType { | ||
EOA, | ||
PASSKEY | ||
// Enum for operation types | ||
enum Operation { | ||
Call = 'Call', | ||
DelegateCall = 'DelegateCall' | ||
} | ||
|
||
export type Signer = { | ||
type: SignerType | ||
data: string | ||
// Type for a single argument condition | ||
type ArgumentCondition = { | ||
operator: ParamOperator | ||
value: any // You might want to be more specific based on your use case | ||
} | ||
|
||
export type Permission = { | ||
type: PermissionType | ||
policies: Policy[] | ||
required: boolean | ||
data: any | ||
// Type for a single function permission | ||
type FunctionPermission = { | ||
functionName: string // Function name | ||
args: ArgumentCondition[] // An array of conditions, each corresponding to an argument for the function | ||
valueLimit: bigint // Maximum value that can be transferred for this specific function call | ||
operation?: Operation // (optional) whether this is a call or a delegatecall. Defaults to call | ||
} | ||
export type Policy = { | ||
type: PolicyType | ||
data: any | ||
export type ContractCallPermission = { | ||
type: 'contract-call' | ||
data: { | ||
address: `0x${string}` | ||
abi: Record<string, unknown>[] | ||
functions: FunctionPermission[] | ||
} | ||
} | ||
|
||
// Union type for all possible permissions | ||
export type Permission = ContractCallPermission | ||
|
||
export type WalletGrantPermissionsRequest = { | ||
chainId: `0x${string}` | ||
address?: `0x${string}` | ||
expiry: number | ||
signer: Signer | ||
permissions: Permission[] | ||
policies: { | ||
type: string | ||
data: Record<string, unknown> | ||
}[] | ||
} | ||
|
||
export type WalletGrantPermissionsResponse = WalletGrantPermissionsRequest & { | ||
context: `0x${string}` | ||
accountMeta?: { | ||
factory: `0x${string}` | ||
factoryData: `0x${string}` | ||
} | ||
signerMeta?: { | ||
// 7679 userOp building | ||
userOpBuilder?: `0x${string}` | ||
// 7710 delegation | ||
delegationManager?: `0x${string}` | ||
} | ||
} | ||
export type PermissionType = | ||
| 'native-token-transfer' | ||
| 'erc20-token-transfer' | ||
| 'erc721-token-transfer' | ||
| 'erc1155-token-transfer' | ||
| { | ||
custom: any | ||
} | ||
export type PolicyType = | ||
| 'gas-limit' | ||
| 'call-limit' | ||
| 'rate-limit' | ||
| 'spent-limit' | ||
| 'value-limit' | ||
| 'time-frame' | ||
| 'uni-action' | ||
| 'simpler-signer' | ||
| { | ||
custom: any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.