feat: cache b58 id

This commit is contained in:
Friedel Ziegelmayer 2016-12-14 09:05:07 +01:00
parent 5d6a962b6c
commit bebb0a7eae

View File

@ -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
} }
} }