@cmdoss/memwal-sdk 0.6.2 → 0.8.0
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/ARCHITECTURE.md +547 -547
- package/BENCHMARKS.md +238 -238
- package/README.md +310 -181
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/client/ClientMemoryManager.js +2 -2
- package/dist/client/ClientMemoryManager.js.map +1 -1
- package/dist/client/PersonalDataWallet.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +29 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +45 -13
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.d.ts +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.js +1 -1
- package/dist/client/namespaces/MemoryNamespace.d.ts +31 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +272 -39
- package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/AINamespace.d.ts +2 -2
- package/dist/client/namespaces/consolidated/AINamespace.js +2 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +62 -4
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/config/ConfigurationHelper.js +61 -61
- package/dist/config/defaults.js +2 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/graph/GraphService.js +21 -21
- package/dist/graph/GraphService.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
- package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.js +37 -15
- package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
- package/dist/infrastructure/seal/SealService.d.ts +13 -5
- package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
- package/dist/infrastructure/seal/SealService.js +36 -34
- package/dist/infrastructure/seal/SealService.js.map +1 -1
- package/dist/langchain/createPDWRAG.js +30 -30
- package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.d.ts +31 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.js +44 -4
- package/dist/retrieval/MemoryRetrievalService.js.map +1 -1
- package/dist/services/CapabilityService.d.ts.map +1 -1
- package/dist/services/CapabilityService.js +30 -14
- package/dist/services/CapabilityService.js.map +1 -1
- package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
- package/dist/services/CrossContextPermissionService.js +9 -7
- package/dist/services/CrossContextPermissionService.js.map +1 -1
- package/dist/services/EmbeddingService.d.ts +28 -1
- package/dist/services/EmbeddingService.d.ts.map +1 -1
- package/dist/services/EmbeddingService.js +54 -0
- package/dist/services/EmbeddingService.js.map +1 -1
- package/dist/services/EncryptionService.d.ts.map +1 -1
- package/dist/services/EncryptionService.js +6 -5
- package/dist/services/EncryptionService.js.map +1 -1
- package/dist/services/GeminiAIService.js +309 -309
- package/dist/services/IndexManager.d.ts +5 -1
- package/dist/services/IndexManager.d.ts.map +1 -1
- package/dist/services/IndexManager.js +17 -40
- package/dist/services/IndexManager.js.map +1 -1
- package/dist/services/QueryService.js +1 -1
- package/dist/services/QueryService.js.map +1 -1
- package/dist/services/StorageService.d.ts +11 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +73 -10
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +20 -0
- package/dist/services/TransactionService.d.ts.map +1 -1
- package/dist/services/TransactionService.js +43 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/ViewService.js +2 -2
- package/dist/services/ViewService.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +101 -1
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +410 -20
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/index.d.ts +1 -1
- package/dist/services/storage/index.d.ts.map +1 -1
- package/dist/services/storage/index.js.map +1 -1
- package/dist/utils/LRUCache.d.ts +106 -0
- package/dist/utils/LRUCache.d.ts.map +1 -0
- package/dist/utils/LRUCache.js +281 -0
- package/dist/utils/LRUCache.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memoryIndexOnChain.d.ts +212 -0
- package/dist/utils/memoryIndexOnChain.d.ts.map +1 -0
- package/dist/utils/memoryIndexOnChain.js +312 -0
- package/dist/utils/memoryIndexOnChain.js.map +1 -0
- package/dist/utils/rebuildIndexNode.d.ts +29 -0
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +366 -98
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/HnswWasmService.d.ts +20 -5
- package/dist/vector/HnswWasmService.d.ts.map +1 -1
- package/dist/vector/HnswWasmService.js +73 -40
- package/dist/vector/HnswWasmService.js.map +1 -1
- package/dist/vector/IHnswService.d.ts +10 -1
- package/dist/vector/IHnswService.d.ts.map +1 -1
- package/dist/vector/IHnswService.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts +16 -0
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +84 -5
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/vector/createHnswService.d.ts +1 -1
- package/dist/vector/createHnswService.js +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.js +1 -1
- package/package.json +157 -157
- package/src/access/PermissionService.ts +635 -635
- package/src/aggregation/AggregationService.ts +389 -389
- package/src/ai-sdk/PDWVectorStore.ts +715 -715
- package/src/ai-sdk/index.ts +65 -65
- package/src/ai-sdk/tools.ts +460 -460
- package/src/ai-sdk/types.ts +404 -404
- package/src/batch/BatchManager.ts +597 -597
- package/src/batch/BatchingService.ts +429 -429
- package/src/batch/MemoryProcessingCache.ts +492 -492
- package/src/batch/index.ts +30 -30
- package/src/browser.ts +200 -200
- package/src/client/ClientMemoryManager.ts +987 -987
- package/src/client/PersonalDataWallet.ts +345 -345
- package/src/client/SimplePDWClient.ts +1289 -1222
- package/src/client/factory.ts +154 -154
- package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
- package/src/client/namespaces/BatchNamespace.ts +356 -356
- package/src/client/namespaces/CacheNamespace.ts +123 -123
- package/src/client/namespaces/CapabilityNamespace.ts +217 -217
- package/src/client/namespaces/ClassifyNamespace.ts +169 -169
- package/src/client/namespaces/ContextNamespace.ts +297 -297
- package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
- package/src/client/namespaces/EncryptionNamespace.ts +221 -221
- package/src/client/namespaces/GraphNamespace.ts +468 -468
- package/src/client/namespaces/IndexNamespace.ts +361 -361
- package/src/client/namespaces/MemoryNamespace.ts +1422 -1135
- package/src/client/namespaces/PermissionsNamespace.ts +254 -254
- package/src/client/namespaces/PipelineNamespace.ts +220 -220
- package/src/client/namespaces/SearchNamespace.ts +1049 -1049
- package/src/client/namespaces/StorageNamespace.ts +458 -458
- package/src/client/namespaces/TxNamespace.ts +260 -260
- package/src/client/namespaces/WalletNamespace.ts +243 -243
- package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -546
- package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
- package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
- package/src/client/namespaces/consolidated/index.ts +39 -39
- package/src/client/signers/KeypairSigner.ts +108 -108
- package/src/client/signers/UnifiedSigner.ts +110 -110
- package/src/client/signers/WalletAdapterSigner.ts +159 -159
- package/src/client/signers/index.ts +26 -26
- package/src/config/ConfigurationHelper.ts +412 -412
- package/src/config/defaults.ts +51 -51
- package/src/config/index.ts +8 -8
- package/src/config/validation.ts +70 -70
- package/src/core/index.ts +14 -14
- package/src/core/interfaces/IService.ts +307 -307
- package/src/core/interfaces/index.ts +8 -8
- package/src/core/types/capability.ts +297 -297
- package/src/core/types/index.ts +870 -870
- package/src/core/types/wallet.ts +270 -270
- package/src/core/types.ts +9 -9
- package/src/core/wallet.ts +222 -222
- package/src/embedding/index.ts +19 -19
- package/src/embedding/types.ts +357 -357
- package/src/errors/index.ts +602 -602
- package/src/errors/recovery.ts +461 -461
- package/src/errors/validation.ts +567 -567
- package/src/generated/pdw/capability.ts +319 -319
- package/src/graph/GraphService.ts +887 -887
- package/src/graph/KnowledgeGraphManager.ts +728 -728
- package/src/graph/index.ts +25 -25
- package/src/index.ts +498 -474
- package/src/infrastructure/index.ts +22 -22
- package/src/infrastructure/seal/EncryptionService.ts +628 -603
- package/src/infrastructure/seal/SealService.ts +613 -615
- package/src/infrastructure/seal/index.ts +9 -9
- package/src/infrastructure/sui/BlockchainManager.ts +627 -627
- package/src/infrastructure/sui/SuiService.ts +888 -888
- package/src/infrastructure/sui/index.ts +9 -9
- package/src/infrastructure/walrus/StorageManager.ts +604 -604
- package/src/infrastructure/walrus/WalrusStorageService.ts +612 -612
- package/src/infrastructure/walrus/index.ts +9 -9
- package/src/langchain/PDWEmbeddings.ts +145 -145
- package/src/langchain/PDWVectorStore.ts +456 -456
- package/src/langchain/createPDWRAG.ts +303 -303
- package/src/langchain/index.ts +47 -47
- package/src/permissions/ConsentRepository.browser.ts +249 -249
- package/src/permissions/ConsentRepository.ts +364 -364
- package/src/pipeline/MemoryPipeline.ts +862 -862
- package/src/pipeline/PipelineManager.ts +683 -683
- package/src/pipeline/index.ts +26 -26
- package/src/retrieval/AdvancedSearchService.ts +629 -629
- package/src/retrieval/MemoryAnalyticsService.ts +711 -711
- package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
- package/src/retrieval/MemoryRetrievalService.ts +904 -830
- package/src/retrieval/index.ts +42 -42
- package/src/services/BatchService.ts +352 -352
- package/src/services/CapabilityService.ts +464 -448
- package/src/services/ClassifierService.ts +465 -465
- package/src/services/CrossContextPermissionService.ts +486 -484
- package/src/services/EmbeddingService.ts +771 -706
- package/src/services/EncryptionService.ts +712 -711
- package/src/services/GeminiAIService.ts +753 -753
- package/src/services/IndexManager.ts +977 -1004
- package/src/services/MemoryIndexService.ts +1003 -1003
- package/src/services/MemoryService.ts +369 -369
- package/src/services/QueryService.ts +890 -890
- package/src/services/StorageService.ts +1182 -1111
- package/src/services/TransactionService.ts +838 -790
- package/src/services/VectorService.ts +462 -462
- package/src/services/ViewService.ts +484 -484
- package/src/services/index.ts +25 -25
- package/src/services/storage/BlobAttributesManager.ts +333 -333
- package/src/services/storage/KnowledgeGraphManager.ts +425 -425
- package/src/services/storage/MemorySearchManager.ts +387 -387
- package/src/services/storage/QuiltBatchManager.ts +1130 -660
- package/src/services/storage/WalrusMetadataManager.ts +268 -268
- package/src/services/storage/WalrusStorageManager.ts +287 -287
- package/src/services/storage/index.ts +57 -52
- package/src/types/index.ts +13 -13
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +76 -68
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndex.ts +290 -290
- package/src/utils/rebuildIndexNode.ts +771 -424
- package/src/vector/BrowserHnswIndexService.ts +758 -758
- package/src/vector/HnswWasmService.ts +731 -679
- package/src/vector/IHnswService.ts +233 -224
- package/src/vector/NodeHnswService.ts +833 -735
- package/src/vector/VectorManager.ts +478 -478
- package/src/vector/createHnswService.ts +135 -135
- package/src/vector/index.ts +56 -56
- package/src/wallet/ContextWalletService.ts +656 -656
- package/src/wallet/MainWalletService.ts +317 -317
|
@@ -1,546 +1,607 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Blockchain Namespace - Consolidated Sui Blockchain Operations
|
|
3
|
-
*
|
|
4
|
-
* Merges functionality from:
|
|
5
|
-
* - TxNamespace: Transaction building and execution
|
|
6
|
-
* - WalletNamespace: Wallet operations and queries
|
|
7
|
-
*
|
|
8
|
-
* Provides a unified interface for all Sui blockchain interactions.
|
|
9
|
-
*
|
|
10
|
-
* @module client/namespaces/consolidated
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { ServiceContainer } from '../../SimplePDWClient';
|
|
14
|
-
import { Transaction } from '@mysten/sui/transactions';
|
|
15
|
-
import type { TransactionResult } from '../../../types';
|
|
16
|
-
|
|
17
|
-
// ============================================================================
|
|
18
|
-
// Types
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Memory transaction options
|
|
23
|
-
*/
|
|
24
|
-
export interface MemoryTxOptions {
|
|
25
|
-
category: string;
|
|
26
|
-
vectorId: number;
|
|
27
|
-
blobId: string;
|
|
28
|
-
importance: number;
|
|
29
|
-
gasBudget?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Batch operation types supported by PTB
|
|
34
|
-
*/
|
|
35
|
-
export type BatchOperationType = 'createMemory' | 'updateMemory' | 'deleteMemory' | 'createCap' | 'transferCap' | 'burnCap';
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Batch operation definition
|
|
39
|
-
*/
|
|
40
|
-
export interface BatchOperation {
|
|
41
|
-
type: BatchOperationType;
|
|
42
|
-
options: any;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Wallet info
|
|
47
|
-
*/
|
|
48
|
-
export interface WalletInfo {
|
|
49
|
-
address: string;
|
|
50
|
-
connected: boolean;
|
|
51
|
-
network: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Object info
|
|
56
|
-
*/
|
|
57
|
-
export interface OwnedObject {
|
|
58
|
-
id: string;
|
|
59
|
-
type: string;
|
|
60
|
-
version: string;
|
|
61
|
-
digest: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Sub-Namespaces
|
|
66
|
-
// ============================================================================
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Transaction sub-namespace
|
|
70
|
-
*/
|
|
71
|
-
class TxSubNamespace {
|
|
72
|
-
constructor(private services: ServiceContainer) {}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Build transaction for creating memory record
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* @
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @returns
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* ```
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
return
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* @
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Blockchain Namespace - Consolidated Sui Blockchain Operations
|
|
3
|
+
*
|
|
4
|
+
* Merges functionality from:
|
|
5
|
+
* - TxNamespace: Transaction building and execution
|
|
6
|
+
* - WalletNamespace: Wallet operations and queries
|
|
7
|
+
*
|
|
8
|
+
* Provides a unified interface for all Sui blockchain interactions.
|
|
9
|
+
*
|
|
10
|
+
* @module client/namespaces/consolidated
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ServiceContainer } from '../../SimplePDWClient';
|
|
14
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
15
|
+
import type { TransactionResult } from '../../../types';
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Types
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Memory transaction options
|
|
23
|
+
*/
|
|
24
|
+
export interface MemoryTxOptions {
|
|
25
|
+
category: string;
|
|
26
|
+
vectorId: number;
|
|
27
|
+
blobId: string;
|
|
28
|
+
importance: number;
|
|
29
|
+
gasBudget?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Batch operation types supported by PTB
|
|
34
|
+
*/
|
|
35
|
+
export type BatchOperationType = 'createMemory' | 'updateMemory' | 'deleteMemory' | 'createCap' | 'transferCap' | 'burnCap';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Batch operation definition
|
|
39
|
+
*/
|
|
40
|
+
export interface BatchOperation {
|
|
41
|
+
type: BatchOperationType;
|
|
42
|
+
options: any;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Wallet info
|
|
47
|
+
*/
|
|
48
|
+
export interface WalletInfo {
|
|
49
|
+
address: string;
|
|
50
|
+
connected: boolean;
|
|
51
|
+
network: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Object info
|
|
56
|
+
*/
|
|
57
|
+
export interface OwnedObject {
|
|
58
|
+
id: string;
|
|
59
|
+
type: string;
|
|
60
|
+
version: string;
|
|
61
|
+
digest: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Sub-Namespaces
|
|
66
|
+
// ============================================================================
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Transaction sub-namespace
|
|
70
|
+
*/
|
|
71
|
+
class TxSubNamespace {
|
|
72
|
+
constructor(private services: ServiceContainer) {}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Build transaction for creating memory record
|
|
76
|
+
*
|
|
77
|
+
* Automatically uses capability-based creation when encryption is enabled,
|
|
78
|
+
* otherwise falls back to lightweight creation without capability.
|
|
79
|
+
*
|
|
80
|
+
* **Smart capability handling:**
|
|
81
|
+
* - If `capId` provided → use it directly (V2)
|
|
82
|
+
* - If encryption enabled + capability service available → auto get/create capability (V2)
|
|
83
|
+
* - Otherwise → fallback to legacy mode (V1)
|
|
84
|
+
*
|
|
85
|
+
* @param options - Memory creation options (with optional capId for V2)
|
|
86
|
+
* @returns Transaction object
|
|
87
|
+
*/
|
|
88
|
+
async buildCreate(options: MemoryTxOptions & { capId?: string }): Promise<Transaction> {
|
|
89
|
+
if (!this.services.tx) {
|
|
90
|
+
throw new Error('Transaction service not configured.');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let capId = options.capId;
|
|
94
|
+
|
|
95
|
+
// Auto get/create capability if encryption enabled and not explicitly provided
|
|
96
|
+
if (!capId && this.services.capability && this.services.config.features?.enableEncryption) {
|
|
97
|
+
try {
|
|
98
|
+
console.log('🔐 Auto-creating capability for encryption...');
|
|
99
|
+
const cap = await this.services.capability.getOrCreate(
|
|
100
|
+
{
|
|
101
|
+
appId: options.category,
|
|
102
|
+
userAddress: this.services.config.userAddress
|
|
103
|
+
},
|
|
104
|
+
this.services.config.signer // Pass signer for transaction signing
|
|
105
|
+
);
|
|
106
|
+
capId = cap.id;
|
|
107
|
+
console.log(`✅ Capability ready: ${capId}`);
|
|
108
|
+
} catch (capError) {
|
|
109
|
+
console.warn('⚠️ Failed to auto-create capability:', capError);
|
|
110
|
+
// Continue without capability (fallback to legacy mode)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Use capability-based creation if capId available (V2 - RECOMMENDED for encryption)
|
|
115
|
+
if (capId) {
|
|
116
|
+
return this.services.tx.buildCreateMemoryRecordLightweightWithCap({
|
|
117
|
+
category: options.category,
|
|
118
|
+
vectorId: options.vectorId,
|
|
119
|
+
blobId: options.blobId,
|
|
120
|
+
importance: options.importance,
|
|
121
|
+
gasBudget: options.gasBudget,
|
|
122
|
+
capId: capId
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Fallback to legacy lightweight creation (V1 - no encryption support)
|
|
127
|
+
return this.services.tx.buildCreateMemoryRecordLightweight({
|
|
128
|
+
category: options.category,
|
|
129
|
+
vectorId: options.vectorId,
|
|
130
|
+
blobId: options.blobId,
|
|
131
|
+
importance: options.importance,
|
|
132
|
+
gasBudget: options.gasBudget
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Build transaction for updating memory metadata
|
|
138
|
+
*
|
|
139
|
+
* @param memoryId - Memory ID to update
|
|
140
|
+
* @param metadataBlobId - New metadata blob ID
|
|
141
|
+
* @returns Transaction object
|
|
142
|
+
*/
|
|
143
|
+
buildUpdate(memoryId: string, metadataBlobId: string): Transaction {
|
|
144
|
+
if (!this.services.tx) {
|
|
145
|
+
throw new Error('Transaction service not configured.');
|
|
146
|
+
}
|
|
147
|
+
return this.services.tx.buildUpdateMemoryMetadata({
|
|
148
|
+
memoryId,
|
|
149
|
+
metadataBlobId,
|
|
150
|
+
embeddingDimension: 3072
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Build transaction for deleting memory record
|
|
156
|
+
*
|
|
157
|
+
* @param memoryId - Memory ID to delete
|
|
158
|
+
* @returns Transaction object
|
|
159
|
+
*/
|
|
160
|
+
buildDelete(memoryId: string): Transaction {
|
|
161
|
+
if (!this.services.tx) {
|
|
162
|
+
throw new Error('Transaction service not configured.');
|
|
163
|
+
}
|
|
164
|
+
return this.services.tx.buildDeleteMemoryRecord({ memoryId });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Execute a transaction
|
|
169
|
+
*
|
|
170
|
+
* @param tx - Transaction to execute
|
|
171
|
+
* @returns Transaction result with digest and status
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const tx = pdw.blockchain.tx.buildCreate({ ... });
|
|
176
|
+
* const result = await pdw.blockchain.tx.execute(tx);
|
|
177
|
+
* console.log('Tx digest:', result.digest);
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
async execute(tx: Transaction): Promise<TransactionResult> {
|
|
181
|
+
const signer = this.services.config.signer;
|
|
182
|
+
|
|
183
|
+
// Check if signer supports signAndExecuteTransaction (browser wallets like DappKitSigner)
|
|
184
|
+
// Browser wallets cannot expose raw Signer for security reasons
|
|
185
|
+
if ('signAndExecuteTransaction' in signer && typeof signer.signAndExecuteTransaction === 'function') {
|
|
186
|
+
try {
|
|
187
|
+
// Use the signer's signAndExecuteTransaction directly
|
|
188
|
+
const result = await signer.signAndExecuteTransaction(tx);
|
|
189
|
+
|
|
190
|
+
// Get full transaction details to extract created objects
|
|
191
|
+
let createdObjects: Array<{ objectId: string; objectType: string }> | undefined;
|
|
192
|
+
let mutatedObjects: Array<{ objectId: string; objectType: string }> | undefined;
|
|
193
|
+
|
|
194
|
+
if (result.objectChanges && Array.isArray(result.objectChanges)) {
|
|
195
|
+
createdObjects = result.objectChanges
|
|
196
|
+
.filter((change: any) => change.type === 'created')
|
|
197
|
+
.map((change: any) => ({
|
|
198
|
+
objectId: change.objectId,
|
|
199
|
+
objectType: change.objectType || 'unknown',
|
|
200
|
+
}));
|
|
201
|
+
|
|
202
|
+
mutatedObjects = result.objectChanges
|
|
203
|
+
.filter((change: any) => change.type === 'mutated')
|
|
204
|
+
.map((change: any) => ({
|
|
205
|
+
objectId: change.objectId,
|
|
206
|
+
objectType: change.objectType || 'unknown',
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Determine status from effects
|
|
211
|
+
// dapp-kit may not return full effects structure unless custom execute is configured
|
|
212
|
+
// We check multiple indicators:
|
|
213
|
+
// 1. If effects.status.status explicitly says 'failure', it failed
|
|
214
|
+
// 2. If effects.status.status says 'success', it succeeded
|
|
215
|
+
// 3. If we have a digest but no effects status, assume success (tx was submitted and confirmed)
|
|
216
|
+
let status: 'success' | 'failure';
|
|
217
|
+
const effectsStatus = result.effects?.status?.status;
|
|
218
|
+
|
|
219
|
+
if (effectsStatus === 'failure') {
|
|
220
|
+
status = 'failure';
|
|
221
|
+
} else if (effectsStatus === 'success') {
|
|
222
|
+
status = 'success';
|
|
223
|
+
} else if (result.digest) {
|
|
224
|
+
// Has digest but no explicit status - DappKitSigner waits for confirmation
|
|
225
|
+
// If we reach here without error, the transaction was successful
|
|
226
|
+
status = 'success';
|
|
227
|
+
} else {
|
|
228
|
+
status = 'failure';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
digest: result.digest,
|
|
233
|
+
status,
|
|
234
|
+
effects: result.effects,
|
|
235
|
+
createdObjects,
|
|
236
|
+
mutatedObjects,
|
|
237
|
+
gasUsed: result.effects?.gasUsed?.computationCost
|
|
238
|
+
? Number(result.effects.gasUsed.computationCost)
|
|
239
|
+
: undefined,
|
|
240
|
+
error: status === 'failure' ? (result.effects?.status?.error || 'Transaction failed without digest') : undefined,
|
|
241
|
+
};
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.error('Transaction execution failed:', error);
|
|
244
|
+
return {
|
|
245
|
+
digest: '',
|
|
246
|
+
status: 'failure',
|
|
247
|
+
error: error instanceof Error ? error.message : String(error),
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Fallback: Use TransactionService with raw Signer (Node.js/backend)
|
|
253
|
+
if (!this.services.tx) {
|
|
254
|
+
throw new Error('Transaction service not configured.');
|
|
255
|
+
}
|
|
256
|
+
return await this.services.tx.executeTransaction(
|
|
257
|
+
tx,
|
|
258
|
+
signer.getSigner()
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Build batch transaction (combine multiple operations into single PTB)
|
|
264
|
+
*
|
|
265
|
+
* @param operations - Array of typed operations to batch
|
|
266
|
+
* @returns Combined transaction with all move calls
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const tx = pdw.blockchain.tx.buildBatch([
|
|
271
|
+
* { type: 'createMemory', options: { ... } },
|
|
272
|
+
* { type: 'createMemory', options: { ... } },
|
|
273
|
+
* ]);
|
|
274
|
+
* const result = await pdw.blockchain.tx.execute(tx);
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
buildBatch(operations: BatchOperation[]): Transaction {
|
|
278
|
+
if (!this.services.tx) {
|
|
279
|
+
throw new Error('Transaction service not configured.');
|
|
280
|
+
}
|
|
281
|
+
return this.services.tx.buildBatchTransaction(operations);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Build and execute batch transaction in one call
|
|
286
|
+
*
|
|
287
|
+
* @param operations - Array of typed operations to batch
|
|
288
|
+
* @param gasBudget - Optional gas budget override
|
|
289
|
+
* @returns Transaction result with digest and status
|
|
290
|
+
*/
|
|
291
|
+
async executeBatch(operations: BatchOperation[], gasBudget?: number): Promise<TransactionResult> {
|
|
292
|
+
if (!this.services.tx) {
|
|
293
|
+
throw new Error('Transaction service not configured.');
|
|
294
|
+
}
|
|
295
|
+
return await this.services.tx.executeBatch(
|
|
296
|
+
operations,
|
|
297
|
+
this.services.config.signer.getSigner(),
|
|
298
|
+
{ gasBudget }
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Estimate gas cost for transaction
|
|
304
|
+
*
|
|
305
|
+
* @param tx - Transaction to estimate
|
|
306
|
+
* @returns Estimated gas cost
|
|
307
|
+
*/
|
|
308
|
+
async estimateGas(tx: Transaction): Promise<number> {
|
|
309
|
+
if (!this.services.tx) {
|
|
310
|
+
throw new Error('Transaction service not configured.');
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const dryRun = await this.services.config.sui.client.dryRunTransactionBlock({
|
|
314
|
+
transactionBlock: await tx.build({ client: this.services.config.sui.client })
|
|
315
|
+
});
|
|
316
|
+
const gasUsed = dryRun.effects.gasUsed;
|
|
317
|
+
return Number(gasUsed.computationCost) +
|
|
318
|
+
Number(gasUsed.storageCost) -
|
|
319
|
+
Number(gasUsed.storageRebate);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
throw new Error(`Gas estimation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Wait for transaction confirmation
|
|
327
|
+
*
|
|
328
|
+
* @param digest - Transaction digest
|
|
329
|
+
* @returns Transaction effects
|
|
330
|
+
*/
|
|
331
|
+
async waitForConfirmation(digest: string): Promise<TransactionResult> {
|
|
332
|
+
if (!this.services.tx) {
|
|
333
|
+
throw new Error('Transaction service not configured.');
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const result = await this.services.config.sui.client.waitForTransaction({
|
|
337
|
+
digest,
|
|
338
|
+
options: {
|
|
339
|
+
showEffects: true,
|
|
340
|
+
showObjectChanges: true,
|
|
341
|
+
showEvents: true
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
digest: result.digest,
|
|
346
|
+
status: result.effects?.status?.status === 'success' ? 'success' : 'failure',
|
|
347
|
+
effects: result.effects,
|
|
348
|
+
gasUsed: result.effects?.gasUsed?.computationCost
|
|
349
|
+
? Number(result.effects.gasUsed.computationCost)
|
|
350
|
+
: undefined
|
|
351
|
+
};
|
|
352
|
+
} catch (error) {
|
|
353
|
+
throw new Error(`Wait for confirmation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Wallet sub-namespace
|
|
360
|
+
*/
|
|
361
|
+
class WalletSubNamespace {
|
|
362
|
+
constructor(private services: ServiceContainer) {}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Get current wallet address
|
|
366
|
+
*
|
|
367
|
+
* @returns Wallet address
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const address = await pdw.blockchain.wallet.getAddress();
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
async getAddress(): Promise<string> {
|
|
375
|
+
return this.services.config.userAddress;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Check if wallet is connected/ready
|
|
380
|
+
*
|
|
381
|
+
* @returns Connection status
|
|
382
|
+
*/
|
|
383
|
+
async isConnected(): Promise<boolean> {
|
|
384
|
+
try {
|
|
385
|
+
const address = await this.getAddress();
|
|
386
|
+
return !!address && address.startsWith('0x');
|
|
387
|
+
} catch {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Get wallet info
|
|
394
|
+
*
|
|
395
|
+
* @returns Wallet information
|
|
396
|
+
*/
|
|
397
|
+
async getInfo(): Promise<WalletInfo> {
|
|
398
|
+
return {
|
|
399
|
+
address: this.services.config.userAddress,
|
|
400
|
+
connected: await this.isConnected(),
|
|
401
|
+
network: this.services.config.sui?.network || 'testnet',
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Get SUI balance
|
|
407
|
+
*
|
|
408
|
+
* @returns Balance in MIST (smallest unit)
|
|
409
|
+
*/
|
|
410
|
+
async getBalance(): Promise<bigint> {
|
|
411
|
+
const suiClient = this.services.config.sui?.client;
|
|
412
|
+
if (!suiClient) {
|
|
413
|
+
throw new Error('SuiClient not initialized');
|
|
414
|
+
}
|
|
415
|
+
const balance = await suiClient.getBalance({
|
|
416
|
+
owner: this.services.config.userAddress,
|
|
417
|
+
coinType: '0x2::sui::SUI',
|
|
418
|
+
});
|
|
419
|
+
return BigInt(balance.totalBalance);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Get formatted SUI balance
|
|
424
|
+
*
|
|
425
|
+
* @returns Balance in SUI (human readable)
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const balance = await pdw.blockchain.wallet.getFormattedBalance();
|
|
430
|
+
* console.log('Balance:', balance); // "1.2345 SUI"
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
async getFormattedBalance(): Promise<string> {
|
|
434
|
+
const balanceMist = await this.getBalance();
|
|
435
|
+
const balanceSui = Number(balanceMist) / 1_000_000_000;
|
|
436
|
+
return `${balanceSui.toFixed(4)} SUI`;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Get all owned objects of a specific type
|
|
441
|
+
*
|
|
442
|
+
* @param structType - Move struct type (e.g., "0x123::memory::Memory")
|
|
443
|
+
* @returns Array of owned objects
|
|
444
|
+
*/
|
|
445
|
+
async getOwnedObjects(structType: string): Promise<OwnedObject[]> {
|
|
446
|
+
const suiClient = this.services.config.sui?.client;
|
|
447
|
+
if (!suiClient) {
|
|
448
|
+
throw new Error('SuiClient not initialized');
|
|
449
|
+
}
|
|
450
|
+
const response = await suiClient.getOwnedObjects({
|
|
451
|
+
owner: this.services.config.userAddress,
|
|
452
|
+
filter: { StructType: structType },
|
|
453
|
+
options: { showContent: true, showType: true },
|
|
454
|
+
});
|
|
455
|
+
return response.data.map(obj => ({
|
|
456
|
+
id: obj.data?.objectId || '',
|
|
457
|
+
type: obj.data?.type || '',
|
|
458
|
+
version: obj.data?.version || '',
|
|
459
|
+
digest: obj.data?.digest || '',
|
|
460
|
+
}));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Get all MemoryCap objects owned by user
|
|
465
|
+
*
|
|
466
|
+
* @returns Array of MemoryCap object IDs
|
|
467
|
+
*/
|
|
468
|
+
async getMemoryCaps(): Promise<OwnedObject[]> {
|
|
469
|
+
const packageId = this.services.config.sui?.packageId;
|
|
470
|
+
if (!packageId) {
|
|
471
|
+
throw new Error('Package ID not configured');
|
|
472
|
+
}
|
|
473
|
+
return await this.getOwnedObjects(`${packageId}::capability::MemoryCap`);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Get all Memory objects owned by user
|
|
478
|
+
*
|
|
479
|
+
* @returns Array of Memory object IDs
|
|
480
|
+
*/
|
|
481
|
+
async getMemories(): Promise<OwnedObject[]> {
|
|
482
|
+
const packageId = this.services.config.sui?.packageId;
|
|
483
|
+
if (!packageId) {
|
|
484
|
+
throw new Error('Package ID not configured');
|
|
485
|
+
}
|
|
486
|
+
return await this.getOwnedObjects(`${packageId}::memory::Memory`);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Sign a message with the connected wallet
|
|
491
|
+
*
|
|
492
|
+
* @param message - Message to sign (string or bytes)
|
|
493
|
+
* @returns Signature as hex string
|
|
494
|
+
*/
|
|
495
|
+
async signMessage(message: string | Uint8Array): Promise<string> {
|
|
496
|
+
const signer = this.services.config.signer;
|
|
497
|
+
const messageBytes = typeof message === 'string'
|
|
498
|
+
? new TextEncoder().encode(message)
|
|
499
|
+
: message;
|
|
500
|
+
const result = await signer.signPersonalMessage(messageBytes);
|
|
501
|
+
if (typeof result === 'string') {
|
|
502
|
+
return result;
|
|
503
|
+
}
|
|
504
|
+
if (result && typeof result === 'object' && 'signature' in result) {
|
|
505
|
+
return result.signature as string;
|
|
506
|
+
}
|
|
507
|
+
throw new Error('Unexpected signature format');
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Get object by ID
|
|
512
|
+
*
|
|
513
|
+
* @param objectId - Object ID to fetch
|
|
514
|
+
* @returns Object data or null
|
|
515
|
+
*/
|
|
516
|
+
async getObject(objectId: string): Promise<any | null> {
|
|
517
|
+
const suiClient = this.services.config.sui?.client;
|
|
518
|
+
if (!suiClient) {
|
|
519
|
+
throw new Error('SuiClient not initialized');
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
const response = await suiClient.getObject({
|
|
523
|
+
id: objectId,
|
|
524
|
+
options: { showContent: true, showOwner: true, showType: true },
|
|
525
|
+
});
|
|
526
|
+
return response.data || null;
|
|
527
|
+
} catch {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// ============================================================================
|
|
534
|
+
// Blockchain Namespace
|
|
535
|
+
// ============================================================================
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Blockchain Namespace - Unified Sui Operations
|
|
539
|
+
*
|
|
540
|
+
* Consolidates transaction building/execution and wallet operations.
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```typescript
|
|
544
|
+
* // Transaction operations
|
|
545
|
+
* const tx = pdw.blockchain.tx.buildCreate({ ... });
|
|
546
|
+
* const result = await pdw.blockchain.tx.execute(tx);
|
|
547
|
+
*
|
|
548
|
+
* // Wallet operations
|
|
549
|
+
* const address = await pdw.blockchain.wallet.getAddress();
|
|
550
|
+
* const balance = await pdw.blockchain.wallet.getFormattedBalance();
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
export class BlockchainNamespace {
|
|
554
|
+
private _tx: TxSubNamespace;
|
|
555
|
+
private _wallet: WalletSubNamespace;
|
|
556
|
+
|
|
557
|
+
constructor(private services: ServiceContainer) {
|
|
558
|
+
this._tx = new TxSubNamespace(services);
|
|
559
|
+
this._wallet = new WalletSubNamespace(services);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Transaction operations
|
|
564
|
+
*/
|
|
565
|
+
get tx(): TxSubNamespace {
|
|
566
|
+
return this._tx;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Wallet operations
|
|
571
|
+
*/
|
|
572
|
+
get wallet(): WalletSubNamespace {
|
|
573
|
+
return this._wallet;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// ==========================================================================
|
|
577
|
+
// Convenience Methods (Top-level shortcuts)
|
|
578
|
+
// ==========================================================================
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Get current wallet address (shortcut)
|
|
582
|
+
*
|
|
583
|
+
* @returns Wallet address
|
|
584
|
+
*/
|
|
585
|
+
async getAddress(): Promise<string> {
|
|
586
|
+
return this._wallet.getAddress();
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Get SUI balance (shortcut)
|
|
591
|
+
*
|
|
592
|
+
* @returns Balance in MIST
|
|
593
|
+
*/
|
|
594
|
+
async getBalance(): Promise<bigint> {
|
|
595
|
+
return this._wallet.getBalance();
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Execute a transaction (shortcut)
|
|
600
|
+
*
|
|
601
|
+
* @param tx - Transaction to execute
|
|
602
|
+
* @returns Transaction result
|
|
603
|
+
*/
|
|
604
|
+
async execute(tx: Transaction): Promise<TransactionResult> {
|
|
605
|
+
return this._tx.execute(tx);
|
|
606
|
+
}
|
|
607
|
+
}
|