Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: accept language option for mnemonic when creating new wallet #588

Merged
merged 3 commits into from Aug 24, 2021

Conversation

pinheadmz
Copy link
Member

@pinheadmz pinheadmz commented Apr 6, 2021

Closes #587

Once handshake-org/hs-client#39 is merged together:

$ hsw-cli --network=regtest --id=cartera --language=spanish mkwallet
{
  "network": "regtest",
  "wid": 1,
  "id": "cartera",
  "watchOnly": false,
  "accountDepth": 1,
  "token": "251e4f2b6a238cf3491ee783bc2d0ab09a8aeed8fb81296cc81d1bbd026c1812",
  "tokenDepth": 0,
  "master": {
    "encrypted": false
  },
  "balance": {
    "account": -1,
    "tx": 0,
    "coin": 0,
    "unconfirmed": 0,
    "confirmed": 0,
    "lockedUnconfirmed": 0,
    "lockedConfirmed": 0
  }
}

$ hsw-cli --network=regtest --id=cartera master
{
  "encrypted": false,
  "key": {
    "xprivkey": "rprvKE8qsHtkmUxUSR1stB2VJX3ibU3WzvUWZXxrzTJph7Sy91AVQJwBPVdE9HxZEkH6MfeDME26YLtmUZ46p1EDpn2HV16rpFGyJ81A6ikrKxV4"
  },
  "mnemonic": {
    "bits": 256,
    "language": "spanish",
    "entropy": "2ff615cbe0665107f3f28665fee8ab7755500159a6c22118b80f0bc94f99d62e",
    "phrase": "chancla perder inicio radical goma lote saber este grada vencer cara tribu faltar abono grave silencio borde reja acusar aula muela ronco fiebre sapo"
  }
}

@coveralls
Copy link

coveralls commented Apr 6, 2021

Pull Request Test Coverage Report for Build 1163870793

  • 7 of 8 (87.5%) changed or added relevant lines in 3 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 61.416%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/hd/mnemonic.js 1 2 50.0%
Files with Coverage Reduction New Missed Lines %
lib/hd/mnemonic.js 6 80.97%
Totals Coverage Status
Change from base Build 1163812216: 0.01%
Covered Lines: 20551
Relevant Lines: 31228

💛 - Coveralls

Copy link
Contributor

@nodech nodech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this only applies when you want wallet to generate mnemonic. (w/o passing phrase)
Otherwise if mnemonic has the phrase it will be used to detect language.

Check is becomes kinda weird: if mnemonic is null becomes the only case when language will be applied, so if (!(mnemonic instanceof Mnemonic)) will only happen when mnemonic is null/undefined?

In that case it can be rewritten as if (!mnemonic)..

Unless manually called with string type as in test should create wallet with spanish mnemonic in wallet-test.

test/wallet-test.js Show resolved Hide resolved
lib/wallet/wallet.js Outdated Show resolved Hide resolved
@pinheadmz
Copy link
Member Author

Rebased on master and also added an explicit error if an unknown language is requested:

(still requires handshake-org/hs-client#39 to test)

--> hsw-cli mkwallet --id=testgerman --language='german'
Error: Unknown language.
    at WalletClient.request (/Users/matthewzipkin/Desktop/work/hs-client/node_modules/bcurl/lib/client.js:233:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async CLI.createWallet (/Users/matthewzipkin/Desktop/work/hs-client/bin/hsw-cli:87:20)
    at async CLI.handleWallet (/Users/matthewzipkin/Desktop/work/hs-client/bin/hsw-cli:552:9)
    at async /Users/matthewzipkin/Desktop/work/hs-client/bin/hsw-cli:676:3
--> hsw-cli mkwallet --id=testfrench --language='french'
{
  "network": "regtest",
  "wid": 9,
  "id": "testfrench",
  "watchOnly": false,
  "accountDepth": 1,
  "token": "16caa2a60a2d89bae1198b5dfc38641ab2a5d4a31b146294309f272850e64c1b",
  "tokenDepth": 0,
  "master": {
    "encrypted": false
  },
  "balance": {
    "account": -1,
    "tx": 0,
    "coin": 0,
    "unconfirmed": 0,
    "confirmed": 0,
    "lockedUnconfirmed": 0,
    "lockedConfirmed": 0
  }
}
--> hsw-cli --id=testfrench master
{
  "encrypted": false,
  "key": {
    "xprivkey": "rprvKE8qsHtkmUxUSQ1ukQb3FaszkrjHb1YNgDmDNoP8DxduM3rKC4pB2r7PaiH7k7uDSWArQj4BFm6WeD2Uzc46VdaXnss93awT1YtrzpTv7uTE"
  },
  "mnemonic": {
    "bits": 256,
    "language": "french",
    "entropy": "3bfd09f4877232dd0f218d1b524fd1303cc0c4d271ee80d6515a3aa94b051d56",
    "phrase": "cruel tasse hurler antidote bricoler furieux cuisine circuler bélier luisant usage exister remuer falaise doseur cylindre inductif paresse enviable gratuit maléfice inoculer gratuit somnoler"
  }
}

@pinheadmz pinheadmz merged commit fa39e42 into handshake-org:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for BIP39 spanish wordlist
3 participants