Skip to content

Commit

Permalink
Refactor some enum names and add UTF-8 error support to the umbrella …
Browse files Browse the repository at this point in the history
…package.
  • Loading branch information
ricmoo committed Jan 21, 2020
1 parent 5878b54 commit 931da2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 10 additions & 5 deletions packages/ethers/src.ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { randomBytes } from "@ethersproject/random";
import { checkProperties, deepCopy, defineReadOnly, getStatic, resolveProperties, shallowCopy } from "@ethersproject/properties";
import * as RLP from "@ethersproject/rlp";
import { computePublicKey, recoverPublicKey, SigningKey } from "@ethersproject/signing-key";
import { formatBytes32String, nameprep, parseBytes32String, _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String } from "@ethersproject/strings";
import { formatBytes32String, nameprep, parseBytes32String, _toEscapedUtf8String, toUtf8Bytes, toUtf8CodePoints, toUtf8String, Utf8ErrorFuncs } from "@ethersproject/strings";
import { computeAddress, parse as parseTransaction, recoverAddress, serialize as serializeTransaction } from "@ethersproject/transactions";
import { commify, formatEther, parseEther, formatUnits, parseUnits } from "@ethersproject/units";
import { verifyMessage } from "@ethersproject/wallet";
Expand All @@ -24,8 +24,8 @@ import { fetchJson, poll } from "@ethersproject/web";
////////////////////////
// Enums

import { SupportedAlgorithms } from "@ethersproject/sha2";
import { UnicodeNormalizationForm } from "@ethersproject/strings";
import { SupportedAlgorithm } from "@ethersproject/sha2";
import { UnicodeNormalizationForm, Utf8ErrorReason } from "@ethersproject/strings";


////////////////////////
Expand All @@ -35,6 +35,7 @@ import { CoerceFunc } from "@ethersproject/abi";
import { Bytes, BytesLike, Hexable } from "@ethersproject/bytes"
import { Mnemonic } from "@ethersproject/hdnode";
import { EncryptOptions, ProgressCallback } from "@ethersproject/json-wallets";
import { Utf8ErrorFunc } from "@ethersproject/strings";
import { ConnectionInfo, FetchJsonResponse, OnceBlockable, PollOptions } from "@ethersproject/web";

////////////////////////
Expand Down Expand Up @@ -91,6 +92,7 @@ export {
toUtf8Bytes,
toUtf8CodePoints,
toUtf8String,
Utf8ErrorFuncs,

formatBytes32String,
parseBytes32String,
Expand Down Expand Up @@ -148,9 +150,10 @@ export {
////////////////////////
// Enums

SupportedAlgorithms,
UnicodeNormalizationForm,
SupportedAlgorithm,

UnicodeNormalizationForm,
Utf8ErrorReason,

////////////////////////
// Types
Expand All @@ -165,6 +168,8 @@ export {

Mnemonic,

Utf8ErrorFunc,

ConnectionInfo,
OnceBlockable,
PollOptions,
Expand Down
6 changes: 3 additions & 3 deletions packages/sha2/src.ts/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);

export enum SupportedAlgorithms { sha256 = "sha256", sha512 = "sha512" };
export enum SupportedAlgorithm { sha256 = "sha256", sha512 = "sha512" };

export function ripemd160(data: BytesLike): string {
return "0x" + (hash.ripemd160().update(arrayify(data)).digest("hex"));
Expand All @@ -23,8 +23,8 @@ export function sha512(data: BytesLike): string {
}


export function computeHmac(algorithm: SupportedAlgorithms, key: BytesLike, data: BytesLike): string {
if (!SupportedAlgorithms[algorithm]) {
export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string {
if (!SupportedAlgorithm[algorithm]) {
logger.throwError("unsupported algorithm " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "hmac",
algorithm: algorithm
Expand Down
6 changes: 3 additions & 3 deletions packages/sha2/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);

export enum SupportedAlgorithms { sha256 = "sha256", sha512 = "sha512" };
export enum SupportedAlgorithm { sha256 = "sha256", sha512 = "sha512" };


export function ripemd160(data: BytesLike): string {
Expand All @@ -24,8 +24,8 @@ export function sha512(data: BytesLike): string {
}


export function computeHmac(algorithm: SupportedAlgorithms, key: BytesLike, data: BytesLike): string {
if (!SupportedAlgorithms[algorithm]) {
export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string {
if (!SupportedAlgorithm[algorithm]) {
logger.throwError("unsupported algorithm - " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "computeHmac",
algorithm: algorithm
Expand Down

0 comments on commit 931da2f

Please sign in to comment.