Skip to content

Commit 7d8edf6

Browse files
committed
wallet: check account ownership of bid TX when making reveal TX
Adds new method hasCoinByAccount(acct, hash, index) to txdb which returns true if the coin (hash, index) is owned by account (number). Adds this check to wallet.makeReveal() to prevent BIDs from other wallet accounts being included as inputs to a new REVEAL TX from a specific account.
1 parent 489d3f7 commit 7d8edf6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/wallet/txdb.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,20 @@ class TXDB {
22502250
});
22512251
}
22522252

2253+
/**
2254+
* Test whether an account owns a coin.
2255+
* @param {Number} acct
2256+
* @param {Hash} hash
2257+
* @param {Index} number
2258+
* @returns {Promise} - Returns Boolean.
2259+
*/
2260+
2261+
hasCoinByAccount(acct, hash, index) {
2262+
assert(typeof acct === 'number');
2263+
2264+
return this.bucket.has(layout.C.encode(acct, hash, index));
2265+
}
2266+
22532267
/**
22542268
* Get hashes of all transactions in the database.
22552269
* @param {Number} acct

lib/wallet/wallet.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,12 +1747,18 @@ class Wallet extends EventEmitter {
17471747
/**
17481748
* Make a reveal MTX.
17491749
* @param {String} name
1750+
* @param {String|Number} acct
17501751
* @returns {MTX}
17511752
*/
17521753

1753-
async makeReveal(name) {
1754+
async makeReveal(name, acct) {
17541755
assert(typeof name === 'string');
17551756

1757+
if (acct != null) {
1758+
assert((acct >>> 0) === acct || typeof acct === 'string');
1759+
acct = await this.getAccountIndex(acct);
1760+
}
1761+
17561762
if (!rules.verifyName(name))
17571763
throw new Error('Invalid name.');
17581764

@@ -1789,6 +1795,9 @@ class Wallet extends EventEmitter {
17891795
if (!coin)
17901796
continue;
17911797

1798+
if (acct != null && !await this.txdb.hasCoinByAccount(acct, hash, index))
1799+
continue;
1800+
17921801
// Is local?
17931802
if (coin.height < ns.height)
17941803
continue;
@@ -1828,7 +1837,8 @@ class Wallet extends EventEmitter {
18281837
*/
18291838

18301839
async _createReveal(name, options) {
1831-
const mtx = await this.makeReveal(name);
1840+
const acct = options ? options.account : null;
1841+
const mtx = await this.makeReveal(name, acct);
18321842
await this.fill(mtx, options);
18331843
return this.finalize(mtx, options);
18341844
}

0 commit comments

Comments
 (0)