@signalapp/mock-server
Advanced tools
Comparing version 2.11.0 to 2.12.0
{ | ||
"name": "@signalapp/mock-server", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "Mock Signal Server for writing tests", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -51,2 +51,5 @@ /// <reference types="node" /> | ||
}>; | ||
export declare type InviteToGroupOptions = EncryptOptions & Readonly<{ | ||
sendInvite?: boolean; | ||
}>; | ||
export declare type SyncSentOptions = Readonly<{ | ||
@@ -164,3 +167,4 @@ timestamp: number; | ||
waitForGroupUpdate(group: Group): Promise<Group>; | ||
inviteToGroup(group: Group, device: Device, options?: EncryptOptions): Promise<Group>; | ||
inviteToGroup(group: Group, device: Device, options?: InviteToGroupOptions): Promise<Group>; | ||
acceptPniInvite(group: Group, device: Device, options?: EncryptOptions): Promise<Group>; | ||
waitForStorageState({ after }?: { | ||
@@ -191,2 +195,3 @@ after?: StorageState; | ||
waitForSyncMessage(predicate?: ((entry: SyncMessageQueueEntry) => boolean)): Promise<SyncMessageQueueEntry>; | ||
private getProfileKeyPresentation; | ||
private getPrivateKey; | ||
@@ -193,0 +198,0 @@ private encryptContent; |
@@ -306,14 +306,8 @@ "use strict"; | ||
async createGroup({ title, members: memberDevices }) { | ||
const ops = new zkgroup_1.ClientZkProfileOperations(this.config.serverPublicParams); | ||
const groupParams = zkgroup_1.GroupSecretParams.generate(); | ||
const members = await Promise.all(memberDevices.map(async (member) => { | ||
const { device, profileKey } = member; | ||
const ctx = ops.createProfileKeyCredentialRequestContext(device.uuid, profileKey); | ||
const response = await this.config.issueExpiringProfileKeyCredential(member.device, ctx.getRequest()); | ||
assert_1.default.ok(response, `Member device ${device.uuid} not initialized`); | ||
const credential = ops.receiveExpiringProfileKeyCredential(ctx, new zkgroup_1.ExpiringProfileKeyCredentialResponse(response)); | ||
const presentation = ops.createExpiringProfileKeyCredentialPresentation(groupParams, credential); | ||
const presentation = await member.getProfileKeyPresentation(groupParams); | ||
return { | ||
uuid: device.uuid, | ||
profileKey, | ||
uuid: member.device.uuid, | ||
profileKey: member.profileKey, | ||
presentation, | ||
@@ -342,5 +336,5 @@ joinedAtVersion: long_1.default.fromNumber(0), | ||
async inviteToGroup(group, device, options = {}) { | ||
const { uuidKind = types_1.UUIDKind.ACI, sendInvite = true } = options; | ||
const serverGroup = await this.config.getGroup(group.publicParams.serialize()); | ||
(0, assert_1.default)(serverGroup !== undefined, 'Group does not exist on server'); | ||
const { uuidKind = types_1.UUIDKind.ACI } = options; | ||
const targetUUID = device.getUUIDByKind(uuidKind); | ||
@@ -366,2 +360,43 @@ const userId = group.encryptUUID(targetUUID); | ||
}); | ||
if (sendInvite) { | ||
// Send the invitation | ||
const encryptOptions = { | ||
timestamp: Date.now(), | ||
...options, | ||
}; | ||
const envelope = await this.encryptContent(device, { | ||
dataMessage: { | ||
groupV2: { | ||
...updatedGroup.toContext(), | ||
groupChange: compiled_1.signalservice.GroupChange.encode(modifyResult.signedChange).finish(), | ||
}, | ||
timestamp: long_1.default.fromNumber(encryptOptions.timestamp), | ||
}, | ||
}, encryptOptions); | ||
await this.config.send(device, envelope); | ||
} | ||
return updatedGroup; | ||
} | ||
async acceptPniInvite(group, device, options = {}) { | ||
const serverGroup = await this.config.getGroup(group.publicParams.serialize()); | ||
(0, assert_1.default)(serverGroup !== undefined, 'Group does not exist on server'); | ||
const aciCiphertext = group.encryptUUID(this.device.uuid); | ||
const pniCiphertext = group.encryptUUID(this.device.pni); | ||
const presentation = await this.getProfileKeyPresentation(group.secretParams); | ||
const modifyResult = await this.config.modifyGroup({ | ||
group: serverGroup, | ||
actions: { | ||
version: group.revision + 1, | ||
promoteMembersPendingPniAciProfileKey: [{ | ||
presentation: presentation.serialize(), | ||
}], | ||
}, | ||
aciCiphertext, | ||
pniCiphertext, | ||
}); | ||
(0, assert_1.default)(!modifyResult.conflict, 'Group update conflict!'); | ||
const updatedGroup = new group_1.Group({ | ||
secretParams: group.secretParams, | ||
groupState: serverGroup.state, | ||
}); | ||
// Send the invitation | ||
@@ -685,2 +720,10 @@ const encryptOptions = { | ||
// | ||
async getProfileKeyPresentation(groupParams) { | ||
const ops = new zkgroup_1.ClientZkProfileOperations(this.config.serverPublicParams); | ||
const ctx = ops.createProfileKeyCredentialRequestContext(this.device.uuid, this.profileKey); | ||
const response = await this.config.issueExpiringProfileKeyCredential(this.device, ctx.getRequest()); | ||
assert_1.default.ok(response, `Member device ${this.device.uuid} not initialized`); | ||
const credential = ops.receiveExpiringProfileKeyCredential(ctx, new zkgroup_1.ExpiringProfileKeyCredentialResponse(response)); | ||
return ops.createExpiringProfileKeyCredentialPresentation(groupParams, credential); | ||
} | ||
getPrivateKey(uuidKind) { | ||
@@ -687,0 +730,0 @@ switch (uuidKind) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3350440
61189