-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/next' into token-management-tx-parser
- Loading branch information
Showing
36 changed files
with
1,433 additions
and
1,140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { assert } from "chai"; | ||
import { Message, MessageComputer } from "./message"; | ||
import { loadTestWallets, TestWallet } from "./testutils"; | ||
import { UserVerifier } from "@multiversx/sdk-wallet"; | ||
import { DEFAULT_MESSAGE_VERSION } from "./constants"; | ||
|
||
describe("test message", () => { | ||
let alice: TestWallet; | ||
const messageComputer = new MessageComputer(); | ||
|
||
before(async function () { | ||
({ alice } = await loadTestWallets()); | ||
}); | ||
|
||
it("should test message compute bytes for signing", async () => { | ||
const data = Buffer.from("test message"); | ||
|
||
const message = new Message({ | ||
data: data, | ||
}); | ||
|
||
const serialized = messageComputer.computeBytesForSigning(message); | ||
|
||
assert.equal( | ||
Buffer.from(serialized).toString("hex"), | ||
"2162d6271208429e6d3e664139e98ba7c5f1870906fb113e8903b1d3f531004d", | ||
); | ||
}); | ||
|
||
it("should create, sign, pack, unpack and verify message", async () => { | ||
const data = Buffer.from("test"); | ||
|
||
const message = new Message({ | ||
data: data, | ||
address: alice.getAddress(), | ||
}); | ||
|
||
message.signature = await alice.signer.sign(Buffer.from(messageComputer.computeBytesForSigning(message))); | ||
|
||
assert.equal( | ||
Buffer.from(message.signature).toString("hex"), | ||
"7aff43cd6e3d880a65033bf0a1b16274854fd7dfa9fe5faa7fa9a665ee851afd4c449310f5f1697d348e42d1819eaef69080e33e7652d7393521ed50d7427a0e", | ||
); | ||
|
||
const packedMessage = messageComputer.packMessage(message); | ||
assert.deepEqual(packedMessage, { | ||
address: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", | ||
message: "74657374", | ||
signature: | ||
"7aff43cd6e3d880a65033bf0a1b16274854fd7dfa9fe5faa7fa9a665ee851afd4c449310f5f1697d348e42d1819eaef69080e33e7652d7393521ed50d7427a0e", | ||
version: 1, | ||
}); | ||
|
||
const unpackedMessage = messageComputer.unpackMessage(packedMessage); | ||
assert.deepEqual(unpackedMessage.address, alice.getAddress()); | ||
assert.deepEqual(unpackedMessage.data, message.data); | ||
assert.deepEqual(unpackedMessage.signature, message.signature); | ||
assert.deepEqual(unpackedMessage.version, message.version); | ||
|
||
const verifier = UserVerifier.fromAddress(alice.getAddress()); | ||
const isValid = verifier.verify( | ||
Buffer.from(messageComputer.computeBytesForVerifying(unpackedMessage)), | ||
Buffer.from(unpackedMessage.signature!), | ||
); | ||
assert.equal(isValid, true); | ||
}); | ||
|
||
it("should unpack legacy message", async () => { | ||
const legacyMessage = { | ||
address: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th", | ||
message: "0x7468697320697320612074657374206d657373616765", | ||
signature: | ||
"0xb16847437049986f936dd4a0917c869730cbf29e40a0c0821ca70db33f44758c3d41bcbea446dee70dea13d50942343bb78e74979dc434bbb2b901e0f4fd1809", | ||
version: 1, | ||
signer: "ErdJS", | ||
}; | ||
|
||
const message = messageComputer.unpackMessage(legacyMessage); | ||
assert.deepEqual(message.address, alice.getAddress()); | ||
assert.deepEqual(Buffer.from(message.data).toString(), "this is a test message"); | ||
assert.deepEqual( | ||
Buffer.from(message.signature!).toString("hex"), | ||
"b16847437049986f936dd4a0917c869730cbf29e40a0c0821ca70db33f44758c3d41bcbea446dee70dea13d50942343bb78e74979dc434bbb2b901e0f4fd1809", | ||
); | ||
assert.deepEqual(message.version, DEFAULT_MESSAGE_VERSION); | ||
}); | ||
}); |
Oops, something went wrong.