pass args by {} and add deviceLink tests
parent
f1244f3031
commit
fa26ff9e32
@ -1,13 +0,0 @@
|
|||||||
import { ContentMessage } from './ContentMessage';
|
|
||||||
import { SignalService } from '../../../../protobuf';
|
|
||||||
|
|
||||||
export class DeviceLinkMessage extends ContentMessage {
|
|
||||||
|
|
||||||
public ttl(): number {
|
|
||||||
return 2 * 60 * 1000; // 2 minutes for linking requests
|
|
||||||
}
|
|
||||||
|
|
||||||
protected contentProto(): SignalService.Content {
|
|
||||||
throw new Error('Not implemented');
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,60 @@
|
|||||||
|
import { SignalService } from '../../../../../protobuf';
|
||||||
|
import { DeviceLinkRequestMessage } from './DeviceLinkRequestMessage';
|
||||||
|
import { LokiProfile } from '../../../../../types/Message';
|
||||||
|
|
||||||
|
interface DeviceLinkGrantMessageParams {
|
||||||
|
timestamp: number;
|
||||||
|
identifier: string;
|
||||||
|
|
||||||
|
// pairing authorisation
|
||||||
|
primaryDevicePubKey: string;
|
||||||
|
secondaryDevicePubKey: string;
|
||||||
|
requestSignature: Uint8Array;
|
||||||
|
grantSignature: Uint8Array;
|
||||||
|
|
||||||
|
lokiProfile: LokiProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DeviceLinkGrantMessage extends DeviceLinkRequestMessage {
|
||||||
|
private readonly displayName: string;
|
||||||
|
private readonly avatarPointer: string;
|
||||||
|
private readonly profileKey: Uint8Array;
|
||||||
|
private readonly grantSignature: Uint8Array | null;
|
||||||
|
|
||||||
|
constructor(params: DeviceLinkGrantMessageParams
|
||||||
|
) {
|
||||||
|
super({
|
||||||
|
timestamp: params.timestamp,
|
||||||
|
identifier: params.identifier,
|
||||||
|
primaryDevicePubKey: params.primaryDevicePubKey,
|
||||||
|
secondaryDevicePubKey: params.secondaryDevicePubKey,
|
||||||
|
requestSignature: params.requestSignature,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.displayName = params.lokiProfile.displayName;
|
||||||
|
this.avatarPointer = params.lokiProfile.avatarPointer;
|
||||||
|
this.profileKey = params.lokiProfile.profileKey;
|
||||||
|
this.grantSignature = params.grantSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPairingAuthorisationMessage(): SignalService.PairingAuthorisationMessage {
|
||||||
|
return new SignalService.PairingAuthorisationMessage({
|
||||||
|
primaryDevicePubKey: this.primaryDevicePubKey,
|
||||||
|
secondaryDevicePubKey: this.secondaryDevicePubKey,
|
||||||
|
requestSignature: this.requestSignature,
|
||||||
|
grantSignature: this.grantSignature,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getDataMessage(): SignalService.DataMessage | null {
|
||||||
|
// Send profile name to secondary device and avatarPointer
|
||||||
|
const profile = new SignalService.DataMessage.LokiProfile();
|
||||||
|
profile.avatar = this.avatarPointer;
|
||||||
|
profile.displayName = this.displayName;
|
||||||
|
|
||||||
|
return new SignalService.DataMessage({
|
||||||
|
profile,
|
||||||
|
profileKey: this.profileKey,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
import { ContentMessage } from '../ContentMessage';
|
||||||
|
import { SignalService } from '../../../../../protobuf';
|
||||||
|
interface DeviceLinkMessageParams {
|
||||||
|
timestamp: number;
|
||||||
|
identifier: string;
|
||||||
|
|
||||||
|
primaryDevicePubKey: string;
|
||||||
|
secondaryDevicePubKey: string;
|
||||||
|
requestSignature: Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class DeviceLinkRequestMessage extends ContentMessage {
|
||||||
|
protected readonly primaryDevicePubKey: string;
|
||||||
|
protected readonly secondaryDevicePubKey: string;
|
||||||
|
protected readonly requestSignature: Uint8Array;
|
||||||
|
|
||||||
|
constructor(params: DeviceLinkMessageParams) {
|
||||||
|
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||||
|
this.primaryDevicePubKey = params.primaryDevicePubKey;
|
||||||
|
this.secondaryDevicePubKey = params.secondaryDevicePubKey;
|
||||||
|
this.requestSignature = params.requestSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ttl(): number {
|
||||||
|
return 2 * 60 * 1000; // 2 minutes for pairing requests
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getDataMessage(): SignalService.DataMessage | null {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPairingAuthorisationMessage(): SignalService.PairingAuthorisationMessage {
|
||||||
|
return new SignalService.PairingAuthorisationMessage({
|
||||||
|
primaryDevicePubKey: this.primaryDevicePubKey,
|
||||||
|
secondaryDevicePubKey: this.secondaryDevicePubKey,
|
||||||
|
requestSignature: this.requestSignature,
|
||||||
|
grantSignature: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected contentProto(): SignalService.Content {
|
||||||
|
return new SignalService.Content({
|
||||||
|
pairingAuthorisation: this.getPairingAuthorisationMessage(),
|
||||||
|
dataMessage: this.getDataMessage() || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,95 @@
|
|||||||
|
import { expect } from 'chai';
|
||||||
|
import { beforeEach} from 'mocha';
|
||||||
|
|
||||||
|
import { DeviceLinkGrantMessage, DeviceLinkRequestMessage, ContentMessage } from '../../../session/messages/outgoing';
|
||||||
|
import { SignalService } from '../../../protobuf';
|
||||||
|
import { LokiProfile } from '../../../types/Message';
|
||||||
|
|
||||||
|
describe('DeviceLinkMessage', () => {
|
||||||
|
let linkRequestMessage: DeviceLinkRequestMessage;
|
||||||
|
let linkGrantMessage: DeviceLinkGrantMessage;
|
||||||
|
let lokiProfile: LokiProfile;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
linkRequestMessage = new DeviceLinkRequestMessage({
|
||||||
|
timestamp: Date.now(),
|
||||||
|
identifier: '123456',
|
||||||
|
primaryDevicePubKey: '111111',
|
||||||
|
secondaryDevicePubKey: '222222',
|
||||||
|
requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]),
|
||||||
|
});
|
||||||
|
|
||||||
|
lokiProfile = {
|
||||||
|
displayName: 'displayName',
|
||||||
|
avatarPointer: 'avatarPointer',
|
||||||
|
profileKey: new Uint8Array([1, 2, 3, 4]),
|
||||||
|
};
|
||||||
|
|
||||||
|
linkGrantMessage = new DeviceLinkGrantMessage({
|
||||||
|
timestamp: Date.now(),
|
||||||
|
identifier: '123456',
|
||||||
|
primaryDevicePubKey: '111111',
|
||||||
|
secondaryDevicePubKey: '222222',
|
||||||
|
requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]),
|
||||||
|
grantSignature: new Uint8Array([6, 5, 4, 3, 2, 1]),
|
||||||
|
lokiProfile,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('content of a linkRequestMessage ', () => {
|
||||||
|
let decoded: any;
|
||||||
|
before(() => {
|
||||||
|
const plainText = linkRequestMessage.plainTextBuffer();
|
||||||
|
decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has a pairingAuthorisation.primaryDevicePubKey', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('primaryDevicePubKey', '111111');
|
||||||
|
});
|
||||||
|
it('has a pairingAuthorisation.secondaryDevicePubKey', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('secondaryDevicePubKey', '222222');
|
||||||
|
});
|
||||||
|
it('has a pairingAuthorisation.requestSignature', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('requestSignature').to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6]));
|
||||||
|
});
|
||||||
|
it('has no pairingAuthorisation.grantSignature', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.not.have.property('grantSignature');
|
||||||
|
});
|
||||||
|
it('has no lokiProfile', () => {
|
||||||
|
expect(decoded).to.not.have.property('lokiProfile');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('content of a linkGrantMessage ', () => {
|
||||||
|
let decoded: any;
|
||||||
|
before(() => {
|
||||||
|
const plainText = linkGrantMessage.plainTextBuffer();
|
||||||
|
decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has a pairingAuthorisation.primaryDevicePubKey', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('primaryDevicePubKey', '111111');
|
||||||
|
});
|
||||||
|
it('has a pairingAuthorisation.secondaryDevicePubKey', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('secondaryDevicePubKey', '222222');
|
||||||
|
});
|
||||||
|
it('has a pairingAuthorisation.requestSignature', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('requestSignature').to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6]));
|
||||||
|
});
|
||||||
|
it('has a pairingAuthorisation.grantSignature', () => {
|
||||||
|
expect(decoded.pairingAuthorisation).to.have.property('grantSignature').to.deep.equal(new Uint8Array([6, 5, 4, 3, 2, 1]));
|
||||||
|
});
|
||||||
|
it('has a lokiProfile', () => {
|
||||||
|
expect(decoded.dataMessage).to.have.property('profileKey').to.be.deep.equal(lokiProfile.profileKey);
|
||||||
|
expect(decoded.dataMessage).to.have.property('profile').to.be.deep.equal({
|
||||||
|
displayName: 'displayName',
|
||||||
|
avatar: 'avatarPointer',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ttl of 2 minutes', () => {
|
||||||
|
expect(linkRequestMessage.ttl()).to.equal(2 * 60 * 1000);
|
||||||
|
expect(linkGrantMessage.ttl()).to.equal(2 * 60 * 1000);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue