npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ts-core/crypto-secp256k1

v3.0.2

Published

TypeScript library for secp256k1 / ECDSA cryptography (compatible with DKLS23 MPC custody signatures) - key generation, signing, verification, public key recovery and address derivation

Downloads

227

Readme

@ts-core/crypto-secp256k1

Библиотека для работы с эллиптической кривой secp256k1 и алгоритмом ECDSA. Предоставляет генерацию ключей, подпись и проверку сообщений, проверку подписей по готовому 32-байтовому digest (совместимо с DKLS23 MPC custody), восстановление публичного ключа и вычисление Ethereum-адреса.

Установка

npm install @ts-core/crypto-secp256k1

Зависимости

  • @ts-core/common — базовые классы и интерфейсы
  • @noble/curves — реализация secp256k1 / ECDSA
  • @noble/hashes — sha256 и keccak256

Основные классы

Secp256k1

Обёртка над secp256k1 / ECDSA. Все ключи и подписи — hex-строки (без префикса 0x).

import { Secp256k1 } from '@ts-core/crypto-secp256k1';

// Генерация пары ключей
const keys = Secp256k1.keys();
console.log(keys.privateKey);  // Приватный ключ (hex)
console.log(keys.publicKey);   // Публичный ключ SEC1 compressed (hex)

// Подпись сообщения (внутри sha256(message))
const signature = Secp256k1.sign('Hello, World!', keys.privateKey);

// Проверка подписи
const isValid = Secp256k1.verify('Hello, World!', signature, keys.publicKey);
console.log(isValid);  // true

Проверка подписи custody (DKLS23)

Custody подписывает готовый 32-байтовый digest, а результат отдаёт в runtime.signature. Для проверки без пересборки digest:

import { Secp256k1 } from '@ts-core/crypto-secp256k1';

// Прямая проверка по digest (аналог verify_signature.py)
const isValid = Secp256k1.verifyDigest(
    'a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3', // digest_hex
    '90dd4e4d...9b87c56d',                                              // signature_hex (r||s)
    '033e11c7758d8d993321b75eb9a6975c05049405455ddf61c04258ac7f7237b69d' // public_key_hex (SEC1 compressed)
);

// Или напрямую из объекта runtime.signature
const isValid2 = Secp256k1.verifySignature(execute.runtime.signature);

⚠️ Проверка выполняется с lowS: false: custody может вернуть подпись с high-S, и форсированная канонизация отбросила бы валидную подпись.

Восстановление ключа и адрес

// Восстановление публичного ключа из подписи (recovery id 0/1)
const publicKey = Secp256k1.recover(digestHex, signatureHex, 0);

// Ethereum-адрес из публичного ключа (keccak256)
const address = Secp256k1.address(publicKey);  // 0x...

TransportCryptoManagerSecp256k1

Менеджер подписи транспортных команд @ts-core/common.

import { TransportCryptoManagerSecp256k1 } from '@ts-core/crypto-secp256k1';

const manager = new TransportCryptoManagerSecp256k1();
const signature = await TransportCryptoManager.sign(command, manager, keys);
const isValid = await TransportCryptoManager.verify(command, manager, signature);

API

| Метод | Назначение | | --- | --- | | keys() | Генерация пары ключей (IKeyAsymmetric, SEC1 compressed) | | from(privateKey) | Восстановление пары из приватного ключа | | nonce() | Случайный 8-байтовый nonce (hex) | | sign(message, privateKey) | Подпись сообщения (sha256), compact r||s | | verify(message, signature, publicKey) | Проверка подписи сообщения | | signDigest(digest, privateKey) | Подпись готового 32-byte digest | | verifyDigest(digest, signature, publicKey) | Проверка подписи по digest (custody) | | verifySignature(signature) | Проверка объекта ISecp256k1Signature | | recover(digest, signature, recovery) | Восстановление публичного ключа | | address(publicKey) | Ethereum-адрес из публичного ключа |