@iov/crypto
Advanced tools
Comparing version 0.14.3 to 0.14.4
@@ -39,6 +39,2 @@ "use strict"; | ||
class Ed25519Keypair { | ||
constructor(privkey, pubkey) { | ||
this.privkey = privkey; | ||
this.pubkey = pubkey; | ||
} | ||
// a libsodium privkey has the format `<ed25519 privkey> + <ed25519 pubkey>` | ||
@@ -51,2 +47,6 @@ static fromLibsodiumPrivkey(libsodiumPrivkey) { | ||
} | ||
constructor(privkey, pubkey) { | ||
this.privkey = privkey; | ||
this.pubkey = pubkey; | ||
} | ||
toLibsodiumPrivkey() { | ||
@@ -53,0 +53,0 @@ return new Uint8Array([...this.privkey, ...this.pubkey]); |
@@ -35,2 +35,3 @@ "use strict"; | ||
} | ||
/* eslint-disable @typescript-eslint/no-object-literal-type-assertion */ | ||
// tslint:disable-next-line:no-object-literal-type-assertion | ||
@@ -45,2 +46,3 @@ return { | ||
}; | ||
/* eslint-enable @typescript-eslint/no-object-literal-type-assertion */ | ||
}); | ||
@@ -47,0 +49,0 @@ } |
@@ -84,6 +84,3 @@ "use strict"; | ||
it("can derive path m/0/2147483647'", () => { | ||
const path = [ | ||
slip10_1.Slip10RawIndex.normal(0), | ||
slip10_1.Slip10RawIndex.hardened(2147483647), | ||
]; | ||
const path = [slip10_1.Slip10RawIndex.normal(0), slip10_1.Slip10RawIndex.hardened(2147483647)]; | ||
const derived = slip10_1.Slip10.derivePath(slip10_1.Slip10Curve.Secp256k1, seed, path); | ||
@@ -90,0 +87,0 @@ expect(derived.chainCode).toEqual(fromHex("be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9")); |
{ | ||
"name": "@iov/crypto", | ||
"version": "0.14.3", | ||
"version": "0.14.4", | ||
"description": "Cryptography resources for IOV projects", | ||
@@ -18,3 +18,3 @@ "author": "IOV SAS <admin@iov.one>", | ||
"docs": "shx rm -rf docs && typedoc --options typedoc.js", | ||
"lint": "tslint -t verbose --project .", | ||
"lint": "eslint --max-warnings 0 \"**/*.{js,ts}\" && tslint -t verbose --project .", | ||
"format": "prettier --write --loglevel warn \"./src/**/*.ts\"", | ||
@@ -28,3 +28,2 @@ "format-text": "prettier --write --prose-wrap always --print-width 80 \"./*.md\"", | ||
"test": "yarn build-or-skip && yarn test-node", | ||
"prebuild": "yarn format", | ||
"move-types": "shx rm -r ./types/* && shx mv build/types/* ./types && shx rm ./types/*.spec.d.ts", | ||
@@ -36,3 +35,3 @@ "build": "shx rm -rf ./build && tsc && yarn move-types", | ||
"dependencies": { | ||
"@iov/encoding": "^0.14.3", | ||
"@iov/encoding": "^0.14.4", | ||
"bip39": "^2.5.0", | ||
@@ -51,3 +50,3 @@ "bn.js": "^4.11.8", | ||
}, | ||
"gitHead": "93942a81ff274b0bfcc7c01ff9016bd7c6a721ee" | ||
"gitHead": "15f31720ee4eedf9dcb7608134acff3f1facc23b" | ||
} |
@@ -11,3 +11,3 @@ import * as bip39 from "bip39"; | ||
public static encode(entropy: Uint8Array): EnglishMnemonic { | ||
const allowedEntropyLengths: ReadonlyArray<number> = [16, 20, 24, 28, 32]; | ||
const allowedEntropyLengths: readonly number[] = [16, 20, 24, 28, 32]; | ||
@@ -14,0 +14,0 @@ if (allowedEntropyLengths.indexOf(entropy.length) === -1) { |
import * as bip39 from "bip39"; | ||
// tslint:disable-next-line:no-submodule-imports | ||
import bip39_wordlist_english from "bip39/wordlists/english.json"; | ||
import bip39WordlistEnglish from "bip39/wordlists/english.json"; | ||
@@ -11,3 +11,3 @@ export class EnglishMnemonic { | ||
constructor(mnemonic: string) { | ||
public constructor(mnemonic: string) { | ||
if (!EnglishMnemonic.mnemonicMatcher.test(mnemonic)) { | ||
@@ -18,3 +18,3 @@ throw new Error("Invalid mnemonic format"); | ||
const words = mnemonic.split(" "); | ||
const allowedWordsLengths: ReadonlyArray<number> = [12, 15, 18, 21, 24]; | ||
const allowedWordsLengths: readonly number[] = [12, 15, 18, 21, 24]; | ||
if (allowedWordsLengths.indexOf(words.length) === -1) { | ||
@@ -27,3 +27,3 @@ throw new Error( | ||
for (const word of words) { | ||
if ((bip39_wordlist_english as ReadonlyArray<string>).indexOf(word) === -1) { | ||
if ((bip39WordlistEnglish as readonly string[]).indexOf(word) === -1) { | ||
throw new Error("Mnemonic contains invalid word"); | ||
@@ -30,0 +30,0 @@ } |
@@ -11,3 +11,3 @@ import { HashFunction } from "./sha"; | ||
constructor(hashFunctionConstructor: new () => H, originalKey: Uint8Array) { | ||
public constructor(hashFunctionConstructor: new () => H, originalKey: Uint8Array) { | ||
// This implementation is based on https://en.wikipedia.org/wiki/HMAC#Implementation | ||
@@ -14,0 +14,0 @@ // with the addition of incremental hashing support. Thus part of the algorithm |
@@ -7,5 +7,5 @@ import jssha3 from "js-sha3"; | ||
private readonly impl: any; | ||
private readonly impl: jssha3.Hasher; | ||
constructor(firstData?: Uint8Array) { | ||
public constructor(firstData?: Uint8Array) { | ||
this.impl = jssha3.keccak256.create(); | ||
@@ -12,0 +12,0 @@ |
@@ -61,4 +61,10 @@ // Keep all classes requiring libsodium-js in one file as having multiple | ||
constructor(public readonly privkey: Uint8Array, public readonly pubkey: Uint8Array) {} | ||
public readonly privkey: Uint8Array; | ||
public readonly pubkey: Uint8Array; | ||
public constructor(privkey: Uint8Array, pubkey: Uint8Array) { | ||
this.privkey = privkey; | ||
this.pubkey = pubkey; | ||
} | ||
public toLibsodiumPrivkey(): Uint8Array { | ||
@@ -65,0 +71,0 @@ return new Uint8Array([...this.privkey, ...this.pubkey]); |
@@ -199,7 +199,7 @@ /* tslint:disable:no-bitwise */ | ||
// signatures are mixed lowS and non-lowS, prehash type is sha256 | ||
const data: ReadonlyArray<{ | ||
const data: readonly { | ||
readonly message: Uint8Array; | ||
readonly privkey: Uint8Array; | ||
readonly signature: Uint8Array; | ||
}> = [ | ||
}[] = [ | ||
{ | ||
@@ -403,7 +403,7 @@ message: fromHex( | ||
// signatures are normalized to lowS, prehash type is sha256 | ||
const data: ReadonlyArray<{ | ||
const data: readonly { | ||
readonly message: Uint8Array; | ||
readonly privkey: Uint8Array; | ||
readonly signature: Uint8Array; | ||
}> = [ | ||
}[] = [ | ||
{ | ||
@@ -410,0 +410,0 @@ message: fromHex( |
@@ -37,2 +37,3 @@ import { Encoding } from "@iov/encoding"; | ||
/* eslint-disable @typescript-eslint/no-object-literal-type-assertion */ | ||
// tslint:disable-next-line:no-object-literal-type-assertion | ||
@@ -47,2 +48,3 @@ return { | ||
} as Secp256k1Keypair; | ||
/* eslint-enable @typescript-eslint/no-object-literal-type-assertion */ | ||
} | ||
@@ -49,0 +51,0 @@ |
@@ -64,3 +64,3 @@ function trimLeadingNullBytes(inData: Uint8Array): Uint8Array { | ||
constructor(r: Uint8Array, s: Uint8Array) { | ||
public constructor(r: Uint8Array, s: Uint8Array) { | ||
if (r.length > 32 || r.length === 0 || r[0] === 0x00) { | ||
@@ -141,3 +141,3 @@ throw new Error("Unsigned integer r must be encoded as unpadded big endian."); | ||
constructor(r: Uint8Array, s: Uint8Array, recovery: number) { | ||
public constructor(r: Uint8Array, s: Uint8Array, recovery: number) { | ||
super(r, s); | ||
@@ -144,0 +144,0 @@ |
@@ -14,3 +14,3 @@ import shajs from "sha.js"; | ||
constructor(firstData?: Uint8Array) { | ||
public constructor(firstData?: Uint8Array) { | ||
this.impl = shajs("sha1"); | ||
@@ -38,3 +38,3 @@ | ||
constructor(firstData?: Uint8Array) { | ||
public constructor(firstData?: Uint8Array) { | ||
this.impl = shajs("sha256"); | ||
@@ -62,3 +62,3 @@ | ||
constructor(firstData?: Uint8Array) { | ||
public constructor(firstData?: Uint8Array) { | ||
this.impl = shajs("sha512"); | ||
@@ -65,0 +65,0 @@ |
@@ -20,3 +20,3 @@ import { Encoding } from "@iov/encoding"; | ||
it("can derive path m", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = []; | ||
const path: readonly Slip10RawIndex[] = []; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -32,3 +32,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.hardened(0)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.hardened(0)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -44,3 +44,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'/1", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.hardened(0), Slip10RawIndex.normal(1)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.hardened(0), Slip10RawIndex.normal(1)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -56,3 +56,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'/1/2'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -72,3 +72,3 @@ Slip10RawIndex.normal(1), | ||
it("can derive path m/0'/1/2'/2", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -89,3 +89,3 @@ Slip10RawIndex.normal(1), | ||
it("can derive path m/0'/1/2'/2/1000000000", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -114,3 +114,3 @@ Slip10RawIndex.normal(1), | ||
it("can derive path m", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = []; | ||
const path: readonly Slip10RawIndex[] = []; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -126,3 +126,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.normal(0)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.normal(0)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -138,6 +138,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0/2147483647'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
Slip10RawIndex.normal(0), | ||
Slip10RawIndex.hardened(2147483647), | ||
]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.normal(0), Slip10RawIndex.hardened(2147483647)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Secp256k1, seed, path); | ||
@@ -153,3 +150,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0/2147483647'/1", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.normal(0), | ||
@@ -169,3 +166,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m/0/2147483647'/1/2147483646'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.normal(0), | ||
@@ -186,3 +183,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m/0/2147483647'/1/2147483646'/2", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.normal(0), | ||
@@ -209,3 +206,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = []; | ||
const path: readonly Slip10RawIndex[] = []; | ||
const derived = Slip10.derivePath(Slip10Curve.Ed25519, seed, path); | ||
@@ -221,3 +218,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.hardened(0)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.hardened(0)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Ed25519, seed, path); | ||
@@ -233,3 +230,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'/1'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.hardened(0), Slip10RawIndex.hardened(1)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.hardened(0), Slip10RawIndex.hardened(1)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Ed25519, seed, path); | ||
@@ -245,3 +242,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'/1'/2'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -261,3 +258,3 @@ Slip10RawIndex.hardened(1), | ||
it("can derive path m/0'/1'/2'/2'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -278,3 +275,3 @@ Slip10RawIndex.hardened(1), | ||
it("can derive path m/0'/1'/2'/2'/1000000000'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -303,3 +300,3 @@ Slip10RawIndex.hardened(1), | ||
it("can derive path m", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = []; | ||
const path: readonly Slip10RawIndex[] = []; | ||
const derived = Slip10.derivePath(Slip10Curve.Ed25519, seed, path); | ||
@@ -315,3 +312,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [Slip10RawIndex.hardened(0)]; | ||
const path: readonly Slip10RawIndex[] = [Slip10RawIndex.hardened(0)]; | ||
const derived = Slip10.derivePath(Slip10Curve.Ed25519, seed, path); | ||
@@ -327,3 +324,3 @@ expect(derived.chainCode).toEqual( | ||
it("can derive path m/0'/2147483647'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -342,3 +339,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m/0'/2147483647'/1'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -358,3 +355,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m/0'/2147483647'/1'/2147483646'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -375,3 +372,3 @@ Slip10RawIndex.hardened(2147483647), | ||
it("can derive path m/0'/2147483647'/1'/2147483646'/2'", () => { | ||
const path: ReadonlyArray<Slip10RawIndex> = [ | ||
const path: readonly Slip10RawIndex[] = [ | ||
Slip10RawIndex.hardened(0), | ||
@@ -378,0 +375,0 @@ Slip10RawIndex.hardened(2147483647), |
@@ -60,3 +60,3 @@ import BN = require("bn.js"); | ||
seed: Uint8Array, | ||
path: ReadonlyArray<Slip10RawIndex>, | ||
path: readonly Slip10RawIndex[], | ||
): Slip10Result { | ||
@@ -63,0 +63,0 @@ let result = this.master(curve, seed); |
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"resolveJsonModule": true, | ||
"baseUrl": ".", | ||
@@ -6,0 +5,0 @@ "outDir": "build", |
@@ -18,5 +18,5 @@ import { As } from "type-tagger"; | ||
export declare class Ed25519Keypair { | ||
static fromLibsodiumPrivkey(libsodiumPrivkey: Uint8Array): Ed25519Keypair; | ||
readonly privkey: Uint8Array; | ||
readonly pubkey: Uint8Array; | ||
static fromLibsodiumPrivkey(libsodiumPrivkey: Uint8Array): Ed25519Keypair; | ||
constructor(privkey: Uint8Array, pubkey: Uint8Array); | ||
@@ -23,0 +23,0 @@ toLibsodiumPrivkey(): Uint8Array; |
@@ -25,3 +25,3 @@ import { Uint32 } from "@iov/encoding"; | ||
export declare class Slip10 { | ||
static derivePath(curve: Slip10Curve, seed: Uint8Array, path: ReadonlyArray<Slip10RawIndex>): Slip10Result; | ||
static derivePath(curve: Slip10Curve, seed: Uint8Array, path: readonly Slip10RawIndex[]): Slip10Result; | ||
private static master; | ||
@@ -28,0 +28,0 @@ private static child; |
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
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
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
978849
12682
Updated@iov/encoding@^0.14.4