-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix seed phrase so it works with masterAccount
- Loading branch information
1 parent
21893e6
commit ef6cbcd
Showing
2 changed files
with
49 additions
and
2,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
const { parseSeedPhrase } = require('near-seed-phrase'); | ||
const { utils: { KeyPair }, InMemorySigner } = require('near-api-js'); | ||
const { InMemoryKeyStore } = require('near-api-js/lib/key_stores'); | ||
const { InMemoryKeyStore, MergeKeyStore } = require('near-api-js/lib/key_stores'); | ||
|
||
const implicitAccountId = require('../utils/implicit-accountid'); | ||
|
||
// near ... --seedPhrase="phrase" --seedPath="m/44'/397'/0'" | ||
// near generate-key --seedPhrase="phrase" | ||
module.exports = async function useSeedPhrase({ seedPhrase, seedPath, publicKey, accountId, networkId }, yargs) { | ||
module.exports = async function useSeedPhrase({ seedPhrase, seedPath, keyStore, accountId, masterAccount, networkId }, yargs) { | ||
if (!seedPhrase) { | ||
return; | ||
} | ||
if (yargs.usingLedger) { | ||
throw new Error('Can not use both --useLedgerKey and --seedPhrase at the same time'); | ||
} | ||
const result = parseSeedPhrase(seedPhrase, seedPath); | ||
publicKey = result.publicKey; | ||
let keyStore = new InMemoryKeyStore(); | ||
accountId = accountId || implicitAccountId(publicKey); | ||
await keyStore.setKey(networkId, accountId, KeyPair.fromString(result.secretKey)); | ||
let signer = new InMemorySigner(keyStore); | ||
return { signer, publicKey, accountId }; | ||
const { publicKey, secretKey } = parseSeedPhrase(seedPhrase, seedPath); | ||
|
||
const seedPhraseKeystore = new InMemoryKeyStore(); | ||
const seedPhraseAccountId = masterAccount ? masterAccount : accountId || implicitAccountId(publicKey); | ||
|
||
await keyStore.setKey(networkId, seedPhraseAccountId, KeyPair.fromString(secretKey)); | ||
if(keyStore instanceof MergeKeyStore) keyStore.keyStores.push(seedPhraseKeystore); | ||
|
||
return { keyStore, accountId }; | ||
}; |
Oops, something went wrong.