-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Author and Signature fields from Record
- Loading branch information
Showing
5 changed files
with
39 additions
and
261 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,14 @@ | ||
package record | ||
|
||
import ( | ||
"bytes" | ||
|
||
proto "github.com/gogo/protobuf/proto" | ||
u "github.com/ipfs/go-ipfs-util" | ||
ci "github.com/libp2p/go-libp2p-crypto" | ||
pb "github.com/libp2p/go-libp2p-record/pb" | ||
) | ||
|
||
// MakePutRecord creates and signs a dht record for the given key/value pair | ||
func MakePutRecord(sk ci.PrivKey, key string, value []byte, sign bool) (*pb.Record, error) { | ||
// MakePutRecord creates a dht record for the given key/value pair | ||
func MakePutRecord(key string, value []byte) *pb.Record { | ||
record := new(pb.Record) | ||
|
||
record.Key = proto.String(string(key)) | ||
record.Value = value | ||
|
||
pkb, err := sk.GetPublic().Bytes() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pkh := u.Hash(pkb) | ||
|
||
record.Author = proto.String(string(pkh)) | ||
if sign { | ||
blob := RecordBlobForSig(record) | ||
|
||
sig, err := sk.Sign(blob) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
record.Signature = sig | ||
} | ||
return record, nil | ||
} | ||
|
||
// RecordBlobForSig returns the blob protected by the record signature | ||
func RecordBlobForSig(r *pb.Record) []byte { | ||
k := []byte(r.GetKey()) | ||
v := []byte(r.GetValue()) | ||
a := []byte(r.GetAuthor()) | ||
return bytes.Join([][]byte{k, v, a}, []byte{}) | ||
return record | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.