-
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.
Merge pull request #739 from near/fix/seed-phrase-create-account
Fix seed phrase so it works with masterAccount
- Loading branch information
Showing
15 changed files
with
429 additions
and
386 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,6 +1,5 @@ | ||
.DS_Store | ||
node_modules | ||
tmp-project | ||
neardev/* | ||
package-lock.json | ||
.idea |
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 |
---|---|---|
@@ -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 { utils: { KeyPair } } = require('near-api-js'); | ||
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 }; | ||
}; |
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 @@ | ||
dev-1620395864376.test.near |
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 @@ | ||
CONTRACT_NAME=dev-1620395864376.test.near |
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 @@ | ||
{"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"} |
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 @@ | ||
{"account_id":"test.near","private_key":"ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"} |
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
Binary file not shown.
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,21 +1,28 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
timestamp=$(date +%s) | ||
testaccount=testaccount$timestamp.test.near | ||
testaccount=testaccount$timestamp$RANDOM.test.near | ||
|
||
ERROR=$(./bin/near create-account $testaccount --masterAccount test.far 2>&1 >/dev/null) | ||
echo $ERROR | ||
EXPECTED_ERROR=".+New account doesn't share the same top-level account.+ " | ||
if [[ ! "$ERROR" =~ $EXPECTED_ERROR ]]; then | ||
echo FAILURE Unexpected output creating account with different master account | ||
exit 1 | ||
fi | ||
|
||
ERROR=$(./bin/near create-account tooshortfortla --masterAccount test.far 2>&1 >/dev/null) | ||
echo $ERROR | ||
EXPECTED_ERROR=".+Top-level accounts must be at least.+ " | ||
if [[ ! "$ERROR" =~ $EXPECTED_ERROR ]]; then | ||
echo FAILURE Unexpected output when creating a short top-level account | ||
exit 1 | ||
fi | ||
|
||
echo Create account with seed phrase | ||
./bin/near create-account $testaccount --publicKey="Au4RC7YHfZuhxK8DnXDrizCSEXXc9mc9teVm4Nbtv6Tj" > /dev/null | ||
RESULT=$(./bin/near create-account create-me.$testaccount --masterAccount=$testaccount --seedPhrase="cross teach omit obvious riot echo parrot member memory wide obscure ball" --initialBalance=1 -v | ./node_modules/.bin/strip-ansi) | ||
EXPECTED=".+Account create-me.$testaccount for network .+ was created.+" | ||
if [[ ! "$RESULT" =~ $EXPECTED ]]; then | ||
echo FAILURE \"Create account with seed phrase\" Unexpected output from create-account | ||
exit 1 | ||
fi | ||
|
||
./bin/near delete $testaccount test.near > /dev/null |
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,20 +1,18 @@ | ||
#!/bin/bash | ||
set -ex | ||
rm -rf tmp-project | ||
yarn create near-app tmp-project | ||
cd tmp-project | ||
set -e | ||
|
||
timestamp=$(date +%s) | ||
testaccount=testaccount$timestamp.test.near | ||
testaccount=testaccount$timestamp$RANDOM.test.near | ||
|
||
echo Create account | ||
../bin/near create-account $testaccount | ||
./bin/near create-account $testaccount | ||
|
||
echo Get account state | ||
RESULT=$(../bin/near state $testaccount -v | ../node_modules/.bin/strip-ansi) | ||
echo $RESULT | ||
RESULT=$(./bin/near state $testaccount -v | ./node_modules/.bin/strip-ansi) | ||
EXPECTED=".+Account $testaccount.+amount:.+'100000000000000000000000000'.+ " | ||
if [[ ! "$RESULT" =~ $EXPECTED ]]; then | ||
echo FAILURE Unexpected output from near view | ||
exit 1 | ||
fi | ||
|
||
../bin/near delete $testaccount test.near | ||
./bin/near delete $testaccount test.near |
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
Oops, something went wrong.