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

Tag ed25519 public key bytes with 0xed and decode into Principal #196

Open
DougAnderson444 opened this issue Jan 17, 2023 · 2 comments
Open

Comments

@DougAnderson444
Copy link

Hi all,

I've been looking for a way to generate a Principal from ed25519 Public Key bytes. I can't find it in the code (and the readme is out of date for Principals) and think this was originally intended to encode ed25519 public key bytes with 0xed, but it does not do what the comment implies it should do:

* Encodes given Principal by tagging it's ed25519 public key with `0xed`
* multiformat code.
*
* @param {API.Principal<API.DID<"key">>} principal
*/
export const encode = principal => DID.encode(principal)

Am I correct with creating a Principal like this, the code seems to work:

import { tagWith } from './multiformat.js'

const taggedMF = tagWith(Verifier.code /* `0xed` */, new Uint8Array(publicKey))
const principal = Verifier.decode(taggedMF);
const audienceDid = principal.did() 

If this is elsewhere in the codebase I must have missed it, but if not, please consider this issue is raised to add this functionality to create tagged, encoded Principals from raw bytes. Thanks!

@Gozala
Copy link
Collaborator

Gozala commented Jan 20, 2023

Am I correct with creating a Principal like this, the code seems to work:

Yeah that seems reasonable!

We do not have a function to do exactly what you're looking for because we store tagged keys so that when importing them we don't need to have additional context about what kind of key it is.

I suppose we could add such a function, but I'm bit hesitant because lib is trying to abstract actual key algorithms with a universal interface. Importing raw keys obviously not going to work universally, but that's not so say we can't add a function to linked module to do just that.

@DougAnderson444
Copy link
Author

Thanks for your feedback 😀

For context, my use case is essentially: "Here is my public key, can you please send me a UCAN?" which is coming from someone who generated their keypair outside the library (so it wouldn't be tagged yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants