@libp2p/crypto 1.0.2 → 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.
@@ -1,12 +1,12 @@
1
- import type { Codec } from 'protons-runtime';
2
1
  import type { Uint8ArrayList } from 'uint8arraylist';
2
+ import type { Codec } from 'protons-runtime';
3
3
  export declare enum KeyType {
4
4
  RSA = "RSA",
5
5
  Ed25519 = "Ed25519",
6
6
  Secp256k1 = "Secp256k1"
7
7
  }
8
8
  export declare namespace KeyType {
9
- const codec: () => Codec<typeof KeyType>;
9
+ const codec: () => Codec<KeyType>;
10
10
  }
11
11
  export interface PublicKey {
12
12
  Type: KeyType;
@@ -14,7 +14,7 @@ export interface PublicKey {
14
14
  }
15
15
  export declare namespace PublicKey {
16
16
  const codec: () => Codec<PublicKey>;
17
- const encode: (obj: PublicKey) => Uint8ArrayList;
17
+ const encode: (obj: PublicKey) => Uint8Array;
18
18
  const decode: (buf: Uint8Array | Uint8ArrayList) => PublicKey;
19
19
  }
20
20
  export interface PrivateKey {
@@ -23,7 +23,7 @@ export interface PrivateKey {
23
23
  }
24
24
  export declare namespace PrivateKey {
25
25
  const codec: () => Codec<PrivateKey>;
26
- const encode: (obj: PrivateKey) => Uint8ArrayList;
26
+ const encode: (obj: PrivateKey) => Uint8Array;
27
27
  const decode: (buf: Uint8Array | Uint8ArrayList) => PrivateKey;
28
28
  }
29
29
  //# sourceMappingURL=keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/keys/keys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,oBAAY,OAAO;IACjB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,SAAS,cAAc;CACxB;AAQD,yBAAiB,OAAO,CAAC;IAChB,MAAM,K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,OAAO,CAAA;IACb,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,yBAAiB,UAAU,CAAC;IAGnB,MAAM,KAAK,QAAO,MAAM,UAAU,CA6DxC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,UAExC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,UAEzD,CAAA;CACF"}
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime';
3
+ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime';
4
4
  export var KeyType;
5
5
  (function (KeyType) {
6
6
  KeyType["RSA"] = "RSA";
@@ -20,11 +20,60 @@ var __KeyTypeValues;
20
20
  })(KeyType || (KeyType = {}));
21
21
  export var PublicKey;
22
22
  (function (PublicKey) {
23
+ let _codec;
23
24
  PublicKey.codec = () => {
24
- return message({
25
- 1: { name: 'Type', codec: KeyType.codec() },
26
- 2: { name: 'Data', codec: bytes }
27
- });
25
+ if (_codec == null) {
26
+ _codec = message((obj, writer, opts = {}) => {
27
+ if (opts.lengthDelimited !== false) {
28
+ writer.fork();
29
+ }
30
+ if (obj.Type != null) {
31
+ writer.uint32(8);
32
+ KeyType.codec().encode(obj.Type, writer);
33
+ }
34
+ else {
35
+ throw new Error('Protocol error: required field "Type" was not found in object');
36
+ }
37
+ if (obj.Data != null) {
38
+ writer.uint32(18);
39
+ writer.bytes(obj.Data);
40
+ }
41
+ else {
42
+ throw new Error('Protocol error: required field "Data" was not found in object');
43
+ }
44
+ if (opts.lengthDelimited !== false) {
45
+ writer.ldelim();
46
+ }
47
+ }, (reader, length) => {
48
+ const obj = {
49
+ Type: KeyType.RSA,
50
+ Data: new Uint8Array(0)
51
+ };
52
+ const end = length == null ? reader.len : reader.pos + length;
53
+ while (reader.pos < end) {
54
+ const tag = reader.uint32();
55
+ switch (tag >>> 3) {
56
+ case 1:
57
+ obj.Type = KeyType.codec().decode(reader);
58
+ break;
59
+ case 2:
60
+ obj.Data = reader.bytes();
61
+ break;
62
+ default:
63
+ reader.skipType(tag & 7);
64
+ break;
65
+ }
66
+ }
67
+ if (obj.Type == null) {
68
+ throw new Error('Protocol error: value for required field "Type" was not found in protobuf');
69
+ }
70
+ if (obj.Data == null) {
71
+ throw new Error('Protocol error: value for required field "Data" was not found in protobuf');
72
+ }
73
+ return obj;
74
+ });
75
+ }
76
+ return _codec;
28
77
  };
29
78
  PublicKey.encode = (obj) => {
30
79
  return encodeMessage(obj, PublicKey.codec());
@@ -35,11 +84,60 @@ export var PublicKey;
35
84
  })(PublicKey || (PublicKey = {}));
36
85
  export var PrivateKey;
37
86
  (function (PrivateKey) {
87
+ let _codec;
38
88
  PrivateKey.codec = () => {
39
- return message({
40
- 1: { name: 'Type', codec: KeyType.codec() },
41
- 2: { name: 'Data', codec: bytes }
42
- });
89
+ if (_codec == null) {
90
+ _codec = message((obj, writer, opts = {}) => {
91
+ if (opts.lengthDelimited !== false) {
92
+ writer.fork();
93
+ }
94
+ if (obj.Type != null) {
95
+ writer.uint32(8);
96
+ KeyType.codec().encode(obj.Type, writer);
97
+ }
98
+ else {
99
+ throw new Error('Protocol error: required field "Type" was not found in object');
100
+ }
101
+ if (obj.Data != null) {
102
+ writer.uint32(18);
103
+ writer.bytes(obj.Data);
104
+ }
105
+ else {
106
+ throw new Error('Protocol error: required field "Data" was not found in object');
107
+ }
108
+ if (opts.lengthDelimited !== false) {
109
+ writer.ldelim();
110
+ }
111
+ }, (reader, length) => {
112
+ const obj = {
113
+ Type: KeyType.RSA,
114
+ Data: new Uint8Array(0)
115
+ };
116
+ const end = length == null ? reader.len : reader.pos + length;
117
+ while (reader.pos < end) {
118
+ const tag = reader.uint32();
119
+ switch (tag >>> 3) {
120
+ case 1:
121
+ obj.Type = KeyType.codec().decode(reader);
122
+ break;
123
+ case 2:
124
+ obj.Data = reader.bytes();
125
+ break;
126
+ default:
127
+ reader.skipType(tag & 7);
128
+ break;
129
+ }
130
+ }
131
+ if (obj.Type == null) {
132
+ throw new Error('Protocol error: value for required field "Type" was not found in protobuf');
133
+ }
134
+ if (obj.Data == null) {
135
+ throw new Error('Protocol error: value for required field "Data" was not found in protobuf');
136
+ }
137
+ return obj;
138
+ });
139
+ }
140
+ return _codec;
43
141
  };
44
142
  PrivateKey.encode = (obj) => {
45
143
  return encodeMessage(obj, PrivateKey.codec());
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../src/keys/keys.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAI3F,MAAM,CAAN,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,sBAAW,CAAA;IACX,8BAAmB,CAAA;IACnB,kCAAuB,CAAA;AACzB,CAAC,EAJW,OAAO,KAAP,OAAO,QAIlB;AAED,IAAK,eAIJ;AAJD,WAAK,eAAe;IAClB,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,+DAAa,CAAA;AACf,CAAC,EAJI,eAAe,KAAf,eAAe,QAInB;AAED,WAAiB,OAAO;IACT,aAAK,GAAG,GAAG,EAAE;QACxB,OAAO,WAAW,CAAiB,eAAe,CAAC,CAAA;IACrD,CAAC,CAAA;AACH,CAAC,EAJgB,OAAO,KAAP,OAAO,QAIvB;AAMD,MAAM,KAAW,SAAS,CAezB;AAfD,WAAiB,SAAS;IACX,eAAK,GAAG,GAAqB,EAAE;QAC1C,OAAO,OAAO,CAAY;YACxB,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE;YAC3C,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;SAClC,CAAC,CAAA;IACJ,CAAC,C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V,UAAU,QAyE1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/crypto",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Crypto primitives for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-crypto#readme",
@@ -184,14 +184,14 @@
184
184
  "err-code": "^3.0.1",
185
185
  "multiformats": "^9.4.5",
186
186
  "node-forge": "^1.1.0",
187
- "protons-runtime": "^2.0.2",
187
+ "protons-runtime": "^3.1.0",
188
188
  "uint8arrays": "^3.0.0"
189
189
  },
190
190
  "devDependencies": {
191
191
  "@types/mocha": "^9.0.0",
192
192
  "aegir": "^37.0.12",
193
193
  "benchmark": "^2.1.4",
194
- "protons": "^4.0.1",
194
+ "protons": "^5.1.0",
195
195
  "sinon": "^14.0.0",
196
196
  "util": "^0.12.3",
197
197
  "wherearewe": "^1.0.0"
package/src/keys/keys.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
 
4
- import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
5
- import type { Codec } from 'protons-runtime'
4
+ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
6
5
  import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import type { Codec } from 'protons-runtime'
7
7
 
8
8
  export enum KeyType {
9
9
  RSA = 'RSA',
@@ -19,7 +19,7 @@ enum __KeyTypeValues {
19
19
 
20
20
  export namespace KeyType {
21
21
  export const codec = () => {
22
- return enumeration<typeof KeyType>(__KeyTypeValues)
22
+ return enumeration<KeyType>(__KeyTypeValues)
23
23
  }
24
24
  }
25
25
  export interface PublicKey {
@@ -28,14 +28,72 @@ export interface PublicKey {
28
28
  }
29
29
 
30
30
  export namespace PublicKey {
31
+ let _codec: Codec<PublicKey>
32
+
31
33
  export const codec = (): Codec<PublicKey> => {
32
- return message<PublicKey>({
33
- 1: { name: 'Type', codec: KeyType.codec() },
34
- 2: { name: 'Data', codec: bytes }
35
- })
34
+ if (_codec == null) {
35
+ _codec = message<PublicKey>((obj, writer, opts = {}) => {
36
+ if (opts.lengthDelimited !== false) {
37
+ writer.fork()
38
+ }
39
+
40
+ if (obj.Type != null) {
41
+ writer.uint32(8)
42
+ KeyType.codec().encode(obj.Type, writer)
43
+ } else {
44
+ throw new Error('Protocol error: required field "Type" was not found in object')
45
+ }
46
+
47
+ if (obj.Data != null) {
48
+ writer.uint32(18)
49
+ writer.bytes(obj.Data)
50
+ } else {
51
+ throw new Error('Protocol error: required field "Data" was not found in object')
52
+ }
53
+
54
+ if (opts.lengthDelimited !== false) {
55
+ writer.ldelim()
56
+ }
57
+ }, (reader, length) => {
58
+ const obj: any = {
59
+ Type: KeyType.RSA,
60
+ Data: new Uint8Array(0)
61
+ }
62
+
63
+ const end = length == null ? reader.len : reader.pos + length
64
+
65
+ while (reader.pos < end) {
66
+ const tag = reader.uint32()
67
+
68
+ switch (tag >>> 3) {
69
+ case 1:
70
+ obj.Type = KeyType.codec().decode(reader)
71
+ break
72
+ case 2:
73
+ obj.Data = reader.bytes()
74
+ break
75
+ default:
76
+ reader.skipType(tag & 7)
77
+ break
78
+ }
79
+ }
80
+
81
+ if (obj.Type == null) {
82
+ throw new Error('Protocol error: value for required field "Type" was not found in protobuf')
83
+ }
84
+
85
+ if (obj.Data == null) {
86
+ throw new Error('Protocol error: value for required field "Data" was not found in protobuf')
87
+ }
88
+
89
+ return obj
90
+ })
91
+ }
92
+
93
+ return _codec
36
94
  }
37
95
 
38
- export const encode = (obj: PublicKey): Uint8ArrayList => {
96
+ export const encode = (obj: PublicKey): Uint8Array => {
39
97
  return encodeMessage(obj, PublicKey.codec())
40
98
  }
41
99
 
@@ -50,14 +108,72 @@ export interface PrivateKey {
50
108
  }
51
109
 
52
110
  export namespace PrivateKey {
111
+ let _codec: Codec<PrivateKey>
112
+
53
113
  export const codec = (): Codec<PrivateKey> => {
54
- return message<PrivateKey>({
55
- 1: { name: 'Type', codec: KeyType.codec() },
56
- 2: { name: 'Data', codec: bytes }
57
- })
114
+ if (_codec == null) {
115
+ _codec = message<PrivateKey>((obj, writer, opts = {}) => {
116
+ if (opts.lengthDelimited !== false) {
117
+ writer.fork()
118
+ }
119
+
120
+ if (obj.Type != null) {
121
+ writer.uint32(8)
122
+ KeyType.codec().encode(obj.Type, writer)
123
+ } else {
124
+ throw new Error('Protocol error: required field "Type" was not found in object')
125
+ }
126
+
127
+ if (obj.Data != null) {
128
+ writer.uint32(18)
129
+ writer.bytes(obj.Data)
130
+ } else {
131
+ throw new Error('Protocol error: required field "Data" was not found in object')
132
+ }
133
+
134
+ if (opts.lengthDelimited !== false) {
135
+ writer.ldelim()
136
+ }
137
+ }, (reader, length) => {
138
+ const obj: any = {
139
+ Type: KeyType.RSA,
140
+ Data: new Uint8Array(0)
141
+ }
142
+
143
+ const end = length == null ? reader.len : reader.pos + length
144
+
145
+ while (reader.pos < end) {
146
+ const tag = reader.uint32()
147
+
148
+ switch (tag >>> 3) {
149
+ case 1:
150
+ obj.Type = KeyType.codec().decode(reader)
151
+ break
152
+ case 2:
153
+ obj.Data = reader.bytes()
154
+ break
155
+ default:
156
+ reader.skipType(tag & 7)
157
+ break
158
+ }
159
+ }
160
+
161
+ if (obj.Type == null) {
162
+ throw new Error('Protocol error: value for required field "Type" was not found in protobuf')
163
+ }
164
+
165
+ if (obj.Data == null) {
166
+ throw new Error('Protocol error: value for required field "Data" was not found in protobuf')
167
+ }
168
+
169
+ return obj
170
+ })
171
+ }
172
+
173
+ return _codec
58
174
  }
59
175
 
60
- export const encode = (obj: PrivateKey): Uint8ArrayList => {
176
+ export const encode = (obj: PrivateKey): Uint8Array => {
61
177
  return encodeMessage(obj, PrivateKey.codec())
62
178
  }
63
179