@cityofzion/blockchain-service 3.1.3 → 3.1.4

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,24 +1,25 @@
1
- import type { TBSAccount, IBlockchainService, IBSWithClaim, IBSWithEncryption, IBSWithExplorer, IBSWithFee, IBSWithLedger, IBSWithNameService, IBSWithNeo3NeoXBridge, IBSWithNft, TUntilIndexRecord, IBSWithWalletConnect, IBSWithFullTransactions } from './interfaces';
2
- export declare function hasNameService<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNameService;
3
- export declare function isClaimable<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithClaim<N>;
4
- export declare function isCalculableFee<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFee<N>;
5
- export declare function hasNft<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNft;
6
- export declare function hasExplorerService<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithExplorer;
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
- export declare function hasNeo3NeoXBridge<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNeo3NeoXBridge<N>;
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<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>;
1
+ import type { TBSAccount, IBlockchainService, IBSWithClaim, IBSWithEncryption, IBSWithExplorer, IBSWithFee, IBSWithLedger, IBSWithNameService, IBSWithNeo3NeoXBridge, IBSWithNft, TUntilIndexRecord, IBSWithWalletConnect, IBSWithFullTransactions, TBSNetworkId, IBSWithFaucet, TBSBridgeName } from './interfaces';
2
+ export declare function hasNameService<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNameService;
3
+ export declare function isClaimable<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithClaim<N>;
4
+ export declare function isCalculableFee<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFee<N>;
5
+ export declare function hasNft<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithNft;
6
+ export declare function hasExplorerService<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithExplorer;
7
+ export declare function hasLedger<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithLedger<N>;
8
+ export declare function hasNeo3NeoXBridge<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is N extends TBSBridgeName ? IBlockchainService<N, A> & IBSWithNeo3NeoXBridge<N> : never;
9
+ export declare function hasEncryption<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithEncryption<N>;
10
+ export declare function hasWalletConnect<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithWalletConnect<N>;
11
+ export declare function hasFullTransactions<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFullTransactions;
12
+ export declare function hasFaucet<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>): service is IBlockchainService<N, A> & IBSWithFaucet;
12
13
  /**
13
14
  * @deprecated use `waitForAccountTransaction` instead
14
15
  */
15
- export declare function waitForTransaction<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>, txId: string): Promise<boolean>;
16
- export declare function waitForAccountTransaction<N extends string = string, A extends string = string>(params: {
16
+ export declare function waitForTransaction<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>, txId: string): Promise<boolean>;
17
+ export declare function waitForAccountTransaction<N extends string, A extends TBSNetworkId>(params: {
17
18
  service: IBlockchainService<N, A>;
18
19
  txId: string;
19
20
  address: string;
20
21
  maxAttempts?: number;
21
22
  }): Promise<boolean>;
22
- export declare function fetchAccounts<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>, initialIndex: number, getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>): Promise<TBSAccount<N>[]>;
23
- export declare function generateAccount<N extends string = string, A extends string = string>(service: IBlockchainService<N, A>, initialIndex: number, untilIndex: number, getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>): Promise<TBSAccount<N>[]>;
24
- export declare function generateAccountForBlockchainService<N extends string = string, A extends string = string>(services: IBlockchainService<N, A>[], getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>, untilIndexByBlockchainService?: TUntilIndexRecord<N>): Promise<Map<N, TBSAccount<N>[]>>;
23
+ export declare function fetchAccounts<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>, initialIndex: number, getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>): Promise<TBSAccount<N>[]>;
24
+ export declare function generateAccount<N extends string, A extends TBSNetworkId>(service: IBlockchainService<N, A>, initialIndex: number, untilIndex: number, getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>): Promise<TBSAccount<N>[]>;
25
+ export declare function generateAccountForBlockchainService<N extends string, A extends TBSNetworkId>(services: IBlockchainService<N, A>[], getAccountCallback: (service: IBlockchainService<N, A>, index: number) => Promise<TBSAccount<N>>, untilIndexByBlockchainService?: TUntilIndexRecord<N>): Promise<Map<N, TBSAccount<N>[]>>;
package/dist/functions.js CHANGED
@@ -10,6 +10,7 @@ exports.hasNeo3NeoXBridge = hasNeo3NeoXBridge;
10
10
  exports.hasEncryption = hasEncryption;
11
11
  exports.hasWalletConnect = hasWalletConnect;
12
12
  exports.hasFullTransactions = hasFullTransactions;
13
+ exports.hasFaucet = hasFaucet;
13
14
  exports.waitForTransaction = waitForTransaction;
14
15
  exports.waitForAccountTransaction = waitForAccountTransaction;
15
16
  exports.fetchAccounts = fetchAccounts;
@@ -20,11 +21,7 @@ function hasNameService(service) {
20
21
  return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
21
22
  }
22
23
  function isClaimable(service) {
23
- return ('claimToken' in service &&
24
- 'burnToken' in service &&
25
- 'claimDataService' in service &&
26
- 'calculateClaimFee' in service &&
27
- 'claim' in service);
24
+ return 'claimService' in service;
28
25
  }
29
26
  function isCalculableFee(service) {
30
27
  return 'calculateTransferFee' in service;
@@ -50,6 +47,9 @@ function hasWalletConnect(service) {
50
47
  function hasFullTransactions(service) {
51
48
  return 'fullTransactionsDataService' in service;
52
49
  }
50
+ function hasFaucet(service) {
51
+ return 'faucet' in service;
52
+ }
53
53
  /**
54
54
  * @deprecated use `waitForAccountTransaction` instead
55
55
  */
@@ -1,9 +1,9 @@
1
- import type { TBSNetwork } from '../interfaces';
1
+ import type { TBSNetwork, TBSNetworkId } from '../interfaces';
2
2
  import { TBSUtilsHelperRetryOptions } from '../types';
3
3
  export declare class BSUtilsHelper {
4
4
  static wait(ms: number): Promise<unknown>;
5
5
  static retry<T = any>(callback: () => Promise<T>, options?: TBSUtilsHelperRetryOptions): Promise<T>;
6
- static validateNetwork(network: TBSNetwork, availableNetworks: TBSNetwork[], networkUrls: string[]): boolean;
6
+ static validateNetwork<A extends TBSNetworkId>(network: TBSNetwork<A>, availableNetworks: TBSNetwork<A>[], networkUrls: string[]): boolean;
7
7
  static tryCatch<T>(callback: () => T): T extends Promise<infer R> ? Promise<[R, undefined] | [undefined, any]> : [T, undefined] | [undefined, any];
8
8
  static isBase64(str: string): boolean;
9
9
  }
@@ -1,6 +1,6 @@
1
1
  import Transport from '@ledgerhq/hw-transport';
2
2
  import TypedEmitter from 'typed-emitter';
3
- import { BSError } from './error';
3
+ import type { BSError } from './error';
4
4
  export type TUntilIndexRecord<N extends string> = Partial<Record<N, Record<string, number>>>;
5
5
  export type TBSAccount<N extends string> = {
6
6
  key: string;
@@ -43,6 +43,7 @@ export interface IBlockchainService<N extends string, A extends string = string>
43
43
  readonly bipDerivationPath: string;
44
44
  readonly feeToken: TBSToken;
45
45
  readonly isMultiTransferSupported: boolean;
46
+ readonly amountToCreateAccount?: string;
46
47
  tokens: TBSToken[];
47
48
  readonly nativeTokens: TBSToken[];
48
49
  networkUrls: string[];
@@ -51,7 +52,7 @@ export interface IBlockchainService<N extends string, A extends string = string>
51
52
  readonly availableNetworks: TBSNetwork<A>[];
52
53
  readonly isCustomNetworkSupported: boolean;
53
54
  exchangeDataService: IExchangeDataService;
54
- blockchainDataService: IBlockchainDataService<N>;
55
+ blockchainDataService: IBlockchainDataService;
55
56
  tokenService: ITokenService;
56
57
  setNetwork(network: TBSNetwork<A>): void;
57
58
  pingNetwork(url?: string): Promise<TPingNetworkResponse>;
@@ -59,7 +60,7 @@ export interface IBlockchainService<N extends string, A extends string = string>
59
60
  generateAccountFromKey(key: string): Promise<TBSAccount<N>>;
60
61
  validateAddress(address: string): boolean;
61
62
  validateKey(key: string): boolean;
62
- transfer(params: TTransferParams<N>): Promise<TTransaction<N>[]>;
63
+ transfer(params: TTransferParams<N>): Promise<TTransaction[]>;
63
64
  }
64
65
  export interface IBSWithEncryption<N extends string> {
65
66
  decrypt(keyOrJson: string, password: string): Promise<TBSAccount<N>>;
@@ -70,11 +71,7 @@ export interface IBSWithFee<N extends string> {
70
71
  calculateTransferFee(params: TTransferParams<N>): Promise<string>;
71
72
  }
72
73
  export interface IBSWithClaim<N extends string> {
73
- readonly claimToken: TBSToken;
74
- readonly burnToken: TBSToken;
75
- claimDataService: IClaimDataService;
76
- calculateClaimFee(account: TBSAccount<N>): Promise<string>;
77
- claim(account: TBSAccount<N>): Promise<TTransaction<N>>;
74
+ claimService: IClaimService<N>;
78
75
  }
79
76
  export interface IBSWithNameService {
80
77
  resolveNameServiceDomain(domainName: string): Promise<string>;
@@ -93,8 +90,11 @@ export interface IBSWithLedger<N extends string> {
93
90
  export interface IBSWithWalletConnect<N extends string> {
94
91
  walletConnectService: IWalletConnectService<N>;
95
92
  }
96
- export interface IBSWithFullTransactions<N extends string> {
97
- fullTransactionsDataService: IFullTransactionsDataService<N>;
93
+ export interface IBSWithFullTransactions {
94
+ fullTransactionsDataService: IFullTransactionsDataService;
95
+ }
96
+ export interface IBSWithFaucet {
97
+ faucet(address: string): Promise<TTransaction>;
98
98
  }
99
99
  export type TContractParameter = {
100
100
  name: string;
@@ -104,54 +104,34 @@ export type TGetTransactionsByAddressParams = {
104
104
  address: string;
105
105
  nextPageParams?: any;
106
106
  };
107
- type TTransactionEventTokenType = 'generic' | (string & NonNullable<unknown>);
108
- export type TTransactionNftEvent = {
109
- eventType: 'nft';
107
+ export type TTransactionBaseEvent = {
110
108
  methodName?: string;
111
- amount?: string;
112
109
  from?: string;
113
110
  fromUrl?: string;
114
111
  to?: string;
115
112
  toUrl?: string;
116
- tokenType: TTransactionEventTokenType;
113
+ amount?: string;
114
+ };
115
+ export type TTransactionDefaultNftEvent = TTransactionBaseEvent & {
116
+ eventType: 'nft';
117
117
  nft?: TNftResponse;
118
118
  };
119
- export type TTransactionTokenEvent = {
119
+ export type TTransactionDefaultTokenEvent = TTransactionBaseEvent & {
120
120
  eventType: 'token';
121
- methodName?: string;
122
- amount?: string;
123
- from?: string;
124
- fromUrl?: string;
125
- to?: string;
126
- toUrl?: string;
127
- tokenType: TTransactionEventTokenType;
128
121
  tokenUrl?: string;
129
122
  token?: TBSToken;
130
123
  };
131
- export type TTransactionDefaultType = {
132
- type: 'default';
133
- };
134
- export type TTransactionVoteType = {
135
- type: 'vote';
124
+ export type TTransactionDefaultGenericEvent = TTransactionBaseEvent & {
125
+ eventType: 'generic';
126
+ data?: Record<string, string | number | boolean | undefined | null>;
136
127
  };
137
- export type TTransactionClaimType = {
138
- type: 'claim';
139
- };
140
- export type TTransactionBridgeNeo3NeoXType<N extends string> = {
141
- type: 'bridgeNeo3NeoX';
142
- data: {
143
- amount: string;
144
- tokenToUse: TBridgeToken<N>;
145
- receiverAddress: string;
146
- };
147
- };
148
- export type TTransactionInputOutput = {
128
+ export type TTransactionUtxoInputOutput = {
149
129
  address?: string;
150
130
  addressUrl?: string;
151
131
  amount: string;
152
132
  token: TBSToken;
153
133
  };
154
- type TTransactionBase<N extends string> = {
134
+ type TTransactionBase = {
155
135
  txId: string;
156
136
  txIdUrl?: string;
157
137
  block?: number;
@@ -160,21 +140,23 @@ type TTransactionBase<N extends string> = {
160
140
  notificationCount?: number;
161
141
  networkFeeAmount?: string;
162
142
  systemFeeAmount?: string;
163
- } & (TTransactionDefaultType | TTransactionVoteType | TTransactionClaimType | TTransactionBridgeNeo3NeoXType<N>);
164
- export type TTransactionDefault<N extends string> = TTransactionBase<N> & {
143
+ data?: any;
144
+ };
145
+ export type TTransactionDefaultEvent = TTransactionDefaultNftEvent | TTransactionDefaultTokenEvent | TTransactionDefaultGenericEvent;
146
+ export type TTransactionDefault = TTransactionBase & {
165
147
  view: 'default';
166
- events: (TTransactionTokenEvent | TTransactionNftEvent)[];
148
+ events: TTransactionDefaultEvent[];
167
149
  };
168
- export type TTransactionUtxo<N extends string> = TTransactionBase<N> & {
150
+ export type TTransactionUtxo = TTransactionBase & {
169
151
  view: 'utxo';
170
152
  hex: string;
171
153
  totalAmount: string;
172
154
  nfts: TNftResponse[];
173
- inputs: TTransactionInputOutput[];
174
- outputs: TTransactionInputOutput[];
155
+ inputs: TTransactionUtxoInputOutput[];
156
+ outputs: TTransactionUtxoInputOutput[];
175
157
  };
176
- export type TTransaction<N extends string> = TTransactionDefault<N> | TTransactionUtxo<N>;
177
- export type TGetTransactionsByAddressResponse<N extends string, T extends TTransaction<N> = TTransaction<N>> = {
158
+ export type TTransaction = TTransactionDefault | TTransactionUtxo;
159
+ export type TGetTransactionsByAddressResponse<T extends TTransaction = TTransaction> = {
178
160
  nextPageParams?: any;
179
161
  transactions: T[];
180
162
  };
@@ -191,10 +173,10 @@ export type TBalanceResponse = {
191
173
  amount: string;
192
174
  token: TBSToken;
193
175
  };
194
- export interface IBlockchainDataService<N extends string> {
176
+ export interface IBlockchainDataService {
195
177
  readonly maxTimeToConfirmTransactionInMs: number;
196
- getTransaction(transactionId: string): Promise<TTransaction<N>>;
197
- getTransactionsByAddress(params: TGetTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse<N>>;
178
+ getTransaction(transactionId: string): Promise<TTransaction>;
179
+ getTransactionsByAddress(params: TGetTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse>;
198
180
  getContract(contractHash: string): Promise<TContractResponse>;
199
181
  getTokenInfo(tokenHash: string): Promise<TBSToken>;
200
182
  getBalance(address: string): Promise<TBalanceResponse[]>;
@@ -212,12 +194,19 @@ export type TExportFullTransactionsByAddressParams = {
212
194
  dateFrom: string;
213
195
  dateTo: string;
214
196
  };
215
- export interface IFullTransactionsDataService<N extends string> {
216
- getFullTransactionsByAddress(params: TGetFullTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse<N>>;
197
+ export interface IFullTransactionsDataService {
198
+ getFullTransactionsByAddress(params: TGetFullTransactionsByAddressParams): Promise<TGetTransactionsByAddressResponse>;
217
199
  exportFullTransactionsByAddress(params: TExportFullTransactionsByAddressParams): Promise<string>;
218
200
  }
219
- export interface IClaimDataService {
201
+ export type TClaimServiceTransactionData = {
202
+ isClaim: boolean;
203
+ };
204
+ export interface IClaimService<N extends string> {
205
+ readonly claimToken: TBSToken;
220
206
  getUnclaimed(address: string): Promise<string>;
207
+ calculateFee(account: TBSAccount<N>): Promise<string>;
208
+ claim(account: TBSAccount<N>): Promise<TTransactionDefault>;
209
+ getTransactionData(transaction: TTransaction): TClaimServiceTransactionData | undefined;
221
210
  }
222
211
  export type TTokenPricesResponse = {
223
212
  usdPrice: number;
@@ -342,9 +331,9 @@ export type TSwapOrchestratorEvents<N extends string> = {
342
331
  availableTokensToReceive: (tokens: TSwapLoadableValue<TSwapToken<N>[]>) => void | Promise<void>;
343
332
  error: (error: string) => void | Promise<void>;
344
333
  };
345
- export type TSwapResponse<N extends string> = {
334
+ export type TSwapResponse = {
346
335
  id: string;
347
- transaction?: TTransaction<N>;
336
+ transaction?: TTransaction;
348
337
  log?: string;
349
338
  };
350
339
  export type TSwapServiceStatusResponse = {
@@ -364,10 +353,11 @@ export interface ISwapOrchestrator<N extends string> {
364
353
  setTokenToReceive(token: TSwapToken<N> | null): Promise<void>;
365
354
  setAddressToReceive(address: string | null): Promise<void>;
366
355
  setExtraIdToReceive(extraId: string | null): Promise<void>;
367
- swap(): Promise<TSwapResponse<N>>;
356
+ swap(): Promise<TSwapResponse>;
368
357
  calculateFee(): Promise<string>;
369
358
  }
370
- export type TBridgeToken<N extends string> = TBSToken & {
359
+ export type TBSBridgeName = 'neo3' | 'neox';
360
+ export type TBridgeToken<N extends TBSBridgeName> = TBSToken & {
371
361
  blockchain: N;
372
362
  multichainId: string;
373
363
  };
@@ -379,7 +369,7 @@ export type TBridgeValue<T> = {
379
369
  export type TBridgeValidateValue<T> = TBridgeValue<T> & {
380
370
  valid: boolean | null;
381
371
  };
382
- export type TBridgeOrchestratorEvents<N extends string> = {
372
+ export type TBridgeOrchestratorEvents<N extends TBSBridgeName> = {
383
373
  accountToUse: (account: TBridgeValue<TBSAccount<N>>) => void | Promise<void>;
384
374
  amountToUse: (amount: TBridgeValidateValue<string>) => void | Promise<void>;
385
375
  amountToUseMin: (max: TBridgeValue<string>) => void | Promise<void>;
@@ -392,7 +382,7 @@ export type TBridgeOrchestratorEvents<N extends string> = {
392
382
  tokenToUseBalance: (balance: TBridgeValue<TBalanceResponse | undefined>) => void | Promise<void>;
393
383
  bridgeFee: (fee: TBridgeValue<string>) => void | Promise<void>;
394
384
  };
395
- export interface IBridgeOrchestrator<N extends string> {
385
+ export interface IBridgeOrchestrator<N extends TBSBridgeName> {
396
386
  eventEmitter: TypedEmitter<TBridgeOrchestratorEvents<N>>;
397
387
  setTokenToUse(token: TBridgeToken<N> | null): Promise<void>;
398
388
  setAccountToUse(account: TBSAccount<N> | null): Promise<void>;
@@ -402,7 +392,7 @@ export interface IBridgeOrchestrator<N extends string> {
402
392
  switchTokens(): Promise<void>;
403
393
  bridge(): Promise<string>;
404
394
  }
405
- export interface IBSWithNeo3NeoXBridge<N extends string> {
395
+ export interface IBSWithNeo3NeoXBridge<N extends TBSBridgeName> {
406
396
  neo3NeoXBridgeService: INeo3NeoXBridgeService<N>;
407
397
  }
408
398
  export type TNeo3NeoXBridgeServiceConstants = {
@@ -410,27 +400,34 @@ export type TNeo3NeoXBridgeServiceConstants = {
410
400
  bridgeMaxAmount: string;
411
401
  bridgeMinAmount: string;
412
402
  };
413
- export type TNeo3NeoXBridgeServiceBridgeParam<N extends string> = {
403
+ export type TNeo3NeoXBridgeServiceBridgeParam<N extends TBSBridgeName> = {
414
404
  account: TBSAccount<N>;
415
405
  receiverAddress: string;
416
406
  amount: string;
417
407
  token: TBridgeToken<N>;
418
408
  bridgeFee: string;
419
409
  };
420
- export type TNeo3NeoXBridgeServiceGetApprovalParam<N extends string> = {
410
+ export type TNeo3NeoXBridgeServiceGetApprovalParam<N extends TBSBridgeName> = {
421
411
  account: TBSAccount<N>;
422
412
  amount: string;
423
413
  token: TBridgeToken<N>;
424
414
  };
425
- export type TNeo3NeoXBridgeServiceGetNonceParams<N extends string> = {
415
+ export type TNeo3NeoXBridgeServiceGetNonceParams<N extends TBSBridgeName> = {
426
416
  token: TBridgeToken<N>;
427
417
  transactionHash: string;
428
418
  };
429
- export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N extends string> = {
419
+ export type TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N extends TBSBridgeName> = {
430
420
  token: TBridgeToken<N>;
431
421
  nonce: string;
432
422
  };
433
- export interface INeo3NeoXBridgeService<N extends string> {
423
+ export type TNeo3NeoXBridgeTransactionData<N extends TBSBridgeName> = {
424
+ neo3NeoxBridge: {
425
+ tokenToUse: TBridgeToken<N>;
426
+ receiverAddress: string;
427
+ amount: string;
428
+ };
429
+ };
430
+ export interface INeo3NeoXBridgeService<N extends TBSBridgeName> {
434
431
  readonly gasToken: TBridgeToken<N>;
435
432
  readonly neoToken: TBridgeToken<N>;
436
433
  getApprovalFee(params: TNeo3NeoXBridgeServiceGetApprovalParam<N>): Promise<string>;
@@ -439,6 +436,7 @@ export interface INeo3NeoXBridgeService<N extends string> {
439
436
  getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<N>): Promise<string>;
440
437
  getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<N>): Promise<string>;
441
438
  getTokenByMultichainId(multichainId: string): TBridgeToken<N> | undefined;
439
+ getTransactionData(transaction: TTransaction): TNeo3NeoXBridgeTransactionData<N> | undefined;
442
440
  }
443
441
  export type TTokenServicePredicateParams = {
444
442
  hash: string;
@@ -456,6 +454,8 @@ export interface ITokenService {
456
454
  predicateBySymbol(compareFrom: TTokenServicePredicateBySymbolParams, compareTo: TTokenServicePredicateBySymbolParams): boolean;
457
455
  normalizeToken<T extends TBSToken | TBSToken[]>(token: T): T;
458
456
  normalizeHash(hash: string): string;
457
+ validateTokenHash(hash?: string): hash is string;
458
+ isNativeToken(hash: string): boolean;
459
459
  }
460
460
  export type TWalletConnectServiceRequestMethodParams<N extends string> = {
461
461
  account: TBSAccount<N>;
@@ -1,8 +1,8 @@
1
- import type { TGetTokenPricesParams, IBlockchainService, IExchangeDataService, TTokenPricesResponse } from '../../interfaces';
1
+ import type { TGetTokenPricesParams, IBlockchainService, IExchangeDataService, TTokenPricesResponse, TBSNetworkId } from '../../interfaces';
2
2
  import { CryptoCompareEDS } from './CryptoCompareEDS';
3
- export declare class FlamingoForthewinEDS<N extends string> extends CryptoCompareEDS implements IExchangeDataService {
3
+ export declare class FlamingoForthewinEDS<N extends string, A extends TBSNetworkId> extends CryptoCompareEDS implements IExchangeDataService {
4
4
  #private;
5
- readonly _service: IBlockchainService<N>;
6
- constructor(service: IBlockchainService<N>);
5
+ readonly _service: IBlockchainService<N, A>;
6
+ constructor(service: IBlockchainService<N, A>);
7
7
  getTokenPrices({ tokens }: TGetTokenPricesParams): Promise<TTokenPricesResponse[]>;
8
8
  }
@@ -1,5 +1,5 @@
1
- import type { IBlockchainService, INftDataService, TGetNftParams, TGetNftsByAddressParams, THasTokenParams, TNftResponse, TNftsResponse } from '../../interfaces';
2
- export declare abstract class GhostMarketNDS<N extends string, A extends string, S extends IBlockchainService<N, A>> implements INftDataService {
1
+ import type { IBlockchainService, INftDataService, TBSNetworkId, TGetNftParams, TGetNftsByAddressParams, THasTokenParams, TNftResponse, TNftsResponse } from '../../interfaces';
2
+ export declare abstract class GhostMarketNDS<N extends string, A extends TBSNetworkId, S extends IBlockchainService<N, A>> implements INftDataService {
3
3
  #private;
4
4
  static readonly BASE_URL: string;
5
5
  _service: S;
@@ -1,8 +1,12 @@
1
- import type { ITokenService, TBSToken, TTokenServicePredicateByHashParams, TTokenServicePredicateBySymbolParams, TTokenServicePredicateParams } from '../../interfaces';
2
- export declare abstract class TokenService implements ITokenService {
1
+ import type { IBlockchainService, ITokenService, TBSNetworkId, TBSToken, TTokenServicePredicateByHashParams, TTokenServicePredicateBySymbolParams, TTokenServicePredicateParams } from '../../interfaces';
2
+ export declare abstract class TokenService<N extends string, A extends TBSNetworkId> implements ITokenService {
3
+ protected _service: IBlockchainService<N, A>;
4
+ constructor(service: IBlockchainService<N, A>);
3
5
  predicate(compareFrom: TTokenServicePredicateParams, compareTo: TTokenServicePredicateParams): boolean;
4
6
  predicateByHash(compareFrom: TTokenServicePredicateByHashParams, compareTo: TTokenServicePredicateByHashParams): boolean;
5
7
  predicateBySymbol(compareFrom: TTokenServicePredicateBySymbolParams, compareTo: TTokenServicePredicateBySymbolParams): boolean;
6
8
  normalizeToken<T extends TBSToken | TBSToken[]>(token: T): T;
9
+ validateTokenHash(hash?: string): hash is string;
10
+ isNativeToken(hash: string): boolean;
7
11
  abstract normalizeHash(hash: string): string;
8
12
  }
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenService = void 0;
4
4
  class TokenService {
5
+ constructor(service) {
6
+ this._service = service;
7
+ }
5
8
  predicate(compareFrom, compareTo) {
6
9
  if (this.normalizeHash(compareFrom.hash) === this.normalizeHash(compareTo.hash))
7
10
  return true;
@@ -32,5 +35,14 @@ class TokenService {
32
35
  hash: this.normalizeHash(token.hash),
33
36
  };
34
37
  }
38
+ validateTokenHash(hash) {
39
+ hash = hash?.trim();
40
+ if (!hash)
41
+ return false;
42
+ return !this.isNativeToken(hash);
43
+ }
44
+ isNativeToken(hash) {
45
+ return this._service.nativeTokens.some(token => this.predicateByHash(hash, token));
46
+ }
35
47
  }
36
48
  exports.TokenService = TokenService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "repository": "https://github.com/CityOfZion/blockchain-services",
5
5
  "license": "GPL-3.0-only",
6
6
  "author": "Coz",
@@ -30,7 +30,7 @@
30
30
  "vitest": "~4.0.18"
31
31
  },
32
32
  "scripts": {
33
- "build": "rm -rf ./dist && npm run typecheck && tsc --project tsconfig.build.json",
33
+ "build": "rm -rf ./dist && rm -f *.tgz && npm run typecheck && tsc --project tsconfig.build.json",
34
34
  "format": "eslint --fix",
35
35
  "lint": "eslint .",
36
36
  "package": "npm run build && npm pack",