Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const { connect: denoConnect, listen: denoListen, watchFs } = globalThis.

// Third-party packages:
//export { base16, base64, bech32, bech32m } from 'npm:@scure/base'
//export { default as Case } from 'npm:case';
//export { Buffer as StreamBuffer } from '@std/streams';

if (globalThis.Deno) {
Expand Down
9 changes: 9 additions & 0 deletions gui/Chain.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
button.chain {
background: #0004;
border-radius: 0.125rem;
color: white;
font-weight: bold;
font-size: 1rem;
border: none;
padding: 1rem 2rem;
}
11 changes: 5 additions & 6 deletions gui/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Html from '../library/Html.ts';
import Bitcoin from '../platform/Bitcoin/Bitcoin.ts';
let chain = null;
export default function Chain () {
const el = Html(['button.chain', chain?.status ?? 'Connecting...']);
chain ??= Bitcoin.Connect('https://liquidtestnet.com').then(connection => {
chain = connection;
}).catch(e => {
chain = { status: e.message }
});
const el = Html(['button.chain', chain ? 'Connecting...' : 'Connected!']);
chain ??= Bitcoin.LiquidTestnet();
console.log(chain);
chain.rpc.getbestblockhash().then(console.log).catch(console.error);
el.firstChild.innerText = 'Connected!';
return el
}
27 changes: 25 additions & 2 deletions gui/Demo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import Html from '../library/Html.ts';
import SimplicityHL from '../platform/SimplicityHL/SimplicityHL.ts';
import { pubECDSA } from 'npm:@scure/btc-signer/utils.js'; // not already in keypair?

export default Demo;
function Demo () {

async function Demo ({
root = document.getElementById('demousers'),
users = {
Alice: Demo.User('Alice'),
Bob: Demo.User('Bob'),
Carol: Demo.User('Carol'),
}
} = {}) {
for (const user of Object.values(users)) root.appendChild(Html(await user));
return Object.assign(root, { users });
}

namespace Demo {
export function User (name: string) {

export async function User (name: string, {
secret = new Uint8Array(Array(32).fill(1)),
keypair = SimplicityHL.Keypair(secret),
pubkey = pubECDSA(secret),
} = {}) {
keypair = await keypair;
console.log({ name, pubkey });
return ['article.demouser',
['section.demometa', ['strong.demoname', name], ['strong', '1.00000000 tLBTC'], 'at tex1p9sv7g8tyljjymz4t6zyjpvepw4...'],
['div.demolog', 'Enter Bob, Carol.'],
Expand All @@ -14,4 +36,5 @@ namespace Demo {
['input', { placeholder: 'chat' }],
['button.pill', 'Say']]]
}

}
8 changes: 5 additions & 3 deletions gui/Editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@
padding: 0;
margin: 0;
margin-bottom: 1rem !important;
@media screen and (max-width: 1366px) {
flex-flow: row wrap;
@media screen and (max-width: 1280px) {
flex-flow: column;
align-items: stretch;
.sidebox { max-width: initial; }
}
@media screen and (min-width: 1367px) {
@media screen and (min-width: 1281px) {
.sidebox { width: 24ch; flex-shrink: 0; }
}
p {
Expand Down
10 changes: 6 additions & 4 deletions gui/Simf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ namespace Simf {
['span', { style: 'float:left;font-size:2rem;padding-right:0.33rem' }, ...content]

export const Info = {
0: ['p', ['strong', 'Fadroma V3'], ' employs WebAssembly to instantly compile, evaluate, and deploy ',
['strong', 'SimplicityHL smart contracts'], ' from all modern JavaScript-based environments alike:',
' browsers, servers, and edge services.'],
1: ['p.sidebox', 'Try these ', ['strong', 'SimplicityHL programs'], ' on Liquid Testnet:', Chain()],
0: ['p'
, ['strong', 'Fadroma V3'], ' employs WebAssembly to instantly compile, evaluate, and deploy '
, ['strong', 'SimplicityHL smart contracts'], ' from all modern JavaScript-based environments alike: browsers, servers, and edge services.'],
1: ['p.sidebox.flex.space-between'
, ['div.grow', 'Try these ', ['strong', 'SimplicityHL programs'], ' on ', ['a', { href: '#' }, 'Liquid Testnet:'], ' ']
, Chain()],
2: ['p.sidebox', 'The ', ['strong', 'Simplicity transaction lifecycle'], ' happens in two phases:' ],
3: ['p', ['span', ['strong', Dropcap('1. '), 'Commitment phase'], '. Compile program to P2TR address, and fund it on-chain:']],
4: ['p', ['span', ['strong', Dropcap('2. '), 'Redemption phase'], '. Fulfill the program\'s conditions to redeem funds:']],
Expand Down
43 changes: 2 additions & 41 deletions gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="stylesheet" href="lib.css" />
<link rel="stylesheet" href="Editor.css" />
<link rel="stylesheet" href="Feature.css" />
<link rel="stylesheet" href="Chain.css" />
<link rel="stylesheet" href="Demo.css" />
<link rel="stylesheet" href="Docs.css" />
</head>
Expand Down Expand Up @@ -72,47 +73,7 @@
import('./Demo.ts').then(({ "default": x }) => x()).catch(console.error);
</script>
<p class="content"><strong>Watch this space:</strong> interactive peer discovery and deal-making in a familiar conversational interface will pop up here.</p>
<div class="content row justify-center">
<article class="demouser">
<section><strong class="demoname">Alice</strong><strong>1.00000000 tLBTC</strong> at tex1p9sv7g8tyljjymz4t6zyjpvepw4...</section>
<div class="demolog">
Enter Bob, Carol.
</div>
<section class="demoprogs">
<button class="pill">Send</button>
<button class="pill">P2PK</button>
<button class="pill">Vault</button>
<button class="pill">Escrow</button>
<input placeholder="chat" /> <button class="pill">Say</button>
</section>
</article>
<article class="demouser">
<section><strong class="demoname">Bob</strong><strong>1.00000000 tLBTC</strong> at tex1p9sv7g8tyljjymz4t6zyjpvepw4...</section>
<div class="demolog">
Enter Alice, Carol.
</div>
<section class="demoprogs">
<button class="pill">Send</button>
<button class="pill">P2PK</button>
<button class="pill">Vault</button>
<button class="pill">Escrow</button>
<input placeholder="chat" /> <button class="pill">Say</button>
</section>
</article>
<article class="demouser">
<section><strong class="demoname">Carol</strong><strong>1.00000000 tLBTC</strong> at tex1p9sv7g8tyljjymz4t6zyjpvepw4...</section>
<div class="demolog">
<em>Enter Alice, Bob.</em>
</div>
<section class="demoprogs">
<button class="pill">Send</button>
<button class="pill">P2PK</button>
<button class="pill">Vault</button>
<button class="pill">Escrow</button>
<input placeholder="chat" /> <button class="pill">Say</button>
</section>
</article>
</div>
<div id="demousers" class="content row justify-center"></div>
<p>Meanwhile, try the example project, and report any issues on our bug tracker!</p>
<p>All further inquiries welcome at <strong><a href="https://hack.bg/contact">https://hack.bg/contact</a></strong>.</p>
</div>
Expand Down
2 changes: 2 additions & 0 deletions gui/stub/stub_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export const process = {
exit () {},
};

export const argv = [];

export default process;
19 changes: 11 additions & 8 deletions gui/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,17 @@ nav.header {
}

.editor-wrapper {
/*resize: vertical;*/
/*overflow: auto;*/
margin: 0 0 0.5rem -1.5rem;
border-top: 1px solid #fff8;
background: #fff4;
/*max-width: 100%;*/
margin: 0 0 0.5rem -1.5rem;
/*border-top: 1px solid #0002;*/
/*border-left: 1px solid #0002;*/
/*border-bottom: 1px solid #0002;*/
/*border-right: 1px solid #0002;*/
border-radius: 0.125rem;
background: #fff4;
.collapsed & {
min-height: 0;
overflow: hidden;
display: none;
overflow: hidden;
display: none;
visibility: hidden;
}
}
Expand Down Expand Up @@ -468,6 +469,8 @@ nav.header {
border: 1px solid white;
min-height: 2rem;
background: #ddd;
padding: 0.33rem;
border-radius: 3px;
.name {
font-size: 1rem;
min-height: 2rem;
Expand Down
8 changes: 4 additions & 4 deletions library/Err.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Fn, Str } from '../index.ts';
import { bold, gray } from './Ansi.ts';
import { cwd } from 'node:process';
import process from 'node:process'; // destructuring this import breaks in Vite

export default function Err (message: string, ...args: object[]) {
return Object.assign(new Error(message), ...args)
Expand All @@ -9,7 +9,7 @@ export default function Err (message: string, ...args: object[]) {
export function formatError (e: Error, name?: Str) {
const [head, ...tail] = (e?.stack||'').split('\n');
const stack = tail.map(x=>x
.replace('('+cwd()+'/', '(')
.replace('('+process.cwd()+'/', '(')
.replace('./node_modules/.pnpm/', ''));
e.message = e.message.split('Logs:')[0].trim();
if (name) e.message = name + ': ' + e.message;
Expand All @@ -36,8 +36,8 @@ export function stackTrace (slice = 3, length?: number): string[] {
}
/** Relativize paths in stack trace, colorize, and reduce indent. */
export function alignTrace (line: string) {
line = line.replace('file://'+cwd(), '.');
line = line.replace(cwd(), '.');
line = line.replace('file://'+process.cwd(), '.');
line = line.replace(process.cwd(), '.');
const format = (x: string, i: number) => (i===0)
? bold(gray(2, x.padEnd(36))) : gray(4, x);
line = line.split(' (').map(format).join(gray(4, ' ('));
Expand Down
6 changes: 3 additions & 3 deletions library/Fn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import process from 'node:process'; // destructuring this import breaks in Vite
import { setImmediate } from 'node:timers';
import { argv, exit } from 'node:process';
import { fileURLToPath } from 'node:url';

export default Fn;
Expand Down Expand Up @@ -265,10 +265,10 @@ namespace Fn {
meta: Main.Meta = {},
main: Fn<string[], unknown>
) {
const [_, argv1, ...args] = argv
const [_, argv1, ...args] = process.argv
if (Main.is(meta || {}, argv1)) setImmediate(async ()=>{
try {
await Promise.resolve(main({ args, exit }));
await Promise.resolve(main({ args, exit: process.exit }));
//exit(0);
} catch (e) {
const error = e as Error & { exitCode?: number };
Expand Down
4 changes: 2 additions & 2 deletions library/Fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { chunked } from './String.ts';
import type { Bytes } from './Byte.ts';
import type { Versioned } from './Version.ts';

import { cwd } from 'node:process';
import process from 'node:process'; // destructuring this import breaks in Vite
import { joinPath, tmpdir, mkdir, rm, mkdtemp, writeFile, resolvePath } from '../deps.ts';

import { zipSync, strToU8 as zipStr } from 'npm:fflate';
Expand Down Expand Up @@ -165,7 +165,7 @@ function LocalFS <D extends Dir> (dir: string|D, path: string = ''): D {

const opts = { recursive: true };
dir.mkdir ??= async (sub: string) => {
const path = resolvePath(cwd(), sub);
const path = resolvePath(process.cwd(), sub);
await mkdir(path, opts)
return LocalFS(dir, path);
};
Expand Down
9 changes: 8 additions & 1 deletion library/String.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import Case from 'npm:case';
import type { Maybe, Bytes } from '../index.ts';
import { Case, stdout } from '../deps.ts';
import { stdout } from '../deps.ts';
import { NO_COLOR } from './Ansi.ts';
import Fn from './Fn.ts';

/** String, or something with a `toString` method. */
export type Str = string|{ toString(): string };

/** Concatenate strings. */
export function Str (...strs: Array<Maybe<Str>|Array<Maybe<Str>>>) {
return chunks(...strs).join('');
}

/** Flatten and filter nested arrays of strings. */
export const chunks = (...strs: Array<Maybe<Str>|Array<Maybe<Str>>>) =>
strs.flat().filter(Boolean).map(x=>x!.toString());

/** Join nested arrays of strings. */
export const joined = (joiner: string, ...strs: Array<Maybe<Str>|Array<Maybe<Str>>>) =>
chunks(...strs).join(joiner);

export const glued = Fn(joined, '');
export const spaced = Fn(joined, ' ');
export const lines = Fn(joined, '\n');
export const joiner = (x?: Str, y = ' ') => x ? (x.toString() + y) : '';

export function chunked (separator: string = '') {
return function unchunk (...chunks: unknown[]): string {
let buffer = '';
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@hackbg/fadroma",
"name": "@hackbg/fadroma",
"version": "3.0.0",
"type": "module",
"main": "lib/index.ts",
"type": "module",
"main": "lib/index.ts",
"scripts": {
"test": "tsx ./test.ts",
"build": "vite build",
"check": "deno check",
"test": "tsx ./test.ts",
"build": "vite build",
"check": "deno check",
"doc:type": "typedoc --out doc/type --darkHighlightTheme everforest-dark --cleanOutputDir --groupReferencesByType --useFirstParagraphOfCommentAsSummary index.ts",
"doc:deno": "deno doc --output doc/deno --html index.ts"
},
Expand All @@ -27,16 +27,16 @@
"fflate": "^0.8.2",
"indexd": "^0.9.1",
"log-update": "^7.0.1",
"protobuf-varint": "^1",
"nats.ws": "^1.30.3",
"p2p": "^0.12.0"
"p2p": "^0.12.0",
"protobuf-varint": "^1"
},
"devDependencies": {
"@noble/curves": "^2.0.1",
"@noble/ed25519": "^3.0.0",
"@noble/hashes": "^2.0.1",
"@noble/secp256k1": "^3.0.0",
"@scure/base": "^2",
"@scure/base": "^2.0.0",
"@scure/bip32": "^2.0.1",
"@scure/bip39": "^2.0.1",
"@scure/btc-signer": "^2.0.1",
Expand All @@ -45,18 +45,18 @@
"case": "^1.6.3",
"fflate": "^0.8.2",
"indexd": "^0.9.1",
"log-update": "^7.0.1",
"log-update": "^7.1.0",
"monaco-editor": "^0.55.1",
"monaco-editor-textmate": "4.0.0",
"monaco-textmate": "3.0.1",
"onigasm": "2.2.5",
"nats.ws": "^1.30.3",
"p2p": "^0.12.0",
"node-stdlib-browser": "^1.3.1",
"protobuf-varint": "^1",
"tsx": "^4.20.6",
"typedoc": "^0.28.14",
"vite": "^7.2.2",
"onigasm": "2.2.5",
"p2p": "^0.12.0",
"protobuf-varint": "^1.0.0",
"tsx": "^4.21.0",
"typedoc": "^0.28.17",
"vite": "^7.3.1",
"vite-plugin-node-polyfills": "^0.24.0"
},
"peerDependenciesMeta": {
Expand Down
6 changes: 5 additions & 1 deletion platform/Bitcoin/Bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ namespace Bitcoin {
}

/** Connect to Liquid testnet. */
export function LiquidTestnet (options?: Options) {/* TODO */}
export function LiquidTestnet (options?: Options) {
return Object.assign(Connect('https://liquidtestnet.com:18891'), LiquidTestnet);
}
export namespace LiquidTestnet {
export const ID = 'liquidtestnet';
export const HRP_BECH32 = 'tex';
Expand Down Expand Up @@ -219,6 +221,7 @@ namespace Bitcoin {
decodescript: Fn,
generatetoaddress: Fn,
getaddressinfo: Fn.Returns<Promise<{ pubkey: string }>>,
getbestblockhash: Fn.Returns<Promise<string>>,
getblockhash: Fn<[Num], Promise<string>>,
getnewaddress: Fn.Returns<Promise<string>>,
getreceivedbyaddress: Fn,
Expand All @@ -245,6 +248,7 @@ namespace Bitcoin {
decodescript: callRpc('decodescript'),
generatetoaddress: callRpc('generatetoaddress'),
getaddressinfo: callRpc('getaddressinfo'),
getbestblockhash: callRpc('getbestblockhash'),
getblockhash: callRpc('getblockhash'),
getnewaddress: callRpc('getnewaddress'),
getreceivedbyaddress: callRpc('getreceivedbyaddress'),
Expand Down
Loading