UNPKG

@decentralized-identity/ion-cli

Version:

A Command Line Interface (CLI) to make working with the ION network and using ION DIDs easy peasy lemon squeezy.

62 lines (61 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const cli_ux_1 = require("cli-ux"); const StorageItem_1 = require("../StorageItem"); const ION = require('@decentralized-identity/ion-tools'); class Sign extends command_1.Command { async run() { const { args, flags } = this.parse(Sign); // Load the did package from the directory. cli_ux_1.default.action.start(`Loading DID with name '${args.friendlyName}' from directory path '${flags.directory}.'`); const storageItem = await StorageItem_1.default.load(flags.directory, args.friendlyName); cli_ux_1.default.action.stop(); // Create the ION did instance. const did = new ION.DID(storageItem.initialState); // Determine whether to use the short or long form // DID in as the key identifier prefix based on whether // the DID has been published. const kidPrefix = storageItem.published ? storageItem.initialState.shortForm : storageItem.initialState.longForm; cli_ux_1.default.action.start(`Signing payload using '${flags.kid}'.`); const jws = await ION.signJws({ payload: args.payload, privateJwk: storageItem.keys, header: { kid: `${kidPrefix}#${flags.kid}` }, detached: flags.detached, }); cli_ux_1.default.action.stop(); console.log(jws); } } exports.default = Sign; Sign.description = 'Sign payload using the private key associated with the specified DID.'; Sign.examples = [ '$ ion sign \'Hello World\' FriendlyName -d d:/dids', '$ ion sign \'Hello World\' FriendlyName -d d:/dids -k \'key-1\'', '$ ion sign \'Hello World\' FriendlyName -d d:/dids -k \'key-1\' -s', '$ ion sign \'Hello World\' FriendlyName -d d:/dids -k \'key-1\' -s -n https://node.local/1.0/identifiers/', ]; Sign.flags = { help: command_1.flags.help({ char: 'h' }), // Flag for specifying a directory to which keys and documents should be saved directory: command_1.flags.string({ char: 'd', description: 'from which to read DID and key. Defaults to environment variable DID_PATH if set.', required: true, env: 'DID_PATH' }), // Flag for specifying the node to use for resolving DIDs. kid: command_1.flags.string({ char: 'k', description: ' of the private key to use for signing.', default: 'key-1', required: false }), // Flag for indicating whether the newly created DID should be published to the ION network. detached: command_1.flags.boolean({ char: 's', description: 'flag indicating a payload-detached JWS should be output. Default is false.', default: false }), }; Sign.args = [ { name: 'payload', required: true, description: 'to sign', }, { name: 'friendlyName', required: true, description: 'of the DID to use to sign the payload', }, ];