Skip to content

Commit ff58d55

Browse files
committed
Secp256k1 signature noramlization
1 parent 836f428 commit ff58d55

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ members = ["contracts", "contracts/wallet", "server"]
77
# client-sdk = { default-features = false, package = "hyle-client-sdk", version = "0.13.0-rc.4" }
88
# hyle = { version = "0.13.0-rc.4" }
99

10-
sdk = { path = "../hyle/crates/contract-sdk", package = "hyle-contract-sdk" }
11-
client-sdk = { path = "../hyle/crates/client-sdk", default-features = false, package = "hyle-client-sdk" }
12-
hyle-hyllar = { path = "../hyle/crates/contracts/hyllar", package = "hyle-hyllar" }
13-
hyle-modules = { path = "../hyle/crates/hyle-modules", package = "hyle-modules" }
10+
sdk = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-contract-sdk", branch = "secp256k1blob" }
11+
client-sdk = { git = "https://github.com/Hyle-org/hyle.git", default-features = false, package = "hyle-client-sdk", branch = "secp256k1blob" }
12+
hyle-hyllar = { git = "https://github.com/Hyle-org/hyle", package = "hyle-hyllar", branch = "secp256k1blob" }
13+
hyle-modules = { git = "https://github.com/Hyle-org/hyle.git", package = "hyle-modules", branch = "secp256k1blob" }
1414

1515
contracts = { path = "contracts", default-features = false, package = "contracts" }
1616
wallet = { path = "contracts/wallet", package = "wallet" }

front/src/services/SessionKeyService.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ class SessionKeyService {
4646
const keyPair = this.ec.keyFromPrivate(privateKey);
4747
const signature = keyPair.sign(hash.toString());
4848

49-
50-
const r = signature.r.toArray('be', 32);
51-
const s = signature.s.toArray('be', 32);
52-
const signatureBytes = new Uint8Array([...r, ...s]);
49+
// Normaliser s en utilisant min(s, n-s)
50+
const n = this.ec.curve.n;
51+
var s = signature.s;
52+
if (s.gt(n.shrn(1))) {
53+
signature.s = n.sub(s);
54+
}
55+
56+
const signatureBytes = new Uint8Array([...signature.r.toArray('be', 32), ...signature.s.toArray('be', 32)]);
5357

5458
const signatureHex = signature.toDER('hex');
5559
console.log("message:", hash.toString());

0 commit comments

Comments
 (0)