Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Feb 16, 2024
1 parent 9b7f2f2 commit 80a4fce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 0 additions & 7 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,3 @@ export interface ITransactionNext {
signature: Uint8Array;
guardianSignature: Uint8Array;
}

export interface IMessage {
data: Uint8Array;
signature?: Uint8Array;
address?: IAddress;
version?: number;
}
10 changes: 5 additions & 5 deletions src/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAddress, IMessage } from "./interface";
import { IAddress } from "./interface";
import { DEFAULT_MESSAGE_VERSION, MESSAGE_PREFIX } from "./constants";
import { Address } from "./address";

Expand Down Expand Up @@ -26,26 +26,26 @@ export class Message {
this.data = options.data;
this.signature = options.signature;
this.address = options.address;
this.version = options.version ? options.version : DEFAULT_MESSAGE_VERSION;
this.version = options.version || DEFAULT_MESSAGE_VERSION;
}
}

export class MessageComputer {
constructor() {}

computeBytesForSigning(message: IMessage): Uint8Array {
computeBytesForSigning(message: Message): Uint8Array {
const messageSize = Buffer.from(message.data.length.toString());
const signableMessage = Buffer.concat([messageSize, message.data]);
let bytesToHash = Buffer.concat([Buffer.from(MESSAGE_PREFIX), signableMessage]);

return createKeccakHash("keccak256").update(bytesToHash).digest();
}

computeBytesForVerifying(message: IMessage): Uint8Array {
computeBytesForVerifying(message: Message): Uint8Array {
return this.computeBytesForSigning(message);
}

packMessage(message: IMessage): {
packMessage(message: Message): {
message: string;
signature: string;
address: string;
Expand Down

0 comments on commit 80a4fce

Please sign in to comment.