@xelis/sdk 0.8.4 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { TransactionData, Transaction } from '../daemon/types.js';
1
+ import { Transaction } from '../daemon/types';
2
2
  export interface GetAddressParams {
3
3
  integrated_data?: string;
4
4
  }
@@ -9,14 +9,21 @@ export interface SplitAddressResult {
9
9
  address: string;
10
10
  integrated_data: string;
11
11
  }
12
+ export interface FeeBuilder {
13
+ multiplier?: number;
14
+ value?: number;
15
+ }
12
16
  export interface BuildTransactionParams {
13
- tx_type: TransactionData;
17
+ transfers: TransferOut[];
18
+ burn?: TxBurn;
14
19
  broadcast: boolean;
15
- fee?: number;
20
+ fee?: FeeBuilder;
21
+ tx_as_hex: boolean;
16
22
  }
17
23
  export interface BuildTransactionResult {
18
24
  hash: string;
19
25
  data: Transaction;
26
+ txt_as_hex?: string;
20
27
  }
21
28
  export interface ListTransactionParams {
22
29
  min_topoheight?: number;
@@ -38,12 +45,23 @@ export interface TxBurn {
38
45
  asset: string;
39
46
  amount: number;
40
47
  }
48
+ export interface TransferIn {
49
+ asset: string;
50
+ amount: number;
51
+ extra_data?: any;
52
+ }
41
53
  export interface TxIncoming {
42
54
  from: string;
43
- transfers: any;
55
+ transfers: TransferIn[];
56
+ }
57
+ export interface TransferOut {
58
+ destination: string;
59
+ asset: string;
60
+ amount: number;
61
+ extra_data?: any;
44
62
  }
45
63
  export interface TxOutgoing {
46
- transfers: any;
64
+ transfers: TransferOut;
47
65
  fees: number;
48
66
  nonce: number;
49
67
  }
@@ -52,6 +70,28 @@ export interface TransactionEntry {
52
70
  topoheight: number;
53
71
  entry: TxCoinbase | TxBurn | TxIncoming | TxOutgoing;
54
72
  }
73
+ export interface RescanParams {
74
+ until_topoheight?: number;
75
+ auto_reconnect: boolean;
76
+ }
77
+ export interface SetOnlineModeParams {
78
+ daemon_address: string;
79
+ auto_reconnect: boolean;
80
+ }
81
+ export interface EstimateFeesParams {
82
+ transfers: TransferOut[];
83
+ burn?: TxBurn;
84
+ }
85
+ export interface BalanceChangedResult {
86
+ asset: string;
87
+ balance: number;
88
+ }
89
+ export interface NewTopoheightResult {
90
+ topoheight: number;
91
+ }
92
+ export interface RescanResult {
93
+ start_topoheight: number;
94
+ }
55
95
  export declare enum RPCMethod {
56
96
  GetVersion = "get_version",
57
97
  GetNetwork = "get_network",
@@ -68,9 +108,20 @@ export declare enum RPCMethod {
68
108
  BuildTransaction = "build_transaction",
69
109
  ListTransactions = "list_transactions",
70
110
  IsOnline = "is_online",
111
+ SetOnlineMode = "set_online_mode",
112
+ SetOfflineMode = "set_offline_mode",
71
113
  SignData = "sign_data",
72
114
  EstimateFees = "estimate_fees"
73
115
  }
116
+ export declare enum RPCEvent {
117
+ NewTopoheight = "new_topoheight",
118
+ NewAsset = "new_asset",
119
+ NewTransaction = "",
120
+ BalanceChanged = "balance_changed",
121
+ Rescan = "rescan",
122
+ Online = "online",
123
+ Offline = "offline"
124
+ }
74
125
  export declare enum Permission {
75
126
  Ask = 0,
76
127
  AcceptAlways = 1,
@@ -1,18 +1,26 @@
1
- import { WS as BaseWS } from '../lib/websocket.js';
2
- import { GetAssetParams, TransactionData } from '../daemon/types.js';
3
- import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult, Signature, TransactionEntry } from './types.js';
1
+ import { WS as BaseWS } from '../lib/websocket';
2
+ import { MessageEvent } from 'ws';
3
+ import { AssetWithData, GetAssetParams, RPCEventResult } from '../daemon/types';
4
+ import { BuildTransactionParams, BuildTransactionResult, GetAddressParams, ListTransactionParams, SplitAddressParams, SplitAddressResult, Signature, RescanParams, SetOnlineModeParams, EstimateFeesParams, TransactionEntry, BalanceChangedResult, NewTopoheightResult, RescanResult } from './types';
4
5
  export declare class WalletMethods {
5
6
  ws: BaseWS;
6
7
  prefix: string;
7
8
  constructor(ws: BaseWS, prefix?: string);
8
9
  dataCall<T>(method: string, params?: any): Promise<T>;
10
+ onNewTopoheight(onData: (msgEvent: MessageEvent, data?: NewTopoheightResult & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
11
+ onNewAsset(onData: (msgEvent: MessageEvent, data?: AssetWithData & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
12
+ onNewTransaction(onData: (msgEvent: MessageEvent, data?: TransactionEntry & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
13
+ onBalanceChanged(onData: (msgEvent: MessageEvent, data?: BalanceChangedResult & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
14
+ onRescan(onData: (msgEvent: MessageEvent, data?: RescanResult & RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
15
+ onOnline(onData: (msgEvent: MessageEvent, data?: RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
16
+ onOffline(onData: (msgEvent: MessageEvent, data?: RPCEventResult, err?: Error) => void): Promise<() => Promise<void>>;
9
17
  getVersion(): Promise<string>;
10
18
  getNetwork(): Promise<string>;
11
19
  getNonce(): Promise<number>;
12
20
  getTopoheight(): Promise<number>;
13
21
  getAddress(params?: GetAddressParams): Promise<string>;
14
22
  splitAddress(params: SplitAddressParams): Promise<SplitAddressResult>;
15
- rescan(): Promise<void>;
23
+ rescan(params: RescanParams): Promise<boolean>;
16
24
  getBalance(asset?: string): Promise<number>;
17
25
  getTrackedAssets(): Promise<string[]>;
18
26
  getAssetPrecision(params: GetAssetParams): Promise<number>;
@@ -21,7 +29,9 @@ export declare class WalletMethods {
21
29
  listTransactions(params?: ListTransactionParams): Promise<TransactionEntry[]>;
22
30
  isOnline(): Promise<boolean>;
23
31
  signData(data: any): Promise<Signature>;
24
- estimateFees(txData: TransactionData): Promise<number>;
32
+ estimateFees(params: EstimateFeesParams): Promise<number>;
33
+ setOnlineMode(params: SetOnlineModeParams): Promise<boolean>;
34
+ setOfflineMode(): Promise<boolean>;
25
35
  }
26
36
  export declare class WS extends BaseWS {
27
37
  methods: WalletMethods;
@@ -1,11 +1,11 @@
1
- import { WS as BaseWS } from '../lib/websocket.js';
2
- import { ApplicationData } from '../wallet/types.js';
3
- import { DaemonMethods } from '../daemon/websocket.js';
4
- import { WalletMethods } from '../wallet/websocket.js';
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
5
  export declare class WS extends BaseWS {
6
6
  daemon: DaemonMethods;
7
7
  wallet: WalletMethods;
8
8
  constructor();
9
- authorize(app: ApplicationData): Promise<import("../lib/types.js").RPCResponse<unknown>>;
9
+ authorize(app: ApplicationData): Promise<import("../lib/types").RPCResponse<unknown>>;
10
10
  }
11
11
  export default WS;
package/package.json CHANGED
@@ -1,39 +1,42 @@
1
- {
2
- "version": "0.8.4",
3
- "name": "@xelis/sdk",
4
- "description": "Xelis software development kit for JS",
5
- "exports": {
6
- "./*": {
7
- "types": "./dist/types/*.d.ts",
8
- "require": "./dist/cjs/*.js",
9
- "import": "./dist/esm/*.js",
10
- "default": "./dist/esm/*.js"
11
- }
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/xelis-project/xelis-js-sdk"
16
- },
17
- "homepage": "https://github.com/xelis-project/xelis-js-sdk#readme",
18
- "scripts": {
19
- "test": "jest",
20
- "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
21
- "clean": "rm -rf ./dist",
22
- "build": "npm run clean && npm run compile && node create_esm_pkg.js",
23
- "prepublishOnly": "npm run build"
24
- },
25
- "devDependencies": {
26
- "@types/jest": "^29.4.0",
27
- "@types/react": "^18.2.23",
28
- "@types/ws": "^8.5.4",
29
- "ts-jest": "^29.0.5",
30
- "typescript": "^4.9.5"
31
- },
32
- "dependencies": {
33
- "await-to-js": "^3.0.0",
34
- "isomorphic-ws": "^5.0.0",
35
- "js-base64": "^3.7.6",
36
- "react": "^18.2.0",
37
- "ws": "^8.12.1"
38
- }
39
- }
1
+ {
2
+ "version": "0.9.1",
3
+ "name": "@xelis/sdk",
4
+ "description": "Xelis software development kit for JS",
5
+ "exports": {
6
+ "./*": {
7
+ "types": "./dist/types/*.d.ts",
8
+ "require": "./dist/cjs/*.js",
9
+ "import": "./dist/esm/*.js",
10
+ "default": "./dist/esm/*.js"
11
+ }
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/xelis-project/xelis-js-sdk"
16
+ },
17
+ "homepage": "https://github.com/xelis-project/xelis-js-sdk#readme",
18
+ "scripts": {
19
+ "test-func": "jest -t",
20
+ "test": "jest",
21
+ "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
22
+ "fix-esm": "fix-esm-import-path ./dist/esm",
23
+ "clean": "rm -rf ./dist",
24
+ "build": "npm run clean && npm run compile && node create_esm_pkg.js && npm run fix-esm",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "devDependencies": {
28
+ "@types/jest": "^29.4.0",
29
+ "@types/react": "^18.2.23",
30
+ "@types/ws": "^8.5.4",
31
+ "fix-esm-import-path": "^1.5.0",
32
+ "ts-jest": "^29.0.5",
33
+ "typescript": "^4.9.5"
34
+ },
35
+ "dependencies": {
36
+ "await-to-js": "^3.0.0",
37
+ "isomorphic-ws": "^5.0.0",
38
+ "js-base64": "^3.7.6",
39
+ "react": "^18.2.0",
40
+ "ws": "^8.12.1"
41
+ }
42
+ }
@@ -0,0 +1,22 @@
1
+ const { RPC: DaemonRPC } = require('../dist/cjs/daemon/rpc')
2
+ const { WS: DaemonWS } = require('../dist/cjs/daemon/websocket')
3
+ const { WS: WalletWS } = require('../dist/cjs/wallet/websocket')
4
+ const { TESTNET_NODE_RPC, TESTNET_NODE_WS, LOCAL_NODE_WS } = require('../dist/cjs/config')
5
+
6
+ const main = async () => {
7
+ const daemonRPC = new DaemonRPC(TESTNET_NODE_RPC)
8
+ const res1 = await daemonRPC.getInfo()
9
+ console.log(res1)
10
+
11
+ const daemonWS = new DaemonWS()
12
+ await daemonWS.connect(TESTNET_NODE_WS)
13
+ const res2 = await daemonWS.methods.getInfo()
14
+ console.log(res2)
15
+
16
+ const walletWS = new WalletWS(`test`, `test`)
17
+ await walletWS.connect(LOCAL_NODE_WS)
18
+ const res3 = await walletWS.methods.getVersion()
19
+ console.log(res3)
20
+ }
21
+
22
+ main()
@@ -0,0 +1,12 @@
1
+ import { RPC as DaemonRPC } from '../dist/esm/daemon/rpc.js'
2
+ import { TESTNET_NODE_RPC } from '../dist/esm/config.js'
3
+
4
+ // need to add "type": "module" in package.json to test
5
+
6
+ const main = async () => {
7
+ const daemon = new DaemonRPC(TESTNET_NODE_RPC)
8
+ const res = await daemon.getInfo()
9
+ console.log(res)
10
+ }
11
+
12
+ main()