@cityofzion/blockchain-service 1.3.2 → 1.5.0

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.
@@ -1,4 +1,4 @@
1
- import { AccountWithDerivationPath, BlockchainService } from './interfaces';
1
+ import { Account, BlockchainService } from './interfaces';
2
2
  export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName, string> = BlockchainService<BSCustomName, string>> {
3
3
  #private;
4
4
  readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
@@ -11,5 +11,5 @@ export declare class BSAggregator<BSCustomName extends string = string, BSCustom
11
11
  getBlockchainNameByAddress(address: string): BSCustomName[];
12
12
  getBlockchainNameByKey(wif: string): BSCustomName[];
13
13
  getBlockchainNameByEncrypted(keyOrJson: string): BSCustomName[];
14
- generateAccountFromMnemonicAllBlockchains(mnemonic: string, skippedAddresses?: string[]): Promise<Map<BSCustomName, AccountWithDerivationPath[]>>;
14
+ generateAccountsFromMnemonic(mnemonic: string): Promise<Map<BSCustomName, Account[]>>;
15
15
  }
@@ -22,6 +22,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
22
  var _BSAggregator_blockchainServices;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.BSAggregator = void 0;
25
+ const functions_1 = require("./functions");
25
26
  class BSAggregator {
26
27
  constructor(blockchainServices) {
27
28
  _BSAggregator_blockchainServices.set(this, void 0);
@@ -55,38 +56,11 @@ class BSAggregator {
55
56
  getBlockchainNameByEncrypted(keyOrJson) {
56
57
  return __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").filter(bs => bs.validateEncrypted(keyOrJson)).map(bs => bs.blockchainName);
57
58
  }
58
- generateAccountFromMnemonicAllBlockchains(mnemonic, skippedAddresses) {
59
+ generateAccountsFromMnemonic(mnemonic) {
59
60
  return __awaiter(this, void 0, void 0, function* () {
60
- const mnemonicAccounts = new Map();
61
- const promises = __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").map((service) => __awaiter(this, void 0, void 0, function* () {
62
- let index = 0;
63
- const accounts = [];
64
- let hasError = false;
65
- while (!hasError) {
66
- const generatedAccount = service.generateAccountFromMnemonic(mnemonic, index);
67
- if (skippedAddresses && skippedAddresses.find(address => address === generatedAccount.address)) {
68
- index++;
69
- continue;
70
- }
71
- if (index !== 0) {
72
- try {
73
- const { transactions } = yield service.blockchainDataService.getTransactionsByAddress({
74
- address: generatedAccount.address,
75
- });
76
- if (!transactions || transactions.length <= 0)
77
- hasError = true;
78
- }
79
- catch (_a) {
80
- hasError = true;
81
- }
82
- }
83
- accounts.push(generatedAccount);
84
- index++;
85
- }
86
- mnemonicAccounts.set(service.blockchainName, accounts);
61
+ return (0, functions_1.fetchAccountsForBlockchainServices)(__classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f"), (service, index) => __awaiter(this, void 0, void 0, function* () {
62
+ return service.generateAccountFromMnemonic(mnemonic, index);
87
63
  }));
88
- yield Promise.all(promises);
89
- return mnemonicAccounts;
90
64
  });
91
65
  }
92
66
  }
@@ -1,4 +1,4 @@
1
- import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BSWithSwap } from './interfaces';
1
+ import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, BSWithSwap } from './interfaces';
2
2
  export declare function hasNameService(service: BlockchainService): service is BlockchainService & BSWithNameService;
3
3
  export declare function isClaimable(service: BlockchainService): service is BlockchainService & BSClaimable;
4
4
  export declare function isCalculableFee(service: BlockchainService): service is BlockchainService & BSCalculableFee;
@@ -7,3 +7,4 @@ export declare function hasExplorerService(service: BlockchainService): service
7
7
  export declare function hasLedger(service: BlockchainService): service is BlockchainService & BSWithLedger;
8
8
  export declare function hasSwap(service: BlockchainService): service is BlockchainService & BSWithSwap;
9
9
  export declare function waitForTransaction(service: BlockchainService, txId: string): Promise<boolean>;
10
+ export declare function fetchAccountsForBlockchainServices<BSCustomName extends string = string>(blockchainServices: BlockchainService<BSCustomName>[], getAccountCallback: (service: BlockchainService<BSCustomName>, index: number) => Promise<Account>): Promise<Map<BSCustomName, Account[]>>;
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.waitForTransaction = exports.hasSwap = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
12
+ exports.fetchAccountsForBlockchainServices = exports.waitForTransaction = exports.hasSwap = 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
  }
