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

feat!: add support for VerifiableURI and deprecate JSONURL / AssetURL #365

Merged
merged 11 commits into from
Dec 14, 2023

Conversation

richtera
Copy link
Collaborator

@richtera richtera commented Dec 6, 2023

What kind of change does this PR introduce (bug fix, feature, docs update, ...)?

  • fix: Add VerifiableURI support and make it default on encode.
  • fix: Add testing for old JSONURL

What is the current behaviour (you can also link to an open issue here)?

The current software does not support the VerifiableURI encoding.

What is the new behaviour (if this is a feature change)?

Support VerifiableURI and JSONURL on read and always output VerifiableURL on encode.

Other information:

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (8a02062) 83.29% compared to head (32c3b52) 83.18%.

Files Patch % Lines
src/lib/encoder.ts 75.00% 0 Missing and 4 partials ⚠️
src/lib/utils.ts 50.00% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #365      +/-   ##
===========================================
- Coverage    83.29%   83.18%   -0.11%     
===========================================
  Files           19       19              
  Lines         1221     1231      +10     
  Branches       276      282       +6     
===========================================
+ Hits          1017     1024       +7     
  Misses         110      110              
- Partials        94       97       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@richtera richtera changed the base branch from develop to main December 6, 2023 10:19
Copy link
Collaborator

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

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

added review comments

src/lib/decodeData.test.ts Outdated Show resolved Hide resolved
src/lib/decodeData.test.ts Outdated Show resolved Hide resolved
src/lib/utils.test.ts Outdated Show resolved Hide resolved
src/lib/utils.test.ts Outdated Show resolved Hide resolved
src/lib/utils.test.ts Outdated Show resolved Hide resolved
src/lib/utils.test.ts Outdated Show resolved Hide resolved
src/lib/encoder.ts Outdated Show resolved Hide resolved
@Hugoo Hugoo changed the base branch from main to develop December 12, 2023 13:47
@richtera richtera closed this Dec 12, 2023
@richtera richtera reopened this Dec 12, 2023
@CJ42
Copy link
Collaborator

CJ42 commented Dec 12, 2023

Let's get @Hugoo review as well on this

Copy link
Contributor

@JeneaVranceanu JeneaVranceanu left a comment

Choose a reason for hiding this comment

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

LGTM except that I think the type should be rather named VerifiableURI and not VerifiableURL.

src/lib/encoder.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

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

I have pushed the latest commit with suggested changes from @JeneaVranceanu

604ec9b

The rest LGTM ✅

src/lib/decodeData.test.ts Show resolved Hide resolved
src/lib/decodeData.test.ts Outdated Show resolved Hide resolved
src/lib/decodeData.test.ts Show resolved Hide resolved
Comment on lines 109 to 121
if (verificationMethod !== undefined) {
const encodedLength = `0x${value.slice(14, 18)}`; // Rest of data string after function hash
const dataLength = hexToNumber(encodedLength, false) as number;
const dataHash = `0x${value.slice(18, 18 + dataLength * 2)}`; // Get jsonHash 32 bytes
const dataSource = hexToUtf8('0x' + value.slice(18 + dataLength * 2)); // Get remainder as URI
return {
verification: {
method: verificationMethod.name,
data: dataHash,
},
url: dataSource,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if there is no verification method?

Id rather do it the other way with early return

if (verificationMethod === undefined) {
return null or undefined or stmg;
}

// and the current code here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A null verification method should return the data but no verification method or data. So you're right we should not exit this way. Fixing.

src/lib/getDataFromExternalSources.ts Outdated Show resolved Hide resolved
src/lib/encoder.ts Outdated Show resolved Hide resolved
const dataSource = hexToUtf8('0x' + value.slice(18 + dataLength * 2)); // Get remainder as URI
return {
verification: {
method: verificationMethod.name,
Copy link
Contributor

@magalimorin18 magalimorin18 Dec 13, 2023

Choose a reason for hiding this comment

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

Suggested change
method: verificationMethod.name,
method: verificationMethod?.name || UNKNOWN_VERIFICATION_METHOD,

Copy link
Contributor

Choose a reason for hiding this comment

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

Can name not be defined on verificationMethod ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The verificationMethod could be undefined and therefore the url is not validated

Copy link
Contributor

Choose a reason for hiding this comment

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

I was more thinking of a situation where : it is defined but doesnt have a name property

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But we kind of want it to be undefined if not defined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default should be the signature hash so that reading a VerificationURI can return a yet unsupported custom verification method.

const dataSource = hexToUtf8('0x' + value.slice(18 + dataLength * 2)); // Get remainder as URI
return {
verification: {
method: verificationMethod.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

I was more thinking of a situation where : it is defined but doesnt have a name property

src/lib/encoder.ts Outdated Show resolved Hide resolved
@Hugoo Hugoo changed the title fix: Add support for verifiableURL. Read JSONURL, VerifiableURL, Write VerifiableURL. Tests. fix: Add support for VerifiableURI. Read JSONURL, VerifiableURI, Write VerifiableURI. Tests. Dec 14, 2023
src/lib/decodeData.test.ts Show resolved Hide resolved
@Hugoo Hugoo changed the title fix: Add support for VerifiableURI. Read JSONURL, VerifiableURI, Write VerifiableURI. Tests. feat!: add support for VerifiableURI and deprecate JSONURL / AssetURL Dec 14, 2023
@magalimorin18
Copy link
Contributor

fmi, will we keep the backward compatibility forever or is it temporary? If so we can already create a ticket that we keep in the backlog to remove the deprecated code

@Hugoo
Copy link
Contributor

Hugoo commented Dec 14, 2023

@magalimorin18 it will be for some time until devs can update their code but ultimately

shouldBackwardCompatibilityOfJSONURLAndAssetURLExistAt(time) when time -> infinity = false

Copy link
Collaborator Author

@richtera richtera left a comment

Choose a reason for hiding this comment

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

Creating github issue for unknown method.

stripHexPrefix(verification ? verification.data : padLeft(0, 64)) +
stripHexPrefix(utf8ToHex(dataSource))
);
return [
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This currently cannot return data containing an unsupported verification method. I think it needs to copy the verification function signature and data verbatim every time. I messed this up.


return {
verification: {
method: verificationMethod?.name || UNKNOWN_VERIFICATION_METHOD,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default should be verificationMethodSig and not UNKNOWN_VERIFICATION_METHOD.

src/index.ts Outdated Show resolved Hide resolved
@richtera richtera merged commit 9aa87e5 into develop Dec 14, 2023
2 checks passed
@richtera richtera deleted the fix/add-verifiable-url branch December 14, 2023 15:15
@Hugoo Hugoo mentioned this pull request Dec 20, 2023
1 task
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.

6 participants