-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backup): allow backup and import of prism wallet
This will enable backup of a wallet to another wallet given the seed is the same. It adds a protocol to enable credential exports. Fixes ATL-6610
- Loading branch information
1 parent
423daf4
commit e519192
Showing
28 changed files
with
864 additions
and
23 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
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
59 changes: 59 additions & 0 deletions
59
EdgeAgentSDK/Domain/Sources/Models/Credentials/ExportableCredential.swift
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Foundation | ||
|
||
/** | ||
A protocol that defines the requirements for credentials that can be exported. | ||
|
||
This protocol ensures that any credential conforming to it can be serialized into a data format suitable for export and specifies the type of restoration that will be required when the credential is imported back. This is particularly useful for scenarios where credentials need to be securely backed up, transferred, or shared between different systems or platforms. | ||
|
||
- Properties: | ||
- exporting: A `Data` representation of the credential that can be serialized and securely stored or transferred. This data should encapsulate all necessary information to recreate the credential upon import. | ||
- restorationType: A `String` that indicates the method or requirements for restoring the credential from the exported data. This could relate to specific security measures, encryption standards, or data formats that are necessary for the credential's reconstruction. | ||
|
||
Implementers of this protocol must ensure that the `exporting` property effectively captures the credential's state and that the `restorationType` accurately describes the requirements for its restoration. | ||
*/ | ||
public protocol ExportableCredential { | ||
var exporting: Data { get } | ||
var restorationType: String { get } | ||
} | ||
|
||
/** | ||
A protocol that defines the functionality required to import credentials from a serialized data format. | ||
|
||
This interface is crucial for scenarios where credentials, previously exported using the `ExportableCredential` protocol, need to be reconstructed or imported back into the system. It allows for the implementation of a customizable import process that can handle various types of credentials and their respective restoration requirements. | ||
|
||
- Method `importCredential`: | ||
- Parameters: | ||
- credentialData: The serialized `Data` representation of the credential to be imported. This data should have been generated by the `exporting` property of an `ExportableCredential`. | ||
- restorationType: A `String` indicating the method or requirements for restoring the credential. This should match the `restorationType` provided during the export process. | ||
- options: An array of `CredentialOperationsOptions` that may modify or provide additional context for the import process, allowing for more flexibility in handling different credential types and scenarios. | ||
- Returns: An asynchronous operation that, upon completion, returns the imported `Credential` object, reconstructed from the provided data. | ||
- Throws: An error if the import process encounters issues, such as data corruption, incompatible restoration types, or if the provided options are not supported. | ||
|
||
Implementers should ensure robust error handling and validation to securely and accurately restore credentials from their exported state. | ||
*/ | ||
public protocol CredentialImporter { | ||
func importCredential( | ||
credentialData: Data, | ||
restorationType: String, | ||
options: [CredentialOperationsOptions] | ||
) async throws -> Credential | ||
} | ||
|
||
/** | ||
Extension to the `Credential` class or struct, providing convenience properties related to the exportability of credentials. | ||
|
||
This extension adds functionality to easily determine whether a credential conforms to the `ExportableCredential` protocol and, if so, obtain its exportable form. This simplifies the process of exporting credentials by abstracting the type checking and casting logic. | ||
|
||
- Properties: | ||
- isExportable: A Boolean value that indicates whether the `Credential` instance conforms to the `ExportableCredential` protocol, thereby supporting export operations. | ||
- exportable: An optional `ExportableCredential` that returns the instance cast to `ExportableCredential` if it conforms to the protocol, or `nil` if it does not. This allows for direct access to the exporting capabilities of the credential without manual type checking or casting. | ||
|
||
These properties enhance the usability of credentials by providing straightforward mechanisms to interact with export-related functionality. | ||
*/ | ||
public extension Credential { | ||
/// A Boolean value indicating whether the credential is exportable. | ||
var isExportable: Bool { self is ExportableCredential } | ||
|
||
/// Returns the exportable representation of the credential. | ||
var exportable: ExportableCredential? { self as? ExportableCredential } | ||
} |
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
Oops, something went wrong.