Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
Created April 8, 2024 17:50
Show Gist options
  • Save ChristianOConnor/fa07462990a74606f486f97031783e50 to your computer and use it in GitHub Desktop.
Save ChristianOConnor/fa07462990a74606f486f97031783e50 to your computer and use it in GitHub Desktop.
Make private key into tweaked oridinal tapscript address (Javascript)
import { Address, Tap } from '@cmdcode/tapscript'
import { Buff } from '@cmdcode/buff-utils'
import { keys } from '@cmdcode/crypto-tools'
async function main() {
const secret = "5b10712a7799e29441f6c27918ff27af8a8f3707da14afd352730a99fb417033"
const inscription = Buff.encode('gywJYnla8SOO5PrmVIXlcgXwAbOWlgPgDXjjAOY')
const marker = Buff.encode('ord')
const mimetype = Buff.encode('text/plain')
const seckey = keys.get_seckey(secret)
const pubkey = keys.get_pubkey(seckey, true)
const script = [ pubkey, 'OP_CHECKSIG', 'OP_0', 'OP_IF', marker, '01', mimetype, 'OP_0', inscription, 'OP_ENDIF' ]
const tapleaf = Tap.encodeScript(script)
const [ tpubkey, cblock ] = Tap.getPubKey(pubkey, { target: tapleaf })
const address = Address.p2tr.fromPubKey(tpubkey, 'testnet')
return { address }
}
main().then(console.log).catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment