sdk38: Remove enabling from secp256k1 offline wallet

This commit is contained in:
willclarktech 2020-07-09 13:42:07 +02:00
parent 0ab80be572
commit 64eba761c8
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
3 changed files with 0 additions and 33 deletions

View File

@ -16,12 +16,6 @@ describe("Secp256k1OfflineWallet", () => {
});
describe("getAccounts", () => {
it("rejects if not enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
spyOn(wallet as any, "enable").and.resolveTo(false);
await expectAsync(wallet.getAccounts()).toBeRejectedWithError(/wallet not enabled/i);
});
it("resolves to a list of accounts if enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
const accounts = await wallet.getAccounts();
@ -43,13 +37,6 @@ describe("Secp256k1OfflineWallet", () => {
});
describe("sign", () => {
it("rejects if not enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
spyOn(wallet as any, "enable").and.resolveTo(false);
const message = toAscii("foo bar");
await expectAsync(wallet.sign(defaultAddress, message)).toBeRejectedWithError(/wallet not enabled/i);
});
it("resolves to valid signature if enabled", async () => {
const wallet = await Secp256k1OfflineWallet.fromMnemonic(defaultMnemonic);
const message = toAscii("foo bar");

View File

@ -79,7 +79,6 @@ export class Secp256k1OfflineWallet implements OfflineSigner {
private readonly privkey: Uint8Array;
private readonly prefix: string;
private readonly algo: Algo = "secp256k1";
private enabled = false;
private constructor(privkey: Uint8Array, pubkey: Uint8Array, prefix: string) {
this.privkey = privkey;
@ -91,18 +90,7 @@ export class Secp256k1OfflineWallet implements OfflineSigner {
return rawSecp256k1PubkeyToAddress(this.pubkey, this.prefix);
}
/**
* Request access to the user's accounts. Some wallets will ask the user to approve or deny access. Returns true if granted access or false if denied.
*/
private async enable(): Promise<boolean> {
this.enabled = true;
return this.enabled;
}
public async getAccounts(): Promise<readonly AccountData[]> {
if (!this.enabled && !(await this.enable())) {
throw new Error("Wallet not enabled");
}
return [
{
address: this.address,
@ -117,9 +105,6 @@ export class Secp256k1OfflineWallet implements OfflineSigner {
message: Uint8Array,
prehashType: PrehashType = "sha256",
): Promise<StdSignature> {
if (!this.enabled && !(await this.enable())) {
throw new Error("Wallet not enabled");
}
if (address !== this.address) {
throw new Error(`Address ${address} not found in wallet`);
}

View File

@ -32,13 +32,8 @@ export declare class Secp256k1OfflineWallet implements OfflineSigner {
private readonly privkey;
private readonly prefix;
private readonly algo;
private enabled;
private constructor();
private get address();
/**
* Request access to the user's accounts. Some wallets will ask the user to approve or deny access. Returns true if granted access or false if denied.
*/
private enable;
getAccounts(): Promise<readonly AccountData[]>;
sign(address: string, message: Uint8Array, prehashType?: PrehashType): Promise<StdSignature>;
}