From ced63940f6949a6d9055b83501a1dcf5a8cd9535 Mon Sep 17 00:00:00 2001 From: volodymyr-basiuk <31999965+volodymyr-basiuk@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:48:29 +0300 Subject: [PATCH] add TransactionService (#220) * add TransactionService --- src/blockchain/index.ts | 1 + src/blockchain/transaction-service.ts | 121 ++++++++++++++++++ src/identity/identity-wallet.ts | 9 +- src/index.ts | 1 + src/storage/blockchain/onchain-revocation.ts | 22 ++-- .../blockchain/onchain-zkp-verifier.ts | 13 +- src/storage/blockchain/state.ts | 33 ++--- src/storage/interfaces/state.ts | 9 +- .../credential-statuses/rhs.test.ts | 12 +- .../credentials/credential-validation.test.ts | 5 + tests/handlers/auth.test.ts | 25 +--- tests/handlers/contract-request.test.ts | 6 +- tests/helpers.ts | 4 + tests/identity/id.test.ts | 7 +- tests/proofs/mtp-onchain.test.ts | 12 +- tests/proofs/mtp.test.ts | 18 +-- tests/proofs/sig-onchain.test.ts | 5 + tests/proofs/sig.test.ts | 5 + 18 files changed, 215 insertions(+), 93 deletions(-) create mode 100644 src/blockchain/index.ts create mode 100644 src/blockchain/transaction-service.ts diff --git a/src/blockchain/index.ts b/src/blockchain/index.ts new file mode 100644 index 00000000..94e0acd9 --- /dev/null +++ b/src/blockchain/index.ts @@ -0,0 +1 @@ +export * from './transaction-service'; diff --git a/src/blockchain/transaction-service.ts b/src/blockchain/transaction-service.ts new file mode 100644 index 00000000..f2d47707 --- /dev/null +++ b/src/blockchain/transaction-service.ts @@ -0,0 +1,121 @@ +import { Block, JsonRpcProvider, Signer, TransactionReceipt, TransactionRequest } from 'ethers'; + +/** + * Resend transaction options + * @type ResendTxnOptions + */ +export type ResendTxnOptions = { + increasedFeesPercentage?: number; +}; + +/** + * Interface for TransactionService + * @public + */ +export interface ITransactionService { + /** + * Returns transaction receipt and block by transaction hash + * + * @param {string} transactionHash - transaction hash. + * @returns `Promise<{receipt?: TransactionReceipt , block?: Block}>` - returns transaction receipt and block + * @public + */ + getTransactionReceiptAndBlock( + transactionHash: string + ): Promise<{ receipt?: TransactionReceipt; block?: Block }>; + + /** + * Send transaction. + * + * @param {Signer} signer - transaction signer. + * @param {TransactionRequest} request - transaction request. + * @returns `Promise; + + /** + * Resend transaction with options. Useful when `transaction underpriced` error thrown on transaction. + * + * @param {Signer} signer - transaction signer. + * @param {TransactionRequest} request - transaction request. + * @param {ResendTxnOptions} opts - resend transaction options. + * @returns `Promise<{ txnHash: string; txnReceipt: TransactionReceipt }>` -returns txn hash and txn receipt. + * @public + */ + resendTransaction( + signer: Signer, + request: TransactionRequest, + opts?: ResendTxnOptions + ): Promise<{ txnHash: string; txnReceipt: TransactionReceipt }>; +} + +/** + * Transaction service to provide interaction with blockchain transactions. + * allows to: get tx receipt by tx id, send and resend transaction with new fees. + * @class TransactionService + * @public + * @implements ITransactionService interface + */ +export class TransactionService implements ITransactionService { + /** + * Creates an instance of TransactionService. + * @param {JsonRpcProvider} - RPC provider + */ + constructor(private readonly _provider: JsonRpcProvider) {} + + /** {@inheritDoc ITransactionService.getTransactionReceiptAndBlock} */ + async getTransactionReceiptAndBlock( + txnHash: string + ): Promise<{ receipt?: TransactionReceipt; block?: Block }> { + const receipt = await this._provider.getTransactionReceipt(txnHash); + const block = await receipt?.getBlock(); + return { receipt: receipt || undefined, block }; + } + + /** {@inheritDoc ITransactionService.sendTransactionRequest} */ + async sendTransactionRequest( + signer: Signer, + request: TransactionRequest + ): Promise<{ txnHash: string; txnReceipt: TransactionReceipt }> { + const tx = await signer.sendTransaction(request); + const txnReceipt = await tx.wait(); + if (!txnReceipt) { + throw new Error(`transaction: ${tx.hash} failed to mined`); + } + const status: number | null = txnReceipt.status; + const txnHash: string = txnReceipt.hash; + + if (!status) { + throw new Error(`transaction: ${txnHash} failed to mined`); + } + + return { txnHash, txnReceipt }; + } + + /** {@inheritDoc ITransactionService.resendTransaction} */ + async resendTransaction( + signer: Signer, + request: TransactionRequest, + opts?: ResendTxnOptions + ): Promise<{ txnHash: string; txnReceipt: TransactionReceipt }> { + const feeData = await this._provider.getFeeData(); + let { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = feeData; + + if (opts?.increasedFeesPercentage) { + const multiplyVal = BigInt((opts.increasedFeesPercentage + 100) / 100); + maxFeePerGas = maxFeePerGas ? maxFeePerGas * multiplyVal : null; + maxPriorityFeePerGas = maxPriorityFeePerGas ? maxPriorityFeePerGas * multiplyVal : null; + gasPrice = gasPrice ? gasPrice * multiplyVal : null; + } + + request.maxFeePerGas = maxFeePerGas; + request.maxPriorityFeePerGas = maxPriorityFeePerGas; + request.gasPrice = gasPrice; + + return this.sendTransactionRequest(signer, request); + } +} diff --git a/src/identity/identity-wallet.ts b/src/identity/identity-wallet.ts index 5580916f..bd48a3f0 100644 --- a/src/identity/identity-wallet.ts +++ b/src/identity/identity-wallet.ts @@ -58,6 +58,7 @@ import { Iden3SmtRhsCredentialStatusPublisher } from '../credentials/status/credential-status-publisher'; import { InputGenerator, IZKProver } from '../proof'; +import { ITransactionService, TransactionService } from '../blockchain'; /** * DID creation options @@ -472,6 +473,7 @@ export interface IIdentityWallet { export class IdentityWallet implements IIdentityWallet { private readonly _credentialStatusPublisherRegistry: CredentialStatusPublisherRegistry; private readonly _inputsGenerator: InputGenerator; + private readonly _transactionService: ITransactionService; /** * Constructs a new instance of the `IdentityWallet` class @@ -491,6 +493,7 @@ export class IdentityWallet implements IIdentityWallet { ) { this._credentialStatusPublisherRegistry = this.getCredentialStatusPublisherRegistry(_opts); this._inputsGenerator = new InputGenerator(this, _credentialWallet, _storage.states); + this._transactionService = new TransactionService(_storage.states.getRpcProvider()); } private getCredentialStatusPublisherRegistry( @@ -1432,13 +1435,13 @@ export class IdentityWallet implements IIdentityWallet { ); const txId = await this.transitState(did, oldTreeState, isOldStateGenesis, ethSigner, prover); - // TODO: update to get blockNumber and blockTimestamp from function instead of passing 0s + const { receipt, block } = await this._transactionService.getTransactionReceiptAndBlock(txId); const credsWithIden3MTPProof = await this.generateIden3SparseMerkleTreeProof( did, [credential], txId, - 0, - 0, + receipt?.blockNumber, + block?.timestamp, undefined, { revNonce: Number(authClaim.getRevocationNonce()), diff --git a/src/index.ts b/src/index.ts index 9d89a21d..e1bb43e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ export * from './iden3comm'; export * from './circuits'; export * from './iden3comm'; export * from './utils'; +export * from './blockchain'; import * as core from '@iden3/js-iden3-core'; import * as jsonLDMerklizer from '@iden3/js-jsonld-merklization'; export { core }; diff --git a/src/storage/blockchain/onchain-revocation.ts b/src/storage/blockchain/onchain-revocation.ts index d6bec8eb..2491b496 100644 --- a/src/storage/blockchain/onchain-revocation.ts +++ b/src/storage/blockchain/onchain-revocation.ts @@ -3,6 +3,7 @@ import { Contract, JsonRpcProvider, Signer, TransactionReceipt, TransactionReque import { Proof, NodeAuxJSON, Hash } from '@iden3/js-merkletree'; import { EthConnectionConfig } from './state'; import abi from '../blockchain/abi/CredentialStatusResolver.json'; +import { ITransactionService, TransactionService } from '../../blockchain'; /** * OnChainRevocationStore is a class that allows to interact with the onchain contract @@ -14,6 +15,7 @@ import abi from '../blockchain/abi/CredentialStatusResolver.json'; export class OnChainRevocationStorage { private readonly _contract: Contract; private readonly _provider: JsonRpcProvider; + private readonly _transactionService: ITransactionService; /** * @@ -35,6 +37,7 @@ export class OnChainRevocationStorage { contract = contract.connect(this._signer) as Contract; } this._contract = contract; + this._transactionService = new TransactionService(this._provider); } /** @@ -99,20 +102,11 @@ export class OnChainRevocationStorage { maxPriorityFeePerGas }; - const tx = await this._signer.sendTransaction(request); - return tx.wait().then((txReceipt) => { - if (!txReceipt) { - throw new Error(`transaction: ${tx.hash} failed to mine`); - } - const status: number | null = txReceipt.status; - const txnHash: string = txReceipt.hash; - - if (!status) { - throw new Error(`transaction: ${txnHash} failed to mine`); - } - - return txReceipt; - }); + const { txnReceipt } = await this._transactionService.sendTransactionRequest( + this._signer, + request + ); + return txnReceipt; } private static convertIssuerInfo(issuer: bigint[]): Issuer { diff --git a/src/storage/blockchain/onchain-zkp-verifier.ts b/src/storage/blockchain/onchain-zkp-verifier.ts index 2c875b17..0449c28b 100644 --- a/src/storage/blockchain/onchain-zkp-verifier.ts +++ b/src/storage/blockchain/onchain-zkp-verifier.ts @@ -3,6 +3,7 @@ import { EthConnectionConfig } from './state'; import { IOnChainZKPVerifier } from '../interfaces/onchain-zkp-verifier'; import { ContractInvokeTransactionData, ZeroKnowledgeProofResponse } from '../../iden3comm'; import abi from './abi/ZkpVerifier.json'; +import { TransactionService } from '../../blockchain'; /** * OnChainZKPVerifier is a class that allows to interact with the OnChainZKPVerifier contract @@ -88,17 +89,9 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { maxFeePerGas, maxPriorityFeePerGas }; - const tx = await ethSigner.sendTransaction(request); - const txnReceipt = await tx.wait(); - if (!txnReceipt) { - throw new Error(`transaction: ${tx.hash} failed to mined`); - } - const status: number | null = txnReceipt.status; - const txnHash: string = txnReceipt.hash; - if (!status) { - throw new Error(`transaction: ${txnHash} failed to mined`); - } + const transactionService = new TransactionService(provider); + const { txnHash } = await transactionService.sendTransactionRequest(ethSigner, request); response.set(txnHash, zkProof); } diff --git a/src/storage/blockchain/state.ts b/src/storage/blockchain/state.ts index 28a79069..b27d685e 100644 --- a/src/storage/blockchain/state.ts +++ b/src/storage/blockchain/state.ts @@ -7,6 +7,7 @@ import { StateTransitionPubSignals } from '../../circuits'; import { byteEncoder } from '../../utils'; import abi from './abi/State.json'; import { DID, getChainId, Id } from '@iden3/js-iden3-core'; +import { ITransactionService, TransactionService } from '../../blockchain'; /** * Configuration of ethereum based blockchain connection @@ -55,7 +56,8 @@ const defaultEthConnectionConfig: EthConnectionConfig = { */ export class EthStateStorage implements IStateStorage { public readonly stateContract: Contract; - public readonly provider: JsonRpcProvider; + private readonly provider: JsonRpcProvider; + private readonly _transactionService: ITransactionService; /** * Creates an instance of EthStateStorage. @@ -65,6 +67,7 @@ export class EthStateStorage implements IStateStorage { const config = Array.isArray(ethConfig) ? ethConfig[0] : ethConfig; this.provider = new JsonRpcProvider(config.url); this.stateContract = new Contract(config.contractAddress, abi, this.provider); + this._transactionService = new TransactionService(this.getRpcProvider()); } /** {@inheritdoc IStateStorage.getLatestStateById} */ @@ -145,7 +148,7 @@ export class EthStateStorage implements IStateStorage { maxPriorityFeePerGas }; - const txnHash: string = await this.sendTransactionRequest(signer, request); + const { txnHash } = await this._transactionService.sendTransactionRequest(signer, request); return txnHash; } @@ -187,7 +190,7 @@ export class EthStateStorage implements IStateStorage { maxPriorityFeePerGas }; - const txnHash: string = await this.sendTransactionRequest(signer, request); + const { txnHash } = await this._transactionService.sendTransactionRequest(signer, request); return txnHash; } @@ -227,6 +230,11 @@ export class EthStateStorage implements IStateStorage { }; } + /** {@inheritdoc IStateStorage.getRpcProvider} */ + getRpcProvider(): JsonRpcProvider { + return this.provider; + } + private getStateContractAndProviderForId(id: bigint): { stateContract: Contract; provider: JsonRpcProvider; @@ -259,23 +267,4 @@ export class EthStateStorage implements IStateStorage { return this.ethConfig as EthConnectionConfig; } - - private async sendTransactionRequest( - signer: Signer, - request: TransactionRequest - ): Promise { - const tx = await signer.sendTransaction(request); - const txnReceipt = await tx.wait(); - if (!txnReceipt) { - throw new Error(`transaction: ${tx.hash} failed to mined`); - } - const status: number | null = txnReceipt.status; - const txnHash: string = txnReceipt.hash; - - if (!status) { - throw new Error(`transaction: ${txnHash} failed to mined`); - } - - return txnHash; - } } diff --git a/src/storage/interfaces/state.ts b/src/storage/interfaces/state.ts index 38876b69..e055ec94 100644 --- a/src/storage/interfaces/state.ts +++ b/src/storage/interfaces/state.ts @@ -1,5 +1,5 @@ import { ZKProof } from '@iden3/js-jwz'; -import { Signer } from 'ethers'; +import { JsonRpcProvider, Signer } from 'ethers'; import { RootInfo, StateInfo, StateProof } from '../entities/state'; import { Id } from '@iden3/js-iden3-core'; import { Hash } from '@iden3/js-merkletree'; @@ -71,4 +71,11 @@ export interface IStateStorage { * @returns `Promise` */ getGISTRootInfo(root: bigint, userId: bigint): Promise; + + /** + * gets RPC provider + * + * @returns `Promise` + */ + getRpcProvider(): JsonRpcProvider; } diff --git a/tests/credentials/credential-statuses/rhs.test.ts b/tests/credentials/credential-statuses/rhs.test.ts index 9b2bed0e..19eace6b 100644 --- a/tests/credentials/credential-statuses/rhs.test.ts +++ b/tests/credentials/credential-statuses/rhs.test.ts @@ -20,7 +20,8 @@ import { Blockchain, DidMethod, NetworkId } from '@iden3/js-iden3-core'; import { expect } from 'chai'; import { RHSResolver } from '../../../src/credentials'; import { CredentialStatusResolverRegistry } from '../../../src/credentials'; -import { RHS_URL, SEED_USER, createIdentity } from '../../helpers'; +import { RHS_URL, SEED_USER, createIdentity, RPC_URL } from '../../helpers'; +import { JsonRpcProvider } from 'ethers'; describe('rhs', () => { let idWallet: IdentityWallet; @@ -61,6 +62,9 @@ describe('rhs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; @@ -106,6 +110,9 @@ describe('rhs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; const mockStateStorageForSecondState: IStateStorage = { @@ -150,6 +157,9 @@ describe('rhs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; diff --git a/tests/credentials/credential-validation.test.ts b/tests/credentials/credential-validation.test.ts index 57d3ae4b..8b2ce793 100644 --- a/tests/credentials/credential-validation.test.ts +++ b/tests/credentials/credential-validation.test.ts @@ -25,6 +25,8 @@ import { chai.use(chaiAsPromised); const { expect } = chai; import fetchMock from '@gr2m/fetch-mock'; +import { JsonRpcProvider } from 'ethers'; +import { RPC_URL } from '../helpers'; const mockStateStorage: IStateStorage = { getLatestStateById: async (id: bigint) => { @@ -74,6 +76,9 @@ const mockStateStorage: IStateStorage = { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider: (): JsonRpcProvider => { + return new JsonRpcProvider(RPC_URL); } }; diff --git a/tests/handlers/auth.test.ts b/tests/handlers/auth.test.ts index 8e620651..2d79ae42 100644 --- a/tests/handlers/auth.test.ts +++ b/tests/handlers/auth.test.ts @@ -299,10 +299,7 @@ describe('auth', () => { const res = await idWallet.addCredentialsToMerkleTree([employeeCred], issuerDID); await idWallet.publishStateToRHS(issuerDID, RHS_URL); - const ethSigner = new ethers.Wallet( - WALLET_KEY, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const txId = await proofService.transitState( issuerDID, @@ -412,10 +409,7 @@ describe('auth', () => { }); it('auth flow identity (profile) with ethereum identity issuer with circuits V3', async () => { - const ethSigner = new ethers.Wallet( - WALLET_KEY, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const { did: didIssuer, credential: issuerAuthCredential } = await idWallet.createEthereumBasedIdentity({ @@ -659,10 +653,7 @@ describe('auth', () => { expect(userAuthCredential).not.to.be.undefined; - const ethSigner = new ethers.Wallet( - WALLET_KEY, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const { did: didIssuer, credential: issuerAuthCredential } = await idWallet.createEthereumBasedIdentity({ @@ -1963,10 +1954,7 @@ describe('auth', () => { const res = await idWallet.addCredentialsToMerkleTree([employeeCred], issuerDID); await idWallet.publishStateToRHS(issuerDID, RHS_URL); - const ethSigner = new ethers.Wallet( - WALLET_KEY, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const txId = await proofService.transitState( issuerDID, @@ -2151,10 +2139,7 @@ describe('auth', () => { }); const prover = new NativeProver(circuitStorage); - const ethSigner = new ethers.Wallet( - WALLET_KEY, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const opts = { seed: SEED_USER, revocationOpts: { diff --git a/tests/handlers/contract-request.test.ts b/tests/handlers/contract-request.test.ts index aef5df57..9fbe6d29 100644 --- a/tests/handlers/contract-request.test.ts +++ b/tests/handlers/contract-request.test.ts @@ -54,7 +54,8 @@ import { Blockchain, BytesHelper, DidMethod, NetworkId } from '@iden3/js-iden3-c import { expect } from 'chai'; import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; -import { ethers, Signer } from 'ethers'; +import { ethers, JsonRpcProvider, Signer } from 'ethers'; +import { RPC_URL } from '../helpers'; describe('contract-request', () => { let idWallet: IdentityWallet; @@ -106,6 +107,9 @@ describe('contract-request', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; diff --git a/tests/helpers.ts b/tests/helpers.ts index 36be90e3..cc89b6fd 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -35,6 +35,7 @@ import { VerifyOpts } from '../src'; import { proving } from '@iden3/js-jwz'; +import { JsonRpcProvider } from 'ethers'; export const SEED_ISSUER: Uint8Array = byteEncoder.encode('seedseedseedseedseedseedseedseed'); export const SEED_USER: Uint8Array = byteEncoder.encode('seedseedseedseedseedseedseeduser'); @@ -189,6 +190,9 @@ export const MOCK_STATE_STORAGE: IStateStorage = { createdAtBlock: 5499734n, replacedAtBlock: 0n }); + }, + getRpcProvider: (): JsonRpcProvider => { + return new JsonRpcProvider(RPC_URL); } }; diff --git a/tests/identity/id.test.ts b/tests/identity/id.test.ts index 32cf9c61..9f6c414f 100644 --- a/tests/identity/id.test.ts +++ b/tests/identity/id.test.ts @@ -11,7 +11,6 @@ import { CredentialStatusResolverRegistry, RHSResolver, CredentialStatusType, - EthStateStorage, FSCircuitStorage, NativeProver, Iden3SparseMerkleTreeProof, @@ -170,7 +169,7 @@ describe('identity', () => { }); it('createIdentity Secp256k1', async () => { - const ethSigner = new Wallet(WALLET_KEY, (dataStorage.states as EthStateStorage).provider); + const ethSigner = new Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const { did, credential } = await createEthereumBasedIdentity(idWallet, { ethSigner @@ -204,7 +203,7 @@ describe('identity', () => { }); const prover = new NativeProver(circuitStorage); - const ethSigner = new Wallet(WALLET_KEY, (dataStorage.states as EthStateStorage).provider); + const ethSigner = new Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const opts = { seed: SEED_USER, revocationOpts: { @@ -260,7 +259,7 @@ describe('identity', () => { }); const prover = new NativeProver(circuitStorage); - const ethSigner = new Wallet(WALLET_KEY, (dataStorage.states as EthStateStorage).provider); + const ethSigner = new Wallet(WALLET_KEY, dataStorage.states.getRpcProvider()); const opts = { seed: SEED_USER, revocationOpts: { diff --git a/tests/proofs/mtp-onchain.test.ts b/tests/proofs/mtp-onchain.test.ts index 28c61bf1..9ff86c95 100644 --- a/tests/proofs/mtp-onchain.test.ts +++ b/tests/proofs/mtp-onchain.test.ts @@ -20,14 +20,14 @@ import { } from '../../src/credentials'; import { ProofService } from '../../src/proof'; import { CircuitId } from '../../src/circuits'; -import { ethers } from 'ethers'; -import { EthStateStorage } from '../../src/storage/blockchain/state'; +import { ethers, JsonRpcProvider } from 'ethers'; import { RootInfo, StateProof } from '../../src/storage/entities/state'; import path from 'path'; import { CredentialStatusType, VerifiableConstants, W3CCredential } from '../../src/verifiable'; import { ZeroKnowledgeProofRequest } from '../../src/iden3comm'; import { Blockchain, DidMethod, NetworkId } from '@iden3/js-iden3-core'; import { expect } from 'chai'; +import { RPC_URL } from '../helpers'; describe('mtp onchain proofs', () => { let idWallet: IdentityWallet; @@ -82,6 +82,9 @@ describe('mtp onchain proofs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; beforeEach(async () => { @@ -185,10 +188,7 @@ describe('mtp onchain proofs', () => { // you must store stat info (e.g. state and it's roots) - const ethSigner = new ethers.Wallet( - walletKey, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(walletKey, dataStorage.states.getRpcProvider()); const txId = await proofService.transitState( issuerDID, diff --git a/tests/proofs/mtp.test.ts b/tests/proofs/mtp.test.ts index 95d55d98..a9a6d52c 100644 --- a/tests/proofs/mtp.test.ts +++ b/tests/proofs/mtp.test.ts @@ -15,8 +15,7 @@ import { InMemoryDataSource, InMemoryMerkleTreeStorage } from '../../src/storage import { CredentialRequest, CredentialWallet } from '../../src/credentials'; import { ProofService } from '../../src/proof'; import { CircuitId } from '../../src/circuits'; -import { ethers } from 'ethers'; -import { EthStateStorage } from '../../src/storage/blockchain/state'; +import { ethers, JsonRpcProvider } from 'ethers'; import { RootInfo, StateProof } from '../../src/storage/entities/state'; import path from 'path'; import { CredentialStatusType, VerifiableConstants, W3CCredential } from '../../src/verifiable'; @@ -24,7 +23,7 @@ import { ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../../src import { expect } from 'chai'; import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; -import { SEED_USER, createIdentity, TEST_VERIFICATION_OPTS } from '../helpers'; +import { SEED_USER, createIdentity, TEST_VERIFICATION_OPTS, RPC_URL } from '../helpers'; describe('mtp proofs', () => { let idWallet: IdentityWallet; @@ -79,6 +78,9 @@ describe('mtp proofs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider: (): JsonRpcProvider => { + return new JsonRpcProvider(RPC_URL); } }; beforeEach(async () => { @@ -164,10 +166,7 @@ describe('mtp proofs', () => { // you must store stat info (e.g. state and it's roots) - const ethSigner = new ethers.Wallet( - walletKey, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(walletKey, dataStorage.states.getRpcProvider()); const txId = await proofService.transitState( issuerDID, res.oldTreeState, @@ -254,10 +253,7 @@ describe('mtp proofs', () => { // you must store stat info (e.g. state and it's roots) - const ethSigner = new ethers.Wallet( - walletKey, - (dataStorage.states as EthStateStorage).provider - ); + const ethSigner = new ethers.Wallet(walletKey, dataStorage.states.getRpcProvider()); const txId = await proofService.transitState( issuerDID, diff --git a/tests/proofs/sig-onchain.test.ts b/tests/proofs/sig-onchain.test.ts index b0229c74..369aab98 100644 --- a/tests/proofs/sig-onchain.test.ts +++ b/tests/proofs/sig-onchain.test.ts @@ -26,6 +26,8 @@ import { byteEncoder } from '../../src'; import { ZeroKnowledgeProofRequest } from '../../src/iden3comm'; import { Blockchain, DidMethod, NetworkId } from '@iden3/js-iden3-core'; import { expect } from 'chai'; +import { JsonRpcProvider } from 'ethers'; +import { RPC_URL } from '../helpers'; describe('sig onchain proofs', () => { let idWallet: IdentityWallet; @@ -69,6 +71,9 @@ describe('sig onchain proofs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } }; diff --git a/tests/proofs/sig.test.ts b/tests/proofs/sig.test.ts index 18534dbb..82321871 100644 --- a/tests/proofs/sig.test.ts +++ b/tests/proofs/sig.test.ts @@ -23,6 +23,8 @@ import { Blockchain, DID, DidMethod, NetworkId } from '@iden3/js-iden3-core'; import { expect } from 'chai'; import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; +import { JsonRpcProvider } from 'ethers'; +import { RPC_URL } from '../helpers'; describe('sig proofs', () => { let idWallet: IdentityWallet; @@ -71,6 +73,9 @@ describe('sig proofs', () => { createdAtBlock: 0n, replacedAtBlock: 0n }); + }, + getRpcProvider() { + return new JsonRpcProvider(RPC_URL); } };