@autonomys/auto-utils 0.1.3 → 0.1.5

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.
Files changed (54) hide show
  1. package/README.md +56 -56
  2. package/dist/address.d.ts +3 -0
  3. package/dist/address.d.ts.map +1 -0
  4. package/dist/address.js +10 -0
  5. package/dist/api.d.ts +6 -6
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +35 -34
  8. package/dist/constants/wallet.d.ts +1 -0
  9. package/dist/constants/wallet.d.ts.map +1 -1
  10. package/dist/constants/wallet.js +2 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +2 -0
  14. package/dist/network.d.ts +5 -5
  15. package/dist/network.d.ts.map +1 -1
  16. package/dist/network.js +4 -4
  17. package/dist/types/event.d.ts +3 -0
  18. package/dist/types/event.d.ts.map +1 -0
  19. package/dist/types/extrinsic.d.ts +5 -0
  20. package/dist/types/extrinsic.d.ts.map +1 -0
  21. package/dist/types/extrinsic.js +3 -0
  22. package/dist/types/index.d.ts +4 -1
  23. package/dist/types/index.d.ts.map +1 -1
  24. package/dist/types/index.js +2 -1
  25. package/dist/types/network.d.ts +5 -2
  26. package/dist/types/network.d.ts.map +1 -1
  27. package/dist/types/network.js +0 -1
  28. package/dist/types/wallet.d.ts +24 -2
  29. package/dist/types/wallet.d.ts.map +1 -1
  30. package/dist/utils/createType.d.ts +3 -0
  31. package/dist/utils/createType.d.ts.map +1 -0
  32. package/dist/utils/createType.js +6 -0
  33. package/dist/utils/format.d.ts +3 -0
  34. package/dist/utils/format.d.ts.map +1 -0
  35. package/dist/utils/format.js +6 -0
  36. package/dist/utils/index.d.ts +6 -0
  37. package/dist/utils/index.d.ts.map +1 -0
  38. package/dist/utils/index.js +21 -0
  39. package/dist/utils/ready.d.ts +3 -0
  40. package/dist/utils/ready.d.ts.map +1 -0
  41. package/dist/utils/ready.js +5 -0
  42. package/dist/utils/sign.d.ts +6 -0
  43. package/dist/utils/sign.d.ts.map +1 -0
  44. package/dist/utils/sign.js +27 -0
  45. package/dist/utils/verify.d.ts +4 -0
  46. package/dist/utils/verify.d.ts.map +1 -0
  47. package/dist/utils/verify.js +7 -0
  48. package/dist/wallet.d.ts +6 -12
  49. package/dist/wallet.d.ts.map +1 -1
  50. package/dist/wallet.js +47 -22
  51. package/package.json +2 -2
  52. package/dist/types/api.d.ts +0 -3
  53. package/dist/types/api.d.ts.map +0 -1
  54. /package/dist/types/{api.js → event.js} +0 -0
