Beta 7 with some repo names changed.
This commit is contained in:
1 parent
0f7b40cca7
commit
963c19493a
3408 files changed
+462217
-15516
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
export const version = "address/5.0.5";
|
||||
//# sourceMappingURL=_version.js.map
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
// We use this for base 36 maths
|
||||
import { BN } from "bn.js";
|
||||
import { arrayify, concat, hexDataLength, hexDataSlice, isHexString, stripZeros } from "@ethersproject/bytes";
|
||||
import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { keccak256 } from "@ethersproject/keccak256";
|
||||
import { encode } from "@ethersproject/rlp";
|
||||
import { Logger } from "@ethersproject/logger";
|
||||
import { version } from "./_version";
|
||||
const logger = new Logger(version);
|
||||
function getChecksumAddress(address) {
|
||||
if (!isHexString(address, 20)) {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
address = address.toLowerCase();
|
||||
const chars = address.substring(2).split("");
|
||||
const expanded = new Uint8Array(40);
|
||||
for (let i = 0; i < 40; i++) {
|
||||
expanded[i] = chars[i].charCodeAt(0);
|
||||
}
|
||||
const hashed = arrayify(keccak256(expanded));
|
||||
for (let i = 0; i < 40; i += 2) {
|
||||
if ((hashed[i >> 1] >> 4) >= 8) {
|
||||
chars[i] = chars[i].toUpperCase();
|
||||
}
|
||||
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
||||
chars[i + 1] = chars[i + 1].toUpperCase();
|
||||
}
|
||||
}
|
||||
return "0x" + chars.join("");
|
||||
}
|
||||
// Shims for environments that are missing some required constants and functions
|
||||
const MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
||||
function log10(x) {
|
||||
if (Math.log10) {
|
||||
return Math.log10(x);
|
||||
}
|
||||
return Math.log(x) / Math.LN10;
|
||||
}
|
||||
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
||||
// Create lookup table
|
||||
const ibanLookup = {};
|
||||
for (let i = 0; i < 10; i++) {
|
||||
ibanLookup[String(i)] = String(i);
|
||||
}
|
||||
for (let i = 0; i < 26; i++) {
|
||||
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
||||
}
|
||||
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
||||
const safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
|
||||
function ibanChecksum(address) {
|
||||
address = address.toUpperCase();
|
||||
address = address.substring(4) + address.substring(0, 2) + "00";
|
||||
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
||||
// Javascript can handle integers safely up to 15 (decimal) digits
|
||||
while (expanded.length >= safeDigits) {
|
||||
let block = expanded.substring(0, safeDigits);
|
||||
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
||||
}
|
||||
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
||||
while (checksum.length < 2) {
|
||||
checksum = "0" + checksum;
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
;
|
||||
export function getAddress(address) {
|
||||
let result = null;
|
||||
if (typeof (address) !== "string") {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
||||
// Missing the 0x prefix
|
||||
if (address.substring(0, 2) !== "0x") {
|
||||
address = "0x" + address;
|
||||
}
|
||||
result = getChecksumAddress(address);
|
||||
// It is a checksummed address with a bad checksum
|
||||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
|
||||
logger.throwArgumentError("bad address checksum", "address", address);
|
||||
}
|
||||
// Maybe ICAP? (we only support direct mode)
|
||||
}
|
||||
else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
||||
// It is an ICAP address with a bad checksum
|
||||
if (address.substring(2, 4) !== ibanChecksum(address)) {
|
||||
logger.throwArgumentError("bad icap checksum", "address", address);
|
||||
}
|
||||
result = (new BN(address.substring(4), 36)).toString(16);
|
||||
while (result.length < 40) {
|
||||
result = "0" + result;
|
||||
}
|
||||
result = getChecksumAddress("0x" + result);
|
||||
}
|
||||
else {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function isAddress(address) {
|
||||
try {
|
||||
getAddress(address);
|
||||
return true;
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
export function getIcapAddress(address) {
|
||||
let base36 = (new BN(getAddress(address).substring(2), 16)).toString(36).toUpperCase();
|
||||
while (base36.length < 30) {
|
||||
base36 = "0" + base36;
|
||||
}
|
||||
return "XE" + ibanChecksum("XE00" + base36) + base36;
|
||||
}
|
||||
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
||||
export function getContractAddress(transaction) {
|
||||
let from = null;
|
||||
try {
|
||||
from = getAddress(transaction.from);
|
||||
}
|
||||
catch (error) {
|
||||
logger.throwArgumentError("missing from address", "transaction", transaction);
|
||||
}
|
||||
const nonce = stripZeros(arrayify(BigNumber.from(transaction.nonce).toHexString()));
|
||||
return getAddress(hexDataSlice(keccak256(encode([from, nonce])), 12));
|
||||
}
|
||||
export function getCreate2Address(from, salt, initCodeHash) {
|
||||
if (hexDataLength(salt) !== 32) {
|
||||
logger.throwArgumentError("salt must be 32 bytes", "salt", salt);
|
||||
}
|
||||
if (hexDataLength(initCodeHash) !== 32) {
|
||||
logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash);
|
||||
}
|
||||
return getAddress(hexDataSlice(keccak256(concat(["0xff", getAddress(from), salt, initCodeHash])), 12));
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = "address/5.0.5";
|
||||
//# sourceMappingURL=_version.js.map
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// We use this for base 36 maths
|
||||
var bn_js_1 = require("bn.js");
|
||||
var bytes_1 = require("@ethersproject/bytes");
|
||||
var bignumber_1 = require("@ethersproject/bignumber");
|
||||
var keccak256_1 = require("@ethersproject/keccak256");
|
||||
var rlp_1 = require("@ethersproject/rlp");
|
||||
var logger_1 = require("@ethersproject/logger");
|
||||
var _version_1 = require("./_version");
|
||||
var logger = new logger_1.Logger(_version_1.version);
|
||||
function getChecksumAddress(address) {
|
||||
if (!bytes_1.isHexString(address, 20)) {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
address = address.toLowerCase();
|
||||
var chars = address.substring(2).split("");
|
||||
var expanded = new Uint8Array(40);
|
||||
for (var i = 0; i < 40; i++) {
|
||||
expanded[i] = chars[i].charCodeAt(0);
|
||||
}
|
||||
var hashed = bytes_1.arrayify(keccak256_1.keccak256(expanded));
|
||||
for (var i = 0; i < 40; i += 2) {
|
||||
if ((hashed[i >> 1] >> 4) >= 8) {
|
||||
chars[i] = chars[i].toUpperCase();
|
||||
}
|
||||
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
||||
chars[i + 1] = chars[i + 1].toUpperCase();
|
||||
}
|
||||
}
|
||||
return "0x" + chars.join("");
|
||||
}
|
||||
// Shims for environments that are missing some required constants and functions
|
||||
var MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
||||
function log10(x) {
|
||||
if (Math.log10) {
|
||||
return Math.log10(x);
|
||||
}
|
||||
return Math.log(x) / Math.LN10;
|
||||
}
|
||||
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
||||
// Create lookup table
|
||||
var ibanLookup = {};
|
||||
for (var i = 0; i < 10; i++) {
|
||||
ibanLookup[String(i)] = String(i);
|
||||
}
|
||||
for (var i = 0; i < 26; i++) {
|
||||
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
||||
}
|
||||
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
||||
var safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
|
||||
function ibanChecksum(address) {
|
||||
address = address.toUpperCase();
|
||||
address = address.substring(4) + address.substring(0, 2) + "00";
|
||||
var expanded = address.split("").map(function (c) { return ibanLookup[c]; }).join("");
|
||||
// Javascript can handle integers safely up to 15 (decimal) digits
|
||||
while (expanded.length >= safeDigits) {
|
||||
var block = expanded.substring(0, safeDigits);
|
||||
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
||||
}
|
||||
var checksum = String(98 - (parseInt(expanded, 10) % 97));
|
||||
while (checksum.length < 2) {
|
||||
checksum = "0" + checksum;
|
||||
}
|
||||
return checksum;
|
||||
}
|
||||
;
|
||||
function getAddress(address) {
|
||||
var result = null;
|
||||
if (typeof (address) !== "string") {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
||||
// Missing the 0x prefix
|
||||
if (address.substring(0, 2) !== "0x") {
|
||||
address = "0x" + address;
|
||||
}
|
||||
result = getChecksumAddress(address);
|
||||
// It is a checksummed address with a bad checksum
|
||||
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
|
||||
logger.throwArgumentError("bad address checksum", "address", address);
|
||||
}
|
||||
// Maybe ICAP? (we only support direct mode)
|
||||
}
|
||||
else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
||||
// It is an ICAP address with a bad checksum
|
||||
if (address.substring(2, 4) !== ibanChecksum(address)) {
|
||||
logger.throwArgumentError("bad icap checksum", "address", address);
|
||||
}
|
||||
result = (new bn_js_1.BN(address.substring(4), 36)).toString(16);
|
||||
while (result.length < 40) {
|
||||
result = "0" + result;
|
||||
}
|
||||
result = getChecksumAddress("0x" + result);
|
||||
}
|
||||
else {
|
||||
logger.throwArgumentError("invalid address", "address", address);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.getAddress = getAddress;
|
||||
function isAddress(address) {
|
||||
try {
|
||||
getAddress(address);
|
||||
return true;
|
||||
}
|
||||
catch (error) { }
|
||||
return false;
|
||||
}
|
||||
exports.isAddress = isAddress;
|
||||
function getIcapAddress(address) {
|
||||
var base36 = (new bn_js_1.BN(getAddress(address).substring(2), 16)).toString(36).toUpperCase();
|
||||
while (base36.length < 30) {
|
||||
base36 = "0" + base36;
|
||||
}
|
||||
return "XE" + ibanChecksum("XE00" + base36) + base36;
|
||||
}
|
||||
exports.getIcapAddress = getIcapAddress;
|
||||
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
||||
function getContractAddress(transaction) {
|
||||
var from = null;
|
||||
try {
|
||||
from = getAddress(transaction.from);
|
||||
}
|
||||
catch (error) {
|
||||
logger.throwArgumentError("missing from address", "transaction", transaction);
|
||||
}
|
||||
var nonce = bytes_1.stripZeros(bytes_1.arrayify(bignumber_1.BigNumber.from(transaction.nonce).toHexString()));
|
||||
return getAddress(bytes_1.hexDataSlice(keccak256_1.keccak256(rlp_1.encode([from, nonce])), 12));
|
||||
}
|
||||
exports.getContractAddress = getContractAddress;
|
||||
function getCreate2Address(from, salt, initCodeHash) {
|
||||
if (bytes_1.hexDataLength(salt) !== 32) {
|
||||
logger.throwArgumentError("salt must be 32 bytes", "salt", salt);
|
||||
}
|
||||
if (bytes_1.hexDataLength(initCodeHash) !== 32) {
|
||||
logger.throwArgumentError("initCodeHash must be 32 bytes", "initCodeHash", initCodeHash);
|
||||
}
|
||||
return getAddress(bytes_1.hexDataSlice(keccak256_1.keccak256(bytes_1.concat(["0xff", getAddress(from), salt, initCodeHash])), 12));
|
||||
}
|
||||
exports.getCreate2Address = getCreate2Address;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "@ethersproject/address@^5.0.4",
|
||||
"_id": "@ethersproject/address@5.0.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-DpkQ6rwk9jTefrRsJzEm6nhRiJd9pvhn1xN0rw5N/jswXG5r7BLk/GVA0mMAVWAsYfvi2xSc5L41FMox43RYEA==",
|
||||
"_location": "/@ethersproject/address",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "@ethersproject/address@^5.0.4",
|
||||
"name": "@ethersproject/address",
|
||||
"escapedName": "@ethersproject%2faddress",
|
||||
"scope": "@ethersproject",
|
||||
"rawSpec": "^5.0.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^5.0.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@ethersproject/abi",
|
||||
"/@ethersproject/hash",
|
||||
"/@ethersproject/transactions"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@ethersproject/address/-/address-5.0.5.tgz",
|
||||
"_shasum": "2caa65f6b7125015395b1b54c985ee0b27059cc7",
|
||||
"_spec": "@ethersproject/address@^5.0.4",
|
||||
"_where": "C:\\Users\\Luis\\source\\repos\\AAMasters\\BackendServers\\node_modules\\@ethersproject\\transactions",
|
||||
"author": {
|
||||
"name": "Richard Moore",
|
||||
"email": "me@ricmoo.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ethers-io/ethers.js/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@ethersproject/bignumber": "^5.0.7",
|
||||
"@ethersproject/bytes": "^5.0.4",
|
||||
"@ethersproject/keccak256": "^5.0.3",
|
||||
"@ethersproject/logger": "^5.0.5",
|
||||
"@ethersproject/rlp": "^5.0.3",
|
||||
"bn.js": "^4.4.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Utilities for handling Ethereum Addresses for ethers.",
|
||||
"ethereum": "donations.ethers.eth",
|
||||
"gitHead": "ffa4a2d0549fe2c606bda3130f4a3f3d788f8dcf",
|
||||
"homepage": "https://github.com/ethers-io/ethers.js#readme",
|
||||
"keywords": [
|
||||
"Ethereum",
|
||||
"ethers"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib.esm/index.js",
|
||||
"name": "@ethersproject/address",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ethers-io/ethers.js.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"tarballHash": "0xd6263c8653bc6784fed703b8a30075630c544e3861f43ed5b49ab56ffb5d4808",
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "5.0.5"
|
||||
}
|
||||
Reference in new issue
Block a user