https://github.com/tradle/chained-obj
json, json+multipart object building/parsing
https://github.com/tradle/chained-obj
Last synced: about 2 months ago
JSON representation
json, json+multipart object building/parsing
- Host: GitHub
- URL: https://github.com/tradle/chained-obj
- Owner: tradle
- License: mit
- Created: 2015-04-07T22:00:38.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-04-17T21:08:03.000Z (about 10 years ago)
- Last Synced: 2025-11-23T15:13:50.735Z (7 months ago)
- Language: JavaScript
- Size: 61.5 KB
- Stars: 2
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# chained-obj
Builder and parser for objects stored by [Tradle](https://github.com/tradle/about/wiki) on chain. Currently uses multipart to store arbitrary JSON data + attachments. These objects are later encrypted and put on-chain.
_this module is used by [Tradle](https://github.com/tradle/about/wiki)_
# Usage
```js
var ChainedObj = require('chained-obj')
var Builder = ChainedObj.Builder
var Parser = ChainedObj.Parser
var b = new Builder()
// required
.data({
some: 'json'
})
// optional
.attach([
{ name: 'headshot', path: './path/to/attachment1' },
{ name: 'passport', path: './path/to/attachment2' }
])
// optional
.signWith(key) // a key from [kiki](https://npmjs.org/package/kiki) or a key conforming to its API
.build(function (err, result) {
// result consists of the form and the multipart boundary used
// {
// form: Buffer,
// boundary: String
// }
})
var p = new Parser()
// optional
.verifyWith(key) // a key from [kiki](https://npmjs.org/package/kiki) or a key
.parse(formBuf, function (err, parsed) {
// parsed consists of the data and attachments
// {
// data: Buffer,
// attachments: [
// {
// name: String,
// path: String,
// contentType: String
// }
// ]
// }
})
```