Skip to content

Instantly share code, notes, and snippets.

@assafmo
Last active December 13, 2024 20:35
Show Gist options
  • Save assafmo/166915d529f34ee56f9542f895f46cfc to your computer and use it in GitHub Desktop.
Save assafmo/166915d529f34ee56f9542f895f46cfc to your computer and use it in GitHub Desktop.
Create bech32 vanity addresses for testing purposes
// pnpm init
// pnpm i -D bech32 ts-node @types/node
// npx ts-node stride-vanity-address.ts
import { bech32 } from "bech32";
// Debug: Test all possible values to find what maps to "1"
for (let i = 0; i < 32; i++) {
const test = bech32.encode("stride", [i]);
console.log(`Value ${i} maps to ${test.charAt(7)}`);
}
function createVanityStrideAddress(word: string): string {
word = word.replace(/ /gi, "").toLowerCase();
const alphabetMap: { [key: string]: number } = {
a: 29,
b: 26, // 6
c: 24,
d: 13,
e: 25,
f: 9,
g: 8,
h: 23,
i: 31, // l
j: 18,
k: 22,
l: 31,
m: 27,
n: 19,
o: 15, // 0
p: 1,
q: 0,
r: 3,
s: 16,
t: 11,
u: 28,
v: 12,
w: 14,
x: 6,
y: 4,
z: 2,
};
for (const char of word) {
if (!(char in alphabetMap)) {
console.error(
`Character '${char}' cannot be represented in bech32 format`
);
process.exit(1);
}
}
const mappedWord = word.split("").map((c) => alphabetMap[c]);
const address = bech32.encode("stride", mappedWord);
return address;
}
const address = createVanityStrideAddress("palmssweatykneesweakarmsareheavy");
console.log(address);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment