Skip to content

Commit

Permalink
Merge pull request #165 from Concordium/bugfix/generateBakerKeys-miss…
Browse files Browse the repository at this point in the history
…ing-private-keys

Add private keys to generateBakerKeys output + bump versions
  • Loading branch information
shjortConcordium authored Apr 21, 2023
2 parents 6198402 + 3ed2da8 commit a52f1ad
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 19 deletions.
8 changes: 8 additions & 0 deletions packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

## 6.4.2 2023-04-21

### Changed

- `generateBakerKeys` now also returns the private baker keys.

## 6.4.1 2023-03-31

### Changed

- Replace use of `setImmediate` with `setTimeout` since the former is not
supported in browsers.

Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/common-sdk",
"version": "6.4.1",
"version": "6.4.2",
"license": "Apache-2.0",
"engines": {
"node": ">=14.16.0"
Expand Down Expand Up @@ -51,7 +51,7 @@
"build-dev": "tsc"
},
"dependencies": {
"@concordium/rust-bindings": "0.11.0",
"@concordium/rust-bindings": "0.11.1",
"@grpc/grpc-js": "^1.3.4",
"@noble/ed25519": "^1.7.1",
"@protobuf-ts/runtime-rpc": "^2.8.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/accountHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AccountInfoBakerV1,
AccountInfoDelegator,
StakePendingChangeV0,
BakerKeysWithProofs,
GenerateBakerKeysOutput,
} from './types';