package/README.md CHANGED
@@ -1,56 +1,56 @@
1
- # Autonomys Auto SDK Utility
2
-
3
- ## Overview
4
-
5
- The Autonomys Auto SDK Utility provides functionalities for wallet setup, network management, data storage, cryptographic operations, and API activation.
6
-
7
- ## Wallet Management
8
-
9
- - `setupWallet(input: MnemonicOrURI): Promise<KeyringPair>`: Initializes a wallet using a mnemonic or URI.
10
- - `activateWallet(input: ActivateWalletInput): Promise<WalletActivated>`: Activates a wallet and returns API and accounts.
11
- - `mockWallets(network: NetworkInput | DomainInput): Promise<WalletActivated[]>`: Creates mock wallets for testing.
12
- - `getMockWallet(name: string, wallets: WalletActivated[]): WalletActivated`: Retrieves a mock wallet by name.
13
-
14
- ## Network Management
15
-
16
- - `getNetworkDetails(input?: NetworkInput): Network`: Gets network details.
17
- - `getNetworkRpcUrls(input?: NetworkInput): string[]`: Gets network RPC URLs.
18
- - `getNetworkDomainDetails(input: DomainInput): Domain`: Gets domain details.
19
- - `getNetworkDomainRpcUrls(input: DomainInput): string[]`: Gets domain RPC URLs.
20
-
21
- ## Data Storage
22
-
23
- - `save(key: string, value: any)`: Saves data to local storage or file system.
24
- - `read(key: string): any`: Reads data from local storage or file system.
25
-
26
- ## Cryptographic Functions
27
-
28
- - `blake2b_256(data: Uint8Array): string`: Hashes data with BLAKE2b-256.
29
- - `stringToUint8Array(text: string): Uint8Array`: Converts a string to a Uint8Array.
30
- - `concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array`: Concatenates two Uint8Arrays.
31
-
32
- ## API Activation
33
-
34
- - `activate(input?: NetworkInput): Promise<ApiPromise>`: Activates the API for a network.
35
- - `activateDomain(input: DomainInput): Promise<ApiPromise>`: Activates the API for a domain.
36
- - `disconnect()`: Disconnects the API.
37
- - `disconnectDomain()`: Disconnects the domain API.
38
-
39
- ## Constants
40
-
41
- - `networks`: Array of network configurations.
42
- - `defaultNetwork`: Default network configuration.
43
- - `mockURIs`: Array of mock URIs.
44
-
45
- ## Types
46
-
47
- - `Network`, `Domain`, `Explorer`, `NetworkInput`, `DomainInput`
48
- - `Mnemonic`, `URI`, `AppName`, `MnemonicOrURI`
49
-
50
- For more details, refer to the source files in the `src` directory.
51
-
52
- ## Import Example
53
-
54
- ```typescript
55
- import { activateWallet } from '@autonomys/auto-utils'
56
- ```
1
+ # Autonomys Auto SDK Utility
2
+
3
+ ## Overview
4
+
5
+ The Autonomys Auto SDK Utility provides functionalities for wallet setup, network management, data storage, cryptographic operations, and API activation.
6
+
7
+ ## Wallet Management
8
+
9
+ - `setupWallet(params: MnemonicOrURI): Promise<KeyringPair>`: Initializes a wallet using a mnemonic or URI.
10
+ - `activateWallet(params: ActivateWalletParams): Promise<WalletActivated>`: Activates a wallet and returns API and accounts.
11
+ - `mockWallets(network: NetworkParams | DomainParams): Promise<WalletActivated[]>`: Creates mock wallets for testing.
12
+ - `getMockWallet(name: string, wallets: WalletActivated[]): WalletActivated`: Retrieves a mock wallet by name.
13
+
14
+ ## Network Management
15
+
16
+ - `getNetworkDetails(input?: NetworkParams): Network`: Gets network details.
17
+ - `getNetworkRpcUrls(input?: NetworkParams): string[]`: Gets network RPC URLs.
18
+ - `getNetworkDomainDetails(params: DomainParams): Domain`: Gets domain details.
19
+ - `getNetworkDomainRpcUrls(params: DomainParams): string[]`: Gets domain RPC URLs.
20
+
21
+ ## Data Storage
22
+
23
+ - `save(key: string, value: any)`: Saves data to local storage or file system.
24
+ - `read(key: string): any`: Reads data from local storage or file system.
25
+
26
+ ## Cryptographic Functions
27
+
28
+ - `blake2b_256(data: Uint8Array): string`: Hashes data with BLAKE2b-256.
29
+ - `stringToUint8Array(text: string): Uint8Array`: Converts a string to a Uint8Array.
30
+ - `concatenateUint8Arrays(array1: Uint8Array, array2: Uint8Array): Uint8Array`: Concatenates two Uint8Arrays.
31
+
32
+ ## API Activation
33
+
34
+ - `activate(input?: NetworkParams): Promise<ApiPromise>`: Activates the API for a network.
35
+ - `activateDomain(params: DomainParams): Promise<ApiPromise>`: Activates the API for a domain.
36
+ - `disconnect()`: Disconnects the API.
37
+ - `disconnectDomain()`: Disconnects the domain API.
38
+
39
+ ## Constants
40
+
41
+ - `networks`: Array of network configurations.
42
+ - `defaultNetwork`: Default network configuration.
43
+ - `mockURIs`: Array of mock URIs.
44
+
45
+ ## Types
46
+
47
+ - `Network`, `Domain`, `Explorer`, `NetworkParams`, `DomainParams`
48
+ - `Mnemonic`, `URI`, `AppName`, `MnemonicOrURI`
49
+
50
+ For more details, refer to the source files in the `src` directory.
51
+
52
+ ## Import Example
53
+
54
+ ```typescript
55
+ import { activateWallet } from '@autonomys/auto-utils'
56
+ ```
@@ -0,0 +1,3 @@
1
+ export declare const address: (address: string | Uint8Array) => string;
2
+ export declare const decode: (address: string) => Uint8Array;
3
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,YAAa,MAAM,GAAG,UAAU,KAAG,MACV,CAAA;AAE7C,eAAO,MAAM,MAAM,YAAa,MAAM,KAAG,UAAoC,CAAA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // file: src/address.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.decode = exports.address = void 0;
5
+ const keyring_1 = require("@polkadot/keyring");
6
+ const wallet_1 = require("./constants/wallet");
7
+ const address = (address) => (0, keyring_1.encodeAddress)(address, wallet_1.DEFAULT_SS58_FORMAT);
8
+ exports.address = address;
9
+ const decode = (address) => (0, keyring_1.decodeAddress)(address);
10
+ exports.decode = decode;
package/dist/api.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { ApiPromise } from './types/api';
2
- import type { DomainInput, NetworkInput } from './types/network';
3
- export declare const activate: (input?: NetworkInput) => Promise<ApiPromise>;
4
- export declare const activateDomain: (input: DomainInput) => Promise<ApiPromise>;
5
- export declare const disconnect: () => Promise<void>;
6
- export declare const disconnectDomain: () => Promise<void>;
1
+ import { ApiPromise } from '@polkadot/api';
2
+ import type { ActivateParams, ApiOptions, DomainParams, NetworkParams } from './types/network';
3
+ export declare const createConnection: (endpoint: string, options?: ApiOptions) => Promise<ApiPromise>;
4
+ export declare const activate: (params?: ActivateParams<NetworkParams>) => Promise<ApiPromise>;
5
+ export declare const activateDomain: (params: ActivateParams<DomainParams>) => Promise<ApiPromise>;
6
+ export declare const disconnect: (api: ApiPromise) => Promise<void>;
7
7
  //# 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":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAQhE,eAAO,MAAM,QAAQ,WAAkB,YAAY,KAAG,QAAQ,UAAU,CASvE,CAAA;AAED,eAAO,MAAM,cAAc,UAAiB,WAAW,KAAG,QAAQ,UAAU,CAS3E,CAAA;AAED,eAAO,MAAM,UAAU,QAAa,QAAQ,IAAI,CAO/C,CAAA;AAED,eAAO,MAAM,gBAAgB,QAAa,QAAQ,IAAI,CAOrD,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,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE9F,eAAO,MAAM,gBAAgB,aACjB,MAAM,YACN,UAAU,KACnB,QAAQ,UAAU,CAYpB,CAAA;AAED,eAAO,MAAM,QAAQ,YAAmB,eAAe,aAAa,CAAC,KAAG,QAAQ,UAAU,CAOzF,CAAA;AAED,eAAO,MAAM,cAAc,WAAkB,eAAe,YAAY,CAAC,KAAG,QAAQ,UAAU,CAO7F,CAAA;AAED,eAAO,MAAM,UAAU,QAAe,UAAU,KAAG,QAAQ,IAAI,CAG9D,CAAA"}
