@steemit/steem-js 1.0.3 → 1.0.5

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 CHANGED
@@ -1,246 +1,121 @@
1
1
  # Steem.js
2
2
 
3
- Steem.js is a JavaScript/TypeScript library for interacting with the Steem blockchain.
3
+ A modern JavaScript/TypeScript library for interacting with the Steem blockchain. Complete refactoring with TypeScript, modern tooling, and improved security.
4
4
 
5
- ## Status
5
+ [![npm version](https://img.shields.io/npm/v/@steemit/steem-js.svg)](https://www.npmjs.com/package/@steemit/steem-js)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
- This is a complete refactoring of the original steem-js library, migrating from JavaScript to TypeScript with modern tooling and improved code quality. Published as `@steemit/steem-js`.
8
+ ## 📚 Documentation
8
9
 
9
- ### Refactoring Progress
10
+ **[👉 Complete API Documentation](./docs/README.md)** - Comprehensive guide with all methods, examples, and usage patterns
10
11
 
11
- - **TypeScript Migration**: Complete migration from JavaScript to TypeScript
12
- - ✅ **Build System**: Migrated from Webpack to Rollup
13
- - ✅ **Testing**: Migrated from Mocha to Vitest
14
- - ✅ **Modern Dependencies (2025)**: Replaced outdated cryptographic libraries
15
- - `bigi` → `bn.js` (modern big integer library)
16
- - `ecurve` → `elliptic` (modern elliptic curve cryptography)
17
- - Removed all shim layers for direct modern library usage
18
- - ✅ **Core Modules**: All core functionality implemented
19
- - API module with HTTP and WebSocket transports
20
- - Authentication and encryption (ECC secp256k1)
21
- - Broadcast operations
22
- - Memo encryption/decryption
23
- - Transaction serialization (95.8% test coverage)
24
- - ✅ **Security**: Fixed insecure random number generation, implemented proper cryptographic functions
25
- - ✅ **Tests**: 174 tests passing, 12 skipped (network-dependent integration tests)
12
+ **[🔧 Refactoring Details](./docs/refactoring-2025.md)** - Technical details about the 2025 modernization
26
13
 
27
- > 📖 **Detailed Refactoring Documentation**: See [docs/refactoring-2025.md](./docs/refactoring-2025.md) for complete modernization refactoring process, technical choices, and architectural improvements.
14
+ ## 🚀 Quick Start
28
15
 
29
- ## Installation
30
-
31
- ```bash
32
- pnpm install
33
- # or
34
- npm install
35
- ```
36
-
37
- ## Installation
38
-
39
- ### npm / pnpm / yarn
16
+ ### Installation
40
17
 
41
18
  ```bash
19
+ # npm
42
20
  npm install @steemit/steem-js
43
- # or
44
- pnpm install @steemit/steem-js
45
- # or
46
- yarn add @steemit/steem-js
47
- ```
48
21
 
49
- ### Browser (CDN)
50
-
51
- ```html
52
- <!-- Include @steemit/steem-js (all dependencies are bundled) -->
53
- <!-- For production: use minified version (692KB) -->
54
- <script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.min.js"></script>
22
+ # pnpm (recommended)
23
+ pnpm install @steemit/steem-js
55
24
 
56
- <!-- For development: use regular version (1.7MB) with better debugging -->
57
- <script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.js"></script>
25
+ # yarn
26
+ yarn add @steemit/steem-js
58
27
  ```
59
28
 
60
- **Note**: The UMD build includes all necessary polyfills (events, buffer, util, stream, assert, crypto-browserify). No additional dependencies are required. The minified version is recommended for production use.
61
-
62
- ## Usage
63
-
64
- ### Node.js / TypeScript / ES Modules
29
+ ### Basic Usage
65
30
 
66
31
  ```typescript
67
32
  import { steem } from '@steemit/steem-js';
68
33
 
69
- // Configure the API endpoint
34
+ // Configure API endpoint
70
35
  steem.config.set({
71
36
  node: 'https://api.steemit.com',
72
- address_prefix: 'STM',
73
- chain_id: '0000000000000000000000000000000000000000000000000000000000000000'
37
+ address_prefix: 'STM'
74
38
  });
75
39
 
76
40
  // Get account information
77
- const account = await steem.api.getAccountAsync('ned');
78
- console.log(account);
79
-
80
- // Generate keys
81
- const keys = steem.auth.generateKeys('username', 'password', ['owner', 'active', 'posting', 'memo']);
82
- console.log(keys);
83
-
84
- // Sign and verify messages
85
- import { generateKeyPair, sign, verify } from '@steemit/steem-js/crypto';
86
- const keyPair = generateKeyPair();
87
- const message = 'Hello, Steem!';
88
- const signature = sign(message, keyPair.privateKey);
89
- const isValid = verify(message, signature, keyPair.publicKey);
90
- console.log('Signature valid:', isValid);
91
- ```
92
-
93
- ### Node.js / CommonJS
94
-
95
- ```javascript
96
- const { steem } = require('@steemit/steem-js');
97
-
98
- steem.config.set({
99
- node: 'https://api.steemit.com',
100
- address_prefix: 'STM'
101
- });
41
+ const accounts = await steem.api.getAccountsAsync(['username']);
42
+ console.log(accounts[0]);
102
43
 
103
- const account = await steem.api.getAccountAsync('ned');
104
- console.log(account);
44
+ // Vote on a post
45
+ const postingWif = steem.auth.toWif('username', 'password', 'posting');
46
+ await steem.broadcast.voteAsync(postingWif, 'voter', 'author', 'permlink', 10000);
105
47
  ```
106
48
 
107
- ### Browser (Script Tag)
108
-
109
- The UMD build includes all necessary dependencies and polyfills, so you can use it directly without any additional setup.
49
+ ### Browser Usage
110
50
 
111
51
  ```html
112
- <!DOCTYPE html>
113
- <html>
114
- <head>
115
- <title>Steem.js Example</title>
116
- <!-- Include @steemit/steem-js (minified for production) -->
117
- <script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.min.js"></script>
118
- </head>
119
- <body>
120
- <script>
121
- // Use the global 'steem' object
122
- steem.config.set({
123
- node: 'https://api.steemit.com',
124
- address_prefix: 'STM'
125
- });
126
-
127
- // Get account information
128
- steem.api.getAccountAsync('ned')
129
- .then(account => {
130
- console.log('Account:', account);
131
- })
132
- .catch(error => {
133
- console.error('Error:', error);
134
- });
135
- </script>
136
- </body>
137
- </html>
52
+ <script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.min.js"></script>
53
+ <script>
54
+ steem.config.set({ node: 'https://api.steemit.com' });
55
+ steem.api.getAccountsAsync(['username']).then(console.log);
56
+ </script>
138
57
  ```
139
58
 
140
- **Note**: The UMD build comes in two versions:
141
- - **Minified** (`index.umd.min.js` - 692KB): Recommended for production
142
- - **Regular** (`index.umd.js` - 1.7MB): Better for development and debugging
143
-
144
- Both include all polyfills, making them ready to use in browsers without additional dependencies. For production use with bundlers (Webpack, Vite, Rollup), use the ES Module or CommonJS builds instead.
145
-
146
- ### Broadcast Operations
147
-
148
- ```typescript
149
- import { steem } from '@steemit/steem-js';
150
-
151
- // Vote on a post
152
- const postingWif = steem.auth.toWif('username', 'password', 'posting');
153
- await steem.broadcast.voteAsync(
154
- postingWif,
155
- 'voter',
156
- 'author',
157
- 'permlink',
158
- 10000 // weight
159
- );
160
-
161
- // Transfer STEEM
162
- await steem.broadcast.transferAsync(
163
- activeWif,
164
- 'from',
165
- 'to',
166
- '1.000 STEEM',
167
- 'memo'
168
- );
169
- ```
59
+ ## Key Features
170
60
 
171
- ## Development
61
+ - **🔒 Type Safety** - Full TypeScript support with complete type definitions
62
+ - **⚡ Modern** - ES modules, async/await, modern cryptography libraries
63
+ - **🌐 Universal** - Works in Node.js, browsers, and bundlers
64
+ - **🔐 Secure** - Proper cryptographic implementations, no key exposure
65
+ - **📖 Well Documented** - Comprehensive API documentation with examples
172
66
 
173
- ### Build
67
+ ## 🏗️ Development
174
68
 
175
69
  ```bash
176
- pnpm build
177
- ```
70
+ # Install dependencies
71
+ pnpm install
178
72
 
179
- ### Test
73
+ # Build the library
74
+ pnpm build
180
75
 
181
- ```bash
182
- # Run all tests
76
+ # Run tests
183
77
  pnpm test
184
78
 
185
- # Run tests in watch mode
186
- pnpm test:watch
187
-
188
- # Run tests with coverage
189
- pnpm test:coverage
190
- ```
191
-
192
- ### Type Check
193
-
194
- ```bash
79
+ # Type checking
195
80
  pnpm typecheck
196
81
  ```
197
82
 
198
- ### Lint
83
+ ## 📦 What's New in 2025
199
84
 
200
- ```bash
201
- pnpm lint
202
- ```
85
+ This is a complete modernization of the original steem-js library:
86
+
87
+ - ✅ **TypeScript Migration** - Full type safety and better developer experience
88
+ - ✅ **Modern Dependencies** - Replaced outdated crypto libraries (`bigi` → `bn.js`, `ecurve` → `elliptic`)
89
+ - ✅ **Build System** - Migrated from Webpack to Rollup for better output
90
+ - ✅ **Testing** - Migrated from Mocha to Vitest with 95.8% test coverage
91
+ - ✅ **Security** - Fixed insecure random number generation and crypto implementations
203
92
 
204
- ## Project Structure
93
+ ## 📋 Project Structure
205
94
 
206
95
  ```
207
96
  src/
208
- api/ # API client with HTTP and WebSocket transports
209
- auth/ # Authentication and key management
210
- broadcast/ # Transaction broadcasting
211
- crypto/ # Cryptographic utilities
212
- formatter/ # Data formatting
213
- memo/ # Encrypted memo handling
214
- operations/ # Operation type definitions
215
- serializer/ # Transaction serialization
216
- utils/ # Utility functions
97
+ ├── api/ # Blockchain API client (HTTP/WebSocket)
98
+ ├── auth/ # Authentication and key management
99
+ ├── broadcast/ # Transaction broadcasting
100
+ ├── crypto/ # Cryptographic utilities
101
+ ├── formatter/ # Data formatting helpers
102
+ ├── memo/ # Encrypted memo handling
103
+ ├── operations/ # Operation type definitions
104
+ ├── serializer/ # Transaction serialization
105
+ └── utils/ # Utility functions
217
106
  ```
218
107
 
219
- ## Key Features
220
-
221
- - **Type Safety**: Full TypeScript support with type definitions
222
- - **Modern ES Modules**: Uses ES modules with CommonJS fallback
223
- - **Secure Cryptography**: Proper implementation using Node.js crypto module
224
- - **Multiple Transports**: Supports both HTTP and WebSocket connections
225
- - **Promise and Callback Support**: Compatible with both async/await and callback patterns
226
-
227
- ## Breaking Changes from Original
228
-
229
- This is a complete refactor with the following changes:
230
-
231
- 1. **TypeScript**: All code is now TypeScript
232
- 2. **ES Modules**: Uses ES modules by default (CommonJS available)
233
- 3. **Build System**: Uses Rollup instead of Webpack
234
- 4. **Testing**: Uses Vitest instead of Mocha
235
- 5. **API**: Some method signatures may have changed for better type safety
108
+ ## 🔗 Links
236
109
 
237
- ## Security Notes
110
+ - **[📖 API Documentation](./docs/README.md)** - Complete method reference
111
+ - **[🔧 Refactoring History](./docs/refactoring-2025.md)** - Technical modernization details
112
+ - **[📦 NPM Package](https://www.npmjs.com/package/@steemit/steem-js)** - Published package
113
+ - **[🐛 Issues](https://github.com/steemit/steem-js/issues)** - Bug reports and feature requests
238
114
 
239
- - Private keys are never logged or exposed
240
- - Uses cryptographically secure random number generation
241
- - All cryptographic operations use proper implementations
115
+ ## 📄 License
242
116
 
243
- ## License
117
+ MIT - see [LICENSE](LICENSE) file for details.
244
118
 
245
- MIT
119
+ ---
246
120
 
121
+ > 💡 **Need help?** Check the [complete documentation](./docs/README.md) for detailed examples and API reference.
@@ -31,6 +31,12 @@ export declare class Api extends EventEmitter {
31
31
  send(api: string, data: any, callback: any): any;
32
32
  call(method: string, params: any[], callback: any): void;
33
33
  signedCall(method: string, params: any[], account: string, key: string, callback: any): void;
34
+ /**
35
+ * Verify a signed RPC request
36
+ * @param signedRequest The signed request to verify
37
+ * @param callback Callback function
38
+ */
39
+ verifySignedRequest(signedRequest: any, callback: any): void;
34
40
  setOptions(options: ApiOptions): void;
35
41
  /**
36
42
  * Set WebSocket URL
@@ -126,3 +132,5 @@ export declare const streamBlockNumber: (...args: any[]) => any;
126
132
  export declare const streamBlock: (...args: any[]) => any;
127
133
  export declare const streamTransactions: (...args: any[]) => any;
128
134
  export declare const streamOperations: (...args: any[]) => any;
135
+ export { sign as signRequest, validate as validateRequest } from './rpc-auth';
136
+ export * as signatureVerification from './signature-verification';
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Signature Verification Utilities for Steem.js
3
+ *
4
+ * This module provides comprehensive signature verification functionality
5
+ * for signed RPC requests and general message signatures.
6
+ */
7
+ export interface SignedRequest {
8
+ jsonrpc: string;
9
+ method: string;
10
+ id: number;
11
+ params: {
12
+ __signed: {
13
+ account: string;
14
+ nonce: string;
15
+ params: string;
16
+ signatures: string[];
17
+ timestamp: string;
18
+ };
19
+ };
20
+ }
21
+ export interface VerificationResult {
22
+ valid: boolean;
23
+ account?: string;
24
+ params?: any;
25
+ error?: string;
26
+ timestamp?: string;
27
+ signatures?: string[];
28
+ }
29
+ export interface AccountKeys {
30
+ owner: string[];
31
+ active: string[];
32
+ posting: string[];
33
+ memo: string;
34
+ }
35
+ /**
36
+ * Verify a signed RPC request against account's public keys
37
+ */
38
+ export declare function verifySignedRequest(signedRequest: SignedRequest, getAccountKeys: (account: string) => Promise<AccountKeys>): Promise<VerificationResult>;
39
+ /**
40
+ * Verify a simple message signature
41
+ */
42
+ export declare function verifyMessageSignature(message: string | Buffer, signature: string, publicKey: string): boolean;
43
+ /**
44
+ * Verify multiple signatures against multiple public keys
45
+ */
46
+ export declare function verifyMultipleSignatures(message: string | Buffer, signatures: string[], publicKeys: string[]): {
47
+ verified: boolean;
48
+ validSignatures: number;
49
+ details: Array<{
50
+ signature: string;
51
+ publicKey: string;
52
+ valid: boolean;
53
+ }>;
54
+ };
55
+ /**
56
+ * Extract account keys from Steem account data
57
+ */
58
+ export declare function extractAccountKeys(accountData: any): AccountKeys;
59
+ /**
60
+ * Create a verification function for use with API calls
61
+ */
62
+ export declare function createApiVerificationFunction(api: any): (account: string) => Promise<AccountKeys>;
63
+ /**
64
+ * Batch verify multiple signed requests
65
+ */
66
+ export declare function batchVerifySignedRequests(signedRequests: SignedRequest[], getAccountKeys: (account: string) => Promise<AccountKeys>): Promise<VerificationResult[]>;
67
+ /**
68
+ * Check if a signature is expired
69
+ */
70
+ export declare function isSignatureExpired(timestamp: string, maxAgeMs?: number): boolean;
71
+ /**
72
+ * Validate signature format
73
+ */
74
+ export declare function isValidSignatureFormat(signature: string): boolean;
75
+ /**
76
+ * Validate public key format
77
+ */
78
+ export declare function isValidPublicKeyFormat(publicKey: string): boolean;
79
+ declare const _default: {
80
+ verifySignedRequest: typeof verifySignedRequest;
81
+ verifyMessageSignature: typeof verifyMessageSignature;
82
+ verifyMultipleSignatures: typeof verifyMultipleSignatures;
83
+ extractAccountKeys: typeof extractAccountKeys;
84
+ createApiVerificationFunction: typeof createApiVerificationFunction;
85
+ batchVerifySignedRequests: typeof batchVerifySignedRequests;
86
+ isSignatureExpired: typeof isSignatureExpired;
87
+ isValidSignatureFormat: typeof isValidSignatureFormat;
88
+ isValidPublicKeyFormat: typeof isValidPublicKeyFormat;
89
+ };
90
+ export default _default;