Skip to content

Commit

Permalink
Key agreement (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
adewaleafolabi authored Sep 22, 2023
1 parent 52c0c25 commit 6624d4c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions helpers/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
DidPrefix = "did:knox:"
ProofType = "Ed25519VerificationKey2020"
DidPrefix = "did:knox:"
ProofType = "Ed25519VerificationKey2020"
KeyAgreementType = "X25519KeyAgreementKey2019"
)

var MultiCodecPrefix = []byte{0xed, 0x01}
Expand All @@ -34,6 +35,9 @@ type KeyPairs struct {

AssertionMethodPublicKey string
AssertionMethodPrivateKey []byte

KeyAgreementPublicKey string
KeyAgreementPrivateKey []byte
}

type cryptoManager struct {
Expand Down Expand Up @@ -72,6 +76,8 @@ func (c *cryptoManager) GenerateKeyPair(mnemonic string) (*KeyPairs, error) {
CapabilityDelegationPrivateKey: private,
AssertionMethodPublicKey: encodedPublic,
AssertionMethodPrivateKey: private,
KeyAgreementPublicKey: encodedPublic,
KeyAgreementPrivateKey: private,
}, nil

}
Expand Down
8 changes: 8 additions & 0 deletions helpers/did/did.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func CreateDidDocument(kps *crypto.KeyPairs) *model.DidDocument {
PublicKeyMultibase: kps.AssertionMethodPublicKey,
},
},
KeyAgreement: []model.KeyMaterial{
{
Id: kps.GetVerificationMethod(signer.KeyAgreement),
Type: crypto.KeyAgreementType,
Controller: crypto.DidPrefix + kps.MasterPublicKey,
PublicKeyMultibase: kps.KeyAgreementPublicKey,
},
},
}
}

Expand Down
1 change: 1 addition & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DidDocument struct {
CapabilityInvocation []KeyMaterial `json:"capabilityInvocation"`
CapabilityDelegation []KeyMaterial `json:"capabilityDelegation"`
AssertionMethod []KeyMaterial `json:"assertionMethod"`
KeyAgreement []KeyMaterial `json:"keyAgreement,omitempty"`
}

type AuthToken struct {
Expand Down
3 changes: 3 additions & 0 deletions signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
CapabilityInvocation
CapabilityDelegation
AssertionMethod
KeyAgreement
)

func (vr VerificationRelation) String() string {
Expand All @@ -23,6 +24,8 @@ func (vr VerificationRelation) String() string {
return "capabilityDelegation"
case AssertionMethod:
return "associationMethod"
case KeyAgreement:
return "keyAgreement"
default:
return ""
}
Expand Down

0 comments on commit 6624d4c

Please sign in to comment.