]> git.codecow.com Git - libnemo.git/commitdiff
Reorder tool functions and explicitly export a const to bundle the tools.
authorChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 19:48:09 +0000 (12:48 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 19:48:09 +0000 (12:48 -0700)
src/lib/rolodex.ts
src/lib/tools.ts
src/main.ts

index 05047fffbd02f44fe578fbc01b4494deef0d2c6c..a45aa0ddc0175bc62e08dde50ba81c16424a87b9 100644 (file)
@@ -3,6 +3,7 @@
 
 import { Account } from './account'
 import { bytes, utf8 } from './convert'
+import { verify } from './tools'
 import { NamedData } from '#types'
 import { SafeWorker } from '#workers'
 
@@ -197,7 +198,6 @@ export class Rolodex {
        * @returns {Promise<boolean>} True if the signature was used to sign the data, else false
        */
        static async verify (name: string, signature: string, ...data: string[]): Promise<boolean> {
-               const { verify } = await import('./tools.js')
                const addresses = await this.getAddresses(name)
                for (const address of addresses) {
                        const { publicKey } = Account.import(address)
index 4bb753c8d151f879ff631b4541d46216420d16f9..8fe75973d19807619f620d540e7a39ee45101c08 100644 (file)
@@ -17,21 +17,6 @@ type SweepResult = {
        message: string
 }
 
-function hash (data: string | string[], encoding?: 'hex'): Uint8Array<ArrayBuffer>
-function hash (data: string | string[], encoding?: 'hex', format?: 'hex'): string | Uint8Array<ArrayBuffer> {
-       if (!Array.isArray(data)) data = [data]
-       const hash = new Blake2b(32)
-       if (encoding === 'hex') {
-               data.forEach(str => hash.update(hex.toBytes(str)))
-       } else {
-               const enc = new TextEncoder()
-               data.forEach(str => hash.update(enc.encode(str)))
-       }
-       return format === 'hex'
-               ? hash.digest('hex').toUpperCase()
-               : hash.digest()
-}
-
 /**
 * Converts a decimal amount of nano from one unit divider to another.
 *
@@ -82,6 +67,21 @@ export async function convert (amount: bigint | string, inputUnit: string, outpu
        return `${i}${f ? '.' : ''}${f}`
 }
 
+function hash (data: string | string[], encoding?: 'hex'): Uint8Array<ArrayBuffer>
+function hash (data: string | string[], encoding?: 'hex', format?: 'hex'): string | Uint8Array<ArrayBuffer> {
+       if (!Array.isArray(data)) data = [data]
+       const hash = new Blake2b(32)
+       if (encoding === 'hex') {
+               data.forEach(str => hash.update(hex.toBytes(str)))
+       } else {
+               const enc = new TextEncoder()
+               data.forEach(str => hash.update(enc.encode(str)))
+       }
+       return format === 'hex'
+               ? hash.digest('hex').toUpperCase()
+               : hash.digest()
+}
+
 /**
 * Signs arbitrary strings with a private key using the Ed25519 signature scheme.
 *
@@ -190,3 +190,5 @@ export async function verify (key: Key, signature: string, ...input: string[]):
                bytes.erase(key)
        }
 }
+
+export const Tools = { convert, hash, sign, sweep, verify }
index 2e45bc555d3f351d4e04f4a50332c522dfdf0348..fe7b46f6d9852aa1359bdd104751752627bdc52e 100644 (file)
@@ -3,10 +3,10 @@
 
 import { Account } from './lib/account'
 import { Blake2b } from './lib/blake2b'
-import { SendBlock, ReceiveBlock, ChangeBlock } from './lib/block'
+import { ChangeBlock, ReceiveBlock, SendBlock } from './lib/block'
 import { Rolodex } from './lib/rolodex'
 import { Rpc } from './lib/rpc'
+import { Tools } from './lib/tools'
 import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './lib/wallets'
-import * as Tools from './lib/tools'
 
-export { Account, Blake2b, SendBlock, ReceiveBlock, ChangeBlock, Rpc, Rolodex, Bip44Wallet, Blake2bWallet, LedgerWallet, Tools }
+export { Account, Blake2b, ChangeBlock, ReceiveBlock, SendBlock, Rolodex, Rpc, Tools, Bip44Wallet, Blake2bWallet, LedgerWallet }