@ethersproject/bytes
Advanced tools
Comparing version 5.0.0-beta.135 to 5.0.0-beta.136
@@ -1,1 +0,1 @@ | ||
export declare const version = "bytes/5.0.0-beta.135"; | ||
export declare const version = "bytes/5.0.0-beta.136"; |
@@ -1,1 +0,1 @@ | ||
export const version = "bytes/5.0.0-beta.135"; | ||
export const version = "bytes/5.0.0-beta.136"; |
@@ -269,12 +269,17 @@ "use strict"; | ||
} | ||
// Get the r and s | ||
// Get the r, s and v | ||
result.r = hexlify(bytes.slice(0, 32)); | ||
result.s = hexlify(bytes.slice(32, 64)); | ||
// Reduce v to the canonical 27 or 28 | ||
result.v = bytes[64]; | ||
if (result.v !== 27 && result.v !== 28) { | ||
result.v = 27 + (result.v % 2); | ||
// Compute recoveryParam from v | ||
result.recoveryParam = 1 - (result.v % 2); | ||
// Allow a recid to be used as the v | ||
if (result.v < 27) { | ||
if (result.v === 0 || result.v === 1) { | ||
result.v += 27; | ||
} | ||
else { | ||
logger.throwArgumentError("signature invalid v byte", "signature", signature); | ||
} | ||
} | ||
// Compute recoveryParam from v | ||
result.recoveryParam = (result.v - 27); | ||
// Compute _vs from recoveryParam and s | ||
@@ -292,39 +297,18 @@ if (result.recoveryParam) { | ||
result._vs = signature._vs; | ||
// Normalize v into a canonical 27 or 28 | ||
if (result.v != null && !(result.v == 27 || result.v == 28)) { | ||
result.v = 27 + (result.v % 2); | ||
} | ||
// Populate a missing v or recoveryParam if possible | ||
if (result.recoveryParam == null && result.v != null) { | ||
result.recoveryParam = 1 - (result.v % 2); | ||
} | ||
else if (result.recoveryParam != null && result.v == null) { | ||
result.v = 27 + result.recoveryParam; | ||
} | ||
else if (result.recoveryParam != null && result.v != null) { | ||
if (result.v !== 27 + result.recoveryParam) { | ||
logger.throwArgumentError("signature v mismatch recoveryParam", "signature", signature); | ||
} | ||
} | ||
// Make sure r and s are padded properly | ||
if (result.r != null) { | ||
result.r = hexZeroPad(result.r, 32); | ||
} | ||
if (result.s != null) { | ||
result.s = hexZeroPad(result.s, 32); | ||
} | ||
// If the _vs is available, use it to populate missing s, v and recoveryParam | ||
// and verify non-missing s, v and recoveryParam | ||
if (result._vs != null) { | ||
result._vs = hexZeroPad(result._vs, 32); | ||
if (result._vs.length > 66) { | ||
logger.throwArgumentError("signature _vs overflow", "signature", signature); | ||
const vs = zeroPad(arrayify(result._vs), 32); | ||
result._vs = hexlify(vs); | ||
// Set or check the recid | ||
const recoveryParam = ((vs[0] >= 128) ? 1 : 0); | ||
if (result.recoveryParam == null) { | ||
result.recoveryParam = recoveryParam; | ||
} | ||
const vs = arrayify(result._vs); | ||
const recoveryParam = ((vs[0] >= 128) ? 1 : 0); | ||
const v = 27 + result.recoveryParam; | ||
// Use _vs to compute s | ||
else if (result.recoveryParam !== recoveryParam) { | ||
logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature); | ||
} | ||
// Set or check the s | ||
vs[0] &= 0x7f; | ||
const s = hexlify(vs); | ||
// Check _vs aggress with other parameters | ||
if (result.s == null) { | ||
@@ -336,37 +320,53 @@ result.s = s; | ||
} | ||
} | ||
// Use recid and v to populate each other | ||
if (result.recoveryParam == null) { | ||
if (result.v == null) { | ||
result.v = v; | ||
logger.throwArgumentError("signature missing v and recoveryParam", "signature", signature); | ||
} | ||
else if (result.v !== v) { | ||
logger.throwArgumentError("signature v mismatch _vs", "signature", signature); | ||
else { | ||
result.recoveryParam = 1 - (result.v % 2); | ||
} | ||
if (recoveryParam == null) { | ||
result.recoveryParam = recoveryParam; | ||
} | ||
else { | ||
if (result.v == null) { | ||
result.v = 27 + result.recoveryParam; | ||
} | ||
else if (result.recoveryParam !== recoveryParam) { | ||
logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature); | ||
else if (result.recoveryParam !== (1 - (result.v % 2))) { | ||
logger.throwArgumentError("signature recoveryParam mismatch v", "signature", signature); | ||
} | ||
} | ||
// After all populating, both v and recoveryParam are still missing... | ||
if (result.v == null && result.recoveryParam == null) { | ||
logger.throwArgumentError("signature requires at least one of recoveryParam, v or _vs", "signature", signature); | ||
if (result.r == null || !isHexString(result.r)) { | ||
logger.throwArgumentError("signature missing or invalid r", "signature", signature); | ||
} | ||
// Check for canonical v | ||
if (result.v !== 27 && result.v !== 28) { | ||
logger.throwArgumentError("signature v not canonical", "signature", signature); | ||
else { | ||
result.r = hexZeroPad(result.r, 32); | ||
} | ||
// Check that r and s are in range | ||
if (result.r.length > 66 || result.s.length > 66) { | ||
logger.throwArgumentError("signature overflow r or s", "signature", signature); | ||
if (result.s == null || !isHexString(result.s)) { | ||
logger.throwArgumentError("signature missing or invalid s", "signature", signature); | ||
} | ||
if (result._vs == null) { | ||
const vs = arrayify(result.s); | ||
if (vs[0] >= 128) { | ||
logger.throwArgumentError("signature s out of range", "signature", signature); | ||
else { | ||
result.s = hexZeroPad(result.s, 32); | ||
} | ||
const vs = arrayify(result.s); | ||
if (vs[0] >= 128) { | ||
logger.throwArgumentError("signature s out of range", "signature", signature); | ||
} | ||
if (result.recoveryParam) { | ||
vs[0] |= 0x80; | ||
} | ||
const _vs = hexlify(vs); | ||
if (result._vs) { | ||
if (!isHexString(result._vs)) { | ||
logger.throwArgumentError("signature invalid _vs", "signature", signature); | ||
} | ||
if (result.recoveryParam) { | ||
vs[0] |= 0x80; | ||
} | ||
result._vs = hexlify(vs); | ||
result._vs = hexZeroPad(result._vs, 32); | ||
} | ||
// Set or check the _vs | ||
if (result._vs == null) { | ||
result._vs = _vs; | ||
} | ||
else if (result._vs !== _vs) { | ||
logger.throwArgumentError("signature _vs mismatch v and s", "signature", signature); | ||
} | ||
} | ||
@@ -373,0 +373,0 @@ return result; |
@@ -1,1 +0,1 @@ | ||
export declare const version = "bytes/5.0.0-beta.135"; | ||
export declare const version = "bytes/5.0.0-beta.136"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = "bytes/5.0.0-beta.135"; | ||
exports.version = "bytes/5.0.0-beta.136"; |
126
lib/index.js
@@ -284,12 +284,17 @@ "use strict"; | ||
} | ||
// Get the r and s | ||
// Get the r, s and v | ||
result.r = hexlify(bytes.slice(0, 32)); | ||
result.s = hexlify(bytes.slice(32, 64)); | ||
// Reduce v to the canonical 27 or 28 | ||
result.v = bytes[64]; | ||
if (result.v !== 27 && result.v !== 28) { | ||
result.v = 27 + (result.v % 2); | ||
// Compute recoveryParam from v | ||
result.recoveryParam = 1 - (result.v % 2); | ||
// Allow a recid to be used as the v | ||
if (result.v < 27) { | ||
if (result.v === 0 || result.v === 1) { | ||
result.v += 27; | ||
} | ||
else { | ||
logger.throwArgumentError("signature invalid v byte", "signature", signature); | ||
} | ||
} | ||
// Compute recoveryParam from v | ||
result.recoveryParam = (result.v - 27); | ||
// Compute _vs from recoveryParam and s | ||
@@ -307,39 +312,18 @@ if (result.recoveryParam) { | ||
result._vs = signature._vs; | ||
// Normalize v into a canonical 27 or 28 | ||
if (result.v != null && !(result.v == 27 || result.v == 28)) { | ||
result.v = 27 + (result.v % 2); | ||
} | ||
// Populate a missing v or recoveryParam if possible | ||
if (result.recoveryParam == null && result.v != null) { | ||
result.recoveryParam = 1 - (result.v % 2); | ||
} | ||
else if (result.recoveryParam != null && result.v == null) { | ||
result.v = 27 + result.recoveryParam; | ||
} | ||
else if (result.recoveryParam != null && result.v != null) { | ||
if (result.v !== 27 + result.recoveryParam) { | ||
logger.throwArgumentError("signature v mismatch recoveryParam", "signature", signature); | ||
} | ||
} | ||
// Make sure r and s are padded properly | ||
if (result.r != null) { | ||
result.r = hexZeroPad(result.r, 32); | ||
} | ||
if (result.s != null) { | ||
result.s = hexZeroPad(result.s, 32); | ||
} | ||
// If the _vs is available, use it to populate missing s, v and recoveryParam | ||
// and verify non-missing s, v and recoveryParam | ||
if (result._vs != null) { | ||
result._vs = hexZeroPad(result._vs, 32); | ||
if (result._vs.length > 66) { | ||
logger.throwArgumentError("signature _vs overflow", "signature", signature); | ||
var vs_1 = zeroPad(arrayify(result._vs), 32); | ||
result._vs = hexlify(vs_1); | ||
// Set or check the recid | ||
var recoveryParam = ((vs_1[0] >= 128) ? 1 : 0); | ||
if (result.recoveryParam == null) { | ||
result.recoveryParam = recoveryParam; | ||
} | ||
var vs = arrayify(result._vs); | ||
var recoveryParam = ((vs[0] >= 128) ? 1 : 0); | ||
var v = 27 + result.recoveryParam; | ||
// Use _vs to compute s | ||
vs[0] &= 0x7f; | ||
var s = hexlify(vs); | ||
// Check _vs aggress with other parameters | ||
else if (result.recoveryParam !== recoveryParam) { | ||
logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature); | ||
} | ||
// Set or check the s | ||
vs_1[0] &= 0x7f; | ||
var s = hexlify(vs_1); | ||
if (result.s == null) { | ||
@@ -351,37 +335,53 @@ result.s = s; | ||
} | ||
} | ||
// Use recid and v to populate each other | ||
if (result.recoveryParam == null) { | ||
if (result.v == null) { | ||
result.v = v; | ||
logger.throwArgumentError("signature missing v and recoveryParam", "signature", signature); | ||
} | ||
else if (result.v !== v) { | ||
logger.throwArgumentError("signature v mismatch _vs", "signature", signature); | ||
else { | ||
result.recoveryParam = 1 - (result.v % 2); | ||
} | ||
if (recoveryParam == null) { | ||
result.recoveryParam = recoveryParam; | ||
} | ||
else { | ||
if (result.v == null) { | ||
result.v = 27 + result.recoveryParam; | ||
} | ||
else if (result.recoveryParam !== recoveryParam) { | ||
logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature); | ||
else if (result.recoveryParam !== (1 - (result.v % 2))) { | ||
logger.throwArgumentError("signature recoveryParam mismatch v", "signature", signature); | ||
} | ||
} | ||
// After all populating, both v and recoveryParam are still missing... | ||
if (result.v == null && result.recoveryParam == null) { | ||
logger.throwArgumentError("signature requires at least one of recoveryParam, v or _vs", "signature", signature); | ||
if (result.r == null || !isHexString(result.r)) { | ||
logger.throwArgumentError("signature missing or invalid r", "signature", signature); | ||
} | ||
// Check for canonical v | ||
if (result.v !== 27 && result.v !== 28) { | ||
logger.throwArgumentError("signature v not canonical", "signature", signature); | ||
else { | ||
result.r = hexZeroPad(result.r, 32); | ||
} | ||
// Check that r and s are in range | ||
if (result.r.length > 66 || result.s.length > 66) { | ||
logger.throwArgumentError("signature overflow r or s", "signature", signature); | ||
if (result.s == null || !isHexString(result.s)) { | ||
logger.throwArgumentError("signature missing or invalid s", "signature", signature); | ||
} | ||
if (result._vs == null) { | ||
var vs = arrayify(result.s); | ||
if (vs[0] >= 128) { | ||
logger.throwArgumentError("signature s out of range", "signature", signature); | ||
else { | ||
result.s = hexZeroPad(result.s, 32); | ||
} | ||
var vs = arrayify(result.s); | ||
if (vs[0] >= 128) { | ||
logger.throwArgumentError("signature s out of range", "signature", signature); | ||
} | ||
if (result.recoveryParam) { | ||
vs[0] |= 0x80; | ||
} | ||
var _vs = hexlify(vs); | ||
if (result._vs) { | ||
if (!isHexString(result._vs)) { | ||
logger.throwArgumentError("signature invalid _vs", "signature", signature); | ||
} | ||
if (result.recoveryParam) { | ||
vs[0] |= 0x80; | ||
} | ||
result._vs = hexlify(vs); | ||
result._vs = hexZeroPad(result._vs, 32); | ||
} | ||
// Set or check the _vs | ||
if (result._vs == null) { | ||
result._vs = _vs; | ||
} | ||
else if (result._vs !== _vs) { | ||
logger.throwArgumentError("signature _vs mismatch v and s", "signature", signature); | ||
} | ||
} | ||
@@ -388,0 +388,0 @@ return result; |
@@ -28,5 +28,5 @@ { | ||
}, | ||
"tarballHash": "0x921a087d89b180890fffb807f9dccfba9d7b9f166af98dd665e16533fc0e54ef", | ||
"tarballHash": "0xb6ffce56dff4aca505d1e9c305fa32b0c480a7bce7699836efd237c205862f05", | ||
"types": "./lib/index.d.ts", | ||
"version": "5.0.0-beta.135" | ||
"version": "5.0.0-beta.136" | ||
} |
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
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
30550