@tgrospic/rnode-grpc-js
Version:
RNode gRPC helpers
71 lines (70 loc) • 2.53 kB
TypeScript
import { ec } from 'elliptic';
/**
* These deploy types are based on protobuf specification which must be
* used to create the hash and signature of deploy data.
*/
/**
* Deploy data (required for signing)
*/
export interface UnsignedDeployData {
readonly term: string;
readonly timestamp: number;
readonly phlolimit: number;
readonly phloprice: number;
readonly validafterblocknumber: number;
readonly shardid: string;
}
/**
* Signed DeployData object (protobuf specification)
* NOTE: Represents the same type as generated DeployData.
*/
export interface DeploySignedProto {
readonly term: string;
readonly timestamp: number;
readonly phlolimit: number;
readonly phloprice: number;
readonly validafterblocknumber: number;
readonly shardid: string;
readonly sigalgorithm: string;
readonly deployer: Uint8Array;
readonly sig: Uint8Array;
}
/**
* Signs deploy data.
*
* The private key for signing can be in different formats supported by
* [elliptic](https://github.com/indutny/elliptic#ecdsa) library.
*
* **NOTE: Signing function can be used independently without this library and JS generated code (see _rnode-sign.ts_ source).**
*
* ```typescript
* // Generate new key pair
* const { ec } = require('elliptic')
* const secp256k1 = new ec('secp256k1')
* const key = secp256k1.genKeyPair()
*
* // Or use existing private key as hex string, Uint8Array, Buffer or ec.KeyPair
* const key = '1bf36a3d89c27ddef7955684b97667c75454317d8964528e57b2308947b250b0'
*
* const deployData = {
* term: 'new out(`rho:io:stdout`) in { out!("Browser deploy test") }',
* timestamp: Date.now(), // nonce
* phloprice: 1, // price of tinny REV for phlogiston (gas)
* phlolimit: 10e3, // max phlogiston (gas) for deploy execution
* validafterblocknumber: 123, // latest block number
* shardid: 'testnet', // shard name
* }
*
* // Signed deploy with deployer, sig and sigalgorithm fields populated
* const signed = signDeploy(key, deployData)
* ```
*/
export declare const signDeploy: (privateKey: ec.KeyPair | string, deployObj: UnsignedDeployData) => DeploySignedProto;
/**
* Verifies deploy for a valid signature.
*/
export declare const verifyDeploy: (deployObj: DeploySignedProto) => boolean;
/**
* Serialization of DeployDataProto object without generated JS code.
*/
export declare const deployDataProtobufSerialize: (deployData: UnsignedDeployData) => Uint8Array;