Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cosmjs/crypto

Package Overview
Dependencies
Maintainers
2
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/crypto - npm Package Compare versions

Comparing version 0.30.1 to 0.31.0-alpha.1

39

build/libsodium.js

@@ -12,3 +12,6 @@ "use strict";

const utils_1 = require("@cosmjs/utils");
const libsodium_wrappers_1 = __importDefault(require("libsodium-wrappers"));
// Using crypto_pwhash requires sumo. Once we migrate to a standalone
// Argon2 implementation, we can use the normal libsodium-wrappers
// again: https://github.com/cosmos/cosmjs/issues/1031
const libsodium_wrappers_sumo_1 = __importDefault(require("libsodium-wrappers-sumo"));
function isArgon2idOptions(thing) {

@@ -28,5 +31,5 @@ if (!(0, utils_1.isNonNullObject)(thing))

static async execute(password, salt, options) {
await libsodium_wrappers_1.default.ready;
return libsodium_wrappers_1.default.crypto_pwhash(options.outputLength, password, salt, // libsodium only supports 16 byte salts and will throw when you don't respect that
options.opsLimit, options.memLimitKib * 1024, libsodium_wrappers_1.default.crypto_pwhash_ALG_ARGON2ID13);
await libsodium_wrappers_sumo_1.default.ready;
return libsodium_wrappers_sumo_1.default.crypto_pwhash(options.outputLength, password, salt, // libsodium only supports 16 byte salts and will throw when you don't respect that
options.opsLimit, options.memLimitKib * 1024, libsodium_wrappers_sumo_1.default.crypto_pwhash_ALG_ARGON2ID13);
}

@@ -36,6 +39,2 @@ }

class Ed25519Keypair {
constructor(privkey, pubkey) {
this.privkey = privkey;
this.pubkey = pubkey;
}
// a libsodium privkey has the format `<ed25519 privkey> + <ed25519 pubkey>`

@@ -48,2 +47,6 @@ static fromLibsodiumPrivkey(libsodiumPrivkey) {

}
constructor(privkey, pubkey) {
this.privkey = privkey;
this.pubkey = pubkey;
}
toLibsodiumPrivkey() {

@@ -64,13 +67,13 @@ return new Uint8Array([...this.privkey, ...this.pubkey]);

static async makeKeypair(seed) {
await libsodium_wrappers_1.default.ready;
const keypair = libsodium_wrappers_1.default.crypto_sign_seed_keypair(seed);
await libsodium_wrappers_sumo_1.default.ready;
const keypair = libsodium_wrappers_sumo_1.default.crypto_sign_seed_keypair(seed);
return Ed25519Keypair.fromLibsodiumPrivkey(keypair.privateKey);
}
static async createSignature(message, keyPair) {
await libsodium_wrappers_1.default.ready;
return libsodium_wrappers_1.default.crypto_sign_detached(message, keyPair.toLibsodiumPrivkey());
await libsodium_wrappers_sumo_1.default.ready;
return libsodium_wrappers_sumo_1.default.crypto_sign_detached(message, keyPair.toLibsodiumPrivkey());
}
static async verifySignature(signature, message, pubkey) {
await libsodium_wrappers_1.default.ready;
return libsodium_wrappers_1.default.crypto_sign_verify_detached(signature, message, pubkey);
await libsodium_wrappers_sumo_1.default.ready;
return libsodium_wrappers_sumo_1.default.crypto_sign_verify_detached(signature, message, pubkey);
}

@@ -87,11 +90,11 @@ }

static async encrypt(message, key, nonce) {
await libsodium_wrappers_1.default.ready;
await libsodium_wrappers_sumo_1.default.ready;
const additionalData = null;
return libsodium_wrappers_1.default.crypto_aead_xchacha20poly1305_ietf_encrypt(message, additionalData, null, // secret nonce: unused and should be null (https://download.libsodium.org/doc/secret-key_cryptography/aead/chacha20-poly1305/xchacha20-poly1305_construction)
return libsodium_wrappers_sumo_1.default.crypto_aead_xchacha20poly1305_ietf_encrypt(message, additionalData, null, // secret nonce: unused and should be null (https://download.libsodium.org/doc/secret-key_cryptography/aead/chacha20-poly1305/xchacha20-poly1305_construction)
nonce, key);
}
static async decrypt(ciphertext, key, nonce) {
await libsodium_wrappers_1.default.ready;
await libsodium_wrappers_sumo_1.default.ready;
const additionalData = null;
return libsodium_wrappers_1.default.crypto_aead_xchacha20poly1305_ietf_decrypt(null, // secret nonce: unused and should be null (https://download.libsodium.org/doc/secret-key_cryptography/aead/chacha20-poly1305/xchacha20-poly1305_construction)
return libsodium_wrappers_sumo_1.default.crypto_aead_xchacha20poly1305_ietf_decrypt(null, // secret nonce: unused and should be null (https://download.libsodium.org/doc/secret-key_cryptography/aead/chacha20-poly1305/xchacha20-poly1305_construction)
ciphertext, additionalData, nonce, key);

@@ -98,0 +101,0 @@ }

@@ -18,14 +18,2 @@ "use strict";

class Secp256k1Signature {
constructor(r, s) {
if (r.length > 32 || r.length === 0 || r[0] === 0x00) {
throw new Error("Unsigned integer r must be encoded as unpadded big endian.");
}
if (s.length > 32 || s.length === 0 || s[0] === 0x00) {
throw new Error("Unsigned integer s must be encoded as unpadded big endian.");
}
this.data = {
r: r,
s: s,
};
}
/**

@@ -79,2 +67,14 @@ * Takes the pair of integers (r, s) as 2x32 byte of binary data.

}
constructor(r, s) {
if (r.length > 32 || r.length === 0 || r[0] === 0x00) {
throw new Error("Unsigned integer r must be encoded as unpadded big endian.");
}
if (s.length > 32 || s.length === 0 || s[0] === 0x00) {
throw new Error("Unsigned integer s must be encoded as unpadded big endian.");
}
this.data = {
r: r,
s: s,
};
}
r(length) {

@@ -125,2 +125,12 @@ if (length === undefined) {

class ExtendedSecp256k1Signature extends Secp256k1Signature {
/**
* Decode extended signature from the simple fixed length encoding
* described in toFixedLength().
*/
static fromFixedLength(data) {
if (data.length !== 65) {
throw new Error(`Got invalid data length ${data.length}. Expected 32 + 32 + 1`);
}
return new ExtendedSecp256k1Signature(trimLeadingNullBytes(data.slice(0, 32)), trimLeadingNullBytes(data.slice(32, 64)), data[64]);
}
constructor(r, s, recovery) {

@@ -137,12 +147,2 @@ super(r, s);

/**
* Decode extended signature from the simple fixed length encoding
* described in toFixedLength().
*/
static fromFixedLength(data) {
if (data.length !== 65) {
throw new Error(`Got invalid data length ${data.length}. Expected 32 + 32 + 1`);
}
return new ExtendedSecp256k1Signature(trimLeadingNullBytes(data.slice(0, 32)), trimLeadingNullBytes(data.slice(32, 64)), data[64]);
}
/**
* A simple custom encoding that encodes the extended signature as

@@ -149,0 +149,0 @@ * r (32 bytes) | s (32 bytes) | recovery param (1 byte)

@@ -50,3 +50,3 @@ import { Uint32 } from "@cosmjs/math";

*/
export declare type HdPath = readonly Slip10RawIndex[];
export type HdPath = readonly Slip10RawIndex[];
export declare class Slip10 {

@@ -53,0 +53,0 @@ static derivePath(curve: Slip10Curve, seed: Uint8Array, path: HdPath): Slip10Result;

{
"name": "@cosmjs/crypto",
"version": "0.30.1",
"version": "0.31.0-alpha.1",
"description": "Cryptography resources for blockchain projects",

@@ -44,9 +44,9 @@ "contributors": [

"dependencies": {
"@cosmjs/encoding": "^0.30.1",
"@cosmjs/math": "^0.30.1",
"@cosmjs/utils": "^0.30.1",
"@cosmjs/encoding": "^0.31.0-alpha.1",
"@cosmjs/math": "^0.31.0-alpha.1",
"@cosmjs/utils": "^0.31.0-alpha.1",
"@noble/hashes": "^1",
"bn.js": "^5.2.0",
"elliptic": "^6.5.4",
"libsodium-wrappers": "^0.7.6"
"libsodium-wrappers-sumo": "^0.7.11"
},

@@ -62,4 +62,4 @@ "devDependencies": {

"@types/karma-jasmine-html-reporter": "^1",
"@types/libsodium-wrappers": "^0.7.7",
"@types/node": "^15.0.1",
"@types/libsodium-wrappers-sumo": "^0.7.5",
"@types/node": "^18",
"@typescript-eslint/eslint-plugin": "^5.54.0",

@@ -88,7 +88,8 @@ "@typescript-eslint/parser": "^5.54.0",

"ts-node": "^8",
"typedoc": "^0.22",
"typescript": "~4.6",
"typedoc": "^0.23",
"typescript": "~4.9",
"webpack": "^5.76.0",
"webpack-cli": "^4.6.0"
}
},
"stableVersion": "0.30.1"
}

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