Skip to content

Commit

Permalink
feat: support wownero in monero.ts bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Oct 15, 2024
1 parent b1db21e commit 19d5722
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 624 deletions.
9 changes: 5 additions & 4 deletions impls/monero.ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ There are at least two ways to do so:
an example of doing so.
```ts
import {
loadDylib,
loadMoneroDylib,
Wallet,
WalletManager,
} from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";

// Try to load dylib from the default lib/* path
loadDylib();
// You can also use loadWowneroDylib for Wownero
loadMoneroDylib();

const wm = await WalletManager.new();
const wallet = await Wallet.create(wm, "./my_wallet", "password");
Expand All @@ -33,11 +34,11 @@ There are at least two ways to do so:
```ts
import { dlopen } from "jsr:@denosaurs/plug";
// It's recommened to put the monero.ts github link into your import_map to reduce the url clutter
import { loadDylib, symbols, Wallet, WalletManager } from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";
import { loadMoneroDylib, symbols, Wallet, WalletManager } from "https://raw.githubusercontent.com/MrCyjaneK/monero_c/master/impls/monero.ts/mod.ts";

// Load dylib loaded by plug
const lib = await dlopen(..., symbols);
loadDylib(lib);
loadMoneroDylib(lib);

const wm = await WalletManager.new();
const wallet = await Wallet.create(wm, "./my_wallet", "password");
Expand Down
12 changes: 6 additions & 6 deletions impls/monero.ts/checksum.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { moneroChecksum } from "./checksum_monero.ts";
import { readCString } from "./src/utils.ts";
import { dylib, loadDylib } from "./src/bindings.ts";
import { getSymbol, readCString } from "./src/utils.ts";
import { dylib, loadMoneroDylib } from "./src/bindings.ts";

loadDylib();
loadMoneroDylib();

export class ChecksumError extends Error {
readonly code: number;
Expand All @@ -21,7 +21,7 @@ export class ChecksumError extends Error {
* @returns {ChecksumError} which contains information about why checksum failed
*/
export async function validateChecksum(): Promise<ChecksumError | null> {
const cppHeaderHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_h(), false);
const cppHeaderHash = await readCString(await getSymbol("checksum_wallet2_api_c_h")!(), false);
const tsHeaderHash = moneroChecksum.wallet2_api_c_h_sha256;

const errors: string[] = [];
Expand All @@ -32,14 +32,14 @@ export async function validateChecksum(): Promise<ChecksumError | null> {
errorCode++;
}

const cppSourceHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_cpp(), false);
const cppSourceHash = await readCString(await getSymbol("checksum_wallet2_api_c_cpp")!(), false);
const tsSourceHash = moneroChecksum.wallet2_api_c_cpp_sha256;
if (cppSourceHash !== tsSourceHash) {
errors.push(`ERR: CPP source file check mismatch ${cppSourceHash} == ${tsSourceHash}`);
errorCode++;
}

const cppExportHash = await readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_exp(), false);
const cppExportHash = await readCString(await getSymbol("checksum_wallet2_api_c_exp")!(), false);
const tsExportHash = moneroChecksum.wallet2_api_c_exp_sha256;
if (cppExportHash !== tsExportHash) {
if (Deno.build.os !== "darwin") {
Expand Down
Loading

0 comments on commit 19d5722

Please sign in to comment.