@rabby-wallet/rabby-api 0.7.0-alpha.2 → 0.7.0-alpha.3

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
@@ -1,28 +1,28 @@
1
- # rabby-api
2
-
3
- ## Install
4
-
5
- ```bash
6
- npm install @rabby-wallet/rabby-api @debank/common
7
- ```
8
-
9
- ## Usage
10
-
11
- ```ts
12
- import { OpenApiService } from 'rabby-api';
13
- import { WebSignApiPlugin } from 'rabby-api/dist/plugins/web-sign.ts';
14
-
15
- const service = new OpenApiService({
16
- store: {
17
- host: 'https://api.rabby.io',
18
- // you can also customize plugin as you requirement
19
- },
20
- plugin: WebSignApiPlugin,
21
- });
22
-
23
- // init service
24
- await service.init();
25
-
26
- // call api
27
- await service.getTotalBalance('0x1234');
28
- ```
1
+ # rabby-api
2
+
3
+ ## Install
4
+
5
+ ```bash
6
+ npm install @rabby-wallet/rabby-api @debank/common
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { OpenApiService } from 'rabby-api';
13
+ import { WebSignApiPlugin } from 'rabby-api/dist/plugins/web-sign.ts';
14
+
15
+ const service = new OpenApiService({
16
+ store: {
17
+ host: 'https://api.rabby.io',
18
+ // you can also customize plugin as you requirement
19
+ },
20
+ plugin: WebSignApiPlugin,
21
+ });
22
+
23
+ // init service
24
+ await service.init();
25
+
26
+ // call api
27
+ await service.getTotalBalance('0x1234');
28
+ ```
package/dist/index.d.ts CHANGED
@@ -12,13 +12,12 @@ interface Options {
12
12
  adapter?: AxiosAdapter;
13
13
  clientName?: string;
14
14
  clientVersion?: string;
15
- clientWebHf?: string;
16
15
  }
17
16
  export declare class OpenApiService {
18
17
  #private;
19
18
  store: OpenApiStore;
20
19
  request: RateLimitedAxiosInstance;
21
- constructor({ store, plugin, adapter, clientName, clientVersion, clientWebHf, }: Options);
20
+ constructor({ store, plugin, adapter, clientName, clientVersion, }: Options);
22
21
  setHost: (host: string) => Promise<void>;
23
22
  setHostSync: (host: string) => void;
24
23
  getHost: () => string;
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
18
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
19
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
20
  };
21
- var _OpenApiService_adapter, _OpenApiService_plugin, _OpenApiService_clientName, _OpenApiService_clientVersion, _OpenApiService_clientWebHf;
21
+ var _OpenApiService_adapter, _OpenApiService_plugin, _OpenApiService_clientName, _OpenApiService_clientVersion;
22
22
  import axios from 'axios';
23
23
  import rateLimit from 'axios-rate-limit';
24
24
  import { ethErrors } from 'eth-rpc-errors';
@@ -26,36 +26,21 @@ import { CHAINS, genSignParams, getChain, getChainByNetwork, sleep, } from './ut
26
26
  import { ASYNC_JOB_RETRY_DELAY, ASYNC_JOB_TIMEOUT } from './const';
27
27
  import { omit } from 'lodash';
28
28
  const maxRPS = 500;
