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

module for convert onchain verifiable credential on w3c verifiable cr… #83

Closed
wants to merge 6 commits into from

Conversation

ilya-korotya
Copy link
Contributor

@ilya-korotya ilya-korotya commented Jan 2, 2024

No description provided.

.golangci.yml Outdated Show resolved Hide resolved

const (
BooleanHashTrue = "18586133768512220936620570745912940619677854269274689475585506675881198879027"
BooleanHashFalse = "19014214495641488759237505126948346942972912379615652741039992445865937985820"
Copy link
Contributor

Choose a reason for hiding this comment

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

You made those vars public deliberately? You are going to use it outside of this package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

regenerateID bool
}

type Option func(*Parser)
Copy link
Contributor

Choose a reason for hiding this comment

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

In this package (onchain), there are many 'main' types, such as onchain.MTP and onchain.Proof. The type Option does not indicate which type it is related to. I would suggest naming it something like ParserOption, in case we need to add other options in future versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed to ConvertorOption

}

// WithMerklizer sets the merklizer instance.
func WithMerklizer(m merklize.Options) Option {
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on this name, I would expect that the function accepts a *merklizer.Merklizer type instead of merklizer.Options. What do you think about renaming it to WithMerklizerOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

nonce, err := strconv.ParseUint(credentialStatus.RevocationNonce, 10, 64)
if err != nil {
return nil,
fmt.Errorf("invalid revocationNonce '%s': %v", credentialStatus.RevocationNonce, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use %w verb for err. In this way we can unwrap original error if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Now I use %w in all places.

}

// ConvertVerifiableCredential converts an onchain verifiable credential to a W3C verifiable credential.
func (p *Parser) ConvertVerifiableCredential(onchainCredential *Credential) (*verifiable.W3CCredential, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the sole public function in Parser type named ConvertVerifiableCredential why the struct not named Converter? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to Converter

IssuerData: verifiable.IssuerData{
ID: issuerDID.String(),
State: verifiable.State{
RootOfRoots: strPtr(rootOfRoots.Hex()),
Copy link
Contributor

Choose a reason for hiding this comment

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

hack to get a pointer to the string )
&[]string{rootOfRoots.Hex()}[0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the advice. But I do want not to create an array to get a pointer to a string
I prefer old school :)

if err != nil {
return fmt.Errorf("failed hash value '%s' with data type '%s': %v", source, datatype, err)
}
origineHash, ok := big.NewInt(0).SetString(origin, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

origineHash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return nil
}

type smtproof struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

for me, this struct looks useless. convertChainProofToMerkleProof can accept MTP directly. But may be I missed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,61 @@
package onchain

type CredentialSubjectField struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

give comments public to structures , not sure why linter didn't fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

RevocationNonce string `json:"revocationNonce"`
}

type Credential struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

is at a god idea to have such a structure public? Why we can't create some internal model and the W3C credential is the only credential that is public structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can do it. But in this case function ConvertVerifiableCredential should accept []bytes instead of typed struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion is okay to have offchain(w3c).VerifiableCredentials and onchain.Verifiable Credential. Since they are different a little bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm against this. Pretty sure it will confuse users of the library and ideologically I do not want to have a term onchain verifiable credential
@olomix @demonsh

verifiable/onchain/parser.go Outdated Show resolved Hide resolved
"github.com/piprate/json-gold/ld"
)

type Parser struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid term Parser due to the collision with JSON / JSONLD parsers. better use DataConvertor. This convertor serves only single purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I renamed to converter

verifiable/onchain/parser.go Outdated Show resolved Hide resolved
verifiable/onchain/parser.go Outdated Show resolved Hide resolved
verifiable/onchain/parser.go Outdated Show resolved Hide resolved
verifiable/onchain/parser.go Outdated Show resolved Hide resolved
verifiable/onchain/parser.go Outdated Show resolved Hide resolved
olomix
olomix previously approved these changes Jan 8, 2024
reservedCredentialSubjectKeyType string = "type"

// nolint:gosec // This is type of the credential, not a secret
verifiableCredentialType = "VerifiableCredential"
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have constant TypeW3CVerifiableCredential

"github.com/piprate/json-gold/ld"
)

type Convertor struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

comments

Copy link
Contributor

Choose a reason for hiding this comment

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

file is named converter, structure is named convertor

// ConvertVerifiableCredential converts an onchain verifiable credential to a W3C verifiable credential.
// The w3c credential id will be regenerated.
func ConvertVerifiableCredential(credential *Credential) (*verifiable.W3CCredential, error) {
id := fmt.Sprintf("urn:uuid:%s", uuid.NewString())
Copy link
Contributor

Choose a reason for hiding this comment

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

why id of credential is not comming from the contract itself. It is not supposed to be different each time.

Copy link
Member

Choose a reason for hiding this comment

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

yes, we should have unique, but still deterministic id. E.g. based on DID of issuer (or chainId+contractAddr) + credential id from contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vmidyllic since we are using int as ID in on-chain issuer. Credentials with id: 1 will not be merklized. We should have valid uri.

Copy link
Contributor

Choose a reason for hiding this comment

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

id must have string format, valid urn, it should come as it from contract. urn:uiid:1

olomix
olomix previously approved these changes Jan 12, 2024
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