@@ -10,5 +10,5 @@ module.exports = Object.assign({}, config, {
|
||||
modulePathIgnorePatterns: [
|
||||
'<rootDir>/packages/wasm-schnorrkel/build'
|
||||
],
|
||||
resolver: './jest.resolver.js'
|
||||
resolver: '@polkadot/dev/config/jest-resolver'
|
||||
});
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const path = require('path');
|
||||
|
||||
module.exports = function resolver (file, config) {
|
||||
return file.includes('package.json')
|
||||
? path.join(config.basedir.replace('/src', '/'), file)
|
||||
: config.defaultResolver(file, config);
|
||||
};
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
[package]
|
||||
authors = ["Jaco Greeff <jacogr@gmail.com>"]
|
||||
description = "WASM bindings to Rust crypto libaries."
|
||||
description = "WASM bindings to Rust crypto libraries."
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
name = "wasm"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "1.5.0-beta.15",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"react-native": {
|
||||
"./wasm_asm_stub.js": "./wasm_asm.js"
|
||||
"./wasm/stub.js": "./wasm/asm.js"
|
||||
},
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
|
||||
6
packages/wasm-crypto/src/index.js
Normal file
6
packages/wasm-crypto/src/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const lib = require('./js');
|
||||
|
||||
module.exports = lib;
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
const { assert, stringToU8a, u8aToString } = require('@polkadot/util');
|
||||
|
||||
const pkg = require('./package.json');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
let wasm;
|
||||
let cachegetInt32 = null;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const wasmBytes = require('../wasm/bytes');
|
||||
const asmFallback = require('../wasm/stub');
|
||||
const { allocString, allocU8a, getWasm, initWasm, resultString, resultU8a, withWasm } = require('./bridge');
|
||||
const imports = require('./imports');
|
||||
const asmFallback = require('./wasm_asm_stub');
|
||||
const wasmBytes = require('./wasm_wasm');
|
||||
|
||||
const wasmPromise = initWasm(wasmBytes, asmFallback, imports).catch(() => null);
|
||||
|
||||
|
||||
@@ -5,7 +5,14 @@
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
#[path = "rs/bip39.rs"]
|
||||
pub mod bip39;
|
||||
|
||||
#[path = "rs/ed25519.rs"]
|
||||
pub mod ed25519;
|
||||
|
||||
#[path = "rs/hashing.rs"]
|
||||
pub mod hashing;
|
||||
|
||||
#[path = "rs/sr25519.rs"]
|
||||
pub mod sr25519;
|
||||
|
||||
6
packages/wasm-crypto/src/wasm/asm.js
Normal file
6
packages/wasm-crypto/src/wasm/asm.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Stub replaced at build time
|
||||
|
||||
module.exports = {};
|
||||
6
packages/wasm-crypto/src/wasm/bytes.js
Normal file
6
packages/wasm-crypto/src/wasm/bytes.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2020 @polkadot/wasm-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Stub replaced at build time
|
||||
|
||||
module.exports = Buffer.from();
|
||||
@@ -4,8 +4,8 @@
|
||||
global.WebAssembly = null;
|
||||
|
||||
require('override-require')(
|
||||
(request) => request === './wasm_asm_stub',
|
||||
() => require('../build/wasm_asm')
|
||||
(request) => request.endsWith('wasm/stub'),
|
||||
() => require('../build/wasm/asm')
|
||||
);
|
||||
|
||||
const { runUnassisted } = require('./all');
|
||||
|
||||
@@ -7,14 +7,21 @@ set -e
|
||||
|
||||
WSM=pkg/wasm_bg.wasm
|
||||
OPT=pkg/wasm_opt.wasm
|
||||
ASM=build/wasm_asm.js
|
||||
ASM=build/wasm/asm.js
|
||||
|
||||
echo "*** Building package"
|
||||
|
||||
# cleanup old
|
||||
echo "*** Cleaning old builds"
|
||||
rm -rf ./build ./pkg
|
||||
mkdir -p build
|
||||
mkdir -p build/js build/wasm
|
||||
|
||||
# copy our package interfaces
|
||||
echo "*** Copying package sources"
|
||||
cp package.json build/
|
||||
cp src/index.d.ts src/index.js build/
|
||||
cp src/js/* build/js/
|
||||
cp src/wasm/* build/wasm/
|
||||
|
||||
# build new via wasm-pack
|
||||
echo "*** Building WASM output"
|
||||
@@ -34,12 +41,8 @@ echo "*** Building asm.js version"
|
||||
|
||||
# cleanup the generated asm, converting to cjs
|
||||
sed -i -e '/import {/d' $ASM
|
||||
echo "const imports = require('./imports');
|
||||
echo "const imports = require('../js/imports');
|
||||
$(cat $ASM)" > $ASM
|
||||
sed -i -e 's/{abort.*},memasmFunc/imports, memasmFunc/g' $ASM
|
||||
sed -i -e 's/export var /module\.exports\./g' $ASM
|
||||
|
||||
# copy our package interfaces
|
||||
echo "*** Copying package sources"
|
||||
cp package.json build/
|
||||
cp src/js/* build/
|
||||
rm -rf build/wasm/*-e
|
||||
|
||||
@@ -12,6 +12,6 @@ cd packages/wasm-crypto
|
||||
../../scripts/test-package.sh
|
||||
|
||||
rm -rf build/*-e build/package.json build/README.md
|
||||
ls -al build
|
||||
ls -alR build
|
||||
|
||||
cd ../..
|
||||
|
||||
@@ -5,7 +5,7 @@ const fs = require('fs');
|
||||
|
||||
const buffer = fs.readFileSync('./pkg/wasm_opt.wasm');
|
||||
|
||||
fs.writeFileSync('./build/wasm_wasm.js', `// Generated as part of the build, do not edit
|
||||
fs.writeFileSync('./build/wasm/bytes.js', `// Generated as part of the build, do not edit
|
||||
|
||||
module.exports = Buffer.from('${buffer.toString('base64')}', 'base64');
|
||||
`);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@polkadot/wasm-schnorrkel": [ "packages/wasm-schnorrkel/src" ]
|
||||
"@polkadot/wasm-crypto": [ "packages/wasm-crypto/src" ]
|
||||
},
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
|
||||
Reference in New Issue
Block a user