Socket
Socket
Sign inDemoInstall

@ethersproject/signing-key

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/signing-key - npm Package Compare versions

Comparing version 5.6.0 to 6.0.0-beta.1

lib/logger.d.ts

2

lib/_version.d.ts

@@ -1,2 +0,2 @@

export declare const version = "signing-key/5.6.0";
export declare const version = "@ethersproject/signing-key@6.0.0-beta.1";
//# sourceMappingURL=_version.d.ts.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = void 0;
exports.version = "signing-key/5.6.0";
export const version = "@ethersproject/signing-key@6.0.0-beta.1";
//# sourceMappingURL=_version.js.map

@@ -1,16 +0,4 @@

import { BytesLike, Signature, SignatureLike } from "@ethersproject/bytes";
export declare class SigningKey {
readonly curve: string;
readonly privateKey: string;
readonly publicKey: string;
readonly compressedPublicKey: string;
readonly _isSigningKey: boolean;
constructor(privateKey: BytesLike);
_addPoint(other: BytesLike): string;
signDigest(digest: BytesLike): Signature;
computeSharedSecret(otherKey: BytesLike): string;
static isSigningKey(value: any): value is SigningKey;
}
export declare function recoverPublicKey(digest: BytesLike, signature: SignatureLike): string;
export declare function computePublicKey(key: BytesLike, compressed?: boolean): string;
export { Signature } from "./signature.js";
export { SigningKey } from "./signing-key.js";
export type { SignatureLike } from "./signature.js";
//# sourceMappingURL=index.d.ts.map

@@ -1,85 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computePublicKey = exports.recoverPublicKey = exports.SigningKey = void 0;
var elliptic_1 = require("./elliptic");
var bytes_1 = require("@ethersproject/bytes");
var properties_1 = require("@ethersproject/properties");
var logger_1 = require("@ethersproject/logger");
var _version_1 = require("./_version");
var logger = new logger_1.Logger(_version_1.version);
var _curve = null;
function getCurve() {
if (!_curve) {
_curve = new elliptic_1.EC("secp256k1");
}
return _curve;
}
var SigningKey = /** @class */ (function () {
function SigningKey(privateKey) {
(0, properties_1.defineReadOnly)(this, "curve", "secp256k1");
(0, properties_1.defineReadOnly)(this, "privateKey", (0, bytes_1.hexlify)(privateKey));
var keyPair = getCurve().keyFromPrivate((0, bytes_1.arrayify)(this.privateKey));
(0, properties_1.defineReadOnly)(this, "publicKey", "0x" + keyPair.getPublic(false, "hex"));
(0, properties_1.defineReadOnly)(this, "compressedPublicKey", "0x" + keyPair.getPublic(true, "hex"));
(0, properties_1.defineReadOnly)(this, "_isSigningKey", true);
}
SigningKey.prototype._addPoint = function (other) {
var p0 = getCurve().keyFromPublic((0, bytes_1.arrayify)(this.publicKey));
var p1 = getCurve().keyFromPublic((0, bytes_1.arrayify)(other));
return "0x" + p0.pub.add(p1.pub).encodeCompressed("hex");
};
SigningKey.prototype.signDigest = function (digest) {
var keyPair = getCurve().keyFromPrivate((0, bytes_1.arrayify)(this.privateKey));
var digestBytes = (0, bytes_1.arrayify)(digest);
if (digestBytes.length !== 32) {
logger.throwArgumentError("bad digest length", "digest", digest);
}
var signature = keyPair.sign(digestBytes, { canonical: true });
return (0, bytes_1.splitSignature)({
recoveryParam: signature.recoveryParam,
r: (0, bytes_1.hexZeroPad)("0x" + signature.r.toString(16), 32),
s: (0, bytes_1.hexZeroPad)("0x" + signature.s.toString(16), 32),
});
};
SigningKey.prototype.computeSharedSecret = function (otherKey) {
var keyPair = getCurve().keyFromPrivate((0, bytes_1.arrayify)(this.privateKey));
var otherKeyPair = getCurve().keyFromPublic((0, bytes_1.arrayify)(computePublicKey(otherKey)));
return (0, bytes_1.hexZeroPad)("0x" + keyPair.derive(otherKeyPair.getPublic()).toString(16), 32);
};
SigningKey.isSigningKey = function (value) {
return !!(value && value._isSigningKey);
};
return SigningKey;
}());
exports.SigningKey = SigningKey;
function recoverPublicKey(digest, signature) {
var sig = (0, bytes_1.splitSignature)(signature);
var rs = { r: (0, bytes_1.arrayify)(sig.r), s: (0, bytes_1.arrayify)(sig.s) };
return "0x" + getCurve().recoverPubKey((0, bytes_1.arrayify)(digest), rs, sig.recoveryParam).encode("hex", false);
}
exports.recoverPublicKey = recoverPublicKey;
function computePublicKey(key, compressed) {
var bytes = (0, bytes_1.arrayify)(key);
if (bytes.length === 32) {
var signingKey = new SigningKey(bytes);
if (compressed) {
return "0x" + getCurve().keyFromPrivate(bytes).getPublic(true, "hex");
}
return signingKey.publicKey;
}
else if (bytes.length === 33) {
if (compressed) {
return (0, bytes_1.hexlify)(bytes);
}
return "0x" + getCurve().keyFromPublic(bytes).getPublic(false, "hex");
}
else if (bytes.length === 65) {
if (!compressed) {
return (0, bytes_1.hexlify)(bytes);
}
return "0x" + getCurve().keyFromPublic(bytes).getPublic(true, "hex");
}
return logger.throwArgumentError("invalid public or private key", "key", "[REDACTED]");
}
exports.computePublicKey = computePublicKey;
export { Signature } from "./signature.js";
export { SigningKey } from "./signing-key.js";
//# sourceMappingURL=index.js.map
MIT License
Copyright (c) 2019 Richard Moore
Copyright (c) 2022 Richard Moore

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"_ethers.alias": {
"elliptic.js": "browser-elliptic.js"
},
"author": "Richard Moore <me@ricmoo.com>",
"dependencies": {
"@ethersproject/bytes": "^5.6.0",
"@ethersproject/logger": "^5.6.0",
"@ethersproject/properties": "^5.6.0",
"bn.js": "^4.11.9",
"elliptic": "6.5.4",
"@ethersproject/bytes": "^6.0.0-beta.1",
"@ethersproject/crypto": "^6.0.0-beta.1",
"@ethersproject/logger": "^6.0.0-beta.1",
"@ethersproject/math": "^6.0.0-beta.1",
"@ethersproject/properties": "^6.0.0-beta.1",
"@noble/secp256k1": "1.5.5"
},
"description": "Elliptic curve library functions for the secp256k1 curve.",
"dummy": {
"hash.js": "1.1.7"
},
"description": "Elliptic curve library functions for the secp256k1 curve.",
"engines": {
"node": ">=12.17.0"
},
"ethereum": "donations.ethers.eth",
"funding": [
{
"type": "individual",
"url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2"
},
{
"type": "individual",
"url": "https://www.buymeacoffee.com/ricmoo"
}
],
"gitHead": "b8cda5dffdcb688e38d7c6a0aec4c7b8b59c1af5",
"gitHead": "77f691b3bc3a6387a5184ec9b1779faab4bcb30d",
"keywords": [

@@ -33,6 +26,6 @@ "Ethereum",

"main": "./lib/index.js",
"module": "./lib.esm/index.js",
"name": "@ethersproject/signing-key",
"publishConfig": {
"access": "public"
"access": "public",
"tag": "beta"
},

@@ -48,5 +41,6 @@ "repository": {

"sideEffects": false,
"tarballHash": "0xd46b04feacaea3dfa9abecbadc9fca733a0f039558f4a86efc68adb7f975eafe",
"tarballHash": "0x1e018e6c270e54aabd3b8ec6bda5d5214afa5db34a1f33456f4a2f1c81f129c9",
"type": "module",
"types": "./lib/index.d.ts",
"version": "5.6.0"
"version": "6.0.0-beta.1"
}

@@ -1,1 +0,1 @@

export const version = "signing-key/5.6.0";
export const version = "@ethersproject/signing-key@6.0.0-beta.1";

@@ -1,103 +0,5 @@

"use strict";
import { EC } from "./elliptic";
export { Signature } from "./signature.js";
export { SigningKey } from "./signing-key.js";
import { arrayify, BytesLike, hexlify, hexZeroPad, Signature, SignatureLike, splitSignature } from "@ethersproject/bytes";
import { defineReadOnly } from "@ethersproject/properties";
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
let _curve: EC = null
function getCurve() {
if (!_curve) {
_curve = new EC("secp256k1");
}
return _curve;
}
export class SigningKey {
readonly curve: string;
readonly privateKey: string;
readonly publicKey: string;
readonly compressedPublicKey: string;
//readonly address: string;
readonly _isSigningKey: boolean;
constructor(privateKey: BytesLike) {
defineReadOnly(this, "curve", "secp256k1");
defineReadOnly(this, "privateKey", hexlify(privateKey));
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
defineReadOnly(this, "publicKey", "0x" + keyPair.getPublic(false, "hex"));
defineReadOnly(this, "compressedPublicKey", "0x" + keyPair.getPublic(true, "hex"));
defineReadOnly(this, "_isSigningKey", true);
}
_addPoint(other: BytesLike): string {
const p0 = getCurve().keyFromPublic(arrayify(this.publicKey));
const p1 = getCurve().keyFromPublic(arrayify(other));
return "0x" + p0.pub.add(p1.pub).encodeCompressed("hex");
}
signDigest(digest: BytesLike): Signature {
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
const digestBytes = arrayify(digest);
if (digestBytes.length !== 32) {
logger.throwArgumentError("bad digest length", "digest", digest);
}
const signature = keyPair.sign(digestBytes, { canonical: true });
return splitSignature({
recoveryParam: signature.recoveryParam,
r: hexZeroPad("0x" + signature.r.toString(16), 32),
s: hexZeroPad("0x" + signature.s.toString(16), 32),
})
}
computeSharedSecret(otherKey: BytesLike): string {
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
const otherKeyPair = getCurve().keyFromPublic(arrayify(computePublicKey(otherKey)));
return hexZeroPad("0x" + keyPair.derive(otherKeyPair.getPublic()).toString(16), 32);
}
static isSigningKey(value: any): value is SigningKey {
return !!(value && value._isSigningKey);
}
}
export function recoverPublicKey(digest: BytesLike, signature: SignatureLike): string {
const sig = splitSignature(signature);
const rs = { r: arrayify(sig.r), s: arrayify(sig.s) };
return "0x" + getCurve().recoverPubKey(arrayify(digest), rs, sig.recoveryParam).encode("hex", false);
}
export function computePublicKey(key: BytesLike, compressed?: boolean): string {
const bytes = arrayify(key);
if (bytes.length === 32) {
const signingKey = new SigningKey(bytes);
if (compressed) {
return "0x" + getCurve().keyFromPrivate(bytes).getPublic(true, "hex");
}
return signingKey.publicKey;
} else if (bytes.length === 33) {
if (compressed) { return hexlify(bytes); }
return "0x" + getCurve().keyFromPublic(bytes).getPublic(false, "hex");
} else if (bytes.length === 65) {
if (!compressed) { return hexlify(bytes); }
return "0x" + getCurve().keyFromPublic(bytes).getPublic(true, "hex");
}
return logger.throwArgumentError("invalid public or private key", "key", "[REDACTED]");
}
export type { SignatureLike } from "./signature.js";

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