Last active
September 5, 2024 15:06
-
-
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
This file contains 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 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