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

Parity for ION Tools #318

Merged
merged 17 commits into from
Mar 27, 2023
Merged

Parity for ION Tools #318

merged 17 commits into from
Mar 27, 2023

Conversation

decentralgabe
Copy link
Member

@decentralgabe decentralgabe commented Mar 23, 2023

@decentralgabe decentralgabe marked this pull request as draft March 23, 2023 03:45
@codecov-commenter
Copy link

codecov-commenter commented Mar 23, 2023

Codecov Report

Merging #318 (3da705c) into main (721d0e4) will decrease coverage by 0.44%.
The diff coverage is 52.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #318      +/-   ##
==========================================
- Coverage   57.46%   57.02%   -0.44%     
==========================================
  Files          50       51       +1     
  Lines        5867     6110     +243     
==========================================
+ Hits         3371     3484     +113     
- Misses       1869     1970     +101     
- Partials      627      656      +29     
Impacted Files Coverage Δ
crypto/jwk.go 42.78% <0.00%> (-1.51%) ⬇️
did/ion/model.go 62.96% <20.00%> (-25.27%) ⬇️
did/ion/did.go 42.31% <43.75%> (-3.69%) ⬇️
did/resolver.go 60.98% <46.15%> (-6.88%) ⬇️
did/ion/operations.go 48.74% <48.74%> (ø)
did/web.go 70.34% <57.14%> (+2.54%) ⬆️
did/ion/request.go 62.15% <76.19%> (+1.09%) ⬆️

@decentralgabe decentralgabe marked this pull request as ready for review March 23, 2023 22:30
@decentralgabe decentralgabe changed the title Parity for ion tools in go ose 529 Parity for ION Tools Mar 23, 2023
@michaelneale
Copy link
Contributor

very nice

did/ion/did.go Outdated
}

// GetShortFormDIDFromLongFormDID returns the short form DID from a long form DID
func GetShortFormDIDFromLongFormDID(longFormDID string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func GetShortFormDIDFromLongFormDID(longFormDID string) (string, error) {
func LongToShortFormDID(longFormDID string) (string, error) {

did/ion/did.go Outdated
return strings.Join([]string{"did", did.IONMethod.String(), hash}, ":"), nil
}

// GetShortFormDIDFromLongFormDID returns the short form DID from a long form DID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test for this would be nice.

}

type Resolver struct {
baseURL string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would suggest typing this, as you're already parsing it.

Suggested change
baseURL string
baseURL url.URL

// and similarly for submitting anchor operations to the ION node...
//
// https://ion.tbd.network/operations
func NewIONResolver(baseURL string) (*Resolver, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important to force HTTPS for the URL.

if i.baseURL == "" {
return nil, errors.New("resolver URL is empty")
}
resp, err := http.Get(strings.Join([]string{i.baseURL, "identifiers", id}, "/"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expose a way for SDK users to provide their own http.Client and the context.Context they want to use for the request. The first allows for users to do their own telemetry and metric measurements. The second allows for termination signal and user configured deadlines.

See https://github.com/TBD54566975/ssi-service/blob/4936f10da0bae4b1606f5b2362c32bb6eb02e170/pkg/service/did/resolve/universal.go#L28 for how you could do both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea - done

if err != nil {
return errors.Wrapf(err, "marshaling anchor operation %+v", op)
}
resp, err := http.Post(strings.Join([]string{i.baseURL, "operations"}, "/"), "application/json", bytes.NewReader(jsonOpBytes))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as previously noted.


// Anchor submits an anchor operation to the ION node by appending the operations path to the base URL
// and making a POST request
func (i Resolver) Anchor(op AnchorOperation) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A top level package example on how to use this package would be awesome. Something super simple like: here's how you create an ION did:

NewIONDID()
Anchor()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

did/resolver.go Outdated
// ParseDIDResolution attempts to parse a DID Resolution Result or a DID Document
func ParseDIDResolution(resolvedDID []byte) (*DIDResolutionResult, error) {
// first try to parse as a DID Resolution Result
var result DIDResolutionResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

did/resolver.go Outdated
@@ -64,3 +65,23 @@ func GetMethodForDID(did string) (Method, error) {
}
return Method(split[1]), nil
}

// ParseDIDResolution attempts to parse a DID Resolution Result or a DID Document
func ParseDIDResolution(resolvedDID []byte) (*DIDResolutionResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a test for this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

did/web.go Outdated
didWeb := DIDWeb(did)
doc, err := didWeb.Resolve()
if err != nil {
return nil, errors.Wrapf(err, "could not resolve did:web DID: %s", did)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, errors.Wrapf(err, "could not resolve did:web DID: %s", did)
return nil, errors.Wrapf(err, "resolving did:web DID: %s", did)

@decentralgabe
Copy link
Member Author

thanks for the thorough review @andresuribe87 ; should have addressed all

This was referenced Mar 24, 2023
// TODO(gabe) enforce validation of DID syntax https://www.w3.org/TR/did-core/#did-syntax
type DIDDocument struct {
type Document struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break backwards compatibility on ssi-service. Was this change intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think it's a simpler name given the package is did I can do the uptake - that ok?

@decentralgabe decentralgabe added this to the BTC Miami milestone Mar 27, 2023
@decentralgabe decentralgabe merged commit a55dfe2 into main Mar 27, 2023
@decentralgabe decentralgabe deleted the parity-for-ion-tools-in-go-ose-529 branch March 27, 2023 19:09
@decentralgabe decentralgabe self-assigned this Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants