@autonomys/auto-utils 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/wallet.d.ts +7 -2
- package/dist/types/wallet.d.ts.map +1 -1
- package/dist/wallet.d.ts +5 -5
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +17 -7
- package/package.json +2 -2
package/dist/types/wallet.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ApiPromise } from '@polkadot/api';
|
|
|
2
2
|
import type { AddressOrPair, ApiDecoration, Signer, SignerResult } from '@polkadot/api/types';
|
|
3
3
|
import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
|
|
4
4
|
import type { KeyringPair } from '@polkadot/keyring/types';
|
|
5
|
+
import type { KeypairType } from '@polkadot/util-crypto/types';
|
|
5
6
|
import type { DomainParams, NetworkParams } from './network';
|
|
6
7
|
export type Mnemonic = {
|
|
7
8
|
mnemonic: string;
|
|
@@ -14,6 +15,10 @@ export type ExtraActivationOptions = {
|
|
|
14
15
|
api?: ApiPromise;
|
|
15
16
|
};
|
|
16
17
|
export type MnemonicOrURI = Mnemonic | URI;
|
|
18
|
+
export type WalletType = {
|
|
19
|
+
type?: KeypairType;
|
|
20
|
+
};
|
|
21
|
+
export type SetupWalletParams = MnemonicOrURI & WalletType;
|
|
17
22
|
export type Wallet = {
|
|
18
23
|
keyringPair?: KeyringPair;
|
|
19
24
|
injectedAccount?: InjectedAccountWithMeta;
|
|
@@ -23,7 +28,7 @@ export type Wallet = {
|
|
|
23
28
|
export interface GeneratedWallet extends Wallet {
|
|
24
29
|
mnemonic: string;
|
|
25
30
|
}
|
|
26
|
-
export type ActivateWalletParams = (NetworkParams | DomainParams) & MnemonicOrURI & ExtraActivationOptions;
|
|
31
|
+
export type ActivateWalletParams = (NetworkParams | DomainParams) & MnemonicOrURI & ExtraActivationOptions & WalletType;
|
|
27
32
|
export type WalletActivated = {
|
|
28
33
|
api: ApiPromise;
|
|
29
34
|
accounts: InjectedAccountWithMeta[] & KeyringPair[];
|
|
@@ -31,5 +36,5 @@ export type WalletActivated = {
|
|
|
31
36
|
};
|
|
32
37
|
export type ApiAtBlockHash = ApiDecoration<'promise'>;
|
|
33
38
|
export type Api = ApiPromise | ApiAtBlockHash;
|
|
34
|
-
export type { AddressOrPair, ApiDecoration, ApiPromise, InjectedAccountWithMeta, KeyringPair, Signer, SignerResult, };
|
|
39
|
+
export type { AddressOrPair, ApiDecoration, ApiPromise, InjectedAccountWithMeta, KeypairType, KeyringPair, Signer, SignerResult, };
|
|
35
40
|
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,eAAe,CAAA;AACxD,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,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,MAAM,GAAG;IACnB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,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,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,CAAA;AAEZ,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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { DomainParams,
|
|
2
|
-
import type { ActivateWalletParams, ApiPromise, GeneratedWallet, Wallet, WalletActivated } from './types/wallet';
|
|
3
|
-
export declare const setupWallet: (params:
|
|
4
|
-
export declare const generateWallet: () => GeneratedWallet;
|
|
1
|
+
import type { DomainParams, NetworkParams } from './types';
|
|
2
|
+
import type { ActivateWalletParams, ApiPromise, GeneratedWallet, KeypairType, SetupWalletParams, Wallet, WalletActivated } from './types/wallet';
|
|
3
|
+
export declare const setupWallet: (params: SetupWalletParams) => Wallet;
|
|
4
|
+
export declare const generateWallet: (type?: KeypairType) => GeneratedWallet;
|
|
5
5
|
export declare const activateWallet: (params: ActivateWalletParams) => Promise<WalletActivated>;
|
|
6
|
-
export declare const mockWallets: (network?: NetworkParams | DomainParams, api?: ApiPromise) => Promise<WalletActivated[]>;
|
|
6
|
+
export declare const mockWallets: (network?: NetworkParams | DomainParams, api?: ApiPromise, type?: KeypairType) => Promise<WalletActivated[]>;
|
|
7
7
|
export declare const getMockWallet: (name: string, wallets: WalletActivated[]) => WalletActivated;
|
|
8
8
|
//# 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,
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAA2B,aAAa,EAAO,MAAM,SAAS,CAAA;AACxF,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"}
|
package/dist/wallet.js
CHANGED
|
@@ -51,7 +51,8 @@ const api_2 = require("./api");
|
|
|
51
51
|
const network_1 = require("./constants/network");
|
|
52
52
|
const wallet_1 = require("./constants/wallet");
|
|
53
53
|
const setupWallet = (params) => {
|
|
54
|
-
const
|
|
54
|
+
const type = params.type || 'sr25519';
|
|
55
|
+
const keyring = new api_1.Keyring({ type });
|
|
55
56
|
let keyringPair;
|
|
56
57
|
if (params.uri) {
|
|
57
58
|
// Treat as uri
|
|
@@ -65,14 +66,14 @@ const setupWallet = (params) => {
|
|
|
65
66
|
throw new Error('Invalid mnemonic or private key');
|
|
66
67
|
return {
|
|
67
68
|
keyringPair,
|
|
68
|
-
address: (0, address_1.address)(keyringPair.address),
|
|
69
|
+
address: type === 'sr25519' ? (0, address_1.address)(keyringPair.address) : keyringPair.address,
|
|
69
70
|
commonAddress: keyringPair.address,
|
|
70
71
|
};
|
|
71
72
|
};
|
|
72
73
|
exports.setupWallet = setupWallet;
|
|
73
|
-
const generateWallet = () => {
|
|
74
|
+
const generateWallet = (type = 'sr25519') => {
|
|
74
75
|
const mnemonic = (0, util_crypto_1.mnemonicGenerate)();
|
|
75
|
-
const { keyringPair, address, commonAddress } = (0, exports.setupWallet)({ mnemonic });
|
|
76
|
+
const { keyringPair, address, commonAddress } = (0, exports.setupWallet)({ mnemonic, type });
|
|
76
77
|
return {
|
|
77
78
|
mnemonic,
|
|
78
79
|
keyringPair,
|
|
@@ -108,14 +109,23 @@ const activateWallet = (params) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
108
109
|
}
|
|
109
110
|
else
|
|
110
111
|
throw new Error('No wallet provided');
|
|
111
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
api: params.api,
|
|
114
|
+
accounts,
|
|
115
|
+
address: params.type && params.type === 'ethereum'
|
|
116
|
+
? accounts[0].address
|
|
117
|
+
: (0, address_1.address)(accounts[0].address),
|
|
118
|
+
};
|
|
112
119
|
});
|
|
113
120
|
exports.activateWallet = activateWallet;
|
|
114
|
-
const mockWallets = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (network = { networkId: network_1.defaultNetwork.id }, api) {
|
|
121
|
+
const mockWallets = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (network = { networkId: network_1.defaultNetwork.id }, api, type) {
|
|
122
|
+
if (!type)
|
|
123
|
+
type = 'sr25519';
|
|
115
124
|
const wallets = [];
|
|
116
125
|
for (const uri of wallet_1.mockURIs) {
|
|
117
126
|
const wallet = yield (0, exports.activateWallet)(Object.assign(Object.assign({}, network), { uri,
|
|
118
|
-
api
|
|
127
|
+
api,
|
|
128
|
+
type }));
|
|
119
129
|
wallets.push(wallet);
|
|
120
130
|
}
|
|
121
131
|
return wallets;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"browser": {
|
|
44
44
|
"fs": false
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "93f124f601a292d88221a164b393819586dcb01b"
|
|
47
47
|
}
|