@xelis/sdk 0.5.17 → 0.6.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 XELIS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -12,33 +12,67 @@ Install library with NPM.
12
12
 
13
13
  Import library and start working :).
14
14
 
15
- Use http/rpc connection.
15
+ Use Daemon HTTP RPC connection.
16
16
 
17
17
  ```js
18
- import { TESTNET_NODE_RPC } from '@xelis/sdk/config/nodes'
18
+ import { TESTNET_NODE_RPC } from '@xelis/sdk/config'
19
19
  import DaemonRPC from '@xelis/sdk/daemon/rpc'
20
20
 
21
21
  const main = async () => {
22
- const daemonRPC = new DaemonRPC(TESTNET_NODE_RPC)
23
- const info = await daemonRPC.getInfo()
22
+ const daemon = new DaemonRPC(TESTNET_NODE_RPC)
23
+ const info = await daemon.getInfo()
24
24
  console.log(info)
25
25
  }
26
26
 
27
27
  main()
28
28
  ```
29
29
 
30
- Use websocket connection.
30
+ Use Daemon WebSocket RPC connection.
31
31
 
32
32
  ```js
33
- import { TESTNET_NODE_WS } from '@xelis/sdk/config/nodes'
33
+ import { TESTNET_NODE_WS } from '@xelis/sdk/config'
34
34
  import DaemonWS from '@xelis/sdk/daemon/websocket'
35
35
 
36
36
  const main = async () => {
37
- const daemonWS = new DaemonWS()
38
- await daemonWS.connect(TESTNET_NODE_WS)
39
- const info = await daemonWS.getInfo()
37
+ const daemon = new DaemonWS()
38
+ await daemon.connect(TESTNET_NODE_WS)
39
+ const info = await daemon.methods.getInfo()
40
40
  console.log(info)
41
41
  }
42
42
 
43
43
  main()
44
44
  ```
