From: Chris Duncan Date: Mon, 13 Apr 2026 06:02:01 +0000 (-0700) Subject: Fix sweep function referencing deprecated account index. Update readme. X-Git-Tag: v0.12.0~5^2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=4a57d70030a260fd0d81d92cd33c3618ed5093d0;p=libnemo.git Fix sweep function referencing deprecated account index. Update readme. --- diff --git a/README.md b/README.md index 6268dd1..80c83dd 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,15 @@ const wallet = await Wallet.load('BLAKE2b', password, seed) const wallet = await Wallet.load('BLAKE2b', password, mnemonic) ``` +Accounts in `libnemo` are guaranteed to be valid: if an account can be retrieved +from a wallet or created _ad hoc_ without throwing an error, its public key and +address can be considered correct for Nano protocol purposes. + +Wallet accounts are cached in an array-like numerically-indexed Map. This means +that deriving an account any time after the first will be faster, and it also +means that deriving a range of accounts will return an object that can be +treated somewhat like a [sparse array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#sparse_arrays). + ```javascript try { await wallet.unlock(password); @@ -95,7 +104,7 @@ const firstAccount = await wallet.account(); const secondAccount = await wallet.account(1); const multipleAccounts = await wallet.accounts(2, 3); const thirdAccount = multipleAccounts[2]; -const { address, publicKey, index } = firstAccount; +const { address, publicKey } = firstAccount; const nodeUrl = "https://nano-node.example.com/"; await firstAccount.refresh(nodeUrl); // online @@ -301,7 +310,7 @@ await wallet.unlock("some_password"); const account = await wallet.account(0); const data = "johndoe@example.com"; -const signature = await wallet.sign(account.index, data); +const signature = await wallet.sign(0, data); const isValid = await Tools.verify(account.publicKey, signature, data); console.log(isValid); @@ -338,16 +347,6 @@ const publicKey = new Account(address).publicKey; const isValid = await Tools.verify(publicKey, signature, ...randomData); ``` -#### Validate a Nano account address - -```javascript -import { Tools } from "libnemo"; - -const valid = Account.validate( - "nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d" -); -``` - ## Tests Test vectors were retrieved from the following publicly-available locations: diff --git a/src/lib/tools.ts b/src/lib/tools.ts index e6ae8fa..b629365 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -187,12 +187,12 @@ export class Tools { const blockRequest: Promise = new Promise(async (resolve) => { let block try { - if (index == null && account.index == null) { + if (index == null) { throw new TypeError('Account index is required', { cause: account }) } block = await new Block(account) .send(recipientAccount, account.balance ?? 0n) - .sign(wallet, account.index ?? index) + .sign(wallet, index) await block.pow() const hash = await block.process(rpc) results.push({ status: 'success', address: block.account.address, message: hash })