Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/utilities/src/code_hash_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class CodeHashManager {
/**
* Encodes object (e.g. input for actor) to a string hash and uses the `secret` to sign the hash.
*/
encode<T extends object>(data: T, user: string) {
encode<T extends object>(data: T, userId: string) {
const meta = {
[CodeHashMetaKey.USER]: user,
[CodeHashMetaKey.USER]: userId,
[CodeHashMetaKey.VERSION]: CodeHashManager.VERSION,
};
const metaBase64 = this.toBase64(JSON.stringify(meta));
Expand All @@ -45,14 +45,14 @@ export class CodeHashManager {
const data = JSON.parse(this.fromBase64(parts[1]).toString());
const signature = this.fromBase64(parts[2]);
const expectedSignature = this.generateSignature(dataToSign);
const validSignature = timingSafeEqual(signature, expectedSignature);
const isSignatureValid = timingSafeEqual(signature, expectedSignature);

return {
data,
meta: {
user: meta[CodeHashMetaKey.USER],
userId: meta[CodeHashMetaKey.USER],
version: meta[CodeHashMetaKey.VERSION],
validSignature,
isSignatureValid,
},
};
}
Expand Down
8 changes: 4 additions & 4 deletions test/code_hash_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ test('encode/decode', async () => {
expect(input).toEqual(data);
expect(meta).toEqual({
version: 1,
user: '123',
validSignature: true,
userId: '123',
isSignatureValid: true,
});
});

Expand All @@ -53,7 +53,7 @@ test('encode without secret', async () => {
expect(input).toEqual(data);
expect(meta).toEqual({
version: 1,
user: '123',
validSignature: false,
userId: '123',
isSignatureValid: false,
});
});