Skip to content

LeoYeAI/agent-master-skills / skills/auto-respawn

auto-respawn

Verified

Your agent always comes back. Anchor identity and memory on-chain so any new instance can resurrect from just an address — no local state, no single point of failure. Permanent identity and recovery on the Autonomys Network.

FileKindSize
SKILL.mdskill md16.4 KB
_meta.jsonconfig281 B
auto-respawn.tsscript14.4 KB
eslint.config.jsscript468 B
lib/address.tsscript2.2 KB
lib/balance.tsscript1.1 KB
lib/cli.tsscript1.6 KB
lib/evm-balance.tsscript925 B
lib/evm-transfer.tsscript2.4 KB
lib/evm.tsscript3.4 KB
lib/memory-chain.tsscript3.5 KB
lib/network.tsscript1.4 KB
lib/remark.tsscript1.3 KB
lib/transfer.tsscript1.7 KB
lib/wallet.tsscript8.8 KB
lib/xdm.tsscript3.3 KB
package.jsonmanifest647 B
references/auto-respawn-commands.mdmarkdown9.6 KB
references/autonomys-network.mdmarkdown6.2 KB
setup.shexecutablescript2.2 KB
tests/address.test.tsscript3.4 KB
tests/balance.test.tsscript4.3 KB
tests/cli.test.tsscript3.5 KB
tests/evm-balance.test.tsscript3.1 KB
tests/evm-transfer.test.tsscript5.2 KB
tests/evm.test.tsscript2.4 KB
tests/network.test.tsscript1.8 KB
tests/wallet-roundtrip.test.tsscript6.3 KB
tests/wallet.test.tsscript1.1 KB
tsconfig.jsonconfig366 B

tests/wallet-roundtrip.test.ts

