bitcoinjs-lib
bitcoinjs-lib copied to clipboard
Info with Angular
hi could i use this lib with angular framework, because i tried but i have some errors.
In particular i have install the module with npm I use module in my service import * as bitcoin from 'bitcoinlib-js'
but when i use the simple method i receive this:
TypeError: Cannot read property 'call' of undefined
at Hash.CipherBase (index.js:7)
at new Hash (browser.js:9)
at createHash (browser.js:29)
at sha256 (crypto.js:23)
at Object.hash160 (crypto.js:29)
at Object.p2pkh (p2pkh.js:109)
at AddressService.
Cryptographic operations could be a little bit of a pain in Angular. They are planning to work on it in the next release. There are quick fixes available for this kind of problem over the internet. One which I found and worked for me -
- In your project root folder, create a file called patch.js containing the following code:
` const fs = require('fs'); const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
fs.readFile(f, 'utf8', function (err,data) { if (err) { return console.log(err); } var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}');
fs.writeFile(f, result, 'utf8', function (err) { if (err) return console.log(err); }); }); `
- In your package.json , under scripts add the entry "postinstall": "node patch.js" , example:
"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "postinstall": "node patch.js" },
- Reinstall your project’s dependencies:
$ rm -R node_modules && npm install
Let me know if it works for you.
Cryptographic operations could be a little bit of a pain in Angular. They are planning to work on it in the next release. There are quick fixes available for this kind of problem over the internet. One which I found and worked for me -
- In your project root folder, create a file called patch.js containing the following code:
` const fs = require('fs'); const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
fs.readFile(f, 'utf8', function (err,data) { if (err) { return console.log(err); } var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}');
fs.writeFile(f, result, 'utf8', function (err) { if (err) return console.log(err); }); }); `
- In your package.json , under scripts add the entry "postinstall": "node patch.js" , example:
"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "postinstall": "node patch.js" },
- Reinstall your project’s dependencies:
$ rm -R node_modules && npm installLet me know if it works for you.
Hi i red yet your solution on the web... but i'm using angular 11 and not found node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js'.... let me know how can i do... now i'm using browserify, but it's not a clean solution.
Thank you
We are using this library in an angular 11 project as well. The script that was posted has to be updated to work with ng11 (and maybe also ng10, not sure). You can find our script / project here: https://github.com/airgap-it/airgap-vault/blob/master/config/patch_crypto.js