@autonomys/auto-utils 0.6.2 → 0.6.4
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 +18 -0
- package/README.md +585 -32
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Autonomys Network (autonomys.xyz)
|
|
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
|
+
1. **Attribution**: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
2. **No Warranty**: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
3. **Limitation of Liability**: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
---
|
package/README.md
CHANGED
|
@@ -1,56 +1,609 @@
|
|
|
1
1
|
# Autonomys Auto SDK Utility
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://github.com/autonomys/auto-sdk/tags)
|
|
6
|
+
[](https://github.com/autonomys/auto-sdk/actions/workflows/build.yaml)
|
|
7
|
+
[](https://badge.fury.io/js/@autonomys%2Fauto-utils)
|
|
8
|
+
|
|
3
9
|
## Overview
|
|
4
10
|
|
|
5
|
-
The Autonomys Auto SDK Utility provides
|
|
11
|
+
The **Autonomys Auto SDK Utility** (`@autonomys/auto-utils`) provides core utility functions for interacting with the Autonomys Network. It offers functionalities for:
|
|
12
|
+
|
|
13
|
+
- **Wallet Management**: Initialize and manage wallets using mnemonics or URIs.
|
|
14
|
+
- **Network Configuration**: Access and manage network and domain settings.
|
|
15
|
+
- **Data Storage**: Save and read data to and from local storage or the file system.
|
|
16
|
+
- **Cryptographic Operations**: Perform hashing and data manipulation using cryptographic functions.
|
|
17
|
+
- **API Activation**: Activate and manage connections to the Autonomys Network APIs.
|
|
18
|
+
- **Address Utilities**: Convert and decode addresses to and from standardized formats.
|
|
19
|
+
|
|
20
|
+
This package serves as the foundational layer for building applications within the Autonomys ecosystem.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Easy Wallet Setup**: Quickly initialize wallets and manage accounts.
|
|
25
|
+
- **Flexible Network Management**: Choose between different networks and domains easily.
|
|
26
|
+
- **Secure Cryptographic Functions**: Utilize robust hashing and data handling functions.
|
|
27
|
+
- **Simplified API Activation**: Streamline connections to network APIs.
|
|
28
|
+
- **Data Persistence**: Easily save and retrieve data within your applications.
|
|
29
|
+
- **TypeScript Support**: Fully typed for enhanced developer experience.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Install the package via npm or yarn:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Using npm
|
|
37
|
+
npm install @autonomys/auto-utils
|
|
38
|
+
|
|
39
|
+
# Using yarn
|
|
40
|
+
yarn add @autonomys/auto-utils
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Getting Started
|
|
44
|
+
|
|
45
|
+
### Prerequisites
|
|
46
|
+
|
|
47
|
+
- **Node.js** (version 14 or higher)
|
|
48
|
+
- **TypeScript** (optional, but recommended for development)
|
|
49
|
+
- Familiarity with async/await and promise handling in JavaScript/TypeScript.
|
|
50
|
+
|
|
51
|
+
## Usage Examples
|
|
52
|
+
|
|
53
|
+
Below are examples demonstrating how to use the functions provided by `@autonomys/auto-utils`.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
### 1. Wallet Management
|
|
58
|
+
|
|
59
|
+
#### **Activate a Wallet**
|
|
60
|
+
|
|
61
|
+
Activate a wallet using a mnemonic phrase:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// Import necessary functions
|
|
65
|
+
import { activateWallet } from '@autonomys/auto-utils'
|
|
66
|
+
;(async () => {
|
|
67
|
+
// Replace with your mnemonic
|
|
68
|
+
const mnemonic = 'your mnemonic phrase here'
|
|
69
|
+
|
|
70
|
+
// Activate the wallet
|
|
71
|
+
const { api, accounts } = await activateWallet({
|
|
72
|
+
mnemonic,
|
|
73
|
+
networkId: 'gemini-3h', // Optional: specify the network ID
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
const account = accounts[0]
|
|
77
|
+
console.log(`Connected with account address: ${account.address}`)
|
|
78
|
+
|
|
79
|
+
// Perform actions with the account...
|
|
80
|
+
|
|
81
|
+
// Disconnect when done
|
|
82
|
+
await api.disconnect()
|
|
83
|
+
})()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Parameters:**
|
|
87
|
+
|
|
88
|
+
- `mnemonic` (string): The mnemonic phrase of the wallet.
|
|
89
|
+
- `networkId` (string, optional): The ID of the network to connect to.
|
|
90
|
+
|
|
91
|
+
**Returns:**
|
|
92
|
+
|
|
93
|
+
- An object containing:
|
|
94
|
+
- `api`: An instance of `ApiPromise` connected to the network.
|
|
95
|
+
- `accounts`: An array of accounts derived from the mnemonic.
|
|
96
|
+
|
|
97
|
+
#### **Activate a Wallet Using URI**
|
|
98
|
+
|
|
99
|
+
You can also activate a wallet using a URI (e.g., `//Alice` for development purposes):
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { activateWallet } from '@autonomys/auto-utils'
|
|
103
|
+
;(async () => {
|
|
104
|
+
const { api, accounts } = await activateWallet({
|
|
105
|
+
uri: '//Alice',
|
|
106
|
+
networkId: 'localhost', // Connect to a local network
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const account = accounts[0]
|
|
110
|
+
console.log(`Connected with account address: ${account.address}`)
|
|
111
|
+
|
|
112
|
+
// Disconnect when done
|
|
113
|
+
await api.disconnect()
|
|
114
|
+
})()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### **Create Mock Wallets for Testing**
|
|
118
|
+
|
|
119
|
+
Create mock wallets for testing purposes:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { activate, mockWallets, getMockWallet } from '@autonomys/auto-utils'
|
|
123
|
+
;(async () => {
|
|
124
|
+
const api = await activate({ networkId: 'gemini-3h' })
|
|
125
|
+
|
|
126
|
+
const wallets = await mockWallets({}, api)
|
|
127
|
+
const aliceWallet = getMockWallet('Alice', wallets)
|
|
128
|
+
const bobWallet = getMockWallet('Bob', wallets)
|
|
129
|
+
|
|
130
|
+
console.log(`Alice's address: ${aliceWallet.accounts[0].address}`)
|
|
131
|
+
console.log(`Bob's address: ${bobWallet.accounts[0].address}`)
|
|
132
|
+
|
|
133
|
+
// Disconnect when done
|
|
134
|
+
await api.disconnect()
|
|
135
|
+
})()
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### 2. Network Management
|
|
141
|
+
|
|
142
|
+
#### **Get Available Networks**
|
|
143
|
+
|
|
144
|
+
List all available networks:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { networks } from '@autonomys/auto-utils'
|
|
148
|
+
|
|
149
|
+
networks.forEach((network) => {
|
|
150
|
+
console.log(`Network ID: ${network.id}, Name: ${network.name}`)
|
|
151
|
+
})
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### **Get Network Details**
|
|
155
|
+
|
|
156
|
+
Retrieve details of a specific network:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { getNetworkDetails } from '@autonomys/auto-utils'
|
|
160
|
+
|
|
161
|
+
const network = getNetworkDetails({ networkId: 'gemini-3h' })
|
|
162
|
+
console.log(`Network Name: ${network.name}`)
|
|
163
|
+
console.log(`RPC URLs: ${network.rpcUrls.join(', ')}`)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### **Get Domain Details**
|
|
167
|
+
|
|
168
|
+
Retrieve details of a specific domain within a network:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { getNetworkDomainDetails } from '@autonomys/auto-utils'
|
|
172
|
+
|
|
173
|
+
const domain = getNetworkDomainDetails({ domainId: '1', networkId: 'gemini-3h' })
|
|
174
|
+
console.log(`Domain Name: ${domain.name}`)
|
|
175
|
+
console.log(`RPC URLs: ${domain.rpcUrls.join(', ')}`)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 3. Cryptographic Functions
|
|
181
|
+
|
|
182
|
+
#### **Hash Data Using BLAKE2b-256**
|
|
183
|
+
|
|
184
|
+
Hash a string using BLAKE2b-256:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { blake2b_256, stringToUint8Array } from '@autonomys/auto-utils'
|
|
188
|
+
|
|
189
|
+
const data = 'Hello, Autonomys!'
|
|
190
|
+
const dataBytes = stringToUint8Array(data)
|
|
191
|
+
const hash = blake2b_256(dataBytes)
|
|
192
|
+
|
|
193
|
+
console.log(`Hash: ${hash}`) // Outputs the hash of the input string
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### **Convert String to Uint8Array**
|
|
197
|
+
|
|
198
|
+
Convert a string to a `Uint8Array`:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { stringToUint8Array } from '@autonomys/auto-utils'
|
|
202
|
+
|
|
203
|
+
const text = 'Sample text'
|
|
204
|
+
const byteArray = stringToUint8Array(text)
|
|
205
|
+
|
|
206
|
+
console.log(byteArray) // Outputs Uint8Array representation of the string
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### **Concatenate Uint8Arrays**
|
|
210
|
+
|
|
211
|
+
Concatenate two `Uint8Array` instances:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { stringToUint8Array, concatenateUint8Arrays } from '@autonomys/auto-utils'
|
|
215
|
+
|
|
216
|
+
const array1 = stringToUint8Array('First part ')
|
|
217
|
+
const array2 = stringToUint8Array('Second part')
|
|
218
|
+
|
|
219
|
+
const concatenated = concatenateUint8Arrays(array1, array2)
|
|
220
|
+
console.log(`Concatenated Result: ${new TextDecoder().decode(concatenated)}`)
|
|
221
|
+
// Outputs: "First part Second part"
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### 4. API Activation
|
|
227
|
+
|
|
228
|
+
#### **Activate the Network API**
|
|
229
|
+
|
|
230
|
+
Connect to the Autonomys Network:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { activate } from '@autonomys/auto-utils'
|
|
234
|
+
;(async () => {
|
|
235
|
+
const api = await activate({ networkId: 'gemini-3h' })
|
|
236
|
+
|
|
237
|
+
console.log('API connected')
|
|
238
|
+
|
|
239
|
+
// Perform API calls...
|
|
240
|
+
|
|
241
|
+
// Disconnect when done
|
|
242
|
+
await api.disconnect()
|
|
243
|
+
})()
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
#### **Activate a Domain API**
|
|
247
|
+
|
|
248
|
+
Connect to a specific domain within the network:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { activateDomain } from '@autonomys/auto-utils'
|
|
252
|
+
;(async () => {
|
|
253
|
+
const api = await activateDomain({ domainId: '1', networkId: 'gemini-3h' })
|
|
254
|
+
|
|
255
|
+
console.log('Domain API connected')
|
|
256
|
+
|
|
257
|
+
// Perform domain-specific API calls...
|
|
258
|
+
|
|
259
|
+
// Disconnect when done
|
|
260
|
+
await api.disconnect()
|
|
261
|
+
})()
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
### 5. Data Storage
|
|
267
|
+
|
|
268
|
+
#### **Save and Read Data**
|
|
269
|
+
|
|
270
|
+
Save data to local storage or the file system and read it back:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { save, read } from '@autonomys/auto-utils'
|
|
274
|
+
|
|
275
|
+
const key = 'myData'
|
|
276
|
+
const value = { message: 'Hello, Autonomys!' }
|
|
277
|
+
|
|
278
|
+
// Save data
|
|
279
|
+
save(key, value)
|
|
280
|
+
|
|
281
|
+
// Read data
|
|
282
|
+
const retrievedValue = read(key)
|
|
283
|
+
console.log(retrievedValue) // Outputs: { message: 'Hello, Autonomys!' }
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
### 6. Address Utilities
|
|
289
|
+
|
|
290
|
+
#### **Convert Address Formats**
|
|
6
291
|
|
|
7
|
-
|
|
292
|
+
Convert an address to a standardized format and decode it:
|
|
8
293
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
294
|
+
```typescript
|
|
295
|
+
import { address, decode } from '@autonomys/auto-utils'
|
|
296
|
+
|
|
297
|
+
const originalAddress = '5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8'
|
|
298
|
+
const standardizedAddress = address(originalAddress)
|
|
299
|
+
const decodedAddress = decode(originalAddress)
|
|
300
|
+
|
|
301
|
+
console.log(`Standardized Address: ${standardizedAddress}`)
|
|
302
|
+
console.log(`Decoded Address:`, decodedAddress)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## API Reference
|
|
308
|
+
|
|
309
|
+
### Wallet Management Functions
|
|
310
|
+
|
|
311
|
+
- **`setupWallet(params: MnemonicOrURI): KeyringPair`**: Initializes a wallet using a mnemonic or URI.
|
|
312
|
+
|
|
313
|
+
- **Parameters**:
|
|
314
|
+
|
|
315
|
+
- `params` (object):
|
|
316
|
+
- `mnemonic` (string, optional): The mnemonic phrase.
|
|
317
|
+
- `uri` (string, optional): The derivation path or URI.
|
|
318
|
+
|
|
319
|
+
- **Returns**: `KeyringPair` - The initialized wallet key pair.
|
|
320
|
+
|
|
321
|
+
- **`activateWallet(params: ActivateWalletParams): Promise<WalletActivated>`**: Activates a wallet and returns API and accounts.
|
|
322
|
+
|
|
323
|
+
- **Parameters**:
|
|
324
|
+
|
|
325
|
+
- `params` (object):
|
|
326
|
+
- `mnemonic` or `uri` (string): Wallet credentials.
|
|
327
|
+
- `networkId` (string, optional): The network ID to connect to.
|
|
328
|
+
|
|
329
|
+
- **Returns**:
|
|
330
|
+
|
|
331
|
+
- **`api`**: Connected `ApiPromise` instance.
|
|
332
|
+
- **`accounts`**: Array of derived accounts.
|
|
333
|
+
|
|
334
|
+
- **`mockWallets(network: NetworkParams | DomainParams, api: ApiPromise): Promise<WalletActivated[]>`**: Creates mock wallets for testing.
|
|
335
|
+
|
|
336
|
+
- **Parameters**:
|
|
337
|
+
|
|
338
|
+
- `network` (object): Network parameters.
|
|
339
|
+
- `api` (`ApiPromise`): Connected API instance.
|
|
340
|
+
|
|
341
|
+
- **Returns**: Array of `WalletActivated` - Mock wallets.
|
|
342
|
+
|
|
343
|
+
- **`getMockWallet(name: string, wallets: WalletActivated[]): WalletActivated`**: Retrieves a mock wallet by name.
|
|
344
|
+
|
|
345
|
+
- **Parameters**:
|
|
346
|
+
|
|
347
|
+
- `name` (string): Name of the mock wallet (e.g., 'Alice', 'Bob').
|
|
348
|
+
- `wallets` (array): Array of `WalletActivated`.
|
|
349
|
+
|
|
350
|
+
- **Returns**: A single `WalletActivated` matching the name.
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
### Network Management Functions
|
|
355
|
+
|
|
356
|
+
- **`getNetworkDetails(input?: NetworkParams): Network`**: Gets network details.
|
|
357
|
+
|
|
358
|
+
- **Parameters**:
|
|
359
|
+
|
|
360
|
+
- `input` (object, optional): Contains `networkId`.
|
|
361
|
+
|
|
362
|
+
- **Returns**: `Network` - Network configuration object.
|
|
363
|
+
|
|
364
|
+
- **`getNetworkRpcUrls(input?: NetworkParams): string[]`**: Gets network RPC URLs.
|
|
365
|
+
|
|
366
|
+
- **Parameters**:
|
|
367
|
+
|
|
368
|
+
- `input` (object, optional): Contains `networkId`.
|
|
369
|
+
|
|
370
|
+
- **Returns**: Array of RPC URL strings.
|
|
371
|
+
|
|
372
|
+
- **`getNetworkDomainDetails(params: DomainParams): Domain`**: Gets domain details.
|
|
373
|
+
|
|
374
|
+
- **Parameters**:
|
|
375
|
+
|
|
376
|
+
- `params` (object): Contains `domainId` and `networkId`.
|
|
377
|
+
|
|
378
|
+
- **Returns**: `Domain` - Domain configuration object.
|
|
379
|
+
|
|
380
|
+
- **`getNetworkDomainRpcUrls(params: DomainParams): string[]`**: Gets domain RPC URLs.
|
|
381
|
+
|
|
382
|
+
- **Parameters**:
|
|
383
|
+
|
|
384
|
+
- `params` (object): Contains `domainId` and `networkId`.
|
|
385
|
+
|
|
386
|
+
- **Returns**: Array of domain RPC URL strings.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
### Data Storage Functions
|
|
391
|
+
|
|
392
|
+
- **`save(key: string, value: any): void`**: Saves data to local storage or file system.
|
|
393
|
+
|
|
394
|
+
- **Parameters**:
|
|
395
|
+
|
|
396
|
+
- `key` (string): Unique identifier for the data.
|
|
397
|
+
- `value` (any): Data to be stored.
|
|
398
|
+
|
|
399
|
+
- **Returns**: `void`
|
|
400
|
+
|
|
401
|
+
- **`read(key: string): any`**: Reads data from local storage or file system.
|
|
402
|
+
|
|
403
|
+
- **Parameters**:
|
|
404
|
+
|
|
405
|
+
- `key` (string): Unique identifier for the data.
|
|
406
|
+
|
|
407
|
+
- **Returns**: The retrieved data.
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
### Cryptographic Functions
|
|
412
|
+
|
|
413
|
+
- **`blake2b_256(data: Uint8Array): string`**: Hashes data with BLAKE2b-256.
|
|
414
|
+
|
|
415
|
+
- **Parameters**:
|
|
416
|
+
|
|
417
|
+
- `data` (`Uint8Array`): Data to be hashed.
|
|
418
|
+
|
|
419
|
+
- **Returns**: Hex string representation of the hash.
|
|
420
|
+
|
|
421
|
+
- **`stringToUint8Array(text: string): Uint8Array`**: Converts a string to a `Uint8Array`.
|
|
422
|
+
|
|
423
|
+
- **Parameters**:
|
|
424
|
+
|
|
425
|
+
- `text` (string): The input string.
|
|
13
426
|
|
|
14
|
-
|
|
427
|
+
- **Returns**: `Uint8Array` representation of the string.
|
|
15
428
|
|
|
16
|
-
-
|
|
17
|
-
- `getNetworkRpcUrls(input?: NetworkParams): string[]`: Gets network RPC URLs.
|
|
18
|
-
- `getNetworkDomainDetails(params: DomainParams): Domain`: Gets domain details.
|
|
19
|
-
- `getNetworkDomainRpcUrls(params: DomainParams): string[]`: Gets domain RPC URLs.
|
|
429
|
+
- **`concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array`**: Concatenates two `Uint8Array` instances.
|
|
20
430
|
|
|
21
|
-
|
|
431
|
+
- **Parameters**:
|
|
22
432
|
|
|
23
|
-
- `
|
|
24
|
-
- `
|
|
433
|
+
- `array1` (`Uint8Array`)
|
|
434
|
+
- `array2` (`Uint8Array`)
|
|
25
435
|
|
|
26
|
-
|
|
436
|
+
- **Returns**: New `Uint8Array` resulting from concatenation.
|
|
27
437
|
|
|
28
|
-
|
|
29
|
-
- `stringToUint8Array(text: string): Uint8Array`: Converts a string to a Uint8Array.
|
|
30
|
-
- `concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array`: Concatenates two Uint8Arrays.
|
|
438
|
+
---
|
|
31
439
|
|
|
32
|
-
|
|
440
|
+
### API Activation Functions
|
|
33
441
|
|
|
34
|
-
-
|
|
35
|
-
- `activateDomain(params: DomainParams): Promise<ApiPromise>`: Activates the API for a domain.
|
|
36
|
-
- `disconnect()`: Disconnects the API.
|
|
37
|
-
- `disconnectDomain()`: Disconnects the domain API.
|
|
442
|
+
- **`activate(params?: ActivateParams<NetworkParams>): Promise<ApiPromise>`**: Activates the API for a network.
|
|
38
443
|
|
|
39
|
-
|
|
444
|
+
- **Parameters**:
|
|
40
445
|
|
|
41
|
-
- `
|
|
42
|
-
- `defaultNetwork`: Default network configuration.
|
|
43
|
-
- `mockURIs`: Array of mock URIs.
|
|
446
|
+
- `params` (object, optional): Network activation parameters.
|
|
44
447
|
|
|
45
|
-
|
|
448
|
+
- **Returns**: `ApiPromise` instance connected to the network.
|
|
46
449
|
|
|
47
|
-
-
|
|
48
|
-
- `Mnemonic`, `URI`, `AppName`, `MnemonicOrURI`
|
|
450
|
+
- **`activateDomain(params: ActivateParams<DomainParams>): Promise<ApiPromise>`**: Activates the API for a domain.
|
|
49
451
|
|
|
50
|
-
|
|
452
|
+
- **Parameters**:
|
|
51
453
|
|
|
52
|
-
|
|
454
|
+
- `params` (object): Domain activation parameters.
|
|
455
|
+
|
|
456
|
+
- **Returns**: `ApiPromise` instance connected to the domain.
|
|
457
|
+
|
|
458
|
+
- **`disconnect(api: ApiPromise): Promise<void>`**: Disconnects the API.
|
|
459
|
+
|
|
460
|
+
- **Parameters**:
|
|
461
|
+
|
|
462
|
+
- `api` (`ApiPromise`): The API instance to disconnect.
|
|
463
|
+
|
|
464
|
+
- **Returns**: `void`
|
|
465
|
+
|
|
466
|
+
---
|
|
467
|
+
|
|
468
|
+
### Address Utilities
|
|
469
|
+
|
|
470
|
+
- **`address(address: string | Uint8Array): string`**: Converts an address to a standardized format.
|
|
471
|
+
|
|
472
|
+
- **Parameters**:
|
|
473
|
+
|
|
474
|
+
- `address` (string | `Uint8Array`): The original address.
|
|
475
|
+
|
|
476
|
+
- **Returns**: Standardized address string.
|
|
477
|
+
|
|
478
|
+
- **`decode(address: string): Uint8Array`**: Decodes an address into a `Uint8Array`.
|
|
479
|
+
|
|
480
|
+
- **Parameters**:
|
|
481
|
+
|
|
482
|
+
- `address` (string): The address to decode.
|
|
483
|
+
|
|
484
|
+
- **Returns**: `Uint8Array` representation of the address.
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
### Constants
|
|
489
|
+
|
|
490
|
+
- **`networks`**: Array of network configurations.
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
import { networks } from '@autonomys/auto-utils'
|
|
494
|
+
|
|
495
|
+
// Example usage
|
|
496
|
+
networks.forEach((network) => {
|
|
497
|
+
console.log(network.id, network.name)
|
|
498
|
+
})
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
- **`defaultNetwork`**: Default network configuration.
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import { defaultNetwork } from '@autonomys/auto-utils'
|
|
505
|
+
|
|
506
|
+
console.log(`Default Network: ${defaultNetwork.name}`)
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
- **`mockURIs`**: Array of mock URIs.
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
import { mockURIs } from '@autonomys/auto-utils'
|
|
513
|
+
|
|
514
|
+
console.log(`Available mock URIs: ${mockURIs.join(', ')}`)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
### Types
|
|
520
|
+
|
|
521
|
+
- **`Network`**, **`Domain`**, **`Explorer`**, **`NetworkParams`**, **`DomainParams`**
|
|
522
|
+
- **`Mnemonic`**, **`URI`**, **`AppName`**, **`MnemonicOrURI`**
|
|
523
|
+
|
|
524
|
+
These types are available for TypeScript users to ensure type safety and better development experience.
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## Error Handling
|
|
529
|
+
|
|
530
|
+
When using `@autonomys/auto-utils`, it's important to handle potential errors, especially when dealing with asynchronous operations like network connections or wallet activations. Make use of `try/catch` blocks or handle promise rejections appropriately.
|
|
531
|
+
|
|
532
|
+
**Example:**
|
|
53
533
|
|
|
54
534
|
```typescript
|
|
55
535
|
import { activateWallet } from '@autonomys/auto-utils'
|
|
536
|
+
;(async () => {
|
|
537
|
+
try {
|
|
538
|
+
const { api, accounts } = await activateWallet({
|
|
539
|
+
mnemonic: 'your mnemonic',
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
// Proceed with using the api and accounts
|
|
543
|
+
} catch (error) {
|
|
544
|
+
console.error('Error activating wallet:', error)
|
|
545
|
+
}
|
|
546
|
+
})()
|
|
56
547
|
```
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## Contributing
|
|
552
|
+
|
|
553
|
+
We welcome community contributions! If you wish to contribute to `@autonomys/auto-utils`, please follow these guidelines:
|
|
554
|
+
|
|
555
|
+
1. **Fork the repository** on GitHub.
|
|
556
|
+
|
|
557
|
+
2. **Clone your fork** locally:
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
git clone https://github.com/your-username/auto-sdk.git
|
|
561
|
+
cd auto-sdk/packages/auto-utils
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
3. **Install dependencies**:
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
yarn install
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
4. **Make your changes** and ensure all tests pass:
|
|
571
|
+
|
|
572
|
+
```bash
|
|
573
|
+
yarn test
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
5. **Commit your changes** with clear and descriptive messages.
|
|
577
|
+
|
|
578
|
+
6. **Push to your fork** and **create a pull request** against the `main` branch of the original repository.
|
|
579
|
+
|
|
580
|
+
### Code Style
|
|
581
|
+
|
|
582
|
+
- Use **TypeScript** for all code.
|
|
583
|
+
- Follow the existing coding conventions.
|
|
584
|
+
- Run `yarn lint` to ensure code style consistency.
|
|
585
|
+
|
|
586
|
+
### Testing
|
|
587
|
+
|
|
588
|
+
- Add tests for any new features or bug fixes.
|
|
589
|
+
- Ensure all existing tests pass.
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
## License
|
|
594
|
+
|
|
595
|
+
This project is licensed under the MIT License. See the [LICENSE](../LICENSE) file for details.
|
|
596
|
+
|
|
597
|
+
---
|
|
598
|
+
|
|
599
|
+
## Additional Resources
|
|
600
|
+
|
|
601
|
+
- **Autonomys Academy**: Learn more about the Autonomys SDK and the vision behind it at [Autonomys Academy](https://academy.autonomys.xyz).
|
|
602
|
+
|
|
603
|
+
## Contact
|
|
604
|
+
|
|
605
|
+
If you have any questions or need support, feel free to reach out:
|
|
606
|
+
|
|
607
|
+
- **GitHub Issues**: [GitHub Issues Page](https://github.com/autonomys/auto-sdk/issues)
|
|
608
|
+
|
|
609
|
+
We appreciate your feedback and contributions!
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-utils",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"browser": {
|
|
39
39
|
"fs": false
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "cbeaa151644f75d43e7e36b5a817d580bff09ebd"
|
|
42
42
|
}
|