@cmdoss/memwal-sdk 0.6.2 → 0.7.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 +181 -181
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/client/PersonalDataWallet.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +1 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +16 -7
- 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 +27 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +104 -0
- 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.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +22 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/graph/GraphService.js +1 -1
- 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/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/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/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 +10 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +13 -0
- package/dist/services/StorageService.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/index.ts +8 -8
- package/src/aggregation/index.ts +8 -8
- package/src/ai-sdk/tools.ts +2 -2
- package/src/client/SimplePDWClient.ts +23 -8
- package/src/client/namespaces/EmbeddingsNamespace.ts +1 -1
- package/src/client/namespaces/MemoryNamespace.ts +137 -0
- package/src/client/namespaces/consolidated/AINamespace.ts +2 -2
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +20 -2
- package/src/client/signers/DappKitSigner.ts +207 -207
- package/src/core/types/index.ts +1 -1
- package/src/generated/pdw/deps/sui/object.ts +12 -12
- package/src/generated/pdw/deps/sui/vec_map.ts +32 -32
- package/src/generated/pdw/memory.ts +1087 -1087
- package/src/generated/pdw/wallet.ts +123 -123
- package/src/generated/utils/index.ts +159 -159
- package/src/graph/GraphService.ts +1 -1
- package/src/index.ts +25 -1
- package/src/permissions/index.ts +9 -9
- package/src/retrieval/MemoryRetrievalService.ts +78 -4
- package/src/services/EmbeddingService.ts +66 -1
- package/src/services/IndexManager.ts +18 -45
- package/src/services/QueryService.ts +1 -1
- package/src/services/StorageService.ts +15 -0
- package/src/services/storage/QuiltBatchManager.ts +492 -22
- package/src/services/storage/index.ts +6 -1
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndexNode.ts +453 -106
- package/src/vector/HnswWasmService.ts +95 -43
- package/src/vector/IHnswService.ts +10 -1
- package/src/vector/NodeHnswService.ts +103 -5
- package/src/vector/createHnswService.ts +1 -1
- package/src/vector/index.ts +1 -1
- package/src/wallet/index.ts +17 -17
|
@@ -1132,4 +1132,141 @@ export class MemoryNamespace {
|
|
|
1132
1132
|
throw new Error(`Failed to export memories: ${error instanceof Error ? error.message : String(error)}`);
|
|
1133
1133
|
}
|
|
1134
1134
|
}
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Index memories from a Quilt into the local HNSW index
|
|
1138
|
+
*
|
|
1139
|
+
* This allows Quilt batch-uploaded memories to be searchable via vector search.
|
|
1140
|
+
* The method fetches memory packages from the Quilt and indexes each one.
|
|
1141
|
+
*
|
|
1142
|
+
* @param quiltId - The Quilt blob ID containing memory packages
|
|
1143
|
+
* @param options - Indexing options
|
|
1144
|
+
* @returns Result with number of memories indexed
|
|
1145
|
+
*
|
|
1146
|
+
* @example
|
|
1147
|
+
* ```typescript
|
|
1148
|
+
* // After uploading a batch via Quilt
|
|
1149
|
+
* const result = await pdw.memory.indexFromQuilt('GTNhNTdWecbUVg3cZuC_VKlRSzJE3iQfBkojWUuwoh0');
|
|
1150
|
+
* console.log(`Indexed ${result.indexed} memories from Quilt`);
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
async indexFromQuilt(
|
|
1154
|
+
quiltId: string,
|
|
1155
|
+
options?: { forceReindex?: boolean }
|
|
1156
|
+
): Promise<{
|
|
1157
|
+
success: boolean;
|
|
1158
|
+
total: number;
|
|
1159
|
+
indexed: number;
|
|
1160
|
+
skipped: number;
|
|
1161
|
+
failed: number;
|
|
1162
|
+
errors: string[];
|
|
1163
|
+
}> {
|
|
1164
|
+
const errors: string[] = [];
|
|
1165
|
+
let indexed = 0;
|
|
1166
|
+
let skipped = 0;
|
|
1167
|
+
let failed = 0;
|
|
1168
|
+
|
|
1169
|
+
try {
|
|
1170
|
+
console.log(`📦 Indexing memories from Quilt ${quiltId}...`);
|
|
1171
|
+
|
|
1172
|
+
// Check if index service is available
|
|
1173
|
+
if (!this.services.memoryIndex) {
|
|
1174
|
+
throw new Error('Memory index service not available');
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// Check if quilt manager is available
|
|
1178
|
+
if (!this.services.storage?.quiltBatchManager) {
|
|
1179
|
+
throw new Error('Quilt batch manager not available');
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// Fetch all memory packages from the Quilt
|
|
1183
|
+
const packages = await this.services.storage.quiltBatchManager.getAllMemoryPackages(quiltId);
|
|
1184
|
+
console.log(` Found ${packages.length} memory packages in Quilt`);
|
|
1185
|
+
|
|
1186
|
+
// Index each memory
|
|
1187
|
+
for (const pkg of packages) {
|
|
1188
|
+
try {
|
|
1189
|
+
const { identifier, memoryPackage, tags } = pkg;
|
|
1190
|
+
|
|
1191
|
+
// Skip if no embedding
|
|
1192
|
+
if (!memoryPackage.embedding || memoryPackage.embedding.length === 0) {
|
|
1193
|
+
console.warn(` ⚠️ Skipping ${identifier}: no embedding`);
|
|
1194
|
+
skipped++;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// Create a unique memory ID from identifier or use memoryId from metadata
|
|
1199
|
+
const memoryId = memoryPackage.metadata?.memoryId as string ||
|
|
1200
|
+
identifier.replace('.json', '').replace('memory-', '');
|
|
1201
|
+
|
|
1202
|
+
// Build metadata for indexing (satisfy MemoryMetadata interface)
|
|
1203
|
+
const metadata = {
|
|
1204
|
+
category: memoryPackage.metadata?.category || 'general',
|
|
1205
|
+
importance: memoryPackage.metadata?.importance || 3,
|
|
1206
|
+
topic: memoryPackage.metadata?.topic || '',
|
|
1207
|
+
contentType: 'text',
|
|
1208
|
+
contentSize: memoryPackage.content?.length || 0,
|
|
1209
|
+
contentHash: '', // Not available from Quilt package
|
|
1210
|
+
embeddingDimension: memoryPackage.embedding?.length || 0,
|
|
1211
|
+
createdTimestamp: memoryPackage.timestamp,
|
|
1212
|
+
customMetadata: {
|
|
1213
|
+
quiltId,
|
|
1214
|
+
identifier,
|
|
1215
|
+
...Object.fromEntries(
|
|
1216
|
+
Object.entries(memoryPackage.metadata || {}).map(([k, v]) => [k, String(v)])
|
|
1217
|
+
)
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
// Content is empty if encrypted, use placeholder
|
|
1222
|
+
const content = memoryPackage.content || '[encrypted]';
|
|
1223
|
+
const isEncrypted = memoryPackage.encrypted === true;
|
|
1224
|
+
|
|
1225
|
+
// Index the memory
|
|
1226
|
+
await this.services.memoryIndex.indexMemory(
|
|
1227
|
+
this.services.config.userAddress,
|
|
1228
|
+
memoryId,
|
|
1229
|
+
quiltId, // Use quiltId as blobId for retrieval reference
|
|
1230
|
+
content,
|
|
1231
|
+
metadata,
|
|
1232
|
+
memoryPackage.embedding,
|
|
1233
|
+
{ isEncrypted }
|
|
1234
|
+
);
|
|
1235
|
+
|
|
1236
|
+
indexed++;
|
|
1237
|
+
console.log(` ✅ Indexed ${identifier} (${indexed}/${packages.length})`);
|
|
1238
|
+
|
|
1239
|
+
} catch (pkgError) {
|
|
1240
|
+
const errMsg = pkgError instanceof Error ? pkgError.message : String(pkgError);
|
|
1241
|
+
errors.push(`${pkg.identifier}: ${errMsg}`);
|
|
1242
|
+
failed++;
|
|
1243
|
+
console.error(` ❌ Failed to index ${pkg.identifier}:`, errMsg);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
console.log(`\n📊 Quilt indexing complete:`);
|
|
1248
|
+
console.log(` Total: ${packages.length}, Indexed: ${indexed}, Skipped: ${skipped}, Failed: ${failed}`);
|
|
1249
|
+
|
|
1250
|
+
return {
|
|
1251
|
+
success: failed === 0,
|
|
1252
|
+
total: packages.length,
|
|
1253
|
+
indexed,
|
|
1254
|
+
skipped,
|
|
1255
|
+
failed,
|
|
1256
|
+
errors
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
1261
|
+
console.error(`❌ Failed to index from Quilt: ${errMsg}`);
|
|
1262
|
+
return {
|
|
1263
|
+
success: false,
|
|
1264
|
+
total: 0,
|
|
1265
|
+
indexed,
|
|
1266
|
+
skipped,
|
|
1267
|
+
failed,
|
|
1268
|
+
errors: [errMsg, ...errors]
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1135
1272
|
}
|
|
@@ -76,12 +76,12 @@ export class AINamespace {
|
|
|
76
76
|
*
|
|
77
77
|
* @param text - Text to embed
|
|
78
78
|
* @param options - Embedding options
|
|
79
|
-
* @returns Embedding vector (
|
|
79
|
+
* @returns Embedding vector (3072 dimensions for Gemini)
|
|
80
80
|
*
|
|
81
81
|
* @example
|
|
82
82
|
* ```typescript
|
|
83
83
|
* const vector = await pdw.ai.embed('My favorite color is blue');
|
|
84
|
-
* console.log(vector.length); //
|
|
84
|
+
* console.log(vector.length); // 3072
|
|
85
85
|
* ```
|
|
86
86
|
*/
|
|
87
87
|
async embed(text: string, options?: EmbedOptions): Promise<number[]> {
|
|
@@ -165,7 +165,25 @@ class TxSubNamespace {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
// Determine status from effects
|
|
168
|
-
|
|
168
|
+
// dapp-kit may not return full effects structure unless custom execute is configured
|
|
169
|
+
// We check multiple indicators:
|
|
170
|
+
// 1. If effects.status.status explicitly says 'failure', it failed
|
|
171
|
+
// 2. If effects.status.status says 'success', it succeeded
|
|
172
|
+
// 3. If we have a digest but no effects status, assume success (tx was submitted and confirmed)
|
|
173
|
+
let status: 'success' | 'failure';
|
|
174
|
+
const effectsStatus = result.effects?.status?.status;
|
|
175
|
+
|
|
176
|
+
if (effectsStatus === 'failure') {
|
|
177
|
+
status = 'failure';
|
|
178
|
+
} else if (effectsStatus === 'success') {
|
|
179
|
+
status = 'success';
|
|
180
|
+
} else if (result.digest) {
|
|
181
|
+
// Has digest but no explicit status - DappKitSigner waits for confirmation
|
|
182
|
+
// If we reach here without error, the transaction was successful
|
|
183
|
+
status = 'success';
|
|
184
|
+
} else {
|
|
185
|
+
status = 'failure';
|
|
186
|
+
}
|
|
169
187
|
|
|
170
188
|
return {
|
|
171
189
|
digest: result.digest,
|
|
@@ -176,7 +194,7 @@ class TxSubNamespace {
|
|
|
176
194
|
gasUsed: result.effects?.gasUsed?.computationCost
|
|
177
195
|
? Number(result.effects.gasUsed.computationCost)
|
|
178
196
|
: undefined,
|
|
179
|
-
error: status === 'failure' ? result.effects?.status?.error : undefined,
|
|
197
|
+
error: status === 'failure' ? (result.effects?.status?.error || 'Transaction failed without digest') : undefined,
|
|
180
198
|
};
|
|
181
199
|
} catch (error) {
|
|
182
200
|
console.error('Transaction execution failed:', error);
|
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DappKit Signer Implementation
|
|
3
|
-
*
|
|
4
|
-
* Adapter for @mysten/dapp-kit hooks to work with SimplePDWClient.
|
|
5
|
-
* Bridges dApp-kit's hook-based API with SDK's UnifiedSigner interface.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { DappKitSigner, createSimplePDWClient } from '@cmdoss/memwal-sdk';
|
|
10
|
-
* import { useCurrentAccount, useSignAndExecuteTransaction, useSuiClient } from '@mysten/dapp-kit';
|
|
11
|
-
*
|
|
12
|
-
* function MyComponent() {
|
|
13
|
-
* const account = useCurrentAccount();
|
|
14
|
-
* const client = useSuiClient();
|
|
15
|
-
* const { mutateAsync: signAndExecute } = useSignAndExecuteTransaction();
|
|
16
|
-
*
|
|
17
|
-
* const signer = useMemo(() => {
|
|
18
|
-
* if (!account) return null;
|
|
19
|
-
* return new DappKitSigner({
|
|
20
|
-
* address: account.address,
|
|
21
|
-
* client,
|
|
22
|
-
* signAndExecuteTransaction: signAndExecute,
|
|
23
|
-
* });
|
|
24
|
-
* }, [account, client, signAndExecute]);
|
|
25
|
-
*
|
|
26
|
-
* // Now use signer with SDK
|
|
27
|
-
* const pdw = await createSimplePDWClient({ signer, network: 'testnet' });
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @module client/signers
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
import type { Transaction } from '@mysten/sui/transactions';
|
|
35
|
-
import type { SuiClient } from '@mysten/sui/client';
|
|
36
|
-
import type { Signer } from '@mysten/sui/cryptography';
|
|
37
|
-
import type {
|
|
38
|
-
UnifiedSigner,
|
|
39
|
-
SignAndExecuteResult,
|
|
40
|
-
SignPersonalMessageResult
|
|
41
|
-
} from './UnifiedSigner';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Function signature for dApp-kit's signAndExecuteTransaction
|
|
45
|
-
* Compatible with useSignAndExecuteTransaction().mutateAsync
|
|
46
|
-
*/
|
|
47
|
-
export interface DappKitSignAndExecuteFn {
|
|
48
|
-
(params: { transaction: Transaction }): Promise<{
|
|
49
|
-
digest: string;
|
|
50
|
-
effects?: any;
|
|
51
|
-
events?: any[];
|
|
52
|
-
objectChanges?: any[];
|
|
53
|
-
}>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Function signature for dApp-kit's signPersonalMessage
|
|
58
|
-
* Compatible with useSignPersonalMessage().mutateAsync
|
|
59
|
-
*/
|
|
60
|
-
export interface DappKitSignPersonalMessageFn {
|
|
61
|
-
(params: { message: Uint8Array }): Promise<{
|
|
62
|
-
signature: string;
|
|
63
|
-
bytes?: Uint8Array;
|
|
64
|
-
}>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Configuration for DappKitSigner
|
|
69
|
-
*/
|
|
70
|
-
export interface DappKitSignerConfig {
|
|
71
|
-
/**
|
|
72
|
-
* User's Sui address (from useCurrentAccount().address)
|
|
73
|
-
*/
|
|
74
|
-
address: string;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* SuiClient instance (from useSuiClient())
|
|
78
|
-
*/
|
|
79
|
-
client: SuiClient;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* signAndExecuteTransaction function (from useSignAndExecuteTransaction().mutateAsync)
|
|
83
|
-
*/
|
|
84
|
-
signAndExecuteTransaction: DappKitSignAndExecuteFn;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* signPersonalMessage function (from useSignPersonalMessage().mutateAsync)
|
|
88
|
-
* Optional - only required for operations that need message signing
|
|
89
|
-
*/
|
|
90
|
-
signPersonalMessage?: DappKitSignPersonalMessageFn;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Public key bytes (optional, from useCurrentAccount().publicKey)
|
|
94
|
-
*/
|
|
95
|
-
publicKey?: Uint8Array;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* DappKitSigner - Adapter for @mysten/dapp-kit hooks
|
|
100
|
-
*
|
|
101
|
-
* Wraps dApp-kit's useSignAndExecuteTransaction and useSignPersonalMessage hooks
|
|
102
|
-
* to provide a UnifiedSigner interface compatible with SDK managers.
|
|
103
|
-
*
|
|
104
|
-
* This adapter does NOT depend on React - it accepts function references
|
|
105
|
-
* that can come from dApp-kit hooks or any other source with compatible signatures.
|
|
106
|
-
*/
|
|
107
|
-
export class DappKitSigner implements UnifiedSigner {
|
|
108
|
-
private config: DappKitSignerConfig;
|
|
109
|
-
|
|
110
|
-
constructor(config: DappKitSignerConfig) {
|
|
111
|
-
if (!config.address) {
|
|
112
|
-
throw new Error('DappKitSigner requires an address');
|
|
113
|
-
}
|
|
114
|
-
if (!config.client) {
|
|
115
|
-
throw new Error('DappKitSigner requires a SuiClient');
|
|
116
|
-
}
|
|
117
|
-
if (!config.signAndExecuteTransaction) {
|
|
118
|
-
throw new Error('DappKitSigner requires signAndExecuteTransaction function');
|
|
119
|
-
}
|
|
120
|
-
this.config = config;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sign and execute transaction using dApp-kit hook
|
|
125
|
-
*
|
|
126
|
-
* Wraps the dApp-kit signAndExecuteTransaction function and waits for
|
|
127
|
-
* transaction finalization to prevent gas coin version conflicts.
|
|
128
|
-
*/
|
|
129
|
-
async signAndExecuteTransaction(transaction: Transaction): Promise<SignAndExecuteResult> {
|
|
130
|
-
const result = await this.config.signAndExecuteTransaction({ transaction });
|
|
131
|
-
|
|
132
|
-
// Wait for transaction to be finalized (important for gas coin versioning)
|
|
133
|
-
if (result.digest) {
|
|
134
|
-
try {
|
|
135
|
-
await this.config.client.waitForTransaction({ digest: result.digest });
|
|
136
|
-
} catch (waitError) {
|
|
137
|
-
console.warn('DappKitSigner: waitForTransaction failed:', waitError);
|
|
138
|
-
// Continue anyway - transaction was submitted
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
digest: result.digest,
|
|
144
|
-
effects: result.effects,
|
|
145
|
-
events: result.events,
|
|
146
|
-
objectChanges: result.objectChanges,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Sign personal message using dApp-kit hook
|
|
152
|
-
*
|
|
153
|
-
* Required for SEAL encryption identity and other message signing operations.
|
|
154
|
-
*/
|
|
155
|
-
async signPersonalMessage(message: Uint8Array): Promise<SignPersonalMessageResult> {
|
|
156
|
-
if (!this.config.signPersonalMessage) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
'DappKitSigner: signPersonalMessage not configured. ' +
|
|
159
|
-
'Pass signPersonalMessage function from useSignPersonalMessage().mutateAsync'
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const result = await this.config.signPersonalMessage({ message });
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
signature: result.signature,
|
|
167
|
-
bytes: result.bytes || message,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Get Sui address
|
|
173
|
-
*/
|
|
174
|
-
getAddress(): string {
|
|
175
|
-
return this.config.address;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get public key (if available)
|
|
180
|
-
*/
|
|
181
|
-
getPublicKey(): Uint8Array | null {
|
|
182
|
-
return this.config.publicKey || null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Get underlying Signer
|
|
187
|
-
*
|
|
188
|
-
* Note: dApp-kit does not expose the underlying Signer for security reasons.
|
|
189
|
-
* Use KeypairSigner for backend/Node.js environments that need raw Signer access.
|
|
190
|
-
*/
|
|
191
|
-
getSigner(): Signer {
|
|
192
|
-
throw new Error(
|
|
193
|
-
'DappKitSigner does not expose underlying Signer. ' +
|
|
194
|
-
'Browser wallets do not provide raw Signer access for security. ' +
|
|
195
|
-
'Use KeypairSigner for backend/Node.js environments.'
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Get SuiClient
|
|
201
|
-
*
|
|
202
|
-
* Returns the SuiClient instance for managers that need to build transactions.
|
|
203
|
-
*/
|
|
204
|
-
getClient(): SuiClient {
|
|
205
|
-
return this.config.client;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* DappKit Signer Implementation
|
|
3
|
+
*
|
|
4
|
+
* Adapter for @mysten/dapp-kit hooks to work with SimplePDWClient.
|
|
5
|
+
* Bridges dApp-kit's hook-based API with SDK's UnifiedSigner interface.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { DappKitSigner, createSimplePDWClient } from '@cmdoss/memwal-sdk';
|
|
10
|
+
* import { useCurrentAccount, useSignAndExecuteTransaction, useSuiClient } from '@mysten/dapp-kit';
|
|
11
|
+
*
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* const account = useCurrentAccount();
|
|
14
|
+
* const client = useSuiClient();
|
|
15
|
+
* const { mutateAsync: signAndExecute } = useSignAndExecuteTransaction();
|
|
16
|
+
*
|
|
17
|
+
* const signer = useMemo(() => {
|
|
18
|
+
* if (!account) return null;
|
|
19
|
+
* return new DappKitSigner({
|
|
20
|
+
* address: account.address,
|
|
21
|
+
* client,
|
|
22
|
+
* signAndExecuteTransaction: signAndExecute,
|
|
23
|
+
* });
|
|
24
|
+
* }, [account, client, signAndExecute]);
|
|
25
|
+
*
|
|
26
|
+
* // Now use signer with SDK
|
|
27
|
+
* const pdw = await createSimplePDWClient({ signer, network: 'testnet' });
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @module client/signers
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
35
|
+
import type { SuiClient } from '@mysten/sui/client';
|
|
36
|
+
import type { Signer } from '@mysten/sui/cryptography';
|
|
37
|
+
import type {
|
|
38
|
+
UnifiedSigner,
|
|
39
|
+
SignAndExecuteResult,
|
|
40
|
+
SignPersonalMessageResult
|
|
41
|
+
} from './UnifiedSigner';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Function signature for dApp-kit's signAndExecuteTransaction
|
|
45
|
+
* Compatible with useSignAndExecuteTransaction().mutateAsync
|
|
46
|
+
*/
|
|
47
|
+
export interface DappKitSignAndExecuteFn {
|
|
48
|
+
(params: { transaction: Transaction }): Promise<{
|
|
49
|
+
digest: string;
|
|
50
|
+
effects?: any;
|
|
51
|
+
events?: any[];
|
|
52
|
+
objectChanges?: any[];
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Function signature for dApp-kit's signPersonalMessage
|
|
58
|
+
* Compatible with useSignPersonalMessage().mutateAsync
|
|
59
|
+
*/
|
|
60
|
+
export interface DappKitSignPersonalMessageFn {
|
|
61
|
+
(params: { message: Uint8Array }): Promise<{
|
|
62
|
+
signature: string;
|
|
63
|
+
bytes?: Uint8Array;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for DappKitSigner
|
|
69
|
+
*/
|
|
70
|
+
export interface DappKitSignerConfig {
|
|
71
|
+
/**
|
|
72
|
+
* User's Sui address (from useCurrentAccount().address)
|
|
73
|
+
*/
|
|
74
|
+
address: string;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* SuiClient instance (from useSuiClient())
|
|
78
|
+
*/
|
|
79
|
+
client: SuiClient;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* signAndExecuteTransaction function (from useSignAndExecuteTransaction().mutateAsync)
|
|
83
|
+
*/
|
|
84
|
+
signAndExecuteTransaction: DappKitSignAndExecuteFn;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* signPersonalMessage function (from useSignPersonalMessage().mutateAsync)
|
|
88
|
+
* Optional - only required for operations that need message signing
|
|
89
|
+
*/
|
|
90
|
+
signPersonalMessage?: DappKitSignPersonalMessageFn;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Public key bytes (optional, from useCurrentAccount().publicKey)
|
|
94
|
+
*/
|
|
95
|
+
publicKey?: Uint8Array;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* DappKitSigner - Adapter for @mysten/dapp-kit hooks
|
|
100
|
+
*
|
|
101
|
+
* Wraps dApp-kit's useSignAndExecuteTransaction and useSignPersonalMessage hooks
|
|
102
|
+
* to provide a UnifiedSigner interface compatible with SDK managers.
|
|
103
|
+
*
|
|
104
|
+
* This adapter does NOT depend on React - it accepts function references
|
|
105
|
+
* that can come from dApp-kit hooks or any other source with compatible signatures.
|
|
106
|
+
*/
|
|
107
|
+
export class DappKitSigner implements UnifiedSigner {
|
|
108
|
+
private config: DappKitSignerConfig;
|
|
109
|
+
|
|
110
|
+
constructor(config: DappKitSignerConfig) {
|
|
111
|
+
if (!config.address) {
|
|
112
|
+
throw new Error('DappKitSigner requires an address');
|
|
113
|
+
}
|
|
114
|
+
if (!config.client) {
|
|
115
|
+
throw new Error('DappKitSigner requires a SuiClient');
|
|
116
|
+
}
|
|
117
|
+
if (!config.signAndExecuteTransaction) {
|
|
118
|
+
throw new Error('DappKitSigner requires signAndExecuteTransaction function');
|
|
119
|
+
}
|
|
120
|
+
this.config = config;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sign and execute transaction using dApp-kit hook
|
|
125
|
+
*
|
|
126
|
+
* Wraps the dApp-kit signAndExecuteTransaction function and waits for
|
|
127
|
+
* transaction finalization to prevent gas coin version conflicts.
|
|
128
|
+
*/
|
|
129
|
+
async signAndExecuteTransaction(transaction: Transaction): Promise<SignAndExecuteResult> {
|
|
130
|
+
const result = await this.config.signAndExecuteTransaction({ transaction });
|
|
131
|
+
|
|
132
|
+
// Wait for transaction to be finalized (important for gas coin versioning)
|
|
133
|
+
if (result.digest) {
|
|
134
|
+
try {
|
|
135
|
+
await this.config.client.waitForTransaction({ digest: result.digest });
|
|
136
|
+
} catch (waitError) {
|
|
137
|
+
console.warn('DappKitSigner: waitForTransaction failed:', waitError);
|
|
138
|
+
// Continue anyway - transaction was submitted
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
digest: result.digest,
|
|
144
|
+
effects: result.effects,
|
|
145
|
+
events: result.events,
|
|
146
|
+
objectChanges: result.objectChanges,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sign personal message using dApp-kit hook
|
|
152
|
+
*
|
|
153
|
+
* Required for SEAL encryption identity and other message signing operations.
|
|
154
|
+
*/
|
|
155
|
+
async signPersonalMessage(message: Uint8Array): Promise<SignPersonalMessageResult> {
|
|
156
|
+
if (!this.config.signPersonalMessage) {
|
|
157
|
+
throw new Error(
|
|
158
|
+
'DappKitSigner: signPersonalMessage not configured. ' +
|
|
159
|
+
'Pass signPersonalMessage function from useSignPersonalMessage().mutateAsync'
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const result = await this.config.signPersonalMessage({ message });
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
signature: result.signature,
|
|
167
|
+
bytes: result.bytes || message,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get Sui address
|
|
173
|
+
*/
|
|
174
|
+
getAddress(): string {
|
|
175
|
+
return this.config.address;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get public key (if available)
|
|
180
|
+
*/
|
|
181
|
+
getPublicKey(): Uint8Array | null {
|
|
182
|
+
return this.config.publicKey || null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get underlying Signer
|
|
187
|
+
*
|
|
188
|
+
* Note: dApp-kit does not expose the underlying Signer for security reasons.
|
|
189
|
+
* Use KeypairSigner for backend/Node.js environments that need raw Signer access.
|
|
190
|
+
*/
|
|
191
|
+
getSigner(): Signer {
|
|
192
|
+
throw new Error(
|
|
193
|
+
'DappKitSigner does not expose underlying Signer. ' +
|
|
194
|
+
'Browser wallets do not provide raw Signer access for security. ' +
|
|
195
|
+
'Use KeypairSigner for backend/Node.js environments.'
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get SuiClient
|
|
201
|
+
*
|
|
202
|
+
* Returns the SuiClient instance for managers that need to build transactions.
|
|
203
|
+
*/
|
|
204
|
+
getClient(): SuiClient {
|
|
205
|
+
return this.config.client;
|
|
206
|
+
}
|
|
207
|
+
}
|
package/src/core/types/index.ts
CHANGED
|
@@ -232,7 +232,7 @@ export interface VectorEmbedding {
|
|
|
232
232
|
|
|
233
233
|
export interface EmbeddingOptions {
|
|
234
234
|
model?: string;
|
|
235
|
-
dimension?: number; // Default
|
|
235
|
+
dimension?: number; // Default 3072 for Gemini
|
|
236
236
|
normalize?: boolean;
|
|
237
237
|
batchSize?: number; // For batch processing
|
|
238
238
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**************************************************************
|
|
2
|
-
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
-
**************************************************************/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** Sui object identifiers */
|
|
7
|
-
|
|
8
|
-
import { MoveStruct } from '../../../utils/index.js';
|
|
9
|
-
import { bcs } from '@mysten/sui/bcs';
|
|
10
|
-
const $moduleName = '0x2::object';
|
|
11
|
-
export const UID = new MoveStruct({ name: `${$moduleName}::UID`, fields: {
|
|
12
|
-
id: bcs.Address
|
|
1
|
+
/**************************************************************
|
|
2
|
+
* THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *
|
|
3
|
+
**************************************************************/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/** Sui object identifiers */
|
|
7
|
+
|
|
8
|
+
import { MoveStruct } from '../../../utils/index.js';
|
|
9
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
10
|
+
const $moduleName = '0x2::object';
|
|
11
|
+
export const UID = new MoveStruct({ name: `${$moduleName}::UID`, fields: {
|
|
12
|
+
id: bcs.Address
|
|
13
13
|
} });
|