Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('correctly serializes/deserializes a UserGroupCreation test vector', async () => {
const userGroupCreation = {
public_signature_key: makeUint8Array('pub sig key', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
public_encryption_key: makeUint8Array('pub enc key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_signature_key: makeUint8Array('encrypted priv sig key', tcrypto.SEALED_SIGNATURE_PRIVATE_KEY_SIZE),
encrypted_group_private_encryption_keys_for_users: [
{
public_user_encryption_key: makeUint8Array('pub user key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_encryption_key: makeUint8Array('encrypted group priv key', tcrypto.SEALED_ENCRYPTION_PRIVATE_KEY_SIZE),
},
{
public_user_encryption_key: makeUint8Array('second pub user key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_encryption_key: makeUint8Array('second encrypted group priv key', tcrypto.SEALED_ENCRYPTION_PRIVATE_KEY_SIZE),
}],
self_signature: makeUint8Array('self signature', tcrypto.SIGNATURE_SIZE),
};
const payload = new Uint8Array([
// public signature key
0x70, 0x75, 0x62, 0x20, 0x73, 0x69, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// is_ghost_device
0x01,
]);
const deviceCreation = {
last_reset: new Uint8Array(32),
ephemeral_public_signature_key: makeUint8Array('eph pub key', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
user_id: makeUint8Array('user id', tcrypto.HASH_SIZE),
delegation_signature: makeUint8Array('delegation sig', tcrypto.SIGNATURE_SIZE),
public_signature_key: makeUint8Array('public signature key', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
public_encryption_key: makeUint8Array('public enc key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
user_key_pair: {
public_encryption_key: makeUint8Array('user pub enc key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_private_encryption_key: makeUint8Array('user enc key', tcrypto.SEALED_KEY_SIZE),
},
is_ghost_device: true,
revoked: Number.MAX_SAFE_INTEGER,
};
expect(unserializeUserDeviceV3(payload)).to.deep.equal(deviceCreation);
});
it('should reject a group creation if it already exists', async () => {
group.publicEncryptionKey = random(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE);
assertFailWithNature(
() => verifyUserGroupCreation(userGroupEntry, user.devices[0].devicePublicSignatureKey, group),
'group_already_exists'
);
});
it('order stuff correctly for UserGroupCreationV1 sign data', async () => {
const record: UserGroupCreationRecordV1 = {
public_signature_key: random(tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
public_encryption_key: random(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_signature_key: random(tcrypto.SEALED_SIGNATURE_PRIVATE_KEY_SIZE),
encrypted_group_private_encryption_keys_for_users: [
{
public_user_encryption_key: random(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_encryption_key: random(tcrypto.SEALED_ENCRYPTION_PRIVATE_KEY_SIZE),
},
{
public_user_encryption_key: random(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_group_private_encryption_key: random(tcrypto.SEALED_ENCRYPTION_PRIVATE_KEY_SIZE),
}],
self_signature: new Uint8Array(0),
};
const expectedSignData = utils.concatArrays(
record.public_signature_key,
record.public_encryption_key,
it('should reject a group creation if it already exists', async () => {
const builder = await makeTrustchainBuilder();
const alice = await builder.addUserV3('alice');
const group = await builder.addUserGroupCreation(alice, ['alice']);
const payload: UserGroupCreationRecord = (group.entry.payload_unverified: any);
const groupId = payload.public_signature_key;
await builder.groupStore.putExternal({
groupId: payload.public_signature_key,
publicSignatureKey: payload.public_signature_key,
publicEncryptionKey: makeUint8Array('wrong encryption key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encryptedPrivateSignatureKey: makeUint8Array('priv sig', tcrypto.SEALED_SIGNATURE_PRIVATE_KEY_SIZE),
lastGroupBlock: group.entry.hash,
index: group.entry.index,
});
await assertFailsWithNature(builder.trustchainVerifier.updateGroupStore([groupId]), 'group_already_exists');
});
});
before(async () => {
userId = random(tcrypto.HASH_SIZE);
const userCreation = await testGenerator.makeUserCreation(userId);
claim = testGenerator.makeProvisionalIdentityClaim(userCreation, userId, random(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE));
await unverifiedStore.addUnverifiedProvisionalIdentityClaimEntries([claim.unverifiedProvisionalIdentityClaim]);
});
(d, o) => getStaticArray(d, tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE, o, 'previous_public_encryption_key'),
(d, o) => getStaticArray(d, tcrypto.SEALED_KEY_SIZE, o, 'encrypted_previous_encryption_key'),
export function serializeProvisionalIdentityClaim(provisionalIdentityClaim: ProvisionalIdentityClaimRecord): Uint8Array {
if (provisionalIdentityClaim.user_id.length !== tcrypto.HASH_SIZE)
throw new InternalError('Assertion error: invalid claim provisional user id size');
if (provisionalIdentityClaim.app_provisional_identity_signature_public_key.length !== tcrypto.SIGNATURE_PUBLIC_KEY_SIZE)
throw new InternalError('Assertion error: invalid claim provisional app public key size');
if (provisionalIdentityClaim.tanker_provisional_identity_signature_public_key.length !== tcrypto.SIGNATURE_PUBLIC_KEY_SIZE)
throw new InternalError('Assertion error: invalid claim provisional tanker public key size');
if (provisionalIdentityClaim.author_signature_by_app_key.length !== tcrypto.SIGNATURE_SIZE)
throw new InternalError('Assertion error: invalid claim provisional app signature size');
if (provisionalIdentityClaim.author_signature_by_tanker_key.length !== tcrypto.SIGNATURE_SIZE)
throw new InternalError('Assertion error: invalid claim provisional tanker signature size');
if (provisionalIdentityClaim.recipient_user_public_key.length !== tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE)
throw new InternalError('Assertion error: invalid claim provisional recipient key size');
if (provisionalIdentityClaim.encrypted_provisional_identity_private_keys.length !== tcrypto.ENCRYPTION_PRIVATE_KEY_SIZE * 2
+ tcrypto.SEAL_OVERHEAD)
throw new InternalError('Assertion error: invalid claim provisional encrypted keys size');
return utils.concatArrays(
provisionalIdentityClaim.user_id,
provisionalIdentityClaim.app_provisional_identity_signature_public_key,
provisionalIdentityClaim.tanker_provisional_identity_signature_public_key,
provisionalIdentityClaim.author_signature_by_app_key,
provisionalIdentityClaim.author_signature_by_tanker_key,
provisionalIdentityClaim.recipient_user_public_key,
provisionalIdentityClaim.encrypted_provisional_identity_private_keys,
);
}
(d, o) => getStaticArray(d, tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE, o, 'public_encryption_key'),
(d, o) => getStaticArray(d, tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE, o, 'previous_public_encryption_key'),