Skip to content

Commit

Permalink
CYPHERNODE_GATEKEEPER_CERT_CA env variable to provide CN cert PEM con…
Browse files Browse the repository at this point in the history
…tents
  • Loading branch information
gabidi committed Dec 10, 2019
1 parent d196d19 commit 57e39ef
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 109 deletions.
26 changes: 26 additions & 0 deletions src/clients/btcClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,32 @@ exports.client = function (_a) {
}
});
});
},
getUnusedAddressesByPub32Label: function (label) {
return __awaiter(this, void 0, void 0, function () {
var label_unused_addresses;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, get("get_unused_addresses_by_watchlabel", label)];
case 1:
label_unused_addresses = (_a.sent()).label_unused_addresses;
return [2 /*return*/, label_unused_addresses];
}
});
});
},
getTransactionsByPub32Label: function (label) {
return __awaiter(this, void 0, void 0, function () {
var label_txns;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, get("get_txns_by_watchlabel", label)];
case 1:
label_txns = (_a.sent()).label_txns;
return [2 /*return*/, label_txns];
}
});
});
}
};
return api;
Expand Down
66 changes: 52 additions & 14 deletions src/clients/btcClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test("Should be able to get a transactions info", function (t) { return __awaite
switch (_b.label) {
case 0:
_a = t.context, getTxn = _a.getTxn, chain = _a.chain;
if (chain === "test") {
if (chain !== "main") {
t.pass();
return [2 /*return*/];
}
Expand Down Expand Up @@ -269,9 +269,9 @@ test("Should be able to watch a pub32", function (t) { return __awaiter(_this, v
switch (_c.label) {
case 0:
_a = t.context, watchPub32 = _a.watchPub32, chain = _a.chain;
tpub = chain === "test"
? "tpubDAenfwNu5GyCJWv8oqRAckdKMSUoZjgVF5p8WvQwHQeXjDhAHmGrPa4a4y2Fn7HF2nfCLefJanHV3ny1UY25MRVogizB2zRUdAo7Tr9XAjm"
: "xpub6AHA9hZDN11k2ijHMeS5QqHx2KP9aMBRhTDqANMnwVtdyw2TDYRmF8PjpvwUFcL1Et8Hj59S3gTSMcUQ5gAqTz3Wd8EsMTmF3DChhqPQBnU";
tpub = chain === "main"
? "xpub6AHA9hZDN11k2ijHMeS5QqHx2KP9aMBRhTDqANMnwVtdyw2TDYRmF8PjpvwUFcL1Et8Hj59S3gTSMcUQ5gAqTz3Wd8EsMTmF3DChhqPQBnU"
: "tpubDAenfwNu5GyCJWv8oqRAckdKMSUoZjgVF5p8WvQwHQeXjDhAHmGrPa4a4y2Fn7HF2nfCLefJanHV3ny1UY25MRVogizB2zRUdAo7Tr9XAjm";
pub32label = "js_sdkpub32_test";
watchOptions = {
label: pub32label,
Expand All @@ -289,13 +289,13 @@ test("Should be able to watch a pub32", function (t) { return __awaiter(_this, v
});
}); });
test("Should be able to get watched address for 32pub by labe", function (t) { return __awaiter(_this, void 0, void 0, function () {
var getWatchedAddressesByPub32Label, ypubLabel, watchedAddresses;
var getWatchedAddressesByPub32Label, pub32Label, watchedAddresses;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
getWatchedAddressesByPub32Label = t.context.getWatchedAddressesByPub32Label;
ypubLabel = "js_sdkpub32_test";
return [4 /*yield*/, getWatchedAddressesByPub32Label(ypubLabel)];
pub32Label = "js_sdkpub32_test";
return [4 /*yield*/, getWatchedAddressesByPub32Label(pub32Label)];
case 1:
watchedAddresses = _a.sent();
t.true(watchedAddresses.length > 0);
Expand All @@ -308,31 +308,69 @@ test("Should be able to get watched address for 32pub by labe", function (t) { r
});
}); });
test("Should be able to get a watched 32pub's balance by label", function (t) { return __awaiter(_this, void 0, void 0, function () {
var getBalanceByPub32Label, ypubLabel, balance;
var getBalanceByPub32Label, pub32Label, balance;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
getBalanceByPub32Label = t.context.getBalanceByPub32Label;
ypubLabel = "js_sdkpub32_test";
return [4 /*yield*/, getBalanceByPub32Label(ypubLabel)];
pub32Label = "js_sdkpub32_test";
return [4 /*yield*/, getBalanceByPub32Label(pub32Label)];
case 1:
balance = _a.sent();
t.true(!isNaN(balance));
return [2 /*return*/];
}
});
}); });
test("Should be able to get a watched 32pub's unused addresses", function (t) { return __awaiter(_this, void 0, void 0, function () {
var getUnusedAddressesByPub32Label, pub32Label, unusedAddressList;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
getUnusedAddressesByPub32Label = t.context.getUnusedAddressesByPub32Label;
pub32Label = "js_sdkpub32_test";
return [4 /*yield*/, getUnusedAddressesByPub32Label(pub32Label)];
case 1:
unusedAddressList = _a.sent();
t.true(Array.isArray(unusedAddressList));
t.true(unusedAddressList.every(function (_a) {
var address = _a.address, address_pub32_index = _a.address_pub32_index;
return !!address.length && !isNaN(address_pub32_index);
}));
return [2 /*return*/];
}
});
}); });
test("Should be able to get transactions for watch label ", function (t) { return __awaiter(_this, void 0, void 0, function () {
var getTransactionsByPub32Label, pub32Label, pub32Txns;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
getTransactionsByPub32Label = t.context.getTransactionsByPub32Label;
pub32Label = "js_sdkpub32_test";
return [4 /*yield*/, getTransactionsByPub32Label(pub32Label)];
case 1:
pub32Txns = _a.sent();
t.true(Array.isArray(pub32Txns));
t.true(pub32Txns.every(function (_a) {
var amount = _a.amount, txid = _a.txid;
return !!txid.length && !isNaN(amount);
}));
return [2 /*return*/];
}
});
}); });
test("Should be able to unwatch by label", function (t) { return __awaiter(_this, void 0, void 0, function () {
var unwatchPub32ByLabel, ypubLabel, label;
var unwatchPub32ByLabel, pub32Label, label;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
unwatchPub32ByLabel = t.context.unwatchPub32ByLabel;
ypubLabel = "js_sdkpub32_test";
return [4 /*yield*/, unwatchPub32ByLabel(ypubLabel)];
pub32Label = "js_sdkpub32_test";
return [4 /*yield*/, unwatchPub32ByLabel(pub32Label)];
case 1:
label = (_a.sent()).label;
t.is(label, ypubLabel);
t.is(label, pub32Label);
return [2 /*return*/];
}
});
Expand Down
74 changes: 0 additions & 74 deletions src/examples/watchingWalletsAndBalances.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/examples/watchingWalletsAndBalances.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/transport/cypherNodeHttpTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var cryptoUtil_1 = require("../lib/cryptoUtil");
var CypherNodeGatewayUrl = (process && process.env.CYPHER_GATEWAY_URL) || "https://localhost:2009/v0/";
var CypherNodeApiKey = (process && process.env.CYPHERNODE_API_KEY) || "";
var CypherNodeApiKeyID = (process && process.env.CYPHERNODE_API_KEY_ID) || 3;
var CypherNodeCertCAPem = (process && process.env.CYPHERNODE_GATEKEEPER_CERT_CA) || "";
var makeToken = cryptoUtil_1.crypto().makeToken;
exports.default = (function (_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.gatewayUrl, gatewayUrl = _c === void 0 ? CypherNodeGatewayUrl : _c, _d = _b.auth, auth = _d === void 0 ? function () { return makeToken(CypherNodeApiKey, CypherNodeApiKeyID); } : _d;
Expand All @@ -72,6 +73,7 @@ exports.default = (function (_a) {
token = _a.sent();
return [4 /*yield*/, agent
.get("" + gatewayUrl + command + "/" + (payload ? payload : ""))
.ca(CypherNodeCertCAPem)
.set("Authorization", "Bearer " + token)];
case 2:
body = (_a.sent()).body;
Expand All @@ -90,6 +92,7 @@ exports.default = (function (_a) {
token = _a.sent();
return [4 /*yield*/, agent
.post("" + gatewayUrl + command)
.ca(CypherNodeCertCAPem)
.set("Authorization", "Bearer " + token)
.send(payload)];
case 2:
Expand Down
4 changes: 4 additions & 0 deletions src/transport/cypherNodeHttpTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const CypherNodeGatewayUrl =
(process && process.env.CYPHER_GATEWAY_URL) || "https://localhost:2009/v0/";
const CypherNodeApiKey = (process && process.env.CYPHERNODE_API_KEY) || "";
const CypherNodeApiKeyID = (process && process.env.CYPHERNODE_API_KEY_ID) || 3;
const CypherNodeCertCAPem =
(process && process.env.CYPHERNODE_GATEKEEPER_CERT_CA) || "";
const { makeToken } = crypto();
export default ({
gatewayUrl = CypherNodeGatewayUrl,
Expand All @@ -19,13 +21,15 @@ export default ({
const token = await auth();
const { body } = await agent
.get(`${gatewayUrl}${command}/${payload ? payload : ""}`)
.ca(CypherNodeCertCAPem)
.set("Authorization", `Bearer ${token}`);
return body;
},
async post<T>(command: CypherNodeCommand, payload: any): Promise<T> {
const token = await auth();
const { body } = await agent
.post(`${gatewayUrl}${command}`)
.ca(CypherNodeCertCAPem)
.set("Authorization", `Bearer ${token}`)
.send(payload);
return body;
Expand Down

0 comments on commit 57e39ef

Please sign in to comment.