Skip to content

Commit

Permalink
known test vector
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed Nov 7, 2023
1 parent dd72a53 commit 8879aa7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions impl/pkg/dht/dht_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dht

import (
"context"
"encoding/hex"
"testing"
"time"

Expand Down Expand Up @@ -42,3 +43,21 @@ func TestGetPutDHT(t *testing.T) {

assert.Equal(t, string(put.V.([]byte)), payload)
}

func TestKnownVector(t *testing.T) {
pubKey := "796f7457532cd39697f4fccd1a2d7074e6c1f6c59e6ecf5dc16c8ecd6e3fea6c"
privKey := "3077903f62fbcff4bdbae9b5129b01b78ab87f68b8b3e3d332f14ca13ad53464796f7457532cd39697f4fccd1a2d7074e6c1f6c59e6ecf5dc16c8ecd6e3fea6c"
pubKeyBytes, _ := hex.DecodeString(pubKey)
privKeyBytes, _ := hex.DecodeString(privKey)

put := &bep44.Put{
V: []byte("Hello World!"),
K: (*[32]byte)(pubKeyBytes),
Seq: 1,
}
put.Sign(privKeyBytes)

assert.Equal(t, "48656c6c6f20576f726c6421", hex.EncodeToString(put.V.([]byte)))
assert.Equal(t, "c1dc657a17f54ca51933b17b7370b87faae10c7edd560fd4baad543869e30e8154c510f4d0b0d94d1e683891b06a07cecd9f0be325fe8f8a0466fe38011b2d0a", hex.EncodeToString(put.Sig[:]))
assert.Equal(t, "796f7457532cd39697f4fccd1a2d7074e6c1f6c59e6ecf5dc16c8ecd6e3fea6c", hex.EncodeToString(put.K[:]))
}

0 comments on commit 8879aa7

Please sign in to comment.