import { PubKey , StateLeaf , } from 'maci-domainobjs' ; import { IncrementalQuinTree , NOTHING_UP_MY_SLEEVE_PUBKEY , } from 'maci-crypto' ; class User { public pubKey : PubKey ; public votes : BigInt [ ] ; public voiceCreditBalance : BigInt ; public nonce : BigInt ; constructor ( _pubKey , _votes , _voiceCreditBalance , _nonce ) { this . pubKey = _pubKey ; this . votes = _votes . map ( BigInt ) ; this . voiceCreditBalance = BigInt ( _voiceCreditBalance ) ; this . nonce = BigInt ( _nonce ) ; } public copy = ( ) : User => { const newVotesArr = [ ] ; for ( let i = 0 ; i < this . votes . length ; i ++ ) { newVotesArr . push ( BigInt ( this . votes [ i ] . toString ( ) ) ) ; } return new User ( this . pubKey . copy ( ) , newVotesArr , BigInt ( this . voiceCreditBalance . toString ( ) ) , BigInt ( this . nonce . toString ( ) ) ) ; } ; public static genBlankUser = ( _voteOptionTreeDepth ) : User => { const votes = [ ] ; for ( let i = 0 ; i < 5 ** _voteOptionTreeDepth ; i ++ ) { votes . push ( BigInt ( 0 ) ) ; } return new User ( new PubKey ( NOTHING_UP_MY_SLEEVE_PUBKEY ) , votes , BigInt ( 0 ) , BigInt ( 0 ) ) ; } ; public genStateLeaf = ( _voteOptionTreeDepth ) : StateLeaf => { const voteOptionTree = new IncrementalQuinTree ( _voteOptionTreeDepth , BigInt ( 0 ) ) ; let lastIndex = this . votes . length - 1 ; while ( lastIndex >= 0 ) { if ( this . votes [ lastIndex ] !== BigInt ( 0 ) ) { break ; } lastIndex -- ; } for ( let i = 0 ; i <= lastIndex ; i ++ ) { voteOptionTree . insert ( this . votes [ i ] ) ; } return new StateLeaf ( this . pubKey , voteOptionTree . root , this . voiceCreditBalance , this . nonce ) ; } ; } export { User } ;