Skip to content

Commit

Permalink
updates from review
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Aug 28, 2024
1 parent 1ffe271 commit c67a75a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
configs/driver.yaml
.env*
resolvers.settings.yaml
test.http
30 changes: 0 additions & 30 deletions pkg/document/proof.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package document

import (
"encoding/json"
"errors"
"time"

"github.com/ethereum/go-ethereum/signer/core/apitypes"
Expand Down Expand Up @@ -31,31 +29,3 @@ const EthereumEip712SignatureProof2021Type verifiable.ProofType = "EthereumEip71
func (p *EthereumEip712SignatureProof2021) ProofType() verifiable.ProofType {
return p.Type
}

func (p *EthereumEip712SignatureProof2021) UnmarshalJSON(in []byte) error {
var obj struct {
Type verifiable.ProofType `json:"type"`
ProofPursopose string `json:"proofPurpose"`
ProofValue string `json:"proofValue"`
VerificationMethod string `json:"verificationMethod"`
Created time.Time `json:"created"`
Eip712 json.RawMessage `json:"eip712"`
}
err := json.Unmarshal(in, &obj)
if err != nil {
return err
}
if obj.Type != EthereumEip712SignatureProof2021Type {
return errors.New("invalid proof type")
}
p.Type = obj.Type
err = json.Unmarshal(obj.Eip712, &p.Eip712)
if err != nil {
return err
}
p.VerificationMethod = obj.VerificationMethod
p.ProofPursopose = obj.ProofPursopose
p.ProofValue = obj.ProofValue
p.Created = obj.Created
return nil
}
47 changes: 28 additions & 19 deletions pkg/services/blockchain/eth/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type AuthData struct {
Address string
}

const (
secp256k1VValue = 27
)

var (
gistNotFoundException = "execution reverted: Root does not exist"
identityNotFoundException = "execution reverted: Identity does not exist"
Expand Down Expand Up @@ -114,7 +118,7 @@ func (r *Resolver) BlockchainID() string {
return fmt.Sprintf("%d:%s", r.chainID, r.contractAddress)
}

func (r *Resolver) WalletAddress() (string, error) {
func (r *Resolver) GetWalletAddress() (string, error) {
if r.walletKey == "" {
return "", errors.New("wallet key is not set")
}
Expand Down Expand Up @@ -242,7 +246,11 @@ func (r *Resolver) Resolve(
}

signature := ""
if r.walletKey != "" && opts.Signature != "" {
if opts.Signature != "" {
if r.walletKey == "" {
return services.IdentityState{},
errors.New("no wallet key found for generating signature")
}
primaryType := services.IdentityStateType
if opts.GistRoot != nil {
primaryType = services.GlobalStateType
Expand All @@ -263,7 +271,7 @@ func (r *Resolver) VerifyState(
identityState services.IdentityState,
did w3c.DID,
) (bool, error) {
walletAddress, err := r.WalletAddress()
walletAddress, err := r.GetWalletAddress()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -291,26 +299,20 @@ func (r *Resolver) TypedData(primaryType services.PrimaryType, did w3c.DID, iden
ID := id.BigInt().String()
idType := fmt.Sprintf("0x%02X%02X", id.Type()[0], id.Type()[1])

root := "0"
state := "0"
replacedAtTimestamp := "0"

if identityState.StateInfo != nil {
state = identityState.StateInfo.State.String()
replacedAtTimestamp = identityState.StateInfo.ReplacedAtTimestamp.String()
}
if identityState.GistInfo != nil {
root = identityState.GistInfo.Root.String()
replacedAtTimestamp = identityState.GistInfo.ReplacedAtTimestamp.String()
}

apiTypes := apitypes.Types{}
message := apitypes.TypedDataMessage{}
primaryTypeString := ""
timestamp := TimeStamp()

switch primaryType {
case services.IdentityStateType:
state := "0"
replacedAtTimestamp := "0"

if identityState.StateInfo != nil {
state = identityState.StateInfo.State.String()
replacedAtTimestamp = identityState.StateInfo.ReplacedAtTimestamp.String()
}
primaryTypeString = "IdentityState"
apiTypes = IdentityStateAPITypes
message = apitypes.TypedDataMessage{
Expand All @@ -320,6 +322,13 @@ func (r *Resolver) TypedData(primaryType services.PrimaryType, did w3c.DID, iden
"replacedAtTimestamp": replacedAtTimestamp,
}
case services.GlobalStateType:
root := "0"
replacedAtTimestamp := "0"

if identityState.GistInfo != nil {
root = identityState.GistInfo.Root.String()
replacedAtTimestamp = identityState.GistInfo.ReplacedAtTimestamp.String()
}
primaryTypeString = "GlobalState"
apiTypes = GlobalStateAPITypes
message = apitypes.TypedDataMessage{
Expand Down Expand Up @@ -351,7 +360,7 @@ func (r *Resolver) signTypedData(primaryType services.PrimaryType, did w3c.DID,
return "", err
}

walletAddress, err := r.WalletAddress()
walletAddress, err := r.GetWalletAddress()
if err != nil {
return "", err
}
Expand All @@ -377,8 +386,8 @@ func (r *Resolver) signTypedData(primaryType services.PrimaryType, did w3c.DID,
return "", err
}

if signature[64] < 27 {
signature[64] += 27
if signature[64] < secp256k1VValue { // Invalid Ethereum signature (V is not 27 or 28)
signature[64] += secp256k1VValue // Transform yellow paper V from 27/28 to 0/1
}

return "0x" + hex.EncodeToString(signature), nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (d *DidDocumentServices) GetDidDocument(ctx context.Context, did string, op
},
)

walletAddress, err := resolver.WalletAddress()
walletAddress, err := resolver.GetWalletAddress()

if err == nil && opts.Signature != "" {
primaryType := IdentityStateType
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type Resolver interface {
Resolve(ctx context.Context, did w3c.DID, opts *ResolverOpts) (IdentityState, error)
ResolveGist(ctx context.Context, opts *ResolverOpts) (*GistInfo, error)
BlockchainID() string
WalletAddress() (string, error)
GetWalletAddress() (string, error)
TypedData(primaryType PrimaryType, did w3c.DID, identityState IdentityState, walletAddress string) (apitypes.TypedData, error)
}

Expand Down
62 changes: 0 additions & 62 deletions test.http

This file was deleted.

0 comments on commit c67a75a

Please sign in to comment.