From 57823f6bc332330f6ee7fd4e1fada66ec932ec44 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Wed, 22 Jan 2025 11:26:52 -0300 Subject: [PATCH 1/4] Renamed 'signing' folder to 'crypto' and updated example files --- examples/crypto/privkey-to-address.js | 52 +++++++++++ examples/crypto/pubkey-to-address.js | 52 +++++++++++ .../sign-verify-qi-musig.js | 79 ++++++++++++---- .../sign-verify-qi-schnorr.js | 49 ++++++++-- examples/crypto/sign-verify-quai-ecdsa.js | 91 +++++++++++++++++++ examples/signing/pubkey-to-address.js | 37 -------- examples/signing/sign-verify-quai.js | 53 ----------- 7 files changed, 296 insertions(+), 117 deletions(-) create mode 100644 examples/crypto/privkey-to-address.js create mode 100644 examples/crypto/pubkey-to-address.js rename examples/{signing => crypto}/sign-verify-qi-musig.js (51%) rename examples/{signing => crypto}/sign-verify-qi-schnorr.js (59%) create mode 100644 examples/crypto/sign-verify-quai-ecdsa.js delete mode 100644 examples/signing/pubkey-to-address.js delete mode 100644 examples/signing/sign-verify-quai.js diff --git a/examples/crypto/privkey-to-address.js b/examples/crypto/privkey-to-address.js new file mode 100644 index 00000000..2e6ea677 --- /dev/null +++ b/examples/crypto/privkey-to-address.js @@ -0,0 +1,52 @@ +const { + computeAddress, + SigningKey, +} = require('../../lib/commonjs/quais'); + +/** + * Key to Address Example + * + * This script demonstrates how to derive a Quai address from a private key. + * It uses the SigningKey class to compute the public key and then derives + * the corresponding address. + * + * Usage: + * ``` + * node key-to-address.js + * ``` + * + * Example: + * ``` + * node key-to-address.js 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef + * ``` + * + * The script will output: + * - The input private key + * - The derived public key + * - The corresponding Quai address + */ + +async function main() { + // Check if a public key is provided as a command line argument + if (process.argv.length < 3) { + console.error('Please provide a public key as a command line argument'); + process.exit(1); + } + + const key = process.argv[2]; + + // Compute the address from the public key + console.log(`Private Key: ${key}`); + const pubkey = SigningKey.computePublicKey(key, true); + console.log(`Public Key: ${pubkey}`); + const address = computeAddress(key); + console.log(`Derived Address: ${address}`); + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/crypto/pubkey-to-address.js b/examples/crypto/pubkey-to-address.js new file mode 100644 index 00000000..bbb609ad --- /dev/null +++ b/examples/crypto/pubkey-to-address.js @@ -0,0 +1,52 @@ +const { + computeAddress, +} = require('../../lib/commonjs/quais'); + +/** + * Public Key to Address Example + * + * This script demonstrates how to derive a Quai address directly from a public key. + * It uses the computeAddress function to derive the corresponding address from + * an uncompressed or compressed public key. + * + * Usage: + * ``` + * node pubkey-to-address.js + * ``` + * + * Example: + * ``` + * node pubkey-to-address.js 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 + * ``` + * + * The script will output: + * - The input public key + * - The derived Quai address + * + * Note: The public key can be either compressed (33 bytes, starting with 02 or 03) + * or uncompressed (65 bytes, starting with 04). + */ + +async function main() { + // Check if a public key is provided as a command line argument + if (process.argv.length < 3) { + console.error('Please provide a public key as a command line argument'); + process.exit(1); + } + + const pubkey = process.argv[2]; + + // Compute the address from the public key + const address = computeAddress(pubkey); + console.log(`Public Key: ${pubkey}`); + console.log(`Derived Address: ${address}`); + + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/signing/sign-verify-qi-musig.js b/examples/crypto/sign-verify-qi-musig.js similarity index 51% rename from examples/signing/sign-verify-qi-musig.js rename to examples/crypto/sign-verify-qi-musig.js index 1b5d12f2..dde777ae 100644 --- a/examples/signing/sign-verify-qi-musig.js +++ b/examples/crypto/sign-verify-qi-musig.js @@ -1,23 +1,60 @@ -const quais = require('../../lib/commonjs/quais'); +const { + Mnemonic, + QiHDWallet, + Zone, + QiTransaction, + getBytes, + musigCrypto, + hexlify, +} = require('../../lib/commonjs/quais'); require('dotenv').config(); -const { keccak_256 } = require('@noble/hashes/sha3'); const { schnorr } = require('@noble/curves/secp256k1'); const { MuSigFactory } = require('@brandonblack/musig'); +/** + * MuSig Signature Example for Qi Transactions + * + * This script demonstrates how to create and verify a MuSig (multi-signature) Schnorr signature + * for a Qi transaction. It shows the complete workflow of: + * 1. Creating multiple addresses from a single wallet + * 2. Creating a Qi transaction with multiple inputs + * 3. Signing with MuSig (aggregated signatures) + * 4. Verifying the aggregated signature + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * + * Then run: + * ``` + * node sign-verify-qi-musig.js + * ``` + * + * The script will output: + * - Two signer addresses + * - The transaction to be signed + * - The serialized signed transaction + * - The transaction hash + * - The verification result + * + * Note: This example uses MuSig for aggregating Schnorr signatures, which is + * particularly useful for UTXO-based multi-signature transactions. + */ + async function main() { // Create wallet - const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC); - const qiWallet = quais.QiHDWallet.fromMnemonic(mnemonic); + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const qiWallet = QiHDWallet.fromMnemonic(mnemonic); // Generate 1 address for each outpoint - const addressInfo1 = await qiWallet.getNextAddress(0, quais.Zone.Cyprus1); + const addressInfo1 = await qiWallet.getNextAddress(0, Zone.Cyprus1); const addr1 = addressInfo1.address; const pubkey1 = addressInfo1.pubKey; - - const addressInfo2 = await qiWallet.getNextAddress(0, quais.Zone.Cyprus1); + console.log('\n... signer address #1: ', addr1); + const addressInfo2 = await qiWallet.getNextAddress(0, Zone.Cyprus1); const addr2 = addressInfo2.address; const pubkey2 = addressInfo2.pubKey; - + console.log('\n... signer address #2: ', addr2); // Define the outpoints for addr1 const outpointsInfo = [ { @@ -27,7 +64,7 @@ async function main() { denomination: 7, }, address: addr1, - zone: quais.Zone.Cyprus1, + zone: Zone.Cyprus1, }, { outpoint: { @@ -36,7 +73,7 @@ async function main() { denomination: 7, }, address: addr2, - zone: quais.Zone.Cyprus1, + zone: Zone.Cyprus1, }, ]; @@ -65,27 +102,31 @@ async function main() { ]; // Create the Qi Tx to be signed - const tx = new quais.QiTransaction(); + const tx = new QiTransaction(); tx.txInputs = txInputs; tx.txOutputs = txOutputs; - // Calculate the hash of the Qi tx (message to be signed and verified) - const txHash = keccak_256(tx.unsignedSerialized); + console.log('\n... transaction to sign: ', JSON.stringify(tx, null, 2)); // Sign the tx const serializedSignedTx = await qiWallet.signTransaction(tx); // Unmarshall the signed Tx - const signedTx = quais.QiTransaction.from(serializedSignedTx); + const signedTxObj = QiTransaction.from(serializedSignedTx); + console.log('\n... signed transaction (serialized): ', serializedSignedTx); + // Digest to verify + const txHash = getBytes(signedTxObj.digest); + console.log('\n... txHash to verify: ', signedTxObj.digest); + // Get the signature from the signed tx - const signature = signedTx.signature; + const signature = signedTxObj.signature; - const musig = MuSigFactory(quais.musigCrypto); - const pubKeysArray = [quais.getBytes(pubkey1), quais.getBytes(pubkey2)]; + const musig = MuSigFactory(musigCrypto); + const pubKeysArray = [getBytes(pubkey1), getBytes(pubkey2)]; const aggPublicKeyObj = musig.keyAgg(pubKeysArray); - let aggPublicKey = quais.hexlify(aggPublicKeyObj.aggPublicKey); + let aggPublicKey = hexlify(aggPublicKeyObj.aggPublicKey); // Remove the last 32 bytes (64 hex) from the aggPublicKey let compressedPubKey = aggPublicKey.slice(0, -64); @@ -94,7 +135,7 @@ async function main() { compressedPubKey = '0x' + compressedPubKey.slice(4); // Verify the schnoor signature - const verified = schnorr.verify(quais.getBytes(signature), txHash, quais.getBytes(compressedPubKey)); + const verified = schnorr.verify(getBytes(signature), txHash, getBytes(compressedPubKey)); console.log('Verified:', verified); } diff --git a/examples/signing/sign-verify-qi-schnorr.js b/examples/crypto/sign-verify-qi-schnorr.js similarity index 59% rename from examples/signing/sign-verify-qi-schnorr.js rename to examples/crypto/sign-verify-qi-schnorr.js index 096e329e..ec982257 100644 --- a/examples/signing/sign-verify-qi-schnorr.js +++ b/examples/crypto/sign-verify-qi-schnorr.js @@ -4,12 +4,41 @@ const { Zone, QiTransaction, getBytes, - keccak256, } = require('../../lib/commonjs/quais'); require('dotenv').config(); const { schnorr } = require('@noble/curves/secp256k1'); +/** + * Schnorr Signature Example for Qi Transactions + * + * This script demonstrates how to create and verify a Schnorr signature + * for a Qi transaction. It shows the complete workflow of: + * 1. Creating a wallet and deriving an address + * 2. Creating a Qi transaction + * 3. Signing with Schnorr signature + * 4. Verifying the signature + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * + * Then run: + * ``` + * node sign-verify-qi-schnorr.js + * ``` + * + * The script will output: + * - The signer's address + * - The transaction to be signed + * - The serialized signed transaction + * - The transaction hash + * - The verification result + * + * Note: This example uses Schnorr signatures which are more efficient and + * provide better privacy compared to ECDSA signatures for UTXO transactions. + */ + async function main() { // Create wallet const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); @@ -18,6 +47,7 @@ async function main() { // Get address info const addressInfo1 = await qiWallet.getNextAddress(0, Zone.Cyprus1); const addr1 = addressInfo1.address; + console.log('\n... signer address: ', addr1); const pubkey1 = addressInfo1.pubKey; // Define the outpoints for addr1 (this is just an example outpoint) @@ -57,24 +87,27 @@ async function main() { tx.txInputs = txInputs; tx.txOutputs = txOutputs; - // Calculate the hash of the Qi tx (message to be signed and verified) - const txHash = getBytes(keccak256(tx.unsignedSerialized)); + console.log('\n... transaction to sign: ', JSON.stringify(tx, null, 2)); // Sign the tx const serializedSignedTx = await qiWallet.signTransaction(tx); - + console.log('\n... signed transaction (serialized): ', serializedSignedTx); // Unmarshall the signed Tx - const signedTx = QiTransaction.from(serializedSignedTx); + const signedTxObj = QiTransaction.from(serializedSignedTx); + + // Digest to verify + const txHash = getBytes(signedTxObj.digest); + console.log('\n... txHash to verify: ', signedTxObj.digest); // Get the signature from the signed tx - const signature = signedTx.signature; + const signature = signedTxObj.signature; // Remove parity byte from pubkey - publicKey = '0x' + pubkey1.slice(4); + const publicKey = '0x' + pubkey1.slice(4); // Verify the schnoor signature const verified = schnorr.verify(getBytes(signature), txHash, getBytes(publicKey)); - console.log('Verified:', verified); + console.log('\n=> signature is valid: ', verified); } main() diff --git a/examples/crypto/sign-verify-quai-ecdsa.js b/examples/crypto/sign-verify-quai-ecdsa.js new file mode 100644 index 00000000..1a1b8fec --- /dev/null +++ b/examples/crypto/sign-verify-quai-ecdsa.js @@ -0,0 +1,91 @@ +const { + Mnemonic, + QuaiHDWallet, + Zone, + QuaiTransaction, + recoverAddress, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * ECDSA Signature Example for Quai Transactions + * + * This script demonstrates how to create and verify an ECDSA signature + * for a Quai (EVM-based) transaction. It shows the complete workflow of: + * 1. Creating a wallet and deriving an address + * 2. Creating a Quai transaction with standard EVM fields + * 3. Signing with ECDSA + * 4. Verifying the signature through address recovery + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * + * Then run: + * ``` + * node sign-verify-quai-ecdsa.js + * ``` + * + * The script will output: + * - The signer's address + * - The transaction to be signed (with chainId, nonce, gas parameters) + * - The serialized signed transaction + * - The transaction hash + * - The recovered signer address + * - Verification result + * + * Note: This example uses standard EVM-style ECDSA signatures, which are + * different from the Schnorr signatures used in Qi (UTXO) transactions. + */ + + +async function main() { + // Create wallet + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const quaiWallet = QuaiHDWallet.fromMnemonic(mnemonic); + + const addressInfo1 = await quaiWallet.getNextAddress(0, Zone.Cyprus1); + const from = addressInfo1.address; + console.log('\n... signer address (from): ', from); + + // Create tx + const txObj = new QuaiTransaction(from); + txObj.chainId = BigInt(969); + txObj.nonce = BigInt(0); + txObj.gasLimit = BigInt(1000000); + txObj.minerTip = BigInt(10000000000); + txObj.gasPrice = BigInt(30000000000000); + txObj.to = '0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329'; + txObj.value = BigInt(4200000); + + + console.log('\n... transaction to sign: ', JSON.stringify(txObj, null, 2)); + + // Sign the tx + const signedTxSerialized = await quaiWallet.signTransaction(txObj); + console.log('\n... signed transaction (serialized): ', signedTxSerialized); + + // Unmarshall the signed tx + const signedTxObj = QuaiTransaction.from(signedTxSerialized); + + // Get the signature + const signature = signedTxObj.signature; + + // Verify the signature + const txHash = signedTxObj.digest; + console.log('\n... txHash to verify: ', txHash); + const signerAddress = recoverAddress(txHash, signature); + console.log('\n... signerAddress (recovered): ', signerAddress); + if (signerAddress === from) { + console.log('\n=> signature is valid'); + } else { + console.log('\n=> signature is invalid'); + } +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/signing/pubkey-to-address.js b/examples/signing/pubkey-to-address.js deleted file mode 100644 index f1c91e6f..00000000 --- a/examples/signing/pubkey-to-address.js +++ /dev/null @@ -1,37 +0,0 @@ -const quais = require('../../lib/commonjs/quais'); - - -async function main() { - // Check if a public key is provided as a command line argument - if (process.argv.length < 3) { - console.error('Please provide a public key as a command line argument'); - process.exit(1); - } - - const pubkey = process.argv[2]; - - // Verify if the provided string is a valid public key of the type 0x0250495cb2f9535c684ebe4687b501c0d41a623d68c118b8dcecd393370f1d90e6 - if (!quais.isHexString(pubkey) || pubkey.length !== 68) { - console.error('Invalid public key format'); - process.exit(1); - } - - - try { - // Compute the address from the public key - const address = quais.computeAddress(pubkey); - console.log(`Public Key: ${pubkey}`); - console.log(`Derived Address: ${address}`); - } catch (error) { - console.error('Error computing address:', error.message); - process.exit(1); - } - -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); diff --git a/examples/signing/sign-verify-quai.js b/examples/signing/sign-verify-quai.js deleted file mode 100644 index 1f342fb3..00000000 --- a/examples/signing/sign-verify-quai.js +++ /dev/null @@ -1,53 +0,0 @@ -const quais = require('../../lib/commonjs/quais'); -require('dotenv').config(); - -async function main() { - // Create wallet - const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC); - const quaiWallet = quais.QuaiHDWallet.fromMnemonic(mnemonic); - - // Create tx - const addressInfo1 = await quaiWallet.getNextAddress(0, quais.Zone.Cyprus1); - const from = addressInfo1.address; - console.log('from: ', from); - const txObj = new quais.QuaiTransaction(from); - txObj.chainId = BigInt(969); - txObj.nonce = BigInt(0); - txObj.gasLimit = BigInt(1000000); - txObj.gasPrice = BigInt(30000000000000); - txObj.to = '0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329'; - txObj.value = BigInt(4200000); - - - // transaction to sign - console.log('txObj: ', JSON.stringify(txObj, null, 2)); - - // Sign the tx - const signedTxSerialized = await quaiWallet.signTransaction(txObj); - console.log('signedTxSerialized: ', signedTxSerialized); - - // Unmarshall the signed tx - const signedTxObj = quais.QuaiTransaction.from(signedTxSerialized); - - console.log('signedTxObj: ', signedTxObj); - - // Get the signature - const signature = signedTxObj.signature; - - // Verify the signature - const txHash = signedTxObj.digest; - const signerAddress = quais.recoverAddress(txHash, signature); - - if (signerAddress === from) { - console.log('\nSignature is valid'); - } else { - console.log('\nSignature is invalid'); - } -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); From af1333b730ec2c1cb7cc44c0d0f8f1389c9dffc0 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Mon, 27 Jan 2025 07:43:48 -0300 Subject: [PATCH 2/4] add new example scripts to 'wallets' --- .../wallets/qi-wallet-generate-addresses.js | 56 ++++++++++++ examples/wallets/qi-wallet-scan.js | 87 +++++++++++++++++++ .../wallets/quai-wallet-generate-addresses.js | 53 +++++++++++ examples/wallets/utils.js | 10 +++ 4 files changed, 206 insertions(+) create mode 100644 examples/wallets/qi-wallet-generate-addresses.js create mode 100644 examples/wallets/qi-wallet-scan.js create mode 100644 examples/wallets/quai-wallet-generate-addresses.js diff --git a/examples/wallets/qi-wallet-generate-addresses.js b/examples/wallets/qi-wallet-generate-addresses.js new file mode 100644 index 00000000..2d6d20e8 --- /dev/null +++ b/examples/wallets/qi-wallet-generate-addresses.js @@ -0,0 +1,56 @@ +const { + Mnemonic, + QiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +const { generateAddresses } = require('./utils'); +require('dotenv').config(); + +/** + * Qi Wallet Address Generation Example + * + * This script demonstrates how to generate multiple Qi (UTXO-based) addresses from a single HD wallet. + * It showcases the hierarchical deterministic (HD) wallet functionality for the Qi ledger, + * implementing BIP44 and QIP-3 specifications for address derivation. + * + * The script demonstrates: + * 1. Creating a Qi HD wallet from a mnemonic + * 2. Deriving multiple addresses for a specific account and zone + * 3. Proper zone-specific address generation following QIP-2 and QIP-4 + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * + * Then run: + * ``` + * node qi-wallet-generate-addresses.js + * ``` + * + * The script will output: + * - 5 derived Qi addresses for account index 0 in the Cyprus1 zone + * - Each address will include its derivation path and public key + * + * Note: Qi addresses follow a different format than Quai addresses as they are + * designed for UTXO-based transactions following QIP-7 specifications. + */ + +async function main() { + // Create quai wallet + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const qiWallet = QiHDWallet.fromMnemonic(mnemonic); + + // derive 5 new addresses for account '0' and zone 'Cyprus1' + const addresses = generateAddresses(qiWallet, 0, Zone.Cyprus1, 5); + console.log('Generated Qi addresses for account 0 and zone Cyprus1:', JSON.stringify(addresses, null, 2)); + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); + + diff --git a/examples/wallets/qi-wallet-scan.js b/examples/wallets/qi-wallet-scan.js new file mode 100644 index 00000000..01f86337 --- /dev/null +++ b/examples/wallets/qi-wallet-scan.js @@ -0,0 +1,87 @@ +const { + JsonRpcProvider, + Mnemonic, + QiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * Qi Wallet Scanning and Balance Discovery Example + * + * This script demonstrates how to scan a Qi (UTXO-based) wallet to discover used addresses, + * track balances, and manage both external and change addresses. It implements BIP44 wallet + * scanning with gap limit management and UTXO tracking. + * + * The script demonstrates: + * 1. Creating and connecting a Qi wallet to a node + * 2. Scanning for used addresses in a specific zone + * 3. Managing external (receiving) and change addresses + * 4. Tracking UTXOs (outpoints) associated with the wallet + * 5. Calculating total wallet balance + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * RPC_URL="your node RPC endpoint" + * + * Then run: + * ``` + * node qi-wallet-scan.js + * ``` + * + * The script will output: + * - List of discovered external addresses with their: + * - Derivation paths + * - Public keys + * - Usage status (USED/UNUSED) + * - Last synced block information + * - List of change addresses with similar details + * - Available UTXOs (outpoints) with: + * - Transaction hashes + * - Output indices + * - Denominations + * - Total wallet balance in the scanned zone + * + * Note: This implementation follows BIP44 for HD wallet structure and QIP-7 + * for UTXO management in the Quai network's sharded architecture. + */ + +async function main() { + // Create provider + const options = {usePathing: false}; + console.log('RPC URL: ', process.env.RPC_URL); + const provider = new JsonRpcProvider(process.env.RPC_URL, undefined, options); + + // Create wallet and connect to provider + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const aliceQiWallet = QiHDWallet.fromMnemonic(mnemonic); + aliceQiWallet.connect(provider); + + console.log('Scanning Alice Qi wallet...'); + await aliceQiWallet.scan(Zone.Cyprus1); + console.log('Alice Qi wallet scan complete'); + + // log Alice wallet external addresses + const externalAddressesInfo = aliceQiWallet.getAddressesForZone(Zone.Cyprus1); + console.log('Alice wallet external addresses: ', JSON.stringify(externalAddressesInfo, null, 2)); + + const changeAddressesInfo = aliceQiWallet.getChangeAddressesForZone(Zone.Cyprus1); + console.log('Alice wallet change addresses: ', JSON.stringify(changeAddressesInfo, null, 2)); + + // log Alice wallet outpoints + const outpoints = aliceQiWallet.getOutpoints(Zone.Cyprus1); + console.log('Alice wallet outpoints: ', JSON.stringify(outpoints, null, 2)); + + // log Alice wallet balance + const balance = await aliceQiWallet.getBalanceForZone(Zone.Cyprus1); + console.log('Alice wallet balance: ', balance); + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/wallets/quai-wallet-generate-addresses.js b/examples/wallets/quai-wallet-generate-addresses.js new file mode 100644 index 00000000..4bd9dc80 --- /dev/null +++ b/examples/wallets/quai-wallet-generate-addresses.js @@ -0,0 +1,53 @@ +const { + Mnemonic, + QuaiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +const { generateAddresses } = require('./utils'); +require('dotenv').config(); + +/** + * Quai Wallet Address Generation Example + * + * This script demonstrates how to generate multiple Quai (EVM-based) addresses from a single HD wallet. + * It showcases the hierarchical deterministic (HD) wallet functionality for the Quai ledger, + * implementing BIP44 specifications with Quai-specific derivation paths. + * + * The script demonstrates: + * 1. Creating a Quai HD wallet from a mnemonic + * 2. Deriving multiple addresses for a specific account and zone + * 3. Proper zone-specific address generation following QIP-2 and QIP-4 + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * + * Then run: + * ``` + * node quai-wallet-generate-addresses.js + * ``` + * + * The script will output: + * - 5 derived Quai addresses for account index 0 in the Cyprus1 zone + * - Each address will include its derivation path and public key + * + * Note: Quai addresses follow the standard EVM address format with zone-specific + * prefixes as defined in QIP-2 and QIP-4. + */ + +async function main() { + // Create quai wallet + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const quaiWallet = QuaiHDWallet.fromMnemonic(mnemonic); + + // derive 5 new addresses for account '0' and zone 'Cyprus1' + const addresses = generateAddresses(quaiWallet, 0, Zone.Cyprus1, 5); + console.log('Generated Quai addresses for account 0 and zone Cyprus1:', JSON.stringify(addresses, null, 2)); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/wallets/utils.js b/examples/wallets/utils.js index 9e59dd7a..c0cd09da 100644 --- a/examples/wallets/utils.js +++ b/examples/wallets/utils.js @@ -104,9 +104,19 @@ function printPaymentCodeInfo(paymentCodeInfo) { } } +function generateAddresses(wallet, account, zone, count) { + let addresses = []; + for (let i = 0; i < count; i++) { + const addressInfo = wallet.getNextAddressSync(account, zone); + addresses.push(addressInfo); + } + return addresses; +} + module.exports = { printWalletInfo, printAddressTable, printOutpointTable, printPaymentCodeInfo, + generateAddresses, }; From 797426446f8bffad308898a7fbefd2697df7fb05 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Sat, 1 Feb 2025 22:05:31 -0300 Subject: [PATCH 3/4] add new example scripts to 'transactions' --- examples/transactions/qihdwallet-aggregate.js | 99 ++++++++++++++ .../qihdwallet-convert-to-quai.js | 102 ++++++++++++++ .../qihdwallet-sendTransaction.js | 124 ++++++++++++++++++ .../transactions/quaihdwallet-send-quai-tx.js | 91 +++++++++++++ examples/transactions/send-qi-tx.js | 73 ----------- examples/transactions/send-quai-tx.js | 40 ------ 6 files changed, 416 insertions(+), 113 deletions(-) create mode 100644 examples/transactions/qihdwallet-aggregate.js create mode 100644 examples/transactions/qihdwallet-convert-to-quai.js create mode 100644 examples/transactions/qihdwallet-sendTransaction.js create mode 100644 examples/transactions/quaihdwallet-send-quai-tx.js delete mode 100644 examples/transactions/send-qi-tx.js delete mode 100644 examples/transactions/send-quai-tx.js diff --git a/examples/transactions/qihdwallet-aggregate.js b/examples/transactions/qihdwallet-aggregate.js new file mode 100644 index 00000000..df4ef8ed --- /dev/null +++ b/examples/transactions/qihdwallet-aggregate.js @@ -0,0 +1,99 @@ +const { + JsonRpcProvider, + Mnemonic, + QiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * Qi HD Wallet UTXO Aggregation Example + * + * This script demonstrates how to aggregate multiple UTXOs into larger denominations + * in a QiHDWallet. It implements QIP-7 specifications for UTXO management and + * optimization of wallet holdings. + * + * The script demonstrates: + * 1. Creating and connecting a QiHDWallet to a provider + * 2. Scanning the wallet for available UTXOs in a specific zone + * 3. Displaying wallet addresses and current UTXO distribution + * 4. Attempting to aggregate smaller denomination UTXOs into larger ones + * 5. Verifying the aggregation results + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * RPC_URL="your Quai node RPC endpoint" + * + * Then run: + * ``` + * node qihdwallet-aggregate.js + * ``` + * + * The script will output: + * - Wallet addresses (both external and change) + * - Initial balance and UTXO distribution + * - Aggregation transaction details + * - Final balance and updated UTXO distribution + * + * Note: This example uses the Cyprus1 zone for demonstration. The aggregation + * process follows QIP-7 specifications for UTXO management, attempting to combine + * smaller denominations into larger ones when possible. The transaction will fail + * if no beneficial aggregation is possible with the current UTXO set. + */ + +async function main() { + // Create provider + const options = {usePathing: false}; + const provider = new JsonRpcProvider(process.env.RPC_URL, undefined, options); + + // Create wallet and connect to provider + console.log(process.env.RPC_URL) + const aliceMnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const aliceWallet = QiHDWallet.fromMnemonic(aliceMnemonic); + aliceWallet.connect(provider); + + // Scan Alice wallet + console.log("...scanning alice wallet"); + await aliceWallet.scan(Zone.Cyprus1); + + // log alice change wallet addresses + console.log("Alice change wallet addresses: ", aliceWallet.getChangeAddressesForZone(Zone.Cyprus1).map(a => a.address)); + // log alice external wallet addresses + console.log("Alice external wallet addresses: ", aliceWallet.getAddressesForZone(Zone.Cyprus1).map(a => a.address)); + + // Get Alice initial balance + console.log("...getting alice initial balance"); + const aliceInitialBalance = await aliceWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Alice initial balance: ", aliceInitialBalance); + + // log Alice outpoints + console.log("Alice outpoints: ", JSON.stringify(aliceWallet.getOutpoints(Zone.Cyprus1), null, 2)); + + // Send Qi + console.log("...aggregating alice balance"); + const tx = await aliceWallet.aggregate(Zone.Cyprus1); + console.log("... Alice transaction sent. Waiting for receipt..."); + + // Wait for tx to be mined + const txReceipt = await tx.wait(); + console.log("Alice's transaction receipt (block number): ", txReceipt.blockNumber); + + // Get Alice final balance + console.log("...getting alice final balance"); + const aliceFinalBalance = await aliceWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Alice final balance: ", aliceFinalBalance); + + // sync Alice wallet and log outpoints + console.log("...syncing alice wallet and logging outpoints"); + await aliceWallet.scan(Zone.Cyprus1); + console.log("Alice outpoints: ", JSON.stringify(aliceWallet.getOutpoints(Zone.Cyprus1), null, 2)); + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/transactions/qihdwallet-convert-to-quai.js b/examples/transactions/qihdwallet-convert-to-quai.js new file mode 100644 index 00000000..b8362e5a --- /dev/null +++ b/examples/transactions/qihdwallet-convert-to-quai.js @@ -0,0 +1,102 @@ +const { + JsonRpcProvider, + Mnemonic, + QiHDWallet, + QuaiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * Qi to Quai Conversion Example + * + * This script demonstrates how to convert Qi (UTXO-based) tokens to Quai (EVM-based) tokens + * using QiHDWallet. It implements QIP-7 specifications for UTXO management and cross-ledger + * conversion between Qi and Quai ledgers. + * + * The script demonstrates: + * 1. Creating both Qi and Quai HD wallets from the same mnemonic + * 2. Scanning the Qi wallet for available UTXOs in a specific zone + * 3. Displaying wallet addresses and current UTXO distribution + * 4. Converting a specified amount of Qi tokens to Quai tokens + * 5. Verifying the conversion results in both ledgers + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * RPC_URL="your Quai node RPC endpoint" + * + * Then run: + * ``` + * node qihdwallet-convert-to-quai.js + * ``` + * + * The script will output: + * - Qi and Quai wallet addresses + * - Initial Qi balance and UTXO distribution + * - Conversion transaction details + * - Final Quai balance after conversion + * + * Note: This example uses the Cyprus1 zone for demonstration. The conversion + * process follows QIP-7 specifications for cross-ledger operations, allowing + * users to move value between Qi (UTXO) and Quai (EVM) ledgers within the + * same zone. The transaction will fail if insufficient UTXOs are available + * for the requested conversion amount. + */ + +async function main() { + // Create provider + const options = {usePathing: false}; + const provider = new JsonRpcProvider(process.env.RPC_URL, undefined, options); + + // Create wallet and connect to provider + console.log(process.env.RPC_URL) + const aliceMnemonic =Mnemonic.fromPhrase(process.env.MNEMONIC); + const aliceQiWallet =QiHDWallet.fromMnemonic(aliceMnemonic); + aliceQiWallet.connect(provider); + + const aliceQuaiWallet =QuaiHDWallet.fromMnemonic(aliceMnemonic); + aliceQuaiWallet.connect(provider); + // get alice quai address + const aliceQuaiAddressInfo = aliceQuaiWallet.getNextAddressSync(0,Zone.Cyprus1); + console.log("Alice Quai address: ", aliceQuaiAddressInfo.address); + + // Scan Alice wallet + console.log("...scanning alice wallet"); + await aliceQiWallet.scan(Zone.Cyprus1); + + // log alice change wallet addresses + console.log("Alice change wallet addresses: ", aliceQiWallet.getChangeAddressesForZone(Zone.Cyprus1).map(a => a.address)); + // log alice external wallet addresses + console.log("Alice external wallet addresses: ", aliceQiWallet.getAddressesForZone(Zone.Cyprus1).map(a => a.address)); + + // Get Alice initial balance + console.log("...getting alice initial balance"); + const aliceInitialQiBalance = await aliceQiWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Alice initial Qi balance: ", aliceInitialQiBalance); + + // log Alice outpoints + console.log("Alice outpoints: ", JSON.stringify(aliceQiWallet.getOutpoints(Zone.Cyprus1), null, 2)); + + const amountToConvert = 100000; + console.log(`...converting ${amountToConvert} Qi to Quai address ${aliceQuaiAddressInfo.address}`); + + const tx = await aliceQiWallet.convertToQuai(aliceQuaiAddressInfo.address, amountToConvert); + console.log("... Alice transaction sent. Waiting for receipt..."); + + // Wait for tx to be mined + const txReceipt = await tx.wait(); + console.log("Alice's transaction receipt (block number): ", txReceipt.blockNumber); + + // Get Alice updated Quai balance + const aliceUpdatedQuaiBalance = await provider.getBalance(aliceQuaiAddressInfo.address); + console.log("Alice updated Quai balance: ", aliceUpdatedQuaiBalance); + +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/transactions/qihdwallet-sendTransaction.js b/examples/transactions/qihdwallet-sendTransaction.js new file mode 100644 index 00000000..d4964ab0 --- /dev/null +++ b/examples/transactions/qihdwallet-sendTransaction.js @@ -0,0 +1,124 @@ +const { + JsonRpcProvider, + Mnemonic, + QiHDWallet, + Zone, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * Qi HD Wallet Transaction Example + * + * This script demonstrates how to perform UTXO-based transactions using QiHDWallet + * between two parties (Alice and Bob) on the Quai network. It implements BIP-0047 + * payment codes for secure address generation and QIP-7 for UTXO transactions. + * + * The script demonstrates: + * 1. Creating QiHDWallets for both sender (Alice) and receiver (Bob) + * 2. Generating and exchanging payment codes between parties + * 3. Opening payment channels using BIP-0047 + * 4. Scanning wallets for available UTXOs + * 5. Sending Qi tokens from Alice to Bob using payment codes + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="sender's twelve word mnemonic phrase here" + * RPC_URL="your Quai node RPC endpoint" + * + * Then run: + * ``` + * node qihdwallet-sendTransaction.js + * ``` + * + * The script will output: + * - Payment codes for both Alice and Bob + * - Wallet addresses for both parties + * - Initial balances + * - Transaction details and confirmation + * + * Note: This example uses the Cyprus1 zone for demonstration. The QiHDWallet + * implements UTXO-based transactions as specified in QIP-7, with privacy features + * from BIP-0047 payment codes. + */ + +async function main() { + // Create provider + const options = {usePathing: false}; + const provider = new JsonRpcProvider(process.env.RPC_URL, undefined, options); + + // Create wallet and connect to provider + console.log(process.env.RPC_URL) + const aliceMnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const aliceWallet = QiHDWallet.fromMnemonic(aliceMnemonic); + aliceWallet.connect(provider); + + // Get Alice payment code + const alicePaymentCode = aliceWallet.getPaymentCode(0); + console.log("Alice payment code: ", alicePaymentCode); + + // Create Bob wallet + const BOB_MNEMONIC = "innocent perfect bus miss prevent night oval position aspect nut angle usage expose grace juice"; + const bobMnemonic = Mnemonic.fromPhrase(BOB_MNEMONIC); + const bobWallet = QiHDWallet.fromMnemonic(bobMnemonic); + bobWallet.connect(provider); + + // Get Bob payment code + const bobPaymentCode = bobWallet.getPaymentCode(0); + console.log("Bob payment code: ", bobPaymentCode); + + // Open channel + aliceWallet.openChannel(bobPaymentCode); + bobWallet.openChannel(alicePaymentCode); + + // Scan Alice wallet + console.log("...scanning alice wallet"); + await aliceWallet.scan(Zone.Cyprus1); + + // log alice change wallet addresses + console.log("Alice change wallet addresses: ", aliceWallet.getChangeAddressesForZone(Zone.Cyprus1).map(a => a.address)); + // log alice external wallet addresses + console.log("Alice external wallet addresses: ", aliceWallet.getAddressesForZone(Zone.Cyprus1).map(a => a.address)); + + // // Scan Bob wallet + console.log("...scanning bob wallet"); + await bobWallet.scan(Zone.Cyprus1); + + // Get Alice initial balance + console.log("...getting alice initial balance"); + const aliceInitialBalance = await aliceWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Alice initial balance: ", aliceInitialBalance); + + // Get Bob initial balance + console.log("...getting bob initial balance"); + const bobInitialBalance = await bobWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Bob initial balance: ", bobInitialBalance); + + // log Alice outpoints + console.log("Alice outpoints: ", JSON.stringify(aliceWallet.getOutpoints(Zone.Cyprus1), null, 2)); + + // Send Qi + const amountToSendToBob = 15000000; + console.log(`...sending ${amountToSendToBob} qit to Bob`); + const tx = await aliceWallet.sendTransaction(bobPaymentCode, amountToSendToBob, Zone.Cyprus1, Zone.Cyprus1); + console.log("... Alice transaction sent. Waiting for receipt..."); + + // Wait for tx to be mined + const txReceipt = await tx.wait(); + console.log("Alice's transaction receipt received. Block number: ", txReceipt.blockNumber); + + // Scan Bob wallet + console.log("...scanning bob wallet"); + await bobWallet.scan(Zone.Cyprus1); + + // Get Bob final balance + console.log("...getting bob final balance"); + const bobFinalBalance = await bobWallet.getBalanceForZone(Zone.Cyprus1); + console.log("Bob final balance: ", bobFinalBalance); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/transactions/quaihdwallet-send-quai-tx.js b/examples/transactions/quaihdwallet-send-quai-tx.js new file mode 100644 index 00000000..3c8f94dd --- /dev/null +++ b/examples/transactions/quaihdwallet-send-quai-tx.js @@ -0,0 +1,91 @@ +const { + JsonRpcProvider, + Mnemonic, + QuaiHDWallet, + QuaiTransaction, + Zone, +} = require('../../lib/commonjs/quais'); +require('dotenv').config(); + +/** + * Quai HD Wallet Transaction Example + * + * This script demonstrates how to perform EVM-based transactions using QuaiHDWallet + * on the Quai network. It shows the basic functionality of sending Quai tokens + * between addresses within the same wallet. + * + * The script demonstrates: + * 1. Creating and connecting a QuaiHDWallet to a provider + * 2. Generating new addresses within a specific zone + * 3. Checking initial balances + * 4. Sending Quai tokens between addresses + * 5. Verifying transaction completion and final balances + * + * Usage: + * First, set up your .env file with: + * MNEMONIC="your twelve word mnemonic phrase here" + * RPC_URL="your Quai node RPC endpoint" + * + * Then run: + * ``` + * node quaihdwallet-send-quai-tx.js + * ``` + * + * The script will output: + * - Generated sender and receiver addresses + * - Initial balance of the receiver + * - Transaction details and confirmation + * - Final balance after transfer + * + * Note: This example uses the Cyprus1 zone for demonstration. The transaction + * follows standard EVM-based operations, with optional parameters for chainId, + * nonce, gasLimit, and gasPrice that can be customized as needed. The transaction + * will fail if the sender has insufficient funds or if gas parameters are incorrectly + * specified. + */ + + +async function main() { + // Create provider + const options = {usePathing: false}; + const provider = new JsonRpcProvider(process.env.RPC_URL, undefined, options); + + // Create wallet and connect to provider + const mnemonic = Mnemonic.fromPhrase(process.env.MNEMONIC); + const quaiWallet = QuaiHDWallet.fromMnemonic(mnemonic); + quaiWallet.connect(provider); + + // Create tx + const addressInfo1 = await quaiWallet.getNextAddress(0, Zone.Cyprus1); + const from = addressInfo1.address; + const txObj = new QuaiTransaction(from); + const addressInfo2 = await quaiWallet.getNextAddress(0, Zone.Cyprus1); + const to = addressInfo2.address; + txObj.to = to; + const initialBalance = await provider.getBalance(to); + console.log('Initial balance:', initialBalance); + txObj.value = BigInt(420000); + /* + * The following fields are optional, but can be set as follows: + * txObj.chainId = BigInt(9000); + * txObj.nonce = await provider.getTransactionCount(from, 'latest'); + * txObj.gasLimit = BigInt(1000000); + * txObj.gasPrice = BigInt(30000000000000), + */ + + // Sign and send the transaction + const tx = await quaiWallet.sendTransaction(txObj); + + // Wait for tx to be mined + const txReceipt = await tx.wait(); + console.log('\nTx included in block:', txReceipt.blockNumber); + const finalBalance = await provider.getBalance(to); + console.log('Final balance:', finalBalance); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/examples/transactions/send-qi-tx.js b/examples/transactions/send-qi-tx.js deleted file mode 100644 index e6cc9b75..00000000 --- a/examples/transactions/send-qi-tx.js +++ /dev/null @@ -1,73 +0,0 @@ -const quais = require('../../lib/commonjs/quais'); -require('dotenv').config(); - -async function main() { - // Create provider - const provider = new quais.JsonRpcProvider(process.env.RPC_URL); - - // Create wallet and connect to provider - console.log(process.env.RPC_URL) - const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC); - console.log(mnemonic) - const qiWallet = quais.QiHDWallet.fromMnemonic(mnemonic); - qiWallet.connect(provider); - - // Get address info - const addressInfo1 = await qiWallet.getNextAddress(0, quais.Zone.Cyprus1); - const addr1 = addressInfo1.address; - const pubkey1 = addressInfo1.pubKey; - - // Define the outpoints for addr1 (this is just an example outpoint) - // Outpoints are typically obtained via the getOutpointsForAddress function - const outpointsInfo = [ - { - outpoint: { - txhash: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - index: 0, - denomination: 7, - }, - address: addr1, - zone: quais.Zone.Cyprus1, - }, - ]; - - // Polulate wallet with outpoints - qiWallet.importOutpoints(outpointsInfo); - - // Set tx inputs and outputs for the Qi Tx - let txInputs = [ - { - txhash: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - index: 0, - pubkey: pubkey1, - }, - ]; - - let txOutputs = [ - { - address: '0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329', - denomination: 7, - }, - ]; - - // Create the Qi Tx to be signed - const txObj = new quais.QiTransaction(); - txObj.txInputs = txInputs; - txObj.txOutputs = txOutputs; - - // Sign and send the tx - console.log('\nSending Qi Tx...') - const tx = await qiWallet.sendTransaction(txObj); - console.log('\nTx:', tx) - - // Wait for tx to be mined - const txReceipt = await tx.wait(); - console.log('\nTx receipt:', txReceipt); -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); diff --git a/examples/transactions/send-quai-tx.js b/examples/transactions/send-quai-tx.js deleted file mode 100644 index c5d36b2f..00000000 --- a/examples/transactions/send-quai-tx.js +++ /dev/null @@ -1,40 +0,0 @@ -const quais = require('../../lib/commonjs/quais'); -require('dotenv').config(); - -async function main() { - // Create provider - const provider = new quais.JsonRpcProvider(process.env.RPC_URL); - - // Create wallet and connect to provider - const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC); - const quaiWallet = quais.QuaiHDWallet.fromMnemonic(mnemonic); - quaiWallet.connect(provider); - - // Create tx - const addressInfo1 = await quaiWallet.getNextAddress(0, quais.Zone.Cyprus1); - const from = addressInfo1.address; - const txObj = new quais.QuaiTransaction(from); - txObj.to = '0x002F4783248e2D6FF1aa6482A8C0D7a76de3C329'; - txObj.value = BigInt(4200000); - /* - * The following fields are optional, but can be set as follows: - * txObj.chainId = BigInt(9000); - * txObj.nonce = await provider.getTransactionCount(from, 'latest'); - * txObj.gasLimit = BigInt(1000000); - * txObj.gasPrice = BigInt(30000000000000), - */ - - // Sign and send the transaction - const tx = await quaiWallet.sendTransaction(txObj); - - // Wait for tx to be mined - const txReceipt = await tx.wait(); - console.log('\nTx receipt:', txReceipt); -} - -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); From 5389c91986885cbffb6e9ace6f7c15299f15ca70 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Mon, 3 Feb 2025 11:15:49 -0600 Subject: [PATCH 4/4] removed unused block fields from formater --- src/_tests/integration/providerdata.integration.test.ts | 3 --- src/providers/format.ts | 3 --- src/providers/formatting.ts | 3 --- src/providers/provider.ts | 6 ------ 4 files changed, 15 deletions(-) diff --git a/src/_tests/integration/providerdata.integration.test.ts b/src/_tests/integration/providerdata.integration.test.ts index a8b3a1d4..1f5c1b8c 100644 --- a/src/_tests/integration/providerdata.integration.test.ts +++ b/src/_tests/integration/providerdata.integration.test.ts @@ -241,9 +241,6 @@ describe.skip('Test Provider Block operations', function () { uncledEntropy: BigInt(rpcBlock.header.uncledEntropy), utxoRoot: rpcBlock.header.utxoRoot, exchangeRate: BigInt(rpcBlock.header.exchangeRate), - quaiToQi: BigInt(rpcBlock.header.quaiToQi), - qiToQuai: BigInt(rpcBlock.header.qiToQuai), - secondaryCoinbase: rpcBlock.header.secondaryCoinbase, }, interlinkHashes: rpcBlock.interlinkHashes, size: BigInt(rpcBlock.size), diff --git a/src/providers/format.ts b/src/providers/format.ts index a223d1c2..001ee2ad 100644 --- a/src/providers/format.ts +++ b/src/providers/format.ts @@ -177,10 +177,7 @@ const _formatHeader = object({ transactionsRoot: formatHash, uncledEntropy: getBigInt, utxoRoot: formatHash, - secondaryCoinbase: allowNull(getAddress), exchangeRate: getBigInt, - quaiToQi: getBigInt, - qiToQuai: getBigInt, }); const _formatUncle = object({ diff --git a/src/providers/formatting.ts b/src/providers/formatting.ts index b653bef1..da703add 100644 --- a/src/providers/formatting.ts +++ b/src/providers/formatting.ts @@ -54,9 +54,6 @@ export interface BlockHeaderParams { uncledEntropy: bigint; utxoRoot: string; exchangeRate: bigint; - quaiToQi: bigint; - qiToQuai: bigint; - secondaryCoinbase: string; } export interface UncleParams { diff --git a/src/providers/provider.ts b/src/providers/provider.ts index 5eb1a448..6451bbea 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -474,9 +474,6 @@ export class BlockHeader implements BlockHeaderParams { readonly uncledEntropy: bigint; readonly utxoRoot!: string; readonly exchangeRate!: bigint; - readonly quaiToQi!: bigint; - readonly qiToQuai!: bigint; - readonly secondaryCoinbase!: string; constructor(params: BlockHeaderParams) { this.baseFeePerGas = params.baseFeePerGas; @@ -509,9 +506,6 @@ export class BlockHeader implements BlockHeaderParams { this.uncledEntropy = params.uncledEntropy; this.utxoRoot = params.utxoRoot; this.exchangeRate = params.exchangeRate; - this.quaiToQi = params.quaiToQi; - this.qiToQuai = params.qiToQuai; - this.secondaryCoinbase = params.secondaryCoinbase; } toJSON(): BlockHeaderParams {