Skip to content

Commit

Permalink
Merge pull request #33 from TBD54566975/dht-create
Browse files Browse the repository at this point in the history
Add DHT create support
  • Loading branch information
mihai-chiorean authored Feb 24, 2024
2 parents c13d00f + 3984685 commit f8a901b
Show file tree
Hide file tree
Showing 28 changed files with 1,331 additions and 381 deletions.
11 changes: 11 additions & 0 deletions crypto/dsa/dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ func PublicKeyToBytes(publicKey jwk.JWK) ([]byte, error) {
return nil, fmt.Errorf("unsupported key type: %s", publicKey.KTY)
}
}

func AlgorithmID(jwk *jwk.JWK) (string, error) {
switch jwk.KTY {
case ecdsa.KeyType:
return ecdsa.AlgorithmID(jwk)
case eddsa.KeyType:
return eddsa.AlgorithmID(jwk)
default:
return "", fmt.Errorf("unsupported key type: %s", jwk.KTY)
}
}
9 changes: 9 additions & 0 deletions crypto/dsa/ecdsa/ecdsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ func PublicKeyToBytes(publicKey jwk.JWK) ([]byte, error) {
func SupportsAlgorithmID(id string) bool {
return algorithmIDs[id]
}

func AlgorithmID(jwk *jwk.JWK) (string, error) {
switch jwk.CRV {
case SECP256K1JWACurve:
return SECP256K1AlgorithmID, nil
default:
return "", fmt.Errorf("unsupported curve: %s", jwk.CRV)
}
}
2 changes: 0 additions & 2 deletions crypto/dsa/ecdsa/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func SECP256K1GeneratePrivateKey() (jwk.JWK, error) {
yBytes := pubKey.Y().Bytes()

privateKey := jwk.JWK{
ALG: SECP256K1JWA,
KTY: KeyType,
CRV: SECP256K1JWACurve,
D: base64.RawURLEncoding.EncodeToString(dBytes[:]),
Expand Down Expand Up @@ -97,7 +96,6 @@ func SECP256K1BytesToPublicKey(input []byte) (jwk.JWK, error) {
}

return jwk.JWK{
ALG: SECP256K1JWA,
KTY: KeyType,
CRV: SECP256K1JWACurve,
X: base64.RawURLEncoding.EncodeToString(pubKey.X().Bytes()),
Expand Down
2 changes: 0 additions & 2 deletions crypto/dsa/eddsa/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func ED25519GeneratePrivateKey() (jwk.JWK, error) {
}

privKeyJwk := jwk.JWK{
ALG: JWA,
KTY: KeyType,
CRV: ED25519JWACurve,
D: base64.RawURLEncoding.EncodeToString(privateKey),
Expand Down Expand Up @@ -58,7 +57,6 @@ func ED25519BytesToPublicKey(input []byte) (jwk.JWK, error) {
}

return jwk.JWK{
ALG: JWA,
KTY: KeyType,
CRV: ED25519JWACurve,
X: base64.RawURLEncoding.EncodeToString(input),
Expand Down
9 changes: 9 additions & 0 deletions crypto/dsa/eddsa/eddsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ func PublicKeyToBytes(publicKey jwk.JWK) ([]byte, error) {
func SupportsAlgorithmID(id string) bool {
return algorithmIDs[id]
}

func AlgorithmID(jwk *jwk.JWK) (string, error) {
switch jwk.CRV {
case ED25519JWACurve:
return ED25519AlgorithmID, nil
default:
return "", fmt.Errorf("unsupported curve: %s", jwk.CRV)
}
}
3 changes: 3 additions & 0 deletions dids/didcore/resolution.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package didcore

import "context"

// MethodResolver is an interface that can be implemented for resolving specific DID methods.
// Each concrete implementation should adhere to the DID core specficiation defined here:
// https://www.w3.org/TR/did-core/#did-resolution
type MethodResolver interface {
Resolve(uri string) (ResolutionResult, error)
ResolveWithContext(ctx context.Context, uri string) (ResolutionResult, error)
}

// ResolutionResult represents the result of a DID (Decentralized Identifier)
Expand Down
49 changes: 0 additions & 49 deletions dids/diddht/bep44_test.go

This file was deleted.

Loading

0 comments on commit f8a901b

Please sign in to comment.