0.7.3 • Published 6 days ago

@bicycle-codes/message v0.7.3

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
6 days ago

message

tests Socket Badge types module license

Create and verify signed messages with Fission crypto libraries.

install

npm i -S @bicycle-codes/message

example

create a message

import { create } from '@bicycle-codes/message'

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

The returned object has a format like

{
    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).

import { test } from '@nichoth/tapzero'
import { create } from '@bicycle-codes/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

import { test } from '@nichoth/tapzero'
import { verify } from '@bicycle-codes/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')
})
0.7.3

6 days ago

0.7.2

2 months ago

0.7.0

3 months ago

0.6.1

3 months ago