11import { mod } from "@noble/curves/abstract/modular.js" ;
2- import { secp256k1 } from "@noble/curves/secp256k1.js" ;
32import { KEY_TYPE , TORUS_NETWORK_TYPE , TORUS_SAPPHIRE_NETWORK } from "@toruslabs/constants" ;
43import { decrypt } from "@toruslabs/eccrypto" ;
54import { Data , post } from "@toruslabs/http-helpers" ;
@@ -28,6 +27,7 @@ import {
2827 Curve ,
2928 derivePubKey ,
3029 encParamsHexToBuf ,
30+ getSecp256k1 ,
3131 hexToBytes ,
3232 keccak256Bytes ,
3333 numberToBytesBE ,
@@ -42,6 +42,7 @@ export const getSecpKeyFromEd25519 = (
4242 scalar : bigint ;
4343 point : Point2D ;
4444} => {
45+ const secp256k1 = getSecp256k1 ( ) ;
4546 const N = secp256k1 . Point . CURVE ( ) . n ;
4647
4748 const keyHash = keccakHash ( numberToBytesBE ( ed25519Scalar , 32 ) ) ;
@@ -93,6 +94,7 @@ export function generateMetadataParams(ecCurve: Curve, serverTimeOffset: number,
9394 data : message ,
9495 timestamp : ( ~ ~ ( serverTimeOffset + Date . now ( ) / 1000 ) ) . toString ( 16 ) ,
9596 } ;
97+ const secp256k1 = getSecp256k1 ( ) ;
9698 const msgHash = keccak256Bytes ( utf8ToBytes ( stringify ( setData ) ) ) ;
9799 // metadata only uses secp for sig validation; prehash: false because msgHash is already hashed
98100 const sig = secp256k1 . sign ( msgHash , numberToBytesBE ( privateKey , 32 ) , { prehash : false } ) ;
@@ -146,6 +148,7 @@ export function generateNonceMetadataParams(
146148 setData . seed = "" ; // setting it as empty to keep ordering same while serializing the data on backend.
147149 }
148150
151+ const secp256k1 = getSecp256k1 ( ) ;
149152 const msgHash = keccak256Bytes ( utf8ToBytes ( stringify ( setData ) ) ) ;
150153 const sig = secp256k1 . sign ( msgHash , numberToBytesBE ( privateKey , 32 ) , { prehash : false } ) ;
151154 const pubKey = derivePubKey ( secp256k1 , privateKey ) ;
@@ -257,6 +260,7 @@ export async function getOrSetSapphireMetadataNonce(
257260 operation : "getOrSetNonce" ,
258261 timestamp : ( ~ ~ ( serverTimeOffset + Date . now ( ) / 1000 ) ) . toString ( 16 ) ,
259262 } ;
263+ const secp256k1 = getSecp256k1 ( ) ;
260264 const msgHash = keccak256Bytes ( utf8ToBytes ( stringify ( setData ) ) ) ;
261265 const sig = secp256k1 . sign ( msgHash , numberToBytesBE ( privKey , 32 ) , { prehash : false } ) ;
262266 const pubKey = derivePubKey ( secp256k1 , privKey ) ;
0 commit comments