0.0.1 • Published 5 years ago
cli-zeropool v0.0.1
ZeroPoolNetwork
Description
ZeroPoolNetwork is a pure JavaScript library for iterating with ZeroPool Ethereum smart contract.
Installation
todo
Usage
const zp = new ZeroPoolNetwork(contractAddress, ethPrivateKey, zpMnemonic);
Deposit
const token = "0x0000000000000000000000000000000000000000";
const amount = 10000002;
zp.deposit(token, amount)
.then(console.log)
/*
{
deposit_blocknumber: 105,
proof:
[ 10618278091481595704348122510710872038636087287541195770304448240179433487922n,
6820251732637745465222229593186089075846105382438918454582995391188310250557n,
7977764039042320623077421308147012660708782524110320576507395364490330869445n,
14953914461711728287547527200248050087041701094087376838307292254072088741940n,
10460258403696081901780263923490850849732816570038643292297476947390988200706n,
2718212615333563440564856193714672454221088851454469820813074089369347359171n,
6789030152397715455983892498661851461827682830031328466936460904369117556271n,
93232926217065064018980471662218186714626644362117158630381502078378084215n ],
message1:
[ 19042329244453370110898339843660190389989373460564000794295392891117279937833n,
6701703612611537740033634303587792786233045263257223542047708984594501958898n,
4502765180101631898944396485550403933458001779181488619404817317480060242672n,
20578363314024645901478243055996495230838830878598425421289539242010094358932n ],
message2:
[ 13181868285613862887915925816963627993565093851737515661429695741209044531872n,
14767233887671425842194198584424922539547194182969602793970424698396606394403n,
15238398247937055560286424375738635418404127500824945360619249482836884226062n,
34666902582085039256491828860506714807643371907628932397069673737056369511552n ],
owner: '0x5c526bc400c619Ca631619F52C58545ad56a0F19',
delta: 10000002n,
token: '0x0000000000000000000000000000000000000000',
utxo:
[ 5927196335330132757957966971520035472662937622288203020448836932640305357500n,
6675163126093257903099739234723449784990797034507726406515264335056294826463n ],
nullifier:
[ 15405626329718232127705544346089433941806776316312070447688218215139210550700n,
14693442481534138816492462133958000852601574444227129873663807305026644958164n ],
rootptr: 0,
new_root:
17970794380061284616596800972425971487597130002759127715876732862858270648168n
}
*/
My Deposits
zp.myDeposits()
.then(console.log)
/*
[
{
deposit: {
token: '0x0000000000000000000000000000000000000000',
amount: '10000002',
txhash:
'0x626b9a6681dae7ec6776d083f08c42fba7c0d1f68bbead511478235ca5afc257',
owner: '0x5c526bc400c619Ca631619F52C58545ad56a0F19',
blocknumber: 105
},
isExists: true,
isSpent: false,
spentInTx: 0
}
]
*/
Cancel Deposit
const deposit = {
token: '0x0000000000000000000000000000000000000000',
amount: '10000002',
txhash: '0x626b9a6681dae7ec6776d083f08c42fba7c0d1f68bbead511478235ca5afc257',
owner: '0x5c526bc400c619Ca631619F52C58545ad56a0F19',
blocknumber: 105
};
zp.depositCancel(deposit)
.then(console.log)
Publish blocks
const block = {
deposit_blocknumber: 105,
proof:
[ 10618278091481595704348122510710872038636087287541195770304448240179433487922n,
6820251732637745465222229593186089075846105382438918454582995391188310250557n,
7977764039042320623077421308147012660708782524110320576507395364490330869445n,
14953914461711728287547527200248050087041701094087376838307292254072088741940n,
10460258403696081901780263923490850849732816570038643292297476947390988200706n,
2718212615333563440564856193714672454221088851454469820813074089369347359171n,
6789030152397715455983892498661851461827682830031328466936460904369117556271n,
93232926217065064018980471662218186714626644362117158630381502078378084215n ],
message1:
[ 19042329244453370110898339843660190389989373460564000794295392891117279937833n,
6701703612611537740033634303587792786233045263257223542047708984594501958898n,
4502765180101631898944396485550403933458001779181488619404817317480060242672n,
20578363314024645901478243055996495230838830878598425421289539242010094358932n ],
message2:
[ 13181868285613862887915925816963627993565093851737515661429695741209044531872n,
14767233887671425842194198584424922539547194182969602793970424698396606394403n,
15238398247937055560286424375738635418404127500824945360619249482836884226062n,
34666902582085039256491828860506714807643371907628932397069673737056369511552n ],
owner: '0x5c526bc400c619Ca631619F52C58545ad56a0F19',
delta: 10000002n,
token: '0x0000000000000000000000000000000000000000',
utxo:
[ 5927196335330132757957966971520035472662937622288203020448836932640305357500n,
6675163126093257903099739234723449784990797034507726406515264335056294826463n ],
nullifier:
[ 15405626329718232127705544346089433941806776316312070447688218215139210550700n,
14693442481534138816492462133958000852601574444227129873663807305026644958164n ],
rootptr: 0,
new_root:
17970794380061284616596800972425971487597130002759127715876732862858270648168n
};
const blocks = [block];
const blocknumber_expires = 500;
zp.publishBlockItems(blocks, blocknumber_expires)
.then(console.log)
Find own UTXO
zp.myUtxos()
.then(console.log)
/*
[
{ token: 0n,
amount: 10000002n,
pubkey:
12123946667276826336013985323462868612130966473467100169422703722373267055672n,
blinding:
18782047853899156349418357931391833619305251468979533390192400340875930082397n,
mp_sibling:
[ 6675163126093257903099739234723449784990797034507726406515264335056294826463n,
9885323406998500013793438129556536303224276963647976814508482533349574357385n,
17325516636655203304685357446470211555866789883064202373892151823301208051968n,
15362496748596162224562673039646463735701166694902230246191366360084089741808n,
3171421283011099678172213181064215781395844368275901880503819278767032266053n,
811463681839953651777473541765908085536220022209428190504815069489494010885n,
13064558374208152162708697998995611495305529433229206948157197076451175327959n,
7311503910832266130755624400428811561405414443392140543102318211775248233362n,
17002201217364759451217610853591697968986488295235380974427951403550807321707n,
3500442693561461904038125704341979247251580107582557078642280160477539792818n,
10501656479781836719197170875200353438080615205837812789201747535798868006609n,
12914839239293365621585921068127683428941648179795690273965418411181646964415n,
12492880136601929540904754914885001782263519525598738093563325262150635302360n,
17936846559010455689227552817658893787011739602623722562423495781781027896246n,
13121683564499582125450586031954700642263221699331733123771659586379936915090n,
2151306395078888140082390342396672064177601520918049536222458442287316625149n,
973981158916562824715210270245787078520087699511931306830353220473866989272n,
12898540022437736719586872477129837513582070640020546314181205384805761992552n,
10735091884781591299635655521928651084111810461354093711649475411912469649843n,
13327530160302227271697984708670609451674249054901805775401956241509057418700n,
15986313087792016329347698116251406749758077340959961537937482287420481099813n,
21663645665006187845941287869331227818803254029633093035761111206856504590873n,
6894123801651624732464317171894904979383696323335879951392387189806360479396n,
3143742548657777282352720086119375615149853609086256306717859951072208904762n,
11576922831286256560284620841077464395695347730830789665177223146385642313483n,
19618776947554247327503805715555642544618369397629233982225982437668900848680n,
2957506134981379138072587707549241847260360051372092991593286757652107999695n,
5535857054133359989943183856109469945469070067054831224622465697587699586741n,
21754553799146747998207416465892208719427900803102670069027925178357742398193n,
19775312519358466453604956678080879392589515452908593006741652198244393197561n,
13238170592610231769082643290569709711316545507151657257788487738181309369115n,
414462044381848533880208748926423808039968765845791454432677987651222650587n ],
mp_path: 0
}
]
*/
Get Balance
zp.getBalance()
.then(console.log)
/*
{ '0x0': 100020 }
*/
Get UTXO Root Hash
zp.utxoRootHash()
.then(console.log)
/*
17970794380061284616596800972425971487597130002759127715876732862858270648168n
*/
Transfer
const token = "0x0000000000000000000000000000000000000000";
const destPubKey = "0x8aba319d7609671a719e30fee2b7c74631ac2ebbb19676510268f64bcae27e8";
const amount = 10002;
zp.transfer(token, destPubKey, amount)
.then(console.log)
/*
{
deposit_blocknumber: '0x0',
proof: [
'0xbc0de2bb5c64ced80dc13711c1b93590cddab7b3b6b1c14fe3a10d139008f93',
'0x2ac4eebf15b882a05c13cd04f3b1aa22880273e82d05732e32d34a64d53ee0db',
'0x2da1714d2833657b2947ee84c54101b5eda3cac6a7714fd28762ee2d8c242539',
'0x4e864c5c780d46dc1481587206cc73183d5e989c4f70ec3acb680677f153e6f',
'0x9e7429c7ed962d1d872581edc26c5d9fdf36c811ae902d902dfd51d27e411c',
'0xedd17246b810febc50a6ab68955d933e6bed4c0418a5b2a8753074768637b12',
'0x11c9f1331e99549364bc8bb6d4ae6e17651a1c73851298d97b821b53472f1e9e',
'0x227826b37a9f8e75880aa638945cdb2e3357947f870d112e02fdab598340d99'
],
message1: [
'0x186de6179698a83a56146038d1f9e5acc4e8a84c5ceca4a2348af5843b2978d2',
'0x2232a8f14876d62545cb640fa89fa94c42265d384a4bf822cd11180018fabe6b',
'0x23427ee7c9cf062f9dde80c4f5d116a3c417dcf6f3915dfcde1ee45919efb4b7',
'0x1e7a41884a62ca6d76b0ea017675b31b377f951e7ed6f1e4230a27b3a3ec9a9c'
],
message2: [
'0x62c9add0a739438ed41217c91bea0b1f7d2f321ef508912d56b629650a53784',
'0x1662000a99028e6eed10ea6f4528238811638428d19c89b22f8b9e7a4cc31cc4',
'0x22676943dc916d852421b883110ce84289a98d51366bce0ccf1940c5015ac7bb',
'0x4d8c69ac13afa256cf9fa77ece69ab2aaccf0a02772667c357f6fdc5975c6589'
],
owner: '0x0000000000000000000000000000000000000000',
delta: '0x0',
token: '0x0000000000000000000000000000000000000000',
utxo: [
'0x18d2c431c0d9252a3d1ff0bf66b29576d1fcaa6fc25b4792064274304c398e1',
'0x21c09f80d474695957affb76d1e9d545c5b4651d610b2a7c4fd8a7095e95b0e7'
],
nullifier: [
'0x2e3ed970064b1c6a89bc6ebcc29d38435e0207e8d0b2b5f4285679fbc4018c4a',
'0xefe35d367ecdb5da9e3b5a48292c58078a25a8c4de9e7f0860ad385257061a6'
],
rootptr: '0xa',
new_root:
'0x1b825f30e484930c34885de46e32a4844a8705956e62e87b500b4ca4269acccc'
}
*/
Prepare withdraw
const token = "0x0000000000000000000000000000000000000000";
const numberOfUtxo = 1;
zp.prepareWithdraw(token, numberOfUtxo)
.then(console.log)
/*
{
deposit_blocknumber: '0x0',
proof:
[ '0x2c845ff87b32298ec0bf00edcdd1c68e2bf7138731e19e487cb94ee2060ed8eb',
'0x2e1493a39a304de70aa49e5641bd423c00b4c2be67833d8ad06437c96d6e05ec',
'0x23e67ebe363e617058033f09931d489f99c0bc59c471984a4c8d593f2551b77b',
'0x2bb921e46736d45e54ef6be1c104ca6d8d54f4b0b698fdc0730fb9f2367bc850',
'0x2f97d73833b4e75d9fb14cfdbe298ff0cc0e34c4fbad4a21ece030b4babb5d57',
'0x24cf80d6bb73532b0585b205d50b21fa1f85190e8322fe0d8c31205162cb6814',
'0x7332e8a4dda326fedbca01e6948774aeee6e219ebe8abb4b4e99687780fdc87',
'0x20813c966d5ae9708c77bc27987aa52ff8ad5d28c604ca2aacaddc6cd6510442' ],
message1:
[ '0xe7ddb23ce6ce2dcf4fdea047fd71ed04f6f88a05f5ee0cbf268e624ab0a6d6b',
'0x15af8d51e96217e0b7c93b4be09a154cc58f53b9a7e0efd3f76f06a01477af1d',
'0x2563056781cf263b1f14795f1950d99d97bbdf875514fd6b7eb2d0cb50c8f49c',
'0x2f2b7d3dd91d78faf0eb90cf128a8f3502830bd3cf3fe6f477cb5e790bb53d09' ],
message2:
[ '0x122cfbae9923c20ed0d03e292b5cc19b8842112dfad71ae6643217d0db26428',
'0x4ebb71be1677cfeaf75c9a7f92982fb1253e3c88f6ee20340912d3e891fb7b9',
'0xc69c65a503fdef1c5f459cd012a3a7ad94a42ec225ca7f2bd3802831af0b6f6',
'0x35e55318020fc5cc17e92ec50105b9556560bf80c5bf5fa8c75df1ac86437edd' ],
owner: '0x5c526bc400c619Ca631619F52C58545ad56a0F19',
delta:
'0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593effe79c7',
token: '0x0000000000000000000000000000000000000000',
utxo:
[ '0x51101e56d94dfac800d52f6a163a73fd9ab93c0fef6000f3391204cb2359b1e',
'0x28b9a4feace9b01fde53b37b3a51915eab2d90fddaad331629a795c1b2e28d71' ],
nullifier:
[ '0x2e3ed970064b1c6a89bc6ebcc29d38435e0207e8d0b2b5f4285679fbc4018c4a',
'0xbd7b1f2ac575a7f5621ed8ad2f67922d424c5d077e8c0200feaaeb19ef26cca' ],
rootptr: '0xa',
new_root:
'0x201a8de61a4a0fa3278ece76cfe0265f4ccc1f60b9d1aef02d1cc9bb8e633e9c',
tx_hash:
'0xc68eca23f89667fd80105d1d7e9c7a087297a7ce701d11e50109e5dd66d9ad98'
}
*/
Withdraw
const token = "0x0000000000000000000000000000000000000000";
zp.withdraw({
token,
amount: 10 ** 5,
owner: zp.ethAddress,
blocknumber: 168,
txhash: "0xc68eca23f89667fd80105d1d7e9c7a087297a7ce701d11e50109e5dd66d9ad98"
}).then(console.log);
0.0.1
5 years ago