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) 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const cli_ux_1 = require("cli-ux"); const jsonpath_1 = require("jsonpath"); const ION = require('@decentralized-identity/ion-tools'); class Verify extends command_1.Command { async run() { var _a; const { args, flags } = this.parse(Verify); // Load the DID document into an ION DID const document = JSON.parse(args.document); // If a kid has been provided attempt to get the matching key // from the DID document, throwing if not found. If no kid // specified get the first key from the document. // QUESTION: Should we parse the jws and see if a kid is specified in the header. let publicKeyJwk; const keyIdentifier = (_a = flags.kid) !== null && _a !== void 0 ? _a : jsonpath_1.value(document, '$..authentication[0]'); publicKeyJwk = jsonpath_1.value(document, `$..verificationMethod[?(@.id=="${keyIdentifier}")].publicKeyJwk`); if (!publicKeyJwk) { throw new Error(`The specified DID document does not have a public key with id '${keyIdentifier}' that can be used for verifying the signature.`); } // Create the ION did instance cli_ux_1.default.action.start('Verifying payload.'); const verifiedPayload = await ION.verifyJws({ jws: args.jws, publicJwk: publicKeyJwk, payload: args.payload, }); this.log(verifiedPayload); cli_ux_1.default.action.stop(); this.exit(); } } exports.default = Verify; Verify.description = 'Verify payload using the private key associated with the specified DID.'; Verify.examples = [ '$ ion verify \'2tleS0xIiwiYWxnIjoiRVMyNTZLIn0..D7kXXnQmtSw1WX1RCW3IzA6T5-qivSOL2_6RVydIo1Z_wXKO00GEUl2xjwvRpHlr4B7jBy1_PZenCNP9_mWx1Q\' \'{ESCAPED DID DOCUMENT}\' \'hello world\' -k \'#key-1\'', ]; Verify.flags = { help: command_1.flags.help({ char: 'h' }), // Flag indicating the public key identifier to use. kid: command_1.flags.string({ description: ' identifier of the public key to use for verifying.', required: false }), }; Verify.args = [ { name: 'jws', required: true, description: 'signature to verify.', }, { name: 'document', required: true, description: 'the escaped DID document of the entity that signed the payload.', }, { name: 'payload', required: false, description: 'when verifying a payload-detached JWS', }, ];