web-dc-api 0.1.5 → 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.
Files changed (148) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/dc.min.js +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/index.d.ts +934 -878
  5. package/package.json +4 -8
  6. package/dist/cjs/helia-core-B1Xqha7a.js +0 -1
  7. package/dist/cjs/helia-core-D8Uv1KjQ.js +0 -1
  8. package/dist/cjs/polkadot-api-7PhQf3ws.js +0 -1
  9. package/dist/cjs/polkadot-api-CtrJVWuZ.js +0 -1
  10. package/dist/esm/chunks/helia-core-BxMqyK2Y.js +0 -1
  11. package/dist/esm/chunks/helia-core-DMXRpcO-.js +0 -1
  12. package/dist/esm/chunks/polkadot-api-5Y9Bw8VT.js +0 -1
  13. package/dist/esm/chunks/polkadot-api-D69Ioun_.js +0 -1
  14. package/lib/common/blowfish/block.ts +0 -259
  15. package/lib/common/blowfish/cipher.ts +0 -144
  16. package/lib/common/blowfish/const.ts +0 -195
  17. package/lib/common/chain.ts +0 -469
  18. package/lib/common/commonclient.ts +0 -202
  19. package/lib/common/constants.ts +0 -55
  20. package/lib/common/dc-key/ed25519.ts +0 -343
  21. package/lib/common/dc-key/keyManager.ts +0 -424
  22. package/lib/common/dcapi.ts +0 -98
  23. package/lib/common/dcutil.ts +0 -627
  24. package/lib/common/define.ts +0 -70
  25. package/lib/common/error.ts +0 -67
  26. package/lib/common/grpc-dc.ts +0 -104
  27. package/lib/common/module-system.ts +0 -184
  28. package/lib/common/service-worker.ts +0 -234
  29. package/lib/common/types/types.ts +0 -344
  30. package/lib/dc.ts +0 -701
  31. package/lib/implements/account/client.ts +0 -185
  32. package/lib/implements/account/manager.ts +0 -683
  33. package/lib/implements/aiproxy/client.ts +0 -357
  34. package/lib/implements/aiproxy/manager.ts +0 -670
  35. package/lib/implements/cache/client.ts +0 -105
  36. package/lib/implements/cache/manager.ts +0 -127
  37. package/lib/implements/comment/client.ts +0 -982
  38. package/lib/implements/comment/manager.ts +0 -1151
  39. package/lib/implements/dc/client.ts +0 -51
  40. package/lib/implements/dc/manager.ts +0 -33
  41. package/lib/implements/file/client.ts +0 -253
  42. package/lib/implements/file/file-cache-manager.ts +0 -142
  43. package/lib/implements/file/manager.ts +0 -1240
  44. package/lib/implements/file/seekableFileStream.ts +0 -344
  45. package/lib/implements/file/streamwriter.ts +0 -322
  46. package/lib/implements/keyvalue/client.ts +0 -376
  47. package/lib/implements/keyvalue/manager.ts +0 -759
  48. package/lib/implements/message/client.ts +0 -250
  49. package/lib/implements/message/manager.ts +0 -215
  50. package/lib/implements/threaddb/cbor/coding.ts +0 -62
  51. package/lib/implements/threaddb/cbor/event.ts +0 -336
  52. package/lib/implements/threaddb/cbor/node.ts +0 -542
  53. package/lib/implements/threaddb/cbor/record.ts +0 -398
  54. package/lib/implements/threaddb/common/AsyncMutex.ts +0 -24
  55. package/lib/implements/threaddb/common/addrinfo.ts +0 -135
  56. package/lib/implements/threaddb/common/dispatcher.ts +0 -81
  57. package/lib/implements/threaddb/common/idbstore-adapter.ts +0 -260
  58. package/lib/implements/threaddb/common/json-patcher.ts +0 -204
  59. package/lib/implements/threaddb/common/key.ts +0 -290
  60. package/lib/implements/threaddb/common/level-adapter.ts +0 -235
  61. package/lib/implements/threaddb/common/lineReader.ts +0 -79
  62. package/lib/implements/threaddb/common/logstore.ts +0 -215
  63. package/lib/implements/threaddb/common/transformed-datastore.ts +0 -308
  64. package/lib/implements/threaddb/core/app.ts +0 -206
  65. package/lib/implements/threaddb/core/core.ts +0 -230
  66. package/lib/implements/threaddb/core/db.ts +0 -249
  67. package/lib/implements/threaddb/core/event.ts +0 -54
  68. package/lib/implements/threaddb/core/head.ts +0 -89
  69. package/lib/implements/threaddb/core/identity.ts +0 -171
  70. package/lib/implements/threaddb/core/logstore.ts +0 -137
  71. package/lib/implements/threaddb/core/options.ts +0 -14
  72. package/lib/implements/threaddb/core/record.ts +0 -54
  73. package/lib/implements/threaddb/db/collection.ts +0 -1910
  74. package/lib/implements/threaddb/db/db.ts +0 -698
  75. package/lib/implements/threaddb/db/json2Query.ts +0 -192
  76. package/lib/implements/threaddb/db/query.ts +0 -524
  77. package/lib/implements/threaddb/dbclient.ts +0 -543
  78. package/lib/implements/threaddb/dbmanager.ts +0 -1906
  79. package/lib/implements/threaddb/lsstoreds/addr_book.ts +0 -549
  80. package/lib/implements/threaddb/lsstoreds/cache.ts +0 -36
  81. package/lib/implements/threaddb/lsstoreds/cyclic_batch.ts +0 -87
  82. package/lib/implements/threaddb/lsstoreds/global.ts +0 -151
  83. package/lib/implements/threaddb/lsstoreds/headbook.ts +0 -373
  84. package/lib/implements/threaddb/lsstoreds/keybook.ts +0 -297
  85. package/lib/implements/threaddb/lsstoreds/logstore.ts +0 -29
  86. package/lib/implements/threaddb/lsstoreds/metadata.ts +0 -223
  87. package/lib/implements/threaddb/net/define.ts +0 -149
  88. package/lib/implements/threaddb/net/grpcClient.ts +0 -589
  89. package/lib/implements/threaddb/net/grpcserver.ts +0 -146
  90. package/lib/implements/threaddb/net/net.ts +0 -2047
  91. package/lib/implements/threaddb/pb/lstore.proto +0 -38
  92. package/lib/implements/threaddb/pb/lstore.ts +0 -393
  93. package/lib/implements/threaddb/pb/lstore_pb.d.ts +0 -433
  94. package/lib/implements/threaddb/pb/lstore_pb.js +0 -1085
  95. package/lib/implements/threaddb/pb/net.proto +0 -194
  96. package/lib/implements/threaddb/pb/net_pb.d.ts +0 -2349
  97. package/lib/implements/threaddb/pb/net_pb.js +0 -5525
  98. package/lib/implements/threaddb/pb/proto-custom-types.ts +0 -212
  99. package/lib/implements/util/client.ts +0 -72
  100. package/lib/implements/util/manager.ts +0 -146
  101. package/lib/implements/wallet/manager.ts +0 -671
  102. package/lib/index.ts +0 -57
  103. package/lib/interfaces/DCContext.ts +0 -51
  104. package/lib/interfaces/aiproxy-interface.ts +0 -145
  105. package/lib/interfaces/auth-interface.ts +0 -118
  106. package/lib/interfaces/cache-interface.ts +0 -22
  107. package/lib/interfaces/client-interface.ts +0 -11
  108. package/lib/interfaces/comment-interface.ts +0 -167
  109. package/lib/interfaces/components/news-component.ts +0 -0
  110. package/lib/interfaces/database-interface.ts +0 -169
  111. package/lib/interfaces/file-interface.ts +0 -120
  112. package/lib/interfaces/index.ts +0 -10
  113. package/lib/interfaces/keyvalue-interface.ts +0 -156
  114. package/lib/interfaces/message-interface.ts +0 -22
  115. package/lib/interfaces/util-interface.ts +0 -31
  116. package/lib/modules/aiproxy-module.ts +0 -246
  117. package/lib/modules/auth-module.ts +0 -753
  118. package/lib/modules/cache-module.ts +0 -99
  119. package/lib/modules/client-module.ts +0 -71
  120. package/lib/modules/comment-module.ts +0 -429
  121. package/lib/modules/components/news-components.ts +0 -390
  122. package/lib/modules/database-module.ts +0 -598
  123. package/lib/modules/file-module.ts +0 -291
  124. package/lib/modules/index.ts +0 -13
  125. package/lib/modules/keyvalue-module.ts +0 -379
  126. package/lib/modules/message-module.ts +0 -107
  127. package/lib/modules/util-module.ts +0 -148
  128. package/lib/polyfills/process-env-browser.ts +0 -1
  129. package/lib/proto/datasource.ts +0 -93
  130. package/lib/proto/dcnet.proto +0 -1601
  131. package/lib/proto/dcnet_proto.d.ts +0 -22857
  132. package/lib/proto/dcnet_proto.js +0 -55204
  133. package/lib/proto/dcnet_proto_sparse.js +0 -55166
  134. package/lib/proto/oidfetch.proto +0 -25
  135. package/lib/proto/oidfetch_proto.d.ts +0 -585
  136. package/lib/proto/oidfetch_proto.js +0 -1247
  137. package/lib/serverless/babel-browser.ts +0 -39
  138. package/lib/serverless/base_entity.ts +0 -78
  139. package/lib/serverless/base_repository.ts +0 -414
  140. package/lib/serverless/browser_schema_extractor.ts +0 -283
  141. package/lib/serverless/decorator_factory.ts +0 -322
  142. package/lib/util/BrowserLineReader.ts +0 -73
  143. package/lib/util/base64.ts +0 -105
  144. package/lib/util/bcrypt.ts +0 -206
  145. package/lib/util/curve25519Encryption.ts +0 -418
  146. package/lib/util/dccrypt.ts +0 -73
  147. package/lib/util/logger.ts +0 -104
  148. package/lib/util/utils.ts +0 -289
@@ -1,54 +0,0 @@
1
- // net.ts
2
- import type { CID } from 'multiformats/cid'
3
- import {IPLDNode} from './core'
4
- import { SymmetricKey } from '../common/key'
5
- import {DAGCBOR} from '@helia/dag-cbor'
6
- import { Blocks } from 'helia'
7
-
8
-
9
- // 事件头接口
10
- export interface EventHeader extends IPLDNode {
11
- /**
12
- * 获取事件体的解密密钥
13
- * @throws 当密钥不可用时抛出 CryptoError
14
- */
15
- key(): Promise<SymmetricKey>
16
- }
17
-
18
- // 线程事件接口
19
- export interface IThreadEvent extends IPLDNode {
20
- /** 获取事件头的 CID */
21
- headerCID(): CID
22
-
23
- /**
24
- * 异步加载事件头
25
- * @param decryptKey 可选的解密密钥(用于加密头)
26
- */
27
- getHeader(
28
- bstore: Blocks,
29
- decryptKey?: SymmetricKey
30
- ): Promise<EventHeader>
31
-
32
- /** 获取事件体的 CID */
33
- bodyCID(): CID
34
-
35
- /**
36
- * 异步加载事件体
37
- * @param decryptKey 必须提供头密钥才能解密
38
- */
39
- getBody(
40
- bstore: Blocks,
41
- decryptKey?: SymmetricKey
42
- ): Promise<IPLDNode>
43
- }
44
-
45
-
46
- // 加密错误类型
47
- export class CryptoError extends Error {
48
- constructor(
49
- public readonly code: 'MISSING_KEY' | 'DECRYPT_FAILED',
50
- message?: string
51
- ) {
52
- super(message)
53
- }
54
- }
@@ -1,89 +0,0 @@
1
- // 使用IPFS CID类型(假设已安装相关类型定义)
2
- import { CID } from 'multiformats/cid'
3
- import { sha256 } from 'multiformats/hashes/sha2'
4
-
5
- // Head结构体转换
6
- export interface Head {
7
- /** 使用multiformats的CID类型表示IPFS内容标识符 */
8
- id?: CID
9
- /** 使用number表示计数器(注意JS的Number精度限制) */
10
- counter: number
11
- }
12
-
13
- // 常量转换
14
- export const CounterUndef: number = 0
15
-
16
-
17
- // // HeadUndef转换方案
18
- // const emptyMultihash = await sha256.digest(new Uint8Array())
19
- // export const HeadUndef: Head = {
20
- // // 使用multiformats的CID undefined表示
21
- // id: CID.create(1, 0x55, emptyMultihash), // 1表示CID版本,0x55表示raw
22
- // counter: CounterUndef
23
- // }
24
-
25
- // export const CIDUndef:CID = CID.create(1, 0x55, emptyMultihash)
26
- export async function getHeadUndef(): Promise<Head> {
27
- // const emptyMultihash = await sha256.digest(new Uint8Array())
28
- return {
29
- counter: CounterUndef
30
- }
31
- }
32
- export async function getCIDUndef(): Promise<CID> {
33
- const emptyMultihash = await sha256.digest(new Uint8Array())
34
- return CID.create(1, 0x55, emptyMultihash)
35
- }
36
-
37
-
38
- /**
39
- * 序列化函数,将 Head 对象转换为 JSON 字符串
40
- * @param head - Head 对象
41
- * @returns 序列化后的 JSON 字符串
42
- */
43
- export function serializeHead(head: Head): string {
44
- return JSON.stringify({
45
- id: head.id?.toString(), // 转换 CID 为字符串
46
- counter: head.counter,
47
- });
48
- }
49
-
50
- /**
51
- * 反序列化函数,将 JSON 字符串转换为 Head 对象
52
- * @param json - JSON 字符串
53
- * @returns 反序列化后的 Head 对象
54
- */
55
- export function deserializeHead(json: string): Head {
56
- const data = JSON.parse(json);
57
- return {
58
- id: CID.parse(data.id), // 从字符串恢复 CID 对象
59
- counter: data.counter,
60
- };
61
- }
62
-
63
- // HeadBookRecord represents the list of heads currently in a log
64
- export interface HeadBookRecord {
65
- // List of current heads of a log.
66
- heads: Head[];
67
- }
68
-
69
- // 序列化函数
70
- export function serializeHeadBookRecord(record: HeadBookRecord): string {
71
- return JSON.stringify({
72
- heads: record.heads.map(head => ({
73
- id: head.id?.toString(), // 转换 CID 为字符串
74
- counter: head.counter
75
- }))
76
- });
77
- }
78
-
79
- // 反序列化函数
80
- export function deserializeHeadBookRecord(json: string): HeadBookRecord {
81
- const raw = JSON.parse(json);
82
-
83
- return {
84
- heads: raw.heads.map((head: any) => ({
85
- id: CID.parse(head.id), // 解析 CID 字符串
86
- counter: Number(head.counter)
87
- }))
88
- };
89
- }
@@ -1,171 +0,0 @@
1
- // thread.ts
2
- import { keys } from "@libp2p/crypto";
3
- import { Ed25519PubKey, Ed25519PrivKey } from '../../../common/dc-key/ed25519';
4
- import {ed25519PublicKeyToCryptoKey,ed25519PrivateKeyToCryptoKey} from '../../../common/dc-key/keyManager'
5
- import { SignJWT, jwtVerify, type JWTPayload, importPKCS8, exportJWK } from 'jose'
6
- import { base32 } from 'multiformats/bases/base32'
7
- import { jwtDecode } from 'jwt-decode'
8
- import { Ed25519PrivateKey } from "@libp2p/interface";
9
-
10
- // ==================== 核心接口 ====================
11
- export interface Identity {
12
- sign(data: Uint8Array): Promise<Uint8Array>
13
- getPublic(): Ed25519PubKey
14
- decrypt(data: Uint8Array): Promise<Uint8Array>
15
- equals(other: Identity): boolean
16
- }
17
-
18
-
19
- // ==================== Ed25519 实现 ====================
20
- export class Ed25519Identity implements Identity {
21
- private constructor(
22
- public readonly privateKey: Ed25519PrivKey,
23
- public readonly publicKey: Ed25519PubKey
24
- ) {}
25
-
26
- static async create(): Promise<Ed25519Identity> {
27
- const privateKey = await keys.generateKeyPair('Ed25519')
28
- const ed25519PrivateKey =new Ed25519PrivKey(privateKey.raw)
29
- const publicKey = ed25519PrivateKey.publicKey
30
- return new Ed25519Identity(ed25519PrivateKey, publicKey)
31
- }
32
-
33
- async sign(data: Uint8Array): Promise<Uint8Array> {
34
- return this.privateKey.sign(data)
35
- }
36
-
37
- getPublic(): Ed25519PubKey {
38
- return this.publicKey
39
- }
40
-
41
- async decrypt(data: Uint8Array): Promise<Uint8Array> {
42
- return this.privateKey.decrypt(data)
43
- }
44
-
45
- equals(other: Identity): boolean {
46
- return other instanceof Ed25519Identity &&
47
- this.publicKey.equals(other.publicKey)
48
- }
49
- }
50
-
51
-
52
-
53
-
54
-
55
- /**
56
- * 将 CryptoKey 转换为 PKCS#8 格式字符串
57
- * 安全提示:仅在需要导出私钥时使用
58
- */
59
- export async function exportPrivateKey(key: CryptoKey): Promise<string> {
60
- const exported = await crypto.subtle.exportKey('pkcs8', key)
61
- return base32.encode(new Uint8Array(exported))
62
- }
63
-
64
-
65
- // ==================== JWT 令牌处理 ====================
66
- export class ThreadToken {
67
- constructor(readonly value: string) {}
68
-
69
- static async issue(issuer: Ed25519Identity, pubKey: Ed25519PubKey): Promise<ThreadToken> {
70
- const privateKey = await ed25519PrivateKeyToCryptoKey(issuer.privateKey.raw)
71
- return new ThreadToken(
72
- await new SignJWT({
73
- sub: pubKey.toString(),
74
- iss: issuer.getPublic().toString()
75
- } as JWTPayload)
76
- .setProtectedHeader({ alg: 'EdDSA' })
77
- .setIssuedAt()
78
- .sign(privateKey)
79
- )
80
- }
81
-
82
- // PubKey returns the public key encoded in the token.
83
-
84
- async pubKey(): Promise<Ed25519PubKey|undefined > {
85
- if (this.value) {
86
- try {
87
- // Parse token without verification
88
- const decoded = jwtDecode<{ sub: string }>(this.value);
89
-
90
- if (!decoded.sub) {
91
- throw new Error('Token subject is missing');
92
- }
93
- // Create public key from subject
94
- try {
95
- // Assuming subject contains the base32-encoded public key
96
- return Ed25519PubKey.unmarshalString(decoded.sub);
97
- } catch (err) {
98
- throw new Error(`Failed to unmarshal public key: ${err instanceof Error ? err.message : String(err)}`);
99
- }
100
- } catch (err) {
101
- if (err instanceof Error && err.message.includes('Invalid token')) {
102
- throw new Error('Invalid token format');
103
- } else {
104
- throw new Error('Token not found or invalid');
105
- }
106
- }
107
- }
108
- return
109
- }
110
-
111
-
112
- async validate(issuerPrivateKey: Ed25519PrivateKey): Promise<Ed25519PubKey |undefined> {
113
- try {
114
- const privateKey = await ed25519PrivateKeyToCryptoKey(issuerPrivateKey.raw, 'raw')
115
- const { payload } = await jwtVerify(this.value, privateKey)
116
- return this.parsePubKey(payload.sub!)
117
- } catch {
118
- return
119
- }
120
- }
121
-
122
- private parsePubKey(str: string): Ed25519PubKey {
123
- return new Ed25519PubKey(base32.decode(str))
124
- }
125
-
126
- get defined(): boolean {
127
- return this.value.length > 0
128
- }
129
- }
130
-
131
-
132
- // ==================== 浏览器上下文管理 ====================
133
- interface ThreadContext {
134
- headers: Headers
135
- }
136
-
137
- const contextStack: ThreadContext[] = [{
138
- headers: new Headers()
139
- }]
140
-
141
- export function withContext<T>(ctx: ThreadContext, fn: () => T): T {
142
- contextStack.push(ctx)
143
- try {
144
- return fn()
145
- } finally {
146
- contextStack.pop()
147
- }
148
- }
149
-
150
- export function currentContext(): ThreadContext {
151
- return contextStack[contextStack.length - 1]!
152
- }
153
-
154
- // ==================== 凭证处理 ====================
155
- export function createAuthHeader(token?: ThreadToken): Headers {
156
- const headers = new Headers()
157
- if (token?.defined) {
158
- headers.set('Authorization', `Bearer ${token.value}`)
159
- }
160
- return headers
161
- }
162
-
163
- // ==================== 错误类型 ====================
164
- export class AuthError extends Error {
165
- constructor(
166
- readonly code: 'MISSING_TOKEN' | 'INVALID_TOKEN',
167
- message?: string
168
- ) {
169
- super(message)
170
- }
171
- }
@@ -1,137 +0,0 @@
1
- import { ThreadID } from '@textile/threads-id';
2
- import type { PeerId, PrivateKey, PublicKey } from "@libp2p/interface";
3
- import { Ed25519PrivKey } from "../../../common/dc-key/ed25519";
4
- import { SymKey, IThreadInfo, IThreadLogInfo } from "./core";
5
- import type { Multiaddr } from "@multiformats/multiaddr";
6
- import { multiaddr } from '@multiformats/multiaddr';
7
- import { Head } from './head';
8
- import { Key } from 'interface-datastore'
9
- import * as pb from '../pb/lstore';
10
-
11
-
12
- // 异常定义
13
- export class ErrThreadExists extends Error {
14
- constructor() { super('thread already exists'); }
15
- }
16
-
17
-
18
-
19
-
20
- // 接口定义
21
- export interface IThreadMetadata {
22
- getInt64(t: ThreadID, key: string): Promise<number | null>;
23
- putInt64(t: ThreadID, key: string, val: number): Promise<void>;
24
- getString(t: ThreadID, key: string): Promise<string | null>;
25
- putString(t: ThreadID, key: string, val: string): Promise<void>;
26
- getBool(t: ThreadID, key: string): Promise<boolean | null>;
27
- putBool(t: ThreadID, key: string, val: boolean): Promise<void>;
28
- getBytes(t: ThreadID, key: string): Promise<Uint8Array | null>;
29
- putBytes(t: ThreadID, key: string, val: Uint8Array): Promise<void>;
30
- clearMetadata(t: ThreadID): Promise<void>;
31
- dumpMeta(): Promise<DumpMetadata>;
32
- restoreMeta(book: DumpMetadata): Promise<void>;
33
- }
34
-
35
- export interface KeyBook {
36
- pubKey(threadId: ThreadID, peerId: PeerId): Promise<PublicKey | undefined>;
37
- addPubKey(threadId: ThreadID, peerId: PeerId, key: PublicKey): Promise<void>;
38
- privKey(threadId: ThreadID, peerId: PeerId): Promise<PrivateKey | null>;
39
- addPrivKey(threadId: ThreadID, peerId: PeerId, key: PrivateKey): Promise<void>;
40
- readKey(threadId: ThreadID): Promise<SymKey|undefined>;
41
- addReadKey(threadId: ThreadID, key: SymKey): Promise<void>;
42
- serviceKey(threadId: ThreadID): Promise<SymKey | undefined>;
43
- addServiceKey(threadId: ThreadID, key: SymKey): Promise<void>;
44
- clearKeys(threadId: ThreadID): Promise<void>;
45
- clearLogKeys(threadId: ThreadID, peerId: PeerId): Promise<void>;
46
- logsWithKeys(threadId: ThreadID): Promise<PeerId[]>;
47
- threadsFromKeys(): Promise<ThreadID[]>;
48
- dumpKeys(): Promise<DumpKeyBook>;
49
- restoreKeys(book: DumpKeyBook): Promise<void>;
50
- }
51
-
52
-
53
-
54
-
55
-
56
- export interface AddrBook {
57
- addAddr(threadId: ThreadID, peerId: PeerId, addr: Multiaddr, ttl: number): Promise<void>;
58
- addAddrs(threadId: ThreadID, peerId: PeerId, addrs: Multiaddr[], ttl: number): Promise<void>;
59
- setAddr(threadId: ThreadID, peerId: PeerId, addr: Multiaddr, ttl: number): Promise<void>;
60
- setAddrs(threadId: ThreadID, peerId: PeerId, addrs: Multiaddr[], ttl: number): Promise<void>;
61
- updateAddrs(threadId: ThreadID, peerId: PeerId, oldTTL: number, newTTL: number): Promise<void>;
62
- addrs(threadId: ThreadID, peerId: PeerId): Promise<Multiaddr[]>;
63
- clearAddrs(threadId: ThreadID, peerId: PeerId): Promise<void>;
64
- logsWithAddrs(threadId: ThreadID): Promise<PeerId[]>;
65
- threadsFromAddrs(): Promise<ThreadID[]>;
66
- addrsEdge(threadId: ThreadID,exceptPeerId?:string): Promise<bigint>;
67
- dumpAddrs(): Promise<DumpAddrBook>;
68
- restoreAddrs(book: DumpAddrBook): Promise<void>;
69
- }
70
-
71
- export interface HeadBook {
72
- addHead(threadId: ThreadID, peerId: PeerId, head: Head): Promise<void>;
73
- addHeads(threadId: ThreadID, peerId: PeerId, heads: Head[]): Promise<void>;
74
- setHead(threadId: ThreadID, peerId: PeerId, head: Head): Promise<void>;
75
- setHeads(threadId: ThreadID, peerId: PeerId, heads: Head[]): Promise<void>;
76
- heads(threadId: ThreadID, peerId: PeerId): Promise<Head[]>;
77
- clearHeads(threadId: ThreadID, peerId: PeerId): Promise<void>;
78
- headsEdge(threadId: ThreadID): Promise<bigint>;
79
- dumpHeads(): Promise<DumpHeadBook>;
80
- restoreHeads(book: DumpHeadBook): Promise<void>;
81
- }
82
-
83
- export interface ILogstore {
84
- metadata: IThreadMetadata;
85
- keyBook: KeyBook;
86
- addrBook: AddrBook;
87
- headBook: HeadBook;
88
- close(): Promise<void>;
89
- threads(): Promise<ThreadID[]>;
90
- addThread(info: IThreadInfo): Promise<void>;
91
- getThread(threadId: ThreadID): Promise<IThreadInfo>;
92
- deleteThread(threadId: ThreadID): Promise<void>;
93
- addLog(threadId: ThreadID, logInfo: IThreadLogInfo): Promise<void>;
94
- getLog(threadId: ThreadID, peerId: PeerId): Promise<IThreadLogInfo>;
95
- getManagedLogs(threadId: ThreadID): Promise<IThreadLogInfo[]>;
96
- deleteLog(threadId: ThreadID, peerId: PeerId): Promise<void>;
97
- }
98
-
99
-
100
-
101
-
102
- // Dump 结构定义
103
- export interface ExpiredAddress {
104
- addr: Multiaddr;
105
- expires: Date;
106
- }
107
-
108
- export interface DumpHeadBook {
109
- data: Record<string, Record<string, Head[]>>;
110
- }
111
-
112
- export interface DumpAddrBook {
113
- data: Record<string, Record<string, ExpiredAddress[]>>;
114
- }
115
-
116
- export interface DumpKeyBook {
117
- data: {
118
- public: Record<string, Record<string, PublicKey>>;
119
- private: Record<string, Record<string, PrivateKey>>;
120
- read: Record<string, Uint8Array>;
121
- service: Record<string, Uint8Array>;
122
- };
123
- }
124
-
125
- export interface MetadataKey {
126
- t: ThreadID;
127
- k: string;
128
- }
129
-
130
- export interface DumpMetadata {
131
- data: {
132
- int64: Record<string, Record<string, number>>;
133
- bool: Record<string, Record<string, boolean>>;
134
- string: Record<string, Record<string, string>>;
135
- bytes: Record<string, Record<string, Uint8Array>>;
136
- };
137
- }
@@ -1,14 +0,0 @@
1
- import {Key as ThreadKey,LogKey} from '../common/key';
2
- import { Ed25519PubKey } from "../../../common/dc-key/ed25519";
3
- import {ThreadToken} from './identity';
4
-
5
-
6
- export type NewThreadOptions = {
7
- threadKey?: ThreadKey;
8
- logKey?: LogKey;
9
- token: ThreadToken;
10
- pubkey?: Ed25519PubKey;
11
- blockHeight: number; // uint32 can be represented as number in TypeScript
12
- signature: Uint8Array; // []byte can be represented as Uint8Array in TypeScript
13
- vaccount?: Ed25519PubKey;
14
- };
@@ -1,54 +0,0 @@
1
-
2
- import type { CID } from 'multiformats/cid'
3
- import {ThreadID} from '@textile/threads-id'
4
- import type { PeerId } from "@libp2p/interface";
5
- import type { PublicKey as CryptoPubKey } from '@libp2p/interface-keys'
6
- import { DAGCBOR} from '@helia/dag-cbor'
7
- import { IPLDNode } from './core'
8
- import { Blocks } from 'helia';
9
-
10
-
11
-
12
-
13
-
14
-
15
- // IPLD 节点接口
16
-
17
-
18
- export type Signature = Uint8Array
19
-
20
-
21
- // Record 基础接口
22
- export interface IRecord extends IPLDNode {
23
- /** 获取内部区块的 CID */
24
- blockID: () => CID
25
-
26
- /** 异步加载内部区块 */
27
- getBlock: ( bstore:Blocks) => Promise<IPLDNode>
28
-
29
- /** 前一个记录的 CID */
30
- prevID: () => CID | undefined
31
-
32
- /** 记录的数字签名 */
33
- sig: () => Signature
34
-
35
- /** 作者的原始公钥字节 */
36
- pubKey: () => Uint8Array
37
-
38
- /** 验证签名有效性 */
39
- verify: (key: CryptoPubKey) => Promise<Error | undefined>
40
- }
41
-
42
- // 线程记录包装器
43
- export interface IThreadRecord {
44
- /** 获取底层记录对象 */
45
- value: () => IRecord
46
-
47
- /** 所属线程的标识符 */
48
- threadID: () => ThreadID
49
-
50
- /** 日志来源的对等节点ID */
51
- logID: () => PeerId
52
- }
53
-
54
-