-
Notifications
You must be signed in to change notification settings - Fork 54
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
Parity for ION Tools #318
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2e089dc
simple resolver
decentralgabe 565d882
temp
decentralgabe ad9581c
Merge branch 'main' into parity-for-ion-tools-in-go-ose-529
decentralgabe 7ba200d
update
decentralgabe c48e555
merge
decentralgabe 8ed5723
add back
decentralgabe c10406d
rebase
decentralgabe 54ee3eb
bad refactors
decentralgabe 074e2eb
recover op
decentralgabe d3ef617
deactivate request
decentralgabe abe2f16
tests
decentralgabe 3bac364
tests
decentralgabe fbfa275
lint
decentralgabe 3da705c
Merge branch 'main' into parity-for-ion-tools-in-go-ose-529
decentralgabe 18cb40b
pr comments
decentralgabe 3ae1c91
add package doc
decentralgabe cde9f55
Merge branch 'main' into parity-for-ion-tools-in-go-ose-529
decentralgabe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,20 +25,14 @@ func CreateLongFormDID(recoveryKey, updateKey crypto.PublicKeyJWK, document Docu | |||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
||||||
shortFormDID, err := CreateShortFormDID(createRequest.SuffixData) | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
||||||
b, _ := json.Marshal(createRequest.SuffixData) | ||||||
println(string(b)) | ||||||
|
||||||
is := InitialState{ | ||||||
Delta: createRequest.Delta, | ||||||
SuffixData: createRequest.SuffixData, | ||||||
} | ||||||
|
||||||
initialStateBytesCanonical, err := CanonicalizeAny(is) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "canonicalizing long form DID suffix data") | ||||||
|
@@ -47,21 +41,6 @@ func CreateLongFormDID(recoveryKey, updateKey crypto.PublicKeyJWK, document Docu | |||||
return strings.Join([]string{shortFormDID, encoded}, ":"), nil | ||||||
} | ||||||
|
||||||
// CreateShortFormDID follows the process on did uri composition from the spec: | ||||||
// https://identity.foundation/sidetree/spec/#did-uri-composition, used to generate a short form DID URI, | ||||||
// which is most frequently used in the protocol and when sharing out ION DIDs. | ||||||
func CreateShortFormDID(suffixData any) (string, error) { | ||||||
createOpSuffixDataCanonical, err := CanonicalizeAny(suffixData) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "canonicalizing suffix data") | ||||||
} | ||||||
hash, err := HashEncode(createOpSuffixDataCanonical) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "generating multihash for DID URI") | ||||||
} | ||||||
return strings.Join([]string{"did", did.IONMethod.String(), hash}, ":"), nil | ||||||
} | ||||||
|
||||||
// DecodeLongFormDID decodes a long form DID into a short form DID and | ||||||
// its create operation suffix data | ||||||
func DecodeLongFormDID(longFormDID string) (string, *InitialState, error) { | ||||||
|
@@ -82,3 +61,27 @@ func DecodeLongFormDID(longFormDID string) (string, *InitialState, error) { | |||||
} | ||||||
return strings.Join(split[0:3], ":"), &initialState, nil | ||||||
} | ||||||
|
||||||
// CreateShortFormDID follows the process on did uri composition from the spec: | ||||||
// https://identity.foundation/sidetree/spec/#did-uri-composition, used to generate a short form DID URI, | ||||||
// which is most frequently used in the protocol and when sharing out ION DIDs. | ||||||
func CreateShortFormDID(suffixData any) (string, error) { | ||||||
createOpSuffixDataCanonical, err := CanonicalizeAny(suffixData) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "canonicalizing suffix data") | ||||||
} | ||||||
hash, err := HashEncode(createOpSuffixDataCanonical) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "generating multihash for DID URI") | ||||||
} | ||||||
return strings.Join([]string{"did", did.IONMethod.String(), hash}, ":"), nil | ||||||
} | ||||||
|
||||||
// GetShortFormDIDFromLongFormDID returns the short form DID from a long form DID | ||||||
func GetShortFormDIDFromLongFormDID(longFormDID string) (string, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
shortFormDID, _, err := DecodeLongFormDID(longFormDID) | ||||||
if err != nil { | ||||||
return "", errors.Wrap(err, "decoding long form DID") | ||||||
} | ||||||
return shortFormDID, nil | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.