diff --git a/.env.example b/.env.example deleted file mode 100644 index fc94449..0000000 --- a/.env.example +++ /dev/null @@ -1,11 +0,0 @@ -NFP_WEB_LCDS="https://lcd.testnet.secretsaturn.net,https://api.pulsar.scrttestnet.com" -NFP_WEB_COMCS="http://localhost:8080/" -NFP_SELF_CHAIN="pulsar-2" -NFP_SELF_CONTRACT="secret1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -NFP_SELF_TOKEN="123" - -# used in autoboot dev mode -NFP_VIEWING_KEY="password123" - -# leave empty to generate one by running `node deploy.mjs` -NFP_WALLET_PRIVATE_KEY="" diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ccc876f..898efb3 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,9 +1,12 @@ module.exports = { - extends: '@blake.regalia/eslint-config-elite', + extends: '@blake.regalia/eslint-config-elite/svelte.js', parserOptions: { ecmaVersion: 2022, sourceType: 'module', tsconfigRootDir: __dirname, project: 'tsconfig.json', }, + globals: { + 'destructureImportedNfpModule': 'readonly', + }, }; diff --git a/.gitignore b/.gitignore index ab79e8e..b14c331 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ # ignore package-manager locks **/*.lock **/package-lock.json + +# keep generated module JSON data +!.nfp-modules.json diff --git a/.nfp-modules.json b/.nfp-modules.json new file mode 100644 index 0000000..06d33ee --- /dev/null +++ b/.nfp-modules.json @@ -0,0 +1,136 @@ +{ + "schema": "1", + "comment": "Do not edit or delete this generated file! It should also be committed to version control.", + "modules": { + "bootloader": { + "version": "0.2", + "hash": "5d66fb5ccabb", + "exports": { + ".": { + "A_TOKEN_LOCATION": { + "symbol": "a", + "dynamic": true + }, + "P_LCD": { + "symbol": "b", + "dynamic": true + }, + "G_QUERY_PERMIT": { + "symbol": "c", + "dynamic": true + }, + "SH_VIEWING_KEY": { + "symbol": "d", + "dynamic": true + }, + "K_CONTRACT": { + "symbol": "e", + "dynamic": true + }, + "load_script": { + "symbol": "f" + }, + "ls_read": { + "symbol": "g" + }, + "ls_write": { + "symbol": "h" + }, + "ls_read_json": { + "symbol": "i" + }, + "ls_write_json": { + "symbol": "j" + }, + "query_contract_infer": { + "symbol": "k" + }, + "nfp_tags": { + "symbol": "l" + }, + "nfp_attr": { + "symbol": "m" + }, + "P_COMC_HOST": { + "symbol": "n", + "dynamic": true + } + } + }, + "dependencies": {} + }, + "app": { + "version": "0.6", + "hash": "8b9b83fd27cb", + "exports": { + ".": { + "SA_OWNER": { + "symbol": "a" + }, + "exec_contract": { + "symbol": "b" + }, + "K_WALLET": { + "symbol": "c", + "dynamic": true + }, + "dm_root": { + "symbol": "d" + }, + "dm_foreign": { + "symbol": "e" + }, + "A_RPCS": { + "symbol": "f" + }, + "P_COMC_HOST": { + "symbol": "g", + "dynamic": true + }, + "A_COMCS": { + "symbol": "h" + } + } + }, + "dependencies": { + "storage": { + "version": "0.1", + "hash": "c87091d4dc20", + "dynamic": true, + "imports": {} + }, + "bootloader": { + "version": "0.2", + "hash": "5d66fb5ccabb" + } + } + }, + "storage": { + "version": "0.1", + "hash": "c87091d4dc20", + "exports": { + ".": { + "readOwner": { + "symbol": "a" + }, + "writeOwner": { + "symbol": "b" + }, + "findFeegranter": { + "symbol": "c" + } + } + }, + "dependencies": { + "app": { + "version": "0.6", + "hash": "8b9b83fd27cb" + }, + "bootloader": { + "version": "0.2", + "hash": "5d66fb5ccabb" + } + } + } + } +} \ No newline at end of file diff --git a/MODULES.md b/MODULES.md new file mode 100644 index 0000000..3babaf7 --- /dev/null +++ b/MODULES.md @@ -0,0 +1,201 @@ + +# Modules + +NFPs are loaded into the browser as SVG documents, not as HTML documents. Consequently ` +``` + + +### Troubleshooting + +In some cases, `destructureImportedNfpModule` may show a type error about its argument. This can happen for instance if a svelte component is attempting to destructure members exported by its own parent module, but that parent isn't a dependency of any other modules in the project. Therefore, the global augmentation from that module's type definitions never get loaded. To fix this, simply add a type-only import to the entry file, importing its own type definitions: + +```ts +/* app/src/main.ts */ +import type {} from 'nfpx:app'; +``` + +#### Importing from self + +Another issue that can arise when using `destructureImportedNfpModule` to import items from the same (current) module, is that the identifier is not found in the module's exports: +``` +"{IDENTIFIER}" export not found in app module +``` + +This can happen because the SDK is trying to find the identifier in the module's compiled export table, but the module hasn't compiled yet. In this scenario, you need to first compile the module with the new export before using that identifier in any destructuring calls from within the same module. + +```ts +/* app/src/main.ts */ + +(async() => { + await someAsyncTask(); + + exportNfpx({ + FOOBAR: 'data', + }); +}); +``` + +```ts +/* app/src/App.svelte */ +const { + FOOBAR, // causing error: "FOOBAR" export not found in app module +} = destructureImportedNfpModule('app'); +``` + +**Solution:** + +Temporarily disable the import and compile. + +```ts +/* app/src/App.svelte */ +const { + // FOOBAR, +} = destructureImportedNfpModule('app'); + +// temporary decl to satisfy type-checker and linters +let FOOBAR!: string; +``` + +Now, `FOOBAR` should be defined in the app's exports in `.nfp-modules.json`. You should be able to revert the file and compile. diff --git a/README.md b/README.md index 6b9de7b..9337af8 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ NFP front-end development is divided into two subdirectories: the bootloader, an ### Bootloader -For maximum portability, robustness, and longevity, a bootloader is a tiny minified script that fetches the NFP's latest packages from the chain and hydrates the running SVG document (e.g., by injecting scripts). The bootloader ensures that the raw, original SVG file can forever be opened and run as a standalone web application in any modern browser. +For maximum portability, robustness, and longevity, a bootloader is a tiny minified script that fetches the NFP's latest packages from the chain and hydrates the running SVG document (i.e., by injecting script elements). The bootloader ensures that the raw, original SVG file can forever be opened and run as a standalone web application in any modern browser. The `@nfps.dev/runtime` package provides a function that can be called by the project's bootloader to automatically handle resolving the NFP's dependencies by reading the requisite children of the `` element. This approach allows project's to add some custom UI or logic to their bootloader flow. @@ -24,6 +24,11 @@ Unlike the bootloader, a project's main application can be updated by deploying The SVG stored on chain references a package by its id and a tag, e.g., ``. +### Modules + +See [MODULES.md](./MODULES.md) for documentation on the NFP module system. + + ## Directory Structure The root directory contains the `package.json` for managing the dependencies used by `app/` and `bootloader/`. @@ -43,22 +48,34 @@ The root directory contains the `package.json` for managing the dependencies use yarn install ``` -2. Set up environment variables +2. Install the nfp cli + + ```sh + yarn global add @nfps.dev/cli + ``` + +3. Set up environment variables ```sh - cp .env.example .env + nfp init ``` -3. Generate or import a private key +4. Import the account of an admin/minter - You can generate a new account by simply running `node deploy.mjs` without a value set for the private key env var. + You can import a private key from `secretcli` using the following command: + ```sh + sed -i'' "s/^NFP_WALLET_PRIVATE_KEY=.*/NFP_WALLET_PRIVATE_KEY=\"$(secretcli keys export "${ACCOUNT_NAME}" --unarmored-hex --unsafe)\"/" .env + ``` - Or, you can import a private key from `secretcli` using the following command: + Mint a new token from this imported account: ```sh - secretcli keys export ACCOUNT_NAME --unarmored-hex --unsafe + nfp mint "${SOME_TOKEN_ID}" ``` -4. Build everything + On success, the above command will update the env vars `NFP_OWNER` and `NFP_TOKEN_ID` in the `.env` file. + + +5. Build everything For production: ```sh @@ -74,13 +91,30 @@ The root directory contains the `package.json` for managing the dependencies use > While developing, you can use `yarn watch:dev` to automatically reload on file changes -5. Deploy the app to chain +6. Deploy the app to chain ```sh - yarn deploy:app # simply calls `node deploy.mjs` + nfp set-vk "password123" + nfp package upload dist/app.js + nfp package upload dist/storage.js --tags 1.x latest + nfp storage owner put 'foo: "bar", baz: 25' ``` -6. Open the built SVG file in a web browser (`file://` protocol works!) or preview in no-script mode using other means. +7. Open the built SVG file in a web browser (`file://` protocol works!) or preview in no-script mode using other means. + +8. Configure a COMC host + + If operating offline, or `x.s2r.sh` is not available, run a local COMC host and update your `.env` file accordingly: e.g., `NFP_COMC_HOST="http://localhost:8080/"`. A COMC host is a page served from an HTTP(S) URL that is capable of communicating with Keplr on behalf of the NFP when it is served from the `file://` protocol (Keplr only injects a content-script into HTTP(S) tabs). + +9. Connect your web extension wallet to the app + + If using Keplr: + - for the testnet, make sure to accept the prompt to add the `pulsar-3` testnet chain + - reload the page and approve the connection request from the COMC host (e.g., `https://x.s2r.sh` or `http://localhost:8080`) + - make sure your wallet is funded. for the testnet: https://faucet-ui-pulsar3.vercel.app/ + +10. Follow instructions to "Grant Allowance". This allows the Neutrino hot hot wallet to pay tx fees using the account of your web wallet. + Outputs: - `dist/nfp.svg` - the built and minified SVG file diff --git a/app/src/App.svelte b/app/src/App.svelte index 737ca10..ab0ad0f 100644 --- a/app/src/App.svelte +++ b/app/src/App.svelte @@ -1,59 +1,165 @@ - qsa((d_event.target as HTMLElement).closest('form')!, 'input,button') - .map(dm => dm.setAttribute('disabled', 'disabled')); + -
-

