UNPKG

copay-crown

Version:

A Secure Crown Wallet

31 lines (27 loc) 673 B
import { IStorage, KeyAlreadyExistsError } from './istorage'; export class RamStorage implements IStorage { hash = {}; constructor() { } get(k: string): Promise<any> { return Promise.resolve(this.hash[k]); }; set(k: string, v: any): Promise<void> { return new Promise<void>(resolve => { this.hash[k] = v; resolve(); }); }; remove(k: string): Promise<void> { return new Promise<void>(resolve => { delete this.hash[k]; resolve(); }); }; create(k: string, v: any): Promise<void> { return this.get(k).then((data) => { if (data) throw new KeyAlreadyExistsError(); this.set(k, v); }); }; }