use same salt derivation as C code for forgettable fields
This commit is contained in:
parent
52b8785d95
commit
1124c709ac
@ -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",
|
||||
);
|
||||
});
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user