Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/multichainClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ describe('getMultichainClient', () => {
describe('revokeSession', () => {
it('should revoke session successfully', async () => {
const client = getMultichainClient({ transport: mockTransport });
await client.revokeSession();
await client.revokeSession({});

expect(mockTransport.request).toHaveBeenCalledWith({
method: 'wallet_revokeSession',
params: {},
});
});

it('should disconnect transport after revoking session', async () => {
const client = getMultichainClient({ transport: mockTransport });
await client.revokeSession();
await client.revokeSession({});

expect(mockTransport.disconnect).toHaveBeenCalled();
});
Expand Down
5 changes: 3 additions & 2 deletions src/multichainClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
MultichainApiMethod,
MultichainApiParams,
MultichainApiReturn,
RevokeSessionParams,
} from './types/multichainApi';
import type { DefaultRpcApi, MethodName, MethodReturn, RpcApi, Scope } from './types/scopes';
import type { SessionData } from './types/session';
Expand Down Expand Up @@ -84,11 +85,11 @@ export function getMultichainClient<T extends RpcApi = DefaultRpcApi>({
await ensureInitialized();
return await request({ transport, method: 'wallet_getSession' });
},
revokeSession: async () => {
revokeSession: async (params?: RevokeSessionParams<T>) => {
await ensureInitialized();
initializationPromise = undefined;
connectionPromise = undefined;
await request({ transport, method: 'wallet_revokeSession' });
await request({ transport, method: 'wallet_revokeSession', params });
await transport.disconnect();
},
invokeMethod: async <S extends Scope<T>, M extends MethodName<T, S>>(
Expand Down
9 changes: 8 additions & 1 deletion src/types/multichainApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type MultichainApiClient<T extends RpcApi = DefaultRpcApi> = {
/**
* Revokes the current session and disconnects from the wallet
*
* @param params - Session revoke parameters
* @param params.sessionScopes - Scopes that may be passed to partially revoke permission granted by the wallet
* @returns A promise that resolves when the session is revoked
*/
revokeSession: MultichainApi<T>['wallet_revokeSession'];
Expand Down Expand Up @@ -68,7 +70,7 @@ export type MultichainApiClient<T extends RpcApi = DefaultRpcApi> = {
export type MultichainApi<T extends RpcApi> = {
wallet_createSession: RpcMethod<CreateSessionParams<T>, SessionData>;
wallet_getSession: RpcMethod<void, SessionData | undefined>;
wallet_revokeSession: RpcMethod<void, void>;
wallet_revokeSession: RpcMethod<RevokeSessionParams<T>, void>;
wallet_invokeMethod: <S extends Scope<T>, M extends MethodName<T, S>>(
params: InvokeMethodParams<T, S, M>,
) => MethodReturn<T, S, M>;
Expand All @@ -81,6 +83,11 @@ export type CreateSessionParams<T extends RpcApi> = {
sessionProperties?: SessionProperties;
};

// wallet_revokeSession params
export type RevokeSessionParams<T extends RpcApi> = {
sessionScopes?: Scope<T>[];
};

// wallet_invokeMethod params
export type InvokeMethodParams<T extends RpcApi, S extends Scope<T>, M extends MethodName<T, S>> = {
scope: S;
Expand Down
Loading