Skip to content

extractSignature

Extract the signature from a signed Git object (commit, tag, etc.).

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

  • ExtractedSignature | null

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

    • signaturestring

      GPG signature of the Git object.

    • signedDatastring

      Signed data of the Git object.

Example

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.