Skip to content

Commit

Permalink
feat: revoke sessions (#3107)
Browse files Browse the repository at this point in the history
Co-authored-by: Enes <[email protected]>
  • Loading branch information
tomiir and enesozturk authored Oct 18, 2024
1 parent 04d5579 commit d3c92fb
Show file tree
Hide file tree
Showing 41 changed files with 1,720 additions and 1,250 deletions.
24 changes: 24 additions & 0 deletions .changeset/twelve-poems-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-experimental': patch
'@reown/appkit-scaffold-ui': patch
'@apps/laboratory': patch
'@reown/appkit': patch
'@reown/appkit-common': patch
'@reown/appkit-wallet': patch
'@reown/appkit-core': patch
'@apps/gallery': patch
'@apps/demo': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-siwe': patch
'@reown/appkit-ui': patch
---

Adds experimental sessions feature ui elements and flows.
Adds revoke session flow.
4 changes: 2 additions & 2 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"clsx": "2.1.0",
"framer-motion": "11.0.8",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"sonner": "1.4.3",
"tailwind-merge": "2.2.1",
"vaul": "0.9.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/gallery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@reown/appkit-common": "workspace:*",
"@reown/appkit-ui": "workspace:*",
"lit": "3.1.0",
"react": "18.2.0",
"react": "18.3.1",
"storybook": "7.6.7"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions apps/laboratory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"framer-motion": "10.17.9",
"next": "14.2.3",
"next-auth": "4.24.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-icons": "4.12.0",
"rpc-websockets": "7.11.0",
"valtio": "1.11.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/laboratory/src/utils/ConstantsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (!projectId) {
throw new Error('NEXT_PUBLIC_PROJECT_ID is not set')
}
export const WALLET_URL = process.env['WALLET_URL'] || 'https://react-wallet.walletconnect.com/'
export const USEROP_BUILDER_SERVICE_BASE_URL = 'https://rpc.walletconnect.com/v1/wallet'
export const USEROP_BUILDER_SERVICE_BASE_URL = 'https://rpc.walletconnect.org/v1/wallet'

export const GALLERY_URL = 'https://appkit-gallery.reown.com/'
export const DOCS_URL = 'https://docs.reown.com/appkit/overview'
Expand Down
3 changes: 2 additions & 1 deletion apps/laboratory/src/utils/EIP5792Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const EIP_5792_RPC_METHODS = {
WALLET_SEND_CALLS: 'wallet_sendCalls'
}
export const EIP_7715_RPC_METHODS = {
WALLET_GRANT_PERMISSIONS: 'wallet_grantPermissions'
WALLET_GRANT_PERMISSIONS: 'wallet_grantPermissions',
WALLET_REVOKE_PERMISSIONS: 'wallet_revokePermissions'
}

