Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@chromia/bridge-client
Advanced tools
This is a client library with utilities for interacting with the Chromia Bridge.
This is a client library with utilities for interacting with the Chromia Bridge.
allowToken
function in the TokenBridge contract. This is possible to do with @chromia/bridge-client
using the built in method allowToken
:
const contractTransactionResponse = await bcl.allowToken(token);
checkAllowance
:
const allowance: bigint = await bcl.checkAllowance();
setBlockchainRid
function in the TokenBridge contract. This is possible to do with @chromia/bridge-client
using the built in method setBlockchainRid
:
const contractTransactionResponse = await bcl.setBlockchainRid(rid);
updateValidators
function in the Validator contract.The bridge client needs an active Session
to handle all Chromia related queries and operations, but it does however not need to be instantiated with it. In order to get an active Session
, you can set up your application with @chromia/ft4
like this:
// 1: Setup a connection to postchain through postchain-client
const pcl = await createClient({
nodeUrlPool: 'YOU_NODE_URL_POOL',
blockchainRid: 'YOUR_BLOCKCHAIN_RID',
});
// 2: Create an account
const evmKeyStore = await createWeb3ProviderEvmKeyStore(window.ethereum);
const ad = createSingleSigAuthDescriptorRegistration(
[AuthFlag.Account, AuthFlag.Transfer],
evmKeyStore.id
);
const response = await registerAccount(
pcl,
evmKeyStore,
registrationStrategy.open(ad)
);
// 3: Log in your user
const evmKeyStoreInteractor = createKeyStoreInteractor(pcl, evmKeyStore);
const accounts = await evmKeyStoreInteractor.getAccounts();
const session = await evmKeyStoreInteractor.getSession(accounts[0].id);
evmKeyStore
somewhere in your application state as some methods in @chromia/bridge-client
will require it.Now that you have your Session
object, you can use it to initialize the bridge client. You will also need to provide an EVM Provider
, either a BrowserProvider
or a JsonRpcProvider
:
const provider = new BrowserProvider(window.ethereum);
const bcl = await bridgeClient(
{ bridgeAddress: 'YOUR_BRIDGE_ADDRESS', tokenAddress: 'YOUR_TOKEN_ADDRESS' },
provider,
session
);
If your application is setup in a way that makes it impossible to have an active Session
at the time you also need to instantiate the bridge client, you can still setup the client without the Session
:
const provider = new BrowserProvider(window.ethereum);
const bcl = await bridgeClient(
{ bridgeAddress: 'YOUR_BRIDGE_ADDRESS', tokenAddress: 'YOUR_TOKEN_ADDRESS' },
provider
);
When you later have access to the Session
, you can simply set it to the client through setSession(session: Session)
:
bcl.setSession(session);
First, make sure that the user approves spending of tokens by the token bridge:
const approvalResponse = await bcl.approveDepositAmount(BigInt(10));
To make a deposit to the Chromia EVM bridge, you need to use the method depositToEvmBridgeContract
. Here you will need to provide the amount
of tokens you want to bridge over.
const contractTransactionResponse = await bcl.depositToEvmBridgeContract(
BigInt(100)
);
After a deposit has been made, you can link the EVM account with the corresponding FT4 account that was created automatically in the deposit process, here you need to provide the evmKeyStore
you created earlier:
const accountLinkingResponse =
await bcl.depositToEvmBridgeContract(evmKeyStore);
accountLinkingResponse
. Do note that an EVM account can have multiple FT4 accounts linked to it.This is all you have to do in order to bridge tokens from EVM to Chromia, if the transaction is successful the user will now have their bridged tokens on Chromia.
For the user one of two things will happen:
Session
or evmKeyStore
was provided, account linking is skipped completelyTo do this, you will first have to call the method bridgeFromChromia
, with the amount
and the assetId
:
// Network ID does not need to be provided as it will be fetched from the provider
const transactionResponse = await bcl.bridgeFromChromia(
BigInt(10),
Buffer.from('YOUR_ASSET_ID', 'hex')
);
The previous action created a pending withdraw request, these need to be accepted by the user in order to start the withdrawal process, which is done with the requestEvmWithdraw
method. This process looks like this:
const erc20WithdrawalInfo = await bcl.getErc20WithdrawalByTransactionRid(
transactionResponse.receipt.transactionRid,
opIndex
);
// Get event proof for withdrawal
const eventProof = await bcl.getWithdrawRequestEventProof(
erc20WithdrawalInfo.event_hash
);
// Request withdrawal
const requestedWithdraw = await bcl.requestEvmWithdraw(eventProof);
Depending on how the bridge contract has been configured, the user will have to wait X number of blocks on EVM in order to complete their withdrawal. This can be done with the getPendingWithdrawFromProof
method:
const { block_number } = await getPendingWithdrawFromProof(eventProof);
Once the block_number
has been reached on the target EVM chain, the user can withdraw their tokens:
const withdrawal = await bcl.evmWithdraw(eventProof.leaf as Buffer);
getErc20Deposits(filter?: DepositFilter, pageSize?: number, pageCursor?: string)
- Returns all deposits as specified by the filter.getErc20Withdrawals(filter?: WithdrawFilter, pageSize?: number, pageCursor?: string)
- Returns all withdrawals from the EVM bridge as specified by the filter.setBlockchainRid(blockchainRid: Buffer)
- Sets the blockchain RID.FAQs
This is a client library with utilities for interacting with the Chromia Bridge.
The npm package @chromia/bridge-client receives a total of 214 weekly downloads. As such, @chromia/bridge-client popularity was classified as not popular.
We found that @chromia/bridge-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.