Skip to content

Commit

Permalink
Merge pull request #15 from Cryptonomic/curveenum
Browse files Browse the repository at this point in the history
Curve handling improvements
  • Loading branch information
anonymoussprocket committed Jul 23, 2020
2 parents 2909180 + ef0786b commit 92e54d1
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TBD
<html>
<head>
<script src="https://cdn.jsdelivr.net/gh/cryptonomic/conseiljs-softsigner/dist-web/conseiljs-softsigner.min.js"
integrity="sha384-gmo96y8/A1pPfu7t/0LS4DjMG4Djzg8ouw5ke9DzwuXDf5mRY4sK6m9M5K/GSVJZ"
integrity="sha384-V1iaajn0x/SMFcZ9Y/xNQmqQSKyll6Dzt27U6OWiv8NdbHTVaHOGHdQ8g0G68HPd"
crossorigin="anonymous"></script>
<script>
//conseiljssoftsigner.
Expand Down
2 changes: 1 addition & 1 deletion dist-web/conseiljs-softsigner.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "conseiljs-softsigner",
"version": "5.0.2-beta.3",
"version": "5.0.3-beta.0",
"description": "ConseilJS software signer plugin for ConseilJS-core. Supports the ED25519 curve via libsodium for tz1-address operations.",
"browser": "dist/index.js",
"main": "dist/index.js",
Expand Down Expand Up @@ -64,7 +64,7 @@
},
"dependencies": {
"bip39": "3.0.2",
"conseiljs": "5.0.2-beta.3",
"conseiljs": "5.0.3-beta.2",
"generate-password": "1.5.1",
"libsodium-wrappers-sumo": "0.7.6"
},
Expand Down
6 changes: 3 additions & 3 deletions src/KeyStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export namespace KeyStoreUtils {
/**
*
*
* @param privateKey Secret key to restore public key and hash from.
* @param {string} secretKey Secret key to restore public key and hash from.
*/
export async function restoreIdentityFromSecretKey(secretKey: string): Promise<KeyStore> {
const secretKeyBytes = TezosMessageUtils.writeKeyWithHint(secretKey, 'edsk');
Expand Down Expand Up @@ -89,12 +89,12 @@ export namespace KeyStoreUtils {
*/
export async function generateKeys(seed: Buffer): Promise<{ publicKey: Buffer, secretKey: Buffer}> {
const keys = await CryptoUtils.generateKeys(seed);
return { publicKey: keys.publicKey, secretKey: keys.privateKey };
return { publicKey: keys.publicKey, secretKey: keys.secretKey };
}

export async function recoverKeys(secretKey: Buffer): Promise<{ publicKey: Buffer, secretKey: Buffer}> {
const keys = await CryptoUtils.recoverPublicKey(secretKey);
return { publicKey: keys.publicKey, secretKey: keys.privateKey };
return { publicKey: keys.publicKey, secretKey: keys.secretKey };
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/SoftSigner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as GeneratePassword from 'generate-password'
import { Signer, TezosMessageUtils } from 'conseiljs';
import { Signer, SignerCurve, TezosMessageUtils } from 'conseiljs';

import { CryptoUtils } from './utils/CryptoUtils'

Expand Down Expand Up @@ -35,6 +35,10 @@ export class SoftSigner implements Signer {
}
}

public getSignerCurve(): SignerCurve {
return SignerCurve.ED25519
}

public static async createSigner(secretKey: Buffer, validity: number = 60): Promise<Signer> {
if (validity >= 0) {
const passphrase = GeneratePassword.generate({ length: 32, numbers: true, symbols: true, lowercase: true, uppercase: true });
Expand Down
4 changes: 2 additions & 2 deletions src/utils/CryptoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export namespace CryptoUtils {
export async function generateKeys(seed: Buffer) {
const k = await wrapper.keys(seed);

return { privateKey: k.privateKey, publicKey: k.publicKey };
return { secretKey: k.privateKey, publicKey: k.publicKey };
}

/**
Expand All @@ -65,7 +65,7 @@ export namespace CryptoUtils {
export async function recoverPublicKey(secretKey: Buffer) {
const k = await wrapper.publicKey(secretKey);

return { privateKey: k.privateKey, publicKey: k.publicKey };
return { secretKey: k.privateKey, publicKey: k.publicKey };
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/CryptoUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,32 @@ describe('generateKeys() and recoverPublicKey()', () => {
});

it('recover public key from secret key', async () => {
const privateKey = TezosMessageUtils.writeKeyWithHint('edskRqLyhpmvk7PGg6zvbEV3n325UsLF2qKuNrDHit4zbJtqEpBE925Jdx13d7ax1uiewmg4FR2TVisnuDL6epbips9NMLtsMc', 'edsk');
const keys = await CryptoUtils.recoverPublicKey(privateKey);
const secretKey = TezosMessageUtils.writeKeyWithHint('edskRqLyhpmvk7PGg6zvbEV3n325UsLF2qKuNrDHit4zbJtqEpBE925Jdx13d7ax1uiewmg4FR2TVisnuDL6epbips9NMLtsMc', 'edsk');
const keys = await CryptoUtils.recoverPublicKey(secretKey);
const publicKeyHash = TezosMessageUtils.computeKeyHash(keys.publicKey, 'tz1');

expect(publicKeyHash).to.equal('tz1io3eJUT6C3heVaewJiDio18QzkNNHaE2v');
});

it('sign a message with secret key, verify signature with public key', async () => {
const privateKey = TezosMessageUtils.writeKeyWithHint('edskRqLyhpmvk7PGg6zvbEV3n325UsLF2qKuNrDHit4zbJtqEpBE925Jdx13d7ax1uiewmg4FR2TVisnuDL6epbips9NMLtsMc', 'edsk');
const keys = await CryptoUtils.recoverPublicKey(privateKey);
const secretKey = TezosMessageUtils.writeKeyWithHint('edskRqLyhpmvk7PGg6zvbEV3n325UsLF2qKuNrDHit4zbJtqEpBE925Jdx13d7ax1uiewmg4FR2TVisnuDL6epbips9NMLtsMc', 'edsk');
const keys = await CryptoUtils.recoverPublicKey(secretKey);
const publicKey = keys.publicKey;

const message = Buffer.from('Tacos Nachos Burritos Guacamole', 'utf8');
const messageSig = await CryptoUtils.signDetached(message, privateKey);
const messageSig = await CryptoUtils.signDetached(message, secretKey);
const check = await CryptoUtils.checkSignature(messageSig, message, publicKey);

expect(check).to.be.true;
});

it('sign a message with secret key, verify signature with public key (Tezos encoding)', async () => {
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskRqLyhpmvk7PGg6zvbEV3n325UsLF2qKuNrDHit4zbJtqEpBE925Jdx13d7ax1uiewmg4FR2TVisnuDL6epbips9NMLtsMc');
const privateKey = TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk');
const secretKey = TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk');
const publicKey = TezosMessageUtils.writeKeyWithHint(keyStore.publicKey, 'edpk');

const message = Buffer.from('Tacos Nachos Burritos Guacamole', 'utf8');
const messageSig = await CryptoUtils.signDetached(message, privateKey);
const messageSig = await CryptoUtils.signDetached(message, secretKey);
const check = await CryptoUtils.checkSignature(messageSig, message, publicKey);

expect(check).to.be.true;
Expand Down
14 changes: 9 additions & 5 deletions test/KeyStoreUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ describe('KeyStoreUtils tests', () => {
});

it('checkTextSignature, hashed', async () => {
const message = 'Tacos Burritos';
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH');
const sig = 'edsigtmoSkpMujSVYXH6zxSaZyiH27qYscBezFWNnDohoBoKdmY9c4Jk8EhdNGok9riQGLu1MTnXM9y5om2cRAUCdFtXKQKp57f';

const result = await KeyStoreUtils.checkTextSignature(sig, message, keyStore.publicKey, true);
let publicKey = (await KeyStoreUtils.restoreIdentityFromSecretKey('edskRgu8wHxjwayvnmpLDDijzD3VZDoAH7ZLqJWuG4zg7LbxmSWZWhtkSyM5Uby41rGfsBGk4iPKWHSDniFyCRv3j7YFCknyHH')).publicKey;
let message = 'Tacos Burritos';
let sig = 'edsigtmoSkpMujSVYXH6zxSaZyiH27qYscBezFWNnDohoBoKdmY9c4Jk8EhdNGok9riQGLu1MTnXM9y5om2cRAUCdFtXKQKp57f';
let result = await KeyStoreUtils.checkTextSignature(sig, message, publicKey, true);
expect(result).to.equal(true);

publicKey = 'edpku976gpuAD2bXyx1XGraeKuCo1gUZ3LAJcHM12W1ecxZwoiu22R';
message = 'test';
sig = 'edsigtzLBGCyadERX1QsYHKpwnxSxEYQeGLnJGsSkHEsyY8vB5GcNdnvzUZDdFevJK7YZQ2ujwVjvQZn62ahCEcy74AwtbA8HuN';
result = await KeyStoreUtils.checkTextSignature(sig, message, publicKey, true);
expect(result).to.equal(true);
});
});

0 comments on commit 92e54d1

Please sign in to comment.