-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathxdcToken.ts
More file actions
94 lines (84 loc) · 2.87 KB
/
Copy pathxdcToken.ts
File metadata and controls
94 lines (84 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @prettier
*/
import { EthLikeTokenConfig, coins } from '@bitgo/statics';
import {
BitGoBase,
CoinConstructor,
NamedCoinConstructor,
common,
MPCAlgorithm,
NO_RECIPIENT_TX_TYPES,
} from '@bitgo/sdk-core';
import {
CoinNames,
EthLikeToken,
recoveryBlockchainExplorerQuery,
VerifyEthTransactionOptions,
} from '@bitgo/abstract-eth';
import { TransactionBuilder } from './lib';
export { EthLikeTokenConfig };
export class XdcToken extends EthLikeToken {
public readonly tokenConfig: EthLikeTokenConfig;
static coinNames: CoinNames = {
Mainnet: 'xdc',
Testnet: 'txdc',
};
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
super(bitgo, tokenConfig, XdcToken.coinNames);
}
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
return super.createTokenConstructor(config, XdcToken.coinNames);
}
static createTokenConstructors(): NamedCoinConstructor[] {
return super.createTokenConstructors(XdcToken.coinNames);
}
protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}
/**
* Make a query to XDC Etherscan for information such as balance, token balance, solidity calls
* @param {Object} query key-value pairs of parameters to append after /api
* @returns {Promise<Object>} response from XDC Etherscan
*/
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
const apiToken = common.Environments[this.bitgo.getEnv()].xdcExplorerApiToken;
const explorerUrl = common.Environments[this.bitgo.getEnv()].xdcExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
}
getFullName(): string {
return 'XDC Token';
}
supportsTss(): boolean {
return true;
}
/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
/**
* Verify if a tss transaction is valid
*
* @param {VerifyEthTransactionOptions} params
* @param {TransactionParams} params.txParams - params object passed to send
* @param {TransactionPrebuild} params.txPrebuild - prebuild object returned by server
* @param {Wallet} params.wallet - Wallet object to obtain keys to verify against
* @returns {boolean}
*/
async verifyTssTransaction(params: VerifyEthTransactionOptions): Promise<boolean> {
const { txParams, txPrebuild, wallet } = params;
if (
!txParams?.recipients &&
!(txParams.prebuildTx?.consolidateId || (txParams.type && NO_RECIPIENT_TX_TYPES.has(txParams.type)))
) {
throw new Error(`missing txParams`);
}
if (!wallet || !txPrebuild) {
throw new Error(`missing params`);
}
if (txParams.hop && txParams.recipients && txParams.recipients.length > 1) {
throw new Error(`tx cannot be both a batch and hop transaction`);
}
return true;
}
}