From 26948d31d33d1dfeab51ce1f669e762791b5a995 Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:44:55 +0200 Subject: [PATCH] update Account --- packages/status-js/src/account.test.ts | 12 ++++++------ packages/status-js/src/account.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/status-js/src/account.test.ts b/packages/status-js/src/account.test.ts index 32c7bde..c953a55 100644 --- a/packages/status-js/src/account.test.ts +++ b/packages/status-js/src/account.test.ts @@ -8,10 +8,10 @@ describe('Account', () => { it('should verify the signature', async () => { const account = new Account() - const message = '123' - const messageHash = keccak256(utf8ToBytes(message)) + const message = utf8ToBytes('123') + const messageHash = keccak256(message) - const signature = await account.sign(message) + const signature = await account.signMessage(message) expect(secp.verify(signature, messageHash, account.publicKey)).toBeTruthy() }) @@ -19,10 +19,10 @@ describe('Account', () => { it('should not verify signature with different message', async () => { const account = new Account() - const message = '123' - const messageHash = keccak256(utf8ToBytes(message)) + const message = utf8ToBytes('123') + const messageHash = keccak256(message) - const signature = await account.sign('abc') + const signature = await account.signMessage(utf8ToBytes('abc')) expect(secp.verify(signature, messageHash, account.publicKey)).toBeFalsy() }) diff --git a/packages/status-js/src/account.ts b/packages/status-js/src/account.ts index 70903df..7fe5434 100644 --- a/packages/status-js/src/account.ts +++ b/packages/status-js/src/account.ts @@ -1,25 +1,24 @@ import { keccak256 } from 'ethereum-cryptography/keccak' import { getPublicKey, sign, utils } from 'ethereum-cryptography/secp256k1' -import { bytesToHex, utf8ToBytes } from 'ethereum-cryptography/utils' - -import { privateKeyToAddress } from './utils/private-key-to-address' +import { bytesToHex } from 'ethereum-cryptography/utils' export class Account { public privateKey: string public publicKey: string - public address: string + public chatKey: string constructor() { const privateKey = utils.randomPrivateKey() const publicKey = getPublicKey(privateKey) + const chatKey = getPublicKey(privateKey, true) this.privateKey = bytesToHex(privateKey) this.publicKey = bytesToHex(publicKey) - this.address = privateKeyToAddress(this.privateKey) + this.chatKey = bytesToHex(chatKey) } - sign = (payload: string) => { - const hash = keccak256(utf8ToBytes(payload)) + signMessage = (payload: Uint8Array) => { + const hash = keccak256(payload) return sign(hash, this.privateKey) } }