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

Go Mobile support for DID Key #457

Merged
merged 11 commits into from
Aug 31, 2023
Merged

Go Mobile support for DID Key #457

merged 11 commits into from
Aug 31, 2023

Conversation

decentralgabe
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2023

Codecov Report

Merging #457 (fd002fd) into main (1b69542) will decrease coverage by 0.19%.
The diff coverage is 50.98%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #457      +/-   ##
==========================================
- Coverage   57.42%   57.23%   -0.19%     
==========================================
  Files          67       67              
  Lines        7499     7494       -5     
==========================================
- Hits         4306     4289      -17     
- Misses       2456     2468      +12     
  Partials      737      737              
Files Changed Coverage Δ
did/util.go 31.63% <0.00%> (-0.15%) ⬇️
crypto/keys.go 74.83% <42.11%> (-4.65%) ⬇️
crypto/jwx/jwt.go 54.63% <88.89%> (+1.84%) ⬆️
crypto/jwx/jwk.go 56.24% <100.00%> (ø)
did/key/key.go 70.52% <100.00%> (ø)

@decentralgabe
Copy link
Member Author

CodeQL will be broken until the authors update it to support go1.21, should not block merge

crypto/keys.go Outdated
Comment on lines 69 to 70
ECDSAMarshalCompressed = Option{Name: "ecdsa-compressed", Value: true}
ECDSAUnmarshalCompressed = Option{Name: "ecdsa-compressed", Value: true}
Copy link
Contributor

Choose a reason for hiding this comment

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

The value of both options is the same. Is that 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.

yes, one used for marshaling one for unmarshaling

I could condense to a ECDSACompressed option

Copy link
Contributor

Choose a reason for hiding this comment

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

I generally discourage using an Option type which has a field named Name. It's bypasses the type system, and makes it easy to shoot yourself in the foot.

I would suggest using an enum es below:

const (
  ECDSAMarshalCompressed int = iota
  ECDSAUnmarshalCompressed
)

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The methods in here aren't tested. I think we should have some sample code that exercises it. It can act as documentation as well on how it should be called.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree will add tests


// IOS Generates the iOS packages
// Note: this command also installs "gomobile" if not present
func IOS() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this target, as well as the Android target, be documented in a README?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes good call

@decentralgabe
Copy link
Member Author

tests added, comments made, bugs fixed. should be good to go

Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

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

Non-blocking comments.


## Android

```
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 cover:

  • Documentation on how to include this in an android/ios project, with a simple example.
  • CI that exercises actual Android/ios code so we can be confident this works.
  • Guidance to readers that tells them how to discover available functionality within the SDK.

Of course, that's a lot of scope for this PR, so tracking in separate issues is cool. But I think this is critically important.

Copy link
Member Author

Choose a reason for hiding this comment

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

will do a mix of now and new issues

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 20 to 23
type GenerateDIDKeyResult struct {
DID string `json:"did"`
JWK map[string]any `json:"jwk"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

godocs for all fields here. This should be treated this as a public API

}

// GenerateDIDKey generates a new DID key and returns a JSON representation of GenerateDIDKeyResult
func GenerateDIDKey(kt string) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you include the possible kt values in the godoc?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add that the values are the result of the GetSupportedDIDKeyTypes

Comment on lines 64 to 67
type CreateDIDKeyRequest struct {
KeyType string `json:"keyType"`
PublicKeyJWK map[string]any `json:"publicKeyJwk"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

godocs for all types here.

Comment on lines 69 to 71
type CreateDIDKeyResult struct {
DID string `json:"did"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

godocs, hopefully with an example. Something like

// DID that was created. E.g. `did:key:zHjkdjd...`

}

type Document struct {
DIDDocument map[string]any `json:"didDocument"`
Copy link
Contributor

Choose a reason for hiding this comment

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

You know what I want :)


// CreateDIDKey creates a new DID key from an existing public key, accepting a JSON representation of CreateDIDKeyRequest
// and returns a JSON representation of CreateDIDKeyResult which contains the DID of the newly created key as a string
func CreateDIDKey(requestBytes []byte) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it easy for clients to understand what they should put into requestBytes: can we type this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mention CreateDIDKeyRequest here - is there a way I can make it clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's tough to say, because I don't know how a mobile dev would interact with this. I'm of the opinion that a worthy goal is to have mobile devs not have to read any go code at all.

So I ask myself, as a mobile dev, do I know what I should put in here? I think the current answer is probably not. I would make a suggestion if I understood better how calling from Java/Kotlin, Swift would look like.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think go docs are the best we can realistically do...if they don't read the API docs they'll always be lost

Copy link
Contributor

Choose a reason for hiding this comment

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

How about having the type of the parameter this function accepts be CreateDIDKeyRequest? According to the documentation, structs are allowed.

It feels like it's a bit easier to deal with a typed object in Kotlin / Swift.

I was hoping that documentation gets automatically translated into the artifact that's created (the AAR or the Obj-C lib), but it unfortunately doesn't look like that's the case. That's unfortunate :(
To mitigate, I would say adding an example in the target language that demonstrates how to call this function would be great.

Copy link
Member Author

Choose a reason for hiding this comment

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

will take this in a follow up - but after seeing what the feedback is from mobile devs

@decentralgabe decentralgabe merged commit 7522c30 into main Aug 31, 2023
4 of 5 checks passed
@decentralgabe decentralgabe deleted the mobile branch August 31, 2023 20:18
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.

None yet

3 participants