Skip to content

Commit

Permalink
Merge pull request #170 from Elenpay/remote-signer-json-match-lambda
Browse files Browse the repository at this point in the history
Various refactor, remote signing matching lambda version
  • Loading branch information
Jossec101 authored May 12, 2023
2 parents 035ca2c + a56b87a commit e339a85
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 74 deletions.
2 changes: 0 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ services:
COINGECKO_KEY: "TBD" #PLEASE FILL IT WITH YOUR OWN
MONITOR_WITHDRAWALS_CRON: "0 */1 * * * ?" # Every Minute
# ENABLE_REMOTE_SIGNER: "false" #Changes the way of signing, instead of a auto-generated internal wallet, NodeGuard will sign with a remote signer function on AWS Lambda
MSSQL_CONNECTIONSTRING: "Server=localhost;Database=master;User=sa;Password=rw_dev;"
REDIS_CONNECTIONSTRING: "redis"
#OTEL_COLLECTOR_ENDPOINT: http://host.docker.internal:4318 #gRPC endpoint for OTel collector (optional)
HTTP1_LISTEN_PORT: 38080

Expand Down
5 changes: 1 addition & 4 deletions src/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class Constants
public static readonly string? AWS_REGION;
public static readonly string? AWS_ACCESS_KEY_ID;
public static readonly string? AWS_SECRET_ACCESS_KEY;
public static readonly string? AWS_KMS_KEY_ID;

// Crons & Jobs
public static readonly string MONITOR_WITHDRAWALS_CRON = "10 0/5 * * * ?";
Expand Down Expand Up @@ -137,9 +136,7 @@ static Constants()
AWS_ACCESS_KEY_ID = GetEnvironmentalVariableOrThrowIfNotTesting("AWS_ACCESS_KEY_ID", "if ENABLE_REMOTE_SIGNER is set, AWS_ACCESS_KEY_ID");

AWS_SECRET_ACCESS_KEY = GetEnvironmentalVariableOrThrowIfNotTesting("AWS_SECRET_ACCESS_KEY", "if ENABLE_REMOTE_SIGNER is set, AWS_SECRET_ACCESS_KEY");

AWS_KMS_KEY_ID = GetEnvironmentalVariableOrThrowIfNotTesting("AWS_KMS_KEY_ID", "if ENABLE_REMOTE_SIGNER is set, AWS_KMS_KEY_ID");


REMOTE_SIGNER_ENDPOINT = GetEnvironmentalVariableOrThrowIfNotTesting("REMOTE_SIGNER_ENDPOINT", "if ENABLE_REMOTE_SIGNER is set, REMOTE_SIGNER_ENDPOINT");
}

