public static string signRequest(String method, String url, CreateWallet.Request args, string key) { //var sig = Utils.signMessage('hola', '09458c090a69a38368975fb68115df2f4b0ab7d1bc463fc60c67aa1730641d6c'); //should.exist(sig); //sig.should.equal('3045022100f2e3369dd4813d4d42aa2ed74b5cf8e364a8fa13d43ec541e4bc29525e0564c302205b37a7d1ca73f684f91256806cdad4b320b4ed3000bee2e388bcec106e0280e0'); String json = JsonConvert.SerializeObject(args); String message = String.Format("{0}|{1}|{2}", method.ToLower(), url, json); //var message = [method.toLowerCase(), url, JSON.stringify(args)].join('|'); NBitcoin.BitcoinSecret s = new BitcoinSecret(key); return(s.PrivateKey.SignMessage(message)); }
public async Task <string> createWallet(String walletName, String copayerName, Int16 m, Int16 n, opts opts) { Cred cred = new Cred() { copayerId = copayerName, network = "testnet", requestPrivKey = "tprv8dxkXXLevuHXR3tLvBkaDLyCnQxsQQVafnDMEQNds8r8tjSPfNTGD5ShtpP8QeTdtCoWGmrMC5gs9j7ap8ATdSsAD2KCv87BGdzPWwmdJt2", xPrivKey = "cNaQCDwmmh4dS9LzCgVtyy1e1xjCJ21GUDHe9K98nzb689JvinGV" }; CreateWallet.Request request = new CreateWallet.Request() { m = m, n = n, name = walletName, pubKey = "02fcba7ecf41bc7e1be4ee122d9d22e3333671eb0a3a87b5cdf099d59874e1940f", network = "testnet" }; String url = BWS_INSTANCE_URL + "/v2/wallets/"; String reqSignature = Utils.signRequest("GET", url, request, cred.xPrivKey); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("x-identity", cred.copayerId); client.DefaultRequestHeaders.Add("x-signature", reqSignature); String json = JsonConvert.SerializeObject(request); StringContent requestContent = new StringContent(json, Encoding.UTF8, "application/json"); using (HttpResponseMessage responseMessage = await client.PostAsync(url, requestContent)) { if (responseMessage.IsSuccessStatusCode) { String responseContent = await responseMessage.Content.ReadAsStringAsync(); CreateWallet.Response response = JsonConvert.DeserializeObject <CreateWallet.Response>(responseContent); String share = buildSecret(response.walletId, cred.xPrivKey, "testnet"); return(share); } else { throw new InvalidOperationException(); } } }
public async Task <CreateWallet.Response> createWallet( String walletName, String copayerName, Int16 m, Int16 n ) { CreateWallet.Request request = new CreateWallet.Request() { m = m, n = n, name = walletName, pubKey = this.credentials.walletPubKey, network = this.network == Network.Main ? "livenet" : "testnet" }; String url = this.baseUrl + "/v2/wallets/"; HttpClient client = new HttpClient(); String json = JsonConvert.SerializeObject(request); StringContent requestContent = new StringContent(json, Encoding.UTF8, "application/json"); Console.WriteLine("Create wallet request"); Console.WriteLine(json); using (HttpResponseMessage responseMessage = await client.PostAsync(url, requestContent)) { if (responseMessage.IsSuccessStatusCode) { String responseContent = await responseMessage.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <CreateWallet.Response>(responseContent)); } else { Console.Out.WriteLine("Error"); Console.Out.WriteLine(responseMessage.StatusCode); Console.Out.WriteLine(await responseMessage.Content.ReadAsStringAsync()); throw new InvalidOperationException(); } } }