mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-26 02:22:20 +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')
|
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = id
|
this._id = id
|
||||||
|
this._idB58String = ''
|
||||||
this._privKey = privKey
|
this._privKey = privKey
|
||||||
this._pubKey = pubKey
|
this._pubKey = pubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get id () {
|
||||||
|
return this._id
|
||||||
|
}
|
||||||
|
|
||||||
get privKey () {
|
get privKey () {
|
||||||
return this._privKey
|
return this._privKey
|
||||||
}
|
}
|
||||||
@ -61,7 +66,7 @@ class PeerId {
|
|||||||
// of go-ipfs for its config file
|
// of go-ipfs for its config file
|
||||||
toJSON () {
|
toJSON () {
|
||||||
return {
|
return {
|
||||||
id: mh.toB58String(this.id),
|
id: this.toB58String(),
|
||||||
privKey: toB64Opt(this.marshalPrivKey()),
|
privKey: toB64Opt(this.marshalPrivKey()),
|
||||||
pubKey: toB64Opt(this.marshalPubKey())
|
pubKey: toB64Opt(this.marshalPubKey())
|
||||||
}
|
}
|
||||||
@ -77,7 +82,11 @@ class PeerId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toB58String () {
|
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