@majikah/majik-key 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +67 -0
- package/README.md +911 -0
- package/dist/core/crypto/constants.d.ts +6 -0
- package/dist/core/crypto/constants.js +3 -0
- package/dist/core/crypto/crypto-provider.d.ts +21 -0
- package/dist/core/crypto/crypto-provider.js +74 -0
- package/dist/core/crypto/encryption-engine.d.ts +36 -0
- package/dist/core/crypto/encryption-engine.js +114 -0
- package/dist/core/database/system/identity.d.ts +61 -0
- package/dist/core/database/system/identity.js +171 -0
- package/dist/core/error.d.ts +4 -0
- package/dist/core/error.js +11 -0
- package/dist/core/majik-contact.d.ts +72 -0
- package/dist/core/majik-contact.js +195 -0
- package/dist/core/types.d.ts +19 -0
- package/dist/core/types.js +1 -0
- package/dist/core/utils.d.ts +28 -0
- package/dist/core/utils.js +107 -0
- package/dist/core/validator.d.ts +10 -0
- package/dist/core/validator.js +80 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/majik-key.d.ts +269 -0
- package/dist/majik-key.js +763 -0
- package/package.json +63 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { MajikContact } from "./core/majik-contact";
|
|
2
|
+
import { MajikKeyJSON, MnemonicJSON } from "./core/types";
|
|
3
|
+
import { MajikMessageIdentity } from "./core/database/system/identity";
|
|
4
|
+
import { MajikUser } from "@thezelijah/majik-user";
|
|
5
|
+
export interface MajikKeyIdentity {
|
|
6
|
+
id: string;
|
|
7
|
+
publicKey: CryptoKey | {
|
|
8
|
+
raw: Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
fingerprint: string;
|
|
11
|
+
privateKey: CryptoKey | {
|
|
12
|
+
raw: Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
encryptedPrivateKey: ArrayBuffer;
|
|
15
|
+
salt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SerializedIdentity {
|
|
18
|
+
id: string;
|
|
19
|
+
publicKey: string;
|
|
20
|
+
fingerprint: string;
|
|
21
|
+
encryptedPrivateKey?: string;
|
|
22
|
+
salt?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface MajikKeyConstructorOptions {
|
|
25
|
+
id: string;
|
|
26
|
+
publicKey: CryptoKey | {
|
|
27
|
+
raw: Uint8Array;
|
|
28
|
+
};
|
|
29
|
+
publicKeyBase64: string;
|
|
30
|
+
fingerprint: string;
|
|
31
|
+
encryptedPrivateKey: ArrayBuffer;
|
|
32
|
+
encryptedPrivateKeyBase64: string;
|
|
33
|
+
salt: string;
|
|
34
|
+
backup: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
timestamp?: Date;
|
|
37
|
+
privateKey?: CryptoKey | {
|
|
38
|
+
raw: Uint8Array;
|
|
39
|
+
};
|
|
40
|
+
privateKeyBase64?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface MajikKeyMetadata {
|
|
43
|
+
id: string;
|
|
44
|
+
fingerprint: string;
|
|
45
|
+
label: string;
|
|
46
|
+
timestamp: Date;
|
|
47
|
+
isLocked: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* MajikKey
|
|
51
|
+
* ----------------
|
|
52
|
+
* A seed phrase account library for creating, managing, and parsing mnemonic-based cryptographic accounts (Majik Keys).
|
|
53
|
+
* Generate deterministic key pairs from BIP39 seed phrases with simple, developer-friendly APIs.
|
|
54
|
+
*/
|
|
55
|
+
export declare class MajikKey {
|
|
56
|
+
private readonly _id;
|
|
57
|
+
private readonly _publicKey;
|
|
58
|
+
private readonly _publicKeyBase64;
|
|
59
|
+
private readonly _fingerprint;
|
|
60
|
+
private readonly _backup;
|
|
61
|
+
private readonly _timestamp;
|
|
62
|
+
private _encryptedPrivateKey;
|
|
63
|
+
private _encryptedPrivateKeyBase64;
|
|
64
|
+
private _salt;
|
|
65
|
+
private _label;
|
|
66
|
+
private _privateKey?;
|
|
67
|
+
private _privateKeyBase64?;
|
|
68
|
+
private constructor();
|
|
69
|
+
get id(): string;
|
|
70
|
+
get fingerprint(): string;
|
|
71
|
+
get publicKey(): CryptoKey | {
|
|
72
|
+
raw: Uint8Array;
|
|
73
|
+
};
|
|
74
|
+
get publicKeyBase64(): string;
|
|
75
|
+
get label(): string;
|
|
76
|
+
get backup(): string;
|
|
77
|
+
get timestamp(): Date;
|
|
78
|
+
get isLocked(): boolean;
|
|
79
|
+
get isUnlocked(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get safe metadata (no sensitive data)
|
|
82
|
+
*/
|
|
83
|
+
get metadata(): MajikKeyMetadata;
|
|
84
|
+
/**
|
|
85
|
+
* CREATE: Generate a new MajikKey from a mnemonic phrase.
|
|
86
|
+
* The key is created in an unlocked state with private keys available.
|
|
87
|
+
*
|
|
88
|
+
* @param mnemonic - BIP39 mnemonic phrase (12-24 words)
|
|
89
|
+
* @param passphrase - Passphrase to encrypt the private key at rest
|
|
90
|
+
* @param label - Optional label for the key
|
|
91
|
+
* @returns A new unlocked MajikKey instance
|
|
92
|
+
*/
|
|
93
|
+
static create(mnemonic: string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
94
|
+
/**
|
|
95
|
+
* Export this MajikKey to MnemonicJSON format.
|
|
96
|
+
* This format is useful for storing mnemonic data with an optional passphrase.
|
|
97
|
+
*
|
|
98
|
+
* @param mnemonic - The BIP39 mnemonic phrase
|
|
99
|
+
* @param passphrase - Optional passphrase (encryption password, not BIP39 passphrase)
|
|
100
|
+
* @returns MnemonicJSON object
|
|
101
|
+
*/
|
|
102
|
+
toMnemonicJSON(mnemonic: string, passphrase?: string): MnemonicJSON;
|
|
103
|
+
/**
|
|
104
|
+
* Create a MajikKey from MnemonicJSON format.
|
|
105
|
+
*
|
|
106
|
+
* @param mnemonicJson - MnemonicJSON object or string
|
|
107
|
+
* @param passphrase - Passphrase to encrypt the key at rest
|
|
108
|
+
* @param label - Optional label for the key
|
|
109
|
+
* @returns A new unlocked MajikKey instance
|
|
110
|
+
*/
|
|
111
|
+
static fromMnemonicJSON(mnemonicJson: MnemonicJSON | string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
112
|
+
/**
|
|
113
|
+
* READ: Load a MajikKey from JSON (locked state).
|
|
114
|
+
* The key must be unlocked with the unlock() method before accessing private keys.
|
|
115
|
+
*
|
|
116
|
+
* @param json - JSON string or object
|
|
117
|
+
* @returns A locked MajikKey instance
|
|
118
|
+
*/
|
|
119
|
+
static fromJSON(json: MajikKeyJSON | string): MajikKey;
|
|
120
|
+
/**
|
|
121
|
+
* UPDATE: Change the label of this MajikKey.
|
|
122
|
+
*
|
|
123
|
+
* @param newLabel - New label value
|
|
124
|
+
* @returns This instance for chaining
|
|
125
|
+
*/
|
|
126
|
+
updateLabel(newLabel: string): this;
|
|
127
|
+
/**
|
|
128
|
+
* UPDATE: Change the passphrase used to encrypt the private key.
|
|
129
|
+
* Requires the current passphrase for verification.
|
|
130
|
+
*
|
|
131
|
+
* @param currentPassphrase - Current passphrase
|
|
132
|
+
* @param newPassphrase - New passphrase
|
|
133
|
+
* @returns This instance for chaining
|
|
134
|
+
*/
|
|
135
|
+
updatePassphrase(currentPassphrase: string, newPassphrase: string): Promise<this>;
|
|
136
|
+
/**
|
|
137
|
+
* DELETE: Securely lock this MajikKey by clearing private keys from memory.
|
|
138
|
+
* The encrypted private key remains stored for future unlocking.
|
|
139
|
+
*
|
|
140
|
+
* @returns This instance for chaining
|
|
141
|
+
*/
|
|
142
|
+
lock(): this;
|
|
143
|
+
/**
|
|
144
|
+
* Unlock this MajikKey by decrypting the private key with the passphrase.
|
|
145
|
+
* Sets the private key in memory for cryptographic operations.
|
|
146
|
+
*
|
|
147
|
+
* @param passphrase - Passphrase to decrypt the private key
|
|
148
|
+
* @returns This instance for chaining
|
|
149
|
+
* @throws MajikKeyError if passphrase is incorrect or key is already unlocked
|
|
150
|
+
*/
|
|
151
|
+
unlock(passphrase: string): Promise<this>;
|
|
152
|
+
/**
|
|
153
|
+
* Verify that the encrypted private key can be decrypted with passphrase
|
|
154
|
+
*/
|
|
155
|
+
verify(passphrase: string): Promise<boolean>;
|
|
156
|
+
/**
|
|
157
|
+
* Get the private key (only available when unlocked).
|
|
158
|
+
*
|
|
159
|
+
* @returns The private key
|
|
160
|
+
* @throws MajikKeyError if the key is locked
|
|
161
|
+
*/
|
|
162
|
+
getPrivateKey(): CryptoKey | {
|
|
163
|
+
raw: Uint8Array;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Get the private key as base64 (only available when unlocked).
|
|
167
|
+
*
|
|
168
|
+
* @returns The private key in base64 format
|
|
169
|
+
* @throws MajikKeyError if the key is locked
|
|
170
|
+
*/
|
|
171
|
+
getPrivateKeyBase64(): string;
|
|
172
|
+
/**
|
|
173
|
+
* Export this MajikKey to JSON format (safe for storage).
|
|
174
|
+
* Private keys are never included in the JSON output.
|
|
175
|
+
*
|
|
176
|
+
* @returns JSON representation of this MajikKey
|
|
177
|
+
*/
|
|
178
|
+
toJSON(): MajikKeyJSON;
|
|
179
|
+
/**
|
|
180
|
+
* Export this MajikKey to a JSON string.
|
|
181
|
+
*
|
|
182
|
+
* @param pretty - Whether to pretty-print the JSON
|
|
183
|
+
* @returns JSON string representation
|
|
184
|
+
*/
|
|
185
|
+
toString(pretty?: boolean): string;
|
|
186
|
+
/**
|
|
187
|
+
* Generate a new BIP39 mnemonic phrase.
|
|
188
|
+
*
|
|
189
|
+
* @param strength - Entropy strength in bits (128 = 12 words, 256 = 24 words)
|
|
190
|
+
* @returns A new mnemonic phrase
|
|
191
|
+
*/
|
|
192
|
+
static generateMnemonic(strength?: 128 | 256): string;
|
|
193
|
+
/**
|
|
194
|
+
* Validate a BIP39 mnemonic phrase.
|
|
195
|
+
*
|
|
196
|
+
* @param mnemonic - Mnemonic phrase to validate
|
|
197
|
+
* @returns true if valid, false otherwise
|
|
198
|
+
*/
|
|
199
|
+
static validateMnemonic(mnemonic: string): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Create a MajikContact from this MajikKey.
|
|
202
|
+
*
|
|
203
|
+
* @returns A MajikContact instance
|
|
204
|
+
*/
|
|
205
|
+
toContact(): MajikContact;
|
|
206
|
+
/**
|
|
207
|
+
* Convert to internal MajikKeyIdentity format (for backward compatibility).
|
|
208
|
+
* Note: Only includes privateKey if unlocked.
|
|
209
|
+
*
|
|
210
|
+
* @returns MajikKeyIdentity object
|
|
211
|
+
*/
|
|
212
|
+
toKeyIdentity(): MajikKeyIdentity;
|
|
213
|
+
/**
|
|
214
|
+
* Convert to internal SerializedIdentity format (for Majik Message).
|
|
215
|
+
*
|
|
216
|
+
* @returns SerializedIdentity object
|
|
217
|
+
*/
|
|
218
|
+
toSerializedIdentity(): SerializedIdentity;
|
|
219
|
+
toMajikMessageIdentity(user: MajikUser, options?: {
|
|
220
|
+
label?: string;
|
|
221
|
+
restricted?: boolean;
|
|
222
|
+
}): Promise<MajikMessageIdentity>;
|
|
223
|
+
/**
|
|
224
|
+
* Export a mnemonic-encrypted backup for this MajikKey.
|
|
225
|
+
* Requires the key to be unlocked.
|
|
226
|
+
*
|
|
227
|
+
* @param mnemonic - The original mnemonic phrase
|
|
228
|
+
* @returns Base64-encoded backup string
|
|
229
|
+
*/
|
|
230
|
+
exportMnemonicBackup(mnemonic: string): Promise<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Import a MajikKey from a mnemonic-encrypted backup.
|
|
233
|
+
*
|
|
234
|
+
* @param backup - Base64-encoded backup string
|
|
235
|
+
* @param mnemonic - The mnemonic phrase used to encrypt the backup
|
|
236
|
+
* @param passphrase - Passphrase to encrypt the imported key
|
|
237
|
+
* @param label - Optional label for the imported key
|
|
238
|
+
* @returns A new unlocked MajikKey instance
|
|
239
|
+
*/
|
|
240
|
+
static importFromMnemonicBackup(backup: string, mnemonic: string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a deterministic identity from a mnemonic and encrypt it with passphrase.
|
|
243
|
+
* The identity `id` is set to the fingerprint for stable referencing.
|
|
244
|
+
*/
|
|
245
|
+
private static createIdentityFromMnemonic;
|
|
246
|
+
/**
|
|
247
|
+
* Export an identity encrypted with a mnemonic-derived key.
|
|
248
|
+
* Returns a base64 string containing iv+ciphertext and publicKey/fingerprint in JSON.
|
|
249
|
+
*/
|
|
250
|
+
private static exportIdentityMnemonicBackup;
|
|
251
|
+
/**
|
|
252
|
+
* Encrypt a private key with a passphrase.
|
|
253
|
+
*/
|
|
254
|
+
private static encryptPrivateKey;
|
|
255
|
+
/**
|
|
256
|
+
* Decrypt a private key with a passphrase.
|
|
257
|
+
*/
|
|
258
|
+
private static decryptPrivateKey;
|
|
259
|
+
private static deriveKeyFromMnemonic;
|
|
260
|
+
/**
|
|
261
|
+
* Validate whether a passphrase can decrypt the stored private key.
|
|
262
|
+
* Does NOT unlock or mutate any in-memory state.
|
|
263
|
+
*/
|
|
264
|
+
private static isPassphraseValid;
|
|
265
|
+
/**
|
|
266
|
+
* Export a CryptoKey to base64 string.
|
|
267
|
+
*/
|
|
268
|
+
private static exportKeyToBase64;
|
|
269
|
+
}
|