@libp2p/crypto 1.0.1 → 1.0.4
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/keys/ed25519-class.d.ts +1 -1
- package/dist/src/keys/exporter.d.ts +1 -1
- package/dist/src/keys/exporter.d.ts.map +1 -1
- package/dist/src/keys/keys.d.ts +4 -4
- package/dist/src/keys/keys.d.ts.map +1 -1
- package/dist/src/keys/keys.js +107 -9
- package/dist/src/keys/keys.js.map +1 -1
- package/dist/src/keys/secp256k1-class.d.ts +1 -1
- package/dist/src/random-bytes.js +2 -2
- package/dist/src/random-bytes.js.map +1 -1
- package/package.json +4 -5
- package/src/keys/keys.ts +129 -13
- package/src/random-bytes.ts +2 -2
|
@@ -30,7 +30,7 @@ export declare class Ed25519PrivateKey {
|
|
|
30
30
|
/**
|
|
31
31
|
* Exports the key into a password protected `format`
|
|
32
32
|
*/
|
|
33
|
-
export(password: string, format?: string): Promise<import("multiformats/bases/base").Multibase<"m">>;
|
|
33
|
+
export(password: string, format?: string): Promise<import("multiformats/bases/base.js").Multibase<"m">>;
|
|
34
34
|
}
|
|
35
35
|
export declare function unmarshalEd25519PrivateKey(bytes: Uint8Array): Ed25519PrivateKey;
|
|
36
36
|
export declare function unmarshalEd25519PublicKey(bytes: Uint8Array): Ed25519PublicKey;
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* The PrivateKey is encrypted via a password derived PBKDF2 key
|
|
4
4
|
* leveraging the aes-gcm cipher algorithm.
|
|
5
5
|
*/
|
|
6
|
-
export declare function exporter(privateKey: Uint8Array, password: string): Promise<import("multiformats/bases/base").Multibase<"m">>;
|
|
6
|
+
export declare function exporter(privateKey: Uint8Array, password: string): Promise<import("multiformats/bases/base.js").Multibase<"m">>;
|
|
7
7
|
//# sourceMappingURL=exporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../../../src/keys/exporter.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,QAAQ,CAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../../../src/keys/exporter.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,QAAQ,CAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gEAIvE"}
|
package/dist/src/keys/keys.d.ts
CHANGED
|
@@ -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<
|
|
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) =>
|
|
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) =>
|
|
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,
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/keys/keys.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,oBAAY,OAAO;IACjB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,SAAS,cAAc;CACxB;AAQD,yBAAiB,OAAO,CAAC;IAChB,MAAM,KAAK,sBAEjB,CAAA;CACF;AACD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,yBAAiB,SAAS,CAAC;IAGlB,MAAM,KAAK,QAAO,MAAM,SAAS,CA6DvC,CAAA;IAEM,MAAM,MAAM,QAAS,SAAS,KAAG,UAEvC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,SAEzD,CAAA;CACF;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,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"}
|
package/dist/src/keys/keys.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
-
import { enumeration, encodeMessage, decodeMessage, message
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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,
|
|
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,MAAM,iBAAiB,CAAA;AAIpF,MAAM,CAAN,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,sBAAW,CA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,CAAA;AACH,CAAC,EAzEgB,UAAU,KAAV,UAAU,QAyE1B"}
|
|
@@ -28,7 +28,7 @@ export declare class Secp256k1PrivateKey {
|
|
|
28
28
|
/**
|
|
29
29
|
* Exports the key into a password protected `format`
|
|
30
30
|
*/
|
|
31
|
-
export(password: string, format?: string): Promise<import("multiformats/bases/base").Multibase<"m">>;
|
|
31
|
+
export(password: string, format?: string): Promise<import("multiformats/bases/base.js").Multibase<"m">>;
|
|
32
32
|
}
|
|
33
33
|
export declare function unmarshalSecp256k1PrivateKey(bytes: Uint8Array): Secp256k1PrivateKey;
|
|
34
34
|
export declare function unmarshalSecp256k1PublicKey(bytes: Uint8Array): Secp256k1PublicKey;
|
package/dist/src/random-bytes.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { utils } from '@noble/secp256k1';
|
|
2
2
|
import errcode from 'err-code';
|
|
3
3
|
export default function randomBytes(length) {
|
|
4
4
|
if (isNaN(length) || length <= 0) {
|
|
5
5
|
throw errcode(new Error('random bytes length must be a Number bigger than 0'), 'ERR_INVALID_LENGTH');
|
|
6
6
|
}
|
|
7
|
-
return
|
|
7
|
+
return utils.randomBytes(length);
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=random-bytes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random-bytes.js","sourceRoot":"","sources":["../../src/random-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"random-bytes.js","sourceRoot":"","sources":["../../src/random-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,OAAO,MAAM,UAAU,CAAA;AAE9B,MAAM,CAAC,OAAO,UAAU,WAAW,CAAE,MAAc;IACjD,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE;QAChC,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,oDAAoD,CAAC,EAAE,oBAAoB,CAAC,CAAA;KACrG;IACD,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;AAClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/crypto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -182,20 +182,19 @@
|
|
|
182
182
|
"@noble/ed25519": "^1.6.0",
|
|
183
183
|
"@noble/secp256k1": "^1.5.4",
|
|
184
184
|
"err-code": "^3.0.1",
|
|
185
|
-
"iso-random-stream": "^2.0.0",
|
|
186
185
|
"multiformats": "^9.4.5",
|
|
187
186
|
"node-forge": "^1.1.0",
|
|
188
|
-
"protons-runtime": "^
|
|
187
|
+
"protons-runtime": "^3.1.0",
|
|
189
188
|
"uint8arrays": "^3.0.0"
|
|
190
189
|
},
|
|
191
190
|
"devDependencies": {
|
|
192
191
|
"@types/mocha": "^9.0.0",
|
|
193
192
|
"aegir": "^37.0.12",
|
|
194
193
|
"benchmark": "^2.1.4",
|
|
195
|
-
"protons": "^
|
|
194
|
+
"protons": "^5.1.0",
|
|
196
195
|
"sinon": "^14.0.0",
|
|
197
196
|
"util": "^0.12.3",
|
|
198
|
-
"wherearewe": "^
|
|
197
|
+
"wherearewe": "^2.0.1"
|
|
199
198
|
},
|
|
200
199
|
"browser": {
|
|
201
200
|
"./dist/src/aes/ciphers.js": "./dist/src/aes/ciphers-browser.js",
|
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
|
|
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<
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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):
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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):
|
|
176
|
+
export const encode = (obj: PrivateKey): Uint8Array => {
|
|
61
177
|
return encodeMessage(obj, PrivateKey.codec())
|
|
62
178
|
}
|
|
63
179
|
|
package/src/random-bytes.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { utils } from '@noble/secp256k1'
|
|
2
2
|
import errcode from 'err-code'
|
|
3
3
|
|
|
4
4
|
export default function randomBytes (length: number): Uint8Array {
|
|
5
5
|
if (isNaN(length) || length <= 0) {
|
|
6
6
|
throw errcode(new Error('random bytes length must be a Number bigger than 0'), 'ERR_INVALID_LENGTH')
|
|
7
7
|
}
|
|
8
|
-
return
|
|
8
|
+
return utils.randomBytes(length)
|
|
9
9
|
}
|