Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ coverage/
*.swo
*~
.DS_Store
.kiro

# Logs
*.log
Expand Down
18 changes: 18 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Root ESLint configuration for monorepo
// This delegates to package-level configs

export default [
{
ignores: [
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/.turbo/**',
'**/target/**',
'**/*.config.js',
'**/*.config.cjs',
'**/*.config.mjs',
],
},
];
15 changes: 15 additions & 0 deletions packages/crypto/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ module.exports = [
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {
// Node.js globals
TextEncoder: 'readonly',
TextDecoder: 'readonly',
crypto: 'readonly',
// Jest globals
describe: 'readonly',
it: 'readonly',
expect: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
jest: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
Expand Down
40 changes: 40 additions & 0 deletions packages/crypto/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.test.ts', '**/?(*.)+(spec|test).ts'],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/__tests__/**',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
],
// Coverage thresholds - will be enforced once implementation is complete
// coverageThreshold: {
// global: {
// branches: 100,
// functions: 100,
// lines: 100,
// statements: 100,
// },
// },
moduleNameMapper: {
'^@ancore/types$': '<rootDir>/../types/src',
},
transform: {
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: {
esModuleInterop: true,
allowSyntheticDefaultImports: true,
},
},
],
},
};
16 changes: 14 additions & 2 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
"test": "echo 'No tests yet'",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"lint": "eslint src/",
"clean": "rm -rf dist"
},
Expand All @@ -21,15 +23,25 @@
"license": "Apache-2.0",
"dependencies": {
"@ancore/types": "workspace:*",
"@noble/ciphers": "^2.1.1",
"@noble/ed25519": "^2.1.0",
"@noble/hashes": "^1.4.0"
"@noble/hashes": "^1.4.0",
"@stellar/stellar-sdk": "^13.0.0",
"bip39": "^3.1.0",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@types/bip39": "^3.0.4",
"@types/jest": "^30.0.0",
"@types/zxcvbn": "^4.4.5",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^9.0.0",
"fast-check": "^4.5.3",
"jest": "^30.2.0",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"tsup": "^8.0.0",
"typescript": "^5.6.0"
}
Expand Down
15 changes: 15 additions & 0 deletions packages/crypto/src/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Setup verification test
* This test verifies that Jest and TypeScript are configured correctly
*/

describe('Setup', () => {
it('should verify Jest is working', () => {
expect(true).toBe(true);
});

it('should verify TypeScript strict mode', () => {
const value: string = 'test';
expect(typeof value).toBe('string');
});
});
110 changes: 110 additions & 0 deletions packages/crypto/src/__tests__/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Tests for type definitions
*
* These tests verify that all type interfaces are properly exported
* and can be used for type checking.
*/

import type {
Keypair,
EncryptedData,
PasswordStrength,
MnemonicOptions,
DerivationOptions,
} from '../types';

describe('Type Definitions', () => {
describe('Keypair', () => {
it('should accept valid keypair structure', () => {
const keypair: Keypair = {
publicKey: 'GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
secretKey: 'SBZVMB74NZNCJYEQVQHQKUDGKZXVLAUSPYAI2VJABQV3KQIQKLSXJVGW',
};

expect(keypair.publicKey).toBeDefined();
expect(keypair.secretKey).toBeDefined();
});
});

describe('EncryptedData', () => {
it('should accept valid encrypted data structure', () => {
const encryptedData: EncryptedData = {
ciphertext: new Uint8Array([1, 2, 3]),
salt: new Uint8Array(32),
nonce: new Uint8Array(24),
};

expect(encryptedData.ciphertext).toBeInstanceOf(Uint8Array);
expect(encryptedData.salt).toBeInstanceOf(Uint8Array);
expect(encryptedData.nonce).toBeInstanceOf(Uint8Array);
});
});

describe('PasswordStrength', () => {
it('should accept valid password strength structure', () => {
const strength: PasswordStrength = {
score: 3,
feedback: ['Add another word'],
isValid: true,
};

expect(strength.score).toBe(3);
expect(strength.feedback).toBeInstanceOf(Array);
expect(strength.isValid).toBe(true);
});
});

describe('MnemonicOptions', () => {
it('should accept valid mnemonic options with 128-bit strength', () => {
const options: MnemonicOptions = {
strength: 128,
};

expect(options.strength).toBe(128);
});

it('should accept valid mnemonic options with 256-bit strength', () => {
const options: MnemonicOptions = {
strength: 256,
};

expect(options.strength).toBe(256);
});

it('should accept empty options object', () => {
const options: MnemonicOptions = {};

expect(options).toBeDefined();
});
});

describe('DerivationOptions', () => {
it('should accept valid derivation options', () => {
const options: DerivationOptions = {
accountIndex: 5,
};

expect(options.accountIndex).toBe(5);
});

it('should accept empty options object', () => {
const options: DerivationOptions = {};

expect(options).toBeDefined();
});
});

describe('Type Exports', () => {
it('should export all types from index', () => {
// This test verifies that types can be imported from the main index
// TypeScript compilation will fail if types are not properly exported
const testImport = async () => {
const types = await import('../index');
// If this compiles, the types are properly exported
expect(types).toBeDefined();
};

expect(testImport).toBeDefined();
});
});
});
16 changes: 11 additions & 5 deletions packages/crypto/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
* Cryptographic utilities for Ancore wallet
*/

// Placeholder export - implement as package develops
// Type exports
export type {
Keypair,
EncryptedData,
PasswordStrength,
MnemonicOptions,
DerivationOptions,
} from './types';

export const CRYPTO_VERSION = '0.1.0';

// Example exports (implement as needed):
// export { generateKeyPair } from './keypair';
// export { sign, verify } from './signatures';
// export { encrypt, decrypt } from './encryption';
// Password module exports
export { validatePassword, generateSalt, deriveEncryptionKey } from './password';
Loading