2022-06-02 12:11:40 +02:00
|
|
|
import { keccak256 } from 'ethereum-cryptography/keccak'
|
|
|
|
import { getPublicKey, sign, utils } from 'ethereum-cryptography/secp256k1'
|
2022-06-03 17:44:55 +02:00
|
|
|
import { bytesToHex } from 'ethereum-cryptography/utils'
|
2022-06-02 12:11:40 +02:00
|
|
|
|
|
|
|
export class Account {
|
|
|
|
public privateKey: string
|
|
|
|
public publicKey: string
|
2022-06-03 17:44:55 +02:00
|
|
|
public chatKey: string
|
2022-06-02 12:11:40 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
const privateKey = utils.randomPrivateKey()
|
|
|
|
const publicKey = getPublicKey(privateKey)
|
2022-06-03 17:44:55 +02:00
|
|
|
const chatKey = getPublicKey(privateKey, true)
|
2022-06-02 12:11:40 +02:00
|
|
|
|
|
|
|
this.privateKey = bytesToHex(privateKey)
|
|
|
|
this.publicKey = bytesToHex(publicKey)
|
2022-06-03 17:44:55 +02:00
|
|
|
this.chatKey = bytesToHex(chatKey)
|
2022-06-02 12:11:40 +02:00
|
|
|
}
|
|
|
|
|
2022-06-03 17:44:55 +02:00
|
|
|
signMessage = (payload: Uint8Array) => {
|
|
|
|
const hash = keccak256(payload)
|
2022-06-02 12:11:40 +02:00
|
|
|
return sign(hash, this.privateKey)
|
|
|
|
}
|
|
|
|
}
|