//! SPDX-License-Identifier: GPL-3.0-or-later
import { allocate, byteLength, bytesToHex, copy, fill, isBytes, normalize } from './primordials'
-import { clearMemory, constants, getOutput, Mutex, setInput, derive as wasm_derive, } from './wasm'
+import { Mutex, constants, getOutput, setInput, derive as wasm_derive, } from './wasm'
const { KEY_BYTELENGTH, } = constants
} finally {
fill(privateKey, 0)
fill(publicKey, 0)
- clearMemory()
+ Mutex.unlock()
}
}
//! SPDX-License-Identifier: GPL-3.0-or-later
import { allocate, byteLength, bytesToHex, copy, fill, isBytes, normalize } from './primordials'
-import { Mutex, clearMemory, constants, getOutput, setInput, sign as wasm_sign } from './wasm'
+import { Mutex, constants, getOutput, setInput, sign as wasm_sign, } from './wasm'
const { KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, SIGNATURE_BYTELENGTH, } = constants
fill(privateKey, 0)
fill(publicKey, 0)
fill(signature, 0)
- clearMemory()
+ Mutex.unlock()
}
}
//! SPDX-License-Identifier: GPL-3.0-or-later
import { allocate, byteLength, copy, isArray, normalize } from './primordials'
-import { Mutex, clearMemory, constants, getOutput, setInput, verify as wasm_verify, verify_blocks as wasm_verify_blocks, } from './wasm'
+import { Mutex, constants, getOutput, setInput, verify as wasm_verify, verify_blocks as wasm_verify_blocks, } from './wasm'
const { BLOCKHASH_BYTELENGTH, KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, MAX_VERIFY_BLOCKS, SIGNATURE_BYTELENGTH, } = constants
const verified = getOutput('verify', 0)
return verified === 1
} finally {
- clearMemory()
+ Mutex.unlock()
}
}
}
return verified
} finally {
- clearMemory()
+ Mutex.unlock()
}
}
let locked = false
export const Mutex = {
+ /**
+ * Sets a module-scoped variable to prevent reentry into the WASM module. This
+ * method *must* be called at the start of every `nano25519` API function.
+ */
lock (): void {
if (locked) throw new Nano25519TypeError('Failed to acquire mutex')
locked = true
+ },
+ /**
+ * Tells the WASM module to clear its own I/O buffers internally, and then
+ * releases the mutex lock.
+ */
+ unlock (): void {
+ exports.clearMemory()
+ locked = false
}
}
setInputSigEndian(s)
}
-/**
- * Tells the WASM module to clear its own I/O buffers internally, and then
- * releases the mutex lock.
- */
-export function clearMemory (): void {
- exports.clearMemory()
- locked = false
-}
-
export const constants = {
BLOCKHASH_BYTELENGTH,
KEY_BYTELENGTH,