~whereswaldon/forest-go

ref: c7a4d89bc08753da0fc038d329bceed1d3285905 forest-go/doc.go -rw-r--r-- 2.2 KiB
c7a4d89bChris Waldon Merge branch 'protonpgp' 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Package forest is a library for creating nodes in the Arbor Forest data structure.

The specification for the Arbor Forest can be found here: https://github.com/arborchat/protocol/blob/forest/spec/Forest.md

All nodes in the Arbor Forest are cryptographically signed by an Identity
node. Identity nodes sign themselves. To create a new identity, first create or load an OpenPGP private key using golang.org/x/crypto/openpgp. Then you can use that key and name to create an identity.

    privkey := getPrivateKey() // do this however
    name, err := fields.NewQualifiedContent(fields.ContentTypeUTF8, "example")
    // handle error
    metadata, err := fields.NewQualifiedContent(fields.ContentTypeJSON, "{}")
    // handle error
    identity, err := forest.NewIdentity(privkey, name, metadata)
    // handle error

Identities (and their private keys) can be used to create other nodes with
the Builder type. You can create community nodes using a builder like so:

    builder := forest.As(identity, privkey)
    communityName, err := fields.NewQualifiedContent(fields.ContentTypeUTF8, "example")
    // handle error
    communityMetadata, err := fields.NewQualifiedContent(fields.ContentTypeJSON, "{}")
    // handle error
    community, err := builder.NewCommunity(communityName, communityMetadata)
    // handle error

Builders can also create reply nodes:

    message, err := fields.NewQualifiedContent(fields.ContentTypeUTF8, "example")
    // handle error
    replyMetadata, err := fields.NewQualifiedContent(fields.ContentTypeJSON, "{}")
    // handle error
    reply, err := builder.NewReply(community, message, replyMetadata)
    // handle error
    message2, err := fields.NewQualifiedContent(fields.ContentTypeUTF8, "reply to reply")
    // handle error
    reply2, err := builder.NewReply(reply, message2, replyMetadata)
    // handle error

The Builder type can also be used fluently like so:

    // omitting creating the qualified content and error handling
    community, err := forest.As(identity, privkey).NewCommunity(communityName, communityMetadata)
    reply, err := forest.As(identity, privkey).NewReply(community, message, replyMetadata)
    reply2, err := forest.As(identity, privkey).NewReply(reply, message2, replyMetadata)

*/
package forest