diff --git a/src/index.js b/src/index.js index 08dd49e..f220efc 100644 --- a/src/index.js +++ b/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 } }