{"_id":"@astra-js/account","_rev":"3-9218c3e4492dc9382899b1232ad1177d","name":"@astra-js/account","dist-tags":{"latest":"0.1.59"},"versions":{"0.1.57":{"name":"@astra-js/account","version":"0.1.57","description":"account and wallet for astra","main":"dist/index.js","node":"dist/index.js","browser":"dist/index.js","module":"dist/index.esm.js","jsnext:main":"dist/index.esm.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"publishConfig":{"access":"public"},"author":{"name":"neeboo@firestack.one"},"license":"MIT","dependencies":{"@astra-js/core":"0.1.57","@astra-js/crypto":"0.1.56","@astra-js/network":"0.1.56","@astra-js/staking":"0.1.56","@astra-js/transaction":"0.1.56","@astra-js/utils":"0.1.56"},"gitHead":"56606e9365721729a490c27d6a294e0daf90fbdf","_id":"@astra-js/account@0.1.57","_nodeVersion":"16.14.0","_npmVersion":"8.3.1","dist":{"integrity":"sha512-2cr+fqF55HQOldwLWroGzPlJwQO2GIaWnO2jrxuIfcaY8ZbH7n96EN4hAU6KKxozGdD3FYS/symxaqYEIVXhZw==","shasum":"49a9e5b4852a0abcb58f5c8927bf8b42c886c2e5","tarball":"https://registry.npmjs.org/@astra-js/account/-/account-0.1.57.tgz","fileCount":13,"unpackedSize":53624,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDj75NU+VB9Dhvh6MmL5HpmefH+97ZaIzEKTNb5A7W58gIhAKm/rPbSJFWjD+S33t05EH+3yyI0Aq///ho8cbbpY2uN"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJifYzPACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq80Q/8CMDNe+YFZQF6gpwxgdd36vpEXll0teOs82kIvCO6dXAoDxUu\r\nACSc5qyolke1KjQgMnhjp6RCH+DDkqJt1eodyF+tDPQy1mjnCkOtxkK25i9m\r\nSQ0/tOC0TzGi//9SzqDv2QDDeZ4djGnGT2QXXOSiEDYGJ6lOqFA+e4JeyROx\r\nEw5+ok4IWky8bWQ/NLKmT0s0/y0dKeec7cu6kVsYr36/ulp8JDimWz6S4PDs\r\nI0ZKzkMqd8p/eMZDi5ZcSbQnXStHShDmdSbZMkrVLg2f7JIogisVJkMxBk+L\r\nG3OaWhsQJGffX7DU+N6m/G3wePPM38qEEv5qRbJaFqqAlOlWjC/8BWGkMX4P\r\nQerdhlzfVpiBK/E6pZaI7sbRoaL0QyFPb8HbCOCyzDULhnILBDuaTNNGMGFC\r\nqrF7YUBYouv1W0QGqgL6riUWtQzStHO0Rbxgo/T0hmhWbEZHwb0ju/I48/qj\r\nqCpeY2OrOGZM0LKVS0Scy/M9vjCdp9kWXKkoL2LHkDdij1WJd1AG79MszkpL\r\nw1vQojEXoQLOHh+IeAuxPfM1ons8Ia89CincRT894epa+Fpl32vGNIcuKiZ9\r\nTV42Lveo0BIDs5h7TFT9fXteDq2t35RObmv+f1I8ZaMz46OPrdLpfIZfFQ9O\r\nq+Zigf6SFaD90hyvJ8BKYHCemlvrOeJSlyc=\r\n=SaKX\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"astra-js","email":"contact@astranetwork.com"},"directories":{},"maintainers":[{"name":"astra-js","email":"contact@astranetwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/account_0.1.57_1652395215203_0.3969790009669274"},"_hasShrinkwrap":false},"0.1.56":{"name":"@astra-js/account","version":"0.1.56","description":"account and wallet for astra","main":"dist/index.js","node":"dist/index.js","browser":"dist/index.js","module":"dist/index.esm.js","jsnext:main":"dist/index.esm.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"publishConfig":{"access":"public"},"author":{"name":"neeboo@firestack.one"},"license":"MIT","dependencies":{"@astra-js/core":"0.1.57","@astra-js/crypto":"0.1.56","@astra-js/network":"0.1.56","@astra-js/staking":"0.1.56","@astra-js/transaction":"0.1.56","@astra-js/utils":"0.1.56"},"gitHead":"56606e9365721729a490c27d6a294e0daf90fbdf","_id":"@astra-js/account@0.1.56","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-Ae1xV7Gr1Uporb898MlNEnoyD/oy3NVHTorfW1sBMc6OKrkbYYz2gcVOPiox4bf9D7WmH+jOhGwg5UyCWj3f9w==","shasum":"7712d3c509c66a3f3afb3d5bf59ce38d472f23f7","tarball":"https://registry.npmjs.org/@astra-js/account/-/account-0.1.56.tgz","fileCount":13,"unpackedSize":52744,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCctvB4XsWDobrzzGHsVxV80dUaWCQyluu9z5B/kyOSwgIgUflP1DRRfSYycN1rNqhDm/KmZluvXpvNg18TLQvZ6H8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJigmzvACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoZ3BAAgVBHnDNukmw1Yq/16eRM+96lsD5L5mbbt9TNIeqWrry6powu\r\nP+zJyXa7Z7DDzcFQkTDP1faHFBx7Nx462Ib5AIph7mFZhbjoKzR5/dCUCzKX\r\nPo/T2ZycYhiag9t5luF3rxo0AD6HeXbecbvJDnMsr8uIZjp8NA9QtGk/rEPz\r\nWUNGU7JyLHMMVgA4AiWG06tCmMruZPbjD2LWdFJAiBWUAqzlrJ1X+hnWajcs\r\nRDP8KWmD1BfqOWp+Dv0xNuZh51rMkofc/Ih0J2B1nr75xtGuvtBK+T9ws+pB\r\n3hcvkBC7QkKyOpvjDpVsriwTR7+NbnTo6IeFTu9K12Ls2JAlhcEbAOH4rxNV\r\nQtatDGBn46aEBlIjSAcCi3p2yKYyO4MyC2vqgaV4E2+ih7awd2F2AYgSzMdd\r\nSjfwghFAWA9gqcJ0zJaSFon4yOsErZk+9qZdW1sUcIZ8uPYwPQ9u+n05du2l\r\njMX6hKbSsAws6fPn01PE59kFavpkcBOTxr7Zn5DdWUG3lGf1NJXoi9mlLhh4\r\n/Xgudl9UXXEn3np8MohBog4WHlPiz9JGrfVFvFnOkSHJahSEjP4E+JuFLnGv\r\nti8lY1PU0FY6+b/4ELZZrqGp27fF1eBRD14PkEhmwgtRTacpoe9XmPQQSRLM\r\n2mbEycGK5wgyP7z8Pt1xX7s4YQuPCqoPUyM=\r\n=I32l\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"astra-network","email":"contact@astranetwork.com"},"directories":{},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/account_0.1.56_1652714735799_0.27354656642613673"},"_hasShrinkwrap":false},"0.1.59":{"name":"@astra-js/account","version":"0.1.59","description":"account and wallet for astra","main":"dist/index.js","node":"dist/index.js","browser":"dist/index.js","module":"dist/index.esm.js","jsnext:main":"dist/index.esm.js","typings":"dist/index.d.ts","types":"dist/index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"publishConfig":{"access":"public"},"author":{"name":"neeboo@firestack.one"},"license":"MIT","dependencies":{"@astra-js/core":"0.1.59","@astra-js/crypto":"0.1.59","@astra-js/network":"0.1.59","@astra-js/staking":"0.1.59","@astra-js/transaction":"0.1.59","@astra-js/utils":"0.1.59"},"gitHead":"552a541e743583dc30ce1d5312e34895c4f1c3c5","_id":"@astra-js/account@0.1.59","_nodeVersion":"16.15.0","_npmVersion":"lerna/3.22.1/node@v16.15.0+x64 (linux)","dist":{"integrity":"sha512-Omg4w2mfXz++9RVKZHXk3q2E6oqMUkffqTbZY+LjmCwebwEz/N8AwZNkOBLkx4/blwOFHYhGXk0lTuaO5guGZw==","shasum":"1438b7cbe3deb10d73ce852d07b3170e7c6c9849","tarball":"https://registry.npmjs.org/@astra-js/account/-/account-0.1.59.tgz","fileCount":37,"unpackedSize":155967,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCWaTxipTMMr+u32p+tZmKoSExhTshe12wpwiDsn4GwHAIgKMlpiQV28eWloKQLXlO6vvEg/Ks38zWkcirPN0EmvkY="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJig9yFACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqkTw//fZAvv78SNwGUK7eTau5XWRDSJvOd6Tg/eGkAeKFuBK9HoVvh\r\n3Y1ya3dtsX4crFoutrHoDBY4/buUVYEqTVjyAdx4n1LanP4dLS/a8ZltDqa4\r\n90uoPMVvTjK2d1PKX+RtqP+jdGsIW5q6RO/HFuOOmw+Y9DgaRBMXmUiTd2Lq\r\nK8EEgPXDKJtoxW/AVBl4gEBGvVogOWgkl2fQjBza1CFtLPdYDan2p3v2fa9x\r\niDKtvN8cj85QnqWx3PpKiDKz3e6P51wIdVPtET2VoLAR+WAKNw6ds21ZS8zK\r\nr6jo6RSce0VCmQuy3KlN0ouKdrWa9zP4wbasNRV+hwy68pAMMw/i8hWc4XiC\r\n1t8GnebM4H0YC76ESzWyLSY2H/RYmu5jUcbtWfzqLknei4Y3Tvm64NOCPAf7\r\ndiaAQs3XVKjsx22LOsxiEnL34r1Gw11f8eiG07PgioZrguvQ0qZHuxxv5qdq\r\nnoa8b/DRjUvEBtqjzy6Uze6NNng+TNdOI6XJZ3mv/VT2qS6Pn+/VbuGRveqB\r\nAxL49FBaq+gTzAWRkTzKhno5wQd34BEQydiQR8UHimwzNXGgroE93sI55f1B\r\nzux0DNWyS3HiaTwbe90vWn0DJODsgjki91oLgnlt/yvnSjjCvdzzN2Ctt0EM\r\nATcsKVmR0TD6Oh0C8hS2Tpmn/786XZkDDHs=\r\n=hez0\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"astra-network","email":"contact@astranetwork.com"},"directories":{},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/account_0.1.59_1652808837571_0.8188536960705641"},"_hasShrinkwrap":false}},"time":{"created":"2022-05-12T22:40:15.136Z","0.1.57":"2022-05-12T22:40:15.361Z","modified":"2022-05-17T17:33:58.044Z","0.1.56":"2022-05-16T15:25:35.954Z","0.1.59":"2022-05-17T17:33:57.956Z"},"maintainers":[{"name":"astra-network","email":"contact@astranetwork.com"}],"description":"account and wallet for astra","author":{"name":"neeboo@firestack.one"},"license":"MIT","readme":"# @astra-js/account\n\nThis package provides a collection of apis to create accounts and wallets and sign using them. A wallet can hold multiple accounts and account is associated with a unique `one` address. This package also provides facilies to manage account keys.\n\n## Installation\n\n```\nnpm install @astra-js/account\n```\n\n## Usage\n\nCreating new account and display addresses \n```javascript\nconst account = new Account(); // or const account = Account.new()\nconsole.log(account.checksumAddress);\nconsole.log(account.address);\n```\n\nCreating new account using private key\n```javascript\nconst account = Account.add('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');\n```\n\nCreating account using private key and custom messenger\n```javascript\nconst account = new Account(\n  '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e',\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\n```\n\nCreating account and setting custom messenger\n```javascript\n// uses by default http://localhost:9500 as messenger\nconst account = new Account();\nconst customMessenger = new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  );\n\naccount.setMessenger(customMessenger);\n```\n\nStoring the account data to keystore file\n```javascript\nconst passphrase = '';\nconst account = new Account('45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e');\naccount.toFile(passphrase).then(keystore => {\n    console.log(keystore);\n});\n```\n\nFetching account from keystore file\n```javascript\nconst passphrase = '';\nconst keystore = '{\"version\":3,\"id\":\"33363566-3564-4264-a638-363531666335\",\"address\":\"7c41e0668b551f4f902cfaec05b5bdca68b124ce\",\"crypto\":{\"ciphertext\":\"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855\",\"cipherparams\":{\"iv\":\"1cd0e0522260eef055b9170f4825f4a0\"},\"cipher\":\"aes-128-ctr\",\"kdf\":\"scrypt\",\"kdfparams\":{\"salt\":\"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b\",\"n\":8192,\"r\":8,\"p\":1,\"dklen\":32},\"mac\":\"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f\"}}';\nconst account = new Account();\naccount.fromFile(keystore, passphrase).then(account => {\n    console.log(account.address);\n});\n```\n\nGet the account balance\n```javascript\nconst account = new Account(\n  '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e',\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\naccount.getBalance().then(response => {\n    console.log(response);\n});\n```\noutputs `{ balance: '9126943763247054940484', nonce: 45, shardID: 0 }`\n\nCreate a transaction and account, and sign it\n```javascript\nconst account = new Account(\n  '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e',\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\nconst { TransactionFactory } = require('@astra-js/transaction');\nconst { Unit } = require('@astra-js/utils');\nconst factory = new TransactionFactory();\n\nconst txn = factory.newTx({\n  to: '0xd6ba69DA5b45eC98b53e3258d7DE756a567B6763',\n  value: new Unit(1).asOne().toWei(),\n  // gas limit, you can use string\n  gasLimit: '21000',\n  // send token from shardID\n  shardID: 0,\n  // send token to toShardID\n  toShardID: 0,\n  // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN\n  gasPrice: new Unit('1').asGwei().toWei(),\n});\n\naccount.signTransaction(txn).then((signedTxn) => {\n  console.log(signedTxn);\n});\n```\n\nSimilarily staking transactions can be created and signed using account.\n\nA wallet represents user wallet that can hold one or more user accounts.\n\nCreating an empty wallet\n```javascript\nconst { Wallet } = require('@astra-js/account')\nconst wallet = new Wallet();\n```\n\nSetting a messenger to be used to send wallet transactions\n```javascript\nwallet.setMessenger(\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\n```\n\nCreate an empty wallet with messenger\n```javascript\nconst wallet = new Wallet(\n  new Messenger(\n    new HttpProvider('https://rpc.s0.t.astranetwork.com'),\n    ChainType.Astra,\n    ChainID.AstraTestnet,\n  ),\n);\n```\n\nAn account could be added to a wallet using different ways. Adding account using mnemonics\n```javascript\nconst mnemonics = 'horse distance dry brother pretty manual chicken mushroom town swim prize clutch';\nconst account = wallet.addByMnemonic(mnemonics);\n```\n\nAdding account using private key\n```javascript\nconst account = wallet.addByPrivateKey('0x676cd9773dd23a4c1d7f22767c61c7b6723cc6be37b078545f6e0e91433a23dd')\n```\n\nAdding account using keystore file\n```javascript\nconst keystore = '{\"version\":3,\"id\":\"33363566-3564-4264-a638-363531666335\",\"address\":\"7c41e0668b551f4f902cfaec05b5bdca68b124ce\",\"crypto\":{\"ciphertext\":\"9b09380afb742838b32d9afc0ec1a3df35dbd7a41e3a160d08c07a4d0e79b855\",\"cipherparams\":{\"iv\":\"1cd0e0522260eef055b9170f4825f4a0\"},\"cipher\":\"aes-128-ctr\",\"kdf\":\"scrypt\",\"kdfparams\":{\"salt\":\"bf35e36c45cccefcef73a4c900f41c682c94c28630d94d2d1f764760d245f30b\",\"n\":8192,\"r\":8,\"p\":1,\"dklen\":32},\"mac\":\"25b4442972356bea02af57eba3b87803086d90b5e7657a57b528b89b1aa25f2f\"}}';\nconst passphrase = '';\nwallet.addByKeyStore(keystore, passphrase).then(account => {\n    console.log(account.address);\n});\n```\n\nCreating a new account using passphrase\n```javascript\nconst passphrase = 'astra-net';\nwallet.createAccount(passphrase).then(account => {\n    console.log(account.address);\n});\n```\n\nGet all accounts in the wallet\n```javascript\nwallet.accounts.forEach(addr => {\n    const account = wallet.getAccount(addr);\n    console.log(account.address);\n});\n```\n\nSet wallet signer when multiple accounts exists in the wallet\n```javascript\nwallet.setSigner(signerAddr);\n```\n\nSign transaction using wallet, will sign the transaction using the wallet signer\n```javascript\nconst txn = factory.newTx({\n  to: '0xd6ba69DA5b45eC98b53e3258d7DE756a567B6763',\n  value: new Unit(1).asOne().toWei(),\n  // gas limit, you can use string\n  gasLimit: '21000',\n  // send token from shardID\n  shardID: 0,\n  // send token to toShardID\n  toShardID: 0,\n  // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN\n  gasPrice: new Unit('1').asGwei().toWei(),\n});\n\nwallet.signTransaction(txn).then((signedTxn) => {\n  console.log(signedTxn);\n});\n```\n\nSimilarily staking transactions can be signed using `signStaking` api.","readmeFilename":"README.md"}