mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
116 lines
2.6 KiB
Go
116 lines
2.6 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package signer
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/go-json-experiment/json"
|
|
"github.com/luxfi/crypto/bls"
|
|
"github.com/luxfi/formatting"
|
|
)
|
|
|
|
var (
|
|
_ Signer = (*ProofOfPossession)(nil)
|
|
|
|
ErrInvalidProofOfPossession = errors.New("invalid proof of possession")
|
|
)
|
|
|
|
type ProofOfPossession struct {
|
|
PublicKey [bls.PublicKeyLen]byte `json:"publicKey"`
|
|
// BLS signature proving ownership of [PublicKey]. The signed message is the
|
|
// [PublicKey].
|
|
ProofOfPossession [bls.SignatureLen]byte `json:"proofOfPossession"`
|
|
|
|
// publicKey is the parsed version of [PublicKey]. It is populated in
|
|
// [Verify].
|
|
publicKey *bls.PublicKey
|
|
}
|
|
|
|
func NewProofOfPossession(sk bls.Signer) (*ProofOfPossession, error) {
|
|
pk := sk.PublicKey()
|
|
pkBytes := bls.PublicKeyToCompressedBytes(pk)
|
|
sig, err := sk.SignProofOfPossession(pkBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
sigBytes := bls.SignatureToBytes(sig)
|
|
|
|
pop := &ProofOfPossession{
|
|
publicKey: pk,
|
|
}
|
|
copy(pop.PublicKey[:], pkBytes)
|
|
copy(pop.ProofOfPossession[:], sigBytes)
|
|
return pop, nil
|
|
}
|
|
|
|
func (p *ProofOfPossession) Verify() error {
|
|
publicKey, err := bls.PublicKeyFromCompressedBytes(p.PublicKey[:])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
signature, err := bls.SignatureFromBytes(p.ProofOfPossession[:])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !bls.VerifyProofOfPossession(publicKey, signature, p.PublicKey[:]) {
|
|
return ErrInvalidProofOfPossession
|
|
}
|
|
|
|
p.publicKey = publicKey
|
|
return nil
|
|
}
|
|
|
|
func (p *ProofOfPossession) Key() *bls.PublicKey {
|
|
return p.publicKey
|
|
}
|
|
|
|
type jsonProofOfPossession struct {
|
|
PublicKey string `json:"publicKey"`
|
|
ProofOfPossession string `json:"proofOfPossession"`
|
|
}
|
|
|
|
func (p *ProofOfPossession) MarshalJSON() ([]byte, error) {
|
|
pk, err := formatting.Encode(formatting.HexNC, p.PublicKey[:])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pop, err := formatting.Encode(formatting.HexNC, p.ProofOfPossession[:])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(jsonProofOfPossession{
|
|
PublicKey: pk,
|
|
ProofOfPossession: pop,
|
|
})
|
|
}
|
|
|
|
func (p *ProofOfPossession) UnmarshalJSON(b []byte) error {
|
|
jsonBLS := jsonProofOfPossession{}
|
|
err := json.Unmarshal(b, &jsonBLS)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pkBytes, err := formatting.Decode(formatting.HexNC, jsonBLS.PublicKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pk, err := bls.PublicKeyFromCompressedBytes(pkBytes)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
popBytes, err := formatting.Decode(formatting.HexNC, jsonBLS.ProofOfPossession)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
copy(p.PublicKey[:], pkBytes)
|
|
copy(p.ProofOfPossession[:], popBytes)
|
|
p.publicKey = pk
|
|
return nil
|
|
}
|