-
Notifications
You must be signed in to change notification settings - Fork 18
/
userprofile.d.ts
144 lines (144 loc) · 5.58 KB
/
userprofile.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { ChainId, Identity, Nonce, SignedTransaction, TxCodec, UnsignedTransaction } from "@iov/bcp";
import { Ed25519Keypair, Slip10RawIndex } from "@iov/crypto";
import { ValueAndUpdates } from "@iov/stream";
import { AbstractLevelDOWN } from "abstract-leveldown";
import { LevelUp } from "levelup";
import { ReadonlyDate } from "readonly-date";
import { Keyring, WalletInfo } from "./keyring";
import { ReadonlyWallet, WalletId } from "./wallet";
export interface UserProfileEncryptionKey {
readonly formatVersion: number;
readonly data: Uint8Array;
}
/**
* An error class that allows handling an unexpected format version.
* It contains all the data needed to derive the encryption key in a different
* format version using UserProfile.deriveEncryptionKey.
*/
export declare class UnexpectedFormatVersionError extends Error {
readonly expectedFormatVersion: number;
readonly actualFormatVersion: number;
constructor(expected: number, actual: number);
}
export interface UserProfileOptions {
readonly createdAt: ReadonlyDate;
readonly keyring: Keyring;
}
/**
* All calls must go though the UserProfile. A newly created UserProfile
* is unlocked until lock() is called, which removes access to private key
* material. Once locked, a UserProfile cannot be unlocked anymore since the
* corresponding storage is not available anymore. Instead, re-create the
* UserProfile via the UserProfileController to get an unlocked UserProfile.
*/
export declare class UserProfile {
/**
* Derives an encryption key from the password. This is a computationally intense task that
* can take many seconds.
*
* Use this function to cache the encryption key in memory.
*
* @param formatVersion Set this if you got a UnexpectedFormatVersionError. This
* error usually means a profile was encrypted with an older format version.
*/
static deriveEncryptionKey(password: string, formatVersion?: number): Promise<UserProfileEncryptionKey>;
static loadFrom(
db: LevelUp<AbstractLevelDOWN<string, string>>,
encryptionSecret: string | UserProfileEncryptionKey,
): Promise<UserProfile>;
readonly createdAt: ReadonlyDate;
readonly locked: ValueAndUpdates<boolean>;
readonly wallets: ValueAndUpdates<readonly WalletInfo[]>;
private keyring;
private readonly lockedProducer;
private readonly walletsProducer;
/** Stores a copy of keyring */
constructor(options?: UserProfileOptions);
/**
* Stores this profile in an open database. This will erase all other data in that database.
*
* @param db the target database
* @param encryptionSecret a password or derivation key used for encryption
*/
storeIn(
db: LevelUp<AbstractLevelDOWN<string, string>>,
encryptionSecret: string | UserProfileEncryptionKey,
): Promise<void>;
lock(): void;
/**
* Adds a copy of the wallet to the primary keyring
*/
addWallet(wallet: ReadonlyWallet): WalletInfo;
/** Sets the label of the wallet with the given ID in the primary keyring */
setWalletLabel(walletId: WalletId, label: string | undefined): void;
/**
* Creates an identity in the wallet with the given ID in the primary keyring
*
* The identity is bound to one chain ID to encourage using different
* keypairs on different chains.
*/
createIdentity(
walletId: WalletId,
chainId: ChainId,
options: Ed25519Keypair | readonly Slip10RawIndex[] | number,
): Promise<Identity>;
/**
* Checks if an identity exists in the wallet with the given ID in the primary keyring
*
* **Example usage**
*
* This allows you to detect which accounts of an HD wallet have been created. Pseudocode
*
* ```
* identityExists("m/44'/234'/0'") == true
* identityExists("m/44'/234'/1'") == true
* identityExists("m/44'/234'/2'") == true
* identityExists("m/44'/234'/3'") == false
* // Shows that identities with account indices 0–2 have been created.
* ```
*/
identityExists(
walletId: WalletId,
chainId: ChainId,
options: Ed25519Keypair | readonly Slip10RawIndex[] | number,
): Promise<boolean>;
/** Assigns a label to one of the identities in the wallet with the given ID in the primary keyring */
setIdentityLabel(identity: Identity, label: string | undefined): void;
/**
* Gets the local label of one of the identities in the wallet with the given ID
* in the primary keyring
*/
getIdentityLabel(identity: Identity): string | undefined;
/** Get identities of the wallet with the given ID in the primary keyring */
getIdentities(id: WalletId): readonly Identity[];
/**
* All identities of the primary keyring
*/
getAllIdentities(): readonly Identity[];
/**
* Signs a transaction using the profile's primary keyring. The transaction's
* creator field specifies the keypair to be used for signing.
*/
signTransaction(transaction: UnsignedTransaction, codec: TxCodec, nonce: Nonce): Promise<SignedTransaction>;
appendSignature(
identity: Identity,
originalTransaction: SignedTransaction,
codec: TxCodec,
nonce: Nonce,
): Promise<SignedTransaction>;
/**
* Exposes the secret data of a wallet in a printable format for
* backup purposes.
*
* The format depends on the implementation and may change over time,
* so do not try to parse the result or make any kind of assumtions on
* how the result looks like.
*/
printableSecret(id: WalletId): string;
/** Throws if the primary keyring is not set, i.e. UserProfile is locked. */
private primaryKeyring;
/** Throws if wallet does not exist in primary keyring */
private findWalletInPrimaryKeyring;
private findWalletInPrimaryKeyringByIdentity;
private walletInfos;
}