Commit 3435ae71 authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Merge pull request #85 from bokobza/tumble-bit

Added tumbler API methods
parents 5d823d76 4ea339fe
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Breeze.TumbleBit.Models;
using NBitcoin;
using NTumbleBit;
using NTumbleBit.ClassicTumbler;
using NTumbleBit.PuzzlePromise;
using NTumbleBit.PuzzleSolver;
using PuzzlePromise = NTumbleBit.PuzzlePromise;
using PuzzleSolver = NTumbleBit.PuzzleSolver;
namespace Breeze.TumbleBit.Client
{
......@@ -17,5 +20,25 @@ namespace Breeze.TumbleBit.Client
/// </summary>
/// <returns></returns>
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.Threading.Tasks;
using Breeze.TumbleBit.Models;
using Flurl;
using Flurl.Http;
using Flurl.Http.Configuration;
using NBitcoin;
using NBitcoin.JsonConverters;
using Newtonsoft.Json;
using NTumbleBit;
using NTumbleBit.ClassicTumbler;
using NTumbleBit.JsonConverters;
using NTumbleBit.PuzzlePromise;
using NTumbleBit.PuzzleSolver;
using PuzzlePromise = NTumbleBit.PuzzlePromise;
using PuzzleSolver = NTumbleBit.PuzzleSolver;
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>();
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