mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-25 08:52:31 +00:00
feat: cache b58 id
This commit is contained in:
parent
5d6a962b6c
commit
bebb0a7eae
15
src/index.js
15
src/index.js
@ -17,11 +17,16 @@ class PeerId {
|
||||
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
|
||||
}
|
||||
|
||||
this.id = id
|
||||
this._id = id
|
||||
this._idB58String = ''
|
||||
this._privKey = privKey
|
||||
this._pubKey = pubKey
|
||||
}
|
||||
|
||||
get id () {
|
||||
return this._id
|
||||
}
|
||||
|
||||
get privKey () {
|
||||
return this._privKey
|
||||
}
|
||||
@ -61,7 +66,7 @@ class PeerId {
|
||||
// of go-ipfs for its config file
|
||||
toJSON () {
|
||||
return {
|
||||
id: mh.toB58String(this.id),
|
||||
id: this.toB58String(),
|
||||
privKey: toB64Opt(this.marshalPrivKey()),
|
||||
pubKey: toB64Opt(this.marshalPubKey())
|
||||
}
|
||||
@ -77,7 +82,11 @@ class PeerId {
|
||||
}
|
||||
|
||||
toB58String () {
|
||||
return mh.toB58String(this.id)
|
||||
if (!this._idB58String) {
|
||||
this._idB58String = mh.toB58String(this.id)
|
||||
}
|
||||
|
||||
return this._idB58String
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user