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 deserializes a ProvisionalIdentityClaim test vector', async () => {
const provisionalIdentityClaim = {
user_id: makeUint8Array('the user id', tcrypto.HASH_SIZE),
app_provisional_identity_signature_public_key: makeUint8Array('the app sig pub key', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
tanker_provisional_identity_signature_public_key: makeUint8Array('the tanker sig pub key', tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
author_signature_by_app_key: makeUint8Array('the author sig by app key', tcrypto.SIGNATURE_SIZE),
author_signature_by_tanker_key: makeUint8Array('the author sig by tanker key', tcrypto.SIGNATURE_SIZE),
recipient_user_public_key: makeUint8Array('user pub key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_provisional_identity_private_keys: makeUint8Array('both encrypted private keys', tcrypto.ENCRYPTION_PRIVATE_KEY_SIZE * 2
+ tcrypto.SEAL_OVERHEAD),
};
const payload = new Uint8Array([
// UserID
0x74, 0x68, 0x65, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x69, 0x64, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// AppProvisionalIdentitySignaturePublicKey
0x74, 0x68, 0x65, 0x20,
0x61, 0x70, 0x70, 0x20, 0x73, 0x69, 0x67, 0x20, 0x70, 0x75, 0x62, 0x20,
0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
it('should throw when unserializing unsupported block version', async () => {
const block = {
author: random(tcrypto.HASH_SIZE),
signature: random(tcrypto.SIGNATURE_SIZE),
trustchain_id: random(tcrypto.HASH_SIZE),
payload: new Uint8Array(0),
nature: NATURE_KIND.key_publish_to_device,
};
const serializedBlock = serializeBlock(block);
serializedBlock[0] = 99;
expect(() => unserializeBlock(serializedBlock)).to.throw(UpgradeRequiredError);
});
it('should reject a group addition with bad self-signature', async () => {
let groupAddition = await generator.newUserGroupAddition(alice.device, group, ['bob']);
const payload = {
self_signature_with_current_key: new Uint8Array(tcrypto.SIGNATURE_SIZE),
};
groupAddition = mergeUserGroupAdditionPayload(groupAddition, payload);
await builder.unverifiedStore.addUnverifiedUserGroups([groupAddition.entry]);
await assertFailsWithNature(builder.trustchainVerifier.updateGroupStore([groupId]), 'invalid_self_signature');
});
it(`should throw when serializing an user group addition block with invalid ${field}`, async () => {
const userGroupAdd = {
group_id: new Uint8Array(tcrypto.HASH_SIZE),
previous_group_block: new Uint8Array(tcrypto.HASH_SIZE),
self_signature_with_current_key: new Uint8Array(tcrypto.SIGNATURE_SIZE),
encrypted_group_private_encryption_keys_for_users: [],
};
expect(() => serializeUserGroupAdditionV1(userGroupAdd)).not.to.throw();
userGroupAdd[field] = new Uint8Array(0);
expect(() => serializeUserGroupAdditionV1(userGroupAdd)).to.throw();
});
});
it('should serialize/unserialize a Block', async () => {
const block = {
trustchain_id: new Uint8Array(tcrypto.HASH_SIZE),
nature: preferredNature(NATURE_KIND.key_publish_to_device),
payload: random(450),
author: random(tcrypto.HASH_SIZE),
signature: random(tcrypto.SIGNATURE_SIZE)
};
expect(unserializeBlock(serializeBlock(block))).to.deep.equal(block);
});
});
it('should only have a root block upon creation', async () => {
expect(generator.pushedBlocks.length).to.equal(1);
const rootBlock = blockToEntry(generator.pushedBlocks[0]);
expect(isTrustchainCreation(rootBlock.nature)).to.true;
expect(utils.equalArray(rootBlock.signature, new Uint8Array(tcrypto.SIGNATURE_SIZE))).to.equal(true);
});
beforeEach(() => {
userDevice = {
last_reset: new Uint8Array(tcrypto.HASH_SIZE),
ephemeral_public_signature_key: new Uint8Array(tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
user_id: new Uint8Array(tcrypto.HASH_SIZE),
delegation_signature: new Uint8Array(tcrypto.SIGNATURE_SIZE),
public_signature_key: new Uint8Array(tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
public_encryption_key: new Uint8Array(tcrypto.SIGNATURE_PUBLIC_KEY_SIZE),
user_key_pair: {
public_encryption_key: new Uint8Array(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
encrypted_private_encryption_key: new Uint8Array(tcrypto.SEALED_KEY_SIZE),
},
is_ghost_device: true,
revoked: Number.MAX_SAFE_INTEGER,
};
});
const fields = [
makeTrustchainCreation = (): TestTrustchainCreation => {
this._trustchainKeys = tcrypto.makeSignKeyPair();
this._trustchainIndex += 1;
const rootBlock = {
trustchain_id: new Uint8Array(0),
nature: preferredNature(NATURE_KIND.trustchain_creation),
author: rootBlockAuthor,
payload: this._trustchainKeys.publicKey,
signature: new Uint8Array(tcrypto.SIGNATURE_SIZE)
};
rootBlock.trustchain_id = hashBlock(rootBlock);
const block = utils.toBase64(serializeBlock(rootBlock));
const unverifiedTrustchainCreation: TrustchainCreationEntry = trustchainCreationFromBlock(block);
this._trustchainId = rootBlock.trustchain_id;
return {
unverifiedTrustchainCreation,
block,
trustchainId: rootBlock.trustchain_id,
trustchainKeys: this._trustchainKeys
};
}
export function makeRootBlock(appKeyPair: Object) {
const rootBlock = {
trustchain_id: new Uint8Array(0),
nature: preferredNature(NATURE_KIND.trustchain_creation),
author: new Uint8Array(32),
payload: appKeyPair.publicKey,
signature: new Uint8Array(tcrypto.SIGNATURE_SIZE)
};
rootBlock.trustchain_id = hashBlock(rootBlock);
return rootBlock;
}
(d, o) => getStaticArray(d, tcrypto.SIGNATURE_SIZE, o, 'delegation_signature'),
(d, o) => getStaticArray(d, tcrypto.SIGNATURE_PUBLIC_KEY_SIZE, o, 'public_signature_key'),