Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache b58 id #44

Merged
merged 2 commits into from
Dec 18, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ class PeerId {
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
}

this.id = id
this._id = id
this._idB58String = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this on creation :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, also throwing now on id mutation

this._privKey = privKey
this._pubKey = pubKey
}

get id () {
return this._id
}

get privKey () {
return this._privKey
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -77,7 +82,11 @@ class PeerId {
}

toB58String () {
return mh.toB58String(this.id)
if (!this._idB58String) {
this._idB58String = mh.toB58String(this.id)
}

return this._idB58String
}
}

Expand Down