internxt-crypto 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asymmetric-crypto.js +3 -4
- package/dist/asymmetric-crypto.js.map +1 -1
- package/dist/asymmetric-crypto.mjs +1 -2
- package/dist/asymmetric-crypto.mjs.map +1 -1
- package/dist/chunk-C13QxCFV.js +50 -0
- package/dist/chunk-CfYAbeIz.mjs +13 -0
- package/dist/constants.js +2 -3
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/derive-key.js +50 -5
- package/dist/derive-key.js.map +1 -0
- package/dist/derive-key.mjs +46 -2
- package/dist/derive-key.mjs.map +1 -0
- package/dist/{deriveKeysFromPassword-iMHv-tIA.js → derive-password-CbYRDq7V.js} +25 -30
- package/dist/derive-password-CbYRDq7V.js.map +1 -0
- package/dist/{deriveKeysFromPassword-DFzo2OII.mjs → derive-password-PED-YfwE.mjs} +27 -34
- package/dist/derive-password-PED-YfwE.mjs.map +1 -0
- package/dist/derive-password.js +5 -6
- package/dist/derive-password.mjs +2 -3
- package/dist/{emailKeys-BFI-paQq.js → email-crypto-Cr7znO1a.js} +116 -121
- package/dist/email-crypto-Cr7znO1a.js.map +1 -0
- package/dist/{emailKeys-BjIeINfC.mjs → email-crypto-cHDsjSb5.mjs} +7 -12
- package/dist/email-crypto-cHDsjSb5.mjs.map +1 -0
- package/dist/email-crypto.d.mts +1 -1
- package/dist/email-crypto.d.ts +1 -1
- package/dist/email-crypto.js +17 -18
- package/dist/email-crypto.mjs +2 -3
- package/dist/hash.js +3 -4
- package/dist/hash.js.map +1 -1
- package/dist/hash.mjs +1 -2
- package/dist/hash.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -56
- package/dist/index.mjs +7 -8
- package/dist/{emailEncryptionKey-CYvr26FG.mjs → keystore-crypto-C6F-NQdX.mjs} +12 -15
- package/dist/keystore-crypto-C6F-NQdX.mjs.map +1 -0
- package/dist/{emailEncryptionKey-Ba95VuFO.js → keystore-crypto-CFiiGohl.js} +67 -70
- package/dist/keystore-crypto-CFiiGohl.js.map +1 -0
- package/dist/keystore-crypto.d.mts +1 -1
- package/dist/keystore-crypto.d.ts +1 -1
- package/dist/keystore-crypto.js +11 -12
- package/dist/keystore-crypto.mjs +2 -3
- package/dist/post-quantum-crypto.js +3 -4
- package/dist/post-quantum-crypto.js.map +1 -1
- package/dist/post-quantum-crypto.mjs +1 -2
- package/dist/post-quantum-crypto.mjs.map +1 -1
- package/dist/storage-service.js +13 -15
- package/dist/storage-service.js.map +1 -1
- package/dist/storage-service.mjs +2 -4
- package/dist/storage-service.mjs.map +1 -1
- package/dist/symmetric-crypto.js +51 -5
- package/dist/symmetric-crypto.js.map +1 -0
- package/dist/symmetric-crypto.mjs +47 -2
- package/dist/symmetric-crypto.mjs.map +1 -0
- package/dist/types-4P0WII1D.d.ts +49 -0
- package/dist/types-4P0WII1D.d.ts.map +1 -0
- package/dist/types-DAPJQG8U.d.mts +49 -0
- package/dist/types-DAPJQG8U.d.mts.map +1 -0
- package/dist/types.d.mts +2 -49
- package/dist/types.d.ts +2 -49
- package/dist/types.js +2 -3
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils.js +127 -14
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +113 -2
- package/dist/utils.mjs.map +1 -0
- package/dist/{xwing-iRWVRtNE.js → xwing-7fEqAT7W.js} +18 -19
- package/dist/{xwing-iRWVRtNE.js.map → xwing-7fEqAT7W.js.map} +1 -1
- package/dist/{xwing-CQmQX6hn.mjs → xwing-B34h5e3Z.mjs} +2 -3
- package/dist/{xwing-CQmQX6hn.mjs.map → xwing-B34h5e3Z.mjs.map} +1 -1
- package/package.json +22 -22
- package/dist/aes-B8TA-JKq.mjs +0 -49
- package/dist/aes-B8TA-JKq.mjs.map +0 -1
- package/dist/aes-CuW_SPl-.js +0 -67
- package/dist/aes-CuW_SPl-.js.map +0 -1
- package/dist/chunk-DQk6qfdC.mjs +0 -18
- package/dist/chunk-EbLFQX5m.js +0 -60
- package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs +0 -49
- package/dist/deriveKeysFromMnemonic-DB0UHE-y.mjs.map +0 -1
- package/dist/deriveKeysFromMnemonic-Dbx7VSBQ.js +0 -67
- package/dist/deriveKeysFromMnemonic-Dbx7VSBQ.js.map +0 -1
- package/dist/deriveKeysFromPassword-DFzo2OII.mjs.map +0 -1
- package/dist/deriveKeysFromPassword-iMHv-tIA.js.map +0 -1
- package/dist/emailEncryptionKey-Ba95VuFO.js.map +0 -1
- package/dist/emailEncryptionKey-CYvr26FG.mjs.map +0 -1
- package/dist/emailKeys-BFI-paQq.js.map +0 -1
- package/dist/emailKeys-BjIeINfC.mjs.map +0 -1
- package/dist/genID-D08K7JPr.mjs +0 -117
- package/dist/genID-D08K7JPr.mjs.map +0 -1
- package/dist/genID-cWOPmspk.js +0 -190
- package/dist/genID-cWOPmspk.js.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/dist/utils.js
CHANGED
|
@@ -1,15 +1,128 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
2
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("./chunk-C13QxCFV.js");
|
|
3
|
+
require("./constants.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
|
+
//#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 (0, _noble_hashes_utils_js.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 (0, _noble_hashes_utils_js.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
|
+
//#endregion
|
|
71
|
+
//#region src/utils/genMnemonic.ts
|
|
72
|
+
/**
|
|
73
|
+
* Generates a mnemonic
|
|
74
|
+
*
|
|
75
|
+
* @returns The generated mnemonic.
|
|
76
|
+
*/
|
|
77
|
+
function genMnemonic() {
|
|
78
|
+
return _scure_bip39.generateMnemonic(_scure_bip39_wordlists_english_js.wordlist, 256);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Converts a mnemonic to Uint8Array
|
|
82
|
+
*
|
|
83
|
+
* @param mnemonic - The mnemonic to convert
|
|
84
|
+
* @returns The mnemonic as Uint8Array
|
|
85
|
+
*/
|
|
86
|
+
function mnemonicToBytes(mnemonic) {
|
|
87
|
+
return _scure_bip39.mnemonicToEntropy(mnemonic, _scure_bip39_wordlists_english_js.wordlist);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Converts a Uint8Array to a mnemonic
|
|
91
|
+
*
|
|
92
|
+
* @param bytes - The bytes to convert
|
|
93
|
+
* @returns The mnemonic string
|
|
94
|
+
*/
|
|
95
|
+
function bytesToMnemonic(bytes) {
|
|
96
|
+
return _scure_bip39.entropyToMnemonic(bytes, _scure_bip39_wordlists_english_js.wordlist);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/utils/genID.ts
|
|
100
|
+
/**
|
|
101
|
+
* Creates a random identifier.
|
|
102
|
+
*
|
|
103
|
+
* @returns The resulting auxilary string
|
|
104
|
+
*/
|
|
105
|
+
function generateUuid() {
|
|
106
|
+
return (0, uuid.v4)();
|
|
107
|
+
}
|
|
108
|
+
function uuidToBytes(uuid$1) {
|
|
109
|
+
return (0, uuid.parse)(uuid$1);
|
|
110
|
+
}
|
|
111
|
+
function bytesToUuid(bytes) {
|
|
112
|
+
return (0, uuid.stringify)(bytes);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
exports.UTF8ToUint8 = UTF8ToUint8;
|
|
116
|
+
exports.base64ToUint8Array = base64ToUint8Array;
|
|
117
|
+
exports.bytesToMnemonic = bytesToMnemonic;
|
|
118
|
+
exports.bytesToUuid = bytesToUuid;
|
|
119
|
+
exports.genMnemonic = genMnemonic;
|
|
120
|
+
exports.generateUuid = generateUuid;
|
|
121
|
+
exports.hexToUint8Array = hexToUint8Array;
|
|
122
|
+
exports.mnemonicToBytes = mnemonicToBytes;
|
|
123
|
+
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
|
124
|
+
exports.uint8ArrayToHex = uint8ArrayToHex;
|
|
125
|
+
exports.uint8ToUTF8 = uint8ToUTF8;
|
|
126
|
+
exports.uuidToBytes = uuidToBytes;
|
|
3
127
|
|
|
4
|
-
|
|
5
|
-
exports.base64ToUint8Array = require_genID.base64ToUint8Array;
|
|
6
|
-
exports.bytesToMnemonic = require_genID.bytesToMnemonic;
|
|
7
|
-
exports.bytesToUuid = require_genID.bytesToUuid;
|
|
8
|
-
exports.genMnemonic = require_genID.genMnemonic;
|
|
9
|
-
exports.generateUuid = require_genID.generateUuid;
|
|
10
|
-
exports.hexToUint8Array = require_genID.hexToUint8Array;
|
|
11
|
-
exports.mnemonicToBytes = require_genID.mnemonicToBytes;
|
|
12
|
-
exports.uint8ArrayToBase64 = require_genID.uint8ArrayToBase64;
|
|
13
|
-
exports.uint8ArrayToHex = require_genID.uint8ArrayToHex;
|
|
14
|
-
exports.uint8ToUTF8 = require_genID.uint8ToUTF8;
|
|
15
|
-
exports.uuidToBytes = require_genID.uuidToBytes;
|
|
128
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["bip39","wordlist","uuid"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.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 * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_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_BYTE_LENGTH * 8);\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"],"mappings":";;;;;;;;;;;;;;;AAQA,SAAgB,gBAAgB,OAA2B;AACzD,SAAA,GAAA,uBAAA,YAAkB,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,SAAA,GAAA,uBAAA,YAAkB,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;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAOA,aAAM,iBAAiBC,kCAAAA,UAAAA,IAAkC;;;;;;;;AASlE,SAAgB,gBAAgB,UAA8B;AAC5D,QAAOD,aAAM,kBAAkB,UAAUC,kCAAAA,SAAS;;;;;;;;AASpD,SAAgB,gBAAgB,OAA2B;AACzD,QAAOD,aAAM,kBAAkB,OAAOC,kCAAAA,SAAS;;;;;;;;;ACvBjD,SAAgB,eAAuB;AACrC,SAAA,GAAA,KAAA,KAAe;;AAGjB,SAAgB,YAAY,QAA0B;AACpD,SAAA,GAAA,KAAA,OAAaC,OAAK;;AAGpB,SAAgB,YAAY,OAA2B;AACrD,SAAA,GAAA,KAAA,WAAiB,MAAM"}
|
package/dist/utils.mjs
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./constants.mjs";
|
|
2
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
import * as bip39 from "@scure/bip39";
|
|
4
|
+
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
5
|
+
import { parse, stringify, v4 } from "uuid";
|
|
6
|
+
//#region src/utils/converters.ts
|
|
7
|
+
/**
|
|
8
|
+
* Converts a Uint8Array into a hexadecimal string.
|
|
9
|
+
*
|
|
10
|
+
* @param array - The Uint8Array to convert.
|
|
11
|
+
* @returns The hexadecimal string representation of the array.
|
|
12
|
+
*/
|
|
13
|
+
function uint8ArrayToHex(array) {
|
|
14
|
+
return bytesToHex(array);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts a UTF-8 string into a Uint8Array.
|
|
18
|
+
*
|
|
19
|
+
* @param str - The UTF-8 string to convert.
|
|
20
|
+
* @returns A Uint8Array created from the UTF-8 string.
|
|
21
|
+
*/
|
|
22
|
+
function UTF8ToUint8(str) {
|
|
23
|
+
return new TextEncoder().encode(str);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Converts an Uint8Array into a UTF-8 string.
|
|
27
|
+
*
|
|
28
|
+
* @param array - The Uint8Array to convert.
|
|
29
|
+
* @returns The UTF-8 string representation of the array.
|
|
30
|
+
*/
|
|
31
|
+
function uint8ToUTF8(array) {
|
|
32
|
+
return new TextDecoder().decode(array);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts a hexadecimal string into a Uint8Array.
|
|
36
|
+
*
|
|
37
|
+
* @param hex - The hexadecimal string to convert.
|
|
38
|
+
* @returns A Uint8Array created from the hex string.
|
|
39
|
+
*/
|
|
40
|
+
function hexToUint8Array(hex) {
|
|
41
|
+
return hexToBytes(hex);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts a Uint8Array into a base64 string.
|
|
45
|
+
*
|
|
46
|
+
* @param array - The Uint8Array to convert.
|
|
47
|
+
* @returns The base64 string representation of the array.
|
|
48
|
+
*/
|
|
49
|
+
function uint8ArrayToBase64(buffer) {
|
|
50
|
+
const array = Uint16Array.from(buffer);
|
|
51
|
+
const binaryString = new TextDecoder("UTF-16").decode(array);
|
|
52
|
+
return btoa(binaryString);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Converts a base64 string into a Uint8Array.
|
|
56
|
+
*
|
|
57
|
+
* @param str - The base64 string to convert.
|
|
58
|
+
* @returns A Uint8Array created from the base64 string.
|
|
59
|
+
*/
|
|
60
|
+
function base64ToUint8Array(str) {
|
|
61
|
+
const binaryString = atob(str);
|
|
62
|
+
const len = binaryString.length;
|
|
63
|
+
const array = new Uint8Array(len);
|
|
64
|
+
for (let i = 0; i < len; i++) array[i] = binaryString.codePointAt(i);
|
|
65
|
+
return new Uint8Array(array.buffer);
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/utils/genMnemonic.ts
|
|
69
|
+
/**
|
|
70
|
+
* Generates a mnemonic
|
|
71
|
+
*
|
|
72
|
+
* @returns The generated mnemonic.
|
|
73
|
+
*/
|
|
74
|
+
function genMnemonic() {
|
|
75
|
+
return bip39.generateMnemonic(wordlist, 256);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Converts a mnemonic to Uint8Array
|
|
79
|
+
*
|
|
80
|
+
* @param mnemonic - The mnemonic to convert
|
|
81
|
+
* @returns The mnemonic as Uint8Array
|
|
82
|
+
*/
|
|
83
|
+
function mnemonicToBytes(mnemonic) {
|
|
84
|
+
return bip39.mnemonicToEntropy(mnemonic, wordlist);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts a Uint8Array to a mnemonic
|
|
88
|
+
*
|
|
89
|
+
* @param bytes - The bytes to convert
|
|
90
|
+
* @returns The mnemonic string
|
|
91
|
+
*/
|
|
92
|
+
function bytesToMnemonic(bytes) {
|
|
93
|
+
return bip39.entropyToMnemonic(bytes, wordlist);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/utils/genID.ts
|
|
97
|
+
/**
|
|
98
|
+
* Creates a random identifier.
|
|
99
|
+
*
|
|
100
|
+
* @returns The resulting auxilary string
|
|
101
|
+
*/
|
|
102
|
+
function generateUuid() {
|
|
103
|
+
return v4();
|
|
104
|
+
}
|
|
105
|
+
function uuidToBytes(uuid) {
|
|
106
|
+
return parse(uuid);
|
|
107
|
+
}
|
|
108
|
+
function bytesToUuid(bytes) {
|
|
109
|
+
return stringify(bytes);
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { UTF8ToUint8, base64ToUint8Array, bytesToMnemonic, bytesToUuid, genMnemonic, generateUuid, hexToUint8Array, mnemonicToBytes, uint8ArrayToBase64, uint8ArrayToHex, uint8ToUTF8, uuidToBytes };
|
|
2
113
|
|
|
3
|
-
|
|
114
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["uuidv4"],"sources":["../src/utils/converters.ts","../src/utils/genMnemonic.ts","../src/utils/genID.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 * as bip39 from '@scure/bip39';\nimport { wordlist } from '@scure/bip39/wordlists/english.js';\nimport { AES_KEY_BYTE_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_BYTE_LENGTH * 8);\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"],"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;;;;;;;;;AC3DrC,SAAgB,cAAsB;AACpC,QAAO,MAAM,iBAAiB,UAAA,IAAkC;;;;;;;;AASlE,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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
require("./chunk-C13QxCFV.js");
|
|
2
2
|
let _noble_post_quantum_hybrid_js = require("@noble/post-quantum/hybrid.js");
|
|
3
|
-
|
|
4
3
|
//#region src/hybrid-crypto/xwing.ts
|
|
5
4
|
function genHybridKeys(seed) {
|
|
6
5
|
return _noble_post_quantum_hybrid_js.ml_kem768_x25519.keygen(seed);
|
|
@@ -11,24 +10,24 @@ function encapsulateHybrid(publicKey) {
|
|
|
11
10
|
function decapsulateHybrid(cipherText, secretKey) {
|
|
12
11
|
return _noble_post_quantum_hybrid_js.ml_kem768_x25519.decapsulate(cipherText, secretKey);
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
|
-
Object.defineProperty(exports,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
Object.defineProperty(exports, "decapsulateHybrid", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return decapsulateHybrid;
|
|
18
|
+
}
|
|
21
19
|
});
|
|
22
|
-
Object.defineProperty(exports,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
Object.defineProperty(exports, "encapsulateHybrid", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return encapsulateHybrid;
|
|
24
|
+
}
|
|
27
25
|
});
|
|
28
|
-
Object.defineProperty(exports,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
Object.defineProperty(exports, "genHybridKeys", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function() {
|
|
29
|
+
return genHybridKeys;
|
|
30
|
+
}
|
|
33
31
|
});
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=xwing-7fEqAT7W.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xwing-
|
|
1
|
+
{"version":3,"file":"xwing-7fEqAT7W.js","names":["hybridCipher"],"sources":["../src/hybrid-crypto/xwing.ts"],"sourcesContent":["import { ml_kem768_x25519 as hybridCipher } from '@noble/post-quantum/hybrid.js';\nimport { HybridKeyPair } from '../types';\n\nexport function genHybridKeys(seed?: Uint8Array): HybridKeyPair {\n return hybridCipher.keygen(seed);\n}\n\nexport function encapsulateHybrid(publicKey: Uint8Array): { cipherText: Uint8Array; sharedSecret: Uint8Array } {\n return hybridCipher.encapsulate(publicKey);\n}\n\nexport function decapsulateHybrid(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n return hybridCipher.decapsulate(cipherText, secretKey);\n}\n"],"mappings":";;;AAGA,SAAgB,cAAc,MAAkC;AAC9D,QAAOA,8BAAAA,iBAAa,OAAO,KAAK;;AAGlC,SAAgB,kBAAkB,WAA6E;AAC7G,QAAOA,8BAAAA,iBAAa,YAAY,UAAU;;AAG5C,SAAgB,kBAAkB,YAAwB,WAAmC;AAC3F,QAAOA,8BAAAA,iBAAa,YAAY,YAAY,UAAU"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ml_kem768_x25519 } from "@noble/post-quantum/hybrid.js";
|
|
2
|
-
|
|
3
2
|
//#region src/hybrid-crypto/xwing.ts
|
|
4
3
|
function genHybridKeys(seed) {
|
|
5
4
|
return ml_kem768_x25519.keygen(seed);
|
|
@@ -10,7 +9,7 @@ function encapsulateHybrid(publicKey) {
|
|
|
10
9
|
function decapsulateHybrid(cipherText, secretKey) {
|
|
11
10
|
return ml_kem768_x25519.decapsulate(cipherText, secretKey);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
13
|
export { encapsulateHybrid as n, genHybridKeys as r, decapsulateHybrid as t };
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=xwing-B34h5e3Z.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xwing-
|
|
1
|
+
{"version":3,"file":"xwing-B34h5e3Z.mjs","names":["hybridCipher"],"sources":["../src/hybrid-crypto/xwing.ts"],"sourcesContent":["import { ml_kem768_x25519 as hybridCipher } from '@noble/post-quantum/hybrid.js';\nimport { HybridKeyPair } from '../types';\n\nexport function genHybridKeys(seed?: Uint8Array): HybridKeyPair {\n return hybridCipher.keygen(seed);\n}\n\nexport function encapsulateHybrid(publicKey: Uint8Array): { cipherText: Uint8Array; sharedSecret: Uint8Array } {\n return hybridCipher.encapsulate(publicKey);\n}\n\nexport function decapsulateHybrid(cipherText: Uint8Array, secretKey: Uint8Array): Uint8Array {\n return hybridCipher.decapsulate(cipherText, secretKey);\n}\n"],"mappings":";;AAGA,SAAgB,cAAc,MAAkC;AAC9D,QAAOA,iBAAa,OAAO,KAAK;;AAGlC,SAAgB,kBAAkB,WAA6E;AAC7G,QAAOA,iBAAa,YAAY,UAAU;;AAG5C,SAAgB,kBAAkB,YAAwB,WAAmC;AAC3F,QAAOA,iBAAa,YAAY,YAAY,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "internxt-crypto",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,31 +19,31 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@eslint/js": "^10.0.1",
|
|
22
|
-
"@internxt/eslint-config-internxt": "2.0
|
|
23
|
-
"@internxt/prettier-config": "
|
|
24
|
-
"@playwright/test": "^1.
|
|
25
|
-
"@types/node": "^25.
|
|
26
|
-
"@vitest/browser-playwright": "^4.
|
|
27
|
-
"@vitest/coverage-istanbul": "^4.
|
|
28
|
-
"@vitest/coverage-v8": "^4.
|
|
29
|
-
"eslint": "^10.0
|
|
30
|
-
"knip": "^
|
|
31
|
-
"lint-staged": "^
|
|
32
|
-
"playwright": "^1.
|
|
33
|
-
"prettier": "^3.
|
|
34
|
-
"tsdown": "^0.
|
|
35
|
-
"typescript": "^
|
|
36
|
-
"vitest": "^4.
|
|
22
|
+
"@internxt/eslint-config-internxt": "^2.1.0",
|
|
23
|
+
"@internxt/prettier-config": "^2.0.1",
|
|
24
|
+
"@playwright/test": "^1.59.1",
|
|
25
|
+
"@types/node": "^25.6.0",
|
|
26
|
+
"@vitest/browser-playwright": "^4.1.5",
|
|
27
|
+
"@vitest/coverage-istanbul": "^4.1.5",
|
|
28
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
29
|
+
"eslint": "^10.3.0",
|
|
30
|
+
"knip": "^6.11.0",
|
|
31
|
+
"lint-staged": "^17.0.2",
|
|
32
|
+
"playwright": "^1.59.1",
|
|
33
|
+
"prettier": "^3.8.3",
|
|
34
|
+
"tsdown": "^0.21.10",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.1.5"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@noble/ciphers": "^2.
|
|
40
|
-
"@noble/curves": "^2.0
|
|
41
|
-
"@noble/hashes": "^2.0
|
|
42
|
-
"@noble/post-quantum": "^0.
|
|
43
|
-
"@scure/bip39": "^2.0
|
|
39
|
+
"@noble/ciphers": "^2.2.0",
|
|
40
|
+
"@noble/curves": "^2.2.0",
|
|
41
|
+
"@noble/hashes": "^2.2.0",
|
|
42
|
+
"@noble/post-quantum": "^0.6.1",
|
|
43
|
+
"@scure/bip39": "^2.2.0",
|
|
44
44
|
"hash-wasm": "^4.12.0",
|
|
45
45
|
"husky": "^9.1.7",
|
|
46
|
-
"uuid": "^
|
|
46
|
+
"uuid": "^14.0.0"
|
|
47
47
|
},
|
|
48
48
|
"exports": {
|
|
49
49
|
".": {
|
package/dist/aes-B8TA-JKq.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { AES_KEY_BYTE_LENGTH, IV_LEN_BYTES } from "./constants.mjs";
|
|
2
|
-
import { concatBytes, randomBytes } from "@noble/hashes/utils.js";
|
|
3
|
-
import { gcm } from "@noble/ciphers/webcrypto.js";
|
|
4
|
-
|
|
5
|
-
//#region src/symmetric-crypto/aes.ts
|
|
6
|
-
/**
|
|
7
|
-
* Symmetrically encrypts the message
|
|
8
|
-
*
|
|
9
|
-
* @param encryptionKey - The symmetric key used for message encryption
|
|
10
|
-
* @param message - The message to encrypt
|
|
11
|
-
* @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
|
|
12
|
-
* @returns The resulting ciphertext.
|
|
13
|
-
*/
|
|
14
|
-
async function encryptSymmetrically(encryptionKey, message, aux) {
|
|
15
|
-
try {
|
|
16
|
-
const iv = randomBytes(IV_LEN_BYTES);
|
|
17
|
-
return concatBytes(await gcm(encryptionKey, iv, aux).encrypt(message), iv);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
throw new Error("Failed to encrypt symmetrically", { cause: error });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Decryps symmetrically encrypted message
|
|
24
|
-
*
|
|
25
|
-
* @param encryptionKey - The symmetric key used for message encryption
|
|
26
|
-
* @param encryptedMessage - The ciphertext
|
|
27
|
-
* @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
|
|
28
|
-
* @returns The resulting ciphertext.
|
|
29
|
-
*/
|
|
30
|
-
async function decryptSymmetrically(encryptionKey, encryptedMessage, aux) {
|
|
31
|
-
try {
|
|
32
|
-
const ciphertext = encryptedMessage.slice(0, encryptedMessage.length - IV_LEN_BYTES);
|
|
33
|
-
return await gcm(encryptionKey, encryptedMessage.slice(encryptedMessage.length - IV_LEN_BYTES), aux).decrypt(ciphertext);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw new Error("Failed to decrypt symmetrically", { cause: error });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Generates symmetric key as Uint8Array
|
|
40
|
-
*
|
|
41
|
-
* @returns The generated Uint8Array.
|
|
42
|
-
*/
|
|
43
|
-
function genSymmetricKey() {
|
|
44
|
-
return randomBytes(AES_KEY_BYTE_LENGTH);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
export { encryptSymmetrically as n, genSymmetricKey as r, decryptSymmetrically as t };
|
|
49
|
-
//# sourceMappingURL=aes-B8TA-JKq.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-B8TA-JKq.mjs","names":["aeadCipher"],"sources":["../src/symmetric-crypto/aes.ts"],"sourcesContent":["import { concatBytes, randomBytes } from '@noble/hashes/utils.js';\nimport { IV_LEN_BYTES, AES_KEY_BYTE_LENGTH } from '../constants';\nimport { gcm as aeadCipher } from '@noble/ciphers/webcrypto.js';\n\n/**\n * Symmetrically encrypts the message\n *\n * @param encryptionKey - The symmetric key used for message encryption\n * @param message - The message to encrypt\n * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.\n * @returns The resulting ciphertext.\n */\nexport async function encryptSymmetrically(\n encryptionKey: Uint8Array,\n message: Uint8Array,\n aux?: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const iv = randomBytes(IV_LEN_BYTES);\n const ciphertext = await aeadCipher(encryptionKey, iv, aux).encrypt(message);\n return concatBytes(ciphertext, iv);\n } catch (error) {\n throw new Error('Failed to encrypt symmetrically', { cause: error });\n }\n}\n\n/**\n * Decryps symmetrically encrypted message\n *\n * @param encryptionKey - The symmetric key used for message encryption\n * @param encryptedMessage - The ciphertext\n * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.\n * @returns The resulting ciphertext.\n */\nexport async function decryptSymmetrically(\n encryptionKey: Uint8Array,\n encryptedMessage: Uint8Array,\n aux?: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const ciphertext = encryptedMessage.slice(0, encryptedMessage.length - IV_LEN_BYTES);\n const iv = encryptedMessage.slice(encryptedMessage.length - IV_LEN_BYTES);\n const result = await aeadCipher(encryptionKey, iv, aux).decrypt(ciphertext);\n return result;\n } catch (error) {\n throw new Error('Failed to decrypt symmetrically', { cause: error });\n }\n}\n\n/**\n * Generates symmetric key as Uint8Array\n *\n * @returns The generated Uint8Array.\n */\nexport function genSymmetricKey(): Uint8Array {\n return randomBytes(AES_KEY_BYTE_LENGTH);\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,eAAsB,qBACpB,eACA,SACA,KACqB;AACrB,KAAI;EACF,MAAM,KAAK,YAAY,aAAa;AAEpC,SAAO,YADY,MAAMA,IAAW,eAAe,IAAI,IAAI,CAAC,QAAQ,QAAQ,EAC7C,GAAG;UAC3B,OAAO;AACd,QAAM,IAAI,MAAM,mCAAmC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYxE,eAAsB,qBACpB,eACA,kBACA,KACqB;AACrB,KAAI;EACF,MAAM,aAAa,iBAAiB,MAAM,GAAG,iBAAiB,SAAS,aAAa;AAGpF,SADe,MAAMA,IAAW,eADrB,iBAAiB,MAAM,iBAAiB,SAAS,aAAa,EACtB,IAAI,CAAC,QAAQ,WAAW;UAEpE,OAAO;AACd,QAAM,IAAI,MAAM,mCAAmC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASxE,SAAgB,kBAA8B;AAC5C,QAAO,YAAY,oBAAoB"}
|
package/dist/aes-CuW_SPl-.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-EbLFQX5m.js');
|
|
2
|
-
const require_constants = require('./constants.js');
|
|
3
|
-
let _noble_hashes_utils_js = require("@noble/hashes/utils.js");
|
|
4
|
-
let _noble_ciphers_webcrypto_js = require("@noble/ciphers/webcrypto.js");
|
|
5
|
-
|
|
6
|
-
//#region src/symmetric-crypto/aes.ts
|
|
7
|
-
/**
|
|
8
|
-
* Symmetrically encrypts the message
|
|
9
|
-
*
|
|
10
|
-
* @param encryptionKey - The symmetric key used for message encryption
|
|
11
|
-
* @param message - The message to encrypt
|
|
12
|
-
* @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
|
|
13
|
-
* @returns The resulting ciphertext.
|
|
14
|
-
*/
|
|
15
|
-
async function encryptSymmetrically(encryptionKey, message, aux) {
|
|
16
|
-
try {
|
|
17
|
-
const iv = (0, _noble_hashes_utils_js.randomBytes)(require_constants.IV_LEN_BYTES);
|
|
18
|
-
return (0, _noble_hashes_utils_js.concatBytes)(await (0, _noble_ciphers_webcrypto_js.gcm)(encryptionKey, iv, aux).encrypt(message), iv);
|
|
19
|
-
} catch (error) {
|
|
20
|
-
throw new Error("Failed to encrypt symmetrically", { cause: error });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Decryps symmetrically encrypted message
|
|
25
|
-
*
|
|
26
|
-
* @param encryptionKey - The symmetric key used for message encryption
|
|
27
|
-
* @param encryptedMessage - The ciphertext
|
|
28
|
-
* @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.
|
|
29
|
-
* @returns The resulting ciphertext.
|
|
30
|
-
*/
|
|
31
|
-
async function decryptSymmetrically(encryptionKey, encryptedMessage, aux) {
|
|
32
|
-
try {
|
|
33
|
-
const ciphertext = encryptedMessage.slice(0, encryptedMessage.length - require_constants.IV_LEN_BYTES);
|
|
34
|
-
return await (0, _noble_ciphers_webcrypto_js.gcm)(encryptionKey, encryptedMessage.slice(encryptedMessage.length - require_constants.IV_LEN_BYTES), aux).decrypt(ciphertext);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw new Error("Failed to decrypt symmetrically", { cause: error });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generates symmetric key as Uint8Array
|
|
41
|
-
*
|
|
42
|
-
* @returns The generated Uint8Array.
|
|
43
|
-
*/
|
|
44
|
-
function genSymmetricKey() {
|
|
45
|
-
return (0, _noble_hashes_utils_js.randomBytes)(require_constants.AES_KEY_BYTE_LENGTH);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
Object.defineProperty(exports, 'decryptSymmetrically', {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
get: function () {
|
|
52
|
-
return decryptSymmetrically;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(exports, 'encryptSymmetrically', {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () {
|
|
58
|
-
return encryptSymmetrically;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(exports, 'genSymmetricKey', {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
get: function () {
|
|
64
|
-
return genSymmetricKey;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
//# sourceMappingURL=aes-CuW_SPl-.js.map
|
package/dist/aes-CuW_SPl-.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-CuW_SPl-.js","names":["IV_LEN_BYTES","AES_KEY_BYTE_LENGTH"],"sources":["../src/symmetric-crypto/aes.ts"],"sourcesContent":["import { concatBytes, randomBytes } from '@noble/hashes/utils.js';\nimport { IV_LEN_BYTES, AES_KEY_BYTE_LENGTH } from '../constants';\nimport { gcm as aeadCipher } from '@noble/ciphers/webcrypto.js';\n\n/**\n * Symmetrically encrypts the message\n *\n * @param encryptionKey - The symmetric key used for message encryption\n * @param message - The message to encrypt\n * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.\n * @returns The resulting ciphertext.\n */\nexport async function encryptSymmetrically(\n encryptionKey: Uint8Array,\n message: Uint8Array,\n aux?: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const iv = randomBytes(IV_LEN_BYTES);\n const ciphertext = await aeadCipher(encryptionKey, iv, aux).encrypt(message);\n return concatBytes(ciphertext, iv);\n } catch (error) {\n throw new Error('Failed to encrypt symmetrically', { cause: error });\n }\n}\n\n/**\n * Decryps symmetrically encrypted message\n *\n * @param encryptionKey - The symmetric key used for message encryption\n * @param encryptedMessage - The ciphertext\n * @param aux - The auxilary string (e.g., context string or timestamp) for AEAD.\n * @returns The resulting ciphertext.\n */\nexport async function decryptSymmetrically(\n encryptionKey: Uint8Array,\n encryptedMessage: Uint8Array,\n aux?: Uint8Array,\n): Promise<Uint8Array> {\n try {\n const ciphertext = encryptedMessage.slice(0, encryptedMessage.length - IV_LEN_BYTES);\n const iv = encryptedMessage.slice(encryptedMessage.length - IV_LEN_BYTES);\n const result = await aeadCipher(encryptionKey, iv, aux).decrypt(ciphertext);\n return result;\n } catch (error) {\n throw new Error('Failed to decrypt symmetrically', { cause: error });\n }\n}\n\n/**\n * Generates symmetric key as Uint8Array\n *\n * @returns The generated Uint8Array.\n */\nexport function genSymmetricKey(): Uint8Array {\n return randomBytes(AES_KEY_BYTE_LENGTH);\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,eAAsB,qBACpB,eACA,SACA,KACqB;AACrB,KAAI;EACF,MAAM,6CAAiBA,+BAAa;AAEpC,iDADmB,2CAAiB,eAAe,IAAI,IAAI,CAAC,QAAQ,QAAQ,EAC7C,GAAG;UAC3B,OAAO;AACd,QAAM,IAAI,MAAM,mCAAmC,EAAE,OAAO,OAAO,CAAC;;;;;;;;;;;AAYxE,eAAsB,qBACpB,eACA,kBACA,KACqB;AACrB,KAAI;EACF,MAAM,aAAa,iBAAiB,MAAM,GAAG,iBAAiB,SAASA,+BAAa;AAGpF,SADe,2CAAiB,eADrB,iBAAiB,MAAM,iBAAiB,SAASA,+BAAa,EACtB,IAAI,CAAC,QAAQ,WAAW;UAEpE,OAAO;AACd,QAAM,IAAI,MAAM,mCAAmC,EAAE,OAAO,OAAO,CAAC;;;;;;;;AASxE,SAAgB,kBAA8B;AAC5C,gDAAmBC,sCAAoB"}
|
package/dist/chunk-DQk6qfdC.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __exportAll as t };
|
package/dist/chunk-EbLFQX5m.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
-
var __exportAll = (all, no_symbols) => {
|
|
10
|
-
let target = {};
|
|
11
|
-
for (var name in all) {
|
|
12
|
-
__defProp(target, name, {
|
|
13
|
-
get: all[name],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (!no_symbols) {
|
|
18
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
19
|
-
}
|
|
20
|
-
return target;
|
|
21
|
-
};
|
|
22
|
-
var __copyProps = (to, from, except, desc) => {
|
|
23
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
25
|
-
key = keys[i];
|
|
26
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
27
|
-
__defProp(to, key, {
|
|
28
|
-
get: ((k) => from[k]).bind(null, key),
|
|
29
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return to;
|
|
35
|
-
};
|
|
36
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
37
|
-
value: mod,
|
|
38
|
-
enumerable: true
|
|
39
|
-
}) : target, mod));
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
|
-
|
|
43
|
-
Object.defineProperty(exports, '__commonJSMin', {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return __commonJSMin;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(exports, '__exportAll', {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
get: function () {
|
|
52
|
-
return __exportAll;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(exports, '__toESM', {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () {
|
|
58
|
-
return __toESM;
|
|
59
|
-
}
|
|
60
|
-
});
|