Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createUser(args: { userId: string, parentDevice?: GeneratorDevice, userKeys: tcrypto.SodiumKeyPair, nature: Nature}): CreateUserResult {
const ephemeralKeys = tcrypto.makeSignKeyPair();
const signKeys = tcrypto.makeSignKeyPair();
const encryptionKeys = tcrypto.makeEncryptionKeyPair();
const obfuscatedUserId = obfuscateUserId(this.trustchainId, args.userId);
const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, obfuscatedUserId);
let authorPrivateKey = this.appSignKeys.privateKey;
let author = this.root.entry.hash;
if (args.parentDevice) {
// A parent device exists so we are in the add Device case
authorPrivateKey = args.parentDevice.signKeys.privateKey;
author = args.parentDevice.id;
}
let userKeyPair = null;
if (args.nature === NATURE.device_creation_v3) {
userKeyPair = {
public_encryption_key: args.userKeys.publicKey,
it('should throw when identity\'s trustchain does not match tanker\'s', async () => {
const otherAppKeyPair = tcrypto.makeSignKeyPair();
const otherAppId = utils.generateAppID(otherAppKeyPair.publicKey);
const identity = await createIdentity(
utils.toBase64(otherAppId),
utils.toBase64(otherAppKeyPair.privateKey),
userId,
);
await expect(tanker.start(identity)).to.be.rejectedWith(InvalidArgument);
});
beforeEach(async () => {
builder = await makeTrustchainBuilder();
groupStore = await makeMemoryGroupStore();
provisionalUserKeys = {
appSignatureKeyPair: tcrypto.makeSignKeyPair(),
appEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
tankerSignatureKeyPair: tcrypto.makeSignKeyPair(),
tankerEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
};
publicProvisionalUser = {
trustchainId: builder.generator.trustchainId,
target: 'email',
value: 'bob@mail.com',
appSignaturePublicKey: provisionalUserKeys.appSignatureKeyPair.publicKey,
appEncryptionPublicKey: provisionalUserKeys.appEncryptionKeyPair.publicKey,
tankerSignaturePublicKey: provisionalUserKeys.tankerSignatureKeyPair.publicKey,
tankerEncryptionPublicKey: provisionalUserKeys.tankerEncryptionKeyPair.publicKey,
};
});
beforeEach(async () => {
builder = await makeTrustchainBuilder();
groupStore = await makeMemoryGroupStore();
provisionalUserKeys = {
appSignatureKeyPair: tcrypto.makeSignKeyPair(),
appEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
tankerSignatureKeyPair: tcrypto.makeSignKeyPair(),
tankerEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
};
publicProvisionalUser = {
trustchainId: builder.generator.trustchainId,
target: 'email',
value: 'bob@mail.com',
appSignaturePublicKey: provisionalUserKeys.appSignatureKeyPair.publicKey,
appEncryptionPublicKey: provisionalUserKeys.appEncryptionKeyPair.publicKey,
tankerSignaturePublicKey: provisionalUserKeys.tankerSignatureKeyPair.publicKey,
tankerEncryptionPublicKey: provisionalUserKeys.tankerEncryptionKeyPair.publicKey,
};
});
before(async () => {
trustchainKeyPair = tcrypto.makeSignKeyPair();
trustchainId = utils.generateAppID(trustchainKeyPair.publicKey);
userIdString = 'clear user id';
});
function createDelegationToken(userId: Uint8Array, trustchainPrivateKey: Uint8Array): DelegationToken {
const ephemeralKeys = tcrypto.makeSignKeyPair();
const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, userId);
return {
ephemeral_private_signature_key: ephemeralKeys.privateKey,
ephemeral_public_signature_key: ephemeralKeys.publicKey,
user_id: userId,
delegation_signature: tcrypto.sign(delegationBuffer, trustchainPrivateKey),
last_reset: new Uint8Array(32),
};
}
export const generateDeviceFromGhostDevice = (
trustchainId: Uint8Array,
userId: Uint8Array,
deviceEncryptionKeyPair: tcrypto.SodiumKeyPair,
deviceSignatureKeyPair: tcrypto.SodiumKeyPair,
ghostDevice: GhostDevice,
ghostDeviceId: Uint8Array,
userKeys: tcrypto.SodiumKeyPair,
) => {
const ephemeralKeys = tcrypto.makeSignKeyPair();
const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, userId);
const encryptedUserKeyForNewDevice = tcrypto.sealEncrypt(
userKeys.privateKey,
deviceEncryptionKeyPair.publicKey
);
const payload = serializeUserDeviceV3({
ephemeral_public_signature_key: ephemeralKeys.publicKey,
user_id: userId,
delegation_signature: tcrypto.sign(delegationBuffer, ghostDevice.privateSignatureKey),
public_signature_key: deviceSignatureKeyPair.publicKey,
public_encryption_key: deviceEncryptionKeyPair.publicKey,
last_reset: new Uint8Array(tcrypto.HASH_SIZE),
user_key_pair: {
public_encryption_key: userKeys.publicKey,
export const generateGhostDeviceKeys = (): GhostDeviceKeys => ({
encryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
signatureKeyPair: tcrypto.makeSignKeyPair(),
});
export function generateKeySafe(): KeySafe {
return {
deviceId: null,
signaturePair: tcrypto.makeSignKeyPair(),
encryptionPair: tcrypto.makeEncryptionKeyPair(),
provisionalUserKeys: {},
devices: [],
trustchainPublicKey: null,
localUserKeys: null,
};
}