@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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14173,6 +14173,77 @@ function sign$3(curve, hash, d, nonce) {
|
|
|
14173
14173
|
const finalS = s.gt(N_OVER_TWO) ? n.sub(s) : s;
|
|
14174
14174
|
return new ECSignature(r, finalS);
|
|
14175
14175
|
}
|
|
14176
|
+
/**
|
|
14177
|
+
* Recover a public key from a signature.
|
|
14178
|
+
*
|
|
14179
|
+
* See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
|
|
14180
|
+
* Key Recovery Operation".
|
|
14181
|
+
*
|
|
14182
|
+
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
|
14183
|
+
*/
|
|
14184
|
+
function recoverPubKey(curve, e, signature, i) {
|
|
14185
|
+
if ((i & 3) !== i) {
|
|
14186
|
+
throw new Error('Recovery param is more than two bits');
|
|
14187
|
+
}
|
|
14188
|
+
const n = new BN(curve.n.toString());
|
|
14189
|
+
const r = signature.r;
|
|
14190
|
+
const s = signature.s;
|
|
14191
|
+
if (r.isNeg() || r.isZero() || !r.lt(n))
|
|
14192
|
+
throw new Error('Invalid r value');
|
|
14193
|
+
if (s.isNeg() || s.isZero() || !s.lt(n))
|
|
14194
|
+
throw new Error('Invalid s value');
|
|
14195
|
+
// Try using elliptic's built-in recoverPubKey method
|
|
14196
|
+
// It expects: msg (Buffer), signature ({r: BN, s: BN}), j (recovery param)
|
|
14197
|
+
try {
|
|
14198
|
+
// Convert e (BN) to Buffer
|
|
14199
|
+
const msgBuffer = e.toArrayLike(Buffer, 'be', 32);
|
|
14200
|
+
// Create signature object compatible with elliptic's recoverPubKey
|
|
14201
|
+
// elliptic expects {r: BN, s: BN} format
|
|
14202
|
+
const sigObj = { r: r, s: s };
|
|
14203
|
+
// Use elliptic's built-in method
|
|
14204
|
+
const Q = curve.recoverPubKey(msgBuffer, sigObj, i);
|
|
14205
|
+
return Q;
|
|
14206
|
+
}
|
|
14207
|
+
catch (error) {
|
|
14208
|
+
// Fallback to manual implementation if elliptic's method fails
|
|
14209
|
+
const G = curve.g;
|
|
14210
|
+
// A set LSB signifies that the y-coordinate is odd
|
|
14211
|
+
const isYOdd = !!(i & 1);
|
|
14212
|
+
// The more significant bit specifies whether we should use the
|
|
14213
|
+
// first or second candidate key.
|
|
14214
|
+
const isSecondKey = i >> 1;
|
|
14215
|
+
// 1.1 Let x = r + jn
|
|
14216
|
+
const x = isSecondKey ? r.add(n) : r;
|
|
14217
|
+
// pointFromX expects a hex string (not BN object)
|
|
14218
|
+
// Convert BN to hex string and ensure proper padding
|
|
14219
|
+
const xHex = x.toString(16);
|
|
14220
|
+
// Ensure hex string is properly padded to 64 characters (32 bytes)
|
|
14221
|
+
const xHexPadded = xHex.padStart(64, '0');
|
|
14222
|
+
// pointFromX may also accept a Buffer, but hex string is more reliable
|
|
14223
|
+
let R;
|
|
14224
|
+
try {
|
|
14225
|
+
R = curve.curve.pointFromX(xHexPadded, isYOdd);
|
|
14226
|
+
}
|
|
14227
|
+
catch (error) {
|
|
14228
|
+
// If hex string fails, try with Buffer
|
|
14229
|
+
const xBuffer = x.toArrayLike(Buffer, 'be', 32);
|
|
14230
|
+
R = curve.curve.pointFromX(xBuffer, isYOdd);
|
|
14231
|
+
}
|
|
14232
|
+
// 1.4 Check that nR is at infinity
|
|
14233
|
+
const nR = R.mul(n);
|
|
14234
|
+
if (!nR.isInfinity())
|
|
14235
|
+
throw new Error('nR is not a valid curve point');
|
|
14236
|
+
// Compute -e from e
|
|
14237
|
+
const eNeg = e.neg().mod(n);
|
|
14238
|
+
// 1.6.1 Compute Q = r^-1 (sR - eG)
|
|
14239
|
+
// Q = r^-1 (sR + -eG)
|
|
14240
|
+
const rInv = r.invm(n);
|
|
14241
|
+
const sR = R.mul(s);
|
|
14242
|
+
const eGNeg = G.mul(eNeg);
|
|
14243
|
+
const Q = sR.add(eGNeg).mul(rInv);
|
|
14244
|
+
return Q;
|
|
14245
|
+
}
|
|
14246
|
+
}
|
|
14176
14247
|
/**
|
|
14177
14248
|
* Calculate pubkey extraction parameter.
|
|
14178
14249
|
*
|
|
@@ -14187,11 +14258,15 @@ function sign$3(curve, hash, d, nonce) {
|
|
|
14187
14258
|
function calcPubKeyRecoveryParam(curve, e, signature, Q) {
|
|
14188
14259
|
for (let i = 0; i < 4; i++) {
|
|
14189
14260
|
try {
|
|
14190
|
-
// Use
|
|
14191
|
-
const Qprime =
|
|
14261
|
+
// Use our own recoverPubKey function instead of curve.recoverPubKey
|
|
14262
|
+
const Qprime = recoverPubKey(curve, e, signature, i);
|
|
14192
14263
|
// 1.6.2 Verify Q = Q'
|
|
14193
|
-
// Compare points by checking
|
|
14194
|
-
|
|
14264
|
+
// Compare points by checking coordinates (more reliable than eq method)
|
|
14265
|
+
const Qx = Q.getX().toString(16);
|
|
14266
|
+
const Qy = Q.getY().toString(16);
|
|
14267
|
+
const QprimeX = Qprime.getX().toString(16);
|
|
14268
|
+
const QprimeY = Qprime.getY().toString(16);
|
|
14269
|
+
if (Qx === QprimeX && Qy === QprimeY) {
|
|
14195
14270
|
return i;
|
|
14196
14271
|
}
|
|
14197
14272
|
}
|
|
@@ -14225,7 +14300,13 @@ class Signature {
|
|
|
14225
14300
|
throw new Error('Invalid signature length');
|
|
14226
14301
|
}
|
|
14227
14302
|
const i = buffer.readUInt8(0);
|
|
14228
|
-
|
|
14303
|
+
// Support both formats: 27-30 (old/legacy) and 31-34 (dsteem compatible)
|
|
14304
|
+
// Check if it's in the old format (27-30) or new format (31-34)
|
|
14305
|
+
const recoveryOld = i - 27;
|
|
14306
|
+
const recoveryNew = i - 31;
|
|
14307
|
+
const isValidOld = recoveryOld >= 0 && recoveryOld <= 3 && (recoveryOld === (recoveryOld & 7));
|
|
14308
|
+
const isValidNew = recoveryNew >= 0 && recoveryNew <= 3 && (recoveryNew === (recoveryNew & 7));
|
|
14309
|
+
if (!isValidOld && !isValidNew) {
|
|
14229
14310
|
throw new Error('Invalid signature parameter');
|
|
14230
14311
|
}
|
|
14231
14312
|
const r = new BN(buffer.slice(1, 33));
|
|
@@ -14274,7 +14355,9 @@ class Signature {
|
|
|
14274
14355
|
}
|
|
14275
14356
|
}
|
|
14276
14357
|
const i = calcPubKeyRecoveryParam(secp256k1, new BN(buf_sha256), ecsignature, privKey.toPublic().Q);
|
|
14277
|
-
|
|
14358
|
+
// Use recovery byte 31-34 (instead of 27-30) to be compatible with dsteem
|
|
14359
|
+
// dsteem expects: recovery = byte - 31, so byte = recovery + 31
|
|
14360
|
+
return new Signature(ecsignature.r, ecsignature.s, i + 31);
|
|
14278
14361
|
}
|
|
14279
14362
|
static isCanonical(r, s) {
|
|
14280
14363
|
// See libraries/fc/src/crypto/elliptic_common.cpp is_fc_canonical
|
|
@@ -25734,7 +25817,7 @@ const steem = {
|
|
|
25734
25817
|
operations,
|
|
25735
25818
|
serializer,
|
|
25736
25819
|
utils: utils$3,
|
|
25737
|
-
version: '1.0.
|
|
25820
|
+
version: '1.0.11',
|
|
25738
25821
|
config: {
|
|
25739
25822
|
set: (options) => {
|
|
25740
25823
|
// If nodes is provided, extract the first node as url for API
|
|
@@ -25774,5 +25857,5 @@ if (typeof window !== 'undefined' || typeof globalThis !== 'undefined') {
|
|
|
25774
25857
|
}
|
|
25775
25858
|
}
|
|
25776
25859
|
|
|
25777
|
-
export { Api, doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, steem, verify };
|
|
25860
|
+
export { Api, doubleSha256, generateKeyPair, hmacSha256, ripemd160, sha256, sign, sign$2 as signRequest, steem, validate as validateRequest, verify };
|
|
25778
25861
|
//# sourceMappingURL=index.js.map
|