Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/crypto/src/libsodium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { isNonNullObject } from "@cosmjs/utils";
import sodium from "libsodium-wrappers";

import { Random } from './random'

export interface Argon2idOptions {
/** Output length in bytes */
readonly outputLength: number;
Expand Down Expand Up @@ -36,10 +38,11 @@ export function isArgon2idOptions(thing: unknown): thing is Argon2idOptions {
export class Argon2id {
public static async execute(
password: string,
salt: Uint8Array,
saltInput: Uint8Array,
options: Argon2idOptions,
): Promise<Uint8Array> {
await sodium.ready;
const salt: Uint8Array = saltInput || Random.getBytes(sodium.crypto_pwhash_SALTBYTES);
return sodium.crypto_pwhash(
options.outputLength,
password,
Expand Down
3 changes: 2 additions & 1 deletion packages/proto-signing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"typedoc": "^0.21",
"typescript": "~4.3",
"webpack": "^5.32.0",
"webpack-cli": "^4.6.0"
"webpack-cli": "^4.6.0",
"proto-signing-v0-26-2": "npm:@cosmjs/[email protected]"
}
}
27 changes: 27 additions & 0 deletions packages/proto-signing/src/directsecp256k1hdwallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Secp256k1, Secp256k1Signature, sha256 } from "@cosmjs/crypto";
import { fromBase64, fromHex } from "@cosmjs/encoding";

import { DirectSecp256k1HdWallet, extractKdfConfiguration } from "./directsecp256k1hdwallet";
import { DirectSecp256k1HdWallet as DirectSecp256k1HdWallet_v0_26_2 } from "proto-signing-v0-26-2"
import { makeAuthInfoBytes, makeSignBytes, makeSignDoc } from "./signing";
import { base64Matcher, faucet, testVectors } from "./testutils.spec";
import { executeKdf, KdfConfiguration } from "./wallet";
Expand Down Expand Up @@ -124,6 +125,23 @@ describe("DirectSecp256k1HdWallet", () => {
},
]);
});

it("can restore: backward compatibility test", async () => {
const original = await DirectSecp256k1HdWallet_v0_26_2.fromMnemonic(defaultMnemonic);
const password = "123";
const serialized = await original.serialize(password);
const deserialized = await DirectSecp256k1HdWallet.deserialize(serialized, password);
const accounts = await deserialized.getAccounts();

expect(deserialized.mnemonic).toEqual(defaultMnemonic);
expect(accounts).toEqual([
{
algo: "secp256k1",
address: defaultAddress,
pubkey: defaultPubkey,
},
]);
});
});

describe("deserializeWithEncryptionKey", () => {
Expand Down Expand Up @@ -299,6 +317,15 @@ describe("DirectSecp256k1HdWallet", () => {
data: jasmine.stringMatching(base64Matcher),
});
});

it("Store a salt next to the serialization options", async () => {
const original = await DirectSecp256k1HdWallet.fromMnemonic(defaultMnemonic);
const password = "123";
const serialized = await original.serialize(password);
const parsed = JSON.parse(serialized);

expect(Object.keys(parsed.kdf.params)).toContain('salt');
});
});

describe("serializeWithEncryptionKey", () => {
Expand Down