mol_crypto_lib 0.1.1385 → 0.1.1387
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/node.d.ts +91 -81
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +431 -369
- package/node.js.map +1 -1
- package/node.meta.tree +4 -1
- package/node.mjs +431 -369
- package/node.test.js +1383 -1302
- package/node.test.js.map +1 -1
- package/package.json +20 -18
- package/web.d.ts +50 -40
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +229 -167
- package/web.js.map +1 -1
- package/web.meta.tree +4 -1
- package/web.mjs +229 -167
- package/web.test.js +71 -52
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
@@ -30,6 +30,97 @@ $.$$ = $
|
|
30
30
|
|
31
31
|
;
|
32
32
|
"use strict";
|
33
|
+
var $;
|
34
|
+
(function ($) {
|
35
|
+
function $mol_base64_encode(src) {
|
36
|
+
throw new Error('Not implemented');
|
37
|
+
}
|
38
|
+
$.$mol_base64_encode = $mol_base64_encode;
|
39
|
+
})($ || ($ = {}));
|
40
|
+
|
41
|
+
;
|
42
|
+
"use strict";
|
43
|
+
var $;
|
44
|
+
(function ($) {
|
45
|
+
function $mol_base64_encode_node(str) {
|
46
|
+
if (!str)
|
47
|
+
return '';
|
48
|
+
if (Buffer.isBuffer(str))
|
49
|
+
return str.toString('base64');
|
50
|
+
return Buffer.from(str).toString('base64');
|
51
|
+
}
|
52
|
+
$.$mol_base64_encode_node = $mol_base64_encode_node;
|
53
|
+
$.$mol_base64_encode = $mol_base64_encode_node;
|
54
|
+
})($ || ($ = {}));
|
55
|
+
|
56
|
+
;
|
57
|
+
"use strict";
|
58
|
+
var $;
|
59
|
+
(function ($) {
|
60
|
+
function $mol_base64_decode(base64) {
|
61
|
+
throw new Error('Not implemented');
|
62
|
+
}
|
63
|
+
$.$mol_base64_decode = $mol_base64_decode;
|
64
|
+
})($ || ($ = {}));
|
65
|
+
|
66
|
+
;
|
67
|
+
"use strict";
|
68
|
+
var $;
|
69
|
+
(function ($) {
|
70
|
+
function $mol_base64_decode_node(base64Str) {
|
71
|
+
base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
|
72
|
+
const buffer = Buffer.from(base64Str, 'base64');
|
73
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
74
|
+
}
|
75
|
+
$.$mol_base64_decode_node = $mol_base64_decode_node;
|
76
|
+
$.$mol_base64_decode = $mol_base64_decode_node;
|
77
|
+
})($ || ($ = {}));
|
78
|
+
|
79
|
+
;
|
80
|
+
"use strict";
|
81
|
+
var $;
|
82
|
+
(function ($) {
|
83
|
+
function $mol_base64_ae_encode(buffer) {
|
84
|
+
return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
|
85
|
+
}
|
86
|
+
$.$mol_base64_ae_encode = $mol_base64_ae_encode;
|
87
|
+
function $mol_base64_ae_decode(str) {
|
88
|
+
return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
|
89
|
+
}
|
90
|
+
$.$mol_base64_ae_decode = $mol_base64_ae_decode;
|
91
|
+
})($ || ($ = {}));
|
92
|
+
|
93
|
+
;
|
94
|
+
"use strict";
|
95
|
+
var $;
|
96
|
+
(function ($) {
|
97
|
+
const named = new WeakSet();
|
98
|
+
function $mol_func_name(func) {
|
99
|
+
let name = func.name;
|
100
|
+
if (name?.length > 1)
|
101
|
+
return name;
|
102
|
+
if (named.has(func))
|
103
|
+
return name;
|
104
|
+
for (let key in this) {
|
105
|
+
try {
|
106
|
+
if (this[key] !== func)
|
107
|
+
continue;
|
108
|
+
name = key;
|
109
|
+
Object.defineProperty(func, 'name', { value: name });
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
catch { }
|
113
|
+
}
|
114
|
+
named.add(func);
|
115
|
+
return name;
|
116
|
+
}
|
117
|
+
$.$mol_func_name = $mol_func_name;
|
118
|
+
function $mol_func_name_from(target, source) {
|
119
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
120
|
+
return target;
|
121
|
+
}
|
122
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
123
|
+
})($ || ($ = {}));
|
33
124
|
|
34
125
|
;
|
35
126
|
"use strict";
|
@@ -41,6 +132,125 @@ var $;
|
|
41
132
|
$.$mol_fail = $mol_fail;
|
42
133
|
})($ || ($ = {}));
|
43
134
|
|
135
|
+
;
|
136
|
+
"use strict";
|
137
|
+
var $;
|
138
|
+
(function ($) {
|
139
|
+
class $mol_buffer extends DataView {
|
140
|
+
static from(array) {
|
141
|
+
if (typeof array === 'number')
|
142
|
+
array = new Uint8Array(array);
|
143
|
+
if (typeof array === 'string')
|
144
|
+
array = $mol_base64_ae_decode(array);
|
145
|
+
return new this(array.buffer, array.byteOffset, array.byteLength);
|
146
|
+
}
|
147
|
+
static toString() {
|
148
|
+
return $$.$mol_func_name(this);
|
149
|
+
}
|
150
|
+
getUint48(offset, LE = false) {
|
151
|
+
if (offset % 4) {
|
152
|
+
return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
setUint48(offset, value, LE = false) {
|
159
|
+
if (offset % 4) {
|
160
|
+
this.setUint16(offset, value & ((1 << 16) - 1), LE);
|
161
|
+
this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
this.setUint32(offset, value | 0, LE);
|
165
|
+
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
int8(offset, next) {
|
169
|
+
if (next === undefined)
|
170
|
+
return this.getInt8(offset);
|
171
|
+
if (next >= -(2 ** 7) && next < 2 ** 7)
|
172
|
+
return this.setInt8(offset, next), next;
|
173
|
+
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
174
|
+
}
|
175
|
+
uint8(offset, next) {
|
176
|
+
if (next === undefined)
|
177
|
+
return this.getUint8(offset);
|
178
|
+
if (next >= 0 && next < 2 ** 8)
|
179
|
+
return this.setUint8(offset, next), next;
|
180
|
+
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
181
|
+
}
|
182
|
+
int16(offset, next) {
|
183
|
+
if (next === undefined)
|
184
|
+
return this.getInt16(offset, true);
|
185
|
+
if (next >= -(2 ** 15) && next < 2 ** 15)
|
186
|
+
return this.setInt16(offset, next, true), next;
|
187
|
+
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
188
|
+
}
|
189
|
+
uint16(offset, next) {
|
190
|
+
if (next === undefined)
|
191
|
+
return this.getUint16(offset, true);
|
192
|
+
if (next >= 0 && next < 2 ** 16)
|
193
|
+
return this.setUint16(offset, next, true), next;
|
194
|
+
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
195
|
+
}
|
196
|
+
int32(offset, next) {
|
197
|
+
if (next === undefined)
|
198
|
+
return this.getInt32(offset, true);
|
199
|
+
if (next >= -(2 ** 31) && next < 2 ** 31)
|
200
|
+
return this.setInt32(offset, next, true), next;
|
201
|
+
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
202
|
+
}
|
203
|
+
uint32(offset, next) {
|
204
|
+
if (next === undefined)
|
205
|
+
return this.getUint32(offset, true);
|
206
|
+
if (next >= 0 && next < 2 ** 32)
|
207
|
+
return this.setUint32(offset, next, true), next;
|
208
|
+
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
209
|
+
}
|
210
|
+
uint48(offset, next) {
|
211
|
+
if (next === undefined)
|
212
|
+
return this.getUint48(offset, true);
|
213
|
+
if (next >= 0 && next < 2 ** 48)
|
214
|
+
return this.setUint48(offset, next, true), next;
|
215
|
+
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
216
|
+
}
|
217
|
+
int64(offset, next) {
|
218
|
+
if (next === undefined)
|
219
|
+
return this.getBigInt64(offset, true);
|
220
|
+
if (next >= -(2 ** 63) && next < 2 ** 63)
|
221
|
+
return this.setBigInt64(offset, next, true), next;
|
222
|
+
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
223
|
+
}
|
224
|
+
uint64(offset, next) {
|
225
|
+
if (next === undefined)
|
226
|
+
return this.getBigUint64(offset, true);
|
227
|
+
if (next >= 0 && next < 2 ** 64)
|
228
|
+
return this.setBigUint64(offset, next, true), next;
|
229
|
+
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
230
|
+
}
|
231
|
+
float32(offset, next) {
|
232
|
+
if (next !== undefined)
|
233
|
+
this.setFloat32(offset, next, true);
|
234
|
+
return this.getFloat32(offset, true);
|
235
|
+
}
|
236
|
+
float64(offset, next) {
|
237
|
+
if (next !== undefined)
|
238
|
+
this.setFloat64(offset, next, true);
|
239
|
+
return this.getFloat64(offset, true);
|
240
|
+
}
|
241
|
+
asArray() {
|
242
|
+
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
243
|
+
}
|
244
|
+
toString() {
|
245
|
+
return $mol_base64_ae_encode(this.asArray());
|
246
|
+
}
|
247
|
+
}
|
248
|
+
$.$mol_buffer = $mol_buffer;
|
249
|
+
})($ || ($ = {}));
|
250
|
+
|
251
|
+
;
|
252
|
+
"use strict";
|
253
|
+
|
44
254
|
;
|
45
255
|
"use strict";
|
46
256
|
var $;
|
@@ -151,38 +361,6 @@ require = (req => Object.assign(function require(name) {
|
|
151
361
|
return $node[name];
|
152
362
|
}, req))(require);
|
153
363
|
|
154
|
-
;
|
155
|
-
"use strict";
|
156
|
-
var $;
|
157
|
-
(function ($) {
|
158
|
-
const named = new WeakSet();
|
159
|
-
function $mol_func_name(func) {
|
160
|
-
let name = func.name;
|
161
|
-
if (name?.length > 1)
|
162
|
-
return name;
|
163
|
-
if (named.has(func))
|
164
|
-
return name;
|
165
|
-
for (let key in this) {
|
166
|
-
try {
|
167
|
-
if (this[key] !== func)
|
168
|
-
continue;
|
169
|
-
name = key;
|
170
|
-
Object.defineProperty(func, 'name', { value: name });
|
171
|
-
break;
|
172
|
-
}
|
173
|
-
catch { }
|
174
|
-
}
|
175
|
-
named.add(func);
|
176
|
-
return name;
|
177
|
-
}
|
178
|
-
$.$mol_func_name = $mol_func_name;
|
179
|
-
function $mol_func_name_from(target, source) {
|
180
|
-
Object.defineProperty(target, 'name', { value: source.name });
|
181
|
-
return target;
|
182
|
-
}
|
183
|
-
$.$mol_func_name_from = $mol_func_name_from;
|
184
|
-
})($ || ($ = {}));
|
185
|
-
|
186
364
|
;
|
187
365
|
"use strict";
|
188
366
|
var $;
|
@@ -1914,83 +2092,155 @@ var $;
|
|
1914
2092
|
"use strict";
|
1915
2093
|
var $;
|
1916
2094
|
(function ($) {
|
1917
|
-
|
1918
|
-
|
1919
|
-
function $mol_charset_encode(value) {
|
1920
|
-
return encoder.encode(value);
|
2095
|
+
function $mol_crypto_salt() {
|
2096
|
+
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
1921
2097
|
}
|
1922
|
-
$.$
|
2098
|
+
$.$mol_crypto_salt = $mol_crypto_salt;
|
2099
|
+
$.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
|
1923
2100
|
})($ || ($ = {}));
|
1924
2101
|
|
1925
2102
|
;
|
1926
2103
|
"use strict";
|
1927
2104
|
var $;
|
1928
2105
|
(function ($) {
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
static
|
1945
|
-
|
1946
|
-
|
1947
|
-
static async pass(pass, salt) {
|
1948
|
-
return new this(await $mol_crypto_native.subtle.deriveKey({
|
1949
|
-
name: "PBKDF2",
|
1950
|
-
salt,
|
1951
|
-
iterations: 10_000,
|
1952
|
-
hash: "SHA-256",
|
1953
|
-
}, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
|
1954
|
-
}
|
1955
|
-
static async derive(private_serial, public_serial) {
|
1956
|
-
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
1957
|
-
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
1958
|
-
const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
|
1959
|
-
...jwk,
|
1960
|
-
key_ops: ['deriveKey'],
|
1961
|
-
x: private_serial.slice(0, 43),
|
1962
|
-
y: private_serial.slice(43, 86),
|
1963
|
-
d: private_serial.slice(86, 129),
|
1964
|
-
}, ecdh, true, ['deriveKey']);
|
1965
|
-
const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
|
1966
|
-
...jwk,
|
1967
|
-
key_ops: [],
|
1968
|
-
x: public_serial.slice(0, 43),
|
1969
|
-
y: public_serial.slice(43, 86),
|
1970
|
-
}, ecdh, true, []);
|
1971
|
-
const secret = await $mol_crypto_native.subtle.deriveKey({
|
1972
|
-
name: "ECDH",
|
1973
|
-
public: public_key,
|
1974
|
-
}, private_key, algorithm, true, ["encrypt", "decrypt"]);
|
1975
|
-
return new this(secret);
|
2106
|
+
function $mol_base64_url_encode(buffer) {
|
2107
|
+
return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
2108
|
+
}
|
2109
|
+
$.$mol_base64_url_encode = $mol_base64_url_encode;
|
2110
|
+
function $mol_base64_url_decode(str) {
|
2111
|
+
return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
|
2112
|
+
}
|
2113
|
+
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
2114
|
+
})($ || ($ = {}));
|
2115
|
+
|
2116
|
+
;
|
2117
|
+
"use strict";
|
2118
|
+
var $;
|
2119
|
+
(function ($) {
|
2120
|
+
class $mol_wrapper extends $mol_object2 {
|
2121
|
+
static wrap;
|
2122
|
+
static run(task) {
|
2123
|
+
return this.func(task)();
|
1976
2124
|
}
|
1977
|
-
|
1978
|
-
return
|
2125
|
+
static func(func) {
|
2126
|
+
return this.wrap(func);
|
2127
|
+
}
|
2128
|
+
static get class() {
|
2129
|
+
return (Class) => {
|
2130
|
+
const construct = (target, args) => new Class(...args);
|
2131
|
+
const handler = {
|
2132
|
+
construct: this.func(construct)
|
2133
|
+
};
|
2134
|
+
handler[Symbol.toStringTag] = Class.name + '#';
|
2135
|
+
return new Proxy(Class, handler);
|
2136
|
+
};
|
2137
|
+
}
|
2138
|
+
static get method() {
|
2139
|
+
return (obj, name, descr) => {
|
2140
|
+
descr.value = this.func(descr.value);
|
2141
|
+
return descr;
|
2142
|
+
};
|
2143
|
+
}
|
2144
|
+
static get field() {
|
2145
|
+
return (obj, name, descr) => {
|
2146
|
+
descr.get = descr.set = this.func(descr.get);
|
2147
|
+
return descr;
|
2148
|
+
};
|
2149
|
+
}
|
2150
|
+
}
|
2151
|
+
$.$mol_wrapper = $mol_wrapper;
|
2152
|
+
})($ || ($ = {}));
|
2153
|
+
|
2154
|
+
;
|
2155
|
+
"use strict";
|
2156
|
+
var $;
|
2157
|
+
(function ($) {
|
2158
|
+
class $mol_memo extends $mol_wrapper {
|
2159
|
+
static wrap(task) {
|
2160
|
+
const store = new WeakMap();
|
2161
|
+
const fun = function (next) {
|
2162
|
+
if (next === undefined && store.has(this))
|
2163
|
+
return store.get(this);
|
2164
|
+
const val = task.call(this, next) ?? next;
|
2165
|
+
store.set(this, val);
|
2166
|
+
return val;
|
2167
|
+
};
|
2168
|
+
Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
|
2169
|
+
return fun;
|
2170
|
+
}
|
2171
|
+
}
|
2172
|
+
$.$mol_memo = $mol_memo;
|
2173
|
+
})($ || ($ = {}));
|
2174
|
+
|
2175
|
+
;
|
2176
|
+
"use strict";
|
2177
|
+
var $;
|
2178
|
+
(function ($) {
|
2179
|
+
class $mol_crypto_sacred extends $mol_buffer {
|
2180
|
+
static size = 16;
|
2181
|
+
static make() {
|
2182
|
+
return this.from($mol_crypto_salt());
|
2183
|
+
}
|
2184
|
+
static from(serial) {
|
2185
|
+
if (typeof serial === 'string') {
|
2186
|
+
serial = new Uint8Array([
|
2187
|
+
...$mol_base64_url_decode(serial),
|
2188
|
+
]);
|
2189
|
+
}
|
2190
|
+
if (!(serial instanceof Uint8Array)) {
|
2191
|
+
serial = new Uint8Array(serial.buffer, serial.byteOffset, serial.byteLength);
|
2192
|
+
}
|
2193
|
+
;
|
2194
|
+
serial[0] = 0;
|
2195
|
+
const sacred = super.from(serial);
|
2196
|
+
return sacred;
|
2197
|
+
}
|
2198
|
+
static async from_native(native) {
|
2199
|
+
const buf = await $mol_crypto_native.subtle.exportKey('raw', native);
|
2200
|
+
const sacred = this.from(new Uint8Array(buf));
|
2201
|
+
sacred._native = native;
|
2202
|
+
return sacred;
|
2203
|
+
}
|
2204
|
+
constructor(buffer, byteOffset, byteLength) {
|
2205
|
+
super(buffer, byteOffset, byteLength);
|
2206
|
+
if (this.getUint8(0) !== 0)
|
2207
|
+
$mol_fail(new Error('Buffer should starts with 0 byte'));
|
2208
|
+
}
|
2209
|
+
toString() {
|
2210
|
+
return $mol_base64_url_encode(this.asArray());
|
2211
|
+
}
|
2212
|
+
_native;
|
2213
|
+
async native() {
|
2214
|
+
return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
|
2215
|
+
name: 'AES-CBC',
|
2216
|
+
length: 128,
|
2217
|
+
}, true, ['encrypt', 'decrypt']));
|
1979
2218
|
}
|
1980
2219
|
async encrypt(open, salt) {
|
1981
2220
|
return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
|
1982
|
-
|
2221
|
+
name: 'AES-CBC',
|
2222
|
+
length: 128,
|
2223
|
+
tagLength: 32,
|
1983
2224
|
iv: salt,
|
1984
|
-
}, this.native, open));
|
2225
|
+
}, await this.native(), open));
|
1985
2226
|
}
|
1986
2227
|
async decrypt(closed, salt) {
|
1987
2228
|
return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
|
1988
|
-
|
2229
|
+
name: 'AES-CBC',
|
2230
|
+
length: 128,
|
2231
|
+
tagLength: 32,
|
1989
2232
|
iv: salt,
|
1990
|
-
}, this.native, closed));
|
2233
|
+
}, await this.native(), closed));
|
2234
|
+
}
|
2235
|
+
async close(sacred, salt) {
|
2236
|
+
const buf = new Uint8Array(this.buffer, this.byteOffset + 1, this.byteLength - 1);
|
2237
|
+
return sacred.encrypt(buf, salt);
|
1991
2238
|
}
|
1992
2239
|
}
|
1993
|
-
|
2240
|
+
__decorate([
|
2241
|
+
$mol_memo.method
|
2242
|
+
], $mol_crypto_sacred.prototype, "toString", null);
|
2243
|
+
$.$mol_crypto_sacred = $mol_crypto_sacred;
|
1994
2244
|
})($ || ($ = {}));
|
1995
2245
|
|
1996
2246
|
;
|
@@ -2017,309 +2267,97 @@ var $;
|
|
2017
2267
|
"use strict";
|
2018
2268
|
var $;
|
2019
2269
|
(function ($) {
|
2020
|
-
async function $
|
2021
|
-
const
|
2022
|
-
if (
|
2023
|
-
return await this.$
|
2024
|
-
const id = await this.$
|
2025
|
-
this.$
|
2270
|
+
async function $mol_crypto_sacred_id() {
|
2271
|
+
const inited = this.$mol_dom.localStorage.getItem('$mol_crypto_sacred_id');
|
2272
|
+
if (inited === 'true')
|
2273
|
+
return await this.$mol_crypto_sacred_id_get();
|
2274
|
+
const id = await this.$mol_crypto_sacred_id_new();
|
2275
|
+
this.$mol_dom.localStorage.setItem('$mol_crypto_sacred_id', 'true');
|
2026
2276
|
return id;
|
2027
2277
|
}
|
2028
|
-
$.$
|
2029
|
-
async function $
|
2030
|
-
const cred = await this.$
|
2278
|
+
$.$mol_crypto_sacred_id = $mol_crypto_sacred_id;
|
2279
|
+
async function $mol_crypto_sacred_id_new() {
|
2280
|
+
const cred = await this.$mol_dom.navigator.credentials.create({
|
2031
2281
|
publicKey: {
|
2032
2282
|
rp: {
|
2033
|
-
name: "$
|
2283
|
+
name: "$mol_crypto_sacred_id",
|
2284
|
+
},
|
2285
|
+
authenticatorSelection: {
|
2286
|
+
userVerification: 'discouraged',
|
2287
|
+
residentKey: 'discouraged',
|
2034
2288
|
},
|
2035
2289
|
user: {
|
2036
2290
|
id: new Uint8Array([0]),
|
2037
2291
|
name: "",
|
2038
2292
|
displayName: ""
|
2039
2293
|
},
|
2040
|
-
pubKeyCredParams: [
|
2041
|
-
{ type: "public-key", alg: -7 },
|
2042
|
-
{ type: "public-key", alg: -257 },
|
2043
|
-
],
|
2294
|
+
pubKeyCredParams: [],
|
2044
2295
|
challenge: new Uint8Array().buffer,
|
2045
2296
|
},
|
2046
2297
|
});
|
2047
|
-
|
2298
|
+
console.log(cred);
|
2299
|
+
const key = new Uint8Array(cred.rawId, 0, 16);
|
2300
|
+
return $mol_crypto_sacred.from(key);
|
2048
2301
|
}
|
2049
|
-
$.$
|
2050
|
-
async function $
|
2051
|
-
const cred = await this.$
|
2302
|
+
$.$mol_crypto_sacred_id_new = $mol_crypto_sacred_id_new;
|
2303
|
+
async function $mol_crypto_sacred_id_get() {
|
2304
|
+
const cred = await this.$mol_dom.navigator.credentials.get({
|
2052
2305
|
mediation: 'silent',
|
2053
2306
|
publicKey: {
|
2054
2307
|
userVerification: 'discouraged',
|
2055
2308
|
challenge: new Uint8Array().buffer,
|
2056
2309
|
},
|
2057
2310
|
});
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
})($ || ($ = {}));
|
2062
|
-
|
2063
|
-
;
|
2064
|
-
"use strict";
|
2065
|
-
var $;
|
2066
|
-
(function ($) {
|
2067
|
-
function $mol_base64_encode(src) {
|
2068
|
-
throw new Error('Not implemented');
|
2069
|
-
}
|
2070
|
-
$.$mol_base64_encode = $mol_base64_encode;
|
2071
|
-
})($ || ($ = {}));
|
2072
|
-
|
2073
|
-
;
|
2074
|
-
"use strict";
|
2075
|
-
var $;
|
2076
|
-
(function ($) {
|
2077
|
-
function $mol_base64_encode_node(str) {
|
2078
|
-
if (!str)
|
2079
|
-
return '';
|
2080
|
-
if (Buffer.isBuffer(str))
|
2081
|
-
return str.toString('base64');
|
2082
|
-
return Buffer.from(str).toString('base64');
|
2083
|
-
}
|
2084
|
-
$.$mol_base64_encode_node = $mol_base64_encode_node;
|
2085
|
-
$.$mol_base64_encode = $mol_base64_encode_node;
|
2086
|
-
})($ || ($ = {}));
|
2087
|
-
|
2088
|
-
;
|
2089
|
-
"use strict";
|
2090
|
-
var $;
|
2091
|
-
(function ($) {
|
2092
|
-
function $mol_base64_decode(base64) {
|
2093
|
-
throw new Error('Not implemented');
|
2094
|
-
}
|
2095
|
-
$.$mol_base64_decode = $mol_base64_decode;
|
2096
|
-
})($ || ($ = {}));
|
2097
|
-
|
2098
|
-
;
|
2099
|
-
"use strict";
|
2100
|
-
var $;
|
2101
|
-
(function ($) {
|
2102
|
-
function $mol_base64_decode_node(base64Str) {
|
2103
|
-
base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
|
2104
|
-
const buffer = Buffer.from(base64Str, 'base64');
|
2105
|
-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
2106
|
-
}
|
2107
|
-
$.$mol_base64_decode_node = $mol_base64_decode_node;
|
2108
|
-
$.$mol_base64_decode = $mol_base64_decode_node;
|
2109
|
-
})($ || ($ = {}));
|
2110
|
-
|
2111
|
-
;
|
2112
|
-
"use strict";
|
2113
|
-
var $;
|
2114
|
-
(function ($) {
|
2115
|
-
function $mol_base64_ae_encode(buffer) {
|
2116
|
-
return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
|
2117
|
-
}
|
2118
|
-
$.$mol_base64_ae_encode = $mol_base64_ae_encode;
|
2119
|
-
function $mol_base64_ae_decode(str) {
|
2120
|
-
return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
|
2121
|
-
}
|
2122
|
-
$.$mol_base64_ae_decode = $mol_base64_ae_decode;
|
2123
|
-
})($ || ($ = {}));
|
2124
|
-
|
2125
|
-
;
|
2126
|
-
"use strict";
|
2127
|
-
var $;
|
2128
|
-
(function ($) {
|
2129
|
-
class $mol_buffer extends DataView {
|
2130
|
-
static from(array) {
|
2131
|
-
if (typeof array === 'number')
|
2132
|
-
array = new Uint8Array(array);
|
2133
|
-
if (typeof array === 'string')
|
2134
|
-
array = $mol_base64_ae_decode(array);
|
2135
|
-
return new this(array.buffer, array.byteOffset, array.byteLength);
|
2136
|
-
}
|
2137
|
-
static toString() {
|
2138
|
-
return $$.$mol_func_name(this);
|
2139
|
-
}
|
2140
|
-
getUint48(offset, LE = false) {
|
2141
|
-
if (offset % 4) {
|
2142
|
-
return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
|
2143
|
-
}
|
2144
|
-
else {
|
2145
|
-
return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
|
2146
|
-
}
|
2147
|
-
}
|
2148
|
-
setUint48(offset, value, LE = false) {
|
2149
|
-
if (offset % 4) {
|
2150
|
-
this.setUint16(offset, value & ((1 << 16) - 1), LE);
|
2151
|
-
this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
|
2152
|
-
}
|
2153
|
-
else {
|
2154
|
-
this.setUint32(offset, value | 0, LE);
|
2155
|
-
this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
|
2156
|
-
}
|
2157
|
-
}
|
2158
|
-
int8(offset, next) {
|
2159
|
-
if (next === undefined)
|
2160
|
-
return this.getInt8(offset);
|
2161
|
-
if (next >= -(2 ** 7) && next < 2 ** 7)
|
2162
|
-
return this.setInt8(offset, next), next;
|
2163
|
-
$mol_fail(new Error(`Wrong int8 value ${next}`));
|
2164
|
-
}
|
2165
|
-
uint8(offset, next) {
|
2166
|
-
if (next === undefined)
|
2167
|
-
return this.getUint8(offset);
|
2168
|
-
if (next >= 0 && next < 2 ** 8)
|
2169
|
-
return this.setUint8(offset, next), next;
|
2170
|
-
$mol_fail(new Error(`Wrong uint8 value ${next}`));
|
2171
|
-
}
|
2172
|
-
int16(offset, next) {
|
2173
|
-
if (next === undefined)
|
2174
|
-
return this.getInt16(offset, true);
|
2175
|
-
if (next >= -(2 ** 15) && next < 2 ** 15)
|
2176
|
-
return this.setInt16(offset, next, true), next;
|
2177
|
-
$mol_fail(new Error(`Wrong int16 value ${next}`));
|
2178
|
-
}
|
2179
|
-
uint16(offset, next) {
|
2180
|
-
if (next === undefined)
|
2181
|
-
return this.getUint16(offset, true);
|
2182
|
-
if (next >= 0 && next < 2 ** 16)
|
2183
|
-
return this.setUint16(offset, next, true), next;
|
2184
|
-
$mol_fail(new Error(`Wrong uint16 value ${next}`));
|
2185
|
-
}
|
2186
|
-
int32(offset, next) {
|
2187
|
-
if (next === undefined)
|
2188
|
-
return this.getInt32(offset, true);
|
2189
|
-
if (next >= -(2 ** 31) && next < 2 ** 31)
|
2190
|
-
return this.setInt32(offset, next, true), next;
|
2191
|
-
$mol_fail(new Error(`Wrong int32 value ${next}`));
|
2192
|
-
}
|
2193
|
-
uint32(offset, next) {
|
2194
|
-
if (next === undefined)
|
2195
|
-
return this.getUint32(offset, true);
|
2196
|
-
if (next >= 0 && next < 2 ** 32)
|
2197
|
-
return this.setUint32(offset, next, true), next;
|
2198
|
-
$mol_fail(new Error(`Wrong uint32 value ${next}`));
|
2199
|
-
}
|
2200
|
-
uint48(offset, next) {
|
2201
|
-
if (next === undefined)
|
2202
|
-
return this.getUint48(offset, true);
|
2203
|
-
if (next >= 0 && next < 2 ** 48)
|
2204
|
-
return this.setUint48(offset, next, true), next;
|
2205
|
-
$mol_fail(new Error(`Wrong uint48 value ${next}`));
|
2206
|
-
}
|
2207
|
-
int64(offset, next) {
|
2208
|
-
if (next === undefined)
|
2209
|
-
return this.getBigInt64(offset, true);
|
2210
|
-
if (next >= -(2 ** 63) && next < 2 ** 63)
|
2211
|
-
return this.setBigInt64(offset, next, true), next;
|
2212
|
-
$mol_fail(new Error(`Wrong int64 value ${next}`));
|
2213
|
-
}
|
2214
|
-
uint64(offset, next) {
|
2215
|
-
if (next === undefined)
|
2216
|
-
return this.getBigUint64(offset, true);
|
2217
|
-
if (next >= 0 && next < 2 ** 64)
|
2218
|
-
return this.setBigUint64(offset, next, true), next;
|
2219
|
-
$mol_fail(new Error(`Wrong uint64 value ${next}`));
|
2220
|
-
}
|
2221
|
-
float32(offset, next) {
|
2222
|
-
if (next !== undefined)
|
2223
|
-
this.setFloat32(offset, next, true);
|
2224
|
-
return this.getFloat32(offset, true);
|
2225
|
-
}
|
2226
|
-
float64(offset, next) {
|
2227
|
-
if (next !== undefined)
|
2228
|
-
this.setFloat64(offset, next, true);
|
2229
|
-
return this.getFloat64(offset, true);
|
2230
|
-
}
|
2231
|
-
asArray() {
|
2232
|
-
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
2233
|
-
}
|
2234
|
-
toString() {
|
2235
|
-
return $mol_base64_ae_encode(this.asArray());
|
2236
|
-
}
|
2311
|
+
const key = new Uint8Array(cred.rawId, 0, 16);
|
2312
|
+
console.log(key);
|
2313
|
+
return $mol_crypto_sacred.from(key);
|
2237
2314
|
}
|
2238
|
-
$.$
|
2315
|
+
$.$mol_crypto_sacred_id_get = $mol_crypto_sacred_id_get;
|
2239
2316
|
})($ || ($ = {}));
|
2240
2317
|
|
2241
2318
|
;
|
2242
2319
|
"use strict";
|
2243
2320
|
var $;
|
2244
2321
|
(function ($) {
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
function $mol_base64_url_decode(str) {
|
2250
|
-
return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
|
2251
|
-
}
|
2252
|
-
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
2253
|
-
})($ || ($ = {}));
|
2254
|
-
|
2255
|
-
;
|
2256
|
-
"use strict";
|
2257
|
-
var $;
|
2258
|
-
(function ($) {
|
2259
|
-
class $mol_wrapper extends $mol_object2 {
|
2260
|
-
static wrap;
|
2261
|
-
static run(task) {
|
2262
|
-
return this.func(task)();
|
2263
|
-
}
|
2264
|
-
static func(func) {
|
2265
|
-
return this.wrap(func);
|
2266
|
-
}
|
2267
|
-
static get class() {
|
2268
|
-
return (Class) => {
|
2269
|
-
const construct = (target, args) => new Class(...args);
|
2270
|
-
const handler = {
|
2271
|
-
construct: this.func(construct)
|
2272
|
-
};
|
2273
|
-
handler[Symbol.toStringTag] = Class.name + '#';
|
2274
|
-
return new Proxy(Class, handler);
|
2275
|
-
};
|
2276
|
-
}
|
2277
|
-
static get method() {
|
2278
|
-
return (obj, name, descr) => {
|
2279
|
-
descr.value = this.func(descr.value);
|
2280
|
-
return descr;
|
2281
|
-
};
|
2282
|
-
}
|
2283
|
-
static get field() {
|
2284
|
-
return (obj, name, descr) => {
|
2285
|
-
descr.get = descr.set = this.func(descr.get);
|
2286
|
-
return descr;
|
2287
|
-
};
|
2288
|
-
}
|
2322
|
+
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
2323
|
+
const encoder = new TextEncoder();
|
2324
|
+
function $mol_charset_encode(value) {
|
2325
|
+
return encoder.encode(value);
|
2289
2326
|
}
|
2290
|
-
$.$
|
2327
|
+
$.$mol_charset_encode = $mol_charset_encode;
|
2291
2328
|
})($ || ($ = {}));
|
2292
2329
|
|
2293
2330
|
;
|
2294
2331
|
"use strict";
|
2295
2332
|
var $;
|
2296
2333
|
(function ($) {
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
$.$mol_memo = $mol_memo;
|
2334
|
+
async function $mol_crypto_sacred_pass(pass, salt) {
|
2335
|
+
const raw = await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]);
|
2336
|
+
const hard = await $mol_crypto_native.subtle.deriveKey({
|
2337
|
+
name: "PBKDF2",
|
2338
|
+
salt,
|
2339
|
+
iterations: 10_000,
|
2340
|
+
hash: "SHA-256",
|
2341
|
+
}, raw, {
|
2342
|
+
name: 'AES-CBC',
|
2343
|
+
length: 128,
|
2344
|
+
}, Boolean('extractable'), ['encrypt', 'decrypt']);
|
2345
|
+
return $mol_crypto_sacred.from_native(hard);
|
2346
|
+
}
|
2347
|
+
$.$mol_crypto_sacred_pass = $mol_crypto_sacred_pass;
|
2312
2348
|
})($ || ($ = {}));
|
2313
2349
|
|
2314
2350
|
;
|
2315
2351
|
"use strict";
|
2316
2352
|
var $;
|
2317
2353
|
(function ($) {
|
2318
|
-
const
|
2354
|
+
const ecdsa = {
|
2319
2355
|
name: 'ECDSA',
|
2320
2356
|
hash: 'SHA-1',
|
2321
2357
|
namedCurve: "P-256",
|
2322
2358
|
};
|
2359
|
+
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
2360
|
+
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
2323
2361
|
class $mol_crypto_key extends $mol_buffer {
|
2324
2362
|
static from(serial) {
|
2325
2363
|
if (typeof serial === 'string') {
|
@@ -2331,9 +2369,6 @@ var $;
|
|
2331
2369
|
}
|
2332
2370
|
return super.from(serial);
|
2333
2371
|
}
|
2334
|
-
asArray() {
|
2335
|
-
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
|
2336
|
-
}
|
2337
2372
|
toString() {
|
2338
2373
|
const arr = this.asArray();
|
2339
2374
|
return $mol_base64_url_encode(arr.subarray(0, 32))
|
@@ -2357,22 +2392,34 @@ var $;
|
|
2357
2392
|
kty: "EC",
|
2358
2393
|
x: str.slice(0, 43),
|
2359
2394
|
y: str.slice(43, 86),
|
2360
|
-
},
|
2395
|
+
}, ecdsa, Boolean('extractable'), ['verify']);
|
2396
|
+
}
|
2397
|
+
async native_derive() {
|
2398
|
+
const serial = this.toString();
|
2399
|
+
return await $mol_crypto_native.subtle.importKey('jwk', {
|
2400
|
+
...jwk,
|
2401
|
+
key_ops: [],
|
2402
|
+
x: serial.slice(0, 43),
|
2403
|
+
y: serial.slice(43, 86),
|
2404
|
+
}, ecdh, true, []);
|
2361
2405
|
}
|
2362
2406
|
async verify(data, sign) {
|
2363
|
-
return await $mol_crypto_native.subtle.verify(
|
2407
|
+
return await $mol_crypto_native.subtle.verify(ecdsa, await this.native(), sign, data);
|
2364
2408
|
}
|
2365
2409
|
}
|
2366
2410
|
__decorate([
|
2367
2411
|
$mol_memo.method
|
2368
2412
|
], $mol_crypto_key_public.prototype, "native", null);
|
2413
|
+
__decorate([
|
2414
|
+
$mol_memo.method
|
2415
|
+
], $mol_crypto_key_public.prototype, "native_derive", null);
|
2369
2416
|
$.$mol_crypto_key_public = $mol_crypto_key_public;
|
2370
2417
|
class $mol_crypto_key_private extends $mol_crypto_key {
|
2371
2418
|
static size_str = 129;
|
2372
2419
|
static size_bin = 96;
|
2373
2420
|
static size_sign = 64;
|
2374
2421
|
static async generate() {
|
2375
|
-
const pair = await $mol_crypto_native.subtle.generateKey(
|
2422
|
+
const pair = await $mol_crypto_native.subtle.generateKey(ecdsa, Boolean('extractable'), ['sign', 'verify']);
|
2376
2423
|
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey);
|
2377
2424
|
return this.from(x + y + d);
|
2378
2425
|
}
|
@@ -2386,24 +2433,50 @@ var $;
|
|
2386
2433
|
x: str.slice(0, 43),
|
2387
2434
|
y: str.slice(43, 86),
|
2388
2435
|
d: str.slice(86, 129),
|
2389
|
-
},
|
2436
|
+
}, ecdsa, Boolean('extractable'), ['sign']);
|
2437
|
+
}
|
2438
|
+
async native_derive() {
|
2439
|
+
const serial = this.toString();
|
2440
|
+
return $mol_crypto_native.subtle.importKey('jwk', {
|
2441
|
+
...jwk,
|
2442
|
+
key_ops: ['deriveKey', 'deriveBits'],
|
2443
|
+
x: serial.slice(0, 43),
|
2444
|
+
y: serial.slice(43, 86),
|
2445
|
+
d: serial.slice(86, 129),
|
2446
|
+
}, ecdh, Boolean('extractable'), ['deriveKey', 'deriveBits']);
|
2390
2447
|
}
|
2391
2448
|
public() {
|
2392
2449
|
return new $mol_crypto_key_public(this.buffer, this.byteOffset, this.byteOffset + 64);
|
2393
2450
|
}
|
2394
2451
|
async sign(data) {
|
2395
|
-
return new Uint8Array(await $mol_crypto_native.subtle.sign(
|
2452
|
+
return new Uint8Array(await $mol_crypto_native.subtle.sign(ecdsa, await this.native(), data));
|
2396
2453
|
}
|
2397
2454
|
}
|
2398
2455
|
__decorate([
|
2399
2456
|
$mol_memo.method
|
2400
2457
|
], $mol_crypto_key_private.prototype, "native", null);
|
2458
|
+
__decorate([
|
2459
|
+
$mol_memo.method
|
2460
|
+
], $mol_crypto_key_private.prototype, "native_derive", null);
|
2401
2461
|
__decorate([
|
2402
2462
|
$mol_memo.method
|
2403
2463
|
], $mol_crypto_key_private.prototype, "public", null);
|
2404
2464
|
$.$mol_crypto_key_private = $mol_crypto_key_private;
|
2405
2465
|
})($ || ($ = {}));
|
2406
2466
|
|
2467
|
+
;
|
2468
|
+
"use strict";
|
2469
|
+
var $;
|
2470
|
+
(function ($) {
|
2471
|
+
async function $mol_crypto_sacred_shared(priv, pub) {
|
2472
|
+
return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
|
2473
|
+
name: "ECDH",
|
2474
|
+
public: await pub.native_derive(),
|
2475
|
+
}, await priv.native_derive(), $mol_crypto_sacred.size)));
|
2476
|
+
}
|
2477
|
+
$.$mol_crypto_sacred_shared = $mol_crypto_sacred_shared;
|
2478
|
+
})($ || ($ = {}));
|
2479
|
+
|
2407
2480
|
;
|
2408
2481
|
"use strict";
|
2409
2482
|
var $;
|
@@ -2506,17 +2579,6 @@ var $;
|
|
2506
2579
|
$.$mol_crypto_hash = $mol_crypto_hash;
|
2507
2580
|
})($ || ($ = {}));
|
2508
2581
|
|
2509
|
-
;
|
2510
|
-
"use strict";
|
2511
|
-
var $;
|
2512
|
-
(function ($) {
|
2513
|
-
function $mol_crypto_salt() {
|
2514
|
-
return $mol_crypto_native.getRandomValues(new Uint8Array(16));
|
2515
|
-
}
|
2516
|
-
$.$mol_crypto_salt = $mol_crypto_salt;
|
2517
|
-
$.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
|
2518
|
-
})($ || ($ = {}));
|
2519
|
-
|
2520
2582
|
|
2521
2583
|
export default $
|
2522
2584
|
//# sourceMappingURL=node.js.map
|