dop-wallet-v6 1.2.4 → 1.2.6
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/services/transactions/__tests__/tx-proof-transfer-with-data.test.d.ts +1 -0
- package/dist/services/transactions/__tests__/tx-proof-transfer-with-data.test.js +99 -0
- package/dist/services/transactions/__tests__/tx-proof-transfer-with-data.test.js.map +1 -0
- package/dist/services/transactions/__tests__/tx-transfer.test.js +2 -2
- package/dist/services/transactions/__tests__/tx-transfer.test.js.map +1 -1
- package/dist/services/transactions/index.d.ts +1 -0
- package/dist/services/transactions/index.js +1 -0
- package/dist/services/transactions/index.js.map +1 -1
- package/dist/services/transactions/tx-proof-transfer-with-data.d.ts +45 -0
- package/dist/services/transactions/tx-proof-transfer-with-data.js +122 -0
- package/dist/services/transactions/tx-proof-transfer-with-data.js.map +1 -0
- package/dist/services/transactions/tx-proof-transfer.d.ts +1 -1
- package/dist/services/transactions/tx-proof-transfer.js +4 -4
- package/dist/services/transactions/tx-proof-transfer.js.map +1 -1
- package/dist/utils/__tests__/bigint-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/bigint-serialization.test.js +106 -0
- package/dist/utils/__tests__/bigint-serialization.test.js.map +1 -0
- package/dist/utils/bigint-serialization.d.ts +29 -0
- package/dist/utils/bigint-serialization.js +58 -0
- package/dist/utils/bigint-serialization.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const tx_proof_transfer_with_data_1 = require("../tx-proof-transfer-with-data");
|
|
5
|
+
describe('tx-proof-transfer-with-data', () => {
|
|
6
|
+
describe('TransferProofData interface structure', () => {
|
|
7
|
+
it('should have the correct TypeScript interface structure', () => {
|
|
8
|
+
// Test that we can create a valid TransferProofData object
|
|
9
|
+
const mockProofData = {
|
|
10
|
+
proof: {
|
|
11
|
+
a: { x: '0x123', y: '0x456' },
|
|
12
|
+
b: {
|
|
13
|
+
x: ['0x789', '0xabc'],
|
|
14
|
+
y: ['0xdef', '0x012']
|
|
15
|
+
},
|
|
16
|
+
c: { x: '0x345', y: '0x678' }
|
|
17
|
+
},
|
|
18
|
+
publicInputs: {
|
|
19
|
+
merkleRoot: '0xmerkleroot',
|
|
20
|
+
nullifiers: ['0xnullifier1', '0xnullifier2'],
|
|
21
|
+
commitments: ['0xcommitment1', '0xcommitment2'],
|
|
22
|
+
boundParamsHash: '0xboundparams'
|
|
23
|
+
},
|
|
24
|
+
transaction: {
|
|
25
|
+
data: '0xtxdata',
|
|
26
|
+
to: '0xrecipient',
|
|
27
|
+
value: '1000000000000000000'
|
|
28
|
+
},
|
|
29
|
+
nullifiers: ['0xnullifier1', '0xnullifier2']
|
|
30
|
+
};
|
|
31
|
+
// Verify the structure matches our interface
|
|
32
|
+
(0, chai_1.expect)(mockProofData).to.have.property('proof');
|
|
33
|
+
(0, chai_1.expect)(mockProofData.proof).to.have.property('a');
|
|
34
|
+
(0, chai_1.expect)(mockProofData.proof).to.have.property('b');
|
|
35
|
+
(0, chai_1.expect)(mockProofData.proof).to.have.property('c');
|
|
36
|
+
(0, chai_1.expect)(mockProofData.proof.a).to.have.property('x');
|
|
37
|
+
(0, chai_1.expect)(mockProofData.proof.a).to.have.property('y');
|
|
38
|
+
(0, chai_1.expect)(mockProofData.proof.b.x).to.be.an('array').with.length(2);
|
|
39
|
+
(0, chai_1.expect)(mockProofData.proof.b.y).to.be.an('array').with.length(2);
|
|
40
|
+
(0, chai_1.expect)(mockProofData).to.have.property('publicInputs');
|
|
41
|
+
(0, chai_1.expect)(mockProofData.publicInputs).to.have.property('merkleRoot');
|
|
42
|
+
(0, chai_1.expect)(mockProofData.publicInputs).to.have.property('nullifiers');
|
|
43
|
+
(0, chai_1.expect)(mockProofData.publicInputs).to.have.property('commitments');
|
|
44
|
+
(0, chai_1.expect)(mockProofData.publicInputs).to.have.property('boundParamsHash');
|
|
45
|
+
(0, chai_1.expect)(mockProofData).to.have.property('transaction');
|
|
46
|
+
(0, chai_1.expect)(mockProofData.transaction).to.have.property('data');
|
|
47
|
+
(0, chai_1.expect)(mockProofData).to.have.property('nullifiers');
|
|
48
|
+
(0, chai_1.expect)(mockProofData.nullifiers).to.be.an('array');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('Function exports and signatures', () => {
|
|
52
|
+
it('should export generateTransferProof function that returns Promise<TransferProofData>', () => {
|
|
53
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProof).to.be.a('function');
|
|
54
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProof.length).to.equal(12); // Should have 12 parameters
|
|
55
|
+
});
|
|
56
|
+
it('should export generateTransferProofWithDataInternal function that returns Promise<void>', () => {
|
|
57
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofWithDataInternal).to.be.a('function');
|
|
58
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofWithDataInternal.length).to.equal(12); // Should have 12 parameters
|
|
59
|
+
});
|
|
60
|
+
it('should export extractTransferProofData function', () => {
|
|
61
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.extractTransferProofData).to.be.a('function');
|
|
62
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.extractTransferProofData.length).to.equal(0); // Should have no parameters
|
|
63
|
+
});
|
|
64
|
+
it('should maintain naming consistency for frontend developers', () => {
|
|
65
|
+
// The main function that frontend developers will use should be generateTransferProof
|
|
66
|
+
// and it should return the proof data (not void)
|
|
67
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProof).to.be.a('function');
|
|
68
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofWithDataInternal).to.be.a('function');
|
|
69
|
+
(0, chai_1.expect)(tx_proof_transfer_with_data_1.extractTransferProofData).to.be.a('function');
|
|
70
|
+
// All functions should exist and be callable
|
|
71
|
+
// generateTransferProof is the one that returns TransferProofData
|
|
72
|
+
// generateTransferProofWithDataInternal is the internal one that returns void
|
|
73
|
+
// extractTransferProofData extracts data from cached proof
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('Integration behavior (may fail in test environment)', () => {
|
|
77
|
+
it('should attempt to call generateTransferProof and handle expected failures gracefully', async () => {
|
|
78
|
+
// This test expects to fail due to missing DOP engine initialization
|
|
79
|
+
// But it verifies the function structure and error handling
|
|
80
|
+
try {
|
|
81
|
+
// This will likely fail, but that's expected in test environment
|
|
82
|
+
await (0, tx_proof_transfer_with_data_1.generateTransferProof)('V3_PoseidonMerkle', // Using string to avoid import issues
|
|
83
|
+
'Polygon', 'test-wallet-id', 'test-encryption-key', true, 'test memo', [], [], undefined, false, undefined, () => { });
|
|
84
|
+
// If we get here, the function worked (unlikely in test env)
|
|
85
|
+
console.log('✅ generateTransferProof executed successfully');
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// This is expected in test environment
|
|
89
|
+
console.log('⚠️ Expected failure in test environment:', error.message);
|
|
90
|
+
// Verify the error is what we expect (DOP engine not initialized)
|
|
91
|
+
(0, chai_1.expect)(error.message).to.satisfy((msg) => msg.includes('not yet initialized') ||
|
|
92
|
+
msg.includes('No cached proof') ||
|
|
93
|
+
msg.includes('MOCK_DB_ENCRYPTION_KEY') ||
|
|
94
|
+
msg.includes('DOP Engine'));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=tx-proof-transfer-with-data.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-proof-transfer-with-data.test.js","sourceRoot":"","sources":["../../../../src/services/transactions/__tests__/tx-proof-transfer-with-data.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,gFAKwC;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AAC,qBAAqB,CAAC;oBACnC,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC;oBAC/B,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC;oBACtC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,CAC3B,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from 'chai';\nimport { \n generateTransferProof, \n generateTransferProofWithDataInternal,\n extractTransferProofData,\n TransferProofData \n} from '../tx-proof-transfer-with-data';\n\ndescribe('tx-proof-transfer-with-data', () => {\n describe('TransferProofData interface structure', () => {\n it('should have the correct TypeScript interface structure', () => {\n // Test that we can create a valid TransferProofData object\n const mockProofData: TransferProofData = {\n proof: {\n a: { x: '0x123', y: '0x456' },\n b: { \n x: ['0x789', '0xabc'], \n y: ['0xdef', '0x012'] \n },\n c: { x: '0x345', y: '0x678' }\n },\n publicInputs: {\n merkleRoot: '0xmerkleroot',\n nullifiers: ['0xnullifier1', '0xnullifier2'],\n commitments: ['0xcommitment1', '0xcommitment2'],\n boundParamsHash: '0xboundparams'\n },\n transaction: {\n data: '0xtxdata',\n to: '0xrecipient',\n value: '1000000000000000000'\n },\n nullifiers: ['0xnullifier1', '0xnullifier2']\n };\n\n // Verify the structure matches our interface\n expect(mockProofData).to.have.property('proof');\n expect(mockProofData.proof).to.have.property('a');\n expect(mockProofData.proof).to.have.property('b');\n expect(mockProofData.proof).to.have.property('c');\n \n expect(mockProofData.proof.a).to.have.property('x');\n expect(mockProofData.proof.a).to.have.property('y');\n \n expect(mockProofData.proof.b.x).to.be.an('array').with.length(2);\n expect(mockProofData.proof.b.y).to.be.an('array').with.length(2);\n \n expect(mockProofData).to.have.property('publicInputs');\n expect(mockProofData.publicInputs).to.have.property('merkleRoot');\n expect(mockProofData.publicInputs).to.have.property('nullifiers');\n expect(mockProofData.publicInputs).to.have.property('commitments');\n expect(mockProofData.publicInputs).to.have.property('boundParamsHash');\n \n expect(mockProofData).to.have.property('transaction');\n expect(mockProofData.transaction).to.have.property('data');\n \n expect(mockProofData).to.have.property('nullifiers');\n expect(mockProofData.nullifiers).to.be.an('array');\n });\n });\n\n describe('Function exports and signatures', () => {\n it('should export generateTransferProof function that returns Promise<TransferProofData>', () => {\n expect(generateTransferProof).to.be.a('function');\n expect(generateTransferProof.length).to.equal(12); // Should have 12 parameters\n });\n\n it('should export generateTransferProofWithDataInternal function that returns Promise<void>', () => {\n expect(generateTransferProofWithDataInternal).to.be.a('function');\n expect(generateTransferProofWithDataInternal.length).to.equal(12); // Should have 12 parameters\n });\n\n it('should export extractTransferProofData function', () => {\n expect(extractTransferProofData).to.be.a('function');\n expect(extractTransferProofData.length).to.equal(0); // Should have no parameters\n });\n\n it('should maintain naming consistency for frontend developers', () => {\n // The main function that frontend developers will use should be generateTransferProof\n // and it should return the proof data (not void)\n expect(generateTransferProof).to.be.a('function');\n expect(generateTransferProofWithDataInternal).to.be.a('function');\n expect(extractTransferProofData).to.be.a('function');\n \n // All functions should exist and be callable\n // generateTransferProof is the one that returns TransferProofData\n // generateTransferProofWithDataInternal is the internal one that returns void\n // extractTransferProofData extracts data from cached proof\n });\n });\n\n describe('Integration behavior (may fail in test environment)', () => {\n it('should attempt to call generateTransferProof and handle expected failures gracefully', async () => {\n // This test expects to fail due to missing DOP engine initialization\n // But it verifies the function structure and error handling\n \n try {\n // This will likely fail, but that's expected in test environment\n await generateTransferProof(\n 'V3_PoseidonMerkle' as any, // Using string to avoid import issues\n 'Polygon' as any,\n 'test-wallet-id',\n 'test-encryption-key',\n true,\n 'test memo',\n [],\n [],\n undefined,\n false,\n undefined,\n () => {},\n );\n \n // If we get here, the function worked (unlikely in test env)\n console.log('✅ generateTransferProof executed successfully');\n \n } catch (error) {\n // This is expected in test environment\n console.log('⚠️ Expected failure in test environment:', error.message);\n \n // Verify the error is what we expect (DOP engine not initialized)\n expect(error.message).to.satisfy((msg: string) => \n msg.includes('not yet initialized') || \n msg.includes('No cached proof') ||\n msg.includes('MOCK_DB_ENCRYPTION_KEY') ||\n msg.includes('DOP Engine')\n );\n }\n });\n });\n});\n"]}
|
|
@@ -236,7 +236,7 @@ describe('tx-transfer', () => {
|
|
|
236
236
|
(0, proof_cache_1.setCachedProvedTransaction)(undefined);
|
|
237
237
|
spyOnERC20Note();
|
|
238
238
|
spyOnNFTNote();
|
|
239
|
-
await (0, tx_proof_transfer_1.
|
|
239
|
+
await (0, tx_proof_transfer_1.generateTransferProofInternal)(txidVersion, dop_sharedmodels_v3_1.NetworkName.Polygon, dopWallet.id, mocks_test_1.MOCK_DB_ENCRYPTION_KEY, true, // showSenderAddressToRecipient
|
|
240
240
|
mocks_test_1.MOCK_MEMO, MOCK_TOKEN_AMOUNT_RECIPIENTS, mocks_test_1.MOCK_NFT_AMOUNT_RECIPIENTS, broadcasterFeeERC20AmountRecipient, false, // sendWithPublicWallet
|
|
241
241
|
overallBatchMinGasPrice, () => { });
|
|
242
242
|
expect(erc20NoteSpy.called).to.be.true;
|
|
@@ -269,7 +269,7 @@ describe('tx-transfer', () => {
|
|
|
269
269
|
});
|
|
270
270
|
it('Should error on populate transfer tx when params changed (invalid cached proof)', async () => {
|
|
271
271
|
stubGasEstimateSuccess();
|
|
272
|
-
await (0, tx_proof_transfer_1.
|
|
272
|
+
await (0, tx_proof_transfer_1.generateTransferProofInternal)(txidVersion, dop_sharedmodels_v3_1.NetworkName.Polygon, dopWallet.id, mocks_test_1.MOCK_DB_ENCRYPTION_KEY, true, // showSenderAddressToRecipient
|
|
273
273
|
mocks_test_1.MOCK_MEMO, MOCK_TOKEN_AMOUNT_RECIPIENTS, mocks_test_1.MOCK_NFT_AMOUNT_RECIPIENTS, broadcasterFeeERC20AmountRecipient, false, // sendWithPublicWallet
|
|
274
274
|
overallBatchMinGasPrice, () => { });
|
|
275
275
|
await expect((0, tx_transfer_1.populateProvedTransfer)(txidVersion, dop_sharedmodels_v3_1.NetworkName.Polygon, dopWallet.id, true, // showSenderAddressToRecipient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx-transfer.test.js","sourceRoot":"","sources":["../../../../src/services/transactions/__tests__/tx-transfer.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,wEAA8C;AAC9C,kDAAmD;AACnD,iDAOuB;AACvB,6DAQ6B;AAC7B,0DAImC;AACnC,0DAmBmC;AACnC,gDAGwB;AACxB,sEAAwD;AACxD,4DAA6D;AAC7D,uDAGmC;AACnC,gDAA4D;AAC5D,qDAAuC;AAEvC,4DAA0E;AAE1E,IAAI,eAA0B,CAAC;AAC/B,IAAI,YAAuB,CAAC;AAC5B,IAAI,iBAA4B,CAAC;AACjC,IAAI,eAA0B,CAAC;AAC/B,IAAI,kCAA6C,CAAC;AAClD,IAAI,aAAuB,CAAC;AAC5B,IAAI,YAAsB,CAAC;AAC3B,IAAI,UAAoB,CAAC;AAEzB,IAAI,SAAoB,CAAC;AACzB,IAAI,kCAA2D,CAAC;AAEhE,cAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACzB,MAAM,EAAE,MAAM,EAAE,GAAG,cAAI,CAAC;AAExB,MAAM,WAAW,GAAG,IAAA,gCAAkB,GAAE,CAAC;AAEzC,MAAM,4BAA4B,GAAqB;IACrD;QACE,YAAY,EAAE,+BAAkB;QAChC,MAAM,EAAE,IAAI;KACb;IACD;QACE,YAAY,EAAE,iCAAoB;QAClC,MAAM,EAAE,IAAI;KACb;CACF,CAAC;AAEF,MAAM,uBAAuB,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEjD,MAAM,UAAU,GAA0B;IACxC,UAAU,EAAE,gCAAU,CAAC,KAAK;IAC5B,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,uBAAuB;CAClC,CAAC;AAEF,MAAM,oCAAoC,GACxC,+BAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACrC,GAAG,W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,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,sBAAsB,EAAE,CAAC;QACzB,IAAA,wCAA0B,EAAC,SAAS,CAAC,CAAC;QACtC,MAAM,MAAM,CACV,IAAA,oCAAsB,EACpB,WAAW,EACX,iCAAW,CAAC,OAAO,EACnB,SAAS,CAAC,EAAE,EACZ,KAAK,EAAE,+BAA+B;QACtC,sBAAS,EACT,4BAA4B,EAC5B,uCAA0B,EAC1B,kCAAkC,EAClC,KAAK,EAAE,uBAAuB;QAC9B,uBAAuB,EACvB,UAAU,CACX,CACF,CAAC,YAAY,CAAC,oCAAoC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iFAAiF,EAAE,KAAK,IAAI,EAAE;QAC/F,sBAAsB,EAAE,CAAC;QACzB,MAAM,IAAA,yCAAqB,EACzB,WAAW,EACX,iCAAW,CAAC,OAAO,EACnB,SAAS,CAAC,EAAE,EACZ,mCAAsB,EACtB,IAAI,EAAE,+BAA+B;QACrC,sBAAS,EACT,4BAA4B,EAC5B,uCAA0B,EAC1B,kCAAkC,EAClC,KAAK,EAAE,uBAAuB;QAC9B,uBAAuB,EACvB,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;QACF,MAAM,MAAM,CACV,IAAA,oCAAsB,EACpB,WAAW,EACX,iCAAW,CAAC,OAAO,EACnB,SAAS,CAAC,EAAE,EACZ,IAAI,EAAE,+BAA+B;QACrC,sBAAS,EACT,sCAAsC,EACtC,uCAA0B,EAC1B,kCAAkC,EAClC,KAAK,EAAE,uBAAuB;QAC9B,uBAAuB,EACvB,UAAU,CACX,CACF,CAAC,YAAY,CAAC,oCAAoC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import chai from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport Sinon, { SinonStub, SinonSpy } from 'sinon';\nimport {\n DopWallet,\n TransactionBatch,\n RelayAdaptVersionedSmartContracts,\n TransactionStructV2,\n TransactionStructV3,\n DopVersionedSmartContracts,\n} from 'dop-engine-v3';\nimport {\n DopERC20Amount,\n NetworkName,\n EVMGasType,\n DopERC20AmountRecipient,\n DopNFTAmountRecipient,\n TransactionGasDetails,\n isDefined,\n} from 'dop-sharedmodels-v3';\nimport {\n closeTestEngine,\n initTestEngine,\n initTestEngineNetworks,\n} from '../../../tests/setup.test';\nimport {\n MOCK_BOUND_PARAMS_V2,\n MOCK_BOUND_PARAMS_V3,\n MOCK_COMMITMENTS,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_ETH_WALLET_ADDRESS,\n MOCK_FEE_TOKEN_DETAILS,\n MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2,\n MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n MOCK_MEMO,\n MOCK_MNEMONIC,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n MOCK_NULLIFIERS,\n MOCK_DOP_WALLET_ADDRESS,\n MOCK_TOKEN_ADDRESS,\n MOCK_TOKEN_ADDRESS_2,\n MOCK_TOKEN_AMOUNTS,\n MOCK_TOKEN_FEE,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n} from '../../../tests/mocks.test';\nimport {\n populateProvedTransfer,\n gasEstimateForUnprovenTransfer,\n} from '../tx-transfer';\nimport * as txGasDetailsModule from '../tx-gas-details';\nimport { generateTransferProof } from '../tx-proof-transfer';\nimport {\n createDopWallet,\n fullWalletForID,\n} from '../../dop/wallets/wallets';\nimport { setCachedProvedTransaction } from '../proof-cache';\nimport * as txNotes from '../tx-notes';\nimport { ContractTransaction, FallbackProvider } from 'ethers';\nimport { getTestTXIDVersion, isV2Test } from '../../../tests/helper.test';\n\nlet gasEstimateStub: SinonStub;\nlet dopProveStub: SinonStub;\nlet dopDummyProveStub: SinonStub;\nlet dopTransactStub: SinonStub;\nlet relayAdaptPopulateDecryptBaseToken: SinonStub;\nlet setDecryptSpy: SinonSpy;\nlet erc20NoteSpy: SinonSpy;\nlet nftNoteSpy: SinonSpy;\n\nlet dopWallet: DopWallet;\nlet broadcasterFeeERC20AmountRecipient: DopERC20AmountRecipient;\n\nchai.use(chaiAsPromised);\nconst { expect } = chai;\n\nconst txidVersion = getTestTXIDVersion();\n\nconst MOCK_TOKEN_AMOUNTS_DIFFERENT: DopERC20Amount[] = [\n {\n tokenAddress: MOCK_TOKEN_ADDRESS,\n amount: 100n,\n },\n {\n tokenAddress: MOCK_TOKEN_ADDRESS_2,\n amount: 300n,\n },\n];\n\nconst overallBatchMinGasPrice = BigInt('0x1000');\n\nconst gasDetails: TransactionGasDetails = {\n evmGasType: EVMGasType.Type1,\n gasEstimate: 1000n,\n gasPrice: overallBatchMinGasPrice,\n};\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS_INVALID: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst MOCK_NFT_AMOUNT_RECIPIENTS_INVALID: DopNFTAmountRecipient[] =\n MOCK_NFT_AMOUNT_RECIPIENTS.map(nftAmountRecipient => ({\n ...nftAmountRecipient,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_DOP_WALLET_ADDRESS,\n }));\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS_DIFFERENT: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS_DIFFERENT.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst stubGasEstimateSuccess = () => {\n gasEstimateStub = Sinon.stub(txGasDetailsModule, 'getGasEstimate').resolves(\n BigInt('200'),\n );\n};\n\nconst stubGasEstimateFailure = () => {\n gasEstimateStub = Sinon.stub(txGasDetailsModule, 'getGasEstimate').rejects(\n new Error('test rejection - gas estimate'),\n );\n};\n\nconst spyOnERC20Note = () => {\n erc20NoteSpy = Sinon.spy(txNotes, 'erc20NoteFromERC20AmountRecipient');\n};\n\nconst spyOnNFTNote = () => {\n nftNoteSpy = Sinon.spy(txNotes, 'nftNoteFromNFTAmountRecipient');\n};\n\ndescribe('tx-transfer', () => {\n before(async function run() {\n this.timeout(60_000);\n await initTestEngine();\n await initTestEngineNetworks();\n const dopWalletInfo = await createDopWallet(\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MNEMONIC,\n undefined, // creationBlockNumbers\n );\n if (!isDefined(dopWalletInfo)) {\n throw new Error('Expected dopWalletInfo');\n }\n dopWallet = fullWalletForID(dopWalletInfo.id);\n\n const broadcasterWalletInfo = await createDopWallet(\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MNEMONIC,\n undefined, // creationBlockNumbers\n );\n if (!isDefined(broadcasterWalletInfo)) {\n throw new Error('Expected broadcasterWalletInfo');\n }\n\n const broadcasterDopAddress = broadcasterWalletInfo.dopAddress;\n\n broadcasterFeeERC20AmountRecipient = {\n ...MOCK_TOKEN_FEE,\n recipientAddress: broadcasterDopAddress,\n };\n\n dopProveStub = Sinon.stub(\n TransactionBatch.prototype,\n 'generateTransactions',\n ).resolves({\n provedTransactions: [\n {\n nullifiers: MOCK_NULLIFIERS,\n },\n ] as (TransactionStructV2 | TransactionStructV3)[],\n preTransactionPOIsPerTxidLeafPerList: {},\n });\n dopDummyProveStub = Sinon.stub(\n TransactionBatch.prototype,\n 'generateDummyTransactions',\n ).resolves([\n {\n txidVersion,\n commitments: MOCK_COMMITMENTS,\n boundParams: isV2Test() ? MOCK_BOUND_PARAMS_V2 : MOCK_BOUND_PARAMS_V3,\n nullifiers: MOCK_NULLIFIERS,\n },\n ] as (TransactionStructV2 | TransactionStructV3)[]);\n dopTransactStub = Sinon.stub(\n DopVersionedSmartContracts,\n 'generateTransact',\n ).resolves({ data: '0x0123' } as ContractTransaction);\n relayAdaptPopulateDecryptBaseToken = Sinon.stub(\n RelayAdaptVersionedSmartContracts,\n 'populateDecryptBaseToken',\n ).resolves({ data: '0x0123' } as ContractTransaction);\n });\n afterEach(() => {\n gasEstimateStub?.restore();\n setDecryptSpy?.restore();\n erc20NoteSpy?.restore();\n nftNoteSpy?.restore();\n });\n after(async () => {\n dopProveStub.restore();\n dopDummyProveStub.restore();\n dopTransactStub.restore();\n relayAdaptPopulateDecryptBaseToken.restore();\n await closeTestEngine();\n });\n\n // TRANSFER ERC20 - GAS ESTIMATE\n\n it('Should get gas estimates for valid erc20 transfer', async () => {\n stubGasEstimateSuccess();\n spyOnERC20Note();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args.length).to.equal(6); // Number of calls - 3 for each of 2 broadcaster fee iterations\n expect(erc20NoteSpy.args[0][0].amount).to.equal(BigInt('0x00')); // original broadcaster fee\n expect(erc20NoteSpy.args[1][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[2][0].amount).to.equal(BigInt('0x200')); // token2\n expect(erc20NoteSpy.args[3][0].amount).to.equal(\n BigInt('0x0275a61bf8737eb4'),\n ); // New estimated Broadcaster Fee\n expect(erc20NoteSpy.args[4][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[5][0].amount).to.equal(BigInt('0x200')); // token2\n expect(rsp.broadcasterFeeCommitment).to.not.be.undefined;\n expect(rsp.broadcasterFeeCommitment?.commitmentCiphertext).to.deep.equal(\n isV2Test()\n ? MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2\n : MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n );\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should get gas estimates for valid erc20 transfer: public wallet', async () => {\n stubGasEstimateSuccess();\n spyOnERC20Note();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n true, // sendWithPublicWallet\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args.length).to.equal(2); // Number of calls (without broadcaster fees)\n expect(erc20NoteSpy.args[0][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[1][0].amount).to.equal(BigInt('0x200')); // token2\n expect(rsp.broadcasterFeeCommitment).to.be.undefined;\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should error on gas estimates for invalid erc20 transfer', async () => {\n stubGasEstimateSuccess();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS_INVALID,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('Invalid DOP address.');\n });\n\n it('Should error on transfer gas estimate for ethers rejections', async () => {\n stubGasEstimateFailure();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('test rejection - gas estimate');\n });\n\n // TRANSFER NFT - GAS ESTIMATE\n\n it('Should get gas estimates for valid NFT transfer', async () => {\n stubGasEstimateSuccess();\n spyOnNFTNote();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS, // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n );\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args.length).to.equal(4); // Number of calls - 2 for each of 2 broadcaster fee iterations\n expect(nftNoteSpy.args[0][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[1][0].tokenSubID).to.equal('0x02'); // nft2\n expect(nftNoteSpy.args[2][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[3][0].tokenSubID).to.equal('0x02'); // nft2\n expect(rsp.broadcasterFeeCommitment).to.not.be.undefined;\n expect(rsp.broadcasterFeeCommitment?.commitmentCiphertext).to.deep.equal(\n isV2Test()\n ? MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2\n : MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n );\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should get gas estimates for valid NFT transfer: public wallet', async () => {\n stubGasEstimateSuccess();\n spyOnNFTNote();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n true, // sendWithPublicWallet\n );\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args.length).to.equal(2); // Number of calls (without broadcaster fees)\n expect(nftNoteSpy.args[0][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[1][0].tokenSubID).to.equal('0x02'); // nft2\n expect(rsp.broadcasterFeeCommitment).to.be.undefined;\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should error on gas estimates for invalid NFT transfer', async () => {\n stubGasEstimateSuccess();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS_INVALID,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('Invalid DOP address.');\n });\n\n // TRANSFER ERC20 - PROVE AND SEND\n\n it('Should populate tx for valid transfer', async () => {\n stubGasEstimateSuccess();\n setCachedProvedTransaction(undefined);\n spyOnERC20Note();\n spyOnNFTNote();\n await generateTransferProof(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n () => {}, // progressCallback\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args[0][0].amount).to.equal(MOCK_TOKEN_FEE.amount);\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args[0][0].nftAddress).to.equal(\n MOCK_NFT_AMOUNT_RECIPIENTS[0].nftAddress,\n );\n const populateResponse = await populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n );\n expect(populateResponse.nullifiers).to.deep.equal([\n '0x0000000000000000000000000000000000000000000000000000000000000001',\n '0x0000000000000000000000000000000000000000000000000000000000000002',\n ]);\n\n const { transaction } = populateResponse;\n\n expect(transaction.nonce).to.equal(undefined);\n expect(transaction.gasPrice?.toString()).to.equal('4096');\n expect(transaction.gasLimit).to.equal(1200n);\n expect(transaction.value?.toString()).to.equal(undefined);\n expect(transaction.data).to.equal('0x0123');\n expect(transaction.to).to.equal(undefined);\n expect(transaction.chainId).to.equal(undefined);\n expect(transaction.type).to.equal(1);\n });\n\n it('Should error on populate transfer tx for unproved transaction', async () => {\n stubGasEstimateSuccess();\n setCachedProvedTransaction(undefined);\n await expect(\n populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n false, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n ),\n ).rejectedWith('Invalid proof for this transaction');\n });\n\n it('Should error on populate transfer tx when params changed (invalid cached proof)', async () => {\n stubGasEstimateSuccess();\n await generateTransferProof(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n () => {}, // progressCallback\n );\n await expect(\n populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS_DIFFERENT,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n ),\n ).rejectedWith('Invalid proof for this transaction');\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"tx-transfer.test.js","sourceRoot":"","sources":["../../../../src/services/transactions/__tests__/tx-transfer.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,wEAA8C;AAC9C,kDAAmD;AACnD,iDAOuB;AACvB,6DAQ6B;AAC7B,0DAImC;AACnC,0DAmBmC;AACnC,gDAGwB;AACxB,sEAAwD;AACxD,4DAAqE;AACrE,uDAGmC;AACnC,gDAA4D;AAC5D,qDAAuC;AAEvC,4DAA0E;AAE1E,IAAI,eAA0B,CAAC;AAC/B,IAAI,YAAuB,CAAC;AAC5B,IAAI,iBAA4B,CAAC;AACjC,IAAI,eAA0B,CAAC;AAC/B,IAAI,kCAA6C,CAAC;AAClD,IAAI,aAAuB,CAAC;AAC5B,IAAI,YAAsB,CAAC;AAC3B,IAAI,UAAoB,CAAC;AAEzB,IAAI,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,OAAO,EACnB,SAAS,CAAC,EAAE,EACZ,mCAAsB,EACtB,IAAI,EAAE,+BAA+B;QACrC,sBAAS,EACT,4BAA4B,EAC5B,uCAA0B,EAC1B,kCAAkC,EAClC,KAAK,EAAE,uBAAuB;QAC9B,uBAAuB,EACvB,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;QACF,MAAM,MAAM,CACV,IAAA,oCAAsB,EACpB,WAAW,EACX,iCAAW,CAAC,OAAO,EACnB,SAAS,CAAC,EAAE,EACZ,IAAI,EAAE,+BAA+B;QACrC,sBAAS,EACT,sCAAsC,EACtC,uCAA0B,EAC1B,kCAAkC,EAClC,KAAK,EAAE,uBAAuB;QAC9B,uBAAuB,EACvB,UAAU,CACX,CACF,CAAC,YAAY,CAAC,oCAAoC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import chai from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport Sinon, { SinonStub, SinonSpy } from 'sinon';\nimport {\n DopWallet,\n TransactionBatch,\n RelayAdaptVersionedSmartContracts,\n TransactionStructV2,\n TransactionStructV3,\n DopVersionedSmartContracts,\n} from 'dop-engine-v3';\nimport {\n DopERC20Amount,\n NetworkName,\n EVMGasType,\n DopERC20AmountRecipient,\n DopNFTAmountRecipient,\n TransactionGasDetails,\n isDefined,\n} from 'dop-sharedmodels-v3';\nimport {\n closeTestEngine,\n initTestEngine,\n initTestEngineNetworks,\n} from '../../../tests/setup.test';\nimport {\n MOCK_BOUND_PARAMS_V2,\n MOCK_BOUND_PARAMS_V3,\n MOCK_COMMITMENTS,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_ETH_WALLET_ADDRESS,\n MOCK_FEE_TOKEN_DETAILS,\n MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2,\n MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n MOCK_MEMO,\n MOCK_MNEMONIC,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n MOCK_NULLIFIERS,\n MOCK_DOP_WALLET_ADDRESS,\n MOCK_TOKEN_ADDRESS,\n MOCK_TOKEN_ADDRESS_2,\n MOCK_TOKEN_AMOUNTS,\n MOCK_TOKEN_FEE,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n} from '../../../tests/mocks.test';\nimport {\n populateProvedTransfer,\n gasEstimateForUnprovenTransfer,\n} from '../tx-transfer';\nimport * as txGasDetailsModule from '../tx-gas-details';\nimport { generateTransferProofInternal } from '../tx-proof-transfer';\nimport {\n createDopWallet,\n fullWalletForID,\n} from '../../dop/wallets/wallets';\nimport { setCachedProvedTransaction } from '../proof-cache';\nimport * as txNotes from '../tx-notes';\nimport { ContractTransaction, FallbackProvider } from 'ethers';\nimport { getTestTXIDVersion, isV2Test } from '../../../tests/helper.test';\n\nlet gasEstimateStub: SinonStub;\nlet dopProveStub: SinonStub;\nlet dopDummyProveStub: SinonStub;\nlet dopTransactStub: SinonStub;\nlet relayAdaptPopulateDecryptBaseToken: SinonStub;\nlet setDecryptSpy: SinonSpy;\nlet erc20NoteSpy: SinonSpy;\nlet nftNoteSpy: SinonSpy;\n\nlet dopWallet: DopWallet;\nlet broadcasterFeeERC20AmountRecipient: DopERC20AmountRecipient;\n\nchai.use(chaiAsPromised);\nconst { expect } = chai;\n\nconst txidVersion = getTestTXIDVersion();\n\nconst MOCK_TOKEN_AMOUNTS_DIFFERENT: DopERC20Amount[] = [\n {\n tokenAddress: MOCK_TOKEN_ADDRESS,\n amount: 100n,\n },\n {\n tokenAddress: MOCK_TOKEN_ADDRESS_2,\n amount: 300n,\n },\n];\n\nconst overallBatchMinGasPrice = BigInt('0x1000');\n\nconst gasDetails: TransactionGasDetails = {\n evmGasType: EVMGasType.Type1,\n gasEstimate: 1000n,\n gasPrice: overallBatchMinGasPrice,\n};\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS_INVALID: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst MOCK_NFT_AMOUNT_RECIPIENTS_INVALID: DopNFTAmountRecipient[] =\n MOCK_NFT_AMOUNT_RECIPIENTS.map(nftAmountRecipient => ({\n ...nftAmountRecipient,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_DOP_WALLET_ADDRESS,\n }));\n\nconst MOCK_TOKEN_AMOUNT_RECIPIENTS_DIFFERENT: DopERC20AmountRecipient[] =\n MOCK_TOKEN_AMOUNTS_DIFFERENT.map(erc20Amount => ({\n ...erc20Amount,\n recipientAddress: MOCK_ETH_WALLET_ADDRESS,\n }));\n\nconst stubGasEstimateSuccess = () => {\n gasEstimateStub = Sinon.stub(txGasDetailsModule, 'getGasEstimate').resolves(\n BigInt('200'),\n );\n};\n\nconst stubGasEstimateFailure = () => {\n gasEstimateStub = Sinon.stub(txGasDetailsModule, 'getGasEstimate').rejects(\n new Error('test rejection - gas estimate'),\n );\n};\n\nconst spyOnERC20Note = () => {\n erc20NoteSpy = Sinon.spy(txNotes, 'erc20NoteFromERC20AmountRecipient');\n};\n\nconst spyOnNFTNote = () => {\n nftNoteSpy = Sinon.spy(txNotes, 'nftNoteFromNFTAmountRecipient');\n};\n\ndescribe('tx-transfer', () => {\n before(async function run() {\n this.timeout(60_000);\n await initTestEngine();\n await initTestEngineNetworks();\n const dopWalletInfo = await createDopWallet(\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MNEMONIC,\n undefined, // creationBlockNumbers\n );\n if (!isDefined(dopWalletInfo)) {\n throw new Error('Expected dopWalletInfo');\n }\n dopWallet = fullWalletForID(dopWalletInfo.id);\n\n const broadcasterWalletInfo = await createDopWallet(\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MNEMONIC,\n undefined, // creationBlockNumbers\n );\n if (!isDefined(broadcasterWalletInfo)) {\n throw new Error('Expected broadcasterWalletInfo');\n }\n\n const broadcasterDopAddress = broadcasterWalletInfo.dopAddress;\n\n broadcasterFeeERC20AmountRecipient = {\n ...MOCK_TOKEN_FEE,\n recipientAddress: broadcasterDopAddress,\n };\n\n dopProveStub = Sinon.stub(\n TransactionBatch.prototype,\n 'generateTransactions',\n ).resolves({\n provedTransactions: [\n {\n nullifiers: MOCK_NULLIFIERS,\n },\n ] as (TransactionStructV2 | TransactionStructV3)[],\n preTransactionPOIsPerTxidLeafPerList: {},\n });\n dopDummyProveStub = Sinon.stub(\n TransactionBatch.prototype,\n 'generateDummyTransactions',\n ).resolves([\n {\n txidVersion,\n commitments: MOCK_COMMITMENTS,\n boundParams: isV2Test() ? MOCK_BOUND_PARAMS_V2 : MOCK_BOUND_PARAMS_V3,\n nullifiers: MOCK_NULLIFIERS,\n },\n ] as (TransactionStructV2 | TransactionStructV3)[]);\n dopTransactStub = Sinon.stub(\n DopVersionedSmartContracts,\n 'generateTransact',\n ).resolves({ data: '0x0123' } as ContractTransaction);\n relayAdaptPopulateDecryptBaseToken = Sinon.stub(\n RelayAdaptVersionedSmartContracts,\n 'populateDecryptBaseToken',\n ).resolves({ data: '0x0123' } as ContractTransaction);\n });\n afterEach(() => {\n gasEstimateStub?.restore();\n setDecryptSpy?.restore();\n erc20NoteSpy?.restore();\n nftNoteSpy?.restore();\n });\n after(async () => {\n dopProveStub.restore();\n dopDummyProveStub.restore();\n dopTransactStub.restore();\n relayAdaptPopulateDecryptBaseToken.restore();\n await closeTestEngine();\n });\n\n // TRANSFER ERC20 - GAS ESTIMATE\n\n it('Should get gas estimates for valid erc20 transfer', async () => {\n stubGasEstimateSuccess();\n spyOnERC20Note();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args.length).to.equal(6); // Number of calls - 3 for each of 2 broadcaster fee iterations\n expect(erc20NoteSpy.args[0][0].amount).to.equal(BigInt('0x00')); // original broadcaster fee\n expect(erc20NoteSpy.args[1][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[2][0].amount).to.equal(BigInt('0x200')); // token2\n expect(erc20NoteSpy.args[3][0].amount).to.equal(\n BigInt('0x0275a61bf8737eb4'),\n ); // New estimated Broadcaster Fee\n expect(erc20NoteSpy.args[4][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[5][0].amount).to.equal(BigInt('0x200')); // token2\n expect(rsp.broadcasterFeeCommitment).to.not.be.undefined;\n expect(rsp.broadcasterFeeCommitment?.commitmentCiphertext).to.deep.equal(\n isV2Test()\n ? MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2\n : MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n );\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should get gas estimates for valid erc20 transfer: public wallet', async () => {\n stubGasEstimateSuccess();\n spyOnERC20Note();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n true, // sendWithPublicWallet\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args.length).to.equal(2); // Number of calls (without broadcaster fees)\n expect(erc20NoteSpy.args[0][0].amount).to.equal(BigInt('0x100')); // token1\n expect(erc20NoteSpy.args[1][0].amount).to.equal(BigInt('0x200')); // token2\n expect(rsp.broadcasterFeeCommitment).to.be.undefined;\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should error on gas estimates for invalid erc20 transfer', async () => {\n stubGasEstimateSuccess();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS_INVALID,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('Invalid DOP address.');\n });\n\n it('Should error on transfer gas estimate for ethers rejections', async () => {\n stubGasEstimateFailure();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n [], // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('test rejection - gas estimate');\n });\n\n // TRANSFER NFT - GAS ESTIMATE\n\n it('Should get gas estimates for valid NFT transfer', async () => {\n stubGasEstimateSuccess();\n spyOnNFTNote();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS, // nftAmountRecipients\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n );\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args.length).to.equal(4); // Number of calls - 2 for each of 2 broadcaster fee iterations\n expect(nftNoteSpy.args[0][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[1][0].tokenSubID).to.equal('0x02'); // nft2\n expect(nftNoteSpy.args[2][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[3][0].tokenSubID).to.equal('0x02'); // nft2\n expect(rsp.broadcasterFeeCommitment).to.not.be.undefined;\n expect(rsp.broadcasterFeeCommitment?.commitmentCiphertext).to.deep.equal(\n isV2Test()\n ? MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V2\n : MOCK_FORMATTED_BROADCASTER_FEE_COMMITMENT_CIPHERTEXT_V3,\n );\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should get gas estimates for valid NFT transfer: public wallet', async () => {\n stubGasEstimateSuccess();\n spyOnNFTNote();\n const rsp = await gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n true, // sendWithPublicWallet\n );\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args.length).to.equal(2); // Number of calls (without broadcaster fees)\n expect(nftNoteSpy.args[0][0].tokenSubID).to.equal('0x01'); // nft1\n expect(nftNoteSpy.args[1][0].tokenSubID).to.equal('0x02'); // nft2\n expect(rsp.broadcasterFeeCommitment).to.be.undefined;\n // Add 9000 for the dummy tx variance\n expect(rsp.gasEstimate).to.equal(9000n + 200n);\n }).timeout(10_000);\n\n it('Should error on gas estimates for invalid NFT transfer', async () => {\n stubGasEstimateSuccess();\n await expect(\n gasEstimateForUnprovenTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n MOCK_MEMO,\n [], // erc20AmountRecipients\n MOCK_NFT_AMOUNT_RECIPIENTS_INVALID,\n MOCK_TRANSACTION_GAS_DETAILS_SERIALIZED_TYPE_2,\n MOCK_FEE_TOKEN_DETAILS,\n false, // sendWithPublicWallet\n ),\n ).rejectedWith('Invalid DOP address.');\n });\n\n // TRANSFER ERC20 - PROVE AND SEND\n\n it('Should populate tx for valid transfer', async () => {\n stubGasEstimateSuccess();\n setCachedProvedTransaction(undefined);\n spyOnERC20Note();\n spyOnNFTNote();\n await generateTransferProofInternal(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n () => {}, // progressCallback\n );\n expect(erc20NoteSpy.called).to.be.true;\n expect(erc20NoteSpy.args[0][0].amount).to.equal(MOCK_TOKEN_FEE.amount);\n expect(nftNoteSpy.called).to.be.true;\n expect(nftNoteSpy.args[0][0].nftAddress).to.equal(\n MOCK_NFT_AMOUNT_RECIPIENTS[0].nftAddress,\n );\n const populateResponse = await populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n );\n expect(populateResponse.nullifiers).to.deep.equal([\n '0x0000000000000000000000000000000000000000000000000000000000000001',\n '0x0000000000000000000000000000000000000000000000000000000000000002',\n ]);\n\n const { transaction } = populateResponse;\n\n expect(transaction.nonce).to.equal(undefined);\n expect(transaction.gasPrice?.toString()).to.equal('4096');\n expect(transaction.gasLimit).to.equal(1200n);\n expect(transaction.value?.toString()).to.equal(undefined);\n expect(transaction.data).to.equal('0x0123');\n expect(transaction.to).to.equal(undefined);\n expect(transaction.chainId).to.equal(undefined);\n expect(transaction.type).to.equal(1);\n });\n\n it('Should error on populate transfer tx for unproved transaction', async () => {\n stubGasEstimateSuccess();\n setCachedProvedTransaction(undefined);\n await expect(\n populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n false, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n ),\n ).rejectedWith('Invalid proof for this transaction');\n });\n\n it('Should error on populate transfer tx when params changed (invalid cached proof)', async () => {\n stubGasEstimateSuccess();\n await generateTransferProofInternal(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n MOCK_DB_ENCRYPTION_KEY,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n () => {}, // progressCallback\n );\n await expect(\n populateProvedTransfer(\n txidVersion,\n NetworkName.Polygon,\n dopWallet.id,\n true, // showSenderAddressToRecipient\n MOCK_MEMO,\n MOCK_TOKEN_AMOUNT_RECIPIENTS_DIFFERENT,\n MOCK_NFT_AMOUNT_RECIPIENTS,\n broadcasterFeeERC20AmountRecipient,\n false, // sendWithPublicWallet\n overallBatchMinGasPrice,\n gasDetails,\n ),\n ).rejectedWith('Invalid proof for this transaction');\n });\n});\n"]}
|
|
@@ -7,6 +7,7 @@ export * from './tx-gas-details';
|
|
|
7
7
|
export * from './tx-gas-broadcaster-fee-estimator';
|
|
8
8
|
export * from './tx-generator';
|
|
9
9
|
export * from './tx-proof-transfer';
|
|
10
|
+
export * from './tx-proof-transfer-with-data';
|
|
10
11
|
export * from './tx-proof-decrypt';
|
|
11
12
|
export * from './tx-nullifiers';
|
|
12
13
|
export * from './tx-transfer';
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./tx-gas-details"), exports);
|
|
|
23
23
|
__exportStar(require("./tx-gas-broadcaster-fee-estimator"), exports);
|
|
24
24
|
__exportStar(require("./tx-generator"), exports);
|
|
25
25
|
__exportStar(require("./tx-proof-transfer"), exports);
|
|
26
|
+
__exportStar(require("./tx-proof-transfer-with-data"), exports);
|
|
26
27
|
__exportStar(require("./tx-proof-decrypt"), exports);
|
|
27
28
|
__exportStar(require("./tx-nullifiers"), exports);
|
|
28
29
|
__exportStar(require("./tx-transfer"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/transactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,4DAA0C;AAC1C,0DAAwC;AACxC,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qEAAmD;AACnD,iDAA+B;AAC/B,sDAAoC;AACpC,qDAAmC;AACnC,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B","sourcesContent":["export * from './proof-cache';\nexport * from './tx-cross-contract-calls';\nexport * from './tx-encrypt-base-token';\nexport * from './tx-encrypt';\nexport * from './tx-notes';\nexport * from './tx-gas-details';\nexport * from './tx-gas-broadcaster-fee-estimator';\nexport * from './tx-generator';\nexport * from './tx-proof-transfer';\nexport * from './tx-proof-decrypt';\nexport * from './tx-nullifiers';\nexport * from './tx-transfer';\nexport * from './tx-decrypt';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/transactions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,4DAA0C;AAC1C,0DAAwC;AACxC,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,qEAAmD;AACnD,iDAA+B;AAC/B,sDAAoC;AACpC,gEAA8C;AAC9C,qDAAmC;AACnC,kDAAgC;AAChC,gDAA8B;AAC9B,+CAA6B","sourcesContent":["export * from './proof-cache';\nexport * from './tx-cross-contract-calls';\nexport * from './tx-encrypt-base-token';\nexport * from './tx-encrypt';\nexport * from './tx-notes';\nexport * from './tx-gas-details';\nexport * from './tx-gas-broadcaster-fee-estimator';\nexport * from './tx-generator';\nexport * from './tx-proof-transfer';\nexport * from './tx-proof-transfer-with-data';\nexport * from './tx-proof-decrypt';\nexport * from './tx-nullifiers';\nexport * from './tx-transfer';\nexport * from './tx-decrypt';\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { NetworkName, DopERC20AmountRecipient, DopNFTAmountRecipient, TXIDVersion } from 'dop-sharedmodels-v3';
|
|
2
|
+
import { GenerateTransactionsProgressCallback } from './tx-generator';
|
|
3
|
+
export interface TransferProofData {
|
|
4
|
+
proof: {
|
|
5
|
+
a: {
|
|
6
|
+
x: string;
|
|
7
|
+
y: string;
|
|
8
|
+
};
|
|
9
|
+
b: {
|
|
10
|
+
x: [string, string];
|
|
11
|
+
y: [string, string];
|
|
12
|
+
};
|
|
13
|
+
c: {
|
|
14
|
+
x: string;
|
|
15
|
+
y: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
publicInputs: {
|
|
19
|
+
merkleRoot: string;
|
|
20
|
+
nullifiers: string[];
|
|
21
|
+
commitments: string[];
|
|
22
|
+
boundParamsHash: string;
|
|
23
|
+
};
|
|
24
|
+
transaction: {
|
|
25
|
+
data: string;
|
|
26
|
+
to?: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
};
|
|
29
|
+
nullifiers: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Internal function to generate transfer proof and cache it
|
|
33
|
+
* Following the dop-wallet pattern for clean separation of concerns
|
|
34
|
+
*/
|
|
35
|
+
export declare const generateTransferProofWithDataInternal: (txidVersion: TXIDVersion, networkName: NetworkName, dopWalletID: string, encryptionKey: string, showSenderAddressToRecipient: boolean, memoText: Optional<string>, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>, sendWithPublicWallet: boolean, overallBatchMinGasPrice: Optional<bigint>, progressCallback: GenerateTransactionsProgressCallback) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Extract proof data from cached transaction for explorer verification
|
|
38
|
+
* This function should be called after generateTransferProofInternal
|
|
39
|
+
*/
|
|
40
|
+
export declare const extractTransferProofData: () => TransferProofData;
|
|
41
|
+
/**
|
|
42
|
+
* Generate transfer proof and return proof data for explorer verification
|
|
43
|
+
* This is the main function that frontend developers should use
|
|
44
|
+
*/
|
|
45
|
+
export declare const generateTransferProof: (txidVersion: TXIDVersion, networkName: NetworkName, dopWalletID: string, encryptionKey: string, showSenderAddressToRecipient: boolean, memoText: Optional<string>, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>, sendWithPublicWallet: boolean, overallBatchMinGasPrice: Optional<bigint>, progressCallback: GenerateTransactionsProgressCallback) => Promise<TransferProofData>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTransferProof = exports.extractTransferProofData = exports.generateTransferProofWithDataInternal = void 0;
|
|
4
|
+
const dop_sharedmodels_v3_1 = require("dop-sharedmodels-v3");
|
|
5
|
+
const tx_generator_1 = require("./tx-generator");
|
|
6
|
+
const proof_cache_1 = require("./proof-cache");
|
|
7
|
+
const error_1 = require("../../utils/error");
|
|
8
|
+
const bigint_serialization_1 = require("../../utils/bigint-serialization");
|
|
9
|
+
/**
|
|
10
|
+
* Internal function to generate transfer proof and cache it
|
|
11
|
+
* Following the dop-wallet pattern for clean separation of concerns
|
|
12
|
+
*/
|
|
13
|
+
const generateTransferProofWithDataInternal = async (txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback) => {
|
|
14
|
+
try {
|
|
15
|
+
(0, proof_cache_1.setCachedProvedTransaction)(undefined);
|
|
16
|
+
const { provedTransactions } = await (0, tx_generator_1.generateProofTransactions)(dop_sharedmodels_v3_1.ProofType.Transfer, networkName, dopWalletID, txidVersion, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, undefined, // relayAdaptID
|
|
17
|
+
false, // useDummyProof
|
|
18
|
+
overallBatchMinGasPrice, progressCallback);
|
|
19
|
+
const transaction = await (0, tx_generator_1.generateTransact)(txidVersion, provedTransactions, networkName, 0n);
|
|
20
|
+
const nullifiers = (0, tx_generator_1.nullifiersForTransactions)(provedTransactions);
|
|
21
|
+
// Cast to our enhanced type that includes proved transactions
|
|
22
|
+
const enhancedProvedTransaction = {
|
|
23
|
+
proofType: dop_sharedmodels_v3_1.ProofType.Transfer,
|
|
24
|
+
txidVersion,
|
|
25
|
+
dopWalletID,
|
|
26
|
+
showSenderAddressToRecipient,
|
|
27
|
+
memoText,
|
|
28
|
+
erc20AmountRecipients,
|
|
29
|
+
nftAmountRecipients,
|
|
30
|
+
relayAdaptDecryptERC20Amounts: undefined,
|
|
31
|
+
relayAdaptDecryptNFTAmounts: undefined,
|
|
32
|
+
relayAdaptEncryptERC20Recipients: undefined,
|
|
33
|
+
relayAdaptEncryptNFTRecipients: undefined,
|
|
34
|
+
crossContractCalls: undefined,
|
|
35
|
+
broadcasterFeeERC20AmountRecipient,
|
|
36
|
+
sendWithPublicWallet,
|
|
37
|
+
transaction,
|
|
38
|
+
overallBatchMinGasPrice,
|
|
39
|
+
nullifiers,
|
|
40
|
+
provedTransactions, // Store the actual proved transactions
|
|
41
|
+
};
|
|
42
|
+
(0, proof_cache_1.setCachedProvedTransaction)(enhancedProvedTransaction);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
throw (0, error_1.reportAndSanitizeError)(exports.generateTransferProofWithDataInternal.name, err);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.generateTransferProofWithDataInternal = generateTransferProofWithDataInternal;
|
|
49
|
+
/**
|
|
50
|
+
* Extract proof data from cached transaction for explorer verification
|
|
51
|
+
* This function should be called after generateTransferProofInternal
|
|
52
|
+
*/
|
|
53
|
+
const extractTransferProofData = () => {
|
|
54
|
+
try {
|
|
55
|
+
const cachedTransaction = (0, proof_cache_1.getCachedProvedTransaction)();
|
|
56
|
+
if (cachedTransaction === undefined) {
|
|
57
|
+
throw new Error('No cached proof found. Call generateTransferProofInternal first.');
|
|
58
|
+
}
|
|
59
|
+
if (cachedTransaction.provedTransactions == null || cachedTransaction.provedTransactions.length === 0) {
|
|
60
|
+
throw new Error('No proved transactions found in cached data.');
|
|
61
|
+
}
|
|
62
|
+
// Get the first proved transaction to extract proof data
|
|
63
|
+
const provedTransaction = cachedTransaction.provedTransactions[0];
|
|
64
|
+
// Extract proof components from the actual proved transaction
|
|
65
|
+
const proofData = {
|
|
66
|
+
proof: {
|
|
67
|
+
a: {
|
|
68
|
+
x: provedTransaction.proof.a.x.toString(),
|
|
69
|
+
y: provedTransaction.proof.a.y.toString(),
|
|
70
|
+
},
|
|
71
|
+
b: {
|
|
72
|
+
x: [
|
|
73
|
+
provedTransaction.proof.b.x[0].toString(),
|
|
74
|
+
provedTransaction.proof.b.x[1].toString(),
|
|
75
|
+
],
|
|
76
|
+
y: [
|
|
77
|
+
provedTransaction.proof.b.y[0].toString(),
|
|
78
|
+
provedTransaction.proof.b.y[1].toString(),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
c: {
|
|
82
|
+
x: provedTransaction.proof.c.x.toString(),
|
|
83
|
+
y: provedTransaction.proof.c.y.toString(),
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
publicInputs: {
|
|
87
|
+
merkleRoot: provedTransaction.merkleRoot.toString(),
|
|
88
|
+
nullifiers: provedTransaction.nullifiers.map((n) => n.toString()),
|
|
89
|
+
commitments: provedTransaction.commitments.map((c) => c.toString()),
|
|
90
|
+
boundParamsHash: (0, bigint_serialization_1.stringifyWithBigInt)(provedTransaction.boundParams),
|
|
91
|
+
},
|
|
92
|
+
transaction: {
|
|
93
|
+
data: (cachedTransaction.transaction.data != null) ? cachedTransaction.transaction.data : '0x',
|
|
94
|
+
to: cachedTransaction.transaction.to,
|
|
95
|
+
value: cachedTransaction.transaction.value?.toString(),
|
|
96
|
+
},
|
|
97
|
+
nullifiers: cachedTransaction.nullifiers,
|
|
98
|
+
};
|
|
99
|
+
return proofData;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw (0, error_1.reportAndSanitizeError)(exports.extractTransferProofData.name, err);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
exports.extractTransferProofData = extractTransferProofData;
|
|
106
|
+
/**
|
|
107
|
+
* Generate transfer proof and return proof data for explorer verification
|
|
108
|
+
* This is the main function that frontend developers should use
|
|
109
|
+
*/
|
|
110
|
+
const generateTransferProof = async (txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback) => {
|
|
111
|
+
try {
|
|
112
|
+
// First generate the proof following the established pattern
|
|
113
|
+
await (0, exports.generateTransferProofWithDataInternal)(txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback);
|
|
114
|
+
// Then extract the proof data for explorer verification
|
|
115
|
+
return (0, exports.extractTransferProofData)();
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
throw (0, error_1.reportAndSanitizeError)(exports.generateTransferProof.name, err);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exports.generateTransferProof = generateTransferProof;
|
|
122
|
+
//# sourceMappingURL=tx-proof-transfer-with-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx-proof-transfer-with-data.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-proof-transfer-with-data.ts"],"names":[],"mappings":";;;AAAA,6DAM6B;AAC7B,iDAKwB;AACxB,+CAAuF;AACvF,6CAA2D;AAE3D,2EAAuE;AAkDvE;;;GAGG;AACI,MAAM,qCAAqC,GAAG,KAAK,EACxD,WAAwB,EACxB,WAAwB,EACxB,WAAmB,EACnB,aAAqB,EACrB,4BAAqC,EACrC,QAA0B,EAC1B,qBAAgD,EAChD,mBAA4C,EAC5C,kCAAqE,EACrE,oBAA6B,EAC7B,uBAAyC,EACzC,gBAAsD,EACvC,EAAE;IACjB,IAAI;QACF,IAAA,wCAA0B,EAAC,SAAS,CAAC,CAAC;QAEtC,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,IAAA,wCAAyB,EAC5D,+BAAS,CAAC,QAAQ,EAClB,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,EACb,4BAA4B,EAC5B,QAAQ,EACR,qBAAqB,EACrB,mBAAmB,EACnB,kCAAkC,EAClC,oBAAoB,EACpB,SAAS,EAAE,eAAe;QAC1B,KAAK,EAAE,gBAAgB;QACvB,uBAAuB,E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,CAAC;AApCW,QAAA,qBAAqB,yBAoChC","sourcesContent":["import {\n NetworkName,\n ProofType,\n DopERC20AmountRecipient,\n DopNFTAmountRecipient,\n TXIDVersion,\n} from 'dop-sharedmodels-v3';\nimport {\n GenerateTransactionsProgressCallback,\n generateProofTransactions,\n generateTransact,\n nullifiersForTransactions,\n} from './tx-generator';\nimport { setCachedProvedTransaction, getCachedProvedTransaction } from './proof-cache';\nimport { reportAndSanitizeError } from '../../utils/error';\nimport { TransactionStructV2, TransactionStructV3 } from 'dop-engine-v3';\nimport { stringifyWithBigInt } from '../../utils/bigint-serialization';\n\n// Type for the proof data needed for explorer verification\nexport interface TransferProofData {\n // ZK-SNARK proof components\n proof: {\n a: { x: string; y: string };\n b: { x: [string, string]; y: [string, string] };\n c: { x: string; y: string };\n };\n // Public inputs for verification\n publicInputs: {\n merkleRoot: string;\n nullifiers: string[];\n commitments: string[];\n boundParamsHash: string;\n };\n // Transaction data\n transaction: {\n data: string;\n to?: string;\n value?: string;\n };\n // Additional metadata\n nullifiers: string[];\n}\n\n// Enhanced cached transaction type that includes the actual proved transactions\ninterface EnhancedProvedTransaction {\n proofType: ProofType;\n txidVersion: TXIDVersion;\n transaction: any;\n dopWalletID: string;\n showSenderAddressToRecipient: boolean;\n memoText: Optional<string>;\n erc20AmountRecipients: DopERC20AmountRecipient[];\n nftAmountRecipients: DopNFTAmountRecipient[];\n relayAdaptDecryptERC20Amounts: Optional<any[]>;\n relayAdaptDecryptNFTAmounts: Optional<any[]>;\n relayAdaptEncryptERC20Recipients: Optional<any[]>;\n relayAdaptEncryptNFTRecipients: Optional<any[]>;\n crossContractCalls: Optional<any[]>;\n broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>;\n sendWithPublicWallet: boolean;\n overallBatchMinGasPrice: Optional<bigint>;\n nullifiers: string[];\n // Store the actual proved transactions for proof data extraction\n provedTransactions: (TransactionStructV2 | TransactionStructV3)[];\n}\n\n/**\n * Internal function to generate transfer proof and cache it\n * Following the dop-wallet pattern for clean separation of concerns\n */\nexport const generateTransferProofWithDataInternal = async (\n txidVersion: TXIDVersion,\n networkName: NetworkName,\n dopWalletID: string,\n encryptionKey: string,\n showSenderAddressToRecipient: boolean,\n memoText: Optional<string>,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>,\n sendWithPublicWallet: boolean,\n overallBatchMinGasPrice: Optional<bigint>,\n progressCallback: GenerateTransactionsProgressCallback,\n): Promise<void> => {\n try {\n setCachedProvedTransaction(undefined);\n\n const { provedTransactions } = await generateProofTransactions(\n ProofType.Transfer,\n networkName,\n dopWalletID,\n txidVersion,\n encryptionKey,\n showSenderAddressToRecipient,\n memoText,\n erc20AmountRecipients,\n nftAmountRecipients,\n broadcasterFeeERC20AmountRecipient,\n sendWithPublicWallet,\n undefined, // relayAdaptID\n false, // useDummyProof\n overallBatchMinGasPrice,\n progressCallback,\n );\n \n const transaction = await generateTransact(\n txidVersion,\n provedTransactions,\n networkName,\n 0n\n );\n\n const nullifiers = nullifiersForTransactions(provedTransactions);\n\n // Cast to our enhanced type that includes proved transactions\n const enhancedProvedTransaction: EnhancedProvedTransaction = {\n proofType: ProofType.Transfer,\n txidVersion,\n dopWalletID,\n showSenderAddressToRecipient,\n memoText,\n erc20AmountRecipients,\n nftAmountRecipients,\n relayAdaptDecryptERC20Amounts: undefined,\n relayAdaptDecryptNFTAmounts: undefined,\n relayAdaptEncryptERC20Recipients: undefined,\n relayAdaptEncryptNFTRecipients: undefined,\n crossContractCalls: undefined,\n broadcasterFeeERC20AmountRecipient,\n sendWithPublicWallet,\n transaction,\n overallBatchMinGasPrice,\n nullifiers,\n provedTransactions, // Store the actual proved transactions\n };\n\n setCachedProvedTransaction(enhancedProvedTransaction);\n } catch (err) {\n throw reportAndSanitizeError(generateTransferProofWithDataInternal.name, err);\n }\n};\n\n/**\n * Extract proof data from cached transaction for explorer verification\n * This function should be called after generateTransferProofInternal\n */\nexport const extractTransferProofData = (): TransferProofData => {\n try {\n const cachedTransaction = getCachedProvedTransaction() as EnhancedProvedTransaction;\n \n if (cachedTransaction === undefined) {\n throw new Error('No cached proof found. Call generateTransferProofInternal first.');\n }\n\n if (cachedTransaction.provedTransactions == null || cachedTransaction.provedTransactions.length === 0) {\n throw new Error('No proved transactions found in cached data.');\n }\n\n // Get the first proved transaction to extract proof data\n const provedTransaction = cachedTransaction.provedTransactions[0];\n \n // Extract proof components from the actual proved transaction\n const proofData: TransferProofData = {\n proof: {\n a: {\n x: provedTransaction.proof.a.x.toString(),\n y: provedTransaction.proof.a.y.toString(),\n },\n b: {\n x: [\n provedTransaction.proof.b.x[0].toString(),\n provedTransaction.proof.b.x[1].toString(),\n ],\n y: [\n provedTransaction.proof.b.y[0].toString(),\n provedTransaction.proof.b.y[1].toString(),\n ],\n },\n c: {\n x: provedTransaction.proof.c.x.toString(),\n y: provedTransaction.proof.c.y.toString(),\n },\n },\n publicInputs: {\n merkleRoot: provedTransaction.merkleRoot.toString(),\n nullifiers: provedTransaction.nullifiers.map((n: any) => n.toString()),\n commitments: provedTransaction.commitments.map((c: any) => c.toString()),\n boundParamsHash: stringifyWithBigInt(provedTransaction.boundParams),\n },\n transaction: {\n data: (cachedTransaction.transaction.data != null) ? cachedTransaction.transaction.data : '0x',\n to: cachedTransaction.transaction.to,\n value: cachedTransaction.transaction.value?.toString(),\n },\n nullifiers: cachedTransaction.nullifiers,\n };\n\n return proofData;\n } catch (err) {\n throw reportAndSanitizeError(extractTransferProofData.name, err);\n }\n};\n\n/**\n * Generate transfer proof and return proof data for explorer verification\n * This is the main function that frontend developers should use\n */\nexport const generateTransferProof = async (\n txidVersion: TXIDVersion,\n networkName: NetworkName,\n dopWalletID: string,\n encryptionKey: string,\n showSenderAddressToRecipient: boolean,\n memoText: Optional<string>,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>,\n sendWithPublicWallet: boolean,\n overallBatchMinGasPrice: Optional<bigint>,\n progressCallback: GenerateTransactionsProgressCallback,\n): Promise<TransferProofData> => {\n try {\n // First generate the proof following the established pattern\n await generateTransferProofWithDataInternal(\n txidVersion,\n networkName,\n dopWalletID,\n encryptionKey,\n showSenderAddressToRecipient,\n memoText,\n erc20AmountRecipients,\n nftAmountRecipients,\n broadcasterFeeERC20AmountRecipient,\n sendWithPublicWallet,\n overallBatchMinGasPrice,\n progressCallback,\n );\n\n // Then extract the proof data for explorer verification\n return extractTransferProofData();\n } catch (err) {\n throw reportAndSanitizeError(generateTransferProof.name, err);\n }\n};\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NetworkName, DopERC20AmountRecipient, DopNFTAmountRecipient, TXIDVersion } from 'dop-sharedmodels-v3';
|
|
2
2
|
import { GenerateTransactionsProgressCallback } from './tx-generator';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const generateTransferProofInternal: (txidVersion: TXIDVersion, networkName: NetworkName, dopWalletID: string, encryptionKey: string, showSenderAddressToRecipient: boolean, memoText: Optional<string>, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>, sendWithPublicWallet: boolean, overallBatchMinGasPrice: Optional<bigint>, progressCallback: GenerateTransactionsProgressCallback) => Promise<void>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateTransferProofInternal = void 0;
|
|
4
4
|
const dop_sharedmodels_v3_1 = require("dop-sharedmodels-v3");
|
|
5
5
|
const tx_generator_1 = require("./tx-generator");
|
|
6
6
|
const proof_cache_1 = require("./proof-cache");
|
|
7
7
|
const error_1 = require("../../utils/error");
|
|
8
|
-
const
|
|
8
|
+
const generateTransferProofInternal = async (txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback) => {
|
|
9
9
|
try {
|
|
10
10
|
(0, proof_cache_1.setCachedProvedTransaction)(undefined);
|
|
11
11
|
const { provedTransactions } = await (0, tx_generator_1.generateProofTransactions)(dop_sharedmodels_v3_1.ProofType.Transfer, networkName, dopWalletID, txidVersion, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, undefined, // relayAdaptID
|
|
@@ -34,8 +34,8 @@ const generateTransferProof = async (txidVersion, networkName, dopWalletID, encr
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
catch (err) {
|
|
37
|
-
throw (0, error_1.reportAndSanitizeError)(exports.
|
|
37
|
+
throw (0, error_1.reportAndSanitizeError)(exports.generateTransferProofInternal.name, err);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
exports.
|
|
40
|
+
exports.generateTransferProofInternal = generateTransferProofInternal;
|
|
41
41
|
//# sourceMappingURL=tx-proof-transfer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx-proof-transfer.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-proof-transfer.ts"],"names":[],"mappings":";;;AAAA,6DAM6B;AAC7B,iDAKwB;AACxB,+CAA2D;AAC3D,6CAA2D;AAEpD,MAAM,
|
|
1
|
+
{"version":3,"file":"tx-proof-transfer.js","sourceRoot":"","sources":["../../../src/services/transactions/tx-proof-transfer.ts"],"names":[],"mappings":";;;AAAA,6DAM6B;AAC7B,iDAKwB;AACxB,+CAA2D;AAC3D,6CAA2D;AAEpD,MAAM,6BAA6B,GAAG,KAAK,EAChD,WAAwB,EACxB,WAAwB,EACxB,WAAmB,EACnB,aAAqB,EACrB,4BAAqC,EAC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ecipient,\n TXIDVersion,\n} from 'dop-sharedmodels-v3';\nimport {\n GenerateTransactionsProgressCallback,\n generateProofTransactions,\n generateTransact,\n nullifiersForTransactions,\n} from './tx-generator';\nimport { setCachedProvedTransaction } from './proof-cache';\nimport { reportAndSanitizeError } from '../../utils/error';\n\nexport const generateTransferProofInternal = async (\n txidVersion: TXIDVersion,\n networkName: NetworkName,\n dopWalletID: string,\n encryptionKey: string,\n showSenderAddressToRecipient: boolean,\n memoText: Optional<string>,\n erc20AmountRecipients: DopERC20AmountRecipient[],\n nftAmountRecipients: DopNFTAmountRecipient[],\n broadcasterFeeERC20AmountRecipient: Optional<DopERC20AmountRecipient>,\n sendWithPublicWallet: boolean,\n overallBatchMinGasPrice: Optional<bigint>,\n progressCallback: GenerateTransactionsProgressCallback,\n): Promise<void> => {\n try {\n setCachedProvedTransaction(undefined);\n\n const { provedTransactions } =\n await generateProofTransactions(\n ProofType.Transfer,\n networkName,\n dopWalletID,\n txidVersion,\n encryptionKey,\n showSenderAddressToRecipient,\n memoText,\n erc20AmountRecipients,\n nftAmountRecipients,\n broadcasterFeeERC20AmountRecipient,\n sendWithPublicWallet,\n undefined, // relayAdaptID\n false, // useDummyProof\n overallBatchMinGasPrice,\n progressCallback,\n );\n const transaction = await generateTransact(\n txidVersion,\n provedTransactions,\n networkName,\n 0n\n );\n\n const nullifiers = nullifiersForTransactions(provedTransactions);\n\n setCachedProvedTransaction({\n proofType: ProofType.Transfer,\n txidVersion,\n dopWalletID,\n showSenderAddressToRecipient,\n memoText,\n erc20AmountRecipients,\n nftAmountRecipients,\n relayAdaptDecryptERC20Amounts: undefined,\n relayAdaptDecryptNFTAmounts: undefined,\n relayAdaptEncryptERC20Recipients: undefined,\n relayAdaptEncryptNFTRecipients: undefined,\n crossContractCalls: undefined,\n broadcasterFeeERC20AmountRecipient,\n sendWithPublicWallet,\n transaction,\n overallBatchMinGasPrice,\n nullifiers,\n });\n } catch (err) {\n throw reportAndSanitizeError(generateTransferProofInternal.name, err);\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const bigint_serialization_1 = require("../bigint-serialization");
|
|
5
|
+
describe('BigInt Serialization Utility', () => {
|
|
6
|
+
describe('bigIntReplacer', () => {
|
|
7
|
+
it('should convert BigInt values to strings', () => {
|
|
8
|
+
const bigIntValue = BigInt('123456789012345678901234567890');
|
|
9
|
+
const result = (0, bigint_serialization_1.bigIntReplacer)('test', bigIntValue);
|
|
10
|
+
(0, chai_1.expect)(result).to.equal('123456789012345678901234567890');
|
|
11
|
+
});
|
|
12
|
+
it('should pass through non-BigInt values unchanged', () => {
|
|
13
|
+
(0, chai_1.expect)((0, bigint_serialization_1.bigIntReplacer)('test', 'string')).to.equal('string');
|
|
14
|
+
(0, chai_1.expect)((0, bigint_serialization_1.bigIntReplacer)('test', 123)).to.equal(123);
|
|
15
|
+
(0, chai_1.expect)((0, bigint_serialization_1.bigIntReplacer)('test', null)).to.equal(null);
|
|
16
|
+
(0, chai_1.expect)((0, bigint_serialization_1.bigIntReplacer)('test', undefined)).to.equal(undefined);
|
|
17
|
+
(0, chai_1.expect)((0, bigint_serialization_1.bigIntReplacer)('test', true)).to.equal(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('stringifyWithBigInt', () => {
|
|
21
|
+
it('should serialize objects containing BigInt values', () => {
|
|
22
|
+
const testObject = {
|
|
23
|
+
normalValue: 'test',
|
|
24
|
+
bigIntValue: BigInt('987654321098765432109876543210'),
|
|
25
|
+
nestedObject: {
|
|
26
|
+
anotherBigInt: BigInt('1111111111111111111111111111'),
|
|
27
|
+
normalNumber: 42
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const result = (0, bigint_serialization_1.stringifyWithBigInt)(testObject);
|
|
31
|
+
const parsed = JSON.parse(result);
|
|
32
|
+
(0, chai_1.expect)(parsed.normalValue).to.equal('test');
|
|
33
|
+
(0, chai_1.expect)(parsed.bigIntValue).to.equal('987654321098765432109876543210');
|
|
34
|
+
(0, chai_1.expect)(parsed.nestedObject.anotherBigInt).to.equal('1111111111111111111111111111');
|
|
35
|
+
(0, chai_1.expect)(parsed.nestedObject.normalNumber).to.equal(42);
|
|
36
|
+
});
|
|
37
|
+
it('should handle arrays with BigInt values', () => {
|
|
38
|
+
const testArray = [
|
|
39
|
+
BigInt('111'),
|
|
40
|
+
'string',
|
|
41
|
+
BigInt('222'),
|
|
42
|
+
{ bigIntProp: BigInt('333') }
|
|
43
|
+
];
|
|
44
|
+
const result = (0, bigint_serialization_1.stringifyWithBigInt)(testArray);
|
|
45
|
+
const parsed = JSON.parse(result);
|
|
46
|
+
(0, chai_1.expect)(parsed[0]).to.equal('111');
|
|
47
|
+
(0, chai_1.expect)(parsed[1]).to.equal('string');
|
|
48
|
+
(0, chai_1.expect)(parsed[2]).to.equal('222');
|
|
49
|
+
(0, chai_1.expect)(parsed[3].bigIntProp).to.equal('333');
|
|
50
|
+
});
|
|
51
|
+
it('should not throw "Do not know how to serialize a BigInt" error', () => {
|
|
52
|
+
const objectWithBigInt = {
|
|
53
|
+
boundParams: {
|
|
54
|
+
treeNumber: BigInt('1'),
|
|
55
|
+
minGasPrice: BigInt('1000000000'),
|
|
56
|
+
unshield: BigInt('0'),
|
|
57
|
+
chainID: BigInt('137')
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
// This should not throw an error
|
|
61
|
+
(0, chai_1.expect)(() => (0, bigint_serialization_1.stringifyWithBigInt)(objectWithBigInt)).to.not.throw();
|
|
62
|
+
// And should produce valid JSON
|
|
63
|
+
const result = (0, bigint_serialization_1.stringifyWithBigInt)(objectWithBigInt);
|
|
64
|
+
(0, chai_1.expect)(() => JSON.parse(result)).to.not.throw();
|
|
65
|
+
});
|
|
66
|
+
it('should preserve the original functionality for native JSON.stringify failures', () => {
|
|
67
|
+
// Test with circular reference
|
|
68
|
+
const circularObj = { name: 'test' };
|
|
69
|
+
circularObj.self = circularObj;
|
|
70
|
+
(0, chai_1.expect)(() => (0, bigint_serialization_1.stringifyWithBigInt)(circularObj)).to.throw();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('Real-world BigInt usage scenarios', () => {
|
|
74
|
+
it('should handle transaction-like objects with BigInt values', () => {
|
|
75
|
+
const mockTransactionData = {
|
|
76
|
+
proof: {
|
|
77
|
+
a: { x: BigInt('12345'), y: BigInt('67890') },
|
|
78
|
+
b: {
|
|
79
|
+
x: [BigInt('11111'), BigInt('22222')],
|
|
80
|
+
y: [BigInt('33333'), BigInt('44444')]
|
|
81
|
+
},
|
|
82
|
+
c: { x: BigInt('55555'), y: BigInt('66666') }
|
|
83
|
+
},
|
|
84
|
+
publicInputs: {
|
|
85
|
+
merkleRoot: BigInt('999999999999999999999'),
|
|
86
|
+
nullifiers: [BigInt('111111'), BigInt('222222')],
|
|
87
|
+
commitments: [BigInt('333333'), BigInt('444444')],
|
|
88
|
+
boundParamsHash: BigInt('555555555555555555555')
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// This should not throw the "Do not know how to serialize a BigInt" error
|
|
92
|
+
(0, chai_1.expect)(() => (0, bigint_serialization_1.stringifyWithBigInt)(mockTransactionData)).to.not.throw();
|
|
93
|
+
const result = (0, bigint_serialization_1.stringifyWithBigInt)(mockTransactionData);
|
|
94
|
+
const parsed = JSON.parse(result);
|
|
95
|
+
// Verify the structure is preserved and BigInt values are converted to strings
|
|
96
|
+
(0, chai_1.expect)(parsed.proof.a.x).to.equal('12345');
|
|
97
|
+
(0, chai_1.expect)(parsed.proof.a.y).to.equal('67890');
|
|
98
|
+
(0, chai_1.expect)(parsed.proof.b.x[0]).to.equal('11111');
|
|
99
|
+
(0, chai_1.expect)(parsed.proof.b.x[1]).to.equal('22222');
|
|
100
|
+
(0, chai_1.expect)(parsed.publicInputs.merkleRoot).to.equal('999999999999999999999');
|
|
101
|
+
(0, chai_1.expect)(parsed.publicInputs.nullifiers[0]).to.equal('111111');
|
|
102
|
+
(0, chai_1.expect)(parsed.publicInputs.commitments[1]).to.equal('444444');
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=bigint-serialization.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint-serialization.test.js","sourceRoot":"","sources":["../../../src/utils/__tests__/bigint-serialization.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,kEAA8E;AAE9E,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YACjD,MAAM,WAAW,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;YAC7D,MAAM,MAAM,GAAG,IAAA,qCAAc,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACnD,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,IAAA,aAAM,EAAC,IAAA,qCAAc,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC5D,IAAA,aAAM,EAAC,IAAA,qCAAc,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClD,IAAA,aAAM,EAAC,IAAA,qCAAc,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACpD,IAAA,aAAM,EAAC,IAAA,qCAAc,EAAC,MAAM,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C,CAAC;QAChE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from 'chai';\nimport { stringifyWithBigInt, bigIntReplacer } from '../bigint-serialization';\n\ndescribe('BigInt Serialization Utility', () => {\n describe('bigIntReplacer', () => {\n it('should convert BigInt values to strings', () => {\n const bigIntValue = BigInt('123456789012345678901234567890');\n const result = bigIntReplacer('test', bigIntValue);\n expect(result).to.equal('123456789012345678901234567890');\n });\n\n it('should pass through non-BigInt values unchanged', () => {\n expect(bigIntReplacer('test', 'string')).to.equal('string');\n expect(bigIntReplacer('test', 123)).to.equal(123);\n expect(bigIntReplacer('test', null)).to.equal(null);\n expect(bigIntReplacer('test', undefined)).to.equal(undefined);\n expect(bigIntReplacer('test', true)).to.equal(true);\n });\n });\n\n describe('stringifyWithBigInt', () => {\n it('should serialize objects containing BigInt values', () => {\n const testObject = {\n normalValue: 'test',\n bigIntValue: BigInt('987654321098765432109876543210'),\n nestedObject: {\n anotherBigInt: BigInt('1111111111111111111111111111'),\n normalNumber: 42\n }\n };\n\n const result = stringifyWithBigInt(testObject);\n const parsed = JSON.parse(result);\n\n expect(parsed.normalValue).to.equal('test');\n expect(parsed.bigIntValue).to.equal('987654321098765432109876543210');\n expect(parsed.nestedObject.anotherBigInt).to.equal('1111111111111111111111111111');\n expect(parsed.nestedObject.normalNumber).to.equal(42);\n });\n\n it('should handle arrays with BigInt values', () => {\n const testArray = [\n BigInt('111'),\n 'string',\n BigInt('222'),\n { bigIntProp: BigInt('333') }\n ];\n\n const result = stringifyWithBigInt(testArray);\n const parsed = JSON.parse(result);\n\n expect(parsed[0]).to.equal('111');\n expect(parsed[1]).to.equal('string');\n expect(parsed[2]).to.equal('222');\n expect(parsed[3].bigIntProp).to.equal('333');\n });\n\n it('should not throw \"Do not know how to serialize a BigInt\" error', () => {\n const objectWithBigInt = {\n boundParams: {\n treeNumber: BigInt('1'),\n minGasPrice: BigInt('1000000000'),\n unshield: BigInt('0'),\n chainID: BigInt('137')\n }\n };\n\n // This should not throw an error\n expect(() => stringifyWithBigInt(objectWithBigInt)).to.not.throw();\n \n // And should produce valid JSON\n const result = stringifyWithBigInt(objectWithBigInt);\n expect(() => JSON.parse(result)).to.not.throw();\n });\n\n it('should preserve the original functionality for native JSON.stringify failures', () => {\n // Test with circular reference\n const circularObj: any = { name: 'test' };\n circularObj.self = circularObj;\n\n expect(() => stringifyWithBigInt(circularObj)).to.throw();\n });\n });\n\n describe('Real-world BigInt usage scenarios', () => {\n it('should handle transaction-like objects with BigInt values', () => {\n const mockTransactionData = {\n proof: {\n a: { x: BigInt('12345'), y: BigInt('67890') },\n b: { \n x: [BigInt('11111'), BigInt('22222')], \n y: [BigInt('33333'), BigInt('44444')] \n },\n c: { x: BigInt('55555'), y: BigInt('66666') }\n },\n publicInputs: {\n merkleRoot: BigInt('999999999999999999999'),\n nullifiers: [BigInt('111111'), BigInt('222222')],\n commitments: [BigInt('333333'), BigInt('444444')],\n boundParamsHash: BigInt('555555555555555555555')\n }\n };\n\n // This should not throw the \"Do not know how to serialize a BigInt\" error\n expect(() => stringifyWithBigInt(mockTransactionData)).to.not.throw();\n \n const result = stringifyWithBigInt(mockTransactionData);\n const parsed = JSON.parse(result);\n \n // Verify the structure is preserved and BigInt values are converted to strings\n expect(parsed.proof.a.x).to.equal('12345');\n expect(parsed.proof.a.y).to.equal('67890');\n expect(parsed.proof.b.x[0]).to.equal('11111');\n expect(parsed.proof.b.x[1]).to.equal('22222');\n expect(parsed.publicInputs.merkleRoot).to.equal('999999999999999999999');\n expect(parsed.publicInputs.nullifiers[0]).to.equal('111111');\n expect(parsed.publicInputs.commitments[1]).to.equal('444444');\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for handling BigInt serialization
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Custom JSON.stringify replacer function that handles BigInt values
|
|
6
|
+
* @param key - Property key
|
|
7
|
+
* @param value - Property value
|
|
8
|
+
* @returns Serialized value with BigInt converted to string
|
|
9
|
+
*/
|
|
10
|
+
export declare function bigIntReplacer(key: string, value: any): any;
|
|
11
|
+
/**
|
|
12
|
+
* Custom JSON.parse reviver function that converts string numbers back to BigInt
|
|
13
|
+
* @param key - Property key
|
|
14
|
+
* @param value - Property value
|
|
15
|
+
* @returns Parsed value with string numbers converted back to BigInt where appropriate
|
|
16
|
+
*/
|
|
17
|
+
export declare function bigIntReviver(key: string, value: any): any;
|
|
18
|
+
/**
|
|
19
|
+
* Safely stringify an object that may contain BigInt values
|
|
20
|
+
* @param obj - Object to stringify
|
|
21
|
+
* @returns JSON string with BigInt values converted to strings
|
|
22
|
+
*/
|
|
23
|
+
export declare function stringifyWithBigInt(obj: any): string;
|
|
24
|
+
/**
|
|
25
|
+
* Safely parse a JSON string that may contain BigInt values
|
|
26
|
+
* @param jsonString - JSON string to parse
|
|
27
|
+
* @returns Parsed object with string numbers converted back to BigInt where appropriate
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseWithBigInt(jsonString: string): any;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for handling BigInt serialization
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseWithBigInt = exports.stringifyWithBigInt = exports.bigIntReviver = exports.bigIntReplacer = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Custom JSON.stringify replacer function that handles BigInt values
|
|
9
|
+
* @param key - Property key
|
|
10
|
+
* @param value - Property value
|
|
11
|
+
* @returns Serialized value with BigInt converted to string
|
|
12
|
+
*/
|
|
13
|
+
function bigIntReplacer(key, value) {
|
|
14
|
+
if (typeof value === 'bigint') {
|
|
15
|
+
return value.toString();
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
exports.bigIntReplacer = bigIntReplacer;
|
|
20
|
+
/**
|
|
21
|
+
* Custom JSON.parse reviver function that converts string numbers back to BigInt
|
|
22
|
+
* @param key - Property key
|
|
23
|
+
* @param value - Property value
|
|
24
|
+
* @returns Parsed value with string numbers converted back to BigInt where appropriate
|
|
25
|
+
*/
|
|
26
|
+
function bigIntReviver(key, value) {
|
|
27
|
+
// This is a basic implementation - you might want to be more specific about which fields to convert
|
|
28
|
+
if (typeof value === 'string' && /^\d+$/.test(value)) {
|
|
29
|
+
// Only convert if it's a string that contains only digits
|
|
30
|
+
try {
|
|
31
|
+
return BigInt(value);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
exports.bigIntReviver = bigIntReviver;
|
|
40
|
+
/**
|
|
41
|
+
* Safely stringify an object that may contain BigInt values
|
|
42
|
+
* @param obj - Object to stringify
|
|
43
|
+
* @returns JSON string with BigInt values converted to strings
|
|
44
|
+
*/
|
|
45
|
+
function stringifyWithBigInt(obj) {
|
|
46
|
+
return JSON.stringify(obj, bigIntReplacer);
|
|
47
|
+
}
|
|
48
|
+
exports.stringifyWithBigInt = stringifyWithBigInt;
|
|
49
|
+
/**
|
|
50
|
+
* Safely parse a JSON string that may contain BigInt values
|
|
51
|
+
* @param jsonString - JSON string to parse
|
|
52
|
+
* @returns Parsed object with string numbers converted back to BigInt where appropriate
|
|
53
|
+
*/
|
|
54
|
+
function parseWithBigInt(jsonString) {
|
|
55
|
+
return JSON.parse(jsonString, bigIntReviver);
|
|
56
|
+
}
|
|
57
|
+
exports.parseWithBigInt = parseWithBigInt;
|
|
58
|
+
//# sourceMappingURL=bigint-serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint-serialization.js","sourceRoot":"","sources":["../../src/utils/bigint-serialization.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,GAAW,EAAE,KAAU;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AALD,wCAKC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW,EAAE,KAAU;IACnD,oGAAoG;IACpG,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACpD,0DAA0D;QAC1D,IAAI;YACF,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;SACtB;QAAC,MAAM;YACN,OAAO,KAAK,CAAC;SACd;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAXD,sCAWC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;AAC7C,CAAC;AAFD,kDAEC;AAED;;;;GAIG;AACH,SAAgB,eAAe,CAAC,UAAkB;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC/C,CAAC;AAFD,0CAEC","sourcesContent":["/**\n * Utility functions for handling BigInt serialization\n */\n\n/**\n * Custom JSON.stringify replacer function that handles BigInt values\n * @param key - Property key\n * @param value - Property value\n * @returns Serialized value with BigInt converted to string\n */\nexport function bigIntReplacer(key: string, value: any): any {\n if (typeof value === 'bigint') {\n return value.toString();\n }\n return value;\n}\n\n/**\n * Custom JSON.parse reviver function that converts string numbers back to BigInt\n * @param key - Property key\n * @param value - Property value\n * @returns Parsed value with string numbers converted back to BigInt where appropriate\n */\nexport function bigIntReviver(key: string, value: any): any {\n // This is a basic implementation - you might want to be more specific about which fields to convert\n if (typeof value === 'string' && /^\\d+$/.test(value)) {\n // Only convert if it's a string that contains only digits\n try {\n return BigInt(value);\n } catch {\n return value;\n }\n }\n return value;\n}\n\n/**\n * Safely stringify an object that may contain BigInt values\n * @param obj - Object to stringify\n * @returns JSON string with BigInt values converted to strings\n */\nexport function stringifyWithBigInt(obj: any): string {\n return JSON.stringify(obj, bigIntReplacer);\n}\n\n/**\n * Safely parse a JSON string that may contain BigInt values\n * @param jsonString - JSON string to parse\n * @returns Parsed object with string numbers converted back to BigInt where appropriate\n */\nexport function parseWithBigInt(jsonString: string): any {\n return JSON.parse(jsonString, bigIntReviver);\n}\n"]}
|