Skip to content

Commit

Permalink
Fix idiosyncrasy: message.getSignature() should also be a Buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Apr 7, 2023
1 parent bb59728 commit 46b5b0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "12.0.1",
"version": "12.1.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
3 changes: 1 addition & 2 deletions src/signableMessage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { assert } from "chai";
import { SignableMessage } from "./signableMessage";
import { Signature } from "./signature";
import { loadTestWallets, TestWallet } from "./testutils";


Expand All @@ -13,7 +12,7 @@ describe("test signable message", () => {
const sm = new SignableMessage({
address: alice.address,
message: Buffer.from("test message", "ascii"),
signature: new Signature(Buffer.from("a".repeat(128), "hex"),),
signature: Buffer.from("a".repeat(128), "hex"),
signer: "ElrondWallet"
});

Expand Down
21 changes: 12 additions & 9 deletions src/signableMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ISignature } from "./interface";
import { Signature } from "./signature";
import { Address } from "./address";
import { ISignature } from "./interface";
const createKeccakHash = require("keccak");

export const MESSAGE_PREFIX = "\x17Elrond Signed Message:\n";
Expand All @@ -14,7 +13,7 @@ export class SignableMessage {
/**
* Signature obtained by a signer of type @param signer .
*/
signature: ISignature;
signature: Buffer;

/**
* Address of the wallet that performed the signing operation
Expand All @@ -33,7 +32,7 @@ export class SignableMessage {

public constructor(init?: Partial<SignableMessage>) {
this.message = Buffer.from([]);
this.signature = new Signature();
this.signature = Buffer.from([]);
this.version = 1;
this.signer = "ErdJS";
this.address = new Address();
Expand All @@ -53,12 +52,16 @@ export class SignableMessage {
return Buffer.concat([this.getMessageSize(), this.message]);
}

getSignature(): ISignature {
getSignature(): Buffer {
return this.signature;
}

applySignature(signature: ISignature): void {
this.signature = signature;
applySignature(signature: ISignature | Buffer) {
if (signature instanceof Buffer) {
this.signature = signature;
} else {
this.signature = Buffer.from(signature.hex(), "hex");
}
}

getMessageSize(): Buffer {
Expand All @@ -71,8 +74,8 @@ export class SignableMessage {
toJSON(): object {
return {
address: this.address.bech32(),
message: "0x" + this.message.toString('hex'),
signature: "0x" + this.signature.hex(),
message: "0x" + this.message.toString("hex"),
signature: "0x" + this.signature.toString("hex"),
version: this.version,
signer: this.signer,
};
Expand Down

0 comments on commit 46b5b0d

Please sign in to comment.