Files
utxo/secp256r1fx/credential_test.go
zeekay 2436a42df2 feat: add ed25519fx, schnorrfx, secp256r1fx, slhdsafx + mldsafx updates
Adds four new Fx (feature-extension) packages for X-Chain UTXO signing
schemes beyond secp256k1:
  - ed25519fx    — Ed25519 (EdDSA on Curve25519)
  - schnorrfx    — Schnorr (classical)
  - secp256r1fx  — P-256 / NIST
  - slhdsafx     — SLH-DSA (FIPS 205 hash-based PQ)

Plus mldsafx updates to match (ML-DSA / FIPS 204 lattice PQ).

Each fx package exports Fx, Credential, Keychain, OutputOwners, Input
following the existing secp256k1fx pattern.

Gitignore .DS_Store.
2026-04-13 07:33:34 -07:00

55 lines
1.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package secp256r1fx
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"
"github.com/stretchr/testify/require"
)
func TestCredentialVerify(t *testing.T) {
require := require.New(t)
var sig [SigLen]byte
cred := &Credential{
Sigs: [][SigLen]byte{sig},
}
require.NoError(cred.Verify())
}
func TestCredentialVerifyNil(t *testing.T) {
var cred *Credential
require.ErrorIs(t, cred.Verify(), ErrNilCredential)
}
func TestCredentialWithPubKeys(t *testing.T) {
require := require.New(t)
sk, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
require.NoError(err)
pk := pubKeyBytes(&sk.PublicKey)
var sig [SigLen]byte
cred := &Credential{
Sigs: [][SigLen]byte{sig},
PubKeys: [][]byte{pk},
}
require.NoError(cred.Verify())
require.Len(cred.PubKeys, 1)
require.Equal(PubKeyLen, len(cred.PubKeys[0]))
}
// Regression: Finding 6 -- Empty Sigs slice must be rejected
func TestCredential_RejectEmptySigs(t *testing.T) {
cred := &Credential{
Sigs: [][SigLen]byte{},
}
require.ErrorIs(t, cred.Verify(), ErrEmptyCredential)
}