0.9.1 • Published 10 months ago

@bicycle-codes/message v0.9.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
10 months ago

message

tests Socket Badge types module install size license

Create and verify signed messages with the webcrypto API.

Contents

install

npm i -S @bicycle-codes/message

example

create a message

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

const alicesKeys = await Keys.create()
const req = await create(alicesKeys, { hello: 'world' })

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 '@substrate-system/tapzero'
import { Keys } from '@bicycle-codes/keys'
import { create } from '@bicycle-codes/message'

let req:SignedMessage<{ hello: 'world' }>
const alicesKeys = await Keys.create()
test('create a message', async t => {
    req = await create(alicesKeys, { hello: 'world' })

    t.ok(req, 'request 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.hello, 'world', '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.8.4

10 months ago

0.9.0

10 months ago

0.9.1

10 months ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.7.3

2 years ago

0.7.2

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago