import { Mutex, constants, getOutput, setInput, derive as wasm_derive, } from './wasm'
const { KEY_BYTELENGTH, } = constants
+let privateKey = allocate(KEY_BYTELENGTH)
+let publicKey = allocate(KEY_BYTELENGTH)
export function derive (prv: unknown, out?: unknown): string | void {
if (typeof out !== 'undefined' && !(isBytes(out) && byteLength(out) === KEY_BYTELENGTH)) {
throw new TypeError('Derive output buffer must be 32-byte Uint8Array<ArrayBuffer>')
}
- const privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv)
- const publicKey = allocate(KEY_BYTELENGTH)
Mutex.lock()
try {
+ privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv)
setInput('prv', privateKey)
wasm_derive()
for (let i = 0; i < KEY_BYTELENGTH; i++) {
import { Mutex, constants, getOutput, setInput, sign as wasm_sign, } from './wasm'
const { KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, SIGNATURE_BYTELENGTH, } = constants
+let privateKey = allocate(KEY_BYTELENGTH)
+let publicKey = allocate(KEY_BYTELENGTH)
+let signature = allocate(SIGNATURE_BYTELENGTH)
export function sign (msg: unknown, prv: unknown, pub: unknown, out?: unknown): string | void {
if (typeof out !== 'undefined' && !(isBytes(out) && byteLength(out) === SIGNATURE_BYTELENGTH)) {
throw new TypeError(`Sign output buffer must be ${SIGNATURE_BYTELENGTH}-byte Uint8Array<ArrayBuffer>`)
}
- const message = normalize('message', 0, MAX_MESSAGE_BYTELENGTH, msg)
- const privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv)
- const publicKey = normalize('public key', KEY_BYTELENGTH, KEY_BYTELENGTH, pub)
- const signature = allocate(SIGNATURE_BYTELENGTH)
Mutex.lock()
try {
+ const message = normalize('message', 0, MAX_MESSAGE_BYTELENGTH, msg)
+ privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv)
+ publicKey = normalize('public key', KEY_BYTELENGTH, KEY_BYTELENGTH, pub)
setInput('msg', message)
setInput('prv', privateKey)
setInput('pub', publicKey)