← Verifying a Document
GO Go verifier
Uses gojsonschema, which fetches the schema URI over HTTP directly.
1
Install
go get github.com/xeipuuv/gojsonschema2
Verify
verify_dbom.go
package main
import (
"encoding/json"; "fmt"; "os"
"github.com/xeipuuv/gojsonschema"
)
func main() {
path := os.Args[1]
raw, _ := os.ReadFile(path)
var doc struct {
Source struct{ Hash struct{ Value string `json:"value"` } `json:"hash"` } `json:"source"`
Lineage []struct{ Step int; InputHash, OutputHash string `json:"input_hash,output_hash"` } `json:"lineage"`
}
json.Unmarshal(raw, &doc)
// structural
result, _ := gojsonschema.Validate(
gojsonschema.NewReferenceLoader("https://usemakoto.dev/schema/v0.1.json"),
gojsonschema.NewReferenceLoader("file://"+path),
)
for _, e := range result.Errors() { fmt.Printf("✗ [%s] %s\n", e.Field(), e.Description()) }
// provenance
s := doc.Lineage
for i := 1; i < len(s); i++ {
if s[i].InputHash != s[i-1].OutputHash {
fmt.Printf("✗ step %d input_hash does not match step %d output_hash\n", s[i].Step, s[i-1].Step)
}
}
if s[len(s)-1].OutputHash != doc.Source.Hash.Value {
fmt.Println("✗ final output_hash does not match source.hash.value")
}
}For production use with full error reporting, see the GitHub repo →