]> git.codecow.com Git - libnemo.git/commitdiff
Fix sweep function referencing deprecated account index. Update readme.
authorChris Duncan <chris@zoso.dev>
Mon, 13 Apr 2026 06:02:01 +0000 (23:02 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 13 Apr 2026 06:02:01 +0000 (23:02 -0700)
README.md
src/lib/tools.ts

index 6268dd19db3b0f8592cd7deb3d27628bf4343d66..80c83ddab02a6da857d203f1b3e83158f8ec63e7 100644 (file)
--- 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:
index e6ae8fae006a3686c386a2f215898a172387168c..b629365d918973038b3e64209c46b6c35226ef42 100644 (file)
@@ -187,12 +187,12 @@ export class Tools {
                        const blockRequest: Promise<void> = 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 })