2016-07-14 20:43:15 +03:00
|
|
|
var rlp = require('rlp');
|
|
|
|
|
2016-07-16 06:47:35 +03:00
|
|
|
var Contract = require('./lib/contract.js');
|
2016-07-22 00:06:42 +03:00
|
|
|
var SigningKey = require('./lib/signing-key.js');
|
|
|
|
var Wallet = require('./lib/wallet.js');
|
2016-07-14 20:43:15 +03:00
|
|
|
|
2016-07-16 06:47:35 +03:00
|
|
|
var utils = require('./lib/utils.js');
|
|
|
|
var BN = utils.BN;
|
2016-07-14 20:43:15 +03:00
|
|
|
|
|
|
|
|
2016-07-16 06:47:35 +03:00
|
|
|
var exportUtils = {};
|
2016-07-22 00:06:42 +03:00
|
|
|
utils.defineProperty(Wallet, 'utils', exportUtils);
|
2016-07-14 20:43:15 +03:00
|
|
|
|
2016-07-22 00:06:42 +03:00
|
|
|
utils.defineProperty(exportUtils, 'BN', BN);
|
|
|
|
utils.defineProperty(exportUtils, 'Buffer', Buffer);
|
2016-07-14 20:43:15 +03:00
|
|
|
|
2016-07-22 00:06:42 +03:00
|
|
|
utils.defineProperty(exportUtils, 'sha3', utils.sha3);
|
|
|
|
utils.defineProperty(exportUtils, 'sha256', utils.sha256);
|
2016-07-14 20:43:15 +03:00
|
|
|
|
2016-07-16 06:47:35 +03:00
|
|
|
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
2016-07-22 00:06:42 +03:00
|
|
|
utils.defineProperty(exportUtils, 'getContractAddress', function(transaction) {
|
|
|
|
return SigningKey.getAddress('0x' + utils.sha3(rlp.encode([
|
|
|
|
utils.hexOrBuffer(utils.getAddress(transaction.from)),
|
2016-07-16 06:47:35 +03:00
|
|
|
utils.hexOrBuffer(utils.hexlify(transaction.nonce, 'nonce'))
|
2016-07-22 00:06:42 +03:00
|
|
|
])).slice(12).toString('hex'));
|
2016-07-14 20:43:15 +03:00
|
|
|
});
|
|
|
|
|
2016-07-22 00:06:42 +03:00
|
|
|
module.exports = Wallet;
|
2016-07-16 06:47:35 +03:00
|
|
|
|
|
|
|
|
2016-07-22 00:06:42 +03:00
|
|
|
utils.defineProperty(Wallet, 'getAddress', SigningKey.getAddress);
|
|
|
|
utils.defineProperty(Wallet, 'getIcapAddress', SigningKey.getIcapAddress);
|
2016-07-14 20:43:15 +03:00
|
|
|
|
|
|
|
module.exports = Wallet;
|