Skip to content

Commit

Permalink
chores: rename and remove unused types.
Browse files Browse the repository at this point in the history
  • Loading branch information
KannuSingh committed Oct 2, 2024
1 parent f29060d commit 7e0ea5f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 199 deletions.
112 changes: 4 additions & 108 deletions advanced/wallets/react-wallet-v2/src/data/EIP7715Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,13 @@ export const EIP7715_METHOD = {
WALLET_GRANT_PERMISSIONS: 'wallet_grantPermissions'
}

export type Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner
export type KeyType = 'secp256k1' | 'secp256r1' | 'ed25519' | 'schonorr'
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
ED25519 = 3,
SCHNORR = 4
SECP256R1 = 1 // Passkey - r1
}
/*
* 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: Record<string, unknown>
}

/*
* 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: {
type: KeyType
publicKey: `0x${string}`
}
}

/*
* A signer representing a multisig signer.
* Each element of `publicKeys` are all explicitly the same `KeyType`, and the public keys are hex-encoded.
Expand All @@ -49,14 +26,6 @@ export type MultiKeySigner = {
}
}

// An account that can be granted with permissions as in ERC-7710.
export type AccountSigner = {
type: 'account'
data: {
address: `0x${string}`
}
}

export type Policy = {
type: string
data: Record<string, unknown>
Expand Down Expand Up @@ -96,82 +65,9 @@ export type ContractCallPermission = {
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
}
}
}

// 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
| {
type: string
data: Record<string, unknown>
}
export type Permission = ContractCallPermission

export type WalletGrantPermissionsRequest = {
chainId: `0x${string}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
parseAbi,
toHex
} from 'viem'
import { MultiKeySigner } from 'viem/_types/experimental/erc7715/types/signer'
import { ModuleType } from 'permissionless/actions/erc7579'
import {
MOCK_VALIDATOR_ADDRESSES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function getActionsFromPermissions(
): ActionData[] {
return permissions.reduce((actions: ActionData[], permission) => {
if (!isContractCallPermission(permission)) {
throw new Error(ERROR_MESSAGES.UNSUPPORTED_PERMISSION_TYPE(permission.type))
throw new Error(ERROR_MESSAGES.UNSUPPORTED_PERMISSION_TYPE((permission as Permission).type))
}

const contractCallActions = createActionForContractCall(permission, chainId, expiry)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,11 @@
import axios, { Method, AxiosError } from 'axios'
import { UserOperationWithBigIntAsHex } from './UserOpBuilder'
import { bigIntReplacer } from '@/utils/HelperUtil'
import { WC_COSIGNER_BASE_URL } from '@/utils/ConstantsUtil'

/*
* 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: Record<string, unknown>
}

// The types of keys that are supported for the following `key` and `keys` signer types.
export type KeyType = 'secp256r1' | 'secp256k1' | 'ed25519' | 'schnorr'

/*
* 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: {
type: KeyType
publicKey: `0x${string}`
}
}

/*
* 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: {
keys: {
type: KeyType
publicKey: `0x${string}`
}[]
}
}

// An account that can be granted with permissions as in ERC-7710.
export type AccountSigner = {
type: 'account'
data: {
address: `0x${string}`
}
}

export type Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner

export type SmartSessionGrantPermissionsRequest = {
chainId: `0x${string}`
address?: `0x${string}`
expiry: number
signer: Signer
permissions: {
type: string
data: Record<string, unknown>
}[]
policies: {
type: string
data: Record<string, unknown>
}[]
}
import { COSIGNER_BASE_URL } from '@/utils/ConstantsUtil'
import { WalletGrantPermissionsRequest } from '@/data/EIP7715Data'

//--Cosigner Types----------------------------------------------------------------------- //
export type AddPermissionRequest = SmartSessionGrantPermissionsRequest
export type AddPermissionRequest = WalletGrantPermissionsRequest

export type AddPermissionResponse = {
pci: string
Expand Down Expand Up @@ -169,12 +107,12 @@ export async function sendCoSignerRequest<
}

// Class to interact with the WalletConnect CoSigner API
export class WalletConnectCosigner {
export class CosignerService {
private baseUrl: string
private projectId: string

constructor(projectId: string) {
this.baseUrl = WC_COSIGNER_BASE_URL
this.baseUrl = COSIGNER_BASE_URL
this.projectId = projectId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { bundlerUrl, paymasterUrl, publicClientUrl } from '@/utils/SmartAccountU
import { getChainById } from '@/utils/ChainUtil'
import { SAFE_FALLBACK_HANDLER_STORAGE_SLOT } from '@/consts/smartAccounts'
import { formatSignature, getDummySignature, getNonce } from './UserOpBuilderUtil'
import { WalletConnectCosigner } from './WalletConnectCosignerUtils'
import { CosignerService } from './CosignerService'
const { getAccount } = require('@rhinestone/module-sdk') as typeof import('@rhinestone/module-sdk')

const ERC_7579_LAUNCHPAD_ADDRESS: Address = '0xEBe001b3D534B9B6E2500FB78E67a1A137f561CE'
Expand Down Expand Up @@ -107,12 +107,11 @@ export class SafeUserOpBuilder implements UserOpBuilder {
})

const pci = params.capabilities.permissions?.context!
const walletConnectCosigner = new WalletConnectCosigner(projectId)
const cosignerService = new CosignerService(projectId)
const caip10AccountAddress = `eip155:${this.chain.id}:${this.accountAddress}`
const permissionsContext = await walletConnectCosigner.getPermissionsContext(
caip10AccountAddress,
{ pci }
)
const permissionsContext = await cosignerService.getPermissionsContext(caip10AccountAddress, {
pci
})
let nonce: bigint = await getNonce({
publicClient: this.publicClient,
account,
Expand Down Expand Up @@ -172,12 +171,11 @@ export class SafeUserOpBuilder implements UserOpBuilder {

//Get PermissionsContext from WalletConnectCosigner given pci
const pci = context
const walletConnectCosigner = new WalletConnectCosigner(projectId)
const cosignerService = new CosignerService(projectId)
const caip10AccountAddress = `eip155:${this.chain.id}:${this.accountAddress}`
const permissionsContext = await walletConnectCosigner.getPermissionsContext(
caip10AccountAddress,
{ pci }
)
const permissionsContext = await cosignerService.getPermissionsContext(caip10AccountAddress, {
pci
})
if (pci && projectId) {
const userOpWithBigIntAsHex: UserOperationWithBigIntAsHex = {
...data,
Expand All @@ -199,15 +197,12 @@ export class SafeUserOpBuilder implements UserOpBuilder {
paymasterData: data.paymasterData,
signature: signature
}
const walletConnectCosigner = new WalletConnectCosigner(projectId)
const cosignerService = new CosignerService(projectId)
const caip10AccountAddress = `eip155:${chainIdNumber}:${userOpWithBigIntAsHex.sender}`
const cosignResponse = await walletConnectCosigner.coSignUserOperation(
caip10AccountAddress,
{
pci,
userOp: userOpWithBigIntAsHex
}
)
const cosignResponse = await cosignerService.coSignUserOperation(caip10AccountAddress, {
pci,
userOp: userOpWithBigIntAsHex
})
data.signature = cosignResponse.signature
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const WC_COSIGNER_BASE_URL = 'https://rpc.walletconnect.org/v1/sessions'
export const COSIGNER_BASE_URL = 'https://rpc.walletconnect.org/v1/sessions'
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { smartAccountWallets } from './SmartAccountUtil'
import { KernelSmartAccountLib } from '@/lib/smart-accounts/KernelSmartAccountLib'
type RequestEventArgs = Omit<SignClientTypes.EventArguments['session_request'], 'verifyContext'>

function getSmartWalletAddressFromSession(requestSession: SessionTypes.Struct, chainId: string) {
function getSmartAccountLibFromSession(requestSession: SessionTypes.Struct, chainId: string) {
const sessionAccounts = requestSession.namespaces['eip155'].accounts.filter(value =>
value.startsWith(chainId)
)
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function approveEIP7715Request(requestEvent: RequestEventArgs) {
SettingsStore.setActiveChainId(chainId)
switch (request.method) {
case EIP7715_METHOD.WALLET_GRANT_PERMISSIONS: {
const wallet = getSmartWalletAddressFromSession(requestSession, chainId)
const wallet = getSmartAccountLibFromSession(requestSession, chainId)
let grantPermissionsRequestParams: WalletGrantPermissionsRequest = request.params[0]
if (
wallet instanceof SafeSmartAccountLib
Expand Down

0 comments on commit 7e0ea5f

Please sign in to comment.