diff --git a/modules/sdk-coin-ada/src/ada.ts b/modules/sdk-coin-ada/src/ada.ts index ee0a61c224..280cec81b2 100644 --- a/modules/sdk-coin-ada/src/ada.ts +++ b/modules/sdk-coin-ada/src/ada.ts @@ -19,8 +19,14 @@ import { AddressFormat, Environments, ITransactionRecipient, - EDDSASignature, - SignatureShareRecord, + MPCTx, + MPCRecoveryOptions, + MPCConsolidationRecoveryOptions, + MPCSweepTxs, + RecoveryTxRequest, + MPCUnsignedTx, + MPCSweepRecoveryOptions, + MPCTxs, } from '@bitgo/sdk-core'; import { KeyPair as AdaKeyPair, Transaction, TransactionBuilderFactory, Utils } from './lib'; import { BaseCoin as StaticsBaseCoin, CoinFamily, coins } from '@bitgo/statics'; @@ -48,95 +54,6 @@ export interface SignTransactionOptions extends BaseSignTransactionOptions { prv: string; } -interface RecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - recoveryDestination: string; - krsProvider?: string; - walletPassphrase?: string; - seed?: string; - index?: number; -} - -interface ConsolidationRecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - walletPassphrase?: string; - startingScanIndex?: number; // default to 1 (inclusive) - endingScanIndex?: number; // default to startingScanIndex + 20 (exclusive) - seed?: string; -} - -interface SweepRecoveryOptions { - signatureShares: SignatureShares[]; -} - -interface SignatureShares { - txRequest: TxRequest; - tssVersion: string; - ovc: Ovc[]; -} - -interface TxRequest { - transactions: OvcTransaction[]; - walletCoin: string; -} - -interface OvcTransaction { - unsignedTx: AdaTx; - signatureShares: SignatureShareRecord[]; - signatureShare: SignatureShare; -} - -interface SignatureShare { - from: string; - to: string; - share: string; - publicShare: string; -} - -interface Ovc { - eddsaSignature: EDDSASignature; -} - -interface AdaTx { - serializedTx: string; - scanIndex: number; - coin?: string; - signableHex?: string; - derivationPath?: string; - parsedTx?: ParsedTransaction; - feeInfo?: { - fee: number; - feeString: string; - }; - coinSpecific?: { - commonKeychain?: string; - lastScanIndex?: number; - }; -} - -interface AdaTxs { - transactions: AdaTx[]; - lastScanIndex: number; -} - -interface AdaUnsignedTx { - unsignedTx: AdaTx; - signatureShares: []; -} - -interface AdaTxRequest { - walletCoin: string; - transactions: AdaUnsignedTx[]; -} - -interface AdaSweepTxs { - txRequests: AdaTxRequest[]; -} - interface AdaAddressParams { bitgoKey: string; index: number; @@ -361,15 +278,15 @@ export class Ada extends BaseCoin { /** * Creates funds sweep recovery transaction(s) without BitGo * - * @param {SweepRecoveryOptions} params parameters needed to combine the signatures + * @param {MPCSweepRecoveryOptions} params parameters needed to combine the signatures * and transactions to create broadcastable transactions * - * @returns {AdaTx[]} array of the serialized transaction hex strings and indices + * @returns {MPCTxs} array of the serialized transaction hex strings and indices * of the addresses being swept */ - async createBroadcastableSweepTransaction(params: SweepRecoveryOptions): Promise { + async createBroadcastableSweepTransaction(params: MPCSweepRecoveryOptions): Promise { const req = params.signatureShares; - const broadcastableTransactions: AdaTx[] = []; + const broadcastableTransactions: MPCTx[] = []; let lastScanIndex = 0; for (let i = 0; i < req.length; i++) { @@ -421,13 +338,13 @@ export class Ada extends BaseCoin { /** * Builds funds recovery transaction(s) without BitGo * - * @param {RecoveryOptions} params parameters needed to construct and + * @param {MPCRecoveryOptions} params parameters needed to construct and * (maybe) sign the transaction * - * @returns {AdaTx} array of the serialized transaction hex strings and indices + * @returns {MPCTx | MPCSweepTxs} array of the serialized transaction hex strings and indices * of the addresses being swept */ - async recover(params: RecoveryOptions): Promise { + async recover(params: MPCRecoveryOptions): Promise { if (!params.bitgoKey) { throw new Error('missing bitgoKey'); } @@ -538,7 +455,7 @@ export class Ada extends BaseCoin { const fee = new BigNumber((parsedTx.fee as { fee: string }).fee); const feeInfo = { fee: fee.toNumber(), feeString: fee.toString() }; const coinSpecific = { commonKeychain: bitgoKey }; - const transaction: AdaTx = { + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index, coin: walletCoin, @@ -548,16 +465,16 @@ export class Ada extends BaseCoin { feeInfo: feeInfo, coinSpecific: coinSpecific, }; - const unsignedTx: AdaUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; - const transactions: AdaUnsignedTx[] = [unsignedTx]; - const txRequest: AdaTxRequest = { + const unsignedTx: MPCUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; + const transactions: MPCUnsignedTx[] = [unsignedTx]; + const txRequest: RecoveryTxRequest = { transactions: transactions, walletCoin: walletCoin, }; - const txRequests: AdaSweepTxs = { txRequests: [txRequest] }; + const txRequests: MPCSweepTxs = { txRequests: [txRequest] }; return txRequests; } - const transaction: AdaTx = { serializedTx: serializedTx, scanIndex: index }; + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index }; return transaction; } @@ -565,11 +482,11 @@ export class Ada extends BaseCoin { * Builds native ADA recoveries of receive addresses in batch without BitGo. * Funds will be recovered to base address first. You need to initiate another sweep txn after that. * - * @param {ConsolidationRecoveryOptions} params - options for consolidation recovery. + * @param {MPCConsolidationRecoveryOptions} params - options for consolidation recovery. * @param {string} [params.startingScanIndex] - receive address index to start scanning from. default to 1 (inclusive). * @param {string} [params.endingScanIndex] - receive address index to end scanning at. default to startingScanIndex + 20 (exclusive). */ - async recoverConsolidations(params: ConsolidationRecoveryOptions): Promise { + async recoverConsolidations(params: MPCConsolidationRecoveryOptions): Promise { const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase; const startIdx = params.startingScanIndex || 1; const endIdx = params.endingScanIndex || startIdx + DEFAULT_SCAN_FACTOR; @@ -611,7 +528,7 @@ export class Ada extends BaseCoin { } if (isUnsignedSweep) { - consolidationTransactions.push((recoveryTransaction as AdaSweepTxs).txRequests[0]); + consolidationTransactions.push((recoveryTransaction as MPCSweepTxs).txRequests[0]); } else { consolidationTransactions.push(recoveryTransaction); } @@ -634,7 +551,7 @@ export class Ada extends BaseCoin { }; consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific = lastTransactionCoinSpecific; - const consolidationSweepTransactions: AdaSweepTxs = { txRequests: consolidationTransactions }; + const consolidationSweepTransactions: MPCSweepTxs = { txRequests: consolidationTransactions }; return consolidationSweepTransactions; } diff --git a/modules/sdk-coin-dot/src/dot.ts b/modules/sdk-coin-dot/src/dot.ts index 4698d9e03b..60d4ca1af6 100644 --- a/modules/sdk-coin-dot/src/dot.ts +++ b/modules/sdk-coin-dot/src/dot.ts @@ -18,8 +18,14 @@ import { VerifyTransactionOptions, EDDSAMethods, EDDSAMethodTypes, - EDDSASignature, - SignatureShareRecord, + MPCTx, + MPCRecoveryOptions, + MPCConsolidationRecoveryOptions, + MPCSweepTxs, + RecoveryTxRequest, + MPCUnsignedTx, + MPCSweepRecoveryOptions, + MPCTxs, } from '@bitgo/sdk-core'; import { BaseCoin as StaticsBaseCoin, coins, PolkadotSpecNameType } from '@bitgo/statics'; import { Interface, KeyPair as DotKeyPair, Transaction, TransactionBuilderFactory, Utils } from './lib'; @@ -53,97 +59,6 @@ export interface VerifiedTransactionParameters { prv: string; } -interface SweepRecoveryOptions { - signatureShares: SignatureShares[]; -} - -interface SignatureShares { - txRequest: TxRequest; - tssVersion: string; - ovc: Ovc[]; -} - -interface TxRequest { - transactions: OvcTransaction[]; - walletCoin: string; -} - -interface OvcTransaction { - unsignedTx: DotTx; - signatureShares: SignatureShareRecord[]; - signatureShare: SignatureShare; -} - -interface SignatureShare { - from: string; - to: string; - share: string; - publicShare: string; -} - -interface Ovc { - eddsaSignature: EDDSASignature; -} - -interface RecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - recoveryDestination: string; - krsProvider?: string; - walletPassphrase?: string; - seed?: string; - index?: number; -} - -interface ConsolidationRecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - walletPassphrase?: string; - startingScanIndex?: number; // default to 1 (inclusive) - endingScanIndex?: number; // default to startingScanIndex + 20 (exclusive) - seed?: string; -} - -interface DotTx { - serializedTx: string; - scanIndex: number; - coin?: string; - signableHex?: string; - derivationPath?: string; - parsedTx?: ParsedTransaction; - feeInfo?: { - fee: number; - feeString: string; - }; - coinSpecific?: { - firstValid?: number; - maxDuration?: number; - commonKeychain?: string; - lastScanIndex?: number; - }; -} - -interface DotTxs { - transactions: DotTx[]; - lastScanIndex: number; -} - -interface DotUnsignedTx { - unsignedTx: DotTx; - signatureShares: []; -} - -interface DotTxRequest { - walletCoin: string; - transactions: DotUnsignedTx[]; -} - -interface DotSweepTxs { - txRequests: DotTxRequest[]; -} - const dotUtils = Utils.default; export class Dot extends BaseCoin { @@ -416,13 +331,13 @@ export class Dot extends BaseCoin { /** * Builds a funds recovery transaction without BitGo - * @param {RecoveryOptions} params parameters needed to construct and + * @param {MPCRecoveryOptions} params parameters needed to construct and * (maybe) sign the transaction * - * @returns {DotTx} the serialized transaction hex string and index + * @returns {MPCTx} the serialized transaction hex string and index * of the address being swept */ - async recover(params: RecoveryOptions): Promise { + async recover(params: MPCRecoveryOptions): Promise { if (!params.bitgoKey) { throw new Error('missing bitgoKey'); } @@ -534,7 +449,7 @@ export class Dot extends BaseCoin { const spendAmount = value.toString(); const parsedTx = { inputs: inputs, outputs: outputs, spendAmount: spendAmount, type: '' }; const feeInfo = { fee: 0, feeString: '0' }; - const transaction: DotTx = { + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index, coin: walletCoin, @@ -545,16 +460,16 @@ export class Dot extends BaseCoin { coinSpecific: { ...validityWindow, commonKeychain: bitgoKey }, }; - const unsignedTx: DotUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; - const transactions: DotUnsignedTx[] = [unsignedTx]; - const txRequest: DotTxRequest = { + const unsignedTx: MPCUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; + const transactions: MPCUnsignedTx[] = [unsignedTx]; + const txRequest: RecoveryTxRequest = { transactions: transactions, walletCoin: walletCoin, }; - const txRequests: DotSweepTxs = { txRequests: [txRequest] }; + const txRequests: MPCSweepTxs = { txRequests: [txRequest] }; return txRequests; } - const transaction: DotTx = { serializedTx: serializedTx, scanIndex: index }; + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index }; return transaction; } @@ -562,11 +477,11 @@ export class Dot extends BaseCoin { * Builds native DOT recoveries of receive addresses in batch without BitGo. * Funds will be recovered to base address first. You need to initiate another sweep txn after that. * - * @param {ConsolidationRecoveryOptions} params - options for consolidation recovery. + * @param {MPCConsolidationRecoveryOptions} params - options for consolidation recovery. * @param {string} [params.startingScanIndex] - receive address index to start scanning from. default to 1 (inclusive). * @param {string} [params.endingScanIndex] - receive address index to end scanning at. default to startingScanIndex + 20 (exclusive). */ - async recoverConsolidations(params: ConsolidationRecoveryOptions): Promise { + async recoverConsolidations(params: MPCConsolidationRecoveryOptions): Promise { const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase; const startIdx = params.startingScanIndex || 1; const endIdx = params.endingScanIndex || startIdx + DEFAULT_SCAN_FACTOR; @@ -609,7 +524,7 @@ export class Dot extends BaseCoin { } if (isUnsignedSweep) { - consolidationTransactions.push((recoveryTransaction as DotSweepTxs).txRequests[0]); + consolidationTransactions.push((recoveryTransaction as MPCSweepTxs).txRequests[0]); } else { consolidationTransactions.push(recoveryTransaction); } @@ -632,7 +547,7 @@ export class Dot extends BaseCoin { }; consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific = lastTransactionCoinSpecific; - const consolidationSweepTransactions: DotSweepTxs = { txRequests: consolidationTransactions }; + const consolidationSweepTransactions: MPCSweepTxs = { txRequests: consolidationTransactions }; return consolidationSweepTransactions; } @@ -642,15 +557,15 @@ export class Dot extends BaseCoin { /** * Creates funds sweep recovery transaction(s) without BitGo * - * @param {SweepRecoveryOptions} params parameters needed to combine the signatures + * @param {MPCSweepRecoveryOptions} params parameters needed to combine the signatures * and transactions to create broadcastable transactions * - * @returns {DotTx[]} array of the serialized transaction hex strings and indices + * @returns {MPCTx[]} array of the serialized transaction hex strings and indices * of the addresses being swept */ - async createBroadcastableSweepTransaction(params: SweepRecoveryOptions): Promise { + async createBroadcastableSweepTransaction(params: MPCSweepRecoveryOptions): Promise { const req = params.signatureShares; - const broadcastableTransactions: DotTx[] = []; + const broadcastableTransactions: MPCTx[] = []; let lastScanIndex = 0; for (let i = 0; i < req.length; i++) { diff --git a/modules/sdk-coin-sol/src/sol.ts b/modules/sdk-coin-sol/src/sol.ts index 62e65a3adc..72f90b2af5 100644 --- a/modules/sdk-coin-sol/src/sol.ts +++ b/modules/sdk-coin-sol/src/sol.ts @@ -30,8 +30,14 @@ import { VerifyTransactionOptions, EDDSAMethodTypes, EDDSAMethods, - EDDSASignature, - SignatureShareRecord, + MPCTx, + MPCRecoveryOptions, + MPCConsolidationRecoveryOptions, + MPCSweepTxs, + RecoveryTxRequest, + MPCUnsignedTx, + MPCSweepRecoveryOptions, + MPCTxs, } from '@bitgo/sdk-core'; import { KeyPair as SolKeyPair, Transaction, TransactionBuilder, TransactionBuilderFactory } from './lib'; import { @@ -105,105 +111,23 @@ export interface SolParseTransactionOptions extends BaseParseTransactionOptions tokenAccountRentExemptAmount?: string; } -export interface SolTx { - serializedTx: string; - scanIndex: number; - coin?: string; - signableHex?: string; - derivationPath?: string; - parsedTx?: ParsedTransaction; - feeInfo?: { - fee: number; - feeString: string; - }; - coinSpecific?: { - commonKeychain?: string; - lastScanIndex?: number; - }; -} - -export interface SolTxs { - transactions: SolTx[]; - lastScanIndex: number; -} - -interface SolUnsignedTx { - unsignedTx: SolTx; - signatureShares: []; -} - -interface SolTxRequest { - walletCoin: string; - transactions: SolUnsignedTx[]; -} - -export interface SolSweepTxs { - txRequests: SolTxRequest[]; -} - interface SolDurableNonceFromNode { authority: string; blockhash: string; } -interface RecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - this is bitgo's xpub and will be used to derive their root address - recoveryDestination: string; // base58 address - walletPassphrase?: string; +export interface SolRecoveryOptions extends MPCRecoveryOptions { durableNonce?: { publicKey: string; secretKey: string; }; - seed?: string; - index?: number; } -interface ConsolidationRecoveryOptions { - userKey?: string; // Box A - backupKey?: string; // Box B - bitgoKey: string; // Box C - walletPassphrase?: string; +export interface SolConsolidationRecoveryOptions extends MPCConsolidationRecoveryOptions { durableNonces: { publicKeys: string[]; secretKey: string; }; - startingScanIndex?: number; // default to 1 (inclusive) - endingScanIndex?: number; // default to startingScanIndex + 20 (exclusive) - seed?: string; -} - -interface SweepRecoveryOptions { - signatureShares: SignatureShares[]; -} - -interface SignatureShares { - txRequest: TxRequest; - tssVersion: string; - ovc: Ovc[]; -} - -interface TxRequest { - transactions: OvcTransaction[]; - walletCoin: string; -} - -interface OvcTransaction { - unsignedTx: SolTx; - signatureShares: SignatureShareRecord[]; - signatureShare: SignatureShare; -} - -interface SignatureShare { - from: string; - to: string; - share: string; - publicShare: string; -} - -interface Ovc { - eddsaSignature: EDDSASignature; } const HEX_REGEX = /^[0-9a-fA-F]+$/; @@ -654,15 +578,15 @@ export class Sol extends BaseCoin { * @param {SweepRecoveryOptions} params parameters needed to combine the signatures * and transactions to create broadcastable transactions * - * @returns {SolTx[]} array of the serialized transaction hex strings and indices + * @returns {MPCTxs} array of the serialized transaction hex strings and indices * of the addresses being swept */ - async createBroadcastableSweepTransaction(params: SweepRecoveryOptions): Promise { + async createBroadcastableSweepTransaction(params: MPCSweepRecoveryOptions): Promise { if (!params.signatureShares) { ('Missing transaction(s)'); } const req = params.signatureShares; - const broadcastableTransactions: SolTx[] = []; + const broadcastableTransactions: MPCTx[] = []; let lastScanIndex = 0; for (let i = 0; i < req.length; i++) { @@ -715,13 +639,13 @@ export class Sol extends BaseCoin { /** * Builds a funds recovery transaction without BitGo - * @param {RecoveryOptions} params parameters needed to construct and + * @param {SolRecoveryOptions} params parameters needed to construct and * (maybe) sign the transaction * - * @returns {SolTxs} the serialized transaction hex string and index + * @returns {MPCTx | MPCSweepTxs} the serialized transaction hex string and index * of the address being swept */ - async recover(params: RecoveryOptions): Promise { + async recover(params: SolRecoveryOptions): Promise { if (!params.bitgoKey) { throw new Error('missing bitgoKey'); } @@ -858,7 +782,7 @@ export class Sol extends BaseCoin { const feeInfo = { fee: totalFee, feeString: new BigNumber(totalFee).toString() }; const coinSpecific = { commonKeychain: bitgoKey }; if (isUnsignedSweep) { - const transaction: SolTx = { + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index, coin: walletCoin, @@ -868,16 +792,16 @@ export class Sol extends BaseCoin { feeInfo: feeInfo, coinSpecific: coinSpecific, }; - const unsignedTx: SolUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; - const transactions: SolUnsignedTx[] = [unsignedTx]; - const txRequest: SolTxRequest = { + const unsignedTx: MPCUnsignedTx = { unsignedTx: transaction, signatureShares: [] }; + const transactions: MPCUnsignedTx[] = [unsignedTx]; + const txRequest: RecoveryTxRequest = { transactions: transactions, walletCoin: walletCoin, }; - const txRequests: SolSweepTxs = { txRequests: [txRequest] }; + const txRequests: MPCSweepTxs = { txRequests: [txRequest] }; return txRequests; } - const transaction: SolTx = { + const transaction: MPCTx = { serializedTx: serializedTx, scanIndex: index, }; @@ -888,11 +812,11 @@ export class Sol extends BaseCoin { * Builds native SOL recoveries of receive addresses in batch without BitGo. * Funds will be recovered to base address first. You need to initiate another sweep txn after that. * - * @param {ConsolidationRecoveryOptions} params - options for consolidation recovery. + * @param {SolConsolidationRecoveryOptions} params - options for consolidation recovery. * @param {string} [params.startingScanIndex] - receive address index to start scanning from. default to 1 (inclusive). * @param {string} [params.endingScanIndex] - receive address index to end scanning at. default to startingScanIndex + 20 (exclusive). */ - async recoverConsolidations(params: ConsolidationRecoveryOptions): Promise { + async recoverConsolidations(params: SolConsolidationRecoveryOptions): Promise { const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase; const startIdx = params.startingScanIndex || 1; const endIdx = params.endingScanIndex || startIdx + DEFAULT_SCAN_FACTOR; @@ -954,7 +878,7 @@ export class Sol extends BaseCoin { } if (isUnsignedSweep) { - consolidationTransactions.push((recoveryTransaction as SolSweepTxs).txRequests[0]); + consolidationTransactions.push((recoveryTransaction as MPCSweepTxs).txRequests[0]); } else { consolidationTransactions.push(recoveryTransaction); } @@ -983,7 +907,7 @@ export class Sol extends BaseCoin { }; consolidationTransactions[consolidationTransactions.length - 1].transactions[0].unsignedTx.coinSpecific = lastTransactionCoinSpecific; - const consolidationSweepTransactions: SolSweepTxs = { txRequests: consolidationTransactions }; + const consolidationSweepTransactions: MPCSweepTxs = { txRequests: consolidationTransactions }; return consolidationSweepTransactions; } diff --git a/modules/sdk-coin-sol/test/unit/sol.ts b/modules/sdk-coin-sol/test/unit/sol.ts index 9ac56aa794..91c8b5df33 100644 --- a/modules/sdk-coin-sol/test/unit/sol.ts +++ b/modules/sdk-coin-sol/test/unit/sol.ts @@ -5,8 +5,8 @@ import * as testData from '../fixtures/sol'; import * as should from 'should'; import * as resources from '../resources/sol'; import * as _ from 'lodash'; -import { KeyPair, Sol, Tsol, SolSweepTxs, SolTx, SolTxs } from '../../src'; -import { TssUtils, TxRequest, Wallet } from '@bitgo/sdk-core'; +import { KeyPair, Sol, Tsol } from '../../src'; +import { TssUtils, TxRequest, Wallet, MPCSweepTxs, MPCTx, MPCTxs } from '@bitgo/sdk-core'; import { getBuilderFactory } from './getBuilderFactory'; import { Transaction } from '../../src/lib'; import { coins } from '@bitgo/statics'; @@ -1545,10 +1545,10 @@ describe('SOL:', function () { latestBlockHashTxn.should.not.be.empty(); latestBlockHashTxn.should.hasOwnProperty('serializedTx'); latestBlockHashTxn.should.hasOwnProperty('scanIndex'); - should.equal((latestBlockHashTxn as SolTx).scanIndex, 0); + should.equal((latestBlockHashTxn as MPCTx).scanIndex, 0); const latestBlockhashTxnDeserialize = new Transaction(coin); - latestBlockhashTxnDeserialize.fromRawTransaction((latestBlockHashTxn as SolTx).serializedTx); + latestBlockhashTxnDeserialize.fromRawTransaction((latestBlockHashTxn as MPCTx).serializedTx); const latestBlockhashTxnJson = latestBlockhashTxnDeserialize.toJson(); should.equal(latestBlockhashTxnJson.nonce, testData.SolInputData.blockhash); @@ -1575,10 +1575,10 @@ describe('SOL:', function () { durableNonceTxn.should.not.be.empty(); durableNonceTxn.should.hasOwnProperty('serializedTx'); durableNonceTxn.should.hasOwnProperty('scanIndex'); - should.equal((durableNonceTxn as SolTx).scanIndex, 0); + should.equal((durableNonceTxn as MPCTx).scanIndex, 0); const durableNonceTxnDeserialize = new Transaction(coin); - durableNonceTxnDeserialize.fromRawTransaction((durableNonceTxn as SolTx).serializedTx); + durableNonceTxnDeserialize.fromRawTransaction((durableNonceTxn as MPCTx).serializedTx); const durableNonceTxnJson = durableNonceTxnDeserialize.toJson(); should.equal(durableNonceTxnJson.nonce, testData.SolInputData.durableNonceBlockhash); @@ -1597,7 +1597,7 @@ describe('SOL:', function () { publicKey: testData.keys.durableNoncePubKey, secretKey: testData.keys.durableNoncePrivKey, }, - })) as SolSweepTxs; + })) as MPCSweepTxs; unsignedSweepTxn.should.not.be.empty(); unsignedSweepTxn.txRequests[0].transactions[0].unsignedTx.should.hasOwnProperty('serializedTx'); @@ -1785,14 +1785,14 @@ describe('SOL:', function () { startingScanIndex: 1, endingScanIndex: 4, durableNonces: durableNonces, - })) as SolTxs; + })) as MPCTxs; res.should.not.be.empty(); res.transactions.length.should.equal(2); res.lastScanIndex.should.equal(3); const txn1 = res.transactions[0]; const latestBlockhashTxnDeserialize1 = new Transaction(coin); - latestBlockhashTxnDeserialize1.fromRawTransaction((txn1 as SolTx).serializedTx); + latestBlockhashTxnDeserialize1.fromRawTransaction((txn1 as MPCTx).serializedTx); const latestBlockhashTxnJson1 = latestBlockhashTxnDeserialize1.toJson(); const nonce1 = testData.SolResponses.getAccountInfoResponse.body.result.value.data.parsed.info.blockhash; @@ -1802,7 +1802,7 @@ describe('SOL:', function () { const txn2 = res.transactions[1]; const latestBlockhashTxnDeserialize2 = new Transaction(coin); - latestBlockhashTxnDeserialize2.fromRawTransaction((txn2 as SolTx).serializedTx); + latestBlockhashTxnDeserialize2.fromRawTransaction((txn2 as MPCTx).serializedTx); const latestBlockhashTxnJson2 = latestBlockhashTxnDeserialize2.toJson(); const nonce2 = testData.SolResponses.getAccountInfoResponse2.body.result.value.data.parsed.info.blockhash; diff --git a/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts b/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts index 78ee517043..ae032fb650 100644 --- a/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts +++ b/modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts @@ -1,9 +1,9 @@ import { Key, SerializedKeyPair } from 'openpgp'; import { IRequestTracer } from '../../../api'; -import { KeychainsTriplet } from '../../baseCoin'; +import { KeychainsTriplet, ParsedTransaction } from '../../baseCoin'; import { ApiKeyShare, Keychain } from '../../keychain'; import { ApiVersion, Memo, WalletType } from '../../wallet'; -import { EDDSA, GShare, SignShare } from '../../../account-lib/mpc/tss'; +import { EDDSA, GShare, SignShare, Signature } from '../../../account-lib/mpc/tss'; import { KeyShare } from './ecdsa'; import { Hash } from 'crypto'; import { EcdsaTypes } from '@bitgo/sdk-lib-mpc'; @@ -371,6 +371,91 @@ export interface BitgoGPGPublicKey { enterpriseId: string; } +export interface MPCTx { + serializedTx: string; + scanIndex: number; + coin?: string; + signableHex?: string; + derivationPath?: string; + parsedTx?: ParsedTransaction; + feeInfo?: { + fee: number; + feeString: string; + }; + coinSpecific?: { + firstValid?: number; + maxDuration?: number; + commonKeychain?: string; + lastScanIndex?: number; + }; +} + +export interface MPCRecoveryOptions { + userKey?: string; // Box A + backupKey?: string; // Box B + bitgoKey: string; // Box C - this is bitgo's xpub and will be used to derive their root address + recoveryDestination: string; + walletPassphrase?: string; + seed?: string; + index?: number; +} + +export interface MPCConsolidationRecoveryOptions { + userKey?: string; // Box A + backupKey?: string; // Box B + bitgoKey: string; // Box C + walletPassphrase?: string; + startingScanIndex?: number; // default to 1 (inclusive) + endingScanIndex?: number; // default to startingScanIndex + 20 (exclusive) + seed?: string; +} + +export interface MPCSweepTxs { + txRequests: RecoveryTxRequest[]; +} + +export interface RecoveryTxRequest { + walletCoin: string; + transactions: MPCUnsignedTx[] | OvcTransaction[]; +} + +export interface MPCUnsignedTx { + unsignedTx: MPCTx; + signatureShares: []; +} + +export interface MPCSweepRecoveryOptions { + signatureShares: SignatureShares[]; +} + +interface SignatureShares { + txRequest: RecoveryTxRequest; + tssVersion: string; + ovc: Ovc[]; +} + +interface OvcTransaction { + unsignedTx: MPCTx; + signatureShares: SignatureShareRecord[]; + signatureShare: SignatureShare; +} + +interface SignatureShare { + from: string; + to: string; + share: string; + publicShare: string; +} + +interface Ovc { + eddsaSignature: Signature; +} + +export interface MPCTxs { + transactions: MPCTx[]; + lastScanIndex: number; +} + export type BackupGpgKey = SerializedKeyPair | Key; /** diff --git a/modules/sdk-core/src/index.ts b/modules/sdk-core/src/index.ts index 5668a95884..2b68934316 100644 --- a/modules/sdk-core/src/index.ts +++ b/modules/sdk-core/src/index.ts @@ -9,7 +9,7 @@ import { EddsaUtils } from './bitgo/utils/tss/eddsa/eddsa'; export { EddsaUtils }; import { EcdsaUtils } from './bitgo/utils/tss/ecdsa/ecdsa'; export { EcdsaUtils }; -export { GShare, SignShare, YShare, Signature as EDDSASignature } from './account-lib/mpc/tss/eddsa/types'; +export { GShare, SignShare, YShare } from './account-lib/mpc/tss/eddsa/types'; export { TssEcdsaStep1ReturnMessage, TssEcdsaStep2ReturnMessage } from './bitgo/tss/types'; export { SShare } from './bitgo/tss/ecdsa/types'; import * as common from './common';