@harmony-js/account
Advanced tools
Comparing version 0.1.3 to 0.1.4
/// <reference types="bn.js" /> | ||
import { BN, Signature } from '@harmony-js/crypto'; | ||
import { ChainID, ChainType } from '@harmony-js/utils'; | ||
import { HttpProvider, WSProvider, RPCRequestPayload } from '@harmony-js/network'; | ||
import { HttpProvider, WSProvider } from '@harmony-js/network'; | ||
import { TransasctionReceipt } from '@harmony-js/transaction'; | ||
interface Web3TxPrams { | ||
import { Account } from './account'; | ||
export interface WalletsInterfaces { | ||
[key: string]: Account; | ||
} | ||
export interface Web3TxPrams { | ||
id?: string; | ||
@@ -38,7 +42,5 @@ from?: string; | ||
getHdWallet(mnemonic: string): void; | ||
send(...args: [RPCRequestPayload<any>, any]): void; | ||
sendAsync(...args: [RPCRequestPayload<any>, any]): void; | ||
getAccounts(cb?: Function): string[]; | ||
getPrivateKey(address: string, cb?: Function): any; | ||
signTransaction(txParams: any | Web3TxPrams, cb: Function): string | undefined; | ||
signTransaction(txParams: any | Web3TxPrams): Promise<string>; | ||
getAddress(idx?: number): string; | ||
@@ -49,3 +51,2 @@ getAddresses(): string[]; | ||
} | ||
export {}; | ||
//# sourceMappingURL=hdnode.d.ts.map |
@@ -80,30 +80,2 @@ "use strict"; | ||
}; | ||
HDNode.prototype.send = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var method = args[0].method; | ||
var newMethod = method; | ||
if (method.startsWith('eth')) { | ||
newMethod = method.replace('eth', 'hmy'); | ||
} | ||
args[0].method = newMethod; | ||
var id = args[0].id; | ||
if (newMethod === 'hmy_accounts') { | ||
args[1](null, { | ||
result: this.getAccounts(), | ||
id: id, | ||
jsonrpc: '2.0', | ||
}); | ||
} | ||
this.provider.send(args[0], args[1]); | ||
}; | ||
HDNode.prototype.sendAsync = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
this.send.apply(this, tslib_1.__spread(args)); | ||
}; | ||
// tslint:disable-next-line: ban-types | ||
@@ -133,27 +105,43 @@ HDNode.prototype.getAccounts = function (cb) { | ||
}; | ||
HDNode.prototype.signTransaction = function (txParams, cb) { | ||
var from = crypto_1.getAddress(txParams.from).checksum; | ||
var to = crypto_1.getAddress(txParams.to).checksum; | ||
var gasLimit = utils_1.isHex(txParams.gasLimit) | ||
? txParams.gasLimit | ||
: new utils_1.Unit(txParams.gasLimit).asWei().toWei(); | ||
var gasPrice = utils_1.isHex(txParams.gasPrice) | ||
? txParams.gasPrice | ||
: new utils_1.Unit(txParams.gasPrice).asWei().toWei(); | ||
var value = utils_1.isHex(txParams.value) | ||
? txParams.value | ||
: utils_1.numberToHex(txParams.value); | ||
var nonce = utils_1.isHex(txParams.nonce) | ||
? txParams.nonce | ||
: utils_1.numberToHex(txParams.nonce); | ||
var prv = this.wallets[from].privateKey; | ||
var tx = new transaction_1.Transaction(tslib_1.__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
tx.getRLPUnsigned(); | ||
if (prv) { | ||
var rawTransaction = transaction_1.RLPSign(tx, prv)[1]; | ||
if (cb) { | ||
cb(null, rawTransaction); | ||
} | ||
return rawTransaction; | ||
} | ||
// tslint:disable-next-line: ban-types | ||
HDNode.prototype.signTransaction = function (txParams) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var from, accountNonce, to, gasLimit, gasPrice, value, nonce, data, prv, signerAccount, tx, signed; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
from = txParams.from | ||
? crypto_1.getAddress(txParams.from).checksum | ||
: '0x'; | ||
return [4 /*yield*/, this.messenger.send('hmy_getTransactionCount', [from, 'latest'], 'hmy')]; | ||
case 1: | ||
accountNonce = _a.sent(); | ||
to = txParams.to ? crypto_1.getAddress(txParams.to).checksum : '0x'; | ||
gasLimit = txParams.gas !== undefined && utils_1.isHex(txParams.gas) | ||
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei() | ||
new utils_1.Unit('1000000').asWei().toWei() | ||
: new utils_1.Unit('0').asWei().toWei(); | ||
gasPrice = txParams.gasPrice !== undefined && utils_1.isHex(txParams.gasPrice) | ||
? // ? new Unit(txParams.gasPrice).asWei().toWei() | ||
new utils_1.Unit('2').asGwei().toWei() | ||
: new utils_1.Unit('0').asWei().toWei(); | ||
value = txParams.value !== undefined && utils_1.isHex(txParams.value) | ||
? txParams.value | ||
: new utils_1.Unit('0').asWei().toWei(); | ||
nonce = txParams.nonce !== undefined && utils_1.isHex(txParams.nonce) | ||
? Number.parseInt(utils_1.hexToNumber(txParams.nonce), 10) | ||
: Number.parseInt(utils_1.hexToNumber(accountNonce.result), 10); | ||
data = txParams.data !== undefined && utils_1.isHex(txParams.data) | ||
? txParams.data | ||
: '0x'; | ||
prv = this.wallets[from].privateKey; | ||
signerAccount = new account_1.Account(prv, this.messenger); | ||
tx = new transaction_1.Transaction(tslib_1.__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce, data: data }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
return [4 /*yield*/, signerAccount.signTransaction(tx)]; | ||
case 2: | ||
signed = _a.sent(); | ||
return [2 /*return*/, signed.getRawTransaction()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -160,0 +148,0 @@ HDNode.prototype.getAddress = function (idx) { |
@@ -778,30 +778,2 @@ /** | ||
}; | ||
HDNode.prototype.send = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var method = args[0].method; | ||
var newMethod = method; | ||
if (method.startsWith('eth')) { | ||
newMethod = method.replace('eth', 'hmy'); | ||
} | ||
args[0].method = newMethod; | ||
var id = args[0].id; | ||
if (newMethod === 'hmy_accounts') { | ||
args[1](null, { | ||
result: this.getAccounts(), | ||
id: id, | ||
jsonrpc: '2.0', | ||
}); | ||
} | ||
this.provider.send(args[0], args[1]); | ||
}; | ||
HDNode.prototype.sendAsync = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
this.send.apply(this, __spread(args)); | ||
}; | ||
// tslint:disable-next-line: ban-types | ||
@@ -831,27 +803,43 @@ HDNode.prototype.getAccounts = function (cb) { | ||
}; | ||
HDNode.prototype.signTransaction = function (txParams, cb) { | ||
var from = crypto.getAddress(txParams.from).checksum; | ||
var to = crypto.getAddress(txParams.to).checksum; | ||
var gasLimit = utils.isHex(txParams.gasLimit) | ||
? txParams.gasLimit | ||
: new utils.Unit(txParams.gasLimit).asWei().toWei(); | ||
var gasPrice = utils.isHex(txParams.gasPrice) | ||
? txParams.gasPrice | ||
: new utils.Unit(txParams.gasPrice).asWei().toWei(); | ||
var value = utils.isHex(txParams.value) | ||
? txParams.value | ||
: utils.numberToHex(txParams.value); | ||
var nonce = utils.isHex(txParams.nonce) | ||
? txParams.nonce | ||
: utils.numberToHex(txParams.nonce); | ||
var prv = this.wallets[from].privateKey; | ||
var tx = new transaction.Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
tx.getRLPUnsigned(); | ||
if (prv) { | ||
var rawTransaction = transaction.RLPSign(tx, prv)[1]; | ||
if (cb) { | ||
cb(null, rawTransaction); | ||
} | ||
return rawTransaction; | ||
} | ||
// tslint:disable-next-line: ban-types | ||
HDNode.prototype.signTransaction = function (txParams) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var from, accountNonce, to, gasLimit, gasPrice, value, nonce, data, prv, signerAccount, tx, signed; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
from = txParams.from | ||
? crypto.getAddress(txParams.from).checksum | ||
: '0x'; | ||
return [4 /*yield*/, this.messenger.send('hmy_getTransactionCount', [from, 'latest'], 'hmy')]; | ||
case 1: | ||
accountNonce = _a.sent(); | ||
to = txParams.to ? crypto.getAddress(txParams.to).checksum : '0x'; | ||
gasLimit = txParams.gas !== undefined && utils.isHex(txParams.gas) | ||
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei() | ||
new utils.Unit('1000000').asWei().toWei() | ||
: new utils.Unit('0').asWei().toWei(); | ||
gasPrice = txParams.gasPrice !== undefined && utils.isHex(txParams.gasPrice) | ||
? // ? new Unit(txParams.gasPrice).asWei().toWei() | ||
new utils.Unit('2').asGwei().toWei() | ||
: new utils.Unit('0').asWei().toWei(); | ||
value = txParams.value !== undefined && utils.isHex(txParams.value) | ||
? txParams.value | ||
: new utils.Unit('0').asWei().toWei(); | ||
nonce = txParams.nonce !== undefined && utils.isHex(txParams.nonce) | ||
? Number.parseInt(utils.hexToNumber(txParams.nonce), 10) | ||
: Number.parseInt(utils.hexToNumber(accountNonce.result), 10); | ||
data = txParams.data !== undefined && utils.isHex(txParams.data) | ||
? txParams.data | ||
: '0x'; | ||
prv = this.wallets[from].privateKey; | ||
signerAccount = new Account(prv, this.messenger); | ||
tx = new transaction.Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce, data: data }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
return [4 /*yield*/, signerAccount.signTransaction(tx)]; | ||
case 2: | ||
signed = _a.sent(); | ||
return [2 /*return*/, signed.getRawTransaction()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -858,0 +846,0 @@ HDNode.prototype.getAddress = function (idx) { |
@@ -7,3 +7,3 @@ /** | ||
import { generatePrivateKey, getAddressFromPrivateKey, getPubkeyFromPrivateKey, encrypt, decrypt, getAddress, bip39, hdkey } from '@harmony-js/crypto'; | ||
import { isPrivateKey, add0xToString, hexToNumber, isAddress, HDPath, isHttp, isWs, Unit, isHex, numberToHex } from '@harmony-js/utils'; | ||
import { isPrivateKey, add0xToString, hexToNumber, isAddress, HDPath, isHttp, isWs, Unit, isHex } from '@harmony-js/utils'; | ||
import { RLPSign, Transaction } from '@harmony-js/transaction'; | ||
@@ -775,30 +775,2 @@ | ||
}; | ||
HDNode.prototype.send = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var method = args[0].method; | ||
var newMethod = method; | ||
if (method.startsWith('eth')) { | ||
newMethod = method.replace('eth', 'hmy'); | ||
} | ||
args[0].method = newMethod; | ||
var id = args[0].id; | ||
if (newMethod === 'hmy_accounts') { | ||
args[1](null, { | ||
result: this.getAccounts(), | ||
id: id, | ||
jsonrpc: '2.0', | ||
}); | ||
} | ||
this.provider.send(args[0], args[1]); | ||
}; | ||
HDNode.prototype.sendAsync = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
this.send.apply(this, __spread(args)); | ||
}; | ||
// tslint:disable-next-line: ban-types | ||
@@ -828,27 +800,43 @@ HDNode.prototype.getAccounts = function (cb) { | ||
}; | ||
HDNode.prototype.signTransaction = function (txParams, cb) { | ||
var from = getAddress(txParams.from).checksum; | ||
var to = getAddress(txParams.to).checksum; | ||
var gasLimit = isHex(txParams.gasLimit) | ||
? txParams.gasLimit | ||
: new Unit(txParams.gasLimit).asWei().toWei(); | ||
var gasPrice = isHex(txParams.gasPrice) | ||
? txParams.gasPrice | ||
: new Unit(txParams.gasPrice).asWei().toWei(); | ||
var value = isHex(txParams.value) | ||
? txParams.value | ||
: numberToHex(txParams.value); | ||
var nonce = isHex(txParams.nonce) | ||
? txParams.nonce | ||
: numberToHex(txParams.nonce); | ||
var prv = this.wallets[from].privateKey; | ||
var tx = new Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
tx.getRLPUnsigned(); | ||
if (prv) { | ||
var rawTransaction = RLPSign(tx, prv)[1]; | ||
if (cb) { | ||
cb(null, rawTransaction); | ||
} | ||
return rawTransaction; | ||
} | ||
// tslint:disable-next-line: ban-types | ||
HDNode.prototype.signTransaction = function (txParams) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var from, accountNonce, to, gasLimit, gasPrice, value, nonce, data, prv, signerAccount, tx, signed; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
from = txParams.from | ||
? getAddress(txParams.from).checksum | ||
: '0x'; | ||
return [4 /*yield*/, this.messenger.send('hmy_getTransactionCount', [from, 'latest'], 'hmy')]; | ||
case 1: | ||
accountNonce = _a.sent(); | ||
to = txParams.to ? getAddress(txParams.to).checksum : '0x'; | ||
gasLimit = txParams.gas !== undefined && isHex(txParams.gas) | ||
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei() | ||
new Unit('1000000').asWei().toWei() | ||
: new Unit('0').asWei().toWei(); | ||
gasPrice = txParams.gasPrice !== undefined && isHex(txParams.gasPrice) | ||
? // ? new Unit(txParams.gasPrice).asWei().toWei() | ||
new Unit('2').asGwei().toWei() | ||
: new Unit('0').asWei().toWei(); | ||
value = txParams.value !== undefined && isHex(txParams.value) | ||
? txParams.value | ||
: new Unit('0').asWei().toWei(); | ||
nonce = txParams.nonce !== undefined && isHex(txParams.nonce) | ||
? Number.parseInt(hexToNumber(txParams.nonce), 10) | ||
: Number.parseInt(hexToNumber(accountNonce.result), 10); | ||
data = txParams.data !== undefined && isHex(txParams.data) | ||
? txParams.data | ||
: '0x'; | ||
prv = this.wallets[from].privateKey; | ||
signerAccount = new Account(prv, this.messenger); | ||
tx = new Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce, data: data }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
return [4 /*yield*/, signerAccount.signTransaction(tx)]; | ||
case 2: | ||
signed = _a.sent(); | ||
return [2 /*return*/, signed.getRawTransaction()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -855,0 +843,0 @@ HDNode.prototype.getAddress = function (idx) { |
@@ -775,30 +775,2 @@ /** | ||
}; | ||
HDNode.prototype.send = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var method = args[0].method; | ||
var newMethod = method; | ||
if (method.startsWith('eth')) { | ||
newMethod = method.replace('eth', 'hmy'); | ||
} | ||
args[0].method = newMethod; | ||
var id = args[0].id; | ||
if (newMethod === 'hmy_accounts') { | ||
args[1](null, { | ||
result: this.getAccounts(), | ||
id: id, | ||
jsonrpc: '2.0', | ||
}); | ||
} | ||
this.provider.send(args[0], args[1]); | ||
}; | ||
HDNode.prototype.sendAsync = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
this.send.apply(this, __spread(args)); | ||
}; | ||
// tslint:disable-next-line: ban-types | ||
@@ -828,27 +800,43 @@ HDNode.prototype.getAccounts = function (cb) { | ||
}; | ||
HDNode.prototype.signTransaction = function (txParams, cb) { | ||
var from = crypto.getAddress(txParams.from).checksum; | ||
var to = crypto.getAddress(txParams.to).checksum; | ||
var gasLimit = utils.isHex(txParams.gasLimit) | ||
? txParams.gasLimit | ||
: new utils.Unit(txParams.gasLimit).asWei().toWei(); | ||
var gasPrice = utils.isHex(txParams.gasPrice) | ||
? txParams.gasPrice | ||
: new utils.Unit(txParams.gasPrice).asWei().toWei(); | ||
var value = utils.isHex(txParams.value) | ||
? txParams.value | ||
: utils.numberToHex(txParams.value); | ||
var nonce = utils.isHex(txParams.nonce) | ||
? txParams.nonce | ||
: utils.numberToHex(txParams.nonce); | ||
var prv = this.wallets[from].privateKey; | ||
var tx = new transaction.Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
tx.getRLPUnsigned(); | ||
if (prv) { | ||
var rawTransaction = transaction.RLPSign(tx, prv)[1]; | ||
if (cb) { | ||
cb(null, rawTransaction); | ||
} | ||
return rawTransaction; | ||
} | ||
// tslint:disable-next-line: ban-types | ||
HDNode.prototype.signTransaction = function (txParams) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var from, accountNonce, to, gasLimit, gasPrice, value, nonce, data, prv, signerAccount, tx, signed; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
from = txParams.from | ||
? crypto.getAddress(txParams.from).checksum | ||
: '0x'; | ||
return [4 /*yield*/, this.messenger.send('hmy_getTransactionCount', [from, 'latest'], 'hmy')]; | ||
case 1: | ||
accountNonce = _a.sent(); | ||
to = txParams.to ? crypto.getAddress(txParams.to).checksum : '0x'; | ||
gasLimit = txParams.gas !== undefined && utils.isHex(txParams.gas) | ||
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei() | ||
new utils.Unit('1000000').asWei().toWei() | ||
: new utils.Unit('0').asWei().toWei(); | ||
gasPrice = txParams.gasPrice !== undefined && utils.isHex(txParams.gasPrice) | ||
? // ? new Unit(txParams.gasPrice).asWei().toWei() | ||
new utils.Unit('2').asGwei().toWei() | ||
: new utils.Unit('0').asWei().toWei(); | ||
value = txParams.value !== undefined && utils.isHex(txParams.value) | ||
? txParams.value | ||
: new utils.Unit('0').asWei().toWei(); | ||
nonce = txParams.nonce !== undefined && utils.isHex(txParams.nonce) | ||
? Number.parseInt(utils.hexToNumber(txParams.nonce), 10) | ||
: Number.parseInt(utils.hexToNumber(accountNonce.result), 10); | ||
data = txParams.data !== undefined && utils.isHex(txParams.data) | ||
? txParams.data | ||
: '0x'; | ||
prv = this.wallets[from].privateKey; | ||
signerAccount = new Account(prv, this.messenger); | ||
tx = new transaction.Transaction(__assign({}, txParams, { from: from, to: to, gasLimit: gasLimit, gasPrice: gasPrice, value: value, nonce: nonce, data: data }), this.messenger, "INITIALIZED" /* INTIALIZED */); | ||
return [4 /*yield*/, signerAccount.signTransaction(tx)]; | ||
case 2: | ||
signed = _a.sent(); | ||
return [2 /*return*/, signed.getRawTransaction()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -855,0 +843,0 @@ HDNode.prototype.getAddress = function (idx) { |
{ | ||
"name": "@harmony-js/account", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "account and wallet for harmony", | ||
@@ -21,9 +21,9 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@harmony-js/core": "0.1.3", | ||
"@harmony-js/core": "0.1.4", | ||
"@harmony-js/crypto": "0.1.0", | ||
"@harmony-js/network": "0.1.1", | ||
"@harmony-js/transaction": "0.1.1", | ||
"@harmony-js/transaction": "0.1.4", | ||
"@harmony-js/utils": "0.1.0" | ||
}, | ||
"gitHead": "4bb13c1ca30438e8bc906afe2c1fa794fbf84cd9" | ||
"gitHead": "1a0a5300c7261e0a9abab96dada48a3e1c2fb7f0" | ||
} |
@@ -11,14 +11,8 @@ import {bip39, hdkey, getAddress, BN, Signature} from '@harmony-js/crypto'; | ||
isHex, | ||
numberToHex, | ||
hexToNumber, | ||
} from '@harmony-js/utils'; | ||
import {Messenger, HttpProvider, WSProvider} from '@harmony-js/network'; | ||
import { | ||
Messenger, | ||
HttpProvider, | ||
WSProvider, | ||
RPCRequestPayload, | ||
} from '@harmony-js/network'; | ||
import { | ||
Transaction, | ||
TxStatus, | ||
RLPSign, | ||
TransasctionReceipt, | ||
@@ -28,7 +22,7 @@ } from '@harmony-js/transaction'; | ||
interface WalletsInterfaces { | ||
export interface WalletsInterfaces { | ||
[key: string]: Account; | ||
} | ||
interface Web3TxPrams { | ||
export interface Web3TxPrams { | ||
id?: string; | ||
@@ -131,26 +125,3 @@ from?: string; | ||
} | ||
send(...args: [RPCRequestPayload<any>, any]) { | ||
const method = args[0].method; | ||
let newMethod: string = method; | ||
if (method.startsWith('eth')) { | ||
newMethod = method.replace('eth', 'hmy'); | ||
} | ||
args[0].method = newMethod; | ||
const {id} = args[0]; | ||
if (newMethod === 'hmy_accounts') { | ||
args[1](null, { | ||
result: this.getAccounts(), | ||
id, | ||
jsonrpc: '2.0', | ||
}); | ||
} | ||
this.provider.send(args[0], args[1]); | ||
} | ||
sendAsync(...args: [RPCRequestPayload<any>, any]) { | ||
this.send(...args); | ||
} | ||
// tslint:disable-next-line: ban-types | ||
@@ -178,32 +149,47 @@ getAccounts(cb?: Function) { | ||
} | ||
signTransaction(txParams: any | Web3TxPrams, cb: Function) { | ||
const from: string = getAddress(txParams.from).checksum; | ||
const to: string = getAddress(txParams.to).checksum; | ||
const gasLimit = isHex(txParams.gasLimit) | ||
? txParams.gasLimit | ||
: new Unit(txParams.gasLimit).asWei().toWei(); | ||
const gasPrice = isHex(txParams.gasPrice) | ||
? txParams.gasPrice | ||
: new Unit(txParams.gasPrice).asWei().toWei(); | ||
const value = isHex(txParams.value) | ||
? txParams.value | ||
: numberToHex(txParams.value); | ||
const nonce = isHex(txParams.nonce) | ||
? txParams.nonce | ||
: numberToHex(txParams.nonce); | ||
// tslint:disable-next-line: ban-types | ||
async signTransaction(txParams: any | Web3TxPrams) { | ||
const from: string = txParams.from | ||
? getAddress(txParams.from).checksum | ||
: '0x'; | ||
const accountNonce = await this.messenger.send( | ||
'hmy_getTransactionCount', | ||
[from, 'latest'], | ||
'hmy', | ||
); | ||
const to: string = txParams.to ? getAddress(txParams.to).checksum : '0x'; | ||
const gasLimit = | ||
txParams.gas !== undefined && isHex(txParams.gas) | ||
? // ? new Unit(hexToNumber(txParams.gas)).asWei().toWei() | ||
new Unit('1000000').asWei().toWei() | ||
: new Unit('0').asWei().toWei(); | ||
const gasPrice = | ||
txParams.gasPrice !== undefined && isHex(txParams.gasPrice) | ||
? // ? new Unit(txParams.gasPrice).asWei().toWei() | ||
new Unit('2').asGwei().toWei() | ||
: new Unit('0').asWei().toWei(); | ||
const value = | ||
txParams.value !== undefined && isHex(txParams.value) | ||
? txParams.value | ||
: new Unit('0').asWei().toWei(); | ||
const nonce = | ||
txParams.nonce !== undefined && isHex(txParams.nonce) | ||
? Number.parseInt(hexToNumber(txParams.nonce), 10) | ||
: Number.parseInt(hexToNumber(accountNonce.result), 10); | ||
const data = | ||
txParams.data !== undefined && isHex(txParams.data) | ||
? txParams.data | ||
: '0x'; | ||
const prv = this.wallets[from].privateKey; | ||
const signerAccount = new Account(prv, this.messenger); | ||
const tx = new Transaction( | ||
{...txParams, from, to, gasLimit, gasPrice, value, nonce}, | ||
{...txParams, from, to, gasLimit, gasPrice, value, nonce, data}, | ||
this.messenger, | ||
TxStatus.INTIALIZED, | ||
); | ||
tx.getRLPUnsigned(); | ||
if (prv) { | ||
const rawTransaction = RLPSign(tx, prv)[1]; | ||
if (cb) { | ||
cb(null, rawTransaction); | ||
} | ||
return rawTransaction; | ||
} | ||
const signed = await signerAccount.signTransaction(tx); | ||
return signed.getRawTransaction(); | ||
} | ||
@@ -210,0 +196,0 @@ getAddress(idx?: number) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
367663
4375
+ Added@harmony-js/contract@0.1.4(transitive)
+ Added@harmony-js/core@0.1.4(transitive)
+ Added@harmony-js/transaction@0.1.4(transitive)
- Removed@harmony-js/contract@0.1.3(transitive)
- Removed@harmony-js/core@0.1.3(transitive)
- Removed@harmony-js/transaction@0.1.1(transitive)
Updated@harmony-js/core@0.1.4