@cityofzion/blockchain-service 1.23.0 → 3.0.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.
@@ -7,8 +7,8 @@ export declare function hasExplorerService<N extends string = string, A extends
7
7
  export declare function hasLedger<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithLedger<N>;
8
8
  export declare function hasNeo3NeoXBridge<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNeo3NeoXBridge<N>;
9
9
  export declare function hasEncryption<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithEncryption<N>;
10
- export declare function hasWalletConnect<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithWalletConnect;
11
- export declare function hasFullTransactions<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFullTransactions;
10
+ export declare function hasWalletConnect<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithWalletConnect<N>;
11
+ export declare function hasFullTransactions<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFullTransactions<N>;
12
12
  /**
13
13
  * @deprecated use `waitForAccountTransaction` instead
14
14
  */
package/dist/functions.js CHANGED
@@ -85,7 +85,7 @@ function waitForAccountTransaction(params) {
85
85
  yield BSUtilsHelper_1.BSUtilsHelper.wait(60000);
86
86
  try {
87
87
  const response = yield service.blockchainDataService.getTransactionsByAddress({ address });
88
- const isTransactionConfirmed = response.data.some(transaction => transaction.txId === txId);
88
+ const isTransactionConfirmed = response.transactions.some(transaction => transaction.txId === txId);
89
89
  if (isTransactionConfirmed)
90
90
  return true;
91
91
  }
@@ -105,10 +105,10 @@ function fetchAccounts(service, initialIndex, getAccountCallback) {
105
105
  while (!shouldBreak) {
106
106
  const generatedAccount = yield getAccountCallback(service, index);
107
107
  try {
108
- const { data } = yield service.blockchainDataService.getTransactionsByAddress({
108
+ const { transactions } = yield service.blockchainDataService.getTransactionsByAddress({
109
109
  address: generatedAccount.address,
110
110
  });
111
- if (!data || data.length <= 0)
111
+ if (!transactions || transactions.length <= 0)
112
112
  shouldBreak = true;
113
113
  }
114
114
  catch (_a) {
@@ -1,8 +1,8 @@
1
1
  import Transport from '@ledgerhq/hw-transport';
2
2
  import TypedEmitter from 'typed-emitter';
3
3
  import { BSError } from './error';
4
- export type TUntilIndexRecord<N extends string = string> = Partial<Record<N, Record<string, number>>>;
5
- export type TBSAccount<N extends string = string> = {
4
+ export type TUntilIndexRecord<N extends string> = Partial<Record<N, Record<string, number>>>;
5
+ export type TBSAccount<N extends string> = {
6
6
  key: string;
7
7
  type: 'wif' | 'privateKey' | 'publicKey';
8
8
  address: string;
@@ -29,7 +29,7 @@ export type TIntentTransferParam = {
29
29
  amount: string;
30
30
  token: TBSToken;
31
31
  };
32
- export type TTransferParam<N extends string = string> = {
32
+ export type TTransferParam<N extends string> = {
33
33
  senderAccount: TBSAccount<N>;
34
34
  intents: TIntentTransferParam[];
35
35
  priorityFee?: string;
@@ -39,7 +39,7 @@ export type TPingNetworkResponse = {
39
39
  url: string;
40
40
  height: number;
41
41
  };
42
- export interface IBlockchainService<N extends string = string, A extends string = string> {
42
+ export interface IBlockchainService<N extends string, A extends string = string> {
43
43
  readonly name: N;
44
44
  readonly bip44DerivationPath: string;
45
45
  readonly feeToken: TBSToken;
@@ -52,7 +52,7 @@ export interface IBlockchainService<N extends string = string, A extends string
52
52
  readonly defaultNetwork: TBSNetwork<A>;
53
53
  readonly availableNetworks: TBSNetwork<A>[];
54
54
  exchangeDataService: IExchangeDataService;
55
- blockchainDataService: IBlockchainDataService;
55
+ blockchainDataService: IBlockchainDataService<N>;
56
56
  tokenService: ITokenService;
57
57
  pingNode(url: string): Promise<TPingNetworkResponse>;
58
58
  setNetwork(network: TBSNetwork<A>): void;
@@ -62,15 +62,15 @@ export interface IBlockchainService<N extends string = string, A extends string
62
62
  validateKey(key: string): boolean;
63
63
  transfer(param: TTransferParam<N>): Promise<string[]>;
64
64
  }
65
- export interface IBSWithEncryption<N extends string = string> {
65
+ export interface IBSWithEncryption<N extends string> {
66
66
  decrypt(keyOrJson: string, password: string): Promise<TBSAccount<N>>;
67
67
  encrypt(key: string, password: string): Promise<string>;
68
68
  validateEncrypted(keyOrJson: string): boolean;
69
69
  }
70
- export interface IBSWithFee<N extends string = string> {
70
+ export interface IBSWithFee<N extends string> {
71
71
  calculateTransferFee(param: TTransferParam<N>): Promise<string>;
72
72
  }
73
- export interface IBSWithClaim<N extends string = string> {
73
+ export interface IBSWithClaim<N extends string> {
74
74
  readonly claimToken: TBSToken;
75
75
  readonly burnToken: TBSToken;
76
76
  claimDataService: IClaimDataService;
@@ -86,15 +86,15 @@ export interface IBSWithExplorer {
86
86
  export interface IBSWithNft {
87
87
  nftDataService: INftDataService;
88
88
  }
89
- export interface IBSWithLedger<N extends string = string> {
89
+ export interface IBSWithLedger<N extends string> {
90
90
  ledgerService: ILedgerService<N>;
91
91
  generateAccountFromPublicKey(publicKey: string): TBSAccount<N>;
92
92
  }
93
- export interface IBSWithWalletConnect {
94
- walletConnectService: IWalletConnectService;
93
+ export interface IBSWithWalletConnect<N extends string> {
94
+ walletConnectService: IWalletConnectService<N>;
95
95
  }
96
- export interface IBSWithFullTransactions {
97
- fullTransactionsDataService: IFullTransactionsDataService;
96
+ export interface IBSWithFullTransactions<N extends string> {
97
+ fullTransactionsDataService: IFullTransactionsDataService<N>;
98
98
  }
99
99
  export type TContractParameter = {
100
100
  name: string;
@@ -137,15 +137,15 @@ export type TTransactionTokenEvent = {
137
137
  type TTransactionDefault = {
138
138
  type: 'default';
139
139
  };
140
- export type TTransactionBridgeNeo3NeoX = {
140
+ export type TTransactionBridgeNeo3NeoX<N extends string> = {
141
141
  type: 'bridgeNeo3NeoX';
142
142
  data: {
143
143
  amount: string;
144
- token: TBridgeToken;
144
+ tokenToUse: TBridgeToken<N>;
145
145
  receiverAddress: string;
146
146
  };
147
147
  };
148
- export type TTransaction = {
148
+ export type TTransactionBase = {
149
149
  txId: string;
150
150
  txIdUrl?: string;
151
151
  block: number;
@@ -155,10 +155,11 @@ export type TTransaction = {
155
155
  networkFeeAmount?: string;
156
156
  systemFeeAmount?: string;
157
157
  events: (TTransactionTokenEvent | TTransactionNftEvent)[];
158
- } & (TTransactionDefault | TTransactionBridgeNeo3NeoX);
159
- export type TGetTransactionsByAddressResponse = {
158
+ };
159
+ export type TTransaction<N extends string> = TTransactionBase & (TTransactionDefault | TTransactionBridgeNeo3NeoX<N>);
160
+ export type TGetTransactionsByAddressResponse<N extends string> = {
160
161
  nextPageParams?: any;
161
- data: TTransaction[];
162
+ transactions: TTransaction<N>[];
162
163
  };
163
164
  export type TContractMethod = {
164
165
  name: string;
@@ -173,10 +174,10 @@ export type TBalanceResponse = {
173
174
  amount: string;
174
175
  token: TBSToken;
175
176
  };
176
- export interface IBlockchainDataService {
177
+ export interface IBlockchainDataService<N extends string> {
177
178
  readonly maxTimeToConfirmTransactionInMs: number;
178
- getTransaction(txid: string): Promise<TTransaction>;
179
- getTransactionsByAddress(params: TGetTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse>;
179
+ getTransaction(txid: string): Promise<TTransaction<N>>;
180
+ getTransactionsByAddress(params: TGetTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse<N>>;
180
181
  getContract(contractHash: string): Promise<TContractResponse>;
181
182
  getTokenInfo(tokenHash: string): Promise<TBSToken>;
182
183
  getBalance(address: string): Promise<TBalanceResponse[]>;
@@ -194,8 +195,8 @@ export type TExportFullTransactionsByAddressParams = {
194
195
  dateFrom: string;
195
196
  dateTo: string;
196
197
  };
197
- export interface IFullTransactionsDataService {
198
- getFullTransactionsByAddress(params: TGetFullTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse>;
198
+ export interface IFullTransactionsDataService<N extends string> {
199
+ getFullTransactionsByAddress(params: TGetFullTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse<N>>;
199
200
  exportFullTransactionsByAddress(params: TExportFullTransactionsByAddressParams): Promise<string>;
200
201
  }
201
202
  export interface IClaimDataService {
@@ -281,14 +282,14 @@ export type TLedgerServiceEmitter = TypedEmitter<{
281
282
  getSignatureStart(): void | Promise<void>;
282
283
  getSignatureEnd(): void | Promise<void>;
283
284
  }>;
284
- export type TGetLedgerTransport<N extends string = string> = (account: TBSAccount<N>) => Promise<Transport>;
285
- export interface ILedgerService<N extends string = string> {
285
+ export type TGetLedgerTransport<N extends string> = (account: TBSAccount<N>) => Promise<Transport>;
286
+ export interface ILedgerService<N extends string> {
286
287
  emitter: TLedgerServiceEmitter;
287
288
  getLedgerTransport?: TGetLedgerTransport<N>;
288
289
  getAccounts(transport: Transport, getUntilIndex?: TUntilIndexRecord<N>): Promise<TBSAccount<N>[]>;
289
290
  getAccount(transport: Transport, index: number): Promise<TBSAccount<N>>;
290
291
  }
291
- export type TSwapToken<N extends string = string> = {
292
+ export type TSwapToken<N extends string> = {
292
293
  id: string;
293
294
  blockchain?: N;
294
295
  imageUrl?: string;
@@ -312,7 +313,7 @@ export type TSwapMinMaxAmount = {
312
313
  min: string;
313
314
  max: string | null;
314
315
  };
315
- export type TSwapOrchestratorEvents<N extends string = string> = {
316
+ export type TSwapOrchestratorEvents<N extends string> = {
316
317
  accountToUse: (account: TSwapValidateValue<TBSAccount<N>>) => void | Promise<void>;
317
318
  amountToUse: (amount: TSwapLoadableValue<string>) => void | Promise<void>;
318
319
  amountToUseMinMax: (minMax: TSwapLoadableValue<TSwapMinMaxAmount>) => void | Promise<void>;
@@ -339,7 +340,7 @@ export type TSwapServiceStatusResponse = {
339
340
  export interface ISwapService {
340
341
  getStatus(id: string): Promise<TSwapServiceStatusResponse>;
341
342
  }
342
- export interface ISwapOrchestrator<N extends string = string> {
343
+ export interface ISwapOrchestrator<N extends string> {
343
344
  eventEmitter: TypedEmitter<TSwapOrchestratorEvents<N>>;
344
345
  setTokenToUse(token: TSwapToken<N> | null): Promise<void>;
345
346
  setAccountToUse(account: TBSAccount<N> | null): Promise<void>;
@@ -350,7 +351,7 @@ export interface ISwapOrchestrator<N extends string = string> {
350
351
  swap(): Promise<TSwapResult>;
351
352
  calculateFee(): Promise<string>;
352
353
  }
353
- export type TBridgeToken<N extends string = string> = TBSToken & {
354
+ export type TBridgeToken<N extends string> = TBSToken & {
354
355
  blockchain: N;
355
356
  multichainId: string;
356
357
  };
@@ -362,7 +363,7 @@ export type TBridgeValue<T> = {
362
363
  export type TBridgeValidateValue<T> = TBridgeValue<T> & {
363
364
  valid: boolean | null;
364
365
  };
365
- export type TBridgeOrchestratorEvents<N extends string = string> = {
366
+ export type TBridgeOrchestratorEvents<N extends string> = {
366
367
  accountToUse: (account: TBridgeValue<TBSAccount<N>>) => void | Promise<void>;
367
368
  amountToUse: (amount: TBridgeValidateValue<string>) => void | Promise<void>;
368
369
  amountToUseMin: (max: TBridgeValue<string>) => void | Promise<void>;
@@ -375,7 +376,7 @@ export type TBridgeOrchestratorEvents<N extends string = string> = {
375
376
  tokenToUseBalance: (balance: TBridgeValue<TBalanceResponse | undefined>) => void | Promise<void>;
376
377
  bridgeFee: (fee: TBridgeValue<string>) => void | Promise<void>;
377
378
  };
378
- export interface IBridgeOrchestrator<N extends string = string> {
379
+ export interface IBridgeOrchestrator<N extends string> {
379
380
  eventEmitter: TypedEmitter<TBridgeOrchestratorEvents<N>>;
380
381
  setTokenToUse(token: TBridgeToken<N> | null): Promise<void>;
381
382
  setAccountToUse(account: TBSAccount<N> | null): Promise<void>;
@@ -385,7 +386,7 @@ export interface IBridgeOrchestrator<N extends string = string> {
385
386
  switchTokens(): Promise<void>;
386
387
  bridge(): Promise<string>;
387
388
  }
388
- export interface IBSWithNeo3NeoXBridge<N extends string = string> {
389
+ export interface IBSWithNeo3NeoXBridge<N extends string> {
389
390
  neo3NeoXBridgeService: INeo3NeoXBridgeService<N>;
390
391
  }
391
392
  export type TNeo3NeoXBridgeServiceConstants = {
@@ -393,34 +394,35 @@ export type TNeo3NeoXBridgeServiceConstants = {
393
394
  bridgeMaxAmount: string;
394
395
  bridgeMinAmount: string;
395
396
  };
396
- export type TNeo3NeoXBridgeServiceBridgeParam<N extends string = string> = {
397
+ export type TNeo3NeoXBridgeServiceBridgeParam<N extends string> = {
397
398
  account: TBSAccount<N>;
398
399
  receiverAddress: string;
399
400
  amount: string;
400
401
  token: TBridgeToken<N>;
401
402
  bridgeFee: string;
402
403
  };
403
- export type TNeo3NeoXBridgeServiceGetApprovalParam<N extends string = string> = {
404
+ export type TNeo3NeoXBridgeServiceGetApprovalParam<N extends string> = {
404
405
  account: TBSAccount<N>;
405
406
  amount: string;
406
407
  token: TBridgeToken<N>;
407
408
  };
408
- export type TNeo3NeoXBridgeServiceGetNonceParams<N extends string = string> = {
409
+ export type TNeo3NeoXBridgeServiceGetNonceParams<N extends string> = {
409
410
  token: TBridgeToken<N>;
410
411
  transactionHash: string;
411
412
  };
412
- export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N extends string = string> = {
413
+ export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N extends string> = {
413
414
  token: TBridgeToken<N>;
414
415
  nonce: string;
415
416
  };
416
- export interface INeo3NeoXBridgeService<N extends string = string> {
417
+ export interface INeo3NeoXBridgeService<N extends string> {
417
418
  readonly gasToken: TBridgeToken<N>;
418
419
  readonly neoToken: TBridgeToken<N>;
419
- getApprovalFee(params: TNeo3NeoXBridgeServiceGetApprovalParam): Promise<string>;
420
- getBridgeConstants(token: TBridgeToken): Promise<TNeo3NeoXBridgeServiceConstants>;
420
+ getApprovalFee(params: TNeo3NeoXBridgeServiceGetApprovalParam<N>): Promise<string>;
421
+ getBridgeConstants(token: TBridgeToken<N>): Promise<TNeo3NeoXBridgeServiceConstants>;
421
422
  bridge(params: TNeo3NeoXBridgeServiceBridgeParam<N>): Promise<string>;
422
423
  getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<N>): Promise<string>;
423
424
  getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N>): Promise<string>;
425
+ getTokenByMultichainId(multichainId: string): TBridgeToken<N> | undefined;
424
426
  }
425
427
  export type TTokenServicePredicateParams = {
426
428
  hash: string;
@@ -439,19 +441,19 @@ export interface ITokenService {
439
441
  normalizeToken<T extends TBSToken | TBSToken[]>(token: T): T;
440
442
  normalizeHash(hash: string): string;
441
443
  }
442
- export type TWalletConnectServiceRequestMethodParams<N extends string = string> = {
444
+ export type TWalletConnectServiceRequestMethodParams<N extends string> = {
443
445
  account: TBSAccount<N>;
444
446
  params: any;
445
447
  };
446
- export type TWalletConnectServiceRequestMethod = (params: TWalletConnectServiceRequestMethodParams) => Promise<any>;
447
- export interface IWalletConnectService {
448
+ export type TWalletConnectServiceRequestMethod<N extends string> = (params: TWalletConnectServiceRequestMethodParams<N>) => Promise<any>;
449
+ export interface IWalletConnectService<N extends string> {
448
450
  readonly namespace: string;
449
451
  readonly chain: string;
450
452
  readonly supportedMethods: string[];
451
453
  readonly supportedEvents: string[];
452
454
  readonly calculableMethods: string[];
453
455
  readonly autoApproveMethods: string[];
454
- calculateRequestFee(args: TWalletConnectServiceRequestMethodParams): Promise<string>;
455
- [methodName: string]: any | TWalletConnectServiceRequestMethod;
456
+ calculateRequestFee(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
457
+ [methodName: string]: any | TWalletConnectServiceRequestMethod<N>;
456
458
  }
457
459
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.23.0",
3
+ "version": "3.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -33,10 +33,11 @@
33
33
  "typescript": "5.9.2"
34
34
  },
35
35
  "scripts": {
36
- "build": "rm -rf ./dist && tsc --project tsconfig.build.json",
36
+ "build": "rm -rf ./dist && npm run typecheck && tsc --project tsconfig.build.json",
37
37
  "test": "jest -i --config jest.config.ts",
38
38
  "lint": "eslint .",
39
39
  "format": "eslint --fix",
40
- "package": "npm run build && npm pack"
40
+ "package": "npm run build && npm pack",
41
+ "typecheck": "tsc --noEmit"
41
42
  }
42
43
  }