Expand Down
58 changes: 3 additions & 55 deletions src/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,7 @@
}
},
"profiles": {
"FundsManager": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:443;http://localhost:38080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"POSTGRES_CONNECTIONSTRING": "Host=127.0.0.1;Port=35433;Database=fundsmanager;Username=rw_dev;Password=rw_dev",
"BITCOIN_NETWORK": "REGTEST",
"MAXIMUM_WITHDRAWAL_BTC_AMOUNT": "21000000",
"NBXPLORER_URI": "http://127.0.0.1:32838",
"NBXPLORER_BTCRPCUSER": "polaruser",
"NBXPLORER_BTCRPCPASSWORD": "polarpass",
"NBXPLORER_BTCRPCURL": "http://127.0.0.1:18443/",
"NBXPLORER_BTCNODEENDPOINT": "127.0.0.1:19444",
"PUSH_NOTIFICATIONS_ONESIGNAL_API_BASE_PATH": "https://onesignal.com/api/v1",
"PUSH_NOTIFICATIONS_ONESIGNAL_APP_ID": "88695835-1513-4f3d-8104-ce8089447d11",
"PUSH_NOTIFICATIONS_ONESIGNAL_API_TOKEN": "NDcxNDRjZTMtYTMxMy00MmU4LWFlYTgtZTNjNTMzNGFiNzE1",
"PUSH_NOTIFICATIONS_ONESIGNAL_ENABLED": "false",
"DEFAULT_DERIVATION_PATH": "m/48'/1'",
"IS_DEV_ENVIRONMENT": "true",
"FUNDSMANAGER_ENDPOINT": "https://localhost",
"Logging__LogLevel__Microsoft": "Warning",
"SWEEPNODEWALLETSJOB_CRON": "0 */1 * * * ?",
"ANCHOR_CLOSINGS_MINIMUM_SATS": "100000",
"ALICE_HOST": "host.docker.internal:10001",
"CAROL_HOST": "host.docker.internal:10003",
"ENABLE_HW_SUPPORT": "false",
"MINIMUM_WITHDRAWAL_BTC_AMOUNT": "0.001",
"MINIMUM_CHANNEL_CAPACITY_SATS": "20000",
"MEMPOOL_ENDPOINT": "https://mempool-staging.elenpay.tech",
"TRANSACTION_CONFIRMATION_MINIMUM_BLOCKS": "6",
"MONITOR_WITHDRAWALS_CRON": "0 */1 * * * ?",
"REDIS_CONNECTIONSTRING": "host.docker.internal",
"COINGECKO_ENDPOINT": "https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin",
"COINGECKO_KEY": "TBD",
"HTTP1_LISTEN_PORT": "38080"
}
},
"FundsManager NOVS": {
"NodeGuard local debug": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:38080",
Expand All @@ -62,8 +24,8 @@
"NBXPLORER_BTCRPCURL": "http://127.0.0.1:18443/",
"NBXPLORER_BTCNODEENDPOINT": "127.0.0.1:19444",
"PUSH_NOTIFICATIONS_ONESIGNAL_API_BASE_PATH": "https://onesignal.com/api/v1",
"PUSH_NOTIFICATIONS_ONESIGNAL_APP_ID": "88695835-1513-4f3d-8104-ce8089447d11",
"PUSH_NOTIFICATIONS_ONESIGNAL_API_TOKEN": "NDcxNDRjZTMtYTMxMy00MmU4LWFlYTgtZTNjNTMzNGFiNzE1",
"PUSH_NOTIFICATIONS_ONESIGNAL_APP_ID": "changeme",
"PUSH_NOTIFICATIONS_ONESIGNAL_API_TOKEN": "changeme",
"PUSH_NOTIFICATIONS_ONESIGNAL_ENABLED": "false",
"DEFAULT_DERIVATION_PATH": "m/48'/1'",
"IS_DEV_ENVIRONMENT": "true",
Expand All @@ -79,24 +41,10 @@
"MEMPOOL_ENDPOINT": "https://mempool-staging.elenpay.tech",
"TRANSACTION_CONFIRMATION_MINIMUM_BLOCKS": "6",
"MONITOR_WITHDRAWALS_CRON": "0 */1 * * * ?",
"REDIS_CONNECTIONSTRING": "localhost:6379,abortConnect=false,connectTimeout=30000,responseTimeout=30000",
"COINGECKO_ENDPOINT": "https://pro-api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin",
"COINGECKO_KEY": "TBD",
"HTTP1_LISTEN_PORT": "38080"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {}
}
}
}
6 changes: 3 additions & 3 deletions src/Services/LightningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ INBXplorerService nbXplorerService
/// <param name="EnforcedSighash"></param>
/// <param name="Network"></param>
/// <param name="AwsKmsKeyId"></param>
public record Input(string Psbt, SigHash? EnforcedSighash, string Network, string AwsKmsKeyId);
public record RemoteSignerRequest(string Psbt, SigHash? EnforcedSighash, string Network);
/// <summary>
/// Record used to match AWS SignPSBT funciton output
/// </summary>
/// <param name="Psbt"></param>
public record Output(string? Psbt);
public record RemoteSignerResponse(string? Psbt);

public async Task OpenChannel(ChannelOperationRequest channelOperationRequest)
{
Expand Down Expand Up @@ -409,7 +409,7 @@ public async Task OpenChannel(ChannelOperationRequest channelOperationRequest)
var changeFixedPSBT = channelfundingTx.CreatePSBT(network).UpdateFrom(fundedPSBT);

PSBT? finalSignedPSBT = null;
//We check the way the fundsmanager signs, with the remoteFundsManagerSigner or by itself.
//We check the way the nodeguard signs, with the nodeguard remote signer or with the embedded signer
if (Constants.ENABLE_REMOTE_SIGNER)
{
finalSignedPSBT = await _remoteSignerService.Sign(changeFixedPSBT);
Expand Down
16 changes: 6 additions & 10 deletions src/Services/RemoteSignerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,9 @@ public RemoteSignerServiceService(ILogger<RemoteSignerServiceService> logger)
awsAccessKeyId,
awsSecretAccessKey,
null);

var awsKmsKeyId = Constants.AWS_KMS_KEY_ID;

var requestPayload = new LightningService.Input(psbt.ToBase64(), SigHash.All,
CurrentNetworkHelper.GetCurrentNetwork().ToString(),
awsKmsKeyId ??
throw new InvalidOperationException());

var requestPayload = new LightningService.RemoteSignerRequest(psbt.ToBase64(), SigHash.All,
CurrentNetworkHelper.GetCurrentNetwork().ToString());

var serializedPayload = JsonSerializer.Serialize(requestPayload);

Expand All @@ -115,11 +111,11 @@ public RemoteSignerServiceService(ILogger<RemoteSignerServiceService> logger)
throw new Exception(errorWhileSignignPsbtWithAwsLambdaFunctionStatus);
}

var output =
JsonSerializer.Deserialize<LightningService.Output>(
var remoteSignerResponse =
JsonSerializer.Deserialize<LightningService.RemoteSignerResponse>(
await signLambdaResponse.Content.ReadAsStreamAsync());

if (!PSBT.TryParse(output.Psbt, CurrentNetworkHelper.GetCurrentNetwork(), out var finalSignedPsbt))
if (!PSBT.TryParse(remoteSignerResponse.Psbt, CurrentNetworkHelper.GetCurrentNetwork(), out var finalSignedPsbt))
{
var errorWhileParsingPsbt = "Error while parsing PSBT signed from AWS Remote FundsManagerSigner";
_logger.LogError(errorWhileParsingPsbt);
Expand Down

0 comments on commit e339a85

Please sign in to comment.