Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@signalapp/mock-server

Package Overview
Dependencies
Maintainers
4
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@signalapp/mock-server - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

package.json
{
"name": "@signalapp/mock-server",
"version": "1.0.1",
"version": "1.1.0",
"description": "Mock Signal Server for writing tests",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -117,3 +117,3 @@ /// <reference types="node" />

expectStorageState(reason: string): Promise<StorageState>;
setStorageState(state: StorageState): Promise<void>;
setStorageState(state: StorageState): Promise<StorageState>;
waitForSync(secondaryDevice: Device): Promise<void>;

@@ -139,2 +139,3 @@ resetSyncState(secondaryDevice: Device): void;

private processSenderKeyDistribution;
private convertManifestToStorageState;
}

@@ -296,23 +296,3 @@ "use strict";

}
const decryptedManifest = (0, crypto_2.decryptStorageManifest)(this.storageKey, manifest);
(0, assert_1.default)(decryptedManifest.version, 'Consistency check');
const version = decryptedManifest.version.toNumber();
const items = await Promise.all((decryptedManifest.keys || []).map(async ({ type, raw: key }) => {
(0, assert_1.default)(type !== null && type !== undefined, 'Missing manifestRecord.keys.type');
(0, assert_1.default)(key, 'Missing manifestRecord.keys.raw');
const keyBuffer = Buffer.from(key);
const item = await this.config.getStorageItem(keyBuffer);
if (!item) {
throw new Error(`Missing item ${keyBuffer.toString('base64')}`);
}
return {
type,
key: keyBuffer,
record: (0, crypto_2.decryptStorageItem)(this.storageKey, {
key,
value: item,
}),
};
}));
return new storage_state_1.StorageState(version, items);
return this.convertManifestToStorageState(manifest);
}

@@ -328,3 +308,8 @@ async expectStorageState(reason) {

const writeOperation = state.createWriteOperation(this.storageKey);
await this.config.applyStorageWrite(writeOperation, false);
(0, assert_1.default)(writeOperation.manifest, 'write operation without manifest');
const { updated, error } = await this.config.applyStorageWrite(writeOperation, false);
if (!updated) {
throw new Error(`setStorageState: failed to update, ${error}`);
}
return this.convertManifestToStorageState(writeOperation.manifest);
}

