* feat: move spend/view key symbols to the monero.ts implementation * feat: add integration tests for `0001-polyseed.patch` * feat(monero.ts): add support for backgroundSync and closing the wallet * feat: add integration tests for `0002-wallet-background-sync-with-just-the-view-key.patch` * feat!: require users to provide own node url BREAKING CHANGE: Requires users manual call to `Wallet.initWallet` after wallet creation with preferred node url * feat: add background sync test for `0002-wallet-background-sync-with-just-the-view-key.patch` * ci: add integration tests step * feat(monero.ts): support creating and recovering wallet from polyseed * feat: actually test polyseeds in the integration test * chore: remove legacy comments * fix: uncomment getting moneroC * feat(monero.ts): add support for reading wallet's seed * feat: add seed test for `0009-Add-recoverDeterministicWalletFromSpendKey.patch` * chore: slight refactor * feat(monero.ts): add bindings for `setOffline` and `isOffline` * feat: add integration tests for `0012-WIP-UR-functions.patch` * fix: use correct node depending on the coin * fix: prevent segfaults on wownero * feat(monero.ts): add partial bindings for `Coins` and `CoinsInfo` * feat: add integration tests for `0004-coin-control.patch` * fix coin control * clean up console.logs * chore: comment out the entire block * dev: add devcontainer config for deno * fix(monero.ts): invalid PendingTransactionPtr brand * feat(monero.ts): add bindings for retrieving keys and managing transactions * feat: improve `0012-WIP-UR-functions.patch` tests to follow the airgap doc * fix(monero.ts): make UR methods optional so wownero can load properly * remove flaky balance assertions * tests: add a little bit of delay to make 0002 patch test less flake-y * tests: run wallet transaction tests on ci * enable logging to determine why it segfaults on ci * add delay to every syncBlockchain call * its console logging time * even more console.logs * eep * eep more * dont assert that its not frozen * remove console.logs * fix(monero.ts): type typo becoming a default value * feat(monero.ts): add bindings for `createTransactionMultDest` * feat(monero.ts): support returning multiple values whenever necessary * feat(monero.ts): add missing reexports * feat(monero.ts)!: rewrite bindings BREAKING CHANGES!: - Calls to methods no longer automatically throw errors, you should take care of handling errors yourself - This means the whole sanitizer ordeal is gone, no more sanitize arguments etc. - Some misplaced methods have been moved to their "proper" place, e.g. creating Wallet is now possible using WalletManager instance methods, instead of passing WalletManager instance to Wallet's static method - Return types probably changed in places, methods were inconsitent about returning string or empty string and `string | null`, now its always `string | null` - Every available symbol should now be available in `symbols`, even for the things that are not yet implemented, so you can access them in that case * tests: adapt tests to monero.ts changes * tests: reuse dylib in tests --------- Co-authored-by: cyan <cyjan@mrcyjanek.net>
132 lines
3.9 KiB
TypeScript
Executable File
132 lines
3.9 KiB
TypeScript
Executable File
import { build$, CommandBuilder } from "jsr:@david/dax";
|
|
|
|
export const $ = build$({
|
|
commandBuilder: new CommandBuilder()
|
|
.printCommand(true)
|
|
.stdin("inherit")
|
|
.stdout("inherit")
|
|
.stderr("inherit"),
|
|
});
|
|
|
|
type Coin = "monero" | "wownero";
|
|
|
|
export async function downloadMoneroCli() {
|
|
const MONERO_CLI_FILE_NAME = "monero-linux-x64-v0.18.3.4";
|
|
const MONERO_WALLET_CLI_URL = `https://downloads.getmonero.org/cli/${MONERO_CLI_FILE_NAME}.tar.bz2`;
|
|
|
|
await $`wget -q -o /dev/null ${MONERO_WALLET_CLI_URL}`;
|
|
await $
|
|
.raw`tar -xf ${MONERO_CLI_FILE_NAME}.tar.bz2 --one-top-level=monero-cli --strip-components=1 -C tests`;
|
|
await $.raw`rm ${MONERO_CLI_FILE_NAME}.tar.bz2`;
|
|
}
|
|
|
|
export async function downloadWowneroCli() {
|
|
const WOWNERO_CLI_FILE_NAME = "wownero-x86_64-linux-gnu-59db3fe8d";
|
|
const WOWNERO_WALLET_CLI_URL =
|
|
`https://codeberg.org/wownero/wownero/releases/download/v0.11.2.0/wownero-x86_64-linux-gnu-59db3fe8d.tar.bz2`;
|
|
|
|
await $`wget -q -o /dev/null ${WOWNERO_WALLET_CLI_URL}`;
|
|
await $
|
|
.raw`tar -xf ${WOWNERO_CLI_FILE_NAME}.tar.bz2 --one-top-level=wownero-cli --strip-components=1 -C tests`;
|
|
await $.raw`rm ${WOWNERO_CLI_FILE_NAME}.tar.bz2`;
|
|
}
|
|
|
|
export function downloadCli(coin: Coin) {
|
|
if (coin === "wownero") {
|
|
return downloadWowneroCli();
|
|
}
|
|
return downloadMoneroCli();
|
|
}
|
|
|
|
interface WalletInfo {
|
|
path: string;
|
|
password: string;
|
|
address: string;
|
|
secretSpendKey: string;
|
|
publicSpendKey: string;
|
|
secretViewKey: string;
|
|
publicViewKey: string;
|
|
}
|
|
|
|
export async function createWalletViaCli(
|
|
coin: Coin,
|
|
name: string,
|
|
password: string,
|
|
): Promise<WalletInfo> {
|
|
const path = `./tests/wallets/${name}`;
|
|
const cliPath = `./tests/${coin}-cli/${coin}-wallet-cli`;
|
|
|
|
await $
|
|
.raw`${cliPath} --generate-new-wallet ${path} --password ${password} --mnemonic-language English --command exit`
|
|
.stdout("null");
|
|
|
|
const address = (await $.raw`${cliPath} --wallet-file ${path} --password ${password} --command address`
|
|
.stdinText(`${password}\n`)
|
|
.lines())
|
|
.at(-1)!
|
|
.split(/\s+/)[1];
|
|
|
|
const retrieveKeys = (lines: string[]) =>
|
|
lines.slice(-2)
|
|
.map((line) => line.split(": ")[1]);
|
|
|
|
const [secretSpendKey, publicSpendKey] = retrieveKeys(
|
|
await $.raw`${cliPath} --wallet-file ${path} --password ${password} --command spendkey`
|
|
.stdinText(`${password}\n`)
|
|
.lines(),
|
|
);
|
|
|
|
const [secretViewKey, publicViewKey] = retrieveKeys(
|
|
await $.raw`${cliPath} --wallet-file ${path} --password ${password} --command viewkey`
|
|
.stdinText(`${password}\n`)
|
|
.lines(),
|
|
);
|
|
|
|
return {
|
|
path,
|
|
password,
|
|
address,
|
|
secretSpendKey,
|
|
publicSpendKey,
|
|
secretViewKey,
|
|
publicViewKey,
|
|
};
|
|
}
|
|
|
|
// deno-lint-ignore ban-types
|
|
export type MoneroCVersion = "next" | (string & {});
|
|
|
|
export async function getMoneroCTags(): Promise<string[]> {
|
|
return ((
|
|
await (await fetch(
|
|
"https://api.github.com/repos/MrCyjanek/monero_c/releases",
|
|
)).json()
|
|
) as { tag_name: string }[])
|
|
.map(({ tag_name }) => tag_name);
|
|
}
|
|
export async function getMoneroC(coin: Coin, version: MoneroCVersion) {
|
|
const dylibName = `${coin}_x86_64-linux-gnu_libwallet2_api_c.so`;
|
|
const endpointDylibName = `${coin}_libwallet2_api_c.so`;
|
|
const releaseDylibName = dylibName.slice(`${coin}_`.length);
|
|
|
|
if (version === "next") {
|
|
await $.raw`xz -kd release/${coin}/${releaseDylibName}.xz`;
|
|
await $`mkdir -p tests/libs/next`;
|
|
await $`mv release/${coin}/${releaseDylibName} tests/libs/next/${endpointDylibName}`;
|
|
} else {
|
|
const downloadUrl = `https://github.com/MrCyjaneK/monero_c/releases/download/${version}/${dylibName}.xz`;
|
|
|
|
const file = await Deno.open(`./tests/${dylibName}.xz`, {
|
|
create: true,
|
|
write: true,
|
|
});
|
|
file.write(await (await fetch(downloadUrl)).bytes());
|
|
file.close();
|
|
|
|
await $.raw`xz -d ./tests/${dylibName}.xz`;
|
|
await $.raw`mkdir -p ./tests/libs/${version}`;
|
|
await $
|
|
.raw`mv ./tests/${dylibName} ./tests/libs/${version}/${endpointDylibName}`;
|
|
}
|
|
}
|