Skip to content

Commit

Permalink
Ensure public keys are constructed correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKishino committed May 28, 2020
1 parent 6150609 commit 17c7bd4
Show file tree
Hide file tree
Showing 8 changed files with 632 additions and 315 deletions.
2 changes: 1 addition & 1 deletion dist/node/index.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Sotez from "./sotez";
export { default as Key } from "./key";
export { default as crypto } from "./crypto";
export { default as forge } from "./forge";
export { default as utility } from "./utility";
export { default as ledger } from "./ledger";
export { default as constants } from "./constants";
import Sotez from './sotez';
export { default as Key } from './key';
export { default as crypto } from './crypto';
export { default as forge } from './forge';
export { default as utility } from './utility';
export { default as ledger } from './ledger';
export { default as constants } from './constants';
export default Sotez;
2 changes: 1 addition & 1 deletion dist/web/index.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions lib/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ export default class Key {
.toArray()[31] % 2
? 3
: 2;
this._publicKey = toBuffer(new Uint8Array([prefixVal].concat(keyPair
// Need to pad keypair array to maintain a length of 32
const pad = [0, 0];
this._publicKey = toBuffer(new Uint8Array([prefixVal].concat(pad
.concat(keyPair
.getPublic()
.getX()
.toArray())));
.toArray())
.slice(-32))));
}
else if (this._curve === 'p2') {
const keyPair = new elliptic.ec('p256').keyFromPrivate(constructedKey);
Expand All @@ -160,10 +164,14 @@ export default class Key {
.toArray()[31] % 2
? 3
: 2;
this._publicKey = toBuffer(new Uint8Array([prefixVal].concat(keyPair
// Need to pad keypair array to maintain a length of 32
const pad = [0, 0];
this._publicKey = toBuffer(new Uint8Array([prefixVal].concat(pad
.concat(keyPair
.getPublic()
.getX()
.toArray())));
.toArray())
.slice(-32))));
}
else {
throw new Error('Invalid key');
Expand Down
Loading

0 comments on commit 17c7bd4

Please sign in to comment.