Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ const {
},
} = require('@dashevo/dapi-grpc');

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

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

/**
*
* @param {DataContractStoreRepository} dataContractRepository
* @param {createQueryResponse} createQueryResponse
* @param {WebAssembly.Instance} dppWasm
* @return {dataContractQueryHandler}
*/
function dataContractQueryHandlerFactory(
dataContractRepository,
createQueryResponse,
dppWasm,
) {
/**
* @typedef dataContractQueryHandler
Expand All @@ -39,9 +38,9 @@ function dataContractQueryHandlerFactory(
async function dataContractQueryHandler(params, { id }, request) {
let contractIdIdentifier;
try {
contractIdIdentifier = new Identifier(id);
contractIdIdentifier = new dppWasm.Identifier(id);
} catch (e) {
if (e instanceof IdentifierError) {
if (e instanceof dppWasm.IdentifierError) {
throw new InvalidArgumentAbciError('id must be a valid identifier (32 bytes long)');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ const {
} = require('@dashevo/abci/types');

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

/**
*
* @param {BlockExecutionContext} latestBlockExecutionContext
* @param {IdentityStoreRepository} identityRepository
* @param {DataContractStoreRepository} dataContractRepository
* @param {DocumentRepository} documentRepository
* @param {WebAssembly.Instance} dppWasm
* @return {getProofsQueryHandler}
*/
function getProofsQueryHandlerFactory(
latestBlockExecutionContext,
identityRepository,
dataContractRepository,
documentRepository,
dppWasm,
) {
/**
* @typedef getProofsQueryHandler
Expand Down Expand Up @@ -73,7 +74,7 @@ function getProofsQueryHandlerFactory(

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

response.identitiesProof = {
Expand All @@ -86,7 +87,7 @@ function getProofsQueryHandlerFactory(

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

response.dataContractsProof = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ const {
},
} = require('@dashevo/dapi-grpc');

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

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

/**
*
* @param {IdentityStoreRepository} identityRepository
* @param {createQueryResponse} createQueryResponse
* @param {WebAssembly.Instance} dppWasm
* @return {identityQueryHandler}
*/
function identityQueryHandlerFactory(
identityRepository,
createQueryResponse,
dppWasm,
) {
/**
* @typedef identityQueryHandler
Expand All @@ -39,9 +38,9 @@ function identityQueryHandlerFactory(
async function identityQueryHandler(params, { id }, request) {
let identifier;
try {
identifier = new Identifier(id);
identifier = new dppWasm.Identifier(id);
} catch (e) {
if (e instanceof IdentifierError) {
if (e instanceof dppWasm.IdentifierError) {
throw new InvalidArgumentAbciError('id must be a valid identifier (32 bytes long)');
}

Expand Down
56 changes: 26 additions & 30 deletions packages/js-drive/lib/createDIContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const RpcClient = require('@dashevo/dashd-rpc/promise');

const { PublicKey } = require('@dashevo/dashcore-lib');

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

const findMyWay = require('find-my-way');

const pino = require('pino');
const pinoMultistream = require('pino-multi-stream');

Expand Down Expand Up @@ -147,7 +143,7 @@ const createContextLoggerFactory = require('./abci/errors/createContextLoggerFac
const IdentityBalanceStoreRepository = require('./identity/IdentityBalanceStoreRepository');

/**
* @param {Object} dppWasmLoaded
* @param {WebAssembly.Instance} dppWasm
* @param {Object} options
* @param {string} options.ABCI_HOST
* @param {string} options.ABCI_PORT
Expand Down Expand Up @@ -186,7 +182,7 @@ const IdentityBalanceStoreRepository = require('./identity/IdentityBalanceStoreR
*
* @return {AwilixContainer}
*/
function createDIContainer(dppWasmLoaded, options) {
function createDIContainer(dppWasm, options) {
if (!options.DPNS_MASTER_PUBLIC_KEY) {
throw new Error('DPNS_MASTER_PUBLIC_KEY must be set');
}
Expand Down Expand Up @@ -289,10 +285,10 @@ function createDIContainer(dppWasmLoaded, options) {
parseInt(options.VALIDATOR_SET_LLMQ_TYPE, 10),
),
masternodeRewardSharesContractId: asValue(
Identifier.from(masternodeRewardsSystemIds.contractId),
dppWasm.Identifier.from(masternodeRewardsSystemIds.contractId),
),
masternodeRewardSharesOwnerId: asValue(
Identifier.from(masternodeRewardsSystemIds.ownerId),
dppWasm.Identifier.from(masternodeRewardsSystemIds.ownerId),
),
masternodeRewardSharesOwnerMasterPublicKey: asValue(
PublicKey.fromString(
Expand All @@ -308,10 +304,10 @@ function createDIContainer(dppWasmLoaded, options) {
masternodeRewardsDocuments,
),
featureFlagsContractId: asValue(
Identifier.from(featureFlagsSystemIds.contractId),
dppWasm.Identifier.from(featureFlagsSystemIds.contractId),
),
featureFlagsOwnerId: asValue(
Identifier.from(featureFlagsSystemIds.ownerId),
dppWasm.Identifier.from(featureFlagsSystemIds.ownerId),
),
featureFlagsOwnerMasterPublicKey: asValue(
PublicKey.fromString(
Expand All @@ -324,8 +320,8 @@ function createDIContainer(dppWasmLoaded, options) {
),
),
featureFlagsDocuments: asValue(featureFlagsDocuments),
dpnsContractId: asValue(Identifier.from(dpnsSystemIds.contractId)),
dpnsOwnerId: asValue(Identifier.from(dpnsSystemIds.ownerId)),
dpnsContractId: asValue(dppWasm.Identifier.from(dpnsSystemIds.contractId)),
dpnsOwnerId: asValue(dppWasm.Identifier.from(dpnsSystemIds.ownerId)),
dpnsOwnerMasterPublicKey: asValue(
PublicKey.fromString(
options.DPNS_MASTER_PUBLIC_KEY,
Expand All @@ -337,8 +333,8 @@ function createDIContainer(dppWasmLoaded, options) {
),
),
dpnsDocuments: asValue(dpnsDocuments),
dashpayContractId: asValue(Identifier.from(dashpaySystemIds.contractId)),
dashpayOwnerId: asValue(Identifier.from(dashpaySystemIds.ownerId)),
dashpayContractId: asValue(dppWasm.Identifier.from(dashpaySystemIds.contractId)),
dashpayOwnerId: asValue(dppWasm.Identifier.from(dashpaySystemIds.ownerId)),
dashpayOwnerMasterPublicKey: asValue(
PublicKey.fromString(
options.DASHPAY_MASTER_PUBLIC_KEY,
Expand All @@ -350,8 +346,8 @@ function createDIContainer(dppWasmLoaded, options) {
),
),
dashpayDocuments: asValue(dashpayDocuments),
withdrawalsContractId: asValue(Identifier.from(withdrawalsSystemIds.contractId)),
withdrawalsOwnerId: asValue(Identifier.from(withdrawalsSystemIds.ownerId)),
withdrawalsContractId: asValue(dppWasm.Identifier.from(withdrawalsSystemIds.contractId)),
withdrawalsOwnerId: asValue(dppWasm.Identifier.from(withdrawalsSystemIds.ownerId)),
withdrawalsOwnerMasterPublicKey: asValue(
PublicKey.fromString(
options.WITHDRAWALS_MASTER_PUBLIC_KEY,
Expand Down Expand Up @@ -439,19 +435,19 @@ function createDIContainer(dppWasmLoaded, options) {
logJsonFileLevel,
logJsonFileStream,
) => [
{
level: logStdoutLevel,
stream: logStdoutStream,
},
{
level: logPrettyFileLevel,
stream: logPrettyFileStream,
},
{
level: logJsonFileLevel,
stream: logJsonFileStream,
},
]),
{
level: logStdoutLevel,
stream: logStdoutStream,
},
{
level: logPrettyFileLevel,
stream: logPrettyFileStream,
},
{
level: logJsonFileLevel,
stream: logJsonFileStream,
},
]),

logger: asFunction(
(loggerStreams) => pino({
Expand Down Expand Up @@ -622,7 +618,7 @@ function createDIContainer(dppWasmLoaded, options) {
* Register DPP
*/
container.register({
dppWasm: asValue(dppWasmLoaded),
dppWasm: asValue(dppWasm),

DashPlatformProtocol: asFunction((dppWasm) => dppWasm.DashPlatformProtocol),

Expand Down
11 changes: 5 additions & 6 deletions packages/js-drive/lib/document/fetchDataContractFactory.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
const IdentifierError = require('@dashevo/dpp/lib/identifier/errors/IdentifierError');
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');

const InvalidQueryError = require('./errors/InvalidQueryError');

/**
* @param {DataContractStoreRepository} dataContractRepository
* @param {WebAssembly.Instance} dppWasm
* @returns {fetchDocuments}
*/
function fetchDataContractFactory(
dataContractRepository,
dppWasm,
) {
/**
* Fetch Data Contract by Contract ID and type
*
* @typedef {Promise} fetchDataContract
* @param {Buffer|Identifier} contractId
* @param {Buffer|dppWasm.Identifier} contractId
* @returns {Promise<StorageResult<DataContract>>}
*/
async function fetchDataContract(contractId) {
let contractIdIdentifier;
try {
contractIdIdentifier = new Identifier(contractId);
contractIdIdentifier = new dppWasm.Identifier(contractId);
} catch (e) {
if (e instanceof IdentifierError) {
if (e instanceof dppWasm.IdentifierError) {
throw new InvalidQueryError(`invalid data contract ID: ${e.message}`);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/js-drive/lib/dpp/DriveStateRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { TYPES } = require('@dashevo/dpp/lib/identity/IdentityPublicKey');

const ReadOperation = require('@dashevo/dpp/lib/stateTransition/fee/operations/ReadOperation');
const SignatureVerificationOperation = require('@dashevo/dpp/lib/stateTransition/fee/operations/SignatureVerificationOperation');
const BlockInfo = require('../blockExecution/BlockInfo');
Expand All @@ -22,6 +20,7 @@ class DriveStateRepository {
* @param {BlockExecutionContext} blockExecutionContext
* @param {SimplifiedMasternodeList} simplifiedMasternodeList
* @param {Drive} rsDrive
* @param {WebAssembly.Instance} dppWasm
* @param {Object} [options]
* @param {Object} [options.useTransaction=false]
*/
Expand All @@ -37,6 +36,7 @@ class DriveStateRepository {
blockExecutionContext,
simplifiedMasternodeList,
rsDrive,
dppWasm,
options = {},
) {
this.identityRepository = identityRepository;
Expand All @@ -50,6 +50,7 @@ class DriveStateRepository {
this.blockExecutionContext = blockExecutionContext;
this.simplifiedMasternodeList = simplifiedMasternodeList;
this.rsDrive = rsDrive;
this.dppWasm = dppWasm;
this.#options = options;
}

Expand Down Expand Up @@ -571,7 +572,7 @@ class DriveStateRepository {

if (executionContext) {
executionContext.addOperation(
new SignatureVerificationOperation(TYPES.ECDSA_SECP256K1),
new SignatureVerificationOperation(this.dppWasm.KeyTypes.ECDSA_SECP256K1),
);

if (executionContext.isDryRun()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const IdentityPublicKey = require('@dashevo/dpp/lib/identity/IdentityPublicKey');
const Identity = require('@dashevo/dpp/lib/identity/Identity');
const InvalidMasternodeIdentityError = require('./errors/InvalidMasternodeIdentityError');

/**
* @param {DashPlatformProtocol} dpp
* @param {IdentityStoreRepository} identityRepository
* @param {getWithdrawPubKeyTypeFromPayoutScript} getWithdrawPubKeyTypeFromPayoutScript
* @param {getPublicKeyFromPayoutScript} getPublicKeyFromPayoutScript
* @param {WebAssembly.Instance} dppWasm
* @return {createMasternodeIdentity}
*/
function createMasternodeIdentityFactory(
dpp,
identityRepository,
getWithdrawPubKeyTypeFromPayoutScript,
getPublicKeyFromPayoutScript,
dppWasm,
) {
/**
* @typedef createMasternodeIdentity
Expand All @@ -34,8 +34,8 @@ function createMasternodeIdentityFactory(
const publicKeys = [{
id: 0,
type: pubKeyType,
purpose: IdentityPublicKey.PURPOSES.AUTHENTICATION,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.MASTER,
purpose: dppWasm.KeyPurpose.AUTHENTICATION,
securityLevel: dppWasm.KeySecurityLevel.MASTER,
readOnly: true,
// Copy data buffer
data: Buffer.from(pubKeyData),
Expand All @@ -47,14 +47,14 @@ function createMasternodeIdentityFactory(
publicKeys.push({
id: 1,
type: withdrawPubKeyType,
purpose: IdentityPublicKey.PURPOSES.WITHDRAW,
securityLevel: IdentityPublicKey.SECURITY_LEVELS.CRITICAL,
purpose: dppWasm.KeyPurpose.WITHDRAW,
securityLevel: dppWasm.KeySecurityLevel.CRITICAL,
readOnly: false,
data: getPublicKeyFromPayoutScript(payoutScript, withdrawPubKeyType),
data: getPublicKeyFromPayoutScript(dppWasm, payoutScript, withdrawPubKeyType),
});
}

const identity = new Identity({
const identity = new dppWasm.Identity({
protocolVersion: dpp.getProtocolVersion(),
id: identifier.toBuffer(),
publicKeys,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Identifier = require('@dashevo/dpp/lib/identifier/Identifier');
const { hash } = require('@dashevo/dpp/lib/util/hash');

/**
* @param {SimplifiedMNListEntry} smlEntry
* @param {WebAssembly.Instance} dppWasm
*/
function createOperatorIdentifier(smlEntry) {
function createOperatorIdentifier(dppWasm, smlEntry) {
const operatorPubKey = Buffer.from(smlEntry.pubKeyOperator, 'hex');

return Identifier.from(
return dppWasm.Identifier.from(
hash(
Buffer.concat([
Buffer.from(smlEntry.proRegTxHash, 'hex'),
Expand Down
Loading