-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Scalar to JS #935
Merged
Merged
Move Scalar to JS #935
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0a0f4d9
scalar constructor
mitschabaude b3511e5
to fields compressed
mitschabaude b305920
constant scalar ops
mitschabaude f18dac4
provable scalar
mitschabaude 925714c
from bits
mitschabaude 7bc1fbe
fix api example
mitschabaude 9c13a04
Merge branch 'main' into refactor/scalar
mitschabaude 66b12fd
remaining methods
mitschabaude c4c3b20
move back to ml-equivalent repr for Group.scale compatibility
mitschabaude a9edabd
fixup scalar representation
mitschabaude cb497c8
bindings
mitschabaude 80b090b
export new scalar everywhere
mitschabaude effad74
update tests
mitschabaude 90b7f7e
remove new test
mitschabaude a286394
remove old scalar
mitschabaude 0d3c3e8
remove old scalar class
mitschabaude 156621c
move private key conversions & base58 to js
mitschabaude 9171ece
add test for consistency with ml function that's no longer used
mitschabaude c7a6c67
move private key conversion to a saner place
mitschabaude 60fbb5c
bindings
mitschabaude 5baafe4
remove sign fee payer and its deps
mitschabaude 18962c7
doccomments
mitschabaude 6f6a693
changelog
mitschabaude 74c8f7d
bindings
mitschabaude b5c5767
remove comment
mitschabaude ea68d95
Merge branch 'refactor/scalar' into refactor/cleanup
mitschabaude 981bcd0
adapt group / scalar interaction
mitschabaude 755f76a
Merge branch 'main' into refactor/scalar
mitschabaude aa4f06e
bindings
mitschabaude a5bcb22
warning for private key from bigint
mitschabaude File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Submodule bindings
updated
from 33a69b to dcf4ee
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 |
---|---|---|
|
@@ -25,7 +25,6 @@ export { | |
SmartContract, | ||
method, | ||
DeployArgs, | ||
signFeePayer, | ||
declareMethods, | ||
Account, | ||
VerificationKey, | ||
|
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
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
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,24 @@ | ||
import { Test } from '../../snarky.js'; | ||
import { Random, test } from '../testing/property.js'; | ||
import { PrivateKey } from '../signature.js'; | ||
import { Ml } from './conversion.js'; | ||
import { expect } from 'expect'; | ||
|
||
// PrivateKey.toBase58, fromBase58 | ||
|
||
test(Random.privateKey, (s) => { | ||
// private key to/from bigint | ||
let sk = PrivateKey.fromBigInt(s); | ||
expect(sk.toBigInt()).toEqual(s); | ||
|
||
let skMl = Ml.fromPrivateKey(sk); | ||
|
||
// toBase58 - check consistency with ml | ||
let ml = Test.encoding.privateKeyToBase58(skMl); | ||
let js = sk.toBase58(); | ||
expect(js).toEqual(ml); | ||
|
||
// fromBase58 - check consistency with where we started | ||
expect(PrivateKey.fromBase58(js)).toEqual(sk); | ||
expect(Test.encoding.privateKeyOfBase58(ml)).toEqual(skMl); | ||
}); |
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,29 @@ | ||
/** | ||
* this file contains conversion functions between JS and OCaml | ||
*/ | ||
|
||
import { Scalar, ScalarConst } from '../scalar.js'; | ||
import { PrivateKey } from '../signature.js'; | ||
|
||
export { Ml }; | ||
|
||
const Ml = { | ||
fromScalar, | ||
toScalar, | ||
fromPrivateKey, | ||
toPrivateKey, | ||
}; | ||
|
||
function fromScalar(s: Scalar) { | ||
return s.toConstant().constantValue; | ||
} | ||
function toScalar(s: ScalarConst) { | ||
return Scalar.from(s); | ||
} | ||
|
||
function fromPrivateKey(sk: PrivateKey) { | ||
return fromScalar(sk.s); | ||
} | ||
function toPrivateKey(sk: ScalarConst) { | ||
return new PrivateKey(Scalar.from(sk)); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add the function constructor for the
Scalar
as well? I am a bit unsure - while it would be uniform,Scalar
is also not really a primitive likeField
orBool
, especially since you cant prove operations like addition 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I think the need is not pressing and requires refactoring the current constructor, so would save it for a future PR