@autonomys/auto-utils 1.5.2 → 1.5.3
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/dist/address.d.ts +54 -0
- package/dist/address.d.ts.map +1 -1
- package/dist/address.js +54 -0
- package/dist/api.d.ts +148 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +148 -0
- package/dist/crypto.d.ts +28 -0
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +28 -0
- package/dist/network.d.ts +150 -0
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +150 -0
- package/dist/number.d.ts +91 -0
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +91 -0
- package/dist/string.d.ts +110 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +110 -0
- package/dist/utils/detectTxSuccess.d.ts +31 -0
- package/dist/utils/detectTxSuccess.d.ts.map +1 -1
- package/dist/utils/detectTxSuccess.js +31 -0
- package/dist/utils/events.d.ts +75 -0
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/events.js +76 -0
- package/dist/utils/format.d.ts +8 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/ready.d.ts +8 -0
- package/dist/utils/ready.d.ts.map +1 -1
- package/dist/utils/sign.d.ts +66 -0
- package/dist/utils/sign.d.ts.map +1 -1
- package/dist/utils/sign.js +58 -0
- package/dist/utils/signAndSendTx.d.ts +71 -0
- package/dist/utils/signAndSendTx.d.ts.map +1 -1
- package/dist/utils/signAndSendTx.js +71 -0
- package/dist/utils/validateEvents.d.ts +67 -0
- package/dist/utils/validateEvents.d.ts.map +1 -1
- package/dist/utils/validateEvents.js +68 -1
- package/dist/utils/verify.d.ts +8 -0
- package/dist/utils/verify.d.ts.map +1 -1
- package/dist/wallet.d.ts +204 -0
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +204 -0
- package/package.json +2 -2
package/dist/address.d.ts
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an address to the standard Autonomys Network format with SS58 encoding.
|
|
3
|
+
*
|
|
4
|
+
* This function standardizes addresses across the Autonomys Network by encoding them
|
|
5
|
+
* using the SS58 format. It accepts both string addresses and Uint8Array representations,
|
|
6
|
+
* making it flexible for various use cases.
|
|
7
|
+
*
|
|
8
|
+
* @param address - The address to convert. Can be a string address or Uint8Array public key.
|
|
9
|
+
* @param ss58Format - The SS58 format number to use for encoding. Defaults to the mainnet format.
|
|
10
|
+
* @returns The standardized address string in SS58 format.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import { address } from '@autonomys/auto-utils'
|
|
14
|
+
*
|
|
15
|
+
* // Convert a raw address to mainnet format
|
|
16
|
+
* const mainnetAddress = address('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
|
17
|
+
* console.log(mainnetAddress) // Output: standardized mainnet address
|
|
18
|
+
*
|
|
19
|
+
* // Convert using custom SS58 format
|
|
20
|
+
* const customAddress = address('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 42)
|
|
21
|
+
* console.log(customAddress) // Output: address in format 42
|
|
22
|
+
*
|
|
23
|
+
* // Convert from Uint8Array public key
|
|
24
|
+
* const publicKey = new Uint8Array(32) // 32-byte public key
|
|
25
|
+
* const addressFromPubKey = address(publicKey)
|
|
26
|
+
* console.log(addressFromPubKey) // Output: standardized address
|
|
27
|
+
*
|
|
28
|
+
* @throws {Error} When the input address is invalid or cannot be encoded.
|
|
29
|
+
*/
|
|
1
30
|
export declare const address: (address: string | Uint8Array, ss58Format?: number) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Decodes an SS58 address to its raw Uint8Array representation.
|
|
33
|
+
*
|
|
34
|
+
* This function extracts the underlying public key bytes from an SS58-encoded address.
|
|
35
|
+
* It's useful when you need to work with the raw address data for cryptographic operations
|
|
36
|
+
* or when interfacing with lower-level blockchain functions.
|
|
37
|
+
*
|
|
38
|
+
* @param address - The SS58-encoded address string to decode.
|
|
39
|
+
* @returns The decoded address as a Uint8Array (32 bytes for most address types).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* import { decode } from '@autonomys/auto-utils'
|
|
43
|
+
*
|
|
44
|
+
* // Decode a mainnet address
|
|
45
|
+
* const addressString = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
|
|
46
|
+
* const publicKeyBytes = decode(addressString)
|
|
47
|
+
* console.log(publicKeyBytes) // Output: Uint8Array(32) [...]
|
|
48
|
+
* console.log(publicKeyBytes.length) // Output: 32
|
|
49
|
+
*
|
|
50
|
+
* // Use decoded bytes for cryptographic operations
|
|
51
|
+
* const decoded = decode('5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8')
|
|
52
|
+
* // decoded can now be used with other crypto functions
|
|
53
|
+
*
|
|
54
|
+
* @throws {Error} When the address is invalid, malformed, or has an incorrect checksum.
|
|
55
|
+
*/
|
|
2
56
|
export declare const decode: (address: string) => Uint8Array;
|
|
3
57
|
//# sourceMappingURL=address.d.ts.map
|
package/dist/address.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,GAClB,SAAS,MAAM,GAAG,UAAU,EAC5B,aAAY,MAA4B,KACvC,MAA4C,CAAA;AAE/C,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,KAAG,UAAoC,CAAA"}
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,OAAO,GAClB,SAAS,MAAM,GAAG,UAAU,EAC5B,aAAY,MAA4B,KACvC,MAA4C,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,KAAG,UAAoC,CAAA"}
|
package/dist/address.js
CHANGED
|
@@ -4,7 +4,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.decode = exports.address = void 0;
|
|
5
5
|
const keyring_1 = require("@polkadot/keyring");
|
|
6
6
|
const wallet_1 = require("./constants/wallet");
|
|
7
|
+
/**
|
|
8
|
+
* Converts an address to the standard Autonomys Network format with SS58 encoding.
|
|
9
|
+
*
|
|
10
|
+
* This function standardizes addresses across the Autonomys Network by encoding them
|
|
11
|
+
* using the SS58 format. It accepts both string addresses and Uint8Array representations,
|
|
12
|
+
* making it flexible for various use cases.
|
|
13
|
+
*
|
|
14
|
+
* @param address - The address to convert. Can be a string address or Uint8Array public key.
|
|
15
|
+
* @param ss58Format - The SS58 format number to use for encoding. Defaults to the mainnet format.
|
|
16
|
+
* @returns The standardized address string in SS58 format.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* import { address } from '@autonomys/auto-utils'
|
|
20
|
+
*
|
|
21
|
+
* // Convert a raw address to mainnet format
|
|
22
|
+
* const mainnetAddress = address('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
|
|
23
|
+
* console.log(mainnetAddress) // Output: standardized mainnet address
|
|
24
|
+
*
|
|
25
|
+
* // Convert using custom SS58 format
|
|
26
|
+
* const customAddress = address('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 42)
|
|
27
|
+
* console.log(customAddress) // Output: address in format 42
|
|
28
|
+
*
|
|
29
|
+
* // Convert from Uint8Array public key
|
|
30
|
+
* const publicKey = new Uint8Array(32) // 32-byte public key
|
|
31
|
+
* const addressFromPubKey = address(publicKey)
|
|
32
|
+
* console.log(addressFromPubKey) // Output: standardized address
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error} When the input address is invalid or cannot be encoded.
|
|
35
|
+
*/
|
|
7
36
|
const address = (address, ss58Format = wallet_1.DEFAULT_SS58_FORMAT) => (0, keyring_1.encodeAddress)(address, ss58Format);
|
|
8
37
|
exports.address = address;
|
|
38
|
+
/**
|
|
39
|
+
* Decodes an SS58 address to its raw Uint8Array representation.
|
|
40
|
+
*
|
|
41
|
+
* This function extracts the underlying public key bytes from an SS58-encoded address.
|
|
42
|
+
* It's useful when you need to work with the raw address data for cryptographic operations
|
|
43
|
+
* or when interfacing with lower-level blockchain functions.
|
|
44
|
+
*
|
|
45
|
+
* @param address - The SS58-encoded address string to decode.
|
|
46
|
+
* @returns The decoded address as a Uint8Array (32 bytes for most address types).
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* import { decode } from '@autonomys/auto-utils'
|
|
50
|
+
*
|
|
51
|
+
* // Decode a mainnet address
|
|
52
|
+
* const addressString = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
|
|
53
|
+
* const publicKeyBytes = decode(addressString)
|
|
54
|
+
* console.log(publicKeyBytes) // Output: Uint8Array(32) [...]
|
|
55
|
+
* console.log(publicKeyBytes.length) // Output: 32
|
|
56
|
+
*
|
|
57
|
+
* // Use decoded bytes for cryptographic operations
|
|
58
|
+
* const decoded = decode('5GmS1wtCfR4tK5SSgnZbVT4kYw5W8NmxmijcsxCQE6oLW6A8')
|
|
59
|
+
* // decoded can now be used with other crypto functions
|
|
60
|
+
*
|
|
61
|
+
* @throws {Error} When the address is invalid, malformed, or has an incorrect checksum.
|
|
62
|
+
*/
|
|
9
63
|
const decode = (address) => (0, keyring_1.decodeAddress)(address);
|
|
10
64
|
exports.decode = decode;
|
package/dist/api.d.ts
CHANGED
|
@@ -1,7 +1,155 @@
|
|
|
1
1
|
import { ApiPromise } from '@polkadot/api';
|
|
2
2
|
import { ActivateParams, ApiOptions, DomainParams, NetworkParams } from './types/network';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a connection to a Polkadot.js API instance with WebSocket provider.
|
|
5
|
+
*
|
|
6
|
+
* This function establishes a WebSocket connection to the Autonomys Network or domain
|
|
7
|
+
* and returns a fully initialized ApiPromise instance. It automatically includes
|
|
8
|
+
* the necessary chain types and waits for the API to be ready before returning.
|
|
9
|
+
*
|
|
10
|
+
* @param endpoint - The WebSocket endpoint URL(s) to connect to. Can be a single URL or array of URLs.
|
|
11
|
+
* @param options - Optional configuration for the API instance.
|
|
12
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { createConnection } from '@autonomys/auto-utils'
|
|
16
|
+
*
|
|
17
|
+
* // Connect to single endpoint
|
|
18
|
+
* const api = await createConnection('wss://rpc-0.taurus.autonomys.xyz/ws')
|
|
19
|
+
* console.log('Connected to API')
|
|
20
|
+
*
|
|
21
|
+
* // Connect with multiple endpoints for failover
|
|
22
|
+
* const endpoints = [
|
|
23
|
+
* 'wss://rpc-0.taurus.autonomys.xyz/ws',
|
|
24
|
+
* 'wss://rpc-1.taurus.autonomys.xyz/ws'
|
|
25
|
+
* ]
|
|
26
|
+
* const apiWithFailover = await createConnection(endpoints)
|
|
27
|
+
*
|
|
28
|
+
* // Connect with custom options
|
|
29
|
+
* const customApi = await createConnection(
|
|
30
|
+
* 'wss://rpc-0.taurus.autonomys.xyz/ws',
|
|
31
|
+
* {
|
|
32
|
+
* noInitWarn: false,
|
|
33
|
+
* types: { CustomType: 'u32' }
|
|
34
|
+
* }
|
|
35
|
+
* )
|
|
36
|
+
*
|
|
37
|
+
* // Always disconnect when done
|
|
38
|
+
* await api.disconnect()
|
|
39
|
+
*
|
|
40
|
+
* @throws {Error} When connection fails or API initialization fails.
|
|
41
|
+
*/
|
|
3
42
|
export declare const createConnection: (endpoint: string | string[], options?: ApiOptions) => Promise<ApiPromise>;
|
|
43
|
+
/**
|
|
44
|
+
* Activates a connection to the Autonomys Network consensus layer.
|
|
45
|
+
*
|
|
46
|
+
* This function simplifies connecting to the Autonomys Network by automatically
|
|
47
|
+
* resolving the network RPC URLs and establishing a connection. It supports all
|
|
48
|
+
* available networks including mainnet, testnet, and local development networks.
|
|
49
|
+
*
|
|
50
|
+
* @param params - Optional network activation parameters including networkId and API options.
|
|
51
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance for the consensus layer.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
55
|
+
*
|
|
56
|
+
* // Connect to default network (mainnet)
|
|
57
|
+
* const api = await activate()
|
|
58
|
+
* console.log('Connected to mainnet')
|
|
59
|
+
*
|
|
60
|
+
* // Connect to specific network
|
|
61
|
+
* const taurusApi = await activate({ networkId: 'taurus' })
|
|
62
|
+
* console.log('Connected to Taurus testnet')
|
|
63
|
+
*
|
|
64
|
+
* // Connect to local development network
|
|
65
|
+
* const localApi = await activate({ networkId: 'localhost' })
|
|
66
|
+
* console.log('Connected to localhost')
|
|
67
|
+
*
|
|
68
|
+
* // Connect with custom API options
|
|
69
|
+
* const customApi = await activate({
|
|
70
|
+
* networkId: 'gemini-3h',
|
|
71
|
+
* noInitWarn: false,
|
|
72
|
+
* types: { CustomType: 'u64' }
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* // Always disconnect when done
|
|
76
|
+
* await api.disconnect()
|
|
77
|
+
*
|
|
78
|
+
* @throws {Error} When the specified network is not found or connection fails.
|
|
79
|
+
*/
|
|
4
80
|
export declare const activate: (params?: ActivateParams<NetworkParams>) => Promise<ApiPromise>;
|
|
81
|
+
/**
|
|
82
|
+
* Activates a connection to a specific domain within the Autonomys Network.
|
|
83
|
+
*
|
|
84
|
+
* This function connects to domain-specific networks like Auto-EVM or Auto-ID
|
|
85
|
+
* which run as domains on top of the Autonomys consensus layer. Each domain
|
|
86
|
+
* has its own RPC endpoints and may have domain-specific functionality.
|
|
87
|
+
*
|
|
88
|
+
* @param params - Domain activation parameters including networkId, domainId, and API options.
|
|
89
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance for the specified domain.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* import { activateDomain } from '@autonomys/auto-utils'
|
|
93
|
+
*
|
|
94
|
+
* // Connect to Auto-EVM domain on Taurus testnet
|
|
95
|
+
* const evmApi = await activateDomain({
|
|
96
|
+
* networkId: 'taurus',
|
|
97
|
+
* domainId: '0'
|
|
98
|
+
* })
|
|
99
|
+
* console.log('Connected to Auto-EVM domain')
|
|
100
|
+
*
|
|
101
|
+
* // Connect to Auto-ID domain on Gemini-3H
|
|
102
|
+
* const autoIdApi = await activateDomain({
|
|
103
|
+
* networkId: 'gemini-3h',
|
|
104
|
+
* domainId: '1'
|
|
105
|
+
* })
|
|
106
|
+
* console.log('Connected to Auto-ID domain')
|
|
107
|
+
*
|
|
108
|
+
* // Connect to localhost domain for development
|
|
109
|
+
* const localDomainApi = await activateDomain({
|
|
110
|
+
* networkId: 'localhost',
|
|
111
|
+
* domainId: '0'
|
|
112
|
+
* })
|
|
113
|
+
*
|
|
114
|
+
* // Connect with custom API options
|
|
115
|
+
* const customDomainApi = await activateDomain({
|
|
116
|
+
* networkId: 'taurus',
|
|
117
|
+
* domainId: '0',
|
|
118
|
+
* noInitWarn: false
|
|
119
|
+
* })
|
|
120
|
+
*
|
|
121
|
+
* // Always disconnect when done
|
|
122
|
+
* await evmApi.disconnect()
|
|
123
|
+
*
|
|
124
|
+
* @throws {Error} When the specified network or domain is not found, or connection fails.
|
|
125
|
+
*/
|
|
5
126
|
export declare const activateDomain: (params: ActivateParams<DomainParams>) => Promise<ApiPromise>;
|
|
127
|
+
/**
|
|
128
|
+
* Disconnects an active API connection and cleans up resources.
|
|
129
|
+
*
|
|
130
|
+
* This function properly closes the WebSocket connection and cleans up any
|
|
131
|
+
* resources associated with the API instance. It should always be called
|
|
132
|
+
* when you're done using an API connection to prevent resource leaks.
|
|
133
|
+
*
|
|
134
|
+
* @param api - The ApiPromise instance to disconnect.
|
|
135
|
+
* @returns A Promise that resolves when the disconnection is complete.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* import { activate, disconnect } from '@autonomys/auto-utils'
|
|
139
|
+
*
|
|
140
|
+
* // Connect and then disconnect
|
|
141
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
142
|
+
*
|
|
143
|
+
* // Use the API for operations...
|
|
144
|
+
* const chainInfo = await api.rpc.system.chain()
|
|
145
|
+
* console.log('Chain:', chainInfo.toString())
|
|
146
|
+
*
|
|
147
|
+
* // Always disconnect when done
|
|
148
|
+
* await disconnect(api)
|
|
149
|
+
* console.log('API disconnected')
|
|
150
|
+
*
|
|
151
|
+
* // Or use the API instance method directly
|
|
152
|
+
* // await api.disconnect()
|
|
153
|
+
*/
|
|
6
154
|
export declare const disconnect: (api: ApiPromise) => Promise<void>;
|
|
7
155
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,eAAe,CAAA;AAEtD,OAAO,EACL,cAAc,EACd,UAAU,EAEV,YAAY,EACZ,aAAa,EACd,MAAM,iBAAiB,CAAA;AAExB,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,GAAG,MAAM,EAAE,EAC3B,UAAU,UAAU,KACnB,OAAO,CAAC,UAAU,CAapB,CAAA;AAED,eAAO,MAAM,QAAQ,GAAU,SAAS,cAAc,CAAC,aAAa,CAAC,KAAG,OAAO,CAAC,UAAU,CAOzF,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,QAAQ,cAAc,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,UAAU,CAQ7F,CAAA;AAED,eAAO,MAAM,UAAU,GAAU,KAAK,UAAU,KAAG,OAAO,CAAC,IAAI,CAG9D,CAAA"}
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,eAAe,CAAA;AAEtD,OAAO,EACL,cAAc,EACd,UAAU,EAEV,YAAY,EACZ,aAAa,EACd,MAAM,iBAAiB,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,MAAM,GAAG,MAAM,EAAE,EAC3B,UAAU,UAAU,KACnB,OAAO,CAAC,UAAU,CAapB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,QAAQ,GAAU,SAAS,cAAc,CAAC,aAAa,CAAC,KAAG,OAAO,CAAC,UAAU,CAOzF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,cAAc,GAAU,QAAQ,cAAc,CAAC,YAAY,CAAC,KAAG,OAAO,CAAC,UAAU,CAQ7F,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,UAAU,GAAU,KAAK,UAAU,KAAG,OAAO,CAAC,IAAI,CAG9D,CAAA"}
|
package/dist/api.js
CHANGED
|
@@ -24,6 +24,45 @@ exports.disconnect = exports.activateDomain = exports.activate = exports.createC
|
|
|
24
24
|
const api_1 = require("@polkadot/api");
|
|
25
25
|
const network_1 = require("./network");
|
|
26
26
|
const network_2 = require("./types/network");
|
|
27
|
+
/**
|
|
28
|
+
* Creates a connection to a Polkadot.js API instance with WebSocket provider.
|
|
29
|
+
*
|
|
30
|
+
* This function establishes a WebSocket connection to the Autonomys Network or domain
|
|
31
|
+
* and returns a fully initialized ApiPromise instance. It automatically includes
|
|
32
|
+
* the necessary chain types and waits for the API to be ready before returning.
|
|
33
|
+
*
|
|
34
|
+
* @param endpoint - The WebSocket endpoint URL(s) to connect to. Can be a single URL or array of URLs.
|
|
35
|
+
* @param options - Optional configuration for the API instance.
|
|
36
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import { createConnection } from '@autonomys/auto-utils'
|
|
40
|
+
*
|
|
41
|
+
* // Connect to single endpoint
|
|
42
|
+
* const api = await createConnection('wss://rpc-0.taurus.autonomys.xyz/ws')
|
|
43
|
+
* console.log('Connected to API')
|
|
44
|
+
*
|
|
45
|
+
* // Connect with multiple endpoints for failover
|
|
46
|
+
* const endpoints = [
|
|
47
|
+
* 'wss://rpc-0.taurus.autonomys.xyz/ws',
|
|
48
|
+
* 'wss://rpc-1.taurus.autonomys.xyz/ws'
|
|
49
|
+
* ]
|
|
50
|
+
* const apiWithFailover = await createConnection(endpoints)
|
|
51
|
+
*
|
|
52
|
+
* // Connect with custom options
|
|
53
|
+
* const customApi = await createConnection(
|
|
54
|
+
* 'wss://rpc-0.taurus.autonomys.xyz/ws',
|
|
55
|
+
* {
|
|
56
|
+
* noInitWarn: false,
|
|
57
|
+
* types: { CustomType: 'u32' }
|
|
58
|
+
* }
|
|
59
|
+
* )
|
|
60
|
+
*
|
|
61
|
+
* // Always disconnect when done
|
|
62
|
+
* await api.disconnect()
|
|
63
|
+
*
|
|
64
|
+
* @throws {Error} When connection fails or API initialization fails.
|
|
65
|
+
*/
|
|
27
66
|
const createConnection = (endpoint, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
67
|
var _a;
|
|
29
68
|
// Create the provider
|
|
@@ -34,6 +73,43 @@ const createConnection = (endpoint, options) => __awaiter(void 0, void 0, void 0
|
|
|
34
73
|
return api;
|
|
35
74
|
});
|
|
36
75
|
exports.createConnection = createConnection;
|
|
76
|
+
/**
|
|
77
|
+
* Activates a connection to the Autonomys Network consensus layer.
|
|
78
|
+
*
|
|
79
|
+
* This function simplifies connecting to the Autonomys Network by automatically
|
|
80
|
+
* resolving the network RPC URLs and establishing a connection. It supports all
|
|
81
|
+
* available networks including mainnet, testnet, and local development networks.
|
|
82
|
+
*
|
|
83
|
+
* @param params - Optional network activation parameters including networkId and API options.
|
|
84
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance for the consensus layer.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
88
|
+
*
|
|
89
|
+
* // Connect to default network (mainnet)
|
|
90
|
+
* const api = await activate()
|
|
91
|
+
* console.log('Connected to mainnet')
|
|
92
|
+
*
|
|
93
|
+
* // Connect to specific network
|
|
94
|
+
* const taurusApi = await activate({ networkId: 'taurus' })
|
|
95
|
+
* console.log('Connected to Taurus testnet')
|
|
96
|
+
*
|
|
97
|
+
* // Connect to local development network
|
|
98
|
+
* const localApi = await activate({ networkId: 'localhost' })
|
|
99
|
+
* console.log('Connected to localhost')
|
|
100
|
+
*
|
|
101
|
+
* // Connect with custom API options
|
|
102
|
+
* const customApi = await activate({
|
|
103
|
+
* networkId: 'gemini-3h',
|
|
104
|
+
* noInitWarn: false,
|
|
105
|
+
* types: { CustomType: 'u64' }
|
|
106
|
+
* })
|
|
107
|
+
*
|
|
108
|
+
* // Always disconnect when done
|
|
109
|
+
* await api.disconnect()
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} When the specified network is not found or connection fails.
|
|
112
|
+
*/
|
|
37
113
|
const activate = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
114
|
// Get the first rpc urls for the network
|
|
39
115
|
const endpoint = (0, network_1.getNetworkRpcUrls)(params);
|
|
@@ -43,6 +119,51 @@ const activate = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
43
119
|
return yield (0, exports.createConnection)(endpoint, params);
|
|
44
120
|
});
|
|
45
121
|
exports.activate = activate;
|
|
122
|
+
/**
|
|
123
|
+
* Activates a connection to a specific domain within the Autonomys Network.
|
|
124
|
+
*
|
|
125
|
+
* This function connects to domain-specific networks like Auto-EVM or Auto-ID
|
|
126
|
+
* which run as domains on top of the Autonomys consensus layer. Each domain
|
|
127
|
+
* has its own RPC endpoints and may have domain-specific functionality.
|
|
128
|
+
*
|
|
129
|
+
* @param params - Domain activation parameters including networkId, domainId, and API options.
|
|
130
|
+
* @returns A Promise that resolves to an initialized ApiPromise instance for the specified domain.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* import { activateDomain } from '@autonomys/auto-utils'
|
|
134
|
+
*
|
|
135
|
+
* // Connect to Auto-EVM domain on Taurus testnet
|
|
136
|
+
* const evmApi = await activateDomain({
|
|
137
|
+
* networkId: 'taurus',
|
|
138
|
+
* domainId: '0'
|
|
139
|
+
* })
|
|
140
|
+
* console.log('Connected to Auto-EVM domain')
|
|
141
|
+
*
|
|
142
|
+
* // Connect to Auto-ID domain on Gemini-3H
|
|
143
|
+
* const autoIdApi = await activateDomain({
|
|
144
|
+
* networkId: 'gemini-3h',
|
|
145
|
+
* domainId: '1'
|
|
146
|
+
* })
|
|
147
|
+
* console.log('Connected to Auto-ID domain')
|
|
148
|
+
*
|
|
149
|
+
* // Connect to localhost domain for development
|
|
150
|
+
* const localDomainApi = await activateDomain({
|
|
151
|
+
* networkId: 'localhost',
|
|
152
|
+
* domainId: '0'
|
|
153
|
+
* })
|
|
154
|
+
*
|
|
155
|
+
* // Connect with custom API options
|
|
156
|
+
* const customDomainApi = await activateDomain({
|
|
157
|
+
* networkId: 'taurus',
|
|
158
|
+
* domainId: '0',
|
|
159
|
+
* noInitWarn: false
|
|
160
|
+
* })
|
|
161
|
+
*
|
|
162
|
+
* // Always disconnect when done
|
|
163
|
+
* await evmApi.disconnect()
|
|
164
|
+
*
|
|
165
|
+
* @throws {Error} When the specified network or domain is not found, or connection fails.
|
|
166
|
+
*/
|
|
46
167
|
const activateDomain = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
168
|
// Get the first rpc urls for the network
|
|
48
169
|
const endpoint = (0, network_1.getNetworkDomainRpcUrls)(params);
|
|
@@ -52,6 +173,33 @@ const activateDomain = (params) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
52
173
|
return yield (0, exports.createConnection)(endpoint, rest);
|
|
53
174
|
});
|
|
54
175
|
exports.activateDomain = activateDomain;
|
|
176
|
+
/**
|
|
177
|
+
* Disconnects an active API connection and cleans up resources.
|
|
178
|
+
*
|
|
179
|
+
* This function properly closes the WebSocket connection and cleans up any
|
|
180
|
+
* resources associated with the API instance. It should always be called
|
|
181
|
+
* when you're done using an API connection to prevent resource leaks.
|
|
182
|
+
*
|
|
183
|
+
* @param api - The ApiPromise instance to disconnect.
|
|
184
|
+
* @returns A Promise that resolves when the disconnection is complete.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* import { activate, disconnect } from '@autonomys/auto-utils'
|
|
188
|
+
*
|
|
189
|
+
* // Connect and then disconnect
|
|
190
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
191
|
+
*
|
|
192
|
+
* // Use the API for operations...
|
|
193
|
+
* const chainInfo = await api.rpc.system.chain()
|
|
194
|
+
* console.log('Chain:', chainInfo.toString())
|
|
195
|
+
*
|
|
196
|
+
* // Always disconnect when done
|
|
197
|
+
* await disconnect(api)
|
|
198
|
+
* console.log('API disconnected')
|
|
199
|
+
*
|
|
200
|
+
* // Or use the API instance method directly
|
|
201
|
+
* // await api.disconnect()
|
|
202
|
+
*/
|
|
55
203
|
const disconnect = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
204
|
// Disconnect the API instance and the provider
|
|
57
205
|
yield api.disconnect();
|
package/dist/crypto.d.ts
CHANGED
|
@@ -23,6 +23,34 @@ export declare function blake2b_256(data: Uint8Array): string;
|
|
|
23
23
|
export declare function stringToUint8Array(text: string): Uint8Array;
|
|
24
24
|
/**
|
|
25
25
|
* Concatenates two Uint8Array instances into a single Uint8Array.
|
|
26
|
+
*
|
|
27
|
+
* This function efficiently combines two byte arrays into a single array, preserving
|
|
28
|
+
* the order of the input arrays. It's commonly used for combining data before hashing,
|
|
29
|
+
* creating composite data structures, or preparing data for cryptographic operations.
|
|
30
|
+
*
|
|
31
|
+
* @param array1 - The first Uint8Array to concatenate.
|
|
32
|
+
* @param array2 - The second Uint8Array to concatenate.
|
|
33
|
+
* @returns A new Uint8Array containing all bytes from array1 followed by all bytes from array2.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import { stringToUint8Array, concatenateUint8Arrays } from '@autonomys/auto-utils'
|
|
37
|
+
*
|
|
38
|
+
* // Concatenate two strings as byte arrays
|
|
39
|
+
* const part1 = stringToUint8Array('Hello, ')
|
|
40
|
+
* const part2 = stringToUint8Array('Autonomys!')
|
|
41
|
+
* const combined = concatenateUint8Arrays(part1, part2)
|
|
42
|
+
*
|
|
43
|
+
* // Convert back to string to verify
|
|
44
|
+
* const result = new TextDecoder().decode(combined)
|
|
45
|
+
* console.log(result) // Output: "Hello, Autonomys!"
|
|
46
|
+
* console.log(combined.length) // Output: 16 (total length of both arrays)
|
|
47
|
+
*
|
|
48
|
+
* // Concatenate with hash data
|
|
49
|
+
* const data1 = stringToUint8Array('message1')
|
|
50
|
+
* const data2 = stringToUint8Array('message2')
|
|
51
|
+
* const combinedData = concatenateUint8Arrays(data1, data2)
|
|
52
|
+
* const hash = blake2b_256(combinedData)
|
|
53
|
+
* console.log(hash) // Output: hash of combined data
|
|
26
54
|
*/
|
|
27
55
|
export declare function concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array;
|
|
28
56
|
//# sourceMappingURL=crypto.d.ts.map
|
package/dist/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAG3D;AAED
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAG3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAKzF"}
|
package/dist/crypto.js
CHANGED
|
@@ -35,6 +35,34 @@ function stringToUint8Array(text) {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Concatenates two Uint8Array instances into a single Uint8Array.
|
|
38
|
+
*
|
|
39
|
+
* This function efficiently combines two byte arrays into a single array, preserving
|
|
40
|
+
* the order of the input arrays. It's commonly used for combining data before hashing,
|
|
41
|
+
* creating composite data structures, or preparing data for cryptographic operations.
|
|
42
|
+
*
|
|
43
|
+
* @param array1 - The first Uint8Array to concatenate.
|
|
44
|
+
* @param array2 - The second Uint8Array to concatenate.
|
|
45
|
+
* @returns A new Uint8Array containing all bytes from array1 followed by all bytes from array2.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* import { stringToUint8Array, concatenateUint8Arrays } from '@autonomys/auto-utils'
|
|
49
|
+
*
|
|
50
|
+
* // Concatenate two strings as byte arrays
|
|
51
|
+
* const part1 = stringToUint8Array('Hello, ')
|
|
52
|
+
* const part2 = stringToUint8Array('Autonomys!')
|
|
53
|
+
* const combined = concatenateUint8Arrays(part1, part2)
|
|
54
|
+
*
|
|
55
|
+
* // Convert back to string to verify
|
|
56
|
+
* const result = new TextDecoder().decode(combined)
|
|
57
|
+
* console.log(result) // Output: "Hello, Autonomys!"
|
|
58
|
+
* console.log(combined.length) // Output: 16 (total length of both arrays)
|
|
59
|
+
*
|
|
60
|
+
* // Concatenate with hash data
|
|
61
|
+
* const data1 = stringToUint8Array('message1')
|
|
62
|
+
* const data2 = stringToUint8Array('message2')
|
|
63
|
+
* const combinedData = concatenateUint8Arrays(data1, data2)
|
|
64
|
+
* const hash = blake2b_256(combinedData)
|
|
65
|
+
* console.log(hash) // Output: hash of combined data
|
|
38
66
|
*/
|
|
39
67
|
function concatenateUint8Arrays(array1, array2) {
|
|
40
68
|
const combined = new Uint8Array(array1.length + array2.length);
|