ethers-gcp-kms-signer
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,8 @@ | ||
## [1.1.1](https://github.com/openlawteam/ethers-gcp-kms-signer/compare/v1.1.0...v1.1.1) (2021-10-28) | ||
### fix | ||
* recoverPubKey function ([20af9ba](https://github.com/openlawteam/ethers-gcp-kms-signer/commit/20af9ba81d25c1f61bd902d3e23e5f416ae345e9)) | ||
# [1.1.0](https://github.com/openlawteam/ethers-gcp-kms-signer/compare/v1.0.0...v1.1.0) (2021-10-28) | ||
@@ -2,0 +9,0 @@ |
@@ -0,3 +1,12 @@ | ||
/// <reference types="node" /> | ||
import { MessageTypes, SignTypedDataVersion, TypedDataV1, TypedMessage } from "@metamask/eth-sig-util"; | ||
/** | ||
* Recover the public key from the given signature and message hash. | ||
* | ||
* @param messageHash - The hash of the signed message. | ||
* @param signature - The signature. | ||
* @returns The public key of the signer. | ||
*/ | ||
export declare function recoverPublicKey(messageHash: any, signature: any): Buffer; | ||
/** | ||
* Validate that the given value is a valid version string. | ||
@@ -4,0 +13,0 @@ * |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.recoverPublicKey = recoverPublicKey; | ||
exports.recoverTypedSignature = recoverTypedSignature; | ||
@@ -12,7 +13,16 @@ exports.validateVersion = validateVersion; | ||
var _utils = require("@metamask/eth-sig-util/dist/utils"); | ||
var _ethereumjsUtil = require("ethereumjs-util"); | ||
/** | ||
* Recover the public key from the given signature and message hash. | ||
* | ||
* @param messageHash - The hash of the signed message. | ||
* @param signature - The signature. | ||
* @returns The public key of the signer. | ||
*/ | ||
function recoverPublicKey(messageHash, signature) { | ||
const sigParams = (0, _ethereumjsUtil.fromRpcSig)(signature); | ||
return (0, _ethereumjsUtil.ecrecover)(messageHash, sigParams.v, sigParams.r, sigParams.s); | ||
} | ||
/** | ||
* Validate that the given value is a valid version string. | ||
@@ -24,2 +34,4 @@ * | ||
*/ | ||
function validateVersion(version, allowedVersions) { | ||
@@ -66,5 +78,5 @@ if (!Object.keys(_ethSigUtil.SignTypedDataVersion).includes(version)) { | ||
const publicKey = (0, _utils.recoverPublicKey)(messageHash, signature); | ||
const publicKey = recoverPublicKey(messageHash, signature); | ||
const sender = (0, _ethereumjsUtil.publicToAddress)(publicKey); | ||
return (0, _ethereumjsUtil.bufferToHex)(sender); | ||
} |
{ | ||
"name": "ethers-gcp-kms-signer", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "An Ethers.js compatible signer that connects to GCP KMS", | ||
@@ -5,0 +5,0 @@ "main": "dist/signer.js", |
@@ -9,6 +9,17 @@ import { | ||
} from "@metamask/eth-sig-util"; | ||
import { recoverPublicKey } from "@metamask/eth-sig-util/dist/utils"; | ||
import { bufferToHex, publicToAddress } from "ethereumjs-util"; | ||
import { bufferToHex, publicToAddress, fromRpcSig, ecrecover } from "ethereumjs-util"; | ||
/** | ||
* Recover the public key from the given signature and message hash. | ||
* | ||
* @param messageHash - The hash of the signed message. | ||
* @param signature - The signature. | ||
* @returns The public key of the signer. | ||
*/ | ||
export function recoverPublicKey(messageHash, signature) { | ||
const sigParams = fromRpcSig(signature); | ||
return ecrecover(messageHash, sigParams.v, sigParams.r, sigParams.s); | ||
} | ||
/** | ||
* Validate that the given value is a valid version string. | ||
@@ -15,0 +26,0 @@ * |
54658
934