From 3e89d53d25a7b42e49898271c7be7fd56ec0af43 Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 10 Apr 2020 12:58:17 +0300 Subject: [PATCH] utxo class init --- src/index.ts | 34 ++++++---------------------------- src/utxo.ts | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 src/utxo.ts diff --git a/src/index.ts b/src/index.ts index c2e69d7..c760647 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,36 +1,14 @@ import BigNumber from "bignumber.js" -class UTXO { - amount: BigNumber; - blinding: BigNumber; - pubkey: BigNumber; - privkey: BigNumber; - commitment: BigNumber; - treeIndex: Boolean[]; - nullifier: BigNumber; - - constructor( - amount, - blinding, - pubkey, - privkey, - commitment, - treeIndex, - nullifier, - ) { - - } -} - -class Transaction { - inputs: UTXO[]; - outputs: UTXO[]; - -} +import { Utxo } from './Utxo' +const { bigInt } = require('snarkjs') +const crypto = require('crypto') +const rbigint = (nbytes = 31) => bigInt.leBuff2int(crypto.randomBytes(nbytes)) async function main() { - const deposit = new UTXO(); + const zeroUtxo = new Utxo(bigInt(0), rbigint(), rbigint()) + console.log('zeroUtxo publicKey', zeroUtxo.publicKey()) } main() diff --git a/src/utxo.ts b/src/utxo.ts new file mode 100644 index 0000000..4400e7e --- /dev/null +++ b/src/utxo.ts @@ -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]) + } +} +