Skip to content

Commit

Permalink
SC-7 Account login key check improvement (#47)
Browse files Browse the repository at this point in the history
* fix: remove vesting_balance_type from vesting_balance_withdraw_operation

* chore: rebuild

* chore(release): 0.6.5

* sync with master (#31)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* Fix merge develop merge conflicts (#42)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* sync with master (#31) (#32)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* 0.6.4 release (#36)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* Sonar (#22)

* ci: sonarlint

* feat: add param to vesting_balance_create

vesting_balance_type new requirement due to gpos additions on mainnet

WAL-250

* build(packages): several packages updated

some potential breaking changes, test impact on updates

* docs: readme update indicating patch change reason

PJL-23

* build: rebuild

merged tag overlapping which adds sonarcloud files (no source code impact) and added new tag bump

PJL-23

* chore: rebuild and merge security PR in

* fix: use string instead of bool for balance type in vesting create

* build: rebuild

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement: vesting_balance_type enum

* improvement: re-add policy items

* improvement: re-add policy items

* fix: add export data for vesting balance type

* Revert "fix: add export data for vesting balance type"

This reverts commit 24138cc.

* fix: remove wrong export item

* fix: add vesting_policy_initializer to exports

* feat(account_update): added value.update_last_voting_time

added value.update_last_voting_time to account_update serializer extensions object

WAL-281

* feat: add balance_type to vesting balance withdraw

* chore: sync with master

some different versions existed, selected latest version from conflicts and reinstalled hence the
update to shrinkwrap file.

* chore: rebuild

* chore(release): 0.6.4

* fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)

* Revert "fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)" (#38)

This reverts commit 6d3293b.

Co-authored-by: Roshan Syed <[email protected]>
Co-authored-by: mseaward <[email protected]>
Co-authored-by: jotprabh1 <[email protected]>
Co-authored-by: Bobinson K B <[email protected]>

* Fix merge conflicts (#43)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* sync with master (#31) (#32)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* 0.6.4 release (#36)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* Sonar (#22)

* ci: sonarlint

* feat: add param to vesting_balance_create

vesting_balance_type new requirement due to gpos additions on mainnet

WAL-250

* build(packages): several packages updated

some potential breaking changes, test impact on updates

* docs: readme update indicating patch change reason

PJL-23

* build: rebuild

merged tag overlapping which adds sonarcloud files (no source code impact) and added new tag bump

PJL-23

* chore: rebuild and merge security PR in

* fix: use string instead of bool for balance type in vesting create

* build: rebuild

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement: vesting_balance_type enum

* improvement: re-add policy items

* improvement: re-add policy items

* fix: add export data for vesting balance type

* Revert "fix: add export data for vesting balance type"

This reverts commit 24138cc.

* fix: remove wrong export item

* fix: add vesting_policy_initializer to exports

* feat(account_update): added value.update_last_voting_time

added value.update_last_voting_time to account_update serializer extensions object

WAL-281

* feat: add balance_type to vesting balance withdraw

* chore: sync with master

some different versions existed, selected latest version from conflicts and reinstalled hence the
update to shrinkwrap file.

* chore: rebuild

* chore(release): 0.6.4

* fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)

* Revert "fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)" (#38)

This reverts commit 6d3293b.

* resolved merge conflict

Co-authored-by: Roshan Syed <[email protected]>
Co-authored-by: mseaward <[email protected]>
Co-authored-by: jotprabh1 <[email protected]>
Co-authored-by: Bobinson K B <[email protected]>

* improvement(accountlogin.js): improve the AccountLogin.js (Login) class

Provide support for prefix assignment in checkKeys without requiring to instantiate the entire
chainStore and websocket connection. Document all function within the AccountLogin class.

#45

* test: adjust scripts, packages, test files

resolve issue regarding deprecation in the test suite such that tests can be run. Repair issues with
tests related to AccountLogin. Replace instances of 'GPH' with 'PPY' where code references a public
key with a 'GPH' prefix (non-Peerplays indicator).

#46, #45

* build: rebuild files in lieu of recent changes

* refactor(accountlogin.js): resolve sonarcloud code smells

* sync with master (#31)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* Fix merge develop merge conflicts (#42)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* sync with master (#31) (#32)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* 0.6.4 release (#36)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* Sonar (#22)

* ci: sonarlint

* feat: add param to vesting_balance_create

vesting_balance_type new requirement due to gpos additions on mainnet

WAL-250

* build(packages): several packages updated

some potential breaking changes, test impact on updates

* docs: readme update indicating patch change reason

PJL-23

* build: rebuild

merged tag overlapping which adds sonarcloud files (no source code impact) and added new tag bump

PJL-23

* chore: rebuild and merge security PR in

* fix: use string instead of bool for balance type in vesting create

* build: rebuild

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement: vesting_balance_type enum

* improvement: re-add policy items

* improvement: re-add policy items

* fix: add export data for vesting balance type

* Revert "fix: add export data for vesting balance type"

This reverts commit 24138cc.

* fix: remove wrong export item

* fix: add vesting_policy_initializer to exports

* feat(account_update): added value.update_last_voting_time

added value.update_last_voting_time to account_update serializer extensions object

WAL-281

* feat: add balance_type to vesting balance withdraw

* chore: sync with master

some different versions existed, selected latest version from conflicts and reinstalled hence the
update to shrinkwrap file.

* chore: rebuild

* chore(release): 0.6.4

* fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)

* Revert "fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)" (#38)

This reverts commit 6d3293b.

Co-authored-by: Roshan Syed <[email protected]>
Co-authored-by: mseaward <[email protected]>
Co-authored-by: jotprabh1 <[email protected]>
Co-authored-by: Bobinson K B <[email protected]>

* Fix merge conflicts (#43)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* sync with master (#31) (#32)

* Pbsa develop (#28)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* PJL-24: security patches (#26)

* Sonar (#22)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* ci(packages): update packages to latest where possible

two audit reports cannot be resolved as we cannot update a packages dependencies ourself. They are
dev only issues so production is safe from these warnings

PJL-24-security-patches

* build: rebuild after npm package upgrades

* chore: rebuild after pbsa-develop merge sync and conflict resolution

* Patch npmignore file (#29)

* chore(release): 0.6.2

* chore(release): 0.6.3

* chore(.npmignore): patch npmignore file

ignore irrelevant files when publishing to NPM

* Update readme with sonar scan badges (#30)

* chore(release): 0.6.2

* chore(release): 0.6.3

* docs(readne): update readme to show status reports of repo

status reports are automatically synced/updated with sonarcloud

* 0.6.4 release (#36)

* ci: sonarlint

WAL-223

* chore: rebuild

* chore(release): 0.6.1

* Sonar (#22)

* ci: sonarlint

* feat: add param to vesting_balance_create

vesting_balance_type new requirement due to gpos additions on mainnet

WAL-250

* build(packages): several packages updated

some potential breaking changes, test impact on updates

* docs: readme update indicating patch change reason

PJL-23

* build: rebuild

merged tag overlapping which adds sonarcloud files (no source code impact) and added new tag bump

PJL-23

* chore: rebuild and merge security PR in

* fix: use string instead of bool for balance type in vesting create

* build: rebuild

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement(vesting_balance_create): use enumerator for balance_type

vesting_balance_create balance_type parameter using enumerator now for serializing the transaction
to match the blockchain type for balance_type

* improvement: vesting_balance_type enum

* improvement: re-add policy items

* improvement: re-add policy items

* fix: add export data for vesting balance type

* Revert "fix: add export data for vesting balance type"

This reverts commit 24138cc.

* fix: remove wrong export item

* fix: add vesting_policy_initializer to exports

* feat(account_update): added value.update_last_voting_time

added value.update_last_voting_time to account_update serializer extensions object

WAL-281

* feat: add balance_type to vesting balance withdraw

* chore: sync with master

some different versions existed, selected latest version from conflicts and reinstalled hence the
update to shrinkwrap file.

* chore: rebuild

* chore(release): 0.6.4

* fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)

* Revert "fix: remove vesting_balance_type from vesting_balance_withdraw_operation (#37)" (#38)

This reverts commit 6d3293b.

* resolved merge conflict

Co-authored-by: Roshan Syed <[email protected]>
Co-authored-by: mseaward <[email protected]>
Co-authored-by: jotprabh1 <[email protected]>
Co-authored-by: Bobinson K B <[email protected]>

* improvement(accountlogin.js): improve the AccountLogin.js (Login) class

Provide support for prefix assignment in checkKeys without requiring to instantiate the entire
chainStore and websocket connection. Document all function within the AccountLogin class.

#45

* test: adjust scripts, packages, test files

resolve issue regarding deprecation in the test suite such that tests can be run. Repair issues with
tests related to AccountLogin. Replace instances of 'GPH' with 'PPY' where code references a public
key with a 'GPH' prefix (non-Peerplays indicator).

#46, #45

* build: rebuild files in lieu of recent changes

* refactor(accountlogin.js): resolve sonarcloud code smells

* chore(npm): sync with pbsa-dev

new version was cut prior and changes needed on this branch

* build: rebuild after syncing with pbsa-develop

* build: rebuild after syncing with pbsa-develop

Co-authored-by: jotprabh1 <[email protected]>
Co-authored-by: Adrian Metzler <[email protected]>
Co-authored-by: Roshan Syed <[email protected]>
Co-authored-by: Bobinson K B <[email protected]>
  • Loading branch information
5 people authored Jan 29, 2020
1 parent 8b0affa commit 7ae7247
Show file tree
Hide file tree
Showing 16 changed files with 1,439 additions and 1,167 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.6.5](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.0...v0.6.5) (2019-12-24)


### Bug Fixes

* remove vesting_balance_type from vesting_balance_withdraw_operation ([1ba7f2f](https://github.com/peerplays-network/peerplaysjs-lib/commit/1ba7f2f810bbf48c6cca88a4cd4869ed7d034c6b))

### [0.6.4](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.2...v0.6.4) (2019-12-16)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The auths object should contain the auth arrays from the account object. An exam
```json
{
active: [
["GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
["PPY∂5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
]
}
```
Expand Down
71 changes: 66 additions & 5 deletions build/peerplaysjs-lib.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/peerplaysjs-lib.min.js

Large diffs are not rendered by default.

65 changes: 63 additions & 2 deletions dist/chain/src/AccountLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,49 @@ var AccountLogin = function () {
function AccountLogin() {
_classCallCheck(this, AccountLogin);

var state = { loggedIn: false, roles: ['active', 'owner', 'memo'] };
var state = { loggedIn: false, roles: ['owner', 'active', 'memo'] };
this.get = (0, _state.get)(state);
this.set = (0, _state.set)(state);

this.subs = {};
}

/**
* Subscribe to provided item.
*
* @param {*} cb
* @memberof AccountLogin
*/


AccountLogin.prototype.addSubscription = function addSubscription(cb) {
this.subs[cb] = cb;
};

/**
* Set the roles. Used for key generation.
*
* @param {Array} roles - ['owner', 'active', 'memo']
* @memberof AccountLogin
*/


AccountLogin.prototype.setRoles = function setRoles(roles) {
this.set('roles', roles);
};

/**
* Call this function to generate Peerplays user account keys.
*
* @param {String} accountName - The users' account name (username).
* @param {String} password - The users' password.
* @param {Array} roles - ['owner', 'active', 'memo']
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Object} - Keys object: `{privKeys, pubKeys}`
* @memberof AccountLogin
*/


AccountLogin.prototype.generateKeys = function generateKeys(accountName, password, roles, prefix) {
if (!accountName || !password) {
throw new Error('Account name or password required');
Expand All @@ -64,12 +92,32 @@ var AccountLogin = function () {
return { privKeys: privKeys, pubKeys: pubKeys };
};

/**
* Accepts an account name {string}, password {string}, and an auths object. We loop over the
* provided auths whichcontains the keys associated with the account we are working with.
*
* We verify that the keys provided (which are pulled from the blockchain prior) match up with
* keys we generate with the provided account name and password.
*
* This function is dependant upon the roles array being specified in the correct order:
* 1. owner
* 2. active
* 3. memo
*
* @param {Object} {accountName, password, auths} - string, string, array
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Boolean}
* @memberof AccountLogin
*/


AccountLogin.prototype.checkKeys = function checkKeys(_ref) {
var _this = this;

var accountName = _ref.accountName,
password = _ref.password,
auths = _ref.auths;
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'PPY';

if (!accountName || !password || !auths) {
throw new Error('checkKeys: Missing inputs');
Expand All @@ -81,11 +129,12 @@ var AccountLogin = function () {
var _loop = function _loop(i, len) {
var role = roles[i];

var _generateKeys = _this.generateKeys(accountName, password, [role]),
var _generateKeys = _this.generateKeys(accountName, password, [role], prefix),
privKeys = _generateKeys.privKeys,
pubKeys = _generateKeys.pubKeys;

auths[role].forEach(function (roleKey) {
// Check if the active key matches
if (roleKey[0] === pubKeys[role]) {
hasKey = true;
_this.set(role, { priv: privKeys[role], pub: pubKeys[role] });
Expand All @@ -106,6 +155,18 @@ var AccountLogin = function () {
return hasKey;
};

/**
* Call this function and provide a valid transaction object to sign it with
* the users' Active key.
* Pre-requisite is that AccountLogin.js (`Login`) has had its roles set and
* the users' keys were generated with AccountLogin.js (`Login`)
*
* @param {Object} tr - Transaction object built via TransactionBuilder.js
* @returns {Object} tr - Transaction object that was passed in but signed.
* @memberof AccountLogin
*/


AccountLogin.prototype.signTransaction = function signTransaction(tr) {
var _this2 = this;

Expand Down
4 changes: 2 additions & 2 deletions dist/ecc/src/PublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ var PublicKey = function () {
};

/**
@arg {string} public_key - like GPHXyz...
@arg {string} address_prefix - like GPH
@arg {string} public_key - like PPYXyz...
@arg {string} address_prefix - like PPY
@throws {Error} if public key is invalid
@return PublicKey
*/
Expand Down
66 changes: 61 additions & 5 deletions lib/chain/src/AccountLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,43 @@ let _keyCachePub = {};

class AccountLogin {
constructor() {
let state = {loggedIn: false, roles: ['active', 'owner', 'memo']};
let state = {loggedIn: false, roles: ['owner', 'active', 'memo']};
this.get = get(state);
this.set = set(state);

this.subs = {};
}

/**
* Subscribe to provided item.
*
* @param {*} cb
* @memberof AccountLogin
*/
addSubscription(cb) {
this.subs[cb] = cb;
}

/**
* Set the roles. Used for key generation.
*
* @param {Array} roles - ['owner', 'active', 'memo']
* @memberof AccountLogin
*/
setRoles(roles) {
this.set('roles', roles);
}

/**
* Call this function to generate Peerplays user account keys.
*
* @param {String} accountName - The users' account name (username).
* @param {String} password - The users' password.
* @param {Array} roles - ['owner', 'active', 'memo']
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Object} - Keys object: `{privKeys, pubKeys}`
* @memberof AccountLogin
*/
generateKeys(accountName, password, roles, prefix) {
if (!accountName || !password) {
throw new Error('Account name or password required');
Expand All @@ -43,15 +65,34 @@ class AccountLogin {
_keyCachePriv[seed] = pkey;

privKeys[role] = pkey;
pubKeys[role] = _keyCachePub[seed] ? _keyCachePub[seed] : pkey.toPublicKey().toString(prefix);
pubKeys[role] = _keyCachePub[seed]
? _keyCachePub[seed]
: pkey.toPublicKey().toString(prefix);

_keyCachePub[seed] = pubKeys[role];
});

return {privKeys, pubKeys};
}

checkKeys({accountName, password, auths}) {
/**
* Accepts an account name {string}, password {string}, and an auths object. We loop over the
* provided auths whichcontains the keys associated with the account we are working with.
*
* We verify that the keys provided (which are pulled from the blockchain prior) match up with
* keys we generate with the provided account name and password.
*
* This function is dependant upon the roles array being specified in the correct order:
* 1. owner
* 2. active
* 3. memo
*
* @param {Object} {accountName, password, auths} - string, string, array
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Boolean}
* @memberof AccountLogin
*/
checkKeys({accountName, password, auths}, prefix = 'PPY') {
if (!accountName || !password || !auths) {
throw new Error('checkKeys: Missing inputs');
}
Expand All @@ -61,8 +102,11 @@ class AccountLogin {

for (let i = 0, len = roles.length; i < len; i++) {
let role = roles[i];
let {privKeys, pubKeys} = this.generateKeys(accountName, password, [role]);
const {privKeys, pubKeys} = this.generateKeys(accountName, password, [
role
], prefix);
auths[role].forEach((roleKey) => {
// Check if the active key matches
if (roleKey[0] === pubKeys[role]) {
hasKey = true;
this.set(role, {priv: privKeys[role], pub: pubKeys[role]});
Expand All @@ -79,6 +123,16 @@ class AccountLogin {
return hasKey;
}

/**
* Call this function and provide a valid transaction object to sign it with
* the users' Active key.
* Pre-requisite is that AccountLogin.js (`Login`) has had its roles set and
* the users' keys were generated with AccountLogin.js (`Login`)
*
* @param {Object} tr - Transaction object built via TransactionBuilder.js
* @returns {Object} tr - Transaction object that was passed in but signed.
* @memberof AccountLogin
*/
signTransaction(tr) {
let hasKey = false;

Expand All @@ -93,7 +147,9 @@ class AccountLogin {
});

if (!hasKey) {
throw new Error('You do not have any private keys to sign this transaction');
throw new Error(
'You do not have any private keys to sign this transaction'
);
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions lib/ecc/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Elliptic curve cryptography functions (ECC)
# ECC

## Elliptic curve cryptography functions (ECC)

Private Key, Public Key, Cryptographic Signature, AES, Encryption / Decryption

```js
import {Address, Aes, PrivateKey, PublicKey, Signature} from "@graphene/ecc"
```

# Configure
## Configure

Update `./.npmrc` if you need to change something:

```bash
@graphene/ecc:default_address_prefix = GPH
```

# See Also
## See Also

* [Address](./src/address.js)
* [Aes](./src/aes.js)
* [PrivateKey](./src/PrivateKey.js)
Expand Down
4 changes: 2 additions & 2 deletions lib/ecc/src/PublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class PublicKey {
}

/**
@arg {string} public_key - like GPHXyz...
@arg {string} address_prefix - like GPH
@arg {string} public_key - like PPYXyz...
@arg {string} address_prefix - like PPY
@throws {Error} if public key is invalid
@return PublicKey
*/
Expand Down
Loading

0 comments on commit 7ae7247

Please sign in to comment.