Skip to content

Commit 874fa08

Browse files
Merge pull request #5945 from BitGo/WIN-5189
feat(icp): add missing function implementations
2 parents 378d7fd + bea1540 commit 874fa08

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

modules/sdk-coin-icp/src/icp.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'assert';
12
import {
23
BaseBroadcastTransactionOptions,
34
BaseBroadcastTransactionResult,
@@ -7,7 +8,6 @@ import {
78
ECDSAUtils,
89
Environments,
910
KeyPair,
10-
MethodNotImplementedError,
1111
MPCAlgorithm,
1212
MultisigType,
1313
multisigTypes,
@@ -37,6 +37,7 @@ import {
3737
ROOT_PATH,
3838
Signatures,
3939
SigningPayload,
40+
IcpTransactionExplanation,
4041
} from './lib/iface';
4142
import { TransactionBuilderFactory } from './lib/transactionBuilderFactory';
4243
import utils from './lib/utils';
@@ -84,16 +85,48 @@ export class Icp extends BaseCoin {
8485
return Math.pow(10, this._staticsCoin.decimalPlaces);
8586
}
8687

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+
8795
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;
89122
}
90123

91124
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
92-
throw new MethodNotImplementedError();
125+
return this.isValidAddress(params.address);
93126
}
94127

95128
async parseTransaction(params: ParseTransactionOptions): Promise<ParsedTransaction> {
96-
throw new MethodNotImplementedError();
129+
return {};
97130
}
98131

99132
/**

modules/sdk-coin-icp/src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as Utils from './utils';
2+
export * from './iface';
23

34
export { KeyPair } from './keyPair';
45
export { TransactionBuilder } from './transactionBuilder';
56
export { TransferBuilder } from './transferBuilder';
67
export { TransactionBuilderFactory } from './transactionBuilderFactory';
78
export { Transaction } from './transaction';
8-
export { Signatures, SignatureType } from './iface';
99
export { Utils };

0 commit comments

Comments
 (0)