sign

package
v0.0.0-...-1b929c4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sign 实现 Ed25519 服务端签名与规范字节串构造。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalBytes

func CanonicalBytes(d Data) []byte

CanonicalBytes 构造确定性规范字节串:

0x01 || id || 0x00 || sha256(content) || 0x00 || sha256(logs) || 0x00
|| be32(len(os_info)) || os_info
|| be32(len(machine_code)) || machine_code
|| be32(len(product_id)) || product_id
|| be32(len(binary_hash)) || binary_hash
|| 0x00 || be64(created_at_unix_sec)

首字节 0x01 为格式版本标记,后续增加字段时递增。 带长度前缀的字符串字段内容可能含 0x00,裸串不可解析,故统一加 be32 长度前缀。

func Verify

func Verify(pub ed25519.PublicKey, d Data, sig []byte) bool

Verify 用指定公钥验证签名。

Types

type Data

type Data struct {
	ID          string // feedback UUID
	Content     string
	Logs        []byte
	OSInfo      string
	MachineCode string
	ProductID   string // 产品 ID
	BinaryHash  string // 可执行文件 sha256 hex(可能为空)
	CreatedAt   int64  // unix 秒
}

Data 参与签名的记录字段。

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer 持有 Ed25519 密钥。

func Load

func Load(envSeed, keyFile string) (*Signer, error)

Load 按优先级加载私钥:env seed(base64) > 文件 > 自动生成并落盘(0600)。

func (*Signer) PublicKey

func (s *Signer) PublicKey() ed25519.PublicKey

PublicKey 返回 32 字节公钥。

func (*Signer) Sign

func (s *Signer) Sign(d Data) []byte

Sign 对规范字节串签名,返回 64 字节签名。

Jump to

Keyboard shortcuts

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