-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tx-signing-js: implemented fromPointHex for js.SigmaProp
- Loading branch information
1 parent
58140c1
commit 9917c2b
Showing
6 changed files
with
68 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package org.ergoplatform.sdk.js | ||
|
||
import sigmastate.Values.SigmaBoolean | ||
import sigmastate.basics.DLogProtocol.ProveDlog | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.annotation.JSExportTopLevel | ||
|
||
/** Equivalent of [[special.sigma.SigmaProp]] available from JS. */ | ||
@JSExportTopLevel("SigmaProp") | ||
class SigmaProp(val sigmaBoolean: SigmaBoolean) extends js.Object | ||
class SigmaProp(val sigmaBoolean: SigmaBoolean) extends js.Object { | ||
} | ||
|
||
@JSExportTopLevel("SigmaPropObj") | ||
object SigmaProp extends js.Object { | ||
/** Creates a new [[SigmaProp]] from the given hex string of public key. | ||
* @param pointHex hex representation of elliptic curve point (ASN.1 encoded) | ||
* @see CryptoFacade.getASN1Encoding, GroupElement.fromPointHex, Point | ||
*/ | ||
def fromPointHex(pointHex: String): SigmaProp = { | ||
val point = GroupElement.fromPointHex(pointHex).point | ||
new SigmaProp(ProveDlog(point)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
const { GroupElementObj, ErgoTree} = require("sigmastate-js/main"); | ||
const { GroupElementObj, ValueObj } = require("sigmastate-js/main"); | ||
|
||
let pointAsn1Hex = "02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"; | ||
|
||
describe("GroupElement", () => { | ||
it("should implement toHex/fromHex", () => { | ||
let ge = GroupElementObj.fromHex(pointAsn1Hex) | ||
expect(ge.toHex()).toEqual(pointAsn1Hex) | ||
it("should implement toPointHex/fromPointHex", () => { | ||
let ge = GroupElementObj.fromPointHex(pointAsn1Hex) | ||
expect(ge.toPointHex()).toEqual(pointAsn1Hex) | ||
|
||
let v = ValueObj.ofGroupElement(pointAsn1Hex) | ||
expect(v.toHex()).toEqual("07"/* GroupElement type id */ + pointAsn1Hex) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { SigmaPropObj, ValueObj } = require("sigmastate-js/main"); | ||
|
||
let pointAsn1Hex = "02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5"; | ||
|
||
describe("SigmaProp", () => { | ||
it("should implement fromPointHex", () => { | ||
let ge = SigmaPropObj.fromPointHex(pointAsn1Hex) | ||
expect(ge).not.toBeUndefined() | ||
|
||
let v = ValueObj.ofSigmaProp(pointAsn1Hex) | ||
expect(v.toHex()) | ||
.toEqual("08"/* SigmaProp type id */ + "cd"/* ProveDlog.opCode */ + pointAsn1Hex) | ||
}); | ||
}); |