Skip to content

Commit 0152201

Browse files
feat(sdk-core): export PrebuildTransactionFeeInfo type
Export PrebuildTransactionFeeInfo from iWallet.ts, convert PrebuildTransactionResult to a type alias, and reuse the fee shape in TSS unsigned/MPC types and the Express FeeInfo codec. WEB-000
1 parent f48909d commit 0152201

4 files changed

Lines changed: 33 additions & 16 deletions

File tree

modules/express/src/typedRoutes/api/v2/prebuildAndSignTransaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ export const AddressVerificationData = t.partial({
217217
});
218218

219219
/**
220-
* Fee information
220+
* Fee information — codec for {@link PrebuildTransactionFeeInfo} from sdk-core.
221221
*/
222222
export const FeeInfo = t.partial({
223223
/** Fee amount */
224224
fee: t.number,
225225
/** Fee as string */
226226
feeString: t.string,
227227
});
228+
export type FeeInfo = t.TypeOf<typeof FeeInfo>;
228229

229230
/**
230231
* Consolidation details for sweep/consolidation transactions

modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Key, SerializedKeyPair } from 'openpgp';
22
import { EncryptionVersion, IEncryptionSession, IRequestTracer } from '../../../api';
33
import { type ITransactionRecipient, KeychainsTriplet, ParsedTransaction, TransactionParams } from '../../baseCoin';
44
import { ApiKeyShare, Keychain, WebauthnKeyEncryptionInfo } from '../../keychain';
5-
import { ApiVersion, Memo, WalletType } from '../../wallet';
5+
import { ApiVersion, Memo, WalletType, type PrebuildTransactionFeeInfo } from '../../wallet';
66
import { EDDSA, GShare, Signature, SignShare } from '../../../account-lib/mpc/tss';
77
import { Signature as EcdsaSignature } from '../../../account-lib/mpc/tss/ecdsa/types';
88
import { KeyShare } from './ecdsa';
@@ -531,10 +531,7 @@ export type UnsignedTransactionTss = SignableTransaction & {
531531
// derivation path of the signer
532532
derivationPath: string;
533533
// transaction fees
534-
feeInfo?: {
535-
fee: number;
536-
feeString: string;
537-
};
534+
feeInfo?: Required<PrebuildTransactionFeeInfo>;
538535
coinSpecific?: Record<string, unknown>;
539536
parsedTx?: unknown;
540537
eip1559?: EIP1559FeeOptions;
@@ -769,10 +766,7 @@ export interface MPCTx {
769766
signableHex?: string;
770767
derivationPath?: string;
771768
parsedTx?: ParsedTransaction;
772-
feeInfo?: {
773-
fee: number;
774-
feeString: string;
775-
};
769+
feeInfo?: Required<PrebuildTransactionFeeInfo>;
776770
coinSpecific?: {
777771
firstValid?: number;
778772
maxDuration?: number;

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,13 @@ export interface PrebuildAndSignTransactionOptions extends PrebuildTransactionOp
323323
verification?: VerificationOptions;
324324
}
325325

326-
export interface PrebuildTransactionResult extends TransactionPrebuild {
326+
/** Fee fields returned on {@link PrebuildTransactionResult} (withdraw / send previews). */
327+
export type PrebuildTransactionFeeInfo = {
328+
fee?: number;
329+
feeString?: string;
330+
};
331+
332+
export type PrebuildTransactionResult = TransactionPrebuild & {
327333
walletId: string;
328334
// Consolidate ID is used for consolidate account transactions and indicates if this is
329335
// a consolidation and what consolidate group it should be referenced by.
@@ -332,16 +338,13 @@ export interface PrebuildTransactionResult extends TransactionPrebuild {
332338
consolidationDetails?: {
333339
senderAddressIndex: number;
334340
};
335-
feeInfo?: {
336-
fee?: number;
337-
feeString?: string;
338-
};
341+
feeInfo?: PrebuildTransactionFeeInfo;
339342
pendingApprovalId?: string;
340343
reqId?: IRequestTracer;
341344
payload?: string;
342345
stakingParams?: unknown;
343346
recipients?: ITransactionRecipient[];
344-
}
347+
};
345348

346349
export interface CustomSigningFunction {
347350
(params: {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import assert from 'assert';
2+
3+
import type { PrebuildTransactionFeeInfo, PrebuildTransactionResult } from '../../../../src/bitgo/wallet/iWallet';
4+
5+
describe('PrebuildTransactionFeeInfo', () => {
6+
it('assigns feeInfo on PrebuildTransactionResult', () => {
7+
const feeInfo: PrebuildTransactionFeeInfo = {
8+
fee: 1000,
9+
feeString: '1000',
10+
};
11+
12+
const prebuild: Pick<PrebuildTransactionResult, 'walletId' | 'feeInfo'> = {
13+
walletId: 'wallet-id',
14+
feeInfo,
15+
};
16+
17+
assert.strictEqual(prebuild.feeInfo?.feeString, '1000');
18+
});
19+
});

0 commit comments

Comments
 (0)