fix: add username to account
This commit is contained in:
parent
8bdff5d869
commit
805944a3d7
|
@ -2,10 +2,13 @@ import { keccak256 } from 'ethereum-cryptography/keccak'
|
||||||
import { getPublicKey, sign, utils } from 'ethereum-cryptography/secp256k1'
|
import { getPublicKey, sign, utils } from 'ethereum-cryptography/secp256k1'
|
||||||
import { bytesToHex, concatBytes } from 'ethereum-cryptography/utils'
|
import { bytesToHex, concatBytes } from 'ethereum-cryptography/utils'
|
||||||
|
|
||||||
|
import { generateUsername } from './utils/generate-username'
|
||||||
|
|
||||||
export class Account {
|
export class Account {
|
||||||
public privateKey: string
|
public privateKey: string
|
||||||
public publicKey: string
|
public publicKey: string
|
||||||
public chatKey: string
|
public chatKey: string
|
||||||
|
public username: string
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const privateKey = utils.randomPrivateKey()
|
const privateKey = utils.randomPrivateKey()
|
||||||
|
@ -14,9 +17,9 @@ export class Account {
|
||||||
|
|
||||||
this.privateKey = bytesToHex(privateKey)
|
this.privateKey = bytesToHex(privateKey)
|
||||||
this.publicKey = bytesToHex(publicKey)
|
this.publicKey = bytesToHex(publicKey)
|
||||||
|
|
||||||
// TODO?: add 0x prefix to public key
|
// TODO?: add 0x prefix to public key
|
||||||
this.chatKey = bytesToHex(chatKey)
|
this.chatKey = bytesToHex(chatKey)
|
||||||
|
this.username = generateUsername('0x' + this.publicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sig must be a 65-byte compact ECDSA signature containing the recovery id as the last element.
|
// sig must be a 65-byte compact ECDSA signature containing the recovery id as the last element.
|
||||||
|
|
Loading…
Reference in New Issue