Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Fix hash function. #24

Merged
merged 1 commit into from Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion spec/integration/GenerateCardanoCredentialSpec.ts
Expand Up @@ -73,7 +73,10 @@ describe("generate a credential", () => {

const signature = signMessage(hashToSign, issuer.keypair);

credential.setSignature(signature, issuer.publicKey);
credential.setSignature(
signature.toString("hex"),
issuer.publicKey.toString("hex")
);

// Run the expectations: the credential must have:
// 1. Complete integrity
Expand Down
25 changes: 13 additions & 12 deletions src/Crypto/CardanoProvider.ts
Expand Up @@ -8,8 +8,11 @@ import { BuildProvider } from "./builder";

import { Signature, Address, Hash, PublicKey } from "../types";

const blake2b_256 = (words: any[]): string =>
blake2bHex(words.join(""), undefined, 32);

const hash = (str: string, nonce: string = ""): string => {
const value = blake2bHex([str, nonce].join(""));
const value = blake2b_256([str, nonce]);

if (value === null) throw FractalError.invalidHashing(str);

Expand All @@ -23,8 +26,8 @@ const verifySignature = (
): boolean =>
Cardano.verify(
Buffer.from(message),
Buffer.from(expectedSigner),
Buffer.from(signature)
Buffer.from(expectedSigner, "hex"),
Buffer.from(signature, "hex")
);

const generateCredentialHash = (
Expand All @@ -34,14 +37,12 @@ const generateCredentialHash = (
countryOfIDIssuance: number,
rootHash: string
): Hash =>
blake2bHex(
[
subjectAddress,
kycType,
countryOfResidence,
countryOfIDIssuance,
rootHash,
].join("")
);
blake2b_256([
subjectAddress,
kycType,
countryOfResidence,
countryOfIDIssuance,
rootHash,
]);

export default BuildProvider(hash, verifySignature, generateCredentialHash);