-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #935 from o1-labs/refactor/scalar
Move Scalar to JS
- Loading branch information
Showing
21 changed files
with
582 additions
and
361 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
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.