PHP WebShell

Текущая директория: /opt/BitGoJS/examples/ts/btc/lightning

Просмотр файла: create-self-custody-lightning-wallet.ts

/**
 * Create a Lightning self-custodial wallet at BitGo.
 *
 * IMPORTANT: Your BitGo account must have the "custodyLightningWallet" license
 * enabled to use this functionality. Contact BitGo support if you receive a
 * license-related error.
 *
 * Copyright 2025, BitGo, Inc.  All Rights Reserved.
 */

import { BitGoAPI } from '@bitgo/sdk-api';
import { Tlnbtc } from '@bitgo/sdk-coin-lnbtc';
import * as crypto from 'crypto';

// TODO: set access token for testnet
// Get this from your BitGo account
const accessToken = '';

// TODO: set passphrase to create a wallet
const passphrase = '';

// TODO: set your enterprise ID
const enterprise = '';

// Generate a passcode encryption code (required for Lightning wallets)
// IMPORTANT: Store this information securely. You will need it to recover your wallet if you lose wallet password.
const passcodeEncryptionCode = process.env.PASSCODE_ENCRYPTION_CODE || crypto.randomBytes(32).toString('hex');

// Use tlnbtc for testnet, lnbtc for mainnet
const coin = 'tlnbtc';

/**
 * Create a Lightning self-custodial wallet
 * This function creates a self-custodial Lightning wallet on the BitGo platform
 * @returns {Promise<void>} Wallet object
 */
async function main(): Promise<void> {
  try {
    const bitgo = new BitGoAPI({
      accessToken,
      env: 'test',
    });

    // Register Lightning Bitcoin coin
    bitgo.register(coin, Tlnbtc.createInstance);

    // Create unique label for the wallet
    const label = `Lightning Self-Custodial Wallet ${new Date().toISOString()}`;

    // Configure wallet creation options
    const walletOptions = {
      label,
      passphrase,
      enterprise,
      passcodeEncryptionCode,
      subType: 'lightningSelfCustody' as const,
    };

    console.log('Creating Lightning self-custodial wallet...');
    console.log('Note: This requires the custodyLightningWallet license on your BitGo account.');

    const wallet = await bitgo.coin(coin).wallets().generateWallet(walletOptions);
    const walletInstance = wallet.wallet;

    // Display wallet information
    console.log('\nWallet created successfully:');
    console.log(`Wallet ID: ${walletInstance.id()}`);
    console.log(`Wallet label: ${walletInstance.label()}`);
    console.log(`Wallet type: ${walletInstance.type()}`);
    console.log(`Wallet subType: ${walletInstance.subType()}`);

    // Display backup information
    console.log('\nIMPORTANT - BACKUP THIS INFORMATION:');
    console.log(`User keychain encrypted xPrv: ${wallet.userKeychain.encryptedPrv}`);

    // CRITICAL: Node Auth keychain is required for self-custodial Lightning wallets
    console.log(`Passcode Encryption Code: ${passcodeEncryptionCode}`);
    console.log('\nStore this information securely. You will need it to recover your wallet.');
  } catch (e) {
    throw e;
  }
}

// Run the example
main()
  .then(() => {
    console.log('Example completed successfully.');
    process.exit(0);
  })
  .catch((e) => {
    console.error('Example failed with error:', e.message);
    process.exit(-1);
  });

Выполнить команду


Для локальной разработки. Не используйте в интернете!