libsecp256k1

package
v0.37.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 8 Imported by: 0

README

This wraps libsecp256k1 with cgo.

It doesn't embed the library or anything smart like that because I don't know how to do it, so you must have it installed in your system.

It is faster than the pure Go version:

goos: linux
goarch: amd64
pkg: github.com/nbd-wtf/go-nostr/libsecp256k1
cpu: AMD Ryzen 3 3200G with Radeon Vega Graphics
BenchmarkSignatureVerification/btcec-4         	     145	   7873130 ns/op	  127069 B/op	     579 allocs/op
BenchmarkSignatureVerification/libsecp256k1-4  	     502	   2314573 ns/op	  112241 B/op	     392 allocs/op

To use it manually, just import. To use it inside the automatic verification that happens for subscriptions, set it up with a SimplePool:

pool := nostr.NewSimplePool()
pool.SignatureChecker = func (evt nostr.Event) bool {
	ok, _ := libsecp256k1.CheckSignature(evt)
	return ok
}

Or directly to the Relay:

relay := nostr.RelayConnect(context.Background(), "wss://relay.nostr.com", nostr.WithSignatureChecker(func (evt nostr.Event) bool {
	ok, _ := libsecp256k1.CheckSignature(evt)
	return ok
}))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSignature

func CheckSignature(evt *nostr.Event) (bool, error)

func Sign

func Sign(msg [32]byte, sk [32]byte) ([64]byte, error)

func Verify

func Verify(msg [32]byte, sig [64]byte, pk [32]byte) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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