This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move seed phrase into a middleware to allow other actions to work wit…
…h it
- Loading branch information
1 parent
ac854a4
commit 9f310e7
Showing
5 changed files
with
51 additions
and
29 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
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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { parseSeedPhrase } = require('near-seed-phrase'); | ||
const { utils: { KeyPair }, InMemorySigner } = require('near-api-js'); | ||
const { InMemoryKeyStore } = 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 }, 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(yargs.networkId, accountId, KeyPair.fromString(result.secretKey)); | ||
let signer = new InMemorySigner(keyStore); | ||
return { signer, publicKey, accountId }; | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { decode } = require('bs58'); | ||
|
||
module.exports = (publicKey) => { | ||
return decode(publicKey.replace('ed25519:', '')).toString('hex'); | ||
}; |