Files
ucan/did/crypto_test.go

52 lines
1022 B
Go
Raw Normal View History

2024-09-09 08:50:15 -04:00
package did_test
import (
"testing"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/require"
2024-09-17 11:17:24 -04:00
"github.com/ucan-wg/go-ucan/did"
2024-09-09 08:50:15 -04:00
)
const (
exampleDIDStr = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK"
examplePubKeyStr = "Lm/M42cB3HkUiODQsXRcweM6TByfzEHGO9ND274JcOY="
)
2024-09-09 08:50:15 -04:00
func TestFromPubKey(t *testing.T) {
t.Parallel()
id, err := did.FromPubKey(examplePubKey(t))
require.NoError(t, err)
require.Equal(t, exampleDID(t), id)
}
func TestToPubKey(t *testing.T) {
t.Parallel()
pubKey, err := did.ToPubKey(exampleDIDStr)
require.NoError(t, err)
require.Equal(t, examplePubKey(t), pubKey)
}
func exampleDID(t *testing.T) did.DID {
t.Helper()
2024-09-09 08:50:15 -04:00
id, err := did.Parse(exampleDIDStr)
2024-09-09 08:50:15 -04:00
require.NoError(t, err)
return id
}
func examplePubKey(t *testing.T) crypto.PubKey {
t.Helper()
2024-09-09 08:50:15 -04:00
pubKeyCfg, err := crypto.ConfigDecodeKey(examplePubKeyStr)
2024-09-09 08:50:15 -04:00
require.NoError(t, err)
pubKey, err := crypto.UnmarshalEd25519PublicKey(pubKeyCfg)
2024-09-09 08:50:15 -04:00
require.NoError(t, err)
return pubKey
2024-09-09 08:50:15 -04:00
}