Git Product home page Git Product logo

wasm's People

Contributors

evgeny-s avatar github-actions[bot] avatar jacogr avatar shelvenzhou avatar stiiifff avatar tarikgul avatar v-zhzhou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasm's Issues

`web3/schnorrkel` failed to verify `ext_sr_sign` generated signatures

Description

Hello! I'm trying to use the repository https://github.com/w3f/schnorrkel, more specifically the function verify_simple to verify signatures generated by polkadot-js using thesignRaw function and unforunately it's not working. However the function signatureVerify from @polkadot/util-crypto verify correctly the same signature.

Steps to reproduce

  1. I've used the polkadot extension and the polkadot-js to generate the signature
scren-record.mov
output at console.log 

Public Key (hex) 0xf84d048da2ddae2d9d8fd6763f469566e8817a26114f39408de15547f6d47805
Message => message to sign
Signature (hex) 0x48ce2c90e08651adfc8ecef84e916f6d1bb51ebebd16150ee12df247841a5437951ea0f9d632ca165e6ab391532e75e701be6a1caa88c8a6bcca3511f55b4183
  1. With the https://github.com/w3f/schnorrkel cloned at my machine I created the following test case (which fails) at src/sign.rs file:
#[test]
fn verify_polkadot_js_signature() {
      use hex_literal::hex;
      const CTX : &'static [u8] = b"substrate";
        
      let message = b"message to sign";
      let public = hex!("f84d048da2ddae2d9d8fd6763f469566e8817a26114f39408de15547f6d47805");
      let public = PublicKey::from_bytes(&public[..]).unwrap();
        
      let signature = hex!("48ce2c90e08651adfc8ecef84e916f6d1bb51ebebd16150ee12df247841a5437951ea0f9d632ca165e6ab391532e75e701be6a1caa88c8a6bcca3511f55b4183");
      let signature = Signature::from_bytes(&signature).unwrap();
        
      let ok = public.verify_simple(CTX, message, &signature).is_ok();
      assert!(ok)
}

Debugging the polkadot-js signatureVerify function I noticed that this function calls the rust function ext_sr_verify under the hoods by a WASM biding (very interestingly 😄 ) and the rust function uses the same w3f/schnorrkel repository, then I assumed the function ext_sr_sign is used to generate the signature so I decided to create the following test case that uses these 2 functions to generate and verify a signature:

    #[test]
fn sign_and_verify() {
        const CTX : &'static [u8] = b"substrate";
        let sec = SecretKey::generate();
        let pub_bytes = sec.to_public().to_bytes();
        
        // ext_sr_sign function
        let sig = match (SecretKey::from_ed25519_bytes(&sec.to_bytes()), PublicKey::from_bytes(&pub_bytes)) {
            (Ok(s), Ok(k)) => s
                .sign_simple(CTX, message, &k)
                .to_bytes()
                .to_vec(),
            _ => panic!("Invalid secret or pubkey provided.")
        };

        // ext_sr_verify function
        let res =   match (Signature::from_bytes(&sig), PublicKey::from_bytes(&pub_bytes)) {
            (Ok(s), Ok(k)) => k
                .verify_simple(CTX, message, &s)
                .is_ok(),
            _ => false
        };

        assert!(res)
}

And unfortunately, this test case fails. The same thing happens with the https://github.com/ChainSafe/go-schnorrkel package, the original issue was reported into Gossamer discord channel.

Thanks in advance!

Out-of-bound object update

  • **I'm submitting a small bug report for trying to dynamically extend an object. **
  • Bug report
  • Feature request
  • Support request
  • Other
  • What is the current behavior and expected behavior?

I have found that, 2 loops have wrong limits and as a result, code tries to assign value to object with a key out-of-bound.
First bug
In last loop of above example, code does this:

out[out.length] = 0;

This is ignored in node (v18) and browser (tested on Chrome). Furthermore, it crashes on specific environments (e.g. QuickJS)

Test in Node:
image
Output:
image

To fix first bug, changing from count = out.length to count = out.length-1 will be enough.
Second bug
This line tried this ++l[-1] many times, first time called by here.

I will update here if I find other places (and if you would like to handle this issue)

  • What is the motivation for changing the behavior?
    I am trying to use polkadot.js with QuickJS (to use it in Godot game engine). It causes to errors in QuickJS. Also it causes unnecessary operations in other environments and may lead to other bugs in future.
  • Please tell us about your environment:
  • Version: 7.3.1

  • Environment:

    • Node.js
    • Browser
    • Other (QuickJS)
  • Language:

    • JavaScript
    • TypeScript (include tsc --version)
    • Other

crash on iOS 11

We have Polkadot.js integrated in react-native, but it crashes under iOS 11.

It should be that iOS 11 isn't compatible with wasm. Can we don't use wasm? Or is there a way to make it compatible?

Here is the log:

Crashed: com.facebook.react.JavaScript
0  JavaScriptCore                 0x18bee82e4 JSC::ExecutableAllocator::allocate(unsigned long, void*, JSC::JITCompilationEffort) + 644
1  JavaScriptCore                 0x18bee82e4 JSC::ExecutableAllocator::allocate(unsigned long, void*, JSC::JITCompilationEffort) + 644
2  JavaScriptCore                 0x18c1501dc JSC::LinkBuffer::allocate(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 256
3  JavaScriptCore                 0x18c14f8b4 void JSC::LinkBuffer::copyCompactAndLinkCode<unsigned int>(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 60
4  JavaScriptCore                 0x18c14f7c4 JSC::LinkBuffer::linkCode(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 56
5  JavaScriptCore                 0x18c3208e4 JSC::Wasm::throwExceptionFromWasmThunkGenerator(WTF::AbstractLocker const&) + 764
6  JavaScriptCore                 0x18c320e48 JSC::Wasm::Thunks::stub(WTF::AbstractLocker const&, JSC::MacroAssemblerCodeRef (*)(WTF::AbstractLocker const&)) + 120
7  JavaScriptCore                 0x18c321210 JSC::Wasm::Thunks::stub(JSC::MacroAssemblerCodeRef (*)(WTF::AbstractLocker const&)) + 92
8  JavaScriptCore                 0x18c308b14 JSC::Wasm::Memory::create(JSC::VM&, JSC::Wasm::PageCount, JSC::Wasm::PageCount) + 96
9  JavaScriptCore                 0x18c119540 JSC::JSWebAssemblyInstance::create(JSC::VM&, JSC::ExecState*, JSC::JSWebAssemblyModule*, JSC::JSObject*, JSC::Structure*) + 3020
10 JavaScriptCore                 0x18c342aec JSC::instantiate(JSC::VM&, JSC::ExecState*, JSC::JSPromiseDeferred*, JSC::JSWebAssemblyModule*, JSC::JSObject*, JSC::Resolve) + 116
11 JavaScriptCore                 0x18c2438ac JSC::PromiseDeferredTimer::doWork() + 524
12 JavaScriptCore                 0x18c0d3d70 JSC::JSRunLoopTimer::timerDidFireCallback(__CFRunLoopTimer*, void*) + 76
13 CoreFoundation                 0x184fc3dc0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
14 CoreFoundation                 0x184fc3ae4 __CFRunLoopDoTimer + 864
15 CoreFoundation                 0x184fc32e4 __CFRunLoopDoTimers + 248
16 CoreFoundation                 0x184fc0ecc __CFRunLoopRun + 1928
17 CoreFoundation                 0x184ee0c58 CFRunLoopRunSpecific + 436
18 React                          0x102655b2c +[RCTCxxBridge runRunLoop] + 264
19 Foundation                     0x185a170f4 __NSThread__start__ + 996
20 libsystem_pthread.dylib        0x184c442b4 _pthread_body + 308
21 libsystem_pthread.dylib        0x184c44180 _pthread_body + 310
22 libsystem_pthread.dylib        0x184c42b74 thread_start + 4

Can't interop with subkey

Guys, I'm driving myself crazy and I hope you can help me out.

If I sign a message with @polkadot, I can't then verify it with subkey, how does that work?

// Output:
//
// pub: 6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
// secret: a8e59c0eaa54b586bafabe3e4c5597d6b96677c61105e60b0f690327f8d4db4fc7f7331ec0a5bd07390edee454c6e60508af900be8b8682da35b94420992f460
// sig: ead0899d04969bea6857a95a2404babf77844d852431383d7adfabbceebe066b87d3888af454ecf1775dd84e7dbfe12266f15d1346c5d8778bad2cdcf2744683

const { sr25519PairFromSeed, sr25519Sign, cryptoWaitReady } = require('@polkadot/util-crypto')

cryptoWaitReady().then(() => {
    const pair = sr25519PairFromSeed(Buffer.from("42f2524bd7800cc244deb8ce5b4c24cb262c1ba317b86880d7ff33f1e93c6348", 'hex'))

    console.log(Buffer.from(pair.publicKey).toString('hex'))
    console.log(Buffer.from(pair.secretKey).toString('hex'))

    console.log(Buffer.from(sr25519Sign("test message", pair)).toString('hex'))
})

From subkey:

$ subkey inspect "time treat merit corn crystal fiscal banner zoo jacket pulse frog long"
Secret phrase:       time treat merit corn crystal fiscal banner zoo jacket pulse frog long

  Network ID:        substrate
  Secret seed:       0x42f2524bd7800cc244deb8ce5b4c24cb262c1ba317b86880d7ff33f1e93c6348
  Public key (hex):  0x6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
  Account ID:        0x6a7636545fecfa16f2e37679ea8547685cc2149807f94a4ada6ec0a264ead14d
  Public key (SS58): 5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
  SS58 Address:      5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
  
$ echo "test message" | subkey verify ead0899d04969bea6857a95a2404babf77844d852431383d7adfabbceebe066b87d3888af454ecf1775dd84e7dbfe12266f15d1346c5d8778bad2cdcf2744683 5EUJ3p7ds1436scqdA2n6ph9xVs6chshRP1ADjgK1Qj3Hqs2
Error: SignatureInvalid

For context

I got here because I am getting an error 1010 when submitting a balance transfer to Westend. I then found these two but I didn't manage to get anywhere either. This code still fails:

const CTX : &'static [u8] = b"substrate";
let sec = SecretKey::generate();
let pub_bytes = sec.to_public().to_bytes();

let message = b"<Bytes>message to sign</Bytes>";

let sig = match (SecretKey::from_ed25519_bytes(&sec.to_bytes()), PublicKey::from_bytes(&pub_bytes)) {
(Ok(s), Ok(k)) => s
	.sign_simple(CTX, message, &k)
	.to_bytes()
	.to_vec(),
_ => panic!("Invalid secret or pubkey provided.")
};


// ext_sr_verify function
let res =   match (Signature::from_bytes(&sig), PublicKey::from_bytes(&pub_bytes)) {
(Ok(s), Ok(k)) => k
	.verify_simple(CTX, message, &s)
	.is_ok(),
_ => false
};

assert!(res)

WebAssembly "Out of memory: wasm memory" bug

Steps to reproduce:
I can't provide any steps to reproduce. I've just been changing the code in my environment with Hot Module Reloading and at one point I was getting tis error. I doesn't happen when I open a new incognito tab and run the same code.

Error log

ERROR: Unable to initialize @polkadot/wasm-crypto:: WebAssembly Instantiation: Out of memory: wasm memory

  | __stack_frame_overlay_proxy_console__ | @ | index.js:2178
-- | -- | -- | --
  | createExportPromise | @ | wasm_bg.js:23
  | async function (async) |   |  
  | createExportPromise | @ | wasm_bg.js:19
  | ./node_modules/@polkadot/wasm-crypto/wasm.js | @ | wasm.js:789
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./node_modules/@polkadot/wasm-crypto/index.js | @ | index.js:6
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./node_modules/@polkadot/util-crypto/index.js | @ | index.js:15
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./node_modules/@polkadot/keyring/index.js | @ | index.js:30
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./node_modules/@polkadot/ui-identicon/Identicon.js | @ | Identicon.js:16
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./node_modules/@polkadot/ui-identicon/index.js | @ | index.js:11
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | ./pages/index.js | @ | xxhash64.js:444
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | (anonymous) | @ | next-client-pages-loader.js:3
  | register | @ | page-loader.js:149
  | registerPage | @ | page-loader.js:191
  | register | @ | index.js:94
  | ./node_modules/next/dist/build/webpack/loaders/next-client-pages-loader.js?page=%2F&absolutePagePath=%2FUsers%2Fstefaniedoll%2FParity%2FCustom%2Fsubstrate-nextjs%2Fpages%2Findex.js!./ | @ | next-client-pages-loader.js:2
  | __webpack_require__ | @ | bootstrap:788
  | fn | @ | bootstrap:149
  | 6 | @ | crypto (ignored)?a400:1
  | __webpack_require__ | @ | bootstrap:788
  | checkDeferredModules | @ | bootstrap:45
  | webpackJsonpCallback | @ | bootstrap:32
  | (anonymous)

Tech Stack:

  "dependencies": {
    "@babel/plugin-proposal-export-default-from": "^7.2.0",
    "@now/next": "^0.1.2",
    "@polkadot/api": "^0.76.0-beta.2",
    "@polkadot/keyring": "^0.76.0-beta.2",
    "@polkadot/rpc-provider": "^0.76.0-beta.2",
    "@polkadot/ui-identicon": "^0.36.1",
    "@polkadot/util": "^0.76.0-beta.2",
    "@polkadot/util-crypto": "^0.76.0-beta.2",
    "@zeit/next-css": "^1.0.1",
    "babel-plugin-module-resolver": "^3.2.0",
    "create-subscription": "^16.8.6",
    "dotenv-webpack": "^1.7.0",
    "file-loader": "^3.0.1",
    "next": "latest",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-with-observable": "^2.0.1",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.86.0",
    "url-loader": "^1.1.2"
  }

Environment:
Google Chrome 73.0.3683.86 (Official Build) (64-bit)
Mac OS Mojave 10.14.3

exports.js file missing @polkadot/[email protected] Version

Started to test @polkadot/[email protected] Version in react native
Getting the following error
Unable to resolve module ./exports from `node_modules/@polkadot/wasm-crypto/index.js

Indeed, none of these files exist
node_modules/@polkadot/wasm-crypto/exports(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)

How to use JavaScript using wasm in Java?

Hello everyone!
I'm java developer working on coin exchange.
We found out that there was no Java related to Polkadot, and we are trying to actively use polkadot-js.
But we will use it in Java.

The method I tried is as follows.

  1. use GraalVm(It's a simple library that binds JavaScript)
  2. use webpack (use your modules to use in one js file)
  3. and run!

But I'm fighting the error below :(
image

Is the method I tried technically possible?

The functions that our exchange needs are as follows.

  • generating signle/multi-signed addresses
  • broadcasting transactions
  • parsing block network information (blocks, extrinsics, call, events, etc, ...)

All the crypto-related functions of polkadot-js are related to wasm.
So I think we should use wasm unconditionally.

question

  • Is there a way to solve the above error?
  • Is the method I tried technically possible??

WebAssembly is not available in your environment

Hi!

How can I import this package in a non-webassembly environment?

I am currently generating client side polkadotJS mockups for testing purposes, but my JS VM has no Webassembly, I am using webpack with babel to generate the client bundle.

I can see by issue #19 that seems to be possible to use some kind of polyfill. Looks like there is two flavors of this package implementation depending on the capabilities of the javascript environment.

But I can't find the selection mechanism, that seems not to be working for me, or how to "force" a particular implementation to be used. I can see that in the unit test global.Webassembly is set to null, but does seems not to do the trick for me.

Everything I try seems to end on "Webassembly not available in your environment".

How can I generate a webpack bundle for such a envirobment?

Expose Schnorrkel's VRF capabilities in util-crypto

Expose Schnorrkel's VRF capabilities to WASM / JS environments.
Having a verifiable source of randomness will will enable interesting use cases for wallet / dapp builders.
Methods to be exposed: vrf_sign, vrf_sign_extra, vrf_verify, vrf_verify_extra.

Centos 7

Logging on behalf of @SleepingNext since the issue is completely different and wrongly allocated to a resolved long-running Chrome-increases-memory-on-refresh issue.

On CentOs 7 Node runs out of memory when creating the WASM bundle. Doesn't do the same under Docker on the same machine.

Provide build instructions to verify bytecode

Hey,

This code is compiled and built for use in a few browser extensions, and the Chrome store policies these extensions have to adhere to often restrict obfuscated code.

With this, it would be useful to include instructions in this repo, with some Dockerfile or similar, on how to generate the bytes that are uploaded to the npm package at npmjs.com, so the reviewers can verify the source.

A good example of this in practice is the uBlock Origin extension, which also contains compiled WASM: https://github.com/gorhill/uBlock/blob/master/src/js/wasm/README.md)

Expose Schnorrkel's VRF capabilities

Expose Schnorrkel's VRF capabilities to WASM / JS environments.
Having a verifiable source of randomness will will enable interesting use cases for wallet / dapp builders.
Methods to be exposed: vrf_sign, vrf_sign_extra, vrf_verify, vrf_verify_extra.

`wasm-crypto` not loading in environments where `wasm-unsafe-eval` CSP is not allowed

TL;DR

Please change current dynamic loading codes to simply import wasmBytes from "path/to.wasm" in the production bundle to make the library work in secure environments.

I am trying to sign payloads within a Cloudflare Worker. The runtime refuses loading the wasm bytes in memory since the CSP policy wasm-unsafe-eval is not allowed in the runtime. After some research, I found that this affects multiple scenarios:

  • Electron where dynamic evaluating is blocked by default
  • Browser environments that blocks wasm-unsafe-eval explicitly
  • Node.js environments that blocks wasm-unsafe-eval explicitly

I appreciate the current dynamic façon to keep the bundle tiny in size, but it won't work in some secure environments.

Some reading: https://github.com/WebAssembly/content-security-policy/blob/main/proposals/CSP.md

Expected: the library should load
Current: FATAL: Unable to initialize @polkadot/wasm-crypto:: WebAssembly.instantiate(): Wasm code generation disallowed by embedder

This happens in ANY Environment where wasm-unsafe-eval is not allowed

  • Environment:

    • Node.js
    • Browser
    • Other (limited support for other environments)

Static import of my env vars and config breaks the usage of the lib

  • I'm submitting a ...

    • Support request
  • What is the current behavior and expected behavior?

I have an index.ts file and a local.ts config file, which has some env vars. The config file looks like this:

export default {
  // different object props and their values
}

If I want to load the config at the start of my application, which runs the program, I can do it in two ways.

First one:

import * as dotenv from 'dotenv'
dotenv.config()
import localConfig from './local'

async function main() {
  let config: any = localConfig
  // start my app
}
main()

Second one:

import * as dotenv from 'dotenv'
dotenv.config()

async function main() {
  let config: any = (await import(`./local`)).default
  // start my app
}
main()

You can see that in the first way I use a static import and in the second, a dynamic import.
When I use a dynamic import, everything works, but when I use static import, I get the following error:

node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@polkadot/wasm-crypto/cjs/bundle.js:46
      throw new Error('The WASM interface has not been initialized. Ensure that you wait for the initialization Promise with waitReady() from @polkadot/wasm-crypto (or cryptoWaitReady() from @polkadot/util-crypto) before attempting to use WASM-only interfaces.');

At the start of my app I call

await cryptoWaitReady()

And later on

    const keyring = new Keyring({ type: 'sr25519' })
    this.signer = keyring.addFromMnemonic(signer)

At .addFromMnemonic() is where the error is triggered.

I don't rly understand why this happens, because in both cases config is loaded correctly (with the signer that is used in the keyring), and await cryptoWaitReady() returns true, before I call the keyring initialization.

  • Please tell us about your environment:

    • Version: 6.4.1

    • Environment:

      • Node.js
    • Language:

      • TypeScript (tsc --version: 5.2.2)

Inconsistency between documentation and code

Hi,

the comment here:

/// returned vector is the concatenation of first the private key (64 bytes)

does not seem to reflect to what is really happening.
While trying to reflect on how the key generation algorithm works in detail and trying to recreate it, I was left confused, because the secret key is 32 bytes long, but the documentation says it is 64 bytes. It also says, that the 64 bytes are followed by 32 bytes of public key, but the total returned vector is 64 bytes long, not 96 bytes.

Additionally, where the wasm code is called from (https://github.com/polkadot-js/common/blob/3597a4eb4e0cf9985104568058c5cd23701bbaed/packages/util-crypto/src/ed25519/pair/fromSeed.ts#L30), the whole 64 byte array is taken for the private key and the second half of that array is taken as the public key. For the public key that is fine, but the private key than consists of both the secret key and the public key. Is that correct how it is?
If yes I would suggest we change the documentation on the ext_ed_from_seed function.

Update to latest schnorrkel version (align with Substrate)

After #397

One small issue would be that the newest (if we update to that as well) uses curve25519-dalek-ng while ed25519-zebra as linked above above still uses curve25519-dalek - having different versions for the same functionality does add overhead/size to the WASM. Either way try to align versions to use the same deps to not have an explosion.

We could possibly also test a trick like this - https://github.com/w3f/schnorrkel/blob/93e27d28f6a112be429295af7fd4549dde9f6796/Cargo.toml#L32

@polkadot/api doesn't get initialised unless the asmInit is passed explicitly

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @polkadot/[email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@polkadot/wasm-crypto/cjs/init.js b/node_modules/@polkadot/wasm-crypto/cjs/init.js
index cbdb8d5..a5cf3b3 100644
--- a/node_modules/@polkadot/wasm-crypto/cjs/init.js
+++ b/node_modules/@polkadot/wasm-crypto/cjs/init.js
@@ -10,6 +10,7 @@ exports.setWasmPromiseFn = setWasmPromiseFn;
 var _util = require("@polkadot/util");
 
 var _wasmCryptoWasm = require("@polkadot/wasm-crypto-wasm");
+var _asmCryptoWasm = require("@polkadot/wasm-crypto-asmjs");
 
 var _bridge = require("./bridge");
 
@@ -50,5 +51,5 @@ function setWasmPromiseFn(fn) {
 }
 
 function initWasm() {
-  return setWasmPromise(_wasmCryptoWasm.wasmBytes, null);
+  return setWasmPromise(_wasmCryptoWasm.wasmBytes, _asmCryptoWasm.asmJsInit);
 }
\ No newline at end of file

This issue body was partially generated by patch-package.

Using the package in react-native where WASM is not available and waitReady or cryptoWaitReady or import '@polkadot/wasm-crypto/initWasmAsm' at the start of the application none of this workarounds solve the problem.

wasm vs asm returns different results

import { asmJsInit } from "@polkadot/wasm-crypto-asmjs/data";
import { wasmBytes } from "@polkadot/wasm-crypto-wasm";
import { initWasm } from "@polkadot/wasm-crypto/bridge";
import { secp256k1FromSeed } from "@polkadot/wasm-crypto";
import * as imports from "@polkadot/wasm-crypto/imports";
const wasmPromise = initWasm(wasmBytes, asmJsInit, imports).catch(() => null);
wasmPromise.then(() => {
  console.log(
    secp256k1FromSeed([
      203,
      109,
      249,
      222,
      30,
      252,
      167,
      163,
      153,
      138,
      142,
      173,
      78,
      2,
      21,
      157,
      95,
      169,
      156,
      62,
      13,
      79,
      214,
      67,
      38,
      103,
      57,
      11,
      180,
      114,
      104,
      84,
    ])
  );
});

outputs

[
  203, 109, 249, 222,  30, 252, 167, 163, 153, 138, 142,
  173,  78,   2,  21, 157,  95, 169, 156,  62,  13,  79,
  214,  67,  38, 103,  57,  11, 180, 114, 104,  84,   2,
   10,  16, 145,  52,  31, 229, 102,  75, 250,  23, 130,
  213, 224,  71, 121, 104, 144, 104, 201,  22, 176,  76,
  179, 101, 236,  49,  83, 117,  86, 132, 217, 161
]

however if you just use asm,

const wasmPromise = initWasm([], asmJsInit, imports).catch(() => null);

itll output

[
  203, 109, 249, 222,  30, 252, 167, 163, 153, 138, 142, 173,
   78,   2,  21, 157,  95, 169, 156,  62,  13,  79, 214,  67,
   38, 103,  57,  11, 180, 114, 104,  84,   2,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
    0,   0,   0,   0,   0
]

seems like asm is somehow broken

Error: Cannot find namespace 'WebAssembly'.

When trying to update Polkadot JS API in the polkadot-launch project, I run into the errors:

$ tsc
node_modules/@polkadot/wasm-bridge/bridge.d.ts:7:16 - error TS2503: Cannot find namespace 'WebAssembly'.

7     get wbg(): WebAssembly.ModuleImports;
                 ~~~~~~~~~~~

node_modules/@polkadot/wasm-bridge/init.d.ts:2:131 - error TS2503: Cannot find namespace 'WebAssembly'.

2 export declare function createWasmFn<C extends WasmBaseInstance>(root: string, wasmBytes: null | Uint8Array, asmFn: null | ((wbg: WebAssembly.ModuleImports) => C)): InitFn<C>;
                                                                                                                                    ~~~~~~~~~~~

node_modules/@polkadot/wasm-bridge/types.d.ts:7:64 - error TS2503: Cannot find namespace 'WebAssembly'.

7 export declare type InitFn<C extends WasmBaseInstance> = (wbg: WebAssembly.ModuleImports) => InitPromise<C>;
                                                                 ~~~~~~~~~~~

node_modules/@polkadot/wasm-bridge/types.d.ts:9:10 - error TS2503: Cannot find namespace 'WebAssembly'.

9     wbg: WebAssembly.ModuleImports;
           ~~~~~~~~~~~

node_modules/@polkadot/wasm-bridge/types.d.ts:25:13 - error TS2503: Cannot find namespace 'WebAssembly'.

25     memory: WebAssembly.Memory;
               ~~~~~~~~~~~


Found 5 errors.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

The diff for updating can be found here: paritytech/polkadot-launch#193

Couldn't find a solution online :/

Support React Native

in RN environment, there's no global WebAssembly.
Can we have a polyfill for it?
https://www.npmjs.com/package/webassembly looks promising.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.