zano_web3 5.0.0 → 5.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/README.md +160 -68
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -25,12 +25,14 @@ or
|
|
|
25
25
|
yarn add zano_web3
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
# WEB API (extension):
|
|
29
|
+
|
|
28
30
|
## Usage
|
|
29
31
|
|
|
30
32
|
### Importing the Library
|
|
31
33
|
|
|
32
34
|
```typescript
|
|
33
|
-
import ZanoWallet from 'zano_web3';
|
|
35
|
+
import ZanoWallet from 'zano_web3/web';
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
### Creating a ZanoWallet Instance
|
|
@@ -164,99 +166,189 @@ export interface Wallet {
|
|
|
164
166
|
}
|
|
165
167
|
```
|
|
166
168
|
|
|
169
|
+
## Requirements
|
|
167
170
|
|
|
168
|
-
|
|
171
|
+
- ZanoWallet browser extension must be installed.
|
|
169
172
|
|
|
170
|
-
The server-side validator function, `validateWallet`, is used to validate wallet authentication data using the Zano RPC API. It supports authentication using either an alias or a public key.
|
|
171
173
|
|
|
172
|
-
|
|
174
|
+
# Server api (Wallet RPC, Daemon):
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
#### Methods
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
178
|
+
- `updateWalletRpcUrl(rpcUrl: string)`: Updates the wallet RPC URL.
|
|
179
|
+
- `updateDaemonRpcUrl(rpcUrl: string)`: Updates the daemon RPC URL.
|
|
180
|
+
- `getAssetsList()`: Retrieves the list of assets.
|
|
181
|
+
- `getAssetDetails(assetId: string)`: Retrieves details of a specific asset.
|
|
182
|
+
- `getAssetInfo(assetId: string)`: Retrieves info of a specific asset.
|
|
183
|
+
- `sendTransfer(assetId: string, address: string, amount: string)`: Sends a transfer to an address.
|
|
184
|
+
- `getBalances()`: Retrieves the balances.
|
|
185
|
+
- `validateWallet(rpcUrl: string, authData: AuthData)`: Validates the wallet.
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
#### 1. **Updating Wallet RPC URL**
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
import { ServerWallet } from "zano_web3/server";
|
|
192
|
+
|
|
193
|
+
(async () => {
|
|
194
|
+
const zanoServerAPI = new ServerWallet({
|
|
195
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
196
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
195
197
|
});
|
|
198
|
+
|
|
199
|
+
// Update the wallet RPC URL
|
|
200
|
+
await zanoServerAPI.updateWalletRpcUrl("http://new_wallet_url:11211/json_rpc");
|
|
201
|
+
|
|
202
|
+
console.log("Wallet RPC URL updated.");
|
|
203
|
+
})();
|
|
196
204
|
```
|
|
197
205
|
|
|
198
|
-
|
|
206
|
+
#### 2. **Updating Daemon RPC URL**
|
|
199
207
|
|
|
200
|
-
|
|
208
|
+
```javascript
|
|
209
|
+
import { ServerWallet } from "zano_web3/server";
|
|
201
210
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
211
|
+
(async () => {
|
|
212
|
+
const zanoServerAPI = new ServerWallet({
|
|
213
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
214
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
215
|
+
});
|
|
208
216
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
217
|
+
// Update the daemon RPC URL
|
|
218
|
+
await zanoServerAPI.updateDaemonRpcUrl("http://new_daemon_url:11211/json_rpc");
|
|
212
219
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
220
|
+
console.log("Daemon RPC URL updated.");
|
|
221
|
+
})();
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### 3. **Getting the List of Assets**
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
import { ServerWallet } from "zano_web3/server";
|
|
228
|
+
|
|
229
|
+
(async () => {
|
|
230
|
+
const zanoServerAPI = new ServerWallet({
|
|
231
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
232
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Get the list of assets
|
|
236
|
+
const assets = await zanoServerAPI.getAssetsList();
|
|
237
|
+
|
|
238
|
+
console.log("Assets List:", assets);
|
|
239
|
+
})();
|
|
240
|
+
```
|
|
216
241
|
|
|
217
|
-
|
|
242
|
+
#### 4. **Getting Asset Details**
|
|
243
|
+
|
|
244
|
+
```javascript
|
|
245
|
+
import { ServerWallet } from "zano_web3/server";
|
|
246
|
+
|
|
247
|
+
(async () => {
|
|
248
|
+
const zanoServerAPI = new ServerWallet({
|
|
249
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
250
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
// Get details of a specific asset by ID
|
|
254
|
+
const assetId = "example-asset-id";
|
|
255
|
+
const assetDetails = await zanoServerAPI.getAssetDetails(assetId);
|
|
256
|
+
|
|
257
|
+
console.log(`Details for Asset ID ${assetId}:`, assetDetails);
|
|
258
|
+
})();
|
|
218
259
|
```
|
|
219
260
|
|
|
220
|
-
|
|
261
|
+
#### 5. **Getting Asset Info**
|
|
221
262
|
|
|
222
|
-
|
|
263
|
+
```javascript
|
|
264
|
+
import { ServerWallet } from "zano_web3/server";
|
|
223
265
|
|
|
224
|
-
|
|
266
|
+
(async () => {
|
|
267
|
+
const zanoServerAPI = new ServerWallet({
|
|
268
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
269
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
270
|
+
});
|
|
225
271
|
|
|
226
|
-
|
|
272
|
+
// Get info for a specific asset by ID
|
|
273
|
+
const assetId = "example-asset-id";
|
|
274
|
+
const assetInfo = await zanoServerAPI.getAssetInfo(assetId);
|
|
227
275
|
|
|
228
|
-
|
|
229
|
-
|
|
276
|
+
console.log(`Info for Asset ID ${assetId}:`, assetInfo);
|
|
277
|
+
})();
|
|
278
|
+
```
|
|
230
279
|
|
|
231
|
-
|
|
280
|
+
#### 6. **Sending a Transfer**
|
|
232
281
|
|
|
233
|
-
|
|
282
|
+
```javascript
|
|
283
|
+
import { ServerWallet } from "zano_web3/server";
|
|
234
284
|
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
message: 'original_message',
|
|
240
|
-
alias: 'user_alias' // or pkey: 'public_key'
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const rpcUrl = 'https://zano-node.example.com';
|
|
244
|
-
|
|
245
|
-
validateWallet(rpcUrl, authData)
|
|
246
|
-
.then(valid => {
|
|
247
|
-
if (valid) {
|
|
248
|
-
console.log('Wallet is valid');
|
|
249
|
-
} else {
|
|
250
|
-
console.log('Invalid wallet data');
|
|
251
|
-
}
|
|
285
|
+
(async () => {
|
|
286
|
+
const zanoServerAPI = new ServerWallet({
|
|
287
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
288
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
252
289
|
});
|
|
290
|
+
|
|
291
|
+
// Send a transfer
|
|
292
|
+
const assetId = "example-asset-id";
|
|
293
|
+
const address = "recipient-address";
|
|
294
|
+
const amount = "10.5"; // in asset units
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
const transferResult = await zanoServerAPI.sendTransfer(assetId, address, amount);
|
|
298
|
+
console.log("Transfer successful:", transferResult);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.error("Transfer failed:", error.message);
|
|
301
|
+
}
|
|
302
|
+
})();
|
|
253
303
|
```
|
|
254
304
|
|
|
305
|
+
#### 7. **Getting Balances**
|
|
255
306
|
|
|
256
|
-
|
|
307
|
+
```javascript
|
|
308
|
+
import { ServerWallet } from "zano_web3/server";
|
|
257
309
|
|
|
258
|
-
|
|
310
|
+
(async () => {
|
|
311
|
+
const zanoServerAPI = new ServerWallet({
|
|
312
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
313
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Get the balances
|
|
317
|
+
const balances = await zanoServerAPI.getBalances();
|
|
318
|
+
|
|
319
|
+
console.log("Balances:", balances);
|
|
320
|
+
})();
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### 8. **Validating a Wallet**
|
|
324
|
+
|
|
325
|
+
```javascript
|
|
326
|
+
import { ServerWallet } from "zano_web3/server";
|
|
327
|
+
import { AuthData } from "./types";
|
|
259
328
|
|
|
260
|
-
|
|
329
|
+
(async () => {
|
|
330
|
+
const zanoServerAPI = new ServerWallet({
|
|
331
|
+
walletUrl: "http://127.0.0.1:11211/json_rpc",
|
|
332
|
+
daemonUrl: "http://127.0.0.1:11211/json_rpc"
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Validate wallet using AuthData
|
|
336
|
+
const authData: AuthData = {
|
|
337
|
+
message: "message to sign",
|
|
338
|
+
address: "wallet-address",
|
|
339
|
+
signature: "signature",
|
|
340
|
+
alias: "wallet-alias"
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
try {
|
|
344
|
+
const isValid = await zanoServerAPI.validateWallet("http://127.0.0.1:11211/json_rpc", authData);
|
|
345
|
+
console.log("Wallet validation:", isValid ? "Valid" : "Invalid");
|
|
346
|
+
} catch (error) {
|
|
347
|
+
console.error("Validation failed:", error.message);
|
|
348
|
+
}
|
|
349
|
+
})();
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Requirements
|
|
261
353
|
|
|
262
|
-
|
|
354
|
+
- Correct RPC URLs for the wallet and daemon.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zano_web3",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"author": "",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@types/big.js": "^6.2.2",
|
|
26
27
|
"@types/node": "^20.14.12",
|
|
27
28
|
"@types/react": "^18.3.3",
|
|
28
29
|
"@types/uuid": "^10.0.0",
|
|
@@ -35,8 +36,5 @@
|
|
|
35
36
|
"bugs": {
|
|
36
37
|
"url": "https://github.com/hyle-team/zano_web3/issues"
|
|
37
38
|
},
|
|
38
|
-
"homepage": "https://github.com/hyle-team/zano_web3#readme"
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@types/big.js": "^6.2.2"
|
|
41
|
-
}
|
|
39
|
+
"homepage": "https://github.com/hyle-team/zano_web3#readme"
|
|
42
40
|
}
|