internxt-crypto 0.0.10-alpha → 0.0.11
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/README.md +3 -4
- package/dist/asymmetric-crypto-BORmLhnx.js +143 -0
- package/dist/asymmetric-crypto-BORmLhnx.js.map +1 -0
- package/dist/asymmetric-crypto-CyXsV4XT.mjs +102 -0
- package/dist/asymmetric-crypto-CyXsV4XT.mjs.map +1 -0
- package/dist/asymmetric-crypto.d.mts +9 -3
- package/dist/asymmetric-crypto.d.ts +9 -3
- package/dist/asymmetric-crypto.js +8 -92
- package/dist/asymmetric-crypto.mjs +2 -84
- package/dist/chunk-DWirmd9C.mjs +18 -0
- package/dist/chunk-Dt-PWiN7.js +60 -0
- package/dist/constants-Ccp21E03.js +208 -0
- package/dist/constants-Ccp21E03.js.map +1 -0
- package/dist/constants-kTeX-2T0.mjs +34 -0
- package/dist/constants-kTeX-2T0.mjs.map +1 -0
- package/dist/constants.d.mts +5 -11
- package/dist/constants.d.ts +5 -11
- package/dist/constants.js +30 -79
- package/dist/constants.mjs +2 -41
- package/dist/derive-key-Be7hS-cN.mjs +751 -0
- package/dist/derive-key-Be7hS-cN.mjs.map +1 -0
- package/dist/derive-key-CBf2WxJd.js +2513 -0
- package/dist/derive-key-CBf2WxJd.js.map +1 -0
- package/dist/derive-key.d.mts +14 -8
- package/dist/derive-key.d.ts +14 -8
- package/dist/derive-key.js +15 -795
- package/dist/derive-key.mjs +5 -783
- package/dist/email-crypto-BrT98taw.js +617 -0
- package/dist/email-crypto-BrT98taw.js.map +1 -0
- package/dist/email-crypto-DJUEjTxA.mjs +534 -0
- package/dist/email-crypto-DJUEjTxA.mjs.map +1 -0
- package/dist/email-crypto.d.mts +58 -78
- package/dist/email-crypto.d.ts +58 -78
- package/dist/email-crypto.js +17 -1409
- package/dist/email-crypto.mjs +8 -1381
- package/dist/email-search.d.mts +39 -32
- package/dist/email-search.d.ts +39 -32
- package/dist/email-search.js +572 -540
- package/dist/email-search.js.map +1 -1
- package/dist/email-search.mjs +567 -539
- package/dist/email-search.mjs.map +1 -1
- package/dist/hash-BoqwNkcd.js +190 -0
- package/dist/hash-BoqwNkcd.js.map +1 -0
- package/dist/hash-CXeGAwai.mjs +131 -0
- package/dist/hash-CXeGAwai.mjs.map +1 -0
- package/dist/hash.d.mts +21 -15
- package/dist/hash.d.ts +21 -15
- package/dist/hash.js +11 -95
- package/dist/hash.mjs +2 -84
- package/dist/index-CQqgKsbX.d.ts +50 -0
- package/dist/index-CintVUbp.d.ts +97 -0
- package/dist/index-D5pBU_A5.d.mts +50 -0
- package/dist/index-MaOov-ag.d.mts +97 -0
- package/dist/index.d.mts +35 -18
- package/dist/index.d.ts +35 -18
- package/dist/index.js +103 -2685
- package/dist/index.mjs +15 -2538
- package/dist/keystore-crypto-B4yCVo9l.js +182 -0
- package/dist/keystore-crypto-B4yCVo9l.js.map +1 -0
- package/dist/keystore-crypto-Bjgriq9h.mjs +159 -0
- package/dist/keystore-crypto-Bjgriq9h.mjs.map +1 -0
- package/dist/keystore-crypto.d.mts +20 -46
- package/dist/keystore-crypto.d.ts +20 -46
- package/dist/keystore-crypto.js +11 -530
- package/dist/keystore-crypto.mjs +9 -501
- package/dist/keystore-service.d.mts +44 -78
- package/dist/keystore-service.d.ts +44 -78
- package/dist/keystore-service.js +113 -340
- package/dist/keystore-service.js.map +1 -1
- package/dist/keystore-service.mjs +107 -335
- package/dist/keystore-service.mjs.map +1 -1
- package/dist/post-quantum-crypto-CAi-cEkV.js +189 -0
- package/dist/post-quantum-crypto-CAi-cEkV.js.map +1 -0
- package/dist/post-quantum-crypto-Vv34t6gX.mjs +154 -0
- package/dist/post-quantum-crypto-Vv34t6gX.mjs.map +1 -0
- package/dist/post-quantum-crypto.d.mts +2 -72
- package/dist/post-quantum-crypto.d.ts +2 -72
- package/dist/post-quantum-crypto.js +13 -92
- package/dist/post-quantum-crypto.mjs +2 -89
- package/dist/storage-service-BgIK2aYZ.js +82 -0
- package/dist/storage-service-BgIK2aYZ.js.map +1 -0
- package/dist/storage-service-CubCbhY2.mjs +65 -0
- package/dist/storage-service-CubCbhY2.mjs.map +1 -0
- package/dist/storage-service.d.mts +2 -53
- package/dist/storage-service.d.ts +2 -53
- package/dist/storage-service.js +12 -68
- package/dist/storage-service.mjs +2 -66
- package/dist/symmetric-crypto-CrdS1Che.mjs +197 -0
- package/dist/symmetric-crypto-CrdS1Che.mjs.map +1 -0
- package/dist/symmetric-crypto-D65zB396.js +244 -0
- package/dist/symmetric-crypto-D65zB396.js.map +1 -0
- package/dist/symmetric-crypto.d.mts +12 -8
- package/dist/symmetric-crypto.d.ts +12 -8
- package/dist/symmetric-crypto.js +10 -142
- package/dist/symmetric-crypto.mjs +3 -133
- package/dist/types-52g887Zi.js +16 -0
- package/dist/types-52g887Zi.js.map +1 -0
- package/dist/types-BiEoleqw.mjs +10 -0
- package/dist/types-BiEoleqw.mjs.map +1 -0
- package/dist/types-Ds3ivE9W.d.ts +104 -0
- package/dist/types-DwQJtrTx.d.mts +104 -0
- package/dist/types.d.mts +2 -102
- package/dist/types.d.ts +2 -102
- package/dist/types.js +2 -13
- package/dist/types.mjs +2 -11
- package/dist/utils-CNs3cyDj.js +263 -0
- package/dist/utils-CNs3cyDj.js.map +1 -0
- package/dist/utils-DS04iUcX.mjs +173 -0
- package/dist/utils-DS04iUcX.mjs.map +1 -0
- package/dist/utils.d.mts +37 -78
- package/dist/utils.d.ts +37 -78
- package/dist/utils.js +16 -313
- package/dist/utils.mjs +2 -272
- package/package.json +15 -90
- package/dist/asymmetric-crypto.js.map +0 -1
- package/dist/asymmetric-crypto.mjs.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/derive-key.js.map +0 -1
- package/dist/derive-key.mjs.map +0 -1
- package/dist/email-crypto.js.map +0 -1
- package/dist/email-crypto.mjs.map +0 -1
- package/dist/email-service.d.mts +0 -38
- package/dist/email-service.d.ts +0 -38
- package/dist/email-service.js +0 -154
- package/dist/email-service.js.map +0 -1
- package/dist/email-service.mjs +0 -147
- package/dist/email-service.mjs.map +0 -1
- package/dist/hash.js.map +0 -1
- package/dist/hash.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/keystore-crypto.js.map +0 -1
- package/dist/keystore-crypto.mjs.map +0 -1
- package/dist/kyber768-B87rMQ7u.d.mts +0 -30
- package/dist/kyber768-B87rMQ7u.d.ts +0 -30
- package/dist/post-quantum-crypto.js.map +0 -1
- package/dist/post-quantum-crypto.mjs.map +0 -1
- package/dist/storage-service.js.map +0 -1
- package/dist/storage-service.mjs.map +0 -1
- package/dist/symmetric-crypto.js.map +0 -1
- package/dist/symmetric-crypto.mjs.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils-BDaK_d6T.d.ts +0 -114
- package/dist/utils-v34IRTIx.d.mts +0 -114
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,102 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
ENCRYPTION = "encryption",
|
|
4
|
-
RECOVERY = "recovery",
|
|
5
|
-
INDEX = "index"
|
|
6
|
-
}
|
|
7
|
-
type EncryptedKeystore = {
|
|
8
|
-
userID: string;
|
|
9
|
-
type: KeystoreType;
|
|
10
|
-
encryptedKeys: SymmetricCiphertext;
|
|
11
|
-
};
|
|
12
|
-
type User = {
|
|
13
|
-
email: string;
|
|
14
|
-
name: string;
|
|
15
|
-
};
|
|
16
|
-
type UserWithPublicKeys = User & {
|
|
17
|
-
publicKeys: PublicKeys;
|
|
18
|
-
};
|
|
19
|
-
type PublicKeys = {
|
|
20
|
-
eccPublicKey: CryptoKey;
|
|
21
|
-
kyberPublicKey: Uint8Array;
|
|
22
|
-
};
|
|
23
|
-
type MediaKeys = {
|
|
24
|
-
olmKey: Uint8Array;
|
|
25
|
-
pqKey: Uint8Array;
|
|
26
|
-
index: number;
|
|
27
|
-
userID: string;
|
|
28
|
-
};
|
|
29
|
-
type PrivateKeys = {
|
|
30
|
-
eccPrivateKey: CryptoKey;
|
|
31
|
-
kyberPrivateKey: Uint8Array;
|
|
32
|
-
};
|
|
33
|
-
type IdentityKeys = {
|
|
34
|
-
userPublicKey: CryptoKey;
|
|
35
|
-
userPrivateKey: CryptoKey;
|
|
36
|
-
};
|
|
37
|
-
type EncryptionKeys = {
|
|
38
|
-
userPublicKey: CryptoKey;
|
|
39
|
-
userPrivateKey: CryptoKey;
|
|
40
|
-
userPublicKyberKey: Uint8Array;
|
|
41
|
-
userPrivateKyberKey: Uint8Array;
|
|
42
|
-
};
|
|
43
|
-
type HybridEncryptedEmail = {
|
|
44
|
-
encryptedKey: HybridEncKey;
|
|
45
|
-
enc: SymmetricCiphertext;
|
|
46
|
-
recipientEmail: string;
|
|
47
|
-
params: EmailPublicParameters;
|
|
48
|
-
id: string;
|
|
49
|
-
};
|
|
50
|
-
type PwdProtectedEmail = {
|
|
51
|
-
encryptedKey: PwdProtectedKey;
|
|
52
|
-
enc: SymmetricCiphertext;
|
|
53
|
-
params: EmailPublicParameters;
|
|
54
|
-
id: string;
|
|
55
|
-
};
|
|
56
|
-
type SymmetricCiphertext = {
|
|
57
|
-
ciphertext: Uint8Array;
|
|
58
|
-
iv: Uint8Array;
|
|
59
|
-
};
|
|
60
|
-
type StoredEmail = {
|
|
61
|
-
params: EmailPublicParameters;
|
|
62
|
-
content: SymmetricCiphertext;
|
|
63
|
-
id: string;
|
|
64
|
-
};
|
|
65
|
-
type HybridEncKey = {
|
|
66
|
-
kyberCiphertext: Uint8Array;
|
|
67
|
-
encryptedKey: Uint8Array;
|
|
68
|
-
};
|
|
69
|
-
type PwdProtectedKey = {
|
|
70
|
-
encryptedKey: Uint8Array;
|
|
71
|
-
salt: Uint8Array;
|
|
72
|
-
};
|
|
73
|
-
type EmailBody = {
|
|
74
|
-
text: string;
|
|
75
|
-
attachments?: string[];
|
|
76
|
-
};
|
|
77
|
-
type EmailPublicParameters = {
|
|
78
|
-
subject: string;
|
|
79
|
-
createdAt: string;
|
|
80
|
-
sender: User;
|
|
81
|
-
recipient: User;
|
|
82
|
-
recipients?: User[];
|
|
83
|
-
replyToEmailID?: number;
|
|
84
|
-
labels?: string[];
|
|
85
|
-
};
|
|
86
|
-
type Email = {
|
|
87
|
-
id: string;
|
|
88
|
-
body: EmailBody;
|
|
89
|
-
params: EmailPublicParameters;
|
|
90
|
-
};
|
|
91
|
-
interface MailCache<Email> {
|
|
92
|
-
esCache: Map<string, Email>;
|
|
93
|
-
cacheSize: number;
|
|
94
|
-
isCacheLimited: boolean;
|
|
95
|
-
isCacheReady: boolean;
|
|
96
|
-
}
|
|
97
|
-
interface EmailSearchResult {
|
|
98
|
-
email: Email;
|
|
99
|
-
score?: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { type Email, type EmailBody, type EmailPublicParameters, type EmailSearchResult, type EncryptedKeystore, type EncryptionKeys, type HybridEncKey, type HybridEncryptedEmail, type IdentityKeys, KeystoreType, type MailCache, type MediaKeys, type PrivateKeys, type PublicKeys, type PwdProtectedEmail, type PwdProtectedKey, type StoredEmail, type SymmetricCiphertext, type User, type UserWithPublicKeys };
|
|
1
|
+
import { _ as PwdProtectedEmail, a as EmailKeysEncrypted, b as User, c as EncryptedKeystore, d as KeystoreType, f as MailCache, g as PublicKeysBase64, h as PublicKeys, i as EmailKeys, l as HybridEncKey, m as PrivateKeysEncrypted, n as EmailBody, o as EmailPublicParameters, p as PrivateKeys, r as EmailBodyEncrypted, s as EmailSearchResult, t as Email, u as HybridEncryptedEmail, v as PwdProtectedKey, x as UserWithPublicKeys, y as StoredEmail } from "./types-Ds3ivE9W.js";
|
|
2
|
+
export { Email, EmailBody, EmailBodyEncrypted, EmailKeys, EmailKeysEncrypted, EmailPublicParameters, EmailSearchResult, EncryptedKeystore, HybridEncKey, HybridEncryptedEmail, KeystoreType, MailCache, PrivateKeys, PrivateKeysEncrypted, PublicKeys, PublicKeysBase64, PwdProtectedEmail, PwdProtectedKey, StoredEmail, User, UserWithPublicKeys };
|
package/dist/types.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
const require_types = require('./types-52g887Zi.js');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var KeystoreType = /* @__PURE__ */ ((KeystoreType2) => {
|
|
5
|
-
KeystoreType2["IDENTITY"] = "identity";
|
|
6
|
-
KeystoreType2["ENCRYPTION"] = "encryption";
|
|
7
|
-
KeystoreType2["RECOVERY"] = "recovery";
|
|
8
|
-
KeystoreType2["INDEX"] = "index";
|
|
9
|
-
return KeystoreType2;
|
|
10
|
-
})(KeystoreType || {});
|
|
11
|
-
|
|
12
|
-
exports.KeystoreType = KeystoreType;
|
|
13
|
-
//# sourceMappingURL=types.js.map
|
|
14
|
-
//# sourceMappingURL=types.js.map
|
|
3
|
+
exports.KeystoreType = require_types.KeystoreType;
|
package/dist/types.mjs
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var KeystoreType = /* @__PURE__ */ ((KeystoreType2) => {
|
|
3
|
-
KeystoreType2["IDENTITY"] = "identity";
|
|
4
|
-
KeystoreType2["ENCRYPTION"] = "encryption";
|
|
5
|
-
KeystoreType2["RECOVERY"] = "recovery";
|
|
6
|
-
KeystoreType2["INDEX"] = "index";
|
|
7
|
-
return KeystoreType2;
|
|
8
|
-
})(KeystoreType || {});
|
|
1
|
+
import { t as KeystoreType } from "./types-BiEoleqw.mjs";
|
|
9
2
|
|
|
10
|
-
export { KeystoreType };
|
|
11
|
-
//# sourceMappingURL=types.mjs.map
|
|
12
|
-
//# sourceMappingURL=types.mjs.map
|
|
3
|
+
export { KeystoreType };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-Dt-PWiN7.js');
|
|
2
|
+
const require_constants = require('./constants-Ccp21E03.js');
|
|
3
|
+
const require_asymmetric_crypto = require('./asymmetric-crypto-BORmLhnx.js');
|
|
4
|
+
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
5
|
+
let _scure_bip39 = require("@scure/bip39");
|
|
6
|
+
_scure_bip39 = require_chunk.__toESM(_scure_bip39);
|
|
7
|
+
let _scure_bip39_wordlists_english_js = require("@scure/bip39/wordlists/english.js");
|
|
8
|
+
let uuid = require("uuid");
|
|
9
|
+
|
|
10
|
+
//#region src/utils/converters.ts
|
|
11
|
+
/**
|
|
12
|
+
* Converts a Uint8Array into a hexadecimal string.
|
|
13
|
+
*
|
|
14
|
+
* @param array - The Uint8Array to convert.
|
|
15
|
+
* @returns The hexadecimal string representation of the array.
|
|
16
|
+
*/
|
|
17
|
+
function uint8ArrayToHex(array) {
|
|
18
|
+
return (0, _noble_hashes_utils_js.bytesToHex)(array);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Converts a UTF-8 string into a Uint8Array.
|
|
22
|
+
*
|
|
23
|
+
* @param str - The UTF-8 string to convert.
|
|
24
|
+
* @returns A Uint8Array created from the UTF-8 string.
|
|
25
|
+
*/
|
|
26
|
+
function UTF8ToUint8(str) {
|
|
27
|
+
return new TextEncoder().encode(str);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Converts an Uint8Array into a UTF-8 string.
|
|
31
|
+
*
|
|
32
|
+
* @param array - The Uint8Array to convert.
|
|
33
|
+
* @returns The UTF-8 string representation of the array.
|
|
34
|
+
*/
|
|
35
|
+
function uint8ToUTF8(array) {
|
|
36
|
+
return new TextDecoder().decode(array);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a hexadecimal string into a Uint8Array.
|
|
40
|
+
*
|
|
41
|
+
* @param hex - The hexadecimal string to convert.
|
|
42
|
+
* @returns A Uint8Array created from the hex string.
|
|
43
|
+
*/
|
|
44
|
+
function hexToUint8Array(hex) {
|
|
45
|
+
return (0, _noble_hashes_utils_js.hexToBytes)(hex);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts a Uint8Array into a base64 string.
|
|
49
|
+
*
|
|
50
|
+
* @param array - The Uint8Array to convert.
|
|
51
|
+
* @returns The base64 string representation of the array.
|
|
52
|
+
*/
|
|
53
|
+
function uint8ArrayToBase64(buffer) {
|
|
54
|
+
const array = Uint16Array.from(buffer);
|
|
55
|
+
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
56
|
+
return btoa(binaryString);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts a base64 string into a Uint8Array.
|
|
60
|
+
*
|
|
61
|
+
* @param str - The base64 string to convert.
|
|
62
|
+
* @returns A Uint8Array created from the base64 string.
|
|
63
|
+
*/
|
|
64
|
+
function base64ToUint8Array(str) {
|
|
65
|
+
const binaryString = atob(str);
|
|
66
|
+
const len = binaryString.length;
|
|
67
|
+
const array = new Uint8Array(len);
|
|
68
|
+
for (let i = 0; i < len; i++) array[i] = binaryString.codePointAt(i);
|
|
69
|
+
return new Uint8Array(array.buffer);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/utils/keyConverters.ts
|
|
74
|
+
/**
|
|
75
|
+
* Converts a base64 string into PublicKeys type.
|
|
76
|
+
*
|
|
77
|
+
* @param base64 - The base64 representation of the public key.
|
|
78
|
+
* @returns The resulting PublicKeys.
|
|
79
|
+
*/
|
|
80
|
+
async function base64ToPublicKey(base64) {
|
|
81
|
+
try {
|
|
82
|
+
return {
|
|
83
|
+
eccPublicKey: await require_asymmetric_crypto.importPublicKey(base64ToUint8Array(base64.eccPublicKeyBase64)),
|
|
84
|
+
kyberPublicKey: base64ToUint8Array(base64.kyberPublicKeyBase64)
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts a PublicKeys type into PublicKeysBase64.
|
|
92
|
+
*
|
|
93
|
+
* @param key - The PublicKeys key.
|
|
94
|
+
* @returns The resulting PublicKeysBase64.
|
|
95
|
+
*/
|
|
96
|
+
async function publicKeyToBase64(key) {
|
|
97
|
+
try {
|
|
98
|
+
return {
|
|
99
|
+
eccPublicKeyBase64: uint8ArrayToBase64(await require_asymmetric_crypto.exportPublicKey(key.eccPublicKey)),
|
|
100
|
+
kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey)
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
throw new Error("Failed to convert key of the type PublicKeys to PublicKeysBase64", { cause: error });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/utils/genMnemonic.ts
|
|
109
|
+
/**
|
|
110
|
+
* Generates a mnemonic
|
|
111
|
+
*
|
|
112
|
+
* @returns The generated mnemonic.
|
|
113
|
+
*/
|
|
114
|
+
function genMnemonic() {
|
|
115
|
+
return _scure_bip39.generateMnemonic(_scure_bip39_wordlists_english_js.wordlist, require_constants.AES_KEY_BIT_LENGTH);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Converts a mnemonic to Uint8Array
|
|
119
|
+
*
|
|
120
|
+
* @param mnemonic - The mnemonic to convert
|
|
121
|
+
* @returns The mnemonic as Uint8Array
|
|
122
|
+
*/
|
|
123
|
+
function mnemonicToBytes(mnemonic) {
|
|
124
|
+
return _scure_bip39.mnemonicToEntropy(mnemonic, _scure_bip39_wordlists_english_js.wordlist);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Converts a Uint8Array to a mnemonic
|
|
128
|
+
*
|
|
129
|
+
* @param bytes - The bytes to convert
|
|
130
|
+
* @returns The mnemonic string
|
|
131
|
+
*/
|
|
132
|
+
function bytesToMnemonic(bytes) {
|
|
133
|
+
return _scure_bip39.entropyToMnemonic(bytes, _scure_bip39_wordlists_english_js.wordlist);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/genID.ts
|
|
138
|
+
/**
|
|
139
|
+
* Creates a random identifier.
|
|
140
|
+
*
|
|
141
|
+
* @returns The resulting auxilary string
|
|
142
|
+
*/
|
|
143
|
+
function generateUuid() {
|
|
144
|
+
return (0, uuid.v4)();
|
|
145
|
+
}
|
|
146
|
+
function uuidToBytes(uuid$1) {
|
|
147
|
+
return (0, uuid.parse)(uuid$1);
|
|
148
|
+
}
|
|
149
|
+
function bytesToUuid(bytes) {
|
|
150
|
+
return (0, uuid.stringify)(bytes);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/utils/index.ts
|
|
155
|
+
var utils_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
156
|
+
UTF8ToUint8: () => UTF8ToUint8,
|
|
157
|
+
base64ToPublicKey: () => base64ToPublicKey,
|
|
158
|
+
base64ToUint8Array: () => base64ToUint8Array,
|
|
159
|
+
bytesToMnemonic: () => bytesToMnemonic,
|
|
160
|
+
bytesToUuid: () => bytesToUuid,
|
|
161
|
+
genMnemonic: () => genMnemonic,
|
|
162
|
+
generateUuid: () => generateUuid,
|
|
163
|
+
hexToUint8Array: () => hexToUint8Array,
|
|
164
|
+
mnemonicToBytes: () => mnemonicToBytes,
|
|
165
|
+
publicKeyToBase64: () => publicKeyToBase64,
|
|
166
|
+
uint8ArrayToBase64: () => uint8ArrayToBase64,
|
|
167
|
+
uint8ArrayToHex: () => uint8ArrayToHex,
|
|
168
|
+
uint8ToUTF8: () => uint8ToUTF8,
|
|
169
|
+
uuidToBytes: () => uuidToBytes
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
Object.defineProperty(exports, 'UTF8ToUint8', {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function () {
|
|
176
|
+
return UTF8ToUint8;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, 'base64ToPublicKey', {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function () {
|
|
182
|
+
return base64ToPublicKey;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(exports, 'base64ToUint8Array', {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function () {
|
|
188
|
+
return base64ToUint8Array;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(exports, 'bytesToMnemonic', {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
get: function () {
|
|
194
|
+
return bytesToMnemonic;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(exports, 'bytesToUuid', {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function () {
|
|
200
|
+
return bytesToUuid;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
Object.defineProperty(exports, 'genMnemonic', {
|
|
204
|
+
enumerable: true,
|
|
205
|
+
get: function () {
|
|
206
|
+
return genMnemonic;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(exports, 'generateUuid', {
|
|
210
|
+
enumerable: true,
|
|
211
|
+
get: function () {
|
|
212
|
+
return generateUuid;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
Object.defineProperty(exports, 'hexToUint8Array', {
|
|
216
|
+
enumerable: true,
|
|
217
|
+
get: function () {
|
|
218
|
+
return hexToUint8Array;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
Object.defineProperty(exports, 'mnemonicToBytes', {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
get: function () {
|
|
224
|
+
return mnemonicToBytes;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty(exports, 'publicKeyToBase64', {
|
|
228
|
+
enumerable: true,
|
|
229
|
+
get: function () {
|
|
230
|
+
return publicKeyToBase64;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
Object.defineProperty(exports, 'uint8ArrayToBase64', {
|
|
234
|
+
enumerable: true,
|
|
235
|
+
get: function () {
|
|
236
|
+
return uint8ArrayToBase64;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
Object.defineProperty(exports, 'uint8ArrayToHex', {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
get: function () {
|
|
242
|
+
return uint8ArrayToHex;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(exports, 'uint8ToUTF8', {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
get: function () {
|
|
248
|
+
return uint8ToUTF8;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(exports, 'utils_exports', {
|
|
252
|
+
enumerable: true,
|
|
253
|
+
get: function () {
|
|
254
|
+
return utils_exports;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(exports, 'uuidToBytes', {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () {
|
|
260
|
+
return uuidToBytes;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
//# sourceMappingURL=utils-CNs3cyDj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-CNs3cyDj.js","names":["importPublicKey","exportPublicKey","bip39","wordlist","AES_KEY_BIT_LENGTH","uuid"],"sources":["../src/utils/converters.ts","../src/utils/keyConverters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts","../src/utils/index.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import { uint8ArrayToBase64, base64ToUint8Array } from '.';\nimport { PublicKeys, PublicKeysBase64 } from '../types';\nimport { exportPublicKey, importPublicKey } from '../asymmetric-crypto';\n\n/**\n * Converts a base64 string into PublicKeys type.\n *\n * @param base64 - The base64 representation of the public key.\n * @returns The resulting PublicKeys.\n */\nexport async function base64ToPublicKey(base64: PublicKeysBase64): Promise<PublicKeys> {\n try {\n const eccPublicKeyBytes = base64ToUint8Array(base64.eccPublicKeyBase64);\n const eccPublicKey = await importPublicKey(eccPublicKeyBytes);\n const kyberPublicKey = base64ToUint8Array(base64.kyberPublicKeyBase64);\n return {\n eccPublicKey: eccPublicKey,\n kyberPublicKey: kyberPublicKey,\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to PublicKeys', { cause: error });\n }\n}\n\n/**\n * Converts a PublicKeys type into PublicKeysBase64.\n *\n * @param key - The PublicKeys key.\n * @returns The resulting PublicKeysBase64.\n */\nexport async function publicKeyToBase64(key: PublicKeys): Promise<PublicKeysBase64> {\n try {\n const eccPublicKeyArray = await exportPublicKey(key.eccPublicKey);\n const keys = {\n eccPublicKeyBase64: uint8ArrayToBase64(eccPublicKeyArray),\n kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey),\n };\n return keys;\n } catch (error) {\n throw new Error('Failed to convert key of the type PublicKeys to PublicKeysBase64', { cause: error });\n }\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BIT_LENGTH);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n","export * from './converters';\nexport * from './keyConverters';\nexport * from './genMnemonic';\nexport * from './genID';\n"],"mappings":";;;;;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,+CAAkB,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,+CAAkB,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;;ACzDrC,eAAsB,kBAAkB,QAA+C;AACrF,KAAI;AAIF,SAAO;GACL,cAHmB,MAAMA,0CADD,mBAAmB,OAAO,mBAAmB,CACV;GAI3D,gBAHqB,mBAAmB,OAAO,qBAAqB;GAIrE;UACM,OAAO;AACd,QAAM,IAAI,MAAM,0CAA0C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/E,eAAsB,kBAAkB,KAA4C;AAClF,KAAI;AAMF,SAJa;GACX,oBAAoB,mBAFI,MAAMC,0CAAgB,IAAI,aAAa,CAEN;GACzD,sBAAsB,mBAAmB,IAAI,eAAe;GAC7D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,oEAAoE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AC/BzG,SAAgB,cAAsB;AACpC,QAAOC,aAAM,iBAAiBC,4CAAUC,qCAAmB;;;;;;;;AAS7D,SAAgB,gBAAgB,UAA8B;AAC5D,QAAOF,aAAM,kBAAkB,UAAUC,2CAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAOD,aAAM,kBAAkB,OAAOC,2CAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,sBAAe;;AAGjB,SAAgB,YAAY,QAA0B;AACpD,wBAAaE,OAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,4BAAiB,MAAM"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-DWirmd9C.mjs";
|
|
2
|
+
import { n as AES_KEY_BIT_LENGTH } from "./constants-kTeX-2T0.mjs";
|
|
3
|
+
import { o as importPublicKey, r as exportPublicKey } from "./asymmetric-crypto-CyXsV4XT.mjs";
|
|
4
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
5
|
+
import * as bip39 from "@scure/bip39";
|
|
6
|
+
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
7
|
+
import { parse, stringify, v4 } from "uuid";
|
|
8
|
+
|
|
9
|
+
//#region src/utils/converters.ts
|
|
10
|
+
/**
|
|
11
|
+
* Converts a Uint8Array into a hexadecimal string.
|
|
12
|
+
*
|
|
13
|
+
* @param array - The Uint8Array to convert.
|
|
14
|
+
* @returns The hexadecimal string representation of the array.
|
|
15
|
+
*/
|
|
16
|
+
function uint8ArrayToHex(array) {
|
|
17
|
+
return bytesToHex(array);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts a UTF-8 string into a Uint8Array.
|
|
21
|
+
*
|
|
22
|
+
* @param str - The UTF-8 string to convert.
|
|
23
|
+
* @returns A Uint8Array created from the UTF-8 string.
|
|
24
|
+
*/
|
|
25
|
+
function UTF8ToUint8(str) {
|
|
26
|
+
return new TextEncoder().encode(str);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Converts an Uint8Array into a UTF-8 string.
|
|
30
|
+
*
|
|
31
|
+
* @param array - The Uint8Array to convert.
|
|
32
|
+
* @returns The UTF-8 string representation of the array.
|
|
33
|
+
*/
|
|
34
|
+
function uint8ToUTF8(array) {
|
|
35
|
+
return new TextDecoder().decode(array);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Converts a hexadecimal string into a Uint8Array.
|
|
39
|
+
*
|
|
40
|
+
* @param hex - The hexadecimal string to convert.
|
|
41
|
+
* @returns A Uint8Array created from the hex string.
|
|
42
|
+
*/
|
|
43
|
+
function hexToUint8Array(hex) {
|
|
44
|
+
return hexToBytes(hex);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Converts a Uint8Array into a base64 string.
|
|
48
|
+
*
|
|
49
|
+
* @param array - The Uint8Array to convert.
|
|
50
|
+
* @returns The base64 string representation of the array.
|
|
51
|
+
*/
|
|
52
|
+
function uint8ArrayToBase64(buffer) {
|
|
53
|
+
const array = Uint16Array.from(buffer);
|
|
54
|
+
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
55
|
+
return btoa(binaryString);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Converts a base64 string into a Uint8Array.
|
|
59
|
+
*
|
|
60
|
+
* @param str - The base64 string to convert.
|
|
61
|
+
* @returns A Uint8Array created from the base64 string.
|
|
62
|
+
*/
|
|
63
|
+
function base64ToUint8Array(str) {
|
|
64
|
+
const binaryString = atob(str);
|
|
65
|
+
const len = binaryString.length;
|
|
66
|
+
const array = new Uint8Array(len);
|
|
67
|
+
for (let i = 0; i < len; i++) array[i] = binaryString.codePointAt(i);
|
|
68
|
+
return new Uint8Array(array.buffer);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/utils/keyConverters.ts
|
|
73
|
+
/**
|
|
74
|
+
* Converts a base64 string into PublicKeys type.
|
|
75
|
+
*
|
|
76
|
+
* @param base64 - The base64 representation of the public key.
|
|
77
|
+
* @returns The resulting PublicKeys.
|
|
78
|
+
*/
|
|
79
|
+
async function base64ToPublicKey(base64) {
|
|
80
|
+
try {
|
|
81
|
+
return {
|
|
82
|
+
eccPublicKey: await importPublicKey(base64ToUint8Array(base64.eccPublicKeyBase64)),
|
|
83
|
+
kyberPublicKey: base64ToUint8Array(base64.kyberPublicKeyBase64)
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error("Failed to convert base64 to PublicKeys", { cause: error });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Converts a PublicKeys type into PublicKeysBase64.
|
|
91
|
+
*
|
|
92
|
+
* @param key - The PublicKeys key.
|
|
93
|
+
* @returns The resulting PublicKeysBase64.
|
|
94
|
+
*/
|
|
95
|
+
async function publicKeyToBase64(key) {
|
|
96
|
+
try {
|
|
97
|
+
return {
|
|
98
|
+
eccPublicKeyBase64: uint8ArrayToBase64(await exportPublicKey(key.eccPublicKey)),
|
|
99
|
+
kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey)
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new Error("Failed to convert key of the type PublicKeys to PublicKeysBase64", { cause: error });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/utils/genMnemonic.ts
|
|
108
|
+
/**
|
|
109
|
+
* Generates a mnemonic
|
|
110
|
+
*
|
|
111
|
+
* @returns The generated mnemonic.
|
|
112
|
+
*/
|
|
113
|
+
function genMnemonic() {
|
|
114
|
+
return bip39.generateMnemonic(wordlist, AES_KEY_BIT_LENGTH);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Converts a mnemonic to Uint8Array
|
|
118
|
+
*
|
|
119
|
+
* @param mnemonic - The mnemonic to convert
|
|
120
|
+
* @returns The mnemonic as Uint8Array
|
|
121
|
+
*/
|
|
122
|
+
function mnemonicToBytes(mnemonic) {
|
|
123
|
+
return bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Converts a Uint8Array to a mnemonic
|
|
127
|
+
*
|
|
128
|
+
* @param bytes - The bytes to convert
|
|
129
|
+
* @returns The mnemonic string
|
|
130
|
+
*/
|
|
131
|
+
function bytesToMnemonic(bytes) {
|
|
132
|
+
return bip39.entropyToMnemonic(bytes, wordlist);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/utils/genID.ts
|
|
137
|
+
/**
|
|
138
|
+
* Creates a random identifier.
|
|
139
|
+
*
|
|
140
|
+
* @returns The resulting auxilary string
|
|
141
|
+
*/
|
|
142
|
+
function generateUuid() {
|
|
143
|
+
return v4();
|
|
144
|
+
}
|
|
145
|
+
function uuidToBytes(uuid) {
|
|
146
|
+
return parse(uuid);
|
|
147
|
+
}
|
|
148
|
+
function bytesToUuid(bytes) {
|
|
149
|
+
return stringify(bytes);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/utils/index.ts
|
|
154
|
+
var utils_exports = /* @__PURE__ */ __exportAll({
|
|
155
|
+
UTF8ToUint8: () => UTF8ToUint8,
|
|
156
|
+
base64ToPublicKey: () => base64ToPublicKey,
|
|
157
|
+
base64ToUint8Array: () => base64ToUint8Array,
|
|
158
|
+
bytesToMnemonic: () => bytesToMnemonic,
|
|
159
|
+
bytesToUuid: () => bytesToUuid,
|
|
160
|
+
genMnemonic: () => genMnemonic,
|
|
161
|
+
generateUuid: () => generateUuid,
|
|
162
|
+
hexToUint8Array: () => hexToUint8Array,
|
|
163
|
+
mnemonicToBytes: () => mnemonicToBytes,
|
|
164
|
+
publicKeyToBase64: () => publicKeyToBase64,
|
|
165
|
+
uint8ArrayToBase64: () => uint8ArrayToBase64,
|
|
166
|
+
uint8ArrayToHex: () => uint8ArrayToHex,
|
|
167
|
+
uint8ToUTF8: () => uint8ToUTF8,
|
|
168
|
+
uuidToBytes: () => uuidToBytes
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { bytesToMnemonic as a, base64ToPublicKey as c, base64ToUint8Array as d, hexToUint8Array as f, uint8ToUTF8 as h, uuidToBytes as i, publicKeyToBase64 as l, uint8ArrayToHex as m, bytesToUuid as n, genMnemonic as o, uint8ArrayToBase64 as p, generateUuid as r, mnemonicToBytes as s, utils_exports as t, UTF8ToUint8 as u };
|
|
173
|
+
//# sourceMappingURL=utils-DS04iUcX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DS04iUcX.mjs","names":["uuidv4"],"sources":["../src/utils/converters.ts","../src/utils/keyConverters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.ts","../src/utils/index.ts"],"sourcesContent":["import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';\n\n/**\n * Converts a Uint8Array into a hexadecimal string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The hexadecimal string representation of the array.\n */\nexport function uint8ArrayToHex(array: Uint8Array): string {\n return bytesToHex(array);\n}\n\n/**\n * Converts a UTF-8 string into a Uint8Array.\n *\n * @param str - The UTF-8 string to convert.\n * @returns A Uint8Array created from the UTF-8 string.\n */\nexport function UTF8ToUint8(str: string): Uint8Array {\n return new TextEncoder().encode(str);\n}\n\n/**\n * Converts an Uint8Array into a UTF-8 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The UTF-8 string representation of the array.\n */\nexport function uint8ToUTF8(array: Uint8Array): string {\n return new TextDecoder().decode(array);\n}\n\n/**\n * Converts a hexadecimal string into a Uint8Array.\n *\n * @param hex - The hexadecimal string to convert.\n * @returns A Uint8Array created from the hex string.\n */\nexport function hexToUint8Array(hex: string): Uint8Array {\n return hexToBytes(hex);\n}\n\n/**\n * Converts a Uint8Array into a base64 string.\n *\n * @param array - The Uint8Array to convert.\n * @returns The base64 string representation of the array.\n */\nexport function uint8ArrayToBase64(buffer: Uint8Array): string {\n const array = Uint16Array.from(buffer);\n const binaryString = new TextDecoder('UTF-16').decode(array);\n return btoa(binaryString);\n}\n\n/**\n * Converts a base64 string into a Uint8Array.\n *\n * @param str - The base64 string to convert.\n * @returns A Uint8Array created from the base64 string.\n */\nexport function base64ToUint8Array(str: string): Uint8Array {\n const binaryString = atob(str);\n const len = binaryString.length;\n const array = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n array[i] = binaryString.codePointAt(i)!;\n }\n return new Uint8Array(array.buffer);\n}\n","import { uint8ArrayToBase64, base64ToUint8Array } from '.';\nimport { PublicKeys, PublicKeysBase64 } from '../types';\nimport { exportPublicKey, importPublicKey } from '../asymmetric-crypto';\n\n/**\n * Converts a base64 string into PublicKeys type.\n *\n * @param base64 - The base64 representation of the public key.\n * @returns The resulting PublicKeys.\n */\nexport async function base64ToPublicKey(base64: PublicKeysBase64): Promise<PublicKeys> {\n try {\n const eccPublicKeyBytes = base64ToUint8Array(base64.eccPublicKeyBase64);\n const eccPublicKey = await importPublicKey(eccPublicKeyBytes);\n const kyberPublicKey = base64ToUint8Array(base64.kyberPublicKeyBase64);\n return {\n eccPublicKey: eccPublicKey,\n kyberPublicKey: kyberPublicKey,\n };\n } catch (error) {\n throw new Error('Failed to convert base64 to PublicKeys', { cause: error });\n }\n}\n\n/**\n * Converts a PublicKeys type into PublicKeysBase64.\n *\n * @param key - The PublicKeys key.\n * @returns The resulting PublicKeysBase64.\n */\nexport async function publicKeyToBase64(key: PublicKeys): Promise<PublicKeysBase64> {\n try {\n const eccPublicKeyArray = await exportPublicKey(key.eccPublicKey);\n const keys = {\n eccPublicKeyBase64: uint8ArrayToBase64(eccPublicKeyArray),\n kyberPublicKeyBase64: uint8ArrayToBase64(key.kyberPublicKey),\n };\n return keys;\n } catch (error) {\n throw new Error('Failed to convert key of the type PublicKeys to PublicKeysBase64', { cause: error });\n }\n}\n","import * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BIT_LENGTH } from '../constants';\n/**\n * Generates a mnemonic\n *\n * @returns The generated mnemonic.\n */\nexport function genMnemonic(): string {\n return bip39.generateMnemonic(wordlist, AES_KEY_BIT_LENGTH);\n}\n\n/**\n * Converts a mnemonic to Uint8Array\n *\n * @param mnemonic - The mnemonic to convert\n * @returns The mnemonic as Uint8Array\n */\nexport function mnemonicToBytes(mnemonic: string): Uint8Array {\n return bip39.mnemonicToEntropy(mnemonic, wordlist);\n}\n\n/**\n * Converts a Uint8Array to a mnemonic\n *\n * @param bytes - The bytes to convert\n * @returns The mnemonic string\n */\nexport function bytesToMnemonic(bytes: Uint8Array): string {\n return bip39.entropyToMnemonic(bytes, wordlist);\n}\n","import { v4 as uuidv4, parse, stringify } from 'uuid';\n/**\n * Creates a random identifier.\n *\n * @returns The resulting auxilary string\n */\nexport function generateUuid(): string {\n return uuidv4();\n}\n\nexport function uuidToBytes(uuid: string): Uint8Array {\n return parse(uuid);\n}\n\nexport function bytesToUuid(bytes: Uint8Array): string {\n return stringify(bytes);\n}\n","export * from './converters';\nexport * from './keyConverters';\nexport * from './genMnemonic';\nexport * from './genID';\n"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,WAAW,MAAM;;;;;;;;AAS1B,SAAgB,YAAY,KAAyB;AACnD,QAAO,IAAI,aAAa,CAAC,OAAO,IAAI;;;;;;;;AAStC,SAAgB,YAAY,OAA2B;AACrD,QAAO,IAAI,aAAa,CAAC,OAAO,MAAM;;;;;;;;AASxC,SAAgB,gBAAgB,KAAyB;AACvD,QAAO,WAAW,IAAI;;;;;;;;AASxB,SAAgB,mBAAmB,QAA4B;CAC7D,MAAM,QAAQ,YAAY,KAAK,OAAO;CACtC,MAAM,eAAe,IAAI,YAAY,SAAS,CAAC,OAAO,MAAM;AAC5D,QAAO,KAAK,aAAa;;;;;;;;AAS3B,SAAgB,mBAAmB,KAAyB;CAC1D,MAAM,eAAe,KAAK,IAAI;CAC9B,MAAM,MAAM,aAAa;CACzB,MAAM,QAAQ,IAAI,WAAW,IAAI;AACjC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IACvB,OAAM,KAAK,aAAa,YAAY,EAAE;AAExC,QAAO,IAAI,WAAW,MAAM,OAAO;;;;;;;;;;;ACzDrC,eAAsB,kBAAkB,QAA+C;AACrF,KAAI;AAIF,SAAO;GACL,cAHmB,MAAM,gBADD,mBAAmB,OAAO,mBAAmB,CACV;GAI3D,gBAHqB,mBAAmB,OAAO,qBAAqB;GAIrE;UACM,OAAO;AACd,QAAM,IAAI,MAAM,0CAA0C,EAAE,OAAO,OAAO,CAAC;;;;;;;;;AAU/E,eAAsB,kBAAkB,KAA4C;AAClF,KAAI;AAMF,SAJa;GACX,oBAAoB,mBAFI,MAAM,gBAAgB,IAAI,aAAa,CAEN;GACzD,sBAAsB,mBAAmB,IAAI,eAAe;GAC7D;UAEM,OAAO;AACd,QAAM,IAAI,MAAM,oEAAoE,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AC/BzG,SAAgB,cAAsB;AACpC,QAAO,MAAM,iBAAiB,UAAU,mBAAmB;;;;;;;;AAS7D,SAAgB,gBAAgB,UAA8B;AAC5D,QAAO,MAAM,kBAAkB,UAAU,SAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAO,MAAM,kBAAkB,OAAO,SAAS;;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,QAAOA,IAAQ;;AAGjB,SAAgB,YAAY,MAA0B;AACpD,QAAO,MAAM,KAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,QAAO,UAAU,MAAM"}
|