Skip to content

Commit bea1540

Browse files
mohd-kashifhitansh-madan
authored andcommitted
Merge pull request #5936 from BitGo/WIN-5178-add-hash-function-icp
feat(sdk-coin-icp): implement getHashFunction TICKET: WIN-5189
1 parent 5f99a06 commit bea1540

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
SignTransactionOptions,
1919
TssVerifyAddressOptions,
2020
VerifyTransactionOptions,
21-
InvalidAddressError,
22-
UnexpectedAddressError,
2321
} from '@bitgo/sdk-core';
2422
import { coins, BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
2523
import { Principal } from '@dfinity/principal';
@@ -40,11 +38,9 @@ import {
4038
Signatures,
4139
SigningPayload,
4240
IcpTransactionExplanation,
43-
IcpCoinSpecific,
4441
} from './lib/iface';
4542
import { TransactionBuilderFactory } from './lib/transactionBuilderFactory';
4643
import utils from './lib/utils';
47-
import { Transaction } from './lib';
4844

4945
/**
5046
* Class representing the Internet Computer (ICP) coin.
@@ -90,13 +86,15 @@ export class Icp extends BaseCoin {
9086
}
9187

9288
async explainTransaction(params: { txHex: string }): Promise<IcpTransactionExplanation> {
93-
const transaction = (await (await this.getBuilderFactory().from(params.txHex)).build()) as Transaction;
89+
const factory = this.getBuilderFactory();
90+
const txBuilder = await factory.from(params.txHex);
91+
const transaction = await txBuilder.build();
9492
return transaction.explainTransaction();
9593
}
9694

9795
async verifyTransaction(params: VerifyTransactionOptions): Promise<boolean> {
9896
const { txParams, txPrebuild } = params;
99-
const { txHex } = txPrebuild;
97+
const txHex = txPrebuild?.txHex;
10098
if (!txHex) {
10199
throw new Error('txHex is required');
102100
}
@@ -113,22 +111,18 @@ export class Icp extends BaseCoin {
113111
const output = explainedTx.outputs[0];
114112
const recipient = txParams.recipients[0];
115113
assert(
116-
output.address === recipient.address && BigNumber(output.amount).eq(BigNumber(recipient.amount)),
114+
typeof recipient.address === 'string' &&
115+
typeof output.address === 'string' &&
116+
output.address === recipient.address &&
117+
BigNumber(output.amount).eq(BigNumber(recipient.amount)),
117118
'Tx outputs does not match with expected txParams recipients'
118119
);
119120
}
120121
return true;
121122
}
122123

123124
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
124-
if (!this.isValidAddress(params.address)) {
125-
throw new InvalidAddressError(`invalid address: ${params.address}`);
126-
}
127-
const rootAddress = (params.coinSpecific as IcpCoinSpecific).rootAddress;
128-
if (params.address.includes(rootAddress)) {
129-
throw new UnexpectedAddressError(`address validation failure: ${params.address} vs ${rootAddress}`);
130-
}
131-
return true;
125+
return this.isValidAddress(params.address);
132126
}
133127

134128
async parseTransaction(params: ParseTransactionOptions): Promise<ParsedTransaction> {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,3 @@ export interface RecoveryOptions {
194194
export interface PublicNodeSubmitResponse {
195195
status: string;
196196
}
197-
198-
export interface IcpCoinSpecific {
199-
rootAddress: string;
200-
}
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)