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
- Variables
- func NewReadSecret(rng io.Reader) ([]byte, error)
- func SenderKeyHash(publicKey ed25519.PublicKey) ([PKHashBytes]byte, error)
- func ShareIDForSenderKeyHash(pkHash []byte) (string, error)
- func Split(full string) (bare, key string, err error)
- func TrimCopiedText(s string) string
- type Link
Constants ¶
const ( // SuiteSenderAuthenticated is the native capability and sender-object suite. SuiteSenderAuthenticated byte = 0x02 // ReadSecretBytes is the 128-bit capability secret width. ReadSecretBytes = 16 SenderAuthenticatedShareIDBytes = 12 // PKHashBytes is the truncated sender Ed25519 public-key hash width. PKHashBytes = 16 )
const (
MaximumRelayHints = 8
)
Variables ¶
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") ErrMalformedFragment = errors.New("link: malformed key string") // ErrKeyConflict:裸链接自带密钥且与另行提供的密钥串不一致时,静默偏袒 // 任何一方都可能让用户拿错密钥解错分享,必须报错让用户裁决。 ErrKeyConflict = errors.New("link: embedded key and separately supplied key do not match") )
Functions ¶
func NewReadSecret ¶
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 ¶
ShareIDForSenderKeyHash deterministically derives the v2 relay route from the public sender identity.
func Split ¶
Split 把完整链接拆为「裸链接 + 密钥串」(发送侧 --split-key 的字符串形态; 与 Merge 构成 §6.3 的拆合纯函数对)。拆前校验密钥串可解,不放走坏链接。
func TrimCopiedText ¶
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 ¶
type Link struct {
Suite byte // 套件/版本位,fragment 首字节
ReadSecret []byte // 16B;链接中唯一秘密
PKHash []byte // suite 0x02 only: first16(SHA-256(sender-key-domain || sender public key))
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 ¶
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.