dop-wallet-v6 1.2.6 → 1.2.7

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.
@@ -3,74 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const chai_1 = require("chai");
4
4
  const tx_proof_transfer_with_data_1 = require("../tx-proof-transfer-with-data");
5
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
6
  describe('Function exports and signatures', () => {
52
- it('should export generateTransferProof function that returns Promise<TransferProofData>', () => {
7
+ it('should export generateTransferProof function that returns proved transactions array', () => {
53
8
  (0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProof).to.be.a('function');
54
9
  (0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProof.length).to.equal(12); // Should have 12 parameters
55
10
  });
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
11
+ it('should export generateTransferProofForExplorer function that returns Promise<void>', () => {
12
+ (0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofForExplorer).to.be.a('function');
13
+ (0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofForExplorer.length).to.equal(12); // Should have 12 parameters
63
14
  });
64
15
  it('should maintain naming consistency for frontend developers', () => {
65
16
  // The main function that frontend developers will use should be generateTransferProof
66
- // and it should return the proof data (not void)
17
+ // and it should return the proved transactions array (not void)
67
18
  (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
19
+ (0, chai_1.expect)(tx_proof_transfer_with_data_1.generateTransferProofForExplorer).to.be.a('function');
20
+ // Both functions should exist and be callable
21
+ // generateTransferProof is the one that returns proved transactions array
22
+ // generateTransferProofForExplorer is the internal one that returns void
74
23
  });
75
24
  });
76
25
  describe('Integration behavior (may fail in test environment)', () => {
@@ -79,10 +28,12 @@ describe('tx-proof-transfer-with-data', () => {
79
28
  // But it verifies the function structure and error handling
80
29
  try {
81
30
  // 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
31
+ const result = await (0, tx_proof_transfer_with_data_1.generateTransferProof)('V3_PoseidonMerkle', // Using string to avoid import issues
83
32
  'Polygon', 'test-wallet-id', 'test-encryption-key', true, 'test memo', [], [], undefined, false, undefined, () => { });
84
33
  // If we get here, the function worked (unlikely in test env)
85
34
  console.log('✅ generateTransferProof executed successfully');
35
+ // Verify it returns an array (proved transactions)
36
+ (0, chai_1.expect)(result).to.be.an('array');
86
37
  }
87
38
  catch (error) {
88
39
  // This is expected in test environment
@@ -1 +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;AAExC,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,QAAQ,CAAC,uCAAuC,EAAE,GAAG,EAAE;QACrD,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;YAChE,2DAA2D;YAC3D,MAAM,aAA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AC;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"]}
1
+ {"version":3,"file":"tx-proof-transfer-with-data.test.js","sourceRoot":"","sources":["../../../../src/services/transactions/__tests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I;gBACF,iEAAiE;gBACjE,MAAM,MAAM,GAAG,MAAM,IAAA,mDAAqB,EACxC,mBAA0B,EAAE,sCAAsC;gBAClE,SAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,IAAI,EACJ,WAAW,EACX,EAAE,EACF,EAAE,EACF,SAAS,EACT,KAAK,EACL,SAAS,EACT,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;gBAEF,6DAA6D;gBAC7D,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;gBAE7D,mDAAmD;gBACnD,IAAA,aAAM,EAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;aAElC;YAAC,OAAO,KAAK,EAAE;gBACd,uCAAuC;gBACvC,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;gBAExE,kEAAkE;gBAClE,IAAA,aAAM,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE,CAC/C,GAAG,CAAC,QAAQ,CAAC,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 generateTransferProofForExplorer\n} from '../tx-proof-transfer-with-data';\n\ndescribe('tx-proof-transfer-with-data', () => {\n describe('Function exports and signatures', () => {\n it('should export generateTransferProof function that returns proved transactions array', () => {\n expect(generateTransferProof).to.be.a('function');\n expect(generateTransferProof.length).to.equal(12); // Should have 12 parameters\n });\n\n it('should export generateTransferProofForExplorer function that returns Promise<void>', () => {\n expect(generateTransferProofForExplorer).to.be.a('function');\n expect(generateTransferProofForExplorer.length).to.equal(12); // Should have 12 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 proved transactions array (not void)\n expect(generateTransferProof).to.be.a('function');\n expect(generateTransferProofForExplorer).to.be.a('function');\n \n // Both functions should exist and be callable\n // generateTransferProof is the one that returns proved transactions array\n // generateTransferProofForExplorer is the internal one that returns void\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 const result = 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 // Verify it returns an array (proved transactions)\n expect(result).to.be.an('array');\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"]}
@@ -1,45 +1,8 @@
1
1
  import { NetworkName, DopERC20AmountRecipient, DopNFTAmountRecipient, TXIDVersion } from 'dop-sharedmodels-v3';
2
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
- }
3
+ export declare const generateTransferProofForExplorer: (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>;
31
4
  /**
32
- * Internal function to generate transfer proof and cache it
33
- * Following the dop-wallet pattern for clean separation of concerns
5
+ * Generate transfer proof and return the raw proved transactions for explorer verification
6
+ * This function generates the proof and returns the complete proved transaction data
34
7
  */
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>;
8
+ 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<(import("dop-engine-v3").TransactionStructV2 | import("dop-engine-v3").TransactionStructV3)[]>;
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateTransferProof = exports.extractTransferProofData = exports.generateTransferProofWithDataInternal = void 0;
3
+ exports.generateTransferProof = exports.generateTransferProofForExplorer = 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 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) => {
8
+ const generateTransferProofForExplorer = async (txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback) => {
14
9
  try {
15
10
  (0, proof_cache_1.setCachedProvedTransaction)(undefined);
16
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
@@ -18,8 +13,7 @@ const generateTransferProofWithDataInternal = async (txidVersion, networkName, d
18
13
  overallBatchMinGasPrice, progressCallback);
19
14
  const transaction = await (0, tx_generator_1.generateTransact)(txidVersion, provedTransactions, networkName, 0n);
20
15
  const nullifiers = (0, tx_generator_1.nullifiersForTransactions)(provedTransactions);
21
- // Cast to our enhanced type that includes proved transactions
22
- const enhancedProvedTransaction = {
16
+ (0, proof_cache_1.setCachedProvedTransaction)({
23
17
  proofType: dop_sharedmodels_v3_1.ProofType.Transfer,
24
18
  txidVersion,
25
19
  dopWalletID,
@@ -37,82 +31,25 @@ const generateTransferProofWithDataInternal = async (txidVersion, networkName, d
37
31
  transaction,
38
32
  overallBatchMinGasPrice,
39
33
  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;
34
+ });
100
35
  }
101
36
  catch (err) {
102
- throw (0, error_1.reportAndSanitizeError)(exports.extractTransferProofData.name, err);
37
+ throw (0, error_1.reportAndSanitizeError)(exports.generateTransferProofForExplorer.name, err);
103
38
  }
104
39
  };
105
- exports.extractTransferProofData = extractTransferProofData;
40
+ exports.generateTransferProofForExplorer = generateTransferProofForExplorer;
106
41
  /**
107
- * Generate transfer proof and return proof data for explorer verification
108
- * This is the main function that frontend developers should use
42
+ * Generate transfer proof and return the raw proved transactions for explorer verification
43
+ * This function generates the proof and returns the complete proved transaction data
109
44
  */
110
45
  const generateTransferProof = async (txidVersion, networkName, dopWalletID, encryptionKey, showSenderAddressToRecipient, memoText, erc20AmountRecipients, nftAmountRecipients, broadcasterFeeERC20AmountRecipient, sendWithPublicWallet, overallBatchMinGasPrice, progressCallback) => {
111
46
  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)();
47
+ // Generate the proof transactions directly
48
+ 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
49
+ false, // useDummyProof
50
+ overallBatchMinGasPrice, progressCallback);
51
+ // Return the raw proved transactions array as expected
52
+ return provedTransactions;
116
53
  }
117
54
  catch (err) {
118
55
  throw (0, error_1.reportAndSanitizeError)(exports.generateTransferProof.name, err);
@@ -1 +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,mBA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,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,6BAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KAC/D;AACH,CAAC,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
+ {"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,+CAA2D;AAC3D,6CAA2D;AAEpD,MAAM,gCAAgC,GAAG,KAAK,EACnD,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,GAC1B,MAAM,IAAA,wCAAyB,EAC7B,+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,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AAE,eAAe;QAC1B,KAAK,EAAE,gBAAgB;QACvB,uBAAuB,EACvB,gBAAgB,CACjB,CAAC;QAEF,uDAAuD;QACvD,OAAO,kBAAkB,CAAC;KAC3B;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,6BAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KAC/D;AACH,CAAC,CAAC;AAvCW,QAAA,qBAAqB,yBAuChC","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 } from './proof-cache';\nimport { reportAndSanitizeError } from '../../utils/error';\n\nexport const generateTransferProofForExplorer = 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(generateTransferProofForExplorer.name, err);\n }\n};\n\n/**\n * Generate transfer proof and return the raw proved transactions for explorer verification\n * This function generates the proof and returns the complete proved transaction data\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) => {\n try {\n // Generate the proof transactions directly\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 // Return the raw proved transactions array as expected\n return provedTransactions;\n } catch (err) {\n throw reportAndSanitizeError(generateTransferProof.name, err);\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dop-wallet-v6",
3
- "version": "1.2.6",
3
+ "version": "1.2.7",
4
4
  "description": "DOP Wallet SDK, compatible with mobile, browser and nodejs environments.",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- export {};
@@ -1,106 +0,0 @@
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
@@ -1 +0,0 @@
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,C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,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACzE,IAAA,aAAM,EAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC7D,IAAA,aAAM,EAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,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"]}
@@ -1,29 +0,0 @@
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;
@@ -1,58 +0,0 @@
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
@@ -1 +0,0 @@
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"]}