Skip to content

Commit 3b1f171

Browse files
authored
Merge pull request #5 from usherlabs/feat/optional-redact
Feat/optional redact
2 parents cde501e + 1dd2109 commit 3b1f171

File tree

8 files changed

+35
-13
lines changed

8 files changed

+35
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,4 @@ This library is licensed under the **MIT License**. See the [LICENSE](https://gi
269269

270270
## Star History
271271

272-
[![Star History Chart](https://api.star-history.com/svg?repos=ccxt/ccxt&type=Date)](https://star-history.com/#ccxt/ccxt&Date)
272+
[![Star History Chart](https://api.star-history.com/svg?repos=ccxt/ccxt&type=Date)](https://star-history.com/#ccxt/ccxt&Date)

js/ccxt.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
44
import * as errors from './src/base/errors.js';
55
import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, LongShortRatio, OrderBooks, OpenInterests, ConstructorArgs } from './src/base/types.js';
66
import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
7-
declare const version = "0.0.6";
7+
declare const version = "0.0.10";
88
import alpaca from './src/alpaca.js';
99
import apex from './src/apex.js';
1010
import ascendex from './src/ascendex.js';

js/ccxt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
3838
import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
3939
//-----------------------------------------------------------------------------
4040
// this is updated by vss.js when building
41-
const version = '0.0.6';
41+
const version = '0.0.10';
4242
Exchange.ccxtVersion = version;
4343
//-----------------------------------------------------------------------------
4444
import alpaca from './src/alpaca.js';

js/src/base/Exchange.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export default class Exchange {
6060
useVerity: boolean;
6161
verityProverUrl: string;
6262
verityMethods: string[];
63+
verityRequestOptions: {
64+
redact: string;
65+
};
6366
minFundingAddressLength: Int;
6467
substituteCommonCurrencyCodes: boolean;
6568
quoteJsonNumbers: boolean;
@@ -332,6 +335,9 @@ export default class Exchange {
332335
setProxyAgents(httpProxy: any, httpsProxy: any, socksProxy: any): any;
333336
loadHttpProxyAgent(): Promise<any>;
334337
getHttpAgentIfNeeded(url: any): any;
338+
addVerityRequestOptions(options: {
339+
redact: string;
340+
}): void;
335341
fetch(url: any, method?: string, headers?: any, body?: any): Promise<any>;
336342
parseJson(jsonString: any): any;
337343
getResponseHeaders(response: any): {};

js/src/base/Exchange.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,9 +2268,12 @@ export default class Exchange {
22682268
this.nodeHttpModuleLoaded = false;
22692269
this.httpAgent = undefined;
22702270
this.httpsAgent = undefined;
2271+
// ! Usher Labs Addition
22712272
this.useVerity = false;
22722273
this.verityProverUrl = "http://localhost:8080";
22732274
this.verityMethods = ["fetchBalance", "fetchDepositAddress", "fetchDepositAddress", "fetchDepositAddresses", "fetchDepositAddressesByNetwork", "fetchDeposits", "withdraw", "fetchFundingHistory", "fetchWithdrawals", "fetchWithdrawal"];
2275+
this.verityRequestOptions = { redact: "" };
2276+
//! ------------------------------
22742277
this.minFundingAddressLength = 1; // used in checkAddress
22752278
this.substituteCommonCurrencyCodes = true; // reserved
22762279
this.quoteJsonNumbers = true; // treat numbers in json as quoted precise strings
@@ -2308,6 +2311,7 @@ export default class Exchange {
23082311
this.last_request_body = undefined;
23092312
this.last_request_url = undefined;
23102313
this.last_request_path = undefined;
2314+
// ! Usher Labs Addition
23112315
this.last_proof = undefined;
23122316
this.id = 'Exchange';
23132317
this.markets = undefined;
@@ -2750,6 +2754,11 @@ export default class Exchange {
27502754
}
27512755
return undefined;
27522756
}
2757+
// ! Usher Labs Addition
2758+
addVerityRequestOptions(options) {
2759+
this.verityRequestOptions = options;
2760+
}
2761+
// ! Usher Labs Addition: Modified to use Verity if instantiated as such. Includes appended headers.
27532762
async fetch(url, method = 'GET', headers = undefined, body = undefined) {
27542763
// load node-http(s) modules only on first call
27552764
if (isNode) {
@@ -2830,21 +2839,19 @@ export default class Exchange {
28302839
}
28312840
}
28322841
try {
2833-
this.last_proof = undefined;
2842+
this.last_proof = undefined; // TODO: I wonder if there's a race condition on last_proof, where another request's proof is passed instead? We should test this.
28342843
const path = url.split("?")[0];
28352844
const idMap = urlToMethodMap[this.id] ?? {};
28362845
const matchedEntry = Object.entries(idMap).find(([prefix]) => path.startsWith(prefix));
28372846
const methodCalled = matchedEntry?.[1] ?? "";
28382847
if (this.verbose) {
28392848
this.log("MethodCalled:", methodCalled + "\n");
28402849
}
2841-
// TODO: make the method Arrays that use verity configurable
28422850
if (this.useVerity && ["get", "post"].includes(method.toLowerCase()) && this.verityMethods.includes(methodCalled)) {
28432851
const client = new verity.VerityClient({ prover_url: this.verityProverUrl });
2844-
const lowercase = Object.keys(axiosConfig.headers).map(h => `req:header:${h.toLowerCase()}`).join(",");
28452852
const response = await client
28462853
.get(axiosConfig.url, axiosConfig)
2847-
.redact(lowercase);
2854+
.redact(this.verityRequestOptions.redact || ""); // ? Should Verity be configured for use on a per request basis always?
28482855
if (this.verbose) {
28492856
this.log("verityProof:", response.proof, "\n\n", "verityNotaryPub:", response.notary_pub_key, "\n");
28502857
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@usherlabs/ccxt",
3-
"version": "0.0.6",
3+
"version": "0.0.10",
44
"description": "A JavaScript cryptocurrency trading library with support for 100+ exchanges. Verifiable data powered by Verity.",
55
"unpkg": "dist/ccxt.browser.min.js",
66
"type": "module",

ts/ccxt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {BaseError, ExchangeError, AuthenticationError, PermissionDenied, Account
4040
//-----------------------------------------------------------------------------
4141
// this is updated by vss.js when building
4242

43-
const version = '0.0.6';
43+
const version = '0.0.10';
4444

4545
(Exchange as any).ccxtVersion = version
4646

ts/src/base/Exchange.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,9 +2466,13 @@ export default class Exchange {
24662466
nodeHttpModuleLoaded: boolean = false;
24672467
httpAgent = undefined;
24682468
httpsAgent = undefined;
2469+
2470+
// ! Usher Labs Addition
24692471
useVerity: boolean = false;
24702472
verityProverUrl = "http://localhost:8080";
24712473
verityMethods: string[] = ["fetchBalance", "fetchDepositAddress", "fetchDepositAddress", "fetchDepositAddresses", "fetchDepositAddressesByNetwork", "fetchDeposits", "withdraw", "fetchFundingHistory", "fetchWithdrawals", "fetchWithdrawal"];
2474+
verityRequestOptions: { redact: string } = { redact: "" };
2475+
//! ------------------------------
24722476

24732477
minFundingAddressLength: Int = 1 // used in checkAddress
24742478
substituteCommonCurrencyCodes: boolean = true // reserved
@@ -2544,6 +2548,7 @@ export default class Exchange {
25442548
last_request_body = undefined
25452549
last_request_url = undefined
25462550
last_request_path = undefined
2551+
// ! Usher Labs Addition
25472552
last_proof: string | undefined = undefined
25482553

25492554
id: string = 'Exchange';
@@ -3060,7 +3065,12 @@ export default class Exchange {
30603065
return undefined;
30613066
}
30623067

3068+
// ! Usher Labs Addition
3069+
addVerityRequestOptions(options: { redact: string }) {
3070+
this.verityRequestOptions = options;
3071+
}
30633072

3073+
// ! Usher Labs Addition: Modified to use Verity if instantiated as such. Includes appended headers.
30643074
async fetch(url, method = 'GET', headers: any = undefined, body: any = undefined) {
30653075

30663076
// load node-http(s) modules only on first call
@@ -3144,7 +3154,8 @@ export default class Exchange {
31443154
}
31453155

31463156
try {
3147-
this.last_proof = undefined;
3157+
this.last_proof = undefined; // TODO: I wonder if there's a race condition on last_proof, where another request's proof is passed instead? We should test this.
3158+
31483159
const path = url.split("?")[0];
31493160
const idMap = urlToMethodMap[this.id] ?? {};
31503161

@@ -3157,13 +3168,11 @@ export default class Exchange {
31573168
this.log("MethodCalled:", methodCalled+ "\n");
31583169
}
31593170

3160-
// TODO: make the method Arrays that use verity configurable
31613171
if (this.useVerity && ["get", "post"].includes(method.toLowerCase()) && this.verityMethods.includes(methodCalled)) {
31623172
const client = new verity.VerityClient({ prover_url: this.verityProverUrl });
3163-
const lowercase = Object.keys(axiosConfig.headers).map(h => `req:header:${h.toLowerCase()}`).join(",");
31643173
const response = await client
31653174
.get(axiosConfig.url, axiosConfig)
3166-
.redact(lowercase);
3175+
.redact(this.verityRequestOptions.redact || ""); // ? Should Verity be configured for use on a per request basis always?
31673176
if (this.verbose) {
31683177
this.log("verityProof:", response.proof, "\n\n", "verityNotaryPub:", response.notary_pub_key, "\n");
31693178
}

0 commit comments

Comments
 (0)