gunk-dev/the-valley

signerprojects.go

sourcebabe14e6c71cmain's published tip history
1.4 KiB
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "the-valley/note"
8)
9
10// readSignerProjects reads the signer projects file at path
11// (note/signerprojects.go), and returns what it says and the bytes it read.
12// An empty path is no file, and restricts nobody. A file that cannot be read, or does not read as a signer
13// projects file, is an error, so a controller given a broken file judges
14// nothing rather than judging without it.
15//
16// The file may not name signer, the name the integrator signs under. A
17// signer the file names signs check evidence and is restricted to
18// projects; the integrator signs transfer statements, which clients
19// believe in every project it serves. A worker or attester restricted
20// under the integrator's own name would be both.
21func readSignerProjects(path, signer string) (note.SignerProjects, []byte, error) {
22 if path == "" {
23 return nil, nil, nil
24 }
25 data, err := os.ReadFile(path)
26 if err != nil {
27 return nil, nil, fmt.Errorf("reading the signer projects file: %w", err)
28 }
29 s, err := note.ParseSignerProjects(data)
30 if err != nil {
31 return nil, nil, fmt.Errorf("the signer projects file %s does not read: %w", path, err)
32 }
33 if s.Restricts(signer) {
34 return nil, nil, fmt.Errorf("the signer projects file %s names %s, the name the integrator signs under; a worker or attester restricted to projects signs under a name of its own", path, signer)
35 }
36 return s, data, nil
37}