Merge pull request #639 from pinheadmz/watch
Wallet: require public key for watchonly
This commit is contained in:
commit
375965c8a6
@ -1,5 +1,13 @@
|
|||||||
# Bcoin Release Notes & Changelog
|
# Bcoin Release Notes & Changelog
|
||||||
|
|
||||||
|
## v1.0.x
|
||||||
|
|
||||||
|
### Wallet API changes
|
||||||
|
|
||||||
|
Creating a watch-only wallet now requires an `account-key` (or `accountKey`)
|
||||||
|
argument. This is to prevent bcoin from generating keys and addresses the user
|
||||||
|
can not spend from.
|
||||||
|
|
||||||
## v1.0.0
|
## v1.0.0
|
||||||
|
|
||||||
### Migration
|
### Migration
|
||||||
|
|||||||
@ -575,7 +575,7 @@ class Wallet extends EventEmitter {
|
|||||||
await this.unlock(passphrase);
|
await this.unlock(passphrase);
|
||||||
|
|
||||||
let key;
|
let key;
|
||||||
if (this.watchOnly && options.accountKey) {
|
if (this.watchOnly) {
|
||||||
key = options.accountKey;
|
key = options.accountKey;
|
||||||
|
|
||||||
if (typeof key === 'string')
|
if (typeof key === 'string')
|
||||||
|
|||||||
@ -25,6 +25,10 @@ const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt'
|
|||||||
const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp'
|
const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp'
|
||||||
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa';
|
+ 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa';
|
||||||
|
|
||||||
|
// abandon abandon... about key at m'/44'/0'/0'
|
||||||
|
const PUBKEY = 'xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhaw'
|
||||||
|
+ 'A7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj';
|
||||||
|
|
||||||
const enabled = true;
|
const enabled = true;
|
||||||
const workers = new WorkerPool({ enabled });
|
const workers = new WorkerPool({ enabled });
|
||||||
const wdb = new WalletDB({ workers });
|
const wdb = new WalletDB({ workers });
|
||||||
@ -1301,12 +1305,31 @@ describe('Wallet', function() {
|
|||||||
importedKey = key;
|
importedKey = key;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should require account key to create watch only wallet', async () => {
|
||||||
|
let err = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await wdb.create({
|
||||||
|
watchOnly: true
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(err);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
'Must add HD public keys to watch only wallet.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should import pubkey', async () => {
|
it('should import pubkey', async () => {
|
||||||
const key = KeyRing.generate();
|
const key = KeyRing.generate();
|
||||||
const pub = new KeyRing(key.publicKey);
|
const pub = new KeyRing(key.publicKey);
|
||||||
|
|
||||||
const wallet = await wdb.create({
|
const wallet = await wdb.create({
|
||||||
watchOnly: true
|
watchOnly: true,
|
||||||
|
accountKey: PUBKEY
|
||||||
});
|
});
|
||||||
|
|
||||||
await wallet.importKey('default', pub);
|
await wallet.importKey('default', pub);
|
||||||
@ -1322,7 +1345,8 @@ describe('Wallet', function() {
|
|||||||
const key = KeyRing.generate();
|
const key = KeyRing.generate();
|
||||||
|
|
||||||
const wallet = await wdb.create({
|
const wallet = await wdb.create({
|
||||||
watchOnly: true
|
watchOnly: true,
|
||||||
|
accountKey: PUBKEY
|
||||||
});
|
});
|
||||||
|
|
||||||
await wallet.importAddress('default', key.getAddress());
|
await wallet.importAddress('default', key.getAddress());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user