Skip to content

extractSignature

Extract a signature from an object identified by its ID.

This method can be used for any object that may be signed, such as commits or tags.

Signature

ts
class Repository {
  extractSignature(oid: string): ExtractedSignature | null;
}

Parameters

  • oidrequired · string

    Object ID (SHA1) of the signed object to extract the signature from.

Returns

  • null | ExtractedSignature

    An ExtractedSignature object containing the signature and signed data if the object is signed,
    or null if the object is not signed.

    • signaturerequired · string

      GPG signature of the commit, or null if the commit is not signed.

    • signedDatarequired · string

      Signed data of the commit.

Examples

ts
import { openRepository } from 'es-git';

const repo = await openRepository('.');
const commit = repo.getCommit('a01e9888e46729ef4aa68953ba19b02a7a64eb82');

// Extract the signature from a commit
const signatureInfo = repo.extractSignature(commit.id());

if (signatureInfo) {
  console.log('Object is signed!');
  console.log('Signature:', signatureInfo.signature);
  console.log('Signed data:', signatureInfo.signedData);
} else {
  console.log('Object is not signed');
}

Released under the MIT License.