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.
Merge pull request #531 from near/generate-key
Enchancing Generate key
- Loading branch information
Showing
7 changed files
with
205 additions
and
15 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
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'); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.