├── .env.example
├── .github
└── dependabot.yml
├── .gitignore
├── .prettierignore
├── .prettierrc.cjs
├── README.md
├── examples
└── payment-flow.md
├── global.d.ts
├── grant
├── grant-continuation.js
├── grant-continuation.ts
├── grant-incoming-payment.js
├── grant-incoming-payment.ts
├── grant-outgoing-payment-interval.js
├── grant-outgoing-payment-interval.ts
├── grant-outgoing-payment.js
├── grant-outgoing-payment.ts
├── grant-quote.js
├── grant-quote.ts
├── grant-revoke.js
├── grant-revoke.ts
├── grant.js
└── grant.ts
├── incoming-payment
├── incoming-payment-complete.js
├── incoming-payment-complete.ts
├── incoming-payment-create.js
├── incoming-payment-create.ts
├── incoming-payment-get.js
├── incoming-payment-get.ts
├── incoming-payment-list.js
└── incoming-payment-list.ts
├── outgoing-payment
├── outgoing-payment-create.js
├── outgoing-payment-create.ts
├── outgoing-payment-get.js
├── outgoing-payment-get.ts
├── outgoing-payment-list.js
└── outgoing-payment-list.ts
├── package.json
├── quote
├── quote-create-debit-amount.js
├── quote-create-debit-amount.ts
├── quote-create-receive-amount.js
├── quote-create-receive-amount.ts
├── quote-create.js
├── quote-create.ts
├── quote-get.js
└── quote-get.ts
├── token
├── token-revoke.js
├── token-revoke.ts
├── token-rotate.js
└── token-rotate.ts
├── tsconfig.json
├── utils
└── parse-token-args.ts
└── wallet-address
├── wallet-address-get-keys.js
├── wallet-address-get-keys.ts
├── wallet-address-get.js
└── wallet-address-get.ts
/.env.example:
--------------------------------------------------------------------------------
1 | # Client
2 | PRIVATE_KEY_PATH=private.key
3 | KEY_ID=
4 | WALLET_ADDRESS=
5 |
6 | # Grant
7 | CONTINUE_URI=
8 | CONTINUE_ACCESS_TOKEN=
9 | URL_WITH_INTERACT_REF=
10 |
11 | # Incoming Payment
12 | INCOMING_PAYMENT_URL=
13 | INCOMING_PAYMENT_ACCESS_TOKEN=
14 | INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL=
15 |
16 | # Quote
17 | QUOTE_URL=
18 | QUOTE_ACCESS_TOKEN=
19 | QUOTE_ACCESS_TOKEN_MANAGE_URL=
20 |
21 | # Outgoing Payment
22 | OUTGOING_PAYMENT_URL=
23 | OUTGOING_PAYMENT_ACCESS_TOKEN=
24 | OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL=
25 |
26 | # Token
27 | MANAGE_URL=
28 | ACCESS_TOKEN=
29 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: weekly
7 | time: "10:00"
8 | open-pull-requests-limit: 10
9 | labels: [dependencies]
10 | versioning-strategy: increase
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
3 | private.key
4 | pnpm-lock.yaml
5 | package-lock.json
6 | yarn.lock
7 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | pnpm-lock.yaml
2 | node_modules
3 |
--------------------------------------------------------------------------------
/.prettierrc.cjs:
--------------------------------------------------------------------------------
1 | /** @type { import("prettier").Config }*/
2 | const config = {
3 | arrowParens: "always",
4 | bracketSameLine: false,
5 | bracketSpacing: true,
6 | printWidth: 120,
7 | proseWrap: "always",
8 | semi: true,
9 | singleQuote: false,
10 | tabWidth: 4,
11 | trailingComma: "all",
12 | useTabs: false,
13 | };
14 |
15 | module.exports = config;
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Open Payments Node SDK Snippets
2 |
3 | These code snippets are intended for use with Rafiki Money. While
4 | everyone is welcome to use these code snippets as a reference, please note that they may need to be adapted to suit your
5 | particular application.
6 |
7 | ---
8 |
9 | ### Prerequisites
10 |
11 | - Node 20 or higher
12 | - A preferred package manager (`npm`, `pnpm`, `yarn`)
13 | - [TSX](https://www.npmjs.com/package/tsx)
14 | - TypeScript [Open Payments SDK](https://www.npmjs.com/package/@interledger/open-payments)
15 |
16 | ### Recommendations
17 |
18 | Before working with the code snippets, create a test wallet account on the Interledger test network. More information about setting up and funding your test wallet account, as well as obtaining a public-private key pair and ID can be found in the Open Payments documentation. You'll need the private key to complete your setup.
19 |
20 | ### Setup
21 |
22 | Install dependencies:
23 |
24 | ```sh
25 | # Using NPM
26 | npm install
27 |
28 | # Using PNPM
29 | pnpm install
30 |
31 | # Using Yarn
32 | yarn
33 | ```
34 |
35 | ### Loading the private key
36 |
37 | When you get your public-private key pair, the private key is automatically downloaded to your machine.
38 |
39 | Move the `private.key` file to the root directory of this repository.
40 |
41 | Ensure you are at the repository root and execute the following command in your terminal:
42 |
43 | ```sh
44 | cp .env.example .env
45 | ```
46 |
47 | Open the newly created `.env` file and fill in the following variables:
48 |
49 | - `WALLET_ADDRESS`
50 | - `KEY_ID`
51 |
52 | Now that you have all the necessary components to initialize the authenticated Open Payments client, you're ready to
53 | begin utilizing the code snippets.
54 |
55 | ### Running a snippet
56 |
57 | From the repository's root you can execute the following scripts using your preferred package manager:
58 |
59 | | Script | Description |
60 | | ------------------ | ---------------------------------------------- |
61 | | grant | Request a grant |
62 | | grant:continuation | Continuation request for a grant (interactive) |
63 | | grant:ip | Request a grant for an incoming payment |
64 | | grant:op | Request a grant for an outgoing payment |
65 | | grant:quote | Request a grant for a quote |
66 | | ip:create | Create an incoming payment |
67 | | ip:complete | Complete an incoming payment |
68 | | ip:get | Retrieve an incoming payment |
69 | | ip:list | List incoming payments |
70 | | op:create | Create an outgoing payment |
71 | | op:get | Retrieve an outgoing payment |
72 | | op:list | List outgoing payments |
73 | | quote:create | Create a quote |
74 | | quote:get | Retrieve a quote |
75 | | wa:get | Retrieve wallet address' information |
76 | | wa:get-keys | Retrieve wallet address' JWKs |
77 | | token:revoke | Revoke a token |
78 | | token:revoke:ip | Revoke incoming payment token |
79 | | token:revoke:op | Revoke outgoing payment token |
80 | | token:revoke:quote | Revoke quote token |
81 | | token:rotate | Rotate a token |
82 | | token:rotate:ip | Rotate incoming payment token |
83 | | token:rotate:op | Rotate outgoing payment token |
84 | | token:rotate:quote | Rotate quote token |
85 |
86 | Example:
87 |
88 | ```sh
89 | # Using NPM
90 | npm run grant
91 |
92 | # Using PNPM
93 | pnpm grant
94 |
95 | # Using Yarn
96 | yarn grant
97 | ```
98 |
99 | ### Examples
100 |
101 | - [Payment flow example](./examples/payment-flow.md)
102 |
--------------------------------------------------------------------------------
/examples/payment-flow.md:
--------------------------------------------------------------------------------
1 | # Payment flow
2 |
3 | Before proceeding with this example, ensure you have met the necessary [prerequisites](../README.md#prerequisites).
4 |
5 | In this example, we use `pnpm`, but you can use any package manager to execute the scripts.
6 |
7 | 1. **Request a Grant for an Incoming Payment**
8 |
9 | ```sh
10 | pnpm grant:ip
11 | ```
12 |
13 | The script will output an `INCOMING_PAYMENT_ACCESS_TOKEN`. Copy its value and fill the corresponding variable in your
14 | `.env` file.
15 |
16 | ```sh
17 | # Output example
18 | INCOMING_PAYMENT_ACCESS_TOKEN = 123456ABD...
19 | ```
20 |
21 | 2. **Create an Incoming Payment**
22 |
23 | ```sh
24 | pnpm ip:create
25 | ```
26 |
27 | Copy the `INCOMING_PAYMENT_URL` value and update the corresponding variable in your `.env` file.
28 |
29 | 3. **Request a Grant for Quoting**
30 |
31 | ```sh
32 | pnpm grant:quote
33 | ```
34 |
35 | Copy the `QUOTE_ACCESS_TOKEN` value and update the corresponding variable in your `.env` file.
36 |
37 | 4. **Create a quote**
38 |
39 | ```sh
40 | pnpm quote:create
41 | ```
42 |
43 | Copy the `QUOTE_URL` value and update the corresponding variable in your `.env` file.
44 |
45 | 5. **Request a Grant for an Outgoing Payment**
46 |
47 | ```sh
48 | pnpm grant:op
49 | ```
50 |
51 | This will output three values: The interaction URL, `CONTINUE_ACCESS_TOKEN`, and `CONTINUE_URI`. Update the `CONTINUE_*`
52 | variables in your `.env` file with these values (only `CONTINUE_ACCESS_TOKEN` and `CONTINUE_URI`).
53 |
54 | Note: In Rafiki, this is the only grant that requires user interaction, necessitating two steps to retrieve an access
55 | token with permission to create an outgoing payment.
56 |
57 | 6. **Accepting the Grant**
58 |
59 | - Click on the interaction URL outputted in the previous step;
60 | - Accept or decline the grant on Rafiki Money;
61 | - After accepting, click the Finish button in the dialog that appears;
62 | - Copy the redirected URL, it should look something like this: `http://localhost:3344/?hash=...&interact_ref=....`
63 | - Update the `URL_WITH_INTERACT_REF` variable in your `.env` file with this URL
64 |
65 | 7. **Continuation request** (notify Rafiki that the user has interacted with the grant)
66 |
67 | ```sh
68 | pnpm grant:continuation
69 | ```
70 |
71 | Copy the `OUTGOING_PAYMENT_ACCESS_TOKEN` value and update the corresponding variable in your `.env` file.
72 |
73 | 8. **Create the Outgoing Payment**
74 |
75 | ```sh
76 | pnpm op:create
77 | ```
78 |
79 | Copy the `OUTGOING_PAYMENT_URL` value and update the corresponding variable in your `.env` file.
80 |
81 | 9. **Retrieve Outgoing Payment Information** (Optional)
82 |
83 | ```sh
84 | pnpm op:get
85 | ```
86 |
--------------------------------------------------------------------------------
/global.d.ts:
--------------------------------------------------------------------------------
1 | declare namespace NodeJS {
2 | export interface ProcessEnv {
3 | PRIVATE_KEY_PATH: string;
4 | KEY_ID: string;
5 | WALLET_ADDRESS: string;
6 | INTERACT_REF: string;
7 | MANAGE_URL: string;
8 | CONTINUE_URI: string;
9 | CONTINUE_ACCESS_TOKEN: string;
10 | URL_WITH_INTERACT_REF: string;
11 | INCOMING_PAYMENT_URL: string;
12 | INCOMING_PAYMENT_ACCESS_TOKEN: string;
13 | INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL: string;
14 | OUTGOING_PAYMENT_URL: string;
15 | OUTGOING_PAYMENT_ACCESS_TOKEN: string;
16 | OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL: string;
17 | QUOTE_URL: string;
18 | QUOTE_ACCESS_TOKEN: string;
19 | QUOTE_ACCESS_TOKEN_MANAGE_URL: string;
20 | ACCESS_TOKEN: string;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/grant/grant-continuation.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const CONTINUE_URI = process.env.CONTINUE_URI;
12 | const CONTINUE_ACCESS_TOKEN = process.env.CONTINUE_ACCESS_TOKEN;
13 | const URL_WITH_INTERACT_REF = process.env.URL_WITH_INTERACT_REF;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 |
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 |
18 | const client = await createAuthenticatedClient({
19 | walletAddressUrl: WALLET_ADDRESS,
20 | privateKey: PRIVATE_KEY_PATH,
21 | keyId: KEY_ID,
22 | });
23 |
24 | // @TODO: Verify hash
25 | const url = new URL(URL_WITH_INTERACT_REF);
26 | const interactRef = url.searchParams.get("interact_ref");
27 |
28 | if (!interactRef) {
29 | throw new Error(`Missing 'interact_ref'. Received params: ${url.searchParams.toString()} `);
30 | }
31 |
32 | const grant = await client.grant.continue(
33 | {
34 | accessToken: CONTINUE_ACCESS_TOKEN,
35 | url: CONTINUE_URI,
36 | },
37 | {
38 | interact_ref: interactRef,
39 | },
40 | );
41 |
42 | if (!isFinalizedGrant(grant)) {
43 | throw new Error("Expected finalized grant. Received non-finalized grant.");
44 | }
45 |
46 | console.log(
47 | "\x1b[34mNote: \x1b[0mIf you requested a grant with the `pnpm grant` script, the following `OUTGOING_PAYMENT_ACCESS_TOKEN` and `OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL` can be used for Incoming Payments and Quotes as well.\n",
48 | );
49 |
50 | console.log("OUTGOING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
51 | console.log("OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL =", grant.access_token.manage);
52 |
--------------------------------------------------------------------------------
/grant/grant-continuation.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const CONTINUE_URI = process.env.CONTINUE_URI;
12 | const CONTINUE_ACCESS_TOKEN = process.env.CONTINUE_ACCESS_TOKEN;
13 | const URL_WITH_INTERACT_REF = process.env.URL_WITH_INTERACT_REF;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 |
16 | //@! start chunk 1 | title=Import dependencies
17 | import { createAuthenticatedClient, isFinalizedGrant } from "@interledger/open-payments";
18 | //@! end chunk 1
19 |
20 | //@! start chunk 2 | title=Initialize Open Payments client
21 | const client = await createAuthenticatedClient({
22 | walletAddressUrl: WALLET_ADDRESS,
23 | privateKey: PRIVATE_KEY_PATH,
24 | keyId: KEY_ID,
25 | });
26 | //@! end chunk 2
27 |
28 | // @TODO: Verify hash
29 | const url = new URL(URL_WITH_INTERACT_REF);
30 | const interactRef = url.searchParams.get("interact_ref");
31 |
32 | if (!interactRef) {
33 | throw new Error(`Missing 'interact_ref'. Received params: ${url.searchParams.toString()} `);
34 | }
35 |
36 | //@! start chunk 3 | title=Continue grant
37 | const grant = await client.grant.continue(
38 | {
39 | accessToken: CONTINUE_ACCESS_TOKEN,
40 | url: CONTINUE_URI,
41 | },
42 | {
43 | interact_ref: interactRef,
44 | },
45 | );
46 | //@! end chunk 3
47 |
48 | //@! start chunk 4 | title=Check grant state
49 | if (!isFinalizedGrant(grant)) {
50 | throw new Error("Expected finalized grant. Received non-finalized grant.");
51 | }
52 | //@! end chunk4
53 |
54 | console.log(
55 | "\x1b[34mNote: \x1b[0mIf you requested a grant with the `pnpm grant` script, the following `OUTGOING_PAYMENT_ACCESS_TOKEN` and `OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL` can be used for Incoming Payments and Quotes as well.\n",
56 | );
57 | //@! start chunk 5 | title=Output
58 | console.log("OUTGOING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
59 | console.log("OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL =", grant.access_token.manage);
60 | //@! end chunk 5
61 |
--------------------------------------------------------------------------------
/grant/grant-incoming-payment.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
14 |
15 | const client = await createAuthenticatedClient({
16 | walletAddressUrl: WALLET_ADDRESS,
17 | privateKey: PRIVATE_KEY_PATH,
18 | keyId: KEY_ID,
19 | });
20 |
21 | const walletAddress = await client.walletAddress.get({
22 | url: WALLET_ADDRESS,
23 | });
24 |
25 | const grant = await client.grant.request(
26 | {
27 | url: walletAddress.authServer,
28 | },
29 | {
30 | access_token: {
31 | access: [
32 | {
33 | type: "incoming-payment",
34 | actions: ["list", "read", "read-all", "complete", "create"],
35 | },
36 | ],
37 | },
38 | },
39 | );
40 |
41 | if (isPendingGrant(grant)) {
42 | throw new Error("Expected non-interactive grant");
43 | }
44 |
45 | console.log("INCOMING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
46 | console.log("INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL = ", grant.access_token.manage);
47 |
--------------------------------------------------------------------------------
/grant/grant-incoming-payment.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | //@! start chunk 1 | title=Import dependencies
14 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
15 | //@! end chunk 1
16 |
17 | //@! start chunk 2 | title=Initialize Open Payments client
18 | const client = await createAuthenticatedClient({
19 | walletAddressUrl: WALLET_ADDRESS,
20 | privateKey: PRIVATE_KEY_PATH,
21 | keyId: KEY_ID,
22 | });
23 | //@! end chunk 2
24 |
25 | //@! start chunk 3 | title=Get wallet address information
26 | const walletAddress = await client.walletAddress.get({
27 | url: WALLET_ADDRESS,
28 | });
29 | //@! end chunk 3
30 |
31 | //@! start chunk 4 | title=Request incoming payment grant
32 | const grant = await client.grant.request(
33 | {
34 | url: walletAddress.authServer,
35 | },
36 | {
37 | access_token: {
38 | access: [
39 | {
40 | type: "incoming-payment",
41 | actions: ["list", "read", "read-all", "complete", "create"],
42 | },
43 | ],
44 | },
45 | },
46 | );
47 | //@! end chunk 4
48 |
49 | //@! start chunk 5 | title=Check grant state
50 | if (isPendingGrant(grant)) {
51 | throw new Error("Expected non-interactive grant");
52 | }
53 | //@! end chunk 5
54 |
55 | //@! start chunk 6 | title=Output
56 | console.log("INCOMING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
57 | console.log("INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL = ", grant.access_token.manage);
58 | //@! end chunk 6
59 |
--------------------------------------------------------------------------------
/grant/grant-outgoing-payment-interval.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 | const NONCE = randomUUID();
16 |
17 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
18 |
19 | const client = await createAuthenticatedClient({
20 | walletAddressUrl: WALLET_ADDRESS,
21 | privateKey: PRIVATE_KEY_PATH,
22 | keyId: KEY_ID,
23 | });
24 |
25 | const walletAddress = await client.walletAddress.get({
26 | url: WALLET_ADDRESS,
27 | });
28 |
29 | const quote = await client.quote.get({
30 | url: QUOTE_URL,
31 | accessToken: QUOTE_ACCESS_TOKEN,
32 | });
33 |
34 | const DEBIT_AMOUNT = quote.debitAmount;
35 | const RECEIVE_AMOUNT = quote.receiveAmount;
36 |
37 | const grant = await client.grant.request(
38 | {
39 | url: walletAddress.authServer,
40 | },
41 | {
42 | access_token: {
43 | access: [
44 | {
45 | identifier: walletAddress.id,
46 | type: "outgoing-payment",
47 | actions: ["list", "list-all", "read", "read-all", "create"],
48 | limits: {
49 | debitAmount: DEBIT_AMOUNT,
50 | receiveAmount: RECEIVE_AMOUNT,
51 | interval: "R/2016-08-24T08:00:00Z/P1D"
52 | },
53 | },
54 | ],
55 | },
56 | interact: {
57 | start: ["redirect"],
58 | finish: {
59 | method: "redirect",
60 | uri: "http://localhost:3344",
61 | nonce: NONCE,
62 | },
63 | },
64 | },
65 | );
66 |
67 | if (!isPendingGrant(grant)) {
68 | throw new Error("Expected interactive grant");
69 | }
70 |
71 | console.log("Please interact at the following URL:", grant.interact.redirect);
72 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
73 | console.log("CONTINUE_URI =", grant.continue.uri);
74 |
--------------------------------------------------------------------------------
/grant/grant-outgoing-payment-interval.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 | const NONCE = randomUUID();
16 |
17 | //@! start chunk 1 | title=Import dependencies
18 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
19 | //@! end chunk 1
20 |
21 | //@! start chunk 2 | title=Initialize Open Payments client
22 | const client = await createAuthenticatedClient({
23 | walletAddressUrl: WALLET_ADDRESS,
24 | privateKey: PRIVATE_KEY_PATH,
25 | keyId: KEY_ID,
26 | });
27 | //@! end chunk 2
28 |
29 | //@! start chunk 3 | title=Get wallet address information
30 | const walletAddress = await client.walletAddress.get({
31 | url: WALLET_ADDRESS,
32 | });
33 | //@! end chunk 3
34 |
35 | const quote = await client.quote.get({
36 | url: QUOTE_URL,
37 | accessToken: QUOTE_ACCESS_TOKEN,
38 | });
39 |
40 | //@! start chunk 4 | title=Request outgoing payment grant with interval
41 | const grant = await client.grant.request(
42 | {
43 | url: walletAddress.authServer,
44 | },
45 | {
46 | access_token: {
47 | access: [
48 | {
49 | identifier: walletAddress.id,
50 | type: "outgoing-payment",
51 | actions: ["list", "list-all", "read", "read-all", "create"],
52 | limits: {
53 | debitAmount: {
54 | assetCode: quote.debitAmount.assetCode,
55 | assetScale: quote.debitAmount.assetScale,
56 | value: quote.debitAmount.value,
57 | },
58 | interval: "R/2016-08-24T08:00:00Z/P1D",
59 | },
60 | },
61 | ],
62 | },
63 | interact: {
64 | start: ["redirect"],
65 | finish: {
66 | method: "redirect",
67 | uri: "http://localhost:3344",
68 | nonce: NONCE,
69 | },
70 | },
71 | },
72 | );
73 | //@! end chunk 4
74 |
75 | //@! start chunk 5 | title=Check grant state
76 | if (!isPendingGrant(grant)) {
77 | throw new Error("Expected interactive grant");
78 | }
79 | //@! end chunk 5
80 |
81 | //@! start chunk 6 | title=Output
82 | console.log("Please interact at the following URL:", grant.interact.redirect);
83 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
84 | console.log("CONTINUE_URI =", grant.continue.uri);
85 | //@! end chunk 6
86 |
--------------------------------------------------------------------------------
/grant/grant-outgoing-payment.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 | const NONCE = randomUUID();
16 |
17 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
18 |
19 | const client = await createAuthenticatedClient({
20 | walletAddressUrl: WALLET_ADDRESS,
21 | privateKey: PRIVATE_KEY_PATH,
22 | keyId: KEY_ID,
23 | });
24 |
25 | const walletAddress = await client.walletAddress.get({
26 | url: WALLET_ADDRESS,
27 | });
28 |
29 | const quote = await client.quote.get({
30 | url: QUOTE_URL,
31 | accessToken: QUOTE_ACCESS_TOKEN,
32 | });
33 |
34 | const DEBIT_AMOUNT = quote.debitAmount;
35 | const RECEIVE_AMOUNT = quote.receiveAmount;
36 |
37 | const grant = await client.grant.request(
38 | {
39 | url: walletAddress.authServer,
40 | },
41 | {
42 | access_token: {
43 | access: [
44 | {
45 | identifier: walletAddress.id,
46 | type: "outgoing-payment",
47 | actions: ["list", "list-all", "read", "read-all", "create"],
48 | limits: {
49 | debitAmount: DEBIT_AMOUNT,
50 | receiveAmount: RECEIVE_AMOUNT,
51 | },
52 | },
53 | ],
54 | },
55 | interact: {
56 | start: ["redirect"],
57 | finish: {
58 | method: "redirect",
59 | uri: "http://localhost:3344",
60 | nonce: NONCE,
61 | },
62 | },
63 | },
64 | );
65 |
66 | if (!isPendingGrant(grant)) {
67 | throw new Error("Expected interactive grant");
68 | }
69 |
70 | console.log("Please interact at the following URL:", grant.interact.redirect);
71 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
72 | console.log("CONTINUE_URI =", grant.continue.uri);
73 |
--------------------------------------------------------------------------------
/grant/grant-outgoing-payment.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
14 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
15 | const NONCE = randomUUID();
16 |
17 | //@! start chunk 1 | title=Import dependencies
18 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
19 | //@! end chunk 1
20 |
21 | //@! start chunk 2 | title=Initialize Open Payments client
22 | const client = await createAuthenticatedClient({
23 | walletAddressUrl: WALLET_ADDRESS,
24 | privateKey: PRIVATE_KEY_PATH,
25 | keyId: KEY_ID,
26 | });
27 | //@! end chunk 2
28 |
29 | //@! start chunk 3 | title=Get wallet address information
30 | const walletAddress = await client.walletAddress.get({
31 | url: WALLET_ADDRESS,
32 | });
33 | //@! end chunk 3
34 |
35 | const quote = await client.quote.get({
36 | url: QUOTE_URL,
37 | accessToken: QUOTE_ACCESS_TOKEN,
38 | });
39 |
40 | //@! start chunk 4 | title=Request outgoing payment grant
41 | const grant = await client.grant.request(
42 | {
43 | url: walletAddress.authServer,
44 | },
45 | {
46 | access_token: {
47 | access: [
48 | {
49 | identifier: walletAddress.id,
50 | type: "outgoing-payment",
51 | actions: ["list", "list-all", "read", "read-all", "create"],
52 | limits: {
53 | debitAmount: {
54 | assetCode: quote.debitAmount.assetCode,
55 | assetScale: quote.debitAmount.assetScale,
56 | value: quote.debitAmount.value,
57 | },
58 | },
59 | },
60 | ],
61 | },
62 | interact: {
63 | start: ["redirect"],
64 | finish: {
65 | method: "redirect",
66 | uri: "http://localhost:3344",
67 | nonce: NONCE,
68 | },
69 | },
70 | },
71 | );
72 | //@! end chunk 4
73 |
74 | //@! start chunk 5 | title=Check grant state
75 | if (!isPendingGrant(grant)) {
76 | throw new Error("Expected interactive grant");
77 | }
78 | //@! end chunk 5
79 |
80 | //@! start chunk 6 | title=Output
81 | console.log("Please interact at the following URL:", grant.interact.redirect);
82 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
83 | console.log("CONTINUE_URI =", grant.continue.uri);
84 | //@! end chunk 6
85 |
--------------------------------------------------------------------------------
/grant/grant-quote.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
14 |
15 | const client = await createAuthenticatedClient({
16 | walletAddressUrl: WALLET_ADDRESS,
17 | privateKey: PRIVATE_KEY_PATH,
18 | keyId: KEY_ID,
19 | });
20 |
21 | const walletAddress = await client.walletAddress.get({
22 | url: WALLET_ADDRESS,
23 | });
24 |
25 | const grant = await client.grant.request(
26 | {
27 | url: walletAddress.authServer,
28 | },
29 | {
30 | access_token: {
31 | access: [
32 | {
33 | type: "quote",
34 | actions: ["create", "read", "read-all"],
35 | },
36 | ],
37 | },
38 | },
39 | );
40 |
41 | if (isPendingGrant(grant)) {
42 | throw new Error("Expected non-interactive grant");
43 | }
44 |
45 | console.log("QUOTE_ACCESS_TOKEN =", grant.access_token.value);
46 | console.log("QUOTE_ACCESS_TOKEN_MANAGE_URL = ", grant.access_token.manage);
47 |
--------------------------------------------------------------------------------
/grant/grant-quote.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | //@! start chunk 1 | title=Import dependencies
14 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
15 | //@! end chunk 1
16 |
17 | //@! start chunk 2 | title=Initialize Open Payments client
18 | const client = await createAuthenticatedClient({
19 | walletAddressUrl: WALLET_ADDRESS,
20 | privateKey: PRIVATE_KEY_PATH,
21 | keyId: KEY_ID,
22 | });
23 | //@! end chunk 2
24 |
25 | //@! start chunk 3 | title=Get wallet address information
26 | const walletAddress = await client.walletAddress.get({
27 | url: WALLET_ADDRESS,
28 | });
29 | //@! end chunk 3
30 |
31 | //@! start chunk 4 | title=Request quote grant
32 | const grant = await client.grant.request(
33 | {
34 | url: walletAddress.authServer,
35 | },
36 | {
37 | access_token: {
38 | access: [
39 | {
40 | type: "quote",
41 | actions: ["create", "read", "read-all"],
42 | },
43 | ],
44 | },
45 | },
46 | );
47 | //@! end chunk 4
48 |
49 | //@! start chunk 5 | title=Check grant state
50 | if (isPendingGrant(grant)) {
51 | throw new Error("Expected non-interactive grant");
52 | }
53 | //@! end chunk 5
54 |
55 | //@! start chunk 6 | title=Output
56 | console.log("QUOTE_ACCESS_TOKEN =", grant.access_token.value);
57 | console.log("QUOTE_ACCESS_TOKEN_MANAGE_URL = ", grant.access_token.manage);
58 | //@! end chunk 6
59 |
--------------------------------------------------------------------------------
/grant/grant-revoke.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const CONTINUE_URI = process.env.CONTINUE_URI;
12 | const CONTINUE_ACCESS_TOKEN = process.env.CONTINUE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | await client.grant.cancel({
24 | accessToken: CONTINUE_ACCESS_TOKEN,
25 | url: CONTINUE_URI,
26 | });
27 |
28 | console.log("Grant revoked.");
29 |
--------------------------------------------------------------------------------
/grant/grant-revoke.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const CONTINUE_URI = process.env.CONTINUE_URI;
12 | const CONTINUE_ACCESS_TOKEN = process.env.CONTINUE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Revoke grant
28 | await client.grant.cancel({
29 | accessToken: CONTINUE_ACCESS_TOKEN,
30 | url: CONTINUE_URI,
31 | });
32 | //@! end chunk 3
33 |
34 | console.log("Grant revoked.");
35 |
--------------------------------------------------------------------------------
/grant/grant.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 | const NONCE = randomUUID();
14 |
15 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const walletAddress = await client.walletAddress.get({
24 | url: WALLET_ADDRESS,
25 | });
26 |
27 | const grant = await client.grant.request(
28 | {
29 | url: walletAddress.authServer,
30 | },
31 | {
32 | access_token: {
33 | access: [
34 | {
35 | type: "quote",
36 | actions: ["read", "read-all", "create"],
37 | },
38 | {
39 | type: "incoming-payment",
40 | actions: ["read", "read-all", "list", "list-all", "create", "complete"],
41 | },
42 | {
43 | identifier: WALLET_ADDRESS,
44 | type: "outgoing-payment",
45 | actions: ["read", "read-all", "list", "list-all", "create"],
46 | limits: {
47 | debitAmount: {
48 | value: "10000",
49 | assetCode: "USD",
50 | assetScale: 2,
51 | },
52 | receiveAmount: {
53 | value: "10000",
54 | assetCode: "USD",
55 | assetScale: 2,
56 | },
57 | },
58 | },
59 | ],
60 | },
61 | interact: {
62 | start: ["redirect"],
63 | finish: {
64 | method: "redirect",
65 | uri: "http://localhost:3344",
66 | nonce: NONCE,
67 | },
68 | },
69 | },
70 | );
71 |
72 | if (!isPendingGrant(grant)) {
73 | throw new Error("Expected interactive grant");
74 | }
75 |
76 | console.log("Please interact at the following URL:", grant.interact.redirect);
77 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
78 | console.log("CONTINUE_URI =", grant.continue.uri);
79 |
--------------------------------------------------------------------------------
/grant/grant.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { randomUUID } from "crypto";
4 | import { fileURLToPath } from "url";
5 |
6 | dotenv.config({
7 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
8 | });
9 |
10 | const KEY_ID = process.env.KEY_ID;
11 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 | const NONCE = randomUUID();
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient, isPendingGrant } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get wallet address information
28 | const walletAddress = await client.walletAddress.get({
29 | url: WALLET_ADDRESS,
30 | });
31 | //@! end chunk 3
32 |
33 | //@! start chunk 4 | title=Request grant
34 | const grant = await client.grant.request(
35 | {
36 | url: walletAddress.authServer,
37 | },
38 | {
39 | access_token: {
40 | access: [
41 | {
42 | type: "quote",
43 | actions: ["read", "read-all", "create"],
44 | },
45 | {
46 | type: "incoming-payment",
47 | actions: ["read", "read-all", "list", "list-all", "create", "complete"],
48 | },
49 | {
50 | identifier: WALLET_ADDRESS,
51 | type: "outgoing-payment",
52 | actions: ["read", "read-all", "list", "list-all", "create"],
53 | limits: {
54 | debitAmount: {
55 | value: "10000",
56 | assetCode: "USD",
57 | assetScale: 2,
58 | },
59 | receiveAmount: {
60 | value: "10000",
61 | assetCode: "USD",
62 | assetScale: 2,
63 | },
64 | },
65 | },
66 | ],
67 | },
68 | interact: {
69 | start: ["redirect"],
70 | finish: {
71 | method: "redirect",
72 | uri: "http://localhost:3344",
73 | nonce: NONCE,
74 | },
75 | },
76 | },
77 | );
78 | //@! end chunk 4
79 |
80 | //@! start chunk 5 | title=Check grant state
81 | if (!isPendingGrant(grant)) {
82 | throw new Error("Expected interactive grant");
83 | }
84 | //@! end chunk 5
85 |
86 | //@! start chunk 6 | title=Output
87 | console.log("Please interact at the following URL:", grant.interact.redirect);
88 | console.log("CONTINUE_ACCESS_TOKEN =", grant.continue.access_token.value);
89 | console.log("CONTINUE_URI =", grant.continue.uri);
90 | //@! end chunk 6
91 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-complete.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const incomingPayment = await client.incomingPayment.complete({
24 | url: INCOMING_PAYMENT_URL,
25 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
26 | });
27 |
28 | console.log("INCOMING PAYMENT:", JSON.stringify(incomingPayment, null, 2));
29 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-complete.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Complete incoming payment
28 | const incomingPayment = await client.incomingPayment.complete({
29 | url: INCOMING_PAYMENT_URL,
30 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
31 | });
32 | //@! end chunk 3
33 |
34 | //@! start chunk 4 | title=Output
35 | console.log("INCOMING PAYMENT:", JSON.stringify(incomingPayment, null, 2));
36 | //@! end chunk 4
37 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-create.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | import { createAuthenticatedClient } from "@interledger/open-payments";
15 |
16 | const client = await createAuthenticatedClient({
17 | walletAddressUrl: WALLET_ADDRESS,
18 | privateKey: PRIVATE_KEY_PATH,
19 | keyId: KEY_ID,
20 | });
21 |
22 | const incomingPayment = await client.incomingPayment.create(
23 | {
24 | url: new URL(WALLET_ADDRESS).origin,
25 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
26 | },
27 | {
28 | walletAddress: WALLET_ADDRESS,
29 | incomingAmount: {
30 | value: "1000",
31 | assetCode: "USD",
32 | assetScale: 2,
33 | },
34 | expiresAt: new Date(Date.now() + 60_000 * 10).toISOString(),
35 | },
36 | );
37 |
38 | console.log("INCOMING PAYMENT URL =", incomingPayment.id);
39 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-create.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | //@! start chunk 1 | title=Import dependencies
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 | //@! end chunk 1
17 |
18 | //@! start chunk 2 | title=Initialize Open Payments client
19 | const client = await createAuthenticatedClient({
20 | walletAddressUrl: WALLET_ADDRESS,
21 | privateKey: PRIVATE_KEY_PATH,
22 | keyId: KEY_ID,
23 | });
24 | //@! end chunk 2
25 |
26 | //@! start chunk 3 | title=Create incoming payment
27 | const incomingPayment = await client.incomingPayment.create(
28 | {
29 | url: new URL(WALLET_ADDRESS).origin,
30 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
31 | },
32 | {
33 | walletAddress: WALLET_ADDRESS,
34 | incomingAmount: {
35 | value: "1000",
36 | assetCode: "USD",
37 | assetScale: 2,
38 | },
39 | expiresAt: new Date(Date.now() + 60_000 * 10).toISOString(),
40 | },
41 | );
42 | //@! end chunk 3
43 |
44 | //@! start chunk 4 | title=Output
45 | console.log("INCOMING PAYMENT URL =", incomingPayment.id);
46 | //@! end chunk 4
47 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-get.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const incomingPayment = await client.incomingPayment.get({
24 | url: INCOMING_PAYMENT_URL,
25 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
26 | });
27 |
28 | console.log("INCOMING PAYMENT:", incomingPayment);
29 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-get.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get incoming payment
28 | const incomingPayment = await client.incomingPayment.get({
29 | url: INCOMING_PAYMENT_URL,
30 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
31 | });
32 | //@! end chunk 3
33 |
34 | //@! start chunk 4 | title=Output
35 | console.log("INCOMING PAYMENT:", incomingPayment);
36 | //@! end chunk 4
37 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-list.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | import { createAuthenticatedClient } from "@interledger/open-payments";
15 |
16 | const client = await createAuthenticatedClient({
17 | walletAddressUrl: WALLET_ADDRESS,
18 | privateKey: PRIVATE_KEY_PATH,
19 | keyId: KEY_ID,
20 | });
21 |
22 | const incomingPayments = await client.incomingPayment.list(
23 | {
24 | url: new URL(WALLET_ADDRESS).origin,
25 | walletAddress: WALLET_ADDRESS,
26 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
27 | },
28 | {
29 | first: 10,
30 | last: undefined,
31 | cursor: undefined,
32 | },
33 | );
34 |
35 | console.log("INCOMING PAYMENTS:", JSON.stringify(incomingPayments, null, 2));
36 |
--------------------------------------------------------------------------------
/incoming-payment/incoming-payment-list.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_ACCESS_TOKEN = process.env.INCOMING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | //@! start chunk 1 | title=Import dependencies
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 | //@! end chunk 1
17 |
18 | //@! start chunk 2 | title=Initialize Open Payments client
19 | const client = await createAuthenticatedClient({
20 | walletAddressUrl: WALLET_ADDRESS,
21 | privateKey: PRIVATE_KEY_PATH,
22 | keyId: KEY_ID,
23 | });
24 | //@! end chunk 2
25 |
26 | //@! start chunk 3 | title=List incoming payments
27 | const incomingPayments = await client.incomingPayment.list(
28 | {
29 | url: new URL(WALLET_ADDRESS).origin,
30 | walletAddress: WALLET_ADDRESS,
31 | accessToken: INCOMING_PAYMENT_ACCESS_TOKEN,
32 | },
33 | {
34 | first: 10,
35 | last: undefined,
36 | cursor: undefined,
37 | },
38 | );
39 | //@! end chunk 3
40 |
41 | //@! start chunk 4 | title=Output
42 | console.log("INCOMING PAYMENTS:", JSON.stringify(incomingPayments, null, 2));
43 | //@! end chunk 4
44 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-create.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const outgoingPayment = await client.outgoingPayment.create(
24 | {
25 | url: new URL(WALLET_ADDRESS).origin,
26 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
27 | },
28 | {
29 | walletAddress: WALLET_ADDRESS,
30 | quoteId: QUOTE_URL,
31 | },
32 | );
33 |
34 | console.log("OUTGOING_PAYMENT_URL = ", outgoingPayment.id);
35 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-create.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const QUOTE_URL = process.env.QUOTE_URL;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Create outgoing payment
28 | const outgoingPayment = await client.outgoingPayment.create(
29 | {
30 | url: new URL(WALLET_ADDRESS).origin,
31 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
32 | },
33 | {
34 | walletAddress: WALLET_ADDRESS,
35 | quoteId: QUOTE_URL,
36 | },
37 | );
38 | //@! end chunk 3
39 |
40 | //@! start chunk 4 | title=Output
41 | console.log("OUTGOING_PAYMENT_URL = ", outgoingPayment.id);
42 | //@! end chunk 4
43 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-get.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const OUTGOING_PAYMENT_URL = process.env.OUTGOING_PAYMENT_URL;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const outgoingPayment = await client.outgoingPayment.get({
24 | url: OUTGOING_PAYMENT_URL,
25 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
26 | });
27 |
28 | console.log("OUTGOING PAYMENT:", outgoingPayment);
29 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-get.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const OUTGOING_PAYMENT_URL = process.env.OUTGOING_PAYMENT_URL;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get outgoing payment
28 | const outgoingPayment = await client.outgoingPayment.get({
29 | url: OUTGOING_PAYMENT_URL,
30 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
31 | });
32 | //@! end chunk 3
33 |
34 | //@! start chunk 4 | title=Output
35 | console.log("OUTGOING PAYMENT:", outgoingPayment);
36 | //@! end chunk 4
37 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-list.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | import { createAuthenticatedClient } from "@interledger/open-payments";
15 |
16 | const client = await createAuthenticatedClient({
17 | walletAddressUrl: WALLET_ADDRESS,
18 | privateKey: PRIVATE_KEY_PATH,
19 | keyId: KEY_ID,
20 | });
21 |
22 | const outgoingPayments = await client.outgoingPayment.list(
23 | {
24 | url: new URL(WALLET_ADDRESS).origin,
25 | walletAddress: WALLET_ADDRESS,
26 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
27 | },
28 | {
29 | first: 10,
30 | last: undefined,
31 | cursor: undefined,
32 | },
33 | );
34 |
35 | console.log("OUTGOING PAYMENTS:", JSON.stringify(outgoingPayments, null, 2));
36 |
--------------------------------------------------------------------------------
/outgoing-payment/outgoing-payment-list.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const OUTGOING_PAYMENT_ACCESS_TOKEN = process.env.OUTGOING_PAYMENT_ACCESS_TOKEN;
12 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
13 |
14 | //@! start chunk 1 | title=Import dependencies
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 | //@! end chunk 1
17 |
18 | //@! start chunk 2 | title=Initialize Open Payments client
19 | const client = await createAuthenticatedClient({
20 | walletAddressUrl: WALLET_ADDRESS,
21 | privateKey: PRIVATE_KEY_PATH,
22 | keyId: KEY_ID,
23 | });
24 | //@! end chunk 2
25 |
26 | //@! start chunk 3 | title=List outgoing payments
27 | const outgoingPayments = await client.outgoingPayment.list(
28 | {
29 | url: new URL(WALLET_ADDRESS).origin,
30 | walletAddress: WALLET_ADDRESS,
31 | accessToken: OUTGOING_PAYMENT_ACCESS_TOKEN,
32 | },
33 | {
34 | first: 10,
35 | last: undefined,
36 | cursor: undefined,
37 | },
38 | );
39 | //@! end chunk 3
40 |
41 | //@! start chunk 4 | title=Output
42 | console.log("OUTGOING PAYMENTS:", JSON.stringify(outgoingPayments, null, 2));
43 | //@! end chunk 4
44 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@interledger/open-payments-snippets",
3 | "version": "0.1.0",
4 | "description": "Open Payments SDK snippets",
5 | "type": "module",
6 | "scripts": {
7 | "format": "prettier . --write --cache --cache-location='node_modules/.cache/prettiercache' --log-level=warn",
8 | "grant": "tsx grant/grant.ts",
9 | "grant:continuation": "tsx grant/grant-continuation.ts",
10 | "grant:ip": "tsx grant/grant-incoming-payment.ts",
11 | "grant:op": "tsx grant/grant-outgoing-payment.ts",
12 | "grant:quote": "tsx grant/grant-quote.ts",
13 | "grant:revoke": "tsx grant/grant-revoke.ts",
14 | "ip:create": "tsx incoming-payment/incoming-payment-create.ts",
15 | "ip:complete": "tsx incoming-payment/incoming-payment-complete.ts",
16 | "ip:get": "tsx incoming-payment/incoming-payment-get.ts",
17 | "ip:list": "tsx incoming-payment/incoming-payment-list.ts",
18 | "quote:create": "tsx quote/quote-create.ts",
19 | "quote:create:ra": "tsx quote/quote-create-receive-amount.ts",
20 | "quote:create:da": "tsx quote/quote-create-debit-amount.ts",
21 | "quote:get": "tsx quote/quote-get.ts",
22 | "op:create": "tsx outgoing-payment/outgoing-payment-create.ts",
23 | "op:get": "tsx outgoing-payment/outgoing-payment-get.ts",
24 | "op:list": "tsx outgoing-payment/outgoing-payment-list.ts",
25 | "token:revoke": "tsx token/token-revoke.ts",
26 | "token:revoke:ip": "tsx token/token-revoke.ts --token ip",
27 | "token:revoke:op": "tsx token/token-revoke.ts --token op",
28 | "token:revoke:quote": "tsx token/token-revoke.ts --token quote",
29 | "token:rotate": "tsx token/token-rotate.ts",
30 | "token:rotate:ip": "tsx token/token-rotate.ts --token ip",
31 | "token:rotate:op": "tsx token/token-rotate.ts --token op",
32 | "token:rotate:quote": "tsx token/token-rotate.ts --token quote",
33 | "wa:get": "tsx wallet-address/wallet-address-get.ts",
34 | "wa:get-keys": "tsx wallet-address/wallet-address-get-keys.ts"
35 | },
36 | "author": "Interledger",
37 | "keywords": [
38 | "open payments",
39 | "interledger",
40 | "code snippets",
41 | "ilp",
42 | "sdk"
43 | ],
44 | "devDependencies": {
45 | "@types/node": "^20.17.16",
46 | "dotenv": "^16.4.7",
47 | "prettier": "^3.4.2",
48 | "tsx": "^4.19.2",
49 | "typescript": "^5.7.3"
50 | },
51 | "dependencies": {
52 | "@interledger/open-payments": "^6.13.2"
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/quote/quote-create-debit-amount.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const walletAddress = await client.walletAddress.get({
24 | url: WALLET_ADDRESS,
25 | });
26 |
27 | const quote = await client.quote.create(
28 | {
29 | url: new URL(WALLET_ADDRESS).origin,
30 | accessToken: QUOTE_ACCESS_TOKEN,
31 | },
32 | {
33 | method: "ilp",
34 | walletAddress: WALLET_ADDRESS,
35 | receiver: INCOMING_PAYMENT_URL,
36 | debitAmount: {
37 | value: "500",
38 | assetCode: walletAddress.assetCode,
39 | assetScale: walletAddress.assetScale,
40 | },
41 | },
42 | );
43 |
44 | console.log("QUOTE_URL =", quote.id);
45 |
--------------------------------------------------------------------------------
/quote/quote-create-debit-amount.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get wallet address information
28 | const walletAddress = await client.walletAddress.get({
29 | url: WALLET_ADDRESS,
30 | });
31 | //@! end chunk 3
32 |
33 | //@! start chunk 4 | title=Create quote with debit amount
34 | const quote = await client.quote.create(
35 | {
36 | url: new URL(WALLET_ADDRESS).origin,
37 | accessToken: QUOTE_ACCESS_TOKEN,
38 | },
39 | {
40 | method: "ilp",
41 | walletAddress: WALLET_ADDRESS,
42 | receiver: INCOMING_PAYMENT_URL,
43 | debitAmount: {
44 | value: "500",
45 | assetCode: walletAddress.assetCode,
46 | assetScale: walletAddress.assetScale,
47 | },
48 | },
49 | );
50 | //@! end chunk 4
51 |
52 | //@! start chunk 5 | title=Output
53 | console.log("QUOTE_URL =", quote.id);
54 | //@! end chunk 5
55 |
--------------------------------------------------------------------------------
/quote/quote-create-receive-amount.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const walletAddress = await client.walletAddress.get({
24 | url: WALLET_ADDRESS,
25 | });
26 |
27 | const quote = await client.quote.create(
28 | {
29 | url: new URL(WALLET_ADDRESS).origin,
30 | accessToken: QUOTE_ACCESS_TOKEN,
31 | },
32 | {
33 | method: "ilp",
34 | walletAddress: WALLET_ADDRESS,
35 | receiver: INCOMING_PAYMENT_URL,
36 | receiveAmount: {
37 | value: "500",
38 | assetCode: walletAddress.assetCode,
39 | assetScale: walletAddress.assetScale,
40 | },
41 | },
42 | );
43 |
44 | console.log("QUOTE_URL =", quote.id);
45 |
--------------------------------------------------------------------------------
/quote/quote-create-receive-amount.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get wallet address information
28 | const walletAddress = await client.walletAddress.get({
29 | url: WALLET_ADDRESS,
30 | });
31 | //@! end chunk 3
32 |
33 | //@! start chunk 4 | title=Create quote with receive amount
34 | const quote = await client.quote.create(
35 | {
36 | url: new URL(WALLET_ADDRESS).origin,
37 | accessToken: QUOTE_ACCESS_TOKEN,
38 | },
39 | {
40 | method: "ilp",
41 | walletAddress: WALLET_ADDRESS,
42 | receiver: INCOMING_PAYMENT_URL,
43 | receiveAmount: {
44 | value: "500",
45 | assetCode: walletAddress.assetCode,
46 | assetScale: walletAddress.assetScale,
47 | },
48 | },
49 | );
50 | //@! end chunk 4
51 |
52 | //@! start chunk 5 | title=Output
53 | console.log("QUOTE_URL =", quote.id);
54 | //@! end chunk 5
55 |
--------------------------------------------------------------------------------
/quote/quote-create.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const quote = await client.quote.create(
24 | {
25 | url: new URL(WALLET_ADDRESS).origin,
26 | accessToken: QUOTE_ACCESS_TOKEN,
27 | },
28 | {
29 | method: "ilp",
30 | walletAddress: WALLET_ADDRESS,
31 | receiver: INCOMING_PAYMENT_URL,
32 | },
33 | );
34 |
35 | console.log("QUOTE_URL =", quote.id);
36 |
--------------------------------------------------------------------------------
/quote/quote-create.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const INCOMING_PAYMENT_URL = process.env.INCOMING_PAYMENT_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Create quote
28 | const quote = await client.quote.create(
29 | {
30 | url: new URL(WALLET_ADDRESS).origin,
31 | accessToken: QUOTE_ACCESS_TOKEN,
32 | },
33 | {
34 | method: "ilp",
35 | walletAddress: WALLET_ADDRESS,
36 | receiver: INCOMING_PAYMENT_URL,
37 | },
38 | );
39 | //@! end chunk 3
40 |
41 | //@! start chunk 4 | title=Output
42 | console.log("QUOTE_URL =", quote.id);
43 | //@! end chunk 4
44 |
--------------------------------------------------------------------------------
/quote/quote-get.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const QUOTE_URL = process.env.QUOTE_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | import { createAuthenticatedClient } from "@interledger/open-payments";
16 |
17 | const client = await createAuthenticatedClient({
18 | walletAddressUrl: WALLET_ADDRESS,
19 | privateKey: PRIVATE_KEY_PATH,
20 | keyId: KEY_ID,
21 | });
22 |
23 | const quote = await client.quote.get({
24 | url: QUOTE_URL,
25 | accessToken: QUOTE_ACCESS_TOKEN,
26 | });
27 |
28 | console.log("QUOTE:", JSON.stringify(quote, null, 2));
29 |
--------------------------------------------------------------------------------
/quote/quote-get.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const QUOTE_URL = process.env.QUOTE_URL;
12 | const QUOTE_ACCESS_TOKEN = process.env.QUOTE_ACCESS_TOKEN;
13 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
14 |
15 | //@! start chunk 1 | title=Import dependencies
16 | import { createAuthenticatedClient } from "@interledger/open-payments";
17 | //@! end chunk 1
18 |
19 | //@! start chunk 2 | title=Initialize Open Payments client
20 | const client = await createAuthenticatedClient({
21 | walletAddressUrl: WALLET_ADDRESS,
22 | privateKey: PRIVATE_KEY_PATH,
23 | keyId: KEY_ID,
24 | });
25 | //@! end chunk 2
26 |
27 | //@! start chunk 3 | title=Get quote
28 | const quote = await client.quote.get({
29 | url: QUOTE_URL,
30 | accessToken: QUOTE_ACCESS_TOKEN,
31 | });
32 | //@! end chunk 3
33 |
34 | //@! start chunk 4 | title=Output
35 | console.log("QUOTE:", JSON.stringify(quote, null, 2));
36 | //@! end chunk 4
37 |
--------------------------------------------------------------------------------
/token/token-revoke.js:
--------------------------------------------------------------------------------
1 | import { parseTokenArgs } from "utils/parse-token-args";
2 |
3 | const KEY_ID = process.env.KEY_ID;
4 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
5 | const { ACCESS_TOKEN, MANAGE_URL } = parseTokenArgs(process.argv.slice(2));
6 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
7 |
8 | import { createAuthenticatedClient } from "@interledger/open-payments";
9 |
10 | const client = await createAuthenticatedClient({
11 | walletAddressUrl: WALLET_ADDRESS,
12 | privateKey: PRIVATE_KEY_PATH,
13 | keyId: KEY_ID,
14 | });
15 |
16 | await client.token.revoke({
17 | url: MANAGE_URL,
18 | accessToken: ACCESS_TOKEN,
19 | });
20 |
21 | console.log("Token revoked.");
22 |
--------------------------------------------------------------------------------
/token/token-revoke.ts:
--------------------------------------------------------------------------------
1 | import { parseTokenArgs } from "utils/parse-token-args";
2 |
3 | const KEY_ID = process.env.KEY_ID;
4 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
5 | const { ACCESS_TOKEN, MANAGE_URL } = parseTokenArgs(process.argv.slice(2));
6 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
7 |
8 | //@! start chunk 1 | title=Import dependencies
9 | import { createAuthenticatedClient } from "@interledger/open-payments";
10 | //@! end chunk 1
11 |
12 | //@! start chunk 2 | title=Initialize Open Payments client
13 | const client = await createAuthenticatedClient({
14 | walletAddressUrl: WALLET_ADDRESS,
15 | privateKey: PRIVATE_KEY_PATH,
16 | keyId: KEY_ID,
17 | });
18 | //@! end chunk 2
19 |
20 | //@! start chunk 3 | title=Revoke token
21 | await client.token.revoke({
22 | url: MANAGE_URL,
23 | accessToken: ACCESS_TOKEN,
24 | });
25 | //@! end chunk 3
26 |
27 | console.log("Token revoked.");
28 |
--------------------------------------------------------------------------------
/token/token-rotate.js:
--------------------------------------------------------------------------------
1 | import { parseTokenArgs } from "utils/parse-token-args";
2 |
3 | const KEY_ID = process.env.KEY_ID;
4 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
5 | const { ACCESS_TOKEN, MANAGE_URL } = parseTokenArgs(process.argv.slice(2));
6 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
7 |
8 | import { createAuthenticatedClient } from "@interledger/open-payments";
9 |
10 | const client = await createAuthenticatedClient({
11 | walletAddressUrl: WALLET_ADDRESS,
12 | privateKey: PRIVATE_KEY_PATH,
13 | keyId: KEY_ID,
14 | });
15 |
16 | const token = await client.token.rotate({
17 | url: MANAGE_URL,
18 | accessToken: ACCESS_TOKEN,
19 | });
20 |
21 | console.log("ACCESS_TOKEN =", token.access_token.value);
22 | console.log("MANAGE_URL =", token.access_token.manage);
23 |
--------------------------------------------------------------------------------
/token/token-rotate.ts:
--------------------------------------------------------------------------------
1 | import { parseTokenArgs } from "utils/parse-token-args";
2 |
3 | const KEY_ID = process.env.KEY_ID;
4 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
5 | const { ACCESS_TOKEN, MANAGE_URL } = parseTokenArgs(process.argv.slice(2));
6 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
7 |
8 | //@! start chunk 1 | title=Import dependencies
9 | import { createAuthenticatedClient } from "@interledger/open-payments";
10 | //@! end chunk 1
11 |
12 | //@! start chunk 2 | title=Initialize Open Payments client
13 | const client = await createAuthenticatedClient({
14 | walletAddressUrl: WALLET_ADDRESS,
15 | privateKey: PRIVATE_KEY_PATH,
16 | keyId: KEY_ID,
17 | });
18 | //@! end chunk 2
19 |
20 | //@! start chunk 3 | title=Rotate token
21 | const token = await client.token.rotate({
22 | url: MANAGE_URL,
23 | accessToken: ACCESS_TOKEN,
24 | });
25 | //@! end chunk 3
26 |
27 | //@! start chunk 4 | title=Output
28 | console.log("ACCESS_TOKEN =", token.access_token.value);
29 | console.log("MANAGE_URL =", token.access_token.manage);
30 | //@! end chunk 4
31 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2022",
4 | "module": "ES2022",
5 | "skipLibCheck": true,
6 | "sourceMap": true,
7 | "outDir": "./dist",
8 | "moduleResolution": "node",
9 | "removeComments": true,
10 | "noImplicitAny": true,
11 | "strictNullChecks": true,
12 | "strictFunctionTypes": true,
13 | "noImplicitThis": true,
14 | "noUnusedLocals": true,
15 | "noUnusedParameters": true,
16 | "noImplicitReturns": true,
17 | "noFallthroughCasesInSwitch": true,
18 | "allowSyntheticDefaultImports": true,
19 | "esModuleInterop": true,
20 | "emitDecoratorMetadata": true,
21 | "experimentalDecorators": true,
22 | "resolveJsonModule": true,
23 | "baseUrl": "."
24 | },
25 | "exclude": ["node_modules"],
26 | "include": ["./**/*.ts"]
27 | }
28 |
--------------------------------------------------------------------------------
/utils/parse-token-args.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | enum Flag {
10 | TOKEN = "--token",
11 | }
12 |
13 | enum Token {
14 | INCOMING = "ip",
15 | OUTGOING = "op",
16 | QUOTE = "quote",
17 | }
18 |
19 | interface TokenOptions {
20 | manageUrl: string;
21 | accessToken: string;
22 | }
23 |
24 | const map = new Map([
25 | [
26 | Token.INCOMING,
27 | {
28 | manageUrl: process.env.INCOMING_PAYMENT_ACCESS_TOKEN_MANAGE_URL,
29 | accessToken: process.env.INCOMING_PAYMENT_ACCESS_TOKEN,
30 | },
31 | ],
32 | [
33 | Token.OUTGOING,
34 | {
35 | manageUrl: process.env.OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL,
36 | accessToken: process.env.OUTGOING_PAYMENT_ACCESS_TOKEN,
37 | },
38 | ],
39 | [
40 | Token.QUOTE,
41 | {
42 | manageUrl: process.env.QUOTE_ACCESS_TOKEN_MANAGE_URL,
43 | accessToken: process.env.QUOTE_ACCESS_TOKEN,
44 | },
45 | ],
46 | ]);
47 |
48 | function isToken(t: any): t is Token {
49 | return Object.values(Token).includes(t);
50 | }
51 |
52 | export function parseTokenArgs(args: string[]) {
53 | let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
54 | let MANAGE_URL = process.env.MANAGE_URL;
55 | let parsedFlags: string[] = [];
56 |
57 | while (args.length > 0) {
58 | const flag = args.shift() as Flag;
59 | let value: string | undefined;
60 |
61 | switch (flag) {
62 | case Flag.TOKEN:
63 | if (parsedFlags.includes(flag)) {
64 | throw new Error(`Received duplicate flag: "${flag}"`);
65 | }
66 | if (args.length === 0) {
67 | throw new Error(`No value was provided for flag "${flag}".`);
68 | }
69 |
70 | value = args.shift();
71 |
72 | if (isToken(value)) {
73 | const options = map.get(value);
74 | if (!options) {
75 | throw new Error(`Missing "manageUrl" and "accessToken" for "${value}"`);
76 | }
77 | ACCESS_TOKEN = options.accessToken;
78 | MANAGE_URL = options.manageUrl;
79 | parsedFlags.push(flag);
80 | } else {
81 | throw new Error(`Invalid "${value}" value.`);
82 | }
83 |
84 | break;
85 | default:
86 | console.log("\x1b[31mIgnoring invalid flag:", flag, "\x1b[0m");
87 | if (args.length === 0) {
88 | break;
89 | }
90 |
91 | if (!args[0].startsWith("--")) {
92 | args.shift();
93 | }
94 | break;
95 | }
96 | }
97 |
98 | return {
99 | ACCESS_TOKEN,
100 | MANAGE_URL,
101 | };
102 | }
103 |
--------------------------------------------------------------------------------
/wallet-address/wallet-address-get-keys.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | import { createAuthenticatedClient } from "@interledger/open-payments";
14 |
15 | const client = await createAuthenticatedClient({
16 | walletAddressUrl: WALLET_ADDRESS,
17 | privateKey: PRIVATE_KEY_PATH,
18 | keyId: KEY_ID,
19 | });
20 |
21 | const walletAddressKeys = await client.walletAddress.getKeys({
22 | url: WALLET_ADDRESS,
23 | });
24 |
25 | console.log("WALLET ADDRESS KEYS:", JSON.stringify(walletAddressKeys, null, 2));
26 |
--------------------------------------------------------------------------------
/wallet-address/wallet-address-get-keys.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | //@! start chunk 1 | title=Import dependencies
14 | import { createAuthenticatedClient } from "@interledger/open-payments";
15 | //@! end chunk 1
16 |
17 | //@! start chunk 2 | title=Initialize Open Payments client
18 | const client = await createAuthenticatedClient({
19 | walletAddressUrl: WALLET_ADDRESS,
20 | privateKey: PRIVATE_KEY_PATH,
21 | keyId: KEY_ID,
22 | });
23 | //@! end chunk 2
24 |
25 | //@! start chunk 3 | title=Get wallet address keys
26 | const walletAddressKeys = await client.walletAddress.getKeys({
27 | url: WALLET_ADDRESS,
28 | });
29 | //@! end chunk 3
30 |
31 | //@! start chunk 4 | title=Output
32 | console.log("WALLET ADDRESS KEYS:", JSON.stringify(walletAddressKeys, null, 2));
33 | //@! end chunk 4
34 |
--------------------------------------------------------------------------------
/wallet-address/wallet-address-get.js:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | import { createAuthenticatedClient } from "@interledger/open-payments";
14 |
15 | const client = await createAuthenticatedClient({
16 | walletAddressUrl: WALLET_ADDRESS,
17 | privateKey: PRIVATE_KEY_PATH,
18 | keyId: KEY_ID,
19 | });
20 |
21 | const walletAddress = await client.walletAddress.get({
22 | url: WALLET_ADDRESS,
23 | });
24 |
25 | console.log("WALLET ADDRESS:", walletAddress);
26 |
27 |
--------------------------------------------------------------------------------
/wallet-address/wallet-address-get.ts:
--------------------------------------------------------------------------------
1 | import dotenv from "dotenv";
2 | import { join } from "path";
3 | import { fileURLToPath } from "url";
4 |
5 | dotenv.config({
6 | path: fileURLToPath(join(import.meta.url, "..", "..", ".env")),
7 | });
8 |
9 | const KEY_ID = process.env.KEY_ID;
10 | const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
11 | const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
12 |
13 | //@! start chunk 1 | title=Import dependencies
14 | import { createAuthenticatedClient } from "@interledger/open-payments";
15 | //@! end chunk 1
16 |
17 | //@! start chunk 2 | title=Initialize Open Payments client
18 | const client = await createAuthenticatedClient({
19 | walletAddressUrl: WALLET_ADDRESS,
20 | privateKey: PRIVATE_KEY_PATH,
21 | keyId: KEY_ID,
22 | });
23 | //@! end chunk 2
24 |
25 | //@! start chunk 3 | title=Get wallet address
26 | const walletAddress = await client.walletAddress.get({
27 | url: WALLET_ADDRESS,
28 | });
29 | //@! end chunk 3
30 |
31 | //@! start chunk 4 | title=Output
32 | console.log("WALLET ADDRESS:", walletAddress);
33 | //@! end chunk 4
34 |
--------------------------------------------------------------------------------