This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Introduce new JS Api #4
Closed
Closed
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0efe8e9
unstable attempt to refactor the api
kianenigma 8216f3c
Merge branch 'master' into kiz-new-api
kianenigma 43d0a58
again; intermediary commit. have to switch back to master now
kianenigma baeb4ea
create new interface with less parameters
kianenigma 65bc34c
merge master and ready to be pulled
kianenigma ec1da79
test using result instead of no panic! #1
kianenigma 36f28c6
move to schnorrkel github -- this is broken until schnorr is updated …
kianenigma ddb7e86
finalize error handling #1
kianenigma b6ed88f
Merge branch 'master' of github.com:paritytech/schnorrkel-js into kiz…
kianenigma a9be7b5
new dual env build added
kianenigma f160767
bump build tool
kianenigma c37efc9
delivers a very ugly way to serve both webpack and node
kianenigma 6e0a409
Update README.md
kianenigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "schnorrkel-js" | ||
version = "0.1.2" | ||
version = "0.1.3" | ||
authors = ["kianenigma <[email protected]>"] | ||
edition = "2018" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
#!/usr/bin/env node | ||
|
||
console.log('+++ Fixing nodejs imports.\n'); | ||
|
||
const fs = require('fs'); | ||
const buffer = fs.readFileSync('./pkg/schnorrkel_js_bg.wasm'); | ||
|
||
fs.writeFileSync('./pkg/schnorrkel_js_bg.js', ` | ||
const imports = {}; | ||
imports['./schnorrkel_js'] = require('./schnorrkel_js'); | ||
const bytes = Buffer.from('${buffer.toString('base64')}', 'base64'); | ||
console.log('\t+++ Fixing node imports.'); | ||
fs.writeFileSync('./pkg/schnorrkel.node.bg.js', ` | ||
const path = require('path').join(__dirname, 'schnorrkel_js_bg.wasm'); | ||
const bytes = require('fs').readFileSync(path); | ||
let imports = {}; | ||
imports['./schnorrkel_js'] = require('./schnorrkel.node'); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
|
||
module.exports = wasmInstance.exports; | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env node | ||
console.log('\t+++ Fixing webpack imports.'); | ||
const fs = require('fs'); | ||
const buffer = fs.readFileSync('./pkg/schnorrkel_js_bg.wasm'); | ||
|
||
fs.writeFileSync('./pkg/schnorrkel.wp.bg.js', ` | ||
const imports = {}; | ||
imports['./schnorrkel_js'] = require('./schnorrkel.wp'); | ||
|
||
const bytes = Buffer.from('${buffer.toString('base64')}', 'base64'); | ||
|
||
const wasmModule = new WebAssembly.Module(bytes); | ||
const wasmInstance = new WebAssembly.Instance(wasmModule, imports); | ||
module.exports = wasmInstance.exports; | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env node | ||
console.log('\t+++ Fixing webpack imports.'); | ||
const fs = require('fs'); | ||
|
||
fs.writeFileSync('./pkg/schnorrkel.wp.bg.js', `const imports = {}; | ||
imports['./schnorrkel_js'] = require('./schnorrkel.wp'); | ||
WebAssembly.instantiateStreaming(fetch('./schnorrkel_js_bg.wasm'), imports) | ||
.then(results => { | ||
console.info('++ schnorrkel-js wasm blob loaded.') | ||
module.exports = results.instance.exports | ||
});`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@parity/schnorrkel-js", | ||
"description": "a wasm port of the schnorrkel crypto library.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/paritytech/schnorrkel-js" | ||
}, | ||
"author": "Parity Technologies <[email protected]> (https://parity.io/)", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/paritytech/schnorrkel-js/issues" | ||
}, | ||
"homepage": "https://github.com/paritytech/schnorrkel-js#readme", | ||
|
||
"collaborators": [ | ||
"kianenigma <[email protected]>" | ||
], | ||
"version": "0.1.5", | ||
"files": [ | ||
"schnorrkel_js_bg.wasm", | ||
|
||
"schnorrkel.wp.js", | ||
"schnorrkel.node.js", | ||
|
||
"schnorrkel_js_bg.js", | ||
"schnorrkel_js.d.ts" | ||
], | ||
"module": "schnorrkel.wp.js", | ||
"types": "schnorrkel_js.d.ts", | ||
"sideEffects": "false" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Compile the latest version; update ./pkg and readme files in it. | ||
wasm-pack build --target nodejs | ||
wasm-pack build --target nodejs --release | ||
mv ./pkg/schnorrkel_js.js ./pkg/schnorrkel.node.js | ||
mv ./pkg/schnorrkel_js_bg.js ./pkg/schnorrkel.node.bg.js | ||
sed -i -e 's/schnorrkel_js_bg/schnorrkel.node.bg/g' ./pkg/schnorrkel.node.js | ||
./pack-node.sh | ||
|
||
# Fix the name | ||
sed -i -e 's/schnorrkel-js/@parity\/schnorrkel-js/g' pkg/package.json | ||
wasm-pack build --target browser --release | ||
mv ./pkg/schnorrkel_js.js ./pkg/schnorrkel.wp.js | ||
sed -i -e 's/schnorrkel_js_bg/schnorrkel.wp.bg.js/g' ./pkg/schnorrkel.wp.js | ||
./pack-wp.sh | ||
# will most likely cause an error saying wasm blobl is larger than 4KB | ||
# ./pack-wp-raw.sh | ||
|
||
# Run the script to fix node/browser import support | ||
./pack-node.sh | ||
# Replace package.json file. | ||
cp ./package.json ./pkg/package.json | ||
|
||
# publish | ||
# wasm-pack publish | ||
# wasm-pack publish | ||
|
||
# replace this at the top of the .wp.js file | ||
# import get_wasm from './schnorrkel.wp.bg.js'; | ||
# var wasm = get_wasm() | ||
# // this line is a gamble... | ||
# setTimeout(() => wasm = get_wasm(), 500) | ||
# setTimeout(() => wasm = get_wasm(), 1000) | ||
# setTimeout(() => wasm = get_wasm(), 1500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caller needs to wait for the actual promise result to ensure it has been added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed but then the export functions will be broken (
export
can only be used in the top level code.). Webpack's asyncimport()
function should be a proper fix for this I believe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will defintaly not merge this branch until at least this ugly thing is gone but it is good to have it pushed in here so that it can be tested without the need to place this horrble piece of code in npm :D