Created
January 17, 2018 22:52
-
-
Save epexa/70279264f85b8dac389587da54a81a61 to your computer and use it in GitHub Desktop.
steem-js first example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/steem.min.js"></script> | |
<script> | |
steem.api.setOptions({ url: 'https://api.steemit.com' }); | |
// поиск аккаунта по юзернейму | |
var usernames = ['epexa', 'epexa2']; | |
steem.api.lookupAccountNames(usernames, function(err, result) { | |
//console.log(err, result); | |
if ( ! err) { | |
result.forEach(function(item) { | |
if (item) console.log('lookupAccountNames', 'username: [', item.name, '] id: [', item.id, ']'); | |
else console.log('lookupAccountNames', 'account not found!'); | |
}); | |
} | |
else console.error(err); | |
}); | |
// получение инфы о аккаунте | |
var accounts = [ 'epexa', 'epexa2' ]; | |
steem.api.getAccounts(accounts, function(err, result) { | |
//console.log(err, result); | |
if ( ! err) { | |
result.forEach(function(item) { | |
console.log('getAccounts', 'username: [', item.name, '] id: [', item.id, ']'); | |
}); | |
} | |
else console.error(err); | |
}); | |
// вывод юзернеймов аккаунтов по поисковой фразе | |
var searchAccountsQuery = 'epe'; | |
var limitResults = 10; | |
steem.api.lookupAccounts(searchAccountsQuery, limitResults, function(err, result) { | |
//console.log(err, result); | |
if ( ! err) { | |
result.forEach(function(item) { | |
console.log('lookupAccounts', 'username: [', item, ']'); | |
}); | |
} | |
else console.error(err); | |
}); | |
// получение юзернейма по публичному постинг или активному ключу | |
var publicKeys = ['STM6...', 'STM5...']; | |
steem.api.getKeyReferences(publicKeys, function(err, result) { | |
//console.log(err, result); | |
if ( ! err) { | |
result.forEach(function(item) { | |
console.log('getKeyReferences', 'username: [', item[0], ']'); | |
}); | |
} | |
else console.error(err); | |
}); | |
// получение ключей | |
var username = 'epexa'; | |
var password = 'P5J...'; // master password | |
var roles = ['owner', 'active', 'posting', 'memo']; // optional parameter, if not specify, then all keys will return | |
var keys = steem.auth.getPrivateKeys(username, password, roles); | |
console.log('getPrivateKeys', keys); | |
// получение приватоного ключа | |
var username = 'epexa'; | |
var password = 'P5J...'; // master password | |
var role = 'posting'; // private key type, one of owner, active, posting, memo | |
var privateKey = steem.auth.toWif(username, password, role); | |
console.log('toWif', privateKey); | |
// проверка приватного ключа (active, memo, owner, posting) на валидный формат | |
var privWif = '5K...'; | |
var resultIsWif = steem.auth.isWif(privWif); | |
console.log('isWif', resultIsWif); | |
// проверка приватного ключа (active, memo, owner, posting) на валидность | |
var privWif = '5K...'; // private key | |
var pubWif = 'STM6...'; // public key | |
var resultWifIsValid = steem.auth.wifIsValid(privWif, pubWif); | |
console.log('wifIsValid', resultWifIsValid); | |
// получение публичного ключа (active, memo, owner, posting) на валидность | |
var privWif = '5K...'; // private key | |
var resultWifToPublic = steem.auth.wifToPublic(privWif, pubWif); | |
console.log('wifToPublic', resultWifToPublic); | |
// проверка на соответсвие юзернейма, мастер-пароля, и публичного ключа | |
var username = 'epexa'; | |
var password = 'P5...'; // master password | |
// object in which the key type public key (active, memo, owner, posting), and the value of the array in the array itself is the public key | |
var auths = { | |
posting: [['STM6...']] | |
}; | |
var verifyResult = steem.auth.verify(username, password, auths); | |
console.log('verify', verifyResult); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment