Skip to content

Commit

Permalink
tx-signing-js: js tests for GroupElement
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Aug 18, 2023
1 parent 5fac6e7 commit 58140c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ class GroupElement(val point: Ecp) extends js.Object {
/** Returns the point encoded as hex string (ASN.1 encoding).
* @see CryptoFacade.getASN1Encoding
*/
def toHex: String = {
def toHex(): String = {
CryptoFacade.getASN1Encoding(point, true).toHex
}
}

object GroupElement {
@JSExportTopLevel("GroupElementObj")
object GroupElement extends js.Object {
/** Creates a new [[GroupElement]] from the given hex string (ASN.1 encoding)
* representation of the underlying [[sigmastate.crypto.Platform.Point]].
*/
Expand Down
8 changes: 8 additions & 0 deletions sigma-js/sigmastate-js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ declare module "sigmastate-js/main" {
static fromHex(value: HexString): ErgoTree;
}

export declare class GroupElement {
toHex(): HexString;
}

export declare class GroupElementObj {
static fromHex(value: HexString): GroupElement;
}

export declare class Type {
name: string;
toString(): string;
Expand Down
10 changes: 10 additions & 0 deletions sigma-js/tests/js/GroupElement.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { GroupElementObj, ErgoTree} = require("sigmastate-js/main");

let pointAsn1Hex = "02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5";

describe("GroupElement", () => {
it("should implement toHex/fromHex", () => {
let ge = GroupElementObj.fromHex(pointAsn1Hex)
expect(ge.toHex()).toEqual(pointAsn1Hex)
});
});

0 comments on commit 58140c1

Please sign in to comment.