Skip to content

Commit

Permalink
Merge pull request #45 from bloxapp/hamlet-support
Browse files Browse the repository at this point in the history
Hamlet support
  • Loading branch information
guym-blox authored Jul 19, 2023
2 parents 852a92f + 2560dce commit 40266fa
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/esbuild/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssv-keys",
"version": "1.0.1",
"version": "1.0.2",
"description": "Tool for splitting a validator key into a predefined threshold of shares via Shamir-Secret-Sharing (SSS), and encrypt them with a set of operator keys.",
"author": "SSV.Network",
"repository": "https://github.com/bloxapp/ssv-keys",
Expand Down
46 changes: 30 additions & 16 deletions examples/server-worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dotenv from 'dotenv';
import { constants } from 'http2';
import bodyParser from 'body-parser';
import { SSVKeys, KeyShares } from 'ssv-keys';
import { SSVKeys, KeyShares, EncryptShare } from 'ssv-keys';
import express, { Express, Request, Response } from 'express';

dotenv.config();
Expand All @@ -12,25 +12,24 @@ const ssvKeys = new SSVKeys();

app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/key-shares/generate', async (req: Request, res: Response) => {
const operators_ids = String(req.body['operators_ids'] || '')
const operator_ids = String(req.body['operator_ids'] || '')
.split(',')
.map((id) => Number(id.trim()))
.filter(id => !!id);

if (!operators_ids.length) {
if (!operator_ids.length) {
return res
.status(constants.HTTP_STATUS_BAD_REQUEST)
.json({ message: 'Operator IDs required' });
}

const operators_keys = String(req.body['operators_keys'] || '')
const operator_keys = String(req.body['operator_keys'] || '')
.split(',')
.map((key) => key.trim())
.filter(key => !!key);

if (!operators_keys.length) {
if (!operator_keys.length) {
return res
.status(constants.HTTP_STATUS_BAD_REQUEST)
.json({ message: 'Operator keys required' });
Expand All @@ -39,11 +38,30 @@ app.post('/key-shares/generate', async (req: Request, res: Response) => {
const keystore = req.body['keystore'];

if (!keystore) {

return res
.status(constants.HTTP_STATUS_BAD_REQUEST)
.json({ message: 'Keystore is required' });
}

// The nonce of the owner within the SSV contract (increments after each validator registration), obtained using the ssv-scanner tool
const nonce = Number(req.body['nonce']);

if (isNaN(nonce)) {
return res
.status(constants.HTTP_STATUS_BAD_REQUEST)
.json({ message: 'Nonce is required' });
}

// The owner address for signing the share payload
const owner_address = String(req.body['owner_address']);

if (!owner_address) {
return res
.status(constants.HTTP_STATUS_BAD_REQUEST)
.json({ message: 'owner_address is required' });
}

const password = String(req.body['password'] || '');

if (!password.length) {
Expand All @@ -54,8 +72,8 @@ app.post('/key-shares/generate', async (req: Request, res: Response) => {

const { publicKey, privateKey } = await ssvKeys.extractKeys(keystore, password);

const operators = operators_keys.map((operatorKey, index) => ({
id: operators_ids[index],
const operators = operator_keys.map((operatorKey, index) => ({
id: operator_ids[index],
operatorKey,
}));

Expand All @@ -65,22 +83,18 @@ app.post('/key-shares/generate', async (req: Request, res: Response) => {
const keyShares = new KeyShares();
keyShares.update({ operators, publicKey });

// The nonce of the owner within the SSV contract (increments after each validator registration), obtained using the ssv-scanner tool
const TEST_OWNER_NONCE = 1;
// The cluster owner address
const TEST_OWNER_ADDRESS = '0x81592c3de184a3e2c0dcb5a261bc107bfa91f494';

await keyShares.buildPayload({
publicKey,
operators,
encryptedShares,
}, {
ownerAddress: TEST_OWNER_ADDRESS,
ownerNonce: TEST_OWNER_NONCE,
},{
ownerAddress: owner_address,
ownerNonce: nonce,
privateKey
});

console.log(`Built key shares for operators: ${String(operators_ids)} and public key: ${keystore.pubkey}`);
console.log(`Built key shares for operators: ${String(operator_ids)} and public key: ${keystore.pubkey}`);
res.json(JSON.parse(keyShares.toJson()));
});

Expand Down
4 changes: 2 additions & 2 deletions examples/server-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssv-keys-server-worker",
"version": "1.0.0",
"version": "1.0.2",
"description": "Example of expressjs server worker accepting data to build key shares and responding with keyshares json",
"main": "./dist/index.js",
"scripts": {
Expand All @@ -18,7 +18,7 @@
"@types/body-parser": "^1.19.2",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.14",
"ssv-keys": "https://github.com/bloxapp/ssv-keys.git#v3"
"ssv-keys": "1.0.1"
},
"devDependencies": {
"body-parser": "^1.20.1",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssv-keys",
"version": "1.0.1",
"version": "1.0.2",
"description": "Tool for splitting a validator key into a predefined threshold of shares via Shamir-Secret-Sharing (SSS), and encrypt them with a set of operator keys.",
"author": "SSV.Network",
"repository": "https://github.com/bloxapp/ssv-keys",
Expand Down

0 comments on commit 40266fa

Please sign in to comment.