How to use the @tanker/crypto.generichash 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__ / unlock.spec.js View on Github external
const senderSignatureKeyPair = tcrypto.makeSignKeyPair();

    const unlockKeyMessage = await createUnlockKeyMessage({
      trustchainId,
      deviceId: senderDeviceId,
      email,
      password,
      unlockKey,
      userSecret,
      privateSigKey: senderSignatureKeyPair.privateKey,
    });

    expect(unlockKeyMessage.trustchainId).to.deep.equal(trustchainId);
    expect(unlockKeyMessage.deviceId).to.deep.equal(senderDeviceId);
    expect(unlockKeyMessage.claims.email).to.deep.equal(utils.fromString(email));
    expect(unlockKeyMessage.claims.password).to.deep.equal(generichash(utils.fromString(password)));
    //$FlowIKnow
    expect(utils.toString(EncryptorV2.decrypt(userSecret, unlockKeyMessage.claims.unlockKey))).to.deep.equal(unlockKey);

    const signedBuffer = getSignData(unlockKeyMessage);
    expect(tcrypto.verifySignature(signedBuffer, unlockKeyMessage.signature, senderSignatureKeyPair.publicKey)).to.equal(true);
  });
});
github TankerHQ / sdk-js / packages / core / src / Session / LocalUser / requests.js View on Github external
export const formatVerificationRequest = (verification: RemoteVerification, localUser: LocalUser): VerificationRequest => {
  if (verification.email) {
    return {
      hashed_email: generichash(utils.fromString(verification.email)),
      encrypted_email: encryptionV2.compatEncrypt(localUser.userSecret, utils.fromString(verification.email)),
      verification_code: verification.verificationCode,
    };
  }
  if (verification.passphrase) {
    return {
      hashed_passphrase: generichash(utils.fromString(verification.passphrase)),
    };
  }
  if (verification.oidcIdToken) {
    return {
      oidc_id_token: verification.oidcIdToken,
    };
  }
  throw new InternalError('Assertion error: invalid remote verification in formatVerificationRequest');
};
github TankerHQ / sdk-js / packages / identity / src / userSecret.js View on Github external
function checksumByte(secretRand: Uint8Array, userIdBytes: Uint8Array): number {
  const hashSize = 16;
  const input = new Uint8Array(USER_SECRET_SIZE - 1 + userIdBytes.length);
  input.set(secretRand);
  input.set(userIdBytes, USER_SECRET_SIZE - 1);
  return generichash(input, hashSize)[0];
}
github TankerHQ / sdk-js / packages / core / src / Unlock / unlock.js View on Github external
email,
  password,
  unlockKey,
  userSecret,
  privateSigKey
}: CreateUnlockKeyMessageParams): Promise {
  const message = {
    trustchainId,
    deviceId,
    claims: {},
    signature: new Uint8Array(0)
  };
  if (email)
    message.claims.email = utils.fromString(email);
  if (password)
    message.claims.password = generichash(utils.fromString(password));
  if (unlockKey)
    message.claims.unlockKey = EncryptorV2.encrypt(userSecret, utils.fromString(unlockKey));

  const buff = getSignData(message);
  message.signature = tcrypto.sign(buff, privateSigKey);
  return message;
}
github TankerHQ / sdk-js / packages / core / src / Blocks / Block.js View on Github external
export function hashBlock(block: Block | BlockNoSignature): Uint8Array {
  const fullPayload = utils.concatArrays(natureToVarint(block.nature), block.author, block.payload);
  return generichash(fullPayload);
}
github TankerHQ / sdk-js / packages / core / src / ProvisionalIdentity / ProvisionalIdentityManager.js View on Github external
async _getProvisionalIdentityKeys(email: string): Promise {
    let result;
    try {
      result = await this._client.send('get verified provisional identity', b64RequestObject({
        verification_method: {
          type: 'email',
          hashed_email: generichash(utils.fromString(email)),
        },
      }));
    } catch (e) {
      if (e instanceof VerificationNeeded) {
        return null;
      }
      throw e;
    }
    return tankerProvisionalKeys(result);
  }