Connecting an External Signer
By default, the SDK uses mnemonics to generate keys and sign transactions. However, in some cases, developers would prefer not to pass the seed key to the SDK. In these cases, you can provide an external signer that provides more control over key management and signing.
To use an external signer, you'll need to:
- Implement the
Signer
trait/interface - Use
connect_with_signer
instead ofconnect
when initializing the SDK
Here's how to implement this:
Rust
async fn connect_with_self_signer(signer: Signer) -> Result<Arc<LiquidSdk>> {
// Create the default config, providing your Breez API key
let mut config = LiquidSdk::default_config(LiquidNetwork::Mainnet, Some("<your-Breez-API-key>".to_string()))?;
// Customize the config object according to your needs
config.working_dir = "path to an existing directory".into();
let connect_request = ConnectWithSignerRequest {
config,
};
let sdk = LiquidSdk::connect_with_signer(connect_request, signer).await?;
Ok(sdk)
}
Swift
func connectWithSelfSigner(signer: Signer) throws -> BindingLiquidSdk? {
let mnemonic = "<mnemonic words>"
// Create the default config, providing your Breez API key
var config = try defaultConfig(network: LiquidNetwork.mainnet, breezApiKey: "<your-Breez-API-key>")
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
let connectRequest = ConnectWithSignerRequest(config: config)
let sdk = try? connectWithSigner(req: connectRequest, signer: signer)
return sdk
}
Kotlin
fun connectWithSelfSigner(signer: Signer) {
// Create the default config, providing your Breez API key
val config : Config = defaultConfig(LiquidNetwork.MAINNET, "<your Breez API key>")
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
try {
val connectRequest = ConnectWithSignerRequest(config)
val sdk = connectWithSigner(connectRequest, signer)
} catch (e: Exception) {
// handle error
}
}
Python
def connect_with_self_signer(signer: Signer):
# Create the default config, providing your Breez API key
config = default_config(network=LiquidNetwork.MAINNET, breez_api_key="<your-Breez-API-key>")
# Customize the config object according to your needs
config.working_dir = "path to an existing directory"
try:
connect_request = ConnectWithSignerRequest(config)
sdk = connect_with_signer(connect_request, signer)
return sdk
except Exception as error:
logging.error(error)
raise
Go
func ConnectWithSelfSigner(signer breez_sdk_liquid.Signer) (*breez_sdk_liquid.BindingLiquidSdk, error) {
// Create the default config, providing your Breez API key
breezApiKey := "<your-Breez-API-key>"
config, err := breez_sdk_liquid.DefaultConfig(breez_sdk_liquid.LiquidNetworkMainnet, &breezApiKey)
if err != nil {
return nil, err
}
// Customize the config object according to your needs
config.WorkingDir = "path to an existing directory"
connectRequest := breez_sdk_liquid.ConnectWithSignerRequest{
Config: config,
}
sdk, err := breez_sdk_liquid.ConnectWithSigner(connectRequest, signer)
return sdk, err
}
C#
public void ConnectWithSelfSigner(Signer signer)
{
// Create the default config, providing your Breez API key
var config = BreezSdkLiquidMethods.DefaultConfig(
LiquidNetwork.Mainnet,
"<your-Breez-API-key>"
) with
{
// Customize the config object according to your needs
workingDir = "path to an existing directory"
};
try
{
var connectRequest = new ConnectWithSignerRequest(config);
var sdk = BreezSdkLiquidMethods.ConnectWithSigner(connectRequest, signer);
}
catch (Exception)
{
// Handle error
}
}
Developer note
A reference implementation of such signer is available in the SDK repository. You can use it as-is or customize it to meet your requirements: SdkSigner.Note that this same implementation is used internally by the SDK when connecting with a mnemonics via the standard `Connect` method.