Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
@generalprotocols/anyhedge
Advanced tools
Library for creation, validation and management of AnyHedge contracts on the Bitcoin Cash blockchain.
Library for creation, validation and management of AnyHedge contracts.
Install the library via NPM:
# npm install @generalprotocols/anyhedge
Developing with AnyHedge is easy but depends on some base knowledge of developing with Bitcoin Cash.
The usage instructions below show the key steps and have links to further documentation.
We also include a custodial funding example as a reference that shows both the preparation and the AnyHedge steps.
To run the custodial example, clone the AnyHedge repo and run npm install
and npm run build
as prerequisites.
Include the AnyHedgeManager into your project.
// Load the AnyHedge library.
import { AnyHedgeManager } from '@generalprotocols/anyhedge';
// Create an instance of the contract manager with the authentication token included.
const authenticationToken = '<authentication token>';
const manager = new AnyHedgeManager({ authenticationToken });
In order to use the automated settlement services, you need to request an authentication token.
const authenticationToken = await manager.requestAuthenticationToken('My name');
Alternatively you can request an authentication token by sending a direct API request with curl.
curl -d 'name=My name' "https://api.anyhedge.com/api/v2/requestToken"
This token then needs to be passed into the constructor of an AnyHedgeManager.
Create a new contract:
// Create new contract.
const contractData = await manager.createContract(...parameters);
// Retrieve its address
const contractAddress = contractData.address;
Register a contract for automatic settlement:
// Submit a contract for external redemption management.
const contractData = await manager.registerContractForSettlement(...parameters);
Get the contract information for any contract that has been registered with the settlement service:
const contractData = await manager.getContractStatus(contractAddress);
There are several steps that need to be completed in order to build a valid funding transaction, which are outlined in the example below. After following these steps, a completed funding transaction can be submitted to the settlement service so that it can be automatically redeemed.
// STEPS:
// 1. Determine who the parties to the contract will be.
// 2. Determine what unspent coins the parties will use.
// 3. Craft a transaction with the following outputs covered
// - funding satoshis (short input + long input + miner cost (~1500) + dust cost (1092))
// to the contract's address.
// - fee satoshis to pay for the automated settlement service
// (fee rate and address are returned in the initial registration call)
// 4. Pass the transaction to each party for signing.
// Submit the funding transaction to the settlement service
const fundingInformation = await manager.submitFundingTransaction(contractAddress, constructedTransactionHex);
A contract can be funded in multiple separate instances. Retrieve a list of the contract's fundings:
const fundings = await manager.getContractFundings(contractData.parameters);
If you need to, you can mature or liquidate a contract funding manually:
Note that this is not necessary if you are using a redemption service as above.
// Mature a contract funding.
const maturationResult = await manager.matureContractFunding(...parameters);
// Liquidate a contract funding.
const liquidationResult = await manager.liquidateContractFunding(...parameters);
Also if needed, you can mutually redeem a contract by agreement between Short and Long in several ways:
Usually, both parties of the contract are separate entities that do not wish to share their private keys. So in order to mutually redeem a contract in a non-custodial way, both parties need to sign a transaction separately.
In a mutual refund, both parties agree to send the initial input amounts back to both parties.
// Sign a mutual refund proposal on the short's side.
const shortProposal = await manager.signMutualRefund(...parameters);
// Sign a mutual refund proposal on the long's side.
const longProposal = await manager.signMutualRefund(...parameters);
// Complete the mutual redemption and broadcast the transaction.
const refundTransaction = await manager.completeMutualRedemption(shortProposal, longProposal, contractData.parameters);
In a mutual early maturation, both parties agree to mimic the behavior of a maturation, but at an arbitrary time.
// Sign a mutual early maturation proposal on the short's side.
const shortProposal = await manager.signMutualEarlyMaturation(...parameters);
// Sign a mutual early maturation proposal on the long's side.
const longProposal = await manager.signMutualEarlyMaturation(...parameters);
// Complete the mutual redemption and broadcast the transaction.
const earlyMaturationTransaction = await manager.completeMutualRedemption(shortProposal, longProposal, contractData.parameters);
In a mutual arbitrary payout, both parties agree to any arbitrary transaction proposal, which can include arbitrary inputs, outputs and locktime.
// Sign a mutual early maturation proposal on the short's side.
const shortProposal = await manager.signMutualArbitraryPayout(...parameters);
// Sign a mutual early maturation proposal on the long's side.
const longProposal = await manager.signMutualArbitraryPayout(...parameters);
// Complete the mutual redemption and broadcast the transaction.
const arbitraryPayoutTransaction = await manager.completeMutualRedemption(shortProposal, longProposal, contractData.parameters);
If you have access to the private keys of both parties of the contract, you can also mutually redeem the contract by providing both private keys:
// Refund both parties' initial inputs.
const refundTransaction = await manager.custodialMutualRefund(...parameters);
// Perform an early maturation.
const earlyMaturationTransaction = await manager.custodialMutualEarlyMaturation(...parameters);
// Perform an arbitrary payout transaction.
const arbitraryPayoutTransaction = await manager.custodialMutualArbitraryPayout(...parameters);
FAQs
Library for creation, validation and management of AnyHedge contracts on the Bitcoin Cash blockchain.
The npm package @generalprotocols/anyhedge receives a total of 382 weekly downloads. As such, @generalprotocols/anyhedge popularity was classified as not popular.
We found that @generalprotocols/anyhedge 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.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.