@vex-chat/crypto 1.0.11-rc.11 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/index.d.ts +26 -16
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -128
- package/dist/index.js.map +1 -0
- package/package.json +81 -73
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.changeset/migrate-to-native-crypto.md +0 -5
- package/.changeset/pre.json +0 -10
- package/CHANGELOG.md +0 -7
- package/RELEASING.md +0 -85
- package/jest.config.js +0 -16
- package/mise.toml +0 -3
- package/tsdoc.json +0 -34
package/README.md
CHANGED
|
@@ -10,9 +10,9 @@ All of the crypto functions for the key exchange are contained in here.
|
|
|
10
10
|
|
|
11
11
|
This library utilizes native Node.js crypto where possible for performance and security.
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
13
|
+
- **tweetnacl**: Primitives for signing and encryption (X25519 / Ed25519).
|
|
14
|
+
- **ed2curve**: Ed25519 signing key to X25519 encryption key conversion.
|
|
15
|
+
- **msgpackr**: High-performance MessagePack serialization (replacing `msgpack-lite`).
|
|
16
|
+
- **bip39**: Mnemonic generation for keys.
|
|
17
|
+
- **Node Crypto**: Native implementations for HKDF, PBKDF2, HMAC, and SHA hashing (replacing `futoin-hkdf`, `create-hmac`, and `sha.js`).
|
|
18
|
+
- **@stablelib**: Constant-time encoding for Base64 and UTF8.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { decode as decodeBase64, encode as encodeBase64 } from "@stablelib/base64";
|
|
2
2
|
import { decode as encodeUTF8, encode as decodeUTF8 } from "@stablelib/utf8";
|
|
3
|
-
import { IBaseMsg } from "@vex-chat/types";
|
|
3
|
+
import type { IBaseMsg } from "@vex-chat/types";
|
|
4
4
|
import ed2curve from "ed2curve";
|
|
5
5
|
/**
|
|
6
6
|
* Provides an interface that can map an ed25519 keypair to its equivalent
|
|
@@ -24,7 +24,7 @@ export declare class XUtils {
|
|
|
24
24
|
*
|
|
25
25
|
* @returns True if equal, else false.
|
|
26
26
|
*/
|
|
27
|
-
static bytesEqual(buf1:
|
|
27
|
+
static bytesEqual(buf1: Uint8Array | ArrayBuffer, buf2: Uint8Array | ArrayBuffer): boolean;
|
|
28
28
|
/**
|
|
29
29
|
* Returns a six bit Uint8Array representation of an integer.
|
|
30
30
|
* The integer must be positive, and it must be able to be stored
|
|
@@ -63,22 +63,31 @@ export declare class XUtils {
|
|
|
63
63
|
*/
|
|
64
64
|
static emptyHeader(): Uint8Array<ArrayBuffer>;
|
|
65
65
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
* Encrypts a secret key with a password and saves it as a file.
|
|
67
|
+
*
|
|
68
|
+
* @param path The path to save the keyfile.
|
|
69
|
+
/**
|
|
70
|
+
* Encrypts a secret key into a portable binary format.
|
|
71
|
+
* The result can be written to disk, sent over the network, etc.
|
|
72
|
+
* No I/O — the caller handles persistence.
|
|
73
|
+
*
|
|
74
|
+
* Format: [iterations(6)|salt(24)|nonce(24)|ciphertext(N)]
|
|
75
|
+
*
|
|
76
|
+
* @param password The password to derive the encryption key from.
|
|
77
|
+
* @param keyToSave The hex-encoded secret key to encrypt.
|
|
78
|
+
* @param iterationOverride Optional PBKDF2 iteration count (random if omitted).
|
|
79
|
+
* @returns The encrypted key data as a Uint8Array.
|
|
80
|
+
*/
|
|
81
|
+
static encryptKeyData: (password: string, keyToSave: string, iterationOverride?: number) => Uint8Array;
|
|
75
82
|
/**
|
|
76
|
-
* Decrypts
|
|
83
|
+
* Decrypts a secret key from the binary format produced by encryptKeyData().
|
|
84
|
+
* No I/O — the caller handles reading the data.
|
|
77
85
|
*
|
|
78
|
-
* @param
|
|
79
|
-
* @param password The password
|
|
86
|
+
* @param keyData The encrypted key data as a Uint8Array.
|
|
87
|
+
* @param password The password used to encrypt.
|
|
88
|
+
* @returns The hex-encoded secret key.
|
|
80
89
|
*/
|
|
81
|
-
static
|
|
90
|
+
static decryptKeyData: (keyData: Uint8Array, password: string) => string;
|
|
82
91
|
/**
|
|
83
92
|
* Decodes a hex string into a Uint8Array.
|
|
84
93
|
*
|
|
@@ -105,7 +114,7 @@ export declare function xMnemonic(entropy: Uint8Array, wordList?: string[] | und
|
|
|
105
114
|
* @param msg the message to create the HMAC of
|
|
106
115
|
* @param SK the secret key to create the HMAC with
|
|
107
116
|
*/
|
|
108
|
-
export declare function xHMAC(msg: any, SK: Uint8Array): Uint8Array<
|
|
117
|
+
export declare function xHMAC(msg: any, SK: Uint8Array): Uint8Array<ArrayBufferLike>;
|
|
109
118
|
/**
|
|
110
119
|
* Constants for vex.
|
|
111
120
|
*/
|
|
@@ -162,3 +171,4 @@ interface XConstants {
|
|
|
162
171
|
HEADER_SIZE: 32;
|
|
163
172
|
}
|
|
164
173
|
export {};
|
|
174
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,IAAI,YAAY,EACtB,MAAM,IAAI,YAAY,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAMhD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAWhC;;;GAGG;AACH,eAAO,MAAM,WAAW,iBAAW,CAAC;AAEpC;;;GAGG;AACH,qBAAa,MAAM;IACf,OAAc,UAAU,oBAAc;IAEtC,OAAc,UAAU,oBAA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AU,CAQhD;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,UAAU,UAErC;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CACf,YAAY,EAAE,UAAU,EACxB,cAAc,EAAE,UAAU,GAC3B,UAAU,CAEZ;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAkB3D;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACnB,SAAS,EAAE,QAAQ,GAAG,MAAM,EAC5B,SAAS,EAAE,UAAU,GACtB,UAAU,CAiCZ;AAkCD;;GAEG;AACH,UAAU,UAAU;IAChB,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,EAAE,GAAG,EAAE,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,EAAE,CAAC;CACnB"}
|
package/dist/index.js
CHANGED
|
@@ -1,77 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.xConstants = exports.XUtils = exports.XKeyConvert = void 0;
|
|
40
|
-
exports.xMnemonic = xMnemonic;
|
|
41
|
-
exports.xHMAC = xHMAC;
|
|
42
|
-
exports.xMakeNonce = xMakeNonce;
|
|
43
|
-
exports.xKDF = xKDF;
|
|
44
|
-
exports.xHash = xHash;
|
|
45
|
-
exports.xDH = xDH;
|
|
46
|
-
exports.xConcat = xConcat;
|
|
47
|
-
exports.xEncode = xEncode;
|
|
48
|
-
const base64_1 = require("@stablelib/base64");
|
|
49
|
-
const utf8_1 = require("@stablelib/utf8");
|
|
50
|
-
const bip39 = __importStar(require("bip39"));
|
|
51
|
-
const node_crypto_1 = require("node:crypto");
|
|
52
|
-
const ed2curve_1 = __importDefault(require("ed2curve"));
|
|
53
|
-
const fs_1 = __importDefault(require("fs"));
|
|
54
|
-
const node_crypto_2 = require("node:crypto");
|
|
55
|
-
const msgpackr_1 = require("msgpackr");
|
|
56
|
-
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
57
|
-
const packer = new msgpackr_1.Packr({
|
|
58
|
-
useRecords: false,
|
|
59
|
-
moreTypes: true,
|
|
60
|
-
});
|
|
1
|
+
import { decode as decodeBase64, encode as encodeBase64, } from "@stablelib/base64";
|
|
2
|
+
import { decode as encodeUTF8, encode as decodeUTF8 } from "@stablelib/utf8";
|
|
3
|
+
import * as bip39 from "bip39";
|
|
4
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
5
|
+
import { sha256, sha512 } from "@noble/hashes/sha2.js";
|
|
6
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
7
|
+
import { pbkdf2 as noblePbkdf2 } from "@noble/hashes/pbkdf2.js";
|
|
8
|
+
import ed2curve from "ed2curve";
|
|
9
|
+
import { Packr } from "msgpackr";
|
|
10
|
+
import nacl from "tweetnacl";
|
|
11
|
+
// msgpackr with useRecords:false emits standard msgpack (no nonstandard record extension).
|
|
12
|
+
// moreTypes:false keeps the extension set to only what other decoders understand.
|
|
13
|
+
// pack() returns Node Buffer (tight view) so consumers like axios send the correct bytes.
|
|
14
|
+
const packer = new Packr({ useRecords: false, moreTypes: false });
|
|
15
|
+
const msgpackEncode = packer.pack.bind(packer);
|
|
16
|
+
const msgpackDecode = packer.unpack.bind(packer);
|
|
61
17
|
/**
|
|
62
18
|
* Provides an interface that can map an ed25519 keypair to its equivalent
|
|
63
19
|
* X25519 keypair.
|
|
64
20
|
*/
|
|
65
|
-
|
|
21
|
+
export const XKeyConvert = ed2curve;
|
|
66
22
|
/**
|
|
67
23
|
* Provides several methods that are useful in working with bytes and
|
|
68
24
|
* vex messages.
|
|
69
25
|
*/
|
|
70
|
-
class XUtils {
|
|
71
|
-
static encodeUTF8 =
|
|
72
|
-
static decodeUTF8 =
|
|
73
|
-
static encodeBase64 =
|
|
74
|
-
static decodeBase64 =
|
|
26
|
+
export class XUtils {
|
|
27
|
+
static encodeUTF8 = encodeUTF8;
|
|
28
|
+
static decodeUTF8 = decodeUTF8;
|
|
29
|
+
static encodeBase64 = encodeBase64;
|
|
30
|
+
static decodeBase64 = decodeBase64;
|
|
75
31
|
/**
|
|
76
32
|
* Checks if two buffer-like objects are equal.
|
|
77
33
|
*
|
|
@@ -81,13 +37,13 @@ class XUtils {
|
|
|
81
37
|
* @returns True if equal, else false.
|
|
82
38
|
*/
|
|
83
39
|
static bytesEqual(buf1, buf2) {
|
|
84
|
-
|
|
40
|
+
const a = buf1 instanceof Uint8Array ? buf1 : new Uint8Array(buf1);
|
|
41
|
+
const b = buf2 instanceof Uint8Array ? buf2 : new Uint8Array(buf2);
|
|
42
|
+
if (a.byteLength !== b.byteLength) {
|
|
85
43
|
return false;
|
|
86
44
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i !== buf1.byteLength; i++) {
|
|
90
|
-
if (dv1[i] !== dv2[i]) {
|
|
45
|
+
for (let i = 0; i !== a.byteLength; i++) {
|
|
46
|
+
if (a[i] !== b[i]) {
|
|
91
47
|
return false;
|
|
92
48
|
}
|
|
93
49
|
}
|
|
@@ -118,7 +74,11 @@ class XUtils {
|
|
|
118
74
|
* @returns the number representation of arr.
|
|
119
75
|
*/
|
|
120
76
|
static uint8ArrToNumber(arr) {
|
|
121
|
-
|
|
77
|
+
let n = 0;
|
|
78
|
+
for (let i = 0; i < arr.length; i++) {
|
|
79
|
+
n = n * 256 + arr[i];
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
122
82
|
}
|
|
123
83
|
/**
|
|
124
84
|
* Takes a vex message and unpacks it into its header and a javascript object
|
|
@@ -129,9 +89,8 @@ class XUtils {
|
|
|
129
89
|
*/
|
|
130
90
|
static unpackMessage(msg) {
|
|
131
91
|
const msgp = Uint8Array.from(msg);
|
|
132
|
-
const msgh = msgp.slice(0,
|
|
133
|
-
|
|
134
|
-
const msgb = packer.unpack(msgp.slice(exports.xConstants.HEADER_SIZE));
|
|
92
|
+
const msgh = msgp.slice(0, xConstants.HEADER_SIZE);
|
|
93
|
+
const msgb = msgpackDecode(msgp.slice(xConstants.HEADER_SIZE));
|
|
135
94
|
return [msgh, msgb];
|
|
136
95
|
}
|
|
137
96
|
/**
|
|
@@ -141,8 +100,7 @@ class XUtils {
|
|
|
141
100
|
* @returns the packed message.
|
|
142
101
|
*/
|
|
143
102
|
static packMessage(msg, header) {
|
|
144
|
-
|
|
145
|
-
const msgb = packer.pack(msg);
|
|
103
|
+
const msgb = msgpackEncode(msg);
|
|
146
104
|
const msgh = header || XUtils.emptyHeader();
|
|
147
105
|
return xConcat(msgh, msgb);
|
|
148
106
|
}
|
|
@@ -152,30 +110,41 @@ class XUtils {
|
|
|
152
110
|
* @returns The empty header.
|
|
153
111
|
*/
|
|
154
112
|
static emptyHeader() {
|
|
155
|
-
return new Uint8Array(
|
|
113
|
+
return new Uint8Array(xConstants.HEADER_SIZE);
|
|
156
114
|
}
|
|
157
115
|
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
116
|
+
* Encrypts a secret key with a password and saves it as a file.
|
|
117
|
+
*
|
|
118
|
+
* @param path The path to save the keyfile.
|
|
119
|
+
/**
|
|
120
|
+
* Encrypts a secret key into a portable binary format.
|
|
121
|
+
* The result can be written to disk, sent over the network, etc.
|
|
122
|
+
* No I/O — the caller handles persistence.
|
|
123
|
+
*
|
|
124
|
+
* Format: [iterations(6)|salt(24)|nonce(24)|ciphertext(N)]
|
|
125
|
+
*
|
|
126
|
+
* @param password The password to derive the encryption key from.
|
|
127
|
+
* @param keyToSave The hex-encoded secret key to encrypt.
|
|
128
|
+
* @param iterationOverride Optional PBKDF2 iteration count (random if omitted).
|
|
129
|
+
* @returns The encrypted key data as a Uint8Array.
|
|
130
|
+
*/
|
|
131
|
+
static encryptKeyData = (password, keyToSave, iterationOverride) => {
|
|
167
132
|
const UNENCRYPTED_SIGNKEY = XUtils.decodeHex(keyToSave);
|
|
168
133
|
const OFFSET = 1000;
|
|
169
|
-
|
|
170
|
-
const rand = (0, node_crypto_1.randomBytes)(2);
|
|
134
|
+
const rand = nacl.randomBytes(2);
|
|
171
135
|
const N1 = rand[0];
|
|
172
136
|
const N2 = rand[1];
|
|
173
|
-
const iterations = iterationOverride
|
|
137
|
+
const iterations = iterationOverride
|
|
138
|
+
? iterationOverride
|
|
139
|
+
: N1 * N2 + OFFSET;
|
|
174
140
|
const ITERATIONS = XUtils.numberToUint8Arr(iterations);
|
|
175
141
|
const PKBDF_SALT = xMakeNonce();
|
|
176
|
-
const ENCRYPTION_KEY = (
|
|
142
|
+
const ENCRYPTION_KEY = noblePbkdf2(sha512, password, PKBDF_SALT, {
|
|
143
|
+
c: iterations,
|
|
144
|
+
dkLen: 32,
|
|
145
|
+
});
|
|
177
146
|
const NONCE = xMakeNonce();
|
|
178
|
-
const ENCRYPTED_SIGNKEY =
|
|
147
|
+
const ENCRYPTED_SIGNKEY = nacl.secretbox(UNENCRYPTED_SIGNKEY, NONCE, ENCRYPTION_KEY);
|
|
179
148
|
const result = new Uint8Array(ITERATIONS.length +
|
|
180
149
|
PKBDF_SALT.length +
|
|
181
150
|
NONCE.length +
|
|
@@ -188,28 +157,30 @@ class XUtils {
|
|
|
188
157
|
result.set(NONCE, offset);
|
|
189
158
|
offset += NONCE.length;
|
|
190
159
|
result.set(ENCRYPTED_SIGNKEY, offset);
|
|
191
|
-
|
|
160
|
+
return result;
|
|
192
161
|
};
|
|
193
162
|
/**
|
|
194
|
-
* Decrypts
|
|
163
|
+
* Decrypts a secret key from the binary format produced by encryptKeyData().
|
|
164
|
+
* No I/O — the caller handles reading the data.
|
|
195
165
|
*
|
|
196
|
-
* @param
|
|
197
|
-
* @param password The password
|
|
166
|
+
* @param keyData The encrypted key data as a Uint8Array.
|
|
167
|
+
* @param password The password used to encrypt.
|
|
168
|
+
* @returns The hex-encoded secret key.
|
|
198
169
|
*/
|
|
199
|
-
static
|
|
200
|
-
const
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
170
|
+
static decryptKeyData = (keyData, password) => {
|
|
171
|
+
const ITERATIONS = XUtils.uint8ArrToNumber(keyData.slice(0, 6));
|
|
172
|
+
const PKBDF_SALT = keyData.slice(6, 30);
|
|
173
|
+
const ENCRYPTION_NONCE = keyData.slice(30, 54);
|
|
174
|
+
const ENCRYPTED_KEY = keyData.slice(54);
|
|
175
|
+
const DERIVED_KEY = noblePbkdf2(sha512, password, PKBDF_SALT, {
|
|
176
|
+
c: ITERATIONS,
|
|
177
|
+
dkLen: 32,
|
|
178
|
+
});
|
|
179
|
+
const DECRYPTED_SIGNKEY = nacl.secretbox.open(ENCRYPTED_KEY, ENCRYPTION_NONCE, DERIVED_KEY);
|
|
207
180
|
if (!DECRYPTED_SIGNKEY) {
|
|
208
181
|
throw new Error("Decryption failed. Wrong password?");
|
|
209
182
|
}
|
|
210
|
-
|
|
211
|
-
return XUtils.encodeHex(DECRYPTED_SIGNKEY);
|
|
212
|
-
}
|
|
183
|
+
return XUtils.encodeHex(DECRYPTED_SIGNKEY);
|
|
213
184
|
};
|
|
214
185
|
/**
|
|
215
186
|
* Decodes a hex string into a Uint8Array.
|
|
@@ -231,15 +202,14 @@ class XUtils {
|
|
|
231
202
|
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
232
203
|
}
|
|
233
204
|
}
|
|
234
|
-
exports.XUtils = XUtils;
|
|
235
205
|
/**
|
|
236
206
|
* Gets a word list representation of a byte sequence.
|
|
237
207
|
*
|
|
238
208
|
* @param entropy The bytes to derive the wordlist from.
|
|
239
209
|
* @param wordList Optional, override the wordlist. See bip39 docs for details.
|
|
240
210
|
*/
|
|
241
|
-
function xMnemonic(entropy, wordList) {
|
|
242
|
-
return bip39.entropyToMnemonic(
|
|
211
|
+
export function xMnemonic(entropy, wordList) {
|
|
212
|
+
return bip39.entropyToMnemonic(XUtils.encodeHex(entropy), wordList);
|
|
243
213
|
}
|
|
244
214
|
/**
|
|
245
215
|
* Returns a 32 byte HMAC of a javscript object.
|
|
@@ -247,17 +217,14 @@ function xMnemonic(entropy, wordList) {
|
|
|
247
217
|
* @param msg the message to create the HMAC of
|
|
248
218
|
* @param SK the secret key to create the HMAC with
|
|
249
219
|
*/
|
|
250
|
-
function xHMAC(msg, SK) {
|
|
251
|
-
const packedMsg =
|
|
252
|
-
|
|
253
|
-
hmacGen.update(packedMsg);
|
|
254
|
-
const hmac = Uint8Array.from(hmacGen.digest());
|
|
255
|
-
return hmac;
|
|
220
|
+
export function xHMAC(msg, SK) {
|
|
221
|
+
const packedMsg = msgpackEncode(msg);
|
|
222
|
+
return hmac(sha256, SK, packedMsg);
|
|
256
223
|
}
|
|
257
224
|
/**
|
|
258
225
|
* Constants for vex.
|
|
259
226
|
*/
|
|
260
|
-
|
|
227
|
+
export const xConstants = {
|
|
261
228
|
CURVE: "X25519",
|
|
262
229
|
HASH: "SHA-512",
|
|
263
230
|
KEY_LENGTH: 32,
|
|
@@ -268,8 +235,8 @@ exports.xConstants = {
|
|
|
268
235
|
/**
|
|
269
236
|
* Returns a 24 byte random nonce of cryptographic quality.
|
|
270
237
|
*/
|
|
271
|
-
function xMakeNonce() {
|
|
272
|
-
return
|
|
238
|
+
export function xMakeNonce() {
|
|
239
|
+
return nacl.randomBytes(24);
|
|
273
240
|
}
|
|
274
241
|
/**
|
|
275
242
|
* Derives a 32 byte secret key from some initial key material.
|
|
@@ -286,8 +253,8 @@ function xMakeNonce() {
|
|
|
286
253
|
// })
|
|
287
254
|
// );
|
|
288
255
|
// }
|
|
289
|
-
function xKDF(IKM) {
|
|
290
|
-
return
|
|
256
|
+
export function xKDF(IKM) {
|
|
257
|
+
return hkdf(sha512, IKM, xMakeSalt(xConstants.CURVE), new TextEncoder().encode(xConstants.INFO), xConstants.KEY_LENGTH);
|
|
291
258
|
}
|
|
292
259
|
/**
|
|
293
260
|
* Hashes some data.
|
|
@@ -295,9 +262,8 @@ function xKDF(IKM) {
|
|
|
295
262
|
* @param data the data to hash.
|
|
296
263
|
* @returns The hash of the data.
|
|
297
264
|
*/
|
|
298
|
-
function xHash(data) {
|
|
299
|
-
|
|
300
|
-
return hash.update(data).digest("hex");
|
|
265
|
+
export function xHash(data) {
|
|
266
|
+
return XUtils.encodeHex(sha512(data));
|
|
301
267
|
}
|
|
302
268
|
/**
|
|
303
269
|
* Derives a shared Secret Key from a known private key and
|
|
@@ -307,15 +273,15 @@ function xHash(data) {
|
|
|
307
273
|
* @param theirPublicKey Their public key
|
|
308
274
|
* @returns The derived shared secret, SK.
|
|
309
275
|
*/
|
|
310
|
-
function xDH(myPrivateKey, theirPublicKey) {
|
|
311
|
-
return
|
|
276
|
+
export function xDH(myPrivateKey, theirPublicKey) {
|
|
277
|
+
return nacl.box.before(theirPublicKey, myPrivateKey);
|
|
312
278
|
}
|
|
313
279
|
/**
|
|
314
280
|
* Concatanates multiple Uint8Arrays.
|
|
315
281
|
*
|
|
316
282
|
* @param arrays As many Uint8Arrays as you would like to concatanate.
|
|
317
283
|
*/
|
|
318
|
-
function xConcat(...arrays) {
|
|
284
|
+
export function xConcat(...arrays) {
|
|
319
285
|
const totalLength = arrays.reduce((acc, value) => acc + value.length, 0);
|
|
320
286
|
if (!arrays.length) {
|
|
321
287
|
return new Uint8Array();
|
|
@@ -336,7 +302,7 @@ function xConcat(...arrays) {
|
|
|
336
302
|
* ittle-endian encoding of the u-coordinate. See [rfc 7748](https://www.ietf.org/rfc/rfc7748.txt) for more
|
|
337
303
|
* details.
|
|
338
304
|
*/
|
|
339
|
-
function xEncode(curveType, publicKey) {
|
|
305
|
+
export function xEncode(curveType, publicKey) {
|
|
340
306
|
if (publicKey.length !== 32) {
|
|
341
307
|
throw new Error("Invalid key length, received key of length " +
|
|
342
308
|
publicKey.length +
|
|
@@ -391,3 +357,4 @@ function isEven(value) {
|
|
|
391
357
|
return false;
|
|
392
358
|
}
|
|
393
359
|
}
|
|
360
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,MAAM,IAAI,YAAY,EACtB,MAAM,IAAI,YAAY,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;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|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"name": "@vex-chat/crypto",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Crypto primitives for Vex",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"author": "Extra <extrahash@protonmail.com>",
|
|
19
|
+
"license": "AGPL-3.0-or-later",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"build:clean": "rimraf dist && tsc",
|
|
23
|
+
"prepack": "npm run build",
|
|
24
|
+
"format": "prettier --write .",
|
|
25
|
+
"format:check": "prettier --check .",
|
|
26
|
+
"lint": "eslint src/",
|
|
27
|
+
"lint:fix": "eslint src/ --fix",
|
|
28
|
+
"prepublish": "npm run build",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@vex-chat/types": "^1.0.0-rc.1",
|
|
33
|
+
"typescript": ">=5.9.0 || >=6.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"typescript": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@noble/hashes": "^2.0.1",
|
|
42
|
+
"@stablelib/base64": "^2.0.1",
|
|
43
|
+
"@stablelib/utf8": "^2.1.0",
|
|
44
|
+
"bip39": "^3.1.0",
|
|
45
|
+
"ed2curve": "^0.3.0",
|
|
46
|
+
"msgpackr": "1.11.8",
|
|
47
|
+
"tweetnacl": "^1.0.3"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@changesets/cli": "^2.29.8",
|
|
51
|
+
"@types/create-hmac": "^1.1.3",
|
|
52
|
+
"@types/ed2curve": "^0.2.4",
|
|
53
|
+
"@types/node": "^24.12.2",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
55
|
+
"@typescript-eslint/parser": "^8.57.1",
|
|
56
|
+
"@vex-chat/types": "^1.0.1",
|
|
57
|
+
"eslint": "^10.1.0",
|
|
58
|
+
"eslint-config-prettier": "^9.0.0",
|
|
59
|
+
"husky": "^9.0.0",
|
|
60
|
+
"lint-staged": "^15.2.0",
|
|
61
|
+
"prettier": "^3.2.0",
|
|
62
|
+
"rimraf": "^6.1.3",
|
|
63
|
+
"typescript": "^6.0.2",
|
|
64
|
+
"vitest": "^3.0.0"
|
|
65
|
+
},
|
|
66
|
+
"lint-staged": {
|
|
67
|
+
"*.ts": [
|
|
68
|
+
"eslint --fix",
|
|
69
|
+
"prettier --write"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "git+https://github.com/vex-chat/libvex-js.git"
|
|
75
|
+
},
|
|
76
|
+
"bugs": {
|
|
77
|
+
"url": "https://github.com/vex-chat/libvex-js/issues"
|
|
78
|
+
},
|
|
79
|
+
"homepage": "https://github.com/vex-chat/libvex-js#readme",
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public",
|
|
82
|
+
"registry": "https://registry.npmjs.org/"
|
|
25
83
|
}
|
|
26
|
-
},
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"@stablelib/base64": "^1.0.1",
|
|
29
|
-
"@stablelib/utf8": "^1.0.1",
|
|
30
|
-
"@vex-chat/types": "1.0.0-rc.0",
|
|
31
|
-
"bip39": "^3.1.0",
|
|
32
|
-
"ed2curve": "^0.3.0",
|
|
33
|
-
"msgpackr": "^1.10.1",
|
|
34
|
-
"tweetnacl": "^1.0.3",
|
|
35
|
-
"uuid": "^9.0.0"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@changesets/cli": "^2.29.8",
|
|
39
|
-
"@types/create-hmac": "^1.1.3",
|
|
40
|
-
"@types/ed2curve": "^0.2.4",
|
|
41
|
-
"@types/jest": "^30.0.0",
|
|
42
|
-
"@types/lodash": "^4.17.21",
|
|
43
|
-
"@types/node": "^22.15.3",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
45
|
-
"@typescript-eslint/parser": "^8.57.1",
|
|
46
|
-
"eslint": "^10.1.0",
|
|
47
|
-
"eslint-config-prettier": "^9.0.0",
|
|
48
|
-
"husky": "^9.0.0",
|
|
49
|
-
"jest": "^30.3.0",
|
|
50
|
-
"lint-staged": "^15.2.0",
|
|
51
|
-
"lodash": "^4.17.23",
|
|
52
|
-
"prettier": "^3.2.0",
|
|
53
|
-
"rimraf": "^6.1.3",
|
|
54
|
-
"ts-jest": "^29.4.6",
|
|
55
|
-
"typescript": "^5.9.0"
|
|
56
|
-
},
|
|
57
|
-
"lint-staged": {
|
|
58
|
-
"src/**/*.{ts}": [
|
|
59
|
-
"eslint --fix"
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
"repository": {
|
|
63
|
-
"type": "git",
|
|
64
|
-
"url": "git+https://github.com/vex-chat/libvex-js.git"
|
|
65
|
-
},
|
|
66
|
-
"resolutions": {
|
|
67
|
-
"minimatch": "^9.0.7",
|
|
68
|
-
"flatted": "^3.4.2",
|
|
69
|
-
"ajv": "^6.14.0",
|
|
70
|
-
"lodash": "^4.17.21"
|
|
71
|
-
},
|
|
72
|
-
"bugs": {
|
|
73
|
-
"url": "https://github.com/vex-chat/libvex-js/issues"
|
|
74
|
-
},
|
|
75
|
-
"homepage": "https://github.com/vex-chat/libvex-js#readme"
|
|
76
84
|
}
|
package/.changeset/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# Changesets
|
|
2
|
-
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
-
find the full documentation for it [in the changesets repo](https://github.com/changesets/changesets)
|
|
6
|
-
|
|
7
|
-
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
-
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
package/.changeset/config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": false,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "public",
|
|
8
|
-
"baseBranch": "master",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
package/.changeset/pre.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# @vex-chat/crypto
|
|
2
|
-
|
|
3
|
-
## 1.0.0-rc.0
|
|
4
|
-
|
|
5
|
-
### Major Changes
|
|
6
|
-
|
|
7
|
-
- 19b36ca: Migrate to msgpackr and native node:crypto, replacing msgpack-lite, create-hmac, sha.js, pbkdf2, and futoin-hkdf with built-in Node.js crypto primitives. Add release tooling with changesets, mise, and updated CI workflows.
|
package/RELEASING.md
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# Releasing @vex-chat/crypto
|
|
2
|
-
|
|
3
|
-
This repo uses [Changesets](https://github.com/changesets/changesets) for versioning and publishing.
|
|
4
|
-
|
|
5
|
-
## Dependency Chain
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
@vex-chat/types
|
|
9
|
-
└─ @vex-chat/crypto ← you are here
|
|
10
|
-
└─ @vex-chat/libvex
|
|
11
|
-
└─ vex-desktop
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
**Publish types first** if it has changes, then publish crypto.
|
|
15
|
-
|
|
16
|
-
## Day-to-Day Workflow
|
|
17
|
-
|
|
18
|
-
### 1. Work on a feature branch
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
git checkout -b my-feature
|
|
22
|
-
# ... make changes ...
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### 2. Add a changeset before pushing
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npx changeset
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
This prompts you to:
|
|
32
|
-
- Select the package (`@vex-chat/crypto`)
|
|
33
|
-
- Choose bump type (patch / minor / major)
|
|
34
|
-
- Write a short summary of the change
|
|
35
|
-
|
|
36
|
-
It creates a file in `.changeset/` — commit it with your code.
|
|
37
|
-
|
|
38
|
-
### 3. Push and open a PR
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
git add .
|
|
42
|
-
git commit -m "my feature"
|
|
43
|
-
git push -u origin my-feature
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 4. Merge to master
|
|
47
|
-
|
|
48
|
-
After merge, the **Release** GitHub Action will:
|
|
49
|
-
1. Detect pending changesets
|
|
50
|
-
2. Open a **"chore: version packages"** PR with bumped version + updated CHANGELOG.md
|
|
51
|
-
3. When you merge that PR, it publishes to npm automatically
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Release Candidates
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
npx changeset pre enter rc # enter RC mode
|
|
59
|
-
npx changeset version # produces e.g. 0.9.0-rc.0
|
|
60
|
-
npx changeset publish # publishes with --tag rc
|
|
61
|
-
|
|
62
|
-
# ... more changes + changesets ...
|
|
63
|
-
npx changeset version # produces 0.9.0-rc.1
|
|
64
|
-
npx changeset publish
|
|
65
|
-
|
|
66
|
-
# ready for stable:
|
|
67
|
-
npx changeset pre exit
|
|
68
|
-
npx changeset version # produces 0.9.0
|
|
69
|
-
npx changeset publish # publishes as @latest
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## GitHub Secrets Required
|
|
73
|
-
|
|
74
|
-
- `NPM_TOKEN` — npm access token with publish permission for `@vex-chat` scope
|
|
75
|
-
- `GITHUB_TOKEN` — provided automatically by GitHub Actions
|
|
76
|
-
|
|
77
|
-
## Local Development
|
|
78
|
-
|
|
79
|
-
You can still use `yalc` for local cross-repo development:
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
yarn push # builds and pushes to yalc for local consumers
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
When publishing for real, changesets handles versioning — yalc is just for local dev loops.
|
package/jest.config.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
roots: ["<rootDir>/src"],
|
|
3
|
-
testMatch: [
|
|
4
|
-
"**/__tests__/**/*.+(ts|tsx|js)",
|
|
5
|
-
"**/?(*.)+(spec|test).+(ts|tsx|js)",
|
|
6
|
-
],
|
|
7
|
-
transform: {
|
|
8
|
-
"^.+\\.(ts|tsx)$": [
|
|
9
|
-
"ts-jest",
|
|
10
|
-
{
|
|
11
|
-
diagnostics: false,
|
|
12
|
-
isolatedModules: true,
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
};
|
package/mise.toml
DELETED
package/tsdoc.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tags": {
|
|
3
|
-
"allowUnknownTags": true
|
|
4
|
-
},
|
|
5
|
-
"plugins": [
|
|
6
|
-
"plugins/markdown",
|
|
7
|
-
"/home/ender/.npm/_npx/229717/lib/node_modules/tsdoc/template/plugins/TSDoc.js"
|
|
8
|
-
],
|
|
9
|
-
"opts": {
|
|
10
|
-
"template": "/home/ender/.npm/_npx/229717/lib/node_modules/tsdoc/template",
|
|
11
|
-
"recurse": "true"
|
|
12
|
-
},
|
|
13
|
-
"templates": {
|
|
14
|
-
"cleverLinks": false,
|
|
15
|
-
"monospaceLinks": false
|
|
16
|
-
},
|
|
17
|
-
"source": {
|
|
18
|
-
"includePattern": "(\\.d)?\\.ts$"
|
|
19
|
-
},
|
|
20
|
-
"markdown": {
|
|
21
|
-
"parser": "gfm",
|
|
22
|
-
"hardwrap": true
|
|
23
|
-
},
|
|
24
|
-
"tsdoc": {
|
|
25
|
-
"source": "/home/ender/code/crypto-js/src/",
|
|
26
|
-
"destination": "/home/ender/code/crypto-js/docs",
|
|
27
|
-
"tutorials": "",
|
|
28
|
-
"systemName": "crypto-js",
|
|
29
|
-
"footer": "",
|
|
30
|
-
"copyright": "crypto-js Copyright © 2020 ender.",
|
|
31
|
-
"outputSourceFiles": true,
|
|
32
|
-
"commentsOnly": true
|
|
33
|
-
}
|
|
34
|
-
}
|