New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eosjs

Package Overview
Dependencies
Maintainers
4
Versions
292
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eosjs - npm Package Compare versions

Comparing version 22.2.0-81-d6097c6 to 22.2.0-82-22a1a05

dist/eosjs-webcrypto-sig.d.ts

20

dist/eosjs-api.js

@@ -70,6 +70,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -201,3 +205,3 @@ var __values = (this && this.__values) || function(o) {

uniqueAccounts = new Set(accounts);
actionPromises = __spreadArray([], __read(uniqueAccounts)).map(function (account) { return __awaiter(_this, void 0, void 0, function () {
actionPromises = __spreadArray([], __read(uniqueAccounts), false).map(function (account) { return __awaiter(_this, void 0, void 0, function () {
var _a;

@@ -307,3 +311,3 @@ return __generator(this, function (_b) {

types.get('resource_payer').serialize(extensionBuffer, transaction.resource_payer);
transaction_extensions = __spreadArray(__spreadArray([], __read(transaction_extensions)), [[1, ser.arrayToHex(extensionBuffer.asUint8Array())]]);
transaction_extensions = __spreadArray(__spreadArray([], __read(transaction_extensions), false), [[1, ser.arrayToHex(extensionBuffer.asUint8Array())]], false);
}

@@ -417,7 +421,7 @@ return transaction_extensions;

Api.prototype.deflateSerializedArray = function (serializedArray) {
return pako_1.deflate(serializedArray, { level: 9 });
return (0, pako_1.deflate)(serializedArray, { level: 9 });
};
/** Inflate a compressed serialized object */
Api.prototype.inflateSerializedArray = function (compressedSerializedArray) {
return pako_1.inflate(compressedSerializedArray);
return (0, pako_1.inflate)(compressedSerializedArray);
};

@@ -424,0 +428,0 @@ /**

2

dist/eosjs-ecc-migration.js

@@ -16,3 +16,3 @@ "use strict";

}
var privateKey = eosjs_key_conversions_1.generateKeyPair(eosjs_numeric_1.KeyType.k1, options).privateKey;
var privateKey = (0, eosjs_key_conversions_1.generateKeyPair)(eosjs_numeric_1.KeyType.k1, options).privateKey;
return Promise.resolve(privateKey.toLegacyString());

@@ -19,0 +19,0 @@ },

@@ -333,3 +333,3 @@ "use strict";

rawAbi = _a.sent();
abi = eosjs_numeric_1.base64ToBinary(rawAbi.abi);
abi = (0, eosjs_numeric_1.base64ToBinary)(rawAbi.abi);
return [2 /*return*/, { accountName: rawAbi.account_name, abi: abi }];

@@ -336,0 +336,0 @@ }

@@ -124,3 +124,3 @@ "use strict";

publicKey = eosjs_key_conversions_1.PublicKey.fromString(key);
ellipticPrivateKey = this.keys.get(eosjs_numeric_1.convertLegacyPublicKey(key));
ellipticPrivateKey = this.keys.get((0, eosjs_numeric_1.convertLegacyPublicKey)(key));
privateKey = eosjs_key_conversions_1.PrivateKey.fromElliptic(ellipticPrivateKey, publicKey.getType());

@@ -127,0 +127,0 @@ signature = privateKey.sign(digest, false);

/// <reference types="node" />
import { ec as EC } from 'elliptic';
import { KeyType } from './eosjs-numeric';
import { PublicKey } from './PublicKey';
import { PrivateKey } from './PrivateKey';
export { PrivateKey } from './PrivateKey';
export { PublicKey } from './PublicKey';
export { Signature } from './Signature';
/** Construct the elliptic curve object based on key type */
export declare const constructElliptic: (type: KeyType) => EC;
export declare const generateKeyPair: (type: KeyType, options?: {
secureEnv?: boolean;
ecOptions?: EC.GenKeyPairOptions;
}) => {
publicKey: PublicKey;
privateKey: PrivateKey;
};
export { generateKeyPair, generateWebCryptoKeyPair, } from './KeyUtil';
export declare const sha256: (data: string | Buffer) => number[] | string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sha256 = exports.generateKeyPair = exports.constructElliptic = exports.Signature = exports.PublicKey = exports.PrivateKey = void 0;
var elliptic_1 = require("elliptic");
exports.sha256 = exports.generateWebCryptoKeyPair = exports.generateKeyPair = exports.Signature = exports.PublicKey = exports.PrivateKey = void 0;
var hash = require("hash.js");
var eosjs_numeric_1 = require("./eosjs-numeric");
var PrivateKey_1 = require("./PrivateKey");
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return PrivateKey_1.PrivateKey; } });
var PublicKey_1 = require("./PublicKey");
var PrivateKey_1 = require("./PrivateKey");
var PrivateKey_2 = require("./PrivateKey");
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return PrivateKey_2.PrivateKey; } });
var PublicKey_2 = require("./PublicKey");
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return PublicKey_2.PublicKey; } });
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return PublicKey_1.PublicKey; } });
var Signature_1 = require("./Signature");
Object.defineProperty(exports, "Signature", { enumerable: true, get: function () { return Signature_1.Signature; } });
/** Construct the elliptic curve object based on key type */
var constructElliptic = function (type) {
if (type === eosjs_numeric_1.KeyType.k1) {
return new elliptic_1.ec('secp256k1');
}
return new elliptic_1.ec('p256');
};
exports.constructElliptic = constructElliptic;
var generateKeyPair = function (type, options) {
if (options === void 0) { options = {}; }
if (!options.secureEnv) {
throw new Error('Key generation is completely INSECURE in production environments in the browser. ' +
'If you are absolutely certain this does NOT describe your environment, set `secureEnv` in your ' +
'options to `true`. If this does describe your environment and you set `secureEnv` to `true`, ' +
'YOU DO SO AT YOUR OWN RISK AND THE RISK OF YOUR USERS.');
}
var ec;
if (type === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
var ellipticKeyPair = ec.genKeyPair(options.ecOptions);
var publicKey = PublicKey_1.PublicKey.fromElliptic(ellipticKeyPair, type, ec);
var privateKey = PrivateKey_1.PrivateKey.fromElliptic(ellipticKeyPair, type, ec);
return { publicKey: publicKey, privateKey: privateKey };
};
exports.generateKeyPair = generateKeyPair;
var KeyUtil_1 = require("./KeyUtil");
Object.defineProperty(exports, "generateKeyPair", { enumerable: true, get: function () { return KeyUtil_1.generateKeyPair; } });
Object.defineProperty(exports, "generateWebCryptoKeyPair", { enumerable: true, get: function () { return KeyUtil_1.generateWebCryptoKeyPair; } });
var sha256 = function (data) {

@@ -45,0 +15,0 @@ return hash.sha256().update(data).digest();

@@ -43,2 +43,6 @@ /** Is `bignum` a negative number? */

export declare const base64ToBinary: (s: string) => Uint8Array;
/** Convert ArrayBuffer to string where characters in string are represented as bytes */
export declare const arrayToString: (data: ArrayBuffer) => string;
/** Convert string where characters in string are represented as bytes to an ArrayBuffer */
export declare const stringToArray: (str: string) => ArrayBuffer;
/** Key types this library supports */

@@ -45,0 +49,0 @@ export declare enum KeyType {

@@ -18,6 +18,10 @@ "use strict";

};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -36,3 +40,3 @@ var __values = (this && this.__values) || function(o) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.signatureToString = exports.stringToSignature = exports.privateKeyToString = exports.privateKeyToLegacyString = exports.stringToPrivateKey = exports.convertLegacyPublicKeys = exports.convertLegacyPublicKey = exports.publicKeyToString = exports.publicKeyToLegacyString = exports.stringToPublicKey = exports.signatureDataSize = exports.privateKeyDataSize = exports.publicKeyDataSize = exports.KeyType = exports.base64ToBinary = exports.binaryToBase58 = exports.base58ToBinary = exports.signedBinaryToDecimal = exports.binaryToDecimal = exports.signedDecimalToBinary = exports.decimalToBinary = exports.negate = exports.isNegative = void 0;
exports.signatureToString = exports.stringToSignature = exports.privateKeyToString = exports.privateKeyToLegacyString = exports.stringToPrivateKey = exports.convertLegacyPublicKeys = exports.convertLegacyPublicKey = exports.publicKeyToString = exports.publicKeyToLegacyString = exports.stringToPublicKey = exports.signatureDataSize = exports.privateKeyDataSize = exports.publicKeyDataSize = exports.KeyType = exports.stringToArray = exports.arrayToString = exports.base64ToBinary = exports.binaryToBase58 = exports.base58ToBinary = exports.signedBinaryToDecimal = exports.binaryToDecimal = exports.signedDecimalToBinary = exports.decimalToBinary = exports.negate = exports.isNegative = void 0;
/**

@@ -113,10 +117,10 @@ * @module Numeric

}
var result = exports.decimalToBinary(size, s);
var result = (0, exports.decimalToBinary)(size, s);
if (negative) {
exports.negate(result);
if (!exports.isNegative(result)) {
(0, exports.negate)(result);
if (!(0, exports.isNegative)(result)) {
throw new Error('number is out of range');
}
}
else if (exports.isNegative(result)) {
else if ((0, exports.isNegative)(result)) {
throw new Error('number is out of range');

@@ -148,3 +152,3 @@ }

result.reverse();
return String.fromCharCode.apply(String, __spreadArray([], __read(result)));
return String.fromCharCode.apply(String, __spreadArray([], __read(result), false));
};

@@ -159,8 +163,8 @@ exports.binaryToDecimal = binaryToDecimal;

if (minDigits === void 0) { minDigits = 1; }
if (exports.isNegative(bignum)) {
if ((0, exports.isNegative)(bignum)) {
var x = bignum.slice();
exports.negate(x);
return '-' + exports.binaryToDecimal(x, minDigits);
(0, exports.negate)(x);
return '-' + (0, exports.binaryToDecimal)(x, minDigits);
}
return exports.binaryToDecimal(bignum, minDigits);
return (0, exports.binaryToDecimal)(bignum, minDigits);
};

@@ -284,3 +288,3 @@ exports.signedBinaryToDecimal = signedBinaryToDecimal;

result.reverse();
return String.fromCharCode.apply(String, __spreadArray([], __read(result)));
return String.fromCharCode.apply(String, __spreadArray([], __read(result), false));
};

@@ -324,2 +328,17 @@ exports.binaryToBase58 = binaryToBase58;

exports.base64ToBinary = base64ToBinary;
/** Convert ArrayBuffer to string where characters in string are represented as bytes */
var arrayToString = function (data) {
return String.fromCharCode.apply(null, new Uint8Array(data));
};
exports.arrayToString = arrayToString;
/** Convert string where characters in string are represented as bytes to an ArrayBuffer */
var stringToArray = function (str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
};
exports.stringToArray = stringToArray;
/** Key types this library supports */

@@ -349,3 +368,3 @@ var KeyType;

var stringToKey = function (s, type, size, suffix) {
var whole = exports.base58ToBinary(size ? size + 4 : 0, s);
var whole = (0, exports.base58ToBinary)(size ? size + 4 : 0, s);
var result = { type: type, data: new Uint8Array(whole.buffer, 0, whole.length - 4) };

@@ -368,3 +387,3 @@ var digest = new Uint8Array(digestSuffixRipemd160(result.data, suffix));

}
return prefix + exports.binaryToBase58(whole);
return prefix + (0, exports.binaryToBase58)(whole);
};

@@ -377,3 +396,3 @@ /** Convert key in `s` to binary form */

if (s.substr(0, 3) === 'EOS') {
var whole = exports.base58ToBinary(exports.publicKeyDataSize + 4, s.substr(3));
var whole = (0, exports.base58ToBinary)(exports.publicKeyDataSize + 4, s.substr(3));
var key = { type: KeyType.k1, data: new Uint8Array(exports.publicKeyDataSize) };

@@ -438,3 +457,3 @@ for (var i = 0; i < exports.publicKeyDataSize; ++i) {

if (s.substr(0, 3) === 'EOS') {
return exports.publicKeyToString(exports.stringToPublicKey(s));
return (0, exports.publicKeyToString)((0, exports.stringToPublicKey)(s));
}

@@ -466,3 +485,3 @@ return s;

// valid signature anyway.
var whole = exports.base58ToBinary(exports.privateKeyDataSize + 5, s);
var whole = (0, exports.base58ToBinary)(exports.privateKeyDataSize + 5, s);
var key = { type: KeyType.k1, data: new Uint8Array(exports.privateKeyDataSize) };

@@ -485,3 +504,3 @@ if (whole[0] !== 0x80) {

key.data.forEach(function (byte) { return whole_1.push(byte); });
var digest = new Uint8Array(hash_js_1.sha256().update(hash_js_1.sha256().update(whole_1).digest()).digest());
var digest = new Uint8Array((0, hash_js_1.sha256)().update((0, hash_js_1.sha256)().update(whole_1).digest()).digest());
var result = new Uint8Array(exports.privateKeyDataSize + 5);

@@ -494,3 +513,3 @@ for (var i = 0; i < whole_1.length; i++) {

}
return exports.binaryToBase58(result);
return (0, exports.binaryToBase58)(result);
}

@@ -497,0 +516,0 @@ else if (key.type === KeyType.r1 || key.type === KeyType.wa) {

/// <reference types="node" />
import { BNInput, ec as EC } from 'elliptic';
import { Key, KeyType } from './eosjs-numeric';
import { PublicKey, Signature } from './eosjs-key-conversions';
import { PublicKey } from './PublicKey';
import { Signature } from './Signature';
declare type WebCryptoSignatureData = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer;
/** Represents/stores a private key and provides easy conversion for use with `elliptic` lib */

@@ -12,2 +14,4 @@ export declare class PrivateKey {

static fromElliptic(privKey: EC.KeyPair, keyType: KeyType, ec?: EC): PrivateKey;
/** Instantiate private key from a `CryptoKey`-format private key */
static fromWebCrypto(privKey: CryptoKey): Promise<PrivateKey>;
/** Instantiate private key from an EOSIO-format private key */

@@ -17,2 +21,4 @@ static fromString(keyString: string, ec?: EC): PrivateKey;

toElliptic(): EC.KeyPair;
/** Export private key as `CryptoKey`-format private key */
toWebCrypto(extractable?: boolean): Promise<CryptoKey>;
toLegacyString(): string;

@@ -27,4 +33,7 @@ /** Export private key as EOSIO-format private key */

sign(data: BNInput, shouldHash?: boolean, encoding?: BufferEncoding): Signature;
/** Use Web Crypto to sign data (that matches types) with private CryptoKey */
webCryptoSign(data: WebCryptoSignatureData): Promise<Signature>;
/** Validate a private key */
isValid(): boolean;
}
export {};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrivateKey = void 0;
var elliptic_1 = require("elliptic");
var eosjs_numeric_1 = require("./eosjs-numeric");
var eosjs_key_conversions_1 = require("./eosjs-key-conversions");
var PublicKey_1 = require("./PublicKey");
var Signature_1 = require("./Signature");
var crypto = (typeof (window) !== 'undefined' ? window.crypto : require('crypto').webcrypto);
/** Represents/stores a private key and provides easy conversion for use with `elliptic` lib */

@@ -15,3 +54,8 @@ var PrivateKey = /** @class */ (function () {

if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(keyType);
if (keyType === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -23,7 +67,36 @@ return new PrivateKey({

};
/** Instantiate private key from a `CryptoKey`-format private key */
PrivateKey.fromWebCrypto = function (privKey) {
return __awaiter(this, void 0, void 0, function () {
var ec, extractedArrayBuffer, extractedDecoded, derHex, privateKeyHex, privateKeyEc;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (privKey.extractable === false) {
throw new Error('Crypto Key is not extractable');
}
ec = new elliptic_1.ec('p256');
return [4 /*yield*/, crypto.subtle.exportKey('pkcs8', privKey)];
case 1:
extractedArrayBuffer = _a.sent();
extractedDecoded = (0, eosjs_numeric_1.arrayToString)(extractedArrayBuffer);
derHex = Buffer.from(extractedDecoded, 'binary').toString('hex');
privateKeyHex = derHex.replace('308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b0201010420', '');
privateKeyHex = privateKeyHex.substring(0, privateKeyHex.indexOf('a144034200'));
privateKeyEc = ec.keyFromPrivate(privateKeyHex, 'hex');
return [2 /*return*/, PrivateKey.fromElliptic(privateKeyEc, eosjs_numeric_1.KeyType.r1, ec)];
}
});
});
};
/** Instantiate private key from an EOSIO-format private key */
PrivateKey.fromString = function (keyString, ec) {
var privateKey = eosjs_numeric_1.stringToPrivateKey(keyString);
var privateKey = (0, eosjs_numeric_1.stringToPrivateKey)(keyString);
if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(privateKey.type);
if (privateKey.type === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -36,8 +109,33 @@ return new PrivateKey(privateKey, ec);

};
/** Export private key as `CryptoKey`-format private key */
PrivateKey.prototype.toWebCrypto = function (extractable) {
if (extractable === void 0) { extractable = false; }
return __awaiter(this, void 0, void 0, function () {
var privateKeyEc, privateKeyHex, publicKey, publicKeyEc, publicKeyHex, derHex, derBinary, pkcs8ArrayBuffer;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
privateKeyEc = this.toElliptic();
privateKeyHex = privateKeyEc.getPrivate('hex');
publicKey = this.getPublicKey();
publicKeyEc = publicKey.toElliptic();
publicKeyHex = publicKeyEc.getPublic('hex');
derHex = "308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b0201010420" + privateKeyHex + "a144034200" + publicKeyHex;
derBinary = Buffer.from(derHex, 'hex').toString('binary');
pkcs8ArrayBuffer = (0, eosjs_numeric_1.stringToArray)(derBinary);
return [4 /*yield*/, crypto.subtle.importKey('pkcs8', pkcs8ArrayBuffer, {
name: 'ECDSA',
namedCurve: 'P-256'
}, extractable, ['sign'])];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
PrivateKey.prototype.toLegacyString = function () {
return eosjs_numeric_1.privateKeyToLegacyString(this.key);
return (0, eosjs_numeric_1.privateKeyToLegacyString)(this.key);
};
/** Export private key as EOSIO-format private key */
PrivateKey.prototype.toString = function () {
return eosjs_numeric_1.privateKeyToString(this.key);
return (0, eosjs_numeric_1.privateKeyToString)(this.key);
};

@@ -51,3 +149,3 @@ /** Get key type from key */

var ellipticPrivateKey = this.toElliptic();
return eosjs_key_conversions_1.PublicKey.fromElliptic(ellipticPrivateKey, this.getType(), this.ec);
return PublicKey_1.PublicKey.fromElliptic(ellipticPrivateKey, this.getType(), this.ec);
};

@@ -74,3 +172,3 @@ /** Sign a message or hashed message digest with private key */

var ellipticSignature = ellipticPrivateKey.sign(data, options);
return eosjs_key_conversions_1.Signature.fromElliptic(ellipticSignature, _this.getType(), _this.ec);
return Signature_1.Signature.fromElliptic(ellipticSignature, _this.getType(), _this.ec);
};

@@ -87,2 +185,26 @@ if (this.key.type === eosjs_numeric_1.KeyType.k1) {

};
/** Use Web Crypto to sign data (that matches types) with private CryptoKey */
PrivateKey.prototype.webCryptoSign = function (data) {
return __awaiter(this, void 0, void 0, function () {
var publicKey, privWebCrypto, webCryptoSig;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
publicKey = this.getPublicKey();
return [4 /*yield*/, this.toWebCrypto()];
case 1:
privWebCrypto = _a.sent();
return [4 /*yield*/, crypto.subtle.sign({
name: 'ECDSA',
hash: {
name: 'SHA-256'
}
}, privWebCrypto, data)];
case 2:
webCryptoSig = _a.sent();
return [2 /*return*/, Signature_1.Signature.fromWebCrypto(data, webCryptoSig, publicKey)];
}
});
});
};
/** Validate a private key */

@@ -89,0 +211,0 @@ PrivateKey.prototype.isValid = function () {

@@ -12,2 +12,4 @@ import { ec as EC } from 'elliptic';

static fromElliptic(publicKey: EC.KeyPair, keyType: KeyType, ec?: EC): PublicKey;
/** Instantiate public key from a `CryptoKey`-format public key */
static fromWebCrypto(publicKey: CryptoKey): Promise<PublicKey>;
/** Export public key as EOSIO-format public key */

@@ -19,2 +21,4 @@ toString(): string;

toElliptic(): EC.KeyPair;
/** Export public key as `CryptoKey`-format public key */
toWebCrypto(extractable?: boolean): Promise<CryptoKey>;
/** Get key type from key */

@@ -21,0 +25,0 @@ getType(): KeyType;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicKey = void 0;
var elliptic_1 = require("elliptic");
var eosjs_numeric_1 = require("./eosjs-numeric");
var eosjs_key_conversions_1 = require("./eosjs-key-conversions");
var crypto = (typeof (window) !== 'undefined' ? window.crypto : require('crypto').webcrypto);
/** Represents/stores a public key and provides easy conversion for use with `elliptic` lib */

@@ -14,5 +51,10 @@ var PublicKey = /** @class */ (function () {

PublicKey.fromString = function (publicKeyStr, ec) {
var key = eosjs_numeric_1.stringToPublicKey(publicKeyStr);
var key = (0, eosjs_numeric_1.stringToPublicKey)(publicKeyStr);
if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(key.type);
if (key.type === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -26,3 +68,8 @@ return new PublicKey(key, ec);

if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(keyType);
if (keyType === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -34,9 +81,32 @@ return new PublicKey({

};
/** Instantiate public key from a `CryptoKey`-format public key */
PublicKey.fromWebCrypto = function (publicKey) {
return __awaiter(this, void 0, void 0, function () {
var ec, extractedArrayBuffer, extractedDecoded, derHex, publicKeyHex, publicKeyEc;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (publicKey.extractable === false) {
throw new Error('Crypto Key is not extractable');
}
ec = new elliptic_1.ec('p256');
return [4 /*yield*/, crypto.subtle.exportKey('spki', publicKey)];
case 1:
extractedArrayBuffer = _a.sent();
extractedDecoded = (0, eosjs_numeric_1.arrayToString)(extractedArrayBuffer);
derHex = Buffer.from(extractedDecoded, 'binary').toString('hex');
publicKeyHex = derHex.replace('3059301306072a8648ce3d020106082a8648ce3d030107034200', '');
publicKeyEc = ec.keyFromPublic(publicKeyHex, 'hex');
return [2 /*return*/, PublicKey.fromElliptic(publicKeyEc, eosjs_numeric_1.KeyType.r1, ec)];
}
});
});
};
/** Export public key as EOSIO-format public key */
PublicKey.prototype.toString = function () {
return eosjs_numeric_1.publicKeyToString(this.key);
return (0, eosjs_numeric_1.publicKeyToString)(this.key);
};
/** Export public key as Legacy EOSIO-format public key */
PublicKey.prototype.toLegacyString = function () {
return eosjs_numeric_1.publicKeyToLegacyString(this.key);
return (0, eosjs_numeric_1.publicKeyToLegacyString)(this.key);
};

@@ -49,2 +119,24 @@ /** Export public key as `elliptic`-format public key */

};
/** Export public key as `CryptoKey`-format public key */
PublicKey.prototype.toWebCrypto = function (extractable) {
if (extractable === void 0) { extractable = false; }
return __awaiter(this, void 0, void 0, function () {
var publicKeyEc, publicKeyHex, derHex, derBase64, spkiArrayBuffer;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
publicKeyEc = this.toElliptic();
publicKeyHex = publicKeyEc.getPublic('hex');
derHex = "3059301306072a8648ce3d020106082a8648ce3d030107034200" + publicKeyHex;
derBase64 = Buffer.from(derHex, 'hex').toString('binary');
spkiArrayBuffer = (0, eosjs_numeric_1.stringToArray)(derBase64);
return [4 /*yield*/, crypto.subtle.importKey('spki', spkiArrayBuffer, {
name: 'ECDSA',
namedCurve: 'P-256'
}, extractable, ['verify'])];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
/** Get key type from key */

@@ -51,0 +143,0 @@ PublicKey.prototype.getType = function () {

/// <reference types="node" />
import { BNInput, ec as EC } from 'elliptic';
import BN = require('bn.js');
import { Key, KeyType } from './eosjs-numeric';
import { PublicKey } from './eosjs-key-conversions';
import { PublicKey } from './PublicKey';
declare type WebCryptoSignatureData = Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer;
/** Represents/stores a Signature and provides easy conversion for use with `elliptic` lib */

@@ -13,3 +15,11 @@ export declare class Signature {

/** Instantiate Signature from an `elliptic`-format Signature */
static fromElliptic(ellipticSig: EC.Signature, keyType: KeyType, ec?: EC): Signature;
static fromElliptic(ellipticSig: EC.Signature | {
r: BN;
s: BN;
recoveryParam: number | null;
}, keyType: KeyType, ec?: EC): Signature;
/** Instantiate Signature from a Web Crypto Signature */
static fromWebCrypto(data: WebCryptoSignatureData, webCryptoSig: ArrayBuffer, publicKey: PublicKey): Promise<Signature>;
/** Replaced version of getRecoveryParam from `elliptic` library */
private static getRecoveryParam;
/** Export Signature as `elliptic`-format Signature

@@ -30,4 +40,7 @@ * NOTE: This isn't an actual elliptic-format Signature, as ec.Signature is not exported by the library.

verify(data: BNInput, publicKey: PublicKey, shouldHash?: boolean, encoding?: BufferEncoding): boolean;
/** Verify a Web Crypto signature with data (that matches types) and public key */
webCryptoVerify(data: WebCryptoSignatureData, webCryptoSig: ArrayBuffer, publicKey: PublicKey): Promise<boolean>;
/** Recover a public key from a message or hashed message digest and signature */
recover(data: BNInput, shouldHash?: boolean, encoding?: BufferEncoding): PublicKey;
}
export {};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Signature = void 0;
var elliptic_1 = require("elliptic");
var BN = require("bn.js");
var eosjs_numeric_1 = require("./eosjs-numeric");
var eosjs_key_conversions_1 = require("./eosjs-key-conversions");
var PublicKey_1 = require("./PublicKey");
var crypto = (typeof (window) !== 'undefined' ? window.crypto : require('crypto').webcrypto);
/** Represents/stores a Signature and provides easy conversion for use with `elliptic` lib */

@@ -15,5 +53,10 @@ var Signature = /** @class */ (function () {

Signature.fromString = function (sig, ec) {
var signature = eosjs_numeric_1.stringToSignature(sig);
var signature = (0, eosjs_numeric_1.stringToSignature)(sig);
if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(signature.type);
if (signature.type === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -38,3 +81,8 @@ return new Signature(signature, ec);

if (!ec) {
ec = eosjs_key_conversions_1.constructElliptic(keyType);
if (keyType === eosjs_numeric_1.KeyType.k1) {
ec = new elliptic_1.ec('secp256k1');
}
else {
ec = new elliptic_1.ec('p256');
}
}

@@ -46,2 +94,25 @@ return new Signature({

};
/** Instantiate Signature from a Web Crypto Signature */
Signature.fromWebCrypto = function (data, webCryptoSig, publicKey) {
return __awaiter(this, void 0, void 0, function () {
var ec, hash, r, s, halforder, recoveryParam;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
ec = new elliptic_1.ec('p256');
return [4 /*yield*/, crypto.subtle.digest('SHA-256', data)];
case 1:
hash = _a.sent();
r = new BN(new Uint8Array(webCryptoSig.slice(0, 32)), 32);
s = new BN(new Uint8Array(webCryptoSig.slice(32)), 32);
halforder = ec.curve.n.ushrn(1);
if (s.ucmp(halforder) === 1) {
s = ec.curve.n.sub(s);
}
recoveryParam = this.getRecoveryParam(Buffer.from(hash), { r: r, s: s }, publicKey.toString(), ec);
return [2 /*return*/, Signature.fromElliptic({ r: r, s: s, recoveryParam: recoveryParam }, eosjs_numeric_1.KeyType.r1, ec)];
}
});
});
};
/** Export Signature as `elliptic`-format Signature

@@ -73,3 +144,3 @@ * NOTE: This isn't an actual elliptic-format Signature, as ec.Signature is not exported by the library.

Signature.prototype.toString = function () {
return eosjs_numeric_1.signatureToString(this.signature);
return (0, eosjs_numeric_1.signatureToString)(this.signature);
};

@@ -98,2 +169,22 @@ /** Export Signature in binary format */

};
/** Verify a Web Crypto signature with data (that matches types) and public key */
Signature.prototype.webCryptoVerify = function (data, webCryptoSig, publicKey) {
return __awaiter(this, void 0, void 0, function () {
var webCryptoPub;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, publicKey.toWebCrypto()];
case 1:
webCryptoPub = _a.sent();
return [4 /*yield*/, crypto.subtle.verify({
name: 'ECDSA',
hash: {
name: 'SHA-256'
}
}, webCryptoPub, webCryptoSig, data)];
case 2: return [2 /*return*/, _a.sent()];
}
});
});
};
/** Recover a public key from a message or hashed message digest and signature */

@@ -112,4 +203,21 @@ Signature.prototype.recover = function (data, shouldHash, encoding) {

var ellipticKPub = this.ec.keyFromPublic(recoveredPublicKey);
return eosjs_key_conversions_1.PublicKey.fromElliptic(ellipticKPub, this.getType(), this.ec);
return PublicKey_1.PublicKey.fromElliptic(ellipticKPub, this.getType(), this.ec);
};
/** Replaced version of getRecoveryParam from `elliptic` library */
Signature.getRecoveryParam = function (digest, signature, publicKey, ec) {
var recoveredKey;
for (var i = 0; i < 4; i++) {
try {
var keyPair = ec.recoverPubKey(digest, signature, i);
recoveredKey = PublicKey_1.PublicKey.fromElliptic(ec.keyFromPublic(keyPair), eosjs_numeric_1.KeyType.r1, ec).toString();
}
catch (e) {
continue;
}
if (recoveredKey === publicKey) {
return i;
}
}
throw new Error('Unable to find valid recovery factor');
};
return Signature;

@@ -116,0 +224,0 @@ }());

{
"name": "eosjs",
"version": "22.2.0-81-d6097c6",
"version": "22.2.0-82-22a1a05",
"description": "Talk to eos API",

@@ -40,5 +40,7 @@ "main": "dist/index.js",

"@types/jest": "^26.0.24",
"@types/node": "^14.17.11",
"@types/node": "^14.17.15",
"@types/node-fetch": "^2.5.12",
"@types/pako": "^1.0.2",
"atob": "^2.1.2",
"btoa": "^1.2.1",
"buffer": "^6.0.3",

@@ -56,4 +58,4 @@ "clean-webpack-plugin": "^3.0.0",

"ts-loader": "^9.2.5",
"typescript": "^4.3.5",
"webpack": "^5.51.1",
"typescript": "^4.4.2",
"webpack": "^5.52.0",
"webpack-cli": "^4.8.0"

@@ -60,0 +62,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc