Skip to content

Commit

Permalink
Fix cosig timestamp endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter committed Oct 3, 2024
1 parent adfa643 commit ae23fd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions note/note_cosigv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewSignerForCosignatureV1(skey string) (*Signer, error) {

// The signature itself is encoded as timestamp || signature.
sig := make([]byte, 0, timestampSize+ed25519.SignatureSize)
sig = binary.LittleEndian.AppendUint64(sig, t)
sig = binary.BigEndian.AppendUint64(sig, t)
sig = append(sig, ed25519.Sign(key, m)...)
return sig, nil
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func CoSigV1Timestamp(s note.Signature) (time.Time, error) {
}
r = r[keyHashSize:] // Skip the hash
// Next 8 bytes are the timestamp as Unix seconds-since-epoch:
return time.Unix(int64(binary.LittleEndian.Uint64(r)), 0), nil
return time.Unix(int64(binary.BigEndian.Uint64(r)), 0), nil
}

// verifyCosigV1 returns a verify function based on key.
Expand All @@ -133,7 +133,7 @@ func verifyCosigV1(key []byte) func(msg, sig []byte) bool {
if len(sig) != timestampSize+ed25519.SignatureSize {
return false
}
t := binary.LittleEndian.Uint64(sig)
t := binary.BigEndian.Uint64(sig)
sig = sig[timestampSize:]
m, err := formatCosignatureV1(t, msg)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions note/note_cosigv1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestCoSigV1Timestamp(t *testing.T) {
}{
{
name: "works",
sig: note.Signature{Base64: "W+8PSVYlTmUAAAAAOUcMpZzRiZaiZRr94NylbaFKHqXu5KQbk70RPuCZVi3PkU8GZJpCQYgyqjnmuSRCShglqdlUZGUplgn7ECavCA=="},
wantTime: time.Unix(1699620182, 0),
sig: note.Signature{Base64: "ZGhGuQAAAABm/qTPeyKXD+R2rzyQsxPiP8mXum7qq/iF0u4vanlqJyocWODBt97w9uL+8qT7S5gxEHWWOworDcFiEBYJXORmnFBOBA=="},
wantTime: time.Unix(1727964367, 0),
}, {
name: "wrong type of signature",
sig: note.Signature{Base64: "eQjRQm6eSKzFoiYalgwCPXu2y3ijtg68is9M46JKxuZB+dRfTmeQeDBoXnvxZx2ugnkyV+MUMLXpWs1hPb/W/4xkNQY="},
Expand Down

0 comments on commit ae23fd2

Please sign in to comment.