Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/bitcore-wallet-service/src/bws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/bitcore-wallet-service/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
24 changes: 14 additions & 10 deletions packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 23 additions & 1 deletion packages/bitcore-wallet-service/src/lib/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import util from 'util';
import {
BitcoreLib as Bitcore,
BitcoreLibCash as BitcoreCash,
Expand Down Expand Up @@ -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);
Expand All @@ -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, '-')}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generating the session ID on the client like this:
${txp.id}:${derivationPath.replace(/\//g, '-')}-input${i}
Because of that, the fetch always returns null.

Could you update it to:
const tssSigSeshId = `${txp.id}:${address.path.replace(/\//g, '-')}-input1`;

Using -input1 is enough here, I tested it and it works correctly.

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);

Expand Down
3 changes: 3 additions & 0 deletions packages/bitcore-wallet-service/src/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down