mpc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlgorithmExperimentalP256Schnorr = "experimental-p256-schnorr-v1"
	AlgorithmFROSTSecp256k1          = "frost-secp256k1-v1"
)
View Source
const (
	CurveName = "P-256"
)
View Source
const FragmentEnvelope = "ecdh-p256-aes-256-gcm-v1"

Variables

View Source
var (
	ErrInvalidKey          = errors.New("invalid key")
	ErrInvalidParticipants = errors.New("invalid participants")
)

Functions

func ApprovalPayload

func ApprovalPayload(approval Approval) string

func Challenge

func Challenge(publicKey, r Point, message []byte) (*big.Int, error)

func ChallengeHex

func ChallengeHex(publicKey, r Point, message []byte) (string, error)

func CombineSignatureShares

func CombineSignatureShares(shares []ShareProof) (string, error)

func CommitmentsHash

func CommitmentsHash(commitments []PublicCommitment) (string, error)

func CurveOrder

func CurveOrder() *big.Int

func DecodePoint

func DecodePoint(point Point) (*big.Int, *big.Int, bool)

func DecodeScalar

func DecodeScalar(value string) (*big.Int, bool)

func DecryptFragment

func DecryptFragment(privateKey *ecdh.PrivateKey, fragment EncryptedFragment) ([]byte, error)

func EncodeScalar

func EncodeScalar(value *big.Int) string

func EvalPolynomial

func EvalPolynomial(coefficients []*big.Int, x *big.Int) *big.Int

func EvaluateCommitment

func EvaluateCommitment(coefficients []Point, partyID int) (*big.Int, *big.Int, bool)

func FragmentAttestationPayload

func FragmentAttestationPayload(attestation FragmentAttestation) string

func FragmentEnvelopeHash

func FragmentEnvelopeHash(fragment EncryptedFragment) (string, error)

func GeneratePolynomial

func GeneratePolynomial(threshold int) ([]*big.Int, error)

func LagrangeCoefficientAtZero

func LagrangeCoefficientAtZero(partyID int, participants []int) (*big.Int, error)

func MessageHash

func MessageHash(message []byte) string

func NormalizeParticipants

func NormalizeParticipants(participants []int, threshold int, partyIDs []int) ([]int, error)

func PadScalar

func PadScalar(value *big.Int) []byte

func RandomScalar

func RandomScalar() (*big.Int, error)

func SignShare

func SignShare(localShare, nonce, challenge *big.Int, partyID int, participants []int) (*big.Int, error)

func Verify

func Verify(message []byte, publicKey Point, sig *Signature) bool

func VerifyApproval

func VerifyApproval(publicKey string, approval Approval, now time.Time) bool

func VerifyFragmentAttestation

func VerifyFragmentAttestation(publicKey string, attestation FragmentAttestation) bool

func VerifyPolynomialShare

func VerifyPolynomialShare(shareHex string, recipientID int, commitment PublicCommitment) bool

func ZeroScalars

func ZeroScalars(values []*big.Int)

Types

type Approval

type Approval struct {
	VaultID           string    `json:"vault_id"`
	SessionID         string    `json:"session_id"`
	KeyID             string    `json:"key_id"`
	PartyID           int       `json:"party_id"`
	Threshold         int       `json:"threshold"`
	Participants      []int     `json:"participants"`
	MessageHash       string    `json:"message_hash"`
	MessageType       string    `json:"message_type,omitempty"`
	Chain             string    `json:"chain,omitempty"`
	Network           string    `json:"network,omitempty"`
	TransactionDigest string    `json:"transaction_digest,omitempty"`
	ExpiresAt         time.Time `json:"expires_at"`
	Signature         string    `json:"signature"`
}

func SignApproval

func SignApproval(privateKey ed25519.PrivateKey, approval Approval) (Approval, error)

type Commitment

type Commitment struct {
	PartyID int   `json:"partyId"`
	R       Point `json:"r"`
}

type EncryptedFragment

type EncryptedFragment struct {
	KeyID                 string               `json:"key_id"`
	PartyID               int                  `json:"party_id"`
	Algorithm             string               `json:"algorithm"`
	EphemeralPublicKey    string               `json:"ephemeral_public_key"`
	Nonce                 string               `json:"nonce"`
	Ciphertext            string               `json:"ciphertext"`
	PublicShareCommitment Point                `json:"public_share_commitment"`
	Attestation           *FragmentAttestation `json:"attestation,omitempty"`
}

func EncryptFragment

func EncryptFragment(keyID string, partyID int, recipientPublicKey string, plaintext []byte, publicShare Point) (EncryptedFragment, error)

type FragmentAttestation

type FragmentAttestation struct {
	VaultID               string    `json:"vault_id"`
	DKGSessionID          string    `json:"dkg_session_id"`
	KeyID                 string    `json:"key_id"`
	PartyID               int       `json:"party_id"`
	PublicShareCommitment Point     `json:"public_share_commitment"`
	CommitmentsHash       string    `json:"commitments_hash"`
	FragmentEnvelopeHash  string    `json:"fragment_envelope_hash"`
	ApprovalPublicKey     string    `json:"approval_public_key"`
	CreatedAt             time.Time `json:"created_at"`
	Signature             string    `json:"signature"`
}

