ethereumjs-util#ECDSASignature TypeScript Examples

The following examples show how to use ethereumjs-util#ECDSASignature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: is-signer.ts    From ethereum-sdk with MIT License 6 votes vote down vote up
function fromRpcSig(buf: Buffer): ECDSASignature {
	let r: Buffer
	let s: Buffer
	let v: number
	if (buf.length >= 65) {
		r = buf.slice(0, 32)
		s = buf.slice(32, 64)
		v = bufferToInt(buf.slice(64))
	} else if (buf.length === 64) {
		// Compact Signature Representation (https://eips.ethereum.org/EIPS/eip-2098)
		r = buf.slice(0, 32)
		s = buf.slice(32, 64)
		v = bufferToInt(buf.slice(32, 33)) >> 7
		s[0] &= 0x7f
	} else {
		throw new Error("Invalid signature length")
	}

	// support both versions of `eth_sign` responses
	if (v < 27) {
		v += 27
	}

	return {
		v,
		r,
		s,
	}
}