From 17f04b3083ecf1c1f12269c4257182b812f1579b Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Mon, 9 Jan 2023 09:26:14 -0800 Subject: [PATCH 1/7] Fix broken test in connection.ts for node 18 and add node 18 testing (#2183) * Change localhost to 127.0.0.1 * Add Node 18 testing --- .github/workflows/nodejs.yml | 16 +++++++--------- packages/xrpl/test/connection.test.ts | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bfa1c067..cbb45007 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -5,7 +5,7 @@ name: Node.js CI on: push: - branches: [ main, 1.x ] + branches: [main, 1.x] pull_request: workflow_dispatch: @@ -57,7 +57,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x] steps: - uses: actions/checkout@v3 @@ -98,15 +98,14 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [12.x, 14.x, 16.x, 18.x] services: rippled: image: natenichols/rippled-standalone:latest ports: - - 6006:6006 - options: - --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s + - 6006:6006 + options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s steps: - uses: actions/checkout@v3 @@ -156,9 +155,8 @@ jobs: rippled: image: natenichols/rippled-standalone:latest ports: - - 6006:6006 - options: - --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s + - 6006:6006 + options: --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s steps: - uses: actions/checkout@v3 diff --git a/packages/xrpl/test/connection.test.ts b/packages/xrpl/test/connection.test.ts index 1b3a3046..1917fc27 100644 --- a/packages/xrpl/test/connection.test.ts +++ b/packages/xrpl/test/connection.test.ts @@ -136,7 +136,7 @@ describe('Connection', function () { createServer().then((server: net.Server) => { const port = (server.address() as net.AddressInfo).port const options = { - proxy: `ws://localhost:${port}`, + proxy: `ws://127.0.0.1:${port}`, authorization: 'authorization', trustedCertificates: ['path/to/pem'], } From ad322053067d3bfa1211a2893a99edfe6184940c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:37:47 -0500 Subject: [PATCH 2/7] build(deps): bump json5 from 1.0.1 to 1.0.2 (#2176) Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Elliot Lee --- package-lock.json | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc752f0e..c0d7c7de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10155,12 +10155,10 @@ "dev": true }, "node_modules/json5": { - "version": "2.2.0", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, - "dependencies": { - "minimist": "^1.2.5" - }, "bin": { "json5": "lib/cli.js" }, @@ -15775,8 +15773,9 @@ } }, "node_modules/tsconfig-paths/node_modules/json5": { - "version": "1.0.1", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", "dev": true, "dependencies": { "minimist": "^1.2.0" @@ -24795,12 +24794,10 @@ "dev": true }, "json5": { - "version": "2.2.0", - "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true }, "jsonc-parser": { "version": "3.0.0", @@ -29080,8 +29077,9 @@ }, "dependencies": { "json5": { - "version": "1.0.1", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", "dev": true, "requires": { "minimist": "^1.2.0" From 45963b70356f4609781a6396407e2211fd15bcf1 Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Fri, 13 Jan 2023 15:23:13 -0800 Subject: [PATCH 3/7] Re-organize the README (#2180) * Re-organize the README --- README.md | 286 +++++++++-------------------------------------- UNIQUE_SETUPS.md | 202 +++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+), 233 deletions(-) create mode 100644 UNIQUE_SETUPS.md diff --git a/README.md b/README.md index 09e537b0..c82bfcbb 100644 --- a/README.md +++ b/README.md @@ -11,25 +11,25 @@ This is the recommended library for integrating a JavaScript/TypeScript app with See the full reference documentation for all classes, methods, and utilities. -## [➡️ Applications and Projects](https://github.com/XRPLF/xrpl.js/blob/main/APPLICATIONS.md) +## Features -What is `xrpl.js` used for? The applications on the list linked above use `xrpl.js`. Open a PR to add your app or project to the list! +1. Managing keys & creating test credentials ([`Wallet`](https://js.xrpl.org/classes/Wallet.html) && [`Client.fundWallet()`](https://js.xrpl.org/classes/Client.html#fundWallet)) +2. Submitting transactions to the XRP Ledger ([`Client.submit(...)`](https://js.xrpl.org/classes/Client.html#submit) & [transaction types](https://xrpl.org/transaction-types.html)) +3. Sending requests to observe the ledger ([`Client.request(...)`](https://js.xrpl.org/classes/Client.html#request) using [public API methods](https://xrpl.org/public-api-methods.html)) +4. Subscribing to changes in the ledger ([Ex. ledger, transactions, & more...](https://xrpl.org/subscribe.html)) +5. Parsing ledger data into more convenient formats ([`xrpToDrops`](https://js.xrpl.org/functions/xrpToDrops.html) and [`rippleTimeToISOTime`](https://js.xrpl.org/functions/rippleTimeToISOTime.html)) -### Features +All of which works in Node.js (tested for v14+) & web browsers (tested for Chrome). -+ Works in Node.js and in web browsers -+ Helpers for creating requests and parsing responses for the [XRP Ledger APIs](https://xrpl.org/rippled-api.html) -+ Listen to events on the XRP Ledger (transactions, ledger, validations, etc.) -+ Sign and submit transactions to the XRP Ledger -+ Type definitions for TypeScript +# Quickstart ### Requirements -+ **[Node.js v14](https://nodejs.org/)** is recommended. We also support v12 and v16. Other versions may work but are not frequently tested. +- **[Node.js v14](https://nodejs.org/)** is recommended. We also support v12 and v16. Other versions may work but are not frequently tested. -## Getting Started +### Installing xrpl.js -In an existing project (with `package.json`), install `xrpl.js`: +In an existing project (with package.json), install xrpl.js with: ``` $ npm install --save xrpl @@ -44,252 +44,72 @@ $ yarn add xrpl Example usage: ```js -const xrpl = require("xrpl") +const xrpl = require("xrpl"); async function main() { - const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233") - await client.connect() + const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233"); + await client.connect(); const response = await client.request({ - "command": "account_info", - "account": "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", - "ledger_index": "validated" - }) - console.log(response) + command: "account_info", + account: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", + ledger_index: "validated", + }); + console.log(response); - client.disconnect() + client.disconnect(); } -main() +main(); ``` -For more examples, see the [documentation](#documentation). - -## Try it out now! - -If you just want to try xrpl.js, you can fork this Code Sandbox template: -https://codesandbox.io/s/xrpl-intro-pxgdjr?file=/src/App.js +For a more in-depth example, you can copy/forking this Code Sandbox template! +
https://codesandbox.io/s/xrpl-intro-pxgdjr?file=/src/App.js It goes through: + 1. Creating a new test account -2. Sending a payment transaction -3. And sending requests to see your account balance +2. Sending a payment transaction +3. And sending requests to see your account balance! -### Using xrpl.js with `create-react-app` -To use `xrpl.js` with React, you need to install shims for core NodeJS modules. Starting with version 5, Webpack stopped including shims by default, so you must modify your Webpack configuration to add the shims you need. Either you can eject your config and modify it, or you can use a library such as `react-app-rewired`. The example below uses `react-app-rewired`. +### Case by Case Setup Steps -1. Install shims (you can use `yarn` as well): +If you're using xrpl.js with React or Deno, you'll need to do a couple extra steps to set it up: - ```shell - npm install --save-dev \ - assert \ - buffer \ - crypto-browserify \ - https-browserify \ - os-browserify \ - process \ - stream-browserify \ - stream-http \ - url - ``` -2. Modify your webpack configuration - 1. Install `react-app-rewired` - - ````shell - npm install --save-dev react-app-rewired - ```` - - 2. At the project root, add a file named `config-overrides.js` with the following content: - - ```javascript - const webpack = require('webpack'); - - module.exports = function override(config) { - const fallback = config.resolve.fallback || {}; - Object.assign(fallback, { - "assert": require.resolve("assert"), - "crypto": require.resolve("crypto-browserify"), - "http": require.resolve("stream-http"), - "https": require.resolve("https-browserify"), - "os": require.resolve("os-browserify"), - "stream": require.resolve("stream-browserify"), - "url": require.resolve("url"), - "ws": require.resolve('xrpl/dist/npm/client/WSWrapper'), - }) - config.resolve.fallback = fallback - config.plugins = (config.plugins || []).concat([ - new webpack.ProvidePlugin({ - process: 'process/browser', - Buffer: ['buffer', 'Buffer'] - }) - ]) - - // This is deprecated in webpack 5 but alias false does not seem to work - config.module.rules.push({ - test: /node_modules[\\\/]https-proxy-agent[\\\/]/, - use: 'null-loader', - }) - return config; - } - ``` - - 3. Update package.json scripts section with - - ``` - "start": "react-app-rewired start", - "build": "react-app-rewired build", - "test": "react-app-rewired test", - ``` - -This online template uses these steps to run xrpl.js with React in the browser: -https://codesandbox.io/s/xrpl-intro-pxgdjr?file=/src/App.js - -### Using xrpl.js with React Native - -If you want to use `xrpl.js` with React Native you will need to install shims for core NodeJS modules. To help with this you can use a module like [rn-nodeify](https://github.com/tradle/rn-nodeify). - -1. Install dependencies (you can use `yarn` as well): - - ```shell - npm install react-native-crypto - npm install xrpl - # install peer deps - npm install react-native-randombytes - # install latest rn-nodeify - npm install rn-nodeify@latest --dev - ``` - -2. After that, run the following command: - - ```shell - # install node core shims and recursively hack package.json files - # in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings - ./node_modules/.bin/rn-nodeify --hack --install - ``` - -3. Enable `crypto`: - - `rn-nodeify` will create a `shim.js` file in the project root directory. - Open it and uncomment the line that requires the crypto module: - - ```javascript - // If using the crypto shim, uncomment the following line to ensure - // crypto is loaded first, so it can populate global.crypto - require('crypto') - ``` - -4. Import `shim` in your project (it must be the first line): - - ```javascript - import './shim' - ... - ``` -### Using xrpl.js with Vite React - -Similar to above, to get xrpl.js to work with Vite you need to set up a couple aliases in the vite.config.ts file. - -1. If it's a fresh project you can use `npm create vite@latest` then choose the React and TypeScript options. - -2. Copy these settings into your `vite.config.ts` file. - -``` -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' -import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill"; -import polyfillNode from 'rollup-plugin-polyfill-node' - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - define: { - 'process.env': {} - }, - optimizeDeps: { - esbuildOptions: { - - define: { - global: 'globalThis', - }, - plugins: [ - NodeGlobalsPolyfillPlugin({ - process: true, - buffer: true, - }), - ], - }, -}, -build: { - rollupOptions: { - plugins: [ - polyfillNode(), - ] - } -}, -resolve: { - alias: { - events: 'events', - crypto: 'crypto-browserify', - stream: 'stream-browserify', - http: 'stream-http', - https: 'https-browserify', - ws: 'xrpl/dist/npm/client/WSWrapper', - }, -}}) -``` - -3. Install the config dependencies and xrpl (e.g. using this command) - -``` -npm install --save-dev @esbuild-plugins/node-globals-polyfill \ - rollup-plugin-polyfill-node \ - && npm install - events \ - crypto-browserify \ - stream-browserify \ - stream-http \ - https-browserify \ - xrpl -``` - -### Using xrpl.js with Deno - -Until official support for [Deno](https://deno.land) is added, you can use the following work-around to use `xrpl.js` with Deno: - -```javascript -import xrpl from 'https://dev.jspm.io/npm:xrpl'; - -(async () => { - const api = new (xrpl as any).Client('wss://s.altnet.rippletest.net:51233'); - const address = 'rH8NxV12EuV...khfJ5uw9kT'; - - api.connect().then(() => { - api.getBalances(address).then((balances: any) => { - console.log(JSON.stringify(balances, null, 2)); - }); - }); -})(); -``` +- [Using xrpl.js with `create-react-app`](./UNIQUE_SETUPS.md#using-xrpljs-with-create-react-app) +- [Using xrpl.js with `React Native`](./UNIQUE_SETUPS.md#using-xrpljs-with-react-native) +- [Using xrpl.js with `Vite React`](./UNIQUE_SETUPS.md#using-xrpljs-with-vite-react) +- [Using xrpl.js with `Deno`](./UNIQUE_SETUPS.md#using-xrpljs-with-deno) ## Documentation -+ [Get Started in Node.js](https://xrpl.org/get-started-using-node-js.html) -+ [Full Reference Documentation](https://js.xrpl.org) -+ [Code Samples](https://github.com/XRPLF/xrpl.js/tree/main/packages/xrpl/snippets/src) +As you develop with xrpl.js, there's two sites you'll use extensively: + +1. [xrpl.org](https://xrpl.org/references.html) is the primary source for: + - How the ledger works ([See Concepts](https://xrpl.org/concepts.html#main-page-header)) + - What kinds of transactions there are ([Transaction Types](https://xrpl.org/transaction-types.html#transaction-types)) + - Requests you can send ([Public API Methods](https://xrpl.org/public-api-methods.html)) + - Tutorials for interacting with various features of the ledger ([Tutorials](https://xrpl.org/tutorials.html#main-page-header)) +2. [js.xrpl.org](https://js.xrpl.org/) has the reference docs for this library ### Mailing Lists -We have a low-traffic mailing list for announcements of new `xrpl.js` releases. (About 1 email per week) +If you want to hear when we release new versions of xrpl.js, you can join our low-traffic mailing list (About 1 email per week): -+ [Subscribe to xrpl-announce](https://groups.google.com/g/xrpl-announce) +- [Subscribe to xrpl-announce](https://groups.google.com/g/xrpl-announce) If you're using the XRP Ledger in production, you should run a [rippled server](https://github.com/ripple/rippled) and subscribe to the ripple-server mailing list as well. -+ [Subscribe to ripple-server](https://groups.google.com/g/ripple-server) +- [Subscribe to ripple-server](https://groups.google.com/g/ripple-server) -### Report an issue +## Asking for help -Experienced an issue? Report it [here](https://github.com/XRPLF/xrpl.js/issues/new). +One of the best spots to ask for help is in the [XRPL Developer Discord](https://xrpldevs.org) - There's a channel for xrpl.js where other community members can help you figure out how to accomplish your goals. -## More Information +You are also welcome to create an [issue](https://github.com/XRPLF/xrpl.js/issues) here and we'll do our best to respond within 3 days. -+ [xrpl-announce mailing list](https://groups.google.com/g/xrpl-announce) - subscribe for release announcements -+ [xrpl.js API Reference](https://js.xrpl.org) -+ [XRP Ledger Dev Portal](https://xrpl.org) +## Key Links + +- [xrpl.js Reference Docs](https://js.xrpl.org/) +- [xrpl.org (Detailed docs on how the XRPL works)](https://xrpl.org/references.html) +- [#javascript in the XRPL Developer Discord for questions & support](https://xrpldevs.org) +- [xrpl-announce (The mailing list for new xrpl.js versions)](https://groups.google.com/g/xrpl-announce) +- [Applications that use xrpl.js](https://github.com/XRPLF/xrpl.js/blob/main/APPLICATIONS.md) (You can open a PR to add your project!) diff --git a/UNIQUE_SETUPS.md b/UNIQUE_SETUPS.md new file mode 100644 index 00000000..acc971f7 --- /dev/null +++ b/UNIQUE_SETUPS.md @@ -0,0 +1,202 @@ +# Unique Setup Steps for Xrpl.js + +For when you need to do more than just install `xrpl.js` for it to work (especially for React projects in the browser). + +### Using xrpl.js with `create-react-app` + +To use `xrpl.js` with React, you need to install shims for core NodeJS modules. Starting with version 5, Webpack stopped including shims by default, so you must modify your Webpack configuration to add the shims you need. Either you can eject your config and modify it, or you can use a library such as `react-app-rewired`. The example below uses `react-app-rewired`. + +1. Install shims (you can use `yarn` as well): + + ```shell + npm install --save-dev \ + assert \ + buffer \ + crypto-browserify \ + https-browserify \ + os-browserify \ + process \ + stream-browserify \ + stream-http \ + url + ``` + +2. Modify your webpack configuration + + 1. Install `react-app-rewired` + + ```shell + npm install --save-dev react-app-rewired + ``` + + 2. At the project root, add a file named `config-overrides.js` with the following content: + + ```javascript + const webpack = require("webpack"); + + module.exports = function override(config) { + const fallback = config.resolve.fallback || {}; + Object.assign(fallback, { + assert: require.resolve("assert"), + crypto: require.resolve("crypto-browserify"), + http: require.resolve("stream-http"), + https: require.resolve("https-browserify"), + os: require.resolve("os-browserify"), + stream: require.resolve("stream-browserify"), + url: require.resolve("url"), + ws: require.resolve("xrpl/dist/npm/client/WSWrapper"), + }); + config.resolve.fallback = fallback; + config.plugins = (config.plugins || []).concat([ + new webpack.ProvidePlugin({ + process: "process/browser", + Buffer: ["buffer", "Buffer"], + }), + ]); + + // This is deprecated in webpack 5 but alias false does not seem to work + config.module.rules.push({ + test: /node_modules[\\\/]https-proxy-agent[\\\/]/, + use: "null-loader", + }); + return config; + }; + ``` + + 3. Update package.json scripts section with + + ``` + "start": "react-app-rewired start", + "build": "react-app-rewired build", + "test": "react-app-rewired test", + ``` + +This online template uses these steps to run xrpl.js with React in the browser: +https://codesandbox.io/s/xrpl-intro-pxgdjr?file=/src/App.js + +### Using xrpl.js with React Native + +If you want to use `xrpl.js` with React Native you will need to install shims for core NodeJS modules. To help with this you can use a module like [rn-nodeify](https://github.com/tradle/rn-nodeify). + +1. Install dependencies (you can use `yarn` as well): + + ```shell + npm install react-native-crypto + npm install xrpl + # install peer deps + npm install react-native-randombytes + # install latest rn-nodeify + npm install rn-nodeify@latest --dev + ``` + +2. After that, run the following command: + + ```shell + # install node core shims and recursively hack package.json files + # in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings + ./node_modules/.bin/rn-nodeify --hack --install + ``` + +3. Enable `crypto`: + + `rn-nodeify` will create a `shim.js` file in the project root directory. + Open it and uncomment the line that requires the crypto module: + + ```javascript + // If using the crypto shim, uncomment the following line to ensure + // crypto is loaded first, so it can populate global.crypto + require("crypto"); + ``` + +4. Import `shim` in your project (it must be the first line): + +```javascript +import './shim' +... +``` + +### Using xrpl.js with Vite React + +Similar to above, to get xrpl.js to work with Vite you need to set up a couple aliases in the vite.config.ts file. + +1. If it's a fresh project you can use `npm create vite@latest` then choose the React and TypeScript options. + +2. Copy these settings into your `vite.config.ts` file. + +``` +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' +import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill"; +import polyfillNode from 'rollup-plugin-polyfill-node' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], + define: { + 'process.env': {} + }, + optimizeDeps: { + esbuildOptions: { + + define: { + global: 'globalThis', + }, + plugins: [ + NodeGlobalsPolyfillPlugin({ + process: true, + buffer: true, + }), + ], + }, +}, +build: { + rollupOptions: { + plugins: [ + polyfillNode(), + ] + } +}, +resolve: { + alias: { + events: 'events', + crypto: 'crypto-browserify', + stream: 'stream-browserify', + http: 'stream-http', + https: 'https-browserify', + ws: 'xrpl/dist/npm/client/WSWrapper', + }, +}}) +``` + +3. Install the config dependencies and xrpl (e.g. using this command) + +``` +npm install --save-dev @esbuild-plugins/node-globals-polyfill \ + rollup-plugin-polyfill-node \ + && npm install + events \ + crypto-browserify \ + stream-browserify \ + stream-http \ + https-browserify \ + xrpl +``` + +### Using xrpl.js with Deno + +Until official support for [Deno](https://deno.land) is added, you can use the following work-around to use `xrpl.js` with Deno: + +```javascript +import xrpl from 'https://dev.jspm.io/npm:xrpl'; + +(async () => { + const api = new (xrpl as any).Client('wss://s.altnet.rippletest.net:51233'); + const address = 'rH8NxV12EuV...khfJ5uw9kT'; + + api.connect().then(() => { + api.getBalances(address).then((balances: any) => { + console.log(JSON.stringify(balances, null, 2)); + }); + }); +})(); +``` From 62a5b60b0d056545d2d0eb2308dd832cdcb66622 Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Fri, 27 Jan 2023 12:39:51 -0800 Subject: [PATCH 4/7] Remove xls20-sandbox tests (#2190) --- packages/xrpl/src/Wallet/defaultFaucets.ts | 1 + packages/xrpl/test/integration/fundWallet.test.ts | 10 ++-------- packages/xrpl/test/wallet/fundWallet.test.ts | 7 ------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/xrpl/src/Wallet/defaultFaucets.ts b/packages/xrpl/src/Wallet/defaultFaucets.ts index 5624e1f0..420c7b77 100644 --- a/packages/xrpl/src/Wallet/defaultFaucets.ts +++ b/packages/xrpl/src/Wallet/defaultFaucets.ts @@ -54,6 +54,7 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined { return FaucetNetwork.Devnet } + // TODO: Remove this once the sandbox is fully decomissioned. if (connectionUrl.includes('xls20-sandbox')) { return FaucetNetwork.NFTDevnet } diff --git a/packages/xrpl/test/integration/fundWallet.test.ts b/packages/xrpl/test/integration/fundWallet.test.ts index 3bdf3096..c563fd77 100644 --- a/packages/xrpl/test/integration/fundWallet.test.ts +++ b/packages/xrpl/test/integration/fundWallet.test.ts @@ -26,16 +26,10 @@ describe('fundWallet', function () { ) }) - it('can generate and fund wallets on nft-devnet', async function () { - await generate_faucet_wallet_and_fund_again( - 'ws://xls20-sandbox.rippletest.net:51233', - ) - }) - it('can generate and fund wallets using a custom host and path', async function () { await generate_faucet_wallet_and_fund_again( - 'ws://xls20-sandbox.rippletest.net:51233', - 'faucet-nft.ripple.com', + 'wss://s.devnet.rippletest.net:51233/', + 'faucet.devnet.rippletest.net', '/accounts', ) }) diff --git a/packages/xrpl/test/wallet/fundWallet.test.ts b/packages/xrpl/test/wallet/fundWallet.test.ts index 0adf0a00..a490b817 100644 --- a/packages/xrpl/test/wallet/fundWallet.test.ts +++ b/packages/xrpl/test/wallet/fundWallet.test.ts @@ -33,13 +33,6 @@ describe('Get Faucet host ', function () { assert.strictEqual(getFaucetHost(this.client), expectedFaucet) }) - it('returns the NFT-Devnet host with the XLS-20 Sandbox server', function () { - const expectedFaucet = FaucetNetwork.NFTDevnet - this.client.connection.url = 'ws://xls20-sandbox.rippletest.net:51233' - - assert.strictEqual(getFaucetHost(this.client), expectedFaucet) - }) - it('returns the Hooks V2 Testnet host', function () { const expectedFaucet = FaucetNetwork.HooksV2Testnet this.client.connection.url = FaucetNetwork.HooksV2Testnet From c6cebefdbee7ead4bbf047a6814e457c955dc3f9 Mon Sep 17 00:00:00 2001 From: pdp2121 <71317875+pdp2121@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:10:27 -0500 Subject: [PATCH 5/7] Add code sample link to README (#2188) Co-authored-by: Elliot Lee --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c82bfcbb..b18e0a47 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ You are also welcome to create an [issue](https://github.com/XRPLF/xrpl.js/issue - [xrpl.js Reference Docs](https://js.xrpl.org/) - [xrpl.org (Detailed docs on how the XRPL works)](https://xrpl.org/references.html) +- [XRPL Code Samples](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples) - [#javascript in the XRPL Developer Discord for questions & support](https://xrpldevs.org) - [xrpl-announce (The mailing list for new xrpl.js versions)](https://groups.google.com/g/xrpl-announce) - [Applications that use xrpl.js](https://github.com/XRPLF/xrpl.js/blob/main/APPLICATIONS.md) (You can open a PR to add your project!) From bbc9bd9e4aea2631f2bfd63911a7a9a0934bdcf1 Mon Sep 17 00:00:00 2001 From: pdp2121 <71317875+pdp2121@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:17:55 -0500 Subject: [PATCH 6/7] Add README.md in snippets folder to point to xrpl.org code samples (#2189) Add README.md in snippets folder to point to xrpl.org code samples Co-authored-by: Elliot Lee --- packages/xrpl/snippets/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/xrpl/snippets/README.md diff --git a/packages/xrpl/snippets/README.md b/packages/xrpl/snippets/README.md new file mode 100644 index 00000000..9ecd1506 --- /dev/null +++ b/packages/xrpl/snippets/README.md @@ -0,0 +1,4 @@ +# More XRPL Code Samples + +- For samples of common use cases, see the [XRPL.org Code Samples](https://xrpl.org/code-samples.html) page. +- You can also browse those samples [directly on GitHub](https://github.com/XRPLF/xrpl-dev-portal/tree/master/content/_code-samples). From c74ffddf59218eb80f52485e264085fb933f55e8 Mon Sep 17 00:00:00 2001 From: pdp2121 <71317875+pdp2121@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:27:02 -0500 Subject: [PATCH 7/7] fix: unset hash128 fields using AccountSet (#2156) --- .../ripple-binary-codec/src/types/hash-128.ts | 17 +++++++++++ .../ripple-binary-codec/test/hash.test.js | 28 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/ripple-binary-codec/src/types/hash-128.ts b/packages/ripple-binary-codec/src/types/hash-128.ts index e5978682..6a45268c 100644 --- a/packages/ripple-binary-codec/src/types/hash-128.ts +++ b/packages/ripple-binary-codec/src/types/hash-128.ts @@ -9,8 +9,25 @@ class Hash128 extends Hash { static readonly ZERO_128: Hash128 = new Hash128(Buffer.alloc(Hash128.width)) constructor(bytes: Buffer) { + if (bytes && bytes.byteLength === 0) { + bytes = Hash128.ZERO_128.bytes + } + super(bytes ?? Hash128.ZERO_128.bytes) } + + /** + * Get the hex representation of a hash-128 bytes, allowing unset + * + * @returns hex String of this.bytes + */ + toHex(): string { + const hex = this.toBytes().toString('hex').toUpperCase() + if (/^0+$/.exec(hex)) { + return '' + } + return hex + } } export { Hash128 } diff --git a/packages/ripple-binary-codec/test/hash.test.js b/packages/ripple-binary-codec/test/hash.test.js index ea59df4d..b5a7b739 100644 --- a/packages/ripple-binary-codec/test/hash.test.js +++ b/packages/ripple-binary-codec/test/hash.test.js @@ -1,7 +1,33 @@ const { coreTypes } = require('../dist/types') -const { Hash160, Hash256, AccountID, Currency } = coreTypes +const { Hash128, Hash160, Hash256, AccountID, Currency } = coreTypes const { Buffer } = require('buffer/') +describe('Hash128', function () { + test('has a static width member', function () { + expect(Hash128.width).toBe(16) + }) + test('can be unset', function () { + const h1 = Hash128.from('') + expect(h1.toJSON()).toBe('') + }) + test('can be compared against another', function () { + const h1 = Hash128.from('100000000000000000000000000000000') + const h2 = Hash128.from('200000000000000000000000000000000') + const h3 = Hash128.from('000000000000000000000000000000003') + expect(h1.lt(h2)).toBe(true) + expect(h3.lt(h2)).toBe(true) + expect(h2.gt(h1)).toBe(true) + expect(h1.gt(h3)).toBe(true) + }) + test('throws when constructed from invalid hash length', () => { + expect(() => Hash128.from('1000000000000000000000000000000')).toThrow( + 'Invalid Hash length 15', + ) + expect(() => Hash128.from('10000000000000000000000000000000000')).toThrow( + 'Invalid Hash length 17', + ) + }) +}) describe('Hash160', function () { test('has a static width member', function () { expect(Hash160.width).toBe(20)