WizardConnect/packages/core/src/utilnostr.ts

22 lines
823 B
TypeScript
Raw Normal View History

2026-02-26 11:19:47 +01:00
// Copyright (C) 2026 Whiterun LLC,
// This software is licensed under the GNU Lesser General Public License (LGPL), version 3.0 or later.
// A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/lgpl-3.0.html
import { binToHex, secp256k1 } from "@bitauth/libauth";
import { unwrap } from "./primitives.js";
export function deriveNostrPublicKey(privateKey: Uint8Array): string {
const publicKeyCompressed = unwrap(
secp256k1.derivePublicKeyCompressed(privateKey),
);
const publicKeyNostr = publicKeyCompressed.slice(1);
return binToHex(publicKeyNostr);
}
export function deriveNostrPublicKeyBytes(privateKey: Uint8Array): Uint8Array {
const publicKeyCompressed = unwrap(
secp256k1.derivePublicKeyCompressed(privateKey),
);
return publicKeyCompressed.slice(1);
}