github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/api/lc_sign.go (about) 1 package api 2 3 import ( 4 "fmt" 5 6 "github.com/vchain-us/vcn/pkg/meta" 7 ) 8 9 // Sign is invoked by the User to notarize an artifact using the given functional options, 10 // By default, the artifact is notarized using status = meta.StatusTrusted, visibility meta.VisibilityPrivate. 11 func (u LcUser) Sign(artifact Artifact, options ...LcSignOption) (bool, uint64, error) { 12 if artifact.Hash == "" { 13 return false, 0, makeError("hash is missing", nil) 14 } 15 if artifact.Size < 0 { 16 return false, 0, makeError("invalid size", nil) 17 } 18 19 o, err := makeLcSignOpts(options...) 20 if err != nil { 21 return false, 0, err 22 } 23 24 return u.createArtifact(artifact, o.status, o.attach, o.bom) 25 } 26 27 // SignMulti ... 28 func (u LcUser) SignMulti(artifacts []*Artifact, options [][]LcSignOption) ([]bool, []uint64, []error, error) { 29 if len(artifacts) != len(options) { 30 return nil, nil, nil, makeError("the number of options must be the same as the number artifacts", nil) 31 } 32 33 statuses := make([]meta.Status, len(artifacts)) 34 attachments := make([][]string, len(artifacts)) 35 bomTexts := make([]string, len(artifacts)) 36 for i, artifact := range artifacts { 37 if artifact.Hash == "" { 38 return nil, nil, nil, makeError(fmt.Sprintf("hash is missing for artifact %s", artifact.Name), nil) 39 } 40 if artifact.Size < 0 { 41 return nil, nil, nil, makeError(fmt.Sprintf("invalid size for artifact %s", artifact.Name), nil) 42 } 43 44 o, err := makeLcSignOpts(options[i]...) 45 if err != nil { 46 return nil, nil, nil, err 47 } 48 statuses[i] = o.status 49 attachments[i] = o.attach 50 bomTexts[i] = o.bom 51 } 52 53 return u.createArtifacts(artifacts, statuses, attachments, bomTexts) 54 }