aboutsummaryrefslogtreecommitdiffstats
path: root/config/dev.env.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-06-16 16:30:31 -0700
committerAdam Soltys <[email protected]>2021-06-16 16:30:31 -0700
commitfe6011b5602608c2b6f737f26652a8966139f562 (patch)
treee4efcf628e4dab7921598de4fc54db2b1d7ec022 /config/dev.env.js
parentfb1228c5b5bd0b0f61261cc6c46e926e0fe451c3 (diff)
downloadcoinos-server-fe6011b5602608c2b6f737f26652a8966139f562.tar.gz
coinos-server-fe6011b5602608c2b6f737f26652a8966139f562.zip
remove redundant funding routes
Diffstat (limited to 'config/dev.env.js')
0 files changed, 0 insertions, 0 deletions
r: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Regtest end-to-end test for the native-JS arkoor SEND path (MuSig2 cosign).
//
// Spends the VTXO received in receive-test.js: pays alice (bark CLI) 4000 sat
// with change back to a fresh key of ours, entirely from JS.
//
// Usage: bun tools/ark/send-test.js  (run receive-test.js first to get funded)

import { execSync } from 'node:child_process';
import { mnemonicToSeedSync } from '@scure/bip39';
import { HDKey } from '@scure/bip32';
import { hex } from '@scure/base';
import { secp256k1 } from '@noble/curves/secp256k1';

import { getArkInfo, decodeAddress, readMailbox, decodeVtxo } from '../../src/ark/proto.js';
import {
  buildArkoorSend, cosignWithServer, buildSignedVtxoBytes,
  registerVtxoTransactions, postArkoorMessage,
} from '../../src/ark/send.js';

const ARK = process.env.ARK_URL || 'http://127.0.0.1:3535';
const BARK = `${process.env.HOME}/bark/target/debug/bark`;
const ALICE = `${BARK} --datadir ${process.env.HOME}/ark-regtest/alice`;
const SEND_SAT = 4000;

const MNEMONIC = 'rug rebuild abstract kiwi rifle vast food robust rifle spirit dilemma stumble';
const seed = mnemonicToSeedSync(MNEMONIC);
const master = HDKey.fromMasterSeed(seed);
const kp = (path) => {
  const k = master.derive(path);
  return { privkey: k.privateKey, pubkey: secp256k1.getPublicKey(k.privateKey, true) };
};
const keys = { vtxo: kp("m/350'/0'/0'"), mailbox: kp("m/350'/1'/0'"), change: kp("m/350'/0'/1'") };

const info = await getArkInfo(ARK);
const serverPubkey = hex.decode(info.serverPubkey);

// --- find our latest vtxo from the mailbox ---
const { messages } = await readMailbox(ARK, keys.mailbox);
const vtxos = messages.filter((m) => m.kind === 'arkoor').flatMap((m) => m.vtxos)
  .filter((v) => v.policy.userPubkey === hex.encode(keys.vtxo.pubkey));
if (!vtxos.length) { console.error('no vtxos in mailbox — run receive-test.js first'); process.exit(1); }
const input = vtxos[vtxos.length - 1];
console.log(`input vtxo: ${input.id} (${input.amountSat} sat, genesis depth ${input.genesis.length})`);

// --- alice's address -> destination pubkey + her blinded mailbox id ---
const aliceAddr = execSync(`${ALICE} -q address`).toString().trim();
const alice = decodeAddress(aliceAddr);
console.log(`alice pubkey: ${alice.userPubkey}`);
const aliceBlindedId = hex.decode(alice.delivery.find((d) => d.type === 1).data);

const outputs = [
  { amountSat: SEND_SAT, userPubkey: hex.decode(alice.userPubkey) },
  { amountSat: input.amountSat - SEND_SAT, userPubkey: keys.change.pubkey },
];

const aliceBalanceBefore = JSON.parse(execSync(`${ALICE} -q balance`).toString()).spendable_sat;

// --- 1. pre-register our input chain ---
await registerVtxoTransactions(ARK, [input._raw.bytes]);
console.log('input chain registered with server');

// --- 2. build txs + sighashes ---
const build = buildArkoorSend({ input, outputs, serverPubkey, vtxoKeys: keys.vtxo });
console.log(`checkpoint txid: ${hex.encode(build.checkpointTxid.slice().reverse())}`);
console.log(`sighashes: ${build.sighashes.length} (1 checkpoint + ${outputs.length} arkoor)`);

// --- 3. MuSig2 cosign ceremony with the ASP ---
const finalSigs = await cosignWithServer(ARK, build, { input, outputs, vtxoKeys: keys.vtxo, serverPubkey });
console.log(`✓ ${finalSigs.length} MuSig2 signatures combined and verified against taproot output keys`);

// --- 4. assemble signed vtxos, round-trip check, register, deliver ---
const destBytes = buildSignedVtxoBytes({ input, outputs, build, finalSigs, serverPubkey, idx: 0 });
const changeBytes = buildSignedVtxoBytes({ input, outputs, build, finalSigs, serverPubkey, idx: 1 });
const dest = decodeVtxo(destBytes); // local round-trip sanity check
console.log(`destination vtxo: ${dest.id} (${dest.amountSat} sat, depth ${dest.genesis.length})`);
const change = decodeVtxo(changeBytes);
console.log(`change vtxo:      ${change.id} (${change.amountSat} sat) -> our change key`);

await registerVtxoTransactions(ARK, [destBytes, changeBytes]);
console.log('signed vtxos registered with server');

await postArkoorMessage(ARK, aliceBlindedId, [destBytes]);
console.log('posted to alice\'s mailbox');

// --- 5. verify alice received it (balance triggers a wallet sync) ---
const aliceBalanceAfter = JSON.parse(execSync(`${ALICE} -q balance`).toString()).spendable_sat;
console.log(`\nalice balance: ${aliceBalanceBefore} -> ${aliceBalanceAfter} sat`);

if (aliceBalanceAfter === aliceBalanceBefore + SEND_SAT) {
  console.log(`\n✅ SUCCESS: native-JS wallet sent ${SEND_SAT} sat over Ark via MuSig2 cosign — bark CLI accepted the vtxo`);
} else {
  console.log('\n❌ alice balance did not increase as expected');
  process.exit(1);
}