Skip to content

Commit b5e49e8

Browse files
florrdvclaude
andauthored
feat: add key export helper (#2434)
* feat: add key export helper Re-introduce exportPrivateKey and experimental_multiOwnerExportPrivateKey methods to BaseSignerClient and BaseAlchemySigner. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: remove experimental_multiOwnerExportPrivateKey Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cf7d9fb commit b5e49e8

17 files changed

Lines changed: 414 additions & 172 deletions

File tree

aa-sdk/core/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";

account-kit/core/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";

account-kit/infra/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";

account-kit/logging/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";

account-kit/react/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is autogenerated by inject-version.ts. Any changes will be
22
// overwritten on commit!
3-
export const VERSION = "4.85.0";
3+
export const VERSION = "4.86.1";

account-kit/signer/src/base.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,16 @@ export abstract class BaseAlchemySigner<TClient extends BaseSignerClient>
10511051
return this.inner.exportWallet(params);
10521052
};
10531053

1054+
/**
1055+
* Exports a private key for a given account
1056+
*
1057+
* @param {ExportPrivateKeyParams} opts the parameters for the export
1058+
* @returns {Promise<string>} the private key
1059+
*/
1060+
exportPrivateKey: TClient["exportPrivateKey"] = (opts) => {
1061+
return this.inner.exportPrivateKey(opts);
1062+
};
1063+
10541064
/**
10551065
* Exports a private key for a given account encrypted with the provided public key
10561066
*

account-kit/signer/src/client/base.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
recoverPublicKey,
88
serializeSignature,
99
sha256,
10+
toHex,
1011
fromHex,
1112
type Address,
1213
type Hex,
@@ -16,6 +17,7 @@ import {
1617
OAuthProvidersError,
1718
UnsupportedFeatureError,
1819
} from "../errors.js";
20+
import { decryptExportBundle } from "@turnkey/crypto";
1921
import { getDefaultProviderCustomization } from "../oauth.js";
2022
import type { OauthMode } from "../signer.js";
2123
import { base64UrlEncode } from "../utils/base64UrlEncode.js";
@@ -59,6 +61,7 @@ import type {
5961
import { VERSION } from "../version.js";
6062
import { secp256k1 } from "@noble/curves/secp256k1";
6163
import { Point } from "@noble/secp256k1";
64+
import { p256 } from "@noble/curves/p256";
6265

6366
export interface BaseSignerClientParams {
6467
stamper: TurnkeyClient["stamper"];
@@ -1562,6 +1565,42 @@ export abstract class BaseSignerClient<
15621565
};
15631566
};
15641567

1568+
/**
1569+
* Exports a private key for a given account
1570+
*
1571+
* @param {ExportPrivateKeyParams} opts the parameters for the export
1572+
* @returns {Promise<string>} the private key
1573+
*/
1574+
public exportPrivateKey = async (
1575+
opts: ExportPrivateKeyParams,
1576+
): Promise<string> => {
1577+
if (!this.user) {
1578+
throw new NotAuthenticatedError();
1579+
}
1580+
1581+
const targetPrivateKey = p256.utils.randomPrivateKey();
1582+
const targetPublicKey = p256.getPublicKey(targetPrivateKey, false);
1583+
const orgId = opts.orgId ?? this.user.orgId;
1584+
const keyFormat = opts.type === "ETHEREUM" ? "HEXADECIMAL" : "SOLANA";
1585+
1586+
const { exportBundle } = await this.exportPrivateKeyEncrypted({
1587+
type: opts.type,
1588+
client: opts.client ?? this.turnkeyClient,
1589+
orgId: orgId,
1590+
encryptWith: toHex(targetPublicKey).slice(2),
1591+
});
1592+
1593+
const decrypted = await decryptExportBundle({
1594+
exportBundle,
1595+
embeddedKey: toHex(targetPrivateKey).slice(2),
1596+
organizationId: orgId,
1597+
returnMnemonic: false,
1598+
keyFormat,
1599+
});
1600+
1601+
return decrypted;
1602+
};
1603+
15651604
/**
15661605
* Exports a private key for a given account in a multi-owner org
15671606
*

0 commit comments

Comments
 (0)