Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7844c0f
chore!: simplify public key to identity structure
shumkov Jun 15, 2022
2dbc228
Update IdentitySyncWorker.js
shumkov Jun 15, 2022
95e9117
test(dpp): fix tests
shumkov Jun 15, 2022
3415c92
fix(wallet): invalid transport name
shumkov Jun 15, 2022
a17e5e5
fix(wallet): identity sync expect undefined
shumkov Jun 16, 2022
44b90c9
test: fix wallet mock and test suite funding
shumkov Jun 16, 2022
6d5db83
test: fix sdk tests
shumkov Jun 16, 2022
a8d5736
fix: dry run issues
shumkov Jun 16, 2022
61bca62
Merge branch 'v0.23-dev' into proofs
Jun 17, 2022
c40c5ec
feat(drive): re-enable proof logic
Jun 17, 2022
7ec545f
feat(drive): re-enable proof logic
Jun 21, 2022
83fa770
feat(drive): re-enable proof logic
Jun 21, 2022
a799d1c
fix: invalid prove queries
shumkov Jun 21, 2022
b92e6b2
feat(drive): re-enable proof logic
Jun 21, 2022
be00389
feat(drive): re-enable proof logic
Jun 22, 2022
2b9f7a2
feat(drive): re-enable proof logic
Jun 22, 2022
7382193
feat(drive): re-enable proof logic
Jun 22, 2022
3664d4d
Merge branch 'v0.23-dev' into proofs
Jun 22, 2022
f4d4572
feat(drive): re-enable proof logic
Jun 22, 2022
6f02633
feat(drive): re-enable proof logic
Jun 22, 2022
617512c
feat(drive): re-enable proof logic
Jun 23, 2022
dc3580d
feat(drive): re-enable proof logic
Jun 23, 2022
cd9d350
feat(drive): re-enable proof logic
Jun 23, 2022
0a8a4e0
feat(drive): re-enable proof logic
Jun 23, 2022
ae06c65
feat(drive): re-enable proof logic
Jun 23, 2022
e63f9b1
feat(drive): re-enable proof logic
Jun 23, 2022
495f0af
feat(drive): re-enable proof logic
Jun 23, 2022
d7c4133
feat: add method to prove multiple docs from different contracts
shumkov Jun 27, 2022
933a8d4
feta: getProofsQuery
Jun 27, 2022
b00bd1b
feta: getProofsQuery
Jun 27, 2022
a810a25
test: document repository
Jun 28, 2022
8e6496d
chore
Jun 28, 2022
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
8 changes: 4 additions & 4 deletions .pnp.cjs

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

