Skip to content

Commit

Permalink
feat: fetch BIP-353 with DNSSEC prover (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Oct 20, 2024
1 parent 7703f36 commit e1991a6
Show file tree
Hide file tree
Showing 15 changed files with 629 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "regtest"]
path = regtest
url = https://github.com/BoltzExchange/regtest.git
[submodule "dnssec-prover"]
path = dnssec-prover
url = https://git.bitcoin.ninja/dnssec-prover
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/utils/dnssec/dnssec*
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
"@babel/preset-typescript",
],
plugins: [
"babel-plugin-transform-import-meta",
"babel-plugin-transform-vite-meta-env",
[
"@babel/plugin-transform-modules-commonjs",
Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def handle_coop_disabled():
data = json.load(f)

network = data["network"]

if data.get("cooperativeDisabled", False):
handle_coop_disabled()

Expand Down
27 changes: 27 additions & 0 deletions build_dnssec_prover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /bin/python3

import os
import shutil
from pathlib import Path

def build():
target_dir = Path(os.path.dirname(__file__)).joinpath("src/utils/dnssec")

build_dir = Path(os.path.dirname(__file__)).joinpath("dnssec-prover/wasmpack")
os.chdir(build_dir)
os.system("wasm-pack build --target web --release && rm Cargo.lock && rm -r target/")

os.chdir(os.path.dirname(__file__))
os.makedirs(target_dir, exist_ok=True)

for base, _, files in os.walk(build_dir.joinpath("pkg")):
for file in files:
if file in ["package.json", ".gitignore"]:
continue

shutil.copy2(
Path(base).joinpath(file),
Path(target_dir).joinpath(file)
)

build()
1 change: 1 addition & 0 deletions dnssec-prover
Submodule dnssec-prover added at c4e06c
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/jest": "^29.5.12",
"@webbtc/webln-types": "^3.0.0",
"babel-jest": "^29.7.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"babel-preset-jest": "^29.6.3",
"babel-preset-solid": "^1.8.19",
Expand Down
7 changes: 7 additions & 0 deletions src/utils/dnssec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# DNSSEC prover

## Copyright

Compiled artifacts of https://git.bitcoin.ninja/dnssec-prover which was created
by Matt Corallo and is licensed under the MIT or Apache 2.0 open source
licenses.
86 changes: 86 additions & 0 deletions src/utils/dnssec/dnssec_prover_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* tslint:disable */
/* eslint-disable */
/**
* Builds a proof builder which can generate a proof for records of the given `ty`pe at the given
* `name`.
*
* After calling this [`get_next_query`] should be called to fetch the initial query.
* @param {string} name
* @param {number} ty
* @returns {WASMProofBuilder | undefined}
*/
export function init_proof_builder(name: string, ty: number): WASMProofBuilder | undefined;
/**
* Processes a response to a query previously fetched from [`get_next_query`].
*
* After calling this, [`get_next_query`] should be called until pending queries are exhausted and
* no more pending queries exist, at which point [`get_unverified_proof`] should be called.
* @param {WASMProofBuilder} proof_builder
* @param {Uint8Array} response
*/
export function process_query_response(proof_builder: WASMProofBuilder, response: Uint8Array): void;
/**
* Gets the next query (if any) that should be sent to the resolver for the given proof builder.
*
* Once the resolver responds [`process_query_response`] should be called with the response.
* @param {WASMProofBuilder} proof_builder
* @returns {Uint8Array | undefined}
*/
export function get_next_query(proof_builder: WASMProofBuilder): Uint8Array | undefined;
/**
* Gets the final, unverified, proof once all queries fetched via [`get_next_query`] have
* completed and their responses passed to [`process_query_response`].
* @param {WASMProofBuilder} proof_builder
* @returns {Uint8Array}
*/
export function get_unverified_proof(proof_builder: WASMProofBuilder): Uint8Array;
/**
* Verifies an RFC 9102-formatted proof and returns verified records matching the given name
* (resolving any C/DNAMEs as required).
* @param {Uint8Array} stream
* @param {string} name_to_resolve
* @returns {string}
*/
export function verify_byte_stream(stream: Uint8Array, name_to_resolve: string): string;
export class WASMProofBuilder {
free(): void;
}

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_wasmproofbuilder_free: (a: number, b: number) => void;
readonly init_proof_builder: (a: number, b: number, c: number) => number;
readonly process_query_response: (a: number, b: number, c: number) => void;
readonly get_next_query: (a: number) => Array;
readonly get_unverified_proof: (a: number) => Array;
readonly verify_byte_stream: (a: number, b: number, c: number, d: number) => Array;
readonly __wbindgen_export_0: WebAssembly.Table;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
readonly __externref_table_dealloc: (a: number) => void;
readonly __wbindgen_start: () => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
*
* @returns {InitOutput}
*/
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
Loading

0 comments on commit e1991a6

Please sign in to comment.