-
Notifications
You must be signed in to change notification settings - Fork 17
/
validator.go
58 lines (44 loc) · 1.34 KB
/
validator.go
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
50
51
52
53
54
55
56
57
58
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package docvalidator
import (
"errors"
"github.com/trustbloc/sidetree-core-go/pkg/document"
)
const didSuffix = "didSuffix"
// Validator is responsible for validating document operations and Sidetree rules.
type Validator struct {
}
// New creates a new document validator.
func New() *Validator {
return &Validator{}
}
// IsValidPayload verifies that the given payload is a valid Sidetree specific payload
// that can be accepted by the Sidetree update operations.
func (v *Validator) IsValidPayload(payload []byte) error {
doc, err := document.FromBytes(payload)
if err != nil {
return err
}
uniqueSuffix := doc.GetStringValue(didSuffix)
if uniqueSuffix == "" {
return errors.New("missing unique suffix")
}
// checking for previous operation existence has been pushed to handler
return nil
}
// IsValidOriginalDocument verifies that the given payload is a valid Sidetree specific document that can be accepted by
// the Sidetree create operation.
func (v *Validator) IsValidOriginalDocument(payload []byte) error {
doc, err := document.FromBytes(payload)
if err != nil {
return err
}
// The document must NOT have the id property
if doc.ID() != "" {
return errors.New("document must NOT have the id property")
}
return nil
}