@did-btc1/keypair
    Preparing search index...

    Class PublicKey

    Encapsulates a secp256k1 public key compliant to BIP-340 BIP schnorr signature scheme. Provides get methods for different formats (compressed, x-only, multibase). Provides helpers methods for comparison and serialization. PublicKey

    Implements

    Implemented by

    Index

    Constructors

    • Creates a PublicKey instance.

      Parameters

      • bytes: Bytes

        The public key byte array.

      Returns PublicKey

      if the byte length is not 32 (x-only) or 33 (compressed)

    Accessors

    • get compressed(): Bytes

      Get the compressed public key.

      Returns Bytes

      The 33-byte compressed public key (0x02 or 0x03, x).

    • get hex(): Hex

      Returns the raw public key as a hex string.

      Returns Hex

      The public key as a hex string.

    • get multibase(): MultibaseObject

      Get the multibase public key.

      Returns MultibaseObject

      An object containing the multibase bytes, address and prefix.

    • get parity(): number

      Get the parity byte of the public key.

      Returns number

      The parity byte of the public key.

    • get point(): Point

      Return the public key point.

      Returns Point

      The public key point.

    • get uncompressed(): Bytes

      Get the uncompressed public key.

      Returns Bytes

      The 65-byte uncompressed public key (0x04, x, y).

    • get x(): Bytes

      Get the x-coordinate of the public key.

      Returns Bytes

      The 32-byte x-coordinate of the public key.

    • get y(): Bytes

      Get the y-coordinate of the public key.

      Returns Bytes

      The 32-byte y-coordinate of the public key.

    Methods

    • Decodes the multibase string to the 35-byte corresponding public key (2 byte prefix + 32 byte public key).

      Returns Bytes

      The decoded public key: prefix and public key bytes

    • Encodes compressed secp256k1 public key from bytes to BIP340 multibase format.

      Returns string

      The public key encoded in base-58-btc multibase format.

    • Compares this public key to another public key.

      Parameters

      • other: PublicKey

        The other public key to compare

      Returns boolean

      True if the public keys are equal, false otherwise.

    • JSON representation of a PublicKey object.

      Returns PublicKeyObject

      The PublicKey as a JSON object.

    • Lifts a 32-byte x-only coordinate into a full secp256k1 point (x, y).

      Returns Uint8Array

      65-byte uncompressed public key (starts with 0x04)

    • Computes modular exponentiation: (base^exp) % mod. Used for computing modular square roots.

      Parameters

      • base: bigint

        The base value

      • exp: bigint

        The exponent value

      • mod: bigint

        The modulus value

      Returns bigint

      The result of the modular exponentiation

    • Computes sqrt(a) mod p using Tonelli-Shanks algorithm. This finds y such that y^2 ≡ a mod p.

      Parameters

      • a: bigint

        The value to find the square root of

      • p: bigint

        The prime modulus

      Returns bigint

      The square root of a mod p

    • Creates a PublicKey object from a JSON representation.

      Parameters

      • json: any

        The JSON object to initialize the PublicKey.

      Returns PublicKey

      The initialized PublicKey object.

    • Computes the deterministic public key for a given private key.

      Parameters

      • sk: Bytes | SecretKey

        The PrivateKey object or the private key bytes

      Returns PublicKey

      A new PublicKey object

    • Returns the point of the public key.

      Parameters

      • pk: Hex

        The public key in hex (Uint8Array or string) format.

      Returns Point

      The point of the public key.

      If the public key is not a valid hex string or byte array.

    • Static version of liftX method.

      Parameters

      • x: Bytes

        The 32-byte x-coordinate to lift.

      Returns Uint8Array

      The 65-byte uncompressed public key (0x04, x, y).