Skip to content

Commit 4f6e36d

Browse files
authored
feat: allow partial revokes via wallet_revokeSession (#75)
* feat: adapt revokeSession for partial session removal * docs: update wallet_revokeSession docs * lint
1 parent ead8b24 commit 4f6e36d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/multichainClient.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ describe('getMultichainClient', () => {
3939
describe('revokeSession', () => {
4040
it('should revoke session successfully', async () => {
4141
const client = getMultichainClient({ transport: mockTransport });
42-
await client.revokeSession();
42+
await client.revokeSession({});
4343

4444
expect(mockTransport.request).toHaveBeenCalledWith({
4545
method: 'wallet_revokeSession',
46+
params: {},
4647
});
4748
});
4849

4950
it('should disconnect transport after revoking session', async () => {
5051
const client = getMultichainClient({ transport: mockTransport });
51-
await client.revokeSession();
52+
await client.revokeSession({});
5253

5354
expect(mockTransport.disconnect).toHaveBeenCalled();
5455
});

src/multichainClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
MultichainApiMethod,
88
MultichainApiParams,
99
MultichainApiReturn,
10+
RevokeSessionParams,
1011
} from './types/multichainApi';
1112
import type { DefaultRpcApi, MethodName, MethodReturn, RpcApi, Scope } from './types/scopes';
1213
import type { SessionData } from './types/session';
@@ -84,11 +85,11 @@ export function getMultichainClient<T extends RpcApi = DefaultRpcApi>({
8485
await ensureInitialized();
8586
return await request({ transport, method: 'wallet_getSession' });
8687
},
87-
revokeSession: async () => {
88+
revokeSession: async (params?: RevokeSessionParams<T>) => {
8889
await ensureInitialized();
8990
initializationPromise = undefined;
9091
connectionPromise = undefined;
91-
await request({ transport, method: 'wallet_revokeSession' });
92+
await request({ transport, method: 'wallet_revokeSession', params });
9293
await transport.disconnect();
9394
},
9495
invokeMethod: async <S extends Scope<T>, M extends MethodName<T, S>>(

src/types/multichainApi.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export type MultichainApiClient<T extends RpcApi = DefaultRpcApi> = {
3232
/**
3333
* Revokes the current session and disconnects from the wallet
3434
*
35+
* @param params - Session revoke parameters
36+
* @param params.sessionScopes - Scopes that may be passed to partially revoke permission granted by the wallet
3537
* @returns A promise that resolves when the session is revoked
3638
*/
3739
revokeSession: MultichainApi<T>['wallet_revokeSession'];
@@ -68,7 +70,7 @@ export type MultichainApiClient<T extends RpcApi = DefaultRpcApi> = {
6870
export type MultichainApi<T extends RpcApi> = {
6971
wallet_createSession: RpcMethod<CreateSessionParams<T>, SessionData>;
7072
wallet_getSession: RpcMethod<void, SessionData | undefined>;
71-
wallet_revokeSession: RpcMethod<void, void>;
73+
wallet_revokeSession: RpcMethod<RevokeSessionParams<T>, void>;
7274
wallet_invokeMethod: <S extends Scope<T>, M extends MethodName<T, S>>(
7375
params: InvokeMethodParams<T, S, M>,
7476
) => MethodReturn<T, S, M>;
@@ -81,6 +83,11 @@ export type CreateSessionParams<T extends RpcApi> = {
8183
sessionProperties?: SessionProperties;
8284
};
8385

86+
// wallet_revokeSession params
87+
export type RevokeSessionParams<T extends RpcApi> = {
88+
sessionScopes?: Scope<T>[];
89+
};
90+
8491
// wallet_invokeMethod params
8592
export type InvokeMethodParams<T extends RpcApi, S extends Scope<T>, M extends MethodName<T, S>> = {
8693
scope: S;

0 commit comments

Comments
 (0)