Package Exports
- @yaring/mcbf
- @yaring/mcbf/dist/index.esm.js
- @yaring/mcbf/dist/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 (@yaring/mcbf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Multi-Chain Blockchain Framework (MCBF)
MCBF is a universal library for working with various blockchain networks, providing a unified interface for creating and managing cryptocurrency wallets.
Key Features
- Support for multiple blockchain networks through an adapter system
- Unified interface for working with different networks
- Wallet generation and recovery from mnemonic phrases (BIP39, Cardano, Monero)
- Data encryption using AES-GCM
- Support for various key derivation protocols
- JSON Schema-based data validation
- Support for multiple address types per network
Installation
npm install @yaring/mcbfSupported Networks and Protocols
| Network | Type | Protocol | Derivation Paths |
|---|---|---|---|
| Bitcoin | UTXO | BIP84 | m/84'/0'/0'/0/0 |
| Ethereum | Account | BIP44 | m/44'/60'/0'/0/0 |
| Cardano | Account | Cardano | m/1852'/1815'/0'/0/0 |
| Cosmos | Dual | BIP44 | m/44'/118'/0'/0/0 |
| Dogecoin | UTXO | BIP84 | m/84'/3'/0'/0/0 |
| Litecoin | UTXO | BIP84 | m/84'/2'/0'/0/0 |
| Monero | Account | CryptoNote | - |
| Polkadot | Account | SR25519 | m/44'/354'/0'/0/0 |
| Solana | Account | ED25519 | m/44'/501'/0'/0/0 |
| TON | Account | ED25519 | m/44'/607'/0'/0/0 |
| TRON | Account | BIP44 | m/44'/195'/0'/0/0 |
Quick Start
import { MCBFManager } from '@yaring/mcbf';
// Initialize manager
const mcbf = new MCBFManager();
// Create new wallet
const wallet = await mcbf.generateBIP39Wallet({
networks: ['bitcoin', 'ethereum', 'solana']
});
console.log(wallet.mnemonic); // 12/24 word mnemonic
console.log(wallet.networks.bitcoin.addresses.default); // bc1...
console.log(wallet.networks.ethereum.addresses.default); // 0x...
console.log(wallet.networks.solana.addresses.default); // Base58...Detailed Usage
Creating an Encrypted Wallet
const mcbf = new MCBFManager({
encryption: {
keyLength: 256,
iterations: 100000
}
});
const wallet = await mcbf.generateBIP39Wallet({
networks: ['bitcoin', 'ethereum']
});
const encrypted = await mcbf.encryptWalletData(wallet, 'strong-password');Restoring from Mnemonic
const wallet = await mcbf.restoreFromMnemonic(
'your twelve or twenty four word mnemonic phrase',
{
networks: ['bitcoin', 'ethereum'],
type: 'BIP39' // or 'CARDANO', 'MONERO'
}
);Working with Specific Networks
Bitcoin
import { BitcoinNetworkAdapter } from '@yaring/mcbf';
const keys = await BitcoinNetworkAdapter.deriveKeys(mnemonic);
console.log({
bech32: keys.addresses.bech32, // Native SegWit (bc1...)
segwit: keys.addresses.segwit, // SegWit (3...)
legacy: keys.addresses.legacy // Legacy (1...)
});Ethereum
import { EVMNetworkAdapter } from '@yaring/mcbf';
const keys = await EVMNetworkAdapter.deriveKeys(mnemonic);
console.log({
address: keys.address, // 0x...
privateKey: keys.privateKey // 0x...
});Cardano
import { CardanoNetworkAdapter } from '@yaring/mcbf';
const keys = await CardanoNetworkAdapter.deriveKeys(mnemonic);
console.log({
base: keys.addresses.base, // addr1...
enterprise: keys.addresses.enterprise, // addr1...
reward: keys.addresses.reward // stake1...
});Data Encryption
import { Encryption } from '@yaring/mcbf';
const encryption = new Encryption({
keyLength: 256,
iterations: 100000,
algorithm: 'AES-GCM'
});
// Encryption
const encrypted = await encryption.encrypt(walletData, password);
// Decryption
const decrypted = await encryption.decrypt(encrypted, password);Data Validation
import { Validator } from '@yaring/mcbf';
const validator = new Validator();
try {
validator.validateData(walletData);
console.log('Data is valid');
} catch (error) {
console.error('Validation error:', error.message);
}Wallet Data Structure
{
format: {
name: "MCBF",
version: "1.0",
timestamp: "2024-03-20T12:00:00Z"
},
wallet: {
id: "uuid-v4",
name: "My Wallet",
creator: {
name: "MCBF",
version: "1.0.0"
}
},
data: {
bip39: {
entropy: "hex-string",
mnemonic: "12/24 words",
networks: {
bitcoin: {
derivationPath: "m/84'/0'/0'/0/0",
privateKey: "hex",
publicKey: "hex",
address: "bc1..."
},
// Other networks...
}
}
}
}Error Handling
The library uses an exception system with informative messages:
try {
const wallet = await mcbf.generateBIP39Wallet();
} catch (error) {
if (error.message.includes('Invalid mnemonic')) {
console.error('Invalid mnemonic phrase');
} else if (error.message.includes('Unsupported network')) {
console.error('Unsupported network');
} else {
console.error('Unknown error:', error.message);
}
}Development
Requirements
- Node.js 16+
- npm 7+
Installing Dependencies
npm installBuilding
npm run buildTesting
npm testLicense
MIT
Support
If you have questions or issues, please create an issue in the project repository.