From 58140c1203cbfa17d7ac4579a2fe46c0df330a9d Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Fri, 18 Aug 2023 15:53:30 +0200 Subject: [PATCH] tx-signing-js: js tests for GroupElement --- .../scala/org/ergoplatform/sdk/js/GroupElement.scala | 5 +++-- sigma-js/sigmastate-js.d.ts | 8 ++++++++ sigma-js/tests/js/GroupElement.spec.js | 10 ++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 sigma-js/tests/js/GroupElement.spec.js diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala index b318200cdc..3e09608ba9 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala @@ -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]]. */ diff --git a/sigma-js/sigmastate-js.d.ts b/sigma-js/sigmastate-js.d.ts index 04bc1c7f49..0ee5e572db 100644 --- a/sigma-js/sigmastate-js.d.ts +++ b/sigma-js/sigmastate-js.d.ts @@ -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; diff --git a/sigma-js/tests/js/GroupElement.spec.js b/sigma-js/tests/js/GroupElement.spec.js new file mode 100644 index 0000000000..c80cdbaa24 --- /dev/null +++ b/sigma-js/tests/js/GroupElement.spec.js @@ -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) + }); +}); \ No newline at end of file