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
26 changes: 26 additions & 0 deletions sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-floating-promises': 'error',
'no-console': 'warn',
},
env: {
node: true,
es2020: true,
},
};
10 changes: 10 additions & 0 deletions sdk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"arrowParens": "always",
"endOfLine": "lf"
}
118 changes: 118 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# PrivacyLayer TypeScript SDK

TypeScript SDK for integrating privacy pool functionality into applications built on Stellar/Soroban.

## Installation

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

## Quick Start

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

// Initialize the client
const client = new PrivacyLayer({
rpcUrl: 'https://soroban-testnet.stellar.org',
networkPassphrase: 'Test SDF Network ; September 2015',
contractId: 'YOUR_CONTRACT_ID',
});

// Generate a note for deposit
const { commitment } = await client.generateNote(Denomination.HUNDRED);
```

## Usage

### Client Configuration

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

const client = createClient({
rpcUrl: 'https://soroban-testnet.stellar.org',
networkPassphrase: 'Test SDF Network ; September 2015',
contractId: 'YOUR_CONTRACT_ID',
});
```

### Types

All types are exported from the main package:

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

### Constants

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

// Access predefined networks
const testnetConfig = NETWORKS.testnet;
```

### Utilities

The SDK exports utility functions for cryptographic operations, encoding, and validation:

```typescript
import {
randomFieldElement,
fieldToHex,
validateAddress,
validateAmount,
} from '@privacylayer/sdk';
```

## API Reference

### PrivacyLayer Client

#### `new PrivacyLayer(config)`

Creates a new PrivacyLayer client instance.

**Parameters:**
- `config.rpcUrl` - Soroban RPC endpoint URL
- `config.networkPassphrase` - Stellar network passphrase
- `config.contractId` - PrivacyLayer contract ID

#### `createClient(config)`

Factory function to create a PrivacyLayer client.

### Denomination

Enum for supported note denominations:

- `Denomination.TEN = 10`
- `Denomination.HUNDRED = 100`
- `Denomination.THOUSAND = 1000`
- `Denomination.TEN_THOUSAND = 10000`

## Development

```bash
# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Run tests with coverage
npm run coverage

# Lint
npm run lint
```

## License

MIT
26 changes: 26 additions & 0 deletions sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.test.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/__tests__/**',
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
verbose: true,
};
48 changes: 48 additions & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@privacylayer/sdk",
"version": "0.1.0",
"description": "TypeScript SDK for PrivacyLayer - enables developers to integrate privacy pool functionality into their applications",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.js"
}
},
"scripts": {
"build": "tsc",
"test": "jest",
"lint": "eslint src --ext .ts",
"coverage": "jest --coverage",
"prepublishOnly": "npm run build"
},
"keywords": [
"privacy",
"stellar",
"soroban",
"sdk"
],
"author": "",
"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"
}
}
Loading