import { Account } from './account'
import { bytes, utf8 } from './convert'
+import { verify } from './tools'
import { NamedData } from '#types'
import { SafeWorker } from '#workers'
* @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)
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.
*
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.
*
bytes.erase(key)
}
}
+
+export const Tools = { convert, hash, sign, sweep, verify }
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 }