45
+
46
+ Use Wallet WebSocket RPC connection.
47
+
48
+ ```js
49
+ import { LOCAL_WALLET_WS } from '@xelis/sdk/config'
50
+ import DaemonWS from '@xelis/sdk/wallet/websocket'
51
+
52
+ const main = async () => {
53
+ const wallet = new WalletWS(`test`, `test`) // username, password
54
+ await wallet.connect(LOCAL_WALLET_WS)
55
+ const address = await wallet.methods.getAddress()
56
+ console.log(address)
57
+ }
58
+
59
+ main()
60
+ ```
61
+
62
+ Use XSWD protocol.
63
+
64
+ ```js
65
+ import { LOCAL_XSWD_WS } from '@xelis/sdk/config'
66
+ import XSWD from '@xelis/sdk/xswd/websocket'
67
+
68
+ const main = async () => {
69
+ const xswd = new XSWD()
70
+ await xswd.connect(LOCAL_XSWD_WS)
71
+ const info = await xswd.daemon.getInfo()
72
+ console.log(info)
73
+ const address = await xswd.wallet.getAddress()
74
+ console.log(address)
75
+ }
76
+
77
+ main()
78
+ ```
package/config.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ export declare const DAEMON_RPC_PORT = "8080";
2
+ export declare const WALLET_RPC_PORT = "8081";
3
+ export declare const XSWD_PORT = "44325";
4
+ export declare const MAINNET_NODE_URL = "node.xelis.io";
5
+ export declare const TESTNET_NODE_URL = "testnet-node.xelis.io";
6
+ export declare const LOCAL_NODE_URL: string;
7
+ export declare const MAINNET_NODE_RPC: string;
8
+ export declare const TESTNET_NODE_RPC: string;
9
+ export declare const LOCAL_NODE_RPC: string;
10
+ export declare const MAINNET_NODE_WS: string;
11
+ export declare const TESTNET_NODE_WS: string;
12
+ export declare const LOCAL_NODE_WS: string;
13
+ export declare const LOCAL_WALLET_URL: string;
14
+ export declare const LOCAL_WALLET_RPC: string;
15
+ export declare const LOCAL_WALLET_WS: string;
16
+ export declare const LOCAL_XSWD_URL: string;
17
+ export declare const LOCAL_XSWD_WS: string;
18
+ declare const _default: {
19
+ MAINNET_NODE_URL: string;
20
+ TESTNET_NODE_URL: string;
21
+ MAINNET_NODE_RPC: string;
22
+ TESTNET_NODE_RPC: string;
23
+ LOCAL_NODE_RPC: string;
24
+ MAINNET_NODE_WS: string;
25
+ TESTNET_NODE_WS: string;
26
+ LOCAL_NODE_WS: string;
27
+ DAEMON_RPC_PORT: string;
28
+ WALLET_RPC_PORT: string;
29
+ XSWD_PORT: string;
30
+ LOCAL_WALLET_URL: string;
31
+ LOCAL_WALLET_RPC: string;
32
+ LOCAL_WALLET_WS: string;
33
+ LOCAL_XSWD_URL: string;
34
+ LOCAL_XSWD_WS: string;
35
+ };
36
+ export default _default;
package/config.js ADDED
@@ -0,0 +1,25 @@
1
+ export const DAEMON_RPC_PORT = `8080`;
2
+ export const WALLET_RPC_PORT = `8081`;
3
+ export const XSWD_PORT = `44325`;
4
+ export const MAINNET_NODE_URL = `node.xelis.io`;
5
+ export const TESTNET_NODE_URL = `testnet-node.xelis.io`;
6
+ export const LOCAL_NODE_URL = `127.0.0.1:${DAEMON_RPC_PORT}`;
7
+ export const MAINNET_NODE_RPC = `https://${MAINNET_NODE_URL}/json_rpc`;
8
+ export const TESTNET_NODE_RPC = `https://${TESTNET_NODE_URL}/json_rpc`;
9
+ export const LOCAL_NODE_RPC = `http://${LOCAL_NODE_URL}/json_rpc`;
10
+ export const MAINNET_NODE_WS = `wss://${MAINNET_NODE_URL}/json_rpc`;
11
+ export const TESTNET_NODE_WS = `wss://${TESTNET_NODE_URL}/json_rpc`;
12
+ export const LOCAL_NODE_WS = `ws://${LOCAL_NODE_URL}/json_rpc`;
13
+ export const LOCAL_WALLET_URL = `127.0.0.1:${WALLET_RPC_PORT}`;
14
+ export const LOCAL_WALLET_RPC = `http://${LOCAL_WALLET_URL}/json_rpc`;
15
+ export const LOCAL_WALLET_WS = `ws://${LOCAL_WALLET_URL}/json_rpc`;
16
+ export const LOCAL_XSWD_URL = `127.0.0.1:${XSWD_PORT}`;
17
+ export const LOCAL_XSWD_WS = `ws://${LOCAL_XSWD_URL}/xswd`;
18
+ export default {
19
+ MAINNET_NODE_URL, TESTNET_NODE_URL,
20
+ MAINNET_NODE_RPC, TESTNET_NODE_RPC, LOCAL_NODE_RPC,
21
+ MAINNET_NODE_WS, TESTNET_NODE_WS, LOCAL_NODE_WS,
22
+ DAEMON_RPC_PORT, WALLET_RPC_PORT, XSWD_PORT,
23
+ LOCAL_WALLET_URL, LOCAL_WALLET_RPC, LOCAL_WALLET_WS,
24
+ LOCAL_XSWD_URL, LOCAL_XSWD_WS
25
+ };
@@ -1,7 +1,12 @@
1
1
  import { MessageEvent } from 'ws';
2
2
  import { Block, GetInfoResult, RPCEventResult, Transaction, TopoHeightRangeParams, P2PStatusResult, Balance, GetBalanceAtTopoHeightParams, GetBalanceResult, HeightRangeParams, BlockOrdered, GetBalanceParams, GetAccountsParams, GetBlockAtTopoHeightParams, GetBlockByHashParams, GetBlocksAtHeightParams, GetTopBlockParams, GetNonceParams, GetNonceResult, GetAccountHistoryParams, AccounHistory, Peer, PeerPeerListUpdated, PeerPeerDisconnected, DevFee, DiskSize, AssetWithData, AssetData, GetAssetParams, HasBalanceParams, HasBalanceResult, IsTxExecutedInBlockParams, BlockOrphaned } from './types';
3
3
  import { WS as BaseWS } from '../lib/websocket';
4
- declare class WS extends BaseWS {
4
+ export declare class DaemonMethods {
5
+ ws: BaseWS;
6
+ prefix: string;
7
+ constructor(ws: BaseWS, prefix?: string);
8
+ listenEvent<T>(event: string, onData: (msgEvent: MessageEvent, data?: T, err?: Error) => void): Promise<() => Promise<void>>;
9
+ dataCall<T>(method: string, params?: any): Promise<T>;
5
10
  onNewBlock(onData: (msgEvent: MessageEvent, data?: Block & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
6
11
  onTransactionAddedInMempool(onData: (msgEvent: MessageEvent, data?: Transaction & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
7
12
  onTransactionExecuted(onData: (msgEvent: MessageEvent, data?: Transaction & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
@@ -49,4 +54,8 @@ declare class WS extends BaseWS {
49
54
  getSizeOnDisk(): Promise<DiskSize>;
50
55
  isTxExecutedInBlock(params: IsTxExecutedInBlockParams): Promise<boolean>;
51
56
  }
57
+ declare class WS extends BaseWS {
58
+ methods: DaemonMethods;
59
+ constructor();
60
+ }
52
61
  export default WS;
@@ -1,6 +1,16 @@
1
1
  import { RPCEvent, RPCMethod } from './types';
2
2
  import { WS as BaseWS } from '../lib/websocket';
3
- class WS extends BaseWS {
3
+ export class DaemonMethods {
4
+ constructor(ws, prefix = "") {
5
+ this.ws = ws;
6
+ this.prefix = prefix;
7
+ }
8
+ async listenEvent(event, onData) {
9
+ return this.ws.listenEvent(this.prefix + event, onData);
10
+ }
11
+ dataCall(method, params) {
12
+ return this.ws.dataCall(this.prefix + method, params);
13
+ }
4
14
  onNewBlock(onData) {
5
15
  return this.listenEvent(RPCEvent.NewBlock, onData);
6
16
  }
@@ -140,4 +150,10 @@ class WS extends BaseWS {
140
150
  return this.dataCall(RPCMethod.IsTxExecutedInBlock, params);
141
151
  }
142
152
  }
153
+ class WS extends BaseWS {
154
+ constructor() {
155
+ super();
156
+ this.methods = new DaemonMethods(this);
157
+ }
158
+ }
143
159
  export default WS;
package/lib/rpc.d.ts CHANGED
@@ -3,5 +3,5 @@ export declare class RPC {
3
3
  endpoint: string;
4
4
  timeout: number;
5
5
  constructor(endpoint: string);
6
- post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
6
+ post<T>(method: string, params?: any, headers?: Headers): Promise<RPCResponse<T>>;
7
7
  }
package/lib/rpc.js CHANGED
@@ -3,14 +3,17 @@ export class RPC {
3
3
  this.endpoint = endpoint;
4
4
  this.timeout = 3000;
5
5
  }
6
- async post(method, params) {
6
+ async post(method, params, headers) {
7
7
  try {
8
8
  const controller = new AbortController();
9
9
  const body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params });
10
10
  const timeoutId = setTimeout(() => {
11
11
  controller.abort();
12
12
  }, this.timeout);
13
+ headers = headers || new Headers();
14
+ headers.set(`Content-Type`, `application/json`);
13
15
  const res = await fetch(this.endpoint, {
16
+ headers,
14
17
  method: `POST`,
15
18
  body,
16
19
  signal: controller.signal
@@ -28,6 +31,7 @@ export class RPC {
28
31
  }
29
32
  }
30
33
  catch (err) {
34
+ console.log(err);
31
35
  return Promise.reject(err);
32
36
  }
33
37
  }
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export interface RPCRequest {
2
- id: number;
2
+ id: number | null;
3
3
  jsonrpc: string;
4
4
  method: string;
5
5
  params: string;
@@ -1,5 +1,7 @@
1
- import { MessageEvent } from 'ws';
1
+ /// <reference types="node" />
2
+ import { ClientOptions, MessageEvent } from 'ws';
2
3
  import WebSocket from 'isomorphic-ws';
4
+ import { ClientRequestArgs } from 'http';
3
5
  import { RPCResponse } from './types';
4
6
  export declare class WS {
5
7
  endpoint: string;
@@ -8,20 +10,21 @@ export declare class WS {
8
10
  unsubscribeSuspense: number;
9
11
  reconnectOnConnectionLoss: boolean;
10
12
  maxConnectionTries: number;
13
+ options?: ClientOptions | ClientRequestArgs;
11
14
  connectionTries: number;
12
15
  methodIdIncrement: number;
13
16
  private events;
14
- constructor();
17
+ constructor(options?: ClientOptions | ClientRequestArgs);
15
18
  connect(endpoint: string): Promise<unknown>;
16
19
  tryReconnect(): void;
17
20
  close(): void;
18
21
  private clearEvent;
19
22
  closeAllListens(event: string): Promise<void>;
20
23
  listenEvent<T>(event: string, onData: (msgEvent: MessageEvent, data?: T, err?: Error) => void): Promise<() => Promise<void>>;
21
- call<T>(method: string, params?: any): Promise<RPCResponse<T>>;
24
+ call<T>(method: string, params?: any, overwriteData?: string): Promise<RPCResponse<T>>;
22
25
  dataCall<T>(method: string, params?: any): Promise<T>;
23
26
  createRequestMethod(method: string, params?: any): {
24
27
  data: string;
25
- id: number;
28
+ id: number | null;
26
29
  };
27
30
  }
package/lib/websocket.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
2
  import to from 'await-to-js';
3
3
  export class WS {
4
- constructor() {
4
+ constructor(options) {
5
5
  this.connectionTries = 0;
6
6
  this.methodIdIncrement = 0;
7
7
  this.endpoint = "";
@@ -10,6 +10,7 @@ export class WS {
10
10
  this.unsubscribeSuspense = 1000;
11
11
  this.maxConnectionTries = 3;
12
12
  this.reconnectOnConnectionLoss = true;
13
+ this.options = options;
13
14
  }
14
15
  connect(endpoint) {
15
16
  // force disconnect if already connected
@@ -19,7 +20,7 @@ export class WS {
19
20
  this.events = {};
20
21
  this.connectionTries = 0;
21
22
  return new Promise((resolve, reject) => {
22
- this.socket = new WebSocket(endpoint);
23
+ this.socket = new WebSocket(endpoint, this.options);
23
24
  this.endpoint = endpoint;
24
25
  this.socket.addEventListener(`open`, (event) => {
25
26
  resolve(event);
@@ -43,7 +44,7 @@ export class WS {
43
44
  if (this.connectionTries > this.maxConnectionTries) {
44
45
  return;
45
46
  }
46
- this.socket = new WebSocket(this.endpoint);
47
+ this.socket = new WebSocket(this.endpoint, this.options);
47
48
  this.socket.addEventListener(`open`, () => {
48
49
  this.connectionTries = 0;
49
50
  });
@@ -143,18 +144,23 @@ export class WS {
143
144
  };
144
145
  return Promise.resolve(closeListen);
145
146
  }
146
- call(method, params) {
147
+ call(method, params, overwriteData) {
147
148
  return new Promise((resolve, reject) => {
148
149
  if (!this.socket)
149
150
  return reject(new Error(`Socket is not initialized.`));
150
151
  if (this.socket.readyState !== WebSocket.OPEN)
151
152
  return reject(new Error(`Can't send msg. Socket is not opened.`));
152
- const { data, id } = this.createRequestMethod(method, params);
153
+ let requestMethod = this.createRequestMethod(method, params);
154
+ // for XSWD we want to send the application data without request method wrapping
155
+ if (overwriteData) {
156
+ requestMethod.id = null;
157
+ requestMethod.data = overwriteData;
158
+ }
153
159
  let timeoutId = null;
154
160
  const onMessage = (msgEvent) => {
155
161
  if (typeof msgEvent.data === `string`) {
156
162
  const data = JSON.parse(msgEvent.data);
157
- if (data.id === id) {
163
+ if (data.id === requestMethod.id) {
158
164
  clearTimeout(timeoutId);
159
165
  this.socket && this.socket.removeEventListener(`message`, onMessage);
160
166
  if (data.error)
@@ -166,12 +172,14 @@ export class WS {
166
172
  };
167
173
  // make sure you listen before sending data
168
174
  this.socket && this.socket.addEventListener(`message`, onMessage); // we don't use { once: true } option because of timeout feature
169
- timeoutId = setTimeout(() => {
170
- this.socket && this.socket.removeEventListener(`message`, onMessage);
171
- reject(new Error(`timeout`));
172
- }, this.timeout);
175
+ if (this.timeout > 0) {
176
+ timeoutId = setTimeout(() => {
177
+ this.socket && this.socket.removeEventListener(`message`, onMessage);
178
+ reject(new Error(`timeout`));
179
+ }, this.timeout);
180
+ }
173
181
  if (this.socket && this.socket.readyState === WebSocket.OPEN) {
174
- this.socket.send(data);
182
+ this.socket.send(requestMethod.data);
175
183
  }
176
184
  });
177
185
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.17",
2
+ "version": "0.6.0",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {
@@ -9,7 +9,7 @@
9
9
  "homepage": "https://github.com/xelis-project/xelis-js-sdk#readme",
10
10
  "scripts": {
11
11
  "test": "jest",
12
- "build": "rm -rf ./dist && npx tsc --declaration && cp package.json ./dist && cp README.md ./dist",
12
+ "build": "rm -rf ./dist && npx tsc --declaration && cp package.json README.md LICENSE ./dist",
13
13
  "publish-npm": "npm run build && cd ./dist && npm publish"
14
14
  },
15
15
  "devDependencies": {
@@ -22,6 +22,7 @@
22
22
  "dependencies": {
23
23
  "await-to-js": "^3.0.0",
24
24
  "isomorphic-ws": "^5.0.0",
25
+ "js-base64": "^3.7.6",
25
26
  "react": "^18.2.0",
26
27
  "ws": "^8.12.1"
27
28
  }
package/wallet/rpc.d.ts CHANGED
@@ -1,19 +1,23 @@
1
1
  import { Transaction, GetAssetParams } from '../daemon/types';
2
2
  import { GetAddressParams, SplitAddressParams, SplitAddressResult, BuildTransactionParams, BuildTransactionResult, ListTransactionParams } from './types';
3
3
  import { RPC as BaseRPC } from '../lib/rpc';
4
+ import { RPCResponse } from '../lib/types';
4
5
  declare class RPC extends BaseRPC {
5
- getVersion(): Promise<import("../lib/types").RPCResponse<string>>;
6
- getNonce(): Promise<import("../lib/types").RPCResponse<number>>;
7
- getTopoheight(): Promise<import("../lib/types").RPCResponse<number>>;
8
- getAddress(params?: GetAddressParams): Promise<import("../lib/types").RPCResponse<string>>;
9
- rescan(): Promise<import("../lib/types").RPCResponse<void>>;
10
- splitAddress(params: SplitAddressParams): Promise<import("../lib/types").RPCResponse<SplitAddressResult>>;
11
- getBalance(asset?: string): Promise<import("../lib/types").RPCResponse<number>>;
12
- getTrackedAssets(): Promise<import("../lib/types").RPCResponse<string[]>>;
13
- getAssetPrecision(params: GetAssetParams): Promise<import("../lib/types").RPCResponse<number>>;
14
- getTransaction(hash: string): Promise<import("../lib/types").RPCResponse<Transaction>>;
15
- buildTransaction(params: BuildTransactionParams): Promise<import("../lib/types").RPCResponse<BuildTransactionResult>>;
16
- listTransactions(params?: ListTransactionParams): Promise<import("../lib/types").RPCResponse<Transaction[]>>;
17
- isOnline(): Promise<import("../lib/types").RPCResponse<boolean>>;
6
+ auth: string;
7
+ constructor(endpoint: string, username: string, password: string);
8
+ post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
9
+ getVersion(): Promise<RPCResponse<string>>;
10
+ getNonce(): Promise<RPCResponse<number>>;
11
+ getTopoheight(): Promise<RPCResponse<number>>;
12
+ getAddress(params?: GetAddressParams): Promise<RPCResponse<string>>;
13
+ rescan(): Promise<RPCResponse<void>>;
14
+ splitAddress(params: SplitAddressParams): Promise<RPCResponse<SplitAddressResult>>;
15
+ getBalance(asset?: string): Promise<RPCResponse<number>>;
16
+ getTrackedAssets(): Promise<RPCResponse<string[]>>;
17
+ getAssetPrecision(params: GetAssetParams): Promise<RPCResponse<number>>;
18
+ getTransaction(hash: string): Promise<RPCResponse<Transaction>>;
19
+ buildTransaction(params: BuildTransactionParams): Promise<RPCResponse<BuildTransactionResult>>;
20
+ listTransactions(params?: ListTransactionParams): Promise<RPCResponse<Transaction[]>>;
21
+ isOnline(): Promise<RPCResponse<boolean>>;
18
22
  }
19
23
  export default RPC;
package/wallet/rpc.js CHANGED
@@ -1,6 +1,17 @@
1
+ import { Base64 } from 'js-base64';
1
2
  import { RPCMethod } from './types';
2
3
  import { RPC as BaseRPC } from '../lib/rpc';
3
4
  class RPC extends BaseRPC {
5
+ constructor(endpoint, username, password) {
6
+ super(endpoint);
7
+ const authValue = Base64.encode(`${username}:${password}`);
8
+ this.auth = `Basic ${authValue}`;
9
+ }
10
+ async post(method, params) {
11
+ const headers = new Headers();
12
+ headers.set(`Authorization`, this.auth);
13
+ return super.post(method, params, headers);
14
+ }
4
15
  getVersion() {
5
16
  return this.post(RPCMethod.GetVersion);
6
17
  }
@@ -10,7 +21,7 @@ class RPC extends BaseRPC {
10
21
  getTopoheight() {
11
22
  return this.post(RPCMethod.GetTopoheight);
12
23
  }
13
- getAddress(params) {
24
+ getAddress(params = {}) {
14
25
  return this.post(RPCMethod.GetAddress, params);
15
26
  }
16
27
  rescan() {
package/wallet/types.d.ts CHANGED
@@ -45,3 +45,16 @@ export declare enum RPCMethod {
45
45
  SignData = "sign_data",
46
46
  EstimateFees = "estimate_fees"
47
47
  }
48
+ export declare enum Permission {
49
+ Ask = 0,
50
+ AcceptAlways = 1,
51
+ DenyAlways = 2
52
+ }
53
+ export interface ApplicationData {
54
+ id: string;
55
+ name: string;
56
+ description: string;
57
+ url?: string;
58
+ permissions: Map<string, Permission>;
59
+ signature?: string;
60
+ }
package/wallet/types.js CHANGED
@@ -17,3 +17,9 @@ export var RPCMethod;
17
17
  RPCMethod["SignData"] = "sign_data";
18
18
  RPCMethod["EstimateFees"] = "estimate_fees";
19
19
  })(RPCMethod || (RPCMethod = {}));
20
+ export var Permission;
21
+ (function (Permission) {
22
+ Permission[Permission["Ask"] = 0] = "Ask";
23
+ Permission[Permission["AcceptAlways"] = 1] = "AcceptAlways";
24
+ Permission[Permission["DenyAlways"] = 2] = "DenyAlways";
25
+ })(Permission || (Permission = {}));
@@ -1,7 +1,11 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
2
  import { GetAssetParams, Transaction } from '../daemon/types';
3
3
  import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult } from './types';
4
- declare class WS extends BaseWS {
4
+ export declare class WalletMethods {
5
+ ws: BaseWS;
6
+ prefix: string;
7
+ constructor(ws: BaseWS, prefix?: string);
8
+ dataCall<T>(method: string, params?: any): Promise<T>;
5
9
  getVersion(): Promise<string>;
6
10
  getNetwork(): Promise<string>;
7
11
  getNonce(): Promise<number>;
@@ -17,4 +21,8 @@ declare class WS extends BaseWS {
17
21
  listTransactions(params?: ListTransactionParams): Promise<Transaction[]>;
18
22
  isOnline(): Promise<boolean>;
19
23
  }
24
+ declare class WS extends BaseWS {
25
+ methods: WalletMethods;
26
+ constructor(username: string, password: string);
27
+ }
20
28
  export default WS;
@@ -1,6 +1,13 @@
1
1
  import { WS as BaseWS } from '../lib/websocket';
2
2
  import { RPCMethod } from './types';
3
- class WS extends BaseWS {
3
+ export class WalletMethods {
4
+ constructor(ws, prefix = "") {
5
+ this.ws = ws;
6
+ this.prefix = prefix;
7
+ }
8
+ dataCall(method, params) {
9
+ return this.ws.dataCall(this.prefix + method, params);
10
+ }
4
11
  getVersion() {
5
12
  return this.dataCall(RPCMethod.GetVersion);
6
13
  }
@@ -13,7 +20,7 @@ class WS extends BaseWS {
13
20
  getTopoheight() {
14
21
  return this.dataCall(RPCMethod.GetTopoheight);
15
22
  }
16
- getAddress(params) {
23
+ getAddress(params = {}) {
17
24
  return this.dataCall(RPCMethod.GetAddress, params);
18
25
  }
19
26
  rescan() {
@@ -44,4 +51,10 @@ class WS extends BaseWS {
44
51
  return this.dataCall(RPCMethod.IsOnline);
45
52
  }
46
53
  }
54
+ class WS extends BaseWS {
55
+ constructor(username, password) {
56
+ super({ auth: `${username}:${password}` });
57
+ this.methods = new WalletMethods(this);
58
+ }
59
+ }
47
60
  export default WS;
@@ -0,0 +1,13 @@
1
+ export declare enum Permission {
2
+ Ask = 0,
3
+ AcceptAlways = 1,
4
+ DenyAlways = 2
5
+ }
6
+ export interface ApplicationData {
7
+ id: string;
8
+ name: string;
9
+ description: string;
10
+ url?: string;
11
+ permissions: Map<string, Permission>;
12
+ signature?: string;
13
+ }
package/xswd/types.js ADDED
@@ -0,0 +1,6 @@
1
+ export var Permission;
2
+ (function (Permission) {
3
+ Permission[Permission["Ask"] = 0] = "Ask";
4
+ Permission[Permission["AcceptAlways"] = 1] = "AcceptAlways";
5
+ Permission[Permission["DenyAlways"] = 2] = "DenyAlways";
6
+ })(Permission || (Permission = {}));
@@ -0,0 +1,11 @@
1
+ import { WS as BaseWS } from '../lib/websocket';
2
+ import { ApplicationData } from '../wallet/types';
3
+ import { DaemonMethods } from '../daemon/websocket';
4
+ import { WalletMethods } from '../wallet/websocket';
5
+ declare class WS extends BaseWS {
6
+ daemon: DaemonMethods;
7
+ wallet: WalletMethods;
8
+ constructor();
9
+ authorize(app: ApplicationData): Promise<import("../lib/types").RPCResponse<unknown>>;
10
+ }
11
+ export default WS;
@@ -0,0 +1,16 @@
1
+ import { WS as BaseWS } from '../lib/websocket';
2
+ import { DaemonMethods } from '../daemon/websocket';
3
+ import { WalletMethods } from '../wallet/websocket';
4
+ class WS extends BaseWS {
5
+ constructor() {
6
+ super();
7
+ this.timeout = 0;
8
+ this.daemon = new DaemonMethods(this, "node.");
9
+ this.wallet = new WalletMethods(this, "wallet.");
10
+ }
11
+ authorize(app) {
12
+ const data = JSON.stringify(app);
13
+ return this.call("", {}, data);
14
+ }
15
+ }
16
+ export default WS;
package/config/nodes.d.ts DELETED
@@ -1,15 +0,0 @@
1
- export declare const NODE_URL = "node.xelis.io";
2
- export declare const TESTNET_NODE_URL = "testnet-node.xelis.io";
3
- export declare const NODE_RPC: string;
4
- export declare const TESTNET_NODE_RPC: string;
5
- export declare const NODE_WS: string;
6
- export declare const TESTNET_NODE_WS: string;
7
- declare const _default: {
8
- NODE_URL: string;
9
- TESTNET_NODE_URL: string;
10
- NODE_RPC: string;
11
- TESTNET_NODE_RPC: string;
12
- NODE_WS: string;
13
- TESTNET_NODE_WS: string;
14
- };
15
- export default _default;
package/config/nodes.js DELETED
@@ -1,11 +0,0 @@
1
- export const NODE_URL = `node.xelis.io`;
2
- export const TESTNET_NODE_URL = `testnet-node.xelis.io`;
3
- export const NODE_RPC = `https://${NODE_URL}/json_rpc`;
4
- export const TESTNET_NODE_RPC = `https://${TESTNET_NODE_URL}/json_rpc`;
5
- export const NODE_WS = `wss://${NODE_URL}/json_rpc`;
6
- export const TESTNET_NODE_WS = `wss://${TESTNET_NODE_URL}/json_rpc`;
7
- export default {
8
- NODE_URL, TESTNET_NODE_URL,
9
- NODE_RPC, TESTNET_NODE_RPC,
10
- NODE_WS, TESTNET_NODE_WS
11
- };