import { Account } from './account'
import { Block } from './block'
import { MAX_SUPPLY, UNITS } from './constants'
-import { bytes, hex } from './convert'
+import { bytes, hex, utf8 } from './convert'
import { Blake2b } from './crypto'
import { Rpc } from './rpc'
import { Wallet } from './wallet'
}
export class Tools {
- static #encoder: TextEncoder = new TextEncoder()
static #normalize (input: string | ArrayBuffer | Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> {
return (typeof input === 'string')
? hex.toBytes(input)
static sign (secretKey: string | ArrayBuffer | Uint8Array<ArrayBuffer>, ...input: string[]): string {
const k = this.#normalize(secretKey)
try {
- const signature = nano25519_sign(this.#encoder.encode(input.join('')), k)
+ const signature = nano25519_sign(utf8.toBytes(input.join('')), k)
return bytes.toHex(signature)
} catch (err) {
throw new Error(`Failed to sign message`, { cause: err })
const k = this.#normalize(publicKey)
const s = this.#normalize(signature)
try {
- return nano25519_verify(s, this.#encoder.encode(input.join('')), k)
+ return nano25519_verify(s, utf8.toBytes(input.join('')), k)
} catch (err) {
throw new Error('Failed to verify signature', { cause: err })
}