Socket
Socket
Sign inDemoInstall

@cosmjs/crypto

Package Overview
Dependencies
33
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.21.1 to 0.22.0-alpha.0

24

build/bip39.js

@@ -29,2 +29,17 @@ "use strict";

class Bip39 {
/**
* Encodes raw entropy of length 16, 20, 24, 28 or 32 bytes as an English mnemonic between 12 and 24 words.
*
* | Entropy | Words |
* |--------------------|-------|
* | 128 bit (16 bytes) | 12 |
* | 160 bit (20 bytes) | 15 |
* | 192 bit (24 bytes) | 18 |
* | 224 bit (28 bytes) | 21 |
* | 256 bit (32 bytes) | 24 |
*
*
* @see https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#generating-the-mnemonic
* @param entropy The entropy to be encoded. This must be cryptographically secure.
*/
static encode(entropy) {

@@ -43,12 +58,11 @@ const allowedEntropyLengths = [16, 20, 24, 28, 32];

// interface of https://www.npmjs.com/package/pbkdf2
const mnemonicBytes = Buffer.from(unorm.nfkd(mnemonic.toString()), "utf8");
const mnemonicBytes = encoding_1.toUtf8(unorm.nfkd(mnemonic.toString()));
const salt = "mnemonic" + (password ? unorm.nfkd(password) : "");
const saltBytes = Buffer.from(salt, "utf8");
const saltBytes = encoding_1.toUtf8(salt);
return this.pbkdf2(mnemonicBytes, saltBytes, 2048, 64, "sha512");
}
// convert pbkdf2's calllback interface to Promise interface
// convert pbkdf2's callback interface to Promise interface
static async pbkdf2(secret, salt, iterations, keylen, digest) {
return new Promise((resolve, reject) => {
// TODO: Patch @types/pbkdf2 to allow Uint8Array as secret and salt argument
pbkdf2_1.pbkdf2(Buffer.from(secret), Buffer.from(salt), iterations, keylen, digest, (err, derivedKey) => {
pbkdf2_1.pbkdf2(secret, salt, iterations, keylen, digest, (err, derivedKey) => {
if (err) {

@@ -55,0 +69,0 @@ reject(err);

@@ -13,3 +13,5 @@ "use strict";

Object.defineProperty(exports, "Xchacha20poly1305Ietf", { enumerable: true, get: function () { return libsodium_1.Xchacha20poly1305Ietf; } });
Object.defineProperty(exports, "xchacha20NonceLength", { enumerable: true, get: function () { return libsodium_1.xchacha20NonceLength; } });
Object.defineProperty(exports, "Argon2id", { enumerable: true, get: function () { return libsodium_1.Argon2id; } });
Object.defineProperty(exports, "isArgon2idOptions", { enumerable: true, get: function () { return libsodium_1.isArgon2idOptions; } });
Object.defineProperty(exports, "Ed25519", { enumerable: true, get: function () { return libsodium_1.Ed25519; } });

@@ -16,0 +18,0 @@ Object.defineProperty(exports, "Ed25519Keypair", { enumerable: true, get: function () { return libsodium_1.Ed25519Keypair; } });

@@ -10,4 +10,17 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Xchacha20poly1305Ietf = exports.Ed25519 = exports.Ed25519Keypair = exports.Argon2id = void 0;
exports.Xchacha20poly1305Ietf = exports.xchacha20NonceLength = exports.Ed25519 = exports.Ed25519Keypair = exports.Argon2id = exports.isArgon2idOptions = void 0;
const utils_1 = require("@cosmjs/utils");
const libsodium_wrappers_1 = __importDefault(require("libsodium-wrappers"));
function isArgon2idOptions(thing) {
if (!utils_1.isNonNullObject(thing))
return false;
if (typeof thing.outputLength !== "number")
return false;
if (typeof thing.opsLimit !== "number")
return false;
if (typeof thing.memLimitKib !== "number")
return false;
return true;
}
exports.isArgon2idOptions = isArgon2idOptions;
class Argon2id {

@@ -62,2 +75,8 @@ static async execute(password, salt, options) {

exports.Ed25519 = Ed25519;
/**
* Nonce length in bytes for all flavours of XChaCha20.
*
* @see https://libsodium.gitbook.io/doc/advanced/stream_ciphers/xchacha20#notes
*/
exports.xchacha20NonceLength = 24;
class Xchacha20poly1305Ietf {

@@ -64,0 +83,0 @@ static async encrypt(message, key, nonce) {

{
"name": "@cosmjs/crypto",
"version": "0.21.1",
"version": "0.22.0-alpha.0",
"description": "Cryptography resources for blockchain projects",

@@ -27,3 +27,3 @@ "contributors": [

"scripts": {
"docs": "shx rm -rf docs && typedoc --options typedoc.js",
"docs": "typedoc --options typedoc.js",
"lint": "eslint --max-warnings 0 \"**/*.{js,ts}\"",

@@ -47,5 +47,5 @@ "lint-fix": "eslint --max-warnings 0 \"**/*.{js,ts}\" --fix",

"dependencies": {
"@cosmjs/encoding": "^0.21.1",
"@cosmjs/math": "^0.21.1",
"@cosmjs/utils": "^0.21.1",
"@cosmjs/encoding": "^0.22.0-alpha.0",
"@cosmjs/math": "^0.22.0-alpha.0",
"@cosmjs/utils": "^0.22.0-alpha.0",
"bip39": "^3.0.2",

@@ -56,3 +56,3 @@ "bn.js": "^4.11.8",

"libsodium-wrappers": "^0.7.6",
"pbkdf2": "^3.0.16",
"pbkdf2": "^3.1.1",
"ripemd160": "^2.0.2",

@@ -67,3 +67,3 @@ "sha.js": "^2.4.11",

"@types/libsodium-wrappers": "^0.7.7",
"@types/pbkdf2": "^3.0.0",
"@types/pbkdf2": "^3.1.0",
"@types/ripemd160": "^2.0.0",

@@ -73,3 +73,3 @@ "@types/sha.js": "^2.4.0",

},
"gitHead": "66c2b2309c27feecec6fdfb43be50820244665ed"
"gitHead": "2f83fcd1f97f4958dbb8911cb29a338153e46460"
}
import { EnglishMnemonic } from "./englishmnemonic";
export declare class Bip39 {
/**
* Encodes raw entropy of length 16, 20, 24, 28 or 32 bytes as an English mnemonic between 12 and 24 words.
*
* | Entropy | Words |
* |--------------------|-------|
* | 128 bit (16 bytes) | 12 |
* | 160 bit (20 bytes) | 15 |
* | 192 bit (24 bytes) | 18 |
* | 224 bit (28 bytes) | 21 |
* | 256 bit (32 bytes) | 24 |
*
*
* @see https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#generating-the-mnemonic
* @param entropy The entropy to be encoded. This must be cryptographically secure.
*/
static encode(entropy: Uint8Array): EnglishMnemonic;

@@ -4,0 +19,0 @@ static decode(mnemonic: EnglishMnemonic): Uint8Array;

@@ -8,8 +8,6 @@ export { Bip39 } from "./bip39";

Xchacha20poly1305Ietf,
Xchacha20poly1305IetfCiphertext,
Xchacha20poly1305IetfKey,
Xchacha20poly1305IetfMessage,
Xchacha20poly1305IetfNonce,
xchacha20NonceLength,
Argon2id,
Argon2idOptions,
isArgon2idOptions,
Ed25519,

@@ -16,0 +14,0 @@ Ed25519Keypair,

@@ -1,11 +0,20 @@

import { As } from "type-tagger";
export declare type Xchacha20poly1305IetfKey = Uint8Array & As<"xchacha20poly1305ietf-key">;
export declare type Xchacha20poly1305IetfMessage = Uint8Array & As<"xchacha20poly1305ietf-message">;
export declare type Xchacha20poly1305IetfNonce = Uint8Array & As<"xchacha20poly1305ietf-nonce">;
export declare type Xchacha20poly1305IetfCiphertext = Uint8Array & As<"xchacha20poly1305ietf-ciphertext">;
export interface Argon2idOptions {
/** Output length in bytes */
readonly outputLength: number;
/**
* An integer between 1 and 4294967295 representing the computational difficulty.
*
* @see https://libsodium.gitbook.io/doc/password_hashing/default_phf#key-derivation
*/
readonly opsLimit: number;
/**
* Memory limit measured in KiB (like argon2 command line tool)
*
* Note: only approximately 16 MiB of memory are available using the non-sumo version of libsodium.js
*
* @see https://libsodium.gitbook.io/doc/password_hashing/default_phf#key-derivation
*/
readonly memLimitKib: number;
}
export declare function isArgon2idOptions(thing: unknown): thing is Argon2idOptions;
export declare class Argon2id {

@@ -34,13 +43,11 @@ static execute(password: string, salt: Uint8Array, options: Argon2idOptions): Promise<Uint8Array>;

}
/**
* Nonce length in bytes for all flavours of XChaCha20.
*
* @see https://libsodium.gitbook.io/doc/advanced/stream_ciphers/xchacha20#notes
*/
export declare const xchacha20NonceLength = 24;
export declare class Xchacha20poly1305Ietf {
static encrypt(
message: Xchacha20poly1305IetfMessage,
key: Xchacha20poly1305IetfKey,
nonce: Xchacha20poly1305IetfNonce,
): Promise<Xchacha20poly1305IetfCiphertext>;
static decrypt(
ciphertext: Xchacha20poly1305IetfCiphertext,
key: Xchacha20poly1305IetfKey,
nonce: Xchacha20poly1305IetfNonce,
): Promise<Xchacha20poly1305IetfMessage>;
static encrypt(message: Uint8Array, key: Uint8Array, nonce: Uint8Array): Promise<Uint8Array>;
static decrypt(ciphertext: Uint8Array, key: Uint8Array, nonce: Uint8Array): Promise<Uint8Array>;
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc