Skip to content

Commit 4f2a900

Browse files
fix biginttobytes
1 parent 619bf70 commit 4f2a900

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Point.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ed25519 } from "@noble/curves/ed25519.js";
22
import { secp256k1 } from "@noble/curves/secp256k1.js";
3-
import { concatBytes, hexToBytes } from "@noble/curves/utils.js";
3+
import { concatBytes, hexToBytes, numberToBytesBE } from "@noble/curves/utils.js";
44

5-
import { bigintToHex, toBigIntBE } from "./helpers/common";
5+
import { toBigIntBE } from "./helpers/common";
66
import { BigIntString, KeyType } from "./interfaces";
77

88
class Point {
@@ -21,7 +21,7 @@ class Point {
2121
encode(enc: string): Uint8Array {
2222
switch (enc) {
2323
case "arr":
24-
return concatBytes(hexToBytes("04"), hexToBytes(bigintToHex(this.x)), hexToBytes(bigintToHex(this.y)));
24+
return concatBytes(hexToBytes("04"), numberToBytesBE(this.x, 32), numberToBytesBE(this.y, 32));
2525
case "elliptic-compressed": {
2626
if (this.keyType === "secp256k1") {
2727
const point = secp256k1.Point.fromAffine({ x: this.x, y: this.y });

src/helpers/metadataUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function generateMetadataParams(ecCurve: Curve, serverTimeOffset: number,
9696
};
9797
const msgHash = keccak256Bytes(utf8ToBytes(stringify(setData)));
9898
// metadata only uses secp for sig validation; prehash: false because msgHash is already hashed
99-
const sig = secp256k1.sign(msgHash, hexToBytes(bigintToHex(privateKey)), { prehash: false });
99+
const sig = secp256k1.sign(msgHash, numberToBytesBE(privateKey, 32), { prehash: false });
100100
const pubKey = derivePubKey(ecCurve, privateKey);
101101
return {
102102
pub_key_X: pubKey.x.toString(16), // DO NOT PAD THIS. BACKEND DOESN'T
@@ -148,7 +148,7 @@ export function generateNonceMetadataParams(
148148
}
149149

150150
const msgHash = keccak256Bytes(utf8ToBytes(stringify(setData)));
151-
const sig = secp256k1.sign(msgHash, hexToBytes(bigintToHex(privateKey)), { prehash: false });
151+
const sig = secp256k1.sign(msgHash, numberToBytesBE(privateKey, 32), { prehash: false });
152152
const pubKey = derivePubKey(secp256k1, privateKey);
153153
return {
154154
pub_key_X: bigintToHex(pubKey.x),
@@ -259,7 +259,7 @@ export async function getOrSetSapphireMetadataNonce(
259259
timestamp: (~~(serverTimeOffset + Date.now() / 1000)).toString(16),
260260
};
261261
const msgHash = keccak256Bytes(utf8ToBytes(stringify(setData)));
262-
const sig = secp256k1.sign(msgHash, hexToBytes(bigintToHex(privKey)), { prehash: false });
262+
const sig = secp256k1.sign(msgHash, numberToBytesBE(privKey, 32), { prehash: false });
263263
const pubKey = derivePubKey(secp256k1, privKey);
264264
data = {
265265
...data,

0 commit comments

Comments
 (0)