Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chromia/bridge-client

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chromia/bridge-client - npm Package Compare versions

Comparing version 2.2.7 to 2.2.8

chunk-4LMGF6R6.mjs

119

client/client.js

@@ -86,2 +86,8 @@ "use strict";

};
var PostchainRestError = class extends Error {
constructor(message) {
super(message);
this.name = "PostchainRestError";
}
};

@@ -1631,3 +1637,9 @@ // src/types/postchain-eif-contracts/factories/index.ts

// src/types/stubs/hbridge/hbridge.ts
function getEventMerkleProofQueryObject(eventHash) {
function getEventMerkleProofQueryObject(eventHash, signers, signatures) {
if (signers && signatures) {
return {
name: "get_event_merkle_proof",
args: { eventHash, signers, signatures }
};
}
return {

@@ -1638,2 +1650,8 @@ name: "get_event_merkle_proof",

}
function getEventBlockHeightQueryObject(eventHash) {
return {
name: "get_event_block_height",
args: { eventHash }
};
}
function getErc20WithdrawalQueryObject(networkId, tokenAddress, beneficiary) {

@@ -1729,2 +1747,60 @@ return {

// src/util/utils.ts
var compareValidatorSet = (cluster, validators) => {
const clustersSorted = cluster.map((addr) => addr.toLowerCase()).sort();
const validatorsSorted = validators.map((addr) => addr.toLowerCase()).sort();
if (clustersSorted.length !== validatorsSorted.length) {
return false;
}
if (!clustersSorted.every(
(cluster2, index) => cluster2 === validatorsSorted[index]
)) {
return false;
}
return true;
};
// src/util/rest.ts
function get(url) {
return __async(this, null, function* () {
try {
return yield fetch(url);
} catch (error) {
throw new PostchainRestError(`Failed to fetch ${url}: ${error}`);
}
});
}
function getDirectoryChainUrl(chainUrl) {
return __async(this, null, function* () {
const directoryChainUrlResponse = yield get(`${chainUrl}/brid/iid_0`);
return yield directoryChainUrlResponse.text();
});
}
function getDirectoryChainCluster(chainUrl, directoryChainUrl, blockchainRid) {
return __async(this, null, function* () {
const directoryChainClusterResponse = yield get(
`${chainUrl}/query/${directoryChainUrl}?type=get_blockchain_cluster&blockchain_rid=${blockchainRid}`
);
return yield directoryChainClusterResponse.text();
});
}
function getClusterNodes(chainUrl, directoryChainUrl, name) {
return __async(this, null, function* () {
const clusterNodesResponse = yield get(
`${chainUrl}/query/${directoryChainUrl}?type=get_cluster_nodes&name=${name.replace(/"/g, "")}`
);
return yield clusterNodesResponse.json();
});
}
function getBlockConfirmations(endpoints, blockchainRid, blockRid) {
return __async(this, null, function* () {
return yield Promise.all(
endpoints.map((endpoint) => __async(this, null, function* () {
const response = (yield get(`${endpoint.url}/blocks/${blockchainRid}/confirm/${blockRid}`)).json();
return response;
}))
);
});
}
// src/client/client.ts

@@ -1937,3 +2013,42 @@ function bridgeClient(options, provider, ftSession) {

);
return generateEventWithProof(eventMerkleProof);
const endpointPool = ftSession.client.config.endpointPool;
const blockchainRid = ftSession.client.config.blockchainRid;
const directoryChainUrl = yield getDirectoryChainUrl(
endpointPool[0].url
);
const directoryChainCluster = yield getDirectoryChainCluster(
endpointPool[0].url,
directoryChainUrl,
blockchainRid
);
const clusterNodes = yield getClusterNodes(
endpointPool[0].url,
directoryChainUrl,
directoryChainCluster.replace(/"/g, "")
);
const evmKeys = clusterNodes.map(
(node) => (0, import_ethers4.computeAddress)("0x" + node.pubkey)
);
const generatedProof = generateEventWithProof(eventMerkleProof);
if (compareValidatorSet(evmKeys, generatedProof.signers)) {
console.log("Event proof is valid.");
return generatedProof;
}
const eventBlockHeight = yield ftSession.query(
getEventBlockHeightQueryObject(eventHash)
);
const block = yield ftSession.client.getBlockInfo(eventBlockHeight);
const newBlockWitness = yield getBlockConfirmations(
endpointPool,
blockchainRid,
block.rid.toString("hex")
);
const newEventMerkleProof = yield ftSession.query(
getEventMerkleProofQueryObject(
eventHash,
newBlockWitness.map((bc) => import_buffer2.Buffer.from(bc.subjectID, "hex")),
newBlockWitness.map((bc) => import_buffer2.Buffer.from(bc.data, "hex"))
)
);
return generateEventWithProof(newEventMerkleProof);
} catch (error) {

@@ -1940,0 +2055,0 @@ throw new EvmBridgeTransactionError(

5

client/error.d.ts

@@ -19,3 +19,6 @@ declare class ClientSessionError extends Error {

}
declare class PostchainRestError extends Error {
constructor(message?: string);
}
export { ClientSessionError, ERC20TokenTransactionError, EvmBridgeTransactionError, EvmProviderError, PostchainQueryError, PostchainTransactionError };
export { ClientSessionError, ERC20TokenTransactionError, EvmBridgeTransactionError, EvmProviderError, PostchainQueryError, PostchainRestError, PostchainTransactionError };

@@ -28,2 +28,3 @@ "use strict";

PostchainQueryError: () => PostchainQueryError,
PostchainRestError: () => PostchainRestError,
PostchainTransactionError: () => PostchainTransactionError

@@ -68,2 +69,8 @@ });

};
var PostchainRestError = class extends Error {
constructor(message) {
super(message);
this.name = "PostchainRestError";
}
};
// Annotate the CommonJS export names for ESM import in node:

@@ -76,3 +83,4 @@ 0 && (module.exports = {

PostchainQueryError,
PostchainRestError,
PostchainTransactionError
});

@@ -47,3 +47,3 @@ import { ContractTransactionResponse } from 'ethers';

*/
depositToEvmBridgeContract(amount: bigint, evmKeyStore?: EvmKeyStore): Promise<ContractTransactionResponse>;
depositToEvmBridgeContract(amount: bigint): Promise<ContractTransactionResponse>;
/**

@@ -102,3 +102,3 @@ * Withdraws an asset from the EVM bridge contract.

/**
* Retrieves proof of a withdrawal request.
* Retrieves proof of a withdrawal request. Will automatically re-confirm the withdrawal event proof if the validator set has changed.
*

@@ -105,0 +105,0 @@ * @param {string} eventHash The withdrawal request.

export { ClientOptions } from './types/clientOptions.js';
export { ClientSessionError, ERC20TokenTransactionError, EvmBridgeTransactionError, EvmProviderError, PostchainQueryError, PostchainTransactionError } from './client/error.js';
export { EventWithProof, RootObject } from './types/bridge.js';
export { ClientSessionError, ERC20TokenTransactionError, EvmBridgeTransactionError, EvmProviderError, PostchainQueryError, PostchainRestError, PostchainTransactionError } from './client/error.js';
export { BlockConfirmation, EventWithProof, RootObject } from './types/bridge.js';
export { DepositFilter, Erc20Withdrawal, WithdrawalFilter } from './types/stubs/hbridge/hbridge.js';

@@ -5,0 +5,0 @@ export { bridgeClient } from './client/client.js';

@@ -48,2 +48,3 @@ "use strict";

PostchainQueryError: () => PostchainQueryError,
PostchainRestError: () => PostchainRestError,
PostchainTransactionError: () => PostchainTransactionError,

@@ -91,5 +92,17 @@ bridgeClient: () => bridgeClient

};
var PostchainRestError = class extends Error {
constructor(message) {
super(message);
this.name = "PostchainRestError";
}
};
// src/types/stubs/hbridge/hbridge.ts
function getEventMerkleProofQueryObject(eventHash) {
function getEventMerkleProofQueryObject(eventHash, signers, signatures) {
if (signers && signatures) {
return {
name: "get_event_merkle_proof",
args: { eventHash, signers, signatures }
};
}
return {

@@ -100,2 +113,8 @@ name: "get_event_merkle_proof",

}
function getEventBlockHeightQueryObject(eventHash) {
return {
name: "get_event_block_height",
args: { eventHash }
};
}
function getErc20WithdrawalQueryObject(networkId, tokenAddress, beneficiary) {

@@ -1737,2 +1756,60 @@ return {

// src/util/utils.ts
var compareValidatorSet = (cluster, validators) => {
const clustersSorted = cluster.map((addr) => addr.toLowerCase()).sort();
const validatorsSorted = validators.map((addr) => addr.toLowerCase()).sort();
if (clustersSorted.length !== validatorsSorted.length) {
return false;
}
if (!clustersSorted.every(
(cluster2, index) => cluster2 === validatorsSorted[index]
)) {
return false;
}
return true;
};
// src/util/rest.ts
function get(url) {
return __async(this, null, function* () {
try {
return yield fetch(url);
} catch (error) {
throw new PostchainRestError(`Failed to fetch ${url}: ${error}`);
}
});
}
function getDirectoryChainUrl(chainUrl) {
return __async(this, null, function* () {
const directoryChainUrlResponse = yield get(`${chainUrl}/brid/iid_0`);
return yield directoryChainUrlResponse.text();
});
}
function getDirectoryChainCluster(chainUrl, directoryChainUrl, blockchainRid) {
return __async(this, null, function* () {
const directoryChainClusterResponse = yield get(
`${chainUrl}/query/${directoryChainUrl}?type=get_blockchain_cluster&blockchain_rid=${blockchainRid}`
);
return yield directoryChainClusterResponse.text();
});
}
function getClusterNodes(chainUrl, directoryChainUrl, name) {
return __async(this, null, function* () {
const clusterNodesResponse = yield get(
`${chainUrl}/query/${directoryChainUrl}?type=get_cluster_nodes&name=${name.replace(/"/g, "")}`
);
return yield clusterNodesResponse.json();
});
}
function getBlockConfirmations(endpoints, blockchainRid, blockRid) {
return __async(this, null, function* () {
return yield Promise.all(
endpoints.map((endpoint) => __async(this, null, function* () {
const response = (yield get(`${endpoint.url}/blocks/${blockchainRid}/confirm/${blockRid}`)).json();
return response;
}))
);
});
}
// src/client/client.ts

@@ -1945,3 +2022,42 @@ function bridgeClient(options, provider, ftSession) {

);
return generateEventWithProof(eventMerkleProof);
const endpointPool = ftSession.client.config.endpointPool;
const blockchainRid = ftSession.client.config.blockchainRid;
const directoryChainUrl = yield getDirectoryChainUrl(
endpointPool[0].url
);
const directoryChainCluster = yield getDirectoryChainCluster(
endpointPool[0].url,
directoryChainUrl,
blockchainRid
);
const clusterNodes = yield getClusterNodes(
endpointPool[0].url,
directoryChainUrl,
directoryChainCluster.replace(/"/g, "")
);
const evmKeys = clusterNodes.map(
(node) => (0, import_ethers4.computeAddress)("0x" + node.pubkey)
);
const generatedProof = generateEventWithProof(eventMerkleProof);
if (compareValidatorSet(evmKeys, generatedProof.signers)) {
console.log("Event proof is valid.");
return generatedProof;
}
const eventBlockHeight = yield ftSession.query(
getEventBlockHeightQueryObject(eventHash)
);
const block = yield ftSession.client.getBlockInfo(eventBlockHeight);
const newBlockWitness = yield getBlockConfirmations(
endpointPool,
blockchainRid,
block.rid.toString("hex")
);
const newEventMerkleProof = yield ftSession.query(
getEventMerkleProofQueryObject(
eventHash,
newBlockWitness.map((bc) => import_buffer2.Buffer.from(bc.subjectID, "hex")),
newBlockWitness.map((bc) => import_buffer2.Buffer.from(bc.data, "hex"))
)
);
return generateEventWithProof(newEventMerkleProof);
} catch (error) {

@@ -2025,4 +2141,5 @@ throw new EvmBridgeTransactionError(

PostchainQueryError,
PostchainRestError,
PostchainTransactionError,
bridgeClient
});
{
"name": "@chromia/bridge-client",
"version": "2.2.7",
"version": "2.2.8",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

@@ -41,3 +41,7 @@ import { BytesLike, BigNumberish } from 'ethers';

};
type BlockConfirmation = {
subjectID: string;
data: string;
};
export type { EventWithProof, RootObject };
export type { BlockConfirmation, EventWithProof, RootObject };
/**
* Client options.
* @property {string} bridgeAddress - The address of the bridge contract.
* @property {string} tokenAddress - The address of the token contract.
* @property {string} tokenAddress - The address of the token contract. Any token following the ERC20 standard can be used for this.
*/

@@ -6,0 +6,0 @@ type ClientOptions = {

@@ -74,3 +74,13 @@ import { QueryObject, Operation } from 'postchain-client';

};
declare function getEventMerkleProofQueryObject(eventHash: string): QueryObject<Buffer>;
type ClusterNode = {
pubkey: string;
host: string;
port: number;
api_url: string;
active: boolean;
};
declare function getEventMerkleProofQueryObject(eventHash: string, signers?: Buffer[], signatures?: Buffer[]): QueryObject<Buffer>;
declare function getBlockchainClusterQueryObject(blockchainRid: Buffer): QueryObject<string>;
declare function getClusterNodesQueryObject(name: string): QueryObject<ClusterNode[]>;
declare function getEventBlockHeightQueryObject(eventHash: string): QueryObject<number>;
declare function getErc20ForAssetQueryObject(assetId: Buffer): QueryObject<Erc20Info[]>;

@@ -96,2 +106,2 @@ declare function getErc20WithdrawalQueryObject(networkId: number, tokenAddress: Buffer, beneficiary: Buffer): QueryObject<Erc20Withdrawal[]>;

export { BridgeMode, type DepositFilter, DepositState, type Erc20DepositHistoryEntry, type Erc20Info, type Erc20Withdrawal, type Erc20WithdrawalHistoryEntry, type Erc20WithdrawalInfo, type GetScAddressesForAccountReturnType, type WithdrawalFilter, WithdrawalStatus, bridgeFt4TokenToEvmOperation, getAccountForEoaAddressQueryObject, getAccountForScAddressQueryObject, getEoaAddressesForAccountQueryObject, getErc20DepositHistoryQueryObject, getErc20DepositsQueryObject, getErc20ForAssetQueryObject, getErc20WithdrawalByTxQueryObject, getErc20WithdrawalHistoryQueryObject, getErc20WithdrawalQueryObject, getErc20WithdrawalsQueryObject, getEventMerkleProofQueryObject, getScAddressesForAccountQueryObject, linkEvmEoaAccountOperation, linkEvmScAccountOperation, recallPendingDepositOperation };
export { BridgeMode, type ClusterNode, type DepositFilter, DepositState, type Erc20DepositHistoryEntry, type Erc20Info, type Erc20Withdrawal, type Erc20WithdrawalHistoryEntry, type Erc20WithdrawalInfo, type GetScAddressesForAccountReturnType, type WithdrawalFilter, WithdrawalStatus, bridgeFt4TokenToEvmOperation, getAccountForEoaAddressQueryObject, getAccountForScAddressQueryObject, getBlockchainClusterQueryObject, getClusterNodesQueryObject, getEoaAddressesForAccountQueryObject, getErc20DepositHistoryQueryObject, getErc20DepositsQueryObject, getErc20ForAssetQueryObject, getErc20WithdrawalByTxQueryObject, getErc20WithdrawalHistoryQueryObject, getErc20WithdrawalQueryObject, getErc20WithdrawalsQueryObject, getEventBlockHeightQueryObject, getEventMerkleProofQueryObject, getScAddressesForAccountQueryObject, linkEvmEoaAccountOperation, linkEvmScAccountOperation, recallPendingDepositOperation };

@@ -29,2 +29,4 @@ "use strict";

getAccountForScAddressQueryObject: () => getAccountForScAddressQueryObject,
getBlockchainClusterQueryObject: () => getBlockchainClusterQueryObject,
getClusterNodesQueryObject: () => getClusterNodesQueryObject,
getEoaAddressesForAccountQueryObject: () => getEoaAddressesForAccountQueryObject,

@@ -38,2 +40,3 @@ getErc20DepositHistoryQueryObject: () => getErc20DepositHistoryQueryObject,

getErc20WithdrawalsQueryObject: () => getErc20WithdrawalsQueryObject,
getEventBlockHeightQueryObject: () => getEventBlockHeightQueryObject,
getEventMerkleProofQueryObject: () => getEventMerkleProofQueryObject,

@@ -65,3 +68,9 @@ getScAddressesForAccountQueryObject: () => getScAddressesForAccountQueryObject,

})(WithdrawalStatus || {});
function getEventMerkleProofQueryObject(eventHash) {
function getEventMerkleProofQueryObject(eventHash, signers, signatures) {
if (signers && signatures) {
return {
name: "get_event_merkle_proof",
args: { eventHash, signers, signatures }
};
}
return {

@@ -72,2 +81,20 @@ name: "get_event_merkle_proof",

}
function getBlockchainClusterQueryObject(blockchainRid) {
return {
name: "get_blockchain_cluster",
args: { blockchainRid }
};
}
function getClusterNodesQueryObject(name) {
return {
name: "get_cluster_nodes",
args: { name }
};
}
function getEventBlockHeightQueryObject(eventHash) {
return {
name: "get_event_block_height",
args: { eventHash }
};
}
function getErc20ForAssetQueryObject(assetId) {

@@ -169,2 +196,4 @@ return {

getAccountForScAddressQueryObject,
getBlockchainClusterQueryObject,
getClusterNodesQueryObject,
getEoaAddressesForAccountQueryObject,

@@ -178,2 +207,3 @@ getErc20DepositHistoryQueryObject,

getErc20WithdrawalsQueryObject,
getEventBlockHeightQueryObject,
getEventMerkleProofQueryObject,

@@ -180,0 +210,0 @@ getScAddressesForAccountQueryObject,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc