Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Add createKeyPairFromPrivateKeyBytes helper #3050

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

lorisleiva
Copy link
Contributor

@lorisleiva lorisleiva commented Aug 2, 2024

This PR adds a createKeyPairFromPrivateKeyBytes helper that creates a keypair from the 32-byte private key bytes.

import { createKeyPairFromPrivateKeyBytes } from '@solana/keys';

const { privateKey, publicKey } = await createKeyPairFromPrivateKeyBytes(new Uint8Array([...]));

This can be useful when you have a private key but not the corresponding public key or when you need to derive key pairs from seeds. For instance, the following code snippet derives a key pair from the hash of a message.

import { getUtf8Encoder } from '@solana/codecs-strings';
import { createKeyPairFromPrivateKeyBytes } from '@solana/keys';

const message = getUtf8Encoder().encode('Hello, World!');
const seed = new Uint8Array(await crypto.subtle.digest('SHA-256', message));

const derivedKeypair = await createKeyPairFromPrivateKeyBytes(seed);

Copy link

changeset-bot bot commented Aug 2, 2024

🦋 Changeset detected

Latest commit: 24d9bdd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@lorisleiva lorisleiva marked this pull request as ready for review August 2, 2024 14:33
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from 43c17fd to cf1091d Compare August 2, 2024 14:34
@lorisleiva lorisleiva changed the title Add createKeyPairFromPrivateKeyBytes helper Add createKeyPairFromPrivateKeyBytes helper Aug 2, 2024
Copy link
Contributor

@mcintyre94 mcintyre94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

packages/keys/src/key-pair.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

packages/keys/src/key-pair.ts Outdated Show resolved Hide resolved
@lorisleiva lorisleiva force-pushed the loris/public-key-helper branch from 981ad42 to 06734a1 Compare August 5, 2024 11:31
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from cf1091d to b738776 Compare August 5, 2024 11:31
@lorisleiva lorisleiva force-pushed the loris/public-key-helper branch from 06734a1 to f3465f7 Compare August 5, 2024 11:36
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from b738776 to 8b2a00d Compare August 5, 2024 11:36
@lorisleiva lorisleiva force-pushed the loris/public-key-helper branch from f3465f7 to 5a9de85 Compare August 5, 2024 11:45
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from 8b2a00d to 329cf27 Compare August 5, 2024 11:45
@lorisleiva lorisleiva force-pushed the loris/public-key-helper branch from 5a9de85 to 526072b Compare August 5, 2024 11:51
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch 2 times, most recently from f180911 to 5de7317 Compare August 5, 2024 12:02
Copy link
Contributor

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added via Giphy

@lorisleiva lorisleiva force-pushed the loris/public-key-helper branch from 526072b to 99f14b3 Compare August 7, 2024 08:09
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from 5de7317 to 913533a Compare August 7, 2024 08:09
Copy link
Contributor Author

lorisleiva commented Aug 7, 2024

Merge activity

  • Aug 7, 4:34 AM EDT: @lorisleiva started a stack merge that includes this pull request via Graphite.
  • Aug 7, 4:42 AM EDT: Graphite rebased this pull request as part of a merge.
  • Aug 7, 4:43 AM EDT: @lorisleiva merged this pull request with Graphite.

@lorisleiva lorisleiva changed the base branch from loris/public-key-helper to graphite-base/3050 August 7, 2024 08:38
@lorisleiva lorisleiva changed the base branch from graphite-base/3050 to master August 7, 2024 08:41
@lorisleiva lorisleiva force-pushed the loris/create-keypair-from-private-key-bytes branch from 913533a to 24d9bdd Compare August 7, 2024 08:41
@lorisleiva lorisleiva merged commit 7d310f6 into master Aug 7, 2024
7 checks passed
@lorisleiva lorisleiva deleted the loris/create-keypair-from-private-key-bytes branch August 7, 2024 08:43
@github-actions github-actions bot mentioned this pull request Aug 7, 2024
Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants