private

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 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 private holds what a reader is handed to open a private store: the store key. A private store is committed to by a record through a salted root and nothing else, so nothing a host or a reader of the record holds leads to its carriers; the store key is the one thing that does.

The key is the publisher's to hand out, by whatever means: a file, a messagebox, a delivery wrapped for one reader. Its JSON form is frozen at the first private store a publisher hands out, like every other format a reader recomputes from.

Index

Constants

View Source
const AnchorSats = 1

AnchorSats is the anchor output's value.

View Source
const EnvelopeVersion = 1

EnvelopeVersion is both envelopes' version.

View Source
const Version = 1

Version is the store key's format version.

Variables

View Source
var (
	ReleaseSignature  = pushdrop.Derivation{Protocol: wallet.Protocol{SecurityLevel: 1, Protocol: "bfinger release"}, KeyID: "release"}
	DeliverySignature = pushdrop.Derivation{Protocol: wallet.Protocol{SecurityLevel: 1, Protocol: "bfinger delivery"}, KeyID: "delivery"}
)

The protocols and key ids the envelopes are encrypted and signed under.

View Source
var AnchorDerivation = pushdrop.Derivation{Protocol: wallet.Protocol{SecurityLevel: 1, Protocol: "bfinger anchor"}, KeyID: "anchor"}

AnchorDerivation is the key an anchor is locked and signed under, the deliverer's: [1, "bfinger anchor"] and key id "anchor", counterparty anyone.

View Source
var AnchorTag = []byte{'b', 'f', 0x03}

AnchorTag is the anchor output's first field: "bf" and 0x03, after the token (0x01) and the funding output (0x02).

View Source
var ErrAnchor = errors.New("private: anchor does not match the delivery")

ErrAnchor is an anchor that is not this delivery's.

View Source
var ErrEnvelope = errors.New("private: envelope does not verify")

ErrEnvelope is an envelope that does not open or does not verify.

View Source
var ErrOpen = errors.New("private: sealed content does not open")

ErrOpen is a sealed sub-record that does not open: a key that is not the committed one, a ciphertext that is not the seal's, or a tag that fails.

View Source
var OriginatorDerivation = pushdrop.Derivation{Protocol: wallet.Protocol{SecurityLevel: 1, Protocol: "bfinger seal"}, KeyID: "originator"}

OriginatorDerivation is the key the originator signs a store's head under: [1, "bfinger seal"] and key id "originator", counterparty anyone, so a reader holding only the identity key derives the verifying key.

Functions

func AnchorFields

func AnchorFields(contentID, deliveryHash, readerCommit [32]byte) [][]byte

AnchorFields are the anchor's fields, tag first.

func Deliver

func Deliver(ctx context.Context, w Wallet, originator string, release []byte, now time.Time) ([]byte, [32]byte, error)

Deliver wraps release for its reader: the outer envelope, signed by the deliverer's wallet w and encrypted to the reader. It returns the delivery file and its hash.

func HeadC

func HeadC(txid string) ([32]byte, error)

HeadC is the head commitment in hash byte order from a txid.

func OpenRelease

func OpenRelease(ctx context.Context, w Wallet, originator string, b []byte) (*Parsed, *ReleaseInfo, error)

OpenRelease opens a release with the reader's wallet: the signature, that it is addressed to this reader, then the store key inside, which must be the identity's that signed and name the content the release names.

func OpenSegment

func OpenSegment(k [32]byte, salt [keyed.SaltLen]byte, i uint64, ciphertext []byte) ([]byte, error)

OpenSegment reverses SealSegment; nothing is returned unless the tag verifies.

func OriginatorDigest

func OriginatorDigest(keyCommit [32]byte, body record.Map) ([32]byte, error)

OriginatorDigest is what the originator signs: a domain string, the content key's commitment, and the hash of the head's body, so the signature binds this content and this key and nothing else.

func ReaderCommit

func ReaderCommit(salt [32]byte, reader *ec.PublicKey, data []byte) [32]byte

ReaderCommit is the salted commitment to what a deliverer records about a reader: SHA-256 of a domain string, the salt, the reader's key and the data.

func Release

func Release(ctx context.Context, w Wallet, originator string, reader *ec.PublicKey, key *Key, contentID [32]byte) ([]byte, error)

Release is the inner envelope: key, the store key, encrypted to reader by the identity's wallet w and signed by it. contentID names the content it releases, the head's seal content id.

func SealSegment

func SealSegment(k [32]byte, salt [keyed.SaltLen]byte, i uint64, plaintext []byte) ([]byte, error)

SealSegment encrypts plaintext as segment i of the content under k: AES-256-GCM under BRC-369's symmetric key, IV keyed.SegmentIV(salt, i), no associated data, tag last.

Types

type Anchor

type Anchor struct {
	ContentID, DeliveryHash, ReaderCommit [32]byte
}

Anchor is a decoded anchor output.

func CheckAnchor

func CheckAnchor(s *script.Script, deliverer *ec.PublicKey, contentID, deliveryHash [32]byte) (*Anchor, error)

CheckAnchor decodes an anchor output and holds it to a delivery: the deliverer's anchor key locks it and signed its fields, and it names this content and this delivery's hash.

type Delivery

type Delivery struct {
	Deliverer *ec.PublicKey
	Reader    *ec.PublicKey
	Nonce     [32]byte
	Time      time.Time
	Release   []byte
	// Hash is SHA-256 of the delivery file as delivered: what a reader
	// anchor names.
	Hash [32]byte
}

Delivery is an opened outer envelope.

func OpenDelivery

func OpenDelivery(ctx context.Context, w Wallet, originator string, b []byte) (*Delivery, error)

OpenDelivery opens a delivery with the reader's wallet: it decrypts, checks the deliverer's signature and that it is addressed to this reader and wraps a release for this reader. The release inside is returned for OpenRelease.

type Handoff

type Handoff struct {
	Delivery []byte
	Anchor   [32]byte
}

Handoff is what a reader is handed: the delivery and the txid of its anchor, in hash byte order.

func DecodeHandoff

func DecodeHandoff(b []byte) (*Handoff, error)

DecodeHandoff reads a handoff.

func (*Handoff) Encode

func (h *Handoff) Encode() ([]byte, error)

Encode writes the handoff as {v: 1, delivery, anchor}.

type Inner

type Inner struct {
	Body       record.Map
	Originator *[33]byte
	Sig        []byte
}

Inner is a sealed sub-record's content.

type Key

type Key struct {
	V int `json:"v"`
	// IdentityKey is the identity whose record carries the store's refs
	// entry, hex, compressed.
	IdentityKey string `json:"identityKey"`
	Store       string `json:"store"`
	Count       uint64 `json:"count"`
	// Head is the head carrier's txid, display order: the form the carrier
	// question takes.
	Head string `json:"head"`
	// CarrierKey is the key the store's carriers are signed and indexed
	// under, hex. The identity's own key, or one the host cannot tie to it.
	CarrierKey string `json:"carrierKey"`
	Salt       string `json:"salt"`
	// ContentKey is the BRC-369 content key every sub-record of the store
	// is sealed under, hex. It is the one secret here: whoever holds it
	// reads the store.
	ContentKey string `json:"contentKey"`
}

Key is a store key: which identity's record commits to the store, the store's name and member count, the head to ask a host for (the one member, or the manifest), the key its carriers are published and indexed under, and the store's salt.

func (*Key) Encode

func (k *Key) Encode() ([]byte, error)

Encode is the key's JSON form, indented, with a trailing newline.

type Opened

type Opened struct {
	Body       record.Map
	Originator *ec.PublicKey
}

Opened is a sealed sub-record opened: its clear body, and the originator when the inner content names one and its signature verified.

func Open

func Open(rec *record.Record, k [32]byte, wantSegment uint64, head bool) (*Opened, error)

Open opens a sealed record with the store's content key: the key is checked against the seal's commitment before it is used (BRC-369 section 5.3, so a wrong key names whoever handed it over), the ciphertext against the seal's content id, then the segment, then, where the seal says the originator is inside and head is set, the originator's signature.

type Parsed

type Parsed struct {
	Key
	Identity *ec.PublicKey
	Carrier  *ec.PublicKey
	HeadC    [32]byte
	SaltB    [32]byte
	Content  [32]byte
}

Parsed is a store key read and checked: every field in the form a reader uses.

func Parse

func Parse(raw []byte) (*Parsed, error)

Parse checks a store key's shape: the version, both keys as points in their one encoding, the head as a txid, the salt as 32 bytes, a store name within the refs bound, and a count a manifest can hold.

func Read

func Read(path string) (*Parsed, error)

Read reads and parses a store key file.

type ReleaseInfo

type ReleaseInfo struct {
	Identity  *ec.PublicKey
	Reader    *ec.PublicKey
	ContentID [32]byte
}

ReleaseInfo is what a release says in the clear.

func ReadRelease

func ReadRelease(b []byte) (*ReleaseInfo, record.Map, error)

ReadRelease checks a release's shape and the identity's signature over it, without opening it: what a deliverer does before wrapping it.

type Sealer

type Sealer struct {
	Key        [32]byte
	Salt       [keyed.SaltLen]byte
	Carrier    string // record.CarrierIdentity or record.CarrierChild
	Originator string // record.OriginatorInside or record.OriginatorAbsent
}

Sealer seals the sub-records of one private store.

func NewSealer

func NewSealer(carrier, originator string) (*Sealer, error)

NewSealer draws a store's content key and salt.

func (*Sealer) Seal

func (s *Sealer) Seal(ctx context.Context, i uint64, body record.Map, signer Signer, originator string) (record.Map, *record.Seal, error)

Seal turns a sub-record's clear body into its sealed body and seal, as segment i. When signer is set (the store's head, with the originator inside) the inner content carries the identity and its signature.

type Signer

type Signer interface {
	GetPublicKey(ctx context.Context, args wallet.GetPublicKeyArgs, originator string) (*wallet.GetPublicKeyResult, error)
	CreateSignature(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error)
}

Signer is what signs a store's head with the originator inside: the identity's wallet, or any part of one that can answer these two.

type Wallet

type Wallet interface {
	Signer
	Encrypt(ctx context.Context, args wallet.EncryptArgs, originator string) (*wallet.EncryptResult, error)
	Decrypt(ctx context.Context, args wallet.DecryptArgs, originator string) (*wallet.DecryptResult, error)
}

Wallet is what makes and opens envelopes: an identity that encrypts, decrypts and signs.

Jump to

Keyboard shortcuts

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