Skip to content

Instantly share code, notes, and snippets.

@tegila
Last active May 25, 2023 14:03
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 tegila/40b4df67d6079164c33ff8072fc4bb4f to your computer and use it in GitHub Desktop.
Save tegila/40b4df67d6079164c33ff8072fc4bb4f to your computer and use it in GitHub Desktop.
Awesome work from @fiatjaf and @paulmillr resulting in total integration between #nostr and #bitcoin
const log = console.log;
import { hex } from '@scure/base';
import * as btc from '@scure/btc-signer';
import { secp256k1, schnorr as secp256k1_schnorr } from '@noble/curves/secp256k1';
import { bech32 } from '@scure/base';
const privKey = secp256k1.utils.randomPrivateKey();
//const privKey = hex.decode('');
log('privKey', hex.encode(privKey));
log('nsec bech32', bech32.encode('nsec', bech32.toWords(privKey)));
//const { prefix, words } = bech32.decode('nsec...');
//log('privKey from words', prefix, hex.encode(bech32.fromWords(words)));
const pub = secp256k1.getPublicKey(privKey, true);
log('secp256k1.getPublicKey', hex.encode(pub));
const schnorr_pubkey = secp256k1_schnorr.getPublicKey(privKey);
log('schnorr.getPublicKey', hex.encode(schnorr_pubkey));
log('npub bech32', bech32.encode('npub', bech32.toWords(schnorr_pubkey)));
log('btc.p2tr(schnorr_pubkey)', btc.p2tr(schnorr_pubkey).address);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment