@btc-vision/ecpair - v4.0.2
    Preparing search index...

    Interface CryptoBackend

    Low-level secp256k1 operations required by the signer layer.

    Two concrete implementations ship with this package:

    Third-party implementations must satisfy every non-optional method.

    interface CryptoBackend {
        isPoint(p: Uint8Array): boolean;
        isPrivate(d: Uint8Array): boolean;
        isXOnlyPoint(p: Uint8Array): boolean;
        pointAddScalar(
            p: PublicKey,
            tweak: Bytes32,
            compressed?: boolean,
        ): PublicKey | null;
        pointCompress(p: PublicKey, compressed?: boolean): PublicKey;
        pointFromScalar(d: PrivateKey, compressed?: boolean): PublicKey | null;
        privateAdd(d: PrivateKey, tweak: Bytes32): PrivateKey | null;
        privateNegate(d: PrivateKey): PrivateKey;
        sign(
            hash: MessageHash,
            privateKey: PrivateKey,
            extraEntropy?: Uint8Array<ArrayBufferLike>,
        ): Signature;
        signSchnorr?(
            hash: MessageHash,
            privateKey: PrivateKey,
            extraEntropy?: Uint8Array<ArrayBufferLike>,
        ): SchnorrSignature;
        verify(
            hash: MessageHash,
            publicKey: PublicKey,
            signature: Signature,
        ): boolean;
        verifySchnorr?(
            hash: MessageHash,
            publicKey: XOnlyPublicKey,
            signature: SchnorrSignature,
        ): boolean;
        xOnlyPointAddTweak(
            p: XOnlyPublicKey,
            tweak: Bytes32,
        ): XOnlyPointAddTweakResult | null;
    }

    Implemented by

    Index

    Methods

    • Returns true if p is a valid SEC1-encoded secp256k1 point.

      Parameters

      • p: Uint8Array

        Compressed (33 bytes) or uncompressed (65 bytes) SEC1 encoding.

      Returns boolean

    • Returns true if d is a valid secp256k1 private key (32 bytes, in range [1, n)).

      Parameters

      • d: Uint8Array

        Raw bytes to test.

      Returns boolean

    • Returns true if p is a valid 32-byte x-only public key whose x-coordinate lies on the secp256k1 curve.

      Parameters

      • p: Uint8Array

        32-byte x-only encoding.

      Returns boolean

    • Adds a scalar tweak to a public key point (P + tweak·G).

      Parameters

      • p: PublicKey

        Base public key.

      • tweak: Bytes32

        32-byte scalar to add.

      • Optionalcompressed: boolean

        Encoding of the returned point.

      Returns PublicKey | null

      The resulting point, or null if the result is the point at infinity.

    • Re-encodes a public key in the requested SEC1 form.

      Parameters

      • p: PublicKey

        Input public key in any SEC1 form.

      • Optionalcompressed: boolean

        Target form. Defaults to compressed.

      Returns PublicKey

    • Derives the public key for a private key scalar.

      Parameters

      • d: PrivateKey

        Private key scalar.

      • Optionalcompressed: boolean

        Return compressed (33 bytes) when true (default), uncompressed (65 bytes) when false.

      Returns PublicKey | null

      The public key, or null if d is invalid.

    • Produces a compact (64-byte) ECDSA signature.

      Parameters

      • hash: MessageHash

        32-byte message hash.

      • privateKey: PrivateKey

        Signing key.

      • OptionalextraEntropy: Uint8Array<ArrayBufferLike>

        Optional additional randomness for RFC 6979.

      Returns Signature