import { Signer , number , stark } from "starknet" ; const nonceStore = { } ; export async function getNonce ( signer ) { const { result } = await signer . callContract ( { contract_address : signer . address , entry_point_selector : stark . getSelectorFromName ( "get_nonce" ) , } ) ; const nonceBn = number . toBN ( result [ 0 ] ) ; const storedNonce = nonceStore [ signer . address ] ; if ( ! storedNonce || ! nonceBn . eq ( number . toBN ( storedNonce ) ) ) { nonceStore [ signer . address ] = number . toHex ( nonceBn ) ; } if ( storedNonce && nonceBn . lt ( number . toBN ( storedNonce ) ) ) { return number . toHex ( number . toBN ( storedNonce ) ) ; } return number . toHex ( nonceBn ) ; } export function increaseStoredNonce ( address ) { const currentNonce = nonceStore [ address ] ; if ( currentNonce ) { nonceStore [ address ] = number . toHex ( number . toBN ( currentNonce ) . add ( number . toBN ( 1 ) ) ) ; } } export function resetStoredNonce ( address ) { delete nonceStore [ address ] ; }