Update dependencies and refactor conversation key generation
- Added `github.com/ebitengine/purego` as a direct dependency to the project. - Removed the unused `p8k.mleku.dev` dependency from the `go.mod` file. - Refactored the `GenerateConversationKeyFromHex` function to clarify parameter order, aligning with the NIP-44 specification. - Enhanced test cases for conversation key generation to ensure proper handling of public key formats and improved error messages. - Updated the `Signer` interface to include methods for extracting and serializing public keys in compressed format.
This commit is contained in:
@@ -47,6 +47,23 @@ func (c *Context) KeypairXOnlyPub(keypair Keypair) (xonly XOnlyPublicKey, pkPari
|
||||
return
|
||||
}
|
||||
|
||||
// KeypairPub extracts the full public key (64-byte internal format) from a keypair
|
||||
func (c *Context) KeypairPub(keypair Keypair) (pubkey []byte, err error) {
|
||||
if keypairPub == nil {
|
||||
err = fmt.Errorf("keypair_pub function not available")
|
||||
return
|
||||
}
|
||||
|
||||
pubkey = make([]byte, PublicKeySize)
|
||||
ret := keypairPub(c.ctx, &pubkey[0], &keypair[0])
|
||||
if ret != 1 {
|
||||
err = fmt.Errorf("failed to extract public key from keypair")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// SchnorrSign creates a Schnorr signature (BIP-340)
|
||||
func (c *Context) SchnorrSign(msg32 []byte, keypair Keypair, auxRand32 []byte) (sig []byte, err error) {
|
||||
if schnorrsigSign32 == nil {
|
||||
|
||||
@@ -67,6 +67,7 @@ var (
|
||||
xonlyPubkeyParse func(ctx uintptr, pubkey *byte, input32 *byte) int32
|
||||
xonlyPubkeySerialize func(ctx uintptr, output32 *byte, pubkey *byte) int32
|
||||
keypairXonlyPub func(ctx uintptr, pubkey *byte, pkParity *int32, keypair *byte) int32
|
||||
keypairPub func(ctx uintptr, pubkey *byte, keypair *byte) int32
|
||||
|
||||
// ECDH functions
|
||||
ecdh func(ctx uintptr, output *byte, pubkey *byte, seckey *byte, hashfp uintptr, data uintptr) int32
|
||||
@@ -193,6 +194,7 @@ func registerSymbols() (err error) {
|
||||
tryRegister(&xonlyPubkeyParse, "secp256k1_xonly_pubkey_parse")
|
||||
tryRegister(&xonlyPubkeySerialize, "secp256k1_xonly_pubkey_serialize")
|
||||
tryRegister(&keypairXonlyPub, "secp256k1_keypair_xonly_pub")
|
||||
tryRegister(&keypairPub, "secp256k1_keypair_pub")
|
||||
tryRegister(&xonlyPubkeyFromPubkey, "secp256k1_xonly_pubkey_from_pubkey")
|
||||
|
||||
// ECDH module
|
||||
@@ -308,6 +310,11 @@ func (c *Context) SerializePublicKey(pubkey []byte, compressed bool) (output []b
|
||||
return
|
||||
}
|
||||
|
||||
// SerializePublicKeyCompressed serializes a public key in compressed format (33 bytes)
|
||||
func (c *Context) SerializePublicKeyCompressed(pubkey []byte) (output []byte, err error) {
|
||||
return c.SerializePublicKey(pubkey, true)
|
||||
}
|
||||
|
||||
// ParsePublicKey parses a serialized public key
|
||||
func (c *Context) ParsePublicKey(input []byte) (pubkey []byte, err error) {
|
||||
pubkey = make([]byte, PublicKeySize)
|
||||
|
||||
Reference in New Issue
Block a user