Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1846b29
chore: install `@dashevo/blake3`
jawid-h Nov 4, 2021
8696bcd
feat: use `blake3` for hashing
jawid-h Nov 4, 2021
a916e22
Merge branch 'v0.22-dev' into dpp/feat/blake3
jawid-h Nov 11, 2021
8584f56
chore: fix linter error
jawid-h Nov 11, 2021
29e7aae
Merge branch 'v0.22-dev' into dpp/feat/blake3
shumkov Nov 11, 2021
809aecc
Merge branch 'v0.22-dev' into dpp/feat/blake3
shumkov Nov 12, 2021
8ab2051
chore(tests): init blake3 in bootstraps
jawid-h Nov 12, 2021
fecf24d
Merge branch 'dpp/feat/blake3' of github.com:dashevo/platform into dp…
jawid-h Nov 12, 2021
1e3132b
Merge branch 'v0.22-dev' into dpp/feat/blake3
shumkov Nov 17, 2021
f554991
chore(tests): missing init in sdk
jawid-h Nov 17, 2021
b60707c
test: initialize blake3 before running tests
shumkov Nov 17, 2021
7414c6f
Merge remote-tracking branch 'origin/dpp/feat/blake3' into dpp/feat/b…
shumkov Nov 17, 2021
6416b40
feat: initialize RE2 and blake3 in parallel
shumkov Nov 17, 2021
d864102
chore: conflicting require
jawid-h Nov 17, 2021
33eddda
chore: fix init of SDK
jawid-h Nov 17, 2021
58b6cef
chore: missing func call
jawid-h Nov 17, 2021
696e085
chore: TODO REMOVE debug
jawid-h Nov 18, 2021
dd9f4f5
chore: removed console logs
jawid-h Nov 18, 2021
c82b754
Merge branch 'v0.22-dev' into dpp/feat/blake3
shumkov Nov 18, 2021
655604a
chore: remove unnecessary initialize
jawid-h Nov 18, 2021
0fe7645
Merge branch 'dpp/feat/blake3' of github.com:dashevo/platform into dp…
jawid-h Nov 18, 2021
c26c428
chore: some logs
jawid-h Nov 18, 2021
4a97168
Merge branch 'v0.22-dev' into dpp/feat/blake3
shumkov Nov 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/dapi/lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions packages/dashpay-contract/lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions packages/dpns-contract/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions packages/feature-flags-contract/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions packages/js-dapi-client/lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down
12 changes: 11 additions & 1 deletion packages/js-dash-sdk/src/test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
8 changes: 8 additions & 0 deletions packages/js-dash-sdk/src/test/karma/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
63 changes: 33 additions & 30 deletions packages/js-dpp/lib/DashPlatformProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/js-dpp/lib/stateTransition/AbstractStateTransition.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
PublicKey,
PrivateKey,
Signer: { sign, verifySignature },
Signer: { signHash, verifyHashSignature },
} = require('@dashevo/dashcore-lib');

const StateTransitionIsNotSignedError = require(
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions packages/js-dpp/lib/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ 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);
use(dirtyChai);
use(chaiString);
use(chaiExclude);

before(async () => {
await initBlake3();
});

beforeEach(function beforeEach() {
if (!this.sinonSandbox) {
this.sinonSandbox = sinon.createSandbox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
() => ({
Expand All @@ -33,5 +35,3 @@ function getContactRequestDocumentFixture(options = {}) {
module.exports = {
getContactRequestDocumentFixture,
};

module.exports.dataContract = dataContract;
Loading