chore: refactor snodesignature input args type

before testing
pull/2873/head
Audric Ackermann 2 years ago
parent 1dc5224c26
commit 820103b340

@ -207,7 +207,7 @@ const networkDeleteMessages = async (hashes: Array<string>): Promise<Array<strin
return pRetry(
async () => {
const signOpts = await SnodeSignature.getSnodeSignatureByHashesParams({
messages: hashes,
messagesHashes: hashes,
method,
pubkey: userX25519PublicKey,
});

@ -200,7 +200,7 @@ export async function expireMessageOnSnode(props: ExpireMessageOnSnodeProps) {
const signResult = await SnodeSignature.generateUpdateExpiryOurSignature({
shortenOrExtend,
timestamp: expiry,
messageHashes: [messageHash],
messagesHashes: [messageHash],
});
if (!signResult) {

@ -172,7 +172,7 @@ async function buildRetrieveRequest(
const signResult = await SnodeSignature.generateUpdateExpiryOurSignature({
shortenOrExtend: '',
timestamp: expiry,
messageHashes: configHashesToBump,
messagesHashes: configHashesToBump,
});
const expireParams: UpdateExpiryOnNodeUserSubRequest = {
@ -196,7 +196,7 @@ async function buildRetrieveRequest(
const signResult = await SnodeSignature.generateUpdateExpiryGroupSignature({
shortenOrExtend: '',
timestamp: expiry,
messageHashes: configHashesToBump,
messagesHashes: configHashesToBump,
groupPk: pubkey,
groupPrivKey: group.secretKey,
});

@ -9,24 +9,28 @@ import { PubKey } from '../../types';
import { toFixedUint8ArrayOfLength } from '../../../types/sqlSharedTypes';
import { PreConditionFailed } from '../../utils/errors';
export type SnodeSignatureResult = {
timestamp: number;
type WithTimestamp = { timestamp: number };
export type SnodeSignatureResult = WithTimestamp & {
signature: string;
pubkey_ed25519: string;
pubkey: string; // this is the x25519 key of the pubkey we are doing the request to (ourself for our swarm usually)
};
type ShortenOrExtend = 'extend' | 'shorten' | '';
type WithShortenOrExtend = { shortenOrExtend: ShortenOrExtend };
type WithMessagesHashes = { messagesHashes: Array<string> };
export type SnodeGroupSignatureResult = Pick<SnodeSignatureResult, 'signature' | 'timestamp'> & {
pubkey: GroupPubkeyType; // this is the 03 pubkey of the corresponding group
};
async function getSnodeSignatureByHashesParams({
messages,
messagesHashes,
method,
pubkey,
}: {
}: WithMessagesHashes & {
pubkey: string;
messages: Array<string>;
method: 'delete';
}): Promise<
Pick<SnodeSignatureResult, 'pubkey_ed25519' | 'signature' | 'pubkey'> & {
@ -41,7 +45,7 @@ async function getSnodeSignatureByHashesParams({
throw new Error(err);
}
const edKeyPrivBytes = fromHexToArray(ourEd25519Key?.privKey);
const verificationData = StringUtils.encode(`${method}${messages.join('')}`, 'utf8');
const verificationData = StringUtils.encode(`${method}${messagesHashes.join('')}`, 'utf8');
const message = new Uint8Array(verificationData);
const sodium = await getSodiumRenderer();
@ -53,7 +57,7 @@ async function getSnodeSignatureByHashesParams({
signature: signatureBase64,
pubkey_ed25519: ourEd25519Key.pubKey,
pubkey,
messages,
messages: messagesHashes,
};
} catch (e) {
window.log.warn('getSnodeSignatureParams failed with: ', e.message);
@ -164,18 +168,17 @@ async function getSnodeGroupSignatureParams({
async function generateUpdateExpirySignature({
shortenOrExtend,
timestamp,
messageHashes,
messagesHashes,
ed25519Privkey,
ed25519Pubkey,
}: {
shortenOrExtend: 'extend' | 'shorten' | '';
timestamp: number;
messageHashes: Array<string>;
ed25519Privkey: Uint8Array | FixedSizeUint8Array<64>;
ed25519Pubkey: string;
}): Promise<{ signature: string; pubkey_ed25519: string }> {
}: WithMessagesHashes &
WithShortenOrExtend &
WithTimestamp & {
ed25519Privkey: Uint8Array | FixedSizeUint8Array<64>;
ed25519Pubkey: string;
}): Promise<{ signature: string; pubkey_ed25519: string }> {
// "expire" || ShortenOrExtend || expiry || messages[0] || ... || messages[N]
const verificationString = `expire${shortenOrExtend}${timestamp}${messageHashes.join('')}`;
const verificationString = `expire${shortenOrExtend}${timestamp}${messagesHashes.join('')}`;
const verificationData = StringUtils.encode(verificationString, 'utf8');
const message = new Uint8Array(verificationData);
@ -197,12 +200,8 @@ async function generateUpdateExpirySignature({
async function generateUpdateExpiryOurSignature({
shortenOrExtend,
timestamp,
messageHashes,
}: {
shortenOrExtend: 'extend' | 'shorten' | '';
timestamp: number;
messageHashes: Array<string>;
}) {
messagesHashes,
}: WithMessagesHashes & WithShortenOrExtend & WithTimestamp) {
const ourEd25519Key = await UserUtils.getUserED25519KeyPair();
if (!ourEd25519Key) {
@ -214,7 +213,7 @@ async function generateUpdateExpiryOurSignature({
const edKeyPrivBytes = fromHexToArray(ourEd25519Key?.privKey);
return generateUpdateExpirySignature({
messageHashes,
messagesHashes,
shortenOrExtend,
timestamp,
ed25519Privkey: edKeyPrivBytes,
@ -225,16 +224,15 @@ async function generateUpdateExpiryOurSignature({
async function generateUpdateExpiryGroupSignature({
shortenOrExtend,
timestamp,
messageHashes,
messagesHashes,
groupPrivKey,
groupPk,
}: {
shortenOrExtend: 'extend' | 'shorten' | '';
timestamp: number;
messageHashes: Array<string>;
groupPk: GroupPubkeyType;
groupPrivKey: FixedSizeUint8Array<64>;
}) {
}: WithMessagesHashes &
WithShortenOrExtend &
WithTimestamp & {
groupPk: GroupPubkeyType;
groupPrivKey: FixedSizeUint8Array<64>;
}) {
if (isEmpty(groupPrivKey) || isEmpty(groupPk)) {
throw new PreConditionFailed(
'generateUpdateExpiryGroupSignature groupPrivKey or groupPks is empty'
@ -242,7 +240,7 @@ async function generateUpdateExpiryGroupSignature({
}
return generateUpdateExpirySignature({
messageHashes,
messagesHashes,
shortenOrExtend,
timestamp,
ed25519Privkey: groupPrivKey,

@ -249,7 +249,7 @@ async function sendMessagesDataToSnode(
messagesHashesToDelete && messagesHashesToDelete.size
? await SnodeSignature.getSnodeSignatureByHashesParams({
method: 'delete' as const,
messages: [...messagesHashesToDelete],
messagesHashes: [...messagesHashesToDelete],
pubkey: destination,
})
: null;

Loading…
Cancel
Save