grindKeyPairs

function grindKeyPairs(config): Promise<CryptoKeyPair[]>;

Generates multiple Ed25519 key pairs whose base58-encoded public key satisfies the provided matches criterion.

Key pairs are generated in batches of concurrency in parallel and tested against the matcher. The loop continues until amount matching key pairs have been found or the provided abortSignal is aborted.

When matches is a RegExp, its literal characters are validated against the base58 alphabet up front to prevent infinite loops caused by typos (e.g. /^anza0/). When matches is a function, it is used as-is with no validation.

Parameters

ParameterTypeDescription
configGrindKeyPairsConfigSee GrindKeyPairsConfig.

Returns

Promise<CryptoKeyPair[]>

A promise that resolves to an array of exactly amount CryptoKeyPair instances, each of which satisfies the matcher. When amount <= 0, the promise resolves to an empty array.

Examples

Find four key pairs whose address starts with anza:

import { grindKeyPairs } from '@solana/keys';
 
const keyPairs = await grindKeyPairs({ matches: /^anza/, amount: 4 });

Use a predicate function for arbitrary matching logic:

import { grindKeyPairs } from '@solana/keys';
 
const keyPairs = await grindKeyPairs({
    matches: address => address.startsWith('anza') && address.endsWith('end'),
    amount: 2,
});

Cancel a long-running grind using an AbortSignal:

import { grindKeyPairs } from '@solana/keys';
 
const keyPairs = await grindKeyPairs({
    matches: /^anza/,
    amount: 10,
    abortSignal: AbortSignal.timeout(60_000),
});

See

grindKeyPair

On this page