@autonomys/auto-utils 1.5.18 → 1.5.20
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 +23 -0
- package/dist/constants/token.d.ts +2 -1
- package/dist/constants/token.d.ts.map +1 -1
- package/dist/constants/token.js +5 -2
- package/dist/number.d.ts +106 -38
- package/dist/number.d.ts.map +1 -1
- package/dist/number.js +117 -43
- package/dist/types/wallet.d.ts +6 -2
- package/dist/types/wallet.d.ts.map +1 -1
- package/dist/wallet.d.ts +14 -6
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +17 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -71,6 +71,8 @@ import { activateWallet } from '@autonomys/auto-utils'
|
|
|
71
71
|
const { api, accounts } = await activateWallet({
|
|
72
72
|
mnemonic,
|
|
73
73
|
networkId: 'mainnet', // Optional: specify the network ID
|
|
74
|
+
// Optional derivation path (useful for ethereum BIP44):
|
|
75
|
+
// derivationPath: "m/44'/60'/0'/0/0",
|
|
74
76
|
})
|
|
75
77
|
|
|
76
78
|
const account = accounts[0]
|
|
@@ -263,6 +265,27 @@ import { activateDomain } from '@autonomys/auto-utils'
|
|
|
263
265
|
|
|
264
266
|
---
|
|
265
267
|
|
|
268
|
+
#### **Setup a Wallet with Ethereum BIP44**
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { setupWallet } from '@autonomys/auto-utils'
|
|
272
|
+
|
|
273
|
+
const mnemonic = 'your mnemonic phrase here'
|
|
274
|
+
|
|
275
|
+
// Default behavior derives from master (m)
|
|
276
|
+
const ethMaster = setupWallet({ mnemonic, type: 'ethereum' })
|
|
277
|
+
|
|
278
|
+
// To derive using BIP44 path
|
|
279
|
+
const ethBip44 = setupWallet({
|
|
280
|
+
mnemonic,
|
|
281
|
+
type: 'ethereum',
|
|
282
|
+
derivationPath: "m/44'/60'/0'/0/0",
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
console.log(ethMaster.address)
|
|
286
|
+
console.log(ethBip44.address)
|
|
287
|
+
```
|
|
288
|
+
|
|
266
289
|
### 5. Address Utilities
|
|
267
290
|
|
|
268
291
|
#### **Convert Address Formats**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare const DEFAULT_TOKEN_DECIMALS = 18;
|
|
2
2
|
export declare const DEFAULT_TOKEN_SYMBOL = "AI3";
|
|
3
3
|
export declare const DEFAULT_TOKEN_NAME = "Auto Token";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS: bigint;
|
|
5
|
+
export declare const DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS: bigint;
|
|
5
6
|
export declare const DEFAULT_TOKEN: {
|
|
6
7
|
decimals: number;
|
|
7
8
|
symbol: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/constants/token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,oBAAoB,QAAQ,CAAA;AAEzC,eAAO,MAAM,kBAAkB,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/constants/token.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,oBAAoB,QAAQ,CAAA;AAEzC,eAAO,MAAM,kBAAkB,eAAe,CAAA;AAG9C,eAAO,MAAM,8CAA8C,QAAyB,CAAA;AAGpF,eAAO,MAAM,2CAA2C,QAAwB,CAAA;AAEhF,eAAO,MAAM,aAAa;;;;CAIzB,CAAA;AAED,eAAO,MAAM,aAAa;;;;CAIzB,CAAA"}
|
package/dist/constants/token.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TESTNET_TOKEN = exports.DEFAULT_TOKEN = exports.
|
|
3
|
+
exports.TESTNET_TOKEN = exports.DEFAULT_TOKEN = exports.DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS = exports.DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS = exports.DEFAULT_TOKEN_NAME = exports.DEFAULT_TOKEN_SYMBOL = exports.DEFAULT_TOKEN_DECIMALS = void 0;
|
|
4
4
|
exports.DEFAULT_TOKEN_DECIMALS = 18;
|
|
5
5
|
exports.DEFAULT_TOKEN_SYMBOL = 'AI3';
|
|
6
6
|
exports.DEFAULT_TOKEN_NAME = 'Auto Token';
|
|
7
|
-
|
|
7
|
+
// Existential deposit for Autonomys Network consensus chain
|
|
8
|
+
exports.DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS = BigInt(10000000000000); // 0.00001 AI3
|
|
9
|
+
// Existential deposit for Autonomys Network domains/EVM
|
|
10
|
+
exports.DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS = BigInt(1000000000000); // 0.000001 AI3
|
|
8
11
|
exports.DEFAULT_TOKEN = {
|
|
9
12
|
decimals: exports.DEFAULT_TOKEN_DECIMALS,
|
|
10
13
|
symbol: exports.DEFAULT_TOKEN_SYMBOL,
|
package/dist/number.d.ts
CHANGED
|
@@ -172,79 +172,147 @@ export declare const shannonsToAi3: (shannons: bigint | string, options?: {
|
|
|
172
172
|
trimTrailingZeros?: boolean;
|
|
173
173
|
}) => string;
|
|
174
174
|
/**
|
|
175
|
-
* Checks if an AI3 amount meets the Autonomys Network existential deposit requirement.
|
|
175
|
+
* Checks if an AI3 amount meets the Autonomys Network consensus chain existential deposit requirement.
|
|
176
176
|
*
|
|
177
177
|
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
178
178
|
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
179
179
|
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
180
180
|
*
|
|
181
|
-
* This function
|
|
182
|
-
* For direct Shannon (BigInt) validation, use `
|
|
181
|
+
* This function is for the consensus chain specifically. For domains/EVM, use `meetsDomainExistentialDepositAi3`.
|
|
182
|
+
* For direct Shannon (BigInt) validation, use `meetsConsensusExistentialDepositShannons` instead.
|
|
183
183
|
*
|
|
184
|
-
* For Autonomys Network, the existential deposit is 0.
|
|
184
|
+
* For Autonomys Network consensus chain, the existential deposit is 0.00001 AI3 (10,000,000,000,000 Shannons).
|
|
185
|
+
*
|
|
186
|
+
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.00001")
|
|
187
|
+
* @returns true if the amount meets or exceeds the consensus chain existential deposit requirement
|
|
188
|
+
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
189
|
+
* @see meetsConsensusExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
190
|
+
* @see meetsDomainExistentialDepositAi3 - for domain/EVM existential deposit validation
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* import { meetsConsensusExistentialDepositAi3, DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS, shannonsToAi3 } from '@autonomys/auto-utils'
|
|
194
|
+
*
|
|
195
|
+
* // Check if amount meets consensus ED requirement
|
|
196
|
+
* const amount = "0.00001"
|
|
197
|
+
* if (meetsConsensusExistentialDepositAi3(amount)) {
|
|
198
|
+
* console.log('Amount meets consensus existential deposit requirement')
|
|
199
|
+
* } else {
|
|
200
|
+
* const minRequired = shannonsToAi3(DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS)
|
|
201
|
+
* console.log(`Amount too low. Minimum required: ${minRequired} AI3 for consensus`)
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* // Examples of different amounts
|
|
205
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.000005")) // false - below ED
|
|
206
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.00001")) // true - exactly at ED
|
|
207
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.00002")) // true - above ED
|
|
208
|
+
* console.log(meetsConsensusExistentialDepositAi3("1")) // true - well above ED
|
|
209
|
+
*/
|
|
210
|
+
export declare const meetsConsensusExistentialDepositAi3: (amount: string) => boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Checks if a Shannon amount meets the Autonomys Network consensus chain existential deposit requirement.
|
|
213
|
+
*
|
|
214
|
+
* This is the Shannon-based version of `meetsConsensusExistentialDepositAi3` that works directly with
|
|
215
|
+
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
216
|
+
* have amounts in Shannon units and don't need string parsing.
|
|
217
|
+
*
|
|
218
|
+
* For Autonomys Network consensus chain, the existential deposit is 10,000,000,000,000 Shannons (0.00001 AI3).
|
|
219
|
+
*
|
|
220
|
+
* @param amount - Shannon amount as BigInt (smallest units)
|
|
221
|
+
* @returns true if the amount meets or exceeds the consensus chain existential deposit requirement
|
|
222
|
+
* @see meetsDomainExistentialDepositShannons - for domain/EVM existential deposit validation
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* import { meetsConsensusExistentialDepositShannons, DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
226
|
+
*
|
|
227
|
+
* // Check if Shannon amount meets consensus ED requirement
|
|
228
|
+
* const shannons = BigInt('10000000000000') // 0.00001 AI3
|
|
229
|
+
* if (meetsConsensusExistentialDepositShannons(shannons)) {
|
|
230
|
+
* console.log('Amount meets consensus existential deposit requirement')
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* // Examples with different Shannon amounts
|
|
234
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('9999999999999'))) // false - below ED
|
|
235
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('10000000000000'))) // true - exactly at ED
|
|
236
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('20000000000000'))) // true - above ED
|
|
237
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
238
|
+
*
|
|
239
|
+
* // Works with the constant directly
|
|
240
|
+
* console.log(meetsConsensusExistentialDepositShannons(DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
241
|
+
*
|
|
242
|
+
* // Handles negative amounts
|
|
243
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('-10000000000000'))) // false
|
|
244
|
+
*/
|
|
245
|
+
export declare const meetsConsensusExistentialDepositShannons: (amount: bigint) => boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Checks if an AI3 amount meets the Autonomys Network domain/EVM existential deposit requirement.
|
|
248
|
+
*
|
|
249
|
+
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
250
|
+
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
251
|
+
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
252
|
+
*
|
|
253
|
+
* This function is for domains/EVM specifically. For consensus chain, use `meetsConsensusExistentialDepositAi3`.
|
|
254
|
+
* For direct Shannon (BigInt) validation, use `meetsDomainExistentialDepositShannons` instead.
|
|
255
|
+
*
|
|
256
|
+
* For Autonomys Network domains/EVM, the existential deposit is 0.000001 AI3 (1,000,000,000,000 Shannons).
|
|
185
257
|
*
|
|
186
258
|
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.000001")
|
|
187
|
-
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
259
|
+
* @returns true if the amount meets or exceeds the domain/EVM existential deposit requirement
|
|
188
260
|
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
189
|
-
* @see
|
|
261
|
+
* @see meetsDomainExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
262
|
+
* @see meetsConsensusExistentialDepositAi3 - for consensus chain existential deposit validation
|
|
190
263
|
*
|
|
191
264
|
* @example
|
|
192
|
-
* import {
|
|
265
|
+
* import { meetsDomainExistentialDepositAi3, DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS, shannonsToAi3 } from '@autonomys/auto-utils'
|
|
193
266
|
*
|
|
194
|
-
* // Check if amount meets ED requirement
|
|
267
|
+
* // Check if amount meets domain/EVM ED requirement
|
|
195
268
|
* const amount = "0.000001"
|
|
196
|
-
* if (
|
|
197
|
-
* console.log('Amount meets existential deposit requirement')
|
|
269
|
+
* if (meetsDomainExistentialDepositAi3(amount)) {
|
|
270
|
+
* console.log('Amount meets domain existential deposit requirement')
|
|
198
271
|
* } else {
|
|
199
|
-
*
|
|
272
|
+
* const minRequired = shannonsToAi3(DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS)
|
|
273
|
+
* console.log(`Amount too low. Minimum required: ${minRequired} AI3 for domains`)
|
|
200
274
|
* }
|
|
201
275
|
*
|
|
202
276
|
* // Examples of different amounts
|
|
203
|
-
* console.log(
|
|
204
|
-
* console.log(
|
|
205
|
-
* console.log(
|
|
206
|
-
* console.log(
|
|
207
|
-
*
|
|
208
|
-
* // Will throw error for invalid formats
|
|
209
|
-
* try {
|
|
210
|
-
* meetsExistentialDepositAi3("invalid")
|
|
211
|
-
* } catch (error) {
|
|
212
|
-
* console.error("Invalid amount format")
|
|
213
|
-
* }
|
|
277
|
+
* console.log(meetsDomainExistentialDepositAi3("0.0000005")) // false - below ED
|
|
278
|
+
* console.log(meetsDomainExistentialDepositAi3("0.000001")) // true - exactly at ED
|
|
279
|
+
* console.log(meetsDomainExistentialDepositAi3("0.000002")) // true - above ED
|
|
280
|
+
* console.log(meetsDomainExistentialDepositAi3("1")) // true - well above ED
|
|
214
281
|
*/
|
|
215
|
-
export declare const
|
|
282
|
+
export declare const meetsDomainExistentialDepositAi3: (amount: string) => boolean;
|
|
216
283
|
/**
|
|
217
|
-
* Checks if a Shannon amount meets the Autonomys Network existential deposit requirement.
|
|
284
|
+
* Checks if a Shannon amount meets the Autonomys Network domain/EVM existential deposit requirement.
|
|
218
285
|
*
|
|
219
|
-
* This is the Shannon-based version of `
|
|
286
|
+
* This is the Shannon-based version of `meetsDomainExistentialDepositAi3` that works directly with
|
|
220
287
|
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
221
288
|
* have amounts in Shannon units and don't need string parsing.
|
|
222
289
|
*
|
|
223
|
-
* For Autonomys Network, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
290
|
+
* For Autonomys Network domains/EVM, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
224
291
|
*
|
|
225
292
|
* @param amount - Shannon amount as BigInt (smallest units)
|
|
226
|
-
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
293
|
+
* @returns true if the amount meets or exceeds the domain/EVM existential deposit requirement
|
|
294
|
+
* @see meetsConsensusExistentialDepositShannons - for consensus chain existential deposit validation
|
|
227
295
|
*
|
|
228
296
|
* @example
|
|
229
|
-
* import {
|
|
297
|
+
* import { meetsDomainExistentialDepositShannons, DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
230
298
|
*
|
|
231
|
-
* // Check if Shannon amount meets ED requirement
|
|
299
|
+
* // Check if Shannon amount meets domain/EVM ED requirement
|
|
232
300
|
* const shannons = BigInt('1000000000000') // 0.000001 AI3
|
|
233
|
-
* if (
|
|
234
|
-
* console.log('Amount meets existential deposit requirement')
|
|
301
|
+
* if (meetsDomainExistentialDepositShannons(shannons)) {
|
|
302
|
+
* console.log('Amount meets domain existential deposit requirement')
|
|
235
303
|
* }
|
|
236
304
|
*
|
|
237
305
|
* // Examples with different Shannon amounts
|
|
238
|
-
* console.log(
|
|
239
|
-
* console.log(
|
|
240
|
-
* console.log(
|
|
241
|
-
* console.log(
|
|
306
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('999999999999'))) // false - below ED
|
|
307
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('1000000000000'))) // true - exactly at ED
|
|
308
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('2000000000000'))) // true - above ED
|
|
309
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
242
310
|
*
|
|
243
311
|
* // Works with the constant directly
|
|
244
|
-
* console.log(
|
|
312
|
+
* console.log(meetsDomainExistentialDepositShannons(DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
245
313
|
*
|
|
246
314
|
* // Handles negative amounts
|
|
247
|
-
* console.log(
|
|
315
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('-1000000000000'))) // false
|
|
248
316
|
*/
|
|
249
|
-
export declare const
|
|
317
|
+
export declare const meetsDomainExistentialDepositShannons: (amount: bigint) => boolean;
|
|
250
318
|
//# sourceMappingURL=number.d.ts.map
|
package/dist/number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../src/number.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,GAAG,MAAM,EACvB,WAAU,MAA+B,oBAI1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,MAAM,GAAG,MAAM,EACvB,WAAU,MAA+B,oBAI1C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,iBAAY,WAU7D,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,MAAM,EACb,WAAU,MAA+B,EACzC,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;CAAO,KACnE,MA2DF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,OAAO,MAAM,GAAG,MAAM,EACtB,WAAU,MAA+B,EACzC,UAAS;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,KAC5C,MAkBF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa,GACxB,WAAW,MAAM,EACjB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;CAAO,KACnE,MAAgE,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,GAAG,MAAM,EACzB,UAAS;IAAE,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAO,KAC5C,MAAgE,CAAA;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,mCAAmC,GAAI,QAAQ,MAAM,KAAG,OAEpE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,wCAAwC,GAAI,QAAQ,MAAM,KAAG,OAEzE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,gCAAgC,GAAI,QAAQ,MAAM,KAAG,OAEjE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,qCAAqC,GAAI,QAAQ,MAAM,KAAG,OAEtE,CAAA"}
|
package/dist/number.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.meetsDomainExistentialDepositShannons = exports.meetsDomainExistentialDepositAi3 = exports.meetsConsensusExistentialDepositShannons = exports.meetsConsensusExistentialDepositAi3 = exports.shannonsToAi3 = exports.ai3ToShannons = exports.formatUnits = exports.parseUnits = exports.formatSpacePledged = exports.formatTokenAmount = exports.parseTokenAmount = void 0;
|
|
4
4
|
const number_1 = require("./constants/number");
|
|
5
5
|
const token_1 = require("./constants/token");
|
|
6
6
|
/**
|
|
@@ -264,84 +264,158 @@ exports.ai3ToShannons = ai3ToShannons;
|
|
|
264
264
|
const shannonsToAi3 = (shannons, options = {}) => (0, exports.formatUnits)(shannons, token_1.DEFAULT_TOKEN_DECIMALS, options);
|
|
265
265
|
exports.shannonsToAi3 = shannonsToAi3;
|
|
266
266
|
/**
|
|
267
|
-
* Checks if an AI3 amount meets the Autonomys Network existential deposit requirement.
|
|
267
|
+
* Checks if an AI3 amount meets the Autonomys Network consensus chain existential deposit requirement.
|
|
268
268
|
*
|
|
269
269
|
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
270
270
|
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
271
271
|
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
272
272
|
*
|
|
273
|
-
* This function
|
|
274
|
-
* For direct Shannon (BigInt) validation, use `
|
|
273
|
+
* This function is for the consensus chain specifically. For domains/EVM, use `meetsDomainExistentialDepositAi3`.
|
|
274
|
+
* For direct Shannon (BigInt) validation, use `meetsConsensusExistentialDepositShannons` instead.
|
|
275
275
|
*
|
|
276
|
-
* For Autonomys Network, the existential deposit is 0.
|
|
276
|
+
* For Autonomys Network consensus chain, the existential deposit is 0.00001 AI3 (10,000,000,000,000 Shannons).
|
|
277
|
+
*
|
|
278
|
+
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.00001")
|
|
279
|
+
* @returns true if the amount meets or exceeds the consensus chain existential deposit requirement
|
|
280
|
+
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
281
|
+
* @see meetsConsensusExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
282
|
+
* @see meetsDomainExistentialDepositAi3 - for domain/EVM existential deposit validation
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* import { meetsConsensusExistentialDepositAi3, DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS, shannonsToAi3 } from '@autonomys/auto-utils'
|
|
286
|
+
*
|
|
287
|
+
* // Check if amount meets consensus ED requirement
|
|
288
|
+
* const amount = "0.00001"
|
|
289
|
+
* if (meetsConsensusExistentialDepositAi3(amount)) {
|
|
290
|
+
* console.log('Amount meets consensus existential deposit requirement')
|
|
291
|
+
* } else {
|
|
292
|
+
* const minRequired = shannonsToAi3(DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS)
|
|
293
|
+
* console.log(`Amount too low. Minimum required: ${minRequired} AI3 for consensus`)
|
|
294
|
+
* }
|
|
295
|
+
*
|
|
296
|
+
* // Examples of different amounts
|
|
297
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.000005")) // false - below ED
|
|
298
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.00001")) // true - exactly at ED
|
|
299
|
+
* console.log(meetsConsensusExistentialDepositAi3("0.00002")) // true - above ED
|
|
300
|
+
* console.log(meetsConsensusExistentialDepositAi3("1")) // true - well above ED
|
|
301
|
+
*/
|
|
302
|
+
const meetsConsensusExistentialDepositAi3 = (amount) => {
|
|
303
|
+
return (0, exports.meetsConsensusExistentialDepositShannons)((0, exports.ai3ToShannons)(amount));
|
|
304
|
+
};
|
|
305
|
+
exports.meetsConsensusExistentialDepositAi3 = meetsConsensusExistentialDepositAi3;
|
|
306
|
+
/**
|
|
307
|
+
* Checks if a Shannon amount meets the Autonomys Network consensus chain existential deposit requirement.
|
|
308
|
+
*
|
|
309
|
+
* This is the Shannon-based version of `meetsConsensusExistentialDepositAi3` that works directly with
|
|
310
|
+
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
311
|
+
* have amounts in Shannon units and don't need string parsing.
|
|
312
|
+
*
|
|
313
|
+
* For Autonomys Network consensus chain, the existential deposit is 10,000,000,000,000 Shannons (0.00001 AI3).
|
|
314
|
+
*
|
|
315
|
+
* @param amount - Shannon amount as BigInt (smallest units)
|
|
316
|
+
* @returns true if the amount meets or exceeds the consensus chain existential deposit requirement
|
|
317
|
+
* @see meetsDomainExistentialDepositShannons - for domain/EVM existential deposit validation
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* import { meetsConsensusExistentialDepositShannons, DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
321
|
+
*
|
|
322
|
+
* // Check if Shannon amount meets consensus ED requirement
|
|
323
|
+
* const shannons = BigInt('10000000000000') // 0.00001 AI3
|
|
324
|
+
* if (meetsConsensusExistentialDepositShannons(shannons)) {
|
|
325
|
+
* console.log('Amount meets consensus existential deposit requirement')
|
|
326
|
+
* }
|
|
327
|
+
*
|
|
328
|
+
* // Examples with different Shannon amounts
|
|
329
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('9999999999999'))) // false - below ED
|
|
330
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('10000000000000'))) // true - exactly at ED
|
|
331
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('20000000000000'))) // true - above ED
|
|
332
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
333
|
+
*
|
|
334
|
+
* // Works with the constant directly
|
|
335
|
+
* console.log(meetsConsensusExistentialDepositShannons(DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
336
|
+
*
|
|
337
|
+
* // Handles negative amounts
|
|
338
|
+
* console.log(meetsConsensusExistentialDepositShannons(BigInt('-10000000000000'))) // false
|
|
339
|
+
*/
|
|
340
|
+
const meetsConsensusExistentialDepositShannons = (amount) => {
|
|
341
|
+
return amount >= token_1.DEFAULT_CONSENSUS_EXISTENTIAL_DEPOSIT_SHANNONS;
|
|
342
|
+
};
|
|
343
|
+
exports.meetsConsensusExistentialDepositShannons = meetsConsensusExistentialDepositShannons;
|
|
344
|
+
/**
|
|
345
|
+
* Checks if an AI3 amount meets the Autonomys Network domain/EVM existential deposit requirement.
|
|
346
|
+
*
|
|
347
|
+
* The existential deposit (ED) is the minimum balance required to keep an account active
|
|
348
|
+
* on the Autonomys Network. Accounts with balances below the ED may be reaped (removed)
|
|
349
|
+
* by the network, and their funds will be destroyed to prevent storage bloat.
|
|
350
|
+
*
|
|
351
|
+
* This function is for domains/EVM specifically. For consensus chain, use `meetsConsensusExistentialDepositAi3`.
|
|
352
|
+
* For direct Shannon (BigInt) validation, use `meetsDomainExistentialDepositShannons` instead.
|
|
353
|
+
*
|
|
354
|
+
* For Autonomys Network domains/EVM, the existential deposit is 0.000001 AI3 (1,000,000,000,000 Shannons).
|
|
277
355
|
*
|
|
278
356
|
* @param amount - AI3 amount as a decimal string (e.g., "1.5", "0.000001")
|
|
279
|
-
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
357
|
+
* @returns true if the amount meets or exceeds the domain/EVM existential deposit requirement
|
|
280
358
|
* @throws Error if the amount format is invalid (same validation as ai3ToShannons)
|
|
281
|
-
* @see
|
|
359
|
+
* @see meetsDomainExistentialDepositShannons - for direct Shannon (BigInt) validation
|
|
360
|
+
* @see meetsConsensusExistentialDepositAi3 - for consensus chain existential deposit validation
|
|
282
361
|
*
|
|
283
362
|
* @example
|
|
284
|
-
* import {
|
|
363
|
+
* import { meetsDomainExistentialDepositAi3, DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS, shannonsToAi3 } from '@autonomys/auto-utils'
|
|
285
364
|
*
|
|
286
|
-
* // Check if amount meets ED requirement
|
|
365
|
+
* // Check if amount meets domain/EVM ED requirement
|
|
287
366
|
* const amount = "0.000001"
|
|
288
|
-
* if (
|
|
289
|
-
* console.log('Amount meets existential deposit requirement')
|
|
367
|
+
* if (meetsDomainExistentialDepositAi3(amount)) {
|
|
368
|
+
* console.log('Amount meets domain existential deposit requirement')
|
|
290
369
|
* } else {
|
|
291
|
-
*
|
|
370
|
+
* const minRequired = shannonsToAi3(DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS)
|
|
371
|
+
* console.log(`Amount too low. Minimum required: ${minRequired} AI3 for domains`)
|
|
292
372
|
* }
|
|
293
373
|
*
|
|
294
374
|
* // Examples of different amounts
|
|
295
|
-
* console.log(
|
|
296
|
-
* console.log(
|
|
297
|
-
* console.log(
|
|
298
|
-
* console.log(
|
|
299
|
-
*
|
|
300
|
-
* // Will throw error for invalid formats
|
|
301
|
-
* try {
|
|
302
|
-
* meetsExistentialDepositAi3("invalid")
|
|
303
|
-
* } catch (error) {
|
|
304
|
-
* console.error("Invalid amount format")
|
|
305
|
-
* }
|
|
375
|
+
* console.log(meetsDomainExistentialDepositAi3("0.0000005")) // false - below ED
|
|
376
|
+
* console.log(meetsDomainExistentialDepositAi3("0.000001")) // true - exactly at ED
|
|
377
|
+
* console.log(meetsDomainExistentialDepositAi3("0.000002")) // true - above ED
|
|
378
|
+
* console.log(meetsDomainExistentialDepositAi3("1")) // true - well above ED
|
|
306
379
|
*/
|
|
307
|
-
const
|
|
308
|
-
return (0, exports.
|
|
380
|
+
const meetsDomainExistentialDepositAi3 = (amount) => {
|
|
381
|
+
return (0, exports.meetsDomainExistentialDepositShannons)((0, exports.ai3ToShannons)(amount));
|
|
309
382
|
};
|
|
310
|
-
exports.
|
|
383
|
+
exports.meetsDomainExistentialDepositAi3 = meetsDomainExistentialDepositAi3;
|
|
311
384
|
/**
|
|
312
|
-
* Checks if a Shannon amount meets the Autonomys Network existential deposit requirement.
|
|
385
|
+
* Checks if a Shannon amount meets the Autonomys Network domain/EVM existential deposit requirement.
|
|
313
386
|
*
|
|
314
|
-
* This is the Shannon-based version of `
|
|
387
|
+
* This is the Shannon-based version of `meetsDomainExistentialDepositAi3` that works directly with
|
|
315
388
|
* BigInt values in the smallest units (Shannons). It's more efficient when you already
|
|
316
389
|
* have amounts in Shannon units and don't need string parsing.
|
|
317
390
|
*
|
|
318
|
-
* For Autonomys Network, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
391
|
+
* For Autonomys Network domains/EVM, the existential deposit is 1,000,000,000,000 Shannons (0.000001 AI3).
|
|
319
392
|
*
|
|
320
393
|
* @param amount - Shannon amount as BigInt (smallest units)
|
|
321
|
-
* @returns true if the amount meets or exceeds the existential deposit requirement
|
|
394
|
+
* @returns true if the amount meets or exceeds the domain/EVM existential deposit requirement
|
|
395
|
+
* @see meetsConsensusExistentialDepositShannons - for consensus chain existential deposit validation
|
|
322
396
|
*
|
|
323
397
|
* @example
|
|
324
|
-
* import {
|
|
398
|
+
* import { meetsDomainExistentialDepositShannons, DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS } from '@autonomys/auto-utils'
|
|
325
399
|
*
|
|
326
|
-
* // Check if Shannon amount meets ED requirement
|
|
400
|
+
* // Check if Shannon amount meets domain/EVM ED requirement
|
|
327
401
|
* const shannons = BigInt('1000000000000') // 0.000001 AI3
|
|
328
|
-
* if (
|
|
329
|
-
* console.log('Amount meets existential deposit requirement')
|
|
402
|
+
* if (meetsDomainExistentialDepositShannons(shannons)) {
|
|
403
|
+
* console.log('Amount meets domain existential deposit requirement')
|
|
330
404
|
* }
|
|
331
405
|
*
|
|
332
406
|
* // Examples with different Shannon amounts
|
|
333
|
-
* console.log(
|
|
334
|
-
* console.log(
|
|
335
|
-
* console.log(
|
|
336
|
-
* console.log(
|
|
407
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('999999999999'))) // false - below ED
|
|
408
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('1000000000000'))) // true - exactly at ED
|
|
409
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('2000000000000'))) // true - above ED
|
|
410
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('1000000000000000000'))) // true - 1 AI3
|
|
337
411
|
*
|
|
338
412
|
* // Works with the constant directly
|
|
339
|
-
* console.log(
|
|
413
|
+
* console.log(meetsDomainExistentialDepositShannons(DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS)) // true
|
|
340
414
|
*
|
|
341
415
|
* // Handles negative amounts
|
|
342
|
-
* console.log(
|
|
416
|
+
* console.log(meetsDomainExistentialDepositShannons(BigInt('-1000000000000'))) // false
|
|
343
417
|
*/
|
|
344
|
-
const
|
|
345
|
-
return amount >= token_1.
|
|
418
|
+
const meetsDomainExistentialDepositShannons = (amount) => {
|
|
419
|
+
return amount >= token_1.DEFAULT_DOMAIN_EXISTENTIAL_DEPOSIT_SHANNONS;
|
|
346
420
|
};
|
|
347
|
-
exports.
|
|
421
|
+
exports.meetsDomainExistentialDepositShannons = meetsDomainExistentialDepositShannons;
|
package/dist/types/wallet.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export type MnemonicOrURI = Mnemonic | URI;
|
|
|
18
18
|
export type WalletType = {
|
|
19
19
|
type?: KeypairType;
|
|
20
20
|
};
|
|
21
|
-
export type SetupWalletParams = MnemonicOrURI & WalletType
|
|
21
|
+
export type SetupWalletParams = MnemonicOrURI & WalletType & {
|
|
22
|
+
derivationPath?: string;
|
|
23
|
+
};
|
|
22
24
|
export type Wallet = {
|
|
23
25
|
keyringPair?: KeyringPair;
|
|
24
26
|
injectedAccount?: InjectedAccountWithMeta;
|
|
@@ -28,7 +30,9 @@ export type Wallet = {
|
|
|
28
30
|
export interface GeneratedWallet extends Wallet {
|
|
29
31
|
mnemonic: string;
|
|
30
32
|
}
|
|
31
|
-
export type ActivateWalletParams = (NetworkParams | DomainParams) & MnemonicOrURI & ExtraActivationOptions & WalletType
|
|
33
|
+
export type ActivateWalletParams = (NetworkParams | DomainParams) & MnemonicOrURI & ExtraActivationOptions & WalletType & {
|
|
34
|
+
derivationPath?: string;
|
|
35
|
+
};
|
|
32
36
|
export type WalletActivated = {
|
|
33
37
|
api: ApiPromise;
|
|
34
38
|
accounts: InjectedAccountWithMeta[] & KeyringPair[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC7F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE5D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,GAAG,CAAA;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC7F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAE5D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,GAAG,CAAA;AAE1C,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,WAAW,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAC3C,UAAU,GAAG;IACX,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAEH,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,eAAe,CAAC,EAAE,uBAAuB,CAAA;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,WAAW,eAAgB,SAAQ,MAAM;IAC7C,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,aAAa,GAAG,YAAY,CAAC,GAC/D,aAAa,GACb,sBAAsB,GACtB,UAAU,GAAG;IACX,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAEH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,UAAU,CAAA;IACf,QAAQ,EAAE,uBAAuB,EAAE,GAAG,WAAW,EAAE,CAAA;IACnD,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;AAErD,MAAM,MAAM,GAAG,GAAG,UAAU,GAAG,cAAc,CAAA;AAE7C,YAAY,EACV,aAAa,EACb,aAAa,EACb,UAAU,EACV,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,MAAM,EACN,YAAY,GACb,CAAA"}
|
package/dist/wallet.d.ts
CHANGED
|
@@ -27,6 +27,14 @@ import type { ActivateWalletParams, ApiPromise, GeneratedWallet, KeypairType, Se
|
|
|
27
27
|
* })
|
|
28
28
|
* console.log(ethWallet.address) // Ethereum-format address (0x...)
|
|
29
29
|
*
|
|
30
|
+
* // Setup ethereum wallet with BIP44 derivation path
|
|
31
|
+
* const ethBip44 = setupWallet({
|
|
32
|
+
* mnemonic: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
33
|
+
* type: 'ethereum',
|
|
34
|
+
* derivationPath: "m/44'/60'/0'/0/0",
|
|
35
|
+
* })
|
|
36
|
+
* console.log(ethBip44.address) // Matches MetaMask default derivation
|
|
37
|
+
*
|
|
30
38
|
* // Setup development wallet from URI
|
|
31
39
|
* const aliceWallet = setupWallet({ uri: '//Alice' })
|
|
32
40
|
* console.log(aliceWallet.address) // Alice's development address
|
|
@@ -91,22 +99,22 @@ export declare const generateWallet: (type?: KeypairType) => GeneratedWallet;
|
|
|
91
99
|
* console.log('Account address:', accounts[0].address)
|
|
92
100
|
*
|
|
93
101
|
* // Activate on specific network
|
|
94
|
-
* const { api:
|
|
102
|
+
* const { api: mainnetApi, accounts: mainnetAccounts } = await activateWallet({
|
|
95
103
|
* mnemonic: 'your mnemonic here',
|
|
96
|
-
* networkId: '
|
|
104
|
+
* networkId: 'mainnet'
|
|
97
105
|
* })
|
|
98
106
|
*
|
|
99
107
|
* // Activate on domain
|
|
100
108
|
* const { api: domainApi, accounts: domainAccounts } = await activateWallet({
|
|
101
109
|
* uri: '//Alice',
|
|
102
|
-
* networkId: '
|
|
110
|
+
* networkId: 'mainnet',
|
|
103
111
|
* domainId: '0' // Auto-EVM domain
|
|
104
112
|
* })
|
|
105
113
|
*
|
|
106
114
|
* // Activate with ethereum key type
|
|
107
115
|
* const { api: ethApi, accounts: ethAccounts } = await activateWallet({
|
|
108
116
|
* mnemonic: 'your mnemonic here',
|
|
109
|
-
* networkId: '
|
|
117
|
+
* networkId: 'mainnet',
|
|
110
118
|
* type: 'ethereum'
|
|
111
119
|
* })
|
|
112
120
|
*
|
|
@@ -144,7 +152,7 @@ export declare const activateWallet: (params: ActivateWalletParams) => Promise<W
|
|
|
144
152
|
* console.log('Created', wallets.length, 'mock wallets')
|
|
145
153
|
*
|
|
146
154
|
* // Create mock wallets for testnet
|
|
147
|
-
* const testWallets = await mockWallets({ networkId: '
|
|
155
|
+
* const testWallets = await mockWallets({ networkId: 'mainnet' })
|
|
148
156
|
*
|
|
149
157
|
* // Create mock wallets with existing API
|
|
150
158
|
* const api = await activate({ networkId: 'localhost' })
|
|
@@ -152,7 +160,7 @@ export declare const activateWallet: (params: ActivateWalletParams) => Promise<W
|
|
|
152
160
|
*
|
|
153
161
|
* // Create ethereum-type mock wallets
|
|
154
162
|
* const ethWallets = await mockWallets(
|
|
155
|
-
* { networkId: '
|
|
163
|
+
* { networkId: 'mainnet' },
|
|
156
164
|
* undefined,
|
|
157
165
|
* 'ethereum'
|
|
158
166
|
* )
|
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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,iBAAiB,KAAG,MAoBvD,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"}
|
package/dist/wallet.js
CHANGED
|
@@ -68,6 +68,14 @@ const wallet_1 = require("./constants/wallet");
|
|
|
68
68
|
* })
|
|
69
69
|
* console.log(ethWallet.address) // Ethereum-format address (0x...)
|
|
70
70
|
*
|
|
71
|
+
* // Setup ethereum wallet with BIP44 derivation path
|
|
72
|
+
* const ethBip44 = setupWallet({
|
|
73
|
+
* mnemonic: 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
|
|
74
|
+
* type: 'ethereum',
|
|
75
|
+
* derivationPath: "m/44'/60'/0'/0/0",
|
|
76
|
+
* })
|
|
77
|
+
* console.log(ethBip44.address) // Matches MetaMask default derivation
|
|
78
|
+
*
|
|
71
79
|
* // Setup development wallet from URI
|
|
72
80
|
* const aliceWallet = setupWallet({ uri: '//Alice' })
|
|
73
81
|
* console.log(aliceWallet.address) // Alice's development address
|
|
@@ -89,7 +97,9 @@ const setupWallet = (params) => {
|
|
|
89
97
|
}
|
|
90
98
|
else if (params.mnemonic) {
|
|
91
99
|
// Treat as mnemonic
|
|
92
|
-
|
|
100
|
+
const base = params.mnemonic;
|
|
101
|
+
const withPath = params.derivationPath ? `${base}/${params.derivationPath}` : base;
|
|
102
|
+
keyringPair = keyring.addFromUri(withPath);
|
|
93
103
|
}
|
|
94
104
|
else
|
|
95
105
|
throw new Error('Invalid mnemonic or private key');
|
|
@@ -162,22 +172,22 @@ exports.generateWallet = generateWallet;
|
|
|
162
172
|
* console.log('Account address:', accounts[0].address)
|
|
163
173
|
*
|
|
164
174
|
* // Activate on specific network
|
|
165
|
-
* const { api:
|
|
175
|
+
* const { api: mainnetApi, accounts: mainnetAccounts } = await activateWallet({
|
|
166
176
|
* mnemonic: 'your mnemonic here',
|
|
167
|
-
* networkId: '
|
|
177
|
+
* networkId: 'mainnet'
|
|
168
178
|
* })
|
|
169
179
|
*
|
|
170
180
|
* // Activate on domain
|
|
171
181
|
* const { api: domainApi, accounts: domainAccounts } = await activateWallet({
|
|
172
182
|
* uri: '//Alice',
|
|
173
|
-
* networkId: '
|
|
183
|
+
* networkId: 'mainnet',
|
|
174
184
|
* domainId: '0' // Auto-EVM domain
|
|
175
185
|
* })
|
|
176
186
|
*
|
|
177
187
|
* // Activate with ethereum key type
|
|
178
188
|
* const { api: ethApi, accounts: ethAccounts } = await activateWallet({
|
|
179
189
|
* mnemonic: 'your mnemonic here',
|
|
180
|
-
* networkId: '
|
|
190
|
+
* networkId: 'mainnet',
|
|
181
191
|
* type: 'ethereum'
|
|
182
192
|
* })
|
|
183
193
|
*
|
|
@@ -250,7 +260,7 @@ exports.activateWallet = activateWallet;
|
|
|
250
260
|
* console.log('Created', wallets.length, 'mock wallets')
|
|
251
261
|
*
|
|
252
262
|
* // Create mock wallets for testnet
|
|
253
|
-
* const testWallets = await mockWallets({ networkId: '
|
|
263
|
+
* const testWallets = await mockWallets({ networkId: 'mainnet' })
|
|
254
264
|
*
|
|
255
265
|
* // Create mock wallets with existing API
|
|
256
266
|
* const api = await activate({ networkId: 'localhost' })
|
|
@@ -258,7 +268,7 @@ exports.activateWallet = activateWallet;
|
|
|
258
268
|
*
|
|
259
269
|
* // Create ethereum-type mock wallets
|
|
260
270
|
* const ethWallets = await mockWallets(
|
|
261
|
-
* { networkId: '
|
|
271
|
+
* { networkId: 'mainnet' },
|
|
262
272
|
* undefined,
|
|
263
273
|
* 'ethereum'
|
|
264
274
|
* )
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"ts-jest": "^29.3.1",
|
|
40
40
|
"typescript": "^5.8.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4ff93ad16144e3bd13d7316e273826c5993672c8"
|
|
43
43
|
}
|