func SignFragmentAttestation

func SignFragmentAttestation(privateKey ed25519.PrivateKey, attestation FragmentAttestation) (FragmentAttestation, error)

type KeyMeta

type KeyMeta struct {
	ID          string
	CreatedAt   time.Time
	Threshold   int
	Parties     []PartyInfo
	PublicKey   Point
	Commitments []PublicCommitment
}

func NewKeyMeta

func NewKeyMeta(id string, threshold int, parties []PartyInfo, commitments []PublicCommitment) (*KeyMeta, error)

func (*KeyMeta) NormalizeParticipants

func (k *KeyMeta) NormalizeParticipants(participants []int) ([]int, error)

func (*KeyMeta) PartyIDs

func (k *KeyMeta) PartyIDs() []int

func (*KeyMeta) Public

func (k *KeyMeta) Public() PublicKey

func (*KeyMeta) Verify

func (k *KeyMeta) Verify(message []byte, sig *Signature) bool

type PartyInfo

type PartyInfo struct {
	ID  int    `json:"id"`
	URL string `json:"url"`
}

type Point

type Point struct {
	X string `json:"x"`
	Y string `json:"y"`
}

func AddEncodedPoints

func AddEncodedPoints(points []Point) (Point, error)

func AggregateCommitments

func AggregateCommitments(commitments []Commitment) (Point, error)

func CombinePublicKey

func CombinePublicKey(commitments []PublicCommitment) (Point, error)

func PublicShareCommitment

func PublicShareCommitment(commitments []PublicCommitment, partyID int) (Point, error)

func ScalarBasePoint

func ScalarBasePoint(value *big.Int) Point

type Provider

type Provider interface {
	Info() ProviderInfo
	NewKeyMeta(id string, threshold int, parties []PartyInfo, commitments []PublicCommitment) (*KeyMeta, error)
	AggregateCommitments(commitments []Commitment) (Point, error)
	ChallengeHex(publicKey, r Point, message []byte) (string, error)
	CombineSignatureShares(shares []ShareProof) (string, error)
	Verify(message []byte, publicKey Point, sig *Signature) bool
	ValidateKeyFragments(keyID string, parties []PartyInfo, commitments []PublicCommitment, fragments []EncryptedFragment) error
}

func GetProvider

func GetProvider(algorithm string) (Provider, error)

type ProviderInfo

type ProviderInfo struct {
	Algorithm                          string         `json:"algorithm"`
	Curve                              string         `json:"curve"`
	Status                             ProviderStatus `json:"status"`
	Domain                             string         `json:"domain"`
	ProductionReady                    bool           `json:"production_ready"`
	SupportsKeygen                     bool           `json:"supports_keygen"`
	SupportsSigning                    bool           `json:"supports_signing"`
	SupportsReshare                    bool           `json:"supports_reshare"`
	SupportsRecoveryImportAttestations bool           `json:"supports_recovery_import_attestations"`
	DeterministicTranscriptValidation  bool           `json:"deterministic_transcript_validation"`
	ChainCompatibility                 []string       `json:"chain_compatibility,omitempty"`
}

func SupportedProviders

func SupportedProviders() []ProviderInfo

type ProviderStatus

type ProviderStatus string
const (
	ProviderStatusExperimental ProviderStatus = "experimental"
	ProviderStatusProduction   ProviderStatus = "production"
)

type PublicCommitment

type PublicCommitment struct {
	PartyID      int     `json:"partyId"`
	Coefficients []Point `json:"coefficients"`
}

func CommitmentsForPolynomial

func CommitmentsForPolynomial(partyID int, coefficients []*big.Int) PublicCommitment

type PublicKey

type PublicKey struct {
	Curve       string `json:"curve"`
	Encoded     string `json:"encoded"`
	X           string `json:"x"`
	Y           string `json:"y"`
	Threshold   int    `json:"threshold"`
	Parties     int    `json:"parties"`
	PartyIDBase int    `json:"partyIdBase"`
}

type ShareProof

type ShareProof struct {
	PartyID int    `json:"partyId"`
	Z       string `json:"z"`
}

type Signature

type Signature struct {
	Curve       string       `json:"curve"`
	R           Point        `json:"r"`
	Z           string       `json:"z"`
	Challenge   string       `json:"challenge"`
	Commitments []Commitment `json:"commitments"`
	Shares      []ShareProof `json:"shares"`
}

type SignerIdentity

type SignerIdentity struct {
	PartyID             int    `json:"party_id"`
	Name                string `json:"name,omitempty"`
	URL                 string `json:"url,omitempty"`
	EncryptionPublicKey string `json:"encryption_public_key"`
	ApprovalPublicKey   string `json:"approval_public_key"`
}

func GenerateSignerIdentity

func GenerateSignerIdentity(partyID int, name, url string) (*ecdh.PrivateKey, ed25519.PrivateKey, SignerIdentity, error)

Jump to

Keyboard shortcuts

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