Skip to content

Commit

Permalink
Merge branch 'master' into patch-3
Browse files Browse the repository at this point in the history
  • Loading branch information
roadscape authored Sep 7, 2018
2 parents 7de808e + d971ee8 commit 45b6889
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/auth/ecc/src/key_public.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ class PublicKey {
}

static fromBuffer(buffer) {
if (
buffer.toString("hex") ===
"000000000000000000000000000000000000000000000000000000000000000000"
)
return new PublicKey(null);
return new PublicKey(ecurve.Point.decodeFrom(secp256k1, buffer));
}

toBuffer(compressed = this.Q.compressed) {
toBuffer(compressed = this.Q ? this.Q.compressed : null) {
if (this.Q === null)
return Buffer.from(
"000000000000000000000000000000000000000000000000000000000000000000",
"hex"
);
return this.Q.getEncoded(compressed);
}

Expand Down
15 changes: 14 additions & 1 deletion test/KeyFormats.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ var test = function(key) {
var address = Address.fromPublic(public_key, true, 56);
assert.equal(key.Compressed_PTS, address.toString());
});

it("null hex to pubkey", function() {
var public_key = PublicKey.fromHex(key.null_hex);
assert.equal(key.null_address, public_key.toPublicKeyString());
});

it("null pubkey to hex", function() {
var public_key = PublicKey.fromString(key.null_address);
assert.equal(key.null_hex, public_key.toHex());
});
});
};

Expand All @@ -87,6 +97,9 @@ test({
Uncompressed_BTC: "STMLAFmEtM8as1mbmjVcj5dphLdPguXquimn",
Compressed_BTC: "STMANNTSEaUviJgWLzJBersPmyFZBY4jJETY",
Uncompressed_PTS: "STMEgj7RM6FBwSoccGaESJLC3Mi18785bM3T",
Compressed_PTS: "STMD5rYtofD6D4UHJH6mo953P5wpBfMhdMEi"
Compressed_PTS: "STMD5rYtofD6D4UHJH6mo953P5wpBfMhdMEi",
// https://github.com/steemit/steem-js/issues/267
null_hex: "000000000000000000000000000000000000000000000000000000000000000000",
null_address: "STM1111111111111111111111111111111114T1Anm"
});

0 comments on commit 45b6889

Please sign in to comment.