App connected

+
+
+

+ {b_loading? 'Loading...': b_writable? 'Synced': 'Awaiting Wallet'} +

+
+
-
-
-
- - - -
-
-
+
+ + +
-
\ No newline at end of file + + + + + diff --git a/app/src/Notifications.svelte b/app/src/Notifications.svelte new file mode 100644 index 0000000..c7d95ce --- /dev/null +++ b/app/src/Notifications.svelte @@ -0,0 +1,27 @@ + + +
+
+ + +
+
diff --git a/app/src/Wallet.svelte b/app/src/Wallet.svelte new file mode 100644 index 0000000..0d2b550 --- /dev/null +++ b/app/src/Wallet.svelte @@ -0,0 +1,922 @@ + + + + + + +
+
+ + {@html icon_to_svg(faWallet.icon, 22, 'f7f7f7')} + + + + {s_spendable} + + + SCRT + + +
+
+
+ {#each a_menus as h_menu, i_menu (JSON.stringify(h_menu))} + + {/each} +
+
+
diff --git a/app/src/def.less b/app/src/def.less new file mode 100644 index 0000000..04fe605 --- /dev/null +++ b/app/src/def.less @@ -0,0 +1,27 @@ + +/* ease-in corresponds to cubic-bezier(0.42, 0, 1.0, 1.0) */ +@ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53); +@ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19); +@ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22); +@ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06); +@ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035); +@ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335); + +/* ease-out corresponds to cubic-bezier(0, 0, 0.58, 1.0) */ +@ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94); +@ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1); +@ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1); +@ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1); +@ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1); +@ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1); + +/* ease-in-out corresponds to cubic-bezier(0.42, 0, 0.58, 1.0) */ +@ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955); +@ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1); +@ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1); +@ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1); +@ease-in-out-expo: cubic-bezier(1, 0, 0, 1); +@ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86); + +/* custom easing */ +@ease-out-quick: cubic-bezier(0, 1, 0, 1); diff --git a/app/src/env.ts b/app/src/env.ts new file mode 100644 index 0000000..13408f7 --- /dev/null +++ b/app/src/env.ts @@ -0,0 +1,15 @@ +/// +/// +/// + +import type {Wallet} from '@solar-republic/neutrino'; + +// declare what the app can export dynamically +export interface NfpxExports { + K_WALLET: Wallet; +} + +/* eslint-disable @typescript-eslint/naming-convention,no-var */ +declare global { + function exportNfpx(h_exports: NfpxExports): void; +} diff --git a/app/src/main.ts b/app/src/main.ts index 022d33d..53b7fe5 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -1,13 +1,31 @@ -import {create_svg, create_html} from '@nfps.dev/runtime'; +import type {NfpxExports} from './env'; +import type {HttpsUrl, SecretBech32} from '@solar-republic/neutrino'; -// import App from './app.svelte'; +import {create_svg, create_html, ls_write, ls_write_b64, ls_read_b64} from '@nfps.dev/runtime'; +import {Wallet, gen_sk, exec_contract} from '@solar-republic/neutrino'; -import type {} from '../../applibs/src/interface'; -import {safe_json, Wallet, type SecretBech32, gen_sk} from '@solar-republic/neutrino'; -import {base64_to_buffer} from '@blake.regalia/belt'; +// reuse as much as possible from the bootloader to cut down on app's bundle size +import { + A_TOKEN_LOCATION, + G_QUERY_PERMIT, + K_CONTRACT, + P_LCD, + SH_VIEWING_KEY, + P_COMC_HOST, + ls_read, + nfp_tags, + nfp_attr, +} from 'nfpx:bootloader'; + +import App from './App.svelte'; const dm_root = document.documentElement; +// read rpc data from nfp +const dm_web = nfp_tags('web')?.[0]; +const A_RPCS = dm_web? nfp_attr(dm_web, 'rpcs')?.split(',') as HttpsUrl[]: []; +const A_COMCS = ((dm_web? nfp_attr(dm_web, 'comcs')?.split(','): null) || [P_COMC_HOST]) as [HttpsUrl, ...HttpsUrl[]]; + // create ui to allow user to play/pause animations const dm_pause = create_html('button', { style: 'position:absolute;top:40em;left:22em;background:#333;color:#ce3', @@ -15,59 +33,81 @@ const dm_pause = create_html('button', { 'Pause', ]); -dm_root.append(create_svg('foreignObject', { +const dm_app = create_html('div', { + id: 'app', +}); + +const dm_foreign = create_svg('foreignObject', { width: '100%', height: '100%', x: '0', y: '0', }, [ - create_html('div', {}, [ - dm_pause, - ]), -])); + dm_app, + // create_html('div', {}, [ + // dm_pause, + // ]), +]); + +dm_root.append(dm_foreign); dm_pause.onclick = () => { dm_pause.textContent = dm_root.classList.toggle('paused')? 'Resume': 'Pause'; }; -const si_storage_token_owner_addr = 'toa:'+loc.join(':'); +const si_storage_token_owner_addr = 'toa:'+A_TOKEN_LOCATION.join(':'); // fetch token owner address -toa = lsgs(si_storage_token_owner_addr) as SecretBech32 - || lsss(si_storage_token_owner_addr, prompt('Please enter the account address that owns this token') || ''); +const SA_OWNER = ls_read(si_storage_token_owner_addr) as SecretBech32 + || ls_write(si_storage_token_owner_addr, prompt('Please enter the account address that owns this token') || ''); + +// const SA_OWNER = await idb_read(si_storage_token_owner_addr) +// || await idb_write(si_storage_token_owner_addr, prompt('Please enter ...')); + +// go async (async() => { // get or create private key - const sh_sk = lsgs('sk'); - const atu8_sk = sh_sk? base64_to_buffer(sh_sk): gen_sk(); + const atu8_sk = ls_read_b64('sk') || gen_sk(); // create wallet - const k_wallet = Wallet(atu8_sk, loc[0], lcd); - - // fetch library - const dm_script = await load('storage.js', { - tag: '1.x', - }, sc, loc, qp || [vk!]); - - // request succeded - if(dm_script) { - // wait for script to load before calling its functions - dm_script.onload = async() => { - // read from token - const g_read = await readOwner(['test']); - console.log(g_read); - - // // load app - // new App({ - // target: document.documentElement, - // props: { - // k_wallet, - // k_contract: sc, - // }, - // }); - }; - - // inject library - dm_root.append(dm_script); - } + const k_wallet = await Wallet(atu8_sk, A_TOKEN_LOCATION[0], P_LCD, A_RPCS[0]); + + // save to local storage + ls_write_b64('sk', atu8_sk); + console.log(`Hot wallet address: ${k_wallet.addr}`); + + // dynamic export before importing libs (which depend on these exports) + exportNfpx({ + K_WALLET: k_wallet, + }); + + // load the 'storage' module before launching 'App.svelte' + await import('nfpx:storage', { + contract: K_CONTRACT, + location: A_TOKEN_LOCATION, + auth: G_QUERY_PERMIT || [SH_VIEWING_KEY, SA_OWNER], + query: { + tag: '1.x', + }, + }); + + // launch the app + new App({ + target: dm_app, + }); })(); + +// augment the collection of data and functions that can be reused by other modules +export { + A_RPCS, + A_COMCS, + SA_OWNER, + exec_contract, + dm_root, + dm_foreign, +}; + +export default interface Default extends NfpxExports { + merge: string; +} diff --git a/app/src/webext-portal.ts b/app/src/webext-portal.ts new file mode 100644 index 0000000..86f9df5 --- /dev/null +++ b/app/src/webext-portal.ts @@ -0,0 +1,18 @@ +import type {ComcClient} from '@nfps.dev/runtime'; +import type {HttpsUrl} from '@solar-republic/neutrino'; + +import {comcPortal, comcClient} from '@nfps.dev/runtime'; + +export async function WebextPortal(a_hosts: [HttpsUrl, ...HttpsUrl[]]=['https://x.s2r.sh/']): Promise { + const { + dm_foreign, + } = destructureImportedNfpModule('app'); + + for(const p_host of a_hosts) { + const dm_iframe = await comcPortal(p_host, dm_foreign); + + return comcClient(dm_iframe); + } + + return null as unknown as ComcClient; +} diff --git a/app/tsconfig.json b/app/tsconfig.json new file mode 100644 index 0000000..0440083 --- /dev/null +++ b/app/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": [ + "../tsconfig.json" + ], + + "compilerOptions": { + "verbatimModuleSyntax": true, + + "sourceMap": true, + + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + } +} \ No newline at end of file diff --git a/app/vite.config.ts b/app/vite.config.ts index 2e24eaa..e494b40 100644 --- a/app/vite.config.ts +++ b/app/vite.config.ts @@ -1,7 +1,8 @@ import {resolve} from 'path'; -import {microWeb} from '@nfps.dev/rollup-plugin-microweb'; -import {defineConfig} from 'vite'; +import {nfpModule} from '@nfps.dev/sdk'; + +import {defineConfig, type Plugin} from 'vite'; export default defineConfig(({mode}) => { const B_DEV = 'development' === mode; @@ -12,7 +13,7 @@ export default defineConfig(({mode}) => { emptyOutDir: false, minify: !B_DEV, sourcemap: B_DEV? 'inline': false, - target: ['es2022'], + target: ['esnext'], lib: { entry: resolve(__dirname, 'src/main.ts'), @@ -28,12 +29,15 @@ export default defineConfig(({mode}) => { }, plugins: [ - microWeb({ + nfpModule({ + id: 'app', include: 'app/src/**/*.ts', compilerOptions: { - sourceMap: B_DEV, + sourceMap: false, + module: 'esnext', }, - }), + svelte: {}, + }) as Plugin[], ], }; }); diff --git a/applibs/rollup.config.ts b/applibs/rollup.config.ts index 87e64cc..5fce81d 100644 --- a/applibs/rollup.config.ts +++ b/applibs/rollup.config.ts @@ -1,7 +1,6 @@ -import type {RollupOptions} from 'rollup'; - -import {microWeb} from '@nfps.dev/rollup-plugin-microweb'; +import type {Plugin, RollupOptions} from 'rollup'; +import {nfpModule} from '@nfps.dev/sdk'; import {defineConfig} from 'rollup'; export default defineConfig([ @@ -11,19 +10,19 @@ export default defineConfig([ output: { format: 'iife', dir: 'dist', - entryFileNames: `${sr_lib}${'development' === process.env['NODE_ENV']? '.dev': ''}.js`, + entryFileNames: `${sr_lib}${'development' === process.env['NFP_ENV']? '.dev': ''}.js`, inlineDynamicImports: false, }, plugins: [ - microWeb({ + nfpModule({ + id: sr_lib, include: [ `applibs/src/${sr_lib}/**/*.ts`, - 'bootloader/src/global.ts', ], compilerOptions: { sourceMap: false, - declaration: false, + // declaration: false, }, - }), + }) as unknown as Plugin, ], } as RollupOptions))); diff --git a/applibs/src/env.ts b/applibs/src/env.ts new file mode 100644 index 0000000..2471373 --- /dev/null +++ b/applibs/src/env.ts @@ -0,0 +1,3 @@ +/// +/// +/// diff --git a/applibs/src/interface.ts b/applibs/src/interface.ts deleted file mode 100644 index 9f6d6c5..0000000 --- a/applibs/src/interface.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention,no-var */ -import type {L} from 'ts-toolbelt'; - -import type { - Dict, -} from '@blake.regalia/belt'; - -import type { - SecretBech32, -} from '@solar-republic/neutrino'; - -declare global { - /** - * Reads from the contract's owner storage - * @returns an `object` of the key/value pairs contained in the response, or `undefined` if there was - * a query error - */ - var readOwner: < - a_keys extends string[], - >(a_keys: a_keys) => Promise, string> | undefined>; - - /** - * Writes to the contract's owner storage - */ - var writeOwner: (h_write: Dict) => Promise<0 | 1>; -} - -export {}; diff --git a/applibs/src/storage/main.ts b/applibs/src/storage/main.ts index 46ebf8a..ebb7fa9 100644 --- a/applibs/src/storage/main.ts +++ b/applibs/src/storage/main.ts @@ -1,22 +1,150 @@ -import type {} from '../interface'; +import type {L} from 'ts-toolbelt'; -import type { - StorageData, -} from '@nfps.dev/runtime'; +import type {JsonValue, Uint128} from '@blake.regalia/belt'; +import type {StorageData} from '@nfps.dev/runtime'; +import type {SecretBech32} from '@solar-republic/neutrino'; + +import {ode, oderac, ofe} from '@blake.regalia/belt'; + +import { + queryFeegrantAllowances, + // tpa, + // tpae, + // tpas, + // tpaw, + // tpar, +} from '@solar-republic/neutrino'; + +import { + SA_OWNER, + K_WALLET, + exec_contract, +} from 'nfpx:app'; import { - ofe, -} from '@blake.regalia/belt'; - -Object.assign(window, { - // eslint-disable-next-line @typescript-eslint/naming-convention - async readOwner(a_keys) { - // perform query on contract - const [g_storage,, s_error] = await qci(sc, 'storage_owner_get', { - keys: a_keys, - }, qp || [vk!, toa]); - - // restructure response - return g_storage? ofe((g_storage.data || []).map(g => [g.key, g.value])): alert(s_error); - }, -} as Pick); + G_QUERY_PERMIT, + K_CONTRACT, + SH_VIEWING_KEY, + query_contract_infer, +} from 'nfpx:bootloader'; + + +type StoragePutSuccess = { + [si_key in `storage_${si_area}_put`]: { + status: 'success'; + }; +}; + + +type Allowance = []; + +const h_feegrants: Record> = {}; + +/** + * + */ +export async function findFeegranter(sa_grantee: SecretBech32, xg_needed: bigint): Promise { + for(const [sa_granter, a_allowance] of ode(h_feegrants[sa_grantee] || {})) { + if(a_allowance) { + return sa_granter; + } + } + + const a_results = await queryFeegrantAllowances(K_WALLET.lcd, sa_grantee); + + for(const g_result of a_results) { + const g_allowance = g_result.allowance; + + // basic allowance + if(g_allowance['@type'].includes('Basic')) { + // destructure spend limit + const [g_coin] = g_allowance.spend_limit; + + // allowance amount is enough to cover needed amount + if(BigInt(g_coin.amount) >= xg_needed) { + return g_result.granter; + } + } + } + + // return tpa(a_results[0])._g || tpa(a_results[0]).$r!; + // return tpas(a_results[0], 'g') || tpae(a_results[0], 'r'); + // return tpaw(a_results[0], 'g') || tpaw(a_results[0], 'r', 1); + // return tpar(a_results[0], /^g/) || tpar(a_results[0], /r$/); + // return a_results[0].granter; + + return; +} + + + +/** + * Reads from the contract's owner storage + * @returns an `object` of the key/value pairs contained in the response, or `undefined` if there was + * a query error + */ +export async function readOwner< + const a_keys extends readonly string[], +>(a_keys: a_keys): Promise<{ + [si_key in L.UnionOf]: string; +} | void | undefined> { + // perform query on contract + const [g_storage,, s_error] = await query_contract_infer(K_CONTRACT, 'storage_owner_get', { + keys: a_keys, + }, G_QUERY_PERMIT || [SH_VIEWING_KEY, SA_OWNER]); + + // restructure response + return g_storage? ofe((g_storage.data || []).map(g => [g.key, g.value])) as { + [si_key in L.UnionOf]: string; + }: alert(s_error); +} + + +// /** +// * Reads from the contract's owner storage +// * @returns an `object` of the key/value pairs contained in the response, or `undefined` if there was +// * a query error +// */ +// export async function readOwnerSelf< +// const a_keys extends readonly string[], +// >(a_keys: a_keys): Promise<{ +// [si_key in L.UnionOf]: string; +// } | void | undefined> { +// // perform query on contract +// const [g_storage,, s_error] = await query_contract_infer(K_CONTRACT, 'storage_owner_get', { +// keys: a_keys, +// }, G_QUERY_PERMIT); + +// // restructure response +// return g_storage? ofe((g_storage.data || []).map(g => [g.key, g.value])) as { +// [si_key in L.UnionOf]: string; +// }: alert(s_error); +// } + + +/** + * Writes to the contract's owner storage + */ +export async function writeOwner(h_write: Record): Promise> { + const a_entries = oderac(h_write, (si_key, w_value) => ({ + key: si_key, + value: w_value, + })); + + const x_limit = 60_000; + const x_fee = x_limit * 0.125; + + // find feegrant + const sa_granter = await findFeegranter(K_WALLET.addr, BigInt(x_fee)); + + const [xc_code, s_res, g_tx] = await exec_contract(K_CONTRACT, K_WALLET, { + storage_owner_put: { + data: a_entries, + // TODO: add scope for token/owner + }, + }, [[''+x_fee as Uint128, 'uscrt']], ''+x_limit as Uint128, '', sa_granter); + + if(xc_code) throw s_res; + + return JSON.parse(s_res) as StoragePutSuccess<'owner'>; +} diff --git a/bootloader/rollup.config.ts b/bootloader/rollup.config.ts index 0f9dba0..8159b82 100644 --- a/bootloader/rollup.config.ts +++ b/bootloader/rollup.config.ts @@ -1,41 +1,26 @@ -import type {RollupOptions} from 'rollup'; +import {nfpModule} from '@nfps.dev/sdk'; +import {defineConfig, type Plugin} from 'rollup'; -import {microWeb} from '@nfps.dev/rollup-plugin-microweb'; - -import replace from '@rollup/plugin-replace'; -import * as dotenv from 'dotenv'; -import {defineConfig} from 'rollup'; - -dotenv.config(); - -const h_env_safe = Object.fromEntries(Object.entries(process.env).filter(([si_key]) => si_key.startsWith('NFP_'))); - -export default defineConfig([ - 'bootloader.ts', - '_autoboot.ts', -].map(sr_file => ({ - input: `bootloader/src/${sr_file}`, +export default defineConfig({ + input: `bootloader/src/bootloader.ts`, output: { format: 'iife', dir: 'dist', - entryFileNames: `[name]${'development' === process.env['NODE_ENV']? '.dev': ''}.js`, - inlineDynamicImports: false, + entryFileNames: `[name]${'development' === process.env['NFP_ENV']? '.dev': ''}.js`, + + // in case any imported libraries use dynamic imports, they will not work in the nfp + // unless inlined with the bundle. set to false if you never expect the conditions + // to be met in which an imported package would attempt a dynamic import + inlineDynamicImports: true, }, plugins: [ - // for the autoboot config - ...sr_file.startsWith('_autoboot')? [ - replace({ - values: { - 'process.env': '('+JSON.stringify(h_env_safe)+')', - }, - }), - ]: [], - - microWeb({ + nfpModule({ + id: 'bootloader', + injectNfpModuleSystem: true, include: 'bootloader/src/**/*.ts', compilerOptions: { sourceMap: false, }, - }), + }) as unknown as Plugin, ], -} as RollupOptions))); +}); diff --git a/bootloader/src/_autoboot.ts b/bootloader/src/_autoboot.ts index 2234c7f..9093c30 100644 --- a/bootloader/src/_autoboot.ts +++ b/bootloader/src/_autoboot.ts @@ -4,59 +4,54 @@ */ import type {HttpsUrl, SecretBech32} from '@solar-republic/neutrino'; -import {oda} from '@blake.regalia/belt'; - -import {create_svg, ls_get_json, ls_get_str, ls_set_json, ls_set_str, qsa} from '@nfps.dev/runtime'; -import {SecretContract, query_contract_infer} from '@solar-republic/neutrino'; +import { + create_svg, + qsa, +} from '@nfps.dev/runtime'; +import {SecretContract} from '@solar-republic/neutrino'; import {dm_root} from './common'; -// show onlyscripts -qsa(dm_root, '.onlyscript').map(dm_elmt => dm_elmt.classList.remove('onlyscript')); - -// env vars -const h_env = process.env; - -// wait for document to load -addEventListener('load', async() => { - const sa_contract = h_env['NFP_SELF_CONTRACT'] as SecretBech32; - const p_lcd = h_env['NFP_WEB_LCDS']?.split(',')[0] as HttpsUrl; - - // save reusable globals - oda(window, { - // boot info - loc: [h_env['NFP_SELF_CHAIN'], sa_contract, h_env['NFP_SELF_TOKEN']], - lcd: p_lcd, - qp: null, - vk: h_env['NFP_VIEWING_KEY'], - sc: await SecretContract(p_lcd, sa_contract), - - // reserved - toa: '', - - // override inject function to link locally instead - load(si_lib: string) { - return create_svg('script', { - href: `./${si_lib.replace(/\.js$/, '.dev.js')}`, - }); - }, - - // runtime functions - lsgs: ls_get_str, - lsss: ls_set_str, - lsgj: ls_get_json, - lssj: ls_set_json, - - // neutrino functions - qci: query_contract_infer, +// exporting as a function ensures no side effects when imported +export default function autoboot(): void { + // show onlyscripts + qsa(dm_root, '.onlyscript').map(dm_elmt => dm_elmt.classList.remove('onlyscript')); + + // env vars + const h_env = import.meta.env; + + // wait for document to load + addEventListener('load', async() => { + const sa_contract = h_env.SELF_CONTRACT as SecretBech32; + const p_lcd = h_env.WEB_LCDS?.split(',')[0] as HttpsUrl; + const p_comc = h_env.WEB_COMCS?.split(',')[0] as HttpsUrl; + + // override sdk's default script loader with a custom one to link to local package instead + const load_script = nfpx.l = si_package => Promise.resolve(create_svg('script', { + href: `./${si_package.replace(/\.js$/, '.dev.js')}`, + })); + + // save reusable globals + exportNfpx({ + // boot info + A_TOKEN_LOCATION: [h_env.SELF_CHAIN!, sa_contract, h_env.SELF_TOKEN!], + P_LCD: p_lcd, + G_QUERY_PERMIT: null, + SH_VIEWING_KEY: h_env.VIEWING_KEY!, + K_CONTRACT: await SecretContract(p_lcd, sa_contract), + P_COMC_HOST: p_comc, + + // export the custom script loader + load_script, + }); + + // inject the app + dm_root.append(create_svg('script', { + href: './app.dev.js', + })); + + // hide banner + qsa(dm_root, '#default div')[0].style.display = 'none'; }); - - // inject the app - dm_root.append(create_svg('script', { - href: './app.dev.js', - })); - - // hide banner - qsa(dm_root, '#default div')[0].style.display = 'none'; -}); +} diff --git a/bootloader/src/bootloader.ts b/bootloader/src/bootloader.ts index e540623..871cc1a 100644 --- a/bootloader/src/bootloader.ts +++ b/bootloader/src/bootloader.ts @@ -1,59 +1,87 @@ -import {oda} from '@blake.regalia/belt'; -import {ls_get_str, type BootInfo, ls_set_str, ls_get_json, ls_set_json} from '@nfps.dev/runtime'; +import type {NfpxExports} from './env'; + +import type {BootInfo} from '@nfps.dev/runtime'; +import type {HttpsUrl} from '@solar-republic/neutrino'; import { boot, load_script, + ls_read, + ls_write, + ls_read_json, + ls_write_json, + nfp_attr, + nfp_tags, } from '@nfps.dev/runtime'; import { query_contract_infer, } from '@solar-republic/neutrino'; +// import autoboot as a module so that it can be optimized out in production +import autoboot from './_autoboot'; + // for side-effects import './common'; -// bind boot function to global so that user has to click to boot -window.boot = async(d_event) => { - const dm_button = d_event.target as HTMLButtonElement; - dm_button.textContent = 'Connecting...'; - dm_button.disabled = true; - - // boot and save bootinfo - let a_info: BootInfo | void; - if((a_info=await boot())) { // eslint-disable-line @typescript-eslint/no-extra-parens - const dm_div = dm_button.closest('div')!; - dm_div.firstChild!.textContent = 'Loaded latest app from chain'; - dm_div.style.background = '#2ec'; - dm_div.style.opacity = '0'; - - dm_button.textContent = 'Connected'; - - // save reusable globals - oda(window, { - // boot info - loc: a_info[0], - lcd: a_info[1], - qp: a_info[2], - vk: a_info[3], - sc: a_info[4], - - // reserved - toa: '', - - // runtime functions - load: load_script, - lsgs: ls_get_str, - lsss: ls_set_str, - lsgj: ls_get_json, - lssj: ls_set_json, - - // neutrino functions - qci: query_contract_infer, - }); - } - // boot failed - else { - dm_button.textContent = 'Failed'; - } +// development mode; perform autoboot +if(import.meta.env.DEV) { + autoboot(); +} +// production +else { + // bind boot function to global so that user has to click to boot + window.boot = async(d_event) => { + const dm_button = d_event.target as HTMLButtonElement; + dm_button.textContent = 'Connecting...'; + dm_button.disabled = true; + + // boot and save bootinfo + let a_info: BootInfo | void; + if((a_info=await boot())) { // eslint-disable-line @typescript-eslint/no-extra-parens + const dm_div = dm_button.closest('div')!; + dm_div.firstChild!.textContent = 'Loaded latest app from chain'; + dm_div.style.background = '#2ec'; + dm_div.style.opacity = '0'; + + dm_button.textContent = 'Connected'; + + // save reusable globals + exportNfpx({ + // boot info + A_TOKEN_LOCATION: a_info[0], + P_LCD: a_info[1], + G_QUERY_PERMIT: a_info[2], + SH_VIEWING_KEY: a_info[3], + K_CONTRACT: a_info[4], + + // comc host + P_COMC_HOST: import.meta.env.WEB_COMCS?.split(',')[0] as HttpsUrl, + }); + } + // boot failed + else { + dm_button.textContent = 'Reset'; + dm_button.disabled = false; + dm_button.onclick = () => { + dm_button.disabled = true; + localStorage.clear(); + dm_button.textContent = 'Done. Reload to retry'; + }; + } + }; +} + +// export anything that may come in handy to reuse in the app or applibs +export { + load_script, + ls_read, + ls_write, + ls_read_json, + ls_write_json, + query_contract_infer, + nfp_tags, + nfp_attr, }; + +export default interface Default extends NfpxExports {} diff --git a/bootloader/src/env.ts b/bootloader/src/env.ts new file mode 100644 index 0000000..0867285 --- /dev/null +++ b/bootloader/src/env.ts @@ -0,0 +1,26 @@ +/// +/// + +import type {Nilable, Promisable} from '@blake.regalia/belt'; +import type {SlimTokenLocation, load_script} from '@nfps.dev/runtime'; +import type {HttpsUrl, QueryPermit, SecretContract} from '@solar-republic/neutrino'; + +// declare what the bootloader can export dynamically +export interface NfpxExports { + A_TOKEN_LOCATION: SlimTokenLocation; + P_LCD: HttpsUrl; + K_CONTRACT: SecretContract; + G_QUERY_PERMIT: Nilable; + SH_VIEWING_KEY: string; + P_COMC_HOST: HttpsUrl; + + load_script?: typeof load_script; +} + +/* eslint-disable @typescript-eslint/naming-convention,no-var */ +declare global { + var boot: (d_event: MouseEvent) => Promisable; + var dismiss: () => void; + + function exportNfpx(h_exports: NfpxExports): void; +} diff --git a/bootloader/src/global.ts b/bootloader/src/global.ts deleted file mode 100644 index a56dd64..0000000 --- a/bootloader/src/global.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention,no-var */ -import type {Promisable, Nilable} from '@blake.regalia/belt'; - -import type { - SlimTokenLocation, - load_script, - ls_get_json, - ls_get_str, - ls_set_json, - ls_set_str, -} from '@nfps.dev/runtime'; - -import type { - SecretContract, - QueryPermit, - Wallet, - HttpsUrl, - query_contract_infer, - SecretBech32, -} from '@solar-republic/neutrino'; - -declare global { - var boot: (d_event: MouseEvent) => Promisable; - var dismiss: () => void; - - /** - * Save the boot info to the global scope so that the app can use it right away - */ - var loc: SlimTokenLocation; - var lcd: HttpsUrl; - var qp: QueryPermit | undefined; - var vk: string | undefined; - var sc: SecretContract; - - /** - * Reserved - */ - var toa: SecretBech32; - - /** - * Runtime functions - */ - var load: typeof load_script; - var lsgs: typeof ls_get_str; - var lsss: typeof ls_set_str; - var lsgj: typeof ls_get_json; - var lssj: typeof ls_set_json; - - /** - * Since the bootloader includes some neutrino lib, make some functions available for reuse - */ - var qci: typeof query_contract_infer; -} diff --git a/build.mjs b/build.mjs index c36aadb..8b5e0bb 100644 --- a/build.mjs +++ b/build.mjs @@ -14,10 +14,11 @@ const { NFP_SELF_CHAIN: si_chain, NFP_SELF_CONTRACT: sa_contract, NFP_SELF_TOKEN: si_token, - NODE_ENV: SI_NODE_ENV, + NFP_ENV: SI_NFP_ENV, } = h_env; -const B_DEV = 'development' === SI_NODE_ENV; +const B_DEV = 'development' === SI_NFP_ENV; +const B_PROD = !B_DEV; const h_argv = yargs(hideBin(process.argv)) .scriptName('build').usage('$0 [flags]') @@ -42,7 +43,7 @@ const h_argv = yargs(hideBin(process.argv)) // make sure autoboot is only used in development mode if(h_argv.autoboot && !B_DEV) { - throw new Error(`Option '-a' can only be used when NODE_ENV=development`); + throw new Error(`Option '-a' can only be used when NFP_ENV=development`); } const sx_out = await build({ @@ -51,6 +52,7 @@ const sx_out = await build({ metadata: { web: { lcds: h_env['NFP_WEB_LCDS']?.split(','), + rpcs: h_env['NFP_WEB_RPCS']?.split(','), comcs: h_env['NFP_WEB_COMCS']?.split(','), }, self: { @@ -94,32 +96,24 @@ const sx_out = await build({ const dm_root = document.documentElement; // inject content - dm_root.append(...h_argv.autoboot - // autoboot mode: omit bootloader and use autoboot script instead - ? [ - // autoboot (should inject app once it's completed any async bootup tasks) - create.svg('script', { - href: './_autoboot.dev.js' - }), - ] - // use bootloader - : [ - // bootloader; depending on environment - B_DEV && h_argv.link - // development: link to bootloader for better debugging experience in browser - ? create.svg('script', { - href: './bootloader.dev.js' - }) - // testing/production: inline script - : create.svg('script', {}, [ - fs.readFileSync(`./dist/bootloader${B_DEV? '.dev': ''}.js`, 'utf8'), - ]), - - // fetch latest app from chain + dm_root.append( + // bootloader; depending on environment + B_DEV && h_argv.link + // development: link to bootloader for better debugging experience in browser + ? create.svg('script', { + href: './bootloader.dev.js' + }) + // testing/production: inline script + : create.svg('script', {}, [ + fs.readFileSync(`./dist/bootloader${B_DEV? '.dev': ''}.js`, 'utf8'), + ]), + + // fetch latest app from chain in production mode + ...B_DEV? []: [ create.nfp('script', { src: 'app.js?tag=latest', }), - ] + ], ); }, }); diff --git a/deploy.ts b/deploy.ts deleted file mode 100644 index a7295fe..0000000 --- a/deploy.ts +++ /dev/null @@ -1,230 +0,0 @@ -import type {Uint128} from '@blake.regalia/belt'; - - -import {readFile} from 'node:fs/promises'; -import path from 'node:path'; -import readline from 'node:readline'; -import zlib from 'node:zlib'; - -import {oderac, base64_to_buffer, buffer_to_base64, hex_to_buffer, buffer_to_hex} from '@blake.regalia/belt'; -import { - format_query, - query_contract, - type HttpsUrl, - type SecretBech32, -} from '@solar-republic/neutrino'; - - -import { - gen_sk, - sk_to_pk, - pubkey_to_bech32, - Wallet, - SecretContract, - query_contract_infer, - exec_contract, - sign_query_permit, -} from '@solar-republic/neutrino'; - -// load environment variables -import * as dotenv from 'dotenv'; -dotenv.config(); -const h_env = process.env; - -// polyfil crypto for older node versions -if(!globalThis.crypto) globalThis.crypto = (await import('node:crypto')).webcrypto; - -// load private key -const sh_sk = h_env['NFP_WALLET_PRIVATE_KEY']; - -// no private key found, generate a new one -if(!sh_sk) { - const atu8_sk = gen_sk(); - const sb16_sk_gen = buffer_to_hex(atu8_sk); - const sa_gen = await pubkey_to_bech32(sk_to_pk(atu8_sk)); - console.log(`No private key found; here is a new account you can use for testing...\n NFP_OWNER="${sa_gen}"\n NFP_WALLET_PRIVATE_KEY="${sb16_sk_gen}"`); - process.exit(0); -} - -// user-friendly output -const print = (s_header: string, h_fields: object) => console.log(s_header+'\n'+oderac(h_fields, (si_key, s_label) => ` ${si_key}: ${s_label}`).join('\n')+'\n'); - -// destructure env vars -const { - NFP_SELF_CHAIN: si_chain, - NFP_WEB_LCDS: s_lcds, - NFP_SELF_CONTRACT: sa_contract, -} = h_env; - -// decode private key -let atu8_sk; -if(64 === sh_sk.length) atu8_sk = hex_to_buffer(sh_sk); -else atu8_sk = atu8_sk = base64_to_buffer(sh_sk); - -const p_lcd = s_lcds?.split(',')[0] as HttpsUrl; - -// create wallet -const k_wallet = await Wallet(atu8_sk, si_chain!, p_lcd); - -// connect to the contract -const k_contract = await SecretContract(p_lcd, sa_contract as SecretBech32); - -// // sign permit -// const g_permit = await sign_query_permit(k_wallet, 'test', [sa_contract], ['balance', 'owner']); - -// await query_contract_infer(k_contract, 'num_tokens', {}); - -// await set_vk(process.env['NFP_VIEWING_KEY']!); - -// await storage_owner_put(); - -// await upload_script('dist/app.js'); -// await upload_script('dist/storage.js', ['1.x', 'latest']); - -(async() => { - // await mint(); - await set_vk('test123'); - // await storage_owner_put(); - // await upload_script('dist/app.js'); - // await upload_script('dist/storage.js', ['1.x', 'latest']); -})(); - -// mint -async function mint() { - console.log(...await exec_contract(k_contract, k_wallet, { - mint_nft: { - token_id: '1', - public_metadata: { - token_uri: 'test-public', - }, - private_metadata: { - token_uri: 'test-private', - }, - }, - }, [['6000', 'uscrt']], `${60000n}`)); -} - -// set viewing key -async function set_vk(sh_vk: string) { - const g_msg = { - set_viewing_key: { - key: sh_vk, - }, - }; - - print('Executing contract', { - contract: k_contract.addr, - from: k_wallet.addr, - message: JSON.stringify(g_msg), - }); - - console.log(...await exec_contract(k_contract, k_wallet, g_msg, [['5000', 'uscrt']], `${50000n}`)); - - const h_query = format_query('storage_owner_get', { - keys: ['test'], - }, ['test123', k_wallet.addr]); - - print('Querying contract', { - contract: k_contract.addr, - message: JSON.stringify(h_query), - }); - - const a_response = await query_contract(k_contract, h_query); - console.log(...a_response); -} - -// write to owner storage -async function storage_owner_put() { - const g_msg = { - storage_owner_put: { - data: [{ - key: 'test', - value: 'data', - }], - }, - }; - - print('Executing contract', { - contract: k_contract.addr, - from: k_wallet.addr, - message: JSON.stringify(g_msg), - }); - - console.log(...await exec_contract(k_contract, k_wallet, g_msg, [['5000', 'uscrt']], `${50000n}`)); - - const h_query = format_query('storage_owner_get', { - keys: ['test'], - }, ['test123', k_wallet.addr]); - - print('Querying contract', { - contract: k_contract.addr, - message: JSON.stringify(h_query), - }); - - const a_response = await query_contract(k_contract, h_query); - console.log(JSON.stringify(a_response[2])); -} - -async function upload_script(sr_path: string, a_tags=['latest'], si_package='') { - // read file contents - const atu8_contents = await readFile(sr_path); - - // package name - if(!si_package) si_package = path.basename(sr_path); - - // compress using gzip - const atu8_compressed = zlib.gzipSync(atu8_contents, { - level: zlib.constants.Z_BEST_COMPRESSION, - }); - - // verbose - print('Gzip compression results:', { - 'file': sr_path, - 'before': `${atu8_contents.byteLength} bytes`, - ' after': `${atu8_compressed.byteLength} bytes`, - }); - - // tx fee - const xg_limit = 60_000n; - const x_price = 0.125; - const x_fee = Math.ceil(Number(xg_limit) * x_price); - - // prep readlne interface - const d_rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - print('Ready to upload:', { - chain: si_chain, - contract: k_contract.addr, - package: si_package, - tags: a_tags.join(', '), - from: k_wallet.addr, - }); - - // confirm - d_rl.question('Broadcast transaction? (y/n): ', async(s_ans) => { - // ok - if(s_ans.startsWith('y')) { - // upload package - const [xc_code, s_res, g_tx] = await exec_contract(k_contract, k_wallet, { - upload_package_version: { - package_id: si_package, - tags: a_tags, - data: { - bytes: buffer_to_base64(atu8_compressed), - content_type: 'application/ecmascript', - content_encoding: 'gzip', - }, - }, - }, [[`${x_fee}` as Uint128, 'uscrt']], `${xg_limit}`); - - // log result - console.log(xc_code, s_res.trim(), g_tx); - } - - // done - d_rl.close(); - }); -} diff --git a/media/preview.html b/media/preview.html index 4d8e956..9577ebe 100644 --- a/media/preview.html +++ b/media/preview.html @@ -5,5 +5,12 @@ + +
+ +
+
\ No newline at end of file diff --git a/media/template.svg b/media/template.svg index 63a2c4e..76bc58b 100644 --- a/media/template.svg +++ b/media/template.svg @@ -77,19 +77,20 @@ - + - + - - + + + diff --git a/package.json b/package.json index 7dfa4eb..a050034 100644 --- a/package.json +++ b/package.json @@ -6,57 +6,68 @@ "type": "module", "main": "dist/main.js", "scripts": { - "build:bootloader": "rollup -c bootloader/rollup.config.ts --configPlugin @rollup/plugin-typescript", - "dev:bootloader": "yarn build:bootloader --environment NODE_ENV:development", + "rollup": "./node_modules/.bin/rollup", + "vite": "./node_modules/.bin/vite", + "build:bootloader": "yarn rollup -c bootloader/rollup.config.ts --configPlugin @rollup/plugin-typescript", + "dev:bootloader": "yarn build:bootloader --environment NFP_ENV:development", "build:svg": "node build.mjs", - "dev:svg": "NODE_ENV=development yarn build:svg -la -o dist/nfp.dev.svg", + "dev:svg": "NFP_ENV=development yarn build:svg -la -o dist/nfp.dev.svg", "build:nfp": "yarn build:bootloader && yarn build:svg", "dev:nfp": "yarn dev:bootloader && yarn dev:svg", - "build:app": "vite build app", - "dev:app": "NODE_ENV=development yarn build:app --mode development", + "build:app": "yarn vite build app", + "dev:app": "NFP_ENV=development yarn build:app --mode development", "watch:app": "yarn dev:app -w", - "deploy:app": "node --loader ts-node/esm deploy.ts", - "build:applibs": "rollup -c applibs/rollup.config.ts --configPlugin @rollup/plugin-typescript", - "dev:applibs": "yarn build:applibs --environment NODE_ENV:development", + "deploy:app": "nfp package upload dist/app.js", + "build:applibs": "yarn rollup -c applibs/rollup.config.ts --configPlugin @rollup/plugin-typescript", + "dev:applibs": "yarn build:applibs --environment NFP_ENV:development", "build": "yarn build:applibs && yarn build:app && yarn build:nfp", "dev": "yarn dev:applibs && yarn dev:app && yarn dev:nfp && echo \"\\n-------- READY --------\\n\"", - "watch:dev": "ls {app,applibs,bootloader,media}/**/*.* package.json build.ts | entr yarn dev", - "watch:build": "ls {app,applibs,bootloader,media}/**/*.* package.json build.ts | entr yarn build" + "watch:dev": "ls {app,applibs,bootloader,media}/**/*.* package.json build.{mjs,ts} | entr yarn dev", + "watch:build": "ls {app,applibs,bootloader,media}/**/*.* package.json build.{mjs,ts} | entr yarn build" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { - "@blake.regalia/belt": "^0.12.0", - "@blake.regalia/eslint-config-elite": "^0.2.8", + "@blake.regalia/belt": "^0.15.0", + "@blake.regalia/eslint-config-elite": "^0.3.3", "@blake.regalia/tsconfig": "^0.1.2", + "@cosmjs/amino": "^0.31.1", + "@fortawesome/fontawesome-svg-core": "^6.4.2", + "@fortawesome/free-solid-svg-icons": "^6.4.2", + "@keplr-wallet/types": "^0.12.23", "@nfps.dev/rollup-plugin-microweb": "^0.3.5", - "@nfps.dev/sdk": "^0.3.0", + "@nfps.dev/sdk": "^0.7.5", "@rollup/plugin-replace": "^5.0.2", - "@rollup/plugin-typescript": "^11.1.1", - "@types/node": "^20.2.1", - "@types/web": "^0.0.99", - "@typescript-eslint/parser": "^5.59.6", - "dotenv": "^16.0.3", - "eslint": "^8.41.0", + "@rollup/plugin-typescript": "^11.1.3", + "@types/node": "^20.6.0", + "@types/web": "^0.0.114", + "@types/ws": "^8.5.5", + "@typescript-eslint/parser": "^6.6.0", + "dotenv": "^16.3.1", + "eslint": "^8.49.0", "eslint-plugin-svelte3": "^4.0.0", - "less": "^4.1.3", - "rollup": "^3.22.0", + "io-ts-transformer": "^1.1.8", + "less": "^4.2.0", + "rollup": "^3.29.1", "rollup-plugin-inject-process-env": "^1.3.1", - "svelte": "^3.59.1", - "svelte-check": "^3.3.2", - "svelte-preprocess": "^5.0.3", + "rollup-plugin-svelte": "^7.1.6", + "rollup-plugin-typescript2": "^0.35.0", + "svelte": "^4.2.0", + "svelte-check": "^3.5.1", + "svelte-preprocess": "^5.0.4", "ts-node": "^10.9.1", "ts-toolbelt": "^9.6.0", - "typescript": "^5.0.4", - "vite": "^4.3.8", - "xml-formatter": "^3.4.1", + "typescript": "^5.2.2", + "vite": "^4.4.9", + "ws": "^8.14.1", + "xml-formatter": "^3.5.0", "yargs": "^17.7.2" }, "dependencies": { - "@nfps.dev/runtime": "^0.8.0", - "@solar-republic/neutrino": "^0.3.7", - "@sveltejs/vite-plugin-svelte": "^2.2.0", - "D": "^1.0.0" + "@nfps.dev/runtime": "^0.13.0", + "@solar-republic/neutrino": "^0.7.0", + "@sveltejs/vite-plugin-svelte": "^2.4.5", + "idb-keyval": "^6.2.1" } } diff --git a/tsconfig.json b/tsconfig.json index 32b08a4..507e332 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,11 +6,21 @@ "outDir": "dist", "declaration": true, - "declarationDir": "dist" + "declarationDir": "dist", + + "module": "ESNext", + + "paths": { + "nfpx:*?tag=latest": ["./dist/*.d.ts"], + "nfpx:*?tag=1.x": ["./dist/*.d.ts"], + "nfpx:*": ["./dist/*.d.ts"], + } }, "include": [ "app/**/*.ts", + "app/**/*.js", + "app/**/*.svelte", "bootloader/**/*.ts", "applibs/**/*.ts", "test/**/*.ts",