-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathdot.ts
More file actions
678 lines (601 loc) · 22.8 KB
/
dot.ts
File metadata and controls
678 lines (601 loc) · 22.8 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
import * as _ from 'lodash';
import {
BaseCoin,
BitGoBase,
DotAssetTypes,
Eddsa,
Environments,
ExplanationResult,
KeyPair,
MPCAlgorithm,
ParsedTransaction,
ParseTransactionOptions,
SignedTransaction,
SignTransactionOptions as BaseSignTransactionOptions,
UnsignedTransaction,
VerifyTransactionOptions,
TssVerifyAddressOptions,
EDDSAMethods,
EDDSAMethodTypes,
MPCTx,
MPCRecoveryOptions,
MPCConsolidationRecoveryOptions,
MPCSweepTxs,
RecoveryTxRequest,
MPCUnsignedTx,
MPCSweepRecoveryOptions,
MPCTxs,
MultisigType,
multisigTypes,
AuditDecryptedKeyParams,
verifyEddsaTssWalletAddress,
} from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins, PolkadotSpecNameType } from '@bitgo/statics';
import { Interface, KeyPair as DotKeyPair, Transaction, TransactionBuilderFactory, Utils } from './lib';
import '@polkadot/api-augment';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Material } from './lib/iface';
import BigNumber from 'bignumber.js';
import { auditEddsaPrivateKey, getDerivationPath } from '@bitgo/sdk-lib-mpc';
export const DEFAULT_SCAN_FACTOR = 20; // default number of receive addresses to scan for funds
export interface SignTransactionOptions extends BaseSignTransactionOptions {
txPrebuild: TransactionPrebuild;
prv: string;
}
export interface TransactionPrebuild {
txHex: string;
transaction: Interface.TxData;
}
export interface ExplainTransactionOptions {
txPrebuild: TransactionPrebuild;
publicKey: string;
feeInfo: {
fee: string;
};
}
export interface VerifiedTransactionParameters {
txHex: string;
prv: string;
}
const dotUtils = Utils.default;
export class Dot extends BaseCoin {
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
readonly MAX_VALIDITY_DURATION = 2400;
readonly SWEEP_TXN_DURATION = 64;
constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo);
if (!staticsCoin) {
throw new Error('missing required constructor parameter staticsCoin');
}
this._staticsCoin = staticsCoin;
}
protected static initialized = false;
protected static MPC: Eddsa;
protected static nodeApiInitialized = false;
protected static API: ApiPromise;
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Dot(bitgo, staticsCoin);
}
getChain(): string {
return 'dot';
}
getBaseChain(): string {
return 'dot';
}
getFamily(): string {
return 'dot';
}
getFullName(): string {
return 'Polkadot';
}
getBaseFactor(): number {
return Math.pow(10, this._staticsCoin.decimalPlaces);
}
/**
* Flag for sending value of 0
* @returns {boolean} True if okay to send 0 value, false otherwise
*/
valuelessTransferAllowed(): boolean {
return true;
}
/** @inheritDoc */
supportsTss(): boolean {
return true;
}
/** inherited doc */
getDefaultMultisigType(): MultisigType {
return multisigTypes.tss;
}
getMPCAlgorithm(): MPCAlgorithm {
return 'eddsa';
}
allowsAccountConsolidations(): boolean {
return true;
}
/**
* Generate ed25519 key pair
*
* @param seed
* @returns {Object} object with generated pub, prv
*/
generateKeyPair(seed?: Buffer): KeyPair {
const keyPair = seed ? dotUtils.keyPairFromSeed(new Uint8Array(seed)) : new DotKeyPair();
const keys = keyPair.getKeys();
if (!keys.prv) {
throw new Error('Missing prv in key generation.');
}
return {
pub: keys.pub,
prv: keys.prv,
};
}
/**
* Return boolean indicating whether input is valid public key for the coin.
*
* @param {String} pub the pub to be checked
* @returns {Boolean} is it valid?
*/
isValidPub(pub: string): boolean {
return dotUtils.isValidPublicKey(pub);
}
/**
* Return boolean indicating whether the supplied private key is a valid dot private key
*
* @param {String} prv the prv to be checked
* @returns {Boolean} is it valid?
*/
isValidPrv(prv: string): boolean {
return dotUtils.isValidPrivateKey(prv);
}
/**
* Return boolean indicating whether input is valid public key for the coin
*
* @param {String} address the pub to be checked
* @returns {Boolean} is it valid?
*/
isValidAddress(address: string): boolean {
return dotUtils.isValidAddress(address);
}
/**
* Sign message with private key
*
* @param key
* @param message
* @return {Buffer} A signature over the given message using the given key
*/
async signMessage(key: KeyPair, message: string | Buffer): Promise<Buffer> {
const msg = Buffer.isBuffer(message) ? message.toString('utf8') : message;
// reconstitute keys and sign
return Buffer.from(new DotKeyPair({ prv: key.prv }).signMessage(msg));
}
/**
* Explain/parse transaction
* @param unsignedTransaction
*/
async explainTransaction(unsignedTransaction: UnsignedTransaction): Promise<ExplanationResult> {
let outputAmount = 0;
unsignedTransaction.parsedTx.outputs.forEach((o) => {
outputAmount += parseInt(o.valueString, 10);
});
const explanationResult: ExplanationResult = {
displayOrder: [
'outputAmount',
'changeAmount',
'outputs',
'changeOutputs',
'fee',
'type',
'sequenceId',
'id',
'blockNumber',
],
sequenceId: unsignedTransaction.parsedTx.sequenceId,
fee: unsignedTransaction.feeInfo?.feeString,
id: unsignedTransaction.parsedTx.id,
type: unsignedTransaction.parsedTx.type,
outputs: unsignedTransaction.parsedTx.outputs,
blockNumber: unsignedTransaction.coinSpecific?.blockNumber,
outputAmount: outputAmount,
changeOutputs: [],
changeAmount: '0',
};
return explanationResult;
}
verifySignTransactionParams(params: SignTransactionOptions): VerifiedTransactionParameters {
const prv = params.prv;
const txHex = params.txPrebuild.txHex;
if (!txHex) {
throw new Error('missing txPrebuild parameter');
}
if (!_.isString(txHex)) {
throw new Error(`txPrebuild must be an object, got type ${typeof txHex}`);
}
if (!prv) {
throw new Error('missing prv parameter to sign transaction');
}
if (!_.isString(prv)) {
throw new Error(`prv must be a string, got type ${typeof prv}`);
}
if (!_.has(params, 'pubs')) {
throw new Error('missing public key parameter to sign transaction');
}
return { txHex, prv };
}
/**
* Assemble keychain and half-sign prebuilt transaction
*
* @param params
* @param params.txPrebuild {TransactionPrebuild} prebuild object returned by platform
* @param params.prv {String} user prv
* @returns {Promise<SignedTransaction>}
*/
async signTransaction(params: SignTransactionOptions): Promise<SignedTransaction> {
const { txHex, prv } = this.verifySignTransactionParams(params);
const factory = this.getBuilder();
const txBuilder = factory.from(txHex);
const keyPair = new DotKeyPair({ prv: prv });
const { referenceBlock, blockNumber, transactionVersion, sender } = params.txPrebuild.transaction;
txBuilder
.validity({ firstValid: blockNumber, maxDuration: this.MAX_VALIDITY_DURATION })
.referenceBlock(referenceBlock)
.version(transactionVersion)
.sender({ address: sender })
.sign({ key: keyPair.getKeys().prv });
const transaction = await txBuilder.build();
if (!transaction) {
throw new Error('Invalid transaction');
}
const signedTxHex = transaction.toBroadcastFormat();
return { txHex: signedTxHex };
}
protected async getInitializedNodeAPI(): Promise<ApiPromise> {
if (!Dot.nodeApiInitialized) {
const wsProvider = new WsProvider(Environments[this.bitgo.getEnv()].dotNodeUrls);
Dot.API = await ApiPromise.create({ provider: wsProvider });
Dot.nodeApiInitialized = true;
}
return Dot.API;
}
protected async getAccountInfo(walletAddr: string): Promise<{ nonce: number; freeBalance: number }> {
const api = await this.getInitializedNodeAPI();
const { nonce, data: balance } = await api.query.system.account(walletAddr);
return { nonce: nonce.toNumber(), freeBalance: balance.free.toNumber() };
}
protected async getHeaderInfo(): Promise<{ headerNumber: number; headerHash: string }> {
const api = await this.getInitializedNodeAPI();
const { number, hash } = await api.rpc.chain.getHeader();
return { headerNumber: number.toNumber(), headerHash: hash.toString() };
}
/**
*
* Estimate the fee of the transaction
*
* @param {string} destAddr destination wallet address
* @param {string} srcAddr source wallet address
* @param {string} amount amount to transfer
* @returns {number} the estimated fee the transaction will cost
*
* @see https://polkadot.js.org/docs/api/cookbook/tx#how-do-i-estimate-the-transaction-fees
*/
protected async getFee(destAddr: string, srcAddr: string, amount: number): Promise<number> {
const api = await this.getInitializedNodeAPI();
const info = await api.tx.balances.transferAllowDeath(destAddr, amount).paymentInfo(srcAddr);
return info.partialFee.toNumber();
}
protected async getMaterial(): Promise<Material> {
const api = await this.getInitializedNodeAPI();
return {
genesisHash: api.genesisHash.toString(),
chainName: api.runtimeChain.toString(),
specName: api.runtimeVersion.specName.toString() as PolkadotSpecNameType,
specVersion: api.runtimeVersion.specVersion.toNumber(),
txVersion: api.runtimeVersion.transactionVersion.toNumber(),
metadata: api.runtimeMetadata.toHex(),
};
}
/**
* Builds a funds recovery transaction without BitGo
* @param {MPCRecoveryOptions} params parameters needed to construct and
* (maybe) sign the transaction
*
* @returns {MPCTx} the serialized transaction hex string and index
* of the address being swept
*/
async recover(params: MPCRecoveryOptions): Promise<MPCTx | MPCSweepTxs> {
if (!params.bitgoKey) {
throw new Error('missing bitgoKey');
}
if (!params.recoveryDestination || !this.isValidAddress(params.recoveryDestination)) {
throw new Error('invalid recoveryDestination');
}
const bitgoKey = params.bitgoKey.replace(/\s/g, '');
const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase;
const MPC = await EDDSAMethods.getInitializedMpcInstance();
const index = params.index || 0;
const currPath = params.seed ? getDerivationPath(params.seed) + `/${index}` : `m/${index}`;
const accountId = MPC.deriveUnhardened(bitgoKey, currPath).slice(0, 64);
const senderAddr = this.getAddressFromPublicKey(accountId);
const { nonce, freeBalance } = await this.getAccountInfo(senderAddr);
const destAddr = params.recoveryDestination;
const amount = freeBalance;
const partialFee = await this.getFee(destAddr, senderAddr, amount);
const value = new BigNumber(freeBalance).minus(new BigNumber(partialFee));
if (value.isLessThanOrEqualTo(0)) {
throw new Error('Did not find address with funds to recover');
}
// first build the unsigned txn
const { headerNumber, headerHash } = await this.getHeaderInfo();
const material = await this.getMaterial();
const validityWindow = { firstValid: headerNumber, maxDuration: this.MAX_VALIDITY_DURATION };
const txnBuilder = this.getBuilder().getTransferBuilder().material(material);
txnBuilder
.sweep(false)
.to({ address: params.recoveryDestination })
.sender({ address: senderAddr })
.validity(validityWindow)
.referenceBlock(headerHash)
.sequenceId({ name: 'Nonce', keyword: 'nonce', value: nonce })
.fee({ amount: 0, type: 'tip' });
const unsignedTransaction = (await txnBuilder.build()) as Transaction;
let serializedTx = unsignedTransaction.toBroadcastFormat();
if (!isUnsignedSweep) {
if (!params.userKey) {
throw new Error('missing userKey');
}
if (!params.backupKey) {
throw new Error('missing backupKey');
}
if (!params.walletPassphrase) {
throw new Error('missing wallet passphrase');
}
// Clean up whitespace from entered values
const userKey = params.userKey.replace(/\s/g, '');
const backupKey = params.backupKey.replace(/\s/g, '');
// Decrypt private keys from KeyCard values
let userPrv;
try {
userPrv = this.bitgo.decrypt({
input: userKey,
password: params.walletPassphrase,
});
} catch (e) {
throw new Error(`Error decrypting user keychain: ${e.message}`);
}
/** TODO BG-52419 Implement Codec for parsing */
const userSigningMaterial = JSON.parse(userPrv) as EDDSAMethodTypes.UserSigningMaterial;
let backupPrv;
try {
backupPrv = this.bitgo.decrypt({
input: backupKey,
password: params.walletPassphrase,
});
} catch (e) {
throw new Error(`Error decrypting backup keychain: ${e.message}`);
}
const backupSigningMaterial = JSON.parse(backupPrv) as EDDSAMethodTypes.BackupSigningMaterial;
// add signature
const signatureHex = await EDDSAMethods.getTSSSignature(
userSigningMaterial,
backupSigningMaterial,
currPath,
unsignedTransaction
);
const dotKeyPair = new DotKeyPair({ pub: accountId });
txnBuilder.addSignature({ pub: dotKeyPair.getKeys().pub }, signatureHex);
const signedTransaction = await txnBuilder.build();
serializedTx = signedTransaction.toBroadcastFormat();
} else {
const value = new BigNumber(freeBalance);
const walletCoin = this.getChain();
const inputs = [
{
address: unsignedTransaction.inputs[0].address,
valueString: value.toString(),
value: value.toNumber(),
},
];
const outputs = [
{
address: unsignedTransaction.outputs[0].address,
valueString: value.toString(),
coinName: walletCoin,
},
];
const spendAmount = value.toString();
const parsedTx = { inputs: inputs, outputs: outputs, spendAmount: spendAmount, type: '' };
const feeInfo = { fee: 0, feeString: '0' };
const transaction: MPCTx = {
serializedTx: serializedTx,
scanIndex: index,
coin: walletCoin,
signableHex: unsignedTransaction.signablePayload.toString('hex'),
derivationPath: currPath,
parsedTx: parsedTx,
feeInfo: feeInfo,
coinSpecific: { ...validityWindow, commonKeychain: bitgoKey },
};
const unsignedTx: MPCUnsignedTx = { unsignedTx: transaction, signatureShares: [] };
const transactions: MPCUnsignedTx[] = [unsignedTx];
const txRequest: RecoveryTxRequest = {
transactions: transactions,
walletCoin: walletCoin,
};
const txRequests: MPCSweepTxs = { txRequests: [txRequest] };
return txRequests;
}
const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index };
return transaction;
}
/**
* Builds native DOT recoveries of receive addresses in batch without BitGo.
* Funds will be recovered to base address first. You need to initiate another sweep txn after that.
*
* @param {MPCConsolidationRecoveryOptions} params - options for consolidation recovery.
* @param {string} [params.startingScanIndex] - receive address index to start scanning from. default to 1 (inclusive).
* @param {string} [params.endingScanIndex] - receive address index to end scanning at. default to startingScanIndex + 20 (exclusive).
*/
async recoverConsolidations(params: MPCConsolidationRecoveryOptions): Promise<MPCTxs | MPCSweepTxs> {
const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase;
const startIdx = params.startingScanIndex || 1;
const endIdx = params.endingScanIndex || startIdx + DEFAULT_SCAN_FACTOR;
if (startIdx < 1 || endIdx <= startIdx || endIdx - startIdx > 10 * DEFAULT_SCAN_FACTOR) {
throw new Error(
`Invalid starting or ending index to scan for addresses. startingScanIndex: ${startIdx}, endingScanIndex: ${endIdx}.`
);
}
const bitgoKey = params.bitgoKey.replace(/\s/g, '');
const MPC = await EDDSAMethods.getInitializedMpcInstance();
const baseIndex = 0;
const basePath = params.seed ? getDerivationPath(params.seed) + `/${baseIndex}` : `m/${baseIndex}`;
const accountId = MPC.deriveUnhardened(bitgoKey, basePath).slice(0, 64);
const baseAddress = this.getAddressFromPublicKey(accountId);
const consolidationTransactions: any[] = [];
let lastScanIndex = startIdx;
for (let i = startIdx; i < endIdx; i++) {
const recoverParams = {
userKey: params.userKey,
backupKey: params.backupKey,
bitgoKey: params.bitgoKey,
walletPassphrase: params.walletPassphrase,
recoveryDestination: baseAddress,
seed: params.seed,
index: i,
};
let recoveryTransaction;
try {
recoveryTransaction = await this.recover(recoverParams);
} catch (e) {
if (e.message === 'Did not find address with funds to recover') {
lastScanIndex = i;
continue;
}
throw e;
}
if (isUnsignedSweep) {
consolidationTransactions.push((recoveryTransaction as MPCSweepTxs).txRequests[0]);
} else {
consolidationTransactions.push(recoveryTransaction);
}
lastScanIndex = i;
}
if (consolidationTransactions.length == 0) {
throw new Error('Did not find an address with funds to recover');
}
if (isUnsignedSweep) {
// lastScanIndex will be used to inform user the last address index scanned for available funds (so they can
// appropriately adjust the scan range on the next iteration of consolidation recoveries). In the case of unsigned
// sweep consolidations, this lastScanIndex will be provided in the coinSpecific of the last txn made.
const lastTransactionCoinSpecific = {
firstValid:
consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific
.firstValid,
maxDuration:
consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific
.maxDuration,
commonKeychain:
consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific
.commonKeychain,
lastScanIndex: lastScanIndex,
};
consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific =
lastTransactionCoinSpecific;
const consolidationSweepTransactions: MPCSweepTxs = { txRequests: consolidationTransactions };
return consolidationSweepTransactions;
}
return { transactions: consolidationTransactions, lastScanIndex };
}
/** inherited doc */
async createBroadcastableSweepTransaction(params: MPCSweepRecoveryOptions): Promise<MPCTxs> {
const req = params.signatureShares;
const broadcastableTransactions: MPCTx[] = [];
let lastScanIndex = 0;
for (let i = 0; i < req.length; i++) {
const MPC = await EDDSAMethods.getInitializedMpcInstance();
const transaction = req[i].txRequest.transactions[0].unsignedTx;
if (!req[i].ovc || !req[i].ovc[0].eddsaSignature) {
throw new Error('Missing signature(s)');
}
const signature = req[i].ovc[0].eddsaSignature;
if (!transaction.signableHex) {
throw new Error('Missing signable hex');
}
const messageBuffer = Buffer.from(transaction.signableHex!, 'hex');
const result = MPC.verify(messageBuffer, signature);
if (!result) {
throw new Error('Invalid signature');
}
const signatureHex = Buffer.concat([Buffer.from(signature.R, 'hex'), Buffer.from(signature.sigma, 'hex')]);
if (
!transaction.coinSpecific ||
!transaction.coinSpecific?.firstValid ||
!transaction.coinSpecific?.maxDuration
) {
throw new Error('missing validity window');
}
const validityWindow = {
firstValid: transaction.coinSpecific?.firstValid,
maxDuration: transaction.coinSpecific?.maxDuration,
};
const material = await this.getMaterial();
if (!transaction.coinSpecific?.commonKeychain) {
throw new Error('Missing common keychain');
}
const commonKeychain = transaction.coinSpecific!.commonKeychain! as string;
if (!transaction.derivationPath) {
throw new Error('Missing derivation path');
}
const derivationPath = transaction.derivationPath as string;
const accountId = MPC.deriveUnhardened(commonKeychain, derivationPath).slice(0, 64);
const senderAddr = this.getAddressFromPublicKey(accountId);
const txnBuilder = this.getBuilder()
.material(material)
.from(transaction.serializedTx as string)
.sender({ address: senderAddr })
.validity(validityWindow);
const dotKeyPair = new DotKeyPair({ pub: accountId });
txnBuilder.addSignature({ pub: dotKeyPair.getKeys().pub }, signatureHex);
const signedTransaction = await txnBuilder.build();
const serializedTx = signedTransaction.toBroadcastFormat();
broadcastableTransactions.push({
serializedTx: serializedTx,
scanIndex: transaction.scanIndex,
});
if (i === req.length - 1 && transaction.coinSpecific!.lastScanIndex) {
lastScanIndex = transaction.coinSpecific!.lastScanIndex as number;
}
}
return { transactions: broadcastableTransactions, lastScanIndex };
}
async parseTransaction(params: ParseTransactionOptions): Promise<ParsedTransaction> {
return {};
}
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
return verifyEddsaTssWalletAddress(
params,
(address) => this.isValidAddress(address),
(publicKey) => this.getAddressFromPublicKey(publicKey)
);
}
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
const { txParams } = params;
if (Array.isArray(txParams.recipients) && txParams.recipients.length > 1) {
throw new Error(
`${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.`
);
}
return true;
}
getAddressFromPublicKey(Pubkey: string): string {
return new DotKeyPair({ pub: Pubkey }).getAddress(Utils.default.getAddressFormat(this.getChain() as DotAssetTypes));
}
private getBuilder(): TransactionBuilderFactory {
return new TransactionBuilderFactory(coins.get(this.getChain()));
}
/** @inheritDoc */
auditDecryptedKey({ publicKey, prv, multiSigType }: AuditDecryptedKeyParams) {
if (multiSigType !== 'tss') {
throw new Error('Unsupported multiSigType');
}
auditEddsaPrivateKey(prv, publicKey ?? '');
}
}