@libp2p/record 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -14
- package/dist/src/index.js.map +1 -1
- package/dist/src/record.d.ts +10 -69
- package/dist/src/record.d.ts.map +1 -0
- package/dist/src/record.js +17 -199
- package/dist/src/record.js.map +1 -0
- package/dist/src/selectors.d.ts +1 -10
- package/dist/src/selectors.d.ts.map +1 -1
- package/dist/src/selectors.js +5 -5
- package/dist/src/selectors.js.map +1 -1
- package/dist/src/validators.d.ts +1 -6
- package/dist/src/validators.d.ts.map +1 -1
- package/dist/src/validators.js +8 -12
- package/dist/src/validators.js.map +1 -1
- package/package.json +17 -18
- package/src/index.ts +10 -18
- package/src/record.ts +29 -0
- package/src/selectors.ts +6 -6
- package/src/validators.ts +9 -14
- package/dist/src/record.proto +0 -20
- package/src/record.d.ts +0 -71
- package/src/record.js +0 -202
package/dist/src/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Record } from './record.js';
|
|
2
2
|
export declare class Libp2pRecord {
|
|
3
3
|
key: Uint8Array;
|
|
4
4
|
value: Uint8Array;
|
|
5
|
-
timeReceived
|
|
6
|
-
constructor(key: Uint8Array, value: Uint8Array, timeReceived
|
|
5
|
+
timeReceived: Date;
|
|
6
|
+
constructor(key: Uint8Array, value: Uint8Array, timeReceived: Date);
|
|
7
7
|
serialize(): Uint8Array;
|
|
8
8
|
/**
|
|
9
9
|
* Return the object format ready to be given to the protobuf library.
|
|
@@ -11,7 +11,7 @@ export declare class Libp2pRecord {
|
|
|
11
11
|
prepareSerialize(): {
|
|
12
12
|
key: Uint8Array;
|
|
13
13
|
value: Uint8Array;
|
|
14
|
-
timeReceived: string
|
|
14
|
+
timeReceived: string;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Decode a protobuf encoded record
|
|
@@ -20,6 +20,6 @@ export declare class Libp2pRecord {
|
|
|
20
20
|
/**
|
|
21
21
|
* Create a record from the raw object returned from the protobuf library
|
|
22
22
|
*/
|
|
23
|
-
static fromDeserialized(obj:
|
|
23
|
+
static fromDeserialized(obj: Record): Libp2pRecord;
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACP,MAAM,aAAa,CAAA;AAGpB,qBAAa,YAAY;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,IAAI,CAAA;gBAEZ,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI;IAcnE,SAAS;IAIT;;OAEG;IACH,gBAAgB;;;;;IAQhB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAE,GAAG,EAAE,UAAU;IAMnC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAE,GAAG,EAAE,MAAM;CAiBrC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Record
|
|
1
|
+
import { Record } from './record.js';
|
|
2
2
|
import * as utils from './utils.js';
|
|
3
3
|
export class Libp2pRecord {
|
|
4
4
|
constructor(key, value, timeReceived) {
|
|
@@ -13,7 +13,7 @@ export class Libp2pRecord {
|
|
|
13
13
|
this.timeReceived = timeReceived;
|
|
14
14
|
}
|
|
15
15
|
serialize() {
|
|
16
|
-
return
|
|
16
|
+
return Record.encode(this.prepareSerialize());
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Return the object format ready to be given to the protobuf library.
|
|
@@ -22,29 +22,21 @@ export class Libp2pRecord {
|
|
|
22
22
|
return {
|
|
23
23
|
key: this.key,
|
|
24
24
|
value: this.value,
|
|
25
|
-
timeReceived:
|
|
25
|
+
timeReceived: utils.toRFC3339(this.timeReceived)
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Decode a protobuf encoded record
|
|
30
30
|
*/
|
|
31
31
|
static deserialize(raw) {
|
|
32
|
-
const
|
|
33
|
-
return Libp2pRecord
|
|
34
|
-
defaults: false,
|
|
35
|
-
arrays: true,
|
|
36
|
-
longs: Number,
|
|
37
|
-
objects: false
|
|
38
|
-
}));
|
|
32
|
+
const rec = Record.decode(raw);
|
|
33
|
+
return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived));
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
36
|
* Create a record from the raw object returned from the protobuf library
|
|
42
37
|
*/
|
|
43
38
|
static fromDeserialized(obj) {
|
|
44
|
-
|
|
45
|
-
if (obj.timeReceived != null) {
|
|
46
|
-
recvtime = utils.parseRFC3339(obj.timeReceived);
|
|
47
|
-
}
|
|
39
|
+
const recvtime = utils.parseRFC3339(obj.timeReceived);
|
|
48
40
|
if (obj.key == null) {
|
|
49
41
|
throw new Error('key missing from deserialized object');
|
|
50
42
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACP,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,MAAM,OAAO,YAAY;IAKvB,YAAa,GAAe,EAAE,KAAiB,EAAE,YAAkB;QACjE,IAAI,CAAC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AED,MAAM,GAAG,GAAG,IAAI,YAAY,CAC1B,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,QAAQ,CAC7B,CAAA;QAED,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
|
package/dist/src/record.d.ts
CHANGED
|
@@ -1,71 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
key?: (Uint8Array|null);
|
|
7
|
-
|
|
8
|
-
/** Record value */
|
|
9
|
-
value?: (Uint8Array|null);
|
|
10
|
-
|
|
11
|
-
/** Record timeReceived */
|
|
12
|
-
timeReceived?: (string|null);
|
|
1
|
+
import type { Codec } from 'protons-runtime';
|
|
2
|
+
export interface Record {
|
|
3
|
+
key: Uint8Array;
|
|
4
|
+
value: Uint8Array;
|
|
5
|
+
timeReceived: string;
|
|
13
6
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Constructs a new Record.
|
|
20
|
-
* @param [p] Properties to set
|
|
21
|
-
*/
|
|
22
|
-
constructor(p?: IRecord);
|
|
23
|
-
|
|
24
|
-
/** Record key. */
|
|
25
|
-
public key: Uint8Array;
|
|
26
|
-
|
|
27
|
-
/** Record value. */
|
|
28
|
-
public value: Uint8Array;
|
|
29
|
-
|
|
30
|
-
/** Record timeReceived. */
|
|
31
|
-
public timeReceived: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
|
|
35
|
-
* @param m Record message or plain object to encode
|
|
36
|
-
* @param [w] Writer to encode to
|
|
37
|
-
* @returns Writer
|
|
38
|
-
*/
|
|
39
|
-
public static encode(m: IRecord, w?: $protobuf.Writer): $protobuf.Writer;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Decodes a Record message from the specified reader or buffer.
|
|
43
|
-
* @param r Reader or buffer to decode from
|
|
44
|
-
* @param [l] Message length if known beforehand
|
|
45
|
-
* @returns Record
|
|
46
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
47
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
48
|
-
*/
|
|
49
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Record;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Creates a Record message from a plain object. Also converts values to their respective internal types.
|
|
53
|
-
* @param d Plain object
|
|
54
|
-
* @returns Record
|
|
55
|
-
*/
|
|
56
|
-
public static fromObject(d: { [k: string]: any }): Record;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a plain object from a Record message. Also converts values to other types if specified.
|
|
60
|
-
* @param m Record
|
|
61
|
-
* @param [o] Conversion options
|
|
62
|
-
* @returns Plain object
|
|
63
|
-
*/
|
|
64
|
-
public static toObject(m: Record, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Converts this Record to JSON.
|
|
68
|
-
* @returns JSON object
|
|
69
|
-
*/
|
|
70
|
-
public toJSON(): { [k: string]: any };
|
|
7
|
+
export declare namespace Record {
|
|
8
|
+
const codec: () => Codec<Record>;
|
|
9
|
+
const encode: (obj: Record) => Uint8Array;
|
|
10
|
+
const decode: (buf: Uint8Array) => Record;
|
|
71
11
|
}
|
|
12
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,yBAAiB,MAAM,CAAC;IACf,MAAM,KAAK,QAAO,MAAM,MAAM,CAMpC,CAAA;IAEM,MAAM,MAAM,QAAS,MAAM,KAAG,UAEpC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,MAExC,CAAA;CACF"}
|
package/dist/src/record.js
CHANGED
|
@@ -1,202 +1,20 @@
|
|
|
1
|
-
/*eslint-disable*/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Properties of a Record.
|
|
14
|
-
* @exports IRecord
|
|
15
|
-
* @interface IRecord
|
|
16
|
-
* @property {Uint8Array|null} [key] Record key
|
|
17
|
-
* @property {Uint8Array|null} [value] Record value
|
|
18
|
-
* @property {string|null} [timeReceived] Record timeReceived
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new Record.
|
|
23
|
-
* @exports Record
|
|
24
|
-
* @classdesc Represents a Record.
|
|
25
|
-
* @implements IRecord
|
|
26
|
-
* @constructor
|
|
27
|
-
* @param {IRecord=} [p] Properties to set
|
|
28
|
-
*/
|
|
29
|
-
function Record(p) {
|
|
30
|
-
if (p)
|
|
31
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
32
|
-
if (p[ks[i]] != null)
|
|
33
|
-
this[ks[i]] = p[ks[i]];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Record key.
|
|
38
|
-
* @member {Uint8Array} key
|
|
39
|
-
* @memberof Record
|
|
40
|
-
* @instance
|
|
41
|
-
*/
|
|
42
|
-
Record.prototype.key = $util.newBuffer([]);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Record value.
|
|
46
|
-
* @member {Uint8Array} value
|
|
47
|
-
* @memberof Record
|
|
48
|
-
* @instance
|
|
49
|
-
*/
|
|
50
|
-
Record.prototype.value = $util.newBuffer([]);
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Record timeReceived.
|
|
54
|
-
* @member {string} timeReceived
|
|
55
|
-
* @memberof Record
|
|
56
|
-
* @instance
|
|
57
|
-
*/
|
|
58
|
-
Record.prototype.timeReceived = "";
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
|
|
62
|
-
* @function encode
|
|
63
|
-
* @memberof Record
|
|
64
|
-
* @static
|
|
65
|
-
* @param {IRecord} m Record message or plain object to encode
|
|
66
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
67
|
-
* @returns {$protobuf.Writer} Writer
|
|
68
|
-
*/
|
|
69
|
-
Record.encode = function encode(m, w) {
|
|
70
|
-
if (!w)
|
|
71
|
-
w = $Writer.create();
|
|
72
|
-
if (m.key != null && Object.hasOwnProperty.call(m, "key"))
|
|
73
|
-
w.uint32(10).bytes(m.key);
|
|
74
|
-
if (m.value != null && Object.hasOwnProperty.call(m, "value"))
|
|
75
|
-
w.uint32(18).bytes(m.value);
|
|
76
|
-
if (m.timeReceived != null && Object.hasOwnProperty.call(m, "timeReceived"))
|
|
77
|
-
w.uint32(42).string(m.timeReceived);
|
|
78
|
-
return w;
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
import { encodeMessage, decodeMessage, message, bytes, string } from 'protons-runtime';
|
|
4
|
+
export var Record;
|
|
5
|
+
(function (Record) {
|
|
6
|
+
Record.codec = () => {
|
|
7
|
+
return message({
|
|
8
|
+
1: { name: 'key', codec: bytes },
|
|
9
|
+
2: { name: 'value', codec: bytes },
|
|
10
|
+
5: { name: 'timeReceived', codec: string }
|
|
11
|
+
});
|
|
79
12
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* Decodes a Record message from the specified reader or buffer.
|
|
83
|
-
* @function decode
|
|
84
|
-
* @memberof Record
|
|
85
|
-
* @static
|
|
86
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
87
|
-
* @param {number} [l] Message length if known beforehand
|
|
88
|
-
* @returns {Record} Record
|
|
89
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
90
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
91
|
-
*/
|
|
92
|
-
Record.decode = function decode(r, l) {
|
|
93
|
-
if (!(r instanceof $Reader))
|
|
94
|
-
r = $Reader.create(r);
|
|
95
|
-
var c = l === undefined ? r.len : r.pos + l, m = new $root.Record();
|
|
96
|
-
while (r.pos < c) {
|
|
97
|
-
var t = r.uint32();
|
|
98
|
-
switch (t >>> 3) {
|
|
99
|
-
case 1:
|
|
100
|
-
m.key = r.bytes();
|
|
101
|
-
break;
|
|
102
|
-
case 2:
|
|
103
|
-
m.value = r.bytes();
|
|
104
|
-
break;
|
|
105
|
-
case 5:
|
|
106
|
-
m.timeReceived = r.string();
|
|
107
|
-
break;
|
|
108
|
-
default:
|
|
109
|
-
r.skipType(t & 7);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return m;
|
|
13
|
+
Record.encode = (obj) => {
|
|
14
|
+
return encodeMessage(obj, Record.codec());
|
|
114
15
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
* Creates a Record message from a plain object. Also converts values to their respective internal types.
|
|
118
|
-
* @function fromObject
|
|
119
|
-
* @memberof Record
|
|
120
|
-
* @static
|
|
121
|
-
* @param {Object.<string,*>} d Plain object
|
|
122
|
-
* @returns {Record} Record
|
|
123
|
-
*/
|
|
124
|
-
Record.fromObject = function fromObject(d) {
|
|
125
|
-
if (d instanceof $root.Record)
|
|
126
|
-
return d;
|
|
127
|
-
var m = new $root.Record();
|
|
128
|
-
if (d.key != null) {
|
|
129
|
-
if (typeof d.key === "string")
|
|
130
|
-
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0);
|
|
131
|
-
else if (d.key.length)
|
|
132
|
-
m.key = d.key;
|
|
133
|
-
}
|
|
134
|
-
if (d.value != null) {
|
|
135
|
-
if (typeof d.value === "string")
|
|
136
|
-
$util.base64.decode(d.value, m.value = $util.newBuffer($util.base64.length(d.value)), 0);
|
|
137
|
-
else if (d.value.length)
|
|
138
|
-
m.value = d.value;
|
|
139
|
-
}
|
|
140
|
-
if (d.timeReceived != null) {
|
|
141
|
-
m.timeReceived = String(d.timeReceived);
|
|
142
|
-
}
|
|
143
|
-
return m;
|
|
16
|
+
Record.decode = (buf) => {
|
|
17
|
+
return decodeMessage(buf, Record.codec());
|
|
144
18
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* Creates a plain object from a Record message. Also converts values to other types if specified.
|
|
148
|
-
* @function toObject
|
|
149
|
-
* @memberof Record
|
|
150
|
-
* @static
|
|
151
|
-
* @param {Record} m Record
|
|
152
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
153
|
-
* @returns {Object.<string,*>} Plain object
|
|
154
|
-
*/
|
|
155
|
-
Record.toObject = function toObject(m, o) {
|
|
156
|
-
if (!o)
|
|
157
|
-
o = {};
|
|
158
|
-
var d = {};
|
|
159
|
-
if (o.defaults) {
|
|
160
|
-
if (o.bytes === String)
|
|
161
|
-
d.key = "";
|
|
162
|
-
else {
|
|
163
|
-
d.key = [];
|
|
164
|
-
if (o.bytes !== Array)
|
|
165
|
-
d.key = $util.newBuffer(d.key);
|
|
166
|
-
}
|
|
167
|
-
if (o.bytes === String)
|
|
168
|
-
d.value = "";
|
|
169
|
-
else {
|
|
170
|
-
d.value = [];
|
|
171
|
-
if (o.bytes !== Array)
|
|
172
|
-
d.value = $util.newBuffer(d.value);
|
|
173
|
-
}
|
|
174
|
-
d.timeReceived = "";
|
|
175
|
-
}
|
|
176
|
-
if (m.key != null && m.hasOwnProperty("key")) {
|
|
177
|
-
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;
|
|
178
|
-
}
|
|
179
|
-
if (m.value != null && m.hasOwnProperty("value")) {
|
|
180
|
-
d.value = o.bytes === String ? $util.base64.encode(m.value, 0, m.value.length) : o.bytes === Array ? Array.prototype.slice.call(m.value) : m.value;
|
|
181
|
-
}
|
|
182
|
-
if (m.timeReceived != null && m.hasOwnProperty("timeReceived")) {
|
|
183
|
-
d.timeReceived = m.timeReceived;
|
|
184
|
-
}
|
|
185
|
-
return d;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Converts this Record to JSON.
|
|
190
|
-
* @function toJSON
|
|
191
|
-
* @memberof Record
|
|
192
|
-
* @instance
|
|
193
|
-
* @returns {Object.<string,*>} JSON object
|
|
194
|
-
*/
|
|
195
|
-
Record.prototype.toJSON = function toJSON() {
|
|
196
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
return Record;
|
|
200
|
-
})();
|
|
201
|
-
|
|
202
|
-
export { $root as default };
|
|
19
|
+
})(Record || (Record = {}));
|
|
20
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAStF,MAAM,KAAW,MAAM,CAgBtB;AAhBD,WAAiB,MAAM;IACR,YAAK,GAAG,GAAkB,EAAE;QACvC,OAAO,OAAO,CAAS;YACrB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;YAChC,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;YAClC,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;SAC3C,CAAC,CAAA;IACJ,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAW,EAAc,EAAE;QAChD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAe,EAAU,EAAE;QAChD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC,EAhBgB,MAAM,KAAN,MAAM,QAgBtB"}
|
package/dist/src/selectors.d.ts
CHANGED
|
@@ -3,14 +3,5 @@ import type { Selectors } from '@libp2p/interfaces/dht';
|
|
|
3
3
|
* Select the best record out of the given records
|
|
4
4
|
*/
|
|
5
5
|
export declare function bestRecord(selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number;
|
|
6
|
-
|
|
7
|
-
* Best record selector, for public key records.
|
|
8
|
-
* Simply returns the first record, as all valid public key
|
|
9
|
-
* records are equal
|
|
10
|
-
*/
|
|
11
|
-
declare function publickKey(k: Uint8Array, records: Uint8Array[]): number;
|
|
12
|
-
export declare const selectors: {
|
|
13
|
-
publickKey: typeof publickKey;
|
|
14
|
-
};
|
|
15
|
-
export {};
|
|
6
|
+
export declare const selectors: Selectors;
|
|
16
7
|
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UA6BrF;
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UA6BrF;AAWD,eAAO,MAAM,SAAS,EAAE,SAEvB,CAAA"}
|
package/dist/src/selectors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import errCode from 'err-code';
|
|
2
2
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
3
3
|
/**
|
|
4
4
|
* Select the best record out of the given records
|
|
@@ -6,18 +6,18 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
|
6
6
|
export function bestRecord(selectors, k, records) {
|
|
7
7
|
if (records.length === 0) {
|
|
8
8
|
const errMsg = 'No records given';
|
|
9
|
-
throw
|
|
9
|
+
throw errCode(new Error(errMsg), 'ERR_NO_RECORDS_RECEIVED');
|
|
10
10
|
}
|
|
11
11
|
const kStr = uint8ArrayToString(k);
|
|
12
12
|
const parts = kStr.split('/');
|
|
13
13
|
if (parts.length < 3) {
|
|
14
14
|
const errMsg = 'Record key does not have a selector function';
|
|
15
|
-
throw
|
|
15
|
+
throw errCode(new Error(errMsg), 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY');
|
|
16
16
|
}
|
|
17
17
|
const selector = selectors[parts[1].toString()];
|
|
18
18
|
if (selector == null) {
|
|
19
19
|
const errMsg = `Unrecognized key prefix: ${parts[1]}`;
|
|
20
|
-
throw
|
|
20
|
+
throw errCode(new Error(errMsg), 'ERR_UNRECOGNIZED_KEY_PREFIX');
|
|
21
21
|
}
|
|
22
22
|
if (records.length === 1) {
|
|
23
23
|
return 0;
|
|
@@ -33,6 +33,6 @@ function publickKey(k, records) {
|
|
|
33
33
|
return 0;
|
|
34
34
|
}
|
|
35
35
|
export const selectors = {
|
|
36
|
-
publickKey
|
|
36
|
+
pk: publickKey
|
|
37
37
|
};
|
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AAC,CAAA;AAC7B,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAE,CAAa,EAAE,OAAqB;IACvD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAc;IAClC,EAAE,EAAE,UAAU;CACf,CAAA"}
|
package/dist/src/validators.d.ts
CHANGED
|
@@ -6,10 +6,5 @@ import type { Validators } from '@libp2p/interfaces/dht';
|
|
|
6
6
|
* If verification fails the returned Promise will reject with the error.
|
|
7
7
|
*/
|
|
8
8
|
export declare function verifyRecord(validators: Validators, record: Libp2pRecord): Promise<void> | undefined;
|
|
9
|
-
export declare const validators:
|
|
10
|
-
publicKey: {
|
|
11
|
-
func: (key: Uint8Array, publicKey: Uint8Array) => Promise<void>;
|
|
12
|
-
sign: boolean;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
9
|
+
export declare const validators: Validators;
|
|
15
10
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,6BAmBzE;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,6BAmBzE;AAmCD,eAAO,MAAM,UAAU,EAAE,UAExB,CAAA"}
|
package/dist/src/validators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import errCode from 'err-code';
|
|
2
2
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
3
3
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
4
4
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
@@ -18,9 +18,9 @@ export function verifyRecord(validators, record) {
|
|
|
18
18
|
const validator = validators[parts[1].toString()];
|
|
19
19
|
if (validator == null) {
|
|
20
20
|
const errMsg = 'Invalid record keytype';
|
|
21
|
-
throw
|
|
21
|
+
throw errCode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE');
|
|
22
22
|
}
|
|
23
|
-
return validator
|
|
23
|
+
return validator(key, record.value);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Validator for public key records.
|
|
@@ -33,26 +33,22 @@ export function verifyRecord(validators, record) {
|
|
|
33
33
|
*/
|
|
34
34
|
const validatePublicKeyRecord = async (key, publicKey) => {
|
|
35
35
|
if (!(key instanceof Uint8Array)) {
|
|
36
|
-
throw
|
|
36
|
+
throw errCode(new Error('"key" must be a Uint8Array'), 'ERR_INVALID_RECORD_KEY_NOT_BUFFER');
|
|
37
37
|
}
|
|
38
38
|
if (key.byteLength < 5) {
|
|
39
|
-
throw
|
|
39
|
+
throw errCode(new Error('invalid public key record'), 'ERR_INVALID_RECORD_KEY_TOO_SHORT');
|
|
40
40
|
}
|
|
41
41
|
const prefix = uint8ArrayToString(key.subarray(0, 4));
|
|
42
42
|
if (prefix !== '/pk/') {
|
|
43
|
-
throw
|
|
43
|
+
throw errCode(new Error('key was not prefixed with /pk/'), 'ERR_INVALID_RECORD_KEY_BAD_PREFIX');
|
|
44
44
|
}
|
|
45
45
|
const keyhash = key.slice(4);
|
|
46
46
|
const publicKeyHash = await sha256.digest(publicKey);
|
|
47
47
|
if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) {
|
|
48
|
-
throw
|
|
48
|
+
throw errCode(new Error('public key does not match passed in key'), 'ERR_INVALID_RECORD_HASH_MISMATCH');
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
const publicKey = {
|
|
52
|
-
func: validatePublicKeyRecord,
|
|
53
|
-
sign: false
|
|
54
|
-
};
|
|
55
51
|
export const validators = {
|
|
56
|
-
|
|
52
|
+
pk: validatePublicKeyRecord
|
|
57
53
|
};
|
|
58
54
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGtE,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/D;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAE,UAAsB,EAAE,MAAoB;IACxE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAA;IACtB,MAAM,SAAS,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAElC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,yBAAyB;QACzB,OAAM;KACP;IAED,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEjD,IAAI,SAAS,IAAI,IAAI,EAAE;QACrB,MAAM,MAAM,GAAG,wBAAwB,CAAA;QAEvC,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,6BAA6B,CAAC,CAAA;KAChE;IAED,OAAO,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"validators.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C,2BAA2B,CAAC,EAAE,kCAAkC,CAAC,CAAA;KAC1F;IAED,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAErD,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,gCAAgC,CAAC,EAAE,mCAAmC,CAAC,CAAA;KAChG;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE5B,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAEpD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE;QACnD,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,yCAAyC,CAAC,EAAE,kCAAkC,CAAC,CAAA;KACxG;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAe;IACpC,EAAE,EAAE,uBAAuB;CAC5B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/record",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "libp2p record implementation",
|
|
5
5
|
"author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -145,30 +145,29 @@
|
|
|
145
145
|
]
|
|
146
146
|
},
|
|
147
147
|
"scripts": {
|
|
148
|
+
"clean": "aegir clean",
|
|
148
149
|
"lint": "aegir lint",
|
|
149
|
-
"
|
|
150
|
-
"test": "aegir test
|
|
151
|
-
"test:node": "
|
|
152
|
-
"test:chrome": "
|
|
153
|
-
"test:chrome-webworker": "
|
|
154
|
-
"test:firefox": "
|
|
155
|
-
"test:firefox-webworker": "
|
|
156
|
-
"build": "
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"generate:proto-types": "pbts -o src/record/record.d.ts src/record/record.js",
|
|
160
|
-
"build:copy-proto-files": "cp src/record* dist/src",
|
|
161
|
-
"release": "semantic-release"
|
|
150
|
+
"dep-check": "aegir dep-check",
|
|
151
|
+
"test": "aegir test",
|
|
152
|
+
"test:node": "aegir test -t node",
|
|
153
|
+
"test:chrome": "aegir test -t browser",
|
|
154
|
+
"test:chrome-webworker": "aegir test -t webworker",
|
|
155
|
+
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
156
|
+
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
157
|
+
"build": "aegir build",
|
|
158
|
+
"generate": "protons ./src/record.proto",
|
|
159
|
+
"release": "aegir release"
|
|
162
160
|
},
|
|
163
161
|
"dependencies": {
|
|
162
|
+
"@libp2p/interfaces": "^1.3.21",
|
|
164
163
|
"err-code": "^3.0.1",
|
|
165
164
|
"multiformats": "^9.4.5",
|
|
166
|
-
"
|
|
165
|
+
"protons-runtime": "^1.0.2",
|
|
167
166
|
"uint8arrays": "^3.0.0"
|
|
168
167
|
},
|
|
169
168
|
"devDependencies": {
|
|
170
|
-
"@libp2p/crypto": "^0.22.
|
|
171
|
-
"
|
|
172
|
-
"
|
|
169
|
+
"@libp2p/crypto": "^0.22.10",
|
|
170
|
+
"aegir": "^37.0.13",
|
|
171
|
+
"protons": "^3.0.2"
|
|
173
172
|
}
|
|
174
173
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
Record as PBRecord
|
|
2
|
+
Record
|
|
4
3
|
} from './record.js'
|
|
5
4
|
import * as utils from './utils.js'
|
|
6
5
|
|
|
7
6
|
export class Libp2pRecord {
|
|
8
7
|
public key: Uint8Array
|
|
9
8
|
public value: Uint8Array
|
|
10
|
-
public timeReceived
|
|
9
|
+
public timeReceived: Date
|
|
11
10
|
|
|
12
|
-
constructor (key: Uint8Array, value: Uint8Array, timeReceived
|
|
11
|
+
constructor (key: Uint8Array, value: Uint8Array, timeReceived: Date) {
|
|
13
12
|
if (!(key instanceof Uint8Array)) {
|
|
14
13
|
throw new Error('key must be a Uint8Array')
|
|
15
14
|
}
|
|
@@ -24,7 +23,7 @@ export class Libp2pRecord {
|
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
serialize () {
|
|
27
|
-
return
|
|
26
|
+
return Record.encode(this.prepareSerialize())
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -34,7 +33,7 @@ export class Libp2pRecord {
|
|
|
34
33
|
return {
|
|
35
34
|
key: this.key,
|
|
36
35
|
value: this.value,
|
|
37
|
-
timeReceived:
|
|
36
|
+
timeReceived: utils.toRFC3339(this.timeReceived)
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
|
|
@@ -42,23 +41,16 @@ export class Libp2pRecord {
|
|
|
42
41
|
* Decode a protobuf encoded record
|
|
43
42
|
*/
|
|
44
43
|
static deserialize (raw: Uint8Array) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
arrays: true,
|
|
49
|
-
longs: Number,
|
|
50
|
-
objects: false
|
|
51
|
-
}))
|
|
44
|
+
const rec = Record.decode(raw)
|
|
45
|
+
|
|
46
|
+
return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived))
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
/**
|
|
55
50
|
* Create a record from the raw object returned from the protobuf library
|
|
56
51
|
*/
|
|
57
|
-
static fromDeserialized (obj:
|
|
58
|
-
|
|
59
|
-
if (obj.timeReceived != null) {
|
|
60
|
-
recvtime = utils.parseRFC3339(obj.timeReceived)
|
|
61
|
-
}
|
|
52
|
+
static fromDeserialized (obj: Record) {
|
|
53
|
+
const recvtime = utils.parseRFC3339(obj.timeReceived)
|
|
62
54
|
|
|
63
55
|
if (obj.key == null) {
|
|
64
56
|
throw new Error('key missing from deserialized object')
|
package/src/record.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { encodeMessage, decodeMessage, message, bytes, string } from 'protons-runtime'
|
|
5
|
+
import type { Codec } from 'protons-runtime'
|
|
6
|
+
|
|
7
|
+
export interface Record {
|
|
8
|
+
key: Uint8Array
|
|
9
|
+
value: Uint8Array
|
|
10
|
+
timeReceived: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export namespace Record {
|
|
14
|
+
export const codec = (): Codec<Record> => {
|
|
15
|
+
return message<Record>({
|
|
16
|
+
1: { name: 'key', codec: bytes },
|
|
17
|
+
2: { name: 'value', codec: bytes },
|
|
18
|
+
5: { name: 'timeReceived', codec: string }
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const encode = (obj: Record): Uint8Array => {
|
|
23
|
+
return encodeMessage(obj, Record.codec())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const decode = (buf: Uint8Array): Record => {
|
|
27
|
+
return decodeMessage(buf, Record.codec())
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/selectors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import errCode from 'err-code'
|
|
2
2
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
3
3
|
import type { Selectors } from '@libp2p/interfaces/dht'
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
|
|
|
9
9
|
if (records.length === 0) {
|
|
10
10
|
const errMsg = 'No records given'
|
|
11
11
|
|
|
12
|
-
throw
|
|
12
|
+
throw errCode(new Error(errMsg), 'ERR_NO_RECORDS_RECEIVED')
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const kStr = uint8ArrayToString(k)
|
|
@@ -18,7 +18,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
|
|
|
18
18
|
if (parts.length < 3) {
|
|
19
19
|
const errMsg = 'Record key does not have a selector function'
|
|
20
20
|
|
|
21
|
-
throw
|
|
21
|
+
throw errCode(new Error(errMsg), 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const selector = selectors[parts[1].toString()]
|
|
@@ -26,7 +26,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
|
|
|
26
26
|
if (selector == null) {
|
|
27
27
|
const errMsg = `Unrecognized key prefix: ${parts[1]}`
|
|
28
28
|
|
|
29
|
-
throw
|
|
29
|
+
throw errCode(new Error(errMsg), 'ERR_UNRECOGNIZED_KEY_PREFIX')
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (records.length === 1) {
|
|
@@ -45,6 +45,6 @@ function publickKey (k: Uint8Array, records: Uint8Array[]) {
|
|
|
45
45
|
return 0
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export const selectors = {
|
|
49
|
-
publickKey
|
|
48
|
+
export const selectors: Selectors = {
|
|
49
|
+
pk: publickKey
|
|
50
50
|
}
|
package/src/validators.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import errCode from 'err-code'
|
|
2
2
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
3
3
|
import type { Libp2pRecord } from './index.js'
|
|
4
4
|
import type { Validators } from '@libp2p/interfaces/dht'
|
|
@@ -25,10 +25,10 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
|
|
|
25
25
|
if (validator == null) {
|
|
26
26
|
const errMsg = 'Invalid record keytype'
|
|
27
27
|
|
|
28
|
-
throw
|
|
28
|
+
throw errCode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return validator
|
|
31
|
+
return validator(key, record.value)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -42,17 +42,17 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
|
|
|
42
42
|
*/
|
|
43
43
|
const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) => {
|
|
44
44
|
if (!(key instanceof Uint8Array)) {
|
|
45
|
-
throw
|
|
45
|
+
throw errCode(new Error('"key" must be a Uint8Array'), 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (key.byteLength < 5) {
|
|
49
|
-
throw
|
|
49
|
+
throw errCode(new Error('invalid public key record'), 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const prefix = uint8ArrayToString(key.subarray(0, 4))
|
|
53
53
|
|
|
54
54
|
if (prefix !== '/pk/') {
|
|
55
|
-
throw
|
|
55
|
+
throw errCode(new Error('key was not prefixed with /pk/'), 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const keyhash = key.slice(4)
|
|
@@ -60,15 +60,10 @@ const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) =
|
|
|
60
60
|
const publicKeyHash = await sha256.digest(publicKey)
|
|
61
61
|
|
|
62
62
|
if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) {
|
|
63
|
-
throw
|
|
63
|
+
throw errCode(new Error('public key does not match passed in key'), 'ERR_INVALID_RECORD_HASH_MISMATCH')
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
sign: false
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const validators = {
|
|
73
|
-
publicKey
|
|
67
|
+
export const validators: Validators = {
|
|
68
|
+
pk: validatePublicKeyRecord
|
|
74
69
|
}
|
package/dist/src/record.proto
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
// Record represents a dht record that contains a value
|
|
4
|
-
// for a key value pair
|
|
5
|
-
message Record {
|
|
6
|
-
// The key that references this record
|
|
7
|
-
bytes key = 1;
|
|
8
|
-
|
|
9
|
-
// The actual value this record is storing
|
|
10
|
-
bytes value = 2;
|
|
11
|
-
|
|
12
|
-
// Note: These fields were removed from the Record message
|
|
13
|
-
// hash of the authors public key
|
|
14
|
-
// optional bytes author = 3;
|
|
15
|
-
// A PKI signature for the key+value+author
|
|
16
|
-
// optional bytes signature = 4;
|
|
17
|
-
|
|
18
|
-
// Time the record was received, set by receiver
|
|
19
|
-
string timeReceived = 5;
|
|
20
|
-
}
|
package/src/record.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as $protobuf from "protobufjs";
|
|
2
|
-
/** Properties of a Record. */
|
|
3
|
-
export interface IRecord {
|
|
4
|
-
|
|
5
|
-
/** Record key */
|
|
6
|
-
key?: (Uint8Array|null);
|
|
7
|
-
|
|
8
|
-
/** Record value */
|
|
9
|
-
value?: (Uint8Array|null);
|
|
10
|
-
|
|
11
|
-
/** Record timeReceived */
|
|
12
|
-
timeReceived?: (string|null);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/** Represents a Record. */
|
|
16
|
-
export class Record implements IRecord {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Constructs a new Record.
|
|
20
|
-
* @param [p] Properties to set
|
|
21
|
-
*/
|
|
22
|
-
constructor(p?: IRecord);
|
|
23
|
-
|
|
24
|
-
/** Record key. */
|
|
25
|
-
public key: Uint8Array;
|
|
26
|
-
|
|
27
|
-
/** Record value. */
|
|
28
|
-
public value: Uint8Array;
|
|
29
|
-
|
|
30
|
-
/** Record timeReceived. */
|
|
31
|
-
public timeReceived: string;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
|
|
35
|
-
* @param m Record message or plain object to encode
|
|
36
|
-
* @param [w] Writer to encode to
|
|
37
|
-
* @returns Writer
|
|
38
|
-
*/
|
|
39
|
-
public static encode(m: IRecord, w?: $protobuf.Writer): $protobuf.Writer;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Decodes a Record message from the specified reader or buffer.
|
|
43
|
-
* @param r Reader or buffer to decode from
|
|
44
|
-
* @param [l] Message length if known beforehand
|
|
45
|
-
* @returns Record
|
|
46
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
47
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
48
|
-
*/
|
|
49
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Record;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Creates a Record message from a plain object. Also converts values to their respective internal types.
|
|
53
|
-
* @param d Plain object
|
|
54
|
-
* @returns Record
|
|
55
|
-
*/
|
|
56
|
-
public static fromObject(d: { [k: string]: any }): Record;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a plain object from a Record message. Also converts values to other types if specified.
|
|
60
|
-
* @param m Record
|
|
61
|
-
* @param [o] Conversion options
|
|
62
|
-
* @returns Plain object
|
|
63
|
-
*/
|
|
64
|
-
public static toObject(m: Record, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Converts this Record to JSON.
|
|
68
|
-
* @returns JSON object
|
|
69
|
-
*/
|
|
70
|
-
public toJSON(): { [k: string]: any };
|
|
71
|
-
}
|
package/src/record.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/*eslint-disable*/
|
|
2
|
-
import $protobuf from "protobufjs/minimal.js";
|
|
3
|
-
|
|
4
|
-
// Common aliases
|
|
5
|
-
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
|
6
|
-
|
|
7
|
-
// Exported root namespace
|
|
8
|
-
const $root = $protobuf.roots["libp2p-record"] || ($protobuf.roots["libp2p-record"] = {});
|
|
9
|
-
|
|
10
|
-
export const Record = $root.Record = (() => {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Properties of a Record.
|
|
14
|
-
* @exports IRecord
|
|
15
|
-
* @interface IRecord
|
|
16
|
-
* @property {Uint8Array|null} [key] Record key
|
|
17
|
-
* @property {Uint8Array|null} [value] Record value
|
|
18
|
-
* @property {string|null} [timeReceived] Record timeReceived
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new Record.
|
|
23
|
-
* @exports Record
|
|
24
|
-
* @classdesc Represents a Record.
|
|
25
|
-
* @implements IRecord
|
|
26
|
-
* @constructor
|
|
27
|
-
* @param {IRecord=} [p] Properties to set
|
|
28
|
-
*/
|
|
29
|
-
function Record(p) {
|
|
30
|
-
if (p)
|
|
31
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
32
|
-
if (p[ks[i]] != null)
|
|
33
|
-
this[ks[i]] = p[ks[i]];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Record key.
|
|
38
|
-
* @member {Uint8Array} key
|
|
39
|
-
* @memberof Record
|
|
40
|
-
* @instance
|
|
41
|
-
*/
|
|
42
|
-
Record.prototype.key = $util.newBuffer([]);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Record value.
|
|
46
|
-
* @member {Uint8Array} value
|
|
47
|
-
* @memberof Record
|
|
48
|
-
* @instance
|
|
49
|
-
*/
|
|
50
|
-
Record.prototype.value = $util.newBuffer([]);
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Record timeReceived.
|
|
54
|
-
* @member {string} timeReceived
|
|
55
|
-
* @memberof Record
|
|
56
|
-
* @instance
|
|
57
|
-
*/
|
|
58
|
-
Record.prototype.timeReceived = "";
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
|
|
62
|
-
* @function encode
|
|
63
|
-
* @memberof Record
|
|
64
|
-
* @static
|
|
65
|
-
* @param {IRecord} m Record message or plain object to encode
|
|
66
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
67
|
-
* @returns {$protobuf.Writer} Writer
|
|
68
|
-
*/
|
|
69
|
-
Record.encode = function encode(m, w) {
|
|
70
|
-
if (!w)
|
|
71
|
-
w = $Writer.create();
|
|
72
|
-
if (m.key != null && Object.hasOwnProperty.call(m, "key"))
|
|
73
|
-
w.uint32(10).bytes(m.key);
|
|
74
|
-
if (m.value != null && Object.hasOwnProperty.call(m, "value"))
|
|
75
|
-
w.uint32(18).bytes(m.value);
|
|
76
|
-
if (m.timeReceived != null && Object.hasOwnProperty.call(m, "timeReceived"))
|
|
77
|
-
w.uint32(42).string(m.timeReceived);
|
|
78
|
-
return w;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Decodes a Record message from the specified reader or buffer.
|
|
83
|
-
* @function decode
|
|
84
|
-
* @memberof Record
|
|
85
|
-
* @static
|
|
86
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
87
|
-
* @param {number} [l] Message length if known beforehand
|
|
88
|
-
* @returns {Record} Record
|
|
89
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
90
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
91
|
-
*/
|
|
92
|
-
Record.decode = function decode(r, l) {
|
|
93
|
-
if (!(r instanceof $Reader))
|
|
94
|
-
r = $Reader.create(r);
|
|
95
|
-
var c = l === undefined ? r.len : r.pos + l, m = new $root.Record();
|
|
96
|
-
while (r.pos < c) {
|
|
97
|
-
var t = r.uint32();
|
|
98
|
-
switch (t >>> 3) {
|
|
99
|
-
case 1:
|
|
100
|
-
m.key = r.bytes();
|
|
101
|
-
break;
|
|
102
|
-
case 2:
|
|
103
|
-
m.value = r.bytes();
|
|
104
|
-
break;
|
|
105
|
-
case 5:
|
|
106
|
-
m.timeReceived = r.string();
|
|
107
|
-
break;
|
|
108
|
-
default:
|
|
109
|
-
r.skipType(t & 7);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return m;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Creates a Record message from a plain object. Also converts values to their respective internal types.
|
|
118
|
-
* @function fromObject
|
|
119
|
-
* @memberof Record
|
|
120
|
-
* @static
|
|
121
|
-
* @param {Object.<string,*>} d Plain object
|
|
122
|
-
* @returns {Record} Record
|
|
123
|
-
*/
|
|
124
|
-
Record.fromObject = function fromObject(d) {
|
|
125
|
-
if (d instanceof $root.Record)
|
|
126
|
-
return d;
|
|
127
|
-
var m = new $root.Record();
|
|
128
|
-
if (d.key != null) {
|
|
129
|
-
if (typeof d.key === "string")
|
|
130
|
-
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0);
|
|
131
|
-
else if (d.key.length)
|
|
132
|
-
m.key = d.key;
|
|
133
|
-
}
|
|
134
|
-
if (d.value != null) {
|
|
135
|
-
if (typeof d.value === "string")
|
|
136
|
-
$util.base64.decode(d.value, m.value = $util.newBuffer($util.base64.length(d.value)), 0);
|
|
137
|
-
else if (d.value.length)
|
|
138
|
-
m.value = d.value;
|
|
139
|
-
}
|
|
140
|
-
if (d.timeReceived != null) {
|
|
141
|
-
m.timeReceived = String(d.timeReceived);
|
|
142
|
-
}
|
|
143
|
-
return m;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Creates a plain object from a Record message. Also converts values to other types if specified.
|
|
148
|
-
* @function toObject
|
|
149
|
-
* @memberof Record
|
|
150
|
-
* @static
|
|
151
|
-
* @param {Record} m Record
|
|
152
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
153
|
-
* @returns {Object.<string,*>} Plain object
|
|
154
|
-
*/
|
|
155
|
-
Record.toObject = function toObject(m, o) {
|
|
156
|
-
if (!o)
|
|
157
|
-
o = {};
|
|
158
|
-
var d = {};
|
|
159
|
-
if (o.defaults) {
|
|
160
|
-
if (o.bytes === String)
|
|
161
|
-
d.key = "";
|
|
162
|
-
else {
|
|
163
|
-
d.key = [];
|
|
164
|
-
if (o.bytes !== Array)
|
|
165
|
-
d.key = $util.newBuffer(d.key);
|
|
166
|
-
}
|
|
167
|
-
if (o.bytes === String)
|
|
168
|
-
d.value = "";
|
|
169
|
-
else {
|
|
170
|
-
d.value = [];
|
|
171
|
-
if (o.bytes !== Array)
|
|
172
|
-
d.value = $util.newBuffer(d.value);
|
|
173
|
-
}
|
|
174
|
-
d.timeReceived = "";
|
|
175
|
-
}
|
|
176
|
-
if (m.key != null && m.hasOwnProperty("key")) {
|
|
177
|
-
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;
|
|
178
|
-
}
|
|
179
|
-
if (m.value != null && m.hasOwnProperty("value")) {
|
|
180
|
-
d.value = o.bytes === String ? $util.base64.encode(m.value, 0, m.value.length) : o.bytes === Array ? Array.prototype.slice.call(m.value) : m.value;
|
|
181
|
-
}
|
|
182
|
-
if (m.timeReceived != null && m.hasOwnProperty("timeReceived")) {
|
|
183
|
-
d.timeReceived = m.timeReceived;
|
|
184
|
-
}
|
|
185
|
-
return d;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Converts this Record to JSON.
|
|
190
|
-
* @function toJSON
|
|
191
|
-
* @memberof Record
|
|
192
|
-
* @instance
|
|
193
|
-
* @returns {Object.<string,*>} JSON object
|
|
194
|
-
*/
|
|
195
|
-
Record.prototype.toJSON = function toJSON() {
|
|
196
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
return Record;
|
|
200
|
-
})();
|
|
201
|
-
|
|
202
|
-
export { $root as default };
|