@cityofzion/blockchain-service 1.15.0 → 1.15.2
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 -8
- package/dist/functions.d.ts +5 -3
- package/dist/functions.js +50 -40
- package/dist/interfaces.d.ts +19 -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,
|
|
13
|
+
generateAccountsFromMnemonic(mnemonic: string, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Map<BSName, Account<BSName>[]>>;
|
|
14
14
|
}
|
package/dist/BSAggregator.js
CHANGED
|
@@ -56,16 +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
|
-
|
|
62
|
-
return (0, functions_1.fetchAccountsForBlockchainServices)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
return service.generateAccountFromMnemonic(mnemonic, index);
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
return (0, functions_1.generateAccountUntilIndexForBlockchainService)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), untilIndex, (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return (0, functions_1.generateAccountForBlockchainService)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), (service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
67
62
|
return service.generateAccountFromMnemonic(mnemonic, index);
|
|
68
|
-
}));
|
|
63
|
+
}), untilIndexByBlockchainService);
|
|
69
64
|
});
|
|
70
65
|
}
|
|
71
66
|
}
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft } from './interfaces';
|
|
1
|
+
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSMigrationNeo3, 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
|
+
export declare function hasMigrationNeo3<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSMigrationNeo3<BSName>;
|
|
4
5
|
export declare function isCalculableFee<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSCalculableFee<BSName>;
|
|
5
6
|
export declare function hasNft<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithNft;
|
|
6
7
|
export declare function hasExplorerService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithExplorerService;
|
|
@@ -11,8 +12,9 @@ export declare function wait(ms: number): Promise<unknown>;
|
|
|
11
12
|
*/
|
|
12
13
|
export declare function waitForTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string): Promise<boolean>;
|
|
13
14
|
export declare function waitForAccountTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string, account: Account<BSName>, maxAttempts?: number): Promise<boolean>;
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
15
|
+
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>[]>;
|
|
16
|
+
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>[]>;
|
|
17
|
+
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>[]>>;
|
|
16
18
|
export declare function normalizeHash(hash: string): string;
|
|
17
19
|
export declare function denormalizeHash(hash: string): string;
|
|
18
20
|
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.hasMigrationNeo3 = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
13
|
function hasNameService(service) {
|
|
14
14
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
15
15
|
}
|
|
@@ -18,6 +18,10 @@ function isClaimable(service) {
|
|
|
18
18
|
return 'claim' in service && 'claimToken' in service && 'getUnclaimed' in service.blockchainDataService;
|
|
19
19
|
}
|
|
20
20
|
exports.isClaimable = isClaimable;
|
|
21
|
+
function hasMigrationNeo3(service) {
|
|
22
|
+
return 'migrateToNeo3' in service && 'calculateToMigrateToNeo3Values' in service;
|
|
23
|
+
}
|
|
24
|
+
exports.hasMigrationNeo3 = hasMigrationNeo3;
|
|
21
25
|
function isCalculableFee(service) {
|
|
22
26
|
return 'calculateTransferFee' in service;
|
|
23
27
|
}
|
|
@@ -81,58 +85,64 @@ function waitForAccountTransaction(service, txId, account, maxAttempts = 10) {
|
|
|
81
85
|
});
|
|
82
86
|
}
|
|
83
87
|
exports.waitForAccountTransaction = waitForAccountTransaction;
|
|
84
|
-
function
|
|
88
|
+
function fetchAccounts(blockchainServices, initialIndex, getAccountCallback) {
|
|
85
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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++;
|
|
90
|
+
const accounts = [];
|
|
91
|
+
let index = initialIndex;
|
|
92
|
+
let shouldBreak = false;
|
|
93
|
+
while (!shouldBreak) {
|
|
94
|
+
const generatedAccount = yield getAccountCallback(blockchainServices, index);
|
|
95
|
+
try {
|
|
96
|
+
const { transactions } = yield blockchainServices.blockchainDataService.getTransactionsByAddress({
|
|
97
|
+
address: generatedAccount.address,
|
|
98
|
+
});
|
|
99
|
+
if (!transactions || transactions.length <= 0)
|
|
100
|
+
shouldBreak = true;
|
|
107
101
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
catch (_b) {
|
|
103
|
+
shouldBreak = true;
|
|
104
|
+
}
|
|
105
|
+
accounts.push(generatedAccount);
|
|
106
|
+
index++;
|
|
107
|
+
}
|
|
108
|
+
return accounts;
|
|
112
109
|
});
|
|
113
110
|
}
|
|
114
|
-
exports.
|
|
115
|
-
function
|
|
111
|
+
exports.fetchAccounts = fetchAccounts;
|
|
112
|
+
function generateAccount(blockchainServices, initialIndex, untilIndex, getAccountCallback) {
|
|
116
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
const accounts = [];
|
|
115
|
+
let index = initialIndex;
|
|
116
|
+
while (index <= untilIndex) {
|
|
117
|
+
const generatedAccount = yield getAccountCallback(blockchainServices, index);
|
|
118
|
+
accounts.push(generatedAccount);
|
|
119
|
+
index++;
|
|
119
120
|
}
|
|
121
|
+
return accounts;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
exports.generateAccount = generateAccount;
|
|
125
|
+
function generateAccountForBlockchainService(blockchainServices, getAccountCallback, untilIndexByBlockchainService) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
127
|
const accountsByBlockchainService = new Map();
|
|
121
128
|
const promises = blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
accounts
|
|
127
|
-
|
|
129
|
+
var _b;
|
|
130
|
+
const firstAccount = yield getAccountCallback(service, 0);
|
|
131
|
+
const untilIndex = (_b = untilIndexByBlockchainService === null || untilIndexByBlockchainService === void 0 ? void 0 : untilIndexByBlockchainService[service.name]) === null || _b === void 0 ? void 0 : _b[firstAccount.address];
|
|
132
|
+
if (untilIndex === undefined) {
|
|
133
|
+
const accounts = yield fetchAccounts(service, 1, getAccountCallback);
|
|
134
|
+
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const accounts = yield generateAccount(service, 1, untilIndex, getAccountCallback);
|
|
138
|
+
accountsByBlockchainService.set(service.name, [firstAccount, ...accounts]);
|
|
128
139
|
}
|
|
129
|
-
accountsByBlockchainService.set(service.name, accounts);
|
|
130
140
|
}));
|
|
131
|
-
yield Promise.
|
|
141
|
+
yield Promise.all(promises);
|
|
132
142
|
return accountsByBlockchainService;
|
|
133
143
|
});
|
|
134
144
|
}
|
|
135
|
-
exports.
|
|
145
|
+
exports.generateAccountForBlockchainService = generateAccountForBlockchainService;
|
|
136
146
|
function normalizeHash(hash) {
|
|
137
147
|
return hash.replace('0x', '').toLowerCase();
|
|
138
148
|
}
|
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';
|
|
@@ -60,6 +61,23 @@ export interface BSClaimable<BSName extends string = string> {
|
|
|
60
61
|
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
61
62
|
claim(account: Account<BSName>): Promise<string>;
|
|
62
63
|
}
|
|
64
|
+
export type MigrateToNeo3Params<BSName extends string = string> = {
|
|
65
|
+
account: Account<BSName>;
|
|
66
|
+
address: string;
|
|
67
|
+
};
|
|
68
|
+
export type CalculateToMigrateToNeo3ValuesParams<BSName extends string = string> = {
|
|
69
|
+
account: Account<BSName>;
|
|
70
|
+
};
|
|
71
|
+
export type CalculateToMigrateToNeo3ValuesResponse = {
|
|
72
|
+
gasMigrationTotalFees?: string;
|
|
73
|
+
neoMigrationTotalFees?: string;
|
|
74
|
+
gasMigrationAmount?: string;
|
|
75
|
+
neoMigrationAmount?: string;
|
|
76
|
+
};
|
|
77
|
+
export interface BSMigrationNeo3<BSName extends string = string> {
|
|
78
|
+
migrateToNeo3(params: MigrateToNeo3Params<BSName>): Promise<string[]>;
|
|
79
|
+
calculateToMigrateToNeo3Values(params: CalculateToMigrateToNeo3ValuesParams<BSName>): Promise<CalculateToMigrateToNeo3ValuesResponse>;
|
|
80
|
+
}
|
|
63
81
|
export interface BSWithNameService {
|
|
64
82
|
resolveNameServiceDomain(domainName: string): Promise<string>;
|
|
65
83
|
validateNameServiceDomainFormat(domainName: string): boolean;
|
|
@@ -226,7 +244,7 @@ export type GetLedgerTransport<BSName extends string = string> = (account: Accou
|
|
|
226
244
|
export interface LedgerService<BSName extends string = string> {
|
|
227
245
|
emitter: LedgerServiceEmitter;
|
|
228
246
|
getLedgerTransport?: GetLedgerTransport<BSName>;
|
|
229
|
-
getAccounts(transport: Transport,
|
|
247
|
+
getAccounts(transport: Transport, getUntilIndex?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
|
|
230
248
|
getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
|
|
231
249
|
}
|
|
232
250
|
export type SwapServiceToken<BSName extends string = string> = {
|