web-dc-api 0.0.56 → 0.0.57

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.
@@ -164,17 +164,14 @@ export class KeyValueDB {
164
164
 
165
165
  export class KeyValueManager {
166
166
  private dc: DcUtil;
167
- private connectedDc: DCConnectInfo = {};
168
167
  private chainUtil: ChainUtil;
169
168
  private context: DCContext;
170
169
  constructor(
171
170
  dc: DcUtil,
172
- connectedDc: DCConnectInfo,
173
171
  chainUtil: ChainUtil,
174
172
  context: DCContext
175
173
  ) {
176
174
  this.dc = dc;
177
- this.connectedDc = connectedDc;
178
175
  this.chainUtil = chainUtil;
179
176
  this.context = context;
180
177
  }
@@ -290,7 +287,7 @@ export class KeyValueManager {
290
287
  const userPubkey = this.context.getPublicKey();
291
288
  let userPubkeyStr = userPubkey.string();
292
289
 
293
- let client = this.connectedDc?.client || null;
290
+ let client = this.context.AccountBackupDc?.client || null;
294
291
  if (!client){
295
292
  client = await this.dc.connectToUserDcPeer(this.context.publicKey.raw);
296
293
  }
@@ -474,7 +471,7 @@ export class KeyValueManager {
474
471
  }
475
472
  const userPubkey = this.context.getPublicKey();
476
473
  let userPubkeyStr = userPubkey.string();
477
- let client = this.connectedDc?.client || null;
474
+ let client = this.context.AccountBackupDc?.client || null;
478
475
  if (!client){
479
476
  client = await this.dc.connectToUserDcPeer(this.context.publicKey.raw);
480
477
  }
@@ -561,7 +558,7 @@ export class KeyValueManager {
561
558
  if (!theme.startsWith("keyvalue_")) {
562
559
  theme = "keyvalue_" + theme;
563
560
  }
564
- let client = this.connectedDc.client || null;
561
+ let client = this.context.AccountBackupDc.client || null;
565
562
  if (themeAuthor != this.context.publicKey.string()) {
566
563
  //查询他人主题评论
567
564
  const authorPublicKey: Ed25519PubKey =
@@ -620,7 +617,7 @@ export class KeyValueManager {
620
617
  if (!theme.startsWith("keyvalue_")) {
621
618
  theme = "keyvalue_" + theme;
622
619
  }
623
- let client = this.connectedDc.client || null;
620
+ let client = this.context.AccountBackupDc.client || null;
624
621
  if (themeAuthor != this.context.publicKey.string()) {
625
622
  //查询他人主题评论
626
623
  const authorPublicKey: Ed25519PubKey =
@@ -683,7 +680,7 @@ export class KeyValueManager {
683
680
  if (!theme.startsWith("keyvalue_")) {
684
681
  theme = "keyvalue_" + theme;
685
682
  }
686
- let client = this.connectedDc.client || null;
683
+ let client = this.context.AccountBackupDc.client || null;
687
684
  if (themeAuthor != this.context.publicKey.string()) {
688
685
  //查询他人主题评论
689
686
  const authorPublicKey: Ed25519PubKey =
@@ -25,17 +25,14 @@ export const Errors = {
25
25
  };
26
26
 
27
27
  export class MessageManager {
28
- private accountBackupDc: DCConnectInfo = {};
29
28
  private context: DCContext;
30
29
  private chainUtil: ChainUtil;
31
30
  private dc: DcUtil;
32
31
  constructor(
33
- accountBackupDc: DCConnectInfo,
34
32
  dc: DcUtil,
35
33
  chainUtil: ChainUtil,
36
34
  context: DCContext
37
35
  ) {
38
- this.accountBackupDc = accountBackupDc;
39
36
  this.dc = dc;
40
37
  this.chainUtil = chainUtil;
41
38
  this.context = context;
@@ -47,7 +44,7 @@ export class MessageManager {
47
44
  msg: string
48
45
  ): Promise<[number | null, Error | null]> => {
49
46
  try {
50
- if (!this.accountBackupDc.client) {
47
+ if (!this.context.AccountBackupDc.client) {
51
48
  return [null, Errors.ErrNoAccountPeerConnected];
52
49
  }
53
50
  const receiverPubkey: Ed25519PubKey = Ed25519PubKey.edPubkeyFromStr(receiver)
@@ -75,7 +72,7 @@ export class MessageManager {
75
72
  receiverClient.token = token;
76
73
 
77
74
  const messageClient = new MessageClient(
78
- this.accountBackupDc.client,
75
+ this.context.AccountBackupDc.client,
79
76
  this.context,
80
77
  receiverClient,
81
78
  );
@@ -93,7 +90,7 @@ export class MessageManager {
93
90
  limit: number = 100
94
91
  ): Promise<[dcnet.pb.IUserMsg[] | null, Error | null]> => {
95
92
  try {
96
- if (!this.accountBackupDc.client) {
93
+ if (!this.context.AccountBackupDc.client) {
97
94
  return [null, Errors.ErrNoAccountPeerConnected];
98
95
  }
99
96
  const publicKey = await this.context.getPublicKey();
@@ -139,7 +136,7 @@ export class MessageManager {
139
136
  maxKey,
140
137
  limit
141
138
  );
142
- const list = res && res.msgs ? res.msgs : [];
139
+ const list = res && res["msgs"]? res["msgs"] : [];
143
140
  console.log('messageClient.getMsgFromUserBox list', list)
144
141
  list.map((item: dcnet.pb.IUserMsg) => {
145
142
  if(item && item.messageId) {
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { Ed25519PrivKey, Ed25519PubKey } from "../common/dc-key/ed25519";
3
- import type { DCConnectInfo, APPInfo, AccountInfo } from "../common/types/types";
3
+ import type { DCConnectInfo, APPInfo, AccountInfo, Account } from "../common/types/types";
4
4
  import type { HeliaLibp2p } from "helia";
5
5
  import { Libp2p } from "@libp2p/interface";
6
6
  import { ChainUtil } from "../common/chain";
@@ -30,6 +30,8 @@ export interface DCContext {
30
30
 
31
31
  // 当前登录的账户信息
32
32
  accountInfo: AccountInfo;
33
+ // 当前登录的用户信息
34
+ userInfo: Account | null;
33
35
 
34
36
  // 数据库管理器
35
37
  dbManager?: DBManager;
@@ -33,7 +33,6 @@ export class AIProxyModule implements DCModule ,IAIProxyOperations{
33
33
  try {
34
34
  this.aiProxyManager = new AIProxyManager(
35
35
  context.dcutil,
36
- context.AccountBackupDc,
37
36
  context.dcNodeClient as any, // Type assertion to bypass service map differences
38
37
  context.dcChain,
39
38
  context
@@ -169,6 +169,7 @@ export class AuthModule implements DCModule, IAuthOperations {
169
169
  > {
170
170
  try {
171
171
  const account = await this.accountLoginWithWalletCall(accountInfo);
172
+ this.context.userInfo = account;
172
173
  return [account, null];
173
174
  } catch (error) {
174
175
  return [null, error as Error];
@@ -239,6 +240,13 @@ export class AuthModule implements DCModule, IAuthOperations {
239
240
  const privKey = Ed25519PrivKey.unmarshalString(res[0]);
240
241
  console.log("=================获取私钥 success");
241
242
  }
243
+ this.context.userInfo = {
244
+ nftAccount, // NFT账号
245
+ appAccount:userPubkey.raw, // 应用专用账号公钥
246
+ ethAccount:'', // 以太坊兼容链上账号
247
+ chainId:'', // 区块链ID
248
+ chainName:'', // 区块链名称
249
+ }
242
250
  return [mnemonic, null];
243
251
  }
244
252
  return ["", new Error("accountLogin failed")];
@@ -4,7 +4,7 @@
4
4
  import { ICacheOperations } from "../interfaces/cache-interface";
5
5
  import { DCContext } from "../../lib/interfaces/DCContext";
6
6
  import { DCModule, CoreModuleName } from "../common/module-system";
7
- import { ThemeManager } from "../implements/cache/manager";
7
+ import { CacheManager } from "../implements/cache/manager";
8
8
  import { keyExpire } from "../common/define";
9
9
  import { createLogger } from "../util/logger";
10
10
 
@@ -16,7 +16,7 @@ const logger = createLogger('CacheModule');
16
16
  */
17
17
  export class CacheModule implements DCModule, ICacheOperations {
18
18
  readonly moduleName = CoreModuleName.CACHE;
19
- private themeManager!: ThemeManager;
19
+ private cacheManager!: CacheManager;
20
20
  private initialized: boolean = false;
21
21
 
22
22
  /**
@@ -26,8 +26,7 @@ export class CacheModule implements DCModule, ICacheOperations {
26
26
  */
27
27
  async initialize(context: DCContext): Promise<boolean> {
28
28
  try {
29
- this.themeManager = new ThemeManager(
30
- context.connectedDc,
29
+ this.cacheManager = new CacheManager(
31
30
  context.dcutil,
32
31
  context.dcChain,
33
32
  context
@@ -55,7 +54,7 @@ export class CacheModule implements DCModule, ICacheOperations {
55
54
  async getCacheValue(key: string): Promise<[string | null, Error | null]>{
56
55
  try {
57
56
  this.assertInitialized();
58
- const res = await this.themeManager.getCacheValue(key);
57
+ const res = await this.cacheManager.getCacheValue(key);
59
58
  if (res[0]) {
60
59
  logger.info(`获取缓存键 ${key} 成功`);
61
60
  return [res[0], null];
@@ -79,7 +78,7 @@ export class CacheModule implements DCModule, ICacheOperations {
79
78
  try {
80
79
  this.assertInitialized();
81
80
  const expireNumber = expire ? expire : keyExpire; // 默认一天
82
- const res = await this.themeManager.setCacheKey(value, expireNumber);
81
+ const res = await this.cacheManager.setCacheKey(value, expireNumber);
83
82
 
84
83
  logger.info(`设置缓存值成功,过期时间: ${expireNumber}秒`);
85
84
  return res;
@@ -8,6 +8,7 @@ import { KeyValueManager, KeyValueStoreType, KeyValueDB } from "../implements/ke
8
8
  import { createLogger } from "../util/logger";
9
9
  import { ThemeAuthInfo, ThemeComment } from "../common/types/types";
10
10
  import { Direction } from "../common/define";
11
+ import { ThemePermission } from "../common/constants";
11
12
  const logger = createLogger('KeyValueModule');
12
13
  const indexkey_dckv = "indexkey_dckv"; //索引键名,keyvalue设置过程中key本身的索引键
13
14
  /**
@@ -28,7 +29,6 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
28
29
  try {
29
30
  this.keyValueManager = new KeyValueManager(
30
31
  context.dcutil,
31
- context.AccountBackupDc,
32
32
  context.dcChain,
33
33
  context
34
34
  );
@@ -110,7 +110,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
110
110
  async configAuth(
111
111
  kvdb: KeyValueDB,
112
112
  authPubkey: string,
113
- permission: number,
113
+ permission: ThemePermission,
114
114
  remark: string,
115
115
  vaccount?: string
116
116
  ): Promise<[number | null, Error | null]> {
@@ -234,7 +234,7 @@ export class KeyValueModule implements DCModule, IKeyValueOperations {
234
234
  }
235
235
 
236
236
  try {
237
- const res = await kvdb.getBatch(writerPubkey, keys, vaccount);
237
+ const res = await kvdb.getBatch(keys, writerPubkey, vaccount);
238
238
  return res;
239
239
  } catch (error) {
240
240
  logger.error(`getBatch失败:`, error);
@@ -29,7 +29,6 @@ export class MessageModule implements DCModule, IMessageOperations {
29
29
  try {
30
30
  this.context = context;
31
31
  this.messageManager = new MessageManager(
32
- context.AccountBackupDc,
33
32
  context.dcutil,
34
33
  context.dcChain,
35
34
  context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-dc-api",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "description": "web相关的dcapi",
5
5
  "type": "module",
6
6
  "browser": "dist/dc.min.js",