How to use @ethersproject/basex - 9 common examples

To help you get started, we’ve selected a few @ethersproject/basex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethers-io / ethers.js / packages / hdnode / src.ts / index.ts View on Github external
static fromExtendedKey(extendedKey: string): HDNode {
        const bytes = Base58.decode(extendedKey);

        if (bytes.length !== 82 || base58check(bytes.slice(0, 78)) !== extendedKey) {
            logger.throwArgumentError("invalid extended key", "extendedKey", "[REDACTED]");
        }

        const depth = bytes[4];
        const parentFingerprint = hexlify(bytes.slice(5, 9));
        const index = parseInt(hexlify(bytes.slice(9, 13)).substring(2), 16);
        const chainCode = hexlify(bytes.slice(13, 45));
        const key = bytes.slice(45, 78);

        switch (hexlify(bytes.slice(0, 4))) {
            // Public Key
            case "0x0488b21e": case "0x043587cf":
                return new HDNode(_constructorGuard, null, hexlify(key), parentFingerprint, chainCode, index, depth, null, null);
github ethers-io / ethers.js / packages / hdnode / lib.esm / index.js View on Github external
static fromExtendedKey(extendedKey) {
        const bytes = Base58.decode(extendedKey);
        if (bytes.length !== 82 || base58check(bytes.slice(0, 78)) !== extendedKey) {
            logger.throwArgumentError("invalid extended key", "extendedKey", "[REDACTED]");
        }
        const depth = bytes[4];
        const parentFingerprint = hexlify(bytes.slice(5, 9));
        const index = parseInt(hexlify(bytes.slice(9, 13)).substring(2), 16);
        const chainCode = hexlify(bytes.slice(13, 45));
        const key = bytes.slice(45, 78);
        switch (hexlify(bytes.slice(0, 4))) {
            // Public Key
            case "0x0488b21e":
            case "0x043587cf":
                return new HDNode(_constructorGuard, null, hexlify(key), parentFingerprint, chainCode, index, depth, null, null);
            // Private Key
            case "0x0488ade4":
            case "0x04358394 ":
github ethers-io / ethers.js / packages / hdnode / lib.esm / index.js View on Github external
function base58check(data) {
    return Base58.encode(concat([data, hexDataSlice(sha256(sha256(data)), 0, 4)]));
}
const _constructorGuard = {};
github ethers-io / ethers.js / packages / cli / lib.esm / bin / ethers-ens.js View on Github external
let content = yield resolver.contenthash(nodehash).then((hash) => {
                        if (hash === "0x") {
                            return "";
                        }
                        if (hash.substring(0, 10) === "0xe3010170" && ethers.utils.isHexString(hash, 38)) {
                            return Base58.encode(ethers.utils.hexDataSlice(hash, 4)) + " (IPFS)";
                        }
                        return hash + " (unknown format)";
                    }, (error) => (""));
                    if (content) {
github ethers-io / ethers.js / packages / hdnode / src.ts / index.ts View on Github external
function base58check(data: Uint8Array): string {
    return Base58.encode(concat([ data, hexDataSlice(sha256(sha256(data)), 0, 4) ]));
}
github ethers-io / ethers.js / packages / hdnode / lib / index.js View on Github external
function base58check(data) {
    return basex_1.Base58.encode(bytes_1.concat([data, bytes_1.hexDataSlice(sha2_1.sha256(sha2_1.sha256(data)), 0, 4)]));
}
var _constructorGuard = {};
github ethers-io / ethers.js / packages / cli / lib / bin / ethers-ens.js View on Github external
return [4 /*yield*/, resolver.contenthash(nodehash).then(function (hash) {
                                                if (hash === "0x") {
                                                    return "";
                                                }
                                                if (hash.substring(0, 10) === "0xe3010170" && ethers_1.ethers.utils.isHexString(hash, 38)) {
                                                    return basex_1.Base58.encode(ethers_1.ethers.utils.hexDataSlice(hash, 4)) + " (IPFS)";
                                                }
                                                return hash + " (unknown format)";
                                            }, function (error) { return (""); })];
                                    case 15:
github ethers-io / ethers.js / packages / cli / lib / bin / ethers-ens.js View on Github external
return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!(key === "hash")) return [3 /*break*/, 2];
                        bytes = basex_1.Base58.decode(value);
                        if (bytes.length !== 34 || bytes[0] !== 18 || bytes[1] !== 32) {
                            this.throwError("Unsupported IPFS hash");
                        }
                        multihash = ethers_1.ethers.utils.concat(["0xe3010170", bytes]);
                        return [4 /*yield*/, _super.prototype._setValue.call(this, "multihash", ethers_1.ethers.utils.hexlify(multihash))];
                    case 1:
                        _a.sent();
                        _a.label = 2;
                    case 2: return [4 /*yield*/, _super.prototype._setValue.call(this, key, value)];
                    case 3:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
github ethers-io / ethers.js / packages / cli / lib.esm / bin / ethers-ens.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            if (key === "hash") {
                let bytes = Base58.decode(value);
                if (bytes.length !== 34 || bytes[0] !== 18 || bytes[1] !== 32) {
                    this.throwError("Unsupported IPFS hash");
                }
                let multihash = ethers.utils.concat(["0xe3010170", bytes]);
                yield _super._setValue.call(this, "multihash", ethers.utils.hexlify(multihash));
            }
            yield _super._setValue.call(this, key, value);
        });
    }

@ethersproject/basex

Base-X without Buffer.

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis