New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

slopes

Package Overview
Dependencies
Maintainers
3
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slopes - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

2

package.json
{
"name": "slopes",
"version": "1.5.0",
"version": "1.5.1",
"description": "AVA Platform JS Library",

@@ -5,0 +5,0 @@ "main": "typings/src/index.js",

@@ -5,3 +5,3 @@ # Slopes - The AVA Platform JavaScript Library

Slopes is a JavaScript Library for interfacing with the AVA Platform. It is built using TypeScript and intended to support both browser and Node.js. The Slopes library allows one to issue commands to the AVA node APIs.
Slopes is a JavaScript Library for interfacing with the AVA Platform. It is built using TypeScript and intended to support both browser and Node.js. The Slopes library allows one to issue commands to the AVA node APIs.

@@ -17,3 +17,3 @@ The APIs currently supported by default are:

We built Slopes with ease of use in mind. With this library, any Javascript developer is able to interact with a node on the AVA Platform who has enabled their API endpoints for the developer's consumption. We keep the library up-to-date with the latest changes in the [AVA Platform Specification](https://avalabs.org/docs/).
We built Slopes with ease of use in mind. With this library, any Javascript developer is able to interact with a node on the AVA Platform who has enabled their API endpoints for the developer's consumption. We keep the library up-to-date with the latest changes in the [AVA Platform Specification](https://avalabs.org/docs/).

@@ -136,6 +136,6 @@ Using Slopes, developers are able to:

```js
let addresses = avm.keyChain().getAddresses(); //returns an array of Buffers for the addresses
let addressStrings = avm.keyChain().getAddressStrings(); //returns an array of strings for the addresses
let exists = myKeychain.hasKey(myaddress); //returns true if the address is managed
let keypair = myKeychain.getKey(myaddress); //returns the keypair class
let addresses = myKeychain.getAddresses(); //returns an array of Buffers for the addresses
let addressStrings = myKeychain.getAddressStrings(); //returns an array of strings for the addresses
let exists = myKeychain.hasKey(newAddress1); //returns true if the address is managed
let keypair = myKeychain.getKey(newAddress1); //returns the keypair class
```

@@ -162,6 +162,6 @@

let message = "Wubalubadubdub";
let message = Buffer.from("Wubalubadubdub");
let signature = keypair.sign(message); //returns a Buffer with the signature
let signerPubk = keypair.recover(message, signature);
let isValid = keypair.verify(message, signature, signerPubk); //returns a boolean
let isValid = keypair.verify(message, signature); //returns a boolean
```

@@ -181,3 +181,3 @@

The first steps in creating a new asset using Slopes is to determine the qualties of the asset. We will give the asset a name, a ticker symbol, as well as a denomination.
The first steps in creating a new asset using Slopes is to determine the qualties of the asset. We will give the asset a name, a ticker symbol, as well as a denomination.

@@ -199,3 +199,3 @@ ```js

We want to mint an asset with 400 coins to all of our managed keys, 500 to the second address we know of, and 600 to the second and third address. This sets up the state that will result from the Create Asset transaction.
We want to mint an asset with 400 coins to all of our managed keys, 500 to the second address we know of, and 600 to the second and third address. This sets up the state that will result from the Create Asset transaction.

@@ -224,3 +224,3 @@ *Note: This example assumes we have the keys already managed in our AVM Keychain.*

Now that we know what we want an asset to look like, we create an output to send to the network. There is an AVM helper function `makeCreateAssetTx()` which does just that.
Now that we know what we want an asset to look like, we create an output to send to the network. There is an AVM helper function `makeCreateAssetTx()` which does just that.

@@ -239,3 +239,3 @@ ```js

Now that we have a signed transaction ready to send to the network, let's issue it!
Now that we have a signed transaction ready to send to the network, let's issue it!

@@ -267,3 +267,3 @@ Using the Slopes AVM API, we going to call the issueTx function. This function can take either the Tx class returned in the previous step, a base-58 string AVA serialized representation of the transaction, or a raw Buffer class with the data for the transaction. Examples of each are below:

// returns one of: "Accepted", "Processing", "Unknown", and "Rejected"
let status = await avm.getTxStatus(txid);
let status = await avm.getTxStatus(txid);
```

@@ -283,2 +283,3 @@

## Example 3 — Sending An Asset
This example sends an asset in the AVM to a single recipient. The first step in this process is to create an instance of Slopes connected to our AVA Platform endpoint of choice.

@@ -296,10 +297,11 @@

The AVM stores all available balances in a datastore called Unspent Transaction Outputs (UTXOs). A UTXO Set is the unique list of outputs produced by transactions, addresses that can spend those outputs, and other variables such as lockout times (a timestamp after which the output can be spent) and thresholds (how many signers are required to spend the output).
The AVM stores all available balances in a datastore called Unspent Transaction Outputs (UTXOs). A UTXO Set is the unique list of outputs produced by transactions, addresses that can spend those outputs, and other variables such as lockout times (a timestamp after which the output can be spent) and thresholds (how many signers are required to spend the output).
For the case of this example, we're going to create a simple transaction that spends an amount of available coins and sends it to a single address without any restrictions. The management of the UTXOs will mostly be abstracted away.
For the case of this example, we're going to create a simple transaction that spends an amount of available coins and sends it to a single address without any restrictions. The management of the UTXOs will mostly be abstracted away.
However, we do need to get the UTXO Set for the addresses we're managing.
However, we do need to get the UTXO Set for the addresses we're managing.
```js
let myAddresses = avm.keyChain().getAddresses(); //returns an array of addresses the keychain manages
let addressStrings = avm.keyChain().getAddressStrings(); //returns an array of addresses the keychain manages as strings
let utxos = await avm.getUTXOs(myAddresses);

@@ -316,2 +318,3 @@ ```

```
We have 400 coins! We're going to now send 100 of those coins to our friend's address.

@@ -331,3 +334,3 @@

// * The AssetID of the funds being sent
let unsignedTx = avm.makeUnsignedTx(utxos, amount, [friendsAddress], myAddresses, myAddresses, assetid);
let unsignedTx = await avm.makeUnsignedTx(utxos, sendAmount, [friendsAddress], addressStrings, addressStrings, assetid);
let signedTx = avm.signTx(unsignedTx);

@@ -345,3 +348,3 @@ let txid = await avm.issueTx(signedTx);

// returns one of: "Accepted", "Processing", "Unknown", and "Rejected"
let status = await avm.getTxStatus(txid);
let status = await avm.getTxStatus(txid);
```

@@ -358,3 +361,3 @@

The transaction finally came back as "Accepted", now let's update the UTXOSet and verify that the transaction balance is as we expected.
The transaction finally came back as "Accepted", now let's update the UTXOSet and verify that the transaction balance is as we expected.

@@ -361,0 +364,0 @@ *Note: In a real network the balance isn't guaranteed to match this scenario. Transaction fees or additional spends may vary the balance. For the purpose of this example, we assume neither of those cases.*

@@ -112,2 +112,21 @@ /**

/**
* Refresh blockchainID, and if a blockchainID is passed in, use that.
*
* @param Optional. BlockchainID to assign, if none, uses the default based on networkID.
*
* @returns The blockchainID
*/
refreshBlockchainID = (blockchainID:string = undefined):boolean => {
let netid:number = this.core.getNetworkID();
if(typeof blockchainID === "undefined" && netid in Defaults.network) {
this.blockchainID = Defaults.network[netid]["avm"].blockchainID;
return true
} else if(typeof blockchainID === "string") {
this.blockchainID = blockchainID;
return true;
}
return false;
}
/**
* Takes an address string and returns its {@link https://github.com/feross/buffer|Buffer} representation if valid.

@@ -392,2 +411,48 @@ *

/**
* Send AVA from the X-Chain to an account on the P-Chain.
*
* After calling this method, you must call the P-Chain’s importAVA method to complete the transfer.
*
* @param username The Keystore user that controls the P-Chain account specified in `to`
* @param password The password of the Keystore user
* @param to The acount on the P-Chain to send the AVA to. Do not include P- in the address
* @param amount Amount of AVA to export as a {@link https://github.com/indutny/bn.js/|BN}
*
* @returns Promise for an unsigned transaction to be signed by the account the the AVA is sent from and pays the transaction fee.
*/
exportAVA = async (username: string, password:string, to:string, amount:BN):Promise<string> => {
let params = {
"to": to,
"amount": amount,
"username": username,
"password": password
}
return this.callMethod("avm.exportAVA", params).then((response:RequestResponseData) => {
return response.data["result"]["txID"];
});
}
/**
* Finalize a transfer of AVA from the P-Chain to the X-Chain.
*
* Before this method is called, you must call the P-Chain’s `exportAVA` method to initiate the transfer.
*
* @param to The address the AVA is sent to. This must be the same as the to argument in the corresponding call to the P-Chain’s exportAVA, except that the prepended X- should be included in this argument
* @param username The Keystore user that controls the address specified in `to`
* @param password The password of the Keystore user
*
* @returns Promise for a string for the transaction, which should be sent to the network by calling issueTx.
*/
importAVA = async (username: string, password:string, to:string):Promise<string> => {
let params = {
"to": to,
"username": username,
"password": password
}
return this.callMethod("avm.importAVA", params).then((response:RequestResponseData) => {
return response.data["result"]["txID"];
});
}
/**
* Lists all the addresses under a user.

@@ -394,0 +459,0 @@ *

@@ -25,18 +25,2 @@ /**

/**
* Add a staked validator to the validator set.
*
* @param tx The string representation of an AddStakerTx
*
* @returns Promise for a boolean value, true on success.
*/
addStaker = async (tx:string):Promise<boolean> => {
let params = {
"tx": tx
};
return this.callMethod("platform.addStaker", params).then((response:RequestResponseData) => {
return response.data["result"]["success"];
});
}
/**
* Creates a new blockchain.

@@ -207,6 +191,247 @@ *

/**
* Add a validator to the Default Subnet.
*
* @param id The node ID of the validator
* @param startTime Javascript Date object for the start time to validate
* @param endTime Javascript Date object for the end time to validate
* @param stakeAmount The amount of nAVA the validator is staking as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account that is providing the staked AVA and paying the transaction fee
* @param destination The P-Chain address of the account that the staked AVA will be returned to, as well as a validation reward if the validator is sufficiently responsive and correct while it validated
* @param delegationFeeRate Optional. The percent fee this validator charges when others delegate stake to them, multiplied by 10,000 as a {@link https://github.com/indutny/bn.js/|BN}. For example, suppose a validator has delegationFeeRate 300,000 and someone delegates to that validator. When the delegation period is over, if the delegator is entitled to a reward, 30% of the reward (300,000 / 10,000) goes to the validator and 70% goes to the delegator
* @param subnetID Optional. Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for a base58 string of the unsigned transaction.
*/
addDefaultSubnetValidator = async (id:string, startTime:Date, endTime:Date, stakeAmount:BN, payerNonce:number, destination:string, delegationFeeRate:BN = undefined):Promise<string> => {
let params = {
"id": id,
"startTime": startTime.getTime()/1000,
"endTime": endTime.getTime()/1000,
"stakeAmount": stakeAmount.toString(10),
"payerNonce": Math.floor(payerNonce),
"destination": destination
};
if (typeof delegationFeeRate !== "undefined") {
params["delegationFeeRate"] = delegationFeeRate.toString(10);
}
return this.callMethod("platform.addDefaultSubnetValidator", params).then((response:RequestResponseData) => {
return response.data["result"]["unsignedTx"];
});
}
/**
* Add a validator to a Subnet other than the Default Subnet. The validator must validate the Default Subnet for the entire duration they validate this Subnet.
*
* @param id The node ID of the validator
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
* @param startTime Javascript Date object for the start time to validate
* @param endTime Javascript Date object for the end time to validate
* @param weight The validator’s weight used for sampling
* @param payerNonce The next unused nonce of the account that is providing the staked AVA and paying the transaction fee
*
* @returns Promise for the unsigned transaction. It must be signed (using sign) by the proper number of the Subnet’s control keys and by the key of the account paying the transaction fee before it can be issued.
*/
addNonDefaultSubnetValidator = async (id:string, subnetID:Buffer | string, startTime:Date, endTime:Date, weight:number, payerNonce:number):Promise<string> => {
let params = {
"id": id,
"subnet": subnetID,
"startTime": startTime.getTime()/1000,
"endTime": endTime.getTime()/1000,
"weight": weight,
"payerNonce": Math.floor(payerNonce)
};
if(typeof subnetID === "string"){
params["subnetID"] = subnetID;
} else if (typeof subnetID !== "undefined") {
params["subnetID"] = bintools.avaSerialize(subnetID);
}
return this.callMethod("platform.addNonDefaultSubnetValidator", params).then((response:RequestResponseData) => {
return response.data["result"]["unsignedTx"];
});
}
/**
* Add a delegator to the Default Subnet.
*
* @param id The node ID of the delegatee
* @param startTime Javascript Date object for when the delegator starts delegating
* @param endTime Javascript Date object for when the delegator starts delegating
* @param stakeAmount The amount of nAVA the delegator is staking as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account that will provide the staked AVA and pay the transaction fee
* @param destination The address of the account the staked AVA and validation reward (if applicable) are sent to at endTime
*
* @returns Promise for an array of validator's stakingIDs.
*/
addDefaultSubnetDelegator = async (id:string, startTime:Date, endTime:Date, stakeAmount:BN, payerNonce:number, destination:string):Promise<string> => {
let params = {
"id": id,
"startTime": startTime.getTime()/1000,
"endTime": endTime.getTime()/1000,
"stakeAmount": stakeAmount.toString(10),
"payerNonce": Math.floor(payerNonce),
"destination": destination
};
return this.callMethod("platform.addDefaultSubnetDelegator", params).then((response:RequestResponseData) => {
return response.data["result"]["unsignedTx"];
});
}
/**
* Create an unsigned transaction to create a new Subnet. The unsigned transaction must be signed with the key of the account paying the transaction fee. The Subnet’s ID is the ID of the transaction that creates it (ie the response from issueTx when issuing the signed transaction).
*
* @param controlKeys Array of platform addresses as strings
* @param threshold To add a validator to this Subnet, a transaction must have threshold signatures, where each signature is from a key whose address is an element of `controlKeys`
* @param payerNonce The next unused nonce of the account providing the transaction fee
*
* @returns Promise for a string with the unsigned transaction encoded as base58.
*/
createSubnet = async (controlKeys:Array<string>, threshold:number, payerNonce:number):Promise<string> => {
let params = {
"controlKeys": controlKeys,
"threshold": threshold,
"payerNonce": payerNonce
}
return this.callMethod("platform.createSubnet", params).then((response:RequestResponseData) => {
return response.data["result"]["unsignedTx"];
});
}
/**
* Get the Subnet that validates a given blockchain.
*
* @param blockchainID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the blockchainID or its alias.
*
* @returns Promise for a string of the subnetID that validates the blockchain.
*/
validatedBy = async (blockchainID:string):Promise<string> => {
let params = {
"blockchainID": blockchainID
}
return this.callMethod("platform.validatedBy", params).then((response:RequestResponseData) => {
return response.data["result"]["subnetID"];
});
}
/**
* Get the IDs of the blockchains a Subnet validates.
*
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for an array of blockchainIDs the subnet validates.
*/
validates = async (subnetID:Buffer | string):Promise<Array<string>> => {
let params = {
"subnetID": subnetID
}
if(typeof subnetID === "string"){
params["subnetID"] = subnetID;
} else if (typeof subnetID !== "undefined") {
params["subnetID"] = bintools.avaSerialize(subnetID);
}
return this.callMethod("platform.validates", params).then((response:RequestResponseData) => {
return response.data["result"]["blockchainIDs"];
});
}
/**
* Get all the blockchains that exist (excluding the P-Chain).
*
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for an array of objects containing fields "id", "subnetID", and "vmID".
*/
getBlockchains = async ():Promise<Array<object>> => {
let params = {}
return this.callMethod("platform.getBlockchains", params).then((response:RequestResponseData) => {
return response.data["result"]["blockchains"];
});
}
/**
* Send AVA from an account on the P-Chain to an address on the X-Chain. This transaction must be signed with the key of the account that the AVA is sent from and which pays the transaction fee. After issuing this transaction, you must call the X-Chain’s importAVA method to complete the transfer.
*
* @param to The address on the X-Chain to send the AVA to. Do not include X- in the address
* @param amount Amount of AVA to export as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account paying the tx fee and providing the sent AVA
*
* @returns Promise for an unsigned transaction to be signed by the account the the AVA is sent from and pays the transaction fee.
*/
exportAVA = async (amount:BN, to:string,payerNonce:number):Promise<string> => {
let params = {
"to": to,
"amount": amount,
"payerNonce": payerNonce
}
return this.callMethod("platform.exportAVA", params).then((response:RequestResponseData) => {
return response.data["result"]["unsignedTx"];
});
}
/**
* Send AVA from an account on the P-Chain to an address on the X-Chain. This transaction must be signed with the key of the account that the AVA is sent from and which pays the transaction fee. After issuing this transaction, you must call the X-Chain’s importAVA method to complete the transfer.
*
* @param username The Keystore user that controls the account specified in `to`
* @param password The password of the Keystore user
* @param to The ID of the account the AVA is sent to. This must be the same as the to argument in the corresponding call to the X-Chain’s exportAVA
* @param payerNonce The next unused nonce of the account specified in `to`
*
* @returns Promise for a string for the transaction, which should be sent to the network by calling issueTx.
*/
importAVA = async (username: string, password:string, to:string, payerNonce:number):Promise<string> => {
let params = {
"to": to,
"payerNonce": payerNonce,
"username": username,
"password": password
}
return this.callMethod("platform.importAVA", params).then((response:RequestResponseData) => {
return response.data["result"]["tx"];
});
}
/**
* Sign an unsigned or partially signed transaction.
*
* Transactions to add non-default Subnets require signatures from control keys and from the account paying the transaction fee. If `signer` is a control key and the transaction needs more signatures from control keys, `sign` will provide a control signature. Otherwise, `signer` will sign to pay the transaction fee.
*
* @param username The Keystore user that controls the key signing `tx`
* @param password The password of the Keystore user
* @param tx The unsigned/partially signed transaction
* @param signer The address of the key signing `tx`
*
* @returns Promise for an string of the transaction after being signed.
*/
sign = async (username: string, password:string, tx:string, signer:string):Promise<string> => {
let params = {
"tx": tx,
"signer": signer,
"username": username,
"password": password
}
return this.callMethod("platform.sign", params).then((response:RequestResponseData) => {
return response.data["result"]["tx"];
});
}
/**
* Issue a transaction to the Platform Chain.
*
* @param tx The base 58 (with checksum) representation of a transaction
*
* @returns Promise for an string of the transaction after being signed.
*/
issueTx = async (tx:string):Promise<string> => {
let params = {
"tx": tx
}
return this.callMethod("platform.issueTx", params).then((response:RequestResponseData) => {
return response.data["result"]["txID"];
});
}
/**
* This class should not be instantiated directly. Instead use the [[Slopes.addAPI]] method.
*
* @param core A reference to the Slopes class
* @param baseurl Defaults to the string "/ext/platform" as the path to blockchain's baseurl
* @param baseurl Defaults to the string "/ext/P" as the path to blockchain's baseurl
*/

@@ -213,0 +438,0 @@ constructor(core:SlopesCore, baseurl:string = "/ext/P"){ super(core, baseurl); }

@@ -188,2 +188,47 @@ import mockAxios from 'jest-mock-axios';

test("exportAVA", async ()=>{
let amount = new BN(100);
let to = "abcdef";
let username = "Robert";
let password = "Paulson";
let txID = "valid";
let result:Promise<string> = api.exportAVA(username, password, to, amount);
let payload:object = {
"result": {
"txID": txID
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(txID);
});
test("importAVA", async ()=>{
let to = "abcdef";
let username = "Robert";
let password = "Paulson";
let txID = "valid";
let result:Promise<string> = api.importAVA(username, password, to);
let payload:object = {
"result": {
"txID": txID
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(txID);
});
test('createAddress', async ()=>{

@@ -190,0 +235,0 @@ let alias = 'randomalias';

@@ -34,21 +34,2 @@ import mockAxios from 'jest-mock-axios';

test("addStaker", async ()=>{
let result:Promise<boolean> = platform.addStaker('txId');
let payload:object = {
"result": {
"success": true
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:boolean = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(true);
});
test("createBlockchain 1", async ()=>{

@@ -428,3 +409,3 @@ let blockchainID:string = "7sik3Pr6r1FeLrvK1oWwECBS8iJ5VPuSh";

test("sampleValidators 1", async ()=>{
test("sampleValidators 3", async ()=>{
let subnetID = Buffer.from("abcdef", "hex");

@@ -448,2 +429,342 @@ let validators = ['val1', 'val2'];

});
test("addDefaultSubnetValidator 1", async ()=>{
let id = "abcdef";
let startTime = new Date(1985,5,9,12,59,43,9);
let endTime = new Date(1982,3,1,12,58,33,7);
let stakeAmount = new BN(13);
let payerNonce = 3;
let destination = "fedcba";
let delegationFeeRate = new BN(2);
let utx = "valid";
let result:Promise<string> = platform.addDefaultSubnetValidator(id, startTime, endTime, stakeAmount, payerNonce, destination, delegationFeeRate);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("addNonDefaultSubnetValidator 1", async ()=>{
let id = "abcdef";
let subnetID;
let startTime = new Date(1985,5,9,12,59,43,9);
let endTime = new Date(1982,3,1,12,58,33,7);
let weight = 13;
let payerNonce = 3;
let utx = "valid";
let result:Promise<string> = platform.addNonDefaultSubnetValidator(id, subnetID, startTime, endTime, weight, payerNonce);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("addNonDefaultSubnetValidator 2", async ()=>{
let id = "abcdef";
let subnetID = "abcdef";
let startTime = new Date(1985,5,9,12,59,43,9);
let endTime = new Date(1982,3,1,12,58,33,7);
let weight = 13;
let payerNonce = 3;
let utx = "valid";
let result:Promise<string> = platform.addNonDefaultSubnetValidator(id, subnetID, startTime, endTime, weight, payerNonce);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("addNonDefaultSubnetValidator 3", async ()=>{
let id = "abcdef";
let subnetID = Buffer.from("abcdef", "hex");
let startTime = new Date(1985,5,9,12,59,43,9);
let endTime = new Date(1982,3,1,12,58,33,7);
let weight = 13;
let payerNonce = 3;
let utx = "valid";
let result:Promise<string> = platform.addNonDefaultSubnetValidator(id, subnetID, startTime, endTime, weight, payerNonce);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("addDefaultSubnetDelegator 1", async ()=>{
let id = "abcdef";
let startTime = new Date(1985,5,9,12,59,43,9);
let endTime = new Date(1982,3,1,12,58,33,7);
let stakeAmount = new BN(13);
let payerNonce = 3;
let destination = "fedcba";
let utx = "valid";
let result:Promise<string> = platform.addDefaultSubnetDelegator(id, startTime, endTime, stakeAmount, payerNonce, destination);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("createSubnet 1", async ()=>{
let controlKeys = ["abcdef"];
let threshold = 13;
let payerNonce = 3;
let utx = "valid";
let result:Promise<string> = platform.createSubnet(controlKeys, threshold, payerNonce);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("validatedBy 1", async ()=>{
let blockchainID = "abcdef";
let resp = "valid";
let result:Promise<string> = platform.validatedBy(blockchainID);
let payload:object = {
"result": {
"subnetID": resp
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(resp);
});
test("validates 1", async ()=>{
let subnetID;
let resp = ["valid"];
let result:Promise<Array<string>> = platform.validates(subnetID);
let payload:object = {
"result": {
"blockchainIDs": resp
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:Array<string> = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(resp);
});
test("validates 2", async ()=>{
let subnetID = "deadbeef";
let resp = ["valid"];
let result:Promise<Array<string>> = platform.validates(subnetID);
let payload:object = {
"result": {
"blockchainIDs": resp
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:Array<string> = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(resp);
});
test("validates 3", async ()=>{
let subnetID = Buffer.from("abcdef", "hex");
let resp = ["valid"];
let result:Promise<Array<string>> = platform.validates(subnetID);
let payload:object = {
"result": {
"blockchainIDs": resp
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:Array<string> = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(resp);
});
test("getBlockchains 1", async ()=>{
let resp = [{
"id": "nodeID",
"subnetID": "subnetID",
"vmID": "vmID"
}];
let result:Promise<Array<object>> = platform.getBlockchains();
let payload:object = {
"result": {
"blockchains": resp
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:Array<object> = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(resp);
});
test("exportAVA 1", async ()=>{
let amount = new BN(100);
let to = "abcdef";
let payerNonce = 3;
let utx = "valid";
let result:Promise<string> = platform.exportAVA(amount, to, payerNonce);
let payload:object = {
"result": {
"unsignedTx": utx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(utx);
});
test("importAVA 1", async ()=>{
let to = "abcdef";
let payerNonce = 3;
let username = "Robert";
let password = "Paulson";
let tx = "valid";
let result:Promise<string> = platform.importAVA(username, password, to, payerNonce);
let payload:object = {
"result": {
"tx": tx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(tx);
});
test("sign 1", async ()=>{
let utx = "abcdef";
let signer = "fedcba";
let username = "Robert";
let password = "Paulson";
let tx = "valid";
let result:Promise<string> = platform.sign(username, password, utx, signer);
let payload:object = {
"result": {
"tx": tx
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(tx);
});
test("issueTx 1", async ()=>{
let tx = "abcdef";
let txID = "valid";
let result:Promise<string> = platform.issueTx(tx);
let payload:object = {
"result": {
"txID": txID
}
};
let responseObj = {
data: payload
};
mockAxios.mockResponse(responseObj);
let response:string = await result;
expect(mockAxios.request).toHaveBeenCalledTimes(1);
expect(response).toBe(txID);
});
});

@@ -77,2 +77,10 @@ /**

/**
* Refresh blockchainID, and if a blockchainID is passed in, use that.
*
* @param Optional. BlockchainID to assign, if none, uses the default based on networkID.
*
* @returns The blockchainID
*/
refreshBlockchainID: (blockchainID?: string) => boolean;
/**
* Takes an address string and returns its {@link https://github.com/feross/buffer|Buffer} representation if valid.

@@ -219,2 +227,27 @@ *

/**
* Send AVA from the X-Chain to an account on the P-Chain.
*
* After calling this method, you must call the P-Chain’s importAVA method to complete the transfer.
*
* @param username The Keystore user that controls the P-Chain account specified in `to`
* @param password The password of the Keystore user
* @param to The acount on the P-Chain to send the AVA to. Do not include P- in the address
* @param amount Amount of AVA to export as a {@link https://github.com/indutny/bn.js/|BN}
*
* @returns Promise for an unsigned transaction to be signed by the account the the AVA is sent from and pays the transaction fee.
*/
exportAVA: (username: string, password: string, to: string, amount: BN) => Promise<string>;
/**
* Finalize a transfer of AVA from the P-Chain to the X-Chain.
*
* Before this method is called, you must call the P-Chain’s `exportAVA` method to initiate the transfer.
*
* @param to The address the AVA is sent to. This must be the same as the to argument in the corresponding call to the P-Chain’s exportAVA, except that the prepended X- should be included in this argument
* @param username The Keystore user that controls the address specified in `to`
* @param password The password of the Keystore user
*
* @returns Promise for a string for the transaction, which should be sent to the network by calling issueTx.
*/
importAVA: (username: string, password: string, to: string) => Promise<string>;
/**
* Lists all the addresses under a user.

@@ -221,0 +254,0 @@ *

@@ -7,2 +7,3 @@ /**

import { Buffer } from "buffer/";
import BN from "bn.js";
/**

@@ -17,10 +18,2 @@ * Class for interacting with a node's PlatformAPI

/**
* Add a staked validator to the validator set.
*
* @param tx The string representation of an AddStakerTx
*
* @returns Promise for a boolean value, true on success.
*/
addStaker: (tx: string) => Promise<boolean>;
/**
* Creates a new blockchain.

@@ -100,6 +93,123 @@ *

/**
* Add a validator to the Default Subnet.
*
* @param id The node ID of the validator
* @param startTime Javascript Date object for the start time to validate
* @param endTime Javascript Date object for the end time to validate
* @param stakeAmount The amount of nAVA the validator is staking as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account that is providing the staked AVA and paying the transaction fee
* @param destination The P-Chain address of the account that the staked AVA will be returned to, as well as a validation reward if the validator is sufficiently responsive and correct while it validated
* @param delegationFeeRate Optional. The percent fee this validator charges when others delegate stake to them, multiplied by 10,000 as a {@link https://github.com/indutny/bn.js/|BN}. For example, suppose a validator has delegationFeeRate 300,000 and someone delegates to that validator. When the delegation period is over, if the delegator is entitled to a reward, 30% of the reward (300,000 / 10,000) goes to the validator and 70% goes to the delegator
* @param subnetID Optional. Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for a base58 string of the unsigned transaction.
*/
addDefaultSubnetValidator: (id: string, startTime: Date, endTime: Date, stakeAmount: BN, payerNonce: number, destination: string, delegationFeeRate?: BN) => Promise<string>;
/**
* Add a validator to a Subnet other than the Default Subnet. The validator must validate the Default Subnet for the entire duration they validate this Subnet.
*
* @param id The node ID of the validator
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
* @param startTime Javascript Date object for the start time to validate
* @param endTime Javascript Date object for the end time to validate
* @param weight The validator’s weight used for sampling
* @param payerNonce The next unused nonce of the account that is providing the staked AVA and paying the transaction fee
*
* @returns Promise for the unsigned transaction. It must be signed (using sign) by the proper number of the Subnet’s control keys and by the key of the account paying the transaction fee before it can be issued.
*/
addNonDefaultSubnetValidator: (id: string, subnetID: string | Buffer, startTime: Date, endTime: Date, weight: number, payerNonce: number) => Promise<string>;
/**
* Add a delegator to the Default Subnet.
*
* @param id The node ID of the delegatee
* @param startTime Javascript Date object for when the delegator starts delegating
* @param endTime Javascript Date object for when the delegator starts delegating
* @param stakeAmount The amount of nAVA the delegator is staking as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account that will provide the staked AVA and pay the transaction fee
* @param destination The address of the account the staked AVA and validation reward (if applicable) are sent to at endTime
*
* @returns Promise for an array of validator's stakingIDs.
*/
addDefaultSubnetDelegator: (id: string, startTime: Date, endTime: Date, stakeAmount: BN, payerNonce: number, destination: string) => Promise<string>;
/**
* Create an unsigned transaction to create a new Subnet. The unsigned transaction must be signed with the key of the account paying the transaction fee. The Subnet’s ID is the ID of the transaction that creates it (ie the response from issueTx when issuing the signed transaction).
*
* @param controlKeys Array of platform addresses as strings
* @param threshold To add a validator to this Subnet, a transaction must have threshold signatures, where each signature is from a key whose address is an element of `controlKeys`
* @param payerNonce The next unused nonce of the account providing the transaction fee
*
* @returns Promise for a string with the unsigned transaction encoded as base58.
*/
createSubnet: (controlKeys: string[], threshold: number, payerNonce: number) => Promise<string>;
/**
* Get the Subnet that validates a given blockchain.
*
* @param blockchainID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the blockchainID or its alias.
*
* @returns Promise for a string of the subnetID that validates the blockchain.
*/
validatedBy: (blockchainID: string) => Promise<string>;
/**
* Get the IDs of the blockchains a Subnet validates.
*
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for an array of blockchainIDs the subnet validates.
*/
validates: (subnetID: string | Buffer) => Promise<string[]>;
/**
* Get all the blockchains that exist (excluding the P-Chain).
*
* @param subnetID Either a {@link https://github.com/feross/buffer|Buffer} or an AVA serialized string for the SubnetID or its alias.
*
* @returns Promise for an array of objects containing fields "id", "subnetID", and "vmID".
*/
getBlockchains: () => Promise<object[]>;
/**
* Send AVA from an account on the P-Chain to an address on the X-Chain. This transaction must be signed with the key of the account that the AVA is sent from and which pays the transaction fee. After issuing this transaction, you must call the X-Chain’s importAVA method to complete the transfer.
*
* @param to The address on the X-Chain to send the AVA to. Do not include X- in the address
* @param amount Amount of AVA to export as a {@link https://github.com/indutny/bn.js/|BN}
* @param payerNonce The next unused nonce of the account paying the tx fee and providing the sent AVA
*
* @returns Promise for an unsigned transaction to be signed by the account the the AVA is sent from and pays the transaction fee.
*/
exportAVA: (amount: BN, to: string, payerNonce: number) => Promise<string>;
/**
* Send AVA from an account on the P-Chain to an address on the X-Chain. This transaction must be signed with the key of the account that the AVA is sent from and which pays the transaction fee. After issuing this transaction, you must call the X-Chain’s importAVA method to complete the transfer.
*
* @param username The Keystore user that controls the account specified in `to`
* @param password The password of the Keystore user
* @param to The ID of the account the AVA is sent to. This must be the same as the to argument in the corresponding call to the X-Chain’s exportAVA
* @param payerNonce The next unused nonce of the account specified in `to`
*
* @returns Promise for a string for the transaction, which should be sent to the network by calling issueTx.
*/
importAVA: (username: string, password: string, to: string, payerNonce: number) => Promise<string>;
/**
* Sign an unsigned or partially signed transaction.
*
* Transactions to add non-default Subnets require signatures from control keys and from the account paying the transaction fee. If `signer` is a control key and the transaction needs more signatures from control keys, `sign` will provide a control signature. Otherwise, `signer` will sign to pay the transaction fee.
*
* @param username The Keystore user that controls the key signing `tx`
* @param password The password of the Keystore user
* @param tx The unsigned/partially signed transaction
* @param signer The address of the key signing `tx`
*
* @returns Promise for an string of the transaction after being signed.
*/
sign: (username: string, password: string, tx: string, signer: string) => Promise<string>;
/**
* Issue a transaction to the Platform Chain.
*
* @param tx The base 58 (with checksum) representation of a transaction
*
* @returns Promise for an string of the transaction after being signed.
*/
issueTx: (tx: string) => Promise<string>;
/**
* This class should not be instantiated directly. Instead use the [[Slopes.addAPI]] method.
*
* @param core A reference to the Slopes class
* @param baseurl Defaults to the string "/ext/platform" as the path to blockchain's baseurl
* @param baseurl Defaults to the string "/ext/P" as the path to blockchain's baseurl
*/

@@ -106,0 +216,0 @@ constructor(core: SlopesCore, baseurl?: string);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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