Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed Jan 4, 2024
1 parent 7e72e54 commit b56db30
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
19 changes: 19 additions & 0 deletions impl/internal/did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ed25519"
"encoding/base64"
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -74,6 +75,24 @@ type VerificationMethod struct {
Purposes []did.PublicKeyPurpose `json:"purposes"`
}

func GenerateVanityDIDDHT(prefix string, opts CreateDIDDHTOpts) (ed25519.PrivateKey, *did.Document, error) {
// generate the identity key
for i := 0; i < math.MaxInt32; i++ {
pubKey, privKey, err := crypto.GenerateEd25519Key()
if err != nil {
return nil, nil, err
}

id := GetDIDDHTIdentifier(pubKey)

if strings.HasPrefix(id, prefix) {
doc, err := CreateDIDDHTDID(pubKey, opts)
return privKey, doc, err
}
}
return nil, nil, fmt.Errorf("failed to generate vanity did:dht identifier with prefix %s", prefix)
}

// GenerateDIDDHT generates a did:dht identifier given a set of options
func GenerateDIDDHT(opts CreateDIDDHTOpts) (ed25519.PrivateKey, *did.Document, error) {
// generate the identity key
Expand Down
14 changes: 14 additions & 0 deletions impl/internal/did/did_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package did
import (
"crypto/ed25519"
"testing"
"time"

"github.com/goccy/go-json"

Expand Down Expand Up @@ -309,3 +310,16 @@ func TestVectors(t *testing.T) {
}
})
}

func TestVanityDID(t *testing.T) {
now := time.Now()
pk, doc, err := GenerateVanityDIDDHT("gabe", CreateDIDDHTOpts{})
require.NoError(t, err)
require.NotEmpty(t, pk)
require.NotEmpty(t, doc)

b, _ := json.Marshal(doc)
println(string(b))

println(time.Since(now).String())
}
34 changes: 34 additions & 0 deletions impl/pkg/service/gateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package service

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/TBD54566975/did-dht-method/config"
"github.com/TBD54566975/did-dht-method/pkg/storage"
)

func TestGatewayService(t *testing.T) {
svc := newGatewayService(t)
require.NotEmpty(t, svc)

t.Run("Publish and Get a DID", func(t *testing.T) {

})
}

func newGatewayService(t *testing.T) GatewayService {
defaultConfig := config.GetDefaultConfig()
db, err := storage.NewStorage(defaultConfig.ServerConfig.DBFile)
require.NoError(t, err)
require.NotEmpty(t, db)
pkarrService, err := NewPkarrService(&defaultConfig, db)
require.NoError(t, err)
require.NotEmpty(t, pkarrService)

gatewayService, err := NewGatewayService(&defaultConfig, db, pkarrService)
require.NoError(t, err)
require.NotEmpty(t, gatewayService)
return *gatewayService
}
6 changes: 3 additions & 3 deletions impl/pkg/service/pkarr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/TBD54566975/did-dht-method/pkg/storage"
)

func TestPKARRService(t *testing.T) {
svc := newPKARRService(t)
func TestPkarrService(t *testing.T) {
svc := newPkarrService(t)
require.NotEmpty(t, svc)

t.Run("test put bad record", func(t *testing.T) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestPKARRService(t *testing.T) {
})
}

func newPKARRService(t *testing.T) PkarrService {
func newPkarrService(t *testing.T) PkarrService {
defaultConfig := config.GetDefaultConfig()
db, err := storage.NewStorage(defaultConfig.ServerConfig.DBFile)
require.NoError(t, err)
Expand Down

0 comments on commit b56db30

Please sign in to comment.