Binary file not shown.
6 changes: 3 additions & 3 deletions packages/dapi/lib/externalApis/drive/DriveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ class DriveClient {
/**
* Fetch proofs by ids
*
* @param {Buffer[]} [documentIds]
* @param {{dataContractId: Identifier, documentId: Identifier, type: string}[]} [documents]
* @param {Buffer[]} [identityIds]
* @param {Buffer[]} [dataContractIds]
* @return {Promise<{data: Buffer}>}
*/
async fetchProofs({ documentIds, identityIds, dataContractIds }) {
async fetchProofs({ documents, identityIds, dataContractIds }) {
return this.requestCbor(
'/proofs',
{
documentIds,
documents,
identityIds,
dataContractIds,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ function fetchProofForStateTransitionFactory(driveClient) {
if (stateTransition.isDocumentStateTransition()) {
({ documentsProof: proof, metadata } = await driveClient.fetchProofs(
{
documentIds: modifiedIds.map((identifier) => identifier.toBuffer()),
documents: stateTransition.getTransitions().map((documentTransition) => ({
dataContractId: documentTransition.getDataContractId().toBuffer(),
documentId: documentTransition.getId().toBuffer(),
type: documentTransition.getType(),
})),
},
));
} else if (stateTransition.isIdentityStateTransition()) {
Expand Down
6 changes: 3 additions & 3 deletions packages/dapi/test/unit/externalApis/drive/DriveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('DriveClient', () => {
it('should call \'fetchProofs\' RPC with the given parameters', async () => {
const drive = new DriveClient({ host: '127.0.0.1', port: 3000 });

const documentIds = undefined;
const documents = undefined;
const identityIds = [Buffer.from('id')];
const dataContractIds = [Buffer.from('anotherId')];

Expand All @@ -236,12 +236,12 @@ describe('DriveClient', () => {
},
});

const result = await drive.fetchProofs({ documentIds, identityIds, dataContractIds });
const result = await drive.fetchProofs({ documents, identityIds, dataContractIds });

expect(drive.client.request).to.have.been.calledOnceWithExactly('abci_query', {
path: '/proofs',
data: cbor.encode({
documentIds,
documents,
identityIds,
dataContractIds,
}).toString('hex'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
const IdentifierError = require('@dashevo/dpp/lib/identifier/errors/IdentifierError');

const NotFoundAbciError = require('../../errors/NotFoundAbciError');
const UnimplementedAbciError = require('../../errors/UnimplementedAbciError');
const InvalidArgumentAbciError = require('../../errors/InvalidArgumentAbciError');

/**
Expand Down Expand Up @@ -59,17 +58,18 @@ function dataContractQueryHandlerFactory(
const response = createQueryResponse(GetDataContractResponse, request.prove);

if (request.prove) {
throw new UnimplementedAbciError('Proofs are not implemented yet');
}
const proof = await signedDataContractRepository.prove(contractIdIdentifier);

const dataContract = await signedDataContractRepository.fetch(contractIdIdentifier);
response.getProof().setMerkleProof(proof.getValue());
} else {
const dataContract = await signedDataContractRepository.fetch(contractIdIdentifier);
if (dataContract.isNull()) {
throw new NotFoundAbciError('Data Contract not found');
}

if (dataContract.isNull()) {
throw new NotFoundAbciError('Data Contract not found');
response.setDataContract(dataContract.getValue().toBuffer());
}

response.setDataContract(dataContract.getValue().toBuffer());

return new ResponseQuery({
value: response.serializeBinary(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ const {

const InvalidArgumentAbciError = require('../../errors/InvalidArgumentAbciError');
const InvalidQueryError = require('../../../document/errors/InvalidQueryError');
const UnimplementedAbciError = require('../../errors/UnimplementedAbciError');

/**
*
* @param {fetchDocuments} fetchSignedDocuments
* @param {proveDocuments} proveSignedDocuments
* @param {createQueryResponse} createQueryResponse
* @param {BlockExecutionContextStack} blockExecutionContextStack
* @return {documentQueryHandler}
*/
function documentQueryHandlerFactory(
fetchSignedDocuments,
proveSignedDocuments,
createQueryResponse,
blockExecutionContextStack,
) {
Expand Down Expand Up @@ -69,20 +70,28 @@ function documentQueryHandlerFactory(

const response = createQueryResponse(GetDocumentsResponse, request.prove);

if (request.prove) {
throw new UnimplementedAbciError('Proofs are not implemented yet');
}

let documentsResult;
const options = {
where,
orderBy,
limit,
startAfter: startAfter ? Buffer.from(startAfter) : startAfter,
startAt: startAt ? Buffer.from(startAt) : startAt,
};

try {
documentsResult = await fetchSignedDocuments(contractId, type, {
where,
orderBy,
limit,
startAfter: startAfter ? Buffer.from(startAfter) : startAfter,
startAt: startAt ? Buffer.from(startAt) : startAt,
});
if (request.prove) {
const proof = await proveSignedDocuments(contractId, type, options);

response.getProof().setMerkleProof(proof.getValue());
} else {
const documentsResult = await fetchSignedDocuments(contractId, type, options);

const documents = documentsResult.getValue();

response.setDocumentsList(
documents.map((document) => document.toBuffer()),
);
}
} catch (e) {
if (e instanceof InvalidQueryError) {
throw new InvalidArgumentAbciError(`Invalid query: ${e.message}`);
Expand All @@ -91,12 +100,6 @@ function documentQueryHandlerFactory(
throw e;
}

const documents = documentsResult.getValue();

response.setDocumentsList(
documents.map((document) => document.toBuffer()),
);

return new ResponseQuery({
value: response.serializeBinary(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ const {
} = require('@dashevo/abci/types');

const cbor = require('cbor');
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');

/**
*
* @param {BlockExecutionContextStack} blockExecutionContextStack
* @param {IdentityStoreRepository} signedIdentityRepository
* @param {DataContractStoreRepository} signedDataContractRepository
* @param {DocumentRepository} signedDocumentRepository
* @return {getProofsQueryHandler}
*/
function getProofsQueryHandlerFactory(
blockExecutionContextStack,
signedIdentityRepository,
signedDataContractRepository,
signedDocumentRepository,
) {
/**
* @typedef getProofsQueryHandler
* @param params
* @param callArguments
* @param {Identifier[]} callArguments.identityIds
* @param {Identifier[]} callArguments.documentIds
* @param {Identifier[]} callArguments.dataContractIds
* @param {Buffer[]} callArguments.identityIds
* @param {Buffer[]} callArguments.dataContractIds
* @param {{dataContractId: Buffer, documentId: Buffer, type: string}[]} documents
* @return {Promise<ResponseQuery>}
*/
async function getProofsQueryHandler(params, {
identityIds,
documentIds,
dataContractIds,
documents,
}) {
// There is no signed state (current committed block height less than 3)
if (!blockExecutionContextStack.getLast()) {
Expand Down Expand Up @@ -68,27 +75,38 @@ function getProofsQueryHandlerFactory(
},
};

if (documentIds && documentIds.length) {
if (documents && documents.length) {
const documentsProof = await signedDocumentRepository
.proveManyDocumentsFromDifferentContracts(documents);

response.documentsProof = {
signatureLlmqHash,
signature,
merkleProof: Buffer.from([1]),
merkleProof: documentsProof.getValue(),
};
}

if (identityIds && identityIds.length) {
const identitiesProof = await signedIdentityRepository.proveMany(
identityIds.map((identityId) => Identifier.from(identityId)),
);

response.identitiesProof = {
signatureLlmqHash,
signature,
merkleProof: Buffer.from([1]),
merkleProof: identitiesProof.getValue(),
};
}

if (dataContractIds && dataContractIds.length) {
const dataContractsProof = await signedDataContractRepository.proveMany(
dataContractIds.map((dataContractId) => Identifier.from(dataContractId)),
);

response.dataContractsProof = {
signatureLlmqHash,
signature,
merkleProof: Buffer.from([1]),
merkleProof: dataContractsProof.getValue(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
} = require('@dashevo/dapi-grpc');

const InvalidArgumentAbciError = require('../../errors/InvalidArgumentAbciError');
const UnimplementedAbciError = require('../../errors/UnimplementedAbciError');

/**
*
Expand Down Expand Up @@ -59,17 +58,19 @@ function identitiesByPublicKeyHashesQueryHandlerFactory(
});
}

if (request.prove) {
throw new UnimplementedAbciError('Proofs are not implemented yet');
}

const response = createQueryResponse(GetIdentitiesByPublicKeyHashesResponse, request.prove);

const result = await signedPublicKeyToIdentitiesRepository.fetchManyBuffers(
publicKeyHashes,
);
if (request.prove) {
const proof = await signedPublicKeyToIdentitiesRepository.proveMany(publicKeyHashes);

response.setIdentitiesList(result.getValue());
response.getProof().setMerkleProof(proof.getValue());
} else {
const identitiesListResult = await signedPublicKeyToIdentitiesRepository.fetchManyBuffers(
publicKeyHashes,
);

response.setIdentitiesList(identitiesListResult.getValue());
}

return new ResponseQuery({
value: response.serializeBinary(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
const IdentifierError = require('@dashevo/dpp/lib/identifier/errors/IdentifierError');

const NotFoundAbciError = require('../../errors/NotFoundAbciError');
const UnimplementedAbciError = require('../../errors/UnimplementedAbciError');
const InvalidArgumentAbciError = require('../../errors/InvalidArgumentAbciError');

/**
Expand Down Expand Up @@ -58,20 +57,22 @@ function identityQueryHandlerFactory(
throw e;
}

const response = createQueryResponse(GetIdentityResponse, request.prove);

if (request.prove) {
throw new UnimplementedAbciError('Proofs are not implemented yet');
}
const proof = await signedIdentityRepository.prove(identifier);

const response = createQueryResponse(GetIdentityResponse, request.prove);
response.getProof().setMerkleProof(proof.getValue());
} else {
const identityResult = await signedIdentityRepository.fetch(identifier);

const identityResult = await signedIdentityRepository.fetch(identifier);
if (identityResult.isNull()) {
throw new NotFoundAbciError('Identity not found');
}

if (identityResult.isNull()) {
throw new NotFoundAbciError('Identity not found');
response.setIdentity(identityResult.getValue().toBuffer());
}

response.setIdentity(identityResult.getValue().toBuffer());

return new ResponseQuery({
value: response.serializeBinary(),
});
Expand Down
27 changes: 22 additions & 5 deletions packages/js-drive/lib/createDIContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const PublicKeyToIdentitiesStoreRepository = require(
const DataContractStoreRepository = require('./dataContract/DataContractStoreRepository');

const fetchDocumentsFactory = require('./document/fetchDocumentsFactory');
const proveDocumentsFactory = require('./document/proveDocumentsFactory');
const fetchDataContractFactory = require('./document/fetchDataContractFactory');
const BlockExecutionContext = require('./blockExecution/BlockExecutionContext');

const CreditsDistributionPoolRepository = require('./creditsDistributionPool/CreditsDistributionPoolRepository');
Expand Down Expand Up @@ -540,18 +542,33 @@ function createDIContainer(options) {
))).singleton(),

fetchDocuments: asFunction(fetchDocumentsFactory).singleton(),

fetchSignedDocuments: asFunction((
signedDocumentRepository,
fetchDataContract: asFunction(fetchDataContractFactory).singleton(),
proveDocuments: asFunction(proveDocumentsFactory).singleton(),
fetchSignedDataContract: asFunction((
signedDataContractRepository,
signedDataContractCache,
) => (
fetchDocumentsFactory(
signedDocumentRepository,
fetchDataContractFactory(
signedDataContractRepository,
signedDataContractCache,
)
)).singleton(),
fetchSignedDocuments: asFunction((
signedDocumentRepository,
fetchSignedDataContract,
) => (
fetchDocumentsFactory(
signedDocumentRepository,
fetchSignedDataContract,
)
)).singleton(),
proveSignedDocuments: asFunction((
signedDocumentRepository,
) => (
proveDocumentsFactory(
signedDocumentRepository,
)
)).singleton(),
});

/**
Expand Down
Loading