export const WALLET_CAPABILITIES = {
Expand Down
4 changes: 2 additions & 2 deletions examples/html-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"@wagmi/core": "2.13.8",
"@reown/appkit-adapter-wagmi": "workspace:*",
"@reown/appkit": "workspace:*",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"vite": "5.2.11"
Expand Down
4 changes: 2 additions & 2 deletions examples/next-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@reown/appkit": "workspace:*",
"ethers": "6.13.2",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/react": "18.2.62",
Expand Down
4 changes: 2 additions & 2 deletions examples/next-wagmi-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@reown/appkit-adapter-wagmi": "workspace:*",
"@wagmi/core": "2.13.8",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"viem": "2.21.26",
"wagmi": "2.12.17"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/next-wagmi-pages-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@tanstack/react-query": "5.56.2",
"@wagmi/core": "2.13.8",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"viem": "2.21.26",
"wagmi": "2.12.17"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/next-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"@wagmi/connectors": "5.1.15",
"@wagmi/core": "2.13.8",
"next": "14.2.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"viem": "2.21.26",
"wagmi": "2.12.17"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/react-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@reown/appkit-adapter-ethers": "workspace:*",
"@reown/appkit": "workspace:*",
"ethers": "6.13.2",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/react": "18.2.62",
Expand Down
4 changes: 2 additions & 2 deletions examples/react-ethers5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@reown/appkit-adapter-ethers5": "workspace:*",
"@reown/appkit": "workspace:*",
"ethers": "5.7.2",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/react": "18.2.62",
Expand Down
4 changes: 2 additions & 2 deletions examples/react-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@reown/appkit": "workspace:*",
"@reown/appkit-adapter-solana": "workspace:*",
"@tanstack/react-query": "5.24.8",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"vite": "5.2.11",
"@solana/wallet-adapter-backpack": "0.1.14",
"@solana/wallet-adapter-wallets": "0.19.32"
Expand Down
4 changes: 2 additions & 2 deletions examples/react-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@reown/appkit": "workspace:*",
"@reown/appkit-adapter-wagmi": "workspace:*",
"@tanstack/react-query": "5.24.8",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"viem": "2.21.26",
"vite": "5.2.11",
"wagmi": "2.12.17"
Expand Down
9 changes: 9 additions & 0 deletions packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,15 @@ export class EthersAdapter {

return await provider.request({ method: 'wallet_grantPermissions', params })
},
revokePermissions: async session => {
const provider = ProviderUtil.getProvider<Provider>(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

return await provider.request({ method: 'wallet_revokePermissions', params: [session] })
},

sendTransaction: async data => {
if (data.chainNamespace && data.chainNamespace !== 'eip155') {
Expand Down
18 changes: 18 additions & 0 deletions packages/adapters/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,24 @@ export class Ethers5Adapter {
const caipNetwork = this.appKit?.getCaipNetwork()

return await Ethers5Methods.getEnsAvatar(value, Number(caipNetwork?.id))
},
grantPermissions: async params => {
const provider = ProviderUtil.getProvider<Provider>(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

return await provider.request({ method: 'wallet_grantPermissions', params })
},
revokePermissions: async session => {
const provider = ProviderUtil.getProvider<Provider>(CommonConstantsUtil.CHAIN.EVM)

if (!provider) {
throw new Error('Provider is undefined')
}

return await provider.request({ method: 'wallet_revokePermissions', params: [session] })
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/adapters/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
"bs58": "5.0.0"
},
"devDependencies": {
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.1",
"@vitest/coverage-v8": "2.1.3",
"@vue/runtime-core": "3.4.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"vue": "3.4.3",
"vitest": "2.1.3"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/adapters/solana/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ export class SolanaAdapter implements ChainAdapter {

grantPermissions: async () => await Promise.resolve('0x'),

revokePermissions: async () => await Promise.resolve('0x'),

sendTransaction: async params => {
if (params.chainNamespace !== CommonConstantsUtil.CHAIN.SOLANA) {
throw new Error('Chain namespace is not supported')
Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"wagmi": ">=2.12"
},
"devDependencies": {
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.1",
"@vitest/coverage-v8": "2.1.3",
"@walletconnect/types": "2.17.0",
"vitest": "2.1.3"
Expand Down
20 changes: 20 additions & 0 deletions packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,26 @@ export class WagmiAdapter implements ChainAdapter {

return provider.request({ method: 'wallet_grantPermissions', params })
},
revokePermissions: async session => {
if (!this.wagmiConfig) {
throw new Error('connectionControllerClient:revokePermissions - wagmiConfig is undefined')
}

const connections = getConnections(this.wagmiConfig)
const connection = connections[0]

if (!connection?.connector) {
throw new Error('connectionControllerClient:revokePermissions - connector is undefined')
}

const provider = (await connection.connector.getProvider()) as UniversalProvider

if (!provider) {
throw new Error('connectionControllerClient:revokePermissions - provider is undefined')
}

return provider.request({ method: 'wallet_revokePermissions', params: [session] })
},

sendTransaction: async (data: SendTransactionArgs) => {
if (data.chainNamespace && data.chainNamespace !== 'eip155') {
Expand Down
8 changes: 4 additions & 4 deletions packages/appkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@
"viem": "2.x"
},
"devDependencies": {
"@types/react": "18.2.0",
"@types/react-dom": "18.2.0",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.1",
"@vitest/coverage-v8": "2.1.3",
"@vue/runtime-core": "3.4.3",
"@walletconnect/types": "2.13.3",
"@walletconnect/universal-provider": "2.17.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"vitest": "2.1.3",
"vue": "3.x"
},
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/src/tests/mocks/UniversalProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const mockProvider = {
'wallet_showCallsStatus',
'wallet_getCallsStatus',
'wallet_grantPermissions',
'wallet_revokePermissions',
'wallet_switchEthereumChain'
],
rpcMap: {
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/src/tests/utils/HelpersUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('WcHelpersUtil', () => {
'wallet_showCallsStatus',
'wallet_getCallsStatus',
'wallet_grantPermissions',
'wallet_revokePermissions',
'wallet_switchEthereumChain'
])
})
Expand Down
11 changes: 10 additions & 1 deletion packages/appkit/src/universal-adapter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const OPTIONAL_METHODS = [
'wallet_sendCalls',
'wallet_getCapabilities',
// EIP-7715
'wallet_grantPermissions'
'wallet_grantPermissions',
'wallet_revokePermissions'
]

// -- Client --------------------------------------------------------------------
Expand Down Expand Up @@ -289,6 +290,14 @@ export class UniversalAdapterClient {

return provider.request({ method: 'wallet_grantPermissions', params })
},
revokePermissions: async session => {
const provider = await this.getWalletConnectProvider()
if (!provider) {
throw new Error('connectionControllerClient:grantPermissions - provider is undefined')
}

return provider.request({ method: 'wallet_revokePermissions', params: [session] })
},

sendTransaction: async () => await Promise.resolve('0x'),

Expand Down
1 change: 1 addition & 0 deletions packages/appkit/src/utils/HelpersUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const WcHelpersUtil = {
'wallet_showCallsStatus',
'wallet_getCallsStatus',
'wallet_grantPermissions',
'wallet_revokePermissions',
'wallet_switchEthereumChain'
]
default:
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/controllers/BlockchainApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,18 @@ export const BlockchainApiController = {
}
})
},

revokeSmartSession(address: `0x${string}`, pci: string, signature: string) {
return state.api.post({
path: `/v1/sessions/${address}/revoke`,
params: {
projectId: OptionsController.state.projectId
},
body: {
pci,
signature
}
})
},
setClientId(clientId: string | null) {
state.clientId = clientId
state.api = new FetchUtil({ baseUrl, clientId })
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface ConnectionControllerClient {
getEnsAddress: (value: string) => Promise<false | string>
getEnsAvatar: (value: string) => Promise<false | string>
grantPermissions: (params: readonly unknown[] | object) => Promise<unknown>
revokePermissions: (params: {
pci: string
permissions: unknown[]
expiry: number
address: `0x${string}`
}) => Promise<`0x${string}`>
getCapabilities: (params: string) => Promise<unknown>
}

Expand Down
3 changes: 2 additions & 1 deletion packages/core/tests/controllers/ChainController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const connectionControllerClient: ConnectionControllerClient = {
getEnsAddress: async (value: string) => Promise.resolve(value),
getEnsAvatar: async (value: string) => Promise.resolve(value),
getCapabilities: async () => Promise.resolve(''),
grantPermissions: async () => Promise.resolve('')
grantPermissions: async () => Promise.resolve(''),
revokePermissions: async () => Promise.resolve('0x')
}

const networkControllerClient: NetworkControllerClient = {
Expand Down
Loading

0 comments on commit d3c92fb

Please sign in to comment.