Skip to content

Instantly share code, notes, and snippets.

@AdamJLemmon
Created March 17, 2022 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamJLemmon/d66a2703f55032bd5eea84466f09d128 to your computer and use it in GitHub Desktop.
Save AdamJLemmon/d66a2703f55032bd5eea84466f09d128 to your computer and use it in GitHub Desktop.
ED25519 Fingerprint Generation
const bs58 = require('bs58');
const MULTICODEC_ED25519_PUB_HEADER = new Uint8Array([ 0xed, 0x01 ]);
const MULTIBASE_BASE58BTC_HEADER = 'z';
const ed25519Fingerprint = ({
base64PubKey,
}) => {
const base64PubKeyBuffer = Buffer.from(base64PubKey, 'base64');
const uint8PubKey = Uint8Array.from(base64PubKeyBuffer);
const multibaseKey = new Uint8Array(MULTICODEC_ED25519_PUB_HEADER.length + uint8PubKey.length);
multibaseKey.set(MULTICODEC_ED25519_PUB_HEADER);
multibaseKey.set(uint8PubKey, MULTICODEC_ED25519_PUB_HEADER.length);
const base58Fingerprint = MULTIBASE_BASE58BTC_HEADER + bs58.encode(multibaseKey);
return base58Fingerprint;
};
// NOTE no padding in b64!
const base64PubKey = 'DA7IPk3KCWp4bRQ413wV57FZOTycSx2FF_uaI4zF28c';
const fingerprint = ed25519Fingerprint({
base64PubKey,
});
console.log({
fingerprint,
did: `did:key:${fingerprint}`,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment