diff --git a/src/universal-dapp.js b/src/universal-dapp.js index d57aaf7160..5bf713f026 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -82,13 +82,18 @@ module.exports = class UniversalDApp extends UdappApi { this.transactionContextAPI = transactionContextAPI } - createVMAccount (privateKey, balance, cb) { - return new Promise((resolve, reject) => { - if (executionContext.getProvider() !== 'vm') return reject('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') - this._addAccount(privateKey, balance) - privateKey = Buffer.from(privateKey, 'hex') - resolve('0x' + ethJSUtil.privateToAddress(privateKey).toString('hex')) - }) + /** + * Create a VM Account + * @param {{privateKey: string, balance: string}} newAccount The new account to create + */ + createVMAccount (newAccount) { + const { privateKey, balance } = newAccount + if (executionContext.getProvider() !== 'vm') { + throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') + } + this._addAccount(privateKey, balance) + const privKey = Buffer.from(privateKey, 'hex') + return '0x' + ethJSUtil.privateToAddress(privKey).toString('hex') } newAccount (password, passwordPromptCb, cb) { diff --git a/test-browser/plugin/plugin.js b/test-browser/plugin/plugin.js index 62bb971037..2d9a90c029 100644 --- a/test-browser/plugin/plugin.js +++ b/test-browser/plugin/plugin.js @@ -44,7 +44,10 @@ window.onload = function () { }) document.querySelector('input#testaccountcreation').addEventListener('click', function () { - extension.call('udapp', 'createVMAccount', ['71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', '0x56BC75E2D63100000'], + extension.call('udapp', 'createVMAccount', [{ + privateKey: '71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', + balance: '0x56BC75E2D63100000' + }], function (error, result) { console.log(error, result) }) }) diff --git a/test-browser/plugin/remix.js b/test-browser/plugin/remix.js index 415f678711..182ff97906 100644 --- a/test-browser/plugin/remix.js +++ b/test-browser/plugin/remix.js @@ -64,7 +64,10 @@ window.onload = function () { action: 'request', key: 'udapp', type: 'createVMAccount', - value: ['71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', '0x56BC75E2D63100000'], + value: [{ + privateKey: '71975fbf7fe448e004ac7ae54cad0a383c3906055a75468714156a07385e96ce', + balance: '0x56BC75E2D63100000' + }], id: 38 }), '*') })