/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see .
*/
import { Transaction } from './qrl_types.js';
import { HexString } from './primitives_types.js';
export type Cipher = 'aes-256-gcm';
export type CipherOptions = {
salt?: Uint8Array | string;
iv?: Uint8Array | string;
kdf?: 'argon2id';
dklen?: number;
t?: number; // iterations
m?: number; // amount of memory to use
p?: number; // degree of parallelism (i.e. number of threads)
};
export type Argon2idParams = {
dklen: number;
t: number;
m: number;
p: number;
salt: Uint8Array | string;
};
export type KeyStore = {
crypto: {
cipher: Cipher;
ciphertext: string;
cipherparams: {
iv: string;
};
kdf: 'argon2id';
kdfparams: Argon2idParams;
};
id: string;
version: 1;
address: string;
};
export interface Web3BaseWalletAccount {
[key: string]: unknown;
readonly address: string;
readonly seed: string;
readonly signTransaction: (tx: Transaction) => Promise<{
readonly messageHash: HexString;
readonly signature: HexString;
readonly rawTransaction: HexString;
readonly transactionHash: HexString;
}>;
readonly sign: (data: Record | string) => {
readonly messageHash: HexString;
readonly message?: string;
readonly signature: HexString;
};
readonly encrypt: (password: string, options?: Record) => Promise;
}
export interface Web3AccountProvider {
seedToAccount: (seed: string) => T;
create: () => T;
decrypt: (
keystore: KeyStore | string,
password: string,
options?: Record,
) => Promise;
}
export abstract class Web3BaseWallet extends Array {
protected readonly _accountProvider: Web3AccountProvider;
public constructor(accountProvider: Web3AccountProvider) {
super();
this._accountProvider = accountProvider;
}
public abstract create(numberOfAccounts: number): this;
public abstract add(account: T | string): this;
public abstract get(addressOrIndex: string | number): T | undefined;
public abstract remove(addressOrIndex: string | number): boolean;
public abstract clear(): this;
public abstract encrypt(
password: string,
options?: Record,
): Promise;
public abstract decrypt(
encryptedWallet: KeyStore[],
password: string,
options?: Record,
): Promise;
public abstract save(
password: string,
keyName?: string,
options?: Record,
): Promise;
public abstract load(password: string, keyName?: string): Promise;
}