From c24e2852755a34b1410bba72aa836ac12a9a872a Mon Sep 17 00:00:00 2001 From: David Dias Date: Sun, 6 Sep 2015 14:26:21 +0100 Subject: [PATCH] remove muxer refs --- README.md | 4 +-- package.json | 3 ++ tests/base-test.js | 80 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c2cb169..6edefc5 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/package.json b/package.json index 8f8e331..87a690f 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/tests/base-test.js b/tests/base-test.js index 49ea253..75ccfd9 100644 --- a/tests/base-test.js +++ b/tests/base-test.js @@ -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') }