2026-03-06 13:20:12 +00:00
|
|
|
package manifest
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crypto/ed25519"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
2026-03-21 23:54:23 +00:00
|
|
|
coreerr "dappco.re/go/core/log"
|
|
|
|
|
"dappco.re/go/core/io"
|
2026-03-06 13:20:12 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-09 14:42:32 +00:00
|
|
|
const manifestPath = ".core/manifest.yaml"
|
2026-03-06 13:20:12 +00:00
|
|
|
|
|
|
|
|
// MarshalYAML serializes a manifest to YAML bytes.
|
|
|
|
|
func MarshalYAML(m *Manifest) ([]byte, error) {
|
|
|
|
|
return yaml.Marshal(m)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-09 14:42:32 +00:00
|
|
|
// Load reads and parses a .core/manifest.yaml from the given root directory.
|
2026-03-06 13:20:12 +00:00
|
|
|
func Load(medium io.Medium, root string) (*Manifest, error) {
|
|
|
|
|
path := filepath.Join(root, manifestPath)
|
|
|
|
|
data, err := medium.Read(path)
|
|
|
|
|
if err != nil {
|
2026-03-16 20:37:25 +00:00
|
|
|
return nil, coreerr.E("manifest.Load", "read failed", err)
|
2026-03-06 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
return Parse([]byte(data))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoadVerified reads, parses, and verifies the ed25519 signature.
|
|
|
|
|
func LoadVerified(medium io.Medium, root string, pub ed25519.PublicKey) (*Manifest, error) {
|
|
|
|
|
m, err := Load(medium, root)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
ok, err := Verify(m, pub)
|
|
|
|
|
if err != nil {
|
2026-03-16 20:37:25 +00:00
|
|
|
return nil, coreerr.E("manifest.LoadVerified", "verification error", err)
|
2026-03-06 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
if !ok {
|
2026-03-16 20:37:25 +00:00
|
|
|
return nil, coreerr.E("manifest.LoadVerified", "signature verification failed for "+m.Code, nil)
|
2026-03-06 13:20:12 +00:00
|
|
|
}
|
|
|
|
|
return m, nil
|
|
|
|
|
}
|