mirror of
https://github.com/luxfi/warp.git
synced 2026-10-30 15:13:04 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue. Co-authored-by: Hanzo Dev <[email protected]>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package warp
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/luxfi/crypto/bls"
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
var (
|
|
_ Signer = (*signer)(nil)
|
|
|
|
ErrWrongSourceChainID = errors.New("wrong SourceChainID")
|
|
ErrWrongNetworkID = errors.New("wrong networkID")
|
|
)
|
|
|
|
// Signer signs warp messages. It signs the Beam domain
|
|
// (BeamSigningBytes(message.ID())), never the bare message bytes or an opaque
|
|
// caller-supplied digest.
|
|
type Signer interface {
|
|
Sign(message *Message) ([]byte, error)
|
|
}
|
|
|
|
// NewSigner creates a new warp message signer using a bls.Signer interface
|
|
func NewSigner(sk bls.Signer, networkID uint32, chainID ids.ID) Signer {
|
|
return &signer{
|
|
sk: sk,
|
|
networkID: networkID,
|
|
chainID: chainID,
|
|
}
|
|
}
|
|
|
|
type signer struct {
|
|
sk bls.Signer
|
|
networkID uint32
|
|
chainID ids.ID
|
|
}
|
|
|
|
func (s *signer) Sign(message *Message) ([]byte, error) {
|
|
if message.SourceChainID != s.chainID {
|
|
return nil, ErrWrongSourceChainID
|
|
}
|
|
if message.NetworkID != s.networkID {
|
|
return nil, ErrWrongNetworkID
|
|
}
|
|
|
|
sig, err := s.sk.Sign(BeamSigningBytes(message.ID()))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return bls.SignatureToBytes(sig), nil
|
|
}
|