utxo class init

This commit is contained in:
Alexey 2020-04-10 12:58:17 +03:00
parent c9f5d2e512
commit 3e89d53d25
2 changed files with 31 additions and 28 deletions

View File

@ -1,36 +1,14 @@
import BigNumber from "bignumber.js" import BigNumber from "bignumber.js"
class UTXO { import { Utxo } from './Utxo'
amount: BigNumber; const { bigInt } = require('snarkjs')
blinding: BigNumber; const crypto = require('crypto')
pubkey: BigNumber; const rbigint = (nbytes = 31) => bigInt.leBuff2int(crypto.randomBytes(nbytes))
privkey: BigNumber;
commitment: BigNumber;
treeIndex: Boolean[];
nullifier: BigNumber;
constructor(
amount,
blinding,
pubkey,
privkey,
commitment,
treeIndex,
nullifier,
) {
}
}
class Transaction {
inputs: UTXO[];
outputs: UTXO[];
}
async function main() { async function main() {
const deposit = new UTXO(); const zeroUtxo = new Utxo(bigInt(0), rbigint(), rbigint())
console.log('zeroUtxo publicKey', zeroUtxo.publicKey())
} }
main() main()

25
src/utxo.ts Normal file
View File

@ -0,0 +1,25 @@
const Hasher = require('../lib/mimc')
const hasher = new Hasher()
const { bigInt } = require('snarkjs')
export class Utxo {
amount: bigint;
blinding: bigint;
privateKey: bigint;
// commitment: bigint;
// treeIndex: Boolean[];
// nullifier: bigint;
constructor(amount?: bigint, blinding?: bigint, privateKey?: bigint) {
this.amount = amount || bigInt(0);
this.blinding = blinding || bigInt(0);
this.privateKey = privateKey || bigInt(0);
}
publicKey() {
return hasher.hashArray([this.privateKey])
}
}