helium-js
helium-js copied to clipboard
Mnemonics checksum issue
const { Keypair, Address } = require ("@helium/crypto") const { PaymentV1, Transaction } = require ("@helium/transactions") const { Client } = require ("@helium/http")
make_transaction(); async function make_transaction(){
const client = new Client()
console.log("Checking the data: ", client)
// the transactions library needs to be configured // with the latest chain vars in order to calcluate fees const vars = await client.vars.get() Transaction.config(vars) // initialize an owned keypair from a 12 word mnemonic const bob = await Keypair.fromWords(['abandon', 'ability', 'able', 'about', 'above', 'absent', 'absorb', 'abstract', 'absurd', 'abuse', 'access','accident'])
// initialize an address from a b58 string const alice = Address.fromB58('148d8KTRcKA5JKPekBcKFd4KfvprvFRpjGtivhtmRmnZ8MFYnP3') console.log("Checking the address: ", alice) // get the speculative nonce for the keypair const account = await client.accounts.get(bob.address.b58) console.log("Checking the account: ", account); // construct a payment txn const paymentTxn = new PaymentV1({ payer: bob.address, payee: alice, amount: 1, nonce: alice.speculativeNonce + 1, })
console.log("nonce is: ", paymentTxn) console.log('transaction fee is:', paymentTxn.fee)
const signedPaymentTxn = await paymentTxn.sign({ payer: bob })
console.log("Checking the serialized transaction: ", signedPaymentTxn.toString()) //client.transactions.submit(signedPaymentTxn.toString()) console.log("Checking the transaction hash: ", client.transactions.submit(signedPaymentTxn.toString()))
}
By executing above code it is giving me this error: " (node:31994) UnhandledPromiseRejectionWarning: Error: invalid checksum at Mnemonic.toEntropy (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Mnemonic.js:49:19) at Function.fromMnemonic (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Keypair.js:34:34) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Function.fromWords (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Keypair.js:29:25) at async maketransaction (/home/alphabet-01/Desktop/anas/javascript/helium.js:19:13) (node:31994) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:31994) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. root@alphabet01-HP-Pavilion-Notebook:/home/alphabet-01/Desktop/anas/javascript# node helium.js "
I have the same issue. I use the words from the Helium App. I can recreate my Wallet in the App with exactly these words, but when I try them with Keypair.fromWords, i get the same error above ("Invalid Checksum at Mnemonic.toEntropy "). Other example words from e.g. the testcases work fine.
From working on the helium-wallet-rs project, there is code there that handles the always 0000 checksum of phrases generated by the mobile wallets. Is this that issue? If so, is there a plan to move the mobile wallet to generating valid BIP39 checksums?
UPDATE: Not sure this is related. I filed #188
const { Keypair, Address } = require ("@helium/crypto") const { PaymentV1, Transaction } = require ("@helium/transactions") const { Client } = require ("@helium/http")
make_transaction(); async function make_transaction(){
const client = new Client()
console.log("Checking the data: ", client)
// the transactions library needs to be configured // with the latest chain vars in order to calcluate fees const vars = await client.vars.get() Transaction.config(vars) // initialize an owned keypair from a 12 word mnemonic const bob = await Keypair.fromWords(['abandon', 'ability', 'able', 'about', 'above', 'absent', 'absorb', 'abstract', 'absurd', 'abuse', 'access','accident'])
// initialize an address from a b58 string const alice = Address.fromB58('148d8KTRcKA5JKPekBcKFd4KfvprvFRpjGtivhtmRmnZ8MFYnP3') console.log("Checking the address: ", alice) // get the speculative nonce for the keypair const account = await client.accounts.get(bob.address.b58) console.log("Checking the account: ", account); // construct a payment txn const paymentTxn = new PaymentV1({ payer: bob.address, payee: alice, amount: 1, nonce: alice.speculativeNonce + 1, })
console.log("nonce is: ", paymentTxn) console.log('transaction fee is:', paymentTxn.fee)
const signedPaymentTxn = await paymentTxn.sign({ payer: bob })
console.log("Checking the serialized transaction: ", signedPaymentTxn.toString()) //client.transactions.submit(signedPaymentTxn.toString()) console.log("Checking the transaction hash: ", client.transactions.submit(signedPaymentTxn.toString()))
}
By executing above code it is giving me this error: " (node:31994) UnhandledPromiseRejectionWarning: Error: invalid checksum at Mnemonic.toEntropy (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Mnemonic.js:49:19) at Function.fromMnemonic (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Keypair.js:34:34) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Function.fromWords (/home/alphabet-01/Desktop/anas/javascript/node_modules/@helium/crypto/build/Keypair.js:29:25) at async maketransaction (/home/alphabet-01/Desktop/anas/javascript/helium.js:19:13) (node:31994) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:31994) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. root@alphabet01-HP-Pavilion-Notebook:/home/alphabet-01/Desktop/anas/javascript# node helium.js "
Do you have a resolution to this problem you can share?
JFI: The solution to my case was that I used only lower case letters in the words.
Please tell me if I'm missing something but this word list should never work: abandon', 'ability', 'able', 'about', 'above', 'absent', 'absorb', 'abstract', 'absurd', 'abuse', 'access', 'accident'
It is not a valid 12-word mnemonic. You can't just pick the last word. It has to be calculated based on a checksum. IIRC for a 12-word phrase, the checksum is the lower 4 bits. So there would be several valid word choices, but it is unlikely 'accident' is one of those valid choices.
JFI: The solution to my case was that I used only lower case letters in the words.
lowercase saved my day
JFI: The solution to my case was that I used only lower case letters in the words.
lowercase saved my day
lowercase saved my day also !