@nullpay/mcp 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aleo.js +11 -7
- package/dist/service.js +18 -6
- package/package.json +1 -1
package/dist/aleo.js
CHANGED
|
@@ -555,14 +555,18 @@ async function getFreezeListIndex(index) {
|
|
|
555
555
|
return value ? value.replace(/"/g, '') : null;
|
|
556
556
|
}
|
|
557
557
|
async function generateFreezeListProof(targetIndex = 1, occupiedLeafValue) {
|
|
558
|
-
const {
|
|
558
|
+
const { Plaintext } = await (0, esm_1.dynamicImport)('@provablehq/sdk');
|
|
559
|
+
const { Poseidon4 } = await (0, esm_1.dynamicImport)('@provablehq/wasm');
|
|
559
560
|
const hasher = new Poseidon4();
|
|
560
561
|
const emptyHashes = [];
|
|
561
562
|
let currentEmpty = '0field';
|
|
563
|
+
const hashFields = (values) => {
|
|
564
|
+
const plaintext = Plaintext.fromString(`[${values.join(', ')}]`);
|
|
565
|
+
return hasher.hash(plaintext.toFields()).toString();
|
|
566
|
+
};
|
|
562
567
|
for (let level = 0; level < 16; level += 1) {
|
|
563
568
|
emptyHashes.push(currentEmpty);
|
|
564
|
-
|
|
565
|
-
currentEmpty = hasher.hash([field, field]).toString();
|
|
569
|
+
currentEmpty = hashFields([currentEmpty, currentEmpty]);
|
|
566
570
|
}
|
|
567
571
|
let currentHash = '0field';
|
|
568
572
|
let currentIndex = targetIndex;
|
|
@@ -575,12 +579,12 @@ async function generateFreezeListProof(targetIndex = 1, occupiedLeafValue) {
|
|
|
575
579
|
siblingHash = occupiedLeafValue;
|
|
576
580
|
}
|
|
577
581
|
proofSiblings.push(siblingHash);
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
582
|
+
currentHash = isLeft
|
|
583
|
+
? hashFields([currentHash, siblingHash])
|
|
584
|
+
: hashFields([siblingHash, currentHash]);
|
|
581
585
|
currentIndex = Math.floor(currentIndex / 2);
|
|
582
586
|
}
|
|
583
|
-
return `[${proofSiblings.join(', ')}]`;
|
|
587
|
+
return `{ siblings: [${proofSiblings.join(', ')}], leaf_index: ${targetIndex}u32 }`;
|
|
584
588
|
}
|
|
585
589
|
async function createSponsoredPaymentAuthorization(args) {
|
|
586
590
|
const session = await getScannerSession(args.walletPrivateKey);
|
package/dist/service.js
CHANGED
|
@@ -235,18 +235,27 @@ class NullPayMcpService {
|
|
|
235
235
|
let recoveredEncryptedBurnerKey = null;
|
|
236
236
|
let usedRecoveredPassword = false;
|
|
237
237
|
let restoredBurnerFromChain = false;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
let chainBackupLoaded = false;
|
|
239
|
+
const loadChainBackup = async () => {
|
|
240
|
+
if (chainBackupLoaded || !mainPrivateKey) {
|
|
241
|
+
return null;
|
|
241
242
|
}
|
|
243
|
+
chainBackupLoaded = true;
|
|
242
244
|
const recovered = await (0, aleo_1.recoverOnChainWalletBackup)(mainPrivateKey, address);
|
|
243
|
-
if (!recovered
|
|
244
|
-
return
|
|
245
|
+
if (!recovered) {
|
|
246
|
+
return null;
|
|
245
247
|
}
|
|
246
|
-
password = recovered.password;
|
|
247
248
|
recoveredBackupSource = recovered.source;
|
|
248
249
|
recoveredBurnerAddress = recovered.burnerAddress || null;
|
|
249
250
|
recoveredEncryptedBurnerKey = recovered.encryptedBurnerKey || null;
|
|
251
|
+
return recovered;
|
|
252
|
+
};
|
|
253
|
+
const attemptRecovery = async () => {
|
|
254
|
+
const recovered = await loadChainBackup();
|
|
255
|
+
if (!recovered?.password) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
password = recovered.password;
|
|
250
259
|
usedRecoveredPassword = true;
|
|
251
260
|
return true;
|
|
252
261
|
};
|
|
@@ -302,6 +311,9 @@ class NullPayMcpService {
|
|
|
302
311
|
burnerAddress = null;
|
|
303
312
|
}
|
|
304
313
|
}
|
|
314
|
+
if (!encryptedBurnerKey || !burnerAddress || !encryptedBurnerAddress) {
|
|
315
|
+
await loadChainBackup();
|
|
316
|
+
}
|
|
305
317
|
if ((!encryptedBurnerAddress || !encryptedBurnerKey || !burnerAddress) && recoveredBurnerAddress && recoveredEncryptedBurnerKey) {
|
|
306
318
|
burnerAddress = recoveredBurnerAddress;
|
|
307
319
|
encryptedBurnerAddress = await (0, crypto_1.encryptWithPassword)(recoveredBurnerAddress, password);
|