You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/session/apis/snode_api/revokeSubaccount.ts

43 lines
1.1 KiB
TypeScript

import { GroupPubkeyType } from 'libsession_util_nodejs';
import { PubKey } from '../../types';
import { RevokeSubaccountParams, UnrevokeSubaccountParams } from './SnodeRequestTypes';
export type RevokeChanges = Array<{
action: 'revoke_subaccount' | 'unrevoke_subaccount';
tokenToRevokeHex: string;
}>;
async function getRevokeSubaccountParams(
groupPk: GroupPubkeyType,
{
revokeChanges,
unrevokeChanges,
}: { revokeChanges: RevokeChanges; unrevokeChanges: RevokeChanges }
) {
if (!PubKey.is03Pubkey(groupPk)) {
throw new Error('revokeSubaccountForGroup: not a 03 group');
}
const revokeParams: RevokeSubaccountParams | null = revokeChanges.length
? {
pubkey: groupPk,
revoke: revokeChanges.map(m => m.tokenToRevokeHex),
}
: null;
const unrevokeParams: UnrevokeSubaccountParams | null = unrevokeChanges.length
? {
pubkey: groupPk,
unrevoke: unrevokeChanges.map(m => m.tokenToRevokeHex),
}
: null;
return {
revokeParams,
unrevokeParams,
};
}
export const SnodeAPIRevoke = { getRevokeSubaccountParams };