-
Notifications
You must be signed in to change notification settings - Fork 300
feat(sdk-coin-dot): enhance DOT tx verification for consolidation to base address #7610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
32db56a
6ca11a2
9bf90a5
b72f323
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,9 +29,17 @@ import { | |
| multisigTypes, | ||
| AuditDecryptedKeyParams, | ||
| verifyEddsaTssWalletAddress, | ||
| TxIntentMismatchRecipientError, | ||
| } from '@bitgo/sdk-core'; | ||
| import { BaseCoin as StaticsBaseCoin, coins, PolkadotSpecNameType } from '@bitgo/statics'; | ||
| import { Interface, KeyPair as DotKeyPair, Transaction, TransactionBuilderFactory, Utils } from './lib'; | ||
| import { | ||
| Interface, | ||
| KeyPair as DotKeyPair, | ||
| NativeTransferBuilder, | ||
| Transaction, | ||
| TransactionBuilderFactory, | ||
| Utils, | ||
| } from './lib'; | ||
| import '@polkadot/api-augment'; | ||
| import { ApiPromise, WsProvider } from '@polkadot/api'; | ||
| import { Material } from './lib/iface'; | ||
|
|
@@ -651,7 +659,7 @@ export class Dot extends BaseCoin { | |
| } | ||
|
|
||
| async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> { | ||
| const { txPrebuild, txParams } = params; | ||
| const { txPrebuild, txParams, verification, wallet, reqId } = params; | ||
| if (!txParams) { | ||
| throw new Error('missing txParams'); | ||
| } | ||
|
|
@@ -665,7 +673,25 @@ export class Dot extends BaseCoin { | |
| } | ||
|
|
||
| const factory = this.getBuilder(); | ||
| const txBuilder = factory.from(txPrebuild.txHex) as any; | ||
| const txBuilder = factory.from(txPrebuild.txHex) as unknown as NativeTransferBuilder; | ||
|
|
||
| if (verification?.consolidationToBaseAddress) { | ||
| // Verify funds are sent to wallet's base address for consolidation | ||
| const baseAddress = wallet?.coinSpecific()?.rootAddress || wallet?.coinSpecific()?.baseAddress; | ||
| if (!baseAddress) { | ||
| throw new Error('Unable to determine base address for consolidation'); | ||
| } | ||
| if (txBuilder['_to'] !== baseAddress) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you fetching it via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're not using the |
||
| throw new TxIntentMismatchRecipientError( | ||
| `Transaction destination address ${txBuilder['_to']} does not match wallet base address ${baseAddress}`, | ||
| reqId, | ||
| [txParams], | ||
| txPrebuild.txHex, | ||
| [{ address: txBuilder['_to'], amount: txBuilder['_amount'] }] | ||
| ); | ||
| } | ||
| return true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not return early. |
||
| } | ||
|
|
||
| if (txParams.recipients !== undefined) { | ||
| if (txParams.recipients.length === 0) { | ||
|
|
@@ -678,17 +704,25 @@ export class Dot extends BaseCoin { | |
| ); | ||
| } | ||
|
|
||
| // validate recipient is same as txBuilder._to | ||
| if (txParams.recipients[0].address !== txBuilder._to) { | ||
| throw new Error( | ||
| `Recipient address ${txParams.recipients[0].address} does not match transaction destination address ${txBuilder._to}` | ||
| // validate recipient is same as txBuilder['_to'] | ||
| if (txParams.recipients[0].address !== txBuilder['_to']) { | ||
| throw new TxIntentMismatchRecipientError( | ||
| `Recipient address ${txParams.recipients[0].address} does not match transaction destination address ${txBuilder['_to']}`, | ||
| reqId, | ||
| [txParams], | ||
| txPrebuild.txHex, | ||
| [{ address: txBuilder['_to'], amount: txBuilder['_amount'] }] | ||
| ); | ||
| } | ||
|
|
||
| // and amount is same as txBuilder._amount | ||
| if (txParams.recipients[0].amount !== txBuilder._amount) { | ||
| throw new Error( | ||
| `Recipient amount ${txParams.recipients[0].amount} does not match transaction amount ${txBuilder._amount}` | ||
| // validate amount is same as txBuilder['_amount'] | ||
| if (txParams.recipients[0].amount !== txBuilder['_amount']) { | ||
| throw new TxIntentMismatchRecipientError( | ||
| `Recipient amount ${txParams.recipients[0].amount} does not match transaction amount ${txBuilder['_amount']}`, | ||
| reqId, | ||
| [txParams], | ||
| txPrebuild.txHex, | ||
| [{ address: txBuilder['_to'], amount: txBuilder['_amount'] }] | ||
| ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dot verifyTransaction has been reverted here #7634
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#7652 revert of revert here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the JSON for a DOT wallet and the base address for DOT is called
rootAddressso I use that to retrieve the address here. I also typed the txBuilder, changed the generic errors to beTxIntentMismatchRecipientErrorwhere appropriate, and I rebased those changes on top of the revert of revert PR.