Skip to content

Instantly share code, notes, and snippets.

@iPaulPro
Last active April 4, 2024 20:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iPaulPro/2255639769eeedb1394921978a6be895 to your computer and use it in GitHub Desktop.
Save iPaulPro/2255639769eeedb1394921978a6be895 to your computer and use it in GitHub Desktop.
Query BitClout Postgres DB with public key
const bs58check = require('bs58check')
const getPublicKeyBase64 = (publicKeyBase58Check) => {
const decoded = bs58check.decode(publicKeyBase58Check);
const payload = Uint8Array.from(decoded).slice(3);
return Buffer.from(payload).toString('base64');
}
const getPublicKeyBase58Check = (bytea) => {
const prefix = [0xcd, 0x14, 0x0];
const prefixAndKey = Uint8Array.from([...prefix, ...bytea]);
return bs58check.encode(prefixAndKey)
}
// You can then query using the result of getPublicKeyBase64():
// select * from pg_profiles where encode(public_key, 'base64') = [PublicKeyBase64]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment