Skip to main content

Class: UnencryptedFileSystemKeyStore

key_stores/unencrypted_file_system_keystore.UnencryptedFileSystemKeyStore

This class is used to store keys on the file system.

See

https://docs.near.org/docs/develop/front-end/naj-quick-reference#key-store

Example

const { homedir } = require('os');
const { connect, keyStores } = require('near-api-js');

const keyStore = new keyStores.UnencryptedFileSystemKeyStore(`${homedir()}/.near-credentials`);
const config = {
keyStore, // instance of UnencryptedFileSystemKeyStore
networkId: 'testnet',
nodeUrl: 'https://rpc.testnet.near.org',
walletUrl: 'https://wallet.testnet.near.org',
helperUrl: 'https://helper.testnet.near.org',
explorerUrl: 'https://explorer.testnet.near.org'
};

// inside an async function
const near = await connect(config)

Hierarchy​

  • KeyStore

    ↳ UnencryptedFileSystemKeyStore

Constructors​

constructor​

new UnencryptedFileSystemKeyStore(keyDir)

Parameters​

NameTypeDescription
keyDirstringbase directory for key storage. Keys will be stored in keyDir/networkId/accountId.json

Overrides​

KeyStore.constructor

Defined in​

key_stores/unencrypted_file_system_keystore.ts:88

Methods​

clear​

clear(): Promise<void>

Deletes all unencrypted files from the keyDir path.

Returns​

Promise<void>

Overrides​

KeyStore.clear

Defined in​

key_stores/unencrypted_file_system_keystore.ts:134


getAccounts​

getAccounts(networkId): Promise<string[]>

Gets the account(s) files in keyDir/networkId

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)

Returns​

Promise<string[]>

Overrides​

KeyStore.getAccounts

Defined in​

key_stores/unencrypted_file_system_keystore.ts:164


getKey​

getKey(networkId, accountId): Promise<KeyPair>

Gets a KeyPair from an unencrypted file

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair

Returns​

Promise<KeyPair>

Overrides​

KeyStore.getKey

Defined in​

key_stores/unencrypted_file_system_keystore.ts:111


getNetworks​

getNetworks(): Promise<string[]>

Get the network(s) from files in keyDir

Returns​

Promise<string[]>

Overrides​

KeyStore.getNetworks

Defined in​

key_stores/unencrypted_file_system_keystore.ts:151


removeKey​

removeKey(networkId, accountId): Promise<void>

Deletes an unencrypted file holding a KeyPair

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair

Returns​

Promise<void>

Overrides​

KeyStore.removeKey

Defined in​

key_stores/unencrypted_file_system_keystore.ts:125


setKey​

setKey(networkId, accountId, keyPair): Promise<void>

Store a KeyPair in an unencrypted file

Parameters​

NameTypeDescription
networkIdstringThe targeted network. (ex. default, betanet, etc…)
accountIdstringThe NEAR account tied to the key pair
keyPairKeyPairThe key pair to store in local storage

Returns​

Promise<void>

Overrides​

KeyStore.setKey

Defined in​

key_stores/unencrypted_file_system_keystore.ts:99