diff --git a/Dockerfile b/Dockerfile index dfa7dd0..951c1cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ FROM node:12-alpine -ADD . / payid-cli/ +ADD . / paystring-cli/ -RUN cd payid-cli/ &&\ +RUN cd paystring-cli/ &&\ npm set unsafe-perm true &&\ npm cache clean --force &&\ npm install &&\ @@ -11,11 +11,11 @@ RUN cd payid-cli/ &&\ FROM node:12-alpine -RUN mkdir /opt/payid-cli +RUN mkdir /opt/paystring-cli -WORKDIR /opt/payid-cli +WORKDIR /opt/paystring-cli -COPY --from=0 /payid-cli/dist /opt/payid-cli/dist -COPY --from=0 /payid-cli/node_modules /opt/payid-cli/node_modules +COPY --from=0 /paystring-cli/dist /opt/paystring-cli/dist +COPY --from=0 /paystring-cli/node_modules /opt/paystring-cli/node_modules -ENTRYPOINT ["node", "/opt/payid-cli/dist/cli.js"] +ENTRYPOINT ["node", "/opt/paystring-cli/dist/cli.js"] diff --git a/README.md b/README.md index 7a29e96..2c2bc8e 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,37 @@ -# `@payid-org/payid-cli` +# `@paystring/paystring-cli` -![NPM version badge](https://img.shields.io/npm/v/@payid-org/payid-cli) +![NPM version badge](https://img.shields.io/npm/v/@paystring/paystring-cli) -Command-line interface to create, fetch, sign, and verify PayIDs. -Based on the Typescript PayID [Utils](https://github.com/payid-org/utils) library. +Command-line interface to create, fetch, sign, and verify PayStrings. +Based on the Typescript PayString [Utils](https://github.com/paystring/utils) library. ## Prerequisites -Before you install PayID CLI locally, ensure that both [node](https://nodejs.org/en/download/) and +Before you install PayString CLI locally, ensure that both [node](https://nodejs.org/en/download/) and [npm](https://docs.npmjs.com/downloading-and-installing-packages-locally) are installed locally. -You can also run PayID CLI as a Docker container. If you run commands that cause information to be stored locally, that information only persists for the duration of the container. +You can also run PayString CLI as a Docker container. If you run commands that cause information to be stored locally, that information only persists for the duration of the container. ## Installation -To install PayID CLI, run the command: +To install PayString CLI, run the command: ``` -npm install -g @payid-org/payid-cli +npm install -g @paystring/paystring-cli ``` -This command installs PayID CLI as a global npm module and links it as a `payid` executable -(typically under /usr/local/bin/payid). +This command installs PayString CLI as a global npm module and links it as a `paystring` executable +(typically under /usr/local/bin/paystring). Alternatively, install and run via Docker: ``` -docker run xpring/payid-cli +docker run xpring/paystring-cli ``` ## Interactive vs. single command mode -You can run PayID CLI in either interactive mode or non-interactive (single command) mode. +You can run PayString CLI in either interactive mode or non-interactive (single command) mode. In interactive mode, a prompt is displayed, and you can run multiple commands from this prompt. Run the `exit` command to leave interactive mode. Interactive mode retains a history of executed commands that you can access by with the up arrow key. Use the key for command completion. @@ -40,25 +40,25 @@ In non-interactive mode, you run a single command, based on supplied command lin No prompt is displayed in this mode. Non-interactive mode is useful for running commands from a script, or to chain the results of multiple commands together. -To run the CLI in interactive mode, run `payid`. You can now enter ` arguments` for each command you want to run. +To run the CLI in interactive mode, run `paystring`. You can now enter ` arguments` for each command you want to run. -To run the CLI in non-interactive mode, run `payid `. +To run the CLI in non-interactive mode, run `paystring `. Examples of non-interactive mode: -The following command lists information about the specified PayID. +The following command lists information about the specified PayString. ``` -payid load 'nhartner$xpring.money' +paystring load 'nhartner$xpring.money' ``` -You can run multiple commands chained together. This set of commands initializes a new or existing PayID, associates a specified crypto-address for the specified currency and network, and then saves the PayID with this information. +You can run multiple commands chained together. This set of commands initializes a new or existing PayString, associates a specified crypto-address for the specified currency and network, and then saves the PayString with this information. ``` -payid init 'my$pay.id' && payid crypto-address add btc mainnet notARealAddress && payid save +paystring init 'my$paystring.com' && paystring crypto-address add btc mainnet notARealAddress && paystring save ``` -_Note_: when passing a PayID as an argument in non-interactive mode, the PayID must be escaped or quoted +_Note_: when passing a PayString as an argument in non-interactive mode, the PayString must be escaped or quoted to avoid the '\$' being interpolated as a variable by the shell. ## Commands @@ -69,62 +69,62 @@ The following commands are available: help [command...] Provides help for a given command. exit Exits application. clear Clears the terminal. - crypto-address add
[tag] Starts building a new PayID. - crypto-address remove
Removes an address from the current PayID. + crypto-address add
[tag] Starts building a new PayString. + crypto-address remove
Removes an address from the current PayString. keys clear Clears all loaded keys. keys generate Generates and saves a new identity key. keys list Lists keys that have been loaded. keys load Loads identity-key from file. keys print Prints keys that have been loaded in pem format. - init Initializes a new PayID. - inspect [payId] Inspects signatures on the loaded PayID or from an optionally specified PayID. - load Loads a PayID from PayID server. - show Shows the currently loaded PayID. - sign Signs the loaded PayID with the loaded signing keys. - verify [payId] Verifies the loaded PayID or an optionally specified PayID. - save Saves the currently loaded PayID. - from-url Converts a URL to a PayID. - to-url Converts a PayID to a URL. + init Initializes a new PayString. + inspect [paystring] Inspects signatures on the loaded PayString or from an optionally specified PayString. + load Loads a PayString from PayString server. + show Shows the currently loaded PayString. + sign Signs the loaded PayString with the loaded signing keys. + verify [paystring] Verifies the loaded PayString or an optionally specified PayString. + save Saves the currently loaded PayString. + from-url Converts a URL to a PayString. + to-url Converts a PayString to a URL. ``` ## Use Cases -### Load a PayID +### Load a PayString -Load an existing PayID from a remote server: +Load an existing PayString from a remote server: ``` load nhartner$xpring.money ``` -This command fetches all the PayID address mappings for the given PayID from the remote +This command fetches all the PayString address mappings for the given PayString from the remote server and displays the resulting JSON. -### Create a new PayID +### Create a new PayString -The following set of commands demonstrates how to create a new PayID, attach multiple +The following set of commands demonstrates how to create a new PayString, attach multiple address mappings, and save the result to a JSON file. ``` -init example$mypayid.com +init example$mypaystring.com crypto-address add xrpl mainnet rP3t3JStqWPYd8H88WfBYh3v84qqYzbHQ6 12345 crypto-address add btc mainnet 3M2CH71P6uZTra1PsjiEhNFB7kCENShCgt save ``` -The PayID JSON representation specified here is saved to the local filesystem as example.json. +The PayString JSON representation specified here is saved to the local filesystem as example.json. ### Identity Keys -The PayID protocol supports signing address mappings using one or more cryptographic keys. -PayID CLI provides several commands to generate and load keys. Once a key is generated -or loaded by PayID CLI, it is retained in PayID CLI's local storage for use when you sign your PayID. +The PayString protocol supports signing address mappings using one or more cryptographic keys. +PayString CLI provides several commands to generate and load keys. Once a key is generated +or loaded by PayString CLI, it is retained in PayString CLI's local storage for use when you sign your PayString. You can generate multiple identity keys by using the `keys generate` and `keys load` commands. To remove all loaded keys from the CLI's local storage, use the `keys clear` command. -To see all keys currently loaded into PayID CLI, use the `keys list` command. +To see all keys currently loaded into PayString CLI, use the `keys list` command. To generate a new key run: @@ -135,34 +135,34 @@ keys generate This generates a new key and saves it to a file named `identity-key.pem`. To load a previously created identity key, run `keys load `. -### Sign a PayID +### Sign a PayString -Before you sign an PayID, you must either load the PayID using the `load` command, or create a PayID using the -`init` command, and you must execute commands so that the PayID one or more crypto-addresses. +Before you sign an PayString, you must either load the PayString using the `load` command, or create a PayString using the +`init` command, and you must execute commands so that the PayString one or more crypto-addresses. -Once a PayID has been initialized or loaded, you can sign it using an [identity key](#identity-keys). You must either generate a new key, or load an existing one. Once your PayID has been loaded or initialized, and your identity key has been generated or loaded, -you can sign the PayID using `sign` command. The `sign` command signs each of your PayID address -mappings using the loaded identity keys, and outputs the resulting PayID with a `verifiedAddress` field. +Once a PayString has been initialized or loaded, you can sign it using an [identity key](#identity-keys). You must either generate a new key, or load an existing one. Once your PayString has been loaded or initialized, and your identity key has been generated or loaded, +you can sign the PayString using `sign` command. The `sign` command signs each of your PayString address +mappings using the loaded identity keys, and outputs the resulting PayString with a `verifiedAddress` field. By default, the sign command clears the unsigned `addresses` from the results. If you wish to retain unsigned addresses after signing, use `sign --keep-addresses` or `sign -k` instead. -Finally, run the `save` command to save your PayID, with signed addresses, to file. +Finally, run the `save` command to save your PayString, with signed addresses, to file. -### Inspect a Verified PayID +### Inspect a Verified PayString -Two commands are available to verify a PayID's verified addresses. +Two commands are available to verify a PayString's verified addresses. - `verify` - checks if all the verified addresses have valid signatures. - `inspect` - displays details information about each verified address and signatures. -## Create, sign, and inspect a PayID +## Create, sign, and inspect a PayString -With a combination of commands, you can create a PayID, add an address mapping, generate an identity key, -sign your PayID address mapping, and then inspect the final result. +With a combination of commands, you can create a PayString, add an address mapping, generate an identity key, +sign your PayString address mapping, and then inspect the final result. ``` -init example$mypayid.com +init example$mypaystring.com crypto-address add xrpl mainnet rP3t3JStqWPYd8H88WfBYh3v84qqYzbHQ6 keys generate sign @@ -171,4 +171,4 @@ inspect ## Legal -By using, reproducing, or distributing this code, you agree to the terms and conditions for use (including the Limitation of Liability) in the [Apache License 2.0](https://github.com/payid-org/payid-cli/blob/master/LICENSE). If you do not agree, you may not use, reproduce, or distribute the code. **This code is not authorised for download in Australia. Any persons located in Australia are expressly prohibited from downloading, using, reproducing or distributing the code.** This code is not owned by, or associated with, NPP Australia Limited, and has no sponsorship, affiliation or other connection with the "Pay ID" service operated by NPP Australia Limited in Australia. +By using, reproducing, or distributing this code, you agree to the terms and conditions for use (including the Limitation of Liability) in the [Apache License 2.0](https://github.com/paystring/payid-cli/blob/master/LICENSE). If you do not agree, you may not use, reproduce, or distribute the code. **This code is not authorised for download in Australia. Any persons located in Australia are expressly prohibited from downloading, using, reproducing or distributing the code.** diff --git a/package-lock.json b/package-lock.json index a553be9..f3c4357 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@payid-org/payid-cli", + "name": "@paystring/paystring-cli", "version": "1.0.4", "lockfileVersion": 1, "requires": true, @@ -419,13 +419,12 @@ "resolved": "https://registry.npmjs.org/@panva/asn1.js/-/asn1.js-1.0.0.tgz", "integrity": "sha512-UdkG3mLEqXgnlKsWanWcgb6dOjUzJ+XC5f+aWw30qrtjxeNUSfKX1cd5FBzOaXQumoe9nIqeZUvrRJS03HCCtw==" }, - "@payid-org/utils": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@payid-org/utils/-/utils-1.2.0.tgz", - "integrity": "sha512-6REhaw2lHek5ZKqS7PBV93ndlQ8TiRYo+2dgfrErrf13bOUqIsQIVVqTF/pU7NRRa3YYPZ9IrUPqmqUqEA1C7Q==", + "@paystring/utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@paystring/utils/-/utils-1.3.0.tgz", + "integrity": "sha512-2tFuSrwCVsJkdDzU+JjcEdlmcOxR6lo/Hj+lCNDGqxctlCiSl9J5oMyAPiSNIxQ5R3CdJhC/QdRu4f320CC0iw==", "requires": { "axios": "^0.19.2", - "beautify-json": "^1.0.1", "jose": "^1.27.3" } }, @@ -2749,9 +2748,9 @@ "dev": true }, "node-forge": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.9.1.tgz", - "integrity": "sha512-G6RlQt5Sb4GMBzXvhfkeFmbqR6MzhtnT7VTHuLadjkii3rdYHNdw0m8zA4BTxVIh68FicCQ2NSUANpsqkr9jvQ==" + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz", + "integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==" }, "node-localstorage": { "version": "0.6.0", diff --git a/package.json b/package.json index b6bcb81..7b54a0c 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { - "name": "@payid-org/payid-cli", + "name": "@paystring/paystring-cli", "version": "1.0.4", - "description": "CLI for PayID", - "homepage": "https://github.com/payid-org/payid-cli#readme", + "description": "CLI for PayString", + "homepage": "https://github.com/paystring/paystring-cli#readme", "bugs": { - "url": "https://github.com/payid-org/payid-cli/issues" + "url": "https://github.com/paystring/paystring-cli/issues" }, "repository": { "type": "git", - "url": "git+https://github.com/payid-org/payid-cli.git" + "url": "git+https://github.com/paystring/paystring-cli.git" }, "license": "Apache-2.0", "author": "", "main": "dist/index.js", "types": "dist/index.d.ts", "bin": { - "payid": "./dist/cli.js" + "paystring": "./dist/cli.js" }, "files": [ "dist/*" @@ -28,11 +28,11 @@ "test": "nyc mocha 'test/**/*.test.ts'" }, "dependencies": { - "@payid-org/utils": "^1.2.0", + "@paystring/utils": "^1.3.0", "axios": "^0.19.2", "beautify-json": "^1.0.1", "jose": "^1.27.3", - "node-forge": "^0.9.1", + "node-forge": "^0.10.0", "vorpal": "^1.12.0" }, "devDependencies": { diff --git a/src/cli.ts b/src/cli.ts index 785cbf0..24609ab 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -7,9 +7,9 @@ import * as cmd from './commands' const vorpal = new Vorpal() // This enables command history within the CLI similar to bash. -vorpal.history('payid') +vorpal.history('payString') -const localStorage = new cmd.LocalStorage('payid', vorpal) +const localStorage = new cmd.LocalStorage('payString', vorpal) new cmd.ClearCommand(vorpal, localStorage).setup() new cmd.AddCryptoAddressCommand(vorpal, localStorage).setup() new cmd.RemoveCryptoAddressCommand(vorpal, localStorage).setup() @@ -18,18 +18,18 @@ new cmd.GenerateIdentityKeyCommand(vorpal, localStorage).setup() new cmd.ListKeysCommand(vorpal, localStorage).setup() new cmd.LoadIdentityKeyCommand(vorpal, localStorage).setup() new cmd.PrintKeysCommand(vorpal, localStorage).setup() -new cmd.InitPayIdCommand(vorpal, localStorage).setup() -new cmd.InspectPayIdCommand(vorpal, localStorage).setup() -new cmd.LoadPayIdCommand(vorpal, localStorage).setup() -new cmd.ShowPayIdCommand(vorpal, localStorage).setup() -new cmd.SignPayIdCommand(vorpal, localStorage).setup() -new cmd.VerifyPayIdCommand(vorpal, localStorage).setup() -new cmd.SavePayIdCommand(vorpal, localStorage).setup() -new cmd.UrlToPayIdCommand(vorpal, localStorage).setup() -new cmd.PayIdToUrlCommand(vorpal, localStorage).setup() +new cmd.InitPayStringCommand(vorpal, localStorage).setup() +new cmd.InspectPayStringCommand(vorpal, localStorage).setup() +new cmd.LoadPayStringCommand(vorpal, localStorage).setup() +new cmd.ShowPayStringCommand(vorpal, localStorage).setup() +new cmd.SignPayStringCommand(vorpal, localStorage).setup() +new cmd.VerifyPayStringCommand(vorpal, localStorage).setup() +new cmd.SavePayStringCommand(vorpal, localStorage).setup() +new cmd.UrlToPayStringCommand(vorpal, localStorage).setup() +new cmd.PayStringToUrlCommand(vorpal, localStorage).setup() // The CLI can be run in interactive mode or to run a single command and terminate. -// For CLI mode, process.argv will have 2 values (e.g. node dist/cli.js) even if using the alias 'payid-utils'. +// For CLI mode, process.argv will have 2 values (e.g. node dist/cli.js) even if using the alias 'paystring-utils'. // For single command mode there will be additional arguments for the single command. if (process.argv.length > 2) { vorpal.parse(process.argv) diff --git a/src/commands/Command.ts b/src/commands/Command.ts index eaf55fd..07c49ed 100644 --- a/src/commands/Command.ts +++ b/src/commands/Command.ts @@ -1,4 +1,4 @@ -import { convertPayIdToUrl, PaymentInformation } from '@payid-org/utils' +import { convertPayStringToUrl, PaymentInformation } from '@paystring/utils' import axios, { AxiosResponse } from 'axios' import * as Vorpal from 'vorpal' import { Args } from 'vorpal' @@ -76,18 +76,18 @@ abstract class Command { } /** - * Retrieves a PayID using the optional payId argument or else returns the PaymentInformation + * Retrieves a PayString using the optional payString argument or else returns the PaymentInformation * currently loaded in local storage. * * @param args - The vorpal args object. * @returns PaymentInformation from args or local storage. Or error if can't be loaded. */ - protected async payIdFromArgsOrLocalStorage( + protected async payStringFromArgsOrLocalStorage( args: Args, ): Promise { - const { payId } = args - if (payId) { - return loadPayId(payId) + const { payId: payString } = args + if (payString) { + return loadPayString(payString) } return this.getPaymentInfo() } @@ -117,11 +117,13 @@ abstract class Command { /** * Loads a PayID from a remote server. * - * @param payId - The PayID to lookup. + * @param payString - The PayID to lookup. * @returns A promise that resolves to the PaymentInformation for the PayID. */ -export async function loadPayId(payId: string): Promise { - const url = convertPayIdToUrl(payId).href +export async function loadPayString( + payString: string, +): Promise { + const url = convertPayStringToUrl(payString).href return axios .get(url, { headers: { diff --git a/src/commands/crypto-address-add.ts b/src/commands/crypto-address-add.ts index 2414ec3..cc0ea42 100644 --- a/src/commands/crypto-address-add.ts +++ b/src/commands/crypto-address-add.ts @@ -1,4 +1,4 @@ -import { Address, AddressDetailsType } from '@payid-org/utils' +import { Address, AddressDetailsType } from '@paystring/utils' import * as Vorpal from 'vorpal' import Command from './Command' diff --git a/src/commands/index.ts b/src/commands/index.ts index 1c01523..bae6ff3 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,6 +1,6 @@ export { default as Command } from './Command' -export { default as PayIdToUrlCommand } from './payid-to-url' -export { default as UrlToPayIdCommand } from './payid-from-url' +export { default as PayStringToUrlCommand } from './paystring-to-url' +export { default as UrlToPayStringCommand } from './paystring-from-url' export { default as ClearCommand } from './clear' export { default as AddCryptoAddressCommand } from './crypto-address-add' export { default as RemoveCryptoAddressCommand } from './crypto-address-remove' @@ -10,10 +10,10 @@ export { default as ClearKeysCommand } from './keys-clear' export { default as ListKeysCommand } from './keys-list' export { default as PrintKeysCommand } from './keys-print' export { default as LocalStorage } from './localstorage' -export { default as InitPayIdCommand } from './payid-init' -export { default as InspectPayIdCommand } from './payid-inspect' -export { default as LoadPayIdCommand } from './payid-load' -export { default as SavePayIdCommand } from './payid-save' -export { default as ShowPayIdCommand } from './payid-show' -export { default as SignPayIdCommand } from './payid-sign' -export { default as VerifyPayIdCommand } from './payid-verify' +export { default as InitPayStringCommand } from './paystring-init' +export { default as InspectPayStringCommand } from './paystring-inspect' +export { default as LoadPayStringCommand } from './paystring-load' +export { default as SavePayStringCommand } from './paystring-save' +export { default as ShowPayStringCommand } from './paystring-show' +export { default as SignPayStringCommand } from './paystring-sign' +export { default as VerifyPayStringCommand } from './paystring-verify' diff --git a/src/commands/key-load.ts b/src/commands/key-load.ts index 1dc06bf..4b6ed76 100644 --- a/src/commands/key-load.ts +++ b/src/commands/key-load.ts @@ -1,4 +1,4 @@ -import { getSigningKeyFromFile } from '@payid-org/utils' +import { getSigningKeyFromFile } from '@paystring/utils' import * as Vorpal from 'vorpal' import Command from './Command' diff --git a/src/commands/keys-print.ts b/src/commands/keys-print.ts index 44ec607..4bac556 100644 --- a/src/commands/keys-print.ts +++ b/src/commands/keys-print.ts @@ -1,4 +1,4 @@ -import { toKey } from '@payid-org/utils' +import { toKey } from '@paystring/utils' import Command from './Command' diff --git a/src/commands/localstorage.ts b/src/commands/localstorage.ts index 5ea1422..f5c230e 100644 --- a/src/commands/localstorage.ts +++ b/src/commands/localstorage.ts @@ -1,10 +1,10 @@ -import { PaymentInformation } from '@payid-org/utils' +import { PaymentInformation } from '@paystring/utils' import { JWKECKey, JWKOctKey, JWKOKPKey, JWKRSAKey } from 'jose' import * as Vorpal from 'vorpal' /** * Facade layer for the Vorpal localstorage object. Provides typed methods for accessing things in - * local storage like signing keys and PayID PaymentInformation. Objects in local storage are + * local storage like signing keys and PayString PaymentInformation. Objects in local storage are * stored as JSON strings. */ export default class LocalStorage { @@ -13,12 +13,12 @@ export default class LocalStorage { /** * Constructs the facade and initializes the localstorage instance. * - * @param id - The id for this local storage. + * @param payString - The payString for this local storage. * @param vorpal - The vorpal instance to use. */ - public constructor(id: string, vorpal: Vorpal) { + public constructor(payString: string, vorpal: Vorpal) { // initializes the local storage instance - vorpal.localStorage(id) + vorpal.localStorage(payString) // The Vorpal API for local storage is really poorly defined and the type defs do not match the actual API. // see https://github.com/dthree/vorpal/wiki/API-%7C-vorpal#vorpallocalstorageid // So many things that make typescript linter upset that it's easiest to just disable all rules for this one line. @@ -35,7 +35,7 @@ export default class LocalStorage { * @returns The instance or undefined if none exists. */ public getPaymentInfo(): PaymentInformation | undefined { - return this.getItem('payid') as PaymentInformation + return this.getItem('paystring') as PaymentInformation } /** @@ -44,7 +44,7 @@ export default class LocalStorage { * @param info - The value to store. */ public setPaymentInfo(info: PaymentInformation): void { - this.setItem('payid', JSON.stringify(info)) + this.setItem('paystring', JSON.stringify(info)) } /** diff --git a/src/commands/payid-from-url.ts b/src/commands/payid-from-url.ts deleted file mode 100644 index 78c9f6f..0000000 --- a/src/commands/payid-from-url.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { convertUrlToPayId } from '@payid-org/utils' -import * as Vorpal from 'vorpal' - -import Command from './Command' - -/** - * Converts a url (eg https://xpring.money/test) to a PayID (eg test$xpring.money). - */ -export default class UrlToPayidCommand extends Command { - /** - * @override - */ - protected command(): string { - return 'from-url ' - } - - /** - * @override - */ - protected description(): string { - return 'convert a URL to a PayID' - } - - /** - * @override - */ - protected async action(args: Vorpal.Args): Promise { - const payid = convertUrlToPayId(args.url) - this.vorpal.log(payid) - } -} diff --git a/src/commands/payid-to-url.ts b/src/commands/payid-to-url.ts deleted file mode 100644 index 39f3e80..0000000 --- a/src/commands/payid-to-url.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { convertPayIdToUrl } from '@payid-org/utils' -import * as Vorpal from 'vorpal' - -import Command from './Command' - -/** - * Converts a PayID (eg test$xpring.money) to it's URL (eg https://xpring.money/test). - */ -export default class PayIdToUrlCommand extends Command { - /** - * @override - */ - protected async action(args: Vorpal.Args): Promise { - const url = convertPayIdToUrl(args.payId).href - this.vorpal.log(url) - } - - /** - * @override - */ - protected command(): string { - return 'to-url ' - } - - /** - * @override - */ - protected description(): string { - return 'converts PayID to url' - } -} diff --git a/src/commands/paystring-from-url.ts b/src/commands/paystring-from-url.ts new file mode 100644 index 0000000..4566c5f --- /dev/null +++ b/src/commands/paystring-from-url.ts @@ -0,0 +1,31 @@ +import { convertUrlToPayString } from '@paystring/utils' +import * as Vorpal from 'vorpal' + +import Command from './Command' + +/** + * Converts a url (eg https://xpring.money/test) to a PayString (eg test$xpring.money). + */ +export default class UrlToPayStringCommand extends Command { + /** + * @override + */ + protected command(): string { + return 'from-url ' + } + + /** + * @override + */ + protected description(): string { + return 'convert a URL to a PayString' + } + + /** + * @override + */ + protected async action(args: Vorpal.Args): Promise { + const payString = convertUrlToPayString(args.url) + this.vorpal.log(payString) + } +} diff --git a/src/commands/payid-init.ts b/src/commands/paystring-init.ts similarity index 64% rename from src/commands/payid-init.ts rename to src/commands/paystring-init.ts index b6c956e..8538b4a 100644 --- a/src/commands/payid-init.ts +++ b/src/commands/paystring-init.ts @@ -1,20 +1,20 @@ -import { PaymentInformation } from '@payid-org/utils' +import { PaymentInformation } from '@paystring/utils' import * as Vorpal from 'vorpal' import Command from './Command' /** - * Initializes a new PayID PaymentInformation object that can be decorated with addresses and signed using + * Initializes a new PayString PaymentInformation object that can be decorated with addresses and signed using * signing keys. */ -export default class InitPayIdCommand extends Command { +export default class InitPayStringCommand extends Command { /** * @override */ protected async action(args: Vorpal.Args): Promise { const info: PaymentInformation = { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Vorpal.Args isn't typed - payId: args.payid, + payId: args.payString, addresses: [], verifiedAddresses: [], } @@ -26,13 +26,13 @@ export default class InitPayIdCommand extends Command { * @override */ protected command(): string { - return 'init ' + return 'init ' } /** * @override */ protected description(): string { - return 'initializes a new PayID' + return 'initializes a new PayString' } } diff --git a/src/commands/payid-inspect.ts b/src/commands/paystring-inspect.ts similarity index 88% rename from src/commands/payid-inspect.ts rename to src/commands/paystring-inspect.ts index 5394f67..ffef816 100644 --- a/src/commands/payid-inspect.ts +++ b/src/commands/paystring-inspect.ts @@ -1,17 +1,17 @@ import { PaymentInformationInspector, SignatureInspectionResult, -} from '@payid-org/utils' +} from '@paystring/utils' import * as Vorpal from 'vorpal' import Command from './Command' import LocalStorage from './localstorage' /** - * Inspects the currently loaded PayID and prints inspection details to the console. + * Inspects the currently loaded PayString and prints inspection details to the console. * Inspection looks at verified addresses and verifies the signatures and certificate chain (if present). */ -export default class InspectPayIdCommand extends Command { +export default class InspectPayStringCommand extends Command { private readonly paymentInformationInspector: PaymentInformationInspector /** @@ -29,21 +29,21 @@ export default class InspectPayIdCommand extends Command { * @override */ protected command(): string { - return 'inspect [payId]' + return 'inspect [payString]' } /** * @override */ protected description(): string { - return 'Inspect signatures on the loaded PayID or from an optionally specified PayID' + return 'Inspect signatures on the loaded PayString or from an optionally specified PayString' } /** * @override */ protected async action(args: Vorpal.Args): Promise { - const info = await this.payIdFromArgsOrLocalStorage(args) + const info = await this.payStringFromArgsOrLocalStorage(args) const result = this.paymentInformationInspector.inspect(info) this.vorpal.log(`${info.payId} ${validString(result.isVerified)}`) result.verifiedAddressesResults.forEach((addressResult) => { diff --git a/src/commands/payid-load.ts b/src/commands/paystring-load.ts similarity index 54% rename from src/commands/payid-load.ts rename to src/commands/paystring-load.ts index be5cb78..35b41fa 100644 --- a/src/commands/payid-load.ts +++ b/src/commands/paystring-load.ts @@ -1,20 +1,20 @@ import * as Vorpal from 'vorpal' -import Command, { loadPayId } from './Command' +import Command, { loadPayString } from './Command' /** - * Loads a PayID from the remote server. For example, "load test$xpring.money" will + * Loads a PayString from the remote server. For example, "load test$xpring.money" will * make an HTTP call the https://xpring.money/test with Accept: application/payid+json * header so that all the addresses are returned. If successful, the PaymentInformation - * is saved to localstorage as the current payid in context. + * is saved to localstorage as the current payString in context. */ -export default class LoadPayIdCommand extends Command { +export default class LoadPayStringCommand extends Command { /** * @override */ protected async action(args: Vorpal.Args): Promise { - const { payId } = args - const info = await loadPayId(payId) + const { payString } = args + const info = await loadPayString(payString) this.localStorage.setPaymentInfo(info) this.logPaymentInfo(info) } @@ -23,13 +23,13 @@ export default class LoadPayIdCommand extends Command { * @override */ protected command(): string { - return 'load ' + return 'load ' } /** * @override */ protected description(): string { - return 'loads a PayID from PayID server' + return 'loads a PayString from PayString server' } } diff --git a/src/commands/payid-save.ts b/src/commands/paystring-save.ts similarity index 60% rename from src/commands/payid-save.ts rename to src/commands/paystring-save.ts index d9aeb35..7cf0681 100644 --- a/src/commands/payid-save.ts +++ b/src/commands/paystring-save.ts @@ -1,21 +1,21 @@ -import { splitPayIdString } from '@payid-org/utils' +import { splitPayString } from '@paystring/utils' import Command from './Command' import { overwriteFile } from './files' /** - * Saves the PaymentInformation for the currently loaded payid to a json file. + * Saves the PaymentInformation for the currently loaded payString to a json file. */ -export default class SavePayIdCommand extends Command { +export default class SavePayStringCommand extends Command { protected async action(): Promise { const info = this.getPaymentInfo() if (info.payId) { - const userHost = splitPayIdString(info.payId) + const userHost = splitPayString(info.payId) const filename = `${userHost[0]}.json` await overwriteFile(filename, JSON.stringify(info, null, 2)) this.vorpal.log(`Saved to ${filename}`) } else { - this.vorpal.log(`missing payID`) + this.vorpal.log(`missing payString`) } } @@ -30,6 +30,6 @@ export default class SavePayIdCommand extends Command { * @override */ protected description(): string { - return 'Save the currently loaded PayID' + return 'Save the currently loaded PayString' } } diff --git a/src/commands/payid-show.ts b/src/commands/paystring-show.ts similarity index 62% rename from src/commands/payid-show.ts rename to src/commands/paystring-show.ts index 4f36370..e5bd79f 100644 --- a/src/commands/payid-show.ts +++ b/src/commands/paystring-show.ts @@ -1,9 +1,9 @@ import Command from './Command' /** - * Prints the currently loaded PayID PaymentInformation to the console. + * Prints the currently loaded PayString PaymentInformation to the console. */ -export default class ShowPayIdCommand extends Command { +export default class ShowPayStringCommand extends Command { protected async action(): Promise { const info = this.getPaymentInfo() this.logPaymentInfo(info) @@ -20,6 +20,6 @@ export default class ShowPayIdCommand extends Command { * @override */ protected description(): string { - return 'Shows the currently loaded PayID' + return 'Shows the currently loaded PayString' } } diff --git a/src/commands/payid-sign.ts b/src/commands/paystring-sign.ts similarity index 89% rename from src/commands/payid-sign.ts rename to src/commands/paystring-sign.ts index 76b3c19..a4d4d2d 100644 --- a/src/commands/payid-sign.ts +++ b/src/commands/paystring-sign.ts @@ -1,19 +1,19 @@ import { convertToVerifiedAddress, - signWithKeys, IdentityKeySigningParams, - toKey, PaymentInformation, -} from '@payid-org/utils' + signWithKeys, + toKey, +} from '@paystring/utils' import { JWKECKey, JWKOctKey, JWKOKPKey, JWKRSAKey } from 'jose' import * as Vorpal from 'vorpal' import Command from './Command' /** - * Signs the currently loaded PayID PaymentInformation using the loaded signings keys. + * Signs the currently loaded PayString PaymentInformation using the loaded signings keys. */ -export default class SignPayIdCommand extends Command { +export default class SignPayStringCommand extends Command { /** * @override */ @@ -47,7 +47,7 @@ export default class SignPayIdCommand extends Command { return } - const updated = signPayId(info, signingKeys, isKeepAddresses) + const updated = signPayString(info, signingKeys, isKeepAddresses) this.localStorage.setPaymentInfo(updated) this.logPaymentInfo(updated) @@ -64,7 +64,7 @@ export default class SignPayIdCommand extends Command { * @override */ protected description(): string { - return 'sign the loaded PayID with the loaded signing keys' + return 'sign the loaded PayString with the loaded signing keys' } /** @@ -90,7 +90,7 @@ export default class SignPayIdCommand extends Command { * @param isKeepAddresses - If true, the unverified addresses property will be retained instead of cleared. * @returns A copy of the PaymentInformation but with verified addresses. */ -export function signPayId( +export function signPayString( info: PaymentInformation, signingKeys: IdentityKeySigningParams[], isKeepAddresses: boolean, diff --git a/src/commands/paystring-to-url.ts b/src/commands/paystring-to-url.ts new file mode 100644 index 0000000..ed956e7 --- /dev/null +++ b/src/commands/paystring-to-url.ts @@ -0,0 +1,31 @@ +import { convertPayStringToUrl } from '@paystring/utils' +import * as Vorpal from 'vorpal' + +import Command from './Command' + +/** + * Converts a PayString (eg test$xpring.money) to it's URL (eg https://xpring.money/test). + */ +export default class PayStringToUrlCommand extends Command { + /** + * @override + */ + protected async action(args: Vorpal.Args): Promise { + const url = convertPayStringToUrl(args.payString).href + this.vorpal.log(url) + } + + /** + * @override + */ + protected command(): string { + return 'to-url ' + } + + /** + * @override + */ + protected description(): string { + return 'converts PayString to url' + } +} diff --git a/src/commands/payid-verify.ts b/src/commands/paystring-verify.ts similarity index 71% rename from src/commands/payid-verify.ts rename to src/commands/paystring-verify.ts index ecaefe1..4035ea2 100644 --- a/src/commands/payid-verify.ts +++ b/src/commands/paystring-verify.ts @@ -1,22 +1,22 @@ import { convertJsonToAddress, PaymentInformation, - verifyPayId, -} from '@payid-org/utils' + verifyPayString, +} from '@paystring/utils' import * as Vorpal from 'vorpal' import Command from './Command' /** - * Verifies the signatures and certs for verified addresses of the currently loaded PayID. + * Verifies the signatures and certs for verified addresses of the currently loaded PayString. */ -export default class VerifyPayIdCommand extends Command { +export default class VerifyPayStringCommand extends Command { /** * @override */ protected async action(args: Vorpal.Args): Promise { - const info = await this.payIdFromArgsOrLocalStorage(args) - if (verifyPayId(info)) { + const info = await this.payStringFromArgsOrLocalStorage(args) + if (verifyPayString(info)) { const addresses = info.verifiedAddresses.map((address) => { return convertJsonToAddress(address.payload) }) @@ -36,13 +36,13 @@ export default class VerifyPayIdCommand extends Command { * @override */ protected command(): string { - return 'verify [payId]' + return 'verify [payString]' } /** * @override */ protected description(): string { - return 'Verify the loaded PayID or an optionally specified PayID' + return 'Verify the loaded PayString or an optionally specified PayString' } } diff --git a/test/unit/getDefaultAlgorithm.test.ts b/test/unit/getDefaultAlgorithm.test.ts index 77d9fdc..c78d12c 100644 --- a/test/unit/getDefaultAlgorithm.test.ts +++ b/test/unit/getDefaultAlgorithm.test.ts @@ -2,7 +2,7 @@ import 'mocha' import { assert } from 'chai' import { JWK } from 'jose' -import { getDefaultAlgorithm } from '../../src/commands/payid-sign' +import { getDefaultAlgorithm } from '../../src/commands/paystring-sign' describe('when getDefaultAlgorithm()', function (): void { it('given an EC key then returns ES256', async function (): Promise { diff --git a/test/unit/loadPayId.test.ts b/test/unit/loadPayString.test.ts similarity index 54% rename from test/unit/loadPayId.test.ts rename to test/unit/loadPayString.test.ts index b569a64..7341775 100644 --- a/test/unit/loadPayId.test.ts +++ b/test/unit/loadPayString.test.ts @@ -1,20 +1,22 @@ import 'mocha' import { assert } from 'chai' -import { loadPayId } from '../../src/commands/Command' +import { loadPayString } from '../../src/commands/Command' -describe('loadPayId()', function (): void { - it('Returns a PaymentInformation given a valid PayID', async function (): Promise< +describe('loadPayString()', function (): void { + it('Returns a PaymentInformation given a valid PayString', async function (): Promise< void > { - const info = await loadPayId('nhartner$xpring.money') + const info = await loadPayString('nhartner$xpring.money') assert.equal(info.payId, 'nhartner$xpring.money') assert.isTrue(info.addresses.length > 0) }) - it('Gives error when PayID returns 404', async function (): Promise { + it('Gives error when PayString returns 404', async function (): Promise< + void + > { try { - await loadPayId('bogusaccount$xpring.money') + await loadPayString('bogusaccount$xpring.money') assert.fail('expected error') } catch (error) { assert.deepEqual( diff --git a/test/unit/signPayId.test.ts b/test/unit/signPayString.test.ts similarity index 81% rename from test/unit/signPayId.test.ts rename to test/unit/signPayString.test.ts index 5aa77c6..f89fc6d 100644 --- a/test/unit/signPayId.test.ts +++ b/test/unit/signPayString.test.ts @@ -3,11 +3,11 @@ import { AddressDetailsType, IdentityKeySigningParams, PaymentInformation, -} from '@payid-org/utils' +} from '@paystring/utils' import { assert } from 'chai' import { JWK } from 'jose' -import { signPayId } from '../../src/commands/payid-sign' +import { signPayString } from '../../src/commands/paystring-sign' const info: PaymentInformation = { payId: 'boaty$mcboatface.com', @@ -24,7 +24,7 @@ const info: PaymentInformation = { verifiedAddresses: [], } -describe('when signPayId()', function (): void { +describe('when signPayString()', function (): void { let signingKey: IdentityKeySigningParams beforeEach('create key', async function (): Promise { @@ -35,7 +35,7 @@ describe('when signPayId()', function (): void { it('called with keepAddresses=true, then addresses property is retained', async function (): Promise< void > { - const result = signPayId(info, [signingKey], true) + const result = signPayString(info, [signingKey], true) assert.equal(result.addresses, info.addresses) assert.lengthOf(result.verifiedAddresses, 1) }) @@ -43,7 +43,7 @@ describe('when signPayId()', function (): void { it('called with keepAddresses=false, then addresses property is cleared', async function (): Promise< void > { - const result = signPayId(info, [signingKey], false) + const result = signPayString(info, [signingKey], false) assert.isEmpty(result.addresses) assert.lengthOf(result.verifiedAddresses, 1) })