@thesingularitynetwork/darkswap-sdk 0.1.7 → 0.1.8
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.esm.js +13 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +13 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/services/base/withdraw.d.ts +1 -1
- package/dist/types/src/services/noteService.d.ts +1 -0
- package/dist/types/src/services/pro/createOrder.d.ts +2 -2
- package/dist/types/src/types.d.ts +4 -0
- package/dist/types/test/services/joinService.test.d.ts +1 -0
- package/dist/types/test/services/withdrawService.test.d.ts +1 -0
- package/dist/types/test/utils/helpers.d.ts +1 -0
- package/package.json +1 -1
- package/src/proof/retail/depositOrderProof.ts +3 -1
- package/src/services/base/deposit.ts +0 -7
- package/src/services/base/withdraw.ts +8 -4
- package/src/services/noteService.ts +5 -0
- package/src/services/pro/createOrder.ts +6 -4
- package/src/types.ts +5 -0
package/dist/index.esm.js
CHANGED
|
@@ -857,6 +857,10 @@ async function isNoteValid(darkSwap, note, publicKey) {
|
|
|
857
857
|
const onChainStatus = await getNoteOnChainStatus(darkSwap, hexlify32(note.note), hexlify32(nullifier));
|
|
858
858
|
return onChainStatus === NoteOnChainStatus.ACTIVE;
|
|
859
859
|
}
|
|
860
|
+
async function getNullifierBySignature(note, signature) {
|
|
861
|
+
const [publicKey] = await generateKeyPair(signature);
|
|
862
|
+
return hexlify32(calcNullifier(note.rho, publicKey));
|
|
863
|
+
}
|
|
860
864
|
|
|
861
865
|
var abi$a = [
|
|
862
866
|
{
|
|
@@ -2948,7 +2952,6 @@ class DepositService extends BaseContractService {
|
|
|
2948
2952
|
return tx.hash;
|
|
2949
2953
|
}
|
|
2950
2954
|
else {
|
|
2951
|
-
console.log(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2952
2955
|
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: context.depositAmount });
|
|
2953
2956
|
await tx.wait();
|
|
2954
2957
|
return tx.hash;
|
|
@@ -3282,14 +3285,14 @@ class WithdrawService extends BaseContractService {
|
|
|
3282
3285
|
super(_darkSwap);
|
|
3283
3286
|
}
|
|
3284
3287
|
async prepare(address, currentBalance, withdrawAmount, signature) {
|
|
3285
|
-
const [pubKey
|
|
3288
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
3286
3289
|
const newBalanceNote = createNote(address, currentBalance.asset, currentBalance.amount - withdrawAmount, pubKey);
|
|
3287
3290
|
const context = new WithdrawContext(signature);
|
|
3288
3291
|
context.currentBalance = currentBalance;
|
|
3289
3292
|
context.newBalance = newBalanceNote;
|
|
3290
3293
|
context.withdrawAmount = withdrawAmount;
|
|
3291
3294
|
context.address = address;
|
|
3292
|
-
return { context,
|
|
3295
|
+
return { context, newBalanceNote };
|
|
3293
3296
|
}
|
|
3294
3297
|
async generateProof(context) {
|
|
3295
3298
|
if (!context || !context.currentBalance || !context.newBalance || !context.withdrawAmount || !context.address) {
|
|
@@ -3314,7 +3317,8 @@ class WithdrawService extends BaseContractService {
|
|
|
3314
3317
|
throw new DarkSwapError('Invalid context');
|
|
3315
3318
|
}
|
|
3316
3319
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
3317
|
-
const tx = await contract.withdraw(context.merkleRoot, context.proof.oldBalanceNullifier, context.
|
|
3320
|
+
const tx = await contract.withdraw(context.merkleRoot, context.currentBalance.asset, context.withdrawAmount, context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
3321
|
+
await tx.wait();
|
|
3318
3322
|
return tx.hash;
|
|
3319
3323
|
}
|
|
3320
3324
|
}
|
|
@@ -4399,6 +4403,7 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4399
4403
|
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
4404
|
const [pubKey] = await generateKeyPair(signature);
|
|
4401
4405
|
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4406
|
+
const orderNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
4402
4407
|
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4403
4408
|
const context = new ProCreateOrderContext(signature);
|
|
4404
4409
|
context.orderNote = orderNote;
|
|
@@ -4407,7 +4412,7 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4407
4412
|
context.oldBalance = balanceNote;
|
|
4408
4413
|
context.newBalance = newBalance;
|
|
4409
4414
|
context.address = address;
|
|
4410
|
-
return { context, orderNote, newBalance };
|
|
4415
|
+
return { context, orderNote: { ...orderNote, nullifier: orderNullifier }, newBalance };
|
|
4411
4416
|
}
|
|
4412
4417
|
async generateProof(context) {
|
|
4413
4418
|
if (!context
|
|
@@ -5951,7 +5956,7 @@ var retailCreateOrderCircuit = {
|
|
|
5951
5956
|
|
|
5952
5957
|
async function generateRetailSwapMessage(address, orderNote, swapInNote, pubKey, privKey) {
|
|
5953
5958
|
const addressMod = encodeAddress(address);
|
|
5954
|
-
calcNullifier(orderNote.rho, pubKey);
|
|
5959
|
+
const orderNoteNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
5955
5960
|
const message = bn_to_hex(mimc_bn254([
|
|
5956
5961
|
BigInt(PROOF_DOMAIN.RETAIL_CREATE_ORDER),
|
|
5957
5962
|
addressMod,
|
|
@@ -5962,6 +5967,7 @@ async function generateRetailSwapMessage(address, orderNote, swapInNote, pubKey,
|
|
|
5962
5967
|
const signature = await signMessage(message, privKey);
|
|
5963
5968
|
return {
|
|
5964
5969
|
orderNote: orderNote,
|
|
5970
|
+
orderNullifier: orderNoteNullifier,
|
|
5965
5971
|
inNote: swapInNote,
|
|
5966
5972
|
publicKey: pubKey,
|
|
5967
5973
|
signature: signature,
|
|
@@ -6220,5 +6226,5 @@ class DarkSwap {
|
|
|
6220
6226
|
}
|
|
6221
6227
|
}
|
|
6222
6228
|
|
|
6223
|
-
export { ChainId, DarkSwap, DarkSwapError, DarkSwapProofError, DepositContext, DepositService, EMPTY_FOOTER, EMPTY_NULLIFIER, EMPTY_PATH, FEE_RATIO, FEE_RATIO_PRECISION, JoinService, NoteOnChainStatus, PROOF_DOMAIN, ProCancelOrderService, ProCreateOrderService, ProSwapService, RetailCancelOrderService, RetailCreateOrderService, TripleJoinService, WithdrawService, contractConfig, generateKeyPair, getMerklePathAndRoot, getNoteOnChainStatusByPublicKey, getNoteOnChainStatusBySignature, hexlify32, isAddressEquals, isHexEquals, isNativeAsset, isNoteActive, isNoteSpent, isNoteValid, legacyTokenConfig, multiGetMerklePathAndRoot };
|
|
6229
|
+
export { ChainId, DarkSwap, DarkSwapError, DarkSwapProofError, DepositContext, DepositService, EMPTY_FOOTER, EMPTY_NULLIFIER, EMPTY_PATH, FEE_RATIO, FEE_RATIO_PRECISION, JoinService, NoteOnChainStatus, PROOF_DOMAIN, ProCancelOrderService, ProCreateOrderService, ProSwapService, RetailCancelOrderService, RetailCreateOrderService, TripleJoinService, WithdrawService, contractConfig, generateKeyPair, getMerklePathAndRoot, getNoteOnChainStatusByPublicKey, getNoteOnChainStatusBySignature, getNullifierBySignature, hexlify32, isAddressEquals, isHexEquals, isNativeAsset, isNoteActive, isNoteSpent, isNoteValid, legacyTokenConfig, multiGetMerklePathAndRoot };
|
|
6224
6230
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -857,6 +857,10 @@ async function isNoteValid(darkSwap, note, publicKey) {
|
|
|
857
857
|
const onChainStatus = await getNoteOnChainStatus(darkSwap, hexlify32(note.note), hexlify32(nullifier));
|
|
858
858
|
return onChainStatus === NoteOnChainStatus.ACTIVE;
|
|
859
859
|
}
|
|
860
|
+
async function getNullifierBySignature(note, signature) {
|
|
861
|
+
const [publicKey] = await generateKeyPair(signature);
|
|
862
|
+
return hexlify32(calcNullifier(note.rho, publicKey));
|
|
863
|
+
}
|
|
860
864
|
|
|
861
865
|
var abi$a = [
|
|
862
866
|
{
|
|
@@ -2948,7 +2952,6 @@ class DepositService extends BaseContractService {
|
|
|
2948
2952
|
return tx.hash;
|
|
2949
2953
|
}
|
|
2950
2954
|
else {
|
|
2951
|
-
console.log(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2952
2955
|
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: context.depositAmount });
|
|
2953
2956
|
await tx.wait();
|
|
2954
2957
|
return tx.hash;
|
|
@@ -3282,14 +3285,14 @@ class WithdrawService extends BaseContractService {
|
|
|
3282
3285
|
super(_darkSwap);
|
|
3283
3286
|
}
|
|
3284
3287
|
async prepare(address, currentBalance, withdrawAmount, signature) {
|
|
3285
|
-
const [pubKey
|
|
3288
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
3286
3289
|
const newBalanceNote = createNote(address, currentBalance.asset, currentBalance.amount - withdrawAmount, pubKey);
|
|
3287
3290
|
const context = new WithdrawContext(signature);
|
|
3288
3291
|
context.currentBalance = currentBalance;
|
|
3289
3292
|
context.newBalance = newBalanceNote;
|
|
3290
3293
|
context.withdrawAmount = withdrawAmount;
|
|
3291
3294
|
context.address = address;
|
|
3292
|
-
return { context,
|
|
3295
|
+
return { context, newBalanceNote };
|
|
3293
3296
|
}
|
|
3294
3297
|
async generateProof(context) {
|
|
3295
3298
|
if (!context || !context.currentBalance || !context.newBalance || !context.withdrawAmount || !context.address) {
|
|
@@ -3314,7 +3317,8 @@ class WithdrawService extends BaseContractService {
|
|
|
3314
3317
|
throw new DarkSwapError('Invalid context');
|
|
3315
3318
|
}
|
|
3316
3319
|
const contract = new ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
3317
|
-
const tx = await contract.withdraw(context.merkleRoot, context.proof.oldBalanceNullifier, context.
|
|
3320
|
+
const tx = await contract.withdraw(context.merkleRoot, context.currentBalance.asset, context.withdrawAmount, context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
3321
|
+
await tx.wait();
|
|
3318
3322
|
return tx.hash;
|
|
3319
3323
|
}
|
|
3320
3324
|
}
|
|
@@ -4399,6 +4403,7 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4399
4403
|
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
4404
|
const [pubKey] = await generateKeyPair(signature);
|
|
4401
4405
|
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4406
|
+
const orderNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
4402
4407
|
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4403
4408
|
const context = new ProCreateOrderContext(signature);
|
|
4404
4409
|
context.orderNote = orderNote;
|
|
@@ -4407,7 +4412,7 @@ class ProCreateOrderService extends BaseContractService {
|
|
|
4407
4412
|
context.oldBalance = balanceNote;
|
|
4408
4413
|
context.newBalance = newBalance;
|
|
4409
4414
|
context.address = address;
|
|
4410
|
-
return { context, orderNote, newBalance };
|
|
4415
|
+
return { context, orderNote: { ...orderNote, nullifier: orderNullifier }, newBalance };
|
|
4411
4416
|
}
|
|
4412
4417
|
async generateProof(context) {
|
|
4413
4418
|
if (!context
|
|
@@ -5951,7 +5956,7 @@ var retailCreateOrderCircuit = {
|
|
|
5951
5956
|
|
|
5952
5957
|
async function generateRetailSwapMessage(address, orderNote, swapInNote, pubKey, privKey) {
|
|
5953
5958
|
const addressMod = encodeAddress(address);
|
|
5954
|
-
calcNullifier(orderNote.rho, pubKey);
|
|
5959
|
+
const orderNoteNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
5955
5960
|
const message = bn_to_hex(mimc_bn254([
|
|
5956
5961
|
BigInt(PROOF_DOMAIN.RETAIL_CREATE_ORDER),
|
|
5957
5962
|
addressMod,
|
|
@@ -5962,6 +5967,7 @@ async function generateRetailSwapMessage(address, orderNote, swapInNote, pubKey,
|
|
|
5962
5967
|
const signature = await signMessage(message, privKey);
|
|
5963
5968
|
return {
|
|
5964
5969
|
orderNote: orderNote,
|
|
5970
|
+
orderNullifier: orderNoteNullifier,
|
|
5965
5971
|
inNote: swapInNote,
|
|
5966
5972
|
publicKey: pubKey,
|
|
5967
5973
|
signature: signature,
|
|
@@ -6220,5 +6226,5 @@ class DarkSwap {
|
|
|
6220
6226
|
}
|
|
6221
6227
|
}
|
|
6222
6228
|
|
|
6223
|
-
export { ChainId, DarkSwap, DarkSwapError, DarkSwapProofError, DepositContext, DepositService, EMPTY_FOOTER, EMPTY_NULLIFIER, EMPTY_PATH, FEE_RATIO, FEE_RATIO_PRECISION, JoinService, NoteOnChainStatus, PROOF_DOMAIN, ProCancelOrderService, ProCreateOrderService, ProSwapService, RetailCancelOrderService, RetailCreateOrderService, TripleJoinService, WithdrawService, contractConfig, generateKeyPair, getMerklePathAndRoot, getNoteOnChainStatusByPublicKey, getNoteOnChainStatusBySignature, hexlify32, isAddressEquals, isHexEquals, isNativeAsset, isNoteActive, isNoteSpent, isNoteValid, legacyTokenConfig, multiGetMerklePathAndRoot };
|
|
6229
|
+
export { ChainId, DarkSwap, DarkSwapError, DarkSwapProofError, DepositContext, DepositService, EMPTY_FOOTER, EMPTY_NULLIFIER, EMPTY_PATH, FEE_RATIO, FEE_RATIO_PRECISION, JoinService, NoteOnChainStatus, PROOF_DOMAIN, ProCancelOrderService, ProCreateOrderService, ProSwapService, RetailCancelOrderService, RetailCreateOrderService, TripleJoinService, WithdrawService, contractConfig, generateKeyPair, getMerklePathAndRoot, getNoteOnChainStatusByPublicKey, getNoteOnChainStatusBySignature, getNullifierBySignature, hexlify32, isAddressEquals, isHexEquals, isNativeAsset, isNoteActive, isNoteSpent, isNoteValid, legacyTokenConfig, multiGetMerklePathAndRoot };
|
|
6224
6230
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -857,6 +857,10 @@
|
|
|
857
857
|
const onChainStatus = await getNoteOnChainStatus(darkSwap, hexlify32(note.note), hexlify32(nullifier));
|
|
858
858
|
return onChainStatus === exports.NoteOnChainStatus.ACTIVE;
|
|
859
859
|
}
|
|
860
|
+
async function getNullifierBySignature(note, signature) {
|
|
861
|
+
const [publicKey] = await generateKeyPair(signature);
|
|
862
|
+
return hexlify32(calcNullifier(note.rho, publicKey));
|
|
863
|
+
}
|
|
860
864
|
|
|
861
865
|
var abi$a = [
|
|
862
866
|
{
|
|
@@ -2948,7 +2952,6 @@
|
|
|
2948
2952
|
return tx.hash;
|
|
2949
2953
|
}
|
|
2950
2954
|
else {
|
|
2951
|
-
console.log(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
2952
2955
|
const tx = await contract.deposit(context.merkleRoot, context.newBalance.asset, hexlify32(context.depositAmount), context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof, { value: context.depositAmount });
|
|
2953
2956
|
await tx.wait();
|
|
2954
2957
|
return tx.hash;
|
|
@@ -3282,14 +3285,14 @@
|
|
|
3282
3285
|
super(_darkSwap);
|
|
3283
3286
|
}
|
|
3284
3287
|
async prepare(address, currentBalance, withdrawAmount, signature) {
|
|
3285
|
-
const [pubKey
|
|
3288
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
3286
3289
|
const newBalanceNote = createNote(address, currentBalance.asset, currentBalance.amount - withdrawAmount, pubKey);
|
|
3287
3290
|
const context = new WithdrawContext(signature);
|
|
3288
3291
|
context.currentBalance = currentBalance;
|
|
3289
3292
|
context.newBalance = newBalanceNote;
|
|
3290
3293
|
context.withdrawAmount = withdrawAmount;
|
|
3291
3294
|
context.address = address;
|
|
3292
|
-
return { context,
|
|
3295
|
+
return { context, newBalanceNote };
|
|
3293
3296
|
}
|
|
3294
3297
|
async generateProof(context) {
|
|
3295
3298
|
if (!context || !context.currentBalance || !context.newBalance || !context.withdrawAmount || !context.address) {
|
|
@@ -3314,7 +3317,8 @@
|
|
|
3314
3317
|
throw new DarkSwapError('Invalid context');
|
|
3315
3318
|
}
|
|
3316
3319
|
const contract = new ethers.ethers.Contract(this._darkSwap.contracts.darkSwapAssetManager, DarkSwapAssetManagerAbi.abi, this._darkSwap.signer);
|
|
3317
|
-
const tx = await contract.withdraw(context.merkleRoot, context.proof.oldBalanceNullifier, context.
|
|
3320
|
+
const tx = await contract.withdraw(context.merkleRoot, context.currentBalance.asset, context.withdrawAmount, context.proof.oldBalanceNullifier, hexlify32(context.newBalance.note), context.proof.newBalanceFooter, context.proof.proof);
|
|
3321
|
+
await tx.wait();
|
|
3318
3322
|
return tx.hash;
|
|
3319
3323
|
}
|
|
3320
3324
|
}
|
|
@@ -4399,6 +4403,7 @@
|
|
|
4399
4403
|
async prepare(address, orderAsset, orderAmount, swapInAsset, swapInAmount, balanceNote, signature) {
|
|
4400
4404
|
const [pubKey] = await generateKeyPair(signature);
|
|
4401
4405
|
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
4406
|
+
const orderNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
4402
4407
|
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
4403
4408
|
const context = new ProCreateOrderContext(signature);
|
|
4404
4409
|
context.orderNote = orderNote;
|
|
@@ -4407,7 +4412,7 @@
|
|
|
4407
4412
|
context.oldBalance = balanceNote;
|
|
4408
4413
|
context.newBalance = newBalance;
|
|
4409
4414
|
context.address = address;
|
|
4410
|
-
return { context, orderNote, newBalance };
|
|
4415
|
+
return { context, orderNote: { ...orderNote, nullifier: orderNullifier }, newBalance };
|
|
4411
4416
|
}
|
|
4412
4417
|
async generateProof(context) {
|
|
4413
4418
|
if (!context
|
|
@@ -5951,7 +5956,7 @@
|
|
|
5951
5956
|
|
|
5952
5957
|
async function generateRetailSwapMessage(address, orderNote, swapInNote, pubKey, privKey) {
|
|
5953
5958
|
const addressMod = encodeAddress(address);
|
|
5954
|
-
calcNullifier(orderNote.rho, pubKey);
|
|
5959
|
+
const orderNoteNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
5955
5960
|
const message = bn_to_hex(mimc_bn254([
|
|
5956
5961
|
BigInt(exports.PROOF_DOMAIN.RETAIL_CREATE_ORDER),
|
|
5957
5962
|
addressMod,
|
|
@@ -5962,6 +5967,7 @@
|
|
|
5962
5967
|
const signature = await signMessage(message, privKey);
|
|
5963
5968
|
return {
|
|
5964
5969
|
orderNote: orderNote,
|
|
5970
|
+
orderNullifier: orderNoteNullifier,
|
|
5965
5971
|
inNote: swapInNote,
|
|
5966
5972
|
publicKey: pubKey,
|
|
5967
5973
|
signature: signature,
|
|
@@ -6243,6 +6249,7 @@
|
|
|
6243
6249
|
exports.getMerklePathAndRoot = getMerklePathAndRoot;
|
|
6244
6250
|
exports.getNoteOnChainStatusByPublicKey = getNoteOnChainStatusByPublicKey;
|
|
6245
6251
|
exports.getNoteOnChainStatusBySignature = getNoteOnChainStatusBySignature;
|
|
6252
|
+
exports.getNullifierBySignature = getNullifierBySignature;
|
|
6246
6253
|
exports.hexlify32 = hexlify32;
|
|
6247
6254
|
exports.isAddressEquals = isAddressEquals;
|
|
6248
6255
|
exports.isHexEquals = isHexEquals;
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -21,7 +21,7 @@ export declare class WithdrawService extends BaseContractService {
|
|
|
21
21
|
constructor(_darkSwap: DarkSwap);
|
|
22
22
|
prepare(address: string, currentBalance: DarkSwapNote, withdrawAmount: bigint, signature: string): Promise<{
|
|
23
23
|
context: WithdrawContext;
|
|
24
|
-
|
|
24
|
+
newBalanceNote: DarkSwapNote;
|
|
25
25
|
}>;
|
|
26
26
|
private generateProof;
|
|
27
27
|
execute(context: WithdrawContext): Promise<string>;
|
|
@@ -7,3 +7,4 @@ export declare function getNoteOnChainStatusBySignature(darkSwap: DarkSwap, note
|
|
|
7
7
|
export declare function isNoteActive(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
|
|
8
8
|
export declare function isNoteSpent(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
|
|
9
9
|
export declare function isNoteValid(darkSwap: DarkSwap, note: DarkSwapNote, publicKey: [Fr, Fr]): Promise<boolean>;
|
|
10
|
+
export declare function getNullifierBySignature(note: DarkSwapNote, signature: string): Promise<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DarkSwap } from '../../darkSwap';
|
|
2
2
|
import { ProCreateOrderProofResult } from '../../proof/pro/orders/createOrderProof';
|
|
3
|
-
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
|
|
3
|
+
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, DarkSwapOrderNoteExt } from '../../types';
|
|
4
4
|
import { BaseContext, BaseContractService } from '../BaseService';
|
|
5
5
|
declare class ProCreateOrderContext extends BaseContext {
|
|
6
6
|
private _orderNote?;
|
|
@@ -33,7 +33,7 @@ export declare class ProCreateOrderService extends BaseContractService {
|
|
|
33
33
|
constructor(_darkSwap: DarkSwap);
|
|
34
34
|
prepare(address: string, orderAsset: string, orderAmount: bigint, swapInAsset: string, swapInAmount: bigint, balanceNote: DarkSwapNote, signature: string): Promise<{
|
|
35
35
|
context: ProCreateOrderContext;
|
|
36
|
-
orderNote:
|
|
36
|
+
orderNote: DarkSwapOrderNoteExt;
|
|
37
37
|
newBalance: DarkSwapNote;
|
|
38
38
|
}>;
|
|
39
39
|
private generateProof;
|
|
@@ -24,6 +24,9 @@ export type DarkSwapNote = CreateNoteParam & {
|
|
|
24
24
|
export type DarkSwapOrderNote = DarkSwapNote & {
|
|
25
25
|
feeRatio: bigint;
|
|
26
26
|
};
|
|
27
|
+
export type DarkSwapOrderNoteExt = DarkSwapOrderNote & {
|
|
28
|
+
nullifier: string;
|
|
29
|
+
};
|
|
27
30
|
export type CreateNoteParam = {
|
|
28
31
|
rho: bigint;
|
|
29
32
|
amount: bigint;
|
|
@@ -47,6 +50,7 @@ export type BaseProofInput = {
|
|
|
47
50
|
};
|
|
48
51
|
export type DarkSwapMessage = {
|
|
49
52
|
orderNote: DarkSwapOrderNote;
|
|
53
|
+
orderNullifier: string;
|
|
50
54
|
inNote: DarkSwapNote;
|
|
51
55
|
publicKey: [Fr, Fr];
|
|
52
56
|
signature: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,4 +2,5 @@ import { ethers } from "ethers";
|
|
|
2
2
|
import { DarkSwap } from "../../src";
|
|
3
3
|
export declare function getAliceWallet(): ethers.Wallet;
|
|
4
4
|
export declare function getAliceSignature(): Promise<string>;
|
|
5
|
+
export declare function getAliceWalletBalance(asset: string): Promise<any>;
|
|
5
6
|
export declare function getDarkSwapForAlice(): DarkSwap;
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import { generateKeyPair } from "../keyService";
|
|
|
9
9
|
import { calcNullifier, getNoteFooter } from "../noteService";
|
|
10
10
|
import { Fr } from "@aztec/foundation/fields";
|
|
11
11
|
import retailCreateOrderCircuit from "../../circuits/retail/dark_swap_retail_deposit_create_order_compiled_circuit.json";
|
|
12
|
+
import { hexlify32 } from "../../utils/util";
|
|
12
13
|
|
|
13
14
|
type RetailCreateOrderProofInput = BaseProofInput & {
|
|
14
15
|
deposit_out_note: string,
|
|
@@ -53,7 +54,7 @@ export async function generateRetailSwapMessage(
|
|
|
53
54
|
): Promise<DarkSwapMessage> {
|
|
54
55
|
|
|
55
56
|
const addressMod = encodeAddress(address);
|
|
56
|
-
const orderNoteNullifier = calcNullifier(orderNote.rho, pubKey);
|
|
57
|
+
const orderNoteNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
57
58
|
const message = bn_to_hex(mimc_bn254([
|
|
58
59
|
BigInt(PROOF_DOMAIN.RETAIL_CREATE_ORDER),
|
|
59
60
|
addressMod,
|
|
@@ -65,6 +66,7 @@ export async function generateRetailSwapMessage(
|
|
|
65
66
|
|
|
66
67
|
return {
|
|
67
68
|
orderNote: orderNote,
|
|
69
|
+
orderNullifier: orderNoteNullifier,
|
|
68
70
|
inNote: swapInNote,
|
|
69
71
|
publicKey: pubKey,
|
|
70
72
|
signature: signature,
|
|
@@ -137,13 +137,6 @@ export class DepositService extends BaseContractService {
|
|
|
137
137
|
await tx.wait();
|
|
138
138
|
return tx.hash;
|
|
139
139
|
} else {
|
|
140
|
-
console.log(context.merkleRoot,
|
|
141
|
-
context.newBalance.asset,
|
|
142
|
-
hexlify32(context.depositAmount),
|
|
143
|
-
context.proof.oldBalanceNullifier,
|
|
144
|
-
hexlify32(context.newBalance.note),
|
|
145
|
-
context.proof.newBalanceFooter,
|
|
146
|
-
context.proof.proof);
|
|
147
140
|
const tx = await contract.deposit(
|
|
148
141
|
context.merkleRoot,
|
|
149
142
|
context.newBalance.asset,
|
|
@@ -8,6 +8,7 @@ import { createNote } from '../../proof/noteService';
|
|
|
8
8
|
import { DarkSwapNote } from '../../types';
|
|
9
9
|
import { BaseContext, BaseContractService } from '../BaseService';
|
|
10
10
|
import { getMerklePathAndRoot } from '../merkletree';
|
|
11
|
+
import { hexlify32 } from '../../utils/util';
|
|
11
12
|
|
|
12
13
|
class WithdrawContext extends BaseContext {
|
|
13
14
|
private _currentBalance?: DarkSwapNote;
|
|
@@ -62,8 +63,8 @@ export class WithdrawService extends BaseContractService {
|
|
|
62
63
|
currentBalance: DarkSwapNote,
|
|
63
64
|
withdrawAmount: bigint,
|
|
64
65
|
signature: string
|
|
65
|
-
): Promise<{ context: WithdrawContext;
|
|
66
|
-
const [pubKey
|
|
66
|
+
): Promise<{ context: WithdrawContext; newBalanceNote: DarkSwapNote }> {
|
|
67
|
+
const [pubKey] = await generateKeyPair(signature);
|
|
67
68
|
const newBalanceNote = createNote(address, currentBalance.asset, currentBalance.amount - withdrawAmount, pubKey);
|
|
68
69
|
|
|
69
70
|
const context = new WithdrawContext(signature);
|
|
@@ -71,7 +72,7 @@ export class WithdrawService extends BaseContractService {
|
|
|
71
72
|
context.newBalance = newBalanceNote;
|
|
72
73
|
context.withdrawAmount = withdrawAmount;
|
|
73
74
|
context.address = address;
|
|
74
|
-
return { context,
|
|
75
|
+
return { context, newBalanceNote };
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
private async generateProof(context: WithdrawContext): Promise<void> {
|
|
@@ -109,11 +110,14 @@ export class WithdrawService extends BaseContractService {
|
|
|
109
110
|
|
|
110
111
|
const tx = await contract.withdraw(
|
|
111
112
|
context.merkleRoot,
|
|
113
|
+
context.currentBalance.asset,
|
|
114
|
+
context.withdrawAmount,
|
|
112
115
|
context.proof.oldBalanceNullifier,
|
|
116
|
+
hexlify32(context.newBalance.note),
|
|
113
117
|
context.proof.newBalanceFooter,
|
|
114
|
-
context.withdrawAmount,
|
|
115
118
|
context.proof.proof
|
|
116
119
|
);
|
|
120
|
+
await tx.wait();
|
|
117
121
|
return tx.hash;
|
|
118
122
|
}
|
|
119
123
|
}
|
|
@@ -68,3 +68,8 @@ export async function isNoteValid(darkSwap: DarkSwap, note: DarkSwapNote, public
|
|
|
68
68
|
const onChainStatus = await getNoteOnChainStatus(darkSwap, hexlify32(note.note), hexlify32(nullifier));
|
|
69
69
|
return onChainStatus === NoteOnChainStatus.ACTIVE;
|
|
70
70
|
}
|
|
71
|
+
|
|
72
|
+
export async function getNullifierBySignature(note: DarkSwapNote, signature: string): Promise<string> {
|
|
73
|
+
const [publicKey] = await generateKeyPair(signature);
|
|
74
|
+
return hexlify32(calcNullifier(note.rho, publicKey));
|
|
75
|
+
}
|
|
@@ -4,11 +4,12 @@ import { FEE_RATIO } from '../../config/config';
|
|
|
4
4
|
import { DarkSwap } from '../../darkSwap';
|
|
5
5
|
import { DarkSwapError } from '../../entities';
|
|
6
6
|
import { generateKeyPair } from '../../proof/keyService';
|
|
7
|
-
import { createNote, createOrderNoteExt } from '../../proof/noteService';
|
|
7
|
+
import { calcNullifier, createNote, createOrderNoteExt } from '../../proof/noteService';
|
|
8
8
|
import { generateProCreateOrderProof, ProCreateOrderProofResult } from '../../proof/pro/orders/createOrderProof';
|
|
9
|
-
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote } from '../../types';
|
|
9
|
+
import { DarkSwapMessage, DarkSwapNote, DarkSwapOrderNote, DarkSwapOrderNoteExt } from '../../types';
|
|
10
10
|
import { BaseContext, BaseContractService } from '../BaseService';
|
|
11
11
|
import { getMerklePathAndRoot } from '../merkletree';
|
|
12
|
+
import { hexlify32 } from '../../utils/util';
|
|
12
13
|
|
|
13
14
|
class ProCreateOrderContext extends BaseContext {
|
|
14
15
|
private _orderNote?: DarkSwapOrderNote;
|
|
@@ -102,9 +103,10 @@ export class ProCreateOrderService extends BaseContractService {
|
|
|
102
103
|
swapInAmount: bigint,
|
|
103
104
|
balanceNote: DarkSwapNote,
|
|
104
105
|
signature: string
|
|
105
|
-
): Promise<{ context: ProCreateOrderContext; orderNote:
|
|
106
|
+
): Promise<{ context: ProCreateOrderContext; orderNote: DarkSwapOrderNoteExt, newBalance: DarkSwapNote }> {
|
|
106
107
|
const [pubKey] = await generateKeyPair(signature);
|
|
107
108
|
const orderNote = createOrderNoteExt(address, orderAsset, orderAmount, FEE_RATIO, pubKey);
|
|
109
|
+
const orderNullifier = hexlify32(calcNullifier(orderNote.rho, pubKey));
|
|
108
110
|
const newBalance = createNote(address, orderAsset, balanceNote.amount - orderAmount, pubKey);
|
|
109
111
|
const context = new ProCreateOrderContext(signature);
|
|
110
112
|
context.orderNote = orderNote;
|
|
@@ -113,7 +115,7 @@ export class ProCreateOrderService extends BaseContractService {
|
|
|
113
115
|
context.oldBalance = balanceNote;
|
|
114
116
|
context.newBalance = newBalance;
|
|
115
117
|
context.address = address;
|
|
116
|
-
return { context, orderNote, newBalance };
|
|
118
|
+
return { context, orderNote: { ...orderNote, nullifier: orderNullifier }, newBalance };
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
private async generateProof(context: ProCreateOrderContext): Promise<void> {
|
package/src/types.ts
CHANGED
|
@@ -35,6 +35,10 @@ export type DarkSwapOrderNote = DarkSwapNote & {
|
|
|
35
35
|
feeRatio: bigint,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
export type DarkSwapOrderNoteExt = DarkSwapOrderNote & {
|
|
39
|
+
nullifier: string,
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
export type CreateNoteParam = {
|
|
39
43
|
rho: bigint,
|
|
40
44
|
amount: bigint,
|
|
@@ -62,6 +66,7 @@ export type BaseProofInput = {
|
|
|
62
66
|
|
|
63
67
|
export type DarkSwapMessage = {
|
|
64
68
|
orderNote: DarkSwapOrderNote,
|
|
69
|
+
orderNullifier: string,
|
|
65
70
|
inNote: DarkSwapNote,
|
|
66
71
|
publicKey: [Fr, Fr],
|
|
67
72
|
signature: any,
|