web-dc-api 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/dc.min.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +934 -878
- package/package.json +4 -8
- package/dist/cjs/helia-core-B1Xqha7a.js +0 -1
- package/dist/cjs/helia-core-D8Uv1KjQ.js +0 -1
- package/dist/cjs/polkadot-api-7PhQf3ws.js +0 -1
- package/dist/cjs/polkadot-api-CtrJVWuZ.js +0 -1
- package/dist/esm/chunks/helia-core-BxMqyK2Y.js +0 -1
- package/dist/esm/chunks/helia-core-DMXRpcO-.js +0 -1
- package/dist/esm/chunks/polkadot-api-5Y9Bw8VT.js +0 -1
- package/dist/esm/chunks/polkadot-api-D69Ioun_.js +0 -1
- package/lib/common/blowfish/block.ts +0 -259
- package/lib/common/blowfish/cipher.ts +0 -144
- package/lib/common/blowfish/const.ts +0 -195
- package/lib/common/chain.ts +0 -469
- package/lib/common/commonclient.ts +0 -202
- package/lib/common/constants.ts +0 -55
- package/lib/common/dc-key/ed25519.ts +0 -343
- package/lib/common/dc-key/keyManager.ts +0 -424
- package/lib/common/dcapi.ts +0 -98
- package/lib/common/dcutil.ts +0 -627
- package/lib/common/define.ts +0 -70
- package/lib/common/error.ts +0 -67
- package/lib/common/grpc-dc.ts +0 -104
- package/lib/common/module-system.ts +0 -184
- package/lib/common/service-worker.ts +0 -234
- package/lib/common/types/types.ts +0 -344
- package/lib/dc.ts +0 -701
- package/lib/implements/account/client.ts +0 -185
- package/lib/implements/account/manager.ts +0 -683
- package/lib/implements/aiproxy/client.ts +0 -357
- package/lib/implements/aiproxy/manager.ts +0 -670
- package/lib/implements/cache/client.ts +0 -105
- package/lib/implements/cache/manager.ts +0 -127
- package/lib/implements/comment/client.ts +0 -982
- package/lib/implements/comment/manager.ts +0 -1151
- package/lib/implements/dc/client.ts +0 -51
- package/lib/implements/dc/manager.ts +0 -33
- package/lib/implements/file/client.ts +0 -253
- package/lib/implements/file/file-cache-manager.ts +0 -142
- package/lib/implements/file/manager.ts +0 -1240
- package/lib/implements/file/seekableFileStream.ts +0 -344
- package/lib/implements/file/streamwriter.ts +0 -322
- package/lib/implements/keyvalue/client.ts +0 -376
- package/lib/implements/keyvalue/manager.ts +0 -759
- package/lib/implements/message/client.ts +0 -250
- package/lib/implements/message/manager.ts +0 -215
- package/lib/implements/threaddb/cbor/coding.ts +0 -62
- package/lib/implements/threaddb/cbor/event.ts +0 -336
- package/lib/implements/threaddb/cbor/node.ts +0 -542
- package/lib/implements/threaddb/cbor/record.ts +0 -398
- package/lib/implements/threaddb/common/AsyncMutex.ts +0 -24
- package/lib/implements/threaddb/common/addrinfo.ts +0 -135
- package/lib/implements/threaddb/common/dispatcher.ts +0 -81
- package/lib/implements/threaddb/common/idbstore-adapter.ts +0 -260
- package/lib/implements/threaddb/common/json-patcher.ts +0 -204
- package/lib/implements/threaddb/common/key.ts +0 -290
- package/lib/implements/threaddb/common/level-adapter.ts +0 -235
- package/lib/implements/threaddb/common/lineReader.ts +0 -79
- package/lib/implements/threaddb/common/logstore.ts +0 -215
- package/lib/implements/threaddb/common/transformed-datastore.ts +0 -308
- package/lib/implements/threaddb/core/app.ts +0 -206
- package/lib/implements/threaddb/core/core.ts +0 -230
- package/lib/implements/threaddb/core/db.ts +0 -249
- package/lib/implements/threaddb/core/event.ts +0 -54
- package/lib/implements/threaddb/core/head.ts +0 -89
- package/lib/implements/threaddb/core/identity.ts +0 -171
- package/lib/implements/threaddb/core/logstore.ts +0 -137
- package/lib/implements/threaddb/core/options.ts +0 -14
- package/lib/implements/threaddb/core/record.ts +0 -54
- package/lib/implements/threaddb/db/collection.ts +0 -1910
- package/lib/implements/threaddb/db/db.ts +0 -698
- package/lib/implements/threaddb/db/json2Query.ts +0 -192
- package/lib/implements/threaddb/db/query.ts +0 -524
- package/lib/implements/threaddb/dbclient.ts +0 -543
- package/lib/implements/threaddb/dbmanager.ts +0 -1906
- package/lib/implements/threaddb/lsstoreds/addr_book.ts +0 -549
- package/lib/implements/threaddb/lsstoreds/cache.ts +0 -36
- package/lib/implements/threaddb/lsstoreds/cyclic_batch.ts +0 -87
- package/lib/implements/threaddb/lsstoreds/global.ts +0 -151
- package/lib/implements/threaddb/lsstoreds/headbook.ts +0 -373
- package/lib/implements/threaddb/lsstoreds/keybook.ts +0 -297
- package/lib/implements/threaddb/lsstoreds/logstore.ts +0 -29
- package/lib/implements/threaddb/lsstoreds/metadata.ts +0 -223
- package/lib/implements/threaddb/net/define.ts +0 -149
- package/lib/implements/threaddb/net/grpcClient.ts +0 -589
- package/lib/implements/threaddb/net/grpcserver.ts +0 -146
- package/lib/implements/threaddb/net/net.ts +0 -2047
- package/lib/implements/threaddb/pb/lstore.proto +0 -38
- package/lib/implements/threaddb/pb/lstore.ts +0 -393
- package/lib/implements/threaddb/pb/lstore_pb.d.ts +0 -433
- package/lib/implements/threaddb/pb/lstore_pb.js +0 -1085
- package/lib/implements/threaddb/pb/net.proto +0 -194
- package/lib/implements/threaddb/pb/net_pb.d.ts +0 -2349
- package/lib/implements/threaddb/pb/net_pb.js +0 -5525
- package/lib/implements/threaddb/pb/proto-custom-types.ts +0 -212
- package/lib/implements/util/client.ts +0 -72
- package/lib/implements/util/manager.ts +0 -146
- package/lib/implements/wallet/manager.ts +0 -671
- package/lib/index.ts +0 -57
- package/lib/interfaces/DCContext.ts +0 -51
- package/lib/interfaces/aiproxy-interface.ts +0 -145
- package/lib/interfaces/auth-interface.ts +0 -118
- package/lib/interfaces/cache-interface.ts +0 -22
- package/lib/interfaces/client-interface.ts +0 -11
- package/lib/interfaces/comment-interface.ts +0 -167
- package/lib/interfaces/components/news-component.ts +0 -0
- package/lib/interfaces/database-interface.ts +0 -169
- package/lib/interfaces/file-interface.ts +0 -120
- package/lib/interfaces/index.ts +0 -10
- package/lib/interfaces/keyvalue-interface.ts +0 -156
- package/lib/interfaces/message-interface.ts +0 -22
- package/lib/interfaces/util-interface.ts +0 -31
- package/lib/modules/aiproxy-module.ts +0 -246
- package/lib/modules/auth-module.ts +0 -753
- package/lib/modules/cache-module.ts +0 -99
- package/lib/modules/client-module.ts +0 -71
- package/lib/modules/comment-module.ts +0 -429
- package/lib/modules/components/news-components.ts +0 -390
- package/lib/modules/database-module.ts +0 -598
- package/lib/modules/file-module.ts +0 -291
- package/lib/modules/index.ts +0 -13
- package/lib/modules/keyvalue-module.ts +0 -379
- package/lib/modules/message-module.ts +0 -107
- package/lib/modules/util-module.ts +0 -148
- package/lib/polyfills/process-env-browser.ts +0 -1
- package/lib/proto/datasource.ts +0 -93
- package/lib/proto/dcnet.proto +0 -1601
- package/lib/proto/dcnet_proto.d.ts +0 -22857
- package/lib/proto/dcnet_proto.js +0 -55204
- package/lib/proto/dcnet_proto_sparse.js +0 -55166
- package/lib/proto/oidfetch.proto +0 -25
- package/lib/proto/oidfetch_proto.d.ts +0 -585
- package/lib/proto/oidfetch_proto.js +0 -1247
- package/lib/serverless/babel-browser.ts +0 -39
- package/lib/serverless/base_entity.ts +0 -78
- package/lib/serverless/base_repository.ts +0 -414
- package/lib/serverless/browser_schema_extractor.ts +0 -283
- package/lib/serverless/decorator_factory.ts +0 -322
- package/lib/util/BrowserLineReader.ts +0 -73
- package/lib/util/base64.ts +0 -105
- package/lib/util/bcrypt.ts +0 -206
- package/lib/util/curve25519Encryption.ts +0 -418
- package/lib/util/dccrypt.ts +0 -73
- package/lib/util/logger.ts +0 -104
- package/lib/util/utils.ts +0 -289
package/lib/util/base64.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
export class CustomBase64 {
|
|
2
|
-
private static readonly alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
3
|
-
private encodeLookup: number[];
|
|
4
|
-
private decodeLookup: number[];
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
// 初始化编码查找表
|
|
8
|
-
this.encodeLookup = new Array(64);
|
|
9
|
-
for (let i = 0; i < CustomBase64.alphabet.length; i++) {
|
|
10
|
-
this.encodeLookup[i] = CustomBase64.alphabet.charCodeAt(i);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 初始化解码查找表
|
|
14
|
-
this.decodeLookup = new Array(256).fill(-1);
|
|
15
|
-
for (let i = 0; i < CustomBase64.alphabet.length; i++) {
|
|
16
|
-
this.decodeLookup[CustomBase64.alphabet.charCodeAt(i)] = i;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
encode(src: Uint8Array): string {
|
|
21
|
-
if (src.length === 0) {
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let result = "";
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < src.length; i += 3) {
|
|
28
|
-
const chunk = (src[i] << 16) |
|
|
29
|
-
((i + 1 < src.length ? src[i + 1] : 0) << 8) |
|
|
30
|
-
(i + 2 < src.length ? src[i + 2] : 0);
|
|
31
|
-
|
|
32
|
-
result += String.fromCharCode(
|
|
33
|
-
this.encodeLookup[(chunk >> 18) & 0x3F],
|
|
34
|
-
this.encodeLookup[(chunk >> 12) & 0x3F]
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (i + 1 < src.length) {
|
|
38
|
-
result += String.fromCharCode(
|
|
39
|
-
this.encodeLookup[(chunk >> 6) & 0x3F]
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (i + 2 < src.length) {
|
|
43
|
-
result += String.fromCharCode(
|
|
44
|
-
this.encodeLookup[chunk & 0x3F]
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
decode(src: Uint8Array): Uint8Array {
|
|
53
|
-
if (src.length === 0) {
|
|
54
|
-
return new Uint8Array(0);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 添加填充
|
|
58
|
-
const padding = 4 - (src.length % 4);
|
|
59
|
-
const paddedSrc = new Uint8Array(src.length + (padding === 4 ? 0 : padding));
|
|
60
|
-
paddedSrc.set(src);
|
|
61
|
-
for (let i = src.length; i < paddedSrc.length; i++) {
|
|
62
|
-
paddedSrc[i] = 61; // '=' character
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const dst = new Uint8Array(Math.floor(paddedSrc.length * 3 / 4));
|
|
66
|
-
let dstIndex = 0;
|
|
67
|
-
|
|
68
|
-
for (let i = 0; i < paddedSrc.length; i += 4) {
|
|
69
|
-
const v1 = this.decodeLookup[paddedSrc[i]];
|
|
70
|
-
const v2 = this.decodeLookup[paddedSrc[i + 1]];
|
|
71
|
-
const v3 = this.decodeLookup[paddedSrc[i + 2]];
|
|
72
|
-
const v4 = this.decodeLookup[paddedSrc[i + 3]];
|
|
73
|
-
|
|
74
|
-
if (v1 === -1 || v2 === -1) {
|
|
75
|
-
throw new Error('Invalid base64 character');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const chunk = (v1 << 18) | (v2 << 12) |
|
|
79
|
-
((v3 === -1 ? 0 : v3) << 6) |
|
|
80
|
-
(v4 === -1 ? 0 : v4);
|
|
81
|
-
|
|
82
|
-
dst[dstIndex++] = (chunk >> 16) & 0xFF;
|
|
83
|
-
if (v3 !== -1) {
|
|
84
|
-
dst[dstIndex++] = (chunk >> 8) & 0xFF;
|
|
85
|
-
}
|
|
86
|
-
if (v4 !== -1) {
|
|
87
|
-
dst[dstIndex++] = chunk & 0xFF;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return dst.slice(0, dstIndex);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 创建单例实例
|
|
96
|
-
const encoder = new CustomBase64();
|
|
97
|
-
|
|
98
|
-
// 返回string的编码函数
|
|
99
|
-
export function base64Encode(src: Uint8Array): string {
|
|
100
|
-
return encoder.encode(src);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function base64Decode(src: Uint8Array): Uint8Array {
|
|
104
|
-
return encoder.decode(src);
|
|
105
|
-
}
|
package/lib/util/bcrypt.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bcrypt password hashing implementation for browsers
|
|
3
|
-
* Compatible with Go's bcrypt implementation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// 导入Blowfish实现
|
|
7
|
-
import { expandKey} from '../common/blowfish/block';
|
|
8
|
-
import {Cipher,newSaltedCipher,BlockSize} from '../common/blowfish/cipher';
|
|
9
|
-
|
|
10
|
-
// 常量定义
|
|
11
|
-
export const MinCost = 4;
|
|
12
|
-
export const MaxCost = 31;
|
|
13
|
-
export const DefaultCost = 10;
|
|
14
|
-
|
|
15
|
-
const majorVersion = '2';
|
|
16
|
-
const minorVersion = 'a';
|
|
17
|
-
const maxCryptedHashSize = 23;
|
|
18
|
-
|
|
19
|
-
// Magic cipher data - 与Go实现保持一致
|
|
20
|
-
const magicCipherData = new Uint8Array([
|
|
21
|
-
0x4f, 0x72, 0x70, 0x68,
|
|
22
|
-
0x65, 0x61, 0x6e, 0x42,
|
|
23
|
-
0x65, 0x68, 0x6f, 0x6c,
|
|
24
|
-
0x64, 0x65, 0x72, 0x53,
|
|
25
|
-
0x63, 0x72, 0x79, 0x44,
|
|
26
|
-
0x6f, 0x75, 0x62, 0x74,
|
|
27
|
-
]);
|
|
28
|
-
|
|
29
|
-
// bcrypt使用的特殊base64字母表
|
|
30
|
-
const bcryptAlphabet = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
31
|
-
|
|
32
|
-
// 类型定义
|
|
33
|
-
interface Hashed {
|
|
34
|
-
hash: Uint8Array;
|
|
35
|
-
salt: Uint8Array;
|
|
36
|
-
cost: number;
|
|
37
|
-
major: string;
|
|
38
|
-
minor: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 错误类
|
|
42
|
-
export class InvalidCostError extends Error {
|
|
43
|
-
constructor(cost: number) {
|
|
44
|
-
super(`crypto/bcrypt: cost ${cost} is outside allowed range (${MinCost},${MaxCost})`);
|
|
45
|
-
this.name = 'InvalidCostError';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 自定义base64编码函数,匹配bcrypt的编码方式
|
|
51
|
-
*/
|
|
52
|
-
function base64Encode(data: Uint8Array): Uint8Array {
|
|
53
|
-
let output = '';
|
|
54
|
-
let i = 0;
|
|
55
|
-
|
|
56
|
-
while (i < data.length) {
|
|
57
|
-
let a = i < data.length ? data[i++] : 0;
|
|
58
|
-
let b = i < data.length ? data[i++] : 0;
|
|
59
|
-
let c = i < data.length ? data[i++] : 0;
|
|
60
|
-
|
|
61
|
-
const triple = (a << 16) + (b << 8) + c;
|
|
62
|
-
|
|
63
|
-
output += bcryptAlphabet[(triple >> 18) & 0x3F];
|
|
64
|
-
output += bcryptAlphabet[(triple >> 12) & 0x3F];
|
|
65
|
-
output += bcryptAlphabet[(triple >> 6) & 0x3F];
|
|
66
|
-
output += bcryptAlphabet[triple & 0x3F];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 处理填充
|
|
70
|
-
const mod = data.length % 3;
|
|
71
|
-
if (mod === 1) {
|
|
72
|
-
output = output.slice(0, -2);
|
|
73
|
-
} else if (mod === 2) {
|
|
74
|
-
output = output.slice(0, -1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return new TextEncoder().encode(output);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 自定义base64解码函数,匹配bcrypt的解码方式
|
|
82
|
-
*/
|
|
83
|
-
function base64Decode(data: Uint8Array): Uint8Array {
|
|
84
|
-
const input = new TextDecoder().decode(data);
|
|
85
|
-
const output = new Uint8Array(Math.floor(input.length * 3 / 4));
|
|
86
|
-
let outputIndex = 0;
|
|
87
|
-
|
|
88
|
-
const getBcryptValue = (char: string) => {
|
|
89
|
-
const index = bcryptAlphabet.indexOf(char);
|
|
90
|
-
if (index === -1) {
|
|
91
|
-
throw new Error('Invalid character in input');
|
|
92
|
-
}
|
|
93
|
-
return index;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
for (let i = 0; i < input.length; i += 4) {
|
|
97
|
-
const a = getBcryptValue(input[i]);
|
|
98
|
-
const b = getBcryptValue(input[i + 1]);
|
|
99
|
-
const c = i + 2 < input.length ? getBcryptValue(input[i + 2]) : 0;
|
|
100
|
-
const d = i + 3 < input.length ? getBcryptValue(input[i + 3]) : 0;
|
|
101
|
-
|
|
102
|
-
const triple = (a << 18) | (b << 12) | (c << 6) | d;
|
|
103
|
-
|
|
104
|
-
output[outputIndex++] = (triple >> 16) & 0xFF;
|
|
105
|
-
if (i + 2 < input.length) output[outputIndex++] = (triple >> 8) & 0xFF;
|
|
106
|
-
if (i + 3 < input.length) output[outputIndex++] = triple & 0xFF;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return output.slice(0, outputIndex);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 检查cost值是否在允许范围内
|
|
114
|
-
*/
|
|
115
|
-
function checkCost(cost: number): void {
|
|
116
|
-
if (cost < MinCost || cost > MaxCost) {
|
|
117
|
-
throw new InvalidCostError(cost);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Blowfish加密设置
|
|
123
|
-
*/
|
|
124
|
-
async function expensiveBlowfishSetup(
|
|
125
|
-
key: Uint8Array,
|
|
126
|
-
cost: number,
|
|
127
|
-
salt: Uint8Array
|
|
128
|
-
): Promise<Cipher> {
|
|
129
|
-
const csalt = base64Decode(salt);
|
|
130
|
-
const ckey = new Uint8Array([...key, 0]);
|
|
131
|
-
|
|
132
|
-
const cipher = newSaltedCipher(ckey, csalt);
|
|
133
|
-
const rounds = 1 << cost;
|
|
134
|
-
for (let i = 0; i < rounds; i++) {
|
|
135
|
-
expandKey(ckey,cipher);
|
|
136
|
-
expandKey(csalt,cipher);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return cipher;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* bcrypt核心加密函数
|
|
144
|
-
*/
|
|
145
|
-
async function bcrypt(
|
|
146
|
-
password: Uint8Array,
|
|
147
|
-
cost: number,
|
|
148
|
-
salt: Uint8Array
|
|
149
|
-
): Promise<Uint8Array> {
|
|
150
|
-
const cipherData = new Uint8Array(magicCipherData);
|
|
151
|
-
|
|
152
|
-
const cipher = await expensiveBlowfishSetup(password, cost, salt);
|
|
153
|
-
|
|
154
|
-
for (let i = 0; i < 24; i += 8) {
|
|
155
|
-
for (let j = 0; j < 64; j++) {
|
|
156
|
-
const block = cipherData.slice(i, i + 8);
|
|
157
|
-
const destBlock = new Uint8Array(BlockSize);
|
|
158
|
-
cipher.encrypt(destBlock,block);
|
|
159
|
-
cipherData.set(destBlock, i);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return base64Encode(cipherData.slice(0, maxCryptedHashSize));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// 修改 generateFromPasswordWithSalt 函数返回完整的哈希信息
|
|
166
|
-
export async function generateFromPasswordWithSalt(
|
|
167
|
-
password: Uint8Array,
|
|
168
|
-
cost: number,
|
|
169
|
-
unencodedSalt: Uint8Array
|
|
170
|
-
): Promise<Hashed> {
|
|
171
|
-
if (unencodedSalt.length !== 16) {
|
|
172
|
-
throw new Error('Salt must be exactly 16 bytes');
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (cost < MinCost) {
|
|
176
|
-
cost = DefaultCost;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
checkCost(cost);
|
|
180
|
-
|
|
181
|
-
const salt = base64Encode(unencodedSalt);
|
|
182
|
-
const hash = await bcrypt(password, cost, salt);
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
hash,
|
|
186
|
-
salt: unencodedSalt,
|
|
187
|
-
cost,
|
|
188
|
-
major: majorVersion,
|
|
189
|
-
minor: minorVersion
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// 辅助函数:将字符串转换为Uint8Array
|
|
194
|
-
export function stringToBytes(str: string): Uint8Array {
|
|
195
|
-
return new TextEncoder().encode(str);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 辅助函数:将Uint8Array转换为字符串
|
|
199
|
-
export function bytesToString(bytes: Uint8Array): string {
|
|
200
|
-
return new TextDecoder().decode(bytes);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// 生成随机salt的辅助函数
|
|
204
|
-
export function generateSalt(): Uint8Array {
|
|
205
|
-
return crypto.getRandomValues(new Uint8Array(16));
|
|
206
|
-
}
|