package/dist/api.js CHANGED
@@ -8,49 +8,50 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.disconnectDomain = exports.disconnect = exports.activateDomain = exports.activate = void 0;
23
+ exports.disconnect = exports.activateDomain = exports.activate = exports.createConnection = void 0;
13
24
  const api_1 = require("@polkadot/api");
14
25
  const network_1 = require("./network");
15
- let provider = null;
16
- let apiInstance = null;
17
- let domainProvider = null;
18
- let apiDomainInstance = null;
19
- const activate = (input) => __awaiter(void 0, void 0, void 0, function* () {
20
- // Get the first rpc urls for the network
21
- const rpcUrl = (0, network_1.getNetworkRpcUrls)(input);
26
+ const createConnection = (endpoint, options) => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _a;
22
28
  // Create the provider
23
- provider = new api_1.WsProvider(rpcUrl[0]);
29
+ const provider = new api_1.WsProvider(endpoint);
24
30
  // Create the API instance
25
- apiInstance = yield api_1.ApiPromise.create({ provider });
26
- return apiInstance;
31
+ const api = yield api_1.ApiPromise.create(Object.assign(Object.assign({}, options), { noInitWarn: (_a = options === null || options === void 0 ? void 0 : options.noInitWarn) !== null && _a !== void 0 ? _a : true, provider }));
32
+ yield api.isReady;
33
+ return api;
34
+ });
35
+ exports.createConnection = createConnection;
36
+ const activate = (params) => __awaiter(void 0, void 0, void 0, function* () {
37
+ // Get the first rpc urls for the network
38
+ const endpoint = (0, network_1.getNetworkRpcUrls)(params);
39
+ // Remove the networkId from the input
40
+ if (params)
41
+ delete params.networkId;
42
+ return yield (0, exports.createConnection)(endpoint[0], params);
27
43
  });
28
44
  exports.activate = activate;
29
- const activateDomain = (input) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const activateDomain = (params) => __awaiter(void 0, void 0, void 0, function* () {
30
46
  // Get the first rpc urls for the network
31
- const rpcUrl = (0, network_1.getNetworkDomainRpcUrls)(input);
32
- // Create the provider
33
- domainProvider = new api_1.WsProvider(rpcUrl[0]);
34
- // Create the API instance
35
- apiDomainInstance = yield api_1.ApiPromise.create({ provider: domainProvider });
36
- return apiDomainInstance;
47
+ const endpoint = (0, network_1.getNetworkDomainRpcUrls)(params);
48
+ // Remove the domainId from the input
49
+ const { domainId } = params, rest = __rest(params, ["domainId"]);
50
+ return yield (0, exports.createConnection)(endpoint[0], rest);
37
51
  });
