Last active
April 4, 2024 20:37
-
-
Save iPaulPro/2255639769eeedb1394921978a6be895 to your computer and use it in GitHub Desktop.
Query BitClout Postgres DB with public key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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