4

I don't see an equivalent of Keypair.fromSeed() in keypair-signer.d.ts

How do you derive a keypair from mnemonic using web3.js v2?

import { Address } from '@solana/addresses';
import { ReadonlyUint8Array } from '@solana/codecs-core';
import { MessagePartialSigner } from './message-partial-signer';
import { TransactionPartialSigner } from './transaction-partial-signer';
/** Defines a signer capable of signing messages and transactions using a CryptoKeyPair. */
export type KeyPairSigner<TAddress extends string = string> = MessagePartialSigner<TAddress> & TransactionPartialSigner<TAddress> & {
    keyPair: CryptoKeyPair;
};
/** Checks whether the provided value implements the {@link KeyPairSigner} interface. */
export declare function isKeyPairSigner<TAddress extends string>(value: {
    [key: string]: unknown;
    address: Address<TAddress>;
}): value is KeyPairSigner<TAddress>;
/** Asserts that the provided value implements the {@link KeyPairSigner} interface. */
export declare function assertIsKeyPairSigner<TAddress extends string>(value: {
    [key: string]: unknown;
    address: Address<TAddress>;
}): asserts value is KeyPairSigner<TAddress>;
/** Creates a KeyPairSigner from the provided Crypto KeyPair. */
export declare function createSignerFromKeyPair(keyPair: CryptoKeyPair): Promise<KeyPairSigner>;
/** Securely generates a signer capable of signing messages and transactions using a Crypto KeyPair. */
export declare function generateKeyPairSigner(): Promise<KeyPairSigner>;
/** Creates a signer capable of signing messages and transactions using the 64 bytes of a KeyPair. */
export declare function createKeyPairSignerFromBytes(bytes: ReadonlyUint8Array, extractable?: boolean): Promise<KeyPairSigner>;
/** Creates a signer capable of signing messages and transactions using the 32 bytes of a private key. */
export declare function createKeyPairSignerFromPrivateKeyBytes(bytes: ReadonlyUint8Array, extractable?: boolean): Promise<KeyPairSigner>;
//# sourceMappingURL=keypair-signer.d.ts.map

1 Answer 1

4

In @solana/web3.js version 1, Keypair.fromSeed(seed) simply uses the provided seed as the private key of the key pair.

The equivalent in @solana/web3.js version 2 is createKeyPairFromPrivateKeyBytes (See documentation).

const keypair = await createKeyPairFromPrivateKeyBytes(seed);

If you want a signer from this key pair directly, you may use the following helper instead (See documentation).

const signer = await createKeyPairSignerFromPrivateKeyBytes(seed);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.