38
52
  exports.activateDomain = activateDomain;
39
- const disconnect = () => __awaiter(void 0, void 0, void 0, function* () {
40
- // Disconnect the API instance and the provider if they exist
41
- if (apiInstance) {
42
- yield apiInstance.disconnect();
43
- apiInstance = null;
44
- provider = null;
45
- }
53
+ const disconnect = (api) => __awaiter(void 0, void 0, void 0, function* () {
54
+ // Disconnect the API instance and the provider
55
+ yield api.disconnect();
46
56
  });
47
57
  exports.disconnect = disconnect;
48
- const disconnectDomain = () => __awaiter(void 0, void 0, void 0, function* () {
49
- // Disconnect the API instance and the provider if they exist
50
- if (apiDomainInstance) {
51
- yield apiDomainInstance.disconnect();
52
- apiDomainInstance = null;
53
- domainProvider = null;
54
- }
55
- });
56
- exports.disconnectDomain = disconnectDomain;
@@ -1,2 +1,3 @@
1
1
  export declare const mockURIs: string[];
2
+ export declare const DEFAULT_SS58_FORMAT = 2254;
2
3
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/constants/wallet.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,UAWpB,CAAA"}
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/constants/wallet.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,UAWpB,CAAA;AAED,eAAO,MAAM,mBAAmB,OAAO,CAAA"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // file: src/constants/wallet.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.mockURIs = void 0;
4
+ exports.DEFAULT_SS58_FORMAT = exports.mockURIs = void 0;
5
5
  exports.mockURIs = [
6
6
  '//Alice',
7
7
  '//Bob',
@@ -14,3 +14,4 @@ exports.mockURIs = [
14
14
  '//Ivy',
15
15
  '//Jacob',
16
16
  ];
17
+ exports.DEFAULT_SS58_FORMAT = 2254;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './address';
1
2
  export * from './api';
2
3
  export * from './crypto';
3
4
  export * from './network';
@@ -7,4 +8,5 @@ export * from './save';
7
8
  export * from './wallet';
8
9
  export * from './constants';
9
10
  export * from './types';
11
+ export * from './utils';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
16
  };
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./address"), exports);
18
19
  __exportStar(require("./api"), exports);
19
20
  __exportStar(require("./crypto"), exports);
20
21
  __exportStar(require("./network"), exports);
@@ -24,3 +25,4 @@ __exportStar(require("./save"), exports);
24
25
  __exportStar(require("./wallet"), exports);
25
26
  __exportStar(require("./constants"), exports);
26
27
  __exportStar(require("./types"), exports);
28
+ __exportStar(require("./utils"), exports);
package/dist/network.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { DomainInput, NetworkInput } from './types/network';
2
- export declare const getNetworkDetails: (input?: NetworkInput) => import("./types/network").Network;
3
- export declare const getNetworkRpcUrls: (input?: NetworkInput) => string[];
4
- export declare const getNetworkDomainDetails: (input: DomainInput) => import("./types/network").Domain;
5
- export declare const getNetworkDomainRpcUrls: (input: DomainInput) => string[];
1
+ import type { DomainParams, NetworkParams } from './types/network';
2
+ export declare const getNetworkDetails: (input?: NetworkParams) => import("./types/network").Network;
3
+ export declare const getNetworkRpcUrls: (input?: NetworkParams) => string[];
4
+ export declare const getNetworkDomainDetails: (params: DomainParams) => import("./types/network").Domain;
5
+ export declare const getNetworkDomainRpcUrls: (params: DomainParams) => string[];
6
6
  //# sourceMappingURL=network.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEhE,eAAO,MAAM,iBAAiB,WAAY,YAAY,sCAWrD,CAAA;AAED,eAAO,MAAM,iBAAiB,WAAY,YAAY,aAOrD,CAAA;AAED,eAAO,MAAM,uBAAuB,UAAW,WAAW,qCAYzD,CAAA;AAED,eAAO,MAAM,uBAAuB,UAAW,WAAW,aAMzD,CAAA"}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAElE,eAAO,MAAM,iBAAiB,WAAY,aAAa,sCAWtD,CAAA;AAED,eAAO,MAAM,iBAAiB,WAAY,aAAa,aAOtD,CAAA;AAED,eAAO,MAAM,uBAAuB,WAAY,YAAY,qCAY3D,CAAA;AAED,eAAO,MAAM,uBAAuB,WAAY,YAAY,aAM3D,CAAA"}
package/dist/network.js CHANGED
@@ -23,8 +23,8 @@ const getNetworkRpcUrls = (input) => {
23
23
  return network.rpcUrls;
24
24
  };
25
25
  exports.getNetworkRpcUrls = getNetworkRpcUrls;
26
- const getNetworkDomainDetails = (input) => {
27
- const { networkId, domainId } = input;
26
+ const getNetworkDomainDetails = (params) => {
27
+ const { networkId, domainId } = params;
28
28
  // Find the network with the provided id
29
29
  const network = (0, exports.getNetworkDetails)({ networkId });
30
30
  if (!network)
@@ -36,9 +36,9 @@ const getNetworkDomainDetails = (input) => {
36
36
  return domain;
37
37
  };
38
38
  exports.getNetworkDomainDetails = getNetworkDomainDetails;
39
- const getNetworkDomainRpcUrls = (input) => {
39
+ const getNetworkDomainRpcUrls = (params) => {
40
40
  // Get the network details
41
- const domain = (0, exports.getNetworkDomainDetails)(input);
41
+ const domain = (0, exports.getNetworkDomainDetails)(params);
42
42
  if (!domain.rpcUrls || domain.rpcUrls.length === 0)
43
43
  throw new Error(`Domain has no rpcUrls`);
44
44
  return domain.rpcUrls;
@@ -0,0 +1,3 @@
1
+ import type { EventRecord } from '@polkadot/types/interfaces';
2
+ export type { EventRecord };
3
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,YAAY,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { SubmittableExtrinsic, SubmittableModuleExtrinsics } from '@polkadot/api/types';
2
+ import type { Hash } from '@polkadot/types/interfaces';
3
+ import type { ISubmittableResult } from '@polkadot/types/types';
4
+ export type { Hash, ISubmittableResult, SubmittableExtrinsic, SubmittableModuleExtrinsics };
5
+ //# sourceMappingURL=extrinsic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extrinsic.d.ts","sourceRoot":"","sources":["../../src/types/extrinsic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAC5F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,YAAY,EAAE,IAAI,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // file: src/types/extrinsic.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,7 @@
1
- export * from './api';
1
+ import type { BN } from '@polkadot/util';
2
+ export * from './event';
3
+ export * from './extrinsic';
2
4
  export * from './network';
3
5
  export * from './wallet';
6
+ export type { BN };
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAExC,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AAExB,YAAY,EAAE,EAAE,EAAE,CAAA"}
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api"), exports);
17
+ __exportStar(require("./event"), exports);
18
+ __exportStar(require("./extrinsic"), exports);
18
19
  __exportStar(require("./network"), exports);
19
20
  __exportStar(require("./wallet"), exports);
@@ -1,3 +1,4 @@
1
+ import type { ApiOptions } from '@polkadot/api/types';
1
2
  export type Explorer = {
2
3
  name: string;
3
4
  url: string;
@@ -16,11 +17,13 @@ export type Network = {
16
17
  isTestnet?: boolean;
17
18
  isLocalhost?: boolean;
18
19
  };
19
- export type NetworkInput = {
20
+ export type NetworkParams = {
20
21
  networkId?: string;
21
22
  } | undefined;
22
- export type DomainInput = {
23
+ export type DomainParams = {
23
24
  networkId?: string;
24
25
  domainId: string;
25
26
  };
27
+ export type ActivateParams<T> = T & ApiOptions;
28
+ export type { ApiOptions };
26
29
  //# sourceMappingURL=network.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/types/network.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,QAAQ,EAAE,CAAA;IACpB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAA;AAE7D,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA"}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/types/network.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,QAAQ,EAAE,QAAQ,EAAE,CAAA;IACpB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAA;AAE9D,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;AAE9C,YAAY,EAAE,UAAU,EAAE,CAAA"}
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // file: src/types/network.ts
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,33 @@
1
+ import type { ApiPromise } from '@polkadot/api';
2
+ import type { AddressOrPair, Signer, SignerResult } from '@polkadot/api/types';
3
+ import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
4
+ import type { KeyringPair } from '@polkadot/keyring/types';
5
+ import type { DomainParams, NetworkParams } from './network';
1
6
  export type Mnemonic = {
2
7
  mnemonic: string;
3
8
  };
4
9
  export type URI = {
5
10
  uri: string;
6
11
  };
7
- export type AppName = {
8
- appName: string;
12
+ export type ExtraActivationOptions = {
13
+ appName?: string;
14
+ api?: ApiPromise;
9
15
  };
10
16
  export type MnemonicOrURI = Mnemonic | URI;
17
+ export type Wallet = {
18
+ keyringPair?: KeyringPair;
19
+ injectedAccount?: InjectedAccountWithMeta;
20
+ address: string;
21
+ commonAddress: string;
22
+ };
23
+ export interface GeneratedWallet extends Wallet {
24
+ mnemonic: string;
25
+ }
26
+ export type ActivateWalletParams = (NetworkParams | DomainParams) & MnemonicOrURI & ExtraActivationOptions;
27
+ export type WalletActivated = {
28
+ api: ApiPromise;
29
+ accounts: InjectedAccountWithMeta[] & KeyringPair[];
30
+ address: string;
31
+ };
32
+ export type { AddressOrPair, ApiPromise, InjectedAccountWithMeta, KeyringPair, Signer, SignerResult, };
11
33
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAEA,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,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,GAAG,CAAA"}
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,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC9E,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,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,CAAA;AAExB,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,YAAY,EACV,aAAa,EACb,UAAU,EACV,uBAAuB,EACvB,WAAW,EACX,MAAM,EACN,YAAY,GACb,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ApiPromise } from '@polkadot/api';
2
+ export declare const createAccountIdType: (api: ApiPromise, address: string) => Uint8Array;
3
+ //# sourceMappingURL=createType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createType.d.ts","sourceRoot":"","sources":["../../src/utils/createType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,eAAO,MAAM,mBAAmB,QAAS,UAAU,WAAW,MAAM,eACZ,CAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAccountIdType = void 0;
4
+ const types_1 = require("@polkadot/types");
5
+ const createAccountIdType = (api, address) => (0, types_1.createType)(api.registry, 'AccountId', address).toU8a();
6
+ exports.createAccountIdType = createAccountIdType;
@@ -0,0 +1,3 @@
1
+ import { stringToU8a, u8aToHex } from '@polkadot/util';
2
+ export { stringToU8a, u8aToHex };
3
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.u8aToHex = exports.stringToU8a = void 0;
4
+ const util_1 = require("@polkadot/util");
5
+ Object.defineProperty(exports, "stringToU8a", { enumerable: true, get: function () { return util_1.stringToU8a; } });
6
+ Object.defineProperty(exports, "u8aToHex", { enumerable: true, get: function () { return util_1.u8aToHex; } });
@@ -0,0 +1,6 @@
1
+ export * from './createType';
2
+ export * from './format';
3
+ export * from './ready';
4
+ export * from './sign';
5
+ export * from './verify';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./createType"), exports);
18
+ __exportStar(require("./format"), exports);
19
+ __exportStar(require("./ready"), exports);
20
+ __exportStar(require("./sign"), exports);
21
+ __exportStar(require("./verify"), exports);
@@ -0,0 +1,3 @@
1
+ import { cryptoWaitReady } from '@polkadot/util-crypto';
2
+ export { cryptoWaitReady };
3
+ //# sourceMappingURL=ready.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ready.d.ts","sourceRoot":"","sources":["../../src/utils/ready.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cryptoWaitReady = void 0;
4
+ const util_crypto_1 = require("@polkadot/util-crypto");
5
+ Object.defineProperty(exports, "cryptoWaitReady", { enumerable: true, get: function () { return util_crypto_1.cryptoWaitReady; } });
@@ -0,0 +1,6 @@
1
+ import { signatureVerify } from '@polkadot/util-crypto';
2
+ import type { Signer } from '../types/wallet';
3
+ export declare const signMessage: (signer: Signer, address: string, data: string) => Promise<import("@polkadot/types/types/extrinsic").SignerResult>;
4
+ export declare const signingKey: (publicKey: Uint8Array) => `0x${string}`;
5
+ export { signatureVerify };
6
+ //# sourceMappingURL=sign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/utils/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAG7C,eAAO,MAAM,WAAW,WAAkB,MAAM,WAAW,MAAM,QAAQ,MAAM,oEAQ9E,CAAA;AAED,eAAO,MAAM,UAAU,cAAe,UAAU,kBAAwB,CAAA;AAExE,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.signatureVerify = exports.signingKey = exports.signMessage = void 0;
13
+ const util_crypto_1 = require("@polkadot/util-crypto");
14
+ Object.defineProperty(exports, "signatureVerify", { enumerable: true, get: function () { return util_crypto_1.signatureVerify; } });
15
+ const format_1 = require("./format");
16
+ const signMessage = (signer, address, data) => __awaiter(void 0, void 0, void 0, function* () {
17
+ if (!signer.signRaw)
18
+ throw new Error('signRaw not available on the signer');
19
+ return yield signer.signRaw({
20
+ address,
21
+ type: 'bytes',
22
+ data,
23
+ });
24
+ });
25
+ exports.signMessage = signMessage;
26
+ const signingKey = (publicKey) => (0, format_1.u8aToHex)(publicKey);
27
+ exports.signingKey = signingKey;
@@ -0,0 +1,4 @@
1
+ import { isHex } from '@polkadot/util';
2
+ import { isAddress } from '@polkadot/util-crypto';
3
+ export { isAddress, isHex };
4
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHex = exports.isAddress = void 0;
4
+ const util_1 = require("@polkadot/util");
5
+ Object.defineProperty(exports, "isHex", { enumerable: true, get: function () { return util_1.isHex; } });
6
+ const util_crypto_1 = require("@polkadot/util-crypto");
7
+ Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return util_crypto_1.isAddress; } });
package/dist/wallet.d.ts CHANGED
@@ -1,14 +1,8 @@
1
- import type { ApiPromise } from '@polkadot/api';
2
- import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
3
- import type { KeyringPair } from '@polkadot/keyring/types';
4
- import type { AppName, DomainInput, MnemonicOrURI, NetworkInput } from './types';
5
- export declare const setupWallet: (input: MnemonicOrURI) => Promise<KeyringPair>;
6
- export type ActivateWalletInput = (NetworkInput | DomainInput) & MnemonicOrURI & AppName;
7
- export type WalletActivated = {
8
- api: ApiPromise;
9
- accounts: InjectedAccountWithMeta[] & KeyringPair[];
10
- };
11
- export declare const activateWallet: (input: ActivateWalletInput) => Promise<WalletActivated>;
12
- export declare const mockWallets: (network?: NetworkInput | DomainInput) => Promise<WalletActivated[]>;
1
+ import type { DomainParams, MnemonicOrURI, NetworkParams } from './types';
2
+ import type { ActivateWalletParams, ApiPromise, GeneratedWallet, Wallet, WalletActivated } from './types/wallet';
3
+ export declare const setupWallet: (params: MnemonicOrURI) => Wallet;
4
+ export declare const generateWallet: () => GeneratedWallet;
5
+ export declare const activateWallet: (params: ActivateWalletParams) => Promise<WalletActivated>;
6
+ export declare const mockWallets: (network?: NetworkParams | DomainParams, api?: ApiPromise) => Promise<WalletActivated[]>;
13
7
  export declare const getMockWallet: (name: string, wallets: WalletActivated[]) => WalletActivated;
14
8
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAK1D,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAY,aAAa,EAAE,YAAY,EAAO,MAAM,SAAS,CAAA;AAE/F,eAAO,MAAM,WAAW,UAAiB,aAAa,KAAG,QAAQ,WAAW,CAc3E,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,aAAa,GAAG,OAAO,CAAA;AACxF,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,UAAU,CAAA;IACf,QAAQ,EAAE,uBAAuB,EAAE,GAAG,WAAW,EAAE,CAAA;CACpD,CAAA;AAED,eAAO,MAAM,cAAc,UAAiB,mBAAmB,KAAG,QAAQ,eAAe,CA0BxF,CAAA;AAED,eAAO,MAAM,WAAW,aACb,YAAY,GAAG,WAAW,KAClC,QAAQ,eAAe,EAAE,CAQzB,CAAA;AAEH,eAAO,MAAM,aAAa,SAAU,MAAM,WAAW,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,EAAE,aAAa,EAAO,MAAM,SAAS,CAAA;AACxF,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,eAAe,EACf,MAAM,EACN,eAAe,EAChB,MAAM,gBAAgB,CAAA;AAEvB,eAAO,MAAM,WAAW,WAAY,aAAa,KAAG,MAiBnD,CAAA;AAED,eAAO,MAAM,cAAc,QAAO,eAUjC,CAAA;AAED,eAAO,MAAM,cAAc,WAAkB,oBAAoB,KAAG,QAAQ,eAAe,CA4B1F,CAAA;AAED,eAAO,MAAM,WAAW,aACb,aAAa,GAAG,YAAY,QAC/B,UAAU,KACf,QAAQ,eAAe,EAAE,CAW3B,CAAA;AAED,eAAO,MAAM,aAAa,SAAU,MAAM,WAAW,eAAe,EAAE,KAAG,eAClB,CAAA"}
package/dist/wallet.js CHANGED
@@ -33,44 +33,63 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  });
34
34
  };
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getMockWallet = exports.mockWallets = exports.activateWallet = exports.setupWallet = void 0;
36
+ exports.getMockWallet = exports.mockWallets = exports.activateWallet = exports.generateWallet = exports.setupWallet = void 0;
37
37
  const api_1 = require("@polkadot/api");
38
38
  const util_crypto_1 = require("@polkadot/util-crypto");
39
+ const address_1 = require("./address");
39
40
  const api_2 = require("./api");
40
41
  const network_1 = require("./constants/network");
41
42
  const wallet_1 = require("./constants/wallet");
42
- const setupWallet = (input) => __awaiter(void 0, void 0, void 0, function* () {
43
- yield (0, util_crypto_1.cryptoWaitReady)();
43
+ const setupWallet = (params) => {
44
44
  const keyring = new api_1.Keyring({ type: 'sr25519' });
45
- let pair;
46
- if (input.uri) {
45
+ let keyringPair;
46
+ if (params.uri) {
47
47
  // Treat as uri
48
- pair = keyring.addFromUri(input.uri);
48
+ keyringPair = keyring.addFromUri(params.uri);
49
49
  }
50
- else if (input.mnemonic) {
50
+ else if (params.mnemonic) {
51
51
  // Treat as mnemonic
52
- pair = keyring.addFromUri(input.mnemonic);
52
+ keyringPair = keyring.addFromUri(params.mnemonic);
53
53
  }
54
54
  else
55
55
  throw new Error('Invalid mnemonic or private key');
56
- return pair;
57
- });
56
+ return {
57
+ keyringPair,
58
+ address: (0, address_1.address)(keyringPair.address),
59
+ commonAddress: keyringPair.address,
60
+ };
61
+ };
58
62
  exports.setupWallet = setupWallet;
59
- const activateWallet = (input) => __awaiter(void 0, void 0, void 0, function* () {
60
- // Create the API instance
61
- const api = input.domainId === undefined
62
- ? yield (0, api_2.activate)(input)
63
- : yield (0, api_2.activateDomain)(input);
63
+ const generateWallet = () => {
64
+ const mnemonic = (0, util_crypto_1.mnemonicGenerate)();
65
+ const { keyringPair, address, commonAddress } = (0, exports.setupWallet)({ mnemonic });
66
+ return {
67
+ mnemonic,
68
+ keyringPair,
69
+ address,
70
+ commonAddress,
71
+ };
72
+ };
73
+ exports.generateWallet = generateWallet;
74
+ const activateWallet = (params) => __awaiter(void 0, void 0, void 0, function* () {
75
+ if (!params.api) {
76
+ // Create the API instance if not provided
77
+ params.api =
78
+ params.domainId === undefined
79
+ ? yield (0, api_2.activate)(params)
80
+ : yield (0, api_2.activateDomain)(params);
81
+ }
64
82
  const accounts = [];
65
- if (input.mnemonic || input.uri) {
83
+ if (params.mnemonic || params.uri) {
66
84
  // Attach the wallet in a node environment
67
- const account = yield (0, exports.setupWallet)(input);
68
- accounts.push(account);
85
+ const { keyringPair } = (0, exports.setupWallet)(params);
86
+ if (keyringPair)
87
+ accounts.push(keyringPair);
69
88
  }
70
89
  else if (typeof window !== 'undefined') {
71
90
  const { web3Enable, web3Accounts } = yield Promise.resolve().then(() => __importStar(require('@polkadot/extension-dapp')));
72
91
  // Enable Polkadot.js extension in the browser
73
- yield web3Enable(input.appName || 'Auto');
92
+ yield web3Enable(params.appName || 'Auto');
74
93
  // Get the list of accounts from the extension
75
94
  const allAccounts = yield web3Accounts();
76
95
  accounts.push(...allAccounts);
@@ -79,11 +98,17 @@ const activateWallet = (input) => __awaiter(void 0, void 0, void 0, function* ()
79
98
  }
80
99
  else
81
100
  throw new Error('No wallet provided');
82
- return { api, accounts };
101
+ return { api: params.api, accounts, address: (0, address_1.address)(accounts[0].address) };
83
102
  });
84
103
  exports.activateWallet = activateWallet;
85
- const mockWallets = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (network = { networkId: network_1.defaultNetwork.id }) {
86
- return yield Promise.all(wallet_1.mockURIs.map((uri) => (0, exports.activateWallet)(Object.assign(Object.assign({}, network), { uri }))));
104
+ const mockWallets = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (network = { networkId: network_1.defaultNetwork.id }, api) {
105
+ const wallets = [];
106
+ for (const uri of wallet_1.mockURIs) {
107
+ const wallet = yield (0, exports.activateWallet)(Object.assign(Object.assign({}, network), { uri,
108
+ api }));
109
+ wallets.push(wallet);
110
+ }
111
+ return wallets;
87
112
  });
88
113
  exports.mockWallets = mockWallets;
89
114
  const getMockWallet = (name, wallets) => wallets[Object.values(wallet_1.mockURIs).indexOf(`//${name}`)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonomys/auto-utils",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc",
@@ -36,5 +36,5 @@
36
36
  "browser": {
37
37
  "fs": false
38
38
  },
39
- "gitHead": "457844c0907bafa6079549968fba6c3a299618ff"
39
+ "gitHead": "8f1d6171a537e44d29aa19ff2f5c5176046ca0f9"
40
40
  }
@@ -1,3 +0,0 @@
1
- import type { ApiPromise as PolkadotApiPromise } from '@polkadot/api';
2
- export type ApiPromise = PolkadotApiPromise;
3
- //# sourceMappingURL=api.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAErE,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAA"}
File without changes