# @ssc-half-light/message

> Create and verify signed messages

Latest version **0.6.1** (published 2024-01-16) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @ssc-half-light/message
pnpm add @ssc-half-light/message
yarn add @ssc-half-light/message
bun add @ssc-half-light/message
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2024-01-16 |
| First published | 2023-09-27 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | nichoth |
| Maintainers | nichoth |
| Keywords | message |

## Links

- npm: https://www.npmjs.com/package/@ssc-half-light/message
- Repository: https://github.com/ssc-half-light/message
- Homepage: https://github.com/ssc-half-light/message#readme
- Issues: https://github.com/ssc-half-light/message/issues
- npm.io page: https://npm.io/package/@ssc-half-light/message

## Dependencies (2)

- [json-canon](https://npm.io/package/json-canon.md) ^1.0.1
- [@ssc-half-light/util](https://npm.io/package/@ssc-half-light/util.md) ^0.10.3

## Recent versions

- 0.6.1 (latest) — 2024-01-16
- 0.6.0 — 2024-01-16
- 0.5.20 — 2023-12-12
- 0.5.19 — 2023-12-10
- 0.5.17 — 2023-12-10
- 0.5.15 — 2023-12-10
- 0.5.14 — 2023-12-02
- 0.5.13 — 2023-12-02
- 0.5.12 — 2023-10-24
- 0.5.11 — 2023-10-23
- 0.5.10 — 2023-10-23
- 0.5.9 — 2023-10-12
- 0.5.8 — 2023-10-09
- 0.5.4 — 2023-09-27

## README

# message

![tests](https://github.com/ssc-half-light/message/actions/workflows/nodejs.yml/badge.svg)
[![Socket Badge](https://socket.dev/api/badge/npm/package/@ssc-half-light/message)](https://socket.dev/npm/package/@ssc-half-light/message)
[![module](https://img.shields.io/badge/module-ESM%2FCJS-blue)](README.md)
[![license](https://img.shields.io/badge/license-PolyForm%20Shield-fc9662)](LICENSE)

Create and verify signed messages with [Fission](https://github.com/oddsdk/ts-odd) libraries.

## install

```sh
npm i @ssc-half-light/message
```

## example

### create a message
```js
import { create } from '@ssc-half-light/message'

// const { crypto } = program.components
await create(crypto, { type: 'test', value: 'wooo' })
```

The returned object has a format like
```js
{
    author: 'did:key:...',
    signature: '123abc',
    ...message
}
```

> [!NOTE]  
> the message will have the fields `author` and `signature` appended to it. `author` is the DID that was used to sign this message. It is read by `verify(message)`.

```js
import { test } from '@nichoth/tapzero'
import { create } from '@ssc-half-light/message'

let req
test('create message', async t => {
    // program is from
    // const program = await odd.program({
    //   ...config
    // })
    const { crypto } = program.components

    req = await create(crypto, { type: 'test', value: 'wooo' })
    t.ok(req, 'message was created')
    t.equal(typeof req.signature, 'string', 'should have a signature')
    t.ok(req.author.includes, 'did:key:', 'should have an author field')
    t.equal(req.type, 'test', 'should have the properties we passed in')
})
```

### verify a message
```js
import { test } from '@nichoth/tapzero'
import { verify } from '@ssc-half-light/message'

test('verify a message', async t => {
    // `req` is the message we created above
    const isOk = await verify(req)
    t.equal(isOk, true, 'should return true for a valid message')
})
```

---
_Source: https://npm.io/package/@ssc-half-light/message · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
