Package Exports
- blocktrails
- blocktrails/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (blocktrails) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
blocktrails-js
Reference implementation of Blocktrails — Nostr-native output-key commitment chaining on Bitcoin.
Install
npm install blocktrailsQuick Start
import { Blocktrail } from 'blocktrails';
// Create a trail with your private key
const trail = new Blocktrail(privateKey);
// Genesis - first state
const genesis = trail.genesis(JSON.stringify({ balance: 1000 }));
console.log(genesis.p2trAddress); // bc1p...
// Advance - state transition
const tx = trail.advance(JSON.stringify({ balance: 900 }));
console.log(tx.newP2trAddress); // bc1p... (different)
// Export for verification
const exported = trail.export();API
genesis(privateKey, state)
Create initial commitment.
import { genesis } from 'blocktrails';
const result = genesis(privateKeyBytes, 'initial state');
// {
// witnessProgram: '...', // 32-byte x-only pubkey (hex)
// p2trAddress: 'bc1p...', // P2TR address
// derivedPrivateKey: '...', // Key for signing
// derivedPublicKey: '...', // Full public key
// }transition(privateKey, prevState, newState)
Create state transition.
import { transition } from 'blocktrails';
const result = transition(privateKeyBytes, 'state 0', 'state 1');
// {
// signingPrivateKey: '...', // Sign prev output with this
// prevWitnessProgram: '...', // What we're spending
// newWitnessProgram: '...', // New output
// newP2trAddress: 'bc1p...',
// }verify(publicKeyBase, states, witnessPrograms)
Verify a state chain.
import { verify } from 'blocktrails';
const result = verify(publicKeyBase, states, witnessPrograms);
// { valid: true } or { valid: false, error: '...' }Blocktrail class
Stateful helper for managing a trail.
import { Blocktrail } from 'blocktrails';
const trail = new Blocktrail(privateKey);
trail.genesis('state 0');
trail.advance('state 1');
trail.advance('state 2');
trail.currentState(); // 'state 2'
trail.currentWitnessProgram(); // Uint8Array
trail.export(); // { publicKeyBase, states, witnessPrograms }Low-level Functions
import {
computeTweak, // H(state) mod n
derivePrivateKey, // d_base + t
derivePublicKey, // P_base + t·G
p2trXonly, // 33-byte → 32-byte x-only
hasEvenY, // Check parity
adjustPrivateKeyForSigning, // Negate if odd y
} from 'blocktrails';Run Tests
npm testRun Demo
npm run demoSpec
See the full specification at blocktrails.org/spec.
License
MIT