Export Key
Users can at any time request to "export" their keys into a private key.
Step 1 : Create Session
- Create TrioSession if you haven't already.
Step 2 : Perform Export
- Call trioSession.export() with the
keyIdwhich returnsResultofSuccesswith the exported private key bytes asDataorFailurewitherror.
Example
Example.swift
// export reconstructs the raw private key for the key addressed by keyId (the
// SDK handles backup encryption internally, with no HTTP roundtrip). Treat the
// result like any private key — encrypt it at rest — and bring it back under
// MPC later with trioSession.import(keysharePrivateKey:).
func exportPrivateKey(keyId: String, trioSession: TrioSession) async -> Data? {
let result = await trioSession.export(keyId: keyId)
// returns nil if the operation fails, or handle it however your flow needs
switch result {
case .success(let privateKeyBytes):
// do something with the reconstructed private-key bytes
Swift.print(privateKeyBytes)
return privateKeyBytes
case .failure(let error):
// show the error to the user or abort the process
Swift.print(error)
return nil
}
}
keyId: Identifies the client's (In this case mobile) key to export. The SDK loads the keyshare from your StorageClient and handles the backup encryption internally.