pvc-fork 1.0.0 → 1.0.1

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/deposit.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import "dotenv/config";
1
2
  import { Connection, PublicKey } from '@solana/web3.js';
2
3
  import * as hasher from '@lightprotocol/hasher.rs';
3
4
  import { EncryptionService } from './utils/encryption.js';
package/dist/deposit.js CHANGED
@@ -1,4 +1,5 @@
1
- import { PublicKey, TransactionInstruction, SystemProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL } from '@solana/web3.js';
1
+ import "dotenv/config";
2
+ import { Keypair, PublicKey, TransactionInstruction, SystemProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL } from '@solana/web3.js';
2
3
  import BN from 'bn.js';
3
4
  import { Utxo } from './models/utxo.js';
4
5
  import { fetchMerkleProof, findNullifierPDAs, getExtDataHash, getProgramAccounts, queryRemoteTreeState, findCrossCheckNullifierPDAs } from './utils/utils.js';
@@ -10,9 +11,23 @@ import { getUtxos } from './getUtxos.js';
10
11
  import { FIELD_SIZE, FEE_RECIPIENT, MERKLE_TREE_DEPTH, RELAYER_API_URL, PROGRAM_ID, ALT_ADDRESS } from './utils/constants.js';
11
12
  import { useExistingALT } from './utils/address_lookup_table.js';
12
13
  import { logger } from './utils/logger.js';
14
+ import { bs58 } from '@coral-xyz/anchor/dist/cjs/utils/bytes/index.js';
15
+ async function relayDepositDevnet(connection, signedTransaction) {
16
+ const payer = Keypair.fromSecretKey(bs58.decode(process.env.SOLANA_PRIVATE_KEY));
17
+ const transaction = VersionedTransaction.deserialize(Buffer.from(signedTransaction, 'base64'));
18
+ transaction.sign([payer]);
19
+ const signature = await connection.sendRawTransaction(Buffer.from(transaction.serialize()), {
20
+ skipPreflight: true,
21
+ });
22
+ logger.info(`Relayed deposit transaction successfully. Signature: ${signature}`);
23
+ return signature;
24
+ }
13
25
  // Function to relay pre-signed deposit transaction to indexer backend
