Skip to content

Commit c1206b4

Browse files
authored
Merge branch 'master' into feature/utils
2 parents 7e4a8b2 + c18ceba commit c1206b4

File tree

6 files changed

+12
-20
lines changed

6 files changed

+12
-20
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let { Zilliqa } = require('zilliqa-js');
4949

5050
//For local testing, use URL = 'http://localhost:4201'
5151
//To connect to the external network, use URL = 'https://api-scilla.zilliqa.com'
52-
URL = 'https://api-scilla.zilliqa.com
52+
let URL = 'https://api-scilla.zilliqa.com'
5353
let zilliqa = new Zilliqa({
5454
nodeUrl: URL
5555
});

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zilliqa-js",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"license": "SEE LICENSE in LICENSE",
55
"description": "zilliqa js library",
66
"repository": "https://github.com/Zilliqa/Zilliqa-Javascript-Library",

Diff for: src/__tests__/util.spec.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@ describe('utils', () => {
3333
});
3434

3535
it('should be able to recover an address from a private key', () => {
36-
const pk = util.generatePrivateKey();
37-
const publicKey = secp256k1
38-
.keyFromPrivate(pk, 'hex')
39-
.getPublic(false, 'hex');
40-
const hash = hashjs
41-
.sha256()
42-
.update(publicKey)
43-
.digest('hex');
44-
const expected = hash.slice(0, 40);
45-
const actual = util.getAddressFromPrivateKey(pk);
36+
const [pair] = pairs;
37+
const expected = util.getAddressFromPublicKey(
38+
util.compressPublicKey(pair.public),
39+
);
40+
const actual = util.getAddressFromPrivateKey(pair.private);
4641

4742
expect(actual).toHaveLength(40);
48-
expect(actual).toEqual(hash.slice(0, 40));
4943
expect(actual).toEqual(expected);
5044
});
5145

@@ -59,7 +53,6 @@ describe('utils', () => {
5953
version: 8,
6054
nonce: 8,
6155
to: pairs[0].digest.slice(0, 40),
62-
from: pairs[1].digest.slice(0, 40),
6356
pubKey: publicKey,
6457
amount: new BN('888', 10),
6558
gasPrice: 8,
@@ -91,7 +84,6 @@ describe('utils', () => {
9184
version: 8,
9285
nonce: 8,
9386
to: pairs[0].digest.slice(0, 40),
94-
from: pairs[1].digest.slice(0, 40),
9587
pubKey: publicKey,
9688
amount: new BN('888', 10),
9789
gasPrice: 8,
@@ -114,12 +106,10 @@ describe('utils', () => {
114106
it('should match the C++ implementation', () => {
115107
schnorrVectors.forEach(({priv, k, r, s}, idx) => {
116108
const pub = secp256k1.keyFromPrivate(priv, 'hex').getPublic(false, 'hex');
117-
const fromIdx = idx === schnorrVectors.length - 1 ? idx - 2 : idx + 1;
118109

119110
const tx = {
120111
version: 8,
121112
nonce: 8,
122-
from: util.getAddressFromPrivateKey(schnorrVectors[fromIdx].priv),
123113
to: util.getAddressFromPublicKey(pub),
124114
pubKey: pub,
125115
amount: new BN('888', 10),

Diff for: src/node.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export default class ZNode {
7373
rpcAjax(
7474
this.url,
7575
'CreateTransaction',
76-
{...args, amount: args.amount.toString(10)},
76+
// FIXME: core must be able to parse amount as string; it currently does
77+
// not. the issue is being tracked here: https://github.com/Zilliqa/Zilliqa/issues/524
78+
{...args, amount: args.amount.toNumber()},
7779
cb,
7880
);
7981
};

Diff for: src/schnorr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const hash = (q: BN, pubkey: Buffer, msg: Buffer) => {
5151
pubkey.copy(B, 33);
5252
msg.copy(B, 66);
5353

54-
return new BN(sha256.update(B).digest('hex'));
54+
return new BN(sha256.update(B).digest('hex'), 16);
5555
};
5656

5757
/**

Diff for: src/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const generatePrivateKey = (): string => {
5050
*/
5151
export const getAddressFromPrivateKey = (privateKey: string) => {
5252
const keyPair = secp256k1.keyFromPrivate(privateKey, 'hex');
53-
const pub = keyPair.getPublic(false, 'hex');
53+
const pub = keyPair.getPublic(true, 'hex');
5454

5555
return hashjs
5656
.sha256()

0 commit comments

Comments
 (0)