Skip to content

Instantly share code, notes, and snippets.

@scrypt-sv
Last active November 16, 2021 16:01
Show Gist options
  • Save scrypt-sv/f6882be580780a88984cee75dd1564c4 to your computer and use it in GitHub Desktop.
Save scrypt-sv/f6882be580780a88984cee75dd1564c4 to your computer and use it in GitHub Desktop.
A simple program to compute arguments for contract TxAdvanced
/*
* a simple program to compute arguments for contract TxAdvanced
*/
const bsv = require('bsv')
const BN = bsv.crypto.BN
const pt = bsv.crypto.Point
const G = pt.getG()
const N = pt.getN()
const privateKey = bsv.PrivateKey.fromRandom('testnet')
console.log('privateKey: ' + privateKey.toHex())
const publicKey = bsv.PublicKey.fromPrivateKey(privateKey)
console.log('publicKey: ' + publicKey.toHex())
const kBuf = bsv.crypto.Random.getRandomBuffer(32)
const k = new BN(kBuf, 'hex')
console.log('k: ' + k.toString('hex'))
const invk = k.invm(N)
console.log('invk: ' + invk.toString('hex'))
const K = G.mul(k)
const r = K.getX()
console.log('r: ' + r.toString('hex'))
console.log('rBigEndian: ' + r.toSM({ endian: 'big'} ).toString('hex'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment