diff options
author | Florian Dold <florian@dold.me> | 2021-06-16 11:44:05 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-06-16 11:44:05 +0200 |
commit | 1124c709acbe1fdff7608b2d2c458e0afc3b7b7c (patch) | |
tree | efb5424cb0b792d87bf7548b3eca1313d373b9d0 | |
parent | 52b8785d95694e373d8efdb2aa1680e51172bd81 (diff) |
use same salt derivation as C code for forgettable fields
-rw-r--r-- | packages/taler-wallet-core/src/util/contractTerms.test.ts | 25 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/contractTerms.ts | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/packages/taler-wallet-core/src/util/contractTerms.test.ts b/packages/taler-wallet-core/src/util/contractTerms.test.ts index b7783f077..74cae4ca7 100644 --- a/packages/taler-wallet-core/src/util/contractTerms.test.ts +++ b/packages/taler-wallet-core/src/util/contractTerms.test.ts @@ -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", + ); +}); diff --git a/packages/taler-wallet-core/src/util/contractTerms.ts b/packages/taler-wallet-core/src/util/contractTerms.ts index 5fb23cf8c..c2e75955b 100644 --- a/packages/taler-wallet-core/src/util/contractTerms.ts +++ b/packages/taler-wallet-core/src/util/contractTerms.ts @@ -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))); } } |