createAccount.spec.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Import modules. */
  2. const Nito = require('../..')
  3. // const bch = require('bitcore-lib-cash')
  4. /* Initialize (32-bit seed) key. */
  5. const seed_32 = '56050fd980e61dba97de474a3738c9e24c258cbd72280f87e6feee9893cf1407'
  6. /* Initialize (mnemonic phrase) key. */
  7. const mnemonic = 'figure chronic wait achieve gift tail garage similar enforce right crash setup seat shock volume eagle auto dish sausage tag matrix travel exotic wrestle'
  8. describe('Wallet:createAccount', () => {
  9. test('it should create a new wallet account (from 32-bit seed)', async () => {
  10. /* Instantiate new wallet. */
  11. const wallet = new Nito.Wallet(seed_32)
  12. /* Set extended private key. */
  13. // const extPrivKey = wallet.accounts[0].toString()
  14. const extPrivKey = wallet.node.toString()
  15. /* Set expected. */
  16. const expected = 'xprv9xxqPm59L1yzhWNWSYEuuMPSvWwUd1PKzgYPrP6vXjrinw3KGF6h4YcMnMxfyWKVFi8Lcp5jtWXT6npnwT8TX6PnQ2J9Bgd1g3eK4Xyxqmb'
  17. /* Evaluate test. */
  18. expect(extPrivKey).toEqual(expected)
  19. })
  20. test('it should create a new wallet account (from mnemonic phrase)', async () => {
  21. /* Instantiate new wallet. */
  22. const wallet = new Nito.Wallet(mnemonic)
  23. /* Set extended private key. */
  24. const extPrivKey = wallet.node.toString()
  25. /* Set expected (extdended) private key. */
  26. const expected = 'xprv9xxqPm59L1yzhWNWSYEuuMPSvWwUd1PKzgYPrP6vXjrinw3KGF6h4YcMnMxfyWKVFi8Lcp5jtWXT6npnwT8TX6PnQ2J9Bgd1g3eK4Xyxqmb'
  27. /* Evaluate test. */
  28. expect(extPrivKey).toEqual(expected)
  29. })
  30. test('it should generate a public key (from mnemonic phrase)', async () => {
  31. /* Instantiate new wallet. */
  32. const wallet = new Nito.Wallet(mnemonic)
  33. /* Retrieve extended public key. */
  34. const extPubKey = wallet.toPubKey()
  35. /* Set expected (extdended) public key. */
  36. const expected = 'xpub6BxBoGc3APYHuzSyYZmvGVLBUYmy2U7BMuTzemWY65PhfjNTonQwcLvqdcsZaoaoGMdwSW9RNjPU1fMRkj8qDaCRnJJv9cf3EUdU7JyM4Jk'
  37. /* Evaluate test. */
  38. expect(extPubKey).toEqual(expected)
  39. })
  40. test('it should generate an address (from mnemonic phrase)', async () => {
  41. /* Instantiate new wallet. */
  42. const wallet = new Nito.Wallet(mnemonic)
  43. /* Set "first child" path. */
  44. const path = 'm/0/0'
  45. /* Initialize "first child" node. */
  46. const childNode = wallet.node.deriveChild(path)
  47. /* Derive address. */
  48. const address = new Nito.Address(childNode.publicKey).toString()
  49. /* Set expected address. */
  50. const expected = 'bitcoincash:qz2nj9frrncm2ksn7t4kc2l62vfvc4szwgq6nxl90n'
  51. /* Evaluate test. */
  52. expect(address).toEqual(expected)
  53. })
  54. })