use same salt derivation as C code for forgettable fields

This commit is contained in:
Florian Dold 2021-06-16 11:44:05 +02:00
parent 52b8785d95
commit 1124c709ac
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 27 additions and 1 deletions

View File

@ -95,3 +95,28 @@ test("contract terms canon hashing (nested)", (t) => {
t.true(ContractTermsUtil.validateForgettable(c3));
t.true(ContractTermsUtil.validateForgettable(c4));
});
test("contract terms reference vector", (t) => {
const j = {
k1: 1,
$forgettable: {
k1: "SALT",
},
k2: {
n1: true,
$forgettable: {
n1: "salt",
},
},
k3: {
n1: "string",
},
};
const h = ContractTermsUtil.hashContractTerms(j);
t.deepEqual(
h,
"VDE8JPX0AEEE3EX1K8E11RYEWSZQKGGZCV6BWTE4ST1C8711P7H850Z7F2Q2HSSYETX87ERC2JNHWB7GTDWTDWMM716VKPSRBXD7SRR",
);
});

View File

@ -65,7 +65,7 @@ export namespace ContractTermsUtil {
const membValCanon = stringToBytes(
canonicalJson(scrub(dup[x])) + "\0",
);
const membSalt = decodeCrock(dup.$forgettable[x]);
const membSalt = stringToBytes(dup.$forgettable[x] + "\0");
const h = kdf(64, membValCanon, membSalt, new Uint8Array([]));
dup.$forgotten[x] = encodeCrock(h);
}
@ -230,6 +230,7 @@ export namespace ContractTermsUtil {
export function hashContractTerms(contractTerms: unknown): string {
const cleaned = scrub(contractTerms);
const canon = canonicalJson(cleaned) + "\0";
console.warn(`canon '${canon}'`)
return encodeCrock(hash(stringToBytes(canon)));
}
}