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

chore: update to new multiformats #98

Merged
merged 7 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@
"it-pushable": "^1.4.2",
"libp2p-crypto": "^0.19.0",
"libp2p-tcp": "^0.15.3",
"multiaddr": "^9.0.1",
"multibase": "^4.0.2",
"multihashes": "^4.0.2",
"multiaddr": "^10.0.0",
"multiformats": "^9.0.2",
"p-defer": "^3.0.0",
"p-limit": "^3.1.0",
"p-wait-for": "^3.2.0",
"peer-id": "^0.14.2",
"peer-id": "^0.15.0",
"protobufjs": "^6.10.2",
"sinon": "^10.0.0",
"streaming-iterables": "^5.0.4",
Expand All @@ -86,7 +85,6 @@
"devDependencies": {
"@types/debug": "^4.1.5",
"aegir": "^33.0.0",
"cids": "^1.1.6",
"events": "^3.3.0",
"it-handshake": "^2.0.0",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/content-routing/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PeerId from 'peer-id'
import { Multiaddr } from 'multiaddr'
import CID from 'cids'
import { CID } from 'multiformats/cid'

export interface ContentRoutingFactory {
new (options?: any): ContentRouting;
Expand Down
4 changes: 2 additions & 2 deletions src/pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class PubsubBaseProtocol extends EventEmitter {
* Child class can override this.
*
* @param {InMessage} msg - the message object
* @returns {Uint8Array} message id as bytes
* @returns {Promise<Uint8Array> | Uint8Array} message id as bytes
*/
getMsgId (msg) {
const signaturePolicy = this.globalSignaturePolicy
Expand Down Expand Up @@ -618,7 +618,7 @@ class PubsubBaseProtocol extends EventEmitter {
case SignaturePolicy.StrictSign:
message.from = this.peerId.toB58String()
message.seqno = utils.randomSeqno()
return signMessage(this.peerId, utils.normalizeOutRpcMessage(message))
return signMessage(this.peerId, message)
case SignaturePolicy.StrictNoSign:
return Promise.resolve(message)
default:
Expand Down
35 changes: 28 additions & 7 deletions src/pubsub/message/rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ export namespace RPC {
constructor(p?: RPC.ISubOpts);

/** SubOpts subscribe. */
public subscribe: boolean;
public subscribe?: (boolean|null);

/** SubOpts topicID. */
public topicID: string;
public topicID?: (string|null);

/** SubOpts _subscribe. */
public _subscribe?: "subscribe";

/** SubOpts _topicID. */
public _topicID?: "topicID";

/**
* Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages.
Expand Down Expand Up @@ -163,22 +169,37 @@ export namespace RPC {
constructor(p?: RPC.IMessage);

/** Message from. */
public from: Uint8Array;
public from?: (Uint8Array|null);

/** Message data. */
public data: Uint8Array;
public data?: (Uint8Array|null);

/** Message seqno. */
public seqno: Uint8Array;
public seqno?: (Uint8Array|null);

/** Message topicIDs. */
public topicIDs: string[];

/** Message signature. */
public signature: Uint8Array;
public signature?: (Uint8Array|null);

/** Message key. */
public key: Uint8Array;
public key?: (Uint8Array|null);

/** Message _from. */
public _from?: "from";

/** Message _data. */
public _data?: "data";

/** Message _seqno. */
public _seqno?: "seqno";

/** Message _signature. */
public _signature?: "signature";

/** Message _key. */
public _key?: "key";

/**
* Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages.
Expand Down
166 changes: 111 additions & 55 deletions src/pubsub/message/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,44 @@ $root.RPC = (function() {

/**
* SubOpts subscribe.
* @member {boolean} subscribe
* @member {boolean|null|undefined} subscribe
* @memberof RPC.SubOpts
* @instance
*/
SubOpts.prototype.subscribe = false;
SubOpts.prototype.subscribe = null;

/**
* SubOpts topicID.
* @member {string} topicID
* @member {string|null|undefined} topicID
* @memberof RPC.SubOpts
* @instance
*/
SubOpts.prototype.topicID = "";
SubOpts.prototype.topicID = null;

// OneOf field names bound to virtual getters and setters
var $oneOfFields;

/**
* SubOpts _subscribe.
* @member {"subscribe"|undefined} _subscribe
* @memberof RPC.SubOpts
* @instance
*/
Object.defineProperty(SubOpts.prototype, "_subscribe", {
get: $util.oneOfGetter($oneOfFields = ["subscribe"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* SubOpts _topicID.
* @member {"topicID"|undefined} _topicID
* @memberof RPC.SubOpts
* @instance
*/
Object.defineProperty(SubOpts.prototype, "_topicID", {
get: $util.oneOfGetter($oneOfFields = ["topicID"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages.
Expand Down Expand Up @@ -315,15 +340,15 @@ $root.RPC = (function() {
if (!o)
o = {};
var d = {};
if (o.defaults) {
d.subscribe = false;
d.topicID = "";
}
if (m.subscribe != null && m.hasOwnProperty("subscribe")) {
d.subscribe = m.subscribe;
if (o.oneofs)
d._subscribe = "subscribe";
}
if (m.topicID != null && m.hasOwnProperty("topicID")) {
d.topicID = m.topicID;
if (o.oneofs)
d._topicID = "topicID";
}
return d;
};
Expand Down Expand Up @@ -374,27 +399,27 @@ $root.RPC = (function() {

/**
* Message from.
* @member {Uint8Array} from
* @member {Uint8Array|null|undefined} from
* @memberof RPC.Message
* @instance
*/
Message.prototype.from = $util.newBuffer([]);
Message.prototype.from = null;

/**
* Message data.
* @member {Uint8Array} data
* @member {Uint8Array|null|undefined} data
* @memberof RPC.Message
* @instance
*/
Message.prototype.data = $util.newBuffer([]);
Message.prototype.data = null;

/**
* Message seqno.
* @member {Uint8Array} seqno
* @member {Uint8Array|null|undefined} seqno
* @memberof RPC.Message
* @instance
*/
Message.prototype.seqno = $util.newBuffer([]);
Message.prototype.seqno = null;

/**
* Message topicIDs.
Expand All @@ -406,19 +431,77 @@ $root.RPC = (function() {

/**
* Message signature.
* @member {Uint8Array} signature
* @member {Uint8Array|null|undefined} signature
* @memberof RPC.Message
* @instance
*/
Message.prototype.signature = $util.newBuffer([]);
Message.prototype.signature = null;

/**
* Message key.
* @member {Uint8Array} key
* @member {Uint8Array|null|undefined} key
* @memberof RPC.Message
* @instance
*/
Message.prototype.key = null;

// OneOf field names bound to virtual getters and setters
var $oneOfFields;

/**
* Message _from.
* @member {"from"|undefined} _from
* @memberof RPC.Message
* @instance
*/
Object.defineProperty(Message.prototype, "_from", {
get: $util.oneOfGetter($oneOfFields = ["from"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Message _data.
* @member {"data"|undefined} _data
* @memberof RPC.Message
* @instance
*/
Object.defineProperty(Message.prototype, "_data", {
get: $util.oneOfGetter($oneOfFields = ["data"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Message _seqno.
* @member {"seqno"|undefined} _seqno
* @memberof RPC.Message
* @instance
*/
Object.defineProperty(Message.prototype, "_seqno", {
get: $util.oneOfGetter($oneOfFields = ["seqno"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Message _signature.
* @member {"signature"|undefined} _signature
* @memberof RPC.Message
* @instance
*/
Message.prototype.key = $util.newBuffer([]);
Object.defineProperty(Message.prototype, "_signature", {
get: $util.oneOfGetter($oneOfFields = ["signature"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Message _key.
* @member {"key"|undefined} _key
* @memberof RPC.Message
* @instance
*/
Object.defineProperty(Message.prototype, "_key", {
get: $util.oneOfGetter($oneOfFields = ["key"]),
set: $util.oneOfSetter($oneOfFields)
});

/**
* Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages.
Expand Down Expand Up @@ -564,51 +647,20 @@ $root.RPC = (function() {
if (o.arrays || o.defaults) {
d.topicIDs = [];
}
if (o.defaults) {
if (o.bytes === String)
d.from = "";
else {
d.from = [];
if (o.bytes !== Array)
d.from = $util.newBuffer(d.from);
}
if (o.bytes === String)
d.data = "";
else {
d.data = [];
if (o.bytes !== Array)
d.data = $util.newBuffer(d.data);
}
if (o.bytes === String)
d.seqno = "";
else {
d.seqno = [];
if (o.bytes !== Array)
d.seqno = $util.newBuffer(d.seqno);
}
if (o.bytes === String)
d.signature = "";
else {
d.signature = [];
if (o.bytes !== Array)
d.signature = $util.newBuffer(d.signature);
}
if (o.bytes === String)
d.key = "";
else {
d.key = [];
if (o.bytes !== Array)
d.key = $util.newBuffer(d.key);
}
}
if (m.from != null && m.hasOwnProperty("from")) {
d.from = o.bytes === String ? $util.base64.encode(m.from, 0, m.from.length) : o.bytes === Array ? Array.prototype.slice.call(m.from) : m.from;
if (o.oneofs)
d._from = "from";
}
if (m.data != null && m.hasOwnProperty("data")) {
d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data;
if (o.oneofs)
d._data = "data";
}
if (m.seqno != null && m.hasOwnProperty("seqno")) {
d.seqno = o.bytes === String ? $util.base64.encode(m.seqno, 0, m.seqno.length) : o.bytes === Array ? Array.prototype.slice.call(m.seqno) : m.seqno;
if (o.oneofs)
d._seqno = "seqno";
}
if (m.topicIDs && m.topicIDs.length) {
d.topicIDs = [];
Expand All @@ -618,9 +670,13 @@ $root.RPC = (function() {
}
if (m.signature != null && m.hasOwnProperty("signature")) {
d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature;
if (o.oneofs)
d._signature = "signature";
}
if (m.key != null && m.hasOwnProperty("key")) {
d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key;
if (o.oneofs)
d._key = "key";
}
return d;
};
Expand Down
Loading