@@ -93,13 +93,14 @@ export function generateMetadataParams(ecCurve: Curve, serverTimeOffset: number,
9393 timestamp : ( ~ ~ ( serverTimeOffset + Date . now ( ) / 1000 ) ) . toString ( 16 ) ,
9494 } ;
9595 const msgHash = hexToBytes ( keccak256 ( utf8ToBytes ( stringify ( setData ) ) ) . slice ( 2 ) ) ;
96- const sig = ecCurve . sign ( msgHash , hexToBytes ( bigintToHex ( privateKey ) ) ) ;
96+ // metadata only uses secp for sig validation; prehash: false because msgHash is already hashed
97+ const sig = secp256k1 . sign ( msgHash , hexToBytes ( bigintToHex ( privateKey ) ) , { prehash : false } ) ;
9798 const pubKey = ecCurve . Point . BASE . multiply ( privateKey ) . toAffine ( ) ;
9899 return {
99100 pub_key_X : pubKey . x . toString ( 16 ) , // DO NOT PAD THIS. BACKEND DOESN'T
100101 pub_key_Y : pubKey . y . toString ( 16 ) , // DO NOT PAD THIS. BACKEND DOESN'T
101102 set_data : setData ,
102- signature : bytesToBase64 ( concatBytes ( hexToBytes ( "00" ) , sig ) ) ,
103+ signature : bytesToBase64 ( concatBytes ( sig , hexToBytes ( "00" ) ) ) ,
103104 } ;
104105}
105106
@@ -145,14 +146,14 @@ export function generateNonceMetadataParams(
145146 }
146147
147148 const msgHash = hexToBytes ( keccak256 ( utf8ToBytes ( stringify ( setData ) ) ) . slice ( 2 ) ) ;
148- const sig = secp256k1 . sign ( msgHash , hexToBytes ( bigintToHex ( privateKey ) ) ) ;
149+ const sig = secp256k1 . sign ( msgHash , hexToBytes ( bigintToHex ( privateKey ) ) , { prehash : false } ) ;
149150 const pubKey = secp256k1 . Point . BASE . multiply ( privateKey ) . toAffine ( ) ;
150151 return {
151152 pub_key_X : bigintToHex ( pubKey . x ) ,
152153 pub_key_Y : bigintToHex ( pubKey . y ) ,
153154 set_data : setData ,
154155 key_type : keyType ,
155- signature : bytesToBase64 ( concatBytes ( hexToBytes ( "00" ) , sig ) ) ,
156+ signature : bytesToBase64 ( concatBytes ( sig , hexToBytes ( "00" ) ) ) ,
156157 } ;
157158}
158159
@@ -256,14 +257,14 @@ export async function getOrSetSapphireMetadataNonce(
256257 timestamp : ( ~ ~ ( serverTimeOffset + Date . now ( ) / 1000 ) ) . toString ( 16 ) ,
257258 } ;
258259 const msgHash = hexToBytes ( keccak256 ( utf8ToBytes ( stringify ( setData ) ) ) . slice ( 2 ) ) ;
259- const sig = secp256k1 . sign ( msgHash , hexToBytes ( bigintToHex ( privKey ) ) ) ;
260+ const sig = secp256k1 . sign ( msgHash , hexToBytes ( bigintToHex ( privKey ) ) , { prehash : false } ) ;
260261 const pubKey = secp256k1 . Point . BASE . multiply ( privKey ) . toAffine ( ) ;
261262 data = {
262263 ...data ,
263264 pub_key_X : bigintToHex ( pubKey . x ) ,
264265 pub_key_Y : bigintToHex ( pubKey . y ) ,
265266 set_data : setData ,
266- signature : bytesToBase64 ( concatBytes ( hexToBytes ( "00" ) , sig ) ) ,
267+ signature : bytesToBase64 ( concatBytes ( sig , hexToBytes ( "00" ) ) ) ,
267268 } ;
268269 }
269270
0 commit comments