@avalanche-sdk/client
Version:
A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa
28 lines (26 loc) • 836 B
text/typescript
import { XPAddress } from "../avalancheAccount.js";
import { privateKeyToXPPublicKey } from "./privateKeyToXPPublicKey.js";
import { publicKeyToXPAddress } from "./publicKeyToXPAddress.js";
/**
* Converts a private key to an XP address.
*
* @param privateKey - The private key to convert.
* @param hrp - The human readable prefix to use for the address.
* @returns The XP address as a `0x` prefixed string.
*
* @example
* ```ts
* import { privateKeyToXPAddress } from "@avalanche-sdk/client/accounts";
*
* const address = privateKeyToXPAddress("0xab....", "avax");
* console.log(address);
* ```
*/
export function privateKeyToXPAddress(
privateKey: string,
hrp: string
): XPAddress {
const publicKey = privateKeyToXPPublicKey(privateKey);
const address = publicKeyToXPAddress(publicKey, hrp);
return address;
}