ncrypt

package module
v0.0.0-...-f3b995e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

ncrypt

ncrypt provides an implementation of the NIP-04 and NIP-44 v2/v3 encryption specifications.

[!CAUTION] ncrypt is in v0 and will likely have breaking changes.

Installation

Add it to your project with go get:

go get pkg.nostr.land/go/ncrypt

View the documentation on pkg.go.dev.

Usage

Secret and public keys are represented as ncrypt.SecretKey and ncrypt.PublicKey, which are of type *[32]byte.

The NIP-04 and NIP-44 v2 packages expose the following APIs:

Encrypt(seckeyA ncrypt.SecretKey, pubkeyB ncrypt.PublicKey, data []byte) ([]byte, error)
Decrypt(seckeyA ncrypt.SecretKey, pubkeyB ncrypt.PublicKey, data []byte) ([]byte, error)

Even though a byte slice is returned, the encrypted data is returned as base64 encoded.

The NIP-44 v3 package also requires an additional Context:

Encrypt(seckeyA ncrypt.SecretKey, pubkeyB ncrypt.PublicKey, context nip44v3.Context, data []byte) ([]byte, error)
Decrypt(seckeyA ncrypt.SecretKey, pubkeyB ncrypt.PublicKey, context nip44v3.Context, data []byte) ([]byte, error)

The Context struct contains the kind of the event, and an additional application-customizable scope. Trying to decrypt a message with a different Context will fail.

On how to set kind/scope, read the NIP-44 v3 implementation guide for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectVersion

func DetectVersion(t []byte) byte

DetectVersion detects the encryption version of the given input. It returns:

- 0 if the ciphertext is invalid - 1 if NIP-04 - 2 if NIP-44 v2 - 3 if NIP-44 v3 - 255 for an unsupported version

Applications should be prepared to handle the addition of new return values.

Types

type PublicKey

type PublicKey *[32]byte

PublicKey represents a BIP340 public key.

type SecretKey

type SecretKey *[32]byte

SecretKey represents a BIP340 secret key.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL