zano_web3 7.0.0 → 7.2.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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "zano_web3",
3
- "version": "7.0.0",
3
+ "version": "7.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build:web": "tsc --project tsconfig.web.json",
8
8
  "build:server": "tsc --project tsconfig.server.json",
9
- "build": "npm run build:web && npm run build:server",
9
+ "build:shared": "tsc --project tsconfig.shared.json",
10
+ "build": "npm run build:web && npm run build:server && npm run build:shared",
10
11
  "postinstall": "npm run build"
11
12
  },
12
13
  "repository": {
@@ -29,6 +30,7 @@
29
30
  "@types/uuid": "^10.0.0",
30
31
  "axios": "^1.7.2",
31
32
  "big.js": "^6.2.1",
33
+ "decimal.js": "^10.4.3",
32
34
  "react": "^18.3.1",
33
35
  "typescript": "^5.5.4",
34
36
  "uuid": "^10.0.0"
@@ -46,6 +48,11 @@
46
48
  "import": "./server/dist/index.js",
47
49
  "require": "./server/dist/index.js",
48
50
  "types": "./server/dist/index.d.ts"
51
+ },
52
+ "./shared": {
53
+ "import": "./shared/dist/index.js",
54
+ "require": "./shared/dist/index.js",
55
+ "types": "./shared/dist/index.d.ts"
49
56
  }
50
57
  },
51
58
  "homepage": "https://github.com/hyle-team/zano_web3#readme"
@@ -14,7 +14,6 @@ export interface PkeyAuth extends BaseAuthData {
14
14
 
15
15
  export type AuthData = AliasAuth | PkeyAuth;
16
16
 
17
-
18
17
  export interface ValidationParams {
19
18
  buff: string;
20
19
  sig: string;
@@ -70,8 +69,8 @@ export interface Transfer {
70
69
  employed_entries: {
71
70
  receive: EmployedEntry[];
72
71
  spent: EmployedEntry[];
73
- },
74
- subtransfers: SubTransfer[],
72
+ };
73
+ subtransfers: SubTransfer[];
75
74
  comment: string;
76
75
  fee: number;
77
76
  height: number;
@@ -92,18 +91,21 @@ export interface Transfer {
92
91
  export interface TxInfo {
93
92
  last_item_index: number;
94
93
  pi: {
95
- balance: number;
96
- curent_height: number;
97
- transfer_entries_count: number;
98
- transfers_count: number;
99
- unlocked_balance: number;
94
+ balance: number;
95
+ curent_height: number;
96
+ transfer_entries_count: number;
97
+ transfers_count: number;
98
+ unlocked_balance: number;
100
99
  };
101
100
  total_transfers: number;
102
101
  transfers: Transfer[];
103
102
  }
104
103
 
105
104
  export interface AliasDetails {
106
- address: string;
107
- comment: string;
108
- tracking_key: string;
109
- }
105
+ alias_details: {
106
+ address: string;
107
+ comment: string;
108
+ tracking_key: string;
109
+ };
110
+ status: 'OK' | 'NOT_FOUND';
111
+ }
@@ -0,0 +1 @@
1
+ export * from "./utils";
@@ -0,0 +1,89 @@
1
+ import Decimal from "decimal.js";
2
+
3
+ export function validateTokensInput(input: string | number, decimal_point: number = 12) {
4
+
5
+ if (typeof input === 'number') {
6
+ input = input.toString();
7
+ }
8
+
9
+ if (input === "") {
10
+ return {
11
+ valid: false,
12
+ error: 'Invalid input',
13
+ };
14
+ }
15
+
16
+ input = input.replace(/[^0-9.,]/g, '');
17
+
18
+ const MAX_NUMBER = new Decimal(2).pow(64).minus(1);
19
+
20
+ if (decimal_point < 0 || decimal_point > 18) {
21
+ return {
22
+ valid: false,
23
+ error: 'Invalid decimal point',
24
+ };
25
+ }
26
+
27
+ const dotInput = input.replace(/,/g, '');
28
+
29
+ const decimalDevider = new Decimal(10).pow(decimal_point);
30
+
31
+ const maxAllowedNumber = MAX_NUMBER.div(decimalDevider);
32
+
33
+ const minAllowedNumber = new Decimal(1).div(decimalDevider);
34
+
35
+ const rounded = (() => {
36
+ if (dotInput.replace('.', '').length > 20) {
37
+ const decimalParts = dotInput.split('.');
38
+
39
+ if (decimalParts.length === 2 && decimalParts[1].length > 1) {
40
+ const beforeDotLength = decimalParts[0].length;
41
+ const roundedInput = new Decimal(dotInput).toFixed(Math.max(20 - beforeDotLength, 0));
42
+
43
+ if (roundedInput.replace(/./g, '').length <= 20) {
44
+ return roundedInput;
45
+ }
46
+ }
47
+
48
+ return false;
49
+ } else {
50
+ return dotInput;
51
+ }
52
+ })();
53
+
54
+ const decimalsAmount = dotInput.split('.')[1]?.length || 0;
55
+
56
+ if (decimalsAmount > decimal_point) {
57
+ return {
58
+ valid: false,
59
+ error: 'Invalid amount - too many decimal points',
60
+ };
61
+ }
62
+
63
+ if (rounded === false) {
64
+ return {
65
+ valid: false,
66
+ error: 'Invalid amount - number is too big or has too many decimal points',
67
+ };
68
+ }
69
+
70
+ const dotInputDecimal = new Decimal(rounded);
71
+
72
+ if (dotInputDecimal.gt(maxAllowedNumber)) {
73
+ return {
74
+ valid: false,
75
+ error: 'Invalid amount - number is too big',
76
+ };
77
+ }
78
+
79
+ if (dotInputDecimal.lt(minAllowedNumber)) {
80
+ return {
81
+ valid: false,
82
+ error: 'Invalid amount - number is too small',
83
+ };
84
+ }
85
+
86
+ return {
87
+ valid: true
88
+ };
89
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./shared/dist",
5
+ "declarationDir": "./shared/dist",
6
+ "rootDir": "./shared/src",
7
+ },
8
+ "include": ["shared/src/**/*"],
9
+ "exclude": ["node_modules"],
10
+ }