Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async createGroup(publicIdentities: Array): Promise {
assertPublicIdentities(publicIdentities);
const deserializedIdentities = publicIdentities.map(i => _deserializePublicIdentity(i));
const { permanentIdentities, provisionalIdentities } = _splitProvisionalAndPermanentPublicIdentities(deserializedIdentities);
const users = await this._UserManager.getUsers({ publicIdentities: permanentIdentities });
const provisionalUsers = await this._provisionalIdentityManager.getProvisionalUsers(provisionalIdentities);
const groupSignatureKeyPair = tcrypto.makeSignKeyPair();
const { payload, nature } = makeUserGroupCreation(
groupSignatureKeyPair,
tcrypto.makeEncryptionKeyPair(),
users,
provisionalUsers
);
await this._client.send('push block', this._localUser.makeBlock(payload, nature), true);
return utils.toBase64(groupSignatureKeyPair.publicKey);
}
async updateGroupMembers(groupId: string, publicIdentities: Array): Promise {
assertPublicIdentities(publicIdentities);
const internalGroupId = utils.fromBase64(groupId);
const existingGroup = await this._getInternalGroupById(internalGroupId);
if (!existingGroup) {
throw new InvalidArgument('groupId', 'string', groupId);
}
const deserializedIdentities = publicIdentities.map(i => _deserializePublicIdentity(i));
const { permanentIdentities, provisionalIdentities } = _splitProvisionalAndPermanentPublicIdentities(deserializedIdentities);
const users = await this._UserManager.getUsers({ publicIdentities: permanentIdentities });
const provisionalUsers = await this._provisionalIdentityManager.getProvisionalUsers(provisionalIdentities);
const { payload, nature } = makeUserGroupAddition(
internalGroupId,
existingGroup.signatureKeyPair.privateKey,
existingGroup.lastGroupBlock,
existingGroup.encryptionKeyPair.privateKey,
users,
provisionalUsers,
);
await this._client.send('push block', this._localUser.makeBlock(payload, nature), true);
}
async _shareResources(keys: Array<{ resourceId: Uint8Array, key: Uint8Array }>, sharingOptions: SharingOptions, shareWithSelf: bool): Promise {
const groupIds = (sharingOptions.shareWithGroups || []).map(g => utils.fromBase64(g));
const groupsKeys = await this._groupManager.getGroupsPublicEncryptionKeys(groupIds);
const deserializedIdentities = (sharingOptions.shareWithUsers || []).map(i => _deserializePublicIdentity(i));
const deserializedIdentitiesWithSelf = this._handleShareWithSelf(deserializedIdentities, shareWithSelf);
const { permanentIdentities, provisionalIdentities } = _splitProvisionalAndPermanentPublicIdentities(deserializedIdentitiesWithSelf);
const users = await this._userManager.getUsers({ publicIdentities: permanentIdentities });
const provisionalUsers = await this._provisionalIdentityManager.getProvisionalUsers(provisionalIdentities);
if (shareWithSelf) {
const [{ resourceId, key }] = keys;
await this._resourceManager.saveResourceKey(resourceId, key);
}
return this._publishKeys(keys, users, provisionalUsers, groupsKeys);
}