binance 2.2.11 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,23 +11,27 @@
11
11
 
12
12
  Node.js connector for the Binance APIs and WebSockets, with TypeScript & browser support.
13
13
 
14
- - Extremely robust connector with significant trading volume in production (livenet).
15
- - Heavy end-to-end testing with real API calls.
16
- - End-to-end testing before any release.
17
- - Real API calls in e2e tests.
18
- - Support REST APIs for Binance Spot, Margin, Isolated Margin & USDM Futures.
14
+ - Extremely robust & performant connector with significant trading volume in production (livenet).
15
+ - Actively maintained with a modern, promise-driven interface.
16
+ - Support for seamless HMAC and RSA authentication.
17
+ - Passing a private key as a secret will automatically revert to RSA authentication.
18
+ - Supports REST APIs for Binance Spot, Margin, Isolated Margin & USDM Futures.
19
19
  - Strongly typed on most requests and responses.
20
- - Support Websockets for Binance Spot, Margin, Isolated Margin & USDM Futures.
20
+ - Supports Websockets for Binance Spot, Margin, Isolated Margin & USDM Futures.
21
21
  - Event driven messaging.
22
22
  - Smart websocket persistence
23
23
  - Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
24
24
  - Automatically handle listenKey persistence and expiration/refresh.
25
25
  - Emit `reconnected` event when dropped connection is restored.
26
- - Strongly typed on most websocket events.
26
+ - Strongly typed on most websocket events, with typeguards available for TypeScript users.
27
27
  - Optional:
28
- - Automatic beautification of websocket events (from one-letter keys to descriptive words, and strings with floats to numbers).
28
+ - Automatic beautification of Websocket events (from one-letter keys to descriptive words, and strings with floats to numbers).
29
29
  - Automatic beautification of REST responses (parsing numbers in strings to numbers).
30
+ - Heavy end-to-end testing with real API calls.
31
+ - End-to-end testing before any release.
32
+ - Real API calls in e2e tests.
30
33
  - Proxy support via axios integration.
34
+ - Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
31
35
 
32
36
  ## Installation
33
37
 
@@ -10,9 +10,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.signMessage = void 0;
13
+ function str2ab(str) {
14
+ const buf = new ArrayBuffer(str.length);
15
+ const bufView = new Uint8Array(buf);
16
+ for (let i = 0, strLen = str.length; i < strLen; i++) {
17
+ bufView[i] = str.charCodeAt(i);
18
+ }
19
+ return buf;
20
+ }
13
21
  function signMessage(message, secret) {
14
22
  return __awaiter(this, void 0, void 0, function* () {
15
23
  const encoder = new TextEncoder();
24
+ if (secret.includes('BEGIN PRIVATE KEY')) {
25
+ const pemHeader = "-----BEGIN PRIVATE KEY-----";
26
+ const pemFooter = "-----END PRIVATE KEY-----";
27
+ const pemContents = secret.substring(pemHeader.length, secret.length - pemFooter.length);
28
+ const binaryDerString = window.atob(pemContents);
29
+ const binaryDer = str2ab(binaryDerString);
30
+ const key = yield window.crypto.subtle.importKey('pkcs8', binaryDer, { name: 'RSASSA-PKCS1-v1_5', hash: { name: 'SHA-256' } }, false, ['sign']);
31
+ const signature = yield window.crypto.subtle.sign('RSASSA-PKCS1-v1_5', key, encoder.encode(message));
32
+ return btoa(String.fromCharCode(...new Uint8Array(signature)));
33
+ }
16
34
  const key = yield window.crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
17
35
  const signature = yield window.crypto.subtle.sign('HMAC', key, encoder.encode(message));
18
36
  return Array.prototype.map.call(new Uint8Array(signature), (x) => ('00' + x.toString(16)).slice(-2)).join('');
@@ -1 +1 @@
1
- {"version":3,"file":"browser-support.js","sourceRoot":"","sources":["../../src/util/browser-support.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,SAAsB,WAAW,CAAC,OAAe,EAAE,MAAc;;QAC/D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9C,KAAK,EACL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OAAO,CAAC,CAAC,CAAC;QAExF,OAAO,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAC7B,IAAI,UAAU,CAAC,SAAS,CAAC,EACzB,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,IAAI,GAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAC5C,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACb,CAAC;CAAA;AArCD,kCAqCC;AAAA,CAAC"}
@@ -33,6 +33,9 @@ const crypto_1 = require("crypto");
33
33
  const browserMethods = __importStar(require("./browser-support"));
34
34
  function signMessage(message, secret) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
+ if (secret.includes('BEGIN PRIVATE KEY') && typeof crypto_1.createSign === 'function') {
37
+ return crypto_1.createSign('RSA-SHA256').update(message).sign(secret, 'base64');
38
+ }
36
39
  if (typeof crypto_1.createHmac === 'function') {
37
40
  return crypto_1.createHmac('sha256', secret)
38
41
  .update(message)
@@ -1 +1 @@
1
- {"version":3,"file":"node-support.js","sourceRoot":"","sources":["../../src/util/node-support.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAoC;AACpC,kEAAoD;AAEpD,SAAsB,WAAW,CAAC,OAAe,EAAE,MAAc;;QAC/D,IAAI,OAAO,mBAAU,KAAK,UAAU,EAAE;YACpC,OAAO,mBAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;iBAClC,MAAM,CAAC,OAAO,CAAC;iBACf,MAAM,CAAC,KAAK,CAAC,CAAC;SAChB;QAED,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;CAAA;AARD,kCAQC;AAAA,CAAC"}
1
+ {"version":3,"file":"node-support.js","sourceRoot":"","sources":["../../src/util/node-support.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgD;AAChD,kEAAoD;AAEpD,SAAsB,WAAW,CAAC,OAAe,EAAE,MAAc;;QAC/D,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,OAAO,mBAAU,KAAK,UAAU,EAAE;YAC5E,OAAO,mBAAU,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;SACxE;QAED,IAAI,OAAO,mBAAU,KAAK,UAAU,EAAE;YACpC,OAAO,mBAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;iBAClC,MAAM,CAAC,OAAO,CAAC;iBACf,MAAM,CAAC,KAAK,CAAC,CAAC;SAChB;QAED,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,CAAC;CAAA;AAZD,kCAYC;AAAA,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binance",
3
- "version": "2.2.11",
3
+ "version": "2.3.1",
4
4
  "description": "Node.js connector for Binance's REST APIs and WebSockets, with TypeScript & integration tests.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",