|
2 | 2 |
|
3 | 3 | const cosmosjs = require("../src"); |
4 | 4 |
|
5 | | - getKeyStationMainAddress = function (mnemonic, hdPath, prefix) { |
| 5 | + getKeyStationMainAddress = function (mnemonic, hdPath, prefix, checkSum = true) { |
6 | 6 | var chainId2 = "" |
7 | 7 | switch (prefix) { |
8 | 8 | case "cosmos": |
|
22 | 22 | const cosmos = cosmosjs.network(window.lcd, chainId2); |
23 | 23 | cosmos.setBech32MainPrefix(prefix); |
24 | 24 | cosmos.setPath(hdPath); |
25 | | - const address = cosmos.getAddress(mnemonic); |
| 25 | + const address = cosmos.getAddress(mnemonic, checkSum); |
26 | 26 |
|
27 | 27 | return address; |
28 | 28 | } |
|
46 | 46 |
|
47 | 47 | let signedTx = cosmos.sign(stdSignMsg, ecpairPriv); |
48 | 48 |
|
49 | | - // // IRIS exception handling about "irishub/stake/BeginRedelegate" type |
| 49 | + // * IRIS exception handling about "irishub/stake/BeginRedelegate" type |
50 | 50 | // if (signedTx.tx.msg[0].type == "irishub/stake/BeginRedelegate") { |
51 | 51 | // // The key of "shares" is using to sign for IRIS Redelegate. |
52 | 52 | // // After signing, you have to replace the "shares" key name to "shares_amount". |
|
56 | 56 | // signedTx = JSON.parse(txBodyStr); |
57 | 57 | // } |
58 | 58 |
|
59 | | - // Debug |
| 59 | + // * Debug |
60 | 60 | // if (stdSignMsg.json.msgs[0].value.from_address == "[KAVA_ADDRESS]") { |
61 | 61 | // console.log("signedTx: ", JSON.stringify(signedTx)); |
62 | 62 | // return; |
@@ -34423,12 +34423,12 @@ Cosmos.prototype.getAccounts = function(address) { |
34423 | 34423 | .then(response => response.json()) |
34424 | 34424 | } |
34425 | 34425 |
|
34426 | | -Cosmos.prototype.getAddress = function(mnemonic) { |
| 34426 | +Cosmos.prototype.getAddress = function(mnemonic, checkSum = true) { |
34427 | 34427 | if (typeof mnemonic !== "string") { |
34428 | 34428 | throw new Error("mnemonic expects a string") |
34429 | 34429 | } |
34430 | | - if (!bip39.validateMnemonic(mnemonic)) { |
34431 | | - throw new Error("mnemonic phrases have invalid checksums") |
| 34430 | + if (checkSum) { |
| 34431 | + if (!bip39.validateMnemonic(mnemonic)) throw new Error("mnemonic phrases have invalid checksums"); |
34432 | 34432 | } |
34433 | 34433 | const seed = bip39.mnemonicToSeed(mnemonic); |
34434 | 34434 | const node = bip32.fromSeed(seed); |
@@ -34537,7 +34537,6 @@ Cosmos.prototype.sign = function(stdSignMsg, ecpairPriv, modeType = "sync") { |
34537 | 34537 | } else { |
34538 | 34538 | signMessage = stdSignMsg.json; |
34539 | 34539 | } |
34540 | | - |
34541 | 34540 | const hash = crypto.createHash('sha256').update(JSON.stringify(sortObject(signMessage))).digest('hex'); |
34542 | 34541 | const buf = Buffer.from(hash, 'hex'); |
34543 | 34542 | let signObj = secp256k1.sign(buf, ecpairPriv); |
|
0 commit comments