using nostr-tools with a facade.

This commit is contained in:
fiatjaf 2022-03-05 13:21:21 -03:00
parent 892b2122b8
commit 3a97f7928b
6 changed files with 40 additions and 6 deletions

View File

@ -1,7 +1,23 @@
#!/usr/bin/env node
require('esbuild').buildSync({
const esbuild = require('esbuild')
const alias = require('esbuild-plugin-alias')
const nodeGlobals = require('@esbuild-plugins/node-globals-polyfill').default
esbuild
.build({
entryPoints: ['globals.js'],
outfile: 'globals.bundle.js',
bundle: true
bundle: true,
plugins: [
alias({
stream: require.resolve('readable-stream')
}),
nodeGlobals({buffer: true})
],
define: {
window: 'self',
global: 'self'
}
})
.then(() => console.log('build success.'))

View File

@ -1,2 +1,3 @@
window.React = require('react')
window.ReactDOM = require('react-dom')
window.Nostr = require('nostr-tools')

View File

@ -1,5 +1,5 @@
<meta charset=utf-8>
<title>title</title>
<title>nostr army knife - nak</title>
<body></body>
<script src=globals.bundle.js></script>
<script src=target/scala-2.13/app-fastopt/main.js></script>

View File

@ -3,7 +3,11 @@
"start": "./build.js && sbt ~fastLinkJS"
},
"dependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"esbuild": "^0.14.23",
"esbuild-plugin-alias": "^0.2.1",
"events": "^3.3.0",
"nostr-tools": "^0.22.2",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}

View File

@ -7,6 +7,7 @@ import slinky.web.html._
import slinky.core.facade.Hooks._
import slinky.core.facade.Fragment
import app.modules.Nostr
import app.handlers.{Handler}
import app.components.{Item}
@ -19,7 +20,9 @@ object KeyHandling extends Handler {
override val component = FunctionalComponent[String] { props =>
Fragment(
Item.component(Item.props("private key", "", props)),
Item.component(Item.props("public key", "", "soon to be shown here"))
Item.component(
Item.props("public key", "", Nostr.getPublicKey(props))
)
)
}
}

View File

@ -0,0 +1,10 @@
package app.modules
import scala.scalajs.js.annotation._
import scala.scalajs.js
@js.native
@JSGlobal
object Nostr extends js.Object {
def getPublicKey(text: String): String = js.native
}