@ethersproject/hash
Advanced tools
Comparing version 5.6.1 to 5.7.0
@@ -1,2 +0,2 @@ | ||
export declare const version = "hash/5.6.1"; | ||
export declare const version = "hash/5.7.0"; | ||
//# sourceMappingURL=_version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = "hash/5.6.1"; | ||
export const version = "hash/5.7.0"; | ||
//# sourceMappingURL=_version.js.map |
import { id } from "./id"; | ||
import { dnsEncode, isValidName, namehash } from "./namehash"; | ||
import { hashMessage, messagePrefix } from "./message"; | ||
import { ensNormalize } from "./namehash"; | ||
import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data"; | ||
export { id, dnsEncode, namehash, isValidName, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
export { id, dnsEncode, namehash, isValidName, ensNormalize, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,4 +5,5 @@ "use strict"; | ||
import { hashMessage, messagePrefix } from "./message"; | ||
import { ensNormalize } from "./namehash"; | ||
import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data"; | ||
export { id, dnsEncode, namehash, isValidName, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
export { id, dnsEncode, namehash, isValidName, ensNormalize, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
export declare function ensNormalize(name: string): string; | ||
export declare function isValidName(name: string): boolean; | ||
@@ -2,0 +3,0 @@ export declare function namehash(name: string): string; |
import { concat, hexlify } from "@ethersproject/bytes"; | ||
import { nameprep, toUtf8Bytes } from "@ethersproject/strings"; | ||
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings"; | ||
import { keccak256 } from "@ethersproject/keccak256"; | ||
@@ -7,14 +7,39 @@ import { Logger } from "@ethersproject/logger"; | ||
const logger = new Logger(version); | ||
import { ens_normalize } from "./ens-normalize/lib"; | ||
const Zeros = new Uint8Array(32); | ||
Zeros.fill(0); | ||
const Partition = new RegExp("^((.*)\\.)?([^.]+)$"); | ||
function checkComponent(comp) { | ||
if (comp.length === 0) { | ||
throw new Error("invalid ENS name; empty component"); | ||
} | ||
return comp; | ||
} | ||
function ensNameSplit(name) { | ||
const bytes = toUtf8Bytes(ens_normalize(name)); | ||
const comps = []; | ||
if (name.length === 0) { | ||
return comps; | ||
} | ||
let last = 0; | ||
for (let i = 0; i < bytes.length; i++) { | ||
const d = bytes[i]; | ||
// A separator (i.e. "."); copy this component | ||
if (d === 0x2e) { | ||
comps.push(checkComponent(bytes.slice(last, i))); | ||
last = i + 1; | ||
} | ||
} | ||
// There was a stray separator at the end of the name | ||
if (last >= bytes.length) { | ||
throw new Error("invalid ENS name; empty component"); | ||
} | ||
comps.push(checkComponent(bytes.slice(last))); | ||
return comps; | ||
} | ||
export function ensNormalize(name) { | ||
return ensNameSplit(name).map((comp) => toUtf8String(comp)).join("."); | ||
} | ||
export function isValidName(name) { | ||
try { | ||
const comps = name.split("."); | ||
for (let i = 0; i < comps.length; i++) { | ||
if (nameprep(comps[i]).length === 0) { | ||
throw new Error("empty"); | ||
} | ||
} | ||
return true; | ||
return (ensNameSplit(name).length !== 0); | ||
} | ||
@@ -29,12 +54,6 @@ catch (error) { } | ||
} | ||
let current = name; | ||
let result = Zeros; | ||
while (current.length) { | ||
const partition = current.match(Partition); | ||
if (partition == null || partition[2] === "") { | ||
logger.throwArgumentError("invalid ENS address; missing component", "name", name); | ||
} | ||
const label = toUtf8Bytes(nameprep(partition[3])); | ||
result = keccak256(concat([result, keccak256(label)])); | ||
current = partition[2] || ""; | ||
const comps = ensNameSplit(name); | ||
while (comps.length) { | ||
result = keccak256(concat([result, keccak256(comps.pop())])); | ||
} | ||
@@ -44,6 +63,9 @@ return hexlify(result); | ||
export function dnsEncode(name) { | ||
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)); | ||
return hexlify(concat(ensNameSplit(name).map((comp) => { | ||
// DNS does not allow components over 63 bytes in length | ||
if (comp.length > 63) { | ||
throw new Error("invalid DNS encoded entry; length exceeds 63 bytes"); | ||
} | ||
const bytes = new Uint8Array(comp.length + 1); | ||
bytes.set(comp, 1); | ||
bytes[0] = bytes.length - 1; | ||
@@ -50,0 +72,0 @@ return bytes; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "hash/5.6.1"; | ||
export declare const version = "hash/5.7.0"; | ||
//# sourceMappingURL=_version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = "hash/5.6.1"; | ||
exports.version = "hash/5.7.0"; | ||
//# sourceMappingURL=_version.js.map |
import { id } from "./id"; | ||
import { dnsEncode, isValidName, namehash } from "./namehash"; | ||
import { hashMessage, messagePrefix } from "./message"; | ||
import { ensNormalize } from "./namehash"; | ||
import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data"; | ||
export { id, dnsEncode, namehash, isValidName, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
export { id, dnsEncode, namehash, isValidName, ensNormalize, messagePrefix, hashMessage, _TypedDataEncoder, }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._TypedDataEncoder = exports.hashMessage = exports.messagePrefix = exports.isValidName = exports.namehash = exports.dnsEncode = exports.id = void 0; | ||
exports._TypedDataEncoder = exports.hashMessage = exports.messagePrefix = exports.ensNormalize = exports.isValidName = exports.namehash = exports.dnsEncode = exports.id = void 0; | ||
var id_1 = require("./id"); | ||
@@ -13,4 +13,6 @@ Object.defineProperty(exports, "id", { enumerable: true, get: function () { return id_1.id; } }); | ||
Object.defineProperty(exports, "messagePrefix", { enumerable: true, get: function () { return message_1.messagePrefix; } }); | ||
var namehash_2 = require("./namehash"); | ||
Object.defineProperty(exports, "ensNormalize", { enumerable: true, get: function () { return namehash_2.ensNormalize; } }); | ||
var typed_data_1 = require("./typed-data"); | ||
Object.defineProperty(exports, "_TypedDataEncoder", { enumerable: true, get: function () { return typed_data_1.TypedDataEncoder; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
export declare function ensNormalize(name: string): string; | ||
export declare function isValidName(name: string): boolean; | ||
@@ -2,0 +3,0 @@ export declare function namehash(name: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dnsEncode = exports.namehash = exports.isValidName = void 0; | ||
exports.dnsEncode = exports.namehash = exports.isValidName = exports.ensNormalize = void 0; | ||
var bytes_1 = require("@ethersproject/bytes"); | ||
@@ -10,14 +10,40 @@ var strings_1 = require("@ethersproject/strings"); | ||
var logger = new logger_1.Logger(_version_1.version); | ||
var lib_1 = require("./ens-normalize/lib"); | ||
var Zeros = new Uint8Array(32); | ||
Zeros.fill(0); | ||
var Partition = new RegExp("^((.*)\\.)?([^.]+)$"); | ||
function checkComponent(comp) { | ||
if (comp.length === 0) { | ||
throw new Error("invalid ENS name; empty component"); | ||
} | ||
return comp; | ||
} | ||
function ensNameSplit(name) { | ||
var bytes = (0, strings_1.toUtf8Bytes)((0, lib_1.ens_normalize)(name)); | ||
var comps = []; | ||
if (name.length === 0) { | ||
return comps; | ||
} | ||
var last = 0; | ||
for (var i = 0; i < bytes.length; i++) { | ||
var d = bytes[i]; | ||
// A separator (i.e. "."); copy this component | ||
if (d === 0x2e) { | ||
comps.push(checkComponent(bytes.slice(last, i))); | ||
last = i + 1; | ||
} | ||
} | ||
// There was a stray separator at the end of the name | ||
if (last >= bytes.length) { | ||
throw new Error("invalid ENS name; empty component"); | ||
} | ||
comps.push(checkComponent(bytes.slice(last))); | ||
return comps; | ||
} | ||
function ensNormalize(name) { | ||
return ensNameSplit(name).map(function (comp) { return (0, strings_1.toUtf8String)(comp); }).join("."); | ||
} | ||
exports.ensNormalize = ensNormalize; | ||
function isValidName(name) { | ||
try { | ||
var comps = name.split("."); | ||
for (var i = 0; i < comps.length; i++) { | ||
if ((0, strings_1.nameprep)(comps[i]).length === 0) { | ||
throw new Error("empty"); | ||
} | ||
} | ||
return true; | ||
return (ensNameSplit(name).length !== 0); | ||
} | ||
@@ -33,12 +59,6 @@ catch (error) { } | ||
} | ||
var current = name; | ||
var result = Zeros; | ||
while (current.length) { | ||
var partition = current.match(Partition); | ||
if (partition == null || partition[2] === "") { | ||
logger.throwArgumentError("invalid ENS address; missing component", "name", name); | ||
} | ||
var label = (0, strings_1.toUtf8Bytes)((0, strings_1.nameprep)(partition[3])); | ||
result = (0, keccak256_1.keccak256)((0, bytes_1.concat)([result, (0, keccak256_1.keccak256)(label)])); | ||
current = partition[2] || ""; | ||
var comps = ensNameSplit(name); | ||
while (comps.length) { | ||
result = (0, keccak256_1.keccak256)((0, bytes_1.concat)([result, (0, keccak256_1.keccak256)(comps.pop())])); | ||
} | ||
@@ -49,6 +69,9 @@ return (0, bytes_1.hexlify)(result); | ||
function dnsEncode(name) { | ||
return (0, bytes_1.hexlify)((0, bytes_1.concat)(name.split(".").map(function (comp) { | ||
// We jam in an _ prefix to fill in with the length later | ||
// Note: Nameprep throws if the component is over 63 bytes | ||
var bytes = (0, strings_1.toUtf8Bytes)("_" + (0, strings_1.nameprep)(comp)); | ||
return (0, bytes_1.hexlify)((0, bytes_1.concat)(ensNameSplit(name).map(function (comp) { | ||
// DNS does not allow components over 63 bytes in length | ||
if (comp.length > 63) { | ||
throw new Error("invalid DNS encoded entry; length exceeds 63 bytes"); | ||
} | ||
var bytes = new Uint8Array(comp.length + 1); | ||
bytes.set(comp, 1); | ||
bytes[0] = bytes.length - 1; | ||
@@ -55,0 +78,0 @@ return bytes; |
{ | ||
"author": "Richard Moore <me@ricmoo.com>", | ||
"dependencies": { | ||
"@ethersproject/abstract-signer": "^5.6.2", | ||
"@ethersproject/address": "^5.6.1", | ||
"@ethersproject/bignumber": "^5.6.2", | ||
"@ethersproject/bytes": "^5.6.1", | ||
"@ethersproject/keccak256": "^5.6.1", | ||
"@ethersproject/logger": "^5.6.0", | ||
"@ethersproject/properties": "^5.6.0", | ||
"@ethersproject/strings": "^5.6.1" | ||
"@ethersproject/abstract-signer": "^5.7.0", | ||
"@ethersproject/address": "^5.7.0", | ||
"@ethersproject/base64": "^5.7.0", | ||
"@ethersproject/bignumber": "^5.7.0", | ||
"@ethersproject/bytes": "^5.7.0", | ||
"@ethersproject/keccak256": "^5.7.0", | ||
"@ethersproject/logger": "^5.7.0", | ||
"@ethersproject/properties": "^5.7.0", | ||
"@ethersproject/strings": "^5.7.0" | ||
}, | ||
@@ -25,3 +26,3 @@ "description": "Hash utility functions for Ethereum.", | ||
], | ||
"gitHead": "a71f51825571d1ea0fa997c1352d5b4d85643416", | ||
"gitHead": "ec1b9583039a14a0e0fa15d0a2a6082a2f41cf5b", | ||
"keywords": [ | ||
@@ -47,5 +48,5 @@ "Ethereum", | ||
"sideEffects": false, | ||
"tarballHash": "0xa60d14c92fd1cd3653f5db87648049aca52ca8fdbd5e1215775d1492969153bb", | ||
"tarballHash": "0x6e7a2a4f4c5a722640a0904a3f015a410699e60655329f11148be6267b5d4c6c", | ||
"types": "./lib/index.d.ts", | ||
"version": "5.6.1" | ||
"version": "5.7.0" | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = "hash/5.6.1"; | ||
export const version = "hash/5.7.0"; |
@@ -7,2 +7,4 @@ "use strict"; | ||
import { ensNormalize } from "./namehash"; | ||
import { TypedDataEncoder as _TypedDataEncoder } from "./typed-data"; | ||
@@ -17,2 +19,4 @@ | ||
ensNormalize, | ||
messagePrefix, | ||
@@ -19,0 +23,0 @@ hashMessage, |
import { concat, hexlify } from "@ethersproject/bytes"; | ||
import { nameprep, toUtf8Bytes } from "@ethersproject/strings"; | ||
import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings"; | ||
import { keccak256 } from "@ethersproject/keccak256"; | ||
@@ -9,16 +9,43 @@ | ||
import { ens_normalize } from "./ens-normalize/lib"; | ||
const Zeros = new Uint8Array(32); | ||
Zeros.fill(0); | ||
const Partition = new RegExp("^((.*)\\.)?([^.]+)$"); | ||
function checkComponent(comp: Uint8Array): Uint8Array { | ||
if (comp.length === 0) { throw new Error("invalid ENS name; empty component"); } | ||
return comp; | ||
} | ||
function ensNameSplit(name: string): Array<Uint8Array> { | ||
const bytes = toUtf8Bytes(ens_normalize(name)); | ||
const comps: Array<Uint8Array> = [ ]; | ||
if (name.length === 0) { return comps; } | ||
let last = 0; | ||
for (let i = 0; i < bytes.length; i++) { | ||
const d = bytes[i]; | ||
// A separator (i.e. "."); copy this component | ||
if (d === 0x2e) { | ||
comps.push(checkComponent(bytes.slice(last, i))); | ||
last = i + 1; | ||
} | ||
} | ||
// There was a stray separator at the end of the name | ||
if (last >= bytes.length) { throw new Error("invalid ENS name; empty component"); } | ||
comps.push(checkComponent(bytes.slice(last))); | ||
return comps; | ||
} | ||
export function ensNormalize(name: string): string { | ||
return ensNameSplit(name).map((comp) => toUtf8String(comp)).join("."); | ||
} | ||
export function isValidName(name: string): boolean { | ||
try { | ||
const comps = name.split("."); | ||
for (let i = 0; i < comps.length; i++) { | ||
if (nameprep(comps[i]).length === 0) { | ||
throw new Error("empty") | ||
} | ||
} | ||
return true; | ||
return (ensNameSplit(name).length !== 0); | ||
} catch (error) { } | ||
@@ -34,13 +61,7 @@ return false; | ||
let current = name; | ||
let result: string | Uint8Array = Zeros; | ||
while (current.length) { | ||
const partition = current.match(Partition); | ||
if (partition == null || partition[2] === "") { | ||
logger.throwArgumentError("invalid ENS address; missing component", "name", name); | ||
} | ||
const label = toUtf8Bytes(nameprep(partition[3])); | ||
result = keccak256(concat([result, keccak256(label)])); | ||
current = partition[2] || ""; | ||
const comps = ensNameSplit(name); | ||
while (comps.length) { | ||
result = keccak256(concat([result, keccak256(comps.pop())])); | ||
} | ||
@@ -52,9 +73,14 @@ | ||
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)); | ||
return hexlify(concat(ensNameSplit(name).map((comp) => { | ||
// DNS does not allow components over 63 bytes in length | ||
if (comp.length > 63) { | ||
throw new Error("invalid DNS encoded entry; length exceeds 63 bytes"); | ||
} | ||
const bytes = new Uint8Array(comp.length + 1); | ||
bytes.set(comp, 1); | ||
bytes[0] = bytes.length - 1; | ||
return bytes; | ||
}))) + "00"; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
257107
84
3433
9
3
2
+ Added@ethersproject/base64@^5.7.0
Updated@ethersproject/bytes@^5.7.0
Updated@ethersproject/logger@^5.7.0