generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
157 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import AnyCodable | ||
import Foundation | ||
|
||
/// A representation of a `BearerDID` that can be moved imported/exported. | ||
/// | ||
/// `PortableDID` bundles all of the necessary information for a `BearerDID`, | ||
/// enabling the usage of the DID in different context. This format is compatible | ||
/// and interoperable across all Web5 programming languages. | ||
public struct PortableDID: Codable { | ||
|
||
public typealias Metadata = [String: AnyCodable] | ||
|
||
/// URI of DID | ||
let uri: String | ||
let verificationMethods: [VerificationMethodKeyPair] | ||
|
||
public struct VerificationMethodKeyPair: Codable { | ||
let publicKey: Jwk | ||
let privateKey: Jwk | ||
/// `DIDDocument` of the DID | ||
let document: DIDDocument | ||
|
||
/// Private keys that correspond to the public keys present in the `document` | ||
let privateKeys: [Jwk] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case publicKey = "publicKeyJwk" | ||
case privateKey = "privateKeyJwk" | ||
} | ||
} | ||
/// Additional DID method specific information to be included | ||
let metadata: Metadata? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import CustomDump | ||
import XCTest | ||
|
||
@testable import Web5 | ||
|
||
final class BearerDIDTests: XCTestCase { | ||
|
||
func test_toKeys() async throws { | ||
func test_export() async throws { | ||
let didJWK = try DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
let portableDID = try await didJWK.toPortableDID() | ||
let portableDID = try await didJWK.export() | ||
|
||
XCTAssertEqual(portableDID.uri, didJWK.uri) | ||
XCTAssertEqual(portableDID.verificationMethods.count, 1) | ||
XCTAssertNoDifference(portableDID.uri, didJWK.uri) | ||
XCTAssertNoDifference(portableDID.document, didJWK.document) | ||
XCTAssertNoDifference(portableDID.privateKeys.count, 1) | ||
XCTAssertNil(portableDID.metadata) | ||
} | ||
|
||
func test_initializeWithKeys() async throws { | ||
let didJWK = try DIDJWK.create(keyManager: InMemoryKeyManager()) | ||
let portableDID = try await didJWK.toPortableDID() | ||
|
||
XCTAssertNoThrow(try BearerDID(portableDID: portableDID)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters