Documentation ¶
Overview ¶
Package legacy how to encode and verify the current ssb messages. You most likely want to use legacy.Verify() in most cases.
See https://spec.scuttlebutt.nz/feed/messages.html for more encoding details.
Index ¶
- func InternalV8Binary(in []byte) ([]byte, error)
- func PrettyPrint(input []byte, opts ...PrettyPrinterOption) ([]byte, error)
- type DeserializedMessage
- type LegacyMessage
- type PrettyPrinterOption
- type SigAlgo
- type Signature
- type SignedLegacyMessage
- type StoredMessage
- func (sm StoredMessage) Author() refs.FeedRef
- func (sm StoredMessage) Claimed() time.Time
- func (sm StoredMessage) ContentBytes() []byte
- func (sm StoredMessage) Key() refs.MessageRef
- func (sm StoredMessage) Previous() *refs.MessageRef
- func (sm StoredMessage) Received() time.Time
- func (sm StoredMessage) Seq() int64
- func (sm StoredMessage) String() string
- func (sm StoredMessage) ValueContent() *refs.Value
- func (sm StoredMessage) ValueContentJSON() json.RawMessage
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InternalV8Binary ¶
InternalV8Binary does some funky v8 magic new Buffer(in, "binary") returns soemthing like (u16 && 0xff)
func PrettyPrint ¶ added in v0.2.1
func PrettyPrint(input []byte, opts ...PrettyPrinterOption) ([]byte, error)
PrettyPrinter formats and indents byte slice b using json.Token izer using two spaces like this to mimics JSON.stringify(....)
{ "field": "val", "arr": [ "foo", "bar" ], "obj": {} }
while preserving the order in which the keys appear
Types ¶
type DeserializedMessage ¶
type DeserializedMessage struct { Previous *refs.MessageRef `json:"previous"` Author refs.FeedRef `json:"author"` Sequence int64 `json:"sequence"` Timestamp float64 `json:"timestamp"` Hash string `json:"hash"` Content json.RawMessage `json:"content"` }
func Verify ¶
func Verify(raw []byte, hmacSecret *[32]byte) (refs.MessageRef, DeserializedMessage, error)
Verify takes an slice of bytes (like json.RawMessage) and uses EncodePreserveOrder to pretty print it. It then uses ExtractSignature and verifies the found signature against the author field of the message. If hmacSecret is non nil, it uses that as the Key for NACL crypto_auth() and verifies the signature against the hash of the message. At last it uses internalV8Binary to create a the SHA256 hash for the message key. If you find a buggy message, use `node ./encode_test.js $feedID` to generate a new testdata.zip
func VerifyWithBuffer ¶ added in v0.2.1
func VerifyWithBuffer(raw []byte, hmacSecret *[32]byte, buf *bytes.Buffer) (refs.MessageRef, DeserializedMessage, error)
type LegacyMessage ¶
type LegacyMessage struct { Previous *refs.MessageRef `json:"previous"` Author string `json:"author"` Sequence int64 `json:"sequence"` Timestamp int64 `json:"timestamp"` Hash string `json:"hash"` Content interface{} `json:"content"` }
func (LegacyMessage) Sign ¶
func (msg LegacyMessage) Sign(priv ed25519.PrivateKey, hmacSecret *[32]byte) (refs.MessageRef, []byte, error)
Sign preserves the filed order (up to content)
type PrettyPrinterOption ¶ added in v0.2.1
type PrettyPrinterOption func(pp *prettyPrinter)
func WithBuffer ¶ added in v0.2.1
func WithBuffer(buf *bytes.Buffer) PrettyPrinterOption
func WithStrictOrderChecking ¶ added in v0.2.1
func WithStrictOrderChecking(yes bool) PrettyPrinterOption
WithStrictOrderChecking enables verification of the field names in the first level of the object
type Signature ¶
type Signature string
func EncodeSignature ¶
func ExtractSignature ¶
ExtractSignature expects a pretty printed message and uses a regexp to strip it from the msg for signature verification
type SignedLegacyMessage ¶
type SignedLegacyMessage struct { LegacyMessage Signature Signature `json:"signature"` }
type StoredMessage ¶
type StoredMessage struct { Author_ refs.FeedRef // @... pubkey Previous_ *refs.MessageRef // %... message hashsha Key_ refs.MessageRef // %... message hashsha Sequence_ int64 Timestamp_ time.Time Raw_ []byte // the original message for gossiping see ssb.EncodePreserveOrdering for why }
func (StoredMessage) Author ¶
func (sm StoredMessage) Author() refs.FeedRef
func (StoredMessage) Claimed ¶
func (sm StoredMessage) Claimed() time.Time
func (StoredMessage) ContentBytes ¶
func (sm StoredMessage) ContentBytes() []byte
func (StoredMessage) Key ¶
func (sm StoredMessage) Key() refs.MessageRef
func (StoredMessage) Previous ¶
func (sm StoredMessage) Previous() *refs.MessageRef
func (StoredMessage) Received ¶
func (sm StoredMessage) Received() time.Time
func (StoredMessage) Seq ¶
func (sm StoredMessage) Seq() int64
func (StoredMessage) String ¶
func (sm StoredMessage) String() string
func (StoredMessage) ValueContent ¶
func (sm StoredMessage) ValueContent() *refs.Value
func (StoredMessage) ValueContentJSON ¶
func (sm StoredMessage) ValueContentJSON() json.RawMessage
Notes ¶
Bugs ¶
this expects signature on the root of the object. some functions (like createHistoryStream with keys:true) nest the message on level deeper and this fails