link

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0, AGPL-3.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package link constructs and parses sender-authenticated capability URLs:

https://<frontend>/<shareId>[?r=<relay-base>]#<base64url(suite||readSecret||pkHash)>

An omitted relay hint selects the link's origin. A single equivalent relay at that origin's root is omitted when constructing links; explicit hints preserve their order. The fragment never travels in HTTP requests. Split and Merge support delivering the link and key separately. Parsing follows the browser receiver in boundary trimming, removal of inner tabs and newlines, dot-segment resolution before taking the route, and reading the fragment verbatim. Each fragment is one canonical key payload; a separately entered key may include a leading '#'. Split emits canonical keys for Merge. All operations are pure.

Index

Constants

View Source
const (
	// SuiteSenderAuthenticated is the native capability and sender-object suite.
	SuiteSenderAuthenticated byte = 0x02

	// ReadSecretBytes is the 128-bit capability secret width.
	ReadSecretBytes = 16
	// SenderAuthenticatedShareIDBytes is the relay route width.
	SenderAuthenticatedShareIDBytes = 12
	// PKHashBytes is the truncated sender Ed25519 public-key hash width.
	PKHashBytes = 16
)
View Source
const (
	MaximumRelayHints = 8
)

Variables

View Source
var (
	// ErrMissingFragment 供接收侧区分「坏链接」与「分离密钥分享」:
	// fragment 为空 → 转入密钥输入流程(网页输入框 / CLI --key,§6.10)。
	ErrMissingFragment = errors.New("link: link does not contain a key fragment")

	// Unknown suites must fail before their key material can be interpreted.
	ErrUnknownSuite = errors.New("link: unsupported link suite")

	ErrMalformedLink     = errors.New("link: malformed link")
	ErrMalformedShareID  = errors.New("link: malformed shareId")
	ErrMalformedFragment = errors.New("link: malformed key string")

	// ErrKeyConflict:裸链接自带密钥且与另行提供的密钥串不一致时,静默偏袒
	// 任何一方都可能让用户拿错密钥解错分享,必须报错让用户裁决。
	ErrKeyConflict = errors.New("link: embedded key and separately supplied key do not match")
)

Functions

func NewReadSecret

func NewReadSecret(rng io.Reader) ([]byte, error)

NewReadSecret 从 rng 取 ReadSecretBytes 随机字节。随机源注入而非内取 crypto/rand:金标向量与测试需要确定性(§7);生产传 crypto/rand.Reader。

func SenderKeyHash

func SenderKeyHash(publicKey ed25519.PublicKey) ([PKHashBytes]byte, error)

SenderKeyHash binds a suite-0x02 capability to its Ed25519 sender identity.

func ShareIDForSenderKeyHash

func ShareIDForSenderKeyHash(pkHash []byte) (string, error)

ShareIDForSenderKeyHash deterministically derives the v2 relay route from the public sender identity.

func Split

func Split(full string) (bare, key string, err error)

Split 把完整链接拆为「裸链接 + 密钥串」(发送侧 --split-key 的字符串形态; 与 Merge 构成 §6.3 的拆合纯函数对)。拆前校验密钥串可解,不放走坏链接。

func TrimCopiedText

func TrimCopiedText(s string) string

TrimCopiedText applies JavaScript's String.prototype.trim, which the browser receiver uses before parsing links and keys. Go's TrimSpace differs at U+0085 and U+FEFF, so clients reading pasted capability text should use this rule.

Types

type Link struct {
	Suite       byte     // 套件/版本位,fragment 首字节
	ReadSecret  []byte   // 16B;链接中唯一秘密
	PKHash      []byte   // suite 0x02 only: first16(SHA-256(sender-key-domain || sender public key))
	ShareID     string   // suite-specific base64url relay route; never an encryption input
	Relays      []string // Ordered relay bases; Parse and Merge resolve omitted hints from the link origin.
	NodeAliases []string // Directory names are resolved by the application, never by the parser.
}

Link 是能力链接的语义结构(§6.3)。

func Merge

func Merge(bare, key string) (Link, error)

Merge combines a capability URL with a separately supplied key. Key input may include a leading '#' or be a complete link, but must match the URL's identity. An embedded key must also agree; conflicting keys return ErrKeyConflict.

func NewSenderAuthenticated

func NewSenderAuthenticated(readSecret []byte, publicKey ed25519.PublicKey, relays []string) (Link, error)

NewSenderAuthenticated constructs the native suite-0x02 capability identity.

func Parse

func Parse(raw string) (Link, error)

Parse 解析完整能力链接。fragment 缺失返回 ErrMissingFragment,接收侧据此 转入分离密钥输入流程(Merge)。

func (Link) KeyString

func (l Link) KeyString() (string, error)

KeyString encodes suite||readSecret||pkHash with strict unpadded base64url.

func (Link) SplitURL

func (l Link) SplitURL(base string) (bare, key string, err error)

SplitURL 输出「裸链接 + 密钥串」两段(分离密钥,§6.10):由工具代剪, 杜绝用户手工截断出错;两段经不同渠道分发,密钥不落单渠道。

func (Link) URL

func (l Link) URL(base string) (string, error)

URL constructs the capability URL with the suite-specific fragment payload. base 为前端基址(前端域是部署期配置,§6.3);fragment 由浏览器语义保证不发往服务器。

Jump to

Keyboard shortcuts

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