Coder Social home page Coder Social logo

msign-example's Introduction

MSign-Example

Assuming you have been through the circles of bureaucratic hell and you got your certificates here is an example how to integrate Msign service in our app.

If you are on start of your journey here is official guide what docs you need(https://mpass.gov.md/info/procedure). After that you can come back soo lets gooooo

MSign uses a SOAP server, you will need to create a SOAP client to access WSDL methods. To have access you will need to create a secure connection with the certs.

const client = await createClientAsync(WSDL_URL, {
  wsdl_options: {
    httpsAgent: new https.Agent({
      keepAlive: true,
      cert: this.pkiCert,
      key: this.privateKey,
    }),
  },
});

client.setSecurity(new ClientSSLSecurity(this.privateKey, this.pkiCert, {}));

With client.describe() you can explore what methods there are. What inputs and outputs for each method.

Sign documents

First at all the sign method only works with PDF and XML format. The request object thats bellow, its a example of the input request for the PostSignRequestAsync method. Also you can add multiple files to sign.

const request = {
  ContentType: 'Pdf',
  Contents: {
    SignContent: [
      {
        Content: Buffer,
      },
      {
        Content: Buffer,
      },
    ],
  },
  ShortContentDescription: 'Cerere',
};

const [result] = await client.PostSignRequestAsync({ request });

As the output you will get an id that you can use as parameter to msign webpage https://msign.staging.egov.md/${id}

{
  "success": true,
  "payload": "ac898a847610443281efb04400efce7c",
  "message": "OK"
}

The url have some additional query parameters that can be add optionally

ReturnUrl - The URL that will receive the result of transaction signing RelayState - Optional string that will be returned back unmodified after signing lang - Language to be used by MSign user interface.

Sign

Sign status

To get the state of the signing process you need to provide as input the id.

const request = {
  requestID: id,
};
const [result] = await client.GetSignResponseAsync(request);

The output of this function have 4 states: Pending | Success | Failure | Expired.

{
  "success": true,
  "payload": "Pending",
  "message": "OK"
}

Verify Sign

With this method you can input a PDF or XML as content to verify if the sign is valid.

const request = {
  Contents: {
    VerificationContent: [{ Content: Buffer }, { Signature: Buffer }],
  },
  SignedContentType: 'Pdf',
};

const [result] = await client.VerifySignaturesAsync({ request });

As the output you get information about when, by who and if the sign is valid.

{
  "success": true,
  "payload": [
    {
      "Certificates": {
        "VerificationCertificate": [
          {
            "Certificate": "Public certificate",
            "SignatureValid": true,
            "SignedAt": "2023-07-13T11:05:51.000Z",
            "Subject": "Info about who sign the document"
          }
        ]
      },
      "Message": "Semnătura este validă",
      "SignaturesValid": true
    },
    {
      "Message": "Semnătura nu este validă",
      "SignaturesValid": false
    }
  ],
  "message": "OK"
}

To do

How to download files that where sign Generate a pdf file Upload file to sign

Shout-out

A great library with a good documentation saved my life - node-soap

Big W for the instruments and services that eGov have achieved this years - eGov official page

msign-example's People

Contributors

zgurea1 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.