@ethersproject/signing-key
Advanced tools
Comparing version 5.6.0 to 6.0.0-beta.1
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
50755
28
770
3
1
0
1
+ Added@noble/secp256k1@1.5.5
+ Added@ethersproject/bytes@6.0.0-beta.3(transitive)
+ Added@ethersproject/crypto@6.0.0-beta.2(transitive)
+ Added@ethersproject/logger@6.0.0-beta.7(transitive)
+ Added@ethersproject/math@6.0.0-beta.3(transitive)
+ Added@ethersproject/properties@6.0.0-beta.6(transitive)
+ Added@noble/hashes@1.0.0(transitive)
+ Added@noble/secp256k1@1.5.5(transitive)
- Removedbn.js@^4.11.9
- Removedelliptic@6.5.4
- Removedhash.js@1.1.7
- Removed@ethersproject/bytes@5.7.0(transitive)
- Removed@ethersproject/logger@5.7.0(transitive)
- Removed@ethersproject/properties@5.7.0(transitive)
- Removedbn.js@4.12.0(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedelliptic@6.5.4(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)