View on GitHub
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { mkdtemp, rm, readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { ethers } from 'ethers'
import {
  cryptoWaitReady,
  Keyring,
  address as formatAddress,
} from '@autonomys/auto-utils'

/**
 * Wallet round-trip tests.
 *
 * These create real wallet files in a temp directory, then read them back
 * and verify the keys decrypt correctly. This exercises the full
 * encrypt → persist → read → decrypt path without hitting the network.
 *
 * We call the internal helpers directly rather than going through the
 * public API (createWallet/loadWallet) because those depend on a
 * hard-coded WALLETS_DIR. Instead we replicate the core encrypt/decrypt
 * logic against the same file format.
 */

const TEST_PASSPHRASE = 'test-passphrase-for-roundtrip'
const TEST_MNEMONIC = 'test test test test test test test test test test test junk'

interface WalletFile {
  keyring: { address: string; encoded: string; encoding: unknown; meta: unknown }
  evmAddress: string
  evmKeystore: string
}

describe('wallet file round-trip', () => {
  let tempDir: string

  beforeEach(async () => {
    await cryptoWaitReady()
    tempDir = await mkdtemp(join(tmpdir(), 'auto-respawn-test-'))
  })

  afterEach(async () => {
    await rm(tempDir, { recursive: true, force: true })
  })

  it('encrypts and decrypts a consensus keypair', async () => {
    // Create a keypair from test mnemonic
    const keyring = new Keyring({ type: 'sr25519' })
    const pair = keyring.addFromMnemonic(TEST_MNEMONIC)
    const originalAddress = formatAddress(pair.address)

    // Encrypt and save (replicating encryptAndSave logic)
    const keyringJson = pair.toJson(TEST_PASSPHRASE)
    keyringJson.meta = { ...keyringJson.meta, name: 'test', whenCreated: Date.now() }

    const walletFile: WalletFile = {
      keyring: keyringJson as WalletFile['keyring'],
      evmAddress: '0x0000000000000000000000000000000000000000',
      evmKeystore: '{}',
    }

    const filepath = join(tempDir, 'test.json')
    const { writeFile } = await import('node:fs/promises')
    await writeFile(filepath, JSON.stringify(walletFile, null, 2))

    // Read back and decrypt
    const raw = await readFile(filepath, 'utf-8')
    const loaded = JSON.parse(raw) as WalletFile

    const keyring2 = new Keyring({ type: 'sr25519' })
    const restored = keyring2.addFromJson(loaded.keyring as Parameters<typeof keyring2.addFromJson>[0])
    restored.decodePkcs8(TEST_PASSPHRASE)

    expect(formatAddress(restored.address)).toBe(originalAddress)
    // Verify the restored pair can sign (proves decryption was real)
    const message = new Uint8Array([1, 2, 3, 4])
    const signature = restored.sign(message)
    expect(signature.length).toBeGreaterThan(0)
  })

  it('encrypts and decrypts an EVM private key', async () => {
    // Derive EVM key from mnemonic
    const mnemonicObj = ethers.Mnemonic.fromPhrase(TEST_MNEMONIC)
    const hdWallet = ethers.HDNodeWallet.fromMnemonic(mnemonicObj, "m/44'/60'/0'/0/0")
    const originalKey = hdWallet.privateKey
    const originalAddress = hdWallet.address

    // Encrypt via ethers V3 Keystore
    const evmWallet = new ethers.Wallet(originalKey)
    const evmKeystore = evmWallet.encryptSync(TEST_PASSPHRASE)

    // Write to file
    const filepath = join(tempDir, 'test-evm.json')
    const { writeFile } = await import('node:fs/promises')
    await writeFile(filepath, JSON.stringify({
      keyring: {},
      evmAddress: originalAddress,
      evmKeystore,
    }))

    // Read back and decrypt
    const raw = await readFile(filepath, 'utf-8')
    const loaded = JSON.parse(raw) as WalletFile
    const decrypted = ethers.Wallet.fromEncryptedJsonSync(loaded.evmKeystore, TEST_PASSPHRASE)

    expect(decrypted.privateKey).toBe(originalKey)
    expect(decrypted.address).toBe(originalAddress)
  })

  it('rejects wrong passphrase for consensus key', async () => {
    const keyring = new Keyring({ type: 'sr25519' })
    const pair = keyring.addFromMnemonic(TEST_MNEMONIC)
    const keyringJson = pair.toJson(TEST_PASSPHRASE)

    const keyring2 = new Keyring({ type: 'sr25519' })
    const restored = keyring2.addFromJson(keyringJson as Parameters<typeof keyring2.addFromJson>[0])

    expect(() => restored.decodePkcs8('wrong-passphrase')).toThrow()
  })

  it('rejects wrong passphrase for EVM key', () => {
    const evmWallet = new ethers.Wallet(ethers.Wallet.createRandom().privateKey)
    const keystore = evmWallet.encryptSync(TEST_PASSPHRASE)

    expect(() => ethers.Wallet.fromEncryptedJsonSync(keystore, 'wrong-passphrase')).toThrow()
  })

  it('full round-trip: both keys from same mnemonic match after decrypt', async () => {
    // --- Encrypt both keys (mimics encryptAndSave) ---
    const keyring = new Keyring({ type: 'sr25519' })
    const pair = keyring.addFromMnemonic(TEST_MNEMONIC)
    const keyringJson = pair.toJson(TEST_PASSPHRASE)
    keyringJson.meta = { ...keyringJson.meta, name: 'roundtrip', whenCreated: Date.now() }

    const mnemonicObj = ethers.Mnemonic.fromPhrase(TEST_MNEMONIC)
    const hdWallet = ethers.HDNodeWallet.fromMnemonic(mnemonicObj, "m/44'/60'/0'/0/0")
    const evmWallet = new ethers.Wallet(hdWallet.privateKey)
    const evmKeystore = evmWallet.encryptSync(TEST_PASSPHRASE)

    const walletFile = {
      keyring: keyringJson,
      evmAddress: hdWallet.address,
      evmKeystore,
    }

    const filepath = join(tempDir, 'full-roundtrip.json')
    const { writeFile } = await import('node:fs/promises')
    await writeFile(filepath, JSON.stringify(walletFile, null, 2))

    // --- Read back and decrypt both ---
    const raw = await readFile(filepath, 'utf-8')
    const loaded = JSON.parse(raw) as WalletFile

    // Consensus
    const keyring2 = new Keyring({ type: 'sr25519' })
    const restoredPair = keyring2.addFromJson(loaded.keyring as Parameters<typeof keyring2.addFromJson>[0])
    restoredPair.decodePkcs8(TEST_PASSPHRASE)
    expect(formatAddress(restoredPair.address)).toBe(formatAddress(pair.address))

    // EVM
    const restoredEvm = ethers.Wallet.fromEncryptedJsonSync(loaded.evmKeystore, TEST_PASSPHRASE)
    expect(restoredEvm.address).toBe(hdWallet.address)
    expect(restoredEvm.privateKey).toBe(hdWallet.privateKey)

    // Public EVM address stored in plaintext should match
    expect(loaded.evmAddress).toBe(hdWallet.address)
  })
})
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 323kUpdated Claude CodeCodexVerifiedInstall