-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add & remove a key in key_auth #213
Conversation
Created an issue on steem repo steemit/steem#1272 |
From abit in above issue:
|
Awesome it's finally working with Abit suggestion :) |
src/broadcast/helpers.js
Outdated
weight = 1, | ||
cb | ||
) => { | ||
api.getAccountsAsync([username]).then(([userAccount]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this fails the callback won't be called, you want to use one of either promises or callbacks all the way
src/broadcast/helpers.js
Outdated
role = 'posting', | ||
cb | ||
) => { | ||
api.getAccountsAsync([username]).then(([userAccount]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
src/broadcast/helpers.js
Outdated
} | ||
} | ||
|
||
// key not exist in authorized list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is slightly confusing to me, too many variables, but all good
src/broadcast/helpers.js
Outdated
) => { | ||
api.getAccounts([username], (err, [userAccount]) => { | ||
if (err) { return cb(err, null); } | ||
if (!userAccount) { return cb('Invalid account name', null); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, the first argument should always be an Error instance
src/broadcast/helpers.js
Outdated
|
||
exports = module.exports = steemBroadcast => { | ||
steemBroadcast.addAccountAuth = ( | ||
activeWif, | ||
username, | ||
authorizedUsername, | ||
role = "posting", | ||
role = 'posting', | ||
weight = 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the account has a different threshold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the account has a weight_threshold
of 2 then the newly added key will not be able to broadcast alone if the weight is not set to 2. I can change the default weight to use the same value as weight_threshold
.
examples/add-key-auth.js
Outdated
username, | ||
'STM88CPfhCmeEzCnvC1Cjc3DNd1DTjkMcmihih8SSxmm4LBqRq5Y9', // @fabien public posting WIF | ||
'posting', | ||
1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would love for these arguments to be named instead of positional
@sneak i've changed the arguments to be named instead of positional and now if weight is not specified it take the weight_thresold value as default weight. |
awesome. in general i prefer named arguments vs positional for anything that takes more than 1-2 params. using names like signingKey instead of activeWif shows which key is which, too. it makes it possible to audit calling code for correctness without knowing the api being called into. |
Yes it make sense, on the rest of the library both solutions (named and positional) are possible example:
I've renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding and removing a key work
I have some trouble making this working and interested to have your feedback.
I created 2 helpers functions:
addKeyAuth
andremoveKeyAuth
for adding and removing a key inside user accountkey_auths
array. It's using the operationaccount_update
to do this change (steem-js/src/broadcast/helpers.js
Lines 109 to 118 in d81a9a3
We have already the helpers functions
addAccountAuth
andremoveAccountAuth
that working well, but for some reason when i try to add a key instead of an account i got the error "Missing Active Authority". I've verified the private active WIF and account_update operation payload and they are valid.Any idea what is wrong?