@majikah/majik-key 0.2.7 → 0.2.10
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 +66 -66
- package/README.md +1 -1
- package/dist/core/crypto/crypto-provider.d.ts +8 -8
- package/dist/core/crypto/crypto-provider.js +1 -1
- package/dist/core/crypto/wordlist.d.ts +13 -0
- package/dist/core/crypto/wordlist.js +12 -0
- package/dist/core/types.d.ts +3 -0
- package/dist/core/validator.js +0 -5
- package/dist/majik-key.d.ts +14 -5
- package/dist/majik-key.js +43 -8
- package/package.json +15 -9
- package/dist/core/majik-contact.d.ts +0 -89
- package/dist/core/majik-contact.js +0 -212
package/LICENSE
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
Copyright (c) 2025 Josef Elijah Delos Santos Fabian
|
|
2
|
-
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
|
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
See the License for the specific language governing permissions and
|
|
13
|
-
limitations under the License.
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
Apache License
|
|
18
|
-
Version 2.0, January 2004
|
|
19
|
-
http://www.apache.org/licenses/
|
|
20
|
-
|
|
21
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
-
|
|
23
|
-
1. Definitions.
|
|
24
|
-
|
|
25
|
-
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
26
|
-
|
|
27
|
-
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
28
|
-
|
|
29
|
-
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
-
|
|
31
|
-
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
32
|
-
|
|
33
|
-
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
34
|
-
|
|
35
|
-
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
36
|
-
|
|
37
|
-
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
-
|
|
39
|
-
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
40
|
-
|
|
41
|
-
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
42
|
-
|
|
43
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
44
|
-
|
|
45
|
-
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
46
|
-
|
|
47
|
-
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
48
|
-
|
|
49
|
-
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
50
|
-
|
|
51
|
-
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
52
|
-
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
53
|
-
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
54
|
-
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
55
|
-
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
56
|
-
|
|
57
|
-
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
58
|
-
|
|
59
|
-
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
60
|
-
|
|
61
|
-
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
-
|
|
63
|
-
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
64
|
-
|
|
65
|
-
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
66
|
-
|
|
1
|
+
Copyright (c) 2025 Josef Elijah Delos Santos Fabian
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
Apache License
|
|
18
|
+
Version 2.0, January 2004
|
|
19
|
+
http://www.apache.org/licenses/
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
26
|
+
|
|
27
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
28
|
+
|
|
29
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
32
|
+
|
|
33
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
40
|
+
|
|
41
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
42
|
+
|
|
43
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
44
|
+
|
|
45
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
46
|
+
|
|
47
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
48
|
+
|
|
49
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
50
|
+
|
|
51
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
52
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
53
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
54
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
55
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
56
|
+
|
|
57
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
58
|
+
|
|
59
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
60
|
+
|
|
61
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
64
|
+
|
|
65
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
66
|
+
|
|
67
67
|
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -893,7 +893,7 @@ Secure messaging platform using Majik Keys
|
|
|
893
893
|
|
|
894
894
|
[Read more about Majik Message here](https://majikah.solutions/products/majik-message)
|
|
895
895
|
|
|
896
|
-
[](https://message.majikah.solutions)
|
|
897
897
|
|
|
898
898
|
> Click the image to try Majik Message live.
|
|
899
899
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export declare const IV_LENGTH = 12;
|
|
2
2
|
export declare function generateRandomBytes(len: number): Uint8Array;
|
|
3
3
|
export declare function generateEd25519Keypair(): {
|
|
4
|
-
edPublic: Uint8Array
|
|
5
|
-
edSecret: Uint8Array
|
|
6
|
-
xPublic: Uint8Array | null;
|
|
7
|
-
xSecret: Uint8Array | null;
|
|
4
|
+
edPublic: Uint8Array<ArrayBufferLike>;
|
|
5
|
+
edSecret: Uint8Array<ArrayBufferLike>;
|
|
6
|
+
xPublic: Uint8Array<ArrayBuffer> | null;
|
|
7
|
+
xSecret: Uint8Array<ArrayBuffer> | null;
|
|
8
8
|
};
|
|
9
9
|
export declare function deriveEd25519FromSeed(seed32: Uint8Array): {
|
|
10
|
-
edPublic: Uint8Array
|
|
11
|
-
edSecret: Uint8Array
|
|
12
|
-
xPublic: Uint8Array | null;
|
|
13
|
-
xSecret: Uint8Array | null;
|
|
10
|
+
edPublic: Uint8Array<ArrayBufferLike>;
|
|
11
|
+
edSecret: Uint8Array<ArrayBufferLike>;
|
|
12
|
+
xPublic: Uint8Array<ArrayBuffer> | null;
|
|
13
|
+
xSecret: Uint8Array<ArrayBuffer> | null;
|
|
14
14
|
};
|
|
15
15
|
export declare function fingerprintFromPublicRaw(rawPublic: Uint8Array): string;
|
|
16
16
|
export declare function aesGcmEncrypt(keyBytes: Uint8Array, iv: Uint8Array, plaintext: Uint8Array): Uint8Array;
|
|
@@ -117,7 +117,7 @@ async function _argon2id(input, salt, params) {
|
|
|
117
117
|
// WASM loaded but failed at runtime (e.g. OOM, corrupted module)
|
|
118
118
|
// Flip flag so we stop trying for the rest of this session
|
|
119
119
|
_wasmAvailable = false;
|
|
120
|
-
console.warn("[majikah/crypto] hash-wasm runtime failure, falling back to @noble/hashes", err);
|
|
120
|
+
console.warn("[majikah/majik-key/crypto] hash-wasm runtime failure, falling back to @noble/hashes", err);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
return _argon2idNoble(input, salt, params);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type MnemonicLanguage = "en" | "fr" | "es" | "it" | "ja" | "ko" | "czech" | "pt" | "zh-cn" | "zh-tw";
|
|
2
|
+
export declare const WORDLISTS: {
|
|
3
|
+
readonly en: () => Promise<typeof import("@scure/bip39/wordlists/english.js")>;
|
|
4
|
+
readonly fr: () => Promise<typeof import("@scure/bip39/wordlists/french.js")>;
|
|
5
|
+
readonly es: () => Promise<typeof import("@scure/bip39/wordlists/spanish.js")>;
|
|
6
|
+
readonly it: () => Promise<typeof import("@scure/bip39/wordlists/italian.js")>;
|
|
7
|
+
readonly ja: () => Promise<typeof import("@scure/bip39/wordlists/japanese.js")>;
|
|
8
|
+
readonly ko: () => Promise<typeof import("@scure/bip39/wordlists/korean.js")>;
|
|
9
|
+
readonly pt: () => Promise<typeof import("@scure/bip39/wordlists/portuguese.js")>;
|
|
10
|
+
readonly czech: () => Promise<typeof import("@scure/bip39/wordlists/czech.js")>;
|
|
11
|
+
readonly "zh-cn": () => Promise<typeof import("@scure/bip39/wordlists/simplified-chinese.js")>;
|
|
12
|
+
readonly "zh-tw": () => Promise<typeof import("@scure/bip39/wordlists/traditional-chinese.js")>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const WORDLISTS = {
|
|
2
|
+
en: () => import("@scure/bip39/wordlists/english.js"),
|
|
3
|
+
fr: () => import("@scure/bip39/wordlists/french.js"),
|
|
4
|
+
es: () => import("@scure/bip39/wordlists/spanish.js"),
|
|
5
|
+
it: () => import("@scure/bip39/wordlists/italian.js"),
|
|
6
|
+
ja: () => import("@scure/bip39/wordlists/japanese.js"),
|
|
7
|
+
ko: () => import("@scure/bip39/wordlists/korean.js"),
|
|
8
|
+
pt: () => import("@scure/bip39/wordlists/portuguese.js"),
|
|
9
|
+
czech: () => import("@scure/bip39/wordlists/czech.js"),
|
|
10
|
+
"zh-cn": () => import("@scure/bip39/wordlists/simplified-chinese.js"),
|
|
11
|
+
"zh-tw": () => import("@scure/bip39/wordlists/traditional-chinese.js"),
|
|
12
|
+
};
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MnemonicLanguage } from "./crypto/wordlist";
|
|
1
2
|
export type ISODateString = string;
|
|
2
3
|
export type MajikMessageAccountID = string;
|
|
3
4
|
export type MajikMessagePublicKey = string;
|
|
@@ -18,6 +19,7 @@ export interface MajikKeyJSON {
|
|
|
18
19
|
encryptedEdSecretKey?: string;
|
|
19
20
|
mlDsaPublicKey?: string;
|
|
20
21
|
encryptedMlDsaSecretKey?: string;
|
|
22
|
+
mnemonicLanguage?: MnemonicLanguage;
|
|
21
23
|
}
|
|
22
24
|
export interface MajikKeyMetadata {
|
|
23
25
|
id: string;
|
|
@@ -27,6 +29,7 @@ export interface MajikKeyMetadata {
|
|
|
27
29
|
isLocked: boolean;
|
|
28
30
|
kdfVersion: number;
|
|
29
31
|
hasMlKem: boolean;
|
|
32
|
+
mnemonicLanguage?: MnemonicLanguage;
|
|
30
33
|
}
|
|
31
34
|
export interface MnemonicJSON {
|
|
32
35
|
seed: string[];
|
package/dist/core/validator.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { validateMnemonic } from "@scure/bip39";
|
|
2
|
-
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
3
1
|
/* -------------------------------
|
|
4
2
|
* Validators
|
|
5
3
|
* ------------------------------- */
|
|
@@ -13,9 +11,6 @@ export class MajikKeyValidator {
|
|
|
13
11
|
if (!trimmed) {
|
|
14
12
|
throw new MajikKeyError("Mnemonic cannot be empty or whitespace");
|
|
15
13
|
}
|
|
16
|
-
if (!validateMnemonic(trimmed, wordlist)) {
|
|
17
|
-
throw new MajikKeyError("Invalid BIP39 mnemonic phrase");
|
|
18
|
-
}
|
|
19
14
|
}
|
|
20
15
|
static validatePassphrase(passphrase, fieldName = "Passphrase") {
|
|
21
16
|
if (!passphrase || typeof passphrase !== "string") {
|
package/dist/majik-key.d.ts
CHANGED
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
* point, so ML-KEM keys can be deterministically re-derived and stored.
|
|
22
22
|
* No partial migration — either fully upgraded or not upgraded yet.
|
|
23
23
|
*/
|
|
24
|
-
import { MajikContact } from "@majikah/majik-contact";
|
|
24
|
+
import { MajikContact, MajikContactMeta } from "@majikah/majik-contact";
|
|
25
25
|
import { KDF_VERSION } from "./core/crypto/constants";
|
|
26
26
|
import type { MajikKeyJSON, MajikKeyMetadata, MnemonicJSON } from "./core/types";
|
|
27
27
|
import { MajikMessageIdentity } from "./core/database/system/identity";
|
|
28
28
|
import { MajikUser } from "@thezelijah/majik-user";
|
|
29
|
+
import { MnemonicLanguage } from "./core/crypto/wordlist";
|
|
29
30
|
export interface MajikKeyIdentity {
|
|
30
31
|
id: string;
|
|
31
32
|
publicKey: CryptoKey | {
|
|
@@ -87,6 +88,7 @@ export interface MajikKeyConstructorOptions {
|
|
|
87
88
|
encryptedMlDsaSecretKeyBase64?: string;
|
|
88
89
|
edSecretKey?: Uint8Array;
|
|
89
90
|
mlDsaSecretKey?: Uint8Array;
|
|
91
|
+
mnemonicLanguage?: MnemonicLanguage;
|
|
90
92
|
}
|
|
91
93
|
export declare class MajikKey {
|
|
92
94
|
private readonly _id;
|
|
@@ -95,6 +97,7 @@ export declare class MajikKey {
|
|
|
95
97
|
private readonly _fingerprint;
|
|
96
98
|
private readonly _backup;
|
|
97
99
|
private readonly _timestamp;
|
|
100
|
+
private readonly _mnemonicLanguage;
|
|
98
101
|
private _encryptedPrivateKey;
|
|
99
102
|
private _encryptedPrivateKeyBase64;
|
|
100
103
|
private _salt;
|
|
@@ -122,6 +125,7 @@ export declare class MajikKey {
|
|
|
122
125
|
};
|
|
123
126
|
get publicKeyBase64(): string;
|
|
124
127
|
get label(): string;
|
|
128
|
+
get mnemonicLanguage(): MnemonicLanguage;
|
|
125
129
|
get backup(): string;
|
|
126
130
|
get timestamp(): Date;
|
|
127
131
|
get kdfVersion(): KDF_VERSION;
|
|
@@ -136,7 +140,7 @@ export declare class MajikKey {
|
|
|
136
140
|
get edPublicKey(): Uint8Array | undefined;
|
|
137
141
|
get mlDsaPublicKey(): Uint8Array | undefined;
|
|
138
142
|
get hasSigningKeys(): boolean;
|
|
139
|
-
static create(mnemonic: string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
143
|
+
static create(mnemonic: string, passphrase: string, label?: string, mnemonicLanguage?: MnemonicLanguage): Promise<MajikKey>;
|
|
140
144
|
static fromJSON(json: MajikKeyJSON | string): MajikKey;
|
|
141
145
|
toMnemonicJSON(mnemonic: string, passphrase?: string): MnemonicJSON;
|
|
142
146
|
static fromMnemonicJSON(mnemonicJson: MnemonicJSON | string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
@@ -159,9 +163,13 @@ export declare class MajikKey {
|
|
|
159
163
|
getMlDsaSecretKey(): Uint8Array;
|
|
160
164
|
toJSON(): MajikKeyJSON;
|
|
161
165
|
toString(pretty?: boolean): string;
|
|
162
|
-
static generateMnemonic(strength?: 128 | 256): string
|
|
166
|
+
static generateMnemonic(strength?: 128 | 256, language?: MnemonicLanguage): Promise<string>;
|
|
163
167
|
static validateMnemonic(mnemonic: string): boolean;
|
|
164
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Converts the MajikKey to a MajikContact.
|
|
170
|
+
* You can pass a custom metadata type if needed, e.g., toContact<MyMeta>()
|
|
171
|
+
*/
|
|
172
|
+
toContact<TMeta extends MajikContactMeta = MajikContactMeta>(initialMeta?: Partial<TMeta>): MajikContact<TMeta>;
|
|
165
173
|
toKeyIdentity(): MajikKeyIdentity;
|
|
166
174
|
toSerializedIdentity(): SerializedIdentity;
|
|
167
175
|
toMajikMessageIdentity(user: MajikUser, options?: {
|
|
@@ -181,7 +189,8 @@ export declare class MajikKey {
|
|
|
181
189
|
* Old accounts without ML-KEM keys become fully post-quantum capable
|
|
182
190
|
* automatically — no extra user steps. The mnemonic is the source of truth.
|
|
183
191
|
*/
|
|
184
|
-
static importFromMnemonicBackup(backup: string, mnemonic: string, passphrase: string, label?: string): Promise<MajikKey>;
|
|
192
|
+
static importFromMnemonicBackup(backup: string, mnemonic: string, passphrase: string, label?: string, mnemonicLanguage?: MnemonicLanguage): Promise<MajikKey>;
|
|
193
|
+
private static _getWordlist;
|
|
185
194
|
private static _deriveAndEncryptFromMnemonic;
|
|
186
195
|
private static _encryptPrivateKey;
|
|
187
196
|
/**
|
package/dist/majik-key.js
CHANGED
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
* point, so ML-KEM keys can be deterministically re-derived and stored.
|
|
22
22
|
* No partial migration — either fully upgraded or not upgraded yet.
|
|
23
23
|
*/
|
|
24
|
-
import { generateMnemonic } from "@scure/bip39";
|
|
24
|
+
import { generateMnemonic as bip39GenerateMnemonic, validateMnemonic, } from "@scure/bip39";
|
|
25
25
|
import { aesGcmDecrypt, aesGcmEncrypt, deriveKeyFromPassphraseArgon2, deriveKeyFromMnemonicArgon2, deriveKeyFromPassphrase, generateRandomBytes, IV_LENGTH, } from "./core/crypto/crypto-provider";
|
|
26
26
|
import { EncryptionEngine } from "./core/crypto/encryption-engine";
|
|
27
27
|
import { MajikContact } from "@majikah/majik-contact";
|
|
28
28
|
import { arrayBufferToBase64, arrayToBase64, base64ToArrayBuffer, concatUint8Arrays, utf8ToBase64, base64ToUtf8, seedStringToArray, seedArrayToString, base64ToUint8Array, } from "./core/utils";
|
|
29
|
-
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
30
29
|
import { KDF_VERSION, KEY_ALGO, MAJIK_MNEMONIC_SALT, } from "./core/crypto/constants";
|
|
31
30
|
import { MajikKeyValidator } from "./core/validator";
|
|
32
31
|
import { MajikKeyError } from "./core/error";
|
|
33
32
|
import { MajikMessageIdentity } from "./core/database/system/identity";
|
|
33
|
+
import { WORDLISTS } from "./core/crypto/wordlist";
|
|
34
34
|
const SALT_SIZE = 32;
|
|
35
35
|
// ─── MajikKey ─────────────────────────────────────────────────────────────────
|
|
36
36
|
export class MajikKey {
|
|
@@ -40,6 +40,7 @@ export class MajikKey {
|
|
|
40
40
|
_fingerprint;
|
|
41
41
|
_backup;
|
|
42
42
|
_timestamp;
|
|
43
|
+
_mnemonicLanguage;
|
|
43
44
|
_encryptedPrivateKey;
|
|
44
45
|
_encryptedPrivateKeyBase64;
|
|
45
46
|
_salt;
|
|
@@ -85,6 +86,7 @@ export class MajikKey {
|
|
|
85
86
|
this._encryptedMlDsaSecretKeyBase64 = options.encryptedMlDsaSecretKeyBase64;
|
|
86
87
|
this._edSecretKey = options.edSecretKey;
|
|
87
88
|
this._mlDsaSecretKey = options.mlDsaSecretKey;
|
|
89
|
+
this._mnemonicLanguage = options.mnemonicLanguage || "en";
|
|
88
90
|
}
|
|
89
91
|
// ── Getters ─────────────────────────────────────────────────────────────────
|
|
90
92
|
get id() {
|
|
@@ -102,6 +104,9 @@ export class MajikKey {
|
|
|
102
104
|
get label() {
|
|
103
105
|
return this._label;
|
|
104
106
|
}
|
|
107
|
+
get mnemonicLanguage() {
|
|
108
|
+
return this._mnemonicLanguage;
|
|
109
|
+
}
|
|
105
110
|
get backup() {
|
|
106
111
|
return this._backup;
|
|
107
112
|
}
|
|
@@ -141,6 +146,7 @@ export class MajikKey {
|
|
|
141
146
|
isLocked: this.isLocked,
|
|
142
147
|
kdfVersion: this.kdfVersion,
|
|
143
148
|
hasMlKem: this.hasMlKem,
|
|
149
|
+
mnemonicLanguage: this.mnemonicLanguage || "en",
|
|
144
150
|
};
|
|
145
151
|
}
|
|
146
152
|
get edPublicKey() {
|
|
@@ -153,11 +159,15 @@ export class MajikKey {
|
|
|
153
159
|
return (this._edPublicKey !== undefined && this._mlDsaPublicKey !== undefined);
|
|
154
160
|
}
|
|
155
161
|
// ── CREATE ──────────────────────────────────────────────────────────────────
|
|
156
|
-
static async create(mnemonic, passphrase, label) {
|
|
162
|
+
static async create(mnemonic, passphrase, label, mnemonicLanguage = "en") {
|
|
157
163
|
try {
|
|
158
164
|
MajikKeyValidator.validateMnemonic(mnemonic);
|
|
159
165
|
MajikKeyValidator.validatePassphrase(passphrase);
|
|
160
166
|
MajikKeyValidator.validateLabel(label);
|
|
167
|
+
const wordlist = await MajikKey._getWordlist(mnemonicLanguage);
|
|
168
|
+
if (!validateMnemonic(mnemonic, wordlist)) {
|
|
169
|
+
throw new MajikKeyError("Invalid BIP39 mnemonic phrase");
|
|
170
|
+
}
|
|
161
171
|
const identity = await MajikKey._deriveAndEncryptFromMnemonic(mnemonic, passphrase);
|
|
162
172
|
const privateKeyBase64 = await MajikKey._exportKeyToBase64(identity.privateKey);
|
|
163
173
|
const publicKeyBase64 = await MajikKey._exportKeyToBase64(identity.publicKey);
|
|
@@ -188,6 +198,7 @@ export class MajikKey {
|
|
|
188
198
|
encryptedMlDsaSecretKeyBase64: arrayBufferToBase64(identity.encryptedMlDsaSecretKey),
|
|
189
199
|
edSecretKey: identity.edSecretKey,
|
|
190
200
|
mlDsaSecretKey: identity.mlDsaSecretKey,
|
|
201
|
+
mnemonicLanguage: mnemonicLanguage,
|
|
191
202
|
});
|
|
192
203
|
}
|
|
193
204
|
catch (err) {
|
|
@@ -251,6 +262,7 @@ export class MajikKey {
|
|
|
251
262
|
mlDsaPublicKey,
|
|
252
263
|
encryptedMlDsaSecretKey,
|
|
253
264
|
encryptedMlDsaSecretKeyBase64,
|
|
265
|
+
mnemonicLanguage: validated?.mnemonicLanguage || "en",
|
|
254
266
|
});
|
|
255
267
|
}
|
|
256
268
|
catch (err) {
|
|
@@ -475,16 +487,21 @@ export class MajikKey {
|
|
|
475
487
|
? arrayToBase64(this._mlDsaPublicKey)
|
|
476
488
|
: undefined,
|
|
477
489
|
encryptedMlDsaSecretKey: this._encryptedMlDsaSecretKeyBase64,
|
|
490
|
+
mnemonicLanguage: this._mnemonicLanguage,
|
|
478
491
|
};
|
|
479
492
|
}
|
|
480
493
|
toString(pretty = false) {
|
|
481
494
|
return JSON.stringify(this.toJSON(), null, pretty ? 2 : 0);
|
|
482
495
|
}
|
|
483
496
|
// ── UTILITY ──────────────────────────────────────────────────────────────────
|
|
484
|
-
static generateMnemonic(strength = 128) {
|
|
497
|
+
static async generateMnemonic(strength = 128, language = "en") {
|
|
485
498
|
if (strength !== 128 && strength !== 256)
|
|
486
499
|
throw new MajikKeyError("Strength must be 128 or 256");
|
|
487
|
-
|
|
500
|
+
const loader = WORDLISTS[language];
|
|
501
|
+
if (!loader)
|
|
502
|
+
throw new MajikKeyError("Unsupported language");
|
|
503
|
+
const wordlist = await MajikKey._getWordlist(language);
|
|
504
|
+
return bip39GenerateMnemonic(wordlist, strength);
|
|
488
505
|
}
|
|
489
506
|
static validateMnemonic(mnemonic) {
|
|
490
507
|
try {
|
|
@@ -495,13 +512,22 @@ export class MajikKey {
|
|
|
495
512
|
return false;
|
|
496
513
|
}
|
|
497
514
|
}
|
|
498
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Converts the MajikKey to a MajikContact.
|
|
517
|
+
* You can pass a custom metadata type if needed, e.g., toContact<MyMeta>()
|
|
518
|
+
*/
|
|
519
|
+
toContact(initialMeta) {
|
|
499
520
|
const mlKeyBase64 = arrayToBase64(this.mlKemPublicKey);
|
|
521
|
+
// We construct the base metadata and merge with any provided initialMeta
|
|
522
|
+
const meta = {
|
|
523
|
+
label: this._label,
|
|
524
|
+
...initialMeta,
|
|
525
|
+
};
|
|
500
526
|
return new MajikContact({
|
|
501
527
|
id: this._id,
|
|
502
528
|
publicKey: this._publicKey,
|
|
503
529
|
fingerprint: this._fingerprint,
|
|
504
|
-
meta:
|
|
530
|
+
meta: meta,
|
|
505
531
|
mlKey: mlKeyBase64,
|
|
506
532
|
edPublicKeyBase64: this._edPublicKey
|
|
507
533
|
? arrayToBase64(this._edPublicKey)
|
|
@@ -564,13 +590,17 @@ export class MajikKey {
|
|
|
564
590
|
* Old accounts without ML-KEM keys become fully post-quantum capable
|
|
565
591
|
* automatically — no extra user steps. The mnemonic is the source of truth.
|
|
566
592
|
*/
|
|
567
|
-
static async importFromMnemonicBackup(backup, mnemonic, passphrase, label) {
|
|
593
|
+
static async importFromMnemonicBackup(backup, mnemonic, passphrase, label, mnemonicLanguage = "en") {
|
|
568
594
|
try {
|
|
569
595
|
if (!backup || typeof backup !== "string")
|
|
570
596
|
throw new MajikKeyError("Backup must be a non-empty string");
|
|
571
597
|
MajikKeyValidator.validateMnemonic(mnemonic);
|
|
572
598
|
MajikKeyValidator.validatePassphrase(passphrase);
|
|
573
599
|
MajikKeyValidator.validateLabel(label);
|
|
600
|
+
const wordlist = await MajikKey._getWordlist(mnemonicLanguage);
|
|
601
|
+
if (!validateMnemonic(mnemonic, wordlist)) {
|
|
602
|
+
throw new MajikKeyError("Invalid BIP39 mnemonic phrase");
|
|
603
|
+
}
|
|
574
604
|
const backupJson = base64ToUtf8(backup);
|
|
575
605
|
const parsed = JSON.parse(backupJson);
|
|
576
606
|
if (!parsed.iv ||
|
|
@@ -623,6 +653,11 @@ export class MajikKey {
|
|
|
623
653
|
}
|
|
624
654
|
}
|
|
625
655
|
// ── PRIVATE: Core Derivation ─────────────────────────────────────────────────
|
|
656
|
+
static async _getWordlist(language) {
|
|
657
|
+
const loader = WORDLISTS[language] ?? WORDLISTS.en;
|
|
658
|
+
const mod = await loader();
|
|
659
|
+
return mod.wordlist;
|
|
660
|
+
}
|
|
626
661
|
static async _deriveAndEncryptFromMnemonic(mnemonic, passphrase) {
|
|
627
662
|
const encIdentity = await EncryptionEngine.deriveIdentityFromMnemonic(mnemonic);
|
|
628
663
|
let exportedXPrivate;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@majikah/majik-key",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "A post-quantum ready seed phrase account library for the Majikah ecosystem. Manages deterministic X25519 and ML-KEM-768 identities with Argon2id protection and seamless legacy account migration.",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.10",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"author": "Zelijah",
|
|
8
8
|
"main": "./dist/index.js",
|
|
@@ -42,17 +42,20 @@
|
|
|
42
42
|
"url": "https://github.com/Majikah/majik-key/issues"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
46
45
|
"build": "tsc",
|
|
47
|
-
"
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"prepublishOnly": "npm run build",
|
|
48
|
+
"package": "npm run build && npm version patch && git push && git push --tags",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"@majikah/majik-contact": "^0.0.
|
|
51
|
-
"@noble/hashes": "^2.0
|
|
52
|
-
"@noble/post-quantum": "^0.
|
|
53
|
-
"@scure/bip39": "^
|
|
53
|
+
"@majikah/majik-contact": "^0.0.6",
|
|
54
|
+
"@noble/hashes": "^2.2.0",
|
|
55
|
+
"@noble/post-quantum": "^0.6.1",
|
|
56
|
+
"@scure/bip39": "^2.2.0",
|
|
54
57
|
"@stablelib/aes": "^2.0.1",
|
|
55
|
-
"@stablelib/ed25519": "^2.0
|
|
58
|
+
"@stablelib/ed25519": "^2.1.0",
|
|
56
59
|
"@stablelib/gcm": "^2.0.1",
|
|
57
60
|
"@stablelib/pbkdf2": "^2.0.1",
|
|
58
61
|
"@stablelib/sha256": "^2.0.1",
|
|
@@ -62,6 +65,9 @@
|
|
|
62
65
|
"hash-wasm": "^4.12.0"
|
|
63
66
|
},
|
|
64
67
|
"devDependencies": {
|
|
65
|
-
"@types/ed2curve": "^0.2.4"
|
|
68
|
+
"@types/ed2curve": "^0.2.4",
|
|
69
|
+
"@types/node": "^26.0.0",
|
|
70
|
+
"typescript": "^6.0.3",
|
|
71
|
+
"vitest": "^4.1.9"
|
|
66
72
|
}
|
|
67
73
|
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { MajikMessageIdentityJSON } from "./database/system/identity";
|
|
2
|
-
import { ISODateString } from "./types";
|
|
3
|
-
export type SerializedMajikContact = {
|
|
4
|
-
id: string;
|
|
5
|
-
fingerprint: string;
|
|
6
|
-
meta?: MajikContactMeta;
|
|
7
|
-
publicKeyBase64: string;
|
|
8
|
-
mlKey: string;
|
|
9
|
-
majikah_registered?: boolean;
|
|
10
|
-
edPublicKeyBase64?: string;
|
|
11
|
-
mlDsaPublicKeyBase64?: string;
|
|
12
|
-
};
|
|
13
|
-
export interface MajikContactMeta {
|
|
14
|
-
label?: string;
|
|
15
|
-
notes?: string;
|
|
16
|
-
blocked?: boolean;
|
|
17
|
-
createdAt?: ISODateString;
|
|
18
|
-
updatedAt?: ISODateString;
|
|
19
|
-
}
|
|
20
|
-
export interface MajikContactData {
|
|
21
|
-
id: string;
|
|
22
|
-
publicKey: CryptoKey | {
|
|
23
|
-
raw: Uint8Array;
|
|
24
|
-
};
|
|
25
|
-
fingerprint: string;
|
|
26
|
-
mlKey: string;
|
|
27
|
-
meta?: MajikContactMeta;
|
|
28
|
-
majikah_registered?: boolean;
|
|
29
|
-
edPublicKeyBase64?: string;
|
|
30
|
-
mlDsaPublicKeyBase64?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface MajikContactCard {
|
|
33
|
-
id: string;
|
|
34
|
-
publicKey: string;
|
|
35
|
-
fingerprint: string;
|
|
36
|
-
label: string;
|
|
37
|
-
mlKey: string;
|
|
38
|
-
edPublicKeyBase64?: string;
|
|
39
|
-
mlDsaPublicKeyBase64?: string;
|
|
40
|
-
}
|
|
41
|
-
export declare class MajikContactError extends Error {
|
|
42
|
-
cause?: unknown;
|
|
43
|
-
constructor(message: string, cause?: unknown);
|
|
44
|
-
}
|
|
45
|
-
export declare class MajikContact {
|
|
46
|
-
readonly id: string;
|
|
47
|
-
readonly publicKey: CryptoKey | {
|
|
48
|
-
raw: Uint8Array;
|
|
49
|
-
};
|
|
50
|
-
readonly fingerprint: string;
|
|
51
|
-
readonly mlKey: string;
|
|
52
|
-
readonly edPublicKeyBase64: string;
|
|
53
|
-
readonly mlDsaPublicKeyBase64: string;
|
|
54
|
-
meta: MajikContactMeta;
|
|
55
|
-
private majikah_registered?;
|
|
56
|
-
constructor(data: MajikContactData);
|
|
57
|
-
static create(id: string, publicKey: CryptoKey | {
|
|
58
|
-
raw: Uint8Array;
|
|
59
|
-
}, mlKey: string, fingerprint: string, meta?: Partial<MajikContactMeta>): MajikContact;
|
|
60
|
-
private assertId;
|
|
61
|
-
private assertMLKey;
|
|
62
|
-
private assertPublicKey;
|
|
63
|
-
private assertFingerprint;
|
|
64
|
-
private updateTimestamp;
|
|
65
|
-
updateLabel(label: string): this;
|
|
66
|
-
updateNotes(notes: string): this;
|
|
67
|
-
isBlocked(): boolean;
|
|
68
|
-
setBlocked(blocked: boolean): this;
|
|
69
|
-
block(): this;
|
|
70
|
-
unblock(): this;
|
|
71
|
-
isMajikahIdentityChecked(): boolean;
|
|
72
|
-
isMajikahRegistered(): boolean;
|
|
73
|
-
setMajikahStatus(status: boolean): this;
|
|
74
|
-
getDisplayName(): Promise<string>;
|
|
75
|
-
/**
|
|
76
|
-
* Support both CryptoKey and raw-key wrappers (fallbacks when WebCrypto X25519 unsupported)
|
|
77
|
-
*/
|
|
78
|
-
getPublicKeyBase64(): Promise<string>;
|
|
79
|
-
toJSON(): Promise<SerializedMajikContact>;
|
|
80
|
-
/**
|
|
81
|
-
* Reconstruct a MajikContact from its serialized form
|
|
82
|
-
*/
|
|
83
|
-
static fromJSON(serialized: SerializedMajikContact): MajikContact;
|
|
84
|
-
/**
|
|
85
|
-
* Create a new MajikContact from a MajikMessageIdentityJSON
|
|
86
|
-
*/
|
|
87
|
-
static fromIdentityJSON(identityJSON: MajikMessageIdentityJSON): Promise<MajikContact>;
|
|
88
|
-
static isBlocked(contact: MajikContact): boolean;
|
|
89
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { arrayBufferToBase64, base64ToArrayBuffer } from "./utils";
|
|
2
|
-
/* -------------------------------
|
|
3
|
-
* Errors
|
|
4
|
-
* ------------------------------- */
|
|
5
|
-
export class MajikContactError extends Error {
|
|
6
|
-
cause;
|
|
7
|
-
constructor(message, cause) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "MajikContactError";
|
|
10
|
-
this.cause = cause;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/* -------------------------------
|
|
14
|
-
* MajikContact Class
|
|
15
|
-
* ------------------------------- */
|
|
16
|
-
export class MajikContact {
|
|
17
|
-
id;
|
|
18
|
-
publicKey;
|
|
19
|
-
fingerprint;
|
|
20
|
-
mlKey;
|
|
21
|
-
edPublicKeyBase64;
|
|
22
|
-
mlDsaPublicKeyBase64;
|
|
23
|
-
meta;
|
|
24
|
-
majikah_registered;
|
|
25
|
-
constructor(data) {
|
|
26
|
-
this.assertId(data.id);
|
|
27
|
-
this.assertPublicKey(data.publicKey);
|
|
28
|
-
this.assertMLKey(data.mlKey);
|
|
29
|
-
this.assertFingerprint(data.fingerprint);
|
|
30
|
-
this.id = data.id;
|
|
31
|
-
this.publicKey = data.publicKey;
|
|
32
|
-
this.fingerprint = data.fingerprint;
|
|
33
|
-
this.mlKey = data.mlKey;
|
|
34
|
-
this.edPublicKeyBase64 = data.edPublicKeyBase64 || "";
|
|
35
|
-
this.mlDsaPublicKeyBase64 = data.mlDsaPublicKeyBase64 || "";
|
|
36
|
-
this.meta = {
|
|
37
|
-
label: data.meta?.label || "",
|
|
38
|
-
notes: data.meta?.notes || "",
|
|
39
|
-
blocked: data.meta?.blocked || false,
|
|
40
|
-
createdAt: data.meta?.createdAt || new Date().toISOString(),
|
|
41
|
-
updatedAt: data.meta?.updatedAt || new Date().toISOString(),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
static create(id, publicKey, mlKey, fingerprint, meta) {
|
|
45
|
-
return new MajikContact({
|
|
46
|
-
id,
|
|
47
|
-
publicKey,
|
|
48
|
-
fingerprint,
|
|
49
|
-
meta,
|
|
50
|
-
mlKey,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
assertId(id) {
|
|
54
|
-
if (!id || typeof id !== "string") {
|
|
55
|
-
throw new MajikContactError("Contact ID must be a non-empty string");
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
assertMLKey(key) {
|
|
59
|
-
if (!key || typeof key !== "string") {
|
|
60
|
-
throw new MajikContactError("ML Key must be a non-empty string");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
assertPublicKey(key) {
|
|
64
|
-
// Accept either a WebCrypto CryptoKey (with .type === 'public')
|
|
65
|
-
// or a raw-key wrapper object that contains a Uint8Array `raw` field.
|
|
66
|
-
if (!key)
|
|
67
|
-
throw new MajikContactError("Invalid public key");
|
|
68
|
-
const anyKey = key;
|
|
69
|
-
if (anyKey && typeof anyKey === "object") {
|
|
70
|
-
if (anyKey.type === "public")
|
|
71
|
-
return;
|
|
72
|
-
if (anyKey.raw instanceof Uint8Array)
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
throw new MajikContactError("Invalid public key");
|
|
76
|
-
}
|
|
77
|
-
assertFingerprint(fingerprint) {
|
|
78
|
-
if (!fingerprint || typeof fingerprint !== "string") {
|
|
79
|
-
throw new MajikContactError("Fingerprint must be a non-empty string");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
updateTimestamp() {
|
|
83
|
-
this.meta.updatedAt = new Date().toISOString();
|
|
84
|
-
}
|
|
85
|
-
updateLabel(label) {
|
|
86
|
-
if (typeof label !== "string")
|
|
87
|
-
throw new MajikContactError("Label must be a string");
|
|
88
|
-
this.meta.label = label;
|
|
89
|
-
this.updateTimestamp();
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
updateNotes(notes) {
|
|
93
|
-
if (typeof notes !== "string")
|
|
94
|
-
throw new MajikContactError("Notes must be a string");
|
|
95
|
-
this.meta.notes = notes;
|
|
96
|
-
this.updateTimestamp();
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
isBlocked() {
|
|
100
|
-
return this.meta.blocked || false;
|
|
101
|
-
}
|
|
102
|
-
setBlocked(blocked) {
|
|
103
|
-
if (typeof blocked !== "boolean")
|
|
104
|
-
throw new MajikContactError("Blocked must be boolean");
|
|
105
|
-
this.meta.blocked = blocked;
|
|
106
|
-
this.updateTimestamp();
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
// Idempotent block/unblock for safe scanning
|
|
110
|
-
block() {
|
|
111
|
-
if (!this.isBlocked())
|
|
112
|
-
this.setBlocked(true);
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
unblock() {
|
|
116
|
-
if (this.isBlocked())
|
|
117
|
-
this.setBlocked(false);
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
isMajikahIdentityChecked() {
|
|
121
|
-
return this.majikah_registered !== undefined;
|
|
122
|
-
}
|
|
123
|
-
isMajikahRegistered() {
|
|
124
|
-
return this.majikah_registered || false;
|
|
125
|
-
}
|
|
126
|
-
setMajikahStatus(status) {
|
|
127
|
-
this.majikah_registered = status;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
async getDisplayName() {
|
|
131
|
-
return this.meta.label || (await this.getPublicKeyBase64());
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Support both CryptoKey and raw-key wrappers (fallbacks when WebCrypto X25519 unsupported)
|
|
135
|
-
*/
|
|
136
|
-
async getPublicKeyBase64() {
|
|
137
|
-
try {
|
|
138
|
-
// If it's a CryptoKey, export with SubtleCrypto
|
|
139
|
-
const raw = await crypto.subtle.exportKey("raw", this.publicKey);
|
|
140
|
-
return arrayBufferToBase64(raw);
|
|
141
|
-
}
|
|
142
|
-
catch (e) {
|
|
143
|
-
// Fallback: publicKey may be a wrapper with `raw` Uint8Array
|
|
144
|
-
const maybe = this.publicKey;
|
|
145
|
-
if (maybe && maybe.raw instanceof Uint8Array) {
|
|
146
|
-
return arrayBufferToBase64(maybe.raw.buffer);
|
|
147
|
-
}
|
|
148
|
-
throw e;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async toJSON() {
|
|
152
|
-
return {
|
|
153
|
-
id: this.id,
|
|
154
|
-
fingerprint: this.fingerprint,
|
|
155
|
-
meta: { ...this.meta },
|
|
156
|
-
publicKeyBase64: await this.getPublicKeyBase64(),
|
|
157
|
-
majikah_registered: this.majikah_registered,
|
|
158
|
-
mlKey: this.mlKey,
|
|
159
|
-
edPublicKeyBase64: this.edPublicKeyBase64,
|
|
160
|
-
mlDsaPublicKeyBase64: this.mlDsaPublicKeyBase64,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Reconstruct a MajikContact from its serialized form
|
|
165
|
-
*/
|
|
166
|
-
static fromJSON(serialized) {
|
|
167
|
-
try {
|
|
168
|
-
const publicKeyRaw = new Uint8Array(base64ToArrayBuffer(serialized.publicKeyBase64));
|
|
169
|
-
return new MajikContact({
|
|
170
|
-
id: serialized.id,
|
|
171
|
-
fingerprint: serialized.fingerprint,
|
|
172
|
-
meta: serialized.meta,
|
|
173
|
-
publicKey: { raw: publicKeyRaw },
|
|
174
|
-
majikah_registered: serialized.majikah_registered,
|
|
175
|
-
mlKey: serialized.mlKey,
|
|
176
|
-
edPublicKeyBase64: serialized.edPublicKeyBase64,
|
|
177
|
-
mlDsaPublicKeyBase64: serialized.mlDsaPublicKeyBase64,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
throw new MajikContactError("Failed to deserialize MajikContact", err);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Create a new MajikContact from a MajikMessageIdentityJSON
|
|
186
|
-
*/
|
|
187
|
-
static async fromIdentityJSON(identityJSON) {
|
|
188
|
-
try {
|
|
189
|
-
const publicKeyRaw = new Uint8Array(base64ToArrayBuffer(identityJSON.public_key));
|
|
190
|
-
const contactData = {
|
|
191
|
-
id: identityJSON.id,
|
|
192
|
-
publicKey: { raw: publicKeyRaw },
|
|
193
|
-
fingerprint: identityJSON.id,
|
|
194
|
-
meta: {
|
|
195
|
-
label: identityJSON.label,
|
|
196
|
-
createdAt: identityJSON.timestamp,
|
|
197
|
-
updatedAt: identityJSON.timestamp,
|
|
198
|
-
blocked: identityJSON.restricted,
|
|
199
|
-
},
|
|
200
|
-
majikah_registered: true,
|
|
201
|
-
mlKey: identityJSON.ml_key,
|
|
202
|
-
};
|
|
203
|
-
return new MajikContact(contactData);
|
|
204
|
-
}
|
|
205
|
-
catch (err) {
|
|
206
|
-
throw new MajikContactError("Failed to create MajikContact from MajikMessageIdentityJSON", err);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
static isBlocked(contact) {
|
|
210
|
-
return !!contact.meta.blocked;
|
|
211
|
-
}
|
|
212
|
-
}
|