diff --git a/package.json b/package.json index a3d8e5dcf1d64c03d4e83c482b7dcb3fb0aea04b..8b4c4e4461419a0d0efe5ed4814d22ed37bf95a5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "homepage": "https://github.com/steemit/steem-js#readme", "dependencies": { + "@steemit/rpc-auth": "^1.1.0", "bigi": "^1.4.2", "bluebird": "^3.4.6", "browserify-aes": "^1.0.6", diff --git a/src/api/index.js b/src/api/index.js index 67e67f54f363f8f9f92ed1b0a9bda6bb88d2b879..0c30e756f5042993cde39e83531a8d12d9dded89 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -15,6 +15,9 @@ import { import { jsonRpc } from './transports/http'; +import { + sign as signRequest +} from '@steemit/rpc-auth'; class Steem extends EventEmitter { constructor(options = {}) { @@ -154,6 +157,23 @@ class Steem extends EventEmitter { .then(res => { callback(null, res) }, err => { callback(err) }); } + signedCall(method, params, account, key, callback) { + if (this._transportType !== 'http') { + callback(new Error('RPC methods can only be called when using http transport')); + return; + } + const id = ++this.seqNo; + let request; + try { + request = signRequest({method, params, id}, account, [key]); + } catch (error) { + callback(error); + return; + } + jsonRpc(this.options.uri, request) + .then(res => { callback(null, res) }, err => { callback(err) }); + } + setOptions(options) { Object.assign(this.options, options); this._setLogger(options); diff --git a/yarn.lock b/yarn.lock index faa350414326f5fd77123d0080da375c4105a1cd..c653b3f936ce1a558fef04ef6674b04ae9996773 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,16 @@ # yarn lockfile v1 +"@steemit/libcrypto@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@steemit/libcrypto/-/libcrypto-1.0.1.tgz#c31ab3e5deb667628169b3d54d746b015de31a79" + +"@steemit/rpc-auth@^1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@steemit/rpc-auth/-/rpc-auth-1.1.0.tgz#4170c04d928ef37af5bdbde3f517ef74909480bd" + dependencies: + "@steemit/libcrypto" "^1.0.1" + abbrev@1: version "1.1.0" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"