js-sero-client
v1.0.2-rc1
Published
Utilities for handling SERO client
Downloads
112
Readme
Install Package
npm install js-sero-client
Account
const sero = require('js-sero-client')
const account = sero.Account
const core = require('js-sero-client/core')
const seedStr = 'fd1b401d2bbfa09fba577b398b09b5ea075bd8f37773095c6e62271a4b080977'
const seed = Buffer.alloc(32, seedStr, 'hex')
const keys = account.NewKeys(seed)
const rnd = core.GetCZero().RandomU32()
var pkr = keys.GenPKr(rnd)
console.log('SK: ' + keys.sk.toString('hex'))
console.log('TK: ' + keys.tk.toString('hex'))
console.log('PK: ' + keys.pk.toString('hex'))
console.log('PKr: ' + pkr.toString('hex'))
if (!keys.IsValidPKr(pkr)) {
core.ReportError('invalid pkr')
}
if (!keys.IsMyPKr(pkr)) {
core.ReportError('Is not my pkr')
}
TxSign
const tx = require('js-sero-client/tx')
const txParamStr = '{"Gas":25000,"GasPrice":1000000000,"From":{"SKr":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","PKr":"0x65f577e2bf871108ca34b16a9559af644f5ce9df198ea2a846836fa45c9b602cc3c2b5c28766c639b3ff14331b0a61a14ce180299c33475abf11e845d3238f20a5ac694b5caf937daeac748fe30096aa57ab6931a359c9c7d94b740ad09bf320"},"Ins":[{"SKr":"0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","Out":{"Root":"0x224013f83250b293c0ee8871f61e1637eeb1fc2ed449a1943a24a77bb6cf5d1c","State":{"OS":{"Index":69,"Out_O":null,"Out_Z":{"AssetCM":"0x6bf6baba3f4805d0e8f8ee7a956a4b2411d804dcb47a6e1d32578fd91aed9318","OutCM":"0x080c31c80d3bbbd0aab1a01d6a8aad6dda6e7e5019160c7aec2293e8b14f478f","RPK":"0x739342f3bddc45ecd43ac8cdcd384bf8adf04ab5794846d316762d102a01c94d","EInfo":"0x4043e110701d2c483164af75ee90f66832f7a4947e93d95dff39dcd1dee22e8bb431e38b55764ffb315be40ac419a2e4e2323e52938028bdb77c2c8ac8ec24bf4f39c2d64cee4d8f80142bbc882e022ecb0069558ee086044918ac92ea529bea7bdc8c219f5f0db027a0e9b94b4e7e353e84bd44920f3a100a062aacb25e649d128b9db6e47f9bceafd51e89e4d005e1a35a243f10e32878dab80c93562ce29a568b5b0769ca150840eeb66920824509aacfe5653a84e6e334e70f96a483cd7a6c3013e4af90e8afb46e27721dbc0c2d1253027c55702602da643f880c1cf6cf","PKr":"0x65f577e2bf871108ca34b16a9559af644f5ce9df198ea2a846836fa45c9b602cc3c2b5c28766c639b3ff14331b0a61a14ce180299c33475abf11e845d3238f20a5ac694b5caf937daeac748fe30096aa57ab6931a359c9c7d94b740ad09bf320","Proof":"0x03ed22d9e7e1194a60f82d03b870f85dd64a5be2cd5603ef84de6af7b93d9900140a3923664dd725039188626c3e7935f863b1ba4ce0b5c402327cbce4edee979de3aba76c1a615ff8cccacc3e7e89e83b5c3eeb7756f0af2fab479071b60ab34e0603bbb7a67f2b6078eb6c671b52c577c74148035b9b5bb5c0b47e52519fad0e4511"},"OutCM":null,"RootCM":"0xcd7fe67eb0a501c8c7c518424b990857fd3959c2a56641b020e8133965b5850b"},"TxHash":"0x0f4fb9b7d886b5cb18e1922326461758aae9a969d8bc300f35d3762083eeff7f","Num":32}},"Witness":{"Pos":"0x45","Paths":["0x41ec5b46e1c5785909ae38554cae2b5aad0db88fdcfbcc24b74dee14cbd47a12","0xe5b178544030ee054d5837008172fa9762521fcb5f0c64977b794c947d1bc29a","0x432403df67a365c57e19c61138edd3acb6527d78f302ffb4fee12956ffb19fa5","0x23b07f59402d6ed982e38170d08b5fdf2a48dda2e07029622d5472d49c264f1c","0xd789a8b2fdfaa399a5e40799e37146af40227a5bdfd4e23c9d7157c7f4ff130e","0x9970271e96d1771eff06ce5c540d6fcf5df59234af6204f45b31ea151c589ba9","0x22e2f7991e4fc3d11d14adc9b66c61050c7b8c2cbd7496fae19571cd1eef3d8e","0xa0f4e174f7fe46368a2c4ed56659c672e0187d0bca2e7619660b9e38564a958e","0x19faaa87edc67b3a03edb38a7690e88bb35f90eaa38556adf4eea04f0a41329b","0x78e2fae5201f6e8b5bcbb7d2cfd9a05b51ee5daac55dc1c67d5bf9496443b124","0x8c473676e83787c7748e9d956e0fd2f316e00dd13771f2cee0367fcf5588f40c","0x6488a7d2ae45fe1f028a2b3d140073efba82aba8db01e9c96d165d515a2b5ead","0xc2baf1c827cfce1eb852561d737b454fe12c7555945ba68017fa6222c93d7f1d","0xc6052c7af376fef1daf078b85913d5b147a68f4c6de75cc9e49399d62a515c92","0xbddc1775065a6ee9386737303af7b9da6ad995c369706fbdcf4a7fcb8cc2cca0","0xd14f617a18014f5bb594e7ca4c999354bc095a6b136a6cd3d097928fe3defd86","0xcfe35d771cfcc111868b623b0885277c74b94f6f5bc544c78c66bc0b5458a524","0x4163b9a6368d125edd8ee3e538f320752b0bd0f113dd79349a72fa3af06c64ab","0x78cb874b15e37a66ae8eee4cf13b1e8af6e63ea72c234067a1023f1f6d989a06","0x13c184ef8cd27a98857dcf2c0a21cefde8808551b4fbc18b1a62b97186662990","0x93584e7b2c0ced44fca221aa0d934cedb1cddb82e0296f041b1934875d505986","0x77865dd539eda3960520bee9cd3e0a8563b9a0ddc854885a1d9dee14b11b3da0","0x8665f83639732248eeba9454540184cc94598e0fe73d126b6e3db31725352f28","0xa322e919186a4b2f2039601db976b005e7b2968e56d75cbf71a77bbe8905292b","0xb995f437374bd1e1a9eb3443bc3d7855f15b4d6ce628051332fe20a3a8cd0e9c","0x75df3f7f39ed5132f0b10ca3d97487eca629128ad37d4e6b5ba391ece4f4702c","0xf59c191e25659b57738ef22ede3d6113091d0425f40ec862de14bf1149fb382e","0xa9588c6ec3513da0ecfdb7967fcf6711ca3566e5ae1b8b60bcc7d54a123f2a07","0x3edc6044a176db79bb6ffccd3f3c950cb5a56b9ba65d4243e9e03cbcf4bbe382"],"Anchor":"0xe909cf147b71fc441ba263b1d5b50870444a8c54bc1d111cf6989a531abf71ad"}}],"Outs":[{"PKr":"0x130da02681642fce51046e641c589b70dab751c95c577ed16bf1169e4fad0e8de7c93ecd80d93b26e9fe59de9c60a85bf015c031660c86ce037f3c17da53c19749eda6c5686e1cce7b2a928c429064f9cc357d73a946ad1c76e728630a882a14","Asset":{"Tkn":{"Currency":"0x000000000000000000000000000000000000000000000000000000005345524f","Value":1000000000000000000},"Tkt":null},"Memo":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"},{"PKr":"0x65f577e2bf871108ca34b16a9559af644f5ce9df198ea2a846836fa45c9b602cc3c2b5c28766c639b3ff14331b0a61a14ce180299c33475abf11e845d3238f20a5ac694b5caf937daeac748fe30096aa57ab6931a359c9c7d94b740ad09bf320","Asset":{"Tkn":{"Currency":"0x000000000000000000000000000000000000000000000000000000005345524f","Value":14999900000000049973},"Tkt":null},"Memo":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}]}'
tx.SignTx(
txParamStr,
keys.sk.toString('hex'),
(err, content) => {
if (err) {
console.error(err)
} else {
console.log(content)
}
}
)
decOut
const outStr = "[{\"Root\":\"0x763f7f5e16506128824178bf2ee855e35a4b93689e8e54ed1e3d03177da09917\",\"State\":{\"Num\":345,\"OS\":{\"Index\":384,\"OutCM\":null,\"Out_O\":null,\"Out_Z\":{\"AssetCM\":\"0x5545b6d57ef6a35b124963daa0dee992da5243e31eb0d99d8f66d0f1a13e9012\",\"EInfo\":\"0x04fc0547da3590767317c3719f7b89516f7afb01037ca09cefc0bd75b4dccb95cfff665a0028069289960dcf07b69928e8d3da06ad0249ba7fd2c31505f5eef96db8741382f68be2e34210be409a84ae67be5c4687ddef64c13bba278d5fbea9d69f1a335585c8544a3b3eac8e7812041a01d95326f8da65e588784cc70c1b5a4b5dd7d0f5921007aef4043ac515cadc864ac206b2902a04022603566a437deb3100fdc04b88eb249746631447cf25964fb8f32fb4314455efbc1ea7520865f52aa762629ab8eed99e0a7918918dfe186188ddf61d7fb3d855a64d71ff5c9688\",\"OutCM\":\"0x5d3ba6999629152264618694968cd18a7a4c7790e2c213498e99209c564039ab\",\"PKr\":\"0xfaf5e31e63cf54a81cb494e57719abf9e2af71fb52720a4ad476ce78006ac0af202f0329828102356f29597815773200b75775b6837bf8592e20eb4df75e73a9c01a79af111451f7f38f4c2f79f03772a9e09b31d5c7bf2ab37808835362c4a0\",\"Proof\":\"0x02902bbd460a55b0dbaf4a96848d0b24ef5f2faab6409b3d68dc77f8f32a96a41d0a450a6076693fd6bef7e4466e6f0533e18905c8fc656741e7d1faf2ae298dba7edb87ab8b1293900e3fac4bd8e47a09b1ee02cf7770965bf990f60c53f57a3c08032dcc4023c7aa706f8fd35c68119caa73d15e8ca1ff35cc9e69fcdd8e46d5120c\",\"RPK\":\"0xb74e284e16cc77659690cee346076701a1040539ce84e6af71292f0acd5a906d\"},\"RootCM\":\"0xe495fe6b43813719352a6256e826dfae9d61d32b28ce1814e0b6a60b9cb05009\"},\"TxHash\":\"0x91a5cc04f6af1803bd8a523fcf23bc845c42552bb7d6d0a49e347ef5070ba274\"}}]"
tx.DecOut(
outStr,
keys.tk.ToBase58(),
(err, content) => {
if (err) {
console.error(err)
} else {
console.log(content)
}
}
)
confirmOutZ
const keyStr = '0x8e27d9fd65a178569b852cf71e476073b68c2f241074bbd7be712f145b84ee32'; //get from result of SignTx
const outzStr = "{\"AssetCM\":\"0xb5c269bc6d7bcd9c1faf4b41349194523a4c55cc7761bc69d649b17bcdaf0425\",\"EInfo\":\"0x589fa1199c1140c1c2e8256f9c10aa3e5388ae0712fc115dbd175650cd5fb287d590ab3120e48cd498c3fbb8e1e83f5025384ab644a2a5080dfc9843cb4b20d70f9657622e8e9f87d5a044f4c4af3b11e9dbc35727452f3ce479dea45205ce23ed7aaea87526b3700634ff909140c6b480ef5d191e54b49ed6cd9099e30cd0306d48bfc8375e1bca92ab90ddc3869ca4e3656974723868b43443f08a5c0bdbeee526d483b00cb838e9533be2db4404132c74f21b02fe9d15a42773f036281f874a5ce1c8e041219f1489fd4e68b80f4ad8634d04803a72c0119c485741e562c1\",\"OutCM\":\"0xb190835c31d22836a7669e126ab47d94a588acf6e540c49e95816297b3e48c14\",\"PKr\":\"0x1da430ae0b5e809de9260fa67dff5057160483ccf03f0a6bcb5fb2b573e6ce2bd7e8efb271a0822dcc917406e765763720dd1d3d456dc62232bdb050ac7161920f1f84c661ed065b0df24850b00de5de58b4f50bbe44ebcf70c2d40af27b0126\",\"Proof\":\"0x03eed61dadcfd3383c413664da8743e0f54914e50e9c9d48469eb45ad1eb551f1d0bd13aa8992d45647564c2f104558e4c6b4a1be09033bf5b960039b7a26cf57e9f5bcded6bd700d112958a353f538e2916c15a87c6ee2e01e8d13bc2417c79720102b35e7f7e336ab8519c47896e39561d1a6ab0cf99470adaadbf45edab24ad9b2a\",\"RPK\":\"0xc80da3956eafc8012b504e59111980ceacfd5d86f23db452461d7bef5b3263c2\"}";
tx.ConfirmOutZ(
outzStr,
keyStr,
(err, content) => {
if (err) {
console.error(err)
} else {
console.log(content)
}
}
)