mirror of
https://github.com/status-im/wakuconnect-chat-sdk.git
synced 2025-02-06 17:23:42 +00:00
26 lines
767 B
TypeScript
26 lines
767 B
TypeScript
|
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'
|
||
|
|
||
|
export class Account {
|
||
|
public privateKey: string
|
||
|
public publicKey: string
|
||
|
public address: string
|
||
|
|
||
|
constructor() {
|
||
|
const privateKey = utils.randomPrivateKey()
|
||
|
const publicKey = getPublicKey(privateKey)
|
||
|
|
||
|
this.privateKey = bytesToHex(privateKey)
|
||
|
this.publicKey = bytesToHex(publicKey)
|
||
|
this.address = privateKeyToAddress(this.privateKey)
|
||
|
}
|
||
|
|
||
|
sign = (payload: string) => {
|
||
|
const hash = keccak256(utf8ToBytes(payload))
|
||
|
return sign(hash, this.privateKey)
|
||
|
}
|
||
|
}
|