Skip to content

Instantly share code, notes, and snippets.

@zhfnjust
Forked from scrypt-sv/txAdvancedArgs.js
Created November 16, 2021 16:01
Show Gist options
  • Save zhfnjust/67ee5ea7d368f9e13de78547ae253677 to your computer and use it in GitHub Desktop.
Save zhfnjust/67ee5ea7d368f9e13de78547ae253677 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