@t-0/provider-starter-ts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -0
- package/bin/cli.js +5 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +121 -0
- package/dist/create.js.map +1 -0
- package/package.json +43 -0
- package/template/.dockerignore +43 -0
- package/template/.env +11 -0
- package/template/.env.example +14 -0
- package/template/.eslintrc.json +20 -0
- package/template/Dockerfile +56 -0
- package/template/package-lock.json +2071 -0
- package/template/package.json +30 -0
- package/template/src/get_quote.ts +29 -0
- package/template/src/index.ts +67 -0
- package/template/src/lib.ts +13 -0
- package/template/src/publish_quotes.ts +34 -0
- package/template/src/service.ts +50 -0
- package/template/src/submit_payment.ts +24 -0
- package/template/tsconfig.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# t-0 Network Provider Starter
|
|
2
|
+
|
|
3
|
+
CLI tool to quickly bootstrap a Node.js TypeScript integration service for the t-0 Network.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This CLI tool scaffolds a complete TypeScript project configured to integrate with the t-0 Network as a provider. It automatically generates secp256k1 cryptographic key pairs, sets up your development environment, and includes all necessary dependencies to get started immediately.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
Before using this tool, ensure you have:
|
|
12
|
+
|
|
13
|
+
- **Node.js** >= 14.0.0
|
|
14
|
+
- **npm** >= 6.0.0
|
|
15
|
+
- **OpenSSL** (for cryptographic key generation)
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Using npx (Recommended)
|
|
20
|
+
|
|
21
|
+
Run the following command to create a new t-0 Network integration:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx @t-0/provider-starter-ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Alternative: Global Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g @t-0/provider-starter-ts
|
|
31
|
+
provider-starter-ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What It Does
|
|
35
|
+
|
|
36
|
+
When you run the CLI tool, it performs the following steps automatically:
|
|
37
|
+
|
|
38
|
+
1. **Interactive Prompt** - Asks for your project name
|
|
39
|
+
2. **Project Directory** - Creates a new directory with your project name
|
|
40
|
+
3. **Template Setup** - Copies pre-configured TypeScript project structure
|
|
41
|
+
4. **Key Generation** - Generates a secp256k1 cryptographic key pair using OpenSSL
|
|
42
|
+
5. **Environment Configuration** - Creates `.env` file with:
|
|
43
|
+
- Generated private key (`PROVIDER_PRIVATE_KEY`)
|
|
44
|
+
- Generated public key (as comment for reference)
|
|
45
|
+
- t-0 Network public key (`NETWORK_PUBLIC_KEY`)
|
|
46
|
+
- Server configuration (`PORT`, `NODE_ENV`)
|
|
47
|
+
- Optional quote publishing interval
|
|
48
|
+
6. **Git Initialization** - Initializes git repository with `.gitignore`
|
|
49
|
+
7. **Dependency Installation** - Runs `npm install` to install all dependencies
|
|
50
|
+
|
|
51
|
+
## Generated Project Structure
|
|
52
|
+
|
|
53
|
+
After running the CLI, your new project will have the following structure:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
your-project-name/
|
|
57
|
+
├── src/
|
|
58
|
+
│ ├── index.ts # Main entry point
|
|
59
|
+
│ ├── service.ts # Provider service implementation
|
|
60
|
+
│ ├── publish_quotes.ts # Quote publishing logic
|
|
61
|
+
│ ├── get_quote.ts # Quote retrieval logic
|
|
62
|
+
│ ├── submit_payment.ts # Payment submission logic
|
|
63
|
+
│ └── lib.ts # Utility functions
|
|
64
|
+
├── .env # Environment variables (with generated keys)
|
|
65
|
+
├── .env.example # Example environment file
|
|
66
|
+
├── .eslintrc.json # ESLint configuration
|
|
67
|
+
├── .gitignore # Git ignore rules
|
|
68
|
+
├── package.json # Project dependencies
|
|
69
|
+
└── tsconfig.json # TypeScript configuration
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Environment Variables
|
|
73
|
+
|
|
74
|
+
The generated `.env` file includes:
|
|
75
|
+
|
|
76
|
+
| Variable | Description |
|
|
77
|
+
|----------|-------------|
|
|
78
|
+
| `NETWORK_PUBLIC_KEY` | t-0 Network's public key (pre-configured) |
|
|
79
|
+
| `PROVIDER_PRIVATE_KEY` | Your generated private key (keep secret!) |
|
|
80
|
+
| `PORT` | Server port (default: 3000) |
|
|
81
|
+
| `NODE_ENV` | Environment mode (default: development) |
|
|
82
|
+
| `TZERO_ENDPOINT` | t-0 Network API endpoint (default: sandbox) |
|
|
83
|
+
| `QUOTE_PUBLISHING_INTERVAL` | Quote publishing frequency in ms (optional) |
|
|
84
|
+
|
|
85
|
+
## Available Scripts
|
|
86
|
+
|
|
87
|
+
In your generated project, you can run:
|
|
88
|
+
|
|
89
|
+
### `npm run dev`
|
|
90
|
+
|
|
91
|
+
Runs the service in development mode using `ts-node`.
|
|
92
|
+
|
|
93
|
+
### `npm run build`
|
|
94
|
+
|
|
95
|
+
Compiles TypeScript to JavaScript in the `dist/` directory.
|
|
96
|
+
|
|
97
|
+
### `npm start`
|
|
98
|
+
|
|
99
|
+
Runs the compiled production build from `dist/`.
|
|
100
|
+
|
|
101
|
+
### `npm run lint`
|
|
102
|
+
|
|
103
|
+
Lints TypeScript files in the `src/` directory using ESLint.
|
|
104
|
+
|
|
105
|
+
## Getting Started with Your Integration
|
|
106
|
+
|
|
107
|
+
After creating your project:
|
|
108
|
+
|
|
109
|
+
1. **Navigate to project directory:**
|
|
110
|
+
```bash
|
|
111
|
+
cd your-project-name
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
2. **Review the generated keys:**
|
|
115
|
+
- Open `.env` file
|
|
116
|
+
- Your private key is stored in `PROVIDER_PRIVATE_KEY`
|
|
117
|
+
- Your public key is shown as a comment (you'll need to share this)
|
|
118
|
+
|
|
119
|
+
3. **Share your public key with t-0 team:**
|
|
120
|
+
- Find your public key in the `.env` file (marked as "Step 1.2")
|
|
121
|
+
- Contact the t-0 team to register your provider
|
|
122
|
+
|
|
123
|
+
4. **Implement quote publishing:**
|
|
124
|
+
- Edit `src/publish_quotes.ts` to implement your quote publishing logic
|
|
125
|
+
- This determines how you provide exchange rate quotes to the network
|
|
126
|
+
|
|
127
|
+
5. **Start development server:**
|
|
128
|
+
```bash
|
|
129
|
+
npm run dev
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
6. **Test your integration:**
|
|
133
|
+
- Follow the TODO comments in `src/index.ts` for step-by-step guidance
|
|
134
|
+
- Test quote retrieval
|
|
135
|
+
- Test payment submission
|
|
136
|
+
- Verify payout endpoint
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Key Features
|
|
140
|
+
|
|
141
|
+
- **Type Safety** - Full TypeScript support with strict mode enabled
|
|
142
|
+
- **Automatic Key Generation** - Secure secp256k1 key pairs generated via OpenSSL
|
|
143
|
+
- **Pre-configured SDK** - t-0 Provider SDK integrated and ready to use
|
|
144
|
+
- **Development Ready** - Hot reload support with ts-node
|
|
145
|
+
- **Production Ready** - Optimized build configuration
|
|
146
|
+
- **Security First** - `.env` automatically excluded from git
|
|
147
|
+
- **Code Quality** - ESLint configured with TypeScript rules
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## Security Considerations
|
|
151
|
+
|
|
152
|
+
- **Never commit `.env` file** - It's automatically added to `.gitignore`
|
|
153
|
+
- **Keep private key secure** - The `PROVIDER_PRIVATE_KEY` must remain confidential
|
|
154
|
+
- **Share only public key** - Only the public key should be shared with t-0 team
|
|
155
|
+
- **Use environment-specific configs** - Different keys for dev/staging/production
|
|
156
|
+
|
|
157
|
+
## Deployment
|
|
158
|
+
|
|
159
|
+
When ready to deploy:
|
|
160
|
+
|
|
161
|
+
1. **Build your project:**
|
|
162
|
+
```bash
|
|
163
|
+
npm run build
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
2. **Set environment variables** on your hosting platform
|
|
167
|
+
|
|
168
|
+
3. **Provide your base URL to t-0 team** for network registration
|
|
169
|
+
|
|
170
|
+
4. **Start the service:**
|
|
171
|
+
```bash
|
|
172
|
+
npm start
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Troubleshooting
|
|
176
|
+
|
|
177
|
+
### "Directory already exists" Error
|
|
178
|
+
The project directory name is already taken. Choose a different project name.
|
|
179
|
+
|
|
180
|
+
### "OpenSSL not found" Error
|
|
181
|
+
Install OpenSSL:
|
|
182
|
+
- **macOS:** `brew install openssl`
|
|
183
|
+
- **Ubuntu/Debian:** `sudo apt-get install openssl`
|
|
184
|
+
- **Windows:** Download from [openssl.org](https://www.openssl.org/)
|
|
185
|
+
|
|
186
|
+
### Key Generation Fails
|
|
187
|
+
Ensure OpenSSL is installed and accessible in your PATH. Try running:
|
|
188
|
+
```bash
|
|
189
|
+
openssl version
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### npm install Fails
|
|
193
|
+
Check your Node.js and npm versions:
|
|
194
|
+
```bash
|
|
195
|
+
node --version # Should be >= 14
|
|
196
|
+
npm --version # Should be >= 6
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Support
|
|
200
|
+
|
|
201
|
+
For issues or questions:
|
|
202
|
+
- Review the generated code comments and TODO markers
|
|
203
|
+
- Check the [t-0 Network documentation](https://t-0.network)
|
|
204
|
+
- Contact the t-0 team for integration support
|
package/bin/cli.js
ADDED
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAeA,iBAAe,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAkGrC;AAkCD,eAAe,MAAM,CAAC"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
async function create() {
|
|
12
|
+
console.log(chalk_1.default.blue('\n🚀 Create Your Service\n'));
|
|
13
|
+
// Prompt for project name
|
|
14
|
+
const answers = await inquirer_1.default.prompt([
|
|
15
|
+
{
|
|
16
|
+
type: 'input',
|
|
17
|
+
name: 'projectName',
|
|
18
|
+
message: 'Project name:',
|
|
19
|
+
validate: (input) => {
|
|
20
|
+
if (!input)
|
|
21
|
+
return 'Project name is required';
|
|
22
|
+
if (!/^[a-z0-9-_]+$/.test(input)) {
|
|
23
|
+
return 'Project name can only contain lowercase letters, numbers, hyphens and underscores';
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
const projectName = answers.projectName;
|
|
30
|
+
const projectPath = path_1.default.join(process.cwd(), projectName);
|
|
31
|
+
// Check if directory exists
|
|
32
|
+
if (fs_extra_1.default.existsSync(projectPath)) {
|
|
33
|
+
console.log(chalk_1.default.red(`\n❌ Directory "${projectName}" already exists!`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
console.log(chalk_1.default.green(`\n✨ Creating project in ${projectPath}...\n`));
|
|
37
|
+
try {
|
|
38
|
+
// Create project directory
|
|
39
|
+
fs_extra_1.default.mkdirSync(projectPath);
|
|
40
|
+
// Copy template files
|
|
41
|
+
const templatePath = path_1.default.join(__dirname, '../template');
|
|
42
|
+
fs_extra_1.default.copySync(templatePath, projectPath);
|
|
43
|
+
// Generate key pair
|
|
44
|
+
console.log(chalk_1.default.cyan('🔐 Generating key pair...'));
|
|
45
|
+
const keys = generateKeyPair();
|
|
46
|
+
// Create .env file with keys
|
|
47
|
+
const envContent = `
|
|
48
|
+
NETWORK_PUBLIC_KEY=0x0436a6bba96086e02bcc8ea3700b82b4722f84b2b7489f36e4490f9a9342b77abfb6428b4a447824e0a6f5abd89098c985f4e506c65b5e9ae64a92810e1a1c0e79
|
|
49
|
+
|
|
50
|
+
# Private Key (secp256k1)
|
|
51
|
+
PROVIDER_PRIVATE_KEY=${keys.privateKey}
|
|
52
|
+
# TODO: Step 1.2 Share this Public Key with t-0 team
|
|
53
|
+
# ${keys.publicKey}
|
|
54
|
+
|
|
55
|
+
# Server Configuration
|
|
56
|
+
PORT=3000
|
|
57
|
+
NODE_ENV=development
|
|
58
|
+
|
|
59
|
+
# QUOTE_PUBLISHING_INTERVAL=5000
|
|
60
|
+
|
|
61
|
+
`;
|
|
62
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(projectPath, '.env'), envContent);
|
|
63
|
+
// Update package.json with project name
|
|
64
|
+
const packageJsonPath = path_1.default.join(projectPath, 'package.json');
|
|
65
|
+
let packageJson = fs_extra_1.default.readFileSync(packageJsonPath, 'utf8');
|
|
66
|
+
packageJson = packageJson.replace('{{PROJECT_NAME}}', projectName);
|
|
67
|
+
fs_extra_1.default.writeFileSync(packageJsonPath, packageJson);
|
|
68
|
+
// Create .gitignore
|
|
69
|
+
const gitignoreContent = `node_modules/
|
|
70
|
+
dist/
|
|
71
|
+
.env
|
|
72
|
+
.env.local
|
|
73
|
+
.env.*.local
|
|
74
|
+
*.log
|
|
75
|
+
.DS_Store
|
|
76
|
+
`;
|
|
77
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(projectPath, '.gitignore'), gitignoreContent);
|
|
78
|
+
// Git init
|
|
79
|
+
console.log(chalk_1.default.cyan('📦 Initializing git repository...'));
|
|
80
|
+
(0, child_process_1.execSync)('git init', { cwd: projectPath, stdio: 'ignore' });
|
|
81
|
+
// npm install
|
|
82
|
+
console.log(chalk_1.default.cyan('📥 Installing dependencies...'));
|
|
83
|
+
(0, child_process_1.execSync)('npm install', { cwd: projectPath, stdio: 'inherit' });
|
|
84
|
+
console.log(chalk_1.default.green('\n✅ Project created successfully!\n'));
|
|
85
|
+
console.log(chalk_1.default.white(` cd ${projectName}`));
|
|
86
|
+
console.log(chalk_1.default.white(` npm run dev\n`));
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
90
|
+
console.error(chalk_1.default.red('\n❌ Error creating project:'), errorMessage);
|
|
91
|
+
// Cleanup on error
|
|
92
|
+
if (fs_extra_1.default.existsSync(projectPath)) {
|
|
93
|
+
//fs.removeSync(projectPath);
|
|
94
|
+
}
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function generateKeyPair() {
|
|
99
|
+
const tempDir = fs_extra_1.default.mkdtempSync('/tmp/keygen-');
|
|
100
|
+
const privateKeyPath = path_1.default.join(tempDir, 'private_key.pem');
|
|
101
|
+
try {
|
|
102
|
+
// Generate private key
|
|
103
|
+
(0, child_process_1.execSync)(`openssl ecparam -genkey -name secp256k1 -noout -out ${privateKeyPath}`, {
|
|
104
|
+
stdio: 'ignore'
|
|
105
|
+
});
|
|
106
|
+
// Extract private key hex
|
|
107
|
+
const privateKeyHex = (0, child_process_1.execSync)(`openssl ec -in ${privateKeyPath} -text -noout 2>/dev/null | grep -A 3 'priv:' | tail -n +2 | tr -d '\\n: ' | sed 's/[^0-9a-f]//g'`, { encoding: 'utf8' }).trim();
|
|
108
|
+
// Extract public key hex
|
|
109
|
+
const publicKeyHex = (0, child_process_1.execSync)(`openssl ec -in ${privateKeyPath} -text -noout 2>/dev/null | grep -A 5 'pub:' | tail -n +2 | tr -d '\\n: ' | sed 's/[^0-9a-f]//g'`, { encoding: 'utf8' }).trim();
|
|
110
|
+
return {
|
|
111
|
+
privateKey: privateKeyHex,
|
|
112
|
+
publicKey: publicKeyHex
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
// Cleanup temp files
|
|
117
|
+
fs_extra_1.default.removeSync(tempDir);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.default = create;
|
|
121
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,iDAAyC;AACzC,wDAAgC;AAChC,kDAA0B;AAW1B,KAAK,UAAU,MAAM;IACnB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,CAAC;IAEtD,0BAA0B;IAC1B,MAAM,OAAO,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAiB;QACpD;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,eAAe;YACxB,QAAQ,EAAE,CAAC,KAAa,EAAE,EAAE;gBAC1B,IAAI,CAAC,KAAK;oBAAE,OAAO,0BAA0B,CAAC;gBAC9C,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjC,OAAO,mFAAmF,CAAC;gBAC7F,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;SACF;KACF,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACxC,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,CAAC;IAE1D,4BAA4B;IAC5B,IAAI,kBAAE,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,kBAAkB,WAAW,mBAAmB,CAAC,CAAC,CAAC;QACzE,OAAO,C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AC;QACH,uBAAuB;QACvB,IAAA,wBAAQ,EAAC,uDAAuD,cAAc,EAAE,EAAE;YAChF,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;QAEH,0BAA0B;QAC1B,MAAM,aAAa,GAAG,IAAA,wBAAQ,EAC5B,kBAAkB,cAAc,mGAAmG,EACnI,EAAE,QAAQ,EAAE,MAAM,EAAE,CACrB,CAAC,IAAI,EAAE,CAAC;QAET,yBAAyB;QACzB,MAAM,YAAY,GAAG,IAAA,wBAAQ,EAC3B,kBAAkB,cAAc,kGAAkG,EAClI,EAAE,QAAQ,EAAE,MAAM,EAAE,CACrB,CAAC,IAAI,EAAE,CAAC;QAET,OAAO;YACL,UAAU,EAAE,aAAa;YACzB,SAAS,EAAE,YAAY;SACxB,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,qBAAqB;QACrB,kBAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;AACH,CAAC;AAED,kBAAe,MAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@t-0/provider-starter-ts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool to scaffold a Node.js t-0 Network integration service",
|
|
5
|
+
"main": "dist/create.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"provider-starter-ts": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"dist",
|
|
12
|
+
"template"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
+
"release": "npm run build && npm publish --access public"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"cli",
|
|
22
|
+
"scaffold",
|
|
23
|
+
"template",
|
|
24
|
+
"nodejs"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git@github.com:t-0-network/provider-starter-ts.git"
|
|
29
|
+
},
|
|
30
|
+
"author": "New Settlement Technologies Inc.",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"chalk": "^4.1.2",
|
|
34
|
+
"inquirer": "^8.2.5",
|
|
35
|
+
"fs-extra": "^11.1.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/fs-extra": "^11.0.4",
|
|
39
|
+
"@types/inquirer": "^8.2.10",
|
|
40
|
+
"@types/node": "^20.10.0",
|
|
41
|
+
"typescript": "^5.3.2"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
npm-debug.log*
|
|
4
|
+
yarn-debug.log*
|
|
5
|
+
yarn-error.log*
|
|
6
|
+
|
|
7
|
+
# Build output
|
|
8
|
+
dist/
|
|
9
|
+
|
|
10
|
+
# Environment files (should be provided at runtime)
|
|
11
|
+
.env
|
|
12
|
+
.env.local
|
|
13
|
+
.env.*.local
|
|
14
|
+
|
|
15
|
+
# IDE and editor files
|
|
16
|
+
.vscode/
|
|
17
|
+
.idea/
|
|
18
|
+
*.swp
|
|
19
|
+
*.swo
|
|
20
|
+
*~
|
|
21
|
+
.DS_Store
|
|
22
|
+
|
|
23
|
+
# Git
|
|
24
|
+
.git/
|
|
25
|
+
.gitignore
|
|
26
|
+
|
|
27
|
+
# Testing
|
|
28
|
+
coverage/
|
|
29
|
+
*.test.ts
|
|
30
|
+
*.spec.ts
|
|
31
|
+
|
|
32
|
+
# Documentation
|
|
33
|
+
README.md
|
|
34
|
+
*.md
|
|
35
|
+
|
|
36
|
+
# Logs
|
|
37
|
+
logs/
|
|
38
|
+
*.log
|
|
39
|
+
|
|
40
|
+
# Temporary files
|
|
41
|
+
tmp/
|
|
42
|
+
temp/
|
|
43
|
+
*.tmp
|
package/template/.env
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Private Key (secp256k1)
|
|
2
|
+
PROVIDER_PRIVATE_KEY=0x53f99e67385faa2f4bf29f8e4cb26a22741039e9f749a2e4932e63efd78176a1
|
|
3
|
+
|
|
4
|
+
# Public Key (secp256k1)
|
|
5
|
+
# your_public_key_here
|
|
6
|
+
|
|
7
|
+
# Server Configuration
|
|
8
|
+
PORT=3000
|
|
9
|
+
NODE_ENV=development
|
|
10
|
+
TZERO_ENDPOINT=https://api-sandbox.t-0.network
|
|
11
|
+
NETWORK_PUBLIC_KEY=0x0436a6bba96086e02bcc8ea3700b82b4722f84b2b7489f36e4490f9a9342b77abfb6428b4a447824e0a6f5abd89098c985f4e506c65b5e9ae64a92810e1a1c0e79
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Private Key (secp256k1)
|
|
2
|
+
PRIVATE_KEY=your_private_key_here
|
|
3
|
+
|
|
4
|
+
# Public Key (secp256k1)
|
|
5
|
+
# your_public_key_here
|
|
6
|
+
|
|
7
|
+
# Server Configuration
|
|
8
|
+
PORT=3000
|
|
9
|
+
NODE_ENV=development
|
|
10
|
+
TZERO_ENDPOINT=https://api-sandbox.t-0.network
|
|
11
|
+
|
|
12
|
+
# Quote Publishing Interval in milliseconds
|
|
13
|
+
# QUOTE_PUBLISHING_INTERVAL=5000
|
|
14
|
+
NETWORK_PUBLIC_KEY=0x0436a6bba96086e02bcc8ea3700b82b4722f84b2b7489f36e4490f9a9342b77abfb6428b4a447824e0a6f5abd89098c985f4e506c65b5e9ae64a92810e1a1c0e79
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"extends": [
|
|
4
|
+
"eslint:recommended",
|
|
5
|
+
"plugin:@typescript-eslint/recommended"
|
|
6
|
+
],
|
|
7
|
+
"parserOptions": {
|
|
8
|
+
"ecmaVersion": 2020,
|
|
9
|
+
"sourceType": "module"
|
|
10
|
+
},
|
|
11
|
+
"env": {
|
|
12
|
+
"node": true,
|
|
13
|
+
"es6": true
|
|
14
|
+
},
|
|
15
|
+
"rules": {
|
|
16
|
+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
|
|
17
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
18
|
+
"@typescript-eslint/no-explicit-any": "warn"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Multi-stage build for optimal image size
|
|
2
|
+
|
|
3
|
+
# Stage 1: Build
|
|
4
|
+
FROM node:24-alpine AS builder
|
|
5
|
+
|
|
6
|
+
# Set working directory
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
# Copy package files
|
|
10
|
+
COPY package*.json ./
|
|
11
|
+
|
|
12
|
+
# Install all dependencies (including devDependencies for build)
|
|
13
|
+
RUN npm ci
|
|
14
|
+
|
|
15
|
+
# Copy source code and config files
|
|
16
|
+
COPY tsconfig.json ./
|
|
17
|
+
COPY src ./src
|
|
18
|
+
|
|
19
|
+
# Build TypeScript to JavaScript
|
|
20
|
+
RUN npm run build
|
|
21
|
+
|
|
22
|
+
# Stage 2: Production
|
|
23
|
+
FROM node:24-alpine
|
|
24
|
+
|
|
25
|
+
# Set working directory
|
|
26
|
+
WORKDIR /app
|
|
27
|
+
|
|
28
|
+
# Copy package files
|
|
29
|
+
COPY package*.json ./
|
|
30
|
+
|
|
31
|
+
# Install only production dependencies
|
|
32
|
+
RUN npm ci --only=production && \
|
|
33
|
+
npm cache clean --force
|
|
34
|
+
|
|
35
|
+
# Copy built files from builder stage
|
|
36
|
+
COPY --from=builder /app/dist ./dist
|
|
37
|
+
|
|
38
|
+
# Create a non-root user
|
|
39
|
+
RUN addgroup -g 1001 -S nodejs && \
|
|
40
|
+
adduser -S nodejs -u 1001
|
|
41
|
+
|
|
42
|
+
# Change ownership of app directory
|
|
43
|
+
RUN chown -R nodejs:nodejs /app
|
|
44
|
+
|
|
45
|
+
# Switch to non-root user
|
|
46
|
+
USER nodejs
|
|
47
|
+
|
|
48
|
+
# Expose the port (default 3000, can be overridden)
|
|
49
|
+
EXPOSE 3000
|
|
50
|
+
|
|
51
|
+
# Health check
|
|
52
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
|
53
|
+
CMD node -e "require('http').get('http://localhost:' + (process.env.PORT || 3000) + '/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" || exit 1
|
|
54
|
+
|
|
55
|
+
# Start the application
|
|
56
|
+
CMD ["node", "dist/index.js"]
|