Skip to content

Commit

Permalink
Merge branch 'v5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 18, 2022
2 parents 7b134bd + 83891f9 commit eb91d70
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 67 deletions.
18 changes: 9 additions & 9 deletions packages/bignumber/src.ts/bignumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class BigNumber implements Hexable {
div(other: BigNumberish): BigNumber {
const o = BigNumber.from(other);
if (o.isZero()) {
throwFault("division by zero", "div");
throwFault("division-by-zero", "div");
}
return toBigNumber(toBN(this).div(toBN(other)));
}
Expand All @@ -95,60 +95,60 @@ export class BigNumber implements Hexable {
mod(other: BigNumberish): BigNumber {
const value = toBN(other);
if (value.isNeg()) {
throwFault("cannot modulo negative values", "mod");
throwFault("division-by-zero", "mod");
}
return toBigNumber(toBN(this).umod(value));
}

pow(other: BigNumberish): BigNumber {
const value = toBN(other);
if (value.isNeg()) {
throwFault("cannot raise to negative values", "pow");
throwFault("negative-power", "pow");
}
return toBigNumber(toBN(this).pow(value));
}

and(other: BigNumberish): BigNumber {
const value = toBN(other);
if (this.isNegative() || value.isNeg()) {
throwFault("cannot 'and' negative values", "and");
throwFault("unbound-bitwise-result", "and");
}
return toBigNumber(toBN(this).and(value));
}

or(other: BigNumberish): BigNumber {
const value = toBN(other);
if (this.isNegative() || value.isNeg()) {
throwFault("cannot 'or' negative values", "or");
throwFault("unbound-bitwise-result", "or");
}
return toBigNumber(toBN(this).or(value));
}

xor(other: BigNumberish): BigNumber {
const value = toBN(other);
if (this.isNegative() || value.isNeg()) {
throwFault("cannot 'xor' negative values", "xor");
throwFault("unbound-bitwise-result", "xor");
}
return toBigNumber(toBN(this).xor(value));
}

mask(value: number): BigNumber {
if (this.isNegative() || value < 0) {
throwFault("cannot mask negative values", "mask");
throwFault("negative-width", "mask");
}
return toBigNumber(toBN(this).maskn(value));
}

shl(value: number): BigNumber {
if (this.isNegative() || value < 0) {
throwFault("cannot shift negative values", "shl");
throwFault("negative-width", "shl");
}
return toBigNumber(toBN(this).shln(value));
}

shr(value: number): BigNumber {
if (this.isNegative() || value < 0) {
throwFault("cannot shift negative values", "shr");
throwFault("negative-width", "shr");
}
return toBigNumber(toBN(this).shrn(value));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/ethers/src.ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getAddress, getCreate2Address, getContractAddress, getIcapAddress, isAd
import * as base64 from "@ethersproject/base64";
import { Base58 as base58 } from "@ethersproject/basex";
import { arrayify, concat, hexConcat, hexDataSlice, hexDataLength, hexlify, hexStripZeros, hexValue, hexZeroPad, isBytes, isBytesLike, isHexString, joinSignature, zeroPad, splitSignature, stripZeros } from "@ethersproject/bytes";
import { _TypedDataEncoder, hashMessage, id, isValidName, namehash } from "@ethersproject/hash";
import { _TypedDataEncoder, dnsEncode, hashMessage, id, isValidName, namehash } from "@ethersproject/hash";
import { defaultPath, entropyToMnemonic, getAccountPath, HDNode, isValidMnemonic, mnemonicToEntropy, mnemonicToSeed } from "@ethersproject/hdnode";
import { getJsonWalletAddress } from "@ethersproject/json-wallets";
import { keccak256 } from "@ethersproject/keccak256";
Expand Down Expand Up @@ -114,6 +114,7 @@ export {
formatBytes32String,
parseBytes32String,

dnsEncode,
hashMessage,
namehash,
isValidName,
Expand Down
3 changes: 2 additions & 1 deletion packages/hash/src.ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use strict";

import { id } from "./id";
import { isValidName, namehash } from "./namehash";
import { dnsEncode, isValidName, namehash } from "./namehash";
import { hashMessage, messagePrefix } from "./message";

import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data";

export {
id,

dnsEncode,
namehash,
isValidName,

Expand Down
9 changes: 9 additions & 0 deletions packages/hash/src.ts/namehash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export function namehash(name: string): string {
return hexlify(result);
}

export function dnsEncode(name: string): string {
return hexlify(concat(name.split(".").map((comp) => {
// We jam in an _ prefix to fill in with the length later
// Note: Nameprep throws if the component is over 63 bytes
const bytes = toUtf8Bytes("_" + nameprep(comp));
bytes[0] = bytes.length - 1;
return bytes;
}))) + "00";
}
39 changes: 39 additions & 0 deletions packages/logger/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,45 @@ export class Logger {
messageDetails.push(`version=${ this.version }`);

const reason = message;

let url = "";

switch (code) {
case ErrorCode.NUMERIC_FAULT: {
url = "NUMERIC_FAULT";
const fault = message;

switch (fault) {
case "overflow": case "underflow":
url += "-" + fault;
break;
case "division-by-zero": case "negative-modulo":
url += "-undefined";
break;
case "negative-power": case "negative-width":
url += "-unsupported";
break;
case "unbound-bitwise-result":
url += "-unbound-result";
break;
}
break;
}
case ErrorCode.CALL_EXCEPTION:
case ErrorCode.INSUFFICIENT_FUNDS:
case ErrorCode.MISSING_NEW:
case ErrorCode.NONCE_EXPIRED:
case ErrorCode.REPLACEMENT_UNDERPRICED:
case ErrorCode.TRANSACTION_REPLACED:
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
url = code;
break;
}

if (url) {
message += " [ See: https:/\/ethers.org/errors/" + url + " ]";
}

if (messageDetails.length) {
message += " (" + messageDetails.join(", ") + ")";
}
Expand Down
Loading

0 comments on commit eb91d70

Please sign in to comment.