@cityofzion/blockchain-service 1.14.0 → 1.15.1
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/BSAggregator.d.ts +2 -2
- package/dist/BSAggregator.js +3 -3
- package/dist/functions.d.ts +4 -2
- package/dist/functions.js +50 -23
- package/dist/interfaces.d.ts +2 -1
- package/package.json +1 -1
package/dist/BSAggregator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Account, BlockchainService } from './interfaces';
|
|
1
|
+
import { Account, BlockchainService, UntilIndexRecord } from './interfaces';
|
|
2
2
|
export declare class BSAggregator<BSName extends string = string> {
|
|
3
3
|
#private;
|
|
4
4
|
readonly blockchainServicesByName: Record<BSName, BlockchainService<BSName>>;
|
|
@@ -10,5 +10,5 @@ export declare class BSAggregator<BSName extends string = string> {
|
|
|
10
10
|
getBlockchainNameByAddress(address: string): BSName[];
|
|
11
11
|
getBlockchainNameByKey(wif: string): BSName[];
|
|
12
12
|
getBlockchainNameByEncrypted(keyOrJson: string): BSName[];
|
|
13
|
-
generateAccountsFromMnemonic(mnemonic: string): Promise<Map<BSName, Account<BSName>[]>>;
|
|
13
|
+
generateAccountsFromMnemonic(mnemonic: string, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
14
14
|
}
|
package/dist/BSAggregator.js
CHANGED
|
@@ -56,11 +56,11 @@ class BSAggregator {
|
|
|
56
56
|
getBlockchainNameByEncrypted(keyOrJson) {
|
|
57
57
|
return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateEncrypted(keyOrJson)).map(bs => bs.name);
|
|
58
58
|
}
|
|
59
|
-
generateAccountsFromMnemonic(mnemonic) {
|
|
59
|
+
generateAccountsFromMnemonic(mnemonic, untilIndexByBlockchainService) {
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
return (0, functions_1.
|
|
61
|
+
return (0, functions_1.generateAccountForBlockchainService)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
62
62
|
return service.generateAccountFromMnemonic(mnemonic, index);
|
|
63
|
-
}));
|
|
63
|
+
}), untilIndexByBlockchainService);
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
}
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft } from './interfaces';
|
|
1
|
+
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, UntilIndexRecord } from './interfaces';
|
|
2
2
|
export declare function hasNameService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithNameService;
|
|
3
3
|
export declare function isClaimable<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSClaimable<BSName>;
|
|
4
4
|
export declare function isCalculableFee<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSCalculableFee<BSName>;
|
|
@@ -11,7 +11,9 @@ export declare function wait(ms: number): Promise<unknown>;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function waitForTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string): Promise<boolean>;
|
|
13
13
|
export declare function waitForAccountTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string, account: Account<BSName>, maxAttempts?: number): Promise<boolean>;
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function fetchAccounts<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
15
|
+
export declare function generateAccount<BSName extends string = string>(blockchainServices: BlockchainService<BSName>, initialIndex: number, untilIndex: number, getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Account<BSName>[]>;
|
|
16
|
+
export declare function generateAccountForBlockchainService<BSName extends string = string>(blockchainServices: BlockchainService<BSName>[], getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
15
17
|
export declare function normalizeHash(hash: string): string;
|
|
16
18
|
export declare function denormalizeHash(hash: string): string;
|
|
17
19
|
export declare function countDecimals(value: string | number): number;
|
package/dist/functions.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.formatNumber = exports.countDecimals = exports.denormalizeHash = exports.normalizeHash = exports.
|
|
12
|
+
exports.formatNumber = exports.countDecimals = exports.denormalizeHash = exports.normalizeHash = exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.wait = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
13
|
function hasNameService(service) {
|
|
14
14
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
15
|
}
|
|
@@ -81,37 +81,64 @@ function waitForAccountTransaction(service, txId, account, maxAttempts = 10) {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
exports.waitForAccountTransaction = waitForAccountTransaction;
|
|
84
|
-
function
|
|
84
|
+
function fetchAccounts(blockchainServices, initialIndex, getAccountCallback) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const accounts = [];
|
|
87
|
+
let index = initialIndex;
|
|
88
|
+
let shouldBreak = false;
|
|
89
|
+
while (!shouldBreak) {
|
|
90
|
+
const generatedAccount = yield getAccountCallback(blockchainServices, index);
|
|
91
|
+
try {
|
|
92
|
+
const { transactions } = yield blockchainServices.blockchainDataService.getTransactionsByAddress({
|
|
93
|
+
address: generatedAccount.address,
|
|
94
|
+
});
|
|
95
|
+
if (!transactions || transactions.length <= 0)
|
|
96
|
+
shouldBreak = true;
|
|
97
|
+
}
|
|
98
|
+
catch (_b) {
|
|
99
|
+
shouldBreak = true;
|
|
100
|
+
}
|
|
101
|
+
accounts.push(generatedAccount);
|
|
102
|
+
index++;
|
|
103
|
+
}
|
|
104
|
+
return accounts;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
exports.fetchAccounts = fetchAccounts;
|
|
108
|
+
function generateAccount(blockchainServices, initialIndex, untilIndex, getAccountCallback) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const accounts = [];
|
|
111
|
+
let index = initialIndex;
|
|
112
|
+
while (index <= untilIndex) {
|
|
113
|
+
const generatedAccount = yield getAccountCallback(blockchainServices, index);
|
|
114
|
+
accounts.push(generatedAccount);
|
|
115
|
+
index++;
|
|
116
|
+
}
|
|
117
|
+
return accounts;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
exports.generateAccount = generateAccount;
|
|
121
|
+
function generateAccountForBlockchainService(blockchainServices, getAccountCallback, untilIndexByBlockchainService) {
|
|
85
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
123
|
const accountsByBlockchainService = new Map();
|
|
87
124
|
const promises = blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (!transactions || transactions.length <= 0)
|
|
99
|
-
shouldBreak = true;
|
|
100
|
-
}
|
|
101
|
-
catch (_b) {
|
|
102
|
-
shouldBreak = true;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
accounts.push(generatedAccount);
|
|
106
|
-
index++;
|
|
125
|
+
var _b;
|
|
126
|
+
const firstAccount = yield getAccountCallback(service, 0);
|
|
127
|
+
const untilIndex = (_b = untilIndexByBlockchainService === null || untilIndexByBlockchainService === void 0 ? void 0 : untilIndexByBlockchainService[service.name]) === null || _b === void 0 ? void 0 : _b[firstAccount.address];
|
|
128
|
+
if (untilIndex === undefined) {
|
|
129
|
+
const accounts = yield fetchAccounts(service, 1, getAccountCallback);
|
|
130
|
+
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const accounts = yield generateAccount(service, 1, untilIndex, getAccountCallback);
|
|
134
|
+
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
107
135
|
}
|
|
108
|
-
accountsByBlockchainService.set(service.name, accounts);
|
|
109
136
|
}));
|
|
110
137
|
yield Promise.all(promises);
|
|
111
138
|
return accountsByBlockchainService;
|
|
112
139
|
});
|
|
113
140
|
}
|
|
114
|
-
exports.
|
|
141
|
+
exports.generateAccountForBlockchainService = generateAccountForBlockchainService;
|
|
115
142
|
function normalizeHash(hash) {
|
|
116
143
|
return hash.replace('0x', '').toLowerCase();
|
|
117
144
|
}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Transport from '@ledgerhq/hw-transport';
|
|
2
2
|
import TypedEmitter from 'typed-emitter';
|
|
3
|
+
export type UntilIndexRecord<BSName extends string = string> = Partial<Record<BSName, Record<string, number>>>;
|
|
3
4
|
export type Account<BSName extends string = string> = {
|
|
4
5
|
key: string;
|
|
5
6
|
type: 'wif' | 'privateKey' | 'publicKey';
|
|
@@ -226,7 +227,7 @@ export type GetLedgerTransport<BSName extends string = string> = (account: Accou
|
|
|
226
227
|
export interface LedgerService<BSName extends string = string> {
|
|
227
228
|
emitter: LedgerServiceEmitter;
|
|
228
229
|
getLedgerTransport?: GetLedgerTransport<BSName>;
|
|
229
|
-
getAccounts(transport: Transport): Promise<Account<BSName>[]>;
|
|
230
|
+
getAccounts(transport: Transport, getUntilIndex?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
|
|
230
231
|
getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
|
|
231
232
|
}
|
|
232
233
|
export type SwapServiceToken<BSName extends string = string> = {
|