glow.ts 1.0.3 → 1.1.0
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 -15
- package/dist/glow.cjs.js +4 -0
- package/dist/glow.cjs.js.map +1 -0
- package/dist/glow.es.js +993 -0
- package/dist/glow.es.js.map +1 -0
- package/dist/index.d.ts +544 -0
- package/package.json +34 -26
- package/dist/cjs2/config.js +0 -18
- package/dist/cjs2/config.js.map +0 -1
- package/dist/cjs2/crypto-storage/crypto-storage.js +0 -118
- package/dist/cjs2/crypto-storage/crypto-storage.js.map +0 -1
- package/dist/cjs2/crypto-storage/in-memory-storage.js +0 -36
- package/dist/cjs2/crypto-storage/in-memory-storage.js.map +0 -1
- package/dist/cjs2/crypto-storage/local-storage.driver.js +0 -36
- package/dist/cjs2/crypto-storage/local-storage.driver.js.map +0 -1
- package/dist/cjs2/crypto-storage/storage-driver.interface.js +0 -3
- package/dist/cjs2/crypto-storage/storage-driver.interface.js.map +0 -1
- package/dist/cjs2/index.js +0 -28
- package/dist/cjs2/index.js.map +0 -1
- package/dist/cjs2/keyring/keyring.js +0 -151
- package/dist/cjs2/keyring/keyring.js.map +0 -1
- package/dist/cjs2/keys/keys.js +0 -40
- package/dist/cjs2/keys/keys.js.map +0 -1
- package/dist/cjs2/mailbox/mailbox.js +0 -352
- package/dist/cjs2/mailbox/mailbox.js.map +0 -1
- package/dist/cjs2/nacl/encryption.helper.js +0 -101
- package/dist/cjs2/nacl/encryption.helper.js.map +0 -1
- package/dist/cjs2/nacl/js-nacl-driver.js +0 -110
- package/dist/cjs2/nacl/js-nacl-driver.js.map +0 -1
- package/dist/cjs2/nacl/keypair.interface.js +0 -3
- package/dist/cjs2/nacl/keypair.interface.js.map +0 -1
- package/dist/cjs2/nacl/nacl-driver.interface.js +0 -3
- package/dist/cjs2/nacl/nacl-driver.interface.js.map +0 -1
- package/dist/cjs2/nacl/nacl.js +0 -29
- package/dist/cjs2/nacl/nacl.js.map +0 -1
- package/dist/cjs2/relay/network-error.js +0 -12
- package/dist/cjs2/relay/network-error.js.map +0 -1
- package/dist/cjs2/relay/relay-factory.js +0 -22
- package/dist/cjs2/relay/relay-factory.js.map +0 -1
- package/dist/cjs2/relay/relay.js +0 -300
- package/dist/cjs2/relay/relay.js.map +0 -1
- package/dist/cjs2/utils/utils.js +0 -39
- package/dist/cjs2/utils/utils.js.map +0 -1
- package/dist/cjs2/zax.interface.js +0 -46
- package/dist/cjs2/zax.interface.js.map +0 -1
- package/dist/esm/config.js +0 -15
- package/dist/esm/config.js.map +0 -1
- package/dist/esm/crypto-storage/crypto-storage.js +0 -114
- package/dist/esm/crypto-storage/crypto-storage.js.map +0 -1
- package/dist/esm/crypto-storage/in-memory-storage.js +0 -32
- package/dist/esm/crypto-storage/in-memory-storage.js.map +0 -1
- package/dist/esm/crypto-storage/local-storage.driver.js +0 -32
- package/dist/esm/crypto-storage/local-storage.driver.js.map +0 -1
- package/dist/esm/crypto-storage/storage-driver.interface.js +0 -2
- package/dist/esm/crypto-storage/storage-driver.interface.js.map +0 -1
- package/dist/esm/index.js +0 -14
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/keyring/keyring.js +0 -147
- package/dist/esm/keyring/keyring.js.map +0 -1
- package/dist/esm/keys/keys.js +0 -36
- package/dist/esm/keys/keys.js.map +0 -1
- package/dist/esm/mailbox/mailbox.js +0 -348
- package/dist/esm/mailbox/mailbox.js.map +0 -1
- package/dist/esm/nacl/encryption.helper.js +0 -97
- package/dist/esm/nacl/encryption.helper.js.map +0 -1
- package/dist/esm/nacl/js-nacl-driver.js +0 -106
- package/dist/esm/nacl/js-nacl-driver.js.map +0 -1
- package/dist/esm/nacl/keypair.interface.js +0 -2
- package/dist/esm/nacl/keypair.interface.js.map +0 -1
- package/dist/esm/nacl/nacl-driver.interface.js +0 -2
- package/dist/esm/nacl/nacl-driver.interface.js.map +0 -1
- package/dist/esm/nacl/nacl.js +0 -25
- package/dist/esm/nacl/nacl.js.map +0 -1
- package/dist/esm/relay/network-error.js +0 -8
- package/dist/esm/relay/network-error.js.map +0 -1
- package/dist/esm/relay/relay-factory.js +0 -18
- package/dist/esm/relay/relay-factory.js.map +0 -1
- package/dist/esm/relay/relay.js +0 -293
- package/dist/esm/relay/relay.js.map +0 -1
- package/dist/esm/utils/utils.js +0 -35
- package/dist/esm/utils/utils.js.map +0 -1
- package/dist/esm/zax.interface.js +0 -43
- package/dist/esm/zax.interface.js.map +0 -1
- package/dist/types/config.d.ts +0 -10
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/crypto-storage/crypto-storage.d.ts +0 -20
- package/dist/types/crypto-storage/crypto-storage.d.ts.map +0 -1
- package/dist/types/crypto-storage/in-memory-storage.d.ts +0 -17
- package/dist/types/crypto-storage/in-memory-storage.d.ts.map +0 -1
- package/dist/types/crypto-storage/local-storage.driver.d.ts +0 -15
- package/dist/types/crypto-storage/local-storage.driver.d.ts.map +0 -1
- package/dist/types/crypto-storage/storage-driver.interface.d.ts +0 -11
- package/dist/types/crypto-storage/storage-driver.interface.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -16
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/keyring/keyring.d.ts +0 -43
- package/dist/types/keyring/keyring.d.ts.map +0 -1
- package/dist/types/keys/keys.d.ts +0 -16
- package/dist/types/keys/keys.d.ts.map +0 -1
- package/dist/types/mailbox/mailbox.d.ts +0 -148
- package/dist/types/mailbox/mailbox.d.ts.map +0 -1
- package/dist/types/nacl/encryption.helper.d.ts +0 -37
- package/dist/types/nacl/encryption.helper.d.ts.map +0 -1
- package/dist/types/nacl/js-nacl-driver.d.ts +0 -39
- package/dist/types/nacl/js-nacl-driver.d.ts.map +0 -1
- package/dist/types/nacl/keypair.interface.d.ts +0 -5
- package/dist/types/nacl/keypair.interface.d.ts.map +0 -1
- package/dist/types/nacl/nacl-driver.interface.d.ts +0 -28
- package/dist/types/nacl/nacl-driver.interface.d.ts.map +0 -1
- package/dist/types/nacl/nacl.d.ts +0 -13
- package/dist/types/nacl/nacl.d.ts.map +0 -1
- package/dist/types/relay/network-error.d.ts +0 -6
- package/dist/types/relay/network-error.d.ts.map +0 -1
- package/dist/types/relay/relay-factory.d.ts +0 -10
- package/dist/types/relay/relay-factory.d.ts.map +0 -1
- package/dist/types/relay/relay.d.ts +0 -88
- package/dist/types/relay/relay.d.ts.map +0 -1
- package/dist/types/utils/utils.d.ts +0 -9
- package/dist/types/utils/utils.d.ts.map +0 -1
- package/dist/types/zax.interface.d.ts +0 -101
- package/dist/types/zax.interface.d.ts.map +0 -1
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkError = void 0;
|
|
4
|
-
class NetworkError extends Error {
|
|
5
|
-
constructor(status) {
|
|
6
|
-
super(`NetworkError status: ${status}`);
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.name = 'NetworkError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.NetworkError = NetworkError;
|
|
12
|
-
//# sourceMappingURL=network-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-error.js","sourceRoot":"","sources":["../../../src/relay/network-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IAGrC,YAAmB,MAAwB;QACzC,KAAK,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;QADvB,WAAM,GAAN,MAAM,CAAkB;QAFlC,SAAI,GAAG,cAAc,CAAC;IAI/B,CAAC;CACF;AAND,oCAMC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RelayFactory = void 0;
|
|
4
|
-
const relay_1 = require("./relay");
|
|
5
|
-
class RelayFactory {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.relays = {};
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Relay factory, that returns a Relay instance for a given URL,
|
|
11
|
-
* or creates a new one if it hasn't yet been initialized.
|
|
12
|
-
*/
|
|
13
|
-
getInstance(url) {
|
|
14
|
-
let relay = this.relays[url];
|
|
15
|
-
if (!relay) {
|
|
16
|
-
relay = this.relays[url] = new relay_1.Relay(url);
|
|
17
|
-
}
|
|
18
|
-
return relay;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.RelayFactory = RelayFactory;
|
|
22
|
-
//# sourceMappingURL=relay-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay-factory.js","sourceRoot":"","sources":["../../../src/relay/relay-factory.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,MAAa,YAAY;IAAzB;QAEU,WAAM,GAA6B,EAAE,CAAC;IAahD,CAAC;IAXC;;;OAGG;IACH,WAAW,CAAC,GAAW;QACrB,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,KAAK,EAAE;YACV,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,aAAK,CAAC,GAAG,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAfD,oCAeC"}
|
package/dist/cjs2/relay/relay.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Relay = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const nacl_1 = require("../nacl/nacl");
|
|
9
|
-
const encryption_helper_1 = require("../nacl/encryption.helper");
|
|
10
|
-
const config_1 = require("../config");
|
|
11
|
-
const utils_1 = require("../utils/utils");
|
|
12
|
-
const keys_1 = require("../keys/keys");
|
|
13
|
-
const zax_interface_1 = require("../zax.interface");
|
|
14
|
-
const network_error_1 = require("./network-error");
|
|
15
|
-
/**
|
|
16
|
-
* Low-level operations with Zax relay
|
|
17
|
-
*/
|
|
18
|
-
class Relay {
|
|
19
|
-
constructor(url) {
|
|
20
|
-
this.url = url;
|
|
21
|
-
this.difficulty = 0;
|
|
22
|
-
this.nacl = nacl_1.NaCl.getInstance();
|
|
23
|
-
}
|
|
24
|
-
get isConnected() {
|
|
25
|
-
// relay is assumed to be connected when it got session keys and server public
|
|
26
|
-
// sessionKeys are not permanent so relay won't be connected when sessionKeys will be removed within timeout
|
|
27
|
-
return !!(this.sessionKeys && this.publicKey);
|
|
28
|
-
}
|
|
29
|
-
// ---------- Connection initialization ----------
|
|
30
|
-
/**
|
|
31
|
-
* Exchanges tokens with a relay and gets a temp session key for this relay.
|
|
32
|
-
* Returns h₂(signature) and a relay public key
|
|
33
|
-
*/
|
|
34
|
-
async openConnection() {
|
|
35
|
-
this.sessionKeys = new keys_1.Keys(await this.nacl.crypto_box_keypair());
|
|
36
|
-
this.clientToken = await this.nacl.random_bytes(config_1.config.RELAY_TOKEN_LEN);
|
|
37
|
-
const relayToken = await this.fetchRelayToken();
|
|
38
|
-
this.publicKey = await this.fetchRelayPublicKey(relayToken);
|
|
39
|
-
return {
|
|
40
|
-
h2Signature: await this.getSignature(relayToken, this.sessionKeys),
|
|
41
|
-
relayPublicKey: this.publicKey
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Sends a client token to a relay and saves a relay token
|
|
46
|
-
*/
|
|
47
|
-
async fetchRelayToken() {
|
|
48
|
-
if (!this.clientToken) {
|
|
49
|
-
throw new Error('[Relay] clientToken is required please openConnection first');
|
|
50
|
-
}
|
|
51
|
-
const data = await this.httpCall('start_session', utils_1.Utils.toBase64(this.clientToken));
|
|
52
|
-
// Set a timer to mark a relay instance as having an expired token after a certain time
|
|
53
|
-
this.scheduleTokenExpiration();
|
|
54
|
-
// Relay responds with its own counter token. Until session is established these 2 tokens are handshake id.
|
|
55
|
-
const [token, difficulty] = this.parseResponse('start_session', data);
|
|
56
|
-
this.difficulty = parseInt(difficulty, 10);
|
|
57
|
-
if (this.difficulty > 10) {
|
|
58
|
-
console.log(`[Relay] ${this.url} requested difficulty ${this.difficulty}. Session handshake may take longer.`);
|
|
59
|
-
}
|
|
60
|
-
return utils_1.Utils.fromBase64(token);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Completes the handshake and saves a relay pubic key
|
|
64
|
-
*/
|
|
65
|
-
async fetchRelayPublicKey(relayToken) {
|
|
66
|
-
if (!this.clientToken) {
|
|
67
|
-
throw new Error('[Relay] clientToken is required please openConnection first');
|
|
68
|
-
}
|
|
69
|
-
// After clientToken is sent to the relay, we use only h2() of it
|
|
70
|
-
const h2ClientToken = utils_1.Utils.toBase64(await this.nacl.h2(this.clientToken));
|
|
71
|
-
const handshake = new Uint8Array([...this.clientToken, ...relayToken]);
|
|
72
|
-
let sessionHandshake;
|
|
73
|
-
// Compute session handshake based on difficulty level set by the server
|
|
74
|
-
if (this.difficulty === 0) {
|
|
75
|
-
sessionHandshake = await this.nacl.h2(handshake);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
sessionHandshake = await this.ensureNonceDifficulty(handshake);
|
|
79
|
-
}
|
|
80
|
-
// We confirm handshake by sending back h2(clientToken, relay_token)
|
|
81
|
-
const relayPk = await this.httpCall('verify_session', h2ClientToken, utils_1.Utils.toBase64(sessionHandshake));
|
|
82
|
-
// Relay gives us back temp session key masked by clientToken we started with
|
|
83
|
-
return utils_1.Utils.fromBase64(relayPk);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Attaches a mailbox and fetches number of messages
|
|
87
|
-
*/
|
|
88
|
-
async prove(payload) {
|
|
89
|
-
if (!this.clientToken) {
|
|
90
|
-
throw new Error('[Relay] clientToken is required please openConnection first');
|
|
91
|
-
}
|
|
92
|
-
if (!this.sessionKeys) {
|
|
93
|
-
throw new Error('[Relay] No session key found, open the connection first');
|
|
94
|
-
}
|
|
95
|
-
const h2ClientToken = utils_1.Utils.toBase64(await this.nacl.h2(this.clientToken));
|
|
96
|
-
const result = await this.httpCall('prove', h2ClientToken, this.sessionKeys.publicKey, payload.nonce, payload.ctext);
|
|
97
|
-
this.scheduleSessionExpiration();
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
async encodeMessage(message) {
|
|
101
|
-
var _a;
|
|
102
|
-
if (!this.publicKey) {
|
|
103
|
-
throw new Error('[Relay] No relay public key found, open the connection first');
|
|
104
|
-
}
|
|
105
|
-
if (!this.sessionKeys) {
|
|
106
|
-
throw new Error('[Relay] No session key found, open the connection first');
|
|
107
|
-
}
|
|
108
|
-
return await encryption_helper_1.EncryptionHelper.encodeMessage(await this.nacl.encode_utf8(message), this.publicKey, utils_1.Utils.fromBase64((_a = this.sessionKeys) === null || _a === void 0 ? void 0 : _a.privateKey));
|
|
109
|
-
}
|
|
110
|
-
async decodeMessage(nonce, ctext) {
|
|
111
|
-
const relayPk = this.publicKey;
|
|
112
|
-
if (!relayPk) {
|
|
113
|
-
throw new Error('[Relay] No relay public key found, open the connection first');
|
|
114
|
-
}
|
|
115
|
-
if (!this.sessionKeys) {
|
|
116
|
-
throw new Error('[Relay] No session key found, open the connection first');
|
|
117
|
-
}
|
|
118
|
-
const decodedData = await encryption_helper_1.EncryptionHelper.decodeMessage(utils_1.Utils.fromBase64(nonce), utils_1.Utils.fromBase64(ctext), relayPk, utils_1.Utils.fromBase64(this.sessionKeys.privateKey));
|
|
119
|
-
if (decodedData === null) {
|
|
120
|
-
throw new Error('[Relay] failed to decode message');
|
|
121
|
-
}
|
|
122
|
-
return JSON.parse(decodedData);
|
|
123
|
-
}
|
|
124
|
-
// ---------- Low-level server request handling ----------
|
|
125
|
-
/**
|
|
126
|
-
* Executes a message/file command on a relay, parses and validates the response
|
|
127
|
-
*/
|
|
128
|
-
async runCmd(command, hpk, message, ctext) {
|
|
129
|
-
if (!Object.keys(zax_interface_1.RelayCommand).includes(command)) {
|
|
130
|
-
throw new Error(`[Relay] ${this.url} doesn't support command ${command}`);
|
|
131
|
-
}
|
|
132
|
-
const payload = [hpk, message.nonce, message.ctext];
|
|
133
|
-
// if we are sending symmetrically encrypted ctext, it goes on the next line in the payload
|
|
134
|
-
if (ctext) {
|
|
135
|
-
payload.push(ctext);
|
|
136
|
-
}
|
|
137
|
-
const response = await this.httpCall('command', ...payload);
|
|
138
|
-
return this.parseResponse(command, response);
|
|
139
|
-
}
|
|
140
|
-
async getSignature(relayToken, sessionKeys) {
|
|
141
|
-
if (!this.clientToken) {
|
|
142
|
-
throw new Error('[Relay] clientToken is required please openConnection first');
|
|
143
|
-
}
|
|
144
|
-
const clientTempPk = utils_1.Utils.fromBase64(sessionKeys.publicKey);
|
|
145
|
-
// Alice creates a 32 byte session signature as h₂(a_temp_pk, relayToken, clientToken)
|
|
146
|
-
const signature = new Uint8Array([...clientTempPk, ...relayToken, ...this.clientToken]);
|
|
147
|
-
const h2Signature = await this.nacl.h2(signature);
|
|
148
|
-
return h2Signature;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Executes a call to a relay and return raw string response
|
|
152
|
-
*/
|
|
153
|
-
async httpCall(command, ...params) {
|
|
154
|
-
var _a, _b;
|
|
155
|
-
const requestPayload = {
|
|
156
|
-
url: `${this.url}/${command}`,
|
|
157
|
-
method: 'post',
|
|
158
|
-
headers: {
|
|
159
|
-
'Accept': 'text/plain',
|
|
160
|
-
'Content-Type': 'text/plain'
|
|
161
|
-
},
|
|
162
|
-
data: params.join('\r\n'),
|
|
163
|
-
responseType: 'text',
|
|
164
|
-
timeout: config_1.config.RELAY_AJAX_TIMEOUT
|
|
165
|
-
};
|
|
166
|
-
// NOTE: Network and server errors are not handled ny Glow itself.
|
|
167
|
-
// They should instead be handled where the library is used
|
|
168
|
-
let response;
|
|
169
|
-
try {
|
|
170
|
-
response = await (0, axios_1.default)(requestPayload);
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
if (err.isAxiosError) {
|
|
174
|
-
const error = err;
|
|
175
|
-
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
176
|
-
// clear session if unauthorized
|
|
177
|
-
this.clearSession();
|
|
178
|
-
this.clearToken();
|
|
179
|
-
}
|
|
180
|
-
// when no network connection axios response is undefined
|
|
181
|
-
throw new network_error_1.NetworkError(((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) || 0);
|
|
182
|
-
}
|
|
183
|
-
throw err;
|
|
184
|
-
}
|
|
185
|
-
return String(response.data);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Parses relay response and throws an error if its format is unexpected
|
|
189
|
-
*/
|
|
190
|
-
parseResponse(command, rawResponse) {
|
|
191
|
-
const response = rawResponse.split('\r\n');
|
|
192
|
-
if (!rawResponse || !this.validateResponse(command, response.length)) {
|
|
193
|
-
console.log(response);
|
|
194
|
-
throw new Error(`[Relay] ${this.url} - ${command}: Bad response`);
|
|
195
|
-
}
|
|
196
|
-
return response;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Compares the expected number of lines in response with what was actually received from a relay
|
|
200
|
-
*/
|
|
201
|
-
validateResponse(command, lines) {
|
|
202
|
-
switch (command) {
|
|
203
|
-
case zax_interface_1.RelayCommand.upload:
|
|
204
|
-
case zax_interface_1.RelayCommand.messageStatus:
|
|
205
|
-
case zax_interface_1.RelayCommand.delete:
|
|
206
|
-
return lines === 1;
|
|
207
|
-
case zax_interface_1.RelayCommand.downloadFileChunk:
|
|
208
|
-
return lines === 3;
|
|
209
|
-
default:
|
|
210
|
-
return lines === 2;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* delete token locally before it was removed on server so will reconnect without getting unauthorized error
|
|
215
|
-
*/
|
|
216
|
-
scheduleTokenExpiration() {
|
|
217
|
-
if (this.tokenExpirationTimeoutHandle) {
|
|
218
|
-
clearTimeout(this.tokenExpirationTimeoutHandle);
|
|
219
|
-
}
|
|
220
|
-
this.tokenExpirationTimeoutHandle = setTimeout(() => this.clearToken(), config_1.config.RELAY_TOKEN_TIMEOUT);
|
|
221
|
-
}
|
|
222
|
-
clearToken() {
|
|
223
|
-
if (this.tokenExpirationTimeoutHandle) {
|
|
224
|
-
clearTimeout(this.tokenExpirationTimeoutHandle);
|
|
225
|
-
}
|
|
226
|
-
if (this.clientToken) {
|
|
227
|
-
delete this.clientToken;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* established session is valid only for some period need to remove it after it's ttl
|
|
232
|
-
* so relay will reconnect without receiving error from server
|
|
233
|
-
*/
|
|
234
|
-
scheduleSessionExpiration() {
|
|
235
|
-
if (this.sessionExpirationTimeoutHandle) {
|
|
236
|
-
clearTimeout(this.sessionExpirationTimeoutHandle);
|
|
237
|
-
}
|
|
238
|
-
this.sessionExpirationTimeoutHandle = setTimeout(() => {
|
|
239
|
-
this.clearSession();
|
|
240
|
-
}, config_1.config.RELAY_SESSION_TIMEOUT);
|
|
241
|
-
}
|
|
242
|
-
clearSession() {
|
|
243
|
-
if (this.sessionExpirationTimeoutHandle) {
|
|
244
|
-
clearTimeout(this.sessionExpirationTimeoutHandle);
|
|
245
|
-
}
|
|
246
|
-
if (this.sessionKeys) {
|
|
247
|
-
delete this.sessionKeys;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
// ---------- Difficulty adjustment ----------
|
|
251
|
-
/**
|
|
252
|
-
* Continuously calculates the nonce until one requested by a relay is found
|
|
253
|
-
*/
|
|
254
|
-
async ensureNonceDifficulty(handshake) {
|
|
255
|
-
let nonce;
|
|
256
|
-
let h2;
|
|
257
|
-
do {
|
|
258
|
-
nonce = await this.nacl.random_bytes(32);
|
|
259
|
-
h2 = await this.nacl.h2(new Uint8Array([...handshake, ...nonce]));
|
|
260
|
-
} while (!this.arrayZeroBits(h2));
|
|
261
|
-
return nonce;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Returns `true` if the rightmost n bits of a byte are 0.
|
|
265
|
-
* Check whether the rightmost difficulty bits of an Uint8Array are 0, where
|
|
266
|
-
* the lowest indexes of the array represent those rightmost bits. Thus if
|
|
267
|
-
* the difficulty is 17, then array[0] and array[1] should be 0, as should the
|
|
268
|
-
* rightmost bit of array[2]. This is used for our difficulty settings in Zax to
|
|
269
|
-
* reduce burden on a busy server by ensuring clients have to do some
|
|
270
|
-
* additional work during the session handshake
|
|
271
|
-
*/
|
|
272
|
-
arrayZeroBits(array) {
|
|
273
|
-
let byte;
|
|
274
|
-
let n = this.difficulty;
|
|
275
|
-
for (let i = 0; i <= (1 + this.difficulty / 8); i++) {
|
|
276
|
-
byte = array[i];
|
|
277
|
-
if (n <= 0) {
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
if (n > 8) {
|
|
281
|
-
n -= 8;
|
|
282
|
-
if (byte > 0) {
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
return this.firstZeroBits(byte, n);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Returns `true` if the rightmost n bits of a byte are 0
|
|
294
|
-
*/
|
|
295
|
-
firstZeroBits(byte, n) {
|
|
296
|
-
return byte === ((byte >> n) << n);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.Relay = Relay;
|
|
300
|
-
//# sourceMappingURL=relay.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../../src/relay/relay.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA8D;AAE9D,uCAAoC;AAEpC,iEAA6D;AAC7D,sCAAmC;AACnC,0CAA+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,CAAC,UAAU,CAAC;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACnD,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAChB,IAAI,CAAC,IAAI,CAAC,EAAE;gBACV,OAAO,IAAI,CAAC;aACb;YACD,IAAI,CAAC,GAAG,CAAC,EAAE;gBACT,CAAC,IAAI,CAAC,CAAC;gBACP,IAAI,IAAI,GAAG,CAAC,EAAE;oBACZ,OAAO,KAAK,CAAC;iBACd;aACF;iBAAM;gBACL,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;aACpC;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAY,EAAE,CAAS;QAC3C,OAAO,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACrC,CAAC;CACF;AA/TD,sBA+TC"}
|
package/dist/cjs2/utils/utils.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = void 0;
|
|
4
|
-
class Utils {
|
|
5
|
-
static toBase64(input) {
|
|
6
|
-
const isBrowser = typeof btoa !== 'undefined';
|
|
7
|
-
return isBrowser ?
|
|
8
|
-
btoa(this.decode_latin1(input)) :
|
|
9
|
-
Buffer.from(this.decode_latin1(input), 'latin1').toString('base64');
|
|
10
|
-
}
|
|
11
|
-
static fromBase64(input) {
|
|
12
|
-
const isBrowser = typeof btoa !== 'undefined';
|
|
13
|
-
return isBrowser ?
|
|
14
|
-
this.encode_latin1(atob(input)) :
|
|
15
|
-
this.encode_latin1(Buffer.from(input, 'base64').toString('latin1'));
|
|
16
|
-
}
|
|
17
|
-
static encode_latin1(data) {
|
|
18
|
-
const result = new Uint8Array(data.length);
|
|
19
|
-
for (let i = 0; i < data.length; i++) {
|
|
20
|
-
const c = data.charCodeAt(i);
|
|
21
|
-
if ((c & 0xff) !== c)
|
|
22
|
-
throw { message: 'Cannot encode string in Latin1', str: data };
|
|
23
|
-
result[i] = (c & 0xff);
|
|
24
|
-
}
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
static decode_latin1(data) {
|
|
28
|
-
const encoded = [];
|
|
29
|
-
for (let i = 0; i < data.length; i++) {
|
|
30
|
-
encoded.push(String.fromCharCode(data[i]));
|
|
31
|
-
}
|
|
32
|
-
return encoded.join('');
|
|
33
|
-
}
|
|
34
|
-
static toObject(pairs) {
|
|
35
|
-
return Array.from(pairs).reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), {});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.Utils = Utils;
|
|
39
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;AAEA,MAAa,KAAK;IAChB,MAAM,CAAC,QAAQ,CAAC,KAAiB;QAC/B,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,WAAW,CAAC;QAC9C,OAAO,SAAS,CAAC,CAAC;YAChB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAa;QAC7B,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,WAAW,CAAC;QAC9C,OAAO,SAAS,CAAC,CAAC;YAChB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC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G,CAAC,EAAE,KAAK,EAAE,CAAC,EAC3D,EAAE,CACH,CAAC;IACJ,CAAC;CACF;AAvCD,sBAuCC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZaxMessageKind = exports.MessageStatusResponse = exports.RelayCommand = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Interfaces of Zax relay command requests and responses.
|
|
6
|
-
* See https://github.com/vault12/zax for details.
|
|
7
|
-
*
|
|
8
|
-
* Full technical specification:
|
|
9
|
-
* https://s3-us-west-1.amazonaws.com/vault12/crypto_relay.pdf
|
|
10
|
-
*/
|
|
11
|
-
// In the future versions, plugins could add their own commands to specific relays
|
|
12
|
-
var RelayCommand;
|
|
13
|
-
(function (RelayCommand) {
|
|
14
|
-
// Zax message commands
|
|
15
|
-
RelayCommand["count"] = "count";
|
|
16
|
-
RelayCommand["upload"] = "upload";
|
|
17
|
-
RelayCommand["download"] = "download";
|
|
18
|
-
RelayCommand["messageStatus"] = "messageStatus";
|
|
19
|
-
RelayCommand["delete"] = "delete";
|
|
20
|
-
// Zax file commands
|
|
21
|
-
RelayCommand["startFileUpload"] = "startFileUpload";
|
|
22
|
-
RelayCommand["uploadFileChunk"] = "uploadFileChunk";
|
|
23
|
-
RelayCommand["downloadFileChunk"] = "downloadFileChunk";
|
|
24
|
-
RelayCommand["fileStatus"] = "fileStatus";
|
|
25
|
-
RelayCommand["deleteFile"] = "deleteFile";
|
|
26
|
-
})(RelayCommand = exports.RelayCommand || (exports.RelayCommand = {}));
|
|
27
|
-
/**
|
|
28
|
-
* Status of a previously sent message equals redis TTL.
|
|
29
|
-
* See https://redis.io/commands/ttl.
|
|
30
|
-
* -2 : missing key
|
|
31
|
-
* -1 : key never expires
|
|
32
|
-
* 0+ : key time to live in seconds
|
|
33
|
-
*/
|
|
34
|
-
var MessageStatusResponse;
|
|
35
|
-
(function (MessageStatusResponse) {
|
|
36
|
-
MessageStatusResponse[MessageStatusResponse["MissingKey"] = -2] = "MissingKey";
|
|
37
|
-
MessageStatusResponse[MessageStatusResponse["NeverExpires"] = -1] = "NeverExpires";
|
|
38
|
-
})(MessageStatusResponse = exports.MessageStatusResponse || (exports.MessageStatusResponse = {}));
|
|
39
|
-
// -------------- Message formats --------------
|
|
40
|
-
var ZaxMessageKind;
|
|
41
|
-
(function (ZaxMessageKind) {
|
|
42
|
-
ZaxMessageKind["message"] = "message";
|
|
43
|
-
ZaxMessageKind["file"] = "file";
|
|
44
|
-
ZaxMessageKind["plain"] = "plain";
|
|
45
|
-
})(ZaxMessageKind = exports.ZaxMessageKind || (exports.ZaxMessageKind = {}));
|
|
46
|
-
//# sourceMappingURL=zax.interface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zax.interface.js","sourceRoot":"","sources":["../../src/zax.interface.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AAEH,kFAAkF;AAClF,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB,uBAAuB;IACvB,+BAAe,CAAA;IACf,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;IACrB,+CAA+B,CAAA;IAC/B,iCAAiB,CAAA;IACjB,oBAAoB;IACpB,mDAAmC,CAAA;IACnC,mDAAmC,CAAA;IACnC,uDAAuC,CAAA;IACvC,yCAAyB,CAAA;IACzB,yCAAyB,CAAA;AAC3B,CAAC,EAbW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAavB;AAED;;;;;;GAMG;AACH,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,8EAAe,CAAA;IACf,kFAAiB,CAAA;AACnB,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAED,gDAAgD;AAEhD,IAAY,cAIX;AAJD,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,+BAAa,CAAA;IACb,iCAAe,CAAA;AACjB,CAAC,EAJW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAIzB"}
|
package/dist/esm/config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const sessionTimeoutBuffer = 30 * 1000;
|
|
2
|
-
export const config = {
|
|
3
|
-
NONCE_TAG: '__nc',
|
|
4
|
-
SKEY_TAG: 'storage_key',
|
|
5
|
-
STORAGE_ROOT: '.v1.stor.vlt12',
|
|
6
|
-
// Relay tokens, keys and hashes are 32 bytes
|
|
7
|
-
RELAY_TOKEN_LEN: 32,
|
|
8
|
-
// 5 min - Token expiration on the server side, matched with config.x.relay.token_timeout on Zax server
|
|
9
|
-
RELAY_TOKEN_TIMEOUT: 5 * 60 * 1000 - sessionTimeoutBuffer,
|
|
10
|
-
// 20 min - Session expiration on the server side, matched with config.x.relay.session_timeout on Zax server
|
|
11
|
-
RELAY_SESSION_TIMEOUT: 20 * 60 * 1000 - sessionTimeoutBuffer,
|
|
12
|
-
// 5 sec - Ajax request timeout
|
|
13
|
-
RELAY_AJAX_TIMEOUT: 5 * 1000
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=config.js.map
|
package/dist/esm/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEvC,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,SAAS,EAAE,MAAM;IACjB,QAAQ,EAAE,aAAa;IACvB,YAAY,EAAE,gBAAgB;IAC9B,6CAA6C;IAC7C,eAAe,EAAE,EAAE;IACnB,uGAAuG;IACvG,mBAAmB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,oBAAoB;IACzD,4GAA4G;IAC5G,qBAAqB,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,oBAAoB;IAC5D,+BAA+B;IAC/B,kBAAkB,EAAE,CAAC,GAAG,IAAI;CAC7B,CAAC"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { NaCl } from '../nacl/nacl';
|
|
2
|
-
import { Utils } from '../utils/utils';
|
|
3
|
-
import { config } from '../config';
|
|
4
|
-
import { LocalStorageDriver } from './local-storage.driver';
|
|
5
|
-
// TODO: add bulk operations to set(), get() and remove() pairs of values simultaneously
|
|
6
|
-
/* CryptoStorage is a handy wrapper around any storage that provides JavaScript interface,
|
|
7
|
-
that allows to store symmetrically encrypted serializable Javascript objects and primitives. */
|
|
8
|
-
export class CryptoStorage {
|
|
9
|
-
constructor(storageDriver, id) {
|
|
10
|
-
const nacl = NaCl.getInstance();
|
|
11
|
-
this.nacl = nacl;
|
|
12
|
-
this.driver = storageDriver;
|
|
13
|
-
this.id = id ? `.${id}${config.STORAGE_ROOT}` : config.STORAGE_ROOT;
|
|
14
|
-
}
|
|
15
|
-
static async new(id) {
|
|
16
|
-
const storageDriver = this.getStorageDriver();
|
|
17
|
-
const storage = new CryptoStorage(storageDriver, id);
|
|
18
|
-
const prefixedStorageKeyTag = storage.addPrefix(config.SKEY_TAG);
|
|
19
|
-
const storageKey = await storageDriver.get(prefixedStorageKeyTag);
|
|
20
|
-
// Either load or generate a storage key
|
|
21
|
-
if (storageKey) {
|
|
22
|
-
const { key } = JSON.parse(storageKey);
|
|
23
|
-
storage.storageKey = Utils.fromBase64(key);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
storage.storageKey = await storage.nacl.random_bytes(storage.nacl.crypto_secretbox_KEYBYTES);
|
|
27
|
-
await storageDriver.set(prefixedStorageKeyTag, JSON.stringify({ key: Utils.toBase64(storage.storageKey) }));
|
|
28
|
-
}
|
|
29
|
-
return storage;
|
|
30
|
-
}
|
|
31
|
-
static getStorageDriver() {
|
|
32
|
-
if (!this.storageDriver) {
|
|
33
|
-
throw new Error('[CryptoStorage] StorageDriver instance is not yet set');
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return this.storageDriver;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
static setDefaultStorageDriver() {
|
|
40
|
-
return this.setStorageDriver(new LocalStorageDriver());
|
|
41
|
-
}
|
|
42
|
-
static setStorageDriver(driver) {
|
|
43
|
-
if (this.storageDriver) {
|
|
44
|
-
throw new Error('[CryptoStorage] StorageDriver has been already set, it is supposed to be set only once');
|
|
45
|
-
}
|
|
46
|
-
this.storageDriver = driver;
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
async save(tag, data) {
|
|
50
|
-
if (!this.driver) {
|
|
51
|
-
throw new Error('[CryptoStorage] Storage driver is not set');
|
|
52
|
-
}
|
|
53
|
-
if (!this.storageKey) {
|
|
54
|
-
throw new Error('[CryptoStorage] Storage key is not set');
|
|
55
|
-
}
|
|
56
|
-
// Convert the data to JSON, then convert that string to a byte array
|
|
57
|
-
const input = JSON.stringify(data);
|
|
58
|
-
const encoded = await this.nacl.encode_utf8(input);
|
|
59
|
-
// For each item in the store we also generate and save its own nonce
|
|
60
|
-
const nonce = await this.nacl.crypto_secretbox_random_nonce();
|
|
61
|
-
const cipherText = await this.nacl.crypto_secretbox(encoded, nonce, this.storageKey);
|
|
62
|
-
// Save the cipher text and nonce
|
|
63
|
-
await this.driver.setMultiple({
|
|
64
|
-
[this.addPrefix(tag)]: Utils.toBase64(cipherText),
|
|
65
|
-
[this.addNonceTag(tag)]: Utils.toBase64(nonce)
|
|
66
|
-
});
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
async get(tag) {
|
|
70
|
-
if (!this.driver) {
|
|
71
|
-
throw new Error('[CryptoStorage] Storage driver is not set');
|
|
72
|
-
}
|
|
73
|
-
if (!this.storageKey) {
|
|
74
|
-
throw new Error('[CryptoStorage] Storage key is not set');
|
|
75
|
-
}
|
|
76
|
-
// Get cipher text and nonce from the storage
|
|
77
|
-
const [data, nonce] = await this.driver.getMultiple([this.addPrefix(tag), this.addNonceTag(tag)]);
|
|
78
|
-
// Nothing to do without cipher text or nonce
|
|
79
|
-
if (!data || !nonce) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
const dataBinary = Utils.fromBase64(data);
|
|
83
|
-
const nonceBinary = Utils.fromBase64(nonce);
|
|
84
|
-
const source = await this.nacl.crypto_secretbox_open(dataBinary, nonceBinary, this.storageKey);
|
|
85
|
-
if (source) {
|
|
86
|
-
const decoded = await this.nacl.decode_utf8(source);
|
|
87
|
-
return JSON.parse(decoded);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error('[CryptoStorage] crypto_secretbox_open: decryption error');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async remove(tag) {
|
|
94
|
-
if (!this.driver) {
|
|
95
|
-
throw new Error('[CryptoStorage] Storage driver is not set');
|
|
96
|
-
}
|
|
97
|
-
await this.driver.removeMultiple([this.addPrefix(tag), this.addNonceTag(tag)]);
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
async selfDestruct() {
|
|
101
|
-
if (!this.driver) {
|
|
102
|
-
throw new Error('[CryptoStorage] Storage driver is not set');
|
|
103
|
-
}
|
|
104
|
-
await this.driver.remove(this.addPrefix(config.SKEY_TAG));
|
|
105
|
-
}
|
|
106
|
-
// Keys are tagged in the storage with a versioned prefix
|
|
107
|
-
addPrefix(key) {
|
|
108
|
-
return this.id ? (key + this.id) : key;
|
|
109
|
-
}
|
|
110
|
-
addNonceTag(tag) {
|
|
111
|
-
return this.addPrefix(`${config.NONCE_TAG}.${tag}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
//# sourceMappingURL=crypto-storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-storage.js","sourceRoot":"","sources":["../../../src/crypto-storage/crypto-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,MAAM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C,CAAC;SAC5B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SAC5E;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,yDAAyD;IACjD,SAAS,CAAC,GAAW;QAC3B,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACzC,CAAC;IAEO,WAAW,CAAC,GAAW;QAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* temporary created in-memory storage for testing purposes
|
|
3
|
-
*/
|
|
4
|
-
export class InMemoryStorage {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.storage = {};
|
|
7
|
-
}
|
|
8
|
-
async get(key) {
|
|
9
|
-
return (await this.getMultiple([key]))[0];
|
|
10
|
-
}
|
|
11
|
-
async getMultiple(keys) {
|
|
12
|
-
return keys.map(key => this.storage[key]);
|
|
13
|
-
}
|
|
14
|
-
set(key, value) {
|
|
15
|
-
return this.setMultiple({ [key]: value });
|
|
16
|
-
}
|
|
17
|
-
async setMultiple(values) {
|
|
18
|
-
for (const key in values) {
|
|
19
|
-
this.storage[key] = values[key];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
remove(key) {
|
|
23
|
-
return this.removeMultiple([key]);
|
|
24
|
-
}
|
|
25
|
-
async removeMultiple(keys) {
|
|
26
|
-
keys.forEach(key => delete this.storage[key]);
|
|
27
|
-
}
|
|
28
|
-
reset() {
|
|
29
|
-
this.storage = {};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=in-memory-storage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-storage.js","sourceRoot":"","sources":["../../../src/crypto-storage/in-memory-storage.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,eAAe;IAA5B;QAEU,YAAO,GAAiC,EAAE,CAAC;IA+BrD,CAAC;IA7BC,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAc;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAU;QACzB,OAAO,IAAI,CAAC,WAAW,CAAC,EAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAC,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,MAAyC;QACzD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;SACjC;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAc;QACjC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
|