@@ -699,3 +684,26 @@ //

}
async convertManifestToStorageState(manifest) {
const decryptedManifest = (0, crypto_2.decryptStorageManifest)(this.storageKey, manifest);
(0, assert_1.default)(decryptedManifest.version, 'Consistency check');
const version = decryptedManifest.version.toNumber();
const items = await Promise.all((decryptedManifest.keys || []).map(async ({ type, raw: key }) => {
(0, assert_1.default)(type !== null && type !== undefined, 'Missing manifestRecord.keys.type');
(0, assert_1.default)(key, 'Missing manifestRecord.keys.raw');
const keyBuffer = Buffer.from(key);
const item = await this.config.getStorageItem(keyBuffer);
if (!item) {
throw new Error(`Missing item ${keyBuffer.toString('base64')}`);
}
return {
type,
key: keyBuffer,
record: (0, crypto_2.decryptStorageItem)(this.storageKey, {
key,
value: item,
}),
};
}));
return new storage_state_1.StorageState(version, items);
}
}
exports.PrimaryDevice = PrimaryDevice;
/// <reference types="node" />
import { signalservice as Proto } from '../../protos/compiled';
import { Device } from '../data/device';
import { Group } from './group';
import { PrimaryDevice } from './primary-device';
export declare type StorageStateItemOptions = Readonly<{
export declare type StorageStateRecord = Readonly<{
type: Proto.ManifestRecord.Identifier.Type;

@@ -11,2 +10,7 @@ key: Buffer;

}>;
export declare type StorageStateNewRecord = Readonly<{
type: Proto.ManifestRecord.Identifier.Type;
key?: Buffer;
record: Proto.IStorageRecord;
}>;
export declare type DiffResult = Readonly<{

@@ -16,21 +20,6 @@ added: ReadonlyArray<Proto.IStorageRecord>;

}>;
declare const IdentifierType: typeof Proto.ManifestRecord.Identifier.Type;
declare type IdentifierType = Proto.ManifestRecord.Identifier.Type;
export declare class StorageStateItem {
readonly type: IdentifierType;
readonly key: Buffer;
readonly record: Proto.IStorageRecord;
constructor({ type, key, record, }: StorageStateItemOptions);
getKeyString(): string;
toStorageItem(storageKey: Buffer): Proto.IStorageItem;
toIdentifier(): Proto.ManifestRecord.IIdentifier;
isAccount(): boolean;
isGroup(group: Group): boolean;
isContact(device: Device): boolean;
inspect(): string;
}
export declare class StorageState {
readonly version: number;
private readonly items;
constructor(version: number, items: ReadonlyArray<StorageStateItemOptions>);
constructor(version: number, items: ReadonlyArray<StorageStateRecord>);
static getEmpty(): StorageState;

@@ -51,7 +40,12 @@ getAccountRecord(): Proto.IAccountRecord | undefined;

isPinned({ device }: PrimaryDevice): boolean;
addRecord(newRecord: StorageStateNewRecord): StorageState;
findRecord(find: (record: StorageStateRecord) => boolean): StorageStateRecord | undefined;
hasRecord(find: (record: StorageStateRecord) => boolean): boolean;
updateRecord(find: (item: StorageStateRecord) => boolean, map: (record: Proto.IStorageRecord) => Proto.IStorageRecord): StorageState;
removeRecord(find: (item: StorageStateRecord) => boolean): StorageState;
createWriteOperation(storageKey: Buffer, previous?: StorageState): Proto.IWriteOperation;
inspect(): string;
diff(oldState: StorageState): DiffResult;
private addItem;
private updateItem;
private addItem;
private replaceItem;

@@ -62,2 +56,1 @@ private changePin;

}
export {};

@@ -8,3 +8,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageState = exports.StorageStateItem = void 0;
exports.StorageState = void 0;
const assert_1 = __importDefault(require("assert"));

@@ -65,4 +65,10 @@ const crypto_1 = __importDefault(require("crypto"));

}
toRecord() {
return {
type: this.type,
key: this.key,
record: this.record,
};
}
}
exports.StorageStateItem = StorageStateItem;
class StorageState {

@@ -117,6 +123,9 @@ constructor(version, items) {

addGroup(group, diff = {}) {
return this.addItem(IdentifierType.GROUPV2, {
groupV2: {
...diff,
masterKey: group.masterKey,
return this.addItem({
type: IdentifierType.GROUPV2,
record: {
groupV2: {
...diff,
masterKey: group.masterKey,
},
},

@@ -153,7 +162,10 @@ });

addContact({ device }, diff = {}) {
return this.addItem(IdentifierType.CONTACT, {
contact: {
serviceUuid: device.uuid,
serviceE164: device.number,
...diff,
return this.addItem({
type: IdentifierType.CONTACT,
record: {
contact: {
serviceUuid: device.uuid,
serviceE164: device.number,
...diff,
},
},

@@ -193,2 +205,29 @@ });

//
// Raw record access
//
addRecord(newRecord) {
return this.addItem(newRecord);
}
findRecord(find) {
const item = this.items.find((item) => find(item.toRecord()));
return item?.toRecord();
}
hasRecord(find) {
return this.findRecord(find) !== undefined;
}
updateRecord(find, map) {
return this.updateItem((item) => find(item.toRecord()), map);
}
removeRecord(find) {
const itemIndex = this.items.findIndex((item) => find(item.toRecord()));
if (itemIndex === -1) {
throw new Error('Record not found');
}
const newItems = [
...this.items.slice(0, itemIndex),
...this.items.slice(itemIndex + 1),
];
return new StorageState(this.version, newItems);
}
//
// General

@@ -245,2 +284,5 @@ //

//
addItem(newRecord) {
return this.replaceItem(this.items.length, newRecord);
}
updateItem(find, map) {

@@ -253,12 +295,11 @@ const itemIndex = this.items.findIndex(find);

(0, assert_1.default)(item, 'consistency check');
return this.replaceItem(itemIndex, item.type, map(item.record));
return this.replaceItem(itemIndex, {
type: item.type,
record: map(item.record),
});
}
addItem(type, record) {
return this.replaceItem(this.items.length, type, record);
}
replaceItem(index, type, record) {
const newKey = StorageState.createStorageID();
replaceItem(index, { type, record, key = StorageState.createStorageID(), }) {
const newItems = [
...this.items.slice(0, index),
new StorageStateItem({ type, key: newKey, record }),
new StorageStateItem({ type, key, record }),
...this.items.slice(index + 1),

@@ -265,0 +306,0 @@ ];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc