Skip to content
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

Fix inconsistent behavior when passing in user-provided private key #801

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@zk-kit/baby-jubjub": "1.0.1",
"@zk-kit/eddsa-poseidon": "1.0.1",
"@zk-kit/eddsa-poseidon": "1.0.2",
"@zk-kit/utils": "1.0.0",
"poseidon-lite": "0.2.0"
}
Expand Down
5 changes: 2 additions & 3 deletions packages/identity/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Point } from "@zk-kit/baby-jubjub"
import { EdDSAPoseidon, Signature, signMessage, verifySignature } from "@zk-kit/eddsa-poseidon"
import type { BigNumberish } from "@zk-kit/utils"
import { bigNumberishToBigInt, bigIntToHexadecimal, BigNumberish } from "@zk-kit/utils"
import { hexadecimalToBuffer } from "@zk-kit/utils/conversions"
import { requireString } from "@zk-kit/utils/error-handlers"
import { isHexadecimal } from "@zk-kit/utils/type-checks"
Expand Down Expand Up @@ -58,8 +58,7 @@ export class Identity {
}
} else {
eddsa = new EdDSAPoseidon()

this._privateKey = eddsa.privateKey as string
this._privateKey = bigIntToHexadecimal(bigNumberishToBigInt(eddsa.privateKey))
}

this._secretScalar = eddsa.secretScalar
Expand Down
11 changes: 11 additions & 0 deletions packages/identity/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ describe("Identity", () => {

expect(fun).toThrow("Parameter 'privateKey' is not a string, received type: number")
})

it("Should be able to recreate identity from randomly generated identity", () => {
const identity = new Identity()

const identity2 = new Identity(identity.privateKey)

expect(identity.privateKey).toBe(identity2.privateKey)
expect(identity.secretScalar).toBe(identity2.secretScalar)
expect(identity.commitment).toEqual(identity2.commitment)
expect(identity.publicKey).toEqual(identity2.publicKey)
})
})

describe("# signMessage", () => {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6394,7 +6394,7 @@ __metadata:
"@rollup/plugin-node-resolve": "npm:^15.2.3"
"@rollup/plugin-typescript": "npm:^11.1.6"
"@zk-kit/baby-jubjub": "npm:1.0.1"
"@zk-kit/eddsa-poseidon": "npm:1.0.1"
"@zk-kit/eddsa-poseidon": "npm:1.0.2"
"@zk-kit/utils": "npm:1.0.0"
poseidon-lite: "npm:0.2.0"
rimraf: "npm:^5.0.5"
Expand Down Expand Up @@ -8487,14 +8487,14 @@ __metadata:
languageName: node
linkType: hard

"@zk-kit/eddsa-poseidon@npm:1.0.1":
version: 1.0.1
resolution: "@zk-kit/eddsa-poseidon@npm:1.0.1"
"@zk-kit/eddsa-poseidon@npm:1.0.2":
version: 1.0.2
resolution: "@zk-kit/eddsa-poseidon@npm:1.0.2"
dependencies:
"@zk-kit/baby-jubjub": "npm:1.0.1"
"@zk-kit/utils": "npm:1.0.0"
buffer: "npm:6.0.3"
checksum: 10/337db4a73bd58680e462b6a82f95321406b3cffce7dce0413f7c857159798b8d85120750de5f5e4c7f2bcc102a02a5e3145302aeb9110a3b6172e6bd3bc29f43
checksum: 10/4b4e984a96c5dbc95a8cf36ceb8b3712e37291c1473d01b0e22c15a33311e9cf88c86175d878dacda1852cc905cd2074aaa76defeaed33490be3964ca7a53372
languageName: node
linkType: hard

Expand Down