@@ -61,3 +61,34 @@ function waitForTransaction(service, txId) {
61
61
  });
62
62
  }
63
63
  exports.waitForTransaction = waitForTransaction;
64
+ function fetchAccountsForBlockchainServices(blockchainServices, getAccountCallback) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const accountsByBlockchainService = new Map();
67
+ const promises = blockchainServices.map((service) => __awaiter(this, void 0, void 0, function* () {
68
+ let index = 0;
69
+ const accounts = [];
70
+ let shouldBreak = false;
71
+ while (!shouldBreak) {
72
+ const generatedAccount = yield getAccountCallback(service, index);
73
+ if (index !== 0) {
74
+ try {
75
+ const { transactions } = yield service.blockchainDataService.getTransactionsByAddress({
76
+ address: generatedAccount.address,
77
+ });
78
+ if (!transactions || transactions.length <= 0)
79
+ shouldBreak = true;
80
+ }
81
+ catch (_a) {
82
+ shouldBreak = true;
83
+ }
84
+ }
85
+ accounts.push(generatedAccount);
86
+ index++;
87
+ }
88
+ accountsByBlockchainService.set(service.blockchainName, accounts);
89
+ }));
90
+ yield Promise.all(promises);
91
+ return accountsByBlockchainService;
92
+ });
93
+ }
94
+ exports.fetchAccountsForBlockchainServices = fetchAccountsForBlockchainServices;
@@ -4,9 +4,7 @@ export type Account = {
4
4
  key: string;
5
5
  type: 'wif' | 'privateKey' | 'publicKey';
6
6
  address: string;
7
- };
8
- export type AccountWithDerivationPath = Account & {
9
- derivationPath: string;
7
+ bip44Path?: string;
10
8
  };
11
9
  export interface Token {
12
10
  symbol: string;
@@ -28,28 +26,29 @@ export type IntentTransferParam = {
28
26
  };
29
27
  export type TransferParam = {
30
28
  senderAccount: Account;
31
- intent: IntentTransferParam;
29
+ intents: IntentTransferParam[];
32
30
  tipIntent?: IntentTransferParam;
33
31
  priorityFee?: string;
34
32
  isLedger?: boolean;
35
33
  };
36
34
  export interface BlockchainService<BSCustomName extends string = string, BSAvailableNetworks extends string = string> {
37
35
  readonly blockchainName: BSCustomName;
38
- readonly derivationPath: string;
36
+ readonly bip44DerivationPath: string;
39
37
  readonly feeToken: Token;
40
38
  exchangeDataService: ExchangeDataService;
41
39
  blockchainDataService: BlockchainDataService;
42
40
  tokens: Token[];
43
41
  network: Network<BSAvailableNetworks>;
42
+ clone: () => BlockchainService<BSCustomName, BSAvailableNetworks>;
44
43
  setNetwork: (partialNetwork: Network<BSAvailableNetworks>) => void;
45
- generateAccountFromMnemonic(mnemonic: string | string, index: number): AccountWithDerivationPath;
44
+ generateAccountFromMnemonic(mnemonic: string | string, index: number): Account;
46
45
  generateAccountFromKey(key: string): Account;
47
46
  decrypt(keyOrJson: string, password: string): Promise<Account>;
48
47
  encrypt(key: string, password: string): Promise<string>;
49
48
  validateAddress(address: string): boolean;
50
49
  validateEncrypted(keyOrJson: string): boolean;
51
50
  validateKey(key: string): boolean;
52
- transfer(param: TransferParam): Promise<string>;
51
+ transfer(param: TransferParam): Promise<string[]>;
53
52
  }
54
53
  export interface BSCalculableFee {
55
54
  calculateTransferFee(param: TransferParam, details?: boolean): Promise<string>;
@@ -223,11 +222,12 @@ export type LedgerServiceEmitter = TypedEmitter<{
223
222
  getSignatureStart(): void | Promise<void>;
224
223
  getSignatureEnd(): void | Promise<void>;
225
224
  }>;
225
+ export type GetLedgerTransport = (account: Account) => Promise<Transport>;
226
226
  export interface LedgerService {
227
227
  emitter: LedgerServiceEmitter;
228
- getLedgerTransport?: (account: Account) => Promise<Transport>;
229
- getAddress(transport: Transport): Promise<string>;
230
- getPublicKey(transport: Transport): Promise<string>;
228
+ getLedgerTransport?: GetLedgerTransport;
229
+ getAccounts(transport: Transport): Promise<Account[]>;
230
+ getAccount(transport: Transport, index: number): Promise<Account>;
231
231
  }
232
232
  export type SwapRoute = {
233
233
  tokenToUse: Token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.3.2",
3
+ "version": "1.5.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",