@arcanetech/privacy-sdk-stellar 0.2.0 → 0.2.3
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/index.d.ts +1051 -0
- package/dist/index.js +29 -16
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +739 -0
- package/dist/node.js +29 -16
- package/dist/node.js.map +1 -1
- package/dist/state/index.d.ts +753 -0
- package/dist/testing/index.d.ts +107 -0
- package/dist/testing/index.js +54 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/transact/index.d.ts +399 -0
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -273,11 +273,14 @@ async function commitStorageChanges(input, eventId, receipt) {
|
|
|
273
273
|
});
|
|
274
274
|
if (input.prepared.outputRecords.length > 0) {
|
|
275
275
|
await input.storage.savePrivateRecords(
|
|
276
|
-
input.prepared.outputRecords.map((record) =>
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
276
|
+
input.prepared.outputRecords.map((record) => {
|
|
277
|
+
const nextStatus = receipt.confirmed ? "finalized" : record.status;
|
|
278
|
+
return {
|
|
279
|
+
...record,
|
|
280
|
+
txHash: receipt.operationId,
|
|
281
|
+
...nextStatus === void 0 ? {} : { status: nextStatus }
|
|
282
|
+
};
|
|
283
|
+
})
|
|
281
284
|
);
|
|
282
285
|
}
|
|
283
286
|
if (input.prepared.consumedRecords.length > 0) {
|
|
@@ -333,7 +336,10 @@ import { insufficientStateError as insufficientStateError3 } from "@arcanetech/p
|
|
|
333
336
|
|
|
334
337
|
// src/transact/transfer-source/resolve.ts
|
|
335
338
|
import { Buffer as Buffer2 } from "buffer";
|
|
336
|
-
import {
|
|
339
|
+
import {
|
|
340
|
+
insufficientStateError,
|
|
341
|
+
invalidIntentError
|
|
342
|
+
} from "@arcanetech/privacy-sdk-core";
|
|
337
343
|
var FIELD_HEX_LENGTH = 64;
|
|
338
344
|
var SCALAR_HEX_PATTERN = new RegExp(`^(0x)?[0-9a-f]{${FIELD_HEX_LENGTH}}$`, "iu");
|
|
339
345
|
function hexToDecimal(hex) {
|
|
@@ -366,6 +372,7 @@ function pendingClaimToCoin(claim) {
|
|
|
366
372
|
}
|
|
367
373
|
function pendingClaimToConsumedRecord(input) {
|
|
368
374
|
const coin = pendingClaimToCoin(input.claim);
|
|
375
|
+
const nullifierHex = input.claim.nullifierHex ?? input.claim.futureNullifierHashHex;
|
|
369
376
|
return {
|
|
370
377
|
id: `pending-claim-${input.claim.id}`,
|
|
371
378
|
owner: input.walletPublicKey.trim(),
|
|
@@ -374,9 +381,9 @@ function pendingClaimToConsumedRecord(input) {
|
|
|
374
381
|
consumed: false,
|
|
375
382
|
status: "finalized",
|
|
376
383
|
poolContract: input.poolContract,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
384
|
+
coinNote: coin,
|
|
385
|
+
...input.claim.commitmentHex ? { commitmentHex: input.claim.commitmentHex } : {},
|
|
386
|
+
...nullifierHex ? { nullifierHex } : {}
|
|
380
387
|
};
|
|
381
388
|
}
|
|
382
389
|
function readPendingClaimFromSource(source) {
|
|
@@ -1784,7 +1791,7 @@ async function resolvePendingClaimSpend(intent, deps, walletPublicKey) {
|
|
|
1784
1791
|
await assertPendingClaimNullifierAvailable({
|
|
1785
1792
|
claim,
|
|
1786
1793
|
walletPublicKey,
|
|
1787
|
-
checkNullifierSpent: deps.checkNullifierSpent
|
|
1794
|
+
...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
|
|
1788
1795
|
});
|
|
1789
1796
|
validatePendingClaimIntentMatches(claim, intent);
|
|
1790
1797
|
return {
|
|
@@ -1810,12 +1817,12 @@ async function resolvePrivateAddressSpend(intent, deps) {
|
|
|
1810
1817
|
kind: "transfer",
|
|
1811
1818
|
intent,
|
|
1812
1819
|
walletPublicKey,
|
|
1813
|
-
checkNullifierSpent: deps.checkNullifierSpent
|
|
1820
|
+
...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
|
|
1814
1821
|
});
|
|
1815
1822
|
await assertPrivateRecordsNullifiersAvailable({
|
|
1816
1823
|
records: consumedRecords,
|
|
1817
1824
|
walletPublicKey: walletAddress.trim(),
|
|
1818
|
-
checkNullifierSpent: deps.checkNullifierSpent
|
|
1825
|
+
...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
|
|
1819
1826
|
});
|
|
1820
1827
|
return {
|
|
1821
1828
|
consumedRecords,
|
|
@@ -1897,7 +1904,7 @@ async function resolvePrepareConsumedRecords(input) {
|
|
|
1897
1904
|
storage: input.storage,
|
|
1898
1905
|
intent: input.intent,
|
|
1899
1906
|
walletPublicKey: await loadSpendSelectionWalletPublicKey(input.wallet),
|
|
1900
|
-
checkNullifierSpent: input.checkNullifierSpent
|
|
1907
|
+
...input.checkNullifierSpent ? { checkNullifierSpent: input.checkNullifierSpent } : {}
|
|
1901
1908
|
});
|
|
1902
1909
|
}
|
|
1903
1910
|
function buildDepositOrWithdrawPrepared(input) {
|
|
@@ -5613,7 +5620,8 @@ async function resolveWalletPublicKey(environment, prepared) {
|
|
|
5613
5620
|
return environment.resolveWalletPublicKey();
|
|
5614
5621
|
}
|
|
5615
5622
|
if (prepared.kind === "deposit") {
|
|
5616
|
-
|
|
5623
|
+
const depositIntent = prepared.intent;
|
|
5624
|
+
return depositIntent.from;
|
|
5617
5625
|
}
|
|
5618
5626
|
throw new Error("Wallet public key resolver is not configured.");
|
|
5619
5627
|
}
|
|
@@ -6408,10 +6416,15 @@ function enrichWithdrawOutputRecords(prepared, proof) {
|
|
|
6408
6416
|
}));
|
|
6409
6417
|
}
|
|
6410
6418
|
async function finalizeWithdrawAtExecute(prepared, environment, poolService) {
|
|
6419
|
+
if (prepared.kind !== "withdraw") {
|
|
6420
|
+
throw new Error("Withdraw finalize requires a withdraw operation.");
|
|
6421
|
+
}
|
|
6422
|
+
const withdrawIntent = prepared.intent;
|
|
6423
|
+
const withdrawFrom = withdrawIntent.from;
|
|
6411
6424
|
const context = await buildSpendProofContextAtExecute({
|
|
6412
6425
|
prepared,
|
|
6413
6426
|
environment,
|
|
6414
|
-
recipientPrivateAddressStpl1:
|
|
6427
|
+
recipientPrivateAddressStpl1: withdrawFrom
|
|
6415
6428
|
});
|
|
6416
6429
|
const changeStroops = BigInt(context.coin.value) - prepared.intent.amount;
|
|
6417
6430
|
const proof = await poolService.prepareWithdrawTransactProof({
|
|
@@ -6424,7 +6437,7 @@ async function finalizeWithdrawAtExecute(prepared, environment, poolService) {
|
|
|
6424
6437
|
yHex: context.ephemeral.yHex
|
|
6425
6438
|
}),
|
|
6426
6439
|
withdrawAmountStroops: prepared.intent.amount,
|
|
6427
|
-
changePrivateAddressStpl1: changeStroops > 0n ?
|
|
6440
|
+
changePrivateAddressStpl1: changeStroops > 0n ? withdrawFrom : void 0,
|
|
6428
6441
|
tokenAddress: context.tokenAddress
|
|
6429
6442
|
});
|
|
6430
6443
|
enrichWithdrawOutputRecords(prepared, proof);
|