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
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
2
|
-
import type { Client } from "../../common/dcapi";
|
|
3
|
-
import { Libp2pGrpcClient } from "grpc-libp2p-client";
|
|
4
|
-
import { dcnet } from "../../proto/dcnet_proto";
|
|
5
|
-
import { base58btc } from "multiformats/bases/base58";
|
|
6
|
-
import { toString as uint8ArrayToString } from "uint8arrays/to-string";
|
|
7
|
-
import { Errors } from "../../common/error";
|
|
8
|
-
import { DCContext } from "../../../lib/interfaces/DCContext";
|
|
9
|
-
import { Direction } from "../../common/define";
|
|
10
|
-
|
|
11
|
-
export class KeyValueClient {
|
|
12
|
-
client: Client;
|
|
13
|
-
context: DCContext;
|
|
14
|
-
|
|
15
|
-
constructor(dcClient: Client, context: DCContext) {
|
|
16
|
-
this.client = dcClient;
|
|
17
|
-
this.context = context;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async configThemeObjAuth(
|
|
21
|
-
theme: string,
|
|
22
|
-
appId: string,
|
|
23
|
-
themeAuthor: string,
|
|
24
|
-
blockHeight: number,
|
|
25
|
-
userPubkeyStr: string,
|
|
26
|
-
contentCid: string,
|
|
27
|
-
content: string,
|
|
28
|
-
contentSize: number,
|
|
29
|
-
type: number,
|
|
30
|
-
signature: Uint8Array,
|
|
31
|
-
vAccount?: string
|
|
32
|
-
): Promise<number> {
|
|
33
|
-
const message = new dcnet.pb.ConfigThemeObjAuthRequest({});
|
|
34
|
-
message.appId = new TextEncoder().encode(appId);
|
|
35
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
36
|
-
message.theme = new TextEncoder().encode(theme);
|
|
37
|
-
message.blockheight = blockHeight;
|
|
38
|
-
message.content = new TextEncoder().encode(content);
|
|
39
|
-
message.contentCid = new TextEncoder().encode(contentCid)
|
|
40
|
-
message.contentSize = contentSize
|
|
41
|
-
message.signature = signature;
|
|
42
|
-
message.type = type;
|
|
43
|
-
message.userPubkey = new TextEncoder().encode(userPubkeyStr);
|
|
44
|
-
if(vAccount){
|
|
45
|
-
message.vaccount = new TextEncoder().encode(vAccount)
|
|
46
|
-
}
|
|
47
|
-
const messageBytes = dcnet.pb.ConfigThemeObjAuthRequest.encode(message).finish();
|
|
48
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
49
|
-
this.client.p2pNode,
|
|
50
|
-
this.client.peerAddr,
|
|
51
|
-
this.client.token,
|
|
52
|
-
this.client.protocol
|
|
53
|
-
);
|
|
54
|
-
try {
|
|
55
|
-
const reply = await grpcClient.unaryCall(
|
|
56
|
-
"/dcnet.pb.Service/ConfigThemeObjAuth",
|
|
57
|
-
messageBytes,
|
|
58
|
-
30000
|
|
59
|
-
);
|
|
60
|
-
console.log("ConfigThemeObjAuth reply", reply);
|
|
61
|
-
const decoded = dcnet.pb.ConfigThemeObjAuthReply.decode(reply);
|
|
62
|
-
console.log("ConfigThemeObjAuth decoded", decoded);
|
|
63
|
-
return decoded.flag;
|
|
64
|
-
} catch (error: any) {
|
|
65
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
66
|
-
// try to get token
|
|
67
|
-
const token = await this.client.GetToken(
|
|
68
|
-
appId,
|
|
69
|
-
this.context.getPublicKey().string(),
|
|
70
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
71
|
-
return this.context.sign(payload);
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
if (!token) {
|
|
75
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
76
|
-
}
|
|
77
|
-
const reply = await grpcClient.unaryCall(
|
|
78
|
-
"/dcnet.pb.Service/ConfigThemeObjAuth",
|
|
79
|
-
messageBytes,
|
|
80
|
-
30000
|
|
81
|
-
);
|
|
82
|
-
console.log("ConfigThemeObjAuth reply", reply);
|
|
83
|
-
const decoded = dcnet.pb.GetUserCommentsReply.decode(reply);
|
|
84
|
-
console.log("ConfigThemeObjAuth decoded", decoded);
|
|
85
|
-
return decoded.flag;
|
|
86
|
-
}
|
|
87
|
-
console.error("ConfigThemeObjAuth error:", error);
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async setKeyValue(
|
|
93
|
-
theme: string,
|
|
94
|
-
appId: string,
|
|
95
|
-
themeAuthor: string,
|
|
96
|
-
blockHeight: number,
|
|
97
|
-
userPubkeyStr: string,
|
|
98
|
-
contentCid: string,
|
|
99
|
-
content: string,
|
|
100
|
-
contentSize: number,
|
|
101
|
-
type: number,
|
|
102
|
-
signature: Uint8Array,
|
|
103
|
-
vaccount?: string,
|
|
104
|
-
): Promise<[number,number]> {
|
|
105
|
-
const message = new dcnet.pb.SetKeyValueRequest({});
|
|
106
|
-
message.appId = new TextEncoder().encode(appId);
|
|
107
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
108
|
-
message.theme = new TextEncoder().encode(theme);
|
|
109
|
-
message.blockheight = blockHeight;
|
|
110
|
-
message.content = new TextEncoder().encode(content);
|
|
111
|
-
message.contentCid = new TextEncoder().encode(contentCid)
|
|
112
|
-
message.contentSize = contentSize
|
|
113
|
-
message.signature = signature;
|
|
114
|
-
message.type = type;
|
|
115
|
-
message.userPubkey = new TextEncoder().encode(userPubkeyStr);
|
|
116
|
-
if(vaccount){
|
|
117
|
-
message.vaccount = new TextEncoder().encode(vaccount)
|
|
118
|
-
}
|
|
119
|
-
const messageBytes = dcnet.pb.SetKeyValueRequest.encode(message).finish();
|
|
120
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
121
|
-
this.client.p2pNode,
|
|
122
|
-
this.client.peerAddr,
|
|
123
|
-
this.client.token,
|
|
124
|
-
this.client.protocol
|
|
125
|
-
);
|
|
126
|
-
try {
|
|
127
|
-
const reply = await grpcClient.unaryCall(
|
|
128
|
-
"/dcnet.pb.Service/SetKeyValue",
|
|
129
|
-
messageBytes,
|
|
130
|
-
30000
|
|
131
|
-
);
|
|
132
|
-
console.log("SetKeyValue reply", reply);
|
|
133
|
-
const decoded = dcnet.pb.SetKeyValueReply.decode(reply);
|
|
134
|
-
console.log("SetKeyValue decoded", decoded);
|
|
135
|
-
return [decoded.flag, decoded.timestamp as number];
|
|
136
|
-
} catch (error: any) {
|
|
137
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
138
|
-
// try to get token
|
|
139
|
-
const token = await this.client.GetToken(
|
|
140
|
-
appId,
|
|
141
|
-
this.context.getPublicKey().string(),
|
|
142
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
143
|
-
return this.context.sign(payload);
|
|
144
|
-
}
|
|
145
|
-
);
|
|
146
|
-
if (!token) {
|
|
147
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
148
|
-
}
|
|
149
|
-
const reply = await grpcClient.unaryCall(
|
|
150
|
-
"/dcnet.pb.Service/SetKeyValue",
|
|
151
|
-
messageBytes,
|
|
152
|
-
30000
|
|
153
|
-
);
|
|
154
|
-
console.log("SetKeyValue reply", reply);
|
|
155
|
-
const decoded = dcnet.pb.SetKeyValueReply.decode(reply);
|
|
156
|
-
console.log("SetKeyValue decoded", decoded);
|
|
157
|
-
return [decoded.flag, decoded.timestamp as number];
|
|
158
|
-
}
|
|
159
|
-
console.error("SetKeyValue error:", error);
|
|
160
|
-
throw error;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async getValueWithKey(
|
|
165
|
-
theme: string,
|
|
166
|
-
appId: string,
|
|
167
|
-
themeAuthor: string,
|
|
168
|
-
userPubkey: string,
|
|
169
|
-
key: string,
|
|
170
|
-
vaccount?: string,
|
|
171
|
-
): Promise<Uint8Array|null> {
|
|
172
|
-
const message = new dcnet.pb.GetValueWithKeyRequest({});
|
|
173
|
-
message.appId = new TextEncoder().encode(appId);
|
|
174
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
175
|
-
message.theme = new TextEncoder().encode(theme);
|
|
176
|
-
message.UserPubkey = new TextEncoder().encode(userPubkey)
|
|
177
|
-
message.Key = new TextEncoder().encode(key);
|
|
178
|
-
if(vaccount){
|
|
179
|
-
message.vaccount = new TextEncoder().encode(vaccount)
|
|
180
|
-
}
|
|
181
|
-
const messageBytes = dcnet.pb.GetValueWithKeyRequest.encode(message).finish();
|
|
182
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
183
|
-
this.client.p2pNode,
|
|
184
|
-
this.client.peerAddr,
|
|
185
|
-
this.client.token,
|
|
186
|
-
this.client.protocol
|
|
187
|
-
);
|
|
188
|
-
try {
|
|
189
|
-
const reply = await grpcClient.unaryCall(
|
|
190
|
-
"/dcnet.pb.Service/GetValueWithKey",
|
|
191
|
-
messageBytes,
|
|
192
|
-
30000
|
|
193
|
-
);
|
|
194
|
-
console.log("GetValueWithKey reply", reply);
|
|
195
|
-
const decoded = dcnet.pb.GetValueWithKeyReply.decode(reply);
|
|
196
|
-
console.log("GetValueWithKey decoded", decoded);
|
|
197
|
-
if(decoded.flag == 0) {
|
|
198
|
-
return decoded.value;
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
} catch (error: any) {
|
|
202
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
203
|
-
// try to get token
|
|
204
|
-
const token = await this.client.GetToken(
|
|
205
|
-
appId,
|
|
206
|
-
this.context.getPublicKey().string(),
|
|
207
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
208
|
-
return this.context.sign(payload);
|
|
209
|
-
}
|
|
210
|
-
);
|
|
211
|
-
if (!token) {
|
|
212
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
213
|
-
}
|
|
214
|
-
const reply = await grpcClient.unaryCall(
|
|
215
|
-
"/dcnet.pb.Service/GetValueWithKey",
|
|
216
|
-
messageBytes,
|
|
217
|
-
30000
|
|
218
|
-
);
|
|
219
|
-
console.log("GetValueWithKey reply", reply);
|
|
220
|
-
const decoded = dcnet.pb.GetValueWithKeyReply.decode(reply);
|
|
221
|
-
console.log("GetValueWithKey decoded", decoded);
|
|
222
|
-
if(decoded.flag == 0) {
|
|
223
|
-
return decoded.value;
|
|
224
|
-
}
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
console.error("GetValueWithKey error:", error);
|
|
228
|
-
throw error;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async getValuesWithKeys(
|
|
233
|
-
theme: string,
|
|
234
|
-
appId: string,
|
|
235
|
-
themeAuthor: string,
|
|
236
|
-
userPubkey: string,
|
|
237
|
-
keys: string,
|
|
238
|
-
vaccount?: string,
|
|
239
|
-
): Promise<Uint8Array|null> {
|
|
240
|
-
const message = new dcnet.pb.GetValuesWithKeysRequest({});
|
|
241
|
-
message.appId = new TextEncoder().encode(appId);
|
|
242
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
243
|
-
message.theme = new TextEncoder().encode(theme);
|
|
244
|
-
message.UserPubkey = new TextEncoder().encode(userPubkey);
|
|
245
|
-
message.Keys = new TextEncoder().encode(keys);
|
|
246
|
-
if(vaccount){
|
|
247
|
-
message.vaccount = new TextEncoder().encode(vaccount)
|
|
248
|
-
}
|
|
249
|
-
const messageBytes = dcnet.pb.GetValuesWithKeysRequest.encode(message).finish();
|
|
250
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
251
|
-
this.client.p2pNode,
|
|
252
|
-
this.client.peerAddr,
|
|
253
|
-
this.client.token,
|
|
254
|
-
this.client.protocol
|
|
255
|
-
);
|
|
256
|
-
try {
|
|
257
|
-
const reply = await grpcClient.unaryCall(
|
|
258
|
-
"/dcnet.pb.Service/GetValuesWithKeys",
|
|
259
|
-
messageBytes,
|
|
260
|
-
30000
|
|
261
|
-
);
|
|
262
|
-
console.log("GetValuesWithKeys reply", reply);
|
|
263
|
-
const decoded = dcnet.pb.GetValuesWithKeysReply.decode(reply);
|
|
264
|
-
console.log("GetValuesWithKeys decoded", decoded);
|
|
265
|
-
if(decoded.flag == 0) {
|
|
266
|
-
return decoded.keyValues;
|
|
267
|
-
}
|
|
268
|
-
return null;
|
|
269
|
-
} catch (error: any) {
|
|
270
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
271
|
-
// try to get token
|
|
272
|
-
const token = await this.client.GetToken(
|
|
273
|
-
appId,
|
|
274
|
-
this.context.getPublicKey().string(),
|
|
275
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
276
|
-
return this.context.sign(payload);
|
|
277
|
-
}
|
|
278
|
-
);
|
|
279
|
-
if (!token) {
|
|
280
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
281
|
-
}
|
|
282
|
-
const reply = await grpcClient.unaryCall(
|
|
283
|
-
"/dcnet.pb.Service/GetValuesWithKeys",
|
|
284
|
-
messageBytes,
|
|
285
|
-
30000
|
|
286
|
-
);
|
|
287
|
-
console.log("GetValuesWithKeys reply", reply);
|
|
288
|
-
const decoded = dcnet.pb.GetValuesWithKeysReply.decode(reply);
|
|
289
|
-
console.log("GetValuesWithKeys decoded", decoded);
|
|
290
|
-
if(decoded.flag == 0) {
|
|
291
|
-
return decoded.keyValues;
|
|
292
|
-
}
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
console.error("GetValuesWithKeys error:", error);
|
|
296
|
-
throw error;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async getValuesWithIndex(
|
|
301
|
-
appId: string,
|
|
302
|
-
themeAuthor: string,
|
|
303
|
-
theme: string,
|
|
304
|
-
indexKey:string,
|
|
305
|
-
indexValue:string,
|
|
306
|
-
seekKey:string,
|
|
307
|
-
direction: Direction = Direction.Forward,
|
|
308
|
-
offset: number,
|
|
309
|
-
limit: number,
|
|
310
|
-
vaccount?: string
|
|
311
|
-
): Promise<Uint8Array|null> {
|
|
312
|
-
const message = new dcnet.pb.GetValuesWithIndexRequest({});
|
|
313
|
-
message.appId = new TextEncoder().encode(appId);
|
|
314
|
-
message.themeAuthor = new TextEncoder().encode(themeAuthor);
|
|
315
|
-
message.theme = new TextEncoder().encode(theme);
|
|
316
|
-
message.indexKey = new TextEncoder().encode(indexKey);
|
|
317
|
-
message.indexValue = new TextEncoder().encode(indexValue);
|
|
318
|
-
message.seekKey = new TextEncoder().encode(seekKey);
|
|
319
|
-
message.direction = direction;
|
|
320
|
-
message.offset = offset;
|
|
321
|
-
message.limit = limit;
|
|
322
|
-
if(vaccount){
|
|
323
|
-
message.vaccount = new TextEncoder().encode(vaccount)
|
|
324
|
-
}
|
|
325
|
-
const messageBytes = dcnet.pb.GetValuesWithIndexRequest.encode(message).finish();
|
|
326
|
-
const grpcClient = new Libp2pGrpcClient(
|
|
327
|
-
this.client.p2pNode,
|
|
328
|
-
this.client.peerAddr,
|
|
329
|
-
this.client.token,
|
|
330
|
-
this.client.protocol
|
|
331
|
-
);
|
|
332
|
-
try {
|
|
333
|
-
const reply = await grpcClient.unaryCall(
|
|
334
|
-
"/dcnet.pb.Service/GetValuesWithIndex",
|
|
335
|
-
messageBytes,
|
|
336
|
-
30000
|
|
337
|
-
);
|
|
338
|
-
console.log("getValuesWithIndex reply", reply);
|
|
339
|
-
const decoded = dcnet.pb.GetValuesWithIndexReply.decode(reply);
|
|
340
|
-
console.log("getValuesWithIndex decoded", decoded);
|
|
341
|
-
if(decoded.flag == 0) {
|
|
342
|
-
return decoded.keyValues;
|
|
343
|
-
}
|
|
344
|
-
return null;
|
|
345
|
-
} catch (error:any) {
|
|
346
|
-
if (error.message.indexOf(Errors.INVALID_TOKEN.message) != -1) {
|
|
347
|
-
// try to get token
|
|
348
|
-
const token = await this.client.GetToken(
|
|
349
|
-
appId,
|
|
350
|
-
this.context.getPublicKey().string(),
|
|
351
|
-
(payload: Uint8Array): Promise<Uint8Array> => {
|
|
352
|
-
return this.context.sign(payload);
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
if (!token) {
|
|
356
|
-
throw new Error(Errors.INVALID_TOKEN.message);
|
|
357
|
-
}
|
|
358
|
-
const reply = await grpcClient.unaryCall(
|
|
359
|
-
"/dcnet.pb.Service/GetValuesWithIndex",
|
|
360
|
-
messageBytes,
|
|
361
|
-
30000
|
|
362
|
-
);
|
|
363
|
-
console.log("GetValuesWithIndex reply", reply);
|
|
364
|
-
const decoded = dcnet.pb.GetValuesWithIndexReply.decode(reply);
|
|
365
|
-
console.log("GetValuesWithIndex decoded", decoded);
|
|
366
|
-
if(decoded.flag == 0) {
|
|
367
|
-
return decoded.keyValues;
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
console.error("GetValuesWithIndex error:", error);
|
|
372
|
-
throw error;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
}
|