@steemit/steem-js 1.0.10 → 1.0.11
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/dist/api/index.d.ts +6 -0
- package/dist/api/types.d.ts +78 -0
- package/dist/browser.esm.js +91 -8
- package/dist/browser.esm.js.map +1 -1
- package/dist/index.cjs +92 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +91 -8
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +90 -7
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/api/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import type { Transport } from './transports/types';
|
|
3
3
|
import type { TransportOptions } from './transports/types';
|
|
4
|
+
import type { ApiMethodSignatures } from './types';
|
|
4
5
|
interface ApiOptions {
|
|
5
6
|
url?: string;
|
|
6
7
|
transport?: string | (new (options: TransportOptions) => Transport);
|
|
@@ -20,6 +21,11 @@ export declare class Api extends EventEmitter {
|
|
|
20
21
|
private transport;
|
|
21
22
|
private options;
|
|
22
23
|
private __logger;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
getAccounts: ApiMethodSignatures['getAccounts'];
|
|
26
|
+
getAccountsAsync: ApiMethodSignatures['getAccountsAsync'];
|
|
27
|
+
getAccountsWith: ApiMethodSignatures['getAccountsWith'];
|
|
28
|
+
getAccountsWithAsync: ApiMethodSignatures['getAccountsWithAsync'];
|
|
23
29
|
private static _wrapWithPromise;
|
|
24
30
|
constructor(options?: ApiOptions);
|
|
25
31
|
private _setTransport;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for dynamically generated API methods
|
|
3
|
+
* These types provide TypeScript support for all API methods
|
|
4
|
+
*/
|
|
5
|
+
export type ApiCallback<T = unknown> = (err: Error | null, result?: T) => void;
|
|
6
|
+
type ApiMethodWithParams<TResult = unknown> = (...args: unknown[]) => Promise<TResult> | void;
|
|
7
|
+
type ApiMethodNoParams<TResult = unknown> = (callback?: ApiCallback<TResult>) => Promise<TResult> | void;
|
|
8
|
+
type ApiMethodWith<TResult = unknown> = (options: Record<string, unknown>, callback?: ApiCallback<TResult>) => Promise<TResult> | void;
|
|
9
|
+
type ApiMethodAsync<TParams extends unknown[] = unknown[], TResult = unknown> = (...args: TParams) => Promise<TResult>;
|
|
10
|
+
type ApiMethodWithAsync<TResult = unknown> = (options: Record<string, unknown>) => Promise<TResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Type definitions for all API methods
|
|
13
|
+
* This interface provides type safety for dynamically generated methods
|
|
14
|
+
*/
|
|
15
|
+
export interface ApiMethodSignatures {
|
|
16
|
+
getAccounts(accounts: string[], callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
17
|
+
getAccountsAsync(accounts: string[]): Promise<any[]>;
|
|
18
|
+
getAccountsWith(options: {
|
|
19
|
+
names: string[];
|
|
20
|
+
}, callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
21
|
+
getAccountsWithAsync(options: {
|
|
22
|
+
names: string[];
|
|
23
|
+
}): Promise<any[]>;
|
|
24
|
+
getAccountHistory(account: string, from: number, limit: number, callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
25
|
+
getAccountHistoryAsync(account: string, from: number, limit: number): Promise<any[]>;
|
|
26
|
+
getAccountHistoryWith(options: {
|
|
27
|
+
account: string;
|
|
28
|
+
from: number;
|
|
29
|
+
limit: number;
|
|
30
|
+
}, callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
31
|
+
getAccountHistoryWithAsync(options: {
|
|
32
|
+
account: string;
|
|
33
|
+
from: number;
|
|
34
|
+
limit: number;
|
|
35
|
+
}): Promise<any[]>;
|
|
36
|
+
getDynamicGlobalProperties(callback?: ApiCallback<any>): Promise<any> | void;
|
|
37
|
+
getDynamicGlobalPropertiesAsync(): Promise<any>;
|
|
38
|
+
getDynamicGlobalPropertiesWith(options: Record<string, unknown>, callback?: ApiCallback<any>): Promise<any> | void;
|
|
39
|
+
getDynamicGlobalPropertiesWithAsync(options: Record<string, unknown>): Promise<any>;
|
|
40
|
+
getContent(author: string, permlink: string, callback?: ApiCallback<any>): Promise<any> | void;
|
|
41
|
+
getContentAsync(author: string, permlink: string): Promise<any>;
|
|
42
|
+
getContentWith(options: {
|
|
43
|
+
author: string;
|
|
44
|
+
permlink: string;
|
|
45
|
+
}, callback?: ApiCallback<any>): Promise<any> | void;
|
|
46
|
+
getContentWithAsync(options: {
|
|
47
|
+
author: string;
|
|
48
|
+
permlink: string;
|
|
49
|
+
}): Promise<any>;
|
|
50
|
+
getFollowers(following: string, startFollower: string, followType: string, limit: number, callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
51
|
+
getFollowersAsync(following: string, startFollower: string, followType: string, limit: number): Promise<any[]>;
|
|
52
|
+
getFollowersWith(options: {
|
|
53
|
+
following: string;
|
|
54
|
+
startFollower: string;
|
|
55
|
+
followType: string;
|
|
56
|
+
limit: number;
|
|
57
|
+
}, callback?: ApiCallback<any[]>): Promise<any[]> | void;
|
|
58
|
+
getFollowersWithAsync(options: {
|
|
59
|
+
following: string;
|
|
60
|
+
startFollower: string;
|
|
61
|
+
followType: string;
|
|
62
|
+
limit: number;
|
|
63
|
+
}): Promise<any[]>;
|
|
64
|
+
getBlock(blockNum: number, callback?: ApiCallback<any>): Promise<any> | void;
|
|
65
|
+
getBlockAsync(blockNum: number): Promise<any>;
|
|
66
|
+
getBlockWith(options: {
|
|
67
|
+
blockNum: number;
|
|
68
|
+
}, callback?: ApiCallback<any>): Promise<any> | void;
|
|
69
|
+
getBlockWithAsync(options: {
|
|
70
|
+
blockNum: number;
|
|
71
|
+
}): Promise<any>;
|
|
72
|
+
getConfig(callback?: ApiCallback<any>): Promise<any> | void;
|
|
73
|
+
getConfigAsync(): Promise<any>;
|
|
74
|
+
getConfigWith(options: Record<string, unknown>, callback?: ApiCallback<any>): Promise<any> | void;
|
|
75
|
+
getConfigWithAsync(options: Record<string, unknown>): Promise<any>;
|
|
76
|
+
[methodName: string]: ApiMethodWithParams | ApiMethodNoParams | ApiMethodWith | ApiMethodAsync<unknown[]> | ApiMethodWithAsync | unknown;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
package/dist/browser.esm.js
CHANGED
|
@@ -17213,6 +17213,77 @@ function sign$3(curve, hash, d, nonce) {
|
|
|
17213
17213
|
const finalS = s.gt(N_OVER_TWO) ? n.sub(s) : s;
|
|
17214
17214
|
return new ECSignature(r, finalS);
|
|
17215
17215
|
}
|
|
17216
|
+
/**
|
|
17217
|
+
* Recover a public key from a signature.
|
|
17218
|
+
*
|
|
17219
|
+
* See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
|
|
17220
|
+
* Key Recovery Operation".
|
|
17221
|
+
*
|
|
17222
|
+
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
|
17223
|
+
*/
|
|
17224
|
+
function recoverPubKey(curve, e, signature, i) {
|
|
17225
|
+
if ((i & 3) !== i) {
|
|
17226
|
+
throw new Error('Recovery param is more than two bits');
|
|
17227
|
+
}
|
|
17228
|
+
const n = new BN(curve.n.toString());
|
|
17229
|
+
const r = signature.r;
|
|
17230
|
+
const s = signature.s;
|
|
17231
|
+
if (r.isNeg() || r.isZero() || !r.lt(n))
|
|
17232
|
+
throw new Error('Invalid r value');
|
|
17233
|
+
if (s.isNeg() || s.isZero() || !s.lt(n))
|
|
17234
|
+
throw new Error('Invalid s value');
|
|
17235
|
+
// Try using elliptic's built-in recoverPubKey method
|
|
17236
|
+
// It expects: msg (Buffer), signature ({r: BN, s: BN}), j (recovery param)
|
|
17237
|
+
try {
|
|
17238
|
+
// Convert e (BN) to Buffer
|
|
17239
|
+
const msgBuffer = e.toArrayLike(bufferExports.Buffer, 'be', 32);
|
|
17240
|
+
// Create signature object compatible with elliptic's recoverPubKey
|
|
17241
|
+
// elliptic expects {r: BN, s: BN} format
|
|
17242
|
+
const sigObj = { r: r, s: s };
|
|
17243
|
+
// Use elliptic's built-in method
|
|
17244
|
+
const Q = curve.recoverPubKey(msgBuffer, sigObj, i);
|
|
17245
|
+
return Q;
|
|
17246
|
+
}
|
|
17247
|
+
catch (error) {
|
|
17248
|
+
// Fallback to manual implementation if elliptic's method fails
|
|
17249
|
+
const G = curve.g;
|
|
17250
|
+
// A set LSB signifies that the y-coordinate is odd
|
|
17251
|
+
const isYOdd = !!(i & 1);
|
|
17252
|
+
// The more significant bit specifies whether we should use the
|
|
17253
|
+
// first or second candidate key.
|
|
17254
|
+
const isSecondKey = i >> 1;
|
|
17255
|
+
// 1.1 Let x = r + jn
|
|
17256
|
+
const x = isSecondKey ? r.add(n) : r;
|
|
17257
|
+
// pointFromX expects a hex string (not BN object)
|
|
17258
|
+
// Convert BN to hex string and ensure proper padding
|
|
17259
|
+
const xHex = x.toString(16);
|
|
17260
|
+
// Ensure hex string is properly padded to 64 characters (32 bytes)
|
|
17261
|
+
const xHexPadded = xHex.padStart(64, '0');
|
|
17262
|
+
// pointFromX may also accept a Buffer, but hex string is more reliable
|
|
17263
|
+
let R;
|
|
17264
|
+
try {
|
|
17265
|
+
R = curve.curve.pointFromX(xHexPadded, isYOdd);
|
|
17266
|
+
}
|
|
17267
|
+
catch (error) {
|
|
17268
|
+
// If hex string fails, try with Buffer
|
|
17269
|
+
const xBuffer = x.toArrayLike(bufferExports.Buffer, 'be', 32);
|
|
17270
|
+
R = curve.curve.pointFromX(xBuffer, isYOdd);
|
|
17271
|
+
}
|
|
17272
|
+
// 1.4 Check that nR is at infinity
|
|
17273
|
+
const nR = R.mul(n);
|
|
17274
|
+
if (!nR.isInfinity())
|
|
17275
|
+
throw new Error('nR is not a valid curve point');
|
|
17276
|
+
// Compute -e from e
|
|
17277
|
+
const eNeg = e.neg().mod(n);
|
|
17278
|
+
// 1.6.1 Compute Q = r^-1 (sR - eG)
|
|
17279
|
+
// Q = r^-1 (sR + -eG)
|
|
17280
|
+
const rInv = r.invm(n);
|
|
17281
|
+
const sR = R.mul(s);
|
|
17282
|
+
const eGNeg = G.mul(eNeg);
|
|
17283
|
+
const Q = sR.add(eGNeg).mul(rInv);
|
|
17284
|
+
return Q;
|
|
17285
|
+
}
|
|
17286
|
+
}
|
|
17216
17287
|
/**
|
|
17217
17288
|
* Calculate pubkey extraction parameter.
|
|
17218
17289
|
*
|
|
@@ -17227,11 +17298,15 @@ function sign$3(curve, hash, d, nonce) {
|
|
|
17227
17298
|
function calcPubKeyRecoveryParam(curve, e, signature, Q) {
|
|
17228
17299
|
for (let i = 0; i < 4; i++) {
|
|
17229
17300
|
try {
|
|
17230
|
-
// Use
|
|
17231
|
-
const Qprime =
|
|
17301
|
+
// Use our own recoverPubKey function instead of curve.recoverPubKey
|
|
17302
|
+
const Qprime = recoverPubKey(curve, e, signature, i);
|
|
17232
17303
|
// 1.6.2 Verify Q = Q'
|
|
17233
|
-
// Compare points by checking
|
|
17234
|
-
|
|
17304
|
+
// Compare points by checking coordinates (more reliable than eq method)
|
|
17305
|
+
const Qx = Q.getX().toString(16);
|
|
17306
|
+
const Qy = Q.getY().toString(16);
|
|
17307
|
+
const QprimeX = Qprime.getX().toString(16);
|
|
17308
|
+
const QprimeY = Qprime.getY().toString(16);
|
|
17309
|
+
if (Qx === QprimeX && Qy === QprimeY) {
|
|
17235
17310
|
return i;
|
|
17236
17311
|
}
|
|
17237
17312
|
}
|
|
@@ -17265,7 +17340,13 @@ class Signature {
|
|
|
17265
17340
|
throw new Error('Invalid signature length');
|
|
17266
17341
|
}
|
|
17267
17342
|
const i = buffer.readUInt8(0);
|
|
17268
|
-
|
|
17343
|
+
// Support both formats: 27-30 (old/legacy) and 31-34 (dsteem compatible)
|
|
17344
|
+
// Check if it's in the old format (27-30) or new format (31-34)
|
|
17345
|
+
const recoveryOld = i - 27;
|
|
17346
|
+
const recoveryNew = i - 31;
|
|
17347
|
+
const isValidOld = recoveryOld >= 0 && recoveryOld <= 3 && (recoveryOld === (recoveryOld & 7));
|
|
17348
|
+
const isValidNew = recoveryNew >= 0 && recoveryNew <= 3 && (recoveryNew === (recoveryNew & 7));
|
|
17349
|
+
if (!isValidOld && !isValidNew) {
|
|
17269
17350
|
throw new Error('Invalid signature parameter');
|
|
17270
17351
|
}
|
|
17271
17352
|
const r = new BN(buffer.slice(1, 33));
|
|
@@ -17314,7 +17395,9 @@ class Signature {
|
|
|
17314
17395
|
}
|
|
17315
17396
|
}
|
|
17316
17397
|
const i = calcPubKeyRecoveryParam(secp256k1, new BN(buf_sha256), ecsignature, privKey.toPublic().Q);
|
|
17317
|
-
|
|
17398
|
+
// Use recovery byte 31-34 (instead of 27-30) to be compatible with dsteem
|
|
17399
|
+
// dsteem expects: recovery = byte - 31, so byte = recovery + 31
|
|
17400
|
+
return new Signature(ecsignature.r, ecsignature.s, i + 31);
|
|
17318
17401
|
}
|
|
17319
17402
|
static isCanonical(r, s) {
|
|
17320
17403
|
// See libraries/fc/src/crypto/elliptic_common.cpp is_fc_canonical
|
|
@@ -29062,7 +29145,7 @@ const steem = {
|
|
|
29062
29145
|
operations,
|
|
29063
29146
|
serializer,
|
|
29064
29147
|
utils: utils$3,
|
|
29065
|
-
version: '1.0.
|
|
29148
|
+
version: '1.0.11',
|
|
29066
29149
|
config: {
|
|
29067
29150
|
set: (options) => {
|
|
29068
29151
|
// If nodes is provided, extract the first node as url for API
|
|
@@ -29102,5 +29185,5 @@ if (typeof window !== 'undefined' || typeof globalThis !== 'undefined') {
|
|
|
29102
29185
|
}
|
|
29103
29186
|
}
|
|
29104
29187
|
|
|
29105
|
-
export { Api, doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, steem, verify };
|
|
29188
|
+
export { Api, doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, sign$2 as signRequest, steem, validate as validateRequest, verify };
|
|
29106
29189
|
//# sourceMappingURL=browser.esm.js.map
|