Commit a464e3f1 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added api methods

parent 34f2bdc4
using System; using System.Threading.Tasks;
using System.Collections.Generic; using Breeze.TumbleBit.Models;
using System.Text; using NBitcoin;
using System.Threading.Tasks;
using NTumbleBit; using NTumbleBit;
using NTumbleBit.ClassicTumbler; using NTumbleBit.ClassicTumbler;
using NTumbleBit.PuzzlePromise;
using NTumbleBit.PuzzleSolver;
using PuzzlePromise = NTumbleBit.PuzzlePromise;
using PuzzleSolver = NTumbleBit.PuzzleSolver;
namespace Breeze.TumbleBit.Client namespace Breeze.TumbleBit.Client
{ {
...@@ -17,5 +20,25 @@ namespace Breeze.TumbleBit.Client ...@@ -17,5 +20,25 @@ namespace Breeze.TumbleBit.Client
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task<ClassicTumblerParameters> GetClassicTumblerParametersAsync(); Task<ClassicTumblerParameters> GetClassicTumblerParametersAsync();
Task<UnsignedVoucherInformation> AskUnsignedVoucher();
Task<PuzzleSolution> SignVoucherAsync(SignVoucherRequest signVoucherRequest);
Task<ScriptCoin> OpenChannelAsync(OpenChannelRequest request);
Task<TumblerEscrowKeyResponse> RequestTumblerEscrowKeyAsync(int cycleStart);
Task<ServerCommitmentsProof> CheckRevelationAsync(int cycleId, string channelId, PuzzlePromise.ClientRevelation revelation);
Task<SolutionKey[]> CheckRevelationAsync(int cycleId, string channelId, PuzzleSolver.ClientRevelation revelation);
Task<PuzzlePromise.ServerCommitment[]> SignHashesAsync(int cycleId, string channelId, SignaturesRequest sigReq);
Task<OfferInformation> CheckBlindFactorsAsync(int cycleId, string channelId, BlindFactor[] blindFactors);
Task<PuzzleSolver.ServerCommitment[]> SolvePuzzlesAsync(int cycleId, string channelId, PuzzleValue[] puzzles);
Task<SolutionKey[]> FulfillOfferAsync(int cycleId, string channelId, TransactionSignature clientSignature);
} }
} }
using NBitcoin;
using NTumbleBit.ClassicTumbler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Breeze.TumbleBit.Models
{
public class SignVoucherRequest
{
public int KeyReference { get; set; }
public PubKey TumblerEscrowPubKey { get; set; }
public ClientEscrowInformation ClientEscrowInformation { get; set; }
public MerkleBlock MerkleProof { get; set; }
public Transaction Transaction { get; set; }
}
}
using NBitcoin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Breeze.TumbleBit.Models
{
public class TumblerEscrowKeyResponse
{
public int KeyIndex { get; set; }
public PubKey PubKey { get; set; }
}
}
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Breeze.TumbleBit.Models;
using Flurl; using Flurl;
using Flurl.Http; using Flurl.Http;
using Flurl.Http.Configuration; using Flurl.Http.Configuration;
using NBitcoin;
using NBitcoin.JsonConverters; using NBitcoin.JsonConverters;
using Newtonsoft.Json; using Newtonsoft.Json;
using NTumbleBit;
using NTumbleBit.ClassicTumbler; using NTumbleBit.ClassicTumbler;
using NTumbleBit.JsonConverters; using NTumbleBit.JsonConverters;
using NTumbleBit.PuzzlePromise;
using NTumbleBit.PuzzleSolver;
using PuzzlePromise = NTumbleBit.PuzzlePromise;
using PuzzleSolver = NTumbleBit.PuzzleSolver;
namespace Breeze.TumbleBit.Client namespace Breeze.TumbleBit.Client
{ {
...@@ -33,5 +40,75 @@ namespace Breeze.TumbleBit.Client ...@@ -33,5 +40,75 @@ namespace Breeze.TumbleBit.Client
ClassicTumblerParameters result = await this.serverAddress.AppendPathSegment("/api/v1/tumblers/0/parameters").GetJsonAsync<ClassicTumblerParameters>(); ClassicTumblerParameters result = await this.serverAddress.AppendPathSegment("/api/v1/tumblers/0/parameters").GetJsonAsync<ClassicTumblerParameters>();
return result; return result;
} }
/// <inheritdoc />
public async Task<UnsignedVoucherInformation> AskUnsignedVoucher()
{
UnsignedVoucherInformation result = await this.serverAddress.AppendPathSegment("api/v1/tumblers/0/vouchers/").GetJsonAsync<UnsignedVoucherInformation>();
return result;
}
/// <inheritdoc />
public async Task<PuzzleSolution> SignVoucherAsync(SignVoucherRequest request)
{
PuzzleSolution result = await this.serverAddress.AppendPathSegment("api/v1/tumblers/0/clientchannels/confirm").PostJsonAsync(request).ReceiveJson<PuzzleSolution>();
return result;
}
/// <inheritdoc />
public async Task<ScriptCoin> OpenChannelAsync(OpenChannelRequest request)
{
ScriptCoin result = await this.serverAddress.AppendPathSegment("api/v1/tumblers/0/channels/").PostJsonAsync(request).ReceiveJson<ScriptCoin>();
return result;
}
/// <inheritdoc />
public async Task<TumblerEscrowKeyResponse> RequestTumblerEscrowKeyAsync(int cycleStart)
{
TumblerEscrowKeyResponse result = await this.serverAddress.AppendPathSegment("api/v1/tumblers/0/clientchannels/").PostJsonAsync(cycleStart).ReceiveJson<TumblerEscrowKeyResponse>();
return result;
}
/// <inheritdoc />
public async Task<ServerCommitmentsProof> CheckRevelationAsync(int cycleId, string channelId, PuzzlePromise.ClientRevelation revelation)
{
ServerCommitmentsProof result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/channels/{cycleId}/{channelId}/checkrevelation").PostJsonAsync(revelation).ReceiveJson<ServerCommitmentsProof>();
return result;
}
/// <inheritdoc />
public async Task<SolutionKey[]> CheckRevelationAsync(int cycleId, string channelId, PuzzleSolver.ClientRevelation revelation)
{
SolutionKey[] result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/clientschannels/{cycleId}/{channelId}/checkrevelation").PostJsonAsync(revelation).ReceiveJson<SolutionKey[]>();
return result;
}
/// <inheritdoc />
public async Task<PuzzlePromise.ServerCommitment[]> SignHashesAsync(int cycleId, string channelId, SignaturesRequest sigReq)
{
PuzzlePromise.ServerCommitment[] result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/channels/{cycleId}/{channelId}/signhashes").PostJsonAsync(sigReq).ReceiveJson<PuzzlePromise.ServerCommitment[]>();
return result;
}
/// <inheritdoc />
public async Task<OfferInformation> CheckBlindFactorsAsync(int cycleId, string channelId, BlindFactor[] blindFactors)
{
OfferInformation result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/clientschannels/{cycleId}/{channelId}/checkblindfactors").PostJsonAsync(blindFactors).ReceiveJson<OfferInformation>();
return result;
}
/// <inheritdoc />
public async Task<PuzzleSolver.ServerCommitment[]> SolvePuzzlesAsync(int cycleId, string channelId, PuzzleValue[] puzzles)
{
PuzzleSolver.ServerCommitment[] result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/clientchannels/{cycleId}/{channelId}/solvepuzzles").PostJsonAsync(puzzles).ReceiveJson<PuzzleSolver.ServerCommitment[]>();
return result;
}
/// <inheritdoc />
public async Task<SolutionKey[]> FulfillOfferAsync(int cycleId, string channelId, TransactionSignature clientSignature)
{
SolutionKey[] result = await this.serverAddress.AppendPathSegment($"api/v1/tumblers/0/clientchannels/{cycleId}/{channelId}/offer").PostJsonAsync(clientSignature).ReceiveJson<SolutionKey[]>();
return result;
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment