-
-
Save zhfnjust/67ee5ea7d368f9e13de78547ae253677 to your computer and use it in GitHub Desktop.
A simple program to compute arguments for contract TxAdvanced
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
/* | |
* 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