From 55c103458b4fa87c42d9da093da72402c5d7b812 Mon Sep 17 00:00:00 2001 From: Konstantin Shuplenkov Date: Fri, 17 Dec 2021 17:24:32 +0300 Subject: [PATCH 1/5] feat(dpp): add readOnly flag to IdentityPublicKey --- .../js-dpp/lib/identity/IdentityPublicKey.js | 28 +++++++++++++++++++ .../unit/identity/IdentityPublicKey.spec.js | 15 ++++++++++ 2 files changed, 43 insertions(+) diff --git a/packages/js-dpp/lib/identity/IdentityPublicKey.js b/packages/js-dpp/lib/identity/IdentityPublicKey.js index 1ef68b8e236..3faf052baf5 100644 --- a/packages/js-dpp/lib/identity/IdentityPublicKey.js +++ b/packages/js-dpp/lib/identity/IdentityPublicKey.js @@ -26,6 +26,10 @@ class IdentityPublicKey { if (Object.prototype.hasOwnProperty.call(rawIdentityPublicKey, 'data')) { this.setData(rawIdentityPublicKey.data); } + + if (Object.prototype.hasOwnProperty.call(rawIdentityPublicKey, 'readOnly')) { + this.setReadOnly(rawIdentityPublicKey.readOnly); + } } /** @@ -133,6 +137,27 @@ class IdentityPublicKey { return this.securityLevel; } + /** + * Set readOnly flag + * + * @param {boolean} readOnly + * @return {IdentityPublicKey} + */ + setReadOnly(readOnly) { + this.readOnly = readOnly; + + return this; + } + + /** + * Get readOnly flag + * + * @return boolean + */ + getReadOnly() { + return this.readOnly; + } + /** * Get the original public key hash * @@ -162,6 +187,7 @@ class IdentityPublicKey { purpose: this.getPurpose(), securityLevel: this.getSecurityLevel(), data: this.getData(), + readOnly: this.getReadOnly(), }; } @@ -185,6 +211,7 @@ class IdentityPublicKey { * @property {number} purpose * @property {number} securityLevel * @property {Buffer} data + * @property {boolean} readOnly */ /** @@ -194,6 +221,7 @@ class IdentityPublicKey { * @property {number} securityLevel * @property {number} type * @property {string} data + * @property {boolean} readOnly */ IdentityPublicKey.TYPES = { diff --git a/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js b/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js index 33dd92ee7d7..49e5f99d427 100644 --- a/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js +++ b/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js @@ -12,6 +12,7 @@ describe('IdentityPublicKey', () => { data: Buffer.from('AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH', 'base64'), purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION, securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER, + readOnly: false, }; publicKey = new IdentityPublicKey(rawPublicKey); @@ -109,6 +110,20 @@ describe('IdentityPublicKey', () => { }); }); + describe('#getReadOnly', () => { + it('should return readOnly', () => { + expect(publicKey.getReadOnly()).to.equal(rawPublicKey.readOnly); + }); + }); + + describe('#setReadOnly', () => { + it('should set readOnly', () => { + publicKey.setReadOnly(true); + + expect(publicKey.readOnly).to.equal(true); + }); + }); + describe('#hash', () => { it('should return original public key hash', () => { const result = publicKey.hash(); From f533227ee5b321763e64a540b5c3729769d665b9 Mon Sep 17 00:00:00 2001 From: Konstantin Shuplenkov Date: Fri, 17 Dec 2021 17:37:21 +0300 Subject: [PATCH 2/5] feat(dpp): add readOnly flag to IdentityPublicKey --- packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js b/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js index 49e5f99d427..ee3db5301c9 100644 --- a/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js +++ b/packages/js-dpp/test/unit/identity/IdentityPublicKey.spec.js @@ -161,6 +161,7 @@ describe('IdentityPublicKey', () => { data: 'AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH', purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION, securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER, + readOnly: false, }); }); }); From a564e8578bce5d1a17179c2161688a89b596a684 Mon Sep 17 00:00:00 2001 From: Konstantin Shuplenkov Date: Fri, 17 Dec 2021 17:59:24 +0300 Subject: [PATCH 3/5] feat(dpp): data contract --- .../test/fixtures/getIdentityCreateTransitionFixture.js | 1 + packages/js-dpp/schema/identity/publicKey.json | 7 ++++++- packages/js-dpp/test/unit/identity/Identity.spec.js | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js b/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js index 2c68ad19c7e..a289514d523 100644 --- a/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js +++ b/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js @@ -26,6 +26,7 @@ module.exports = function getIdentityCreateTransitionFixture(oneTimePrivateKey = data: Buffer.from('AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di', 'base64'), purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION, securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER, + readOnly: false, }, ], }; diff --git a/packages/js-dpp/schema/identity/publicKey.json b/packages/js-dpp/schema/identity/publicKey.json index 7492cc88fb2..983d7ab38f9 100644 --- a/packages/js-dpp/schema/identity/publicKey.json +++ b/packages/js-dpp/schema/identity/publicKey.json @@ -38,7 +38,12 @@ "description": "Public key security level. 0 - Master, 1 - Critical, 2 - High, 3 - Medium", "$comment": "It can't be changed after adding a key" }, - "data": true + "data": true, + "readOnly": { + "type": "boolean", + "description": "Read only flag", + "$comment": "It can't be changed after adding a key" + } }, "allOf": [ { diff --git a/packages/js-dpp/test/unit/identity/Identity.spec.js b/packages/js-dpp/test/unit/identity/Identity.spec.js index 76b839d8fea..79dee958e5b 100644 --- a/packages/js-dpp/test/unit/identity/Identity.spec.js +++ b/packages/js-dpp/test/unit/identity/Identity.spec.js @@ -26,6 +26,7 @@ describe('Identity', () => { data: Buffer.alloc(36).fill('a'), purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION, securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER, + readOnly: false, }, ], balance: 0, @@ -152,6 +153,7 @@ describe('Identity', () => { data: rawIdentity.publicKeys[0].data.toString('base64'), purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION, securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER, + readOnly: false, }, ], balance: 0, From 6e7794fceac074e0dddf6ad547596aa8a2437aba Mon Sep 17 00:00:00 2001 From: Konstantin Shuplenkov Date: Mon, 20 Dec 2021 16:36:18 +0300 Subject: [PATCH 4/5] fix(dpp): readOnly property data contract description --- packages/js-dpp/schema/identity/publicKey.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/js-dpp/schema/identity/publicKey.json b/packages/js-dpp/schema/identity/publicKey.json index 983d7ab38f9..640dd2834d3 100644 --- a/packages/js-dpp/schema/identity/publicKey.json +++ b/packages/js-dpp/schema/identity/publicKey.json @@ -41,8 +41,8 @@ "data": true, "readOnly": { "type": "boolean", - "description": "Read only flag", - "$comment": "It can't be changed after adding a key" + "description": "Read only", + "$comment": "Identity public key can't be modified with readOnly set to true. It can't be changed." } }, "allOf": [ From d0217774a9fa51c5fb6931445695cc69b2372f78 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 21 Dec 2021 14:20:44 +0700 Subject: [PATCH 5/5] Update publicKey.json --- packages/js-dpp/schema/identity/publicKey.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js-dpp/schema/identity/publicKey.json b/packages/js-dpp/schema/identity/publicKey.json index 640dd2834d3..d4cbd3b7194 100644 --- a/packages/js-dpp/schema/identity/publicKey.json +++ b/packages/js-dpp/schema/identity/publicKey.json @@ -42,7 +42,7 @@ "readOnly": { "type": "boolean", "description": "Read only", - "$comment": "Identity public key can't be modified with readOnly set to true. It can't be changed." + "$comment": "Identity public key can't be modified with readOnly set to true. It can’t be changed after adding a key" } }, "allOf": [