Skip to content

Commit

Permalink
add example script for qi addresses derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 committed Oct 29, 2024
1 parent ebff3e7 commit 8952a2e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
75 changes: 75 additions & 0 deletions examples/wallets/qi-wallet-derive-addresses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const quais = require('../../lib/commonjs/quais');
require('dotenv').config();
const { printAddressTable } = require('./utils');

async function main() {

const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC);

const aliceQiWallet = quais.QiHDWallet.fromMnemonic(mnemonic);

console.log('Generating 5 Qi addresses for Cyprus1:');
const cyprus1Addresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextAddress(0, quais.Zone.Cyprus1);
cyprus1Addresses.push(addressInfo);
}
printAddressTable(cyprus1Addresses);

console.log('Generating 5 Qi addresses for Cyprus2:');
const cyprus2Addresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextAddress(0, quais.Zone.Cyprus2);
cyprus2Addresses.push(addressInfo);
}
printAddressTable(cyprus2Addresses);

console.log('Generating 5 Qi change addresses for Cyprus1:');
const cyprus1ChangeAddresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextChangeAddress(0, quais.Zone.Cyprus1);
cyprus1ChangeAddresses.push(addressInfo);
}
printAddressTable(cyprus1ChangeAddresses);

console.log('Generating 5 Qi change addresses for Cyprus2:');
const cyprus2ChangeAddresses = [];

for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextChangeAddress(0, quais.Zone.Cyprus2);
cyprus2ChangeAddresses.push(addressInfo);
}
printAddressTable(cyprus2ChangeAddresses);

const bobMnemonic = quais.Mnemonic.fromPhrase("innocent perfect bus miss prevent night oval position aspect nut angle usage expose grace juice");
const bobaliceQiWallet = quais.QiHDWallet.fromMnemonic(bobMnemonic);
const bobPaymentCode = bobaliceQiWallet.getPaymentCode(0);
aliceQiWallet.openChannel(bobPaymentCode);

console.log('Generating 5 Qi send addresses for Cyprus1:');
const cyprus1PaymentCodeSendAddresses = [];
for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextSendAddress(bobPaymentCode, quais.Zone.Cyprus1);
cyprus1PaymentCodeSendAddresses.push(addressInfo);
}
printAddressTable(cyprus1PaymentCodeSendAddresses);

console.log('Generating 5 Qi receive addresses for Cyprus1:');
const cyprus1PaymentCodeReceivedAddresses = [];
for (let i = 0; i < 5; i++) {
const addressInfo = await aliceQiWallet.getNextReceiveAddress(bobPaymentCode, quais.Zone.Cyprus1);
cyprus1PaymentCodeReceivedAddresses.push(addressInfo);
}
printAddressTable(cyprus1PaymentCodeReceivedAddresses);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

3 changes: 3 additions & 0 deletions examples/wallets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,7 @@ function printPaymentCodeInfo(paymentCodeInfo) {

module.exports = {
printWalletInfo,
printAddressTable,
printOutpointTable,
printPaymentCodeInfo
};

0 comments on commit 8952a2e

Please sign in to comment.