Skip to content

Commit

Permalink
JS - 0.9.74, HF 30 - Private messages; update getAccounts to support …
Browse files Browse the repository at this point in the history
…blockings
  • Loading branch information
1aerostorm committed Aug 30, 2024
1 parent 09114e6 commit 787afce
Show file tree
Hide file tree
Showing 8 changed files with 720 additions and 193 deletions.
113 changes: 91 additions & 22 deletions golos-lib-js/docs/files/msgs.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion golos-lib-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "golos-lib-js",
"version": "0.9.73",
"version": "0.9.74",
"description": "Golos-js the JavaScript library with API for GOLOS blockchain",
"main": "lib/index.js",
"scripts": {
Expand Down
29 changes: 25 additions & 4 deletions golos-lib-js/src/api/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ module.exports = [
{
"api": "database_api",
"method": "get_accounts",
"params": ["accountNames"]
"has_default_values": true,
"params": ["accountNames", `query=${EMPTY_OBJECT}`]
},
{
"api": "database_api",
Expand Down Expand Up @@ -679,7 +680,12 @@ module.exports = [
{
"api": "private_message",
"method": "get_thread",
"params": ["from", "to", "query"]
"has_default_values": true,
"params": [
"from_or_query",
`to=${EMPTY_STRING}`,
`opts=${EMPTY_OBJECT}`,
]
},
{
"api": "private_message",
Expand All @@ -695,12 +701,22 @@ module.exports = [
{
"api": "private_message",
"method": "get_contact_info",
"params": ["owner", "contact"]
"has_default_values": true,
"params": [
"owner_or_query",
`contact=${EMPTY_STRING}`,
]
},
{
"api": "private_message",
"method": "get_contacts",
"params": ["owner", "type", "limit", "offset"]
"has_default_values": true,
"params": [
"owner_or_query",
`type="unknown"`,
`limit=20`,
`offset=0`,
]
},
{
"api": "private_message",
Expand Down Expand Up @@ -793,4 +809,9 @@ module.exports = [
"method": "decrypt_comments",
"params": ["query={}"]
},
{
"api": "cryptor",
"method": "decrypt_messages",
"params": ["query={}"]
},
]
2 changes: 1 addition & 1 deletion golos-lib-js/src/auth/ecc/src/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function cryptoJsEncrypt(message, key, iv) {

/** @return {string} unique 64 bit unsigned number string. Being time based, this is careful to never choose the same nonce twice. This value could be recorded in the blockchain for a long time.
*/
function uniqueNonce() {
export function uniqueNonce() {
if(unique_nonce_entropy === null) {
const b = secureRandom.randomUint8Array(2)
unique_nonce_entropy = parseInt(b[0] << 8 | b[1], 10)
Expand Down
58 changes: 56 additions & 2 deletions golos-lib-js/src/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var bigi = require('bigi'),
PublicKey = require('./ecc/src/key_public'),
session = require('./session'),
multiSession = require('./multiSession'),
api = require('../api'),
golosApi = require('../api'),
hash = require('./ecc/src/hash');

var Auth = {};
Expand Down Expand Up @@ -97,7 +97,7 @@ Auth.loginAsync = function (name, password, callback) {
privateKeys[role] = PrivateKey.fromSeed(`${name}${role}${password}`).toString()
);
}
api.getAccountsAsync([name], (err, res) => {
golosApi.getAccounts([name], (err, res) => {
if (err) {
callback(err, null);
return;
Expand Down Expand Up @@ -128,6 +128,60 @@ Auth.loginAsync = function (name, password, callback) {

Auth.login = promisify(Auth.loginAsync);

// `keys` is object like:
// { posting: "private posting key" }
Auth.withNodeLogin = async function ({ account, keys,
call, dgp, api, sessionName }) {
if (!sessionName) sessionName = 'node_login'
if (!api) {
api = golosApi
}

if (!dgp) {
dgp = await api.getDynamicGlobalPropertiesAsync()
}

let resp

const { MultiSession } = multiSession
const ms = new MultiSession(sessionName)
const sessionData = ms.load()
let loginData = sessionData.getVal(account, 'login_data')
if (loginData) {
let resp = await call(loginData)
if (!resp.login_error) {
return resp
}
}

const { head_block_number, witness } = dgp

console.time('withNodeLogin - signData')
const signed = this.signData(head_block_number.toString(), keys)
console.timeEnd('withNodeLogin - signData')

// TODO: only 1st, because node supports only 1 key
const signature = Object.values(signed)[0]

loginData = {
account,
signed_data: {
head_block_number,
witness,
},
signature,
}

resp = await call(loginData)
if (resp.login_error) {
throw resp.login_error
}

sessionData.setVal(account, 'login_data', loginData).save()

return resp
}

Auth.toWif = function (name, password, role) {
var seed = name + role + password;
var brainKey = seed.trim().split(/[\t\n\v\f\r ]+/).join(' ');
Expand Down
Loading

0 comments on commit 787afce

Please sign in to comment.