Implement UnencryptedJsonKeystore & UnencryptedJsonFileKeystore
See original GitHub issueDescribe the bug This is a bug that reveals that for the default UnencryptedFileSystemKeystore the KeyDir assumes a specific structure for the reading of the keys. This structure is out of alignment with any default construction as of the latest near-cli 1.6.0 The key paths by default are ~/.near-credentials/default/nameofaccount.json
The issue is the assumptions made here: https://github.com/near/near-api-js/blob/master/src/key_stores/unencrypted_file_system_keystore.ts#L114
To Reproduce npm install near-api-js
const nearAPI = require('near-api-js')
const
{ keyStores }
= nearAPI;
const KEY_PATH = "~/.near-credentials/default/"
const keyStore = new keyStores.UnencryptedFileSystemKeyStore(KEY_PATH);
const result = await keyStore.getKey("yournetwork","youracccountid")
copy pasta into an index.js
Expected behavior You expect to receive your key instead you’ll throw a can’t find key error
Desktop (please complete the following information):
- OS: Mac
- Version 10.15.7
Additional context Should be a simple fix, the network order assumption should perhaps be removed, or the cli should put the keys in the proper paths, alternatively the error message should throw a put structure keys in directory as follows.
I’m most inclined for removing the path assumption from the Keystore.
What do you all think?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
I like this idea, I think it’ll make the keystore a little more flexible. How do you feel about Json with Json Schema?
My thought here is that if we just spec out a schema see below. Then we can do cool things like add type ahead support in all the environments for configuring the keystore. Like the monaco editor allows you to add support for json schema in configuration files.
This would mean that in online editing environments you can add typeahead and light error correcting. Additionally if we use json we can support in emory representations of the keystore that have a similar mapping if not 1-1 corresponding mapping to the JSON config representation of the keystore.
The interface would be:
UnencryptedJsonFileKeystore just uses JsonKeystore under the hood, it’s a convenience wrapper that reads files from disk.
here’s a spec via gist and inline here so it’s maybe easier to read it’s verbose 😁
example
This looks good to me!