Skip to content

Commit

Permalink
Merge pull request #222 from getAlby/fix/examples-crypto-nodejs-20
Browse files Browse the repository at this point in the history
Fix: examples for nodeJS 20+
  • Loading branch information
im-adithya authored Jun 3, 2024
2 parents d89e0f5 + d8559c5 commit f7a85c0
Show file tree
Hide file tree
Showing 25 changed files with 28 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ import "websocket-polyfill";
// or: require('websocket-polyfill');
```
if you get an `crypto is not defined` error you have to import it first:
if you get an `crypto is not defined` error, either upgrade to node.js 20 or above, or import it manually:
```js
import * as crypto from 'crypto'; // or 'node:crypto'
Expand Down
4 changes: 4 additions & 0 deletions examples/crypto-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js < 20
if (!global.crypto) {
global.crypto = crypto;
}
3 changes: 1 addition & 2 deletions examples/nwc/client/get-balance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/get-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/get-wallet-service-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/get-wallet-service-supported-methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/list-transactions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/lookup-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/make-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/multi-pay-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import { LightningAddress } from "@getalby/lightning-tools";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/multi-pay-keysend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/pay-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/pay-keysend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/sign-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/client/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/get-balance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/get-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/keysend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/list-transactions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/lookup-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/make-invoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/multi-keysend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/send-multi-payment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import { LightningAddress } from "@getalby/lightning-tools";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/send-payment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down
3 changes: 1 addition & 2 deletions examples/nwc/sign-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as crypto from "node:crypto"; // required in node.js
global.crypto = crypto; // required in node.js
import "../crypto-polyfill.js";
import "websocket-polyfill"; // required in node.js

import * as readline from "node:readline/promises";
Expand Down

0 comments on commit f7a85c0

Please sign in to comment.