Files
utxo/secp256k1fx/credential.go
zeekay 8f7179ae0d refactor: move fx packages to root
Drop redundant fx/ directory since packages already have fx suffix:
- github.com/luxfi/utxo/fx/secp256k1fx → github.com/luxfi/utxo/secp256k1fx
- github.com/luxfi/utxo/fx/nftfx → github.com/luxfi/utxo/nftfx
- github.com/luxfi/utxo/fx/propertyfx → github.com/luxfi/utxo/propertyfx

BREAKING CHANGE: Import paths changed
2026-01-10 12:54:02 -08:00

45 lines
1.0 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package secp256k1fx
import (
"encoding/json"
"errors"
"fmt"
"github.com/luxfi/crypto/secp256k1"
"github.com/luxfi/formatting"
)
var ErrNilCredential = errors.New("nil credential")
type Credential struct {
Sigs [][secp256k1.SignatureLen]byte `serialize:"true" json:"signatures"`
}
// MarshalJSON marshals [cr] to JSON
// The string representation of each signature is created using the hex formatter
func (cr *Credential) MarshalJSON() ([]byte, error) {
signatures := make([]string, len(cr.Sigs))
for i, sig := range cr.Sigs {
sigStr, err := formatting.Encode(formatting.HexNC, sig[:])
if err != nil {
return nil, fmt.Errorf("couldn't convert signature to string: %w", err)
}
signatures[i] = sigStr
}
jsonFieldMap := map[string]interface{}{
"signatures": signatures,
}
return json.Marshal(jsonFieldMap)
}
func (cr *Credential) Verify() error {
if cr == nil {
return ErrNilCredential
}
return nil
}