mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 21:42:21 +00:00
remove muxer refs
This commit is contained in:
parent
9d56ac50e1
commit
c24e285275
@ -28,12 +28,12 @@ Include this badge in your readme if you make a module that is compatible with t
|
||||
|
||||
```
|
||||
var tape = require('tape')
|
||||
var tests = require('abstract-stream-muxer/tests')
|
||||
var tests = require('abstract-record-store/tests')
|
||||
var YourRecordStore = require('../src')
|
||||
|
||||
var common = {
|
||||
setup: function (t, cb) {
|
||||
cb(null, YourStreamMuxer)
|
||||
cb(null, YourRecordStore)
|
||||
},
|
||||
teardown: function (t, cb) {
|
||||
cb()
|
||||
|
@ -19,6 +19,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/diasdavid/abstract-record-store",
|
||||
"dependencies": {
|
||||
"ecdsa": "^0.6.0",
|
||||
"ipld": "^0.1.3",
|
||||
"multihashing": "^0.1.3",
|
||||
"timed-tape": "^0.1.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,85 @@
|
||||
var crypto = require('crypto')
|
||||
var multihashing = require('multihashing')
|
||||
var ipld = require('ipld')
|
||||
var ecdsa = require('ecdsa')
|
||||
|
||||
module.exports.all = function (test, common) {
|
||||
|
||||
test('Store a valid record', function (t) {
|
||||
common.setup(test, function (err, recordStore) {
|
||||
t.ifError(err, 'Should not throw')
|
||||
t.pass('woo')
|
||||
|
||||
var mdagStore = recordStore.mdagStore
|
||||
|
||||
var ecdh = crypto.createECDH('secp256k1')
|
||||
ecdh.generateKeys()
|
||||
|
||||
var mdagObj_pubKey = {
|
||||
'@context': ipld.context.merkleweb,
|
||||
algorithm: {
|
||||
mlink: 'secp256k1'
|
||||
},
|
||||
encoding: {
|
||||
mlink: 'raw'
|
||||
},
|
||||
bytes: ecdh.getPublicKey()
|
||||
}
|
||||
|
||||
var mdagObj_pubKey_encoded = ipld.marshal(mdagObj_pubKey)
|
||||
var mdagObj_pubKey_mh = multihashing(mdagObj_pubKey_encoded, 'sha2-256')
|
||||
mdagStore.put(mdagObj_pubKey, mdagObj_pubKey_mh)
|
||||
|
||||
var current = new Date()
|
||||
|
||||
var mdagObj_record = {
|
||||
'@context': ipld.context.merkleweb,
|
||||
scheme: {
|
||||
mlink: 'type-a'
|
||||
},
|
||||
expires: (new Date()).setDate(current.getDate() + 1),
|
||||
value: 'aaah the data!'
|
||||
}
|
||||
|
||||
var mdagObj_record_encoded = ipld.marshal(mdagObj_record)
|
||||
var mdagObj_record_mh = multihashing(mdagObj_record_encoded, 'sha2-256')
|
||||
mdagStore.put(mdagObj_record, mdagObj_record_mh)
|
||||
|
||||
var mdagObj_record_encoded_hash = crypto.createHash('sha256').update(mdagObj_record_encoded).digest()
|
||||
var record_signed = ecdsa.sign(mdagObj_record_encoded_hash, ecdh.getPrivateKey())
|
||||
|
||||
var mdagObj_record_signature = {
|
||||
'@context': ipld.context.merkleweb,
|
||||
pubKey: {
|
||||
mlink: mdagObj_pubKey_mh
|
||||
},
|
||||
algorithm: {
|
||||
mlink: 'secp256k1'
|
||||
},
|
||||
encoding: {
|
||||
mlink: 'binary'
|
||||
},
|
||||
signee: {
|
||||
mlink: mdagObj_record_mh
|
||||
},
|
||||
bytes: record_signed
|
||||
}
|
||||
|
||||
var mdagObj_record_signature_encoded = ipld.marshal(mdagObj_record_signature)
|
||||
var mdagObj_record_signature_encoded_mh = multihashing(mdagObj_record_signature_encoded, 'sha2-256')
|
||||
|
||||
mdagStore.put(mdagObj_record_signature, mdagObj_record_signature_encoded_mh)
|
||||
|
||||
recordStore.put('bananas', mdagObj_record_signature, function (err) {
|
||||
t.ifError(err, 'Should not throw')
|
||||
t.pass('record was stored successfully')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('Store an unvalid record')
|
||||
test('Store and retrieve a valid record')
|
||||
test('Store a bunch of valid and unvalid records and check what gets retrieved')
|
||||
test('Store a bunch of records with variable validity, wait for some to expire, check what gets retrieved')
|
||||
// test('Store an unvalid record')
|
||||
// test('Store and retrieve a valid record')
|
||||
// test('Store a bunch of valid and unvalid records and check what gets retrieved')
|
||||
// test('Store a bunch of records with variable validity, wait for some to expire, check what gets retrieved')
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user