Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Update ID rules in NewVerifiableCredentialBuilder #532

Merged
merged 9 commits into from
Jun 20, 2024

Conversation

m-rit
Copy link
Contributor

@m-rit m-rit commented Jun 5, 2024

Address Issue #400 .
Changes default id in NewVerifiableCredentialBuilder as empty, validates if id is a parsable uri in SetID

func NewVerifiableCredentialBuilder() VerifiableCredentialBuilder {
contexts := []string{VerifiableCredentialsLinkedDataContext}
types := []string{VerifiableCredentialType}
return VerifiableCredentialBuilder{
contexts: contexts,
types: types,
VerifiableCredential: &VerifiableCredential{
ID: uuid.NewString(),
ID: "",
Copy link
Member

Choose a reason for hiding this comment

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

🤔 given that this is a required property I'm not sure it's a good idea to leave this empty

perhaps it should be added as an optional property to the builder, and if that is empty we generate it automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's better to keep an option argument. I'll make the changes, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @decentralgabe, I have added an optional argument to keep ID empty. Kindly review.

@@ -33,19 +33,25 @@ type VerifiableCredentialBuilder struct {

// NewVerifiableCredentialBuilder returns an initialized credential builder with some default fields populated
// Default id is empty
func NewVerifiableCredentialBuilder() VerifiableCredentialBuilder {
func NewVerifiableCredentialBuilder(emptyID ...bool) VerifiableCredentialBuilder {
Copy link
Member

@decentralgabe decentralgabe Jun 6, 2024

Choose a reason for hiding this comment

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

what do you think about making this a bit more readabale?

we could change the build to accept a new type like IDvalue for example

type IDValue string

const EmptyIDValue IDValue = ""

func NewVerifiableCredentialBuilder(id IDValue) VerifiableCredentialBuilder {
    if id == EmptyIDValue {
        // generate ID
    }
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @decentralgabe, thanks for your inputs.
Please confirm if the behaviour is as follows:

NewVerifiableCredentialBuilder (EmptyIDValue)  -> creates vc with id as uuid
NewVerifiableCredentialBuilder  ("xxx") -> generates vc with id as "xxx"
vcb.SetID("") ->  sets ID as empty

Copy link
Member

Choose a reason for hiding this comment

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

ah, good consideration.

Perhaps we should add....

EmptyIDValue -> set ID value to empty
GenerateIDValue -> generate a uuid
CustomIDValue("<your-id-here>") -> use custom ID

to be unambiguous?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @decentralgabe , I have added IDValue argument here to all three cases (empty ID/ generate ID/ custom ID)

@decentralgabe decentralgabe enabled auto-merge (squash) June 10, 2024 16:21
@decentralgabe
Copy link
Member

thanks @m-rit I approved - you may have to take a look at the build issues

auto-merge was automatically disabled June 20, 2024 09:41

Head branch was pushed to by a user without write access

@m-rit
Copy link
Contributor Author

m-rit commented Jun 20, 2024

Hi @decentralgabe, I have fixed all the build issues (the function signature for NewVerifiableCredentialBuilder had to be updated in all files). I think additional approval is needed for the workflows.

@decentralgabe decentralgabe enabled auto-merge (squash) June 20, 2024 21:54
@decentralgabe
Copy link
Member

thanks @m-rit approved and merging

@decentralgabe decentralgabe disabled auto-merge June 20, 2024 22:12
@decentralgabe decentralgabe merged commit f54f15a into TBD54566975:main Jun 20, 2024
5 of 6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants