Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kosu.js: implement a go-kosu JSONRPC client (the NodeClient) #229

Merged
merged 18 commits into from Aug 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

adding func to convert from public key to node ID

  • Loading branch information
hrharder committed Aug 22, 2019
commit 11b9cc0abae0f2a60bac632384f6b14c3fc113fb
@@ -1,5 +1,6 @@
import { WebsocketProvider, WebsocketProviderOptions } from "@0x/web3-providers-fork";
import uuid from "uuid/v4";
import { createHash } from "crypto";

export class NodeClient {
public static DEFAULT_OPTIONS: WebsocketProviderOptions = { timeout: 3000 };
@@ -8,6 +9,12 @@ export class NodeClient {
private readonly _heartbeatInterval: number;
private readonly _subscriptionIdMap: { [uuid: string]: string };

public static publicKeyToNodeId(publicKey: string): string {
const hash = createHash("SHA256");
const pub = Buffer.from(publicKey, "base64");
return hash.update(pub).digest().slice(0, 20).toString("hex");
}

private static _convertValidatorData(...rawValidators: any[]): Validator[] {
const validators = [];
for (const validator of rawValidators) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.