SDK
Utilities
generateStealthAddress

generateStealthAddress

Generates a stealth address from a given stealth meta-address.

Import

import { generateStealthAddress } from "@scopelift/stealth-address-sdk";

Usage

// Follows the format: "st:<chain>:<stealthMetaAddress>", where <chain> is the chain identifier (https://eips.ethereum.org/EIPS/eip-3770#examples) and <stealthMetaAddress> is the stealth meta-address.
// Alternatively, you can simply provide the stealth meta-address without the URI prefix: "0x..."
const stealthMetaAddressURI = "...";
 
// Generate a stealth address using the default scheme (1)
// To learn more about the initial implementation scheme using SECP256k1, please see the reference here (https://eips.ethereum.org/EIPS/eip-5564)
// When not passing in the scheme id, the default scheme id is 1
const { stealthAddress, ephemeralPublicKey, viewTag } = generateStealthAddress({
  stealthMetaAddressURI,
});

Return Value

/**
 * Represents the output of the generateStealthAddress function,
 * containing the stealth address, ephemeralPublicKey, and viewTag.
 */
export type GenerateStealthAddressReturnType = {
  /** The generated stealth address. */
  stealthAddress: EthAddress;
  /** The ephemeral public key used to generate the stealth address. */
  ephemeralPublicKey: HexString;
  /** The view tag derived from the hashed shared secret. */
  viewTag: HexString;
};

The generated stealth address details.

Parameters

stealthMetaAddressURI

  • Type: string or HexString The stealth meta-address URI or the stealth meta-address itself.

    The URI follows the format: st:<chain>:<stealthMetaAddress>, where <chain> is the chain identifier (EIP-3770 examples (opens in a new tab)) and <stealthMetaAddress> is the stealth meta-address.

    Alternatively, you can provide the stealth meta-address without the URI prefix like so 0x....

const { stealthAddress, ephemeralPublicKey, viewTag } = generateStealthAddress({
  ephemeralPrivateKey,
  schemeId,
  stealthMetaAddressURI,
});

schemeId (optional)

  • Type: VALID_SCHEME_ID The scheme id used to generate the stealth address.

    The default scheme id is 1.

const { stealthAddress, ephemeralPublicKey, viewTag } = generateStealthAddress({
  ephemeralPrivateKey,
  schemeId,
  stealthMetaAddressURI,
});

ephemeralPrivateKey (optional)

  • Type: HexString The ephemeral private key used to generate the stealth address. If not provided, a random ephemeral private key is generated.

    You most likely won't need to pass this parameter, as you will want the ephemeral public key (derived from the ephemeral private key) to be generated non-deterministically. However, if you need to generate the stealth address deterministically (such as during testing), you can provide the ephemeral private key.

    The ephemeral private key is a 32-byte hexadecimal string.

const { stealthAddress, ephemeralPublicKey, viewTag } = generateStealthAddress({
  ephemeralPrivateKey,
  schemeId,
  stealthMetaAddressURI,
});