29
- function getWebHf() {
30
- var _a, _b, _c, _d;
31
- const hf =
32
- // @ts-expect-error
33
- typeof chrome === 'undefined'
34
- ? ''
35
- : // @ts-expect-error
36
- ((_b = (_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.getURL) === null || _b === void 0 ? void 0 : _b.call(_a, 'bridge.html')) ||
37
- (
38
- // @ts-expect-error
39
- (_d = (_c = chrome === null || chrome === void 0 ? void 0 : chrome.extension) === null || _c === void 0 ? void 0 : _c.getURL) === null || _d === void 0 ? void 0 : _d.call(_c, 'bridge.html')) ||
40
- '';
41
- return hf;
42
- }
43
29
  export class OpenApiService {
44
30
  constructor(_a) {
45
31
  var _b;
46
- var { store, plugin, adapter, clientName = 'Rabby', clientVersion = (_b = process.env.release) !== null && _b !== void 0 ? _b : '0.0.0', clientWebHf = getWebHf(), } = _a;
32
+ var { store, plugin, adapter, clientName = 'Rabby', clientVersion = (_b = process.env.release) !== null && _b !== void 0 ? _b : '0.0.0', } = _a;
47
33
  _OpenApiService_adapter.set(this, void 0);
48
34
  _OpenApiService_plugin.set(this, void 0);
49
35
  _OpenApiService_clientName.set(this, void 0);
50
36
  _OpenApiService_clientVersion.set(this, void 0);
51
- _OpenApiService_clientWebHf.set(this, void 0);
52
37
  this.setHost = (host) => __awaiter(this, void 0, void 0, function* () {
53
38
  this.store.host = host;
54
- yield this.init({ webHf: __classPrivateFieldGet(this, _OpenApiService_clientWebHf, "f") });
39
+ yield this.init();
55
40
  });
56
41
  this.setHostSync = (host) => {
57
42
  this.store.host = host;
58
- this.initSync({ webHf: __classPrivateFieldGet(this, _OpenApiService_clientWebHf, "f") });
43
+ this.initSync();
59
44
  };
60
45
  this.getHost = () => {
61
46
  return this.store.host;
@@ -833,7 +818,6 @@ export class OpenApiService {
833
818
  __classPrivateFieldSet(this, _OpenApiService_adapter, adapter, "f");
834
819
  __classPrivateFieldSet(this, _OpenApiService_clientName, clientName, "f");
835
820
  __classPrivateFieldSet(this, _OpenApiService_clientVersion, clientVersion, "f");
836
- __classPrivateFieldSet(this, _OpenApiService_clientWebHf, clientWebHf, "f");
837
821
  }
838
822
  initSync(options) {
839
823
  var _a, _b;
@@ -878,4 +862,4 @@ export class OpenApiService {
878
862
  this._mountMethods();
879
863
  }
880
864
  }
881
- _OpenApiService_adapter = new WeakMap(), _OpenApiService_plugin = new WeakMap(), _OpenApiService_clientName = new WeakMap(), _OpenApiService_clientVersion = new WeakMap(), _OpenApiService_clientWebHf = new WeakMap();
865
+ _OpenApiService_adapter = new WeakMap(), _OpenApiService_plugin = new WeakMap(), _OpenApiService_clientName = new WeakMap(), _OpenApiService_clientVersion = new WeakMap();
@@ -1,5 +1,8 @@
1
1
  import type { AxiosRequestConfig } from 'axios';
2
2
  export declare type InitOptions = {
3
+ /**
4
+ * @deprecated legacy option, don't need to use it anymore
5
+ */
3
6
  webHf?: string;
4
7
  };
5
8
  export interface RabbyApiPlugin {
@@ -9,10 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
11
11
  import { SIGN_HDS } from '../const';
12
+ function getWebHf() {
13
+ var _a, _b, _c, _d;
14
+ const hf =
15
+ // @ts-expect-error
16
+ typeof chrome === 'undefined'
17
+ ? ''
18
+ : // @ts-expect-error
19
+ ((_b = (_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.getURL) === null || _b === void 0 ? void 0 : _b.call(_a, 'bridge.html')) ||
20
+ (
21
+ // @ts-expect-error
22
+ (_d = (_c = chrome === null || chrome === void 0 ? void 0 : chrome.extension) === null || _c === void 0 ? void 0 : _c.getURL) === null || _d === void 0 ? void 0 : _d.call(_c, 'bridge.html')) ||
23
+ '';
24
+ return hf;
25
+ }
12
26
  export const WebSignApiPlugin = {
13
27
  onInitiateAsync(options) {
14
28
  return __awaiter(this, void 0, void 0, function* () {
15
- yield sign.lW(options === null || options === void 0 ? void 0 : options.webHf);
29
+ yield sign.lW((options === null || options === void 0 ? void 0 : options.webHf) || getWebHf());
16
30
  });
17
31
  },
18
32
  onSignRequest(ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-api",
3
- "version": "0.7.0-alpha.2",
3
+ "version": "0.7.0-alpha.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [