|
| 1 | +#!/usr/bin/env npx tsx |
| 2 | +/** |
| 3 | + * Stage 1: Bootstrap CI smoke-test wallets. |
| 4 | + * |
| 5 | + * Reads mnemonic secrets from env vars, derives payment addresses, |
| 6 | + * authenticates the bot, creates 3 wallet variants (legacy, hierarchical, |
| 7 | + * SDK-based), and writes versioned context JSON for downstream stages. |
| 8 | + * |
| 9 | + * Required env vars: |
| 10 | + * API_BASE_URL - Base URL of the multisig API |
| 11 | + * SIGNER_MNEMONIC_1 - Space-separated mnemonic for signer 1 |
| 12 | + * SIGNER_MNEMONIC_2 - Space-separated mnemonic for signer 2 |
| 13 | + * BOT_KEY_ID - Bot key ID for authentication |
| 14 | + * BOT_SECRET - Bot secret for authentication |
| 15 | + * BOT_MNEMONIC - Space-separated mnemonic for bot wallet |
| 16 | + * |
| 17 | + * Usage: |
| 18 | + * npx tsx scripts/ci-smoke/create-wallets.ts |
| 19 | + */ |
| 20 | +import { derivePaymentAddress, mnemonicFromEnv, requireEnv } from "./lib/keys"; |
| 21 | +import { writeContext } from "./lib/context"; |
| 22 | +import { botAuth, createWallet } from "../bot-ref/bot-client"; |
| 23 | +import type { Context } from "./scenarios/types"; |
| 24 | + |
| 25 | +const REQUIRED_ENV_VARS = [ |
| 26 | + "API_BASE_URL", |
| 27 | + "SIGNER_MNEMONIC_1", |
| 28 | + "SIGNER_MNEMONIC_2", |
| 29 | + "BOT_MNEMONIC", |
| 30 | + "BOT_KEY_ID", |
| 31 | + "BOT_SECRET", |
| 32 | +]; |
| 33 | + |
| 34 | +const NETWORK_ID = 0; // preprod |
| 35 | + |
| 36 | +async function main() { |
| 37 | + const missing = REQUIRED_ENV_VARS.filter((v) => !process.env[v]); |
| 38 | + if (missing.length > 0) { |
| 39 | + console.error("Smoke test skipped: missing env vars:", missing.join(", ")); |
| 40 | + console.error("Configure the SMOKE_* secrets in GitHub repository settings."); |
| 41 | + process.exit(0); |
| 42 | + } |
| 43 | + |
| 44 | + const baseUrl = requireEnv("API_BASE_URL"); |
| 45 | + |
| 46 | + console.log("Deriving signer addresses..."); |
| 47 | + const signer1Mnemonic = mnemonicFromEnv("SIGNER_MNEMONIC_1"); |
| 48 | + const signer2Mnemonic = mnemonicFromEnv("SIGNER_MNEMONIC_2"); |
| 49 | + const botMnemonic = mnemonicFromEnv("BOT_MNEMONIC"); |
| 50 | + |
| 51 | + const [signer1Addr, signer2Addr, botAddr] = await Promise.all([ |
| 52 | + derivePaymentAddress(signer1Mnemonic, NETWORK_ID), |
| 53 | + derivePaymentAddress(signer2Mnemonic, NETWORK_ID), |
| 54 | + derivePaymentAddress(botMnemonic, NETWORK_ID), |
| 55 | + ]); |
| 56 | + |
| 57 | + console.log(`Signer 1: ${signer1Addr}`); |
| 58 | + console.log(`Signer 2: ${signer2Addr}`); |
| 59 | + console.log(`Bot: ${botAddr}`); |
| 60 | + |
| 61 | + console.log("Authenticating bot..."); |
| 62 | + const botKeyId = requireEnv("BOT_KEY_ID"); |
| 63 | + const botSecret = requireEnv("BOT_SECRET"); |
| 64 | + const { token, botId } = await botAuth({ |
| 65 | + baseUrl, |
| 66 | + botKeyId, |
| 67 | + secret: botSecret, |
| 68 | + paymentAddress: botAddr, |
| 69 | + }); |
| 70 | + |
| 71 | + console.log("Creating legacy wallet (2 signers, atLeast 1)..."); |
| 72 | + const legacy = await createWallet(baseUrl, token, { |
| 73 | + name: `CI-Legacy-${Date.now()}`, |
| 74 | + description: "CI smoke: legacy 2-of-1", |
| 75 | + signersAddresses: [signer1Addr, botAddr], |
| 76 | + signersDescriptions: ["Signer1", "Bot"], |
| 77 | + numRequiredSigners: 1, |
| 78 | + scriptType: "atLeast", |
| 79 | + network: NETWORK_ID, |
| 80 | + }); |
| 81 | + console.log(` Legacy wallet: ${legacy.walletId} (${legacy.address})`); |
| 82 | + |
| 83 | + console.log("Creating hierarchical wallet (2 signers + stake/DRep, atLeast 2)..."); |
| 84 | + const hierarchical = await createWallet(baseUrl, token, { |
| 85 | + name: `CI-Hierarchical-${Date.now()}`, |
| 86 | + description: "CI smoke: hierarchical 2-of-2 with stake+DRep", |
| 87 | + signersAddresses: [signer1Addr, signer2Addr], |
| 88 | + signersDescriptions: ["Signer1", "Signer2"], |
| 89 | + numRequiredSigners: 2, |
| 90 | + scriptType: "atLeast", |
| 91 | + network: NETWORK_ID, |
| 92 | + }); |
| 93 | + console.log(` Hierarchical wallet: ${hierarchical.walletId} (${hierarchical.address})`); |
| 94 | + |
| 95 | + console.log("Creating SDK wallet (3 signers, atLeast 2)..."); |
| 96 | + const sdk = await createWallet(baseUrl, token, { |
| 97 | + name: `CI-SDK-${Date.now()}`, |
| 98 | + description: "CI smoke: SDK 3-of-2", |
| 99 | + signersAddresses: [signer1Addr, signer2Addr, botAddr], |
| 100 | + signersDescriptions: ["Signer1", "Signer2", "Bot"], |
| 101 | + numRequiredSigners: 2, |
| 102 | + scriptType: "atLeast", |
| 103 | + network: NETWORK_ID, |
| 104 | + }); |
| 105 | + console.log(` SDK wallet: ${sdk.walletId} (${sdk.address})`); |
| 106 | + |
| 107 | + const ctx: Context = { |
| 108 | + version: "1", |
| 109 | + baseUrl, |
| 110 | + botToken: token, |
| 111 | + botId, |
| 112 | + botAddress: botAddr, |
| 113 | + signerAddresses: [signer1Addr, signer2Addr], |
| 114 | + wallets: { |
| 115 | + legacy: { id: legacy.walletId, address: legacy.address }, |
| 116 | + hierarchical: { id: hierarchical.walletId, address: hierarchical.address }, |
| 117 | + sdk: { id: sdk.walletId, address: sdk.address }, |
| 118 | + }, |
| 119 | + }; |
| 120 | + |
| 121 | + writeContext(ctx); |
| 122 | + console.log("\nBootstrap complete. Context written to ci-artifacts/bootstrap-context.json"); |
| 123 | +} |
| 124 | + |
| 125 | +main().catch((e) => { |
| 126 | + console.error("Bootstrap failed:", e); |
| 127 | + process.exit(1); |
| 128 | +}); |
0 commit comments