Socket
Socket
Sign inDemoInstall

@iov/encoding

Package Overview
Dependencies
Maintainers
3
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iov/encoding - npm Package Compare versions

Comparing version 0.16.0-alpha.4 to 0.16.0

build/bech32.js

16

build/encoding.js

@@ -11,3 +11,2 @@ "use strict";

const base64js = __importStar(require("base64-js"));
const bech32 = __importStar(require("bech32"));
const readonly_date_1 = require("readonly-date");

@@ -146,17 +145,2 @@ class Encoding {

exports.Encoding = Encoding;
class Bech32 {
static encode(prefix, data) {
const dataToWords = bech32.toWords(Buffer.from(data));
const encodedData = bech32.encode(prefix, dataToWords);
return encodedData;
}
static decode(address) {
const decodedAddress = bech32.decode(address);
return {
prefix: decodedAddress.prefix,
data: new Uint8Array(bech32.fromWords(decodedAddress.words)),
};
}
}
exports.Bech32 = Bech32;
//# sourceMappingURL=encoding.js.map

@@ -267,16 +267,2 @@ "use strict";

});
describe("Bech32", () => {
// test data generate using https://github.com/nym-zone/bech32
// bech32 -e -h eth 9d4e856e572e442f0a4b2763e72d08a0e99d8ded
const ethAddressRaw = encoding_1.Encoding.fromHex("9d4e856e572e442f0a4b2763e72d08a0e99d8ded");
it("encodes", () => {
expect(encoding_1.Bech32.encode("eth", ethAddressRaw)).toEqual("eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw");
});
it("decodes", () => {
expect(encoding_1.Bech32.decode("eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw")).toEqual({
prefix: "eth",
data: ethAddressRaw,
});
});
});
//# sourceMappingURL=encoding.spec.js.map

8

build/index.js
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./encoding"));
var bech32_1 = require("./bech32");
exports.Bech32 = bech32_1.Bech32;
var encoding_1 = require("./encoding");
exports.Encoding = encoding_1.Encoding;
var integers_1 = require("./integers");

@@ -8,0 +8,0 @@ exports.Int53 = integers_1.Int53;

{
"name": "@iov/encoding",
"version": "0.16.0-alpha.4",
"version": "0.16.0",
"description": "Encoding helpers for IOV projects",

@@ -27,3 +27,4 @@ "author": "IOV SAS <admin@iov.one>",

"move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && shx rm ./types/*.spec.d.ts",
"build": "shx rm -rf ./build && tsc && yarn move-types",
"format-types": "prettier --write --loglevel warn \"./types/**/*.d.ts\"",
"build": "shx rm -rf ./build && tsc && yarn move-types && yarn format-types",
"build-or-skip": "[ -n \"$SKIP_BUILD\" ] || yarn build",

@@ -39,6 +40,5 @@ "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js"

"devDependencies": {
"@types/base64-js": "^1.2.5",
"@types/bech32": "^1.1.1"
"@types/base64-js": "^1.2.5"
},
"gitHead": "a791348b27cbd9dbea14f15c307109fa9f57f70d"
"gitHead": "fbf20f085319a9f11bb685a10d1c4479f05d2d4b"
}

@@ -1,2 +0,2 @@

import { Bech32, Encoding } from "./encoding";
import { Encoding } from "./encoding";

@@ -436,18 +436,1 @@ describe("Encoding", () => {

});
describe("Bech32", () => {
// test data generate using https://github.com/nym-zone/bech32
// bech32 -e -h eth 9d4e856e572e442f0a4b2763e72d08a0e99d8ded
const ethAddressRaw = Encoding.fromHex("9d4e856e572e442f0a4b2763e72d08a0e99d8ded");
it("encodes", () => {
expect(Bech32.encode("eth", ethAddressRaw)).toEqual("eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw");
});
it("decodes", () => {
expect(Bech32.decode("eth1n48g2mjh9ezz7zjtya37wtgg5r5emr0drkwlgw")).toEqual({
prefix: "eth",
data: ethAddressRaw,
});
});
});
import * as base64js from "base64-js";
import * as bech32 from "bech32";
import { ReadonlyDate } from "readonly-date";

@@ -168,17 +167,1 @@

}
export class Bech32 {
public static encode(prefix: string, data: Uint8Array): string {
const dataToWords = bech32.toWords(Buffer.from(data));
const encodedData = bech32.encode(prefix, dataToWords);
return encodedData;
}
public static decode(address: string): { readonly prefix: string; readonly data: Uint8Array } {
const decodedAddress = bech32.decode(address);
return {
prefix: decodedAddress.prefix,
data: new Uint8Array(bech32.fromWords(decodedAddress.words)),
};
}
}

@@ -1,2 +0,3 @@

export * from "./encoding";
export { Bech32 } from "./bech32";
export { Encoding } from "./encoding";
export { Int53, Uint32, Uint53, Uint64 } from "./integers";

