Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: use regular protocol-buffers until protobufjs is fixed (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias authored Sep 6, 2017
1 parent 83257bc commit 957fdd3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 518 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"libp2p-crypto-secp256k1": "~0.2.2",
"multihashing-async": "~0.4.6",
"pem-jwk": "^1.5.1",
"protobufjs": "^6.8.0",
"protocol-buffers": "^3.2.1",
"rsa-pem-to-jwk": "^1.1.3",
"tweetnacl": "^1.0.0",
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#master"
Expand Down
10 changes: 4 additions & 6 deletions src/keys/ed25519-class.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

const multihashing = require('multihashing-async')
const protobuf = require('protocol-buffers')

const crypto = require('./ed25519')
const pbm = require('./keys.proto.js')
const pbm = protobuf(require('./keys.proto'))

class Ed25519PublicKey {
constructor (key) {
Expand All @@ -20,11 +21,10 @@ class Ed25519PublicKey {
}

get bytes () {
const msg = pbm.PublicKey.create({
return pbm.PublicKey.encode({
Type: pbm.KeyType.Ed25519,
Data: this.marshal()
})
return Buffer.from(pbm.PublicKey.encode(msg).finish())
}

equals (key) {
Expand Down Expand Up @@ -63,12 +63,10 @@ class Ed25519PrivateKey {
}

get bytes () {
const msg = pbm.PrivateKey.create({
return pbm.PrivateKey.encode({
Type: pbm.KeyType.Ed25519,
Data: this.marshal()
})

return Buffer.from(pbm.PrivateKey.encode(msg).finish())
}

equals (key) {
Expand Down
7 changes: 4 additions & 3 deletions src/keys/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const keysPBM = require('./keys.proto.js')
const protobuf = require('protocol-buffers')
const keysPBM = protobuf(require('./keys.proto'))

exports = module.exports

Expand Down Expand Up @@ -49,7 +50,7 @@ exports.generateKeyPairFromSeed = (type, seed, bits, cb) => {
// representative object
exports.unmarshalPublicKey = (buf) => {
const decoded = keysPBM.PublicKey.decode(buf)
const data = Buffer.from(decoded.Data)
const data = decoded.Data

switch (decoded.Type) {
case keysPBM.KeyType.RSA:
Expand Down Expand Up @@ -81,7 +82,7 @@ exports.marshalPublicKey = (key, type) => {
// representative object
exports.unmarshalPrivateKey = (buf, callback) => {
const decoded = keysPBM.PrivateKey.decode(buf)
const data = Buffer.from(decoded.Data)
const data = decoded.Data

switch (decoded.Type) {
case keysPBM.KeyType.RSA:
Expand Down
15 changes: 0 additions & 15 deletions src/keys/keys.proto

This file was deleted.

Loading

0 comments on commit 957fdd3

Please sign in to comment.