Skip to content
Closed
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
3 changes: 1 addition & 2 deletions .codacy/codacy.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
runtimes:
- java@17.0.10
- node@22.2.0
- java@17.0.10
- python@3.11.11
tools:
- eslint@8.57.0
- lizard@1.17.31
- pmd@6.55.0
- semgrep@1.78.0
- trivy@0.66.0
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion brightchain-api-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"types": "./src/index.d.ts",
"dependencies": {
"@aws-sdk/client-ses": "^3.859.0",
"@brightchain/brightchain-lib": "0.10.0",
"@brightchain/brightchain-lib": "0.11.0",
"@digitaldefiance/enclave-bridge-client": "^1.1.0",
"@digitaldefiance/node-ecies-lib": "^4.13.8",
"@ethereumjs/wallet": "^10.0.0",
Expand Down
2 changes: 1 addition & 1 deletion brightchain-api-lib/src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class App<TID extends PlatformID> extends BaseApplication<TID> {
: new HandleableError(
new Error(
err.message ||
translate(BrightChainStrings.Error_UnexpectedError),
translate(BrightChainStrings.Error_Unexpected_Error),
),
{ cause: err },
);
Expand Down
43 changes: 0 additions & 43 deletions brightchain-api-lib/src/lib/interfaces/api-constants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,6 @@ describe('IApiConstants Type Structure', () => {
});
});

describe('Duplicate Interfaces Removed', () => {
it('should not have local checksum-consts.ts file', () => {
// Verify that the duplicate interface file has been removed
expect(() => {
// This will throw if the file doesn't exist
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./checksum-consts');
}).toThrow();
});

it('should not have local encryption-consts.ts file', () => {
// Verify that the duplicate interface file has been removed
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./encryption-consts');
}).toThrow();
});

it('should not have local fec-consts.ts file', () => {
// Verify that the duplicate interface file has been removed
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./fec-consts');
}).toThrow();
});

it('should not have local keyring-consts.ts file', () => {
// Verify that the duplicate interface file has been removed
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./keyring-consts');
}).toThrow();
});

it('should not have local wrapped-key-consts.ts file', () => {
// Verify that the duplicate interface file has been removed
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./wrapped-key-consts');
}).toThrow();
});
});