export const isDelegatorAccount = (
Expand Down Expand Up @@ -50,11 +50,11 @@ export const isRemovalPendingChange = (
/**
* Generates random baker keys for the specified account, that can be used with the configureBaker transaction
* @param account the address of the account that the keys should be added to.
* @returns baker keys and their associated proofs
* @returns an object containing the public baker keys, their associated proofs and their associated private keys.
*/
export function generateBakerKeys(
account: AccountAddress
): BakerKeysWithProofs {
): GenerateBakerKeysOutput {
const rawKeys = wasm.generateBakerKeys(account.address);
try {
return JSON.parse(rawKeys);
Expand Down
17 changes: 16 additions & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,15 +1267,30 @@ export interface UpdateCredentialsPayload {
currentNumberOfCredentials: bigint;
}

export interface BakerKeysWithProofs {
export interface PublicBakerKeys {
signatureVerifyKey: HexString;
electionVerifyKey: HexString;
aggregationVerifyKey: HexString;
}

export interface PrivateBakerKeys {
aggregationSignKey: HexString;
signatureSignKey: HexString;
electionPrivateKey: HexString;
}

export interface BakerKeyProofs {
proofAggregation: HexString;
proofSig: HexString;
proofElection: HexString;
}

export type BakerKeysWithProofs = PublicBakerKeys & BakerKeyProofs;

export type GenerateBakerKeysOutput = PublicBakerKeys &
PrivateBakerKeys &
BakerKeyProofs;

export interface ConfigureBakerPayload {
/* stake to bake. if set to 0, this removes the account as a baker */
stake?: CcdAmount;
Expand Down
7 changes: 5 additions & 2 deletions packages/common/test/accountHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { AccountAddress } from '../src';
import { generateBakerKeys } from '../src/accountHelpers';

test('generate baker keys', async () => {
test('generate baker keys', () => {
const accountAddress = '3eP94feEdmhYiPC1333F9VoV31KGMswonuHk5tqmZrzf761zK5';
const keys = await generateBakerKeys(new AccountAddress(accountAddress));
const keys = generateBakerKeys(new AccountAddress(accountAddress));
expect(typeof keys.signatureVerifyKey).toBe('string');
expect(typeof keys.electionVerifyKey).toBe('string');
expect(typeof keys.aggregationVerifyKey).toBe('string');
expect(typeof keys.signatureSignKey).toBe('string');
expect(typeof keys.electionPrivateKey).toBe('string');
expect(typeof keys.aggregationSignKey).toBe('string');
expect(typeof keys.proofAggregation).toBe('string');
expect(typeof keys.proofSig).toBe('string');
expect(typeof keys.proofElection).toBe('string');
Expand Down
6 changes: 6 additions & 0 deletions packages/rust-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.11.1 2023-4-21

### Changes

- `generateBakerKeys` now also returns the private keys.

## 0.11.0 2023-3-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/rust-bindings/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/rust-bindings",
"version": "0.11.0",
"version": "0.11.1",
"license": "Apache-2.0",
"engines": {
"node": ">=14.16.0"
Expand Down
24 changes: 22 additions & 2 deletions packages/rust-bindings/src/aux_functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{helpers::*, types::*};
use anyhow::{anyhow, bail, ensure, Context, Result};
use concordium_base::{
base::BakerKeyPairs,
base::{BakerAggregationSignKey, BakerElectionSignKey, BakerKeyPairs, BakerSignatureSignKey},
common::{
types::{KeyIndex, KeyPair, TransactionTime},
*,
Expand Down Expand Up @@ -885,8 +885,28 @@ pub fn create_unsigned_credential_v1_aux(input: UnsignedCredentialInput) -> Resu
Ok(response.to_string())
}

#[derive(SerdeSerialize)]
#[serde(rename_all = "camelCase")]
pub struct BakerKeys {
#[serde(flatten)]
keys_payload: ConfigureBakerKeysPayload,
#[serde(serialize_with = "base16_encode", rename = "electionPrivateKey")]
election_private_key: BakerElectionSignKey,
#[serde(serialize_with = "base16_encode", rename = "signatureSignKey")]
signature_sign_key: BakerSignatureSignKey,
#[serde(serialize_with = "base16_encode", rename = "aggregationSignKey")]
aggregation_sign_key: BakerAggregationSignKey,
}

pub fn generate_baker_keys(sender: AccountAddress) -> Result<JsonString> {
let mut csprng = thread_rng();
let keys = BakerKeyPairs::generate(&mut csprng);
Ok(json!(ConfigureBakerKeysPayload::new(&keys, sender, &mut csprng)).to_string())
let keys_payload = ConfigureBakerKeysPayload::new(&keys, sender, &mut csprng);
let output = BakerKeys {
keys_payload,
election_private_key: keys.election_sign,
signature_sign_key: keys.signature_sign,
aggregation_sign_key: keys.aggregation_sign,
};
Ok(serde_json::to_string(&output)?)
}
6 changes: 6 additions & 0 deletions packages/web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.4.2 2023-4-21

### Changed

- Bumped @concordium/common-sdk to 6.4.2. (`generateBakerKeys` include private baker keys in output)

## 3.4.1 2023-3-31

### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/web-sdk",
"version": "3.4.1",
"version": "3.4.2",
"license": "Apache-2.0",
"browser": "lib/concordium.min.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -48,8 +48,8 @@
"webpack-cli": "^4.9.2"
},
"dependencies": {
"@concordium/common-sdk": "6.4.1",
"@concordium/rust-bindings": "0.11.0",
"@concordium/common-sdk": "6.4.2",
"@concordium/rust-bindings": "0.11.1",
"@grpc/grpc-js": "^1.3.4",
"@protobuf-ts/grpcweb-transport": "^2.8.2",
"buffer": "^6.0.3",
Expand Down
37 changes: 32 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1312,11 +1312,11 @@ __metadata:
languageName: node
linkType: hard

"@concordium/[email protected].1, @concordium/common-sdk@workspace:packages/common":
"@concordium/[email protected].2, @concordium/common-sdk@workspace:packages/common":
version: 0.0.0-use.local
resolution: "@concordium/common-sdk@workspace:packages/common"
dependencies:
"@concordium/rust-bindings": 0.11.0
"@concordium/rust-bindings": 0.11.1
"@grpc/grpc-js": ^1.3.4
"@noble/ed25519": ^1.7.1
"@protobuf-ts/plugin": 2.8.1
Expand Down Expand Up @@ -1370,6 +1370,26 @@ __metadata:
languageName: node
linkType: hard

"@concordium/common-sdk@npm:6.4.1":
version: 6.4.1
resolution: "@concordium/common-sdk@npm:6.4.1"
dependencies:
"@concordium/rust-bindings": 0.11.0
"@grpc/grpc-js": ^1.3.4
"@noble/ed25519": ^1.7.1
"@protobuf-ts/runtime-rpc": ^2.8.2
"@scure/bip39": ^1.1.0
bs58check: ^2.1.2
buffer: ^6.0.3
cross-fetch: 3.1.5
hash.js: ^1.1.7
iso-3166-1: ^2.1.1
json-bigint: ^1.0.0
uuid: ^8.3.2
checksum: 26cce68b496f9799359666d7ddf430c659c0250e16a96c8bfe1956162f737517896a9ab9e0c9a7a3a17117ee6d763a91cbcde20891c76d87444f67299a37c8c6
languageName: node
linkType: hard

"@concordium/[email protected], @concordium/node-sdk@workspace:packages/nodejs":
version: 0.0.0-use.local
resolution: "@concordium/node-sdk@workspace:packages/nodejs"
Expand Down Expand Up @@ -1403,18 +1423,25 @@ __metadata:
languageName: unknown
linkType: soft

"@concordium/[email protected].0, @concordium/rust-bindings@workspace:packages/rust-bindings":
"@concordium/[email protected].1, @concordium/rust-bindings@workspace:packages/rust-bindings":
version: 0.0.0-use.local
resolution: "@concordium/rust-bindings@workspace:packages/rust-bindings"
languageName: unknown
linkType: soft

"@concordium/rust-bindings@npm:0.11.0":
version: 0.11.0
resolution: "@concordium/rust-bindings@npm:0.11.0"
checksum: a6c437cb782b7b2e9f217215dd4dbed9ffb8b3ef46fa307952aca3ae8f166cb96687de64efd18490aec7e86d58712dccb7d1a8bf63c151e3ed2a0170f066cd6d
languageName: node
linkType: hard

"@concordium/web-sdk@workspace:packages/web":
version: 0.0.0-use.local
resolution: "@concordium/web-sdk@workspace:packages/web"
dependencies:
"@concordium/common-sdk": 6.4.1
"@concordium/rust-bindings": 0.11.0
"@concordium/common-sdk": 6.4.2
"@concordium/rust-bindings": 0.11.1
"@grpc/grpc-js": ^1.3.4
"@protobuf-ts/grpcweb-transport": ^2.8.2
"@typescript-eslint/eslint-plugin": ^4.28.1
Expand Down

0 comments on commit a52f1ad

Please sign in to comment.