@concordium/node-sdk
Advanced tools
Comparing version
import { ChannelCredentials, Metadata } from '@grpc/grpc-js'; | ||
import { P2PClient } from '../grpc/concordium_p2p_rpc_grpc_pb'; | ||
import { AccountAddress as Address } from './types/accountAddress'; | ||
import { AccountInfo, AccountTransaction, AccountTransactionSignature, BlockInfo, BlockSummary, ConsensusStatus, NextAccountNonce, TransactionStatus } from './types'; | ||
import { PeerListResponse } from '../grpc/concordium_p2p_rpc_pb'; | ||
import { AccountInfo, AccountTransaction, AccountTransactionSignature, ArInfo, BlockInfo, BlockSummary, ConsensusStatus, CryptographicParameters, IpInfo, NextAccountNonce, TransactionStatus, Versioned } from './types'; | ||
/** | ||
@@ -89,3 +90,28 @@ * A concordium-node specific gRPC client wrapper. | ||
getConsensusStatus(): Promise<ConsensusStatus>; | ||
/** | ||
* Retrieves the global cryptographic parameters on the blockchain at | ||
* the provided block. | ||
* @param blockHash the block to get the cryptographic parameters at | ||
* @returns the global cryptographic parameters at the given block, or undefined it the block does not exist. | ||
*/ | ||
getCryptographicParameters(blockHash: string): Promise<Versioned<CryptographicParameters> | undefined>; | ||
/** | ||
* Retrieves a list of the node's peers and connection information related to them. | ||
* @param includeBootstrappers whether or not any bootstrapper nodes should be included in the list | ||
* @returns a list of the node's peers and connection information related to them | ||
*/ | ||
getPeerList(includeBootstrappers: boolean): Promise<PeerListResponse>; | ||
/** | ||
* Retrieves the list of identity providers at the provided blockhash. | ||
* @param blockHash the block to get the identity providers at | ||
* @returns the list of identity providers at the given block | ||
*/ | ||
getIdentityProviders(blockHash: string): Promise<IpInfo[] | undefined>; | ||
/** | ||
* Retrieves the list of anonymity revokers at the provided blockhash. | ||
* @param blockHash the block to get the anonymity revokers at | ||
* @returns the list of anonymity revokers at the given block | ||
*/ | ||
getAnonymityRevokers(blockHash: string): Promise<ArInfo[] | undefined>; | ||
sendRequest<T>(command: any, input: T): Promise<Uint8Array>; | ||
} |
@@ -77,2 +77,6 @@ "use strict"; | ||
'amount', | ||
'stakedAmount', | ||
'bakerId', | ||
'newStake', | ||
'epoch', | ||
]; | ||
@@ -205,2 +209,3 @@ return util_1.unwrapJsonResponse(response, util_1.buildJsonResponseReviver(datePropertyKeys, bigIntPropertyKeys), util_1.intToStringTransformer(bigIntPropertyKeys)); | ||
'genesisTime', | ||
'currentEraGenesisTime', | ||
'lastFinalizedTime', | ||
@@ -216,2 +221,3 @@ ]; | ||
'blocksReceivedCount', | ||
'protocolVersion', | ||
]; | ||
@@ -224,2 +230,50 @@ const consensusStatus = util_1.unwrapJsonResponse(response, util_1.buildJsonResponseReviver(datePropertyKeys, bigIntPropertyKeys), util_1.intToStringTransformer(bigIntPropertyKeys)); | ||
} | ||
/** | ||
* Retrieves the global cryptographic parameters on the blockchain at | ||
* the provided block. | ||
* @param blockHash the block to get the cryptographic parameters at | ||
* @returns the global cryptographic parameters at the given block, or undefined it the block does not exist. | ||
*/ | ||
async getCryptographicParameters(blockHash) { | ||
if (!util_1.isValidHash(blockHash)) { | ||
throw new Error('The input was not a valid hash: ' + blockHash); | ||
} | ||
const blockHashObject = new concordium_p2p_rpc_pb_1.BlockHash(); | ||
blockHashObject.setBlockHash(blockHash); | ||
const response = await this.sendRequest(this.client.getCryptographicParameters, blockHashObject); | ||
return util_1.unwrapJsonResponse(response); | ||
} | ||
/** | ||
* Retrieves a list of the node's peers and connection information related to them. | ||
* @param includeBootstrappers whether or not any bootstrapper nodes should be included in the list | ||
* @returns a list of the node's peers and connection information related to them | ||
*/ | ||
async getPeerList(includeBootstrappers) { | ||
const peersRequest = new concordium_p2p_rpc_pb_1.PeersRequest(); | ||
peersRequest.setIncludeBootstrappers(includeBootstrappers); | ||
const response = await this.sendRequest(this.client.peerList, peersRequest); | ||
return concordium_p2p_rpc_pb_1.PeerListResponse.deserializeBinary(response); | ||
} | ||
/** | ||
* Retrieves the list of identity providers at the provided blockhash. | ||
* @param blockHash the block to get the identity providers at | ||
* @returns the list of identity providers at the given block | ||
*/ | ||
async getIdentityProviders(blockHash) { | ||
const blockHashObject = new concordium_p2p_rpc_pb_1.BlockHash(); | ||
blockHashObject.setBlockHash(blockHash); | ||
const response = await this.sendRequest(this.client.getIdentityProviders, blockHashObject); | ||
return util_1.unwrapJsonResponse(response); | ||
} | ||
/** | ||
* Retrieves the list of anonymity revokers at the provided blockhash. | ||
* @param blockHash the block to get the anonymity revokers at | ||
* @returns the list of anonymity revokers at the given block | ||
*/ | ||
async getAnonymityRevokers(blockHash) { | ||
const blockHashObject = new concordium_p2p_rpc_pb_1.BlockHash(); | ||
blockHashObject.setBlockHash(blockHash); | ||
const response = await this.sendRequest(this.client.getAnonymityRevokers, blockHashObject); | ||
return util_1.unwrapJsonResponse(response); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types | ||
@@ -226,0 +280,0 @@ sendRequest(command, input) { |
@@ -21,3 +21,2 @@ import { Buffer } from 'buffer/'; | ||
* @param signatures the signatures that will also be part of the hash | ||
* @param sha256 the sha256 hashing function | ||
* @returns the sha256 hash of the serialized block item kind, signatures, header, type and payload | ||
@@ -28,7 +27,3 @@ */ | ||
* Returns the digest of the transaction that has to be signed. | ||
* The hashing function is provided to keep the implementation clean of | ||
* node specific imports, so that it can be used from a renderer | ||
* thread in Electron. | ||
* @param accountTransaction the transaction to hash | ||
* @param sha256 the sha256 hashing function | ||
* @param signatureCount number of expected signatures | ||
@@ -35,0 +30,0 @@ * @returns the sha256 hash on the serialized header, type and payload |
@@ -85,3 +85,2 @@ "use strict"; | ||
* @param signatures the signatures that will also be part of the hash | ||
* @param sha256 the sha256 hashing function | ||
* @returns the sha256 hash of the serialized block item kind, signatures, header, type and payload | ||
@@ -96,7 +95,3 @@ */ | ||
* Returns the digest of the transaction that has to be signed. | ||
* The hashing function is provided to keep the implementation clean of | ||
* node specific imports, so that it can be used from a renderer | ||
* thread in Electron. | ||
* @param accountTransaction the transaction to hash | ||
* @param sha256 the sha256 hashing function | ||
* @param signatureCount number of expected signatures | ||
@@ -103,0 +98,0 @@ * @returns the sha256 hash on the serialized header, type and payload |
@@ -299,2 +299,3 @@ import { AccountAddress } from './types/accountAddress'; | ||
genesisBlock: string; | ||
currentEraGenesisBlock: string; | ||
lastFinalizedBlock: string; | ||
@@ -321,6 +322,14 @@ epochDuration: bigint; | ||
genesisTime: Date; | ||
currentEraGenesisTime: Date; | ||
blockLastReceivedTime?: Date; | ||
blockLastArrivedTime?: Date; | ||
lastFinalizedTime?: Date; | ||
genesisIndex: number; | ||
protocolVersion: bigint; | ||
} | ||
export interface CryptographicParameters { | ||
onChainCommitmentKey: string; | ||
bulletproofGenerators: string; | ||
genesisString: string; | ||
} | ||
export interface NextAccountNonce { | ||
@@ -392,2 +401,21 @@ nonce: bigint; | ||
} | ||
export interface BakerReduceStakePendingChange { | ||
change: 'ReduceStake'; | ||
newStake: bigint; | ||
epoch: bigint; | ||
} | ||
export interface BakerRemovalPendingChange { | ||
change: 'RemoveBaker'; | ||
epoch: bigint; | ||
} | ||
export declare type BakerPendingChange = BakerReduceStakePendingChange | BakerRemovalPendingChange; | ||
export interface AccountBakerDetails { | ||
restakeEarnings: boolean; | ||
bakerId: bigint; | ||
bakerAggregationVerifyKey: string; | ||
bakerElectionVerifyKey: string; | ||
bakerSignatureVerifyKey: string; | ||
stakedAmount: bigint; | ||
pendingChange?: BakerPendingChange; | ||
} | ||
export interface AccountInfo { | ||
@@ -402,3 +430,20 @@ accountNonce: bigint; | ||
accountCredentials: Record<number, Versioned<InitialAccountCredential | NormalAccountCredential>>; | ||
accountBaker?: AccountBakerDetails; | ||
} | ||
export interface Description { | ||
name: string; | ||
url: string; | ||
description: string; | ||
} | ||
export interface IpInfo { | ||
ipIdentity: number; | ||
ipDescription: Description; | ||
ipVerifyKey: string; | ||
ipCdiVerifyKey: string; | ||
} | ||
export interface ArInfo { | ||
arIdentity: number; | ||
arDescription: Description; | ||
arPublicKey: string; | ||
} | ||
export declare enum BlockItemKind { | ||
@@ -405,0 +450,0 @@ AccountTransactionKind = 0, |
{ | ||
"name": "@concordium/node-sdk", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Helpers for interacting with the Concordium node", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -84,3 +84,3 @@ # concordium-node-sdk-js | ||
const signingKey = "ce432f6bba0d47caec1f45739331dc354b6d749fdb8ab7c2b7f6cb24db39ca0c"; | ||
const hashToSign = getAccountTransactionSignDigest(accountTransaction, sha256); | ||
const hashToSign = getAccountTransactionSignDigest(accountTransaction); | ||
const signature = Buffer.from(await ed.sign(hashToSign, signingKey)).toString("hex"); | ||
@@ -109,3 +109,3 @@ | ||
// as it will take some time for the transaction to be processed. | ||
const transactionHash = getAccountTransactionHash(accountTransaction, signatures, sha256); | ||
const transactionHash = getAccountTransactionHash(accountTransaction, signatures); | ||
const transactionStatus = await client.getTransactionStatus(transactionHash); | ||
@@ -121,3 +121,3 @@ ``` | ||
```js | ||
const accountAddress = "3sAHwfehRNEnXk28W7A3XB3GzyBiuQkXLNRmDwDGPUe8JsoAcU"; | ||
const accountAddress = new AccountAddress("3sAHwfehRNEnXk28W7A3XB3GzyBiuQkXLNRmDwDGPUe8JsoAcU"); | ||
const blockHash = "6b01f2043d5621192480f4223644ef659dd5cda1e54a78fc64ad642587c73def"; | ||
@@ -137,3 +137,3 @@ const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash); | ||
```js | ||
const accountAddress = "3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt"; | ||
const accountAddress = new AccountAddress("3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt"); | ||
const nextAccountNonce: NextAccountNonce = await client.getNextAccountNonce(accountAddress); | ||
@@ -214,2 +214,37 @@ const nonce: bigint = nextAccountNonce.nonce; | ||
## getCryptographicParameters | ||
Retrieves the global cryptographic parameters for the blockchain at a specific block. | ||
These are a required input for e.g. creating credentials. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8761d08554756f42bf268a42749" | ||
const cryptographicParameters = await client.getCryptographicParameters(blockHash); | ||
... | ||
``` | ||
## getIdentityProviders | ||
Retrieves the list of identity providers at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const identityProviders = await client.getIdentityProviders(blockHash); | ||
... | ||
``` | ||
## getAnonymityRevokers | ||
Retrieves the list of anonymity revokers at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const identityProviders = await client.getAnonymityRevokers(blockHash); | ||
... | ||
``` | ||
## getPeerList | ||
Retrieves the list of peers that the node is connected to, including some | ||
connection information about them. A boolean parameter determines if this | ||
should include bootstrapper nodes or not. | ||
```js | ||
const peerListResponse = await client.getPeerList(false); | ||
const peersList = peerListResponse.getPeersList(); | ||
... | ||
``` | ||
## Check block for transfers with memo | ||
@@ -216,0 +251,0 @@ The following example demonstrates how to check and parse a block |
390061
1.6%7797
1.5%299
13.26%