@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
|
@@ -14,6 +14,77 @@ exports.signAndSendTx = void 0;
|
|
|
14
14
|
const detectTxSuccess_1 = require("./detectTxSuccess");
|
|
15
15
|
const events_1 = require("./events");
|
|
16
16
|
const validateEvents_1 = require("./validateEvents");
|
|
17
|
+
/**
|
|
18
|
+
* Signs and sends a transaction to the Autonomys Network, with comprehensive error handling and event validation.
|
|
19
|
+
*
|
|
20
|
+
* This function handles the complete transaction lifecycle: signing, sending, monitoring for inclusion,
|
|
21
|
+
* and validating expected events. It provides detailed error handling and supports custom error mapping
|
|
22
|
+
* for domain-specific error handling. The function waits for the transaction to be included in a block
|
|
23
|
+
* and validates that expected events were emitted.
|
|
24
|
+
*
|
|
25
|
+
* @param sender - The account to sign and send the transaction. Can be a KeyringPair, address string, or AddressOrPair.
|
|
26
|
+
* @param tx - The submittable extrinsic to sign and send.
|
|
27
|
+
* @param options - Optional signer options including nonce, tip, and other transaction parameters.
|
|
28
|
+
* @param eventsExpected - Array of expected event names to validate. Defaults to successful transaction events.
|
|
29
|
+
* @param log - Whether to log transaction progress to console. Defaults to false.
|
|
30
|
+
* @param mapErrorCodeToEnum - Optional function to map error codes to custom error enums for better error handling.
|
|
31
|
+
* @returns Promise resolving to transaction results including success status, hashes, events, and receipt.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import { signAndSendTx, activate, setupWallet } from '@autonomys/auto-utils'
|
|
35
|
+
*
|
|
36
|
+
* // Basic transaction signing and sending
|
|
37
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
38
|
+
* const wallet = setupWallet({ uri: '//Alice' })
|
|
39
|
+
*
|
|
40
|
+
* const tx = api.tx.balances.transfer('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', 1000000000000000000n)
|
|
41
|
+
*
|
|
42
|
+
* const result = await signAndSendTx(wallet.keyringPair, tx)
|
|
43
|
+
* if (result.success) {
|
|
44
|
+
* console.log('Transaction successful')
|
|
45
|
+
* console.log('Transaction hash:', result.txHash)
|
|
46
|
+
* console.log('Block hash:', result.blockHash)
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* // With custom options and event validation
|
|
50
|
+
* const transferTx = api.tx.balances.transfer(receiverAddress, amount)
|
|
51
|
+
* const transferResult = await signAndSendTx(
|
|
52
|
+
* senderKeyringPair,
|
|
53
|
+
* transferTx,
|
|
54
|
+
* { tip: 1000000000000000n }, // Custom tip
|
|
55
|
+
* ['balances.Transfer'], // Expected events
|
|
56
|
+
* true // Enable logging
|
|
57
|
+
* )
|
|
58
|
+
*
|
|
59
|
+
* // With error mapping for custom error handling
|
|
60
|
+
* const stakingTx = api.tx.domains.nominateOperator(operatorId, amount)
|
|
61
|
+
* const stakingResult = await signAndSendTx(
|
|
62
|
+
* nominatorKeyringPair,
|
|
63
|
+
* stakingTx,
|
|
64
|
+
* {},
|
|
65
|
+
* ['domains.OperatorNominated'],
|
|
66
|
+
* false,
|
|
67
|
+
* (errorCode) => {
|
|
68
|
+
* // Map error codes to custom error types
|
|
69
|
+
* switch (errorCode) {
|
|
70
|
+
* case '0': return 'InsufficientBalance'
|
|
71
|
+
* case '1': return 'OperatorNotFound'
|
|
72
|
+
* default: return undefined
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* )
|
|
76
|
+
*
|
|
77
|
+
* // Handle Auto-ID registration with identifier extraction
|
|
78
|
+
* const autoIdTx = api.tx.autoId.registerAutoId(autoIdData)
|
|
79
|
+
* const autoIdResult = await signAndSendTx(sender, autoIdTx)
|
|
80
|
+
* if (autoIdResult.identifier) {
|
|
81
|
+
* console.log('Auto-ID registered with identifier:', autoIdResult.identifier)
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* @throws {Error} When the transaction fails, times out, or expected events are not found.
|
|
85
|
+
* @throws {Error} When the transaction is retracted, dropped, or invalid.
|
|
86
|
+
* @throws {Error} When custom error mapping indicates a specific error condition.
|
|
87
|
+
*/
|
|
17
88
|
const signAndSendTx = (sender_1, tx_1, ...args_1) => __awaiter(void 0, [sender_1, tx_1, ...args_1], void 0, function* (sender, tx, options = {}, eventsExpected = events_1.expectSuccessfulTxEvent, log = false, mapErrorCodeToEnum) {
|
|
18
89
|
let success = false;
|
|
19
90
|
let txHashHex = undefined;
|
|
@@ -1,3 +1,70 @@
|
|
|
1
1
|
import type { EventRecord, Events, EventsValidated } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that expected blockchain events were emitted during transaction execution.
|
|
4
|
+
*
|
|
5
|
+
* This function checks if all expected events were found in the transaction's event list.
|
|
6
|
+
* It's essential for ensuring that transactions not only succeeded but also produced
|
|
7
|
+
* the specific side effects (events) that were expected. The function supports both
|
|
8
|
+
* string and nested array formats for expected events.
|
|
9
|
+
*
|
|
10
|
+
* @param events - Array of EventRecord objects emitted by the transaction.
|
|
11
|
+
* @param eventsExpected - Expected events in various formats (string, array of strings, or nested arrays).
|
|
12
|
+
* @param tx - Transaction hash for logging purposes.
|
|
13
|
+
* @param block - Block hash where the transaction was included for logging purposes.
|
|
14
|
+
* @param log - Whether to log unexpected events and missing events. Defaults to false.
|
|
15
|
+
* @returns EventsValidated object containing arrays of expected (missing) and found events.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { validateEvents, expectSuccessfulTxEvent } from '@autonomys/auto-utils'
|
|
19
|
+
*
|
|
20
|
+
* // Basic validation with system success events
|
|
21
|
+
* const events = [] // event records from transaction
|
|
22
|
+
* const validation = validateEvents(
|
|
23
|
+
* events,
|
|
24
|
+
* expectSuccessfulTxEvent,
|
|
25
|
+
* '0x1234...', // transaction hash
|
|
26
|
+
* '0x5678...', // block hash
|
|
27
|
+
* true // enable logging
|
|
28
|
+
* )
|
|
29
|
+
*
|
|
30
|
+
* if (validation.expected.length === 0) {
|
|
31
|
+
* console.log('All expected events found:', validation.found)
|
|
32
|
+
* } else {
|
|
33
|
+
* console.log('Missing events:', validation.expected)
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // Validate multiple specific events
|
|
37
|
+
* const transferValidation = validateEvents(
|
|
38
|
+
* events,
|
|
39
|
+
* ['system.ExtrinsicSuccess', 'balances.Transfer'],
|
|
40
|
+
* txHash,
|
|
41
|
+
* blockHash
|
|
42
|
+
* )
|
|
43
|
+
*
|
|
44
|
+
* // Validate complex event patterns
|
|
45
|
+
* const stakingValidation = validateEvents(
|
|
46
|
+
* events,
|
|
47
|
+
* [
|
|
48
|
+
* 'system.ExtrinsicSuccess',
|
|
49
|
+
* ['domains.OperatorNominated', 'domains.StakeAdded'], // Either of these
|
|
50
|
+
* 'balances.Transfer'
|
|
51
|
+
* ],
|
|
52
|
+
* txHash,
|
|
53
|
+
* blockHash,
|
|
54
|
+
* true
|
|
55
|
+
* )
|
|
56
|
+
*
|
|
57
|
+
* // Use in transaction monitoring
|
|
58
|
+
* const expectedDomainEvents = [
|
|
59
|
+
* 'system.ExtrinsicSuccess',
|
|
60
|
+
* 'domains.DomainInstantiated',
|
|
61
|
+
* 'balances.Transfer'
|
|
62
|
+
* ]
|
|
63
|
+
* const domainValidation = validateEvents(events, expectedDomainEvents, txHash, blockHash)
|
|
64
|
+
*
|
|
65
|
+
* // Check if validation passed
|
|
66
|
+
* const isValid = domainValidation.expected.length === 0
|
|
67
|
+
* console.log('Domain creation valid:', isValid)
|
|
68
|
+
*/
|
|
2
69
|
export declare const validateEvents: (events: EventRecord[], eventsExpected: Events | undefined, tx: string, block: string, log?: boolean) => EventsValidated;
|
|
3
70
|
//# sourceMappingURL=validateEvents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateEvents.d.ts","sourceRoot":"","sources":["../../src/utils/validateEvents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGpE,eAAO,MAAM,cAAc,GACzB,QAAQ,WAAW,EAAE,EACrB,gBAAgB,MAAM,YAA0B,EAChD,IAAI,MAAM,EACV,OAAO,MAAM,EACb,MAAK,OAAe,KACnB,
|
|
1
|
+
{"version":3,"file":"validateEvents.d.ts","sourceRoot":"","sources":["../../src/utils/validateEvents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,WAAW,EAAE,EACrB,gBAAgB,MAAM,YAA0B,EAChD,IAAI,MAAM,EACV,OAAO,MAAM,EACb,MAAK,OAAe,KACnB,eAoBF,CAAA"}
|
|
@@ -3,10 +3,77 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.validateEvents = void 0;
|
|
5
5
|
const events_1 = require("./events");
|
|
6
|
+
/**
|
|
7
|
+
* Validates that expected blockchain events were emitted during transaction execution.
|
|
8
|
+
*
|
|
9
|
+
* This function checks if all expected events were found in the transaction's event list.
|
|
10
|
+
* It's essential for ensuring that transactions not only succeeded but also produced
|
|
11
|
+
* the specific side effects (events) that were expected. The function supports both
|
|
12
|
+
* string and nested array formats for expected events.
|
|
13
|
+
*
|
|
14
|
+
* @param events - Array of EventRecord objects emitted by the transaction.
|
|
15
|
+
* @param eventsExpected - Expected events in various formats (string, array of strings, or nested arrays).
|
|
16
|
+
* @param tx - Transaction hash for logging purposes.
|
|
17
|
+
* @param block - Block hash where the transaction was included for logging purposes.
|
|
18
|
+
* @param log - Whether to log unexpected events and missing events. Defaults to false.
|
|
19
|
+
* @returns EventsValidated object containing arrays of expected (missing) and found events.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* import { validateEvents, expectSuccessfulTxEvent } from '@autonomys/auto-utils'
|
|
23
|
+
*
|
|
24
|
+
* // Basic validation with system success events
|
|
25
|
+
* const events = [] // event records from transaction
|
|
26
|
+
* const validation = validateEvents(
|
|
27
|
+
* events,
|
|
28
|
+
* expectSuccessfulTxEvent,
|
|
29
|
+
* '0x1234...', // transaction hash
|
|
30
|
+
* '0x5678...', // block hash
|
|
31
|
+
* true // enable logging
|
|
32
|
+
* )
|
|
33
|
+
*
|
|
34
|
+
* if (validation.expected.length === 0) {
|
|
35
|
+
* console.log('All expected events found:', validation.found)
|
|
36
|
+
* } else {
|
|
37
|
+
* console.log('Missing events:', validation.expected)
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // Validate multiple specific events
|
|
41
|
+
* const transferValidation = validateEvents(
|
|
42
|
+
* events,
|
|
43
|
+
* ['system.ExtrinsicSuccess', 'balances.Transfer'],
|
|
44
|
+
* txHash,
|
|
45
|
+
* blockHash
|
|
46
|
+
* )
|
|
47
|
+
*
|
|
48
|
+
* // Validate complex event patterns
|
|
49
|
+
* const stakingValidation = validateEvents(
|
|
50
|
+
* events,
|
|
51
|
+
* [
|
|
52
|
+
* 'system.ExtrinsicSuccess',
|
|
53
|
+
* ['domains.OperatorNominated', 'domains.StakeAdded'], // Either of these
|
|
54
|
+
* 'balances.Transfer'
|
|
55
|
+
* ],
|
|
56
|
+
* txHash,
|
|
57
|
+
* blockHash,
|
|
58
|
+
* true
|
|
59
|
+
* )
|
|
60
|
+
*
|
|
61
|
+
* // Use in transaction monitoring
|
|
62
|
+
* const expectedDomainEvents = [
|
|
63
|
+
* 'system.ExtrinsicSuccess',
|
|
64
|
+
* 'domains.DomainInstantiated',
|
|
65
|
+
* 'balances.Transfer'
|
|
66
|
+
* ]
|
|
67
|
+
* const domainValidation = validateEvents(events, expectedDomainEvents, txHash, blockHash)
|
|
68
|
+
*
|
|
69
|
+
* // Check if validation passed
|
|
70
|
+
* const isValid = domainValidation.expected.length === 0
|
|
71
|
+
* console.log('Domain creation valid:', isValid)
|
|
72
|
+
*/
|
|
6
73
|
const validateEvents = (events, eventsExpected = events_1.expectSuccessfulTxEvent, tx, block, log = false) => {
|
|
7
74
|
const _eventsExpected = typeof eventsExpected === 'string'
|
|
8
75
|
? [eventsExpected]
|
|
9
|
-
: eventsExpected.
|
|
76
|
+
: eventsExpected.reduce((acc, e) => acc.concat(typeof e === 'string' ? [e] : e), []);
|
|
10
77
|
const found = [];
|
|
11
78
|
events.forEach(({ event: { method, section } }) => {
|
|
12
79
|
const index = _eventsExpected.indexOf(`${section}.${method}`);
|
package/dist/utils/verify.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { isHex } from '@polkadot/util';
|
|
2
2
|
import { isAddress } from '@polkadot/util-crypto';
|
|
3
|
+
/**
|
|
4
|
+
* Essential validation utilities re-exported from Polkadot.js for convenience.
|
|
5
|
+
*
|
|
6
|
+
* These functions provide validation capabilities for common Autonomys Network
|
|
7
|
+
* data types including addresses and hex strings.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://polkadot.js.org/docs/ | Polkadot.js Documentation} for complete API details.
|
|
10
|
+
*/
|
|
3
11
|
export { isAddress, isHex };
|
|
4
12
|
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/utils/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/utils/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA"}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -1,8 +1,212 @@
|
|
|
1
1
|
import type { DomainParams, NetworkParams } from './types';
|
|
2
2
|
import type { ActivateWalletParams, ApiPromise, GeneratedWallet, KeypairType, SetupWalletParams, Wallet, WalletActivated } from './types/wallet';
|
|
3
|
+
/**
|
|
4
|
+
* Sets up a wallet from a mnemonic phrase or derivation URI.
|
|
5
|
+
*
|
|
6
|
+
* This function creates a KeyringPair from either a mnemonic phrase or a derivation
|
|
7
|
+
* URI (like //Alice for development). It supports different key types including
|
|
8
|
+
* sr25519 (default) and ethereum for cross-chain compatibility.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Wallet setup parameters containing either mnemonic or URI, plus optional key type.
|
|
11
|
+
* @returns A Wallet object containing the KeyringPair and standardized addresses.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { setupWallet } from '@autonomys/auto-utils'
|
|
15
|
+
*
|
|
16
|
+
* // Setup wallet from mnemonic (sr25519 default)
|
|
17
|
+
* const wallet = setupWallet({
|
|
18
|
+
* mnemonic: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
|
19
|
+
* })
|
|
20
|
+
* console.log(wallet.address) // Standardized Autonomys address
|
|
21
|
+
* console.log(wallet.commonAddress) // Original address format
|
|
22
|
+
*
|
|
23
|
+
* // Setup wallet with ethereum key type
|
|
24
|
+
* const ethWallet = setupWallet({
|
|
25
|
+
* mnemonic: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
26
|
+
* type: 'ethereum'
|
|
27
|
+
* })
|
|
28
|
+
* console.log(ethWallet.address) // Ethereum-format address (0x...)
|
|
29
|
+
*
|
|
30
|
+
* // Setup development wallet from URI
|
|
31
|
+
* const aliceWallet = setupWallet({ uri: '//Alice' })
|
|
32
|
+
* console.log(aliceWallet.address) // Alice's development address
|
|
33
|
+
*
|
|
34
|
+
* // Setup with custom derivation path
|
|
35
|
+
* const customWallet = setupWallet({
|
|
36
|
+
* uri: '//Alice/stash'
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* @throws {Error} When neither mnemonic nor URI is provided, or when the input is invalid.
|
|
40
|
+
*/
|
|
3
41
|
export declare const setupWallet: (params: SetupWalletParams) => Wallet;
|
|
42
|
+
/**
|
|
43
|
+
* Generates a new wallet with a random mnemonic phrase.
|
|
44
|
+
*
|
|
45
|
+
* This function creates a brand new wallet by generating a cryptographically secure
|
|
46
|
+
* mnemonic phrase and deriving the corresponding KeyringPair. It's useful for creating
|
|
47
|
+
* new user accounts or generating test wallets.
|
|
48
|
+
*
|
|
49
|
+
* @param type - The cryptographic key type to use. Defaults to 'sr25519'.
|
|
50
|
+
* @returns A GeneratedWallet object containing the mnemonic, KeyringPair, and addresses.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* import { generateWallet } from '@autonomys/auto-utils'
|
|
54
|
+
*
|
|
55
|
+
* // Generate new sr25519 wallet (default)
|
|
56
|
+
* const newWallet = generateWallet()
|
|
57
|
+
* console.log(newWallet.mnemonic) // 12-word mnemonic phrase
|
|
58
|
+
* console.log(newWallet.address) // Standardized Autonomys address
|
|
59
|
+
* console.log(newWallet.commonAddress) // Original address format
|
|
60
|
+
*
|
|
61
|
+
* // Generate ethereum-compatible wallet
|
|
62
|
+
* const ethWallet = generateWallet('ethereum')
|
|
63
|
+
* console.log(ethWallet.mnemonic) // Same 12-word mnemonic
|
|
64
|
+
* console.log(ethWallet.address) // Ethereum-format address (0x...)
|
|
65
|
+
*
|
|
66
|
+
* // Store the mnemonic securely for later use
|
|
67
|
+
* const mnemonic = newWallet.mnemonic
|
|
68
|
+
* // Use setupWallet later to recreate the same wallet
|
|
69
|
+
* const restoredWallet = setupWallet({ mnemonic })
|
|
70
|
+
* console.log(restoredWallet.address === newWallet.address) // true
|
|
71
|
+
*/
|
|
4
72
|
export declare const generateWallet: (type?: KeypairType) => GeneratedWallet;
|
|
73
|
+
/**
|
|
74
|
+
* Activates a wallet and establishes connection to the Autonomys Network or domain.
|
|
75
|
+
*
|
|
76
|
+
* This comprehensive function handles wallet activation in both Node.js and browser
|
|
77
|
+
* environments. It can work with mnemonic phrases, URIs, or browser extensions,
|
|
78
|
+
* and automatically establishes the appropriate API connection.
|
|
79
|
+
*
|
|
80
|
+
* @param params - Wallet activation parameters including credentials, network, and options.
|
|
81
|
+
* @returns A WalletActivated object containing the API connection and account information.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* import { activateWallet } from '@autonomys/auto-utils'
|
|
85
|
+
*
|
|
86
|
+
* // Activate wallet with mnemonic on mainnet
|
|
87
|
+
* const { api, accounts } = await activateWallet({
|
|
88
|
+
* mnemonic: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
|
|
89
|
+
* })
|
|
90
|
+
* console.log('Connected to mainnet')
|
|
91
|
+
* console.log('Account address:', accounts[0].address)
|
|
92
|
+
*
|
|
93
|
+
* // Activate on specific network
|
|
94
|
+
* const { api: taurusApi, accounts: taurusAccounts } = await activateWallet({
|
|
95
|
+
* mnemonic: 'your mnemonic here',
|
|
96
|
+
* networkId: 'taurus'
|
|
97
|
+
* })
|
|
98
|
+
*
|
|
99
|
+
* // Activate on domain
|
|
100
|
+
* const { api: domainApi, accounts: domainAccounts } = await activateWallet({
|
|
101
|
+
* uri: '//Alice',
|
|
102
|
+
* networkId: 'taurus',
|
|
103
|
+
* domainId: '0' // Auto-EVM domain
|
|
104
|
+
* })
|
|
105
|
+
*
|
|
106
|
+
* // Activate with ethereum key type
|
|
107
|
+
* const { api: ethApi, accounts: ethAccounts } = await activateWallet({
|
|
108
|
+
* mnemonic: 'your mnemonic here',
|
|
109
|
+
* networkId: 'taurus',
|
|
110
|
+
* type: 'ethereum'
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* // Use with existing API instance
|
|
114
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
115
|
+
* const existingApi = await activate({ networkId: 'gemini-3h' })
|
|
116
|
+
* const { accounts } = await activateWallet({
|
|
117
|
+
* uri: '//Bob',
|
|
118
|
+
* api: existingApi
|
|
119
|
+
* })
|
|
120
|
+
*
|
|
121
|
+
* // Always disconnect when done
|
|
122
|
+
* await api.disconnect()
|
|
123
|
+
*
|
|
124
|
+
* @throws {Error} When no wallet credentials are provided or connection fails.
|
|
125
|
+
*/
|
|
5
126
|
export declare const activateWallet: (params: ActivateWalletParams) => Promise<WalletActivated>;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a collection of mock wallets for testing and development purposes.
|
|
129
|
+
*
|
|
130
|
+
* This function generates wallets for all predefined development accounts
|
|
131
|
+
* (Alice, Bob, Charlie, Dave, etc.) and establishes connections to the specified
|
|
132
|
+
* network. It's essential for testing applications and running development scenarios.
|
|
133
|
+
*
|
|
134
|
+
* @param network - Network parameters specifying which network to connect to. Defaults to mainnet.
|
|
135
|
+
* @param api - Optional existing API instance to reuse. If not provided, creates new connections.
|
|
136
|
+
* @param type - The cryptographic key type to use for all mock wallets. Defaults to 'sr25519'.
|
|
137
|
+
* @returns Promise resolving to an array of WalletActivated objects for all mock accounts.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* import { mockWallets, activate } from '@autonomys/auto-utils'
|
|
141
|
+
*
|
|
142
|
+
* // Create mock wallets for mainnet
|
|
143
|
+
* const wallets = await mockWallets()
|
|
144
|
+
* console.log('Created', wallets.length, 'mock wallets')
|
|
145
|
+
*
|
|
146
|
+
* // Create mock wallets for testnet
|
|
147
|
+
* const testWallets = await mockWallets({ networkId: 'taurus' })
|
|
148
|
+
*
|
|
149
|
+
* // Create mock wallets with existing API
|
|
150
|
+
* const api = await activate({ networkId: 'localhost' })
|
|
151
|
+
* const localWallets = await mockWallets({ networkId: 'localhost' }, api)
|
|
152
|
+
*
|
|
153
|
+
* // Create ethereum-type mock wallets
|
|
154
|
+
* const ethWallets = await mockWallets(
|
|
155
|
+
* { networkId: 'taurus' },
|
|
156
|
+
* undefined,
|
|
157
|
+
* 'ethereum'
|
|
158
|
+
* )
|
|
159
|
+
*
|
|
160
|
+
* // Use specific mock wallet
|
|
161
|
+
* const aliceWallet = wallets[0] // Alice is always first
|
|
162
|
+
* const bobWallet = wallets[1] // Bob is always second
|
|
163
|
+
*
|
|
164
|
+
* // Access wallet details
|
|
165
|
+
* console.log('Alice address:', aliceWallet.accounts[0].address)
|
|
166
|
+
* console.log('Bob address:', bobWallet.accounts[0].address)
|
|
167
|
+
*
|
|
168
|
+
* // Disconnect all APIs when done
|
|
169
|
+
* for (const wallet of wallets) {
|
|
170
|
+
* await wallet.api.disconnect()
|
|
171
|
+
* }
|
|
172
|
+
*/
|
|
6
173
|
export declare const mockWallets: (network?: NetworkParams | DomainParams, api?: ApiPromise, type?: KeypairType) => Promise<WalletActivated[]>;
|
|
174
|
+
/**
|
|
175
|
+
* Retrieves a specific mock wallet by name from a collection of mock wallets.
|
|
176
|
+
*
|
|
177
|
+
* This utility function provides easy access to specific development accounts
|
|
178
|
+
* by name, making test code more readable and maintainable. It works with the
|
|
179
|
+
* standard set of development account names.
|
|
180
|
+
*
|
|
181
|
+
* @param name - The name of the mock wallet to retrieve (e.g., 'Alice', 'Bob').
|
|
182
|
+
* @param wallets - Array of WalletActivated objects from mockWallets().
|
|
183
|
+
* @returns The WalletActivated object for the specified mock account.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* import { mockWallets, getMockWallet } from '@autonomys/auto-utils'
|
|
187
|
+
*
|
|
188
|
+
* // Create mock wallets and get specific ones
|
|
189
|
+
* const wallets = await mockWallets({ networkId: 'localhost' })
|
|
190
|
+
*
|
|
191
|
+
* const alice = getMockWallet('Alice', wallets)
|
|
192
|
+
* const bob = getMockWallet('Bob', wallets)
|
|
193
|
+
* const charlie = getMockWallet('Charlie', wallets)
|
|
194
|
+
*
|
|
195
|
+
* console.log('Alice address:', alice.accounts[0].address)
|
|
196
|
+
* console.log('Bob address:', bob.accounts[0].address)
|
|
197
|
+
* console.log('Charlie address:', charlie.accounts[0].address)
|
|
198
|
+
*
|
|
199
|
+
* // Use in tests
|
|
200
|
+
* const sender = getMockWallet('Alice', wallets)
|
|
201
|
+
* const receiver = getMockWallet('Bob', wallets)
|
|
202
|
+
*
|
|
203
|
+
* // Perform transfer from Alice to Bob
|
|
204
|
+
* // ... transfer logic here ...
|
|
205
|
+
*
|
|
206
|
+
* // Available mock wallet names:
|
|
207
|
+
* // 'Alice', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank', 'Grace', 'Harry', 'Ivy', 'Jacob'
|
|
208
|
+
*
|
|
209
|
+
* @throws {Error} When the specified name is not found in the available mock wallets.
|
|
210
|
+
*/
|
|
7
211
|
export declare const getMockWallet: (name: string, wallets: WalletActivated[]) => WalletActivated;
|
|
8
212
|
//# sourceMappingURL=wallet.d.ts.map
|
package/dist/wallet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAY,aAAa,EAAO,MAAM,SAAS,CAAA;AACzE,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAEvB,eAAO,MAAM,WAAW,GAAI,QAAQ,iBAAiB,KAAG,MAkBvD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,OAAM,WAAuB,KAAG,eAU9D,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,QAAQ,oBAAoB,KAAG,OAAO,CAAC,eAAe,CAmC1F,CAAA;AAED,eAAO,MAAM,WAAW,GACtB,UAAS,aAAa,GAAG,YAA+C,EACxE,MAAM,UAAU,EAChB,OAAO,WAAW,KACjB,OAAO,CAAC,eAAe,EAAE,CAa3B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,SAAS,eAAe,EAAE,KAAG,eAClB,CAAA"}
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAY,aAAa,EAAO,MAAM,SAAS,CAAA;AACzE,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,MAAM,EACN,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,iBAAiB,KAAG,MAkBvD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,cAAc,GAAI,OAAM,WAAuB,KAAG,eAU9D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,cAAc,GAAU,QAAQ,oBAAoB,KAAG,OAAO,CAAC,eAAe,CAmC1F,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,WAAW,GACtB,UAAS,aAAa,GAAG,YAA+C,EACxE,MAAM,UAAU,EAChB,OAAO,WAAW,KACjB,OAAO,CAAC,eAAe,EAAE,CAa3B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,SAAS,eAAe,EAAE,KAAG,eAClB,CAAA"}
|