Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #734 from klaytn/release/v1.10.1
Browse files Browse the repository at this point in the history
[Master] release/v1.10.1 QA Sign-off
  • Loading branch information
Nohyun Nehemiah Kwak authored Dec 27, 2022
2 parents 9a86b02 + b593861 commit 7bcf29e
Show file tree
Hide file tree
Showing 8 changed files with 415 additions and 281 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "caver-js",
"version": "1.10.0",
"version": "1.10.1",
"description": "caver-js is a JavaScript API library that allows developers to interact with a Klaytn node",
"main": "index.js",
"types": "types/index.d.ts",
Expand Down
7 changes: 4 additions & 3 deletions packages/caver-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,9 +1399,10 @@ const isEmptySig = sig => {
* @return {string} The hashed message with Klaytn specific prefix.
*/
const hashMessage = data => {
const message = isHexStrict(data) ? hexToBytes(data) : data
const messageBuffer = Buffer.from(message)
const preamble = `\x19Klaytn Signed Message:\n${message.length}`
const messageHex = isHexStrict(data) ? data : utf8ToHex(data)
const messageBytes = hexToBytes(messageHex)
const messageBuffer = Buffer.from(messageBytes)
const preamble = `\x19Klaytn Signed Message:\n${messageBytes.length}`
const preambleBuffer = Buffer.from(preamble)
// klayMessage is concatenated buffer (preambleBuffer + messageBuffer)
const klayMessage = Buffer.concat([preambleBuffer, messageBuffer])
Expand Down
20 changes: 20 additions & 0 deletions test/packages/caver.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ describe('caver.validator.validateSignedMessage', () => {
const ret = await caver.validator.validateSignedMessage(message, invalid, keyring.address)
expect(ret).to.be.false
}).timeout(100000)

it('CAVERJS-UNIT-VALIDATOR-006: should return true when korean-format message are passed as a parameter', async () => {
const getAccoutKeyStub = sandbox.stub(caver.validator.klaytnCall, 'getAccountKey')
getAccoutKeyStub.resolves(getAccountKeyResult)

const kMessage = '하이'
const kAddress = '0x82B4deC52696c7777b4453986496612a0a2B1e99'
const kSignedMessage =
'0x85e6ae815bb80814ba8f63b3b16941f0740f471a048efb79b31428dcb61345132bd48cbf9594a243243a97951fbd3cc555101158c76168bbcb0b2e1a0de08b2d1b'
// pub key
// "0xf2a480ed864b9fa3856e2841aa0851463ce34ba9c43a503d08e9ab5dcfd4136cc5fddab6ea35271f43fb75597eed634056c8b0e211a134e26ed1e01b9161a132"

const v = `0x${kSignedMessage.substring(2).substring(128, 130)}`
const r = `0x${kSignedMessage.substring(2).substring(0, 64)}`
const s = `0x${kSignedMessage.substring(2).substring(64, 128)}`
const sig = [v, r, s]

const ret = await caver.validator.validateSignedMessage(kMessage, sig, kAddress)
expect(ret).to.be.true
}).timeout(100000)
})

context('caver.validator.validateSignedMessage with AccountKeyPublic', () => {
Expand Down
Loading

0 comments on commit 7bcf29e

Please sign in to comment.