-
Notifications
You must be signed in to change notification settings - Fork 390
Implementation wallet_grantPermissions based on Appkit spec #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c14e598
refactor ContextBuilderUtil
KannuSingh 7fa12c0
chores: build fix
KannuSingh fc01314
implement userOpBuilder service as per new spec
KannuSingh b0c01a0
remove use of mockvalidator from contextBuilderUtils
KannuSingh 62afeba
add ContractCallPermissions types
KannuSingh e06f873
add ERC5792 support for baseSepolia
KannuSingh a40c79a
update WalletConnectCosigner as per new spec
KannuSingh ad106b6
fix request/response types for UserOpBuilderService
KannuSingh 0cfcd4e
fix: walletClient in grantPermissions impl
KannuSingh 28c4f5d
chores: remove comments
KannuSingh 4dc8d2b
refactor ContextBuilderUtils
KannuSingh 8231010
remove _middleware.ts
KannuSingh bc59012
Merge branch 'main' into smart-session-prod-support
KannuSingh a90dd34
handle grantPermissions error response
KannuSingh 8d386f0
change api to handle JSON rpc call for wallet_prepareCalls and wallet…
KannuSingh 701efc4
add passkey dummy signature support for UserOpBuilder
KannuSingh 56adf61
chore: refactor and type fixes
KannuSingh f29060d
add permissions capabilities for SCA
KannuSingh 7e0ea5f
chores: rename and remove unused types.
KannuSingh a20c672
chores: refactor and deps update
KannuSingh 496c419
chores:fix names
KannuSingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
206 changes: 162 additions & 44 deletions
206
advanced/wallets/react-wallet-v2/src/data/EIP7715Data.ts
This file contains hidden or 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,200 @@ | ||
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 Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner | ||
export type KeyType = 'secp256k1' | 'secp256r1' | 'ed25519' | 'schonorr' | ||
// 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 | ||
ED25519 = 3, | ||
SCHNORR = 4 | ||
} | ||
/* | ||
* A wallet is the signer for these permissions | ||
* `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: {} | ||
data: Record<string, unknown> | ||
} | ||
|
||
// 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. | ||
/* | ||
* A signer representing a single key. | ||
* "Key" types are explicitly secp256r1 (p256) or secp256k1, and the public keys are hex-encoded. | ||
*/ | ||
export type KeySigner = { | ||
type: 'key' | ||
data: { | ||
id: string | ||
type: KeyType | ||
publicKey: `0x${string}` | ||
} | ||
} | ||
|
||
// 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}` | ||
address: `0x${string}` | ||
} | ||
} | ||
|
||
export enum SignerType { | ||
EOA, | ||
PASSKEY | ||
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 | ||
} | ||
|
||
// 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 PermissionType = | ||
| 'native-token-transfer' | ||
| 'erc20-token-transfer' | ||
| 'erc721-token-transfer' | ||
| 'erc1155-token-transfer' | ||
| { | ||
custom: any | ||
export type ContractCallPermission = { | ||
type: 'contract-call' | ||
data: { | ||
address: `0x${string}` | ||
abi: Record<string, unknown>[] | ||
functions: FunctionPermission[] | ||
} | ||
} | ||
// Native token transfer, e.g. ETH on Ethereum | ||
export type NativeTokenTransferPermission = { | ||
type: 'native-token-transfer' | ||
data: { | ||
allowance: `0x${string}` // hex value | ||
} | ||
} | ||
|
||
// ERC20 token transfer | ||
export type ERC20TokenTransferPermission = { | ||
type: 'erc20-token-transfer' | ||
data: { | ||
address: `0x${string}` // erc20 contract | ||
allowance: `0x${string}` // hex value | ||
} | ||
} | ||
|
||
// ERC721 token transfer | ||
export type ERC721TokenTransferPermission = { | ||
type: 'erc721-token-transfer' | ||
data: { | ||
address: `0x${string}` // erc721 contract | ||
tokenIds: `0x${string}`[] // hex value array | ||
} | ||
} | ||
|
||
// ERC1155 token transfer | ||
export type ERC1155TokenTransferPermission = { | ||
type: 'erc1155-token-transfer' | ||
data: { | ||
address: `0x${string}` // erc1155 contract | ||
allowances: { | ||
[tokenId: string]: `0x${string}` // hex value | ||
} | ||
export type PolicyType = | ||
| 'gas-limit' | ||
| 'call-limit' | ||
| 'rate-limit' | ||
| 'spent-limit' | ||
| 'value-limit' | ||
| 'time-frame' | ||
| 'uni-action' | ||
| 'simpler-signer' | ||
} | ||
} | ||
|
||
// The maximum gas limit spent in the session in total | ||
export type GasLimitPermission = { | ||
type: 'gas-limit' | ||
data: { | ||
limit: `0x${string}` // hex value | ||
} | ||
} | ||
|
||
// The number of calls the session can make in total | ||
export type CallLimitPermission = { | ||
type: 'call-limit' | ||
data: { | ||
count: `0x${string}` // hex value | ||
} | ||
} | ||
|
||
// The number of calls the session can make during each interval | ||
export type RateLimitPermission = { | ||
type: 'rate-limit' | ||
data: { | ||
count: `0x${string}` //hex value: the number of times during each interval | ||
interval: `0x${string}` //hex value in seconds | ||
} | ||
} | ||
|
||
// Union type for all possible permissions | ||
export type Permission = | ||
| ContractCallPermission | ||
| NativeTokenTransferPermission | ||
| ERC20TokenTransferPermission | ||
| ERC721TokenTransferPermission | ||
| ERC1155TokenTransferPermission | ||
| GasLimitPermission | ||
| CallLimitPermission | ||
| RateLimitPermission | ||
| { | ||
custom: any | ||
type: string | ||
data: Record<string, unknown> | ||
} | ||
|
||
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}` | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we set up capabilities in this way?