Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-wallet example is not working in the browser #76

Open
Ekliptor opened this issue Nov 10, 2019 · 2 comments
Open

create-wallet example is not working in the browser #76

Ekliptor opened this issue Nov 10, 2019 · 2 comments

Comments

@Ekliptor
Copy link

Ekliptor commented Nov 10, 2019

Tested in Chrome 78
I have uploaded a small sample project to reproduce this error: https://github.com/Ekliptor/BlockchainAPI

I can run the example from here with NodeJS v12 and create a wallet https://github.com/Bitcoin-com/slp-sdk/blob/master/examples/create-wallet/create-wallet.js
However, when I try to run it in the browser I get an error in hdnode.js:

f {message: "Expected property "0" of type ECPair, got g", __label: undefined, __property: 0, __value: g, __type: ƒ, …}
message: "Expected property "0" of type ECPair, got g"
__label: undefined
__property: 0
__type: ƒ t(t)
__value: g {d: n, compressed: true, network: {…}}
__valueTypeName: "g"
stack: "Error: Expected property "0" of type ECPair, got g↵    at a (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:60:76182)↵    at tfSubError (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:60:77360)↵    at http://localhost:63342/BlockchainAPI/blockchain-api.min.js:24:73605↵    at Array.every (<anonymous>)↵    at t (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:24:73547)↵    at d (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:24:74101)↵    at new p (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:72:5919)↵    at Function.p.fromSeedBuffer (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:72:6536)↵    at t.e.fromSeed (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:52:66628)↵    at Object.<anonymous> (http://localhost:63342/BlockchainAPI/blockchain-api.min.js:60:275738)"
__proto__: Error

Stack

(anonymous) | @ | index.js:190
-- | -- | --
  | t | @ | index.js:186
  | d | @ | index.js:233
  | p | @ | hdnode.js:16
  | p.fromSeedBuffer | @ | hdnode.js:48
  | e.fromSeed | @ | HDNode.ts:26
  | (anonymous) | @ | createWallet.ts:40
  | r | @ | bootstrap:19
  | (anonymous) | @ | bootstrap:83
  | (anonymous) | @ | bootstrap:83

Possibly this error should be forwarded to bitcoinjs-lib.

I also remember this worked with SLP-SDK v1.x about 1 year ago, but now even going back to 1.3.2 still results in the same error. So some breaking changes in WebPack (??) could also be the cause.

@Ekliptor
Copy link
Author

Ekliptor commented Nov 17, 2019

I have tracked the issue down to the JS minifaction done by Webpack.
Specifically by changing mode: "development", in webpack.config.js the code works in the browser without changes.

I also tried switching from Terser minification (WebPack's default) to ClosureCompiler. Still gives exactly the same error.
By simply creating breakpoints in hdnode.js in HDNode.fromSeedBuffer there is no visible difference in local variables and function parameters between the working and not working (minified) code.
So I assume minify removes some code which is needed for this. Even when explicitly disabling WebPacks Tree shaking with "sideEffects": true, in package.json (which should only be understood by Terser minify either way) the error persists.

The problem also continues after updating to latest WebPack 4.41.2. But it's not urgent anymore, as for now my workaround is just to compile slp-sdkseperately (not minified) and expose it on the global window object for the main project to use.

@christroutner
Copy link
Contributor

You rock @Ekliptor. Thanks for chasing down this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants