mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Rename to serialize/serializeWithEncryptionKey
This commit is contained in:
parent
ed8497b005
commit
588b31fed6
@ -69,10 +69,10 @@ describe("Secp256k1Wallet", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("save", () => {
|
||||
describe("serialize", () => {
|
||||
it("can save with password", async () => {
|
||||
const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic);
|
||||
const serialized = await wallet.save("123");
|
||||
const serialized = await wallet.serialize("123");
|
||||
expect(JSON.parse(serialized)).toEqual(
|
||||
jasmine.objectContaining({
|
||||
type: "v1",
|
||||
@ -96,7 +96,7 @@ describe("Secp256k1Wallet", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("saveWithEncryptionKey", () => {
|
||||
describe("serializeWithEncryptionKey", () => {
|
||||
it("can save with password", async () => {
|
||||
const wallet = await Secp256k1Wallet.fromMnemonic(defaultMnemonic);
|
||||
|
||||
@ -106,7 +106,7 @@ describe("Secp256k1Wallet", () => {
|
||||
opsLimit: 321,
|
||||
memLimitKib: 11 * 1024,
|
||||
};
|
||||
const serialized = await wallet.saveWithEncryptionKey(key, customKdfParams);
|
||||
const serialized = await wallet.serializeWithEncryptionKey(key, customKdfParams);
|
||||
expect(JSON.parse(serialized)).toEqual(
|
||||
jasmine.objectContaining({
|
||||
type: "v1",
|
||||
|
@ -241,22 +241,22 @@ export class Secp256k1Wallet implements OfflineSigner {
|
||||
* @param password The user provided password used to generate an encryption key via a KDF.
|
||||
* This is not normalized internally (see "Unicode normalization" to learn more).
|
||||
*/
|
||||
public async save(password: string): Promise<string> {
|
||||
public async serialize(password: string): Promise<string> {
|
||||
const kdfOption = basicPasswordHashingOptions;
|
||||
const encryptionKey = await Argon2id.execute(password, secp256k1WalletSalt, kdfOption);
|
||||
return this.saveWithEncryptionKey(encryptionKey, kdfOption);
|
||||
return this.serializeWithEncryptionKey(encryptionKey, kdfOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an encrypted serialization of this wallet.
|
||||
*
|
||||
* This is an advanced alternative of calling `save(password)` directly, which allows you to
|
||||
* This is an advanced alternative of calling `serialize(password)` directly, which allows you to
|
||||
* offload the KDF execution to an non-UI thread (e.g. in a WebWorker).
|
||||
*
|
||||
* The caller is responsible for ensuring the key was derived with the given kdf options. If this
|
||||
* is not the case, the wallet cannot be restored with the original password.
|
||||
*/
|
||||
public async saveWithEncryptionKey(
|
||||
public async serializeWithEncryptionKey(
|
||||
encryptionKey: Uint8Array,
|
||||
kdfOptions: Argon2idOptions,
|
||||
): Promise<string> {
|
||||
|
6
packages/sdk38/types/wallet.d.ts
vendored
6
packages/sdk38/types/wallet.d.ts
vendored
@ -100,15 +100,15 @@ export declare class Secp256k1Wallet implements OfflineSigner {
|
||||
* @param password The user provided password used to generate an encryption key via a KDF.
|
||||
* This is not normalized internally (see "Unicode normalization" to learn more).
|
||||
*/
|
||||
save(password: string): Promise<string>;
|
||||
serialize(password: string): Promise<string>;
|
||||
/**
|
||||
* Generates an encrypted serialization of this wallet.
|
||||
*
|
||||
* This is an advanced alternative of calling `save(password)` directly, which allows you to
|
||||
* This is an advanced alternative of calling `serialize(password)` directly, which allows you to
|
||||
* offload the KDF execution to an non-UI thread (e.g. in a WebWorker).
|
||||
*
|
||||
* The caller is responsible for ensuring the key was derived with the given kdf options. If this
|
||||
* is not the case, the wallet cannot be restored with the original password.
|
||||
*/
|
||||
saveWithEncryptionKey(encryptionKey: Uint8Array, kdfOptions: Argon2idOptions): Promise<string>;
|
||||
serializeWithEncryptionKey(encryptionKey: Uint8Array, kdfOptions: Argon2idOptions): Promise<string>;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user