@cityofzion/blockchain-service 1.3.1 → 1.4.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,8 +1,10 @@
1
- import { BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft } 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;
5
5
  export declare function hasNft(service: BlockchainService): service is BlockchainService & BSWithNft;
6
6
  export declare function hasExplorerService(service: BlockchainService): service is BlockchainService & BSWithExplorerService;
7
7
  export declare function hasLedger(service: BlockchainService): service is BlockchainService & BSWithLedger;
8
+ export declare function hasSwap(service: BlockchainService): service is BlockchainService & BSWithSwap;
8
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.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
  }
@@ -34,6 +34,10 @@ function hasLedger(service) {
34
34
  return 'ledgerService' in service;
35
35
  }
36
36
  exports.hasLedger = hasLedger;
37
+ function hasSwap(service) {
38
+ return 'createSwapService' in service;
39
+ }
40
+ exports.hasSwap = hasSwap;
37
41
  function wait(ms) {
38
42
  return new Promise(resolve => setTimeout(resolve, ms));
39
43
  }
@@ -57,3 +61,34 @@ function waitForTransaction(service, txId) {
57
61
  });
58
62
  }
59
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,28 @@ 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>;
44
42
  setNetwork: (partialNetwork: Network<BSAvailableNetworks>) => void;
45
- generateAccountFromMnemonic(mnemonic: string | string, index: number): AccountWithDerivationPath;
43
+ generateAccountFromMnemonic(mnemonic: string | string, index: number): Account;
46
44
  generateAccountFromKey(key: string): Account;
47
45
  decrypt(keyOrJson: string, password: string): Promise<Account>;
48
46
  encrypt(key: string, password: string): Promise<string>;
49
47
  validateAddress(address: string): boolean;
50
48
  validateEncrypted(keyOrJson: string): boolean;
51
49
  validateKey(key: string): boolean;
52
- transfer(param: TransferParam): Promise<string>;
50
+ transfer(param: TransferParam): Promise<string[]>;
53
51
  }
54
52
  export interface BSCalculableFee {
55
53
  calculateTransferFee(param: TransferParam, details?: boolean): Promise<string>;
@@ -74,6 +72,9 @@ export interface BSWithLedger {
74
72
  ledgerService: LedgerService;
75
73
  generateAccountFromPublicKey(publicKey: string): Account;
76
74
  }
75
+ export interface BSWithSwap<BSAvailableNetworks extends string = string> {
76
+ createSwapService(): SwapService<BSAvailableNetworks>;
77
+ }
77
78
  export type TransactionNotifications = {
78
79
  eventName: string;
79
80
  state: {
@@ -223,8 +224,8 @@ export type LedgerServiceEmitter = TypedEmitter<{
223
224
  export interface LedgerService {
224
225
  emitter: LedgerServiceEmitter;
225
226
  getLedgerTransport?: (account: Account) => Promise<Transport>;
226
- getAddress(transport: Transport): Promise<string>;
227
- getPublicKey(transport: Transport): Promise<string>;
227
+ getAccounts(transport: Transport): Promise<Account[]>;
228
+ getAccount(transport: Transport, index: number): Promise<Account>;
228
229
  }
229
230
  export type SwapRoute = {
230
231
  tokenToUse: Token;
@@ -279,6 +280,5 @@ export interface SwapService<AvailableNetworkIds extends string> {
279
280
  setTokenToReceive(token: Token | null): void;
280
281
  startListeningBlockGeneration(): void;
281
282
  stopListeningBlockGeneration(): void;
282
- listSwappableTokensSymbol(network: Network<AvailableNetworkIds>): string[];
283
283
  swap(isLedger?: boolean): void;
284
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",