# Assinatura via Push

## Ambientes

* Develop: <https://apicloudid.dev.vaultid.com.br>
* Homologação Bird: <https://apihom.birdid.com.br>
* Homologação Vault: <https://apicloudid.hom.vaultid.com.br>
* Produção Bird: <https://api.birdid.com.br>
* Produção Vault: <https://apicloudid.vaultid.com.br>

## API

### Solicitação da assinatura

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/async-signature`&#x20;

#### Permissão

A aplicação (client\_id) deve possuir a permissão de **assinatura por notificação** que é configurado pela corporação no Wings.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |

#### Request Body

| Name              | Type           | Description                                                                                                                                                                      |
| ----------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| client\_id        | string         | Deve ter a identificação da aplicação.                                                                                                                                           |
| client\_secret    | string         | Deve ter a senha da aplicação.                                                                                                                                                   |
| username          | string         | Identificação do usuário por meio de CPF ou CNPJ.                                                                                                                                |
| message           | string         | Mensagem a ser apresentada no app solicitando a assinatura.                                                                                                                      |
| hashes            | array\[string] | Lista com os conteúdos a serem assinados.                                                                                                                                        |
| callback\_url     | string         | Url de webhook para recebimento da notificação de assinatura.                                                                                                                    |
| signature\_format | string         | <ul><li>RAW: Assinatura PKCS#1 v1.5, resultado direto da operação RSA/DSA sobre o hash;</li><li>CMS: Assinatura CMS-detached utilizando o hash no campo messageDigest.</li></ul> |
| lifetime          | integer        | Tempo de vida desejado para o token a ser gerado em segundos. Para pessoas físicas não deve ultrapassar (7 dias), e para pessoas jurídicas este limite será de (30 dias).        |

#### Exemplo de requisição

```sh
curl --location '{{BASE_URL}}/async-signature' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
    "username": "{{USERNAME}}",
    "client_id": "{{CLIENT_ID}}",
    "client_secret": "{{CLIENT_SECRET}}",
    "message": "Por favor, assine isso!",
    "hashes": ["ed0b5acaf193ccc109d0c6e5bd3bb1ae8220e8850017bf29b38187026e572cc2"],
    "callback_url": "https://webhook-demo.lab.vaultid.com.br/webhook/YXV0aC1wdXNo",
    "signature_format": "CMS",
    "lifetime": 3600
}'
```

#### Response Body

| Name         | Type    | Description                                                   |
| ------------ | ------- | ------------------------------------------------------------- |
| client\_name | string  | Nome aplicação do client\_id informado.                       |
| token        | string  | Token a ser utilizado para solicitação do conteúdo assinado.  |
| environment  | string  | Identificador do ambiente em que será realizada a assinatura. |
| ttl          | integer | Tempo de vida em segundos do processo de assinatura.          |

{% tabs %}
{% tab title="201 " %}

```json
{
    "client_name": "Minha Aplicação",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3Njk1MTgzMTcsImV4cCI6MTc2OTUyMTkxN30.bGvn2CIaz53cAgFWDv02skEjtCGGWusYrub2c4Whv28",
    "environment": "bird_stg",
    "ttl": 3600
}
```

{% endtab %}
{% endtabs %}

### Recebimento do callback

Após a confirmação da assinatura. O sistema realiza a chamada de callback para a url informada no `callback_url` pelo método `POST` enviando o token de acesso ao conteúdo da assinatura.

<mark style="color:green;">`POST`</mark> `{{CALLBACK_URL}}`

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |

#### Request Body

| Name  | Type   | Description                                                  |
| ----- | ------ | ------------------------------------------------------------ |
| token | string | Token a ser utilizado para solicitação do conteúdo assinado. |

```sh
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3Njk1MTgzMTcsImV4cCI6MTc2OTUyMTkxN30.bGvn2CIaz53cAgFWDv02skEjtCGGWusYrub2c4Whv28"
}
```

### Obtenção da assinatura

Esse endpoint é responsável por retornar o conteúdo das assinaturas dos hashes informados no início.

<mark style="color:green;">`GET`</mark> `{{BASE_URL}}/async-signature`

#### Headers

| Name          | Type   | Description                                           |
| ------------- | ------ | ----------------------------------------------------- |
| Content-Type  | string | application/json                                      |
| Authorization | string | Bearer token (recebido na solicitação ou no callback) |

```sh
curl --location '{{BASE_URL}}/async-signature' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token'
```

#### Response Body

| Name            | Type           | Description                           |
| --------------- | -------------- | ------------------------------------- |
| raw\_signatures | array\[string] | Lista com o conteúdo das assinaturas. |

{% tabs %}
{% tab title="200" %}

```json
{
    "rawSignatures": [
        "-----BEGIN PKCS7-----\nMIIK...3Cg==\n-----END PKCS7-----\n"
    ]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.vaultid.com.br/workspace/cloud/api/uso-de-certificado/assinatura-via-push.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
