Skip to content

Commit

Permalink
feat: upstream changes to bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-Beast committed Sep 6, 2024
1 parent f3e74f1 commit a5396d9
Show file tree
Hide file tree
Showing 16 changed files with 1,188 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/full_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ jobs:
- name: Run tests
run: |
cd impls/monero.ts
deno run --unstable-ffi --allow-ffi monero_bindings.ts
deno run --unstable-ffi --allow-ffi checksum.ts
comment_pr:
name: comment on pr
Expand Down
5 changes: 4 additions & 1 deletion impls/monero.ts/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# monero.ts wip library
# monero.ts

# Usage
monero.ts uses Deno as its runtime of choice
63 changes: 63 additions & 0 deletions impls/monero.ts/checksum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { moneroChecksum } from "./checksum_monero.ts";
import { readCString } from "./src/utils.ts";
import { dylib } from "./src/bindings.ts";

export class ChecksumError extends Error {
readonly code: number;
readonly errors: string[];

constructor(code: number, errors: string[]) {
super("MoneroC binding checksum failed:\n" + errors.join("\n"));
this.code = code;
this.errors = errors;
}
}

/**
* Validates MoneroC checksums
* @returns {null} if checksums are correct
* @returns {ChecksumError} which contains information about why checksum failed
*/
export async function validateChecksum(): Promise<ChecksumError | null> {
const cppHeaderHash = readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_h());
const tsHeaderHash = moneroChecksum.wallet2_api_c_h_sha256;

const errors: string[] = [];

let errorCode = 0;
if (cppHeaderHash !== tsHeaderHash) {
errors.push("ERR: Header file check mismatch");
errorCode++;
}

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

const cppExportHash = readCString(await dylib.symbols.MONERO_checksum_wallet2_api_c_exp());
const tsExportHash = moneroChecksum.wallet2_api_c_exp_sha256;
if (cppExportHash !== tsExportHash) {
if (Deno.build.os !== "darwin") {
errors.push("WARN: EXP source file check mismatch");
} else {
errors.push(`ERR: EXP source file check mismatch ${cppExportHash} == ${tsExportHash}`);
}
errorCode++;
}

if (errorCode) {
return new ChecksumError(errorCode, errors);
}

return null;
}

if (import.meta.main) {
const maybeError = await validateChecksum();
if (maybeError) {
throw maybeError;
}
}
5 changes: 5 additions & 0 deletions impls/monero.ts/deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"fmt": {
"lineWidth": 120
}
}
6 changes: 6 additions & 0 deletions impls/monero.ts/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./src/bindings.ts";
export * from "./src/pending_transaction.ts";
export * from "./src/transaction_history.ts";
export * from "./src/transaction_info.ts";
export * from "./src/wallet.ts";
export * from "./src/wallet_manager.ts";
136 changes: 0 additions & 136 deletions impls/monero.ts/monero_bindings.ts

This file was deleted.

Loading

0 comments on commit a5396d9

Please sign in to comment.