Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new vector; update code for vectors besides gateways #161

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion impl/concurrencytest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func generateDIDPutRequest() (string, []byte, error) {
return "", nil, err
}

packet, err := did.DHT(doc.ID).ToDNSPacket(*doc, nil)
packet, err := did.DHT(doc.ID).ToDNSPacket(*doc, nil, nil)
if err != nil {
return "", nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion impl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/BurntSushi/toml v1.3.2
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240321215515-97ccd06a631d
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240402005820-2c6b20991baa
github.com/allegro/bigcache/v3 v3.1.0
github.com/anacrolix/dht/v2 v2.21.1
github.com/anacrolix/log v0.15.2
Expand Down
8 changes: 6 additions & 2 deletions impl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ github.com/RoaringBitmap/roaring v0.4.17/go.mod h1:D3qVegWTmfCaX4Bl5CrBE9hfrSrrX
github.com/RoaringBitmap/roaring v0.4.23/go.mod h1:D0gp8kJQgE1A4LQ5wFLggQEyvDi06Mq5mKs52e1TwOo=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240321215515-97ccd06a631d h1:lEekCCpwjxtQBNNUoUmPiDg35t3quQzDgtetug5xbx4=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240321215515-97ccd06a631d/go.mod h1:UoNlAhXuPb1VxsAkNbLyr4XYeyHhLvcwSbkmsaOeGjM=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240401231222-6550aeed8a9d h1:M/dYJOKyLNBDh97VYAyLvzO7sS01K1eIBwNcAK2SFDQ=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240401231222-6550aeed8a9d/go.mod h1:nyTjplXnrari2nQg63ztI4C0rgMb7Jjn3gfn0OM656g=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240402005210-f282aecaa186 h1:XIaS0WBSrg2wU00Cx45NO9H3x3ca7WEI35sSef6NC5c=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240402005210-f282aecaa186/go.mod h1:nyTjplXnrari2nQg63ztI4C0rgMb7Jjn3gfn0OM656g=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240402005820-2c6b20991baa h1:1kJozfMxe8fRI0jjKUbKhj7/o16d1oTDOfZJLOMTU28=
github.com/TBD54566975/ssi-sdk v0.0.4-alpha.0.20240402005820-2c6b20991baa/go.mod h1:nyTjplXnrari2nQg63ztI4C0rgMb7Jjn3gfn0OM656g=
github.com/alecthomas/assert/v2 v2.0.0-alpha3 h1:pcHeMvQ3OMstAWgaeaXIAL8uzB9xMm2zlxt+/4ml8lk=
github.com/alecthomas/assert/v2 v2.0.0-alpha3/go.mod h1:+zD0lmDXTeQj7TgDgCt0ePWxb0hMC1G+PGTsTCv1B9o=
github.com/alecthomas/atomic v0.1.0-alpha2 h1:dqwXmax66gXvHhsOS4pGPZKqYOlTkapELkLb3MNdlH8=
Expand Down
5 changes: 3 additions & 2 deletions impl/integrationtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"os/signal"
"time"

"github.com/sirupsen/logrus"

"github.com/TBD54566975/did-dht-method/internal/did"
"github.com/TBD54566975/did-dht-method/pkg/dht"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -97,7 +98,7 @@ func generateDIDPutRequest() (string, []byte, error) {
return "", nil, err
}

packet, err := did.DHT(doc.ID).ToDNSPacket(*doc, nil)
packet, err := did.DHT(doc.ID).ToDNSPacket(*doc, nil, nil)
if err != nil {
return "", nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions impl/internal/did/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ func NewGatewayClient(gatewayURL string) (*GatewayClient, error) {
}, nil
}

// GetDIDDocument gets a DID document and its types from a did:dht Gateway
func (c *GatewayClient) GetDIDDocument(id string) (*did.Document, []TypeIndex, error) {
// GetDIDDocument gets a DID document, its types, and authoritative gateways, from a did:dht Gateway
func (c *GatewayClient) GetDIDDocument(id string) (*did.Document, []TypeIndex, []AuthoritativeGateway, error) {
d := DHT(id)
if !d.IsValid() {
return nil, nil, errors.New("invalid did")
return nil, nil, nil, errors.New("invalid did")
}
suffix, err := d.Suffix()
if err != nil {
return nil, nil, errors.Wrap(err, "failed to get suffix")
return nil, nil, nil, errors.Wrap(err, "failed to get suffix")
}
resp, err := http.Get(c.gatewayURL + "/" + suffix)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to get did document")
return nil, nil, nil, errors.Wrap(err, "failed to get did document")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, nil, errors.Errorf("failed to get did document, status code: %d", resp.StatusCode)
return nil, nil, nil, errors.Errorf("failed to get did document, status code: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to read response body")
return nil, nil, nil, errors.Wrap(err, "failed to read response body")
}
msg := new(dns.Msg)
if err = msg.Unpack(body[72:]); err != nil {
return nil, nil, errors.Wrap(err, "failed to unpack records")
return nil, nil, nil, errors.Wrap(err, "failed to unpack records")
}
return d.FromDNSPacket(msg)
}
Expand Down
36 changes: 20 additions & 16 deletions impl/internal/did/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestClient(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, doc)

packet, err := DHT(doc.ID).ToDNSPacket(*doc, nil)
packet, err := DHT(doc.ID).ToDNSPacket(*doc, nil, nil)
assert.NoError(t, err)
assert.NotEmpty(t, packet)

Expand All @@ -34,7 +34,7 @@ func TestClient(t *testing.T) {
err = client.PutDocument(doc.ID, *bep44Put)
assert.NoError(t, err)

gotDID, _, err := client.GetDIDDocument(doc.ID)
gotDID, _, _, err := client.GetDIDDocument(doc.ID)
assert.NoError(t, err)
assert.EqualValues(t, doc, gotDID)

Expand All @@ -51,31 +51,35 @@ func TestClientInvalidGateway(t *testing.T) {
func TestInvalidDIDDocument(t *testing.T) {
client, err := NewGatewayClient("https://diddht.tbddev.test")
require.NoError(t, err)
require.NotNil(t, client)
require.NotEmpty(t, client)

did, ty, err := client.GetDIDDocument("this is not a valid did")
did, types, gateways, err := client.GetDIDDocument("this is not a valid did")
assert.Error(t, err)
assert.Nil(t, ty)
assert.Nil(t, did)
assert.Empty(t, did)
assert.Empty(t, types)
assert.Empty(t, gateways)

did, ty, err = client.GetDIDDocument("did:dht:example")
did, types, gateways, err = client.GetDIDDocument("did:dht:example")
assert.EqualError(t, err, "invalid did")
assert.Nil(t, ty)
assert.Nil(t, did)
assert.Empty(t, did)
assert.Empty(t, types)
assert.Empty(t, gateways)

did, ty, err = client.GetDIDDocument("did:dht:i9xkp8ddcbcg8jwq54ox699wuzxyifsqx4jru45zodqu453ksz6y")
did, types, gateways, err = client.GetDIDDocument("did:dht:i9xkp8ddcbcg8jwq54ox699wuzxyifsqx4jru45zodqu453ksz6y")
assert.Error(t, err) // this should error because the gateway URL is invalid
assert.Nil(t, ty)
assert.Nil(t, did)
assert.Empty(t, did)
assert.Empty(t, types)
assert.Empty(t, gateways)

client, err = NewGatewayClient("https://tbd.website")
require.NoError(t, err)
require.NotNil(t, client)
require.NotEmpty(t, client)

did, ty, err = client.GetDIDDocument("did:dht:i9xkp8ddcbcg8jwq54ox699wuzxyifsqx4jru45zodqu453ksz6y")
did, types, gateways, err = client.GetDIDDocument("did:dht:i9xkp8ddcbcg8jwq54ox699wuzxyifsqx4jru45zodqu453ksz6y")
assert.Error(t, err) // this should error because the gateway URL will return a non-200
assert.Nil(t, ty)
assert.Nil(t, did)
assert.Empty(t, did)
assert.Empty(t, types)
assert.Empty(t, gateways)

err = client.PutDocument("did:dht:example", bep44.Put{})
assert.Error(t, err)
Expand Down
Loading
Loading