14
- async function relayDepositToIndexer(signedTransaction, publicKey, referrer) {
26
+ async function relayDepositToIndexer(connection, signedTransaction, publicKey, referrer) {
15
27
  try {
28
+ if (connection.rpcEndpoint.includes('devnet')) {
29
+ return await relayDepositDevnet(connection, signedTransaction);
30
+ }
16
31
  logger.debug('Relaying pre-signed deposit transaction to indexer backend...');
17
32
  const params = {
18
33
  signedTransaction,
@@ -45,10 +60,10 @@ async function relayDepositToIndexer(signedTransaction, publicKey, referrer) {
45
60
  }
46
61
  }
47
62
  async function finalizeDepositFlow(params) {
48
- const { serializedTransaction, publicKey, referrer, encryptedOutputHex } = params;
63
+ const { connection, serializedTransaction, publicKey, referrer, encryptedOutputHex } = params;
49
64
  // Relay the pre-signed transaction to indexer backend
50
65
  logger.info('submitting transaction to relayer...');
51
- const signature = await relayDepositToIndexer(serializedTransaction, publicKey, referrer);
66
+ const signature = await relayDepositToIndexer(connection, serializedTransaction, publicKey, referrer);
52
67
  logger.debug('Transaction signature:', signature);
53
68
  logger.debug(`Transaction link: https://explorer.solana.com/tx/${signature}`);
54
69
  logger.info('Waiting for transaction confirmation...');
@@ -358,6 +373,7 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
358
373
  unsignedTransaction,
359
374
  resume: async (signedTransaction) => {
360
375
  return finalizeDepositFlow({
376
+ connection,
361
377
  serializedTransaction: signedTransaction,
362
378
  publicKey,
363
379
  referrer,
@@ -1,5 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
+ import "dotenv/config";
3
4
  export declare const FIELD_SIZE: BN;
4
5
  export declare const PROGRAM_ID: PublicKey;
5
6
  export declare const FEE_RECIPIENT: PublicKey;
@@ -1,5 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
+ import "dotenv/config";
3
4
  export const FIELD_SIZE = new BN('21888242871839275222246405745257275088548364400416034343698204186575808495617');
4
5
  export const PROGRAM_ID = process.env.NEXT_PUBLIC_PROGRAM_ID ? new PublicKey(process.env.NEXT_PUBLIC_PROGRAM_ID) : new PublicKey('9fhQBbumKEFuXtMBDw8AaQyAjCorLGJQiS3skWZdQyQD');
5
6
  export const FEE_RECIPIENT = new PublicKey('AWexibGxNFKTa1b5R5MN4PJr9HWnWRwf8EW9g8cLx3dM');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pvc-fork",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "repository": "",
@@ -14,7 +14,8 @@
14
14
  "build": "tsc",
15
15
  "test": "vitest run --exclude \"**/__tests__/e2e.test.ts,**/__tests__/e2espl.test.ts\"",
16
16
  "teste2e": "vitest run e2e.test.ts",
17
- "teste2espl": "vitest run e2espl.test.ts"
17
+ "teste2espl": "vitest run e2espl.test.ts",
18
+ "example": "npm run build && tsx ./example/index.ts"
18
19
  },
19
20
  "keywords": [],
20
21
  "author": "",
@@ -45,7 +46,8 @@
45
46
  "@types/node-localstorage": "^1.3.3",
46
47
  "@types/snarkjs": "^0.7.9",
47
48
  "@types/tmp": "^0.2.6",
49
+ "tsx": "^4.21.0",
48
50
  "typescript": "^5.9.2",
49
51
  "vitest": "^3.2.4"
50
52
  }
51
- }
53
+ }
package/src/deposit.ts CHANGED
@@ -1,3 +1,5 @@
1
+
2
+ import "dotenv/config";
1
3
  import { Connection, Keypair, PublicKey, TransactionInstruction, SystemProgram, ComputeBudgetProgram, VersionedTransaction, TransactionMessage, LAMPORTS_PER_SOL } from '@solana/web3.js';
2
4
  import BN from 'bn.js';
3
5
  import { Utxo } from './models/utxo.js';
@@ -11,13 +13,32 @@ import { getUtxos, isUtxoSpent } from './getUtxos.js';
11
13
  import { FIELD_SIZE, FEE_RECIPIENT, MERKLE_TREE_DEPTH, RELAYER_API_URL, PROGRAM_ID, ALT_ADDRESS } from './utils/constants.js';
12
14
  import { useExistingALT } from './utils/address_lookup_table.js';
13
15
  import { logger } from './utils/logger.js';
14
-
16
+ import { bs58 } from '@coral-xyz/anchor/dist/cjs/utils/bytes/index.js';
17
+
18
+ async function relayDepositDevnet(connection: Connection, signedTransaction: string): Promise<string> {
19
+ const payer = Keypair.fromSecretKey(bs58.decode(process.env.SOLANA_PRIVATE_KEY!));
20
+
21
+ const transaction = VersionedTransaction.deserialize(
22
+ Buffer.from(signedTransaction, 'base64')
23
+ );
24
+ transaction.sign([payer]);
25
+ const signature = await connection.sendRawTransaction(
26
+ Buffer.from(transaction.serialize()),
27
+ {
28
+ skipPreflight: true,
29
+ }
30
+ );
31
+ logger.info(`Relayed deposit transaction successfully. Signature: ${signature}`);
32
+ return signature;
33
+ }
15
34
 
16
35
  // Function to relay pre-signed deposit transaction to indexer backend
17
- async function relayDepositToIndexer(signedTransaction: string, publicKey: PublicKey, referrer?: string): Promise<string> {
36
+ async function relayDepositToIndexer(connection: Connection, signedTransaction: string, publicKey: PublicKey, referrer?: string): Promise<string> {
18
37
  try {
38
+ if (connection.rpcEndpoint.includes('devnet')) {
39
+ return await relayDepositDevnet(connection, signedTransaction);
40
+ }
19
41
  logger.debug('Relaying pre-signed deposit transaction to indexer backend...');
20
-
21
42
  const params: any = {
22
43
  signedTransaction,
23
44
  senderAddress: publicKey.toString()
@@ -54,16 +75,17 @@ async function relayDepositToIndexer(signedTransaction: string, publicKey: Publi
54
75
  }
55
76
 
56
77
  async function finalizeDepositFlow(params: {
78
+ connection: Connection,
57
79
  serializedTransaction: string,
58
80
  publicKey: PublicKey,
59
81
  referrer?: string,
60
82
  encryptedOutputHex: string
61
83
  }) {
62
- const { serializedTransaction, publicKey, referrer, encryptedOutputHex } = params;
84
+ const { connection, serializedTransaction, publicKey, referrer, encryptedOutputHex } = params;
63
85
 
64
86
  // Relay the pre-signed transaction to indexer backend
65
87
  logger.info('submitting transaction to relayer...')
66
- const signature = await relayDepositToIndexer(serializedTransaction, publicKey, referrer);
88
+ const signature = await relayDepositToIndexer(connection, serializedTransaction, publicKey, referrer);
67
89
  logger.debug('Transaction signature:', signature);
68
90
  logger.debug(`Transaction link: https://explorer.solana.com/tx/${signature}`);
69
91
 
@@ -449,6 +471,7 @@ export async function deposit({ lightWasm, storage, keyBasePath, publicKey, conn
449
471
  unsignedTransaction,
450
472
  resume: async (signedTransaction: string) => {
451
473
  return finalizeDepositFlow({
474
+ connection,
452
475
  serializedTransaction: signedTransaction,
453
476
  publicKey,
454
477
  referrer,
@@ -1,5 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
+ import "dotenv/config";
3
4
 
4
5
  export const FIELD_SIZE = new BN('21888242871839275222246405745257275088548364400416034343698204186575808495617')
5
6