|
| 1 | +import assert from 'assert'; |
1 | 2 | import {
|
2 | 3 | BaseBroadcastTransactionOptions,
|
3 | 4 | BaseBroadcastTransactionResult,
|
|
7 | 8 | ECDSAUtils,
|
8 | 9 | Environments,
|
9 | 10 | KeyPair,
|
10 |
| - MethodNotImplementedError, |
11 | 11 | MPCAlgorithm,
|
12 | 12 | MultisigType,
|
13 | 13 | multisigTypes,
|
@@ -37,6 +37,7 @@ import {
|
37 | 37 | ROOT_PATH,
|
38 | 38 | Signatures,
|
39 | 39 | SigningPayload,
|
| 40 | + IcpTransactionExplanation, |
40 | 41 | } from './lib/iface';
|
41 | 42 | import { TransactionBuilderFactory } from './lib/transactionBuilderFactory';
|
42 | 43 | import utils from './lib/utils';
|
@@ -84,16 +85,48 @@ export class Icp extends BaseCoin {
|
84 | 85 | return Math.pow(10, this._staticsCoin.decimalPlaces);
|
85 | 86 | }
|
86 | 87 |
|
| 88 | + async explainTransaction(params: { txHex: string }): Promise<IcpTransactionExplanation> { |
| 89 | + const factory = this.getBuilderFactory(); |
| 90 | + const txBuilder = await factory.from(params.txHex); |
| 91 | + const transaction = await txBuilder.build(); |
| 92 | + return transaction.explainTransaction(); |
| 93 | + } |
| 94 | + |
87 | 95 | async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
|
88 |
| - throw new MethodNotImplementedError(); |
| 96 | + const { txParams, txPrebuild } = params; |
| 97 | + const txHex = txPrebuild?.txHex; |
| 98 | + if (!txHex) { |
| 99 | + throw new Error('txHex is required'); |
| 100 | + } |
| 101 | + const explainedTx = await this.explainTransaction({ txHex }); |
| 102 | + |
| 103 | + if (Array.isArray(txParams.recipients) && txParams.recipients.length > 0) { |
| 104 | + if (txParams.recipients.length > 1) { |
| 105 | + throw new Error( |
| 106 | + `${this.getChain()} doesn't support sending to more than 1 destination address within a single transaction. Try again, using only a single recipient.` |
| 107 | + ); |
| 108 | + } |
| 109 | + assert(explainedTx.outputs.length === 1, 'Tx outputs does not match with expected txParams recipients'); |
| 110 | + |
| 111 | + const output = explainedTx.outputs[0]; |
| 112 | + const recipient = txParams.recipients[0]; |
| 113 | + assert( |
| 114 | + typeof recipient.address === 'string' && |
| 115 | + typeof output.address === 'string' && |
| 116 | + output.address === recipient.address && |
| 117 | + BigNumber(output.amount).eq(BigNumber(recipient.amount)), |
| 118 | + 'Tx outputs does not match with expected txParams recipients' |
| 119 | + ); |
| 120 | + } |
| 121 | + return true; |
89 | 122 | }
|
90 | 123 |
|
91 | 124 | async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
|
92 |
| - throw new MethodNotImplementedError(); |
| 125 | + return this.isValidAddress(params.address); |
93 | 126 | }
|
94 | 127 |
|
95 | 128 | async parseTransaction(params: ParseTransactionOptions): Promise<ParsedTransaction> {
|
96 |
| - throw new MethodNotImplementedError(); |
| 129 | + return {}; |
97 | 130 | }
|
98 | 131 |
|
99 | 132 | /**
|
|
0 commit comments