Skip to content

Commit

Permalink
Remove explicit protocols, they did more harm than good right now
Browse files Browse the repository at this point in the history
  • Loading branch information
amika-sq committed Feb 7, 2024
1 parent 5888950 commit 3e2a100
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 96 deletions.
7 changes: 1 addition & 6 deletions Sources/Web5/Dids/Methods/DIDIon.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Foundation

/// `did:ion` DID Method
public enum DIDIon: DIDMethod {
public enum DIDIon {

public static let methodName = "ion"
}

// MARK: - DIDMethodResolver

extension DIDIon: DIDMethodResolver {

/// Resolves a `did:ion` URI into a `DIDResolutionResult`
/// - Parameters:
Expand Down
29 changes: 2 additions & 27 deletions Sources/Web5/Dids/Methods/DIDJWK.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Foundation

/// `did:jwk` DID Method
public enum DIDJWK: DIDMethod {
public enum DIDJWK {

public static let methodName = "jwk"
}

// MARK: - DIDMethodResolver

extension DIDJWK: DIDMethodResolver {

/// Resolves a `did:jwk` URI into a `DIDResolutionResult`
/// - Parameters:
Expand All @@ -30,11 +25,6 @@ extension DIDJWK: DIDMethodResolver {
let didDocument = didDocument(did: did, publicKey: jwk)
return DIDResolutionResult(didDocument: didDocument)
}
}

// MARK: - DIDMethodCreator

extension DIDJWK: DIDMethodCreator {

/// Options that can be provided to customize how a `did:jwk` is created
public struct CreateOptions {
Expand Down Expand Up @@ -62,7 +52,7 @@ extension DIDJWK: DIDMethodCreator {
/// - Returns: `BearerDID` that represents the created DIDJWK
public static func create(
keyManager: KeyManager,
options: CreateOptions
options: CreateOptions = .default
) throws -> BearerDID {
let keyAlias = try keyManager.generatePrivateKey(algorithm: options.algorithm)
let publicKey = try keyManager.getPublicKey(keyAlias: keyAlias)
Expand All @@ -79,21 +69,6 @@ extension DIDJWK: DIDMethodCreator {
)
}

/// Create a new `BearerDID` using the `did:jwk` method.
///
/// - Parameters:
/// - keyManager: `KeyManager` used to generate and store the keys associated to the DID
/// - Returns: `BearerDID` that represents the created DIDJWK
public static func create(
keyManager: KeyManager
) throws -> BearerDID {
// Create a new `BearerDID` using default options
return try create(
keyManager: keyManager,
options: CreateOptions.default
)
}

/// Import a `PortableDID` that represents a DIDJWK into a `BearerDID` that can be used
/// to sign and verify data
///
Expand Down
7 changes: 1 addition & 6 deletions Sources/Web5/Dids/Methods/DIDWeb.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Foundation

/// `did:web` DID Method
enum DIDWeb: DIDMethod {
enum DIDWeb {

public static let methodName = "web"
}

// MARK: - DIDMethodResolver

extension DIDWeb: DIDMethodResolver {

/// Resolves a `did:web` URI into a `DIDResolutionResult`
/// - Parameters:
Expand Down
10 changes: 0 additions & 10 deletions Sources/Web5/Dids/Methods/Protocols/DIDMethod.swift

This file was deleted.

28 changes: 0 additions & 28 deletions Sources/Web5/Dids/Methods/Protocols/DIDMethodCreator.swift

This file was deleted.

14 changes: 0 additions & 14 deletions Sources/Web5/Dids/Methods/Protocols/DIDMethodResolver.swift

This file was deleted.

12 changes: 7 additions & 5 deletions Sources/Web5/Dids/Resolution/DIDResolver.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Foundation

typealias DIDMethodResolver = (String) async -> DIDResolutionResult

public enum DIDResolver {

private static var methodResolvers: [String: DIDMethodResolver.Type] = [
DIDIon.methodName: DIDIon.self,
DIDJWK.methodName: DIDJWK.self,
DIDWeb.methodName: DIDWeb.self,
private static var methodResolvers: [String: DIDMethodResolver] = [
DIDIon.methodName: DIDIon.resolve,
DIDJWK.methodName: DIDJWK.resolve,
DIDWeb.methodName: DIDWeb.resolve,
]

/// Resolves a DID URI to its DID Document
Expand All @@ -20,6 +22,6 @@ public enum DIDResolver {
return DIDResolutionResult(error: .methodNotSupported)
}

return await methodResolver.resolve(didURI: didURI)
return await methodResolver(didURI)
}
}

0 comments on commit 3e2a100

Please sign in to comment.