zano_web3 6.0.0 → 6.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,6 +1,6 @@
1
1
  {
2
2
  "name": "zano_web3",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -48,9 +48,5 @@
48
48
  "types": "./server/dist/index.d.ts"
49
49
  }
50
50
  },
51
- "files": [
52
- "web/dist",
53
- "server/dist"
54
- ],
55
51
  "homepage": "https://github.com/hyle-team/zano_web3#readme"
56
52
  }
@@ -1,2 +1,2 @@
1
- import ServerWallet from "./server";
2
- export { ServerWallet };
1
+ import ServerWallet from "./server";
2
+ export {ServerWallet};
@@ -1,184 +1,245 @@
1
- import axios from 'axios';
2
- import Big from "big.js";
3
- import { ZANO_ASSET_ID, ZanoError } from './utils';
4
- class ServerWallet {
5
- walletUrl;
6
- daemonUrl;
7
- constructor(params) {
8
- this.walletUrl = params.walletUrl;
9
- this.daemonUrl = params.daemonUrl;
10
- }
11
- async fetchDaemon(method, params) {
12
- const headers = { "Content-Type": "application/json" };
13
- const data = {
14
- jsonrpc: "2.0",
15
- id: 0,
16
- method: method,
17
- params: params
18
- };
19
- return axios.post(this.daemonUrl, data, { headers });
20
- }
21
- async fetchWallet(method, params) {
22
- const headers = { "Content-Type": "application/json" };
23
- const data = {
24
- jsonrpc: "2.0",
25
- id: 0,
26
- method: method,
27
- params: params
28
- };
29
- return axios.post(this.walletUrl, data, { headers });
30
- }
31
- async updateWalletRpcUrl(rpcUrl) {
32
- this.walletUrl = rpcUrl;
33
- }
34
- async updateDaemonRpcUrl(rpcUrl) {
35
- this.daemonUrl = rpcUrl;
36
- }
37
- async getAssetsList() {
38
- const count = 100; // Number of items to fetch per request
39
- let offset = 0;
40
- let allAssets = [];
41
- let keepFetching = true;
42
- while (keepFetching) {
43
- try {
44
- const response = await this.fetchDaemon("get_assets_list", { count, offset });
45
- const assets = response.data.result.assets;
46
- if (assets.length < count) {
47
- keepFetching = false;
48
- }
49
- allAssets = allAssets.concat(assets);
50
- offset += count;
51
- }
52
- catch (error) {
53
- throw new ZanoError("Failed to fetch assets list", "ASSETS_FETCH_ERROR");
54
- }
55
- }
56
- return allAssets;
57
- }
58
- ;
59
- async getAssetDetails(assetId) {
60
- const assets = await this.getAssetsList();
61
- const asset = assets.find((a) => a.asset_id === assetId);
62
- if (!asset) {
63
- throw new ZanoError(`Asset with ID ${assetId} not found`, "ASSET_NOT_FOUND");
64
- }
65
- return asset;
66
- }
67
- async getAssetInfo(assetId) {
68
- try {
69
- const response = await this.fetchDaemon("get_asset_info", { asset_id: assetId });
70
- if (response.data.result) {
71
- return response.data.result;
72
- }
73
- else {
74
- throw new ZanoError(`Error fetching info for asset ID ${assetId}`, "ASSET_INFO_ERROR");
75
- }
76
- }
77
- catch (error) {
78
- console.error(error);
79
- throw new ZanoError("Failed to fetch asset info", "ASSET_INFO_FETCH_ERROR");
80
- }
81
- }
82
- ;
83
- async sendTransfer(assetId, address, amount) {
84
- let decimalPoint;
85
- if (assetId === ZANO_ASSET_ID) {
86
- decimalPoint = 12;
87
- }
88
- else {
89
- const asset = await this.getAssetDetails(assetId);
90
- decimalPoint = asset.decimal_point;
91
- }
92
- const bigAmount = new Big(amount)
93
- .times(new Big(10).pow(decimalPoint))
94
- .toString();
95
- try {
96
- const response = await this.fetchWallet("transfer", {
97
- destinations: [{ address, amount: bigAmount, asset_id: assetId }],
98
- fee: "10000000000",
99
- mixin: 15,
100
- });
101
- if (response.data.result) {
102
- return response.data.result;
103
- }
104
- else if (response.data.error &&
105
- response.data.error.message === "WALLET_RPC_ERROR_CODE_NOT_ENOUGH_MONEY") {
106
- throw new ZanoError("Not enough funds", "NOT_ENOUGH_FUNDS");
107
- }
108
- else {
109
- throw new ZanoError("Error sending transfer", "TRANSFER_ERROR");
110
- }
111
- }
112
- catch (error) {
113
- if (error instanceof ZanoError) {
114
- throw error; // Re-throw the custom error
115
- }
116
- else {
117
- throw new ZanoError("Failed to send transfer", "TRANSFER_SEND_ERROR");
118
- }
119
- }
120
- }
121
- ;
122
- async getBalances() {
123
- try {
124
- const response = await this.fetchWallet("getbalance", {});
125
- const balancesData = response.data.result.balances;
126
- const balances = balancesData.map((asset) => ({
127
- name: asset.asset_info.full_name,
128
- ticker: asset.asset_info.ticker,
129
- id: asset.asset_info.asset_id,
130
- amount: new Big(asset.unlocked)
131
- .div(new Big(10).pow(asset.asset_info.decimal_point))
132
- .toString(),
133
- }));
134
- return balances.sort((a, b) => {
135
- if (a.id === ZANO_ASSET_ID)
136
- return -1;
137
- if (b.id === ZANO_ASSET_ID)
138
- return 1;
139
- return 0;
140
- });
141
- }
142
- catch (error) {
143
- throw new ZanoError("Failed to fetch balances", "BALANCES_FETCH_ERROR");
144
- }
145
- }
146
- ;
147
- async validateWallet(authData) {
148
- const { message, address, signature } = authData;
149
- const alias = authData.alias || undefined;
150
- const pkey = authData.pkey || undefined;
151
- if (!message || (!alias && !pkey) || !signature) {
152
- return false;
153
- }
154
- const validationParams = {
155
- "buff": Buffer.from(message).toString("base64"),
156
- "sig": signature
157
- };
158
- if (alias) {
159
- validationParams['alias'] = alias;
160
- }
161
- else {
162
- validationParams['pkey'] = pkey;
163
- }
164
- const response = await this.fetchDaemon('validate_signature', validationParams);
165
- const valid = response?.data?.result?.status === 'OK';
166
- if (!valid) {
167
- return false;
168
- }
169
- if (alias) {
170
- const aliasDetailsResponse = await this.fetchDaemon('get_alias_details', {
171
- "alias": alias,
172
- });
173
- const aliasDetails = aliasDetailsResponse?.data?.result?.alias_details;
174
- const aliasAddress = aliasDetails?.address;
175
- const addressValid = !!aliasAddress && aliasAddress === address;
176
- if (!addressValid) {
177
- return false;
178
- }
179
- }
180
- return valid;
181
- }
182
- }
183
- export default ServerWallet;
184
- //# sourceMappingURL=server.js.map
1
+ import axios from 'axios';
2
+ import Big from "big.js";
3
+ import {
4
+ AuthData,
5
+ AliasAuth,
6
+ PkeyAuth,
7
+ ValidationParams,
8
+ BalanceInfo,
9
+ } from './types';
10
+
11
+ import { ZANO_ASSET_ID, ZanoError } from './utils';
12
+ import { APIAsset, APIBalance } from './types';
13
+
14
+
15
+ interface ConstructorParams {
16
+ walletUrl: string;
17
+ daemonUrl: string;
18
+ }
19
+
20
+ class ServerWallet {
21
+ private walletUrl: string;
22
+ private daemonUrl: string;
23
+
24
+ constructor(params: ConstructorParams) {
25
+ this.walletUrl = params.walletUrl;
26
+ this.daemonUrl = params.daemonUrl;
27
+ }
28
+
29
+ private async fetchDaemon(method: string, params: any) {
30
+ const headers = { "Content-Type": "application/json" };
31
+
32
+ const data = {
33
+ jsonrpc: "2.0",
34
+ id: 0,
35
+ method: method,
36
+ params: params
37
+ };
38
+
39
+ return axios.post(this.daemonUrl, data, { headers })
40
+ }
41
+
42
+ private async fetchWallet(method: string, params: any) {
43
+ const headers = { "Content-Type": "application/json" };
44
+
45
+ const data = {
46
+ jsonrpc: "2.0",
47
+ id: 0,
48
+ method: method,
49
+ params: params
50
+ };
51
+
52
+ return axios.post(this.walletUrl, data, { headers })
53
+ }
54
+
55
+ async updateWalletRpcUrl(rpcUrl: string) {
56
+ this.walletUrl = rpcUrl;
57
+ }
58
+
59
+ async updateDaemonRpcUrl(rpcUrl: string) {
60
+ this.daemonUrl = rpcUrl;
61
+ }
62
+
63
+ async getAssetsList() {
64
+ const count = 100; // Number of items to fetch per request
65
+ let offset = 0;
66
+ let allAssets: APIAsset[] = [];
67
+ let keepFetching = true;
68
+
69
+ while (keepFetching) {
70
+ try {
71
+ const response = await this.fetchDaemon("get_assets_list", { count, offset });
72
+
73
+ const assets = response.data.result.assets;
74
+ if (assets.length < count) {
75
+ keepFetching = false;
76
+ }
77
+ allAssets = allAssets.concat(assets);
78
+ offset += count;
79
+ } catch (error) {
80
+ throw new ZanoError("Failed to fetch assets list", "ASSETS_FETCH_ERROR");
81
+ }
82
+ }
83
+
84
+ return allAssets as APIAsset[];
85
+ };
86
+
87
+ async getAssetDetails(assetId: string) {
88
+ const assets = await this.getAssetsList();
89
+ const asset = assets.find((a) => a.asset_id === assetId);
90
+
91
+ if (!asset) {
92
+ throw new ZanoError(
93
+ `Asset with ID ${assetId} not found`,
94
+ "ASSET_NOT_FOUND"
95
+ );
96
+ }
97
+
98
+ return asset as APIAsset;
99
+ }
100
+
101
+
102
+ async getAssetInfo(assetId: string) {
103
+ try {
104
+ const response = await this.fetchDaemon("get_asset_info", { asset_id: assetId });
105
+
106
+ if (response.data.result) {
107
+ return response.data.result;
108
+ } else {
109
+ throw new ZanoError(
110
+ `Error fetching info for asset ID ${assetId}`,
111
+ "ASSET_INFO_ERROR"
112
+ );
113
+ }
114
+ } catch (error) {
115
+ console.error(error);
116
+ throw new ZanoError("Failed to fetch asset info", "ASSET_INFO_FETCH_ERROR");
117
+ }
118
+ };
119
+
120
+ async sendTransfer(assetId: string, address: string, amount: string) {
121
+ let decimalPoint: number;
122
+
123
+ if (assetId === ZANO_ASSET_ID) {
124
+ decimalPoint = 12;
125
+ } else {
126
+ const asset = await this.getAssetDetails(assetId);
127
+ decimalPoint = asset.decimal_point;
128
+ }
129
+
130
+ const bigAmount = new Big(amount)
131
+ .times(new Big(10).pow(decimalPoint))
132
+ .toString();
133
+
134
+ try {
135
+ const response = await this.fetchWallet("transfer", {
136
+ destinations: [{ address, amount: bigAmount, asset_id: assetId }],
137
+ fee: "10000000000",
138
+ mixin: 15,
139
+ });
140
+
141
+ if (response.data.result) {
142
+ return response.data.result;
143
+ } else if (
144
+ response.data.error &&
145
+ response.data.error.message === "WALLET_RPC_ERROR_CODE_NOT_ENOUGH_MONEY"
146
+ ) {
147
+ throw new ZanoError("Not enough funds", "NOT_ENOUGH_FUNDS");
148
+ } else {
149
+ throw new ZanoError("Error sending transfer", "TRANSFER_ERROR");
150
+ }
151
+
152
+ } catch (error) {
153
+ if (error instanceof ZanoError) {
154
+ throw error; // Re-throw the custom error
155
+ } else {
156
+ throw new ZanoError("Failed to send transfer", "TRANSFER_SEND_ERROR");
157
+ }
158
+ }
159
+ };
160
+
161
+ async getBalances() {
162
+ try {
163
+ const response = await this.fetchWallet("getbalance", {});
164
+ const balancesData = response.data.result.balances as APIBalance[];
165
+
166
+
167
+ const balances = balancesData.map((asset) => ({
168
+ name: asset.asset_info.full_name,
169
+ ticker: asset.asset_info.ticker,
170
+ id: asset.asset_info.asset_id,
171
+ amount: new Big(asset.unlocked)
172
+ .div(new Big(10).pow(asset.asset_info.decimal_point))
173
+ .toString(),
174
+ }));
175
+
176
+ return balances.sort((a, b) => {
177
+ if (a.id === ZANO_ASSET_ID)
178
+ return -1;
179
+ if (b.id === ZANO_ASSET_ID )
180
+ return 1;
181
+ return 0;
182
+ }) as BalanceInfo[];
183
+
184
+ } catch (error) {
185
+ throw new ZanoError("Failed to fetch balances", "BALANCES_FETCH_ERROR");
186
+ }
187
+ };
188
+
189
+ async validateWallet(authData: AuthData) {
190
+
191
+ const { message, address, signature } = authData;
192
+
193
+ const alias = (authData as AliasAuth).alias || undefined;
194
+ const pkey = (authData as PkeyAuth).pkey || undefined;
195
+
196
+ if (!message || (!alias && !pkey) || !signature) {
197
+ return false;
198
+ }
199
+
200
+ const validationParams: ValidationParams = {
201
+ "buff": Buffer.from(message).toString("base64"),
202
+ "sig": signature
203
+ };
204
+
205
+ if (alias) {
206
+ validationParams['alias'] = alias;
207
+ } else {
208
+ validationParams['pkey'] = pkey;
209
+ }
210
+
211
+ const response = await this.fetchDaemon(
212
+ 'validate_signature',
213
+ validationParams
214
+ );
215
+
216
+ const valid = response?.data?.result?.status === 'OK';
217
+
218
+ if (!valid) {
219
+ return false;
220
+ }
221
+
222
+ if (alias) {
223
+ const aliasDetailsResponse = await this.fetchDaemon(
224
+ 'get_alias_details',
225
+ {
226
+ "alias": alias,
227
+ }
228
+ );
229
+
230
+ const aliasDetails = aliasDetailsResponse?.data?.result?.alias_details;
231
+ const aliasAddress = aliasDetails?.address;
232
+
233
+ const addressValid = !!aliasAddress && aliasAddress === address;
234
+
235
+ if (!addressValid) {
236
+ return false;
237
+ }
238
+ }
239
+
240
+ return valid;
241
+ }
242
+ }
243
+
244
+
245
+ export default ServerWallet;
@@ -1,42 +1,50 @@
1
- export interface BaseAuthData {
2
- address: string;
3
- signature: string;
4
- message: string;
5
- }
6
- export interface AliasAuth extends BaseAuthData {
7
- alias: string;
8
- }
9
- export interface PkeyAuth extends BaseAuthData {
10
- pkey: string;
11
- }
12
- export type AuthData = AliasAuth | PkeyAuth;
13
- export interface ValidationParams {
14
- buff: string;
15
- sig: string;
16
- alias?: string;
17
- pkey?: string;
18
- }
19
- export interface APIAsset {
20
- asset_id: string;
21
- current_supply: number;
22
- decimal_point: number;
23
- full_name: string;
24
- hidden_supply: boolean;
25
- meta_info: string;
26
- owner: string;
27
- ticker: string;
28
- total_max_supply: number;
29
- }
30
- export interface APIBalance {
31
- asset_info: APIAsset;
32
- awaiting_in: number;
33
- awaiting_out: number;
34
- total: number;
35
- unlocked: number;
36
- }
37
- export interface BalanceInfo {
38
- name: string;
39
- ticker: string;
40
- id: string;
41
- amount: string;
42
- }
1
+ export interface BaseAuthData {
2
+ address: string;
3
+ signature: string;
4
+ message: string;
5
+ }
6
+
7
+ export interface AliasAuth extends BaseAuthData {
8
+ alias: string;
9
+ }
10
+
11
+ export interface PkeyAuth extends BaseAuthData {
12
+ pkey: string;
13
+ }
14
+
15
+ export type AuthData = AliasAuth | PkeyAuth;
16
+
17
+
18
+ export interface ValidationParams {
19
+ buff: string;
20
+ sig: string;
21
+ alias?: string;
22
+ pkey?: string;
23
+ }
24
+
25
+ export interface APIAsset {
26
+ asset_id: string;
27
+ current_supply: number;
28
+ decimal_point: number;
29
+ full_name: string;
30
+ hidden_supply: boolean;
31
+ meta_info: string;
32
+ owner: string;
33
+ ticker: string;
34
+ total_max_supply: number;
35
+ }
36
+
37
+ export interface APIBalance {
38
+ asset_info: APIAsset;
39
+ awaiting_in: number;
40
+ awaiting_out: number;
41
+ total: number;
42
+ unlocked: number;
43
+ }
44
+
45
+ export interface BalanceInfo {
46
+ name: string;
47
+ ticker: string;
48
+ id: string;
49
+ amount: string;
50
+ }
@@ -1,11 +1,13 @@
1
- export const ZANO_ASSET_ID = "d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a";
2
- export class ZanoError extends Error {
3
- code;
4
- name;
5
- constructor(message, code) {
6
- super(message);
7
- this.name = "ZanoError";
8
- this.code = code;
9
- }
10
- }
11
- //# sourceMappingURL=utils.js.map
1
+ export const ZANO_ASSET_ID = "d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a";
2
+
3
+ export class ZanoError extends Error {
4
+
5
+ public code: string;
6
+ public name: string;
7
+
8
+ constructor(message: string, code: string) {
9
+ super(message);
10
+ this.name = "ZanoError";
11
+ this.code = code;
12
+ }
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "moduleResolution": "node",
8
+ "resolveJsonModule": true,
9
+ "declaration": true,
10
+ "lib": [
11
+ "ESNext",
12
+ "DOM"
13
+ ],
14
+ "sourceMap": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "baseUrl": ".",
17
+ "paths": {
18
+ "@common/*": ["common/*"]
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./server/dist",
5
+ "declarationDir": "./server/dist",
6
+ "rootDir": "./server/src",
7
+ },
8
+ "include": ["server/src/**/*"],
9
+ "exclude": ["node_modules"]
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./web/dist",
5
+ "declarationDir": "./web/dist",
6
+ "rootDir": "./web/src",
7
+ },
8
+ "include": ["web/src/**/*"],
9
+ "exclude": ["node_modules"],
10
+ }
@@ -0,0 +1,18 @@
1
+ import ZanoWallet, { ZanoWalletParams } from './zanoWallet';
2
+ import { useEffect, useState } from 'react';
3
+
4
+ function useZanoWallet(params: ZanoWalletParams) {
5
+ const [zanoWallet, setZanoWallet] = useState<ZanoWallet | null>(null);
6
+
7
+ useEffect(() => {
8
+ if (typeof window === 'undefined') {
9
+ return;
10
+ }
11
+
12
+ setZanoWallet(new ZanoWallet(params));
13
+ }, []);
14
+
15
+ return zanoWallet;
16
+ }
17
+
18
+ export { useZanoWallet };
@@ -0,0 +1,7 @@
1
+ import zanoWallet from "./zanoWallet";
2
+
3
+ import {useZanoWallet} from "./hooks";
4
+ export {useZanoWallet};
5
+
6
+ export * from "./types";
7
+ export {zanoWallet};
@@ -1,32 +1,35 @@
1
- export interface Asset {
2
- name: string;
3
- ticker: string;
4
- assetId: string;
5
- decimalPoint: number;
6
- balance: string;
7
- unlockedBalance: string;
8
- }
9
- export interface Transfer {
10
- amount: string;
11
- assetId: string;
12
- incoming: boolean;
13
- }
14
- export interface Transaction {
15
- isConfirmed: boolean;
16
- txHash: string;
17
- blobSize: number;
18
- timestamp: number;
19
- height: number;
20
- paymentId: string;
21
- comment: string;
22
- fee: string;
23
- isInitiator: boolean;
24
- transfers: Transfer[];
25
- }
26
- export interface Wallet {
27
- address: string;
28
- alias: string;
29
- balance: string;
30
- assets: Asset[];
31
- transactions: Transaction[];
32
- }
1
+ export interface Asset {
2
+ name: string;
3
+ ticker: string;
4
+ assetId: string;
5
+ decimalPoint: number;
6
+ balance: string;
7
+ unlockedBalance: string;
8
+ }
9
+
10
+ export interface Transfer {
11
+ amount: string;
12
+ assetId: string;
13
+ incoming: boolean;
14
+ }
15
+
16
+ export interface Transaction {
17
+ isConfirmed: boolean;
18
+ txHash: string;
19
+ blobSize: number;
20
+ timestamp: number;
21
+ height: number;
22
+ paymentId: string;
23
+ comment: string;
24
+ fee: string;
25
+ isInitiator: boolean;
26
+ transfers: Transfer[];
27
+ }
28
+
29
+ export interface Wallet {
30
+ address: string;
31
+ alias: string;
32
+ balance: string;
33
+ assets: Asset[];
34
+ transactions: Transaction[];
35
+ }
@@ -1,143 +1,217 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- class ZanoWallet {
3
- DEFAULT_LOCAL_STORAGE_KEY = "wallet";
4
- localStorageKey;
5
- params;
6
- zanoWallet;
7
- constructor(params) {
8
- if (typeof window === 'undefined') {
9
- throw new Error('ZanoWallet can only be used in the browser');
10
- }
11
- if (!window.zano) {
12
- console.error('ZanoWallet requires the ZanoWallet extension to be installed');
13
- }
14
- this.params = params;
15
- this.zanoWallet = window.zano;
16
- this.localStorageKey = params.customLocalStorageKey || this.DEFAULT_LOCAL_STORAGE_KEY;
17
- }
18
- handleError({ message }) {
19
- if (this.params.onConnectError) {
20
- this.params.onConnectError(message);
21
- }
22
- else {
23
- console.error(message);
24
- }
25
- }
26
- getSavedWalletCredentials() {
27
- const savedWallet = localStorage.getItem(this.localStorageKey);
28
- if (!savedWallet)
29
- return undefined;
30
- try {
31
- return JSON.parse(savedWallet);
32
- }
33
- catch {
34
- return undefined;
35
- }
36
- }
37
- setWalletCredentials(credentials) {
38
- if (credentials) {
39
- localStorage.setItem(this.localStorageKey, JSON.stringify(credentials));
40
- }
41
- else {
42
- localStorage.removeItem(this.localStorageKey);
43
- }
44
- }
45
- cleanWalletCredentials() {
46
- this.setWalletCredentials(undefined);
47
- }
48
- async connect() {
49
- if (this.params.beforeConnect) {
50
- await this.params.beforeConnect();
51
- }
52
- if (this.params.onConnectStart) {
53
- this.params.onConnectStart();
54
- }
55
- const walletData = (await window.zano.request('GET_WALLET_DATA')).data;
56
- if (!walletData?.address) {
57
- return this.handleError({ message: 'Companion is offline' });
58
- }
59
- if (!walletData?.alias && this.params.aliasRequired) {
60
- return this.handleError({ message: 'Alias not found' });
61
- }
62
- let nonce = "";
63
- let signature = "";
64
- let publicKey = "";
65
- const existingWallet = this.params.useLocalStorage ? this.getSavedWalletCredentials() : undefined;
66
- const existingWalletValid = existingWallet && existingWallet.address === walletData.address;
67
- console.log('existingWalletValid', existingWalletValid);
68
- console.log('existingWallet', existingWallet);
69
- console.log('walletData', walletData);
70
- if (existingWalletValid) {
71
- nonce = existingWallet.nonce;
72
- signature = existingWallet.signature;
73
- publicKey = existingWallet.publicKey;
74
- }
75
- else {
76
- const generatedNonce = this.params.customNonce || uuidv4();
77
- const signResult = await this.zanoWallet.request('REQUEST_MESSAGE_SIGN', {
78
- message: generatedNonce
79
- }, null);
80
- if (!signResult?.data?.result) {
81
- return this.handleError({ message: 'Failed to sign message' });
82
- }
83
- nonce = generatedNonce;
84
- signature = signResult.data.result.sig;
85
- publicKey = signResult.data.result.pkey;
86
- }
87
- const serverData = {
88
- alias: walletData.alias,
89
- address: walletData.address,
90
- signature,
91
- pkey: publicKey,
92
- message: nonce,
93
- isSavedData: existingWalletValid
94
- };
95
- if (this.params.onLocalConnectEnd) {
96
- this.params.onLocalConnectEnd(serverData);
97
- }
98
- if (!this.params.disableServerRequest) {
99
- const result = await fetch(this.params.customServerPath || "/api/auth", {
100
- method: "POST",
101
- headers: {
102
- "Content-Type": "application/json",
103
- },
104
- body: JSON.stringify({
105
- data: serverData
106
- })
107
- })
108
- .then(res => res.json())
109
- .catch((e) => ({
110
- success: false,
111
- error: e.message
112
- }));
113
- if (!result?.success || !result?.data) {
114
- return this.handleError({ message: result.error });
115
- }
116
- if (!existingWalletValid && this.params.useLocalStorage) {
117
- this.setWalletCredentials({
118
- publicKey,
119
- signature,
120
- nonce,
121
- address: walletData.address
122
- });
123
- }
124
- if (this.params.onConnectEnd) {
125
- this.params.onConnectEnd({
126
- ...serverData,
127
- token: result.data.token
128
- });
129
- }
130
- }
131
- }
132
- async getWallet() {
133
- return (await this.zanoWallet.request('GET_WALLET_DATA'))?.data;
134
- }
135
- async getAddressByAlias(alias) {
136
- return ((await this.zanoWallet.request('GET_ALIAS_DETAILS', { alias })) || undefined);
137
- }
138
- async createAlias(alias) {
139
- return ((await this.zanoWallet.request('CREATE_ALIAS', { alias })) || undefined).data;
140
- }
141
- }
142
- export default ZanoWallet;
143
- //# sourceMappingURL=zanoWallet.js.map
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { Wallet } from './types';
3
+
4
+ export interface ZanoWalletParams {
5
+ authPath: string;
6
+ useLocalStorage?: boolean; // default: true
7
+ aliasRequired?: boolean;
8
+ customLocalStorageKey?: string;
9
+ customNonce?: string;
10
+ customServerPath?: string;
11
+ disableServerRequest?: boolean;
12
+
13
+ onConnectStart?: (...params: any) => any;
14
+ onConnectEnd?: (...params: any) => any;
15
+ onConnectError?: (...params: any) => any;
16
+
17
+ beforeConnect?: (...params: any) => any;
18
+ onLocalConnectEnd?: (...params: any) => any;
19
+ }
20
+
21
+ type GlobalWindow = Window & typeof globalThis;
22
+
23
+ interface ZanoWindowParams {
24
+ request: (str: string, params?: any, timeoutMs?: number | null) => Promise<any>;
25
+ }
26
+
27
+ type ZanoWindow = Omit<GlobalWindow, 'Infinity'> & {
28
+ zano: ZanoWindowParams
29
+ }
30
+
31
+ interface WalletCredentials {
32
+ nonce: string;
33
+ signature: string;
34
+ publicKey: string;
35
+ address: string;
36
+ }
37
+
38
+ class ZanoWallet {
39
+
40
+ private DEFAULT_LOCAL_STORAGE_KEY = "wallet";
41
+ private localStorageKey: string;
42
+
43
+ private params: ZanoWalletParams;
44
+ private zanoWallet: ZanoWindowParams;
45
+
46
+ constructor(params: ZanoWalletParams) {
47
+
48
+ if (typeof window === 'undefined') {
49
+ throw new Error('ZanoWallet can only be used in the browser');
50
+ }
51
+
52
+ if (!((window as unknown) as ZanoWindow).zano) {
53
+ console.error('ZanoWallet requires the ZanoWallet extension to be installed');
54
+ }
55
+
56
+ this.params = params;
57
+ this.zanoWallet = ((window as unknown) as ZanoWindow).zano;
58
+ this.localStorageKey = params.customLocalStorageKey || this.DEFAULT_LOCAL_STORAGE_KEY;
59
+ }
60
+
61
+
62
+ private handleError({ message } : { message: string }) {
63
+ if (this.params.onConnectError) {
64
+ this.params.onConnectError(message);
65
+ } else {
66
+ console.error(message);
67
+ }
68
+ }
69
+
70
+ getSavedWalletCredentials() {
71
+ const savedWallet = localStorage.getItem(this.localStorageKey);
72
+ if (!savedWallet) return undefined;
73
+ try {
74
+ return JSON.parse(savedWallet) as WalletCredentials;
75
+ } catch {
76
+ return undefined;
77
+ }
78
+ }
79
+
80
+ setWalletCredentials(credentials: WalletCredentials | undefined) {
81
+ if (credentials) {
82
+ localStorage.setItem(this.localStorageKey, JSON.stringify(credentials));
83
+ } else {
84
+ localStorage.removeItem(this.localStorageKey);
85
+ }
86
+ }
87
+
88
+ cleanWalletCredentials() {
89
+ this.setWalletCredentials(undefined);
90
+ }
91
+
92
+ async connect() {
93
+
94
+ if (this.params.beforeConnect) {
95
+ await this.params.beforeConnect();
96
+ }
97
+
98
+ if (this.params.onConnectStart) {
99
+ this.params.onConnectStart();
100
+ }
101
+
102
+ const walletData = (await ((window as unknown) as ZanoWindow).zano.request('GET_WALLET_DATA')).data;
103
+
104
+
105
+ if (!walletData?.address) {
106
+ return this.handleError({ message: 'Companion is offline' });
107
+ }
108
+
109
+ if (!walletData?.alias && this.params.aliasRequired) {
110
+ return this.handleError({ message: 'Alias not found' });
111
+ }
112
+
113
+ let nonce = "";
114
+ let signature = "";
115
+ let publicKey = "";
116
+
117
+
118
+ const existingWallet = this.params.useLocalStorage ? this.getSavedWalletCredentials() : undefined;
119
+
120
+ const existingWalletValid = existingWallet && existingWallet.address === walletData.address;
121
+
122
+ console.log('existingWalletValid', existingWalletValid);
123
+ console.log('existingWallet', existingWallet);
124
+ console.log('walletData', walletData);
125
+
126
+ if (existingWalletValid) {
127
+ nonce = existingWallet.nonce;
128
+ signature = existingWallet.signature;
129
+ publicKey = existingWallet.publicKey;
130
+ } else {
131
+ const generatedNonce = this.params.customNonce || uuidv4();
132
+
133
+ const signResult = await this.zanoWallet.request(
134
+ 'REQUEST_MESSAGE_SIGN',
135
+ {
136
+ message: generatedNonce
137
+ },
138
+ null
139
+ );
140
+
141
+ if (!signResult?.data?.result) {
142
+ return this.handleError({ message: 'Failed to sign message' });
143
+ }
144
+
145
+ nonce = generatedNonce;
146
+ signature = signResult.data.result.sig;
147
+ publicKey = signResult.data.result.pkey;
148
+ }
149
+
150
+
151
+ const serverData = {
152
+ alias: walletData.alias,
153
+ address: walletData.address,
154
+ signature,
155
+ pkey: publicKey,
156
+ message: nonce,
157
+ isSavedData: existingWalletValid
158
+ }
159
+
160
+ if (this.params.onLocalConnectEnd) {
161
+ this.params.onLocalConnectEnd(serverData);
162
+ }
163
+
164
+ if (!this.params.disableServerRequest) {
165
+ const result = await fetch( this.params.customServerPath || "/api/auth", {
166
+ method: "POST",
167
+ headers: {
168
+ "Content-Type": "application/json",
169
+ },
170
+ body: JSON.stringify(
171
+ {
172
+ data: serverData
173
+ }
174
+ )
175
+ })
176
+ .then(res => res.json())
177
+ .catch((e) => ({
178
+ success: false,
179
+ error: e.message
180
+ }));
181
+
182
+ if (!result?.success || !result?.data) {
183
+ return this.handleError({ message: result.error });
184
+ }
185
+
186
+ if (!existingWalletValid && this.params.useLocalStorage) {
187
+ this.setWalletCredentials({
188
+ publicKey,
189
+ signature,
190
+ nonce,
191
+ address: walletData.address
192
+ });
193
+ }
194
+
195
+ if (this.params.onConnectEnd) {
196
+ this.params.onConnectEnd({
197
+ ...serverData,
198
+ token: result.data.token
199
+ });
200
+ }
201
+ }
202
+ }
203
+
204
+ async getWallet() {
205
+ return (await this.zanoWallet.request('GET_WALLET_DATA'))?.data as Wallet;
206
+ }
207
+
208
+ async getAddressByAlias(alias: string) {
209
+ return ((await this.zanoWallet.request('GET_ALIAS_DETAILS', { alias })) || undefined) as string | undefined;
210
+ }
211
+
212
+ async createAlias(alias: string) {
213
+ return ((await this.zanoWallet.request('CREATE_ALIAS', { alias })) || undefined).data;
214
+ }
215
+ }
216
+
217
+ export default ZanoWallet;
@@ -1,3 +0,0 @@
1
- import ServerWallet from "./server";
2
- export { ServerWallet };
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,CAAC"}
@@ -1,22 +0,0 @@
1
- import { AuthData, BalanceInfo } from './types';
2
- import { APIAsset } from './types';
3
- interface ConstructorParams {
4
- walletUrl: string;
5
- daemonUrl: string;
6
- }
7
- declare class ServerWallet {
8
- private walletUrl;
9
- private daemonUrl;
10
- constructor(params: ConstructorParams);
11
- private fetchDaemon;
12
- private fetchWallet;
13
- updateWalletRpcUrl(rpcUrl: string): Promise<void>;
14
- updateDaemonRpcUrl(rpcUrl: string): Promise<void>;
15
- getAssetsList(): Promise<APIAsset[]>;
16
- getAssetDetails(assetId: string): Promise<APIAsset>;
17
- getAssetInfo(assetId: string): Promise<any>;
18
- sendTransfer(assetId: string, address: string, amount: string): Promise<any>;
19
- getBalances(): Promise<BalanceInfo[]>;
20
- validateWallet(authData: AuthData): Promise<boolean>;
21
- }
22
- export default ServerWallet;
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,QAAQ,CAAC;AASzB,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AASnD,MAAM,YAAY;IACN,SAAS,CAAS;IAClB,SAAS,CAAS;IAE1B,YAAY,MAAyB;QACjC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACtC,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,MAAW;QACjD,MAAM,OAAO,GAAG,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;QAEvD,MAAM,IAAI,GAAG;Y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AO,CAAC;YAE3C,MAAM,YAAY,GAAG,CAAC,CAAC,YAAY,IAAI,YAAY,KAAK,OAAO,CAAC;YAEhE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAChB,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAGD,eAAe,YAAY,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- export declare const ZANO_ASSET_ID = "d6329b5b1f7c0805b5c345f4957554002a2f557845f64d7645dae0e051a6498a";
2
- export declare class ZanoError extends Error {
3
- code: string;
4
- name: string;
5
- constructor(message: string, code: string);
6
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,kEAAkE,CAAC;AAEhG,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEzB,IAAI,CAAS;IACb,IAAI,CAAS;IAEpB,YAAY,OAAe,EAAE,IAAY;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ"}
@@ -1,3 +0,0 @@
1
- import ZanoWallet, { ZanoWalletParams } from './zanoWallet';
2
- declare function useZanoWallet(params: ZanoWalletParams): ZanoWallet | null;
3
- export { useZanoWallet };
package/web/dist/hooks.js DELETED
@@ -1,14 +0,0 @@
1
- import ZanoWallet from './zanoWallet';
2
- import { useEffect, useState } from 'react';
3
- function useZanoWallet(params) {
4
- const [zanoWallet, setZanoWallet] = useState(null);
5
- useEffect(() => {
6
- if (typeof window === 'undefined') {
7
- return;
8
- }
9
- setZanoWallet(new ZanoWallet(params));
10
- }, []);
11
- return zanoWallet;
12
- }
13
- export { useZanoWallet };
14
- //# sourceMappingURL=hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,UAAgC,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,SAAS,aAAa,CAAC,MAAwB;IAC3C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAoB,IAAI,CAAC,CAAC;IAEtE,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,OAAO;QACX,CAAC;QAED,aAAa,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,5 +0,0 @@
1
- import zanoWallet from "./zanoWallet";
2
- import { useZanoWallet } from "./hooks";
3
- export { useZanoWallet };
4
- export * from "./types";
5
- export { zanoWallet };
package/web/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- import zanoWallet from "./zanoWallet";
2
- import { useZanoWallet } from "./hooks";
3
- export { useZanoWallet };
4
- export * from "./types";
5
- export { zanoWallet };
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAC,aAAa,EAAC,CAAC;AAEvB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAC,UAAU,EAAC,CAAC"}
package/web/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,37 +0,0 @@
1
- import { Wallet } from './types';
2
- export interface ZanoWalletParams {
3
- authPath: string;
4
- useLocalStorage?: boolean;
5
- aliasRequired?: boolean;
6
- customLocalStorageKey?: string;
7
- customNonce?: string;
8
- customServerPath?: string;
9
- disableServerRequest?: boolean;
10
- onConnectStart?: (...params: any) => any;
11
- onConnectEnd?: (...params: any) => any;
12
- onConnectError?: (...params: any) => any;
13
- beforeConnect?: (...params: any) => any;
14
- onLocalConnectEnd?: (...params: any) => any;
15
- }
16
- interface WalletCredentials {
17
- nonce: string;
18
- signature: string;
19
- publicKey: string;
20
- address: string;
21
- }
22
- declare class ZanoWallet {
23
- private DEFAULT_LOCAL_STORAGE_KEY;
24
- private localStorageKey;
25
- private params;
26
- private zanoWallet;
27
- constructor(params: ZanoWalletParams);
28
- private handleError;
29
- getSavedWalletCredentials(): WalletCredentials | undefined;
30
- setWalletCredentials(credentials: WalletCredentials | undefined): void;
31
- cleanWalletCredentials(): void;
32
- connect(): Promise<void>;
33
- getWallet(): Promise<Wallet>;
34
- getAddressByAlias(alias: string): Promise<string | undefined>;
35
- createAlias(alias: string): Promise<any>;
36
- }
37
- export default ZanoWallet;
@@ -1 +0,0 @@
1
- {"version":3,"file":"zanoWallet.js","sourceRoot":"","sources":["../src/zanoWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAqCpC,MAAM,UAAU;IAEJ,yBAAyB,GAAG,QAAQ,CAAC;IACrC,eAAe,CAAS;IAExB,MAAM,CAAmB;IACzB,UAAU,CAAmB;IAErC,YAAY,MAAwB;QAEhC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAClE,CAAC;QAED,IAAI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