SignedRequest.go
package model
import (
"errors"
"github.com/Saseul/util"
)
type SignedRequest struct {
SignedData
}
func NewSignedRequest(item map[string]interface{}) *SignedRequest {
sr := &SignedRequest{
SignedData: SignedData{
Data: item["request"].(map[string]interface{}),
PublicKey: item["public_key"].(string),
Signature: item["signature"].(string),
Cid: item["request"].(map[string]interface{})["cid"].(string),
Type: item["request"].(map[string]interface{})["type"].(string),
Timestamp: int64(item["request"].(map[string]interface{})["timestamp"].(float64)),
Attributes: make(map[string]interface{}),
CachedUniversal: make(map[string]interface{}),
CachedLocal: make(map[string]interface{}),
},
}
sr.Hash = sr.Hash()
return sr
}
func (sr *SignedRequest) Validity() (bool, error) {
if sr.Data == nil {
return false, errors.New("The request must contain the 'request' parameter.")
}
if sr.Type == "" {
return false, errors.New("The request must contain the 'request.type' parameter.")
}
if _, ok := sr.Data["type"].(string); !ok {
return false, errors.New("Parameter 'request.type' must be of string type.")
}
return true, nil
}
func (sr *SignedRequest) Obj() map[string]interface{} {
return map[string]interface{}{
"request": sr.Data,
"public_key": sr.PublicKey,
"signature": sr.Signature,
}
}SignedRequest ꡬ쑰체
SignedRequest ꡬ쑰체NewSignedRequest ν¨μ
NewSignedRequest ν¨μValidity ν¨μ
Validity ν¨μObj ν¨μ
Obj ν¨μμ 체 μ½λ μμ
Last updated