Skip to content

Embedded Public Key IDs #12

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

Merged
merged 5 commits into from
Mar 5, 2025
Merged

Embedded Public Key IDs #12

merged 5 commits into from
Mar 5, 2025

Conversation

btoms20
Copy link
Member

@btoms20 btoms20 commented Mar 5, 2025

What:

  • This PR adds additional support for PeerIDs with embedded public keys in their ID.

Changes:

  • The PeerID equality check can now compare across traditional (SHA256) and Embedded PubKey (Identity) IDs.
  • Introduced public func traditionalB58String() throws -> String to force the traditional SHA256 version of the ID.
  • The existing CID initializers support embedded public key ID's now.
  • PeerID stores the actual Multihash instead of just the Multihash's underlying value.

Fixes:

#11

Result:

Allows the following

// Embedded Public Key
let peerID1 = try PeerID(cid: "12D3KooWAfPDpPRRRBrmqy9is2zjU5srQ4hKuZitiGmh4NTTpS2d")
// Traditional (SHA256 variant)
let peerID2 = try PeerID(cid: "QmPoHmYtUt8BU9eiwMYdBfT6rooBnna5fdAZHUaZASGQY8")

// Equality Check
print(peerID1 == peerID2)  // true

// Embedded version has a public key available (for signature verification, etc)
print(peerID1.type)  // .isPublic

// Traditional version does not have a public key (it's an ID only)
print(peerID2.type)  // .idOnly

// Embedded PeerID's
// default to staying embedded
print(peerID1.b58String)  // 12D3KooWAfPDpPRRRBrmqy9is2zjU5srQ4hKuZitiGmh4NTTpS2d

// but we can still grab the traditional SHA256 value if necessary
print(peerID1.traditionalB58String())  // QmPoHmYtUt8BU9eiwMYdBfT6rooBnna5fdAZHUaZASGQY8

// Traditional PeerIDs
// can only ever be traditional (since hashes are one way streets)
print(peerID2.b58String)  // QmPoHmYtUt8BU9eiwMYdBfT6rooBnna5fdAZHUaZASGQY8

print(peerID2.traditionalB58String())  // QmPoHmYtUt8BU9eiwMYdBfT6rooBnna5fdAZHUaZASGQY8

@btoms20 btoms20 added the dependency-check Tests direct dependents for breaking changes label Mar 5, 2025
@btoms20 btoms20 merged commit 0d2f304 into main Mar 5, 2025
23 checks passed
@btoms20 btoms20 deleted the embedded-public-keys branch March 5, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency-check Tests direct dependents for breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant