@steemit/steem-js 0.7.11 → 1.0.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 +203 -87
- package/dist/api/index.d.ts +128 -0
- package/dist/api/methods.d.ts +9 -0
- package/dist/api/rpc-auth.d.ts +43 -0
- package/dist/api/transports/base.d.ts +13 -0
- package/dist/api/transports/http.d.ts +9 -0
- package/dist/api/transports/index.d.ts +9 -0
- package/dist/api/transports/types.d.ts +35 -0
- package/dist/api/transports/ws.d.ts +18 -0
- package/dist/auth/ecc/index.d.ts +9 -0
- package/dist/auth/ecc/src/address.d.ts +13 -0
- package/dist/auth/ecc/src/aes.d.ts +16 -0
- package/dist/auth/ecc/src/brain_key.d.ts +1 -0
- package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
- package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
- package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
- package/dist/auth/ecc/src/hash.d.ts +25 -0
- package/dist/auth/ecc/src/index.d.ts +9 -0
- package/dist/auth/ecc/src/key_private.d.ts +38 -0
- package/dist/auth/ecc/src/key_public.d.ts +41 -0
- package/dist/auth/ecc/src/key_utils.d.ts +9 -0
- package/dist/auth/ecc/src/signature.d.ts +18 -0
- package/dist/auth/ecc.d.ts +3 -0
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/key_classes.d.ts +3 -0
- package/dist/auth/serializer.d.ts +19 -0
- package/dist/broadcast/helpers.d.ts +11 -0
- package/dist/broadcast/index.d.ts +43 -0
- package/dist/broadcast/operations.d.ts +6 -0
- package/dist/config.d.ts +25 -0
- package/dist/crypto/index.d.ts +25 -0
- package/dist/formatter/index.d.ts +92 -0
- package/dist/index.cjs +25848 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +25812 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +57513 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/memo/index.d.ts +11 -0
- package/dist/operations/index.d.ts +44 -0
- package/dist/serializer/convert.d.ts +12 -0
- package/dist/serializer/index.d.ts +11 -0
- package/dist/serializer/number_utils.d.ts +8 -0
- package/dist/serializer/precision.d.ts +5 -0
- package/dist/serializer/types.d.ts +36 -0
- package/dist/types/index.d.ts +131 -0
- package/dist/types.d.ts +34 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +72 -67
- package/.circleci/config.yml +0 -23
- package/.dockerignore +0 -12
- package/.editorconfig +0 -20
- package/.eslintrc +0 -27
- package/LICENSE +0 -21
- package/circle.yml +0 -3
- package/config.json +0 -10
- package/dist/statistics.html +0 -208
- package/dist/steem-tests.min.js +0 -23
- package/dist/steem-tests.min.js.gz +0 -0
- package/dist/steem-tests.min.js.map +0 -1
- package/dist/steem.min.js +0 -18
- package/dist/steem.min.js.gz +0 -0
- package/dist/steem.min.js.map +0 -1
- package/lib/api/index.js +0 -422
- package/lib/api/methods.js +0 -413
- package/lib/api/transports/base.js +0 -72
- package/lib/api/transports/http.js +0 -172
- package/lib/api/transports/index.js +0 -20
- package/lib/api/transports/ws.js +0 -228
- package/lib/auth/ecc/README.md +0 -20
- package/lib/auth/ecc/index.js +0 -13
- package/lib/auth/ecc/package.json +0 -36
- package/lib/auth/ecc/src/address.js +0 -84
- package/lib/auth/ecc/src/aes.js +0 -184
- package/lib/auth/ecc/src/brain_key.js +0 -13
- package/lib/auth/ecc/src/ecdsa.js +0 -219
- package/lib/auth/ecc/src/ecsignature.js +0 -128
- package/lib/auth/ecc/src/enforce_types.js +0 -49
- package/lib/auth/ecc/src/hash.js +0 -67
- package/lib/auth/ecc/src/key_private.js +0 -212
- package/lib/auth/ecc/src/key_public.js +0 -215
- package/lib/auth/ecc/src/key_utils.js +0 -112
- package/lib/auth/ecc/src/signature.js +0 -187
- package/lib/auth/index.js +0 -126
- package/lib/auth/memo.js +0 -147
- package/lib/auth/serializer/README.md +0 -13
- package/lib/auth/serializer/index.js +0 -21
- package/lib/auth/serializer/package.json +0 -32
- package/lib/auth/serializer/src/ChainTypes.js +0 -90
- package/lib/auth/serializer/src/convert.js +0 -37
- package/lib/auth/serializer/src/error_with_cause.js +0 -42
- package/lib/auth/serializer/src/fast_parser.js +0 -77
- package/lib/auth/serializer/src/number_utils.js +0 -67
- package/lib/auth/serializer/src/object_id.js +0 -68
- package/lib/auth/serializer/src/operations.js +0 -787
- package/lib/auth/serializer/src/precision.js +0 -95
- package/lib/auth/serializer/src/serializer.js +0 -211
- package/lib/auth/serializer/src/template.js +0 -17
- package/lib/auth/serializer/src/types.js +0 -1238
- package/lib/auth/serializer/src/validation.js +0 -360
- package/lib/broadcast/helpers.js +0 -177
- package/lib/broadcast/index.js +0 -127
- package/lib/broadcast/operations.js +0 -255
- package/lib/browser.js +0 -29
- package/lib/config.js +0 -45
- package/lib/formatter.js +0 -189
- package/lib/index.js +0 -19
- package/lib/utils.js +0 -55
- package/node-4.dockerfile +0 -6
- package/node-6.dockerfile +0 -6
- package/test/Crypto.js +0 -100
- package/test/KeyFormats.js +0 -105
- package/test/all_types.js +0 -115
- package/test/api.test.js +0 -326
- package/test/broadcast.test.js +0 -225
- package/test/browser/BrowserTests.js +0 -55
- package/test/comment.test.js +0 -69
- package/test/hf20-accounts.test.js +0 -76
- package/test/hf21-sps.test.js +0 -78
- package/test/memo.test.js +0 -37
- package/test/number_utils.js +0 -28
- package/test/operations_test.js +0 -39
- package/test/smt.test.js +0 -347
- package/test/test-post.json +0 -13
- package/test/test.html +0 -13
- package/test/test_helper.js +0 -19
- package/test/types_test.js +0 -139
- package/webpack/makeConfig.js +0 -105
- package/webpack.config.js +0 -2
- package/yarn.lock +0 -3336
package/README.md
CHANGED
|
@@ -1,116 +1,232 @@
|
|
|
1
|
-
[](https://github.com/steemit/steem-js/blob/master/LICENSE)
|
|
2
|
-
[](https://steemit.chat/channel/steemjs)
|
|
3
|
-
|
|
4
1
|
# Steem.js
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
##
|
|
2
|
+
|
|
3
|
+
Steem.js is a JavaScript/TypeScript library for interacting with the Steem blockchain.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
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
|
+
|
|
9
|
+
### Refactoring Progress
|
|
10
|
+
|
|
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
|
+
- ✅ **Core Modules**: All core functionality implemented
|
|
15
|
+
- API module with HTTP and WebSocket transports
|
|
16
|
+
- Authentication and encryption (ECC secp256k1)
|
|
17
|
+
- Broadcast operations
|
|
18
|
+
- Memo encryption/decryption
|
|
19
|
+
- Transaction serialization
|
|
20
|
+
- ✅ **Security**: Fixed insecure random number generation, implemented proper cryptographic functions
|
|
21
|
+
- ✅ **Tests**: 174 tests passing, 12 skipped (network-dependent integration tests)
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pnpm install
|
|
27
|
+
# or
|
|
28
|
+
npm install
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
### npm / pnpm / yarn
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @steemit/steem-js
|
|
37
|
+
# or
|
|
38
|
+
pnpm install @steemit/steem-js
|
|
39
|
+
# or
|
|
40
|
+
yarn add @steemit/steem-js
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Browser (CDN)
|
|
44
|
+
|
|
35
45
|
```html
|
|
36
|
-
|
|
37
|
-
<script>
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
<!-- Include @steemit/steem-js (all dependencies are bundled) -->
|
|
47
|
+
<script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.js"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Note**: The UMD build includes all necessary polyfills (axios, events, buffer, util, stream, assert, crypto). No additional dependencies are required.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Node.js / TypeScript / ES Modules
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { steem } from '@steemit/steem-js';
|
|
58
|
+
|
|
59
|
+
// Configure the API endpoint
|
|
60
|
+
steem.config.set({
|
|
61
|
+
node: 'https://api.steemit.com',
|
|
62
|
+
address_prefix: 'STM',
|
|
63
|
+
chain_id: '0000000000000000000000000000000000000000000000000000000000000000'
|
|
40
64
|
});
|
|
41
|
-
|
|
65
|
+
|
|
66
|
+
// Get account information
|
|
67
|
+
const account = await steem.api.getAccountAsync('ned');
|
|
68
|
+
console.log(account);
|
|
69
|
+
|
|
70
|
+
// Generate keys
|
|
71
|
+
const keys = steem.auth.generateKeys('username', 'password', ['owner', 'active', 'posting', 'memo']);
|
|
72
|
+
console.log(keys);
|
|
73
|
+
|
|
74
|
+
// Sign and verify messages
|
|
75
|
+
import { generateKeyPair, sign, verify } from '@steemit/steem-js/crypto';
|
|
76
|
+
const keyPair = generateKeyPair();
|
|
77
|
+
const message = 'Hello, Steem!';
|
|
78
|
+
const signature = sign(message, keyPair.privateKey);
|
|
79
|
+
const isValid = verify(message, signature, keyPair.publicKey);
|
|
80
|
+
console.log('Signature valid:', isValid);
|
|
42
81
|
```
|
|
43
82
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
83
|
+
### Node.js / CommonJS
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
const { steem } = require('@steemit/steem-js');
|
|
87
|
+
|
|
88
|
+
steem.config.set({
|
|
89
|
+
node: 'https://api.steemit.com',
|
|
90
|
+
address_prefix: 'STM'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const account = await steem.api.getAccountAsync('ned');
|
|
94
|
+
console.log(account);
|
|
48
95
|
```
|
|
49
96
|
|
|
50
|
-
|
|
51
|
-
|
|
97
|
+
### Browser (Script Tag)
|
|
98
|
+
|
|
99
|
+
The UMD build includes all necessary dependencies and polyfills, so you can use it directly without any additional setup.
|
|
52
100
|
|
|
53
|
-
|
|
54
|
-
|
|
101
|
+
```html
|
|
102
|
+
<!DOCTYPE html>
|
|
103
|
+
<html>
|
|
104
|
+
<head>
|
|
105
|
+
<title>Steem.js Example</title>
|
|
106
|
+
<!-- Include @steemit/steem-js (all dependencies bundled) -->
|
|
107
|
+
<script src="https://cdn.jsdelivr.net/npm/@steemit/steem-js/dist/index.umd.js"></script>
|
|
108
|
+
</head>
|
|
109
|
+
<body>
|
|
110
|
+
<script>
|
|
111
|
+
// Use the global 'steem' object
|
|
112
|
+
steem.config.set({
|
|
113
|
+
node: 'https://api.steemit.com',
|
|
114
|
+
address_prefix: 'STM'
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Get account information
|
|
118
|
+
steem.api.getAccountAsync('ned')
|
|
119
|
+
.then(account => {
|
|
120
|
+
console.log('Account:', account);
|
|
121
|
+
})
|
|
122
|
+
.catch(error => {
|
|
123
|
+
console.error('Error:', error);
|
|
124
|
+
});
|
|
125
|
+
</script>
|
|
126
|
+
</body>
|
|
127
|
+
</html>
|
|
55
128
|
```
|
|
56
|
-
|
|
129
|
+
|
|
130
|
+
**Note**: The UMD build (1.7MB) includes all polyfills, making it ready to use in browsers without additional dependencies. For production use with bundlers (Webpack, Vite, Rollup), use the ES Module or CommonJS builds instead.
|
|
131
|
+
|
|
132
|
+
### Broadcast Operations
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { steem } from '@steemit/steem-js';
|
|
136
|
+
|
|
137
|
+
// Vote on a post
|
|
138
|
+
const postingWif = steem.auth.toWif('username', 'password', 'posting');
|
|
139
|
+
await steem.broadcast.voteAsync(
|
|
140
|
+
postingWif,
|
|
141
|
+
'voter',
|
|
142
|
+
'author',
|
|
143
|
+
'permlink',
|
|
144
|
+
10000 // weight
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// Transfer STEEM
|
|
148
|
+
await steem.broadcast.transferAsync(
|
|
149
|
+
activeWif,
|
|
150
|
+
'from',
|
|
151
|
+
'to',
|
|
152
|
+
'1.000 STEEM',
|
|
153
|
+
'memo'
|
|
154
|
+
);
|
|
57
155
|
```
|
|
58
156
|
|
|
59
|
-
##
|
|
60
|
-
https://api.steemit.com By Default<br/>
|
|
61
|
-
https://node.steem.ws<br/>
|
|
62
|
-
https://this.piston.rocks<br/>
|
|
157
|
+
## Development
|
|
63
158
|
|
|
64
|
-
|
|
65
|
-
### Broadcast Vote
|
|
66
|
-
```js
|
|
67
|
-
var steem = require('steem');
|
|
159
|
+
### Build
|
|
68
160
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
console.log(err, result);
|
|
72
|
-
});
|
|
161
|
+
```bash
|
|
162
|
+
pnpm build
|
|
73
163
|
```
|
|
74
164
|
|
|
75
|
-
###
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
165
|
+
### Test
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Run all tests
|
|
169
|
+
pnpm test
|
|
170
|
+
|
|
171
|
+
# Run tests in watch mode
|
|
172
|
+
pnpm test:watch
|
|
173
|
+
|
|
174
|
+
# Run tests with coverage
|
|
175
|
+
pnpm test:coverage
|
|
80
176
|
```
|
|
81
177
|
|
|
82
|
-
###
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
178
|
+
### Type Check
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
pnpm typecheck
|
|
87
182
|
```
|
|
88
183
|
|
|
89
|
-
###
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
184
|
+
### Lint
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pnpm lint
|
|
93
188
|
```
|
|
94
189
|
|
|
95
|
-
|
|
96
|
-
Steem-js requires some configuration to work on the public Steem testnet.
|
|
190
|
+
## Project Structure
|
|
97
191
|
|
|
98
|
-
You need to set two Steem API options, `address_prefix` and `chain_id`.
|
|
99
|
-
```js
|
|
100
|
-
steem.api.setOptions({
|
|
101
|
-
address_prefix: 'TST',
|
|
102
|
-
chain_id: '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32',
|
|
103
|
-
useTestNet: true,
|
|
104
|
-
});
|
|
105
192
|
```
|
|
193
|
+
src/
|
|
194
|
+
api/ # API client with HTTP and WebSocket transports
|
|
195
|
+
auth/ # Authentication and key management
|
|
196
|
+
broadcast/ # Transaction broadcasting
|
|
197
|
+
crypto/ # Cryptographic utilities
|
|
198
|
+
formatter/ # Data formatting
|
|
199
|
+
memo/ # Encrypted memo handling
|
|
200
|
+
operations/ # Operation type definitions
|
|
201
|
+
serializer/ # Transaction serialization
|
|
202
|
+
utils/ # Utility functions
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Key Features
|
|
106
206
|
|
|
107
|
-
|
|
207
|
+
- **Type Safety**: Full TypeScript support with type definitions
|
|
208
|
+
- **Modern ES Modules**: Uses ES modules with CommonJS fallback
|
|
209
|
+
- **Secure Cryptography**: Proper implementation using Node.js crypto module
|
|
210
|
+
- **Multiple Transports**: Supports both HTTP and WebSocket connections
|
|
211
|
+
- **Promise and Callback Support**: Compatible with both async/await and callback patterns
|
|
108
212
|
|
|
109
|
-
##
|
|
110
|
-
Patches are welcome! Contributors are listed in the package.json file. Please run the tests before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list or on Steemit Chat channel #steemjs https://steemit.chat/channel/steemjs.
|
|
213
|
+
## Breaking Changes from Original
|
|
111
214
|
|
|
112
|
-
|
|
113
|
-
|
|
215
|
+
This is a complete refactor with the following changes:
|
|
216
|
+
|
|
217
|
+
1. **TypeScript**: All code is now TypeScript
|
|
218
|
+
2. **ES Modules**: Uses ES modules by default (CommonJS available)
|
|
219
|
+
3. **Build System**: Uses Rollup instead of Webpack
|
|
220
|
+
4. **Testing**: Uses Vitest instead of Mocha
|
|
221
|
+
5. **API**: Some method signatures may have changed for better type safety
|
|
222
|
+
|
|
223
|
+
## Security Notes
|
|
224
|
+
|
|
225
|
+
- Private keys are never logged or exposed
|
|
226
|
+
- Uses cryptographically secure random number generation
|
|
227
|
+
- All cryptographic operations use proper implementations
|
|
114
228
|
|
|
115
229
|
## License
|
|
230
|
+
|
|
116
231
|
MIT
|
|
232
|
+
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import Bluebird from 'bluebird';
|
|
3
|
+
interface ApiOptions {
|
|
4
|
+
url?: string;
|
|
5
|
+
uri?: string;
|
|
6
|
+
/**
|
|
7
|
+
* WebSocket URL
|
|
8
|
+
* NOTE: WebSocket functionality is currently not supported.
|
|
9
|
+
* This field is kept for backward compatibility only.
|
|
10
|
+
* Please use HTTP transport (via url or uri field) for API calls.
|
|
11
|
+
*/
|
|
12
|
+
websocket?: string;
|
|
13
|
+
transport?: string | any;
|
|
14
|
+
logger?: any;
|
|
15
|
+
useTestNet?: boolean;
|
|
16
|
+
useAppbaseApi?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class Api extends EventEmitter {
|
|
19
|
+
private seqNo;
|
|
20
|
+
private _transportType;
|
|
21
|
+
private transport;
|
|
22
|
+
private options;
|
|
23
|
+
private __logger;
|
|
24
|
+
private static _wrapWithPromise;
|
|
25
|
+
constructor(options?: ApiOptions);
|
|
26
|
+
private _setTransport;
|
|
27
|
+
private _setLogger;
|
|
28
|
+
log(logLevel: string, ...args: any[]): void;
|
|
29
|
+
start(): any;
|
|
30
|
+
stop(): any;
|
|
31
|
+
send(api: string, data: any, callback: any): any;
|
|
32
|
+
call(method: string, params: any[], callback: any): void;
|
|
33
|
+
signedCall(method: string, params: any[], account: string, key: string, callback: any): void;
|
|
34
|
+
setOptions(options: ApiOptions): void;
|
|
35
|
+
/**
|
|
36
|
+
* Set WebSocket URL
|
|
37
|
+
*
|
|
38
|
+
* NOTE: WebSocket functionality is currently not supported.
|
|
39
|
+
* This method is kept for backward compatibility only.
|
|
40
|
+
* Please use HTTP transport (via setOptions({ url: 'https://api.steemit.com' })) for API calls.
|
|
41
|
+
*/
|
|
42
|
+
setWebSocket(url: string): void;
|
|
43
|
+
setUri(url: string): void;
|
|
44
|
+
streamBlockNumber(mode: string | undefined, callback: any, ts?: number): () => void;
|
|
45
|
+
streamBlock(mode: string | undefined, callback: any): () => void;
|
|
46
|
+
streamTransactions(mode: string | undefined, callback: any): () => void;
|
|
47
|
+
streamOperations(mode: string | undefined, callback: any): () => void;
|
|
48
|
+
broadcastTransactionSynchronousWith(options: any, callback: any): void;
|
|
49
|
+
/**
|
|
50
|
+
* Broadcast a transaction to the blockchain.
|
|
51
|
+
* @param trx The transaction object
|
|
52
|
+
* @param callback Callback function
|
|
53
|
+
*/
|
|
54
|
+
broadcastTransaction(trx: any, callback: any): void;
|
|
55
|
+
/**
|
|
56
|
+
* Sign a transaction with the provided private key(s).
|
|
57
|
+
* @param trx The transaction object
|
|
58
|
+
* @param keys Array of WIF private keys
|
|
59
|
+
* @returns Signed transaction object
|
|
60
|
+
*/
|
|
61
|
+
signTransaction(trx: any, keys: string[]): any;
|
|
62
|
+
/**
|
|
63
|
+
* Get a single account by name (backward compatibility).
|
|
64
|
+
* @param name The account name
|
|
65
|
+
* @param callback Optional callback
|
|
66
|
+
* @returns Account object or Promise
|
|
67
|
+
*/
|
|
68
|
+
getAccount(name: string, callback?: (err: any, result?: any) => void): Bluebird<any> | void;
|
|
69
|
+
/**
|
|
70
|
+
* Get followers for an account (backward compatibility).
|
|
71
|
+
* @param account The account name
|
|
72
|
+
* @param startFollower The follower to start from
|
|
73
|
+
* @param type The type of follow
|
|
74
|
+
* @param limit The number of followers to return
|
|
75
|
+
* @param callback Optional callback
|
|
76
|
+
* @returns Array of followers or Promise
|
|
77
|
+
*/
|
|
78
|
+
getFollowers(account: string, startFollower: string, type: string, limit: number, callback?: (err: any, result?: any) => void): Bluebird<any[]> | void;
|
|
79
|
+
/**
|
|
80
|
+
* Broadcast a transaction with a confirmation callback.
|
|
81
|
+
* @param confirmationCallback Callback function for transaction confirmation
|
|
82
|
+
* @param trx Transaction object to broadcast
|
|
83
|
+
* @param callback Callback function
|
|
84
|
+
*/
|
|
85
|
+
broadcastTransactionWithCallback(confirmationCallback: any, trx: any, callback: any): void;
|
|
86
|
+
/**
|
|
87
|
+
* Broadcast a block to the network.
|
|
88
|
+
* @param block Block object to broadcast
|
|
89
|
+
* @param callback Callback function
|
|
90
|
+
*/
|
|
91
|
+
broadcastBlock(block: any, callback: any): void;
|
|
92
|
+
/**
|
|
93
|
+
* Set the maximum block age for transaction acceptance.
|
|
94
|
+
* @param maxBlockAge Maximum block age in seconds
|
|
95
|
+
* @param callback Callback function
|
|
96
|
+
*/
|
|
97
|
+
setMaxBlockAge(maxBlockAge: number, callback: any): void;
|
|
98
|
+
/**
|
|
99
|
+
* Verify transaction authority.
|
|
100
|
+
* @param trx Transaction object to verify
|
|
101
|
+
* @param callback Optional callback function
|
|
102
|
+
* @returns Promise with verification result if no callback provided
|
|
103
|
+
*/
|
|
104
|
+
verifyAuthority(trx: any, callback?: (err: any, result?: boolean) => void): Bluebird<boolean> | void;
|
|
105
|
+
/**
|
|
106
|
+
* Verify account authority.
|
|
107
|
+
* @param nameOrId Account name or ID
|
|
108
|
+
* @param signers Array of signer public keys
|
|
109
|
+
* @param callback Optional callback function
|
|
110
|
+
* @returns Promise with verification result if no callback provided
|
|
111
|
+
*/
|
|
112
|
+
verifyAccountAuthority(nameOrId: string, signers: string[], callback?: (err: any, result?: boolean) => void): Bluebird<boolean> | void;
|
|
113
|
+
}
|
|
114
|
+
declare const api: Api;
|
|
115
|
+
export declare function setOptions(options: ApiOptions): void;
|
|
116
|
+
export declare function call(method: string, params: any[], callback: any): void;
|
|
117
|
+
export declare function signTransaction(trx: any, keys: string[]): any;
|
|
118
|
+
export declare function verifyAuthority(..._args: any[]): boolean;
|
|
119
|
+
export default api;
|
|
120
|
+
export declare const getDynamicGlobalPropertiesAsync: any;
|
|
121
|
+
export declare const getBlockAsync: any;
|
|
122
|
+
export declare const getFollowersAsync: any;
|
|
123
|
+
export declare const getContentAsync: any;
|
|
124
|
+
export declare const listeners: (...args: any[]) => any;
|
|
125
|
+
export declare const streamBlockNumber: (...args: any[]) => any;
|
|
126
|
+
export declare const streamBlock: (...args: any[]) => any;
|
|
127
|
+
export declare const streamTransactions: (...args: any[]) => any;
|
|
128
|
+
export declare const streamOperations: (...args: any[]) => any;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface RpcRequest {
|
|
2
|
+
method: string;
|
|
3
|
+
params: any[];
|
|
4
|
+
id: number;
|
|
5
|
+
}
|
|
6
|
+
interface SignedRequest {
|
|
7
|
+
jsonrpc: string;
|
|
8
|
+
method: string;
|
|
9
|
+
id: number;
|
|
10
|
+
params: {
|
|
11
|
+
__signed: {
|
|
12
|
+
account: string;
|
|
13
|
+
nonce: string;
|
|
14
|
+
params: string;
|
|
15
|
+
signatures: string[];
|
|
16
|
+
timestamp: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Signing constant used to reserve opcode space and prevent cross-protocol attacks.
|
|
22
|
+
* Output of `sha256('steem_jsonrpc_auth')`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const K: Buffer<ArrayBuffer>;
|
|
25
|
+
/**
|
|
26
|
+
* Sign a JSON RPC Request.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sign(request: RpcRequest, account: string, keys: string[]): SignedRequest;
|
|
29
|
+
/**
|
|
30
|
+
* Validate a signed JSON RPC request.
|
|
31
|
+
* Throws a ValidationError if the request fails validation.
|
|
32
|
+
*
|
|
33
|
+
* @param request The signed JSON RPC request to validate
|
|
34
|
+
* @param verify Function to verify signatures against public keys
|
|
35
|
+
* @returns Resolved request params
|
|
36
|
+
*/
|
|
37
|
+
export declare function validate(request: SignedRequest, verify: (message: Buffer, signatures: string[], account: string) => Promise<void>): Promise<any>;
|
|
38
|
+
declare const _default: {
|
|
39
|
+
sign: typeof sign;
|
|
40
|
+
validate: typeof validate;
|
|
41
|
+
K: Buffer<ArrayBuffer>;
|
|
42
|
+
};
|
|
43
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { Transport, TransportOptions } from './types';
|
|
3
|
+
export declare class BaseTransport extends EventEmitter implements Transport {
|
|
4
|
+
options: TransportOptions;
|
|
5
|
+
id: number;
|
|
6
|
+
constructor(options?: TransportOptions);
|
|
7
|
+
setOptions(options: TransportOptions): void;
|
|
8
|
+
listenTo(target: EventEmitter, eventName: string, callback: (...args: any[]) => void): () => void;
|
|
9
|
+
send(_api: string, _data: any, _callback: (error: any, result?: any) => void): void;
|
|
10
|
+
start(): Promise<void>;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export default BaseTransport;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TransportOptions, JsonRpcRequest } from './types';
|
|
2
|
+
import { BaseTransport } from './base';
|
|
3
|
+
export declare const jsonRpc: (uri: string, request: Partial<JsonRpcRequest>) => Promise<any>;
|
|
4
|
+
export declare class HttpTransport extends BaseTransport {
|
|
5
|
+
constructor(options: TransportOptions);
|
|
6
|
+
get nonRetriableOperations(): string[];
|
|
7
|
+
isBroadcastOperation(method: string): boolean;
|
|
8
|
+
send(api: string, data: any, callback?: (err: any, result?: any, attempt?: number) => void): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HttpTransport } from './http';
|
|
2
|
+
import { WsTransport } from './ws';
|
|
3
|
+
import { BaseTransport } from './base';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export declare const transports: {
|
|
6
|
+
http: typeof HttpTransport;
|
|
7
|
+
ws: typeof WsTransport;
|
|
8
|
+
};
|
|
9
|
+
export { BaseTransport };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface TransportOptions {
|
|
2
|
+
url?: string;
|
|
3
|
+
uri?: string;
|
|
4
|
+
/**
|
|
5
|
+
* WebSocket URL
|
|
6
|
+
* NOTE: WebSocket functionality is currently not supported.
|
|
7
|
+
* This field is kept for backward compatibility only.
|
|
8
|
+
* Please use HTTP transport (via url or uri field) for API calls.
|
|
9
|
+
*/
|
|
10
|
+
websocket?: string;
|
|
11
|
+
transport?: string | any;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
export interface JsonRpcRequest {
|
|
15
|
+
id: number;
|
|
16
|
+
method: string;
|
|
17
|
+
params: any[];
|
|
18
|
+
jsonrpc?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface JsonRpcResponse {
|
|
21
|
+
id: number;
|
|
22
|
+
result: any;
|
|
23
|
+
error?: {
|
|
24
|
+
code: number;
|
|
25
|
+
message: string;
|
|
26
|
+
data?: any;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface Transport {
|
|
30
|
+
options: TransportOptions;
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
setOptions(options: TransportOptions): void;
|
|
34
|
+
send(api: string, data: any, callback: (error: any, result?: any) => void): void | Promise<void>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransportOptions } from './types';
|
|
2
|
+
import { BaseTransport } from './base';
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket transport implementation
|
|
5
|
+
*
|
|
6
|
+
* NOTE: WebSocket functionality is currently not supported.
|
|
7
|
+
* This implementation is kept for backward compatibility only.
|
|
8
|
+
* Please use HTTP transport (via https://api.steemit.com) for API calls.
|
|
9
|
+
*/
|
|
10
|
+
export declare class WsTransport extends BaseTransport {
|
|
11
|
+
private ws;
|
|
12
|
+
private _requests;
|
|
13
|
+
private seqNo;
|
|
14
|
+
constructor(options: TransportOptions);
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
stop(): Promise<void>;
|
|
17
|
+
send(api: string, data: any, callback: (error: any, result?: any) => void): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Address } from './src/address';
|
|
2
|
+
export { Aes } from './src/aes';
|
|
3
|
+
export { PrivateKey } from './src/key_private';
|
|
4
|
+
export { PublicKey } from './src/key_public';
|
|
5
|
+
export { Signature } from './src/signature';
|
|
6
|
+
export { normalize as brainKey } from './src/brain_key';
|
|
7
|
+
export * as key_utils from './src/key_utils';
|
|
8
|
+
export * as hash from './src/hash';
|
|
9
|
+
export { Config as ecc_config } from '../../config';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PublicKey } from './key_public';
|
|
2
|
+
export declare class Address {
|
|
3
|
+
private addy;
|
|
4
|
+
constructor(addy: Buffer);
|
|
5
|
+
static fromBuffer(buffer: Buffer): string;
|
|
6
|
+
static fromString(address: string): Buffer;
|
|
7
|
+
static fromPublicKey(public_key: PublicKey, compressed?: boolean): string;
|
|
8
|
+
static fromPublic(public_key: PublicKey, compressed?: boolean, version?: number): Address;
|
|
9
|
+
static toBuffer(address: string): Buffer;
|
|
10
|
+
toBuffer(): Buffer;
|
|
11
|
+
getVersion(): number;
|
|
12
|
+
toString(address_prefix?: string): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PrivateKey } from './key_private';
|
|
2
|
+
import { PublicKey } from './key_public';
|
|
3
|
+
export declare class Aes {
|
|
4
|
+
static uniqueNonce(): string;
|
|
5
|
+
static encrypt(private_key: PrivateKey, public_key: PublicKey, message: Buffer | string, nonce?: string): {
|
|
6
|
+
nonce: string;
|
|
7
|
+
message: string;
|
|
8
|
+
checksum: number;
|
|
9
|
+
};
|
|
10
|
+
static decrypt(private_key: PrivateKey, public_key: PublicKey, nonce: string, message: string, checksum: number): Buffer;
|
|
11
|
+
static fromSeed(seed: string): Buffer;
|
|
12
|
+
static fromBuffer(buffer: Buffer): Buffer;
|
|
13
|
+
static fromString(string: string): Buffer;
|
|
14
|
+
static toBuffer(aes: Buffer): Buffer;
|
|
15
|
+
static toString(aes: Buffer): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalize(brain_key: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import BigInteger from 'bigi';
|
|
2
|
+
import ECSignature from './ecsignature';
|
|
3
|
+
type Curve = any;
|
|
4
|
+
type Point = any;
|
|
5
|
+
export declare function sign(curve: Curve, hash: Buffer, d: BigInteger, nonce?: number): ECSignature;
|
|
6
|
+
export declare function verify(curve: Curve, hash: Buffer, signature: ECSignature, Q: Point): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Recover a public key from a signature.
|
|
9
|
+
*
|
|
10
|
+
* See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
|
|
11
|
+
* Key Recovery Operation".
|
|
12
|
+
*
|
|
13
|
+
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
|
14
|
+
*/
|
|
15
|
+
export declare function recoverPubKey(curve: Curve, e: BigInteger, signature: ECSignature, i: number): Point;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate pubkey extraction parameter.
|
|
18
|
+
*
|
|
19
|
+
* When extracting a pubkey from a signature, we have to
|
|
20
|
+
* distinguish four different cases. Rather than putting this
|
|
21
|
+
* burden on the verifier, Bitcoin includes a 2-bit value with the
|
|
22
|
+
* signature.
|
|
23
|
+
*
|
|
24
|
+
* This function simply tries all four cases and returns the value
|
|
25
|
+
* that resulted in a successful pubkey recovery.
|
|
26
|
+
*/
|
|
27
|
+
export declare function calcPubKeyRecoveryParam(curve: Curve, e: BigInteger, signature: ECSignature, Q: Point): number;
|
|
28
|
+
export {};
|