From: Chris Duncan Date: Fri, 24 Apr 2026 06:48:16 +0000 (-0700) Subject: Import string encoder for consistency. X-Git-Tag: v0.12.0~3^2~2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=ee49b114975e11742b759c51ed1a6d4139057946;p=libnemo.git Import string encoder for consistency. --- diff --git a/src/lib/tools.ts b/src/lib/tools.ts index b8137af..e010afc 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -5,7 +5,7 @@ import { sign as nano25519_sign, verify as nano25519_verify } from 'nano25519/sy 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' @@ -17,7 +17,6 @@ type SweepResult = { } export class Tools { - static #encoder: TextEncoder = new TextEncoder() static #normalize (input: string | ArrayBuffer | Uint8Array): Uint8Array { return (typeof input === 'string') ? hex.toBytes(input) @@ -149,7 +148,7 @@ export class Tools { static sign (secretKey: string | ArrayBuffer | Uint8Array, ...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 }) @@ -228,7 +227,7 @@ export class Tools { 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 }) }