How to use the @tanker/crypto.tcrypto.sealDecrypt function in @tanker/crypto

To help you get started, we’ve selected a few @tanker/crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / sdk-js / packages / core / src / __tests__ / BlockGenerator.spec.js View on Github external
const block = blockGenerator.createUserGroup(
      groupSignatureKeyPair,
      groupEncryptionKeyPair,
      [user],
      []
    );

    const entry = getGroupEntryFromBlock(block);
    const record: UserGroupCreationRecordV2 = (entry: any);
    expect(record.public_signature_key).to.deep.equal(groupSignatureKeyPair.publicKey);
    expect(record.public_encryption_key).to.deep.equal(groupEncryptionKeyPair.publicKey);
    expect(tcrypto.sealDecrypt(record.encrypted_group_private_signature_key, groupEncryptionKeyPair)).to.deep.equal(groupSignatureKeyPair.privateKey);
    expect(record.encrypted_group_private_encryption_keys_for_users.length).to.deep.equal(1);
    expect(record.encrypted_group_private_encryption_keys_for_users[0].public_user_encryption_key).to.deep.equal(userKeys.publicKey);
    expect(tcrypto.sealDecrypt(record.encrypted_group_private_encryption_keys_for_users[0].encrypted_group_private_encryption_key, userKeys)).to.deep.equal(groupEncryptionKeyPair.privateKey);
    const signData = getUserGroupCreationBlockSignDataV2(record);
    expect(tcrypto.verifySignature(signData, record.self_signature, groupSignatureKeyPair.publicKey)).to.equal(true);
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / TestGenerator.js View on Github external
makeUserCreation = async (userId: Uint8Array): Promise => {
    const deviceSignatureKeyPair = tcrypto.makeSignKeyPair();
    const deviceEncryptionKeyPair = tcrypto.makeEncryptionKeyPair();
    const delegationToken = createDelegationToken(userId, this._trustchainKeys.privateKey);
    const ghostDeviceKeys = generateGhostDeviceKeys();

    const { userCreationBlock, ghostDevice } = generateUserCreation(this._trustchainId, userId, deviceEncryptionKeyPair, deviceSignatureKeyPair, ghostDeviceKeys, delegationToken);
    const unverifiedDeviceCreation = ((userEntryFromBlock(userCreationBlock): any): DeviceCreationEntry);

    const privateUserKey = tcrypto.sealDecrypt(unverifiedDeviceCreation.user_key_pair.encrypted_private_encryption_key, ghostDeviceKeys.encryptionKeyPair);

    const testDevice: TestDevice = {
      id: unverifiedDeviceCreation.hash,
      signKeys: ghostDeviceKeys.signatureKeyPair,
      encryptionKeys: ghostDeviceKeys.encryptionKeyPair,
      revoked: false,
      isGhost: true,
    };
    const identity = await createIdentity(utils.toBase64(this._trustchainId), utils.toBase64(this._trustchainKeys.privateKey), utils.toBase64(userId));
    const publicIdentity = await getPublicIdentity(identity);

    const testUser: TestUser = {
      id: userId,
      userKeys: [{
        publicKey: unverifiedDeviceCreation.user_key_pair.public_encryption_key,
        privateKey: privateUserKey,
github TankerHQ / sdk-js / packages / core / src / Resource / KeyDecryptor.js View on Github external
async decryptResourceKeyPublishedToProvisionalIdentity(keyPublishEntry: KeyPublish): Promise {
    const keys = this._localUser.findProvisionalUserKey(keyPublishEntry.recipient);
    if (!keys)
      throw new Error('Provisional user key not found');
    const d1 = tcrypto.sealDecrypt(keyPublishEntry.key, keys.tankerEncryptionKeyPair);
    const d2 = tcrypto.sealDecrypt(d1, keys.appEncryptionKeyPair);
    return d2;
  }
github TankerHQ / sdk-js / packages / core / src / ProvisionalIdentity / ProvisionalIdentityManager.js View on Github external
async _decryptPrivateProvisionalKeys(recipientUserPublicKey: Uint8Array, encryptedPrivateProvisionalKeys: Uint8Array): Promise {
    const userKeyPair = await this._localUserManager.findUserKey(recipientUserPublicKey);

    const provisionalUserPrivateKeys = tcrypto.sealDecrypt(encryptedPrivateProvisionalKeys, userKeyPair);
    const appEncryptionKeyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(new Uint8Array(provisionalUserPrivateKeys.subarray(0, tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE)));

    const tankerEncryptionKeyPair = tcrypto.getEncryptionKeyPairFromPrivateKey(new Uint8Array(provisionalUserPrivateKeys.subarray(tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE)));

    return { appEncryptionKeyPair, tankerEncryptionKeyPair };
  }
github TankerHQ / sdk-js / packages / core / src / Resource / KeyDecryptor.js View on Github external
async decryptResourceKeyPublishedToUser(keyPublishEntry: KeyPublish): Promise {
    const userKey = this._localUser.findUserKey(keyPublishEntry.recipient);
    if (!userKey)
      throw new Error('User key not found');
    return tcrypto.sealDecrypt(keyPublishEntry.key, userKey);
  }
github TankerHQ / sdk-js / packages / core / src / Groups / ManagerHelper.js View on Github external
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
  const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
  return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}
github TankerHQ / sdk-js / packages / core / src / Groups / GroupUpdater.js View on Github external
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
  const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
  return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}
github TankerHQ / sdk-js / packages / core / src / Groups / GroupUpdater.js View on Github external
function provisionalUnseal(ciphertext: Uint8Array, keys: ProvisionalUserKeyPairs): Uint8Array {
  const intermediate = tcrypto.sealDecrypt(ciphertext, keys.tankerEncryptionKeyPair);
  return tcrypto.sealDecrypt(intermediate, keys.appEncryptionKeyPair);
}