Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 83 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The BSV Wallet Toolbox builds on the [SDK](https://bsv-blockchain.github.io/ts-s
- [Objective](#objective)
- [Examples](#examples)
- [Documentation](#documentation)
- [Testing](#testing)
- [Contribution Guidelines](#contribution-guidelines)
- [Support \& Contacts](#support--contacts)
- [License](#license)
Expand All @@ -25,7 +26,88 @@ The BSV Wallet Toolbox Examples provides a collection of self-contained sample c
[The Docs](https://bsv-blockchain.github.io/wallet-toolbox) are available here on Github pages.
[Example code](https://docs.bsvblockchain.org/guides/sdks/ts/examples) is available over on our gitbook.

The Toolbox is richly documented with code-level annotations. This should show up well within editors like VSCode.
The Toolbox is richly documented with code-level annotations. This should show up well within editors like VSCode.


## Testing

### Running Tests

To run the test suite:
```bash
npm test
```

For development with watch mode:
```bash
npm run test:watch
```

### Live Testing with Real Funds

The Python storage server tests (`brc100.py.test.ts`) support live testing with real testnet funds. This allows you to verify that transactions are properly broadcasted and confirmed on the testnet blockchain.

#### Setup for Live Testing

1. **Generate a Testnet Key**
```bash
npm run keygen
```
This will output a new private key and testnet address. The private key should be added to your `.env` file.

2. **Fund the Address**
Copy the testnet address and fund it using one of these faucets:
- [MoneyButton Testnet Faucet](https://testnetfaucet.moneybutton.com/)
- [Whatsonchain Testnet Faucet](https://faucet.whatsonchain.com/)
- [Mempool Testnet Faucet](https://testnet-faucet.mempool.space/)

You'll need at least 10 satoshis to run the transaction tests.

3. **Configure Environment**
Add the generated private key to your `.env` file:
```bash
LIVE_PRIVATE_KEY=your_generated_private_key_here
```

4. **Fund the Address**
Send testnet funds to the generated address using one of the faucets listed above.

5. **Start the Python Storage Server**
Make sure the Python storage server is running:
```bash
cd ../py-wallet-toolbox/examples/storage_server_example
python manage.py runserver
```

6. **Run Live Tests**
The tests will automatically detect your funded address and attempt to internalize the funding transaction:
```bash
npm run test:py:live
```

**Note**: Transaction internalization requires Atomic BEEF format. If automatic internalization fails, you can manually run:
```bash
npm run internalize-funding
```
```bash
npm run test:py:live
```

#### What Live Testing Does

- Uses your funded testnet key instead of development keys
- Broadcasts real transactions to the testnet blockchain
- Verifies transaction confirmations and balance updates
- Provides links to view transactions on blockchain explorers

**⚠️ WARNING**: Live testing uses real testnet funds. While testnet coins have no monetary value, they still cost gas fees and should be used responsibly.

#### Test Scripts

- `npm run keygen` - Generate a new testnet key and address
- `npm run internalize-funding` - Manually internalize funding transaction into wallet (if auto-internalization fails)
- `npm run test:py` - Run Python storage server tests in test mode (no broadcasting)
- `npm run test:py:live` - Run Python storage server tests in live mode with automatic funding detection


## Examples
Expand Down
44 changes: 44 additions & 0 deletions debug_brc104_nonces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { Setup } = require('@bsv/wallet-toolbox');
const { Peer, SimplifiedFetchTransport } = require('@bsv/sdk');

async function debugNonces() {
const env = Setup.getEnv('test');
const rootKeyHex = env.devKeys[env.identityKey];

const setup = await Setup.createWallet({
env,
rootKeyHex
});

console.log('Client Identity:', env.identityKey);

// Create transport and peer
const transport = new SimplifiedFetchTransport('http://localhost:8000');
const peer = new Peer(setup.wallet, transport);

// Intercept the send method to log what's being sent
const originalSend = transport.send.bind(transport);
transport.send = async function(message) {
if (message.messageType === 'general') {
console.log('\n[CLIENT] Sending general message:');
console.log(' nonce (request):', message.nonce);
console.log(' yourNonce (server nonce from handshake):', message.yourNonce);
console.log(' Expected keyID:', `${message.nonce} ${message.yourNonce}`);
}
return originalSend(message);
};

try {
// This will trigger the handshake
const testPayload = Buffer.from(JSON.stringify({ method: 'test' }));
await peer.toPeer(Array.from(testPayload));
console.log('\n✅ Message sent successfully!');
} catch (error) {
console.error('\n❌ Error:', error.message);
}

process.exit(0);
}

debugNonces().catch(console.error);

55 changes: 55 additions & 0 deletions debug_signature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { PrivateKey } = require('@bsv/sdk');
const { Setup } = require('@bsv/wallet-toolbox');

async function debugSignature() {
const env = Setup.getEnv('test');
const rootKeyHex = env.devKeys[env.identityKey];

console.log('Client Root Key:', rootKeyHex);
console.log('Client Identity Key:', env.identityKey);

// Create wallet
const setup = await Setup.createWallet({
env,
rootKeyHex
});

// Test data
const testData = Buffer.from('hello world');
const protocolID = [2, 'auth message signature'];
const keyID = 'nonce1 nonce2';
const counterparty = '0320295654f4c8d4d2bc2ed79b0169f7584e62519b17f6a829adebe400316c90d6'; // Server public key

console.log('\n--- Creating Signature ---');
console.log('Data:', testData.toString('hex'));
console.log('ProtocolID:', protocolID);
console.log('KeyID:', keyID);
console.log('Counterparty:', counterparty);

const sigResult = await setup.wallet.createSignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty
});

console.log('Signature:', Buffer.from(sigResult.signature).toString('hex'));

// Now verify
console.log('\n--- Verifying Signature ---');
const verifyResult = await setup.wallet.verifySignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty,
signature: sigResult.signature
});

console.log('Verification result:', verifyResult.valid);

process.exit(0);
}

debugSignature().catch(console.error);


67 changes: 67 additions & 0 deletions debug_signature2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { PrivateKey } = require('@bsv/sdk');
const { Setup } = require('@bsv/wallet-toolbox');

async function debugSignature() {
const env = Setup.getEnv('test');
const rootKeyHex = env.devKeys[env.identityKey];

console.log('Client Root Key:', rootKeyHex);
console.log('Client Identity Key:', env.identityKey);

// Create wallet
const setup = await Setup.createWallet({
env,
rootKeyHex
});

// Test data
const testData = Buffer.from('hello world');
const protocolID = [2, 'auth message signature'];
const keyID = 'nonce1 nonce2';

console.log('\n--- Test 1: With counterparty="self" ---');
const sigResult1 = await setup.wallet.createSignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty: 'self'
});

console.log('Signature:', Buffer.from(sigResult1.signature).toString('hex'));

const verifyResult1 = await setup.wallet.verifySignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty: 'self',
signature: sigResult1.signature
});

console.log('Verification result:', verifyResult1.valid);

console.log('\n--- Test 2: With counterparty="anyone" ---');
const sigResult2 = await setup.wallet.createSignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty: 'anyone'
});

console.log('Signature:', Buffer.from(sigResult2.signature).toString('hex'));

const verifyResult2 = await setup.wallet.verifySignature({
data: Array.from(testData),
protocolID,
keyID,
counterparty: 'anyone',
signature: sigResult2.signature
});

console.log('Verification result:', verifyResult2.valid);

process.exit(0);
}

debugSignature().catch(console.error);


Loading