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( return pRetry(
async () => { async () => {
const signOpts = await SnodeSignature.getSnodeSignatureByHashesParams({ const signOpts = await SnodeSignature.getSnodeSignatureByHashesParams({
messages: hashes, messagesHashes: hashes,
method, method,
pubkey: userX25519PublicKey, pubkey: userX25519PublicKey,
}); });

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

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

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

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

Loading…
Cancel
Save