diff --git a/package-lock.json b/package-lock.json index 558200c0578..de37d53a7d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1594,6 +1594,11 @@ "protocol-buffers-encodings": "^1.1.0" } }, + "node_modules/@dashevo/blake3": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@dashevo/blake3/-/blake3-2.1.5.tgz", + "integrity": "sha512-Rws+fmKuxrEbVPGIH3TdncFyKot8aVWJdBs09eabQQ+05W6x6+vsNt2omoS83TBLaVMW0iAtsrEz5EF12+6/5A==" + }, "node_modules/@dashevo/dapi": { "resolved": "packages/dapi", "link": true @@ -18550,6 +18555,7 @@ "license": "MIT", "dependencies": { "@apidevtools/json-schema-ref-parser": "^8.0.0", + "@dashevo/blake3": "^2.1.5", "@dashevo/dashcore-lib": "~0.19.26", "@dashevo/feature-flags-contract": "0.2.1", "@dashevo/re2-wasm": "~1.0.4", @@ -19951,6 +19957,11 @@ "protocol-buffers-encodings": "^1.1.0" } }, + "@dashevo/blake3": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@dashevo/blake3/-/blake3-2.1.5.tgz", + "integrity": "sha512-Rws+fmKuxrEbVPGIH3TdncFyKot8aVWJdBs09eabQQ+05W6x6+vsNt2omoS83TBLaVMW0iAtsrEz5EF12+6/5A==" + }, "@dashevo/dapi": { "version": "file:packages/dapi", "requires": { @@ -20694,6 +20705,7 @@ "@apidevtools/json-schema-ref-parser": "^8.0.0", "@babel/core": "^7.15.5", "@babel/preset-env": "^7.15.4", + "@dashevo/blake3": "^2.1.5", "@dashevo/dashcore-lib": "~0.19.26", "@dashevo/dashpay-contract": "0.4.1", "@dashevo/dpns-contract": "0.4.0", diff --git a/packages/dapi/lib/test/bootstrap.js b/packages/dapi/lib/test/bootstrap.js index 72c692e455c..76eaee8e59f 100644 --- a/packages/dapi/lib/test/bootstrap.js +++ b/packages/dapi/lib/test/bootstrap.js @@ -9,6 +9,8 @@ const chaiAsPromised = require('chai-as-promised'); const DashCoreOptions = require('@dashevo/dp-services-ctl/lib/services/dashCore/DashCoreOptions'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(sinonChai); use(chaiAsPromised); use(dirtyChai); @@ -50,6 +52,11 @@ if (process.env.SERVICE_IMAGE_CORE) { }); } +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/dashpay-contract/lib/test/bootstrap.js b/packages/dashpay-contract/lib/test/bootstrap.js index 461846fa5e7..6b3ec139ee4 100644 --- a/packages/dashpay-contract/lib/test/bootstrap.js +++ b/packages/dashpay-contract/lib/test/bootstrap.js @@ -4,9 +4,16 @@ const sinonChai = require('sinon-chai'); const { expect, use } = require('chai'); const dirtyChai = require('dirty-chai'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(dirtyChai); use(sinonChai); +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/dpns-contract/test/bootstrap.js b/packages/dpns-contract/test/bootstrap.js index 461846fa5e7..6b3ec139ee4 100644 --- a/packages/dpns-contract/test/bootstrap.js +++ b/packages/dpns-contract/test/bootstrap.js @@ -4,9 +4,16 @@ const sinonChai = require('sinon-chai'); const { expect, use } = require('chai'); const dirtyChai = require('dirty-chai'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(dirtyChai); use(sinonChai); +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/feature-flags-contract/test/bootstrap.js b/packages/feature-flags-contract/test/bootstrap.js index 461846fa5e7..6b3ec139ee4 100644 --- a/packages/feature-flags-contract/test/bootstrap.js +++ b/packages/feature-flags-contract/test/bootstrap.js @@ -4,9 +4,16 @@ const sinonChai = require('sinon-chai'); const { expect, use } = require('chai'); const dirtyChai = require('dirty-chai'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(dirtyChai); use(sinonChai); +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/js-dapi-client/lib/test/bootstrap.js b/packages/js-dapi-client/lib/test/bootstrap.js index dc85f196965..51c92014dca 100644 --- a/packages/js-dapi-client/lib/test/bootstrap.js +++ b/packages/js-dapi-client/lib/test/bootstrap.js @@ -4,10 +4,16 @@ const sinonChai = require('sinon-chai'); const dirtyChai = require('dirty-chai'); const chaiAsPromised = require('chai-as-promised'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(sinonChai); use(chaiAsPromised); use(dirtyChai); +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/names/register.spec.ts b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/names/register.spec.ts index eab823e77dd..95b88098ef6 100644 --- a/packages/js-dash-sdk/src/SDK/Client/Platform/methods/names/register.spec.ts +++ b/packages/js-dash-sdk/src/SDK/Client/Platform/methods/names/register.spec.ts @@ -57,7 +57,7 @@ describe('Platform', () => { expect(platformMock.documents.create.getCall(0).args[0]).to.deep.equal('dpns.preorder'); expect(platformMock.documents.create.getCall(0).args[1]).to.deep.equal(identityMock); expect(platformMock.documents.create.getCall(0).args[2].saltedDomainHash.toString('hex')).to.deep.equal( - 'df46c47179745ea18c0fdc95910372dca8810127acc9afe3c9b326b07555e6b4', + '0a7c796d4d76f0d536c4a6efdffa0647aac6e74239251a5c1c13dc5d4d414a98', ); expect(platformMock.documents.create.getCall(1).args).to.have.deep.members([ @@ -89,7 +89,7 @@ describe('Platform', () => { expect(platformMock.documents.create.getCall(0).args[0]).to.deep.equal('dpns.preorder'); expect(platformMock.documents.create.getCall(0).args[1]).to.deep.equal(identityMock); expect(platformMock.documents.create.getCall(0).args[2].saltedDomainHash.toString('hex')).to.deep.equal( - '04a52b75ca842ee9fb14f2cdd27aa0982b9b2cfb2c0e95f640ca3f0c24f1bb9a', + '23ded03e8006422aa5cd19003713e60c87902590084b3f1dbea26045a93c517d', ); expect(platformMock.documents.create.getCall(1).args).to.have.deep.members([ diff --git a/packages/js-dash-sdk/src/test/bootstrap.js b/packages/js-dash-sdk/src/test/bootstrap.js index 182411c1b28..02faa846c63 100644 --- a/packages/js-dash-sdk/src/test/bootstrap.js +++ b/packages/js-dash-sdk/src/test/bootstrap.js @@ -1,18 +1,28 @@ const dotenvSafe = require('dotenv-safe'); const path = require('path'); - const sinon = require('sinon'); const sinonChai = require('sinon-chai'); const { expect, use } = require('chai'); const dirtyChai = require('dirty-chai'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + dotenvSafe.config({ path: path.resolve(__dirname, '..', '..', '.env'), }); +before(async () => { + await initBlake3(); +}); + use(dirtyChai); use(sinonChai); +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/js-dash-sdk/src/test/karma/bootstrap.ts b/packages/js-dash-sdk/src/test/karma/bootstrap.ts index f579523ef71..946a7b55f81 100644 --- a/packages/js-dash-sdk/src/test/karma/bootstrap.ts +++ b/packages/js-dash-sdk/src/test/karma/bootstrap.ts @@ -4,9 +4,17 @@ import { use } from 'chai'; import dirtyChai from 'dirty-chai'; import sinonChai from 'sinon-chai'; +// @ts-ignore +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(dirtyChai); use(sinonChai); +// Initialize blake3 hashing for DPP +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/js-dpp/lib/DashPlatformProtocol.js b/packages/js-dpp/lib/DashPlatformProtocol.js index dd2d05046fa..a0a21f44f46 100644 --- a/packages/js-dpp/lib/DashPlatformProtocol.js +++ b/packages/js-dpp/lib/DashPlatformProtocol.js @@ -10,6 +10,7 @@ const DocumentFacade = require('./document/DocumentFacade'); const StateTransitionFacade = require('./stateTransition/StateTransitionFacade'); const IdentityFacade = require('./identity/IdentityFacade'); +const { initBlake3 } = require('./util/hash'); /** * @class DashPlatformProtocol @@ -43,36 +44,38 @@ class DashPlatformProtocol { return this.initialized; } - this.initialized = getRE2Class().then((RE2) => { - this.stateRepository = this.options.stateRepository; - - this.jsonSchemaValidator = this.options.jsonSchemaValidator; - if (this.jsonSchemaValidator === undefined) { - const ajv = createAjv(RE2); - - this.jsonSchemaValidator = new JsonSchemaValidator(ajv); - } - - this.dataContract = new DataContractFacade( - this, - RE2, - ); - - this.document = new DocumentFacade( - this, - ); - - this.stateTransition = new StateTransitionFacade( - this, - RE2, - ); - - this.identity = new IdentityFacade( - this, - ); - - return true; - }); + this.initialized = Promise.all([ + getRE2Class() + .then((RE2) => { + this.stateRepository = this.options.stateRepository; + + this.jsonSchemaValidator = this.options.jsonSchemaValidator; + if (this.jsonSchemaValidator === undefined) { + const ajv = createAjv(RE2); + + this.jsonSchemaValidator = new JsonSchemaValidator(ajv); + } + + this.dataContract = new DataContractFacade( + this, + RE2, + ); + + this.document = new DocumentFacade( + this, + ); + + this.stateTransition = new StateTransitionFacade( + this, + RE2, + ); + + this.identity = new IdentityFacade( + this, + ); + }), + initBlake3(), + ]).then(() => true); return this.initialized; } diff --git a/packages/js-dpp/lib/stateTransition/AbstractStateTransition.js b/packages/js-dpp/lib/stateTransition/AbstractStateTransition.js index 74a929bc834..9cd5a41da24 100644 --- a/packages/js-dpp/lib/stateTransition/AbstractStateTransition.js +++ b/packages/js-dpp/lib/stateTransition/AbstractStateTransition.js @@ -1,7 +1,7 @@ const { PublicKey, PrivateKey, - Signer: { sign, verifySignature }, + Signer: { signHash, verifyHashSignature }, } = require('@dashevo/dashcore-lib'); const StateTransitionIsNotSignedError = require( @@ -157,10 +157,10 @@ class AbstractStateTransition { * @return {AbstractStateTransition} */ signByPrivateKey(privateKey) { - const data = this.toBuffer({ skipSignature: true }); + const stHash = this.hash({ skipSignature: true }); const privateKeyModel = new PrivateKey(privateKey); - this.setSignature(sign(data, privateKeyModel)); + this.setSignature(signHash(stHash, privateKeyModel)); return this; } @@ -176,13 +176,13 @@ class AbstractStateTransition { throw new StateTransitionIsNotSignedError(this); } - const data = this.toBuffer({ skipSignature: true }); + const stHash = this.hash({ skipSignature: true }); const publicKeyModel = new PublicKey(publicKey, {}); let isSignatureVerified; try { - isSignatureVerified = verifySignature(data, signature, publicKeyModel); + isSignatureVerified = verifyHashSignature(stHash, signature, publicKeyModel.hash); } catch (e) { isSignatureVerified = false; } diff --git a/packages/js-dpp/lib/stateTransition/AbstractStateTransitionIdentitySigned.js b/packages/js-dpp/lib/stateTransition/AbstractStateTransitionIdentitySigned.js index 44175dc2ddc..75e08935393 100644 --- a/packages/js-dpp/lib/stateTransition/AbstractStateTransitionIdentitySigned.js +++ b/packages/js-dpp/lib/stateTransition/AbstractStateTransitionIdentitySigned.js @@ -49,9 +49,14 @@ class AbstractStateTransitionIdentitySigned extends AbstractStateTransition { let privateKeyModel; let pubKeyBase; + let privateKeyBase = privateKey; + if (Buffer.isBuffer(privateKey) || Array.isArray(privateKey)) { + privateKeyBase = Buffer.from(privateKeyBase).toString('hex'); + } + switch (identityPublicKey.getType()) { case IdentityPublicKey.TYPES.ECDSA_SECP256K1: - privateKeyModel = new PrivateKey(privateKey); + privateKeyModel = new PrivateKey(privateKeyBase); /* We store compressed public key in the identity as a base64 string, /* and here we compare the private key used to sign the state transition diff --git a/packages/js-dpp/lib/test/bootstrap.js b/packages/js-dpp/lib/test/bootstrap.js index ea15af6ab9d..66b423aa797 100644 --- a/packages/js-dpp/lib/test/bootstrap.js +++ b/packages/js-dpp/lib/test/bootstrap.js @@ -5,6 +5,7 @@ const dirtyChai = require('dirty-chai'); const chaiAsPromised = require('chai-as-promised'); const chaiString = require('chai-string'); const chaiExclude = require('chai-exclude'); +const { initBlake3 } = require('../util/hash'); use(sinonChai); use(chaiAsPromised); @@ -12,6 +13,10 @@ use(dirtyChai); use(chaiString); use(chaiExclude); +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinonSandbox) { this.sinonSandbox = sinon.createSandbox(); diff --git a/packages/js-dpp/lib/test/fixtures/getDashPayDocumentFixture.js b/packages/js-dpp/lib/test/fixtures/getDashPayDocumentFixture.js index c7036824fc2..478a236222d 100644 --- a/packages/js-dpp/lib/test/fixtures/getDashPayDocumentFixture.js +++ b/packages/js-dpp/lib/test/fixtures/getDashPayDocumentFixture.js @@ -4,12 +4,14 @@ const generateRandomIdentifier = require('../utils/generateRandomIdentifier'); const createDPPMock = require('../mocks/createDPPMock'); const ownerId = generateRandomIdentifier(); -const dataContract = getDashPayContractFixture(); /** * @return {Document} */ -function getContactRequestDocumentFixture(options = {}) { +function getContactRequestDocumentFixture( + dataContract = getDashPayContractFixture(), + options = {}, +) { const factory = new DocumentFactory( createDPPMock(), () => ({ @@ -33,5 +35,3 @@ function getContactRequestDocumentFixture(options = {}) { module.exports = { getContactRequestDocumentFixture, }; - -module.exports.dataContract = dataContract; diff --git a/packages/js-dpp/lib/test/fixtures/getDpnsDocumentFixture.js b/packages/js-dpp/lib/test/fixtures/getDpnsDocumentFixture.js index 6293e900b7f..81cc4ff3c54 100644 --- a/packages/js-dpp/lib/test/fixtures/getDpnsDocumentFixture.js +++ b/packages/js-dpp/lib/test/fixtures/getDpnsDocumentFixture.js @@ -5,12 +5,11 @@ const generateRandomIdentifier = require('../utils/generateRandomIdentifier'); const createDPPMock = require('../mocks/createDPPMock'); const ownerId = generateRandomIdentifier(); -const dataContract = getDpnsContractFixture(); /** * @return {Document} */ -function getTopDocumentFixture(options = {}) { +function getTopDocumentFixture(dataContract = getDpnsContractFixture(), options = {}) { const factory = new DocumentFactory( createDPPMock(), () => ({ @@ -41,7 +40,7 @@ function getTopDocumentFixture(options = {}) { /** * @return {Document} */ -function getParentDocumentFixture(options = {}) { +function getParentDocumentFixture(dataContract = getDpnsContractFixture(), options = {}) { const factory = new DocumentFactory( createDPPMock(), () => ({ @@ -72,7 +71,7 @@ function getParentDocumentFixture(options = {}) { /** * @return {Document} */ -function getChildDocumentFixture(options = {}) { +function getChildDocumentFixture(dataContract = getDpnsContractFixture(), options = {}) { const factory = new DocumentFactory( createDPPMock(), () => ({ @@ -107,5 +106,3 @@ module.exports = { getParentDocumentFixture, getChildDocumentFixture, }; - -module.exports.dataContract = dataContract; diff --git a/packages/js-dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js b/packages/js-dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js index a9feeae6354..c32db2d3d7b 100644 --- a/packages/js-dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js +++ b/packages/js-dpp/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js @@ -4,12 +4,11 @@ const generateRandomIdentifier = require('../utils/generateRandomIdentifier'); const createDPPMock = require('../mocks/createDPPMock'); const ownerId = generateRandomIdentifier(); -const dataContract = getFeatureFlagsContractFixture(); /** * @return {Document} */ -function getFeatureFlagsDocumentsFixture() { +function getFeatureFlagsDocumentsFixture(dataContract = getFeatureFlagsContractFixture()) { const factory = new DocumentFactory( createDPPMock(), () => ({ @@ -27,5 +26,3 @@ function getFeatureFlagsDocumentsFixture() { } module.exports = getFeatureFlagsDocumentsFixture; - -module.exports.dataContract = dataContract; diff --git a/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js b/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js index 8a56fb85b04..6f9e470657c 100644 --- a/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js +++ b/packages/js-dpp/lib/test/fixtures/getIdentityCreateTransitionFixture.js @@ -23,7 +23,7 @@ module.exports = function getIdentityCreateTransitionFixture(oneTimePrivateKey = { id: 0, type: IdentityPublicKey.TYPES.ECDSA_SECP256K1, - data: Buffer.from('AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di', 'base64'), + data: oneTimePrivateKey.toPublicKey().toBuffer(), }, ], }; diff --git a/packages/js-dpp/lib/util/hash.js b/packages/js-dpp/lib/util/hash.js index fb58965876f..f8fcbfaa42b 100644 --- a/packages/js-dpp/lib/util/hash.js +++ b/packages/js-dpp/lib/util/hash.js @@ -1,18 +1,25 @@ -const crypto = require('crypto'); +const blake3Promise = require('@dashevo/blake3/browser-async'); -function sha256(payload) { - return crypto.createHash('sha256') - .update(payload) - .digest(); +let blake3 = {}; +/** + * Init the blake 3 hasher + * @returns {Promise} + */ +async function initBlake3() { + blake3 = await blake3Promise(); } + /** - * Serialize and hash payload using double sha256 + * Serialize and hash payload using blake 3 * * @param {Buffer} buffer * @return {Buffer} */ function hash(buffer) { - return sha256(sha256(buffer)); + return Buffer.from(blake3.hash(buffer)); } -module.exports = { hash }; +module.exports = { + initBlake3, + hash, +}; diff --git a/packages/js-dpp/package.json b/packages/js-dpp/package.json index 975e7eae6d2..a08be578463 100644 --- a/packages/js-dpp/package.json +++ b/packages/js-dpp/package.json @@ -83,6 +83,7 @@ }, "dependencies": { "@apidevtools/json-schema-ref-parser": "^8.0.0", + "@dashevo/blake3": "^2.1.5", "@dashevo/dashcore-lib": "~0.19.26", "@dashevo/feature-flags-contract": "0.2.1", "@dashevo/re2-wasm": "~1.0.4", diff --git a/packages/js-dpp/test/unit/dataContract/generateDataContractId.spec.js b/packages/js-dpp/test/unit/dataContract/generateDataContractId.spec.js index d2a77250561..1a7306e8fe1 100644 --- a/packages/js-dpp/test/unit/dataContract/generateDataContractId.spec.js +++ b/packages/js-dpp/test/unit/dataContract/generateDataContractId.spec.js @@ -11,7 +11,7 @@ describe('generateDataContractId', () => { }); it('should generate bs58 id based on ', () => { - const id = bs58.decode('CnS7cz4z1qoPsNfEgpgyVnKdtH2u7bgzZXHLcCQt24US'); + const id = bs58.decode('DJftzP4Db8pdN76p72SScmw27jcVjcxrqbT4mmZNMJcw'); const generatedId = generateDataContractId(ownerId, entropy); expect(Buffer.compare(id, generatedId)).to.equal(0); diff --git a/packages/js-dpp/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js b/packages/js-dpp/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js index 98adf415372..c31d2f4f417 100644 --- a/packages/js-dpp/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +++ b/packages/js-dpp/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js @@ -28,10 +28,10 @@ describe('createDomainDataTrigger', () => { beforeEach(function beforeEach() { dataContract = getDpnsContractFixture(); - topDocument = getTopDocumentFixture(); - parentDocument = getParentDocumentFixture(); - childDocument = getChildDocumentFixture(); - const preorderDocument = getPreorderDocumentFixture(); + topDocument = getTopDocumentFixture(dataContract); + parentDocument = getParentDocumentFixture(dataContract); + childDocument = getChildDocumentFixture(dataContract); + const preorderDocument = getPreorderDocumentFixture(dataContract); [parentDocumentTransition] = getDocumentTransitionFixture({ create: [parentDocument], @@ -112,7 +112,10 @@ describe('createDomainDataTrigger', () => { }); it('should fail with invalid normalizedLabel', async () => { - childDocument = getChildDocumentFixture({ normalizedLabel: childDocument.getData().label }); + childDocument = getChildDocumentFixture( + dataContract, + { normalizedLabel: childDocument.getData().label }, + ); stateRepositoryMock.fetchTransaction .withArgs( childDocument.getData().records.dashUniqueIdentityId, @@ -137,11 +140,14 @@ describe('createDomainDataTrigger', () => { }); it('should fail with invalid parent domain', async () => { - childDocument = getChildDocumentFixture({ - label: 'label', - normalizedLabel: 'label', - normalizedParentDomainName: 'parent.invalidname', - }); + childDocument = getChildDocumentFixture( + dataContract, + { + label: 'label', + normalizedLabel: 'label', + normalizedParentDomainName: 'parent.invalidname', + }, + ); stateRepositoryMock.fetchTransaction .withArgs( @@ -182,7 +188,7 @@ describe('createDomainDataTrigger', () => { Buffer.alloc(32, 5), ); - childDocument = getChildDocumentFixture({ + childDocument = getChildDocumentFixture(dataContract, { records: { dashUniqueIdentityId: dashUniqueIdentityId.toBuffer(), }, @@ -210,7 +216,7 @@ describe('createDomainDataTrigger', () => { Buffer.alloc(32, 2), ); - childDocument = getChildDocumentFixture({ + childDocument = getChildDocumentFixture(dataContract, { records: { dashAliasIdentityId: dashUniqueIdentityId.toBuffer(), }, @@ -234,7 +240,7 @@ describe('createDomainDataTrigger', () => { }); it('should fail with preorder document was not found', async () => { - childDocument = getChildDocumentFixture({ + childDocument = getChildDocumentFixture(dataContract, { preorderSalt: Buffer.alloc(256, '012fd'), }); @@ -256,7 +262,7 @@ describe('createDomainDataTrigger', () => { }); it('should fail with invalid full domain name length', async () => { - childDocument = getChildDocumentFixture({ + childDocument = getChildDocumentFixture(dataContract, { normalizedParentDomainName: 'a'.repeat(512), }); @@ -317,7 +323,9 @@ describe('createDomainDataTrigger', () => { }); it('should fail with allowing subdomains for non top level domain', async () => { - childDocument = getChildDocumentFixture({ subdomainRules: { allowSubdomains: true } }); + childDocument = getChildDocumentFixture( + dataContract, { subdomainRules: { allowSubdomains: true } }, + ); [childDocumentTransition] = getDocumentTransitionFixture({ create: [childDocument], diff --git a/packages/js-dpp/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js b/packages/js-dpp/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js index 84550863755..3db9462ce6e 100644 --- a/packages/js-dpp/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +++ b/packages/js-dpp/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js @@ -9,6 +9,7 @@ const createStateRepositoryMock = require('../../../../lib/test/mocks/createStat const DataTriggerExecutionResult = require('../../../../lib/dataTrigger/DataTriggerExecutionResult'); const DataTriggerConditionError = require('../../../../lib/errors/consensus/state/dataContract/dataTrigger/DataTriggerConditionError'); const Identifier = require('../../../../lib/identifier/Identifier'); +const getFeatureFlagsContractFixture = require('../../../../lib/test/fixtures/getFeatureFlagsContractFixture'); describe('createFeatureFlagDataTrigger', () => { let contextMock; @@ -24,7 +25,9 @@ describe('createFeatureFlagDataTrigger', () => { height: new Long(42), }); - const [document] = getFeatureFlagsDocumentsFixture(); + const dataContract = getFeatureFlagsContractFixture(); + + const [document] = getFeatureFlagsDocumentsFixture(dataContract); [documentTransition] = getDocumentTransitionsFixture({ create: [document], @@ -33,7 +36,7 @@ describe('createFeatureFlagDataTrigger', () => { contextMock = { getStateRepository: () => stateRepositoryMock, getOwnerId: this.sinonSandbox.stub(), - getDataContract: () => getFeatureFlagsDocumentsFixture.dataContract, + getDataContract: () => dataContract, }; contextMock.getOwnerId.returns(topLevelIdentityId); }); diff --git a/packages/js-dpp/test/unit/dataTrigger/getDataTriggersFactory.spec.js b/packages/js-dpp/test/unit/dataTrigger/getDataTriggersFactory.spec.js index df16b544815..6924d8e69ff 100644 --- a/packages/js-dpp/test/unit/dataTrigger/getDataTriggersFactory.spec.js +++ b/packages/js-dpp/test/unit/dataTrigger/getDataTriggersFactory.spec.js @@ -10,6 +10,7 @@ const createDomainDataTrigger = require('../../../lib/dataTrigger/dpnsTriggers/c const rejectDataTrigger = require('../../../lib/dataTrigger/rejectDataTrigger'); const generateRandomIdentifier = require('../../../lib/test/utils/generateRandomIdentifier'); +const getDpnsContractFixture = require('../../../lib/test/fixtures/getDpnsContractFixture'); describe('getDataTriggers', () => { let getDataTriggers; @@ -31,12 +32,13 @@ describe('getDataTriggers', () => { let processMock; beforeEach(function beforeEach() { - createDocument = getDpnsDocumentFixture.getChildDocumentFixture(); - updateDocument = getDpnsDocumentFixture.getChildDocumentFixture(); - deleteDocument = getDpnsDocumentFixture.getChildDocumentFixture(); + const dataContract = getDpnsContractFixture(); + createDocument = getDpnsDocumentFixture.getChildDocumentFixture(dataContract); + updateDocument = getDpnsDocumentFixture.getChildDocumentFixture(dataContract); + deleteDocument = getDpnsDocumentFixture.getChildDocumentFixture(dataContract); deleteDocument.data = {}; - dataContractId = getDpnsDocumentFixture.dataContract.getId(); + dataContractId = dataContract.getId(); topLevelIdentity = generateRandomIdentifier().toBuffer(); createTrigger = new DataTrigger( diff --git a/packages/js-dpp/test/unit/document/DocumentFactory.spec.js b/packages/js-dpp/test/unit/document/DocumentFactory.spec.js index 830ae24e4da..4a9ab865803 100644 --- a/packages/js-dpp/test/unit/document/DocumentFactory.spec.js +++ b/packages/js-dpp/test/unit/document/DocumentFactory.spec.js @@ -112,7 +112,7 @@ describe('DocumentFactory', () => { expect(newDocument.getRevision()).to.equal(DocumentCreateTransition.INITIAL_REVISION); - expect(newDocument.getId()).to.deep.equal(bs58.decode('B99gjrjq6R1FXwGUQnoP7VrmCDDT1PbKprUNzjVbxXfz')); + expect(newDocument.getId()).to.deep.equal(bs58.decode('E6ZqBauuv4LnFXhhnikuqQ9itmAbrCjQqzbL5jJgAK2h')); expect(newDocument.getCreatedAt().getTime()).to.be.equal(fakeTimeDate.getTime()); expect(newDocument.getCreatedAt().getTime()).to.equal(newDocument.getUpdatedAt().getTime()); diff --git a/packages/js-dpp/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js b/packages/js-dpp/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js index f0f84f01d9f..8562143552e 100644 --- a/packages/js-dpp/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js +++ b/packages/js-dpp/test/unit/stateTransition/validation/validateStateTransitionKeySignatureFactory.spec.js @@ -7,6 +7,8 @@ const { expectValidationError } = require('../../../../lib/test/expect/expectErr const ValidationResult = require('../../../../lib/validation/ValidationResult'); +const { hash } = require('../../../../lib/util/hash'); + describe('validateStateTransitionKeySignatureFactory', () => { let publicKeyHash; let stateTransition; @@ -19,7 +21,7 @@ describe('validateStateTransitionKeySignatureFactory', () => { publicKeyHash = Buffer.alloc(20).fill(1); stateTransition = getIdentityCreateTransitionFixture(); - stateTransitionHash = stateTransition.hash({ skipSignature: true }); + stateTransitionHash = hash(stateTransition.toBuffer({ skipSignature: true })); verifyHashSignatureMock = this.sinonSandbox.stub(); diff --git a/packages/js-drive/lib/test/bootstrap.js b/packages/js-drive/lib/test/bootstrap.js index 028c7616204..7b11590e08f 100644 --- a/packages/js-drive/lib/test/bootstrap.js +++ b/packages/js-drive/lib/test/bootstrap.js @@ -8,6 +8,8 @@ const dirtyChai = require('dirty-chai'); const chaiAsPromised = require('chai-as-promised'); const chaiString = require('chai-string'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + use(sinonChai); use(chaiAsPromised); use(chaiString); @@ -25,6 +27,10 @@ const dotenvConfig = dotenvSafe.config({ }); dotenvExpand(dotenvConfig); +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinon) { this.sinon = sinon.createSandbox(); diff --git a/packages/js-drive/scripts/abci.js b/packages/js-drive/scripts/abci.js index 41d476cda2d..ce9461bc8a5 100644 --- a/packages/js-drive/scripts/abci.js +++ b/packages/js-drive/scripts/abci.js @@ -67,9 +67,13 @@ console.log(chalk.hex('#008de4')(banner)); * Initialize DPP */ + console.log('Initializing DPP !!!!!!!!!!!!!!!!!!!!!'); + await dpp.initialize(); await transactionalDpp.initialize(); + console.log('DPP Initialized !!!!!!!!!!!!!!!!!!!!!'); + /** * Initialize Block Execution Contexts */ diff --git a/packages/platform-test-suite/lib/test/createClientWithFundedWallet.js b/packages/platform-test-suite/lib/test/createClientWithFundedWallet.js index 76011988345..2b13e646313 100644 --- a/packages/platform-test-suite/lib/test/createClientWithFundedWallet.js +++ b/packages/platform-test-suite/lib/test/createClientWithFundedWallet.js @@ -52,6 +52,8 @@ async function createClientWithFundedWallet(HDPrivateKey = undefined) { await fundWallet(faucetClient.wallet, client.wallet, amount); + await client.platform.initialize(); + return client; } diff --git a/packages/wallet-lib/src/test/bootstrap.js b/packages/wallet-lib/src/test/bootstrap.js index 7ed8f32f31e..8e10d1e972a 100644 --- a/packages/wallet-lib/src/test/bootstrap.js +++ b/packages/wallet-lib/src/test/bootstrap.js @@ -2,10 +2,16 @@ const path = require('path'); const dotenvSafe = require('dotenv-safe'); const sinon = require('sinon'); +const { initBlake3 } = require('@dashevo/dpp/lib/util/hash'); + dotenvSafe.config({ path: path.resolve(__dirname, '..', '..', '.env'), }); +before(async () => { + await initBlake3(); +}); + beforeEach(function beforeEach() { if (!this.sinonSandbox) { this.sinonSandbox = sinon.createSandbox();