@wener/common 1.0.5 → 2.0.2
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/lib/cn/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- package/lib/consola/index.js +0 -1
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- package/lib/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/foundation/schema/SexType.js +14 -0
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- package/lib/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +295 -30
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +6 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- package/src/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- package/src/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +7 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +28 -28
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
reject(error);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (info.done) {
|
|
11
|
+
resolve(value);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
Promise.resolve(value).then(_next, _throw);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _async_to_generator(fn) {
|
|
18
|
+
return function () {
|
|
19
|
+
var self = this, args = arguments;
|
|
20
|
+
return new Promise(function (resolve, reject) {
|
|
21
|
+
var gen = fn.apply(self, args);
|
|
22
|
+
function _next(value) {
|
|
23
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
24
|
+
}
|
|
25
|
+
function _throw(err) {
|
|
26
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
27
|
+
}
|
|
28
|
+
_next(undefined);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _object_without_properties(source, excluded) {
|
|
33
|
+
if (source == null)
|
|
34
|
+
return {};
|
|
35
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
36
|
+
var key, i;
|
|
37
|
+
if (Object.getOwnPropertySymbols) {
|
|
38
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
39
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
40
|
+
key = sourceSymbolKeys[i];
|
|
41
|
+
if (excluded.indexOf(key) >= 0)
|
|
42
|
+
continue;
|
|
43
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
44
|
+
continue;
|
|
45
|
+
target[key] = source[key];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return target;
|
|
49
|
+
}
|
|
50
|
+
function _object_without_properties_loose(source, excluded) {
|
|
51
|
+
if (source == null)
|
|
52
|
+
return {};
|
|
53
|
+
var target = {};
|
|
54
|
+
var sourceKeys = Object.keys(source);
|
|
55
|
+
var key, i;
|
|
56
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
57
|
+
key = sourceKeys[i];
|
|
58
|
+
if (excluded.indexOf(key) >= 0)
|
|
59
|
+
continue;
|
|
60
|
+
target[key] = source[key];
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function _ts_generator(thisArg, body) {
|
|
65
|
+
var f, y, t, _ = {
|
|
66
|
+
label: 0,
|
|
67
|
+
sent: function () {
|
|
68
|
+
if (t[0] & 1)
|
|
69
|
+
throw t[1];
|
|
70
|
+
return t[1];
|
|
71
|
+
},
|
|
72
|
+
trys: [],
|
|
73
|
+
ops: []
|
|
74
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
75
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
76
|
+
return this;
|
|
77
|
+
}), g;
|
|
78
|
+
function verb(n) {
|
|
79
|
+
return function (v) {
|
|
80
|
+
return step([
|
|
81
|
+
n,
|
|
82
|
+
v
|
|
83
|
+
]);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function step(op) {
|
|
87
|
+
if (f)
|
|
88
|
+
throw new TypeError("Generator is already executing.");
|
|
89
|
+
while (g && (g = 0, op[0] && (_ = 0)), _)
|
|
90
|
+
try {
|
|
91
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
92
|
+
return t;
|
|
93
|
+
if (y = 0, t)
|
|
94
|
+
op = [
|
|
95
|
+
op[0] & 2,
|
|
96
|
+
t.value
|
|
97
|
+
];
|
|
98
|
+
switch (op[0]) {
|
|
99
|
+
case 0:
|
|
100
|
+
case 1:
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
case 4:
|
|
104
|
+
_.label++;
|
|
105
|
+
return {
|
|
106
|
+
value: op[1],
|
|
107
|
+
done: false
|
|
108
|
+
};
|
|
109
|
+
case 5:
|
|
110
|
+
_.label++;
|
|
111
|
+
y = op[1];
|
|
112
|
+
op = [
|
|
113
|
+
0
|
|
114
|
+
];
|
|
115
|
+
continue;
|
|
116
|
+
case 7:
|
|
117
|
+
op = _.ops.pop();
|
|
118
|
+
_.trys.pop();
|
|
119
|
+
continue;
|
|
120
|
+
default:
|
|
121
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
122
|
+
_ = 0;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
126
|
+
_.label = op[1];
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
130
|
+
_.label = t[1];
|
|
131
|
+
t = op;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
if (t && _.label < t[2]) {
|
|
135
|
+
_.label = t[2];
|
|
136
|
+
_.ops.push(op);
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (t[2])
|
|
140
|
+
_.ops.pop();
|
|
141
|
+
_.trys.pop();
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
op = body.call(thisArg, _);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
op = [
|
|
148
|
+
6,
|
|
149
|
+
e
|
|
150
|
+
];
|
|
151
|
+
y = 0;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
f = t = 0;
|
|
155
|
+
}
|
|
156
|
+
if (op[0] & 5)
|
|
157
|
+
throw op[1];
|
|
158
|
+
return {
|
|
159
|
+
value: op[0] ? op[1] : void 0,
|
|
160
|
+
done: true
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
import { describe, expect, test } from "vitest";
|
|
165
|
+
import { createArgon2PasswordAlgorithm } from "./createArgon2PasswordAlgorithm.js";
|
|
166
|
+
import { createBase64PasswordAlgorithm } from "./createBase64PasswordAlgorithm.js";
|
|
167
|
+
import { createBcryptPasswordAlgorithm } from "./createBcryptPasswordAlgorithm.js";
|
|
168
|
+
import { Password } from "./Password.js";
|
|
169
|
+
describe("Password", function () {
|
|
170
|
+
var check = function (_param) {
|
|
171
|
+
return _async_to_generator(function () {
|
|
172
|
+
var _param_password, password, rest, out, result;
|
|
173
|
+
return _ts_generator(this, function (_state) {
|
|
174
|
+
switch (_state.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
_param_password = _param.password, password = _param_password === void 0 ? "1" : _param_password, rest = _object_without_properties(_param, [
|
|
177
|
+
"password"
|
|
178
|
+
]);
|
|
179
|
+
return [
|
|
180
|
+
4,
|
|
181
|
+
Password.hash(password, rest)
|
|
182
|
+
];
|
|
183
|
+
case 1:
|
|
184
|
+
out = _state.sent();
|
|
185
|
+
console.log("".concat(rest.algorithm || "default", ": hash ").concat(out));
|
|
186
|
+
return [
|
|
187
|
+
4,
|
|
188
|
+
Password.verify(password, out)
|
|
189
|
+
];
|
|
190
|
+
case 2:
|
|
191
|
+
result = _state.sent();
|
|
192
|
+
expect(result).toBe(true);
|
|
193
|
+
return [
|
|
194
|
+
2
|
|
195
|
+
];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
})();
|
|
199
|
+
};
|
|
200
|
+
Password.addAlgorithm(createBcryptPasswordAlgorithm());
|
|
201
|
+
Password.addAlgorithm(createBase64PasswordAlgorithm());
|
|
202
|
+
Password.addAlgorithm(createArgon2PasswordAlgorithm({
|
|
203
|
+
provide: import("argon2")
|
|
204
|
+
}));
|
|
205
|
+
// Password.addAlgorithm(createScryptPasswordAlgorithm());
|
|
206
|
+
test("base", function () {
|
|
207
|
+
return _async_to_generator(function () {
|
|
208
|
+
return _ts_generator(this, function (_state) {
|
|
209
|
+
switch (_state.label) {
|
|
210
|
+
case 0:
|
|
211
|
+
return [
|
|
212
|
+
4,
|
|
213
|
+
check({})
|
|
214
|
+
];
|
|
215
|
+
case 1:
|
|
216
|
+
_state.sent();
|
|
217
|
+
return [
|
|
218
|
+
4,
|
|
219
|
+
check({
|
|
220
|
+
algorithm: "bcrypt"
|
|
221
|
+
})
|
|
222
|
+
];
|
|
223
|
+
case 2:
|
|
224
|
+
_state.sent();
|
|
225
|
+
return [
|
|
226
|
+
4,
|
|
227
|
+
check({
|
|
228
|
+
algorithm: "base64"
|
|
229
|
+
})
|
|
230
|
+
];
|
|
231
|
+
case 3:
|
|
232
|
+
_state.sent();
|
|
233
|
+
// invalid base 64
|
|
234
|
+
return [
|
|
235
|
+
4,
|
|
236
|
+
check({
|
|
237
|
+
algorithm: "base64",
|
|
238
|
+
password: "\u4F60\u597D"
|
|
239
|
+
})
|
|
240
|
+
];
|
|
241
|
+
case 4:
|
|
242
|
+
_state.sent();
|
|
243
|
+
return [
|
|
244
|
+
4,
|
|
245
|
+
check({
|
|
246
|
+
algorithm: "5"
|
|
247
|
+
})
|
|
248
|
+
];
|
|
249
|
+
case 5:
|
|
250
|
+
_state.sent();
|
|
251
|
+
return [
|
|
252
|
+
4,
|
|
253
|
+
check({
|
|
254
|
+
algorithm: "6"
|
|
255
|
+
})
|
|
256
|
+
];
|
|
257
|
+
case 6:
|
|
258
|
+
_state.sent();
|
|
259
|
+
return [
|
|
260
|
+
4,
|
|
261
|
+
check({
|
|
262
|
+
algorithm: "7"
|
|
263
|
+
})
|
|
264
|
+
];
|
|
265
|
+
case 7:
|
|
266
|
+
_state.sent();
|
|
267
|
+
return [
|
|
268
|
+
2
|
|
269
|
+
];
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
})();
|
|
273
|
+
});
|
|
274
|
+
test("should verify manual created hash", function () {
|
|
275
|
+
return _async_to_generator(function () {
|
|
276
|
+
var tests, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, _step_value_password, password, hash, err;
|
|
277
|
+
return _ts_generator(this, function (_state) {
|
|
278
|
+
switch (_state.label) {
|
|
279
|
+
case 0:
|
|
280
|
+
tests = [
|
|
281
|
+
{
|
|
282
|
+
hash: "$2y$10$MQ057tMbDG6/lVkGFWrNwOR9kh/5rzbkhBPrwNPTPuZ5wBpGNbWLa"
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
hash: "$argon2i$v=19$m=16,t=2,p=1$SDZBU29LRUp0eTJyRDJqZg$76L95nAjG4SjjdoR0YZyFw"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
hash: "$argon2d$v=19$m=16,t=2,p=1$SDZBU29LRUp0eTJyRDJqZg$+cB2R45sauVlfxbGslAmOw"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
hash: "$argon2id$v=19$m=16,t=2,p=1$SDZBU29LRUp0eTJyRDJqZg$iP9HYuSDXgG2lW7KARBuQQ"
|
|
292
|
+
}
|
|
293
|
+
];
|
|
294
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
295
|
+
_state.label = 1;
|
|
296
|
+
case 1:
|
|
297
|
+
_state.trys.push([
|
|
298
|
+
1,
|
|
299
|
+
6,
|
|
300
|
+
7,
|
|
301
|
+
8
|
|
302
|
+
]);
|
|
303
|
+
_iterator = tests[Symbol.iterator]();
|
|
304
|
+
_state.label = 2;
|
|
305
|
+
case 2:
|
|
306
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
307
|
+
return [
|
|
308
|
+
3,
|
|
309
|
+
5
|
|
310
|
+
];
|
|
311
|
+
_step_value = _step.value, _step_value_password = _step_value.password, password = _step_value_password === void 0 ? "1" : _step_value_password, hash = _step_value.hash;
|
|
312
|
+
return [
|
|
313
|
+
4,
|
|
314
|
+
Password.verify(password, hash)
|
|
315
|
+
];
|
|
316
|
+
case 3:
|
|
317
|
+
expect.apply(void 0, [
|
|
318
|
+
_state.sent()
|
|
319
|
+
]).toBe(true);
|
|
320
|
+
_state.label = 4;
|
|
321
|
+
case 4:
|
|
322
|
+
_iteratorNormalCompletion = true;
|
|
323
|
+
return [
|
|
324
|
+
3,
|
|
325
|
+
2
|
|
326
|
+
];
|
|
327
|
+
case 5:
|
|
328
|
+
return [
|
|
329
|
+
3,
|
|
330
|
+
8
|
|
331
|
+
];
|
|
332
|
+
case 6:
|
|
333
|
+
err = _state.sent();
|
|
334
|
+
_didIteratorError = true;
|
|
335
|
+
_iteratorError = err;
|
|
336
|
+
return [
|
|
337
|
+
3,
|
|
338
|
+
8
|
|
339
|
+
];
|
|
340
|
+
case 7:
|
|
341
|
+
try {
|
|
342
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
343
|
+
_iterator.return();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
finally {
|
|
347
|
+
if (_didIteratorError) {
|
|
348
|
+
throw _iteratorError;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return [
|
|
352
|
+
7
|
|
353
|
+
];
|
|
354
|
+
case 8:
|
|
355
|
+
return [
|
|
356
|
+
2
|
|
357
|
+
];
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
})();
|
|
361
|
+
});
|
|
362
|
+
});
|
|
@@ -1,30 +1,157 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
+
return this;
|
|
42
|
+
}), g;
|
|
43
|
+
function verb(n) {
|
|
44
|
+
return function(v) {
|
|
45
|
+
return step([
|
|
46
|
+
n,
|
|
47
|
+
v
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function step(op) {
|
|
52
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
+
if (y = 0, t) op = [
|
|
56
|
+
op[0] & 2,
|
|
57
|
+
t.value
|
|
58
|
+
];
|
|
59
|
+
switch(op[0]){
|
|
60
|
+
case 0:
|
|
61
|
+
case 1:
|
|
62
|
+
t = op;
|
|
63
|
+
break;
|
|
64
|
+
case 4:
|
|
65
|
+
_.label++;
|
|
66
|
+
return {
|
|
67
|
+
value: op[1],
|
|
68
|
+
done: false
|
|
69
|
+
};
|
|
70
|
+
case 5:
|
|
71
|
+
_.label++;
|
|
72
|
+
y = op[1];
|
|
73
|
+
op = [
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
continue;
|
|
77
|
+
case 7:
|
|
78
|
+
op = _.ops.pop();
|
|
79
|
+
_.trys.pop();
|
|
80
|
+
continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
+
_ = 0;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
+
_.label = op[1];
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
+
_.label = t[1];
|
|
92
|
+
t = op;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (t && _.label < t[2]) {
|
|
96
|
+
_.label = t[2];
|
|
97
|
+
_.ops.push(op);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (t[2]) _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
op = body.call(thisArg, _);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
op = [
|
|
107
|
+
6,
|
|
108
|
+
e
|
|
109
|
+
];
|
|
110
|
+
y = 0;
|
|
111
|
+
} finally{
|
|
112
|
+
f = t = 0;
|
|
113
|
+
}
|
|
114
|
+
if (op[0] & 5) throw op[1];
|
|
115
|
+
return {
|
|
116
|
+
value: op[0] ? op[1] : void 0,
|
|
117
|
+
done: true
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
import { maybeFunction } from '@wener/utils';
|
|
122
|
+
export function createArgon2PasswordAlgorithm() {
|
|
123
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, type = _ref.type, _ref_provide = _ref.provide, provide = _ref_provide === void 0 ? function() {
|
|
124
|
+
return _async_to_generator(function() {
|
|
125
|
+
return _ts_generator(this, function(_state) {
|
|
126
|
+
throw new Error('Please provide argon2');
|
|
127
|
+
});
|
|
128
|
+
// const { default: wasm } = await import('argon2-browser/dist/argon2.wasm');
|
|
129
|
+
// const argon2 = await WebAssembly.instantiateStreaming(fetch(wasm), {
|
|
130
|
+
// env: {
|
|
131
|
+
// memoryBase: 0,
|
|
132
|
+
// tableBase: 0,
|
|
133
|
+
// memory: new WebAssembly.Memory({ initial: 256 }),
|
|
134
|
+
// table: new WebAssembly.Table({ initial: 0, element: 'anyfunc' }),
|
|
135
|
+
// __memory_base: 0,
|
|
136
|
+
// __table_base: 0,
|
|
137
|
+
// },
|
|
138
|
+
// });
|
|
139
|
+
// console.log(argon2.instance.exports);
|
|
140
|
+
// const { hash } = argon2.instance.exports as any as typeof import('argon2-browser');
|
|
141
|
+
})();
|
|
142
|
+
} : _ref_provide;
|
|
18
143
|
// 0=Argon2d, 1=Argon2i, 2=Argon2id
|
|
19
|
-
|
|
144
|
+
var toType = {
|
|
20
145
|
argon2d: 0,
|
|
21
146
|
argon2i: 1,
|
|
22
147
|
argon2id: 2
|
|
23
148
|
};
|
|
24
|
-
|
|
25
|
-
|
|
149
|
+
var mod;
|
|
150
|
+
var resolve = function() {
|
|
26
151
|
if (mod) return mod;
|
|
27
|
-
return Promise.resolve(maybeFunction(provide)).then((v)
|
|
152
|
+
return Promise.resolve(maybeFunction(provide)).then(function(v) {
|
|
153
|
+
return mod = v;
|
|
154
|
+
});
|
|
28
155
|
};
|
|
29
156
|
return {
|
|
30
157
|
name: 'argon2',
|
|
@@ -33,21 +160,50 @@ export function createArgon2PasswordAlgorithm({ type, provide = async ()=>{
|
|
|
33
160
|
'argon2d',
|
|
34
161
|
'argon2id'
|
|
35
162
|
],
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
163
|
+
hash: function hash(password, opts) {
|
|
164
|
+
return _async_to_generator(function() {
|
|
165
|
+
var hash, id, _toType_;
|
|
166
|
+
return _ts_generator(this, function(_state) {
|
|
167
|
+
switch(_state.label){
|
|
168
|
+
case 0:
|
|
169
|
+
return [
|
|
170
|
+
4,
|
|
171
|
+
resolve()
|
|
172
|
+
];
|
|
173
|
+
case 1:
|
|
174
|
+
hash = _state.sent().hash;
|
|
175
|
+
id = opts === null || opts === void 0 ? void 0 : opts.id;
|
|
176
|
+
return [
|
|
177
|
+
2,
|
|
178
|
+
hash(password, {
|
|
179
|
+
salt: (opts === null || opts === void 0 ? void 0 : opts.salt) ? Buffer.from(opts.salt) : undefined,
|
|
180
|
+
raw: false,
|
|
181
|
+
type: (_toType_ = toType[id || '']) !== null && _toType_ !== void 0 ? _toType_ : toType[type || '']
|
|
182
|
+
})
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
})();
|
|
45
187
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
188
|
+
verify: function verify(password, hash) {
|
|
189
|
+
return _async_to_generator(function() {
|
|
190
|
+
var verify;
|
|
191
|
+
return _ts_generator(this, function(_state) {
|
|
192
|
+
switch(_state.label){
|
|
193
|
+
case 0:
|
|
194
|
+
return [
|
|
195
|
+
4,
|
|
196
|
+
resolve()
|
|
197
|
+
];
|
|
198
|
+
case 1:
|
|
199
|
+
verify = _state.sent().verify;
|
|
200
|
+
return [
|
|
201
|
+
2,
|
|
202
|
+
verify(hash, password)
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
})();
|
|
49
207
|
}
|
|
50
208
|
};
|
|
51
209
|
}
|
|
52
|
-
|
|
53
|
-
//# sourceMappingURL=createArgon2PasswordAlgorithm.js.map
|