describe('Upstream Properties Available', () => {
it('should have access to PBKDF2 from upstream', () => {
// Verify that properties from upstream are accessible
Expand Down
6 changes: 2 additions & 4 deletions brightchain-api-lib/src/lib/stores/diskCBLStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export class DiskCBLStore<

this._blockService = getGlobalServiceProvider<TID>().blockService;
this._cblService = getGlobalServiceProvider<TID>().cblService;
this._checksumService =
getGlobalServiceProvider<TID>().checksumService;
this._checksumService = getGlobalServiceProvider<TID>().checksumService;
}

/**
Expand Down Expand Up @@ -248,8 +247,7 @@ export class DiskCBLStore<

// Hydrate the creator
const idProvider =
getGlobalServiceProvider<TID>().eciesService.constants
.idProvider;
getGlobalServiceProvider<TID>().eciesService.constants.idProvider;
const creator: Member<TID> =
this._activeUser &&
arraysEqual(
Expand Down
2 changes: 1 addition & 1 deletion brightchain-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@brightchain/brightchain-lib",
"version": "0.10.0",
"version": "0.11.0",
"description": "BrightChain core library - browser-compatible blockchain storage",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion brightchain-lib/src/lib/blockPaddingTransform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { randomBytes } from './browserCrypto';
import { Transform, TransformCallback } from './browserStream';
import { BrightChainStrings } from './enumerations';
import { BlockSize } from './enumerations/blockSize';
import { TranslatableBrightChainError } from './errors/translatableBrightChainError';

class BlockPaddingTransform extends Transform {
private readonly blockSize: number;
Expand Down Expand Up @@ -29,7 +31,9 @@ class BlockPaddingTransform extends Transform {
data = new Uint8Array(chunk);
} else {
callback(
new Error('Input must be Uint8Array, TypedArray, or ArrayBuffer'),
new TranslatableBrightChainError(
BrightChainStrings.BlockPaddingTransform_MustBeArray,
),
);
return;
}
Expand Down
10 changes: 2 additions & 8 deletions brightchain-lib/src/lib/blocks/cblBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,11 @@ export abstract class CBLBase<TID extends PlatformID = Uint8Array>

// Validate that we got valid byte arrays
if (!creatorIdBytes || creatorIdBytes.length === 0) {
throw new CblError(
CblErrorType.InvalidStructure,
'Failed to extract creator ID bytes from CBL header',
);
throw new CblError(CblErrorType.FailedToExtractCreatorId);
}

if (!memberIdBytes || memberIdBytes.length === 0) {
throw new CblError(
CblErrorType.InvalidStructure,
'Failed to extract member ID bytes from provided creator',
);
throw new CblError(CblErrorType.FailedToExtractProvidedCreatorId);
}

// Use constant-time comparison for security (prevents timing attacks)
Expand Down
4 changes: 1 addition & 3 deletions brightchain-lib/src/lib/blocks/edgeCases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ describe('Block Edge Cases', () => {

expect(() => {
new RawDataBlock(blockSize, oversizedData, new Date());
}).toThrow(
`Data length (${(blockSize as number) + 1}) exceeds block size (${blockSize})`,
);
}).toThrow(/Error_BlockError_DataLengthExceedsBlockSizeTemplate/);
});
};

Expand Down
3 changes: 1 addition & 2 deletions brightchain-lib/src/lib/blocks/encrypted.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { BlockValidationErrorType } from '../enumerations/blockValidationErrorTy
import { EphemeralBlockMetadata } from '../ephemeralBlockMetadata';
import { BlockValidationError } from '../errors/block';
import { ChecksumMismatchError } from '../errors/checksumMismatch';
import { initializeBrightChain } from '../init';
import { ChecksumService } from '../services/checksum.service';
import { ServiceProvider } from '../services/service.provider';
import { Checksum } from '../types/checksum';
Expand Down Expand Up @@ -89,8 +90,6 @@ describe('EncryptedBlock', () => {

beforeAll(() => {
// Initialize BrightChain with browser-compatible configuration first
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { initializeBrightChain } = require('../init');
initializeBrightChain();

// Reset service provider to ensure we use the correct configuration
Expand Down
8 changes: 5 additions & 3 deletions brightchain-lib/src/lib/blocks/encrypted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ import { EphemeralBlock } from './ephemeral';
interface IEncryptedBlockServices<TID extends PlatformID> {
idProvider: TypedIdProviderWrapper<TID>;
eciesService: {
parseSingleEncryptedHeader(...args: unknown[]): ISingleEncryptedParsedHeader;
parseSingleEncryptedHeader(
...args: unknown[]
): ISingleEncryptedParsedHeader;
parseMultiEncryptedHeader(...args: unknown[]): IMultiEncryptedParsedHeader;
};
blockService: {
decrypt(
creator: Member<TID>,
block: unknown,
newBlockType: BlockType
newBlockType: BlockType,
): Promise<unknown>;
decryptMultiple(creator: Member<TID>, block: unknown): Promise<unknown>;
};
Expand Down Expand Up @@ -218,7 +220,7 @@ export class EncryptedBlock<TID extends PlatformID = Uint8Array>
rBytes = r;
} else {
// For Guid objects, get the bytes using the idProvider
const result = this._idProvider.toBytes(r as any);
const result = this._idProvider.toBytes(r);
rBytes = result;
}
return arraysEqual(rBytes, recipientWithKey.idBytes);
Expand Down
7 changes: 6 additions & 1 deletion brightchain-lib/src/lib/blocks/encryptedBlockCreator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Member, PlatformID } from '@digitaldefiance/ecies-lib';
import { BrightChainStrings } from '../enumerations';
import { BlockDataType } from '../enumerations/blockDataType';
import { BlockSize } from '../enumerations/blockSize';
import { BlockType } from '../enumerations/blockType';
import { TranslatableBrightChainError } from '../errors/translatableBrightChainError';
import { Checksum } from '../types/checksum';
import { EncryptedBlock } from './encrypted';

Expand Down Expand Up @@ -50,7 +52,10 @@ export class EncryptedBlockCreator {
): Promise<EncryptedBlock<TID>> {
const blockCreator = EncryptedBlockCreator.creators.get(type);
if (!blockCreator) {
throw new Error(`No creator registered for block type ${type}`);
throw new TranslatableBrightChainError(
BrightChainStrings.EncryptedBlockCreator_NoCreatorRegisteredTemplate,
{ TYPE: type },
);
}
return blockCreator(
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe('EncryptedBlockFactory', () => {
const checksum = checksumService.calculateChecksum(data);
const testDate = new Date('2024-01-01');

// Use EncryptedOwnedDataBlock which is a valid encrypted block type
const block = await EncryptedBlockFactory.createBlock(
BlockType.EncryptedOwnedDataBlock,
BlockDataType.RawData,
Expand Down
Loading
Loading