File tree Expand file tree Collapse file tree 4 files changed +32
-5
lines changed
Expand file tree Collapse file tree 4 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -60,14 +60,15 @@ import {
6060 SignSessionError ,
6161 CreateSessionParams ,
6262 createSession ,
63- buildSessionAccount
63+ buildSessionAccount ,
64+ bytesToHexString
6465} from " @argent/x-sessions"
6566import { ec } from " starknet"
6667
6768const privateKey = ec .starkCurve .utils .randomPrivateKey ()
6869
6970const sessionKey: SessionKey = {
70- privateKey ,
71+ privateKey: bytesToHexString ( privateKey ) ,
7172 publicKey: ec .starkCurve .getStarkKey (privateKey )
7273}
7374
@@ -150,7 +151,7 @@ This package expose a method in order to get the Call required to perform an exe
150151const privateKey = ec .starkCurve .utils .randomPrivateKey ()
151152
152153const sessionKey: SessionKey = {
153- privateKey ,
154+ privateKey: bytesToHexString ( privateKey ) ,
154155 publicKey: ec .starkCurve .getStarkKey (privateKey )
155156}
156157
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ export const createOutsideExecutionCall = async ({
144144 const outsideExecutionTypedData = buildOutsideExecutionTypedData ( {
145145 outsideExecution,
146146 chainId : session . chainId ,
147- version : version || "1" ,
147+ version : version || "2" , // version, set as "2" because of a bug in x-sessions where default was wrongly set to "1"
148148 } )
149149
150150 const signature = await signOutsideExecution ( {
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ export type CreateSessionParams = {
6969
7070export type SessionKey = {
7171 publicKey : string
72- privateKey : Uint8Array
72+ privateKey : string
7373}
7474
7575export type BuildSessionAccountParams = {
Original file line number Diff line number Diff line change 33 Account ,
44 constants ,
55 ec ,
6+ encode ,
67 hash ,
78 shortString ,
89 Signature ,
@@ -238,6 +239,29 @@ const verifySession = ({
238239 )
239240}
240241
242+ /**
243+ * Converts a byte array to a hex string.
244+ * @param bytes The byte array to convert.
245+ * @returns The hex string.
246+ */
247+ const bytesToHexString = ( bytes : Uint8Array ) : string => {
248+ return encode . addHexPrefix ( encode . buf2hex ( bytes ) )
249+ }
250+
251+ /**
252+ * Converts a hex string to a byte array.
253+ * @param hexString The hex string to convert.
254+ * @returns The byte array.
255+ */
256+ const hexStringToBytes = ( hexString : string ) : Uint8Array => {
257+ const hex = encode . removeHexPrefix ( hexString )
258+ const hexArray = hex . match ( / .{ 1 , 2 } / g)
259+ if ( ! hexArray ) {
260+ throw new Error ( "Invalid hex string" )
261+ }
262+ return Uint8Array . from ( hexArray . map ( ( byte ) => parseInt ( byte , 16 ) ) )
263+ }
264+
241265export {
242266 buildSessionAccount ,
243267 createOffchainSession ,
@@ -247,4 +271,6 @@ export {
247271 getSessionTypedData ,
248272 sessionTypes ,
249273 verifySession ,
274+ bytesToHexString ,
275+ hexStringToBytes ,
250276}
You can’t perform that action at this time.
0 commit comments