@@ -3,0 +4,0 @@ export {

import { ReadonlyDate } from "readonly-date";
export declare class Encoding {
static toHex(data: Uint8Array): string;
static fromHex(hexstring: string): Uint8Array;
static toBase64(data: Uint8Array): string;
static fromBase64(base64String: string): Uint8Array;
static toAscii(input: string): Uint8Array;
static fromAscii(data: Uint8Array): string;
static toUtf8(str: string): Uint8Array;
static fromUtf8(data: Uint8Array): string;
static fromRfc3339(str: string): ReadonlyDate;
static toRfc3339(date: Date | ReadonlyDate): string;
private static isValidUtf8;
static toHex(data: Uint8Array): string;
static fromHex(hexstring: string): Uint8Array;
static toBase64(data: Uint8Array): string;
static fromBase64(base64String: string): Uint8Array;
static toAscii(input: string): Uint8Array;
static fromAscii(data: Uint8Array): string;
static toUtf8(str: string): Uint8Array;
static fromUtf8(data: Uint8Array): string;
static fromRfc3339(str: string): ReadonlyDate;
static toRfc3339(date: Date | ReadonlyDate): string;
private static isValidUtf8;
}
export declare class Bech32 {
static encode(prefix: string, data: Uint8Array): string;
static decode(address: string): {
readonly prefix: string;
readonly data: Uint8Array;
};
}

@@ -1,5 +0,13 @@

export * from "./encoding";
export { Bech32 } from "./bech32";
export { Encoding } from "./encoding";
export { Int53, Uint32, Uint53, Uint64 } from "./integers";
export { JsonCompatibleValue, isJsonCompatibleValue, JsonCompatibleDictionary, isJsonCompatibleDictionary, JsonCompatibleArray, isJsonCompatibleArray, } from "./json";
export {
JsonCompatibleValue,
isJsonCompatibleValue,
JsonCompatibleDictionary,
isJsonCompatibleDictionary,
JsonCompatibleArray,
isJsonCompatibleArray,
} from "./json";
export { TransactionEncoder } from "./transactionencoder";
export { isNonNullObject, isUint8Array } from "./typechecks";
interface Integer {
readonly toNumber: () => number;
readonly toString: () => string;
readonly toNumber: () => number;
readonly toString: () => string;
}
export declare class Uint32 implements Integer {
static fromBigEndianBytes(bytes: ArrayLike<number>): Uint32;
protected readonly data: number;
constructor(input: number);
toBytesBigEndian(): readonly number[];
toNumber(): number;
toString(): string;
static fromBigEndianBytes(bytes: ArrayLike<number>): Uint32;
protected readonly data: number;
constructor(input: number);
toBytesBigEndian(): readonly number[];
toNumber(): number;
toString(): string;
}
export declare class Int53 implements Integer {
static fromString(str: string): Int53;
protected readonly data: number;
constructor(input: number);
toNumber(): number;
toString(): string;
static fromString(str: string): Int53;
protected readonly data: number;
constructor(input: number);
toNumber(): number;
toString(): string;
}
export declare class Uint53 implements Integer {
static fromString(str: string): Uint53;
protected readonly data: Int53;
constructor(input: number);
toNumber(): number;
toString(): string;
static fromString(str: string): Uint53;
protected readonly data: Int53;
constructor(input: number);
toNumber(): number;
toString(): string;
}
export declare class Uint64 implements Integer {
static fromBytesBigEndian(bytes: ArrayLike<number>): Uint64;
static fromString(str: string): Uint64;
static fromNumber(input: number): Uint64;
private readonly data;
private constructor();
toBytesBigEndian(): readonly number[];
toBytesLittleEndian(): readonly number[];
toString(): string;
toNumber(): number;
static fromBytesBigEndian(bytes: ArrayLike<number>): Uint64;
static fromString(str: string): Uint64;
static fromNumber(input: number): Uint64;
private readonly data;
private constructor();
toBytesBigEndian(): readonly number[];
toBytesLittleEndian(): readonly number[];
toString(): string;
toNumber(): number;
}
export {};
/**
* A single JSON value. This is the missing return type of JSON.parse().
*/
export declare type JsonCompatibleValue = JsonCompatibleDictionary | JsonCompatibleArray | string | number | boolean | null;
export declare type JsonCompatibleValue =
| JsonCompatibleDictionary
| JsonCompatibleArray
| string
| number
| boolean
| null;
/**
* An array of JsonCompatibleValue
*/
export interface JsonCompatibleArray extends ReadonlyArray<JsonCompatibleValue> {
}
export interface JsonCompatibleArray extends ReadonlyArray<JsonCompatibleValue> {}
/**

@@ -14,3 +19,3 @@ * A string to json value dictionary.

export interface JsonCompatibleDictionary {
readonly [key: string]: JsonCompatibleValue | readonly JsonCompatibleValue[];
readonly [key: string]: JsonCompatibleValue | readonly JsonCompatibleValue[];
}

@@ -17,0 +22,0 @@ export declare function isJsonCompatibleValue(value: unknown): value is JsonCompatibleValue;

@@ -16,4 +16,4 @@ import { JsonCompatibleValue } from "./json";

export declare class TransactionEncoder {
static toJson(data: unknown): JsonCompatibleValue;
static fromJson(data: JsonCompatibleValue): any;
static toJson(data: unknown): JsonCompatibleValue;
static fromJson(data: JsonCompatibleValue): any;
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc