Skip to content
Open
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
25 changes: 25 additions & 0 deletions sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
'no-console': ['warn', { allow: ['warn', 'error'] }],
'curly': ['error', 'all'],
'eqeqeq': ['error', 'always'],
'no-throw-literal': 'error',
},
};
8 changes: 8 additions & 0 deletions sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
117 changes: 117 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# @privacylayer/sdk

TypeScript SDK for PrivacyLayer - Zero-knowledge shielded pool on Stellar Soroban

## Installation

```bash
npm install @privacylayer/sdk
```

## Quick Start

```typescript
import { utils, Denomination } from '@privacylayer/sdk';

// Generate a new note
const note = utils.generateNote(Denomination.TEN);
console.log('Generated note:', note);

// Validate the note
const errors = utils.validateNote(note);
if (errors.length === 0) {
console.log('Note is valid');
}

// Convert between formats
const hex = 'deadbeef';
const buffer = utils.hexToBuffer(hex);
const backToHex = utils.bufferToHex(buffer);
console.log('Conversion successful:', backToHex === hex);
```

## Features

- **Note Generation**: Create privacy-preserving notes for deposits
- **Cryptographic Utilities**: Field element operations and validation
- **Encoding/Decoding**: Hex, base64, and buffer conversions
- **Validation**: Address, amount, and network configuration validation
- **Type Safety**: Full TypeScript support with comprehensive type definitions

## API Reference

### Core Types

```typescript
import { Note, Denomination, DepositReceipt, NetworkConfig } from '@privacylayer/sdk';

// Note structure
const note: Note = {
nullifier: 'hex-string',
secret: 'hex-string',
commitment: 'hex-string',
denomination: Denomination.TEN
};
```

### Utilities

The SDK provides utility functions in three categories:

1. **Crypto**: Cryptographic operations and field element handling
2. **Encoding**: Data format conversions
3. **Validation**: Input validation and sanitization

```typescript
import { utils } from '@privacylayer/sdk';

// Generate random field element
const fieldElement = utils.randomFieldElement();

// Validate Stellar address
const isValid = utils.isValidStellarAddress('G...');

// Convert hex to base64
const base64 = utils.hexToBase64('deadbeef');
```

## Development

### Setup

```bash
cd sdk
npm install
```

### Build

```bash
npm run build
```

### Test

```bash
npm test
```

### Lint

```bash
npm run lint
```

### Format Code

```bash
npm run format
```

## Contributing

Contributions are welcome! Please see the main repository's [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines.

## License

MIT
23 changes: 23 additions & 0 deletions sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.test.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/__tests__/**',
'!src/index.ts'
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
coverageDirectory: 'coverage',
verbose: true
};
56 changes: 56 additions & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@privacylayer/sdk",
"version": "0.1.0",
"description": "TypeScript SDK for PrivacyLayer - Zero-knowledge shielded pool on Stellar Soroban",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc",
"test": "jest",
"lint": "eslint src --ext .ts",
"format": "prettier --write src/**/*.ts",
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint"
},
"keywords": [
"stellar",
"soroban",
"zk",
"zero-knowledge",
"privacy",
"cryptography"
],
"author": "PrivacyLayer Contributors",
"license": "MIT",
"dependencies": {
"@stellar/stellar-sdk": "^12.0.0",
"bignumber.js": "^9.1.0",
"buffer": "^6.0.3"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.50.0",
"jest": "^29.7.0",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"typescript": "^5.2.0"
},
"engines": {
"node": ">=18.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ANAVHEOBA/PrivacyLayer.git",
"directory": "sdk"
},
"bugs": {
"url": "https://github.com/ANAVHEOBA/PrivacyLayer/issues"
},
"homepage": "https://github.com/ANAVHEOBA/PrivacyLayer#readme"
}
Loading