diff --git a/packages/bitcore-wallet-service/src/bws.ts b/packages/bitcore-wallet-service/src/bws.ts index 6eec71b872..ab7dd76e40 100755 --- a/packages/bitcore-wallet-service/src/bws.ts +++ b/packages/bitcore-wallet-service/src/bws.ts @@ -34,6 +34,8 @@ if (config.https) { fs.readFileSync(config.CAinter2), fs.readFileSync(config.CAroot) ]; + } else if (config.certificateAuthorities) { + serverOpts.ca = config.certificateAuthorities.map(caPath => fs.readFileSync(caPath)); } } diff --git a/packages/bitcore-wallet-service/src/lib/common/utils.ts b/packages/bitcore-wallet-service/src/lib/common/utils.ts index 83b13f34f0..af75330135 100644 --- a/packages/bitcore-wallet-service/src/lib/common/utils.ts +++ b/packages/bitcore-wallet-service/src/lib/common/utils.ts @@ -365,6 +365,12 @@ export const Utils = { return 'testnet'; }, + getAddressNetworkForDbLookup(address, network) { + const generic = Utils.getGenericName(network); + if (generic === 'livenet') return address; + return `${address}:${generic}`; + }, + castToBool(input: any) { input = input?.toString(); if (input?.toLowerCase() === 'true' || input == '1') { diff --git a/packages/bitcore-wallet-service/src/lib/model/txproposal.ts b/packages/bitcore-wallet-service/src/lib/model/txproposal.ts index bc5e7c24a2..7b3c290b17 100644 --- a/packages/bitcore-wallet-service/src/lib/model/txproposal.ts +++ b/packages/bitcore-wallet-service/src/lib/model/txproposal.ts @@ -424,16 +424,20 @@ export class TxProposal implements ITxProposal { } getCurrentSignatures() { - const acceptedActions = _.filter(this.actions, a => { - return a.type == 'accept'; - }); - - return _.map(acceptedActions, x => { - return { - signatures: x.signatures, - xpub: x.xpub - }; - }); + const acceptedActions = this.actions.filter(a => a.type == 'accept'); + + const uniqueXpubs = new Set(); + const signatures = []; + for (const a of acceptedActions) { + // TSS will have multiple accept actions with the same xpub/signature (different copayerIds) + if (uniqueXpubs.has(a.xpub)) continue; + uniqueXpubs.add(a.xpub); + signatures.push({ + signatures: a.signatures, + xpub: a.xpub + }); + } + return signatures; } getRawTx() { diff --git a/packages/bitcore-wallet-service/src/lib/server.ts b/packages/bitcore-wallet-service/src/lib/server.ts index ea8dc4162f..f8b1e4d297 100644 --- a/packages/bitcore-wallet-service/src/lib/server.ts +++ b/packages/bitcore-wallet-service/src/lib/server.ts @@ -1,3 +1,4 @@ +import util from 'util'; import { BitcoreLib as Bitcore, BitcoreLibCash as BitcoreCash, @@ -3340,9 +3341,9 @@ export class WalletService implements IWalletService { const copayer = wallet.getCopayer(this.copayerId); + const xPubKey = wallet.tssKeyId ? wallet.clientDerivedPublicKey : copayer.xPubKey; try { - const xPubKey = wallet.tssKeyId ? wallet.clientDerivedPublicKey : copayer.xPubKey; if (!txp.sign(this.copayerId, opts.signatures, xPubKey)) { this.logw('Error signing transaction (BAD_SIGNATURES)'); this.logw('Client version:', this.clientVersion); @@ -3357,6 +3358,27 @@ export class WalletService implements IWalletService { return cb(ex); } + if (wallet.tssKeyId) { + try { + // Add the other copayers to the txp.copayers array + // so the client can see who participated in the signing. + const addrDbString = Utils.getAddressNetworkForDbLookup(txp.from || txp.inputs[0]?.address, wallet.network); + const address = await util.promisify(storage.fetchAddressByWalletId).call(storage, wallet.id, addrDbString); + const tssSigSeshId = `${txp.id}:${address.path.replace(/\//g, '-')}`; + const tssSigSession = await storage.fetchTssSigSession({ id: tssSigSeshId }); + if (!tssSigSession) { + throw new Error('TSS signature session not found'); + } + const copayerIds = tssSigSession.participants.map(p => p.copayerId); + for (const copayerId of copayerIds) { + if (copayerId === this.copayerId) continue; + txp.addAction(copayerId, 'accept', null, opts.signatures, xPubKey); + } + } catch (err) { + this.logw('Error finding accepting copayers for TSS txp: %o %o', txp.id, err); + } + } + this.storage.storeTx(this.walletId, txp, err => { if (err) return cb(err); diff --git a/packages/bitcore-wallet-service/src/lib/storage.ts b/packages/bitcore-wallet-service/src/lib/storage.ts index 118837f219..0c6b3787af 100644 --- a/packages/bitcore-wallet-service/src/lib/storage.ts +++ b/packages/bitcore-wallet-service/src/lib/storage.ts @@ -166,6 +166,9 @@ export class Storage { db.collection(collections.TSS_KEYGEN).createIndex({ id: 1 }, { unique: true }); + db.collection(collections.TSS_SIGN).createIndex({ + id: 1 + }, { unique: true }); } connect(opts, cb) {