near-kit provides several KeyStore implementations to suit different environments, from temporary testing to secure production servers.
1. InMemoryKeyStore (Testing & Scripts)
- Best for: Unit tests, CI/CD, and short-lived scripts.
2. FileKeyStore (Dev & Servers)
- Best for: Local development and simple server deployments.
- Requires: Node.js or Bun.
~/.near-credentials directory. This makes it compatible with the NEAR CLI.
3. NativeKeyStore (Maximum Security)
- Best for: Production servers, desktop apps, and CLI tools.
- Requires: Node.js/Bun and
@napi-rs/keyring.
Note: OS Keyrings do not allow listing all keys for security reasons. You must know the accountId you want to retrieve.
4. RotatingKeyStore (High Throughput)
- Best for: Trading bots, faucets, and high-traffic relayers.
InvalidNonce errors.
RotatingKeyStore solves this by managing multiple keys for a single account and rotating through them round-robin.
Permissions
When you add a key to an account (using.addKey), you define what that key can do.
Full Access
Can do anything: transfer NEAR, delete the account, deploy code, add more keys.- Use case: Your main admin key.
Function Call Access
Can only call specific methods on a specific contract. It cannot transfer NEAR.- Use case: “Log in with NEAR”, limited session keys, automated agents.
Signature schemes
near-kit supports three signature schemes. They are interchangeable everywhere a key is used (parseKey, signWith, addKey, the keystores):
ML-DSA-65 (post-quantum)
ML-DSA-65 keys let an account sign with a quantum-resistant scheme. Generate one withMlDsa65KeyPair, then add it like any other key:
MlDsa65KeyPair, the serialized secret key is the 32-byte seed (ml-dsa-65:<base58 seed>). parseKey also accepts the 4032-byte raw expanded secret key that nearcore / near-cli write to credential files (ml-dsa-65:<base58 raw key>), so existing credentials load too. Either form round-trips. The public key is 1952 bytes and signatures are 3309 bytes.
Deriving from a seed phrase
parseSeedPhrase can derive an ML-DSA-65 key from a BIP-39 mnemonic, so a post-quantum key is recoverable from the same phrase a wallet already backs up:
HMAC-SHA512(key = "ML-DSA-65 seed", data = BIP-39 seed), children use the standard SLIP-0010 hardened-only step, and the derived 32-byte node secret is the FIPS 204 seed ξ fed to ML-DSA key generation. Because the master salt differs from ed25519’s, the ML-DSA-65 key derived from a phrase is unrelated to the ed25519 key derived from that same phrase.
On-chain, an ML-DSA-65 access key is stored as a 32-byte hash, so
view_access_key_list returns it as ml-dsa-65-hash:..., not the full key. Parse that form with parseMlDsa65Handle() for display and comparison — it is a read-only handle and cannot be used to sign or as an addKey public key (the full key is not recoverable from it).