@libp2p/crypto 0.22.7 → 0.22.10
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/ecdh-browser.d.ts.map +1 -1
- package/dist/src/keys/ecdh-browser.js +0 -1
- package/dist/src/keys/ecdh-browser.js.map +1 -1
- package/dist/src/keys/ed25519-class.js +2 -2
- package/dist/src/keys/ed25519-class.js.map +1 -1
- package/dist/src/keys/keys.d.ts +22 -220
- package/dist/src/keys/keys.d.ts.map +1 -1
- package/dist/src/keys/keys.js +44 -344
- package/dist/src/keys/keys.js.map +1 -1
- package/dist/src/keys/rsa-class.js +2 -2
- package/dist/src/keys/rsa-class.js.map +1 -1
- package/dist/src/keys/secp256k1-class.js +2 -2
- package/dist/src/keys/secp256k1-class.js.map +1 -1
- package/dist/src/pbkdf2.d.ts +1 -1
- package/dist/src/pbkdf2.d.ts.map +1 -1
- package/package.json +18 -19
- package/src/keys/ecdh-browser.ts +0 -1
- package/src/keys/ed25519-class.ts +2 -2
- package/src/keys/keys.ts +60 -0
- package/src/keys/rsa-class.ts +2 -2
- package/src/keys/secp256k1-class.ts +2 -2
- package/src/pbkdf2.ts +1 -1
- package/src/keys/keys.d.ts +0 -146
- package/src/keys/keys.js +0 -366
package/src/keys/rsa-class.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class RsaPublicKey {
|
|
|
29
29
|
return pbm.PublicKey.encode({
|
|
30
30
|
Type: pbm.KeyType.RSA,
|
|
31
31
|
Data: this.marshal()
|
|
32
|
-
})
|
|
32
|
+
})
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
encrypt (bytes: Uint8Array) {
|
|
@@ -84,7 +84,7 @@ export class RsaPrivateKey {
|
|
|
84
84
|
return pbm.PrivateKey.encode({
|
|
85
85
|
Type: pbm.KeyType.RSA,
|
|
86
86
|
Data: this.marshal()
|
|
87
|
-
})
|
|
87
|
+
})
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
equals (key: any) {
|
|
@@ -26,7 +26,7 @@ export class Secp256k1PublicKey {
|
|
|
26
26
|
return keysProtobuf.PublicKey.encode({
|
|
27
27
|
Type: keysProtobuf.KeyType.Secp256k1,
|
|
28
28
|
Data: this.marshal()
|
|
29
|
-
})
|
|
29
|
+
})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
equals (key: any) {
|
|
@@ -67,7 +67,7 @@ export class Secp256k1PrivateKey {
|
|
|
67
67
|
return keysProtobuf.PrivateKey.encode({
|
|
68
68
|
Type: keysProtobuf.KeyType.Secp256k1,
|
|
69
69
|
Data: this.marshal()
|
|
70
|
-
})
|
|
70
|
+
})
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
equals (key: any) {
|
package/src/pbkdf2.ts
CHANGED
|
@@ -20,7 +20,7 @@ const hashName = {
|
|
|
20
20
|
/**
|
|
21
21
|
* Computes the Password-Based Key Derivation Function 2.
|
|
22
22
|
*/
|
|
23
|
-
export default function pbkdf2 (password: string, salt: string, iterations: number, keySize: number, hash: string) {
|
|
23
|
+
export default function pbkdf2 (password: string, salt: string, iterations: number, keySize: number, hash: string): string {
|
|
24
24
|
if (hash !== 'sha1' && hash !== 'sha2-256' && hash !== 'sha2-512') {
|
|
25
25
|
const types = Object.keys(hashName).join(' / ')
|
|
26
26
|
throw errcode(new Error(`Hash '${hash}' is unknown or not supported. Must be ${types}`), 'ERR_UNSUPPORTED_HASH_TYPE')
|
package/src/keys/keys.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import $protobuf from 'protobufjs'
|
|
2
|
-
|
|
3
|
-
/** KeyType enum. */
|
|
4
|
-
export enum KeyType {
|
|
5
|
-
RSA = 0,
|
|
6
|
-
Ed25519 = 1,
|
|
7
|
-
Secp256k1 = 2
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface IPublicKey {
|
|
11
|
-
|
|
12
|
-
/** PublicKey Type. */
|
|
13
|
-
Type: KeyType
|
|
14
|
-
|
|
15
|
-
/** PublicKey Data. */
|
|
16
|
-
Data: Uint8Array
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Represents a PublicKey. */
|
|
20
|
-
export class PublicKey implements IPublicKey {
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new PublicKey.
|
|
23
|
-
*
|
|
24
|
-
* @param [p] - Properties to set
|
|
25
|
-
*/
|
|
26
|
-
constructor (p?: IPublicKey);
|
|
27
|
-
|
|
28
|
-
/** PublicKey Type. */
|
|
29
|
-
public Type: KeyType
|
|
30
|
-
|
|
31
|
-
/** PublicKey Data. */
|
|
32
|
-
public Data: Uint8Array
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages.
|
|
36
|
-
*
|
|
37
|
-
* @param m - PublicKey message or plain object to encode
|
|
38
|
-
* @param [w] - Writer to encode to
|
|
39
|
-
* @returns Writer
|
|
40
|
-
*/
|
|
41
|
-
public static encode (m: IPublicKey, w?: $protobuf.Writer): $protobuf.Writer;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Decodes a PublicKey message from the specified reader or buffer.
|
|
45
|
-
*
|
|
46
|
-
* @param r - Reader or buffer to decode from
|
|
47
|
-
* @param [l] - Message length if known beforehand
|
|
48
|
-
* @returns PublicKey
|
|
49
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
50
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
51
|
-
*/
|
|
52
|
-
public static decode (r: ($protobuf.Reader|Uint8Array), l?: number): PublicKey;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Creates a PublicKey message from a plain object. Also converts values to their respective internal types.
|
|
56
|
-
*
|
|
57
|
-
* @param d - Plain object
|
|
58
|
-
* @returns PublicKey
|
|
59
|
-
*/
|
|
60
|
-
public static fromObject (d: { [k: string]: any }): PublicKey;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Creates a plain object from a PublicKey message. Also converts values to other types if specified.
|
|
64
|
-
*
|
|
65
|
-
* @param m - PublicKey
|
|
66
|
-
* @param [o] - Conversion options
|
|
67
|
-
* @returns Plain object
|
|
68
|
-
*/
|
|
69
|
-
public static toObject (m: PublicKey, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Converts this PublicKey to JSON.
|
|
73
|
-
*
|
|
74
|
-
* @returns JSON object
|
|
75
|
-
*/
|
|
76
|
-
public toJSON (): { [k: string]: any };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface IPrivateKey {
|
|
80
|
-
|
|
81
|
-
/** PrivateKey Type. */
|
|
82
|
-
Type: KeyType
|
|
83
|
-
|
|
84
|
-
/** PrivateKey Data. */
|
|
85
|
-
Data: Uint8Array
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Represents a PrivateKey. */
|
|
89
|
-
export class PrivateKey implements IPrivateKey {
|
|
90
|
-
/**
|
|
91
|
-
* Constructs a new PrivateKey.
|
|
92
|
-
*
|
|
93
|
-
* @param [p] - Properties to set
|
|
94
|
-
*/
|
|
95
|
-
constructor (p?: IPrivateKey);
|
|
96
|
-
|
|
97
|
-
/** PrivateKey Type. */
|
|
98
|
-
public Type: KeyType
|
|
99
|
-
|
|
100
|
-
/** PrivateKey Data. */
|
|
101
|
-
public Data: Uint8Array
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Encodes the specified PrivateKey message. Does not implicitly {@link PrivateKey.verify|verify} messages.
|
|
105
|
-
*
|
|
106
|
-
* @param m - PrivateKey message or plain object to encode
|
|
107
|
-
* @param [w] - Writer to encode to
|
|
108
|
-
* @returns Writer
|
|
109
|
-
*/
|
|
110
|
-
public static encode (m: IPrivateKey, w?: $protobuf.Writer): $protobuf.Writer;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Decodes a PrivateKey message from the specified reader or buffer.
|
|
114
|
-
*
|
|
115
|
-
* @param r - Reader or buffer to decode from
|
|
116
|
-
* @param [l] - Message length if known beforehand
|
|
117
|
-
* @returns PrivateKey
|
|
118
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
119
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
120
|
-
*/
|
|
121
|
-
public static decode (r: ($protobuf.Reader|Uint8Array), l?: number): PrivateKey;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Creates a PrivateKey message from a plain object. Also converts values to their respective internal types.
|
|
125
|
-
*
|
|
126
|
-
* @param d - Plain object
|
|
127
|
-
* @returns PrivateKey
|
|
128
|
-
*/
|
|
129
|
-
public static fromObject (d: { [k: string]: any }): PrivateKey;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Creates a plain object from a PrivateKey message. Also converts values to other types if specified.
|
|
133
|
-
*
|
|
134
|
-
* @param m - PrivateKey
|
|
135
|
-
* @param [o] - Conversion options
|
|
136
|
-
* @returns Plain object
|
|
137
|
-
*/
|
|
138
|
-
public static toObject (m: PrivateKey, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Converts this PrivateKey to JSON.
|
|
142
|
-
*
|
|
143
|
-
* @returns JSON object
|
|
144
|
-
*/
|
|
145
|
-
public toJSON (): { [k: string]: any };
|
|
146
|
-
}
|
package/src/keys/keys.js
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
/*eslint-disable*/
|
|
4
|
-
import $protobuf from "protobufjs/minimal.js";
|
|
5
|
-
|
|
6
|
-
// Common aliases
|
|
7
|
-
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
|
8
|
-
|
|
9
|
-
// Exported root namespace
|
|
10
|
-
const $root = $protobuf.roots["libp2p-crypto-keys"] || ($protobuf.roots["libp2p-crypto-keys"] = {});
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* KeyType enum.
|
|
14
|
-
* @exports KeyType
|
|
15
|
-
* @enum {number}
|
|
16
|
-
* @property {number} RSA=0 RSA value
|
|
17
|
-
* @property {number} Ed25519=1 Ed25519 value
|
|
18
|
-
* @property {number} Secp256k1=2 Secp256k1 value
|
|
19
|
-
*/
|
|
20
|
-
export const KeyType = $root.KeyType = (() => {
|
|
21
|
-
const valuesById = {}, values = Object.create(valuesById);
|
|
22
|
-
values[valuesById[0] = "RSA"] = 0;
|
|
23
|
-
values[valuesById[1] = "Ed25519"] = 1;
|
|
24
|
-
values[valuesById[2] = "Secp256k1"] = 2;
|
|
25
|
-
return values;
|
|
26
|
-
})();
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Properties of a PublicKey.
|
|
30
|
-
* @exports IPublicKey
|
|
31
|
-
* @interface IPublicKey
|
|
32
|
-
* @property {KeyType} Type PublicKey Type
|
|
33
|
-
* @property {Uint8Array} Data PublicKey Data
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Constructs a new PublicKey.
|
|
38
|
-
* @exports PublicKey
|
|
39
|
-
* @classdesc Represents a PublicKey.
|
|
40
|
-
* @implements IPublicKey
|
|
41
|
-
* @constructor
|
|
42
|
-
* @param {IPublicKey=} [p] Properties to set
|
|
43
|
-
*/
|
|
44
|
-
export function PublicKey(p) {
|
|
45
|
-
if (p)
|
|
46
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
47
|
-
if (p[ks[i]] != null)
|
|
48
|
-
this[ks[i]] = p[ks[i]];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* PublicKey Type.
|
|
53
|
-
* @member {KeyType} Type
|
|
54
|
-
* @memberof PublicKey
|
|
55
|
-
* @instance
|
|
56
|
-
*/
|
|
57
|
-
PublicKey.prototype.Type = 0;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* PublicKey Data.
|
|
61
|
-
* @member {Uint8Array} Data
|
|
62
|
-
* @memberof PublicKey
|
|
63
|
-
* @instance
|
|
64
|
-
*/
|
|
65
|
-
PublicKey.prototype.Data = $util.newBuffer([]);
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages.
|
|
69
|
-
* @function encode
|
|
70
|
-
* @memberof PublicKey
|
|
71
|
-
* @static
|
|
72
|
-
* @param {IPublicKey} m PublicKey message or plain object to encode
|
|
73
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
74
|
-
* @returns {$protobuf.Writer} Writer
|
|
75
|
-
*/
|
|
76
|
-
PublicKey.encode = function encode(m, w) {
|
|
77
|
-
if (!w)
|
|
78
|
-
w = $Writer.create();
|
|
79
|
-
w.uint32(8).int32(m.Type);
|
|
80
|
-
w.uint32(18).bytes(m.Data);
|
|
81
|
-
return w;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Decodes a PublicKey message from the specified reader or buffer.
|
|
86
|
-
* @function decode
|
|
87
|
-
* @memberof PublicKey
|
|
88
|
-
* @static
|
|
89
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
90
|
-
* @param {number} [l] Message length if known beforehand
|
|
91
|
-
* @returns {PublicKey} PublicKey
|
|
92
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
93
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
94
|
-
*/
|
|
95
|
-
PublicKey.decode = function decode(r, l) {
|
|
96
|
-
if (!(r instanceof $Reader))
|
|
97
|
-
r = $Reader.create(r);
|
|
98
|
-
var c = l === undefined ? r.len : r.pos + l, m = new PublicKey();
|
|
99
|
-
while (r.pos < c) {
|
|
100
|
-
var t = r.uint32();
|
|
101
|
-
switch (t >>> 3) {
|
|
102
|
-
case 1:
|
|
103
|
-
m.Type = r.int32();
|
|
104
|
-
break;
|
|
105
|
-
case 2:
|
|
106
|
-
m.Data = r.bytes();
|
|
107
|
-
break;
|
|
108
|
-
default:
|
|
109
|
-
r.skipType(t & 7);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!m.hasOwnProperty("Type"))
|
|
114
|
-
throw $util.ProtocolError("missing required 'Type'", { instance: m });
|
|
115
|
-
if (!m.hasOwnProperty("Data"))
|
|
116
|
-
throw $util.ProtocolError("missing required 'Data'", { instance: m });
|
|
117
|
-
return m;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Creates a PublicKey message from a plain object. Also converts values to their respective internal types.
|
|
122
|
-
* @function fromObject
|
|
123
|
-
* @memberof PublicKey
|
|
124
|
-
* @static
|
|
125
|
-
* @param {Object.<string,*>} d Plain object
|
|
126
|
-
* @returns {PublicKey} PublicKey
|
|
127
|
-
*/
|
|
128
|
-
PublicKey.fromObject = function fromObject(d) {
|
|
129
|
-
if (d instanceof PublicKey)
|
|
130
|
-
return d;
|
|
131
|
-
var m = new PublicKey();
|
|
132
|
-
switch (d.Type) {
|
|
133
|
-
case "RSA":
|
|
134
|
-
case 0:
|
|
135
|
-
m.Type = 0;
|
|
136
|
-
break;
|
|
137
|
-
case "Ed25519":
|
|
138
|
-
case 1:
|
|
139
|
-
m.Type = 1;
|
|
140
|
-
break;
|
|
141
|
-
case "Secp256k1":
|
|
142
|
-
case 2:
|
|
143
|
-
m.Type = 2;
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
if (d.Data != null) {
|
|
147
|
-
if (typeof d.Data === "string")
|
|
148
|
-
$util.base64.decode(d.Data, m.Data = $util.newBuffer($util.base64.length(d.Data)), 0);
|
|
149
|
-
else if (d.Data.length)
|
|
150
|
-
m.Data = d.Data;
|
|
151
|
-
}
|
|
152
|
-
return m;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Creates a plain object from a PublicKey message. Also converts values to other types if specified.
|
|
157
|
-
* @function toObject
|
|
158
|
-
* @memberof PublicKey
|
|
159
|
-
* @static
|
|
160
|
-
* @param {PublicKey} m PublicKey
|
|
161
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
162
|
-
* @returns {Object.<string,*>} Plain object
|
|
163
|
-
*/
|
|
164
|
-
PublicKey.toObject = function toObject(m, o) {
|
|
165
|
-
if (!o)
|
|
166
|
-
o = {};
|
|
167
|
-
var d = {};
|
|
168
|
-
if (o.defaults) {
|
|
169
|
-
d.Type = o.enums === String ? "RSA" : 0;
|
|
170
|
-
if (o.bytes === String)
|
|
171
|
-
d.Data = "";
|
|
172
|
-
else {
|
|
173
|
-
d.Data = [];
|
|
174
|
-
if (o.bytes !== Array)
|
|
175
|
-
d.Data = $util.newBuffer(d.Data);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (m.Type != null && m.hasOwnProperty("Type")) {
|
|
179
|
-
d.Type = o.enums === String ? $root.KeyType[m.Type] : m.Type;
|
|
180
|
-
}
|
|
181
|
-
if (m.Data != null && m.hasOwnProperty("Data")) {
|
|
182
|
-
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;
|
|
183
|
-
}
|
|
184
|
-
return d;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Converts this PublicKey to JSON.
|
|
189
|
-
* @function toJSON
|
|
190
|
-
* @memberof PublicKey
|
|
191
|
-
* @instance
|
|
192
|
-
* @returns {Object.<string,*>} JSON object
|
|
193
|
-
*/
|
|
194
|
-
PublicKey.prototype.toJSON = function toJSON() {
|
|
195
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Properties of a PrivateKey.
|
|
200
|
-
* @exports IPrivateKey
|
|
201
|
-
* @interface IPrivateKey
|
|
202
|
-
* @property {KeyType} Type PrivateKey Type
|
|
203
|
-
* @property {Uint8Array} Data PrivateKey Data
|
|
204
|
-
*/
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Constructs a new PrivateKey.
|
|
208
|
-
* @exports PrivateKey
|
|
209
|
-
* @classdesc Represents a PrivateKey.
|
|
210
|
-
* @implements IPrivateKey
|
|
211
|
-
* @constructor
|
|
212
|
-
* @param {IPrivateKey=} [p] Properties to set
|
|
213
|
-
*/
|
|
214
|
-
export function PrivateKey(p) {
|
|
215
|
-
if (p)
|
|
216
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
217
|
-
if (p[ks[i]] != null)
|
|
218
|
-
this[ks[i]] = p[ks[i]];
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* PrivateKey Type.
|
|
223
|
-
* @member {KeyType} Type
|
|
224
|
-
* @memberof PrivateKey
|
|
225
|
-
* @instance
|
|
226
|
-
*/
|
|
227
|
-
PrivateKey.prototype.Type = 0;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* PrivateKey Data.
|
|
231
|
-
* @member {Uint8Array} Data
|
|
232
|
-
* @memberof PrivateKey
|
|
233
|
-
* @instance
|
|
234
|
-
*/
|
|
235
|
-
PrivateKey.prototype.Data = $util.newBuffer([]);
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Encodes the specified PrivateKey message. Does not implicitly {@link PrivateKey.verify|verify} messages.
|
|
239
|
-
* @function encode
|
|
240
|
-
* @memberof PrivateKey
|
|
241
|
-
* @static
|
|
242
|
-
* @param {IPrivateKey} m PrivateKey message or plain object to encode
|
|
243
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
244
|
-
* @returns {$protobuf.Writer} Writer
|
|
245
|
-
*/
|
|
246
|
-
PrivateKey.encode = function encode(m, w) {
|
|
247
|
-
if (!w)
|
|
248
|
-
w = $Writer.create();
|
|
249
|
-
w.uint32(8).int32(m.Type);
|
|
250
|
-
w.uint32(18).bytes(m.Data);
|
|
251
|
-
return w;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Decodes a PrivateKey message from the specified reader or buffer.
|
|
256
|
-
* @function decode
|
|
257
|
-
* @memberof PrivateKey
|
|
258
|
-
* @static
|
|
259
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
260
|
-
* @param {number} [l] Message length if known beforehand
|
|
261
|
-
* @returns {PrivateKey} PrivateKey
|
|
262
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
263
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
264
|
-
*/
|
|
265
|
-
PrivateKey.decode = function decode(r, l) {
|
|
266
|
-
if (!(r instanceof $Reader))
|
|
267
|
-
r = $Reader.create(r);
|
|
268
|
-
var c = l === undefined ? r.len : r.pos + l, m = new PrivateKey();
|
|
269
|
-
while (r.pos < c) {
|
|
270
|
-
var t = r.uint32();
|
|
271
|
-
switch (t >>> 3) {
|
|
272
|
-
case 1:
|
|
273
|
-
m.Type = r.int32();
|
|
274
|
-
break;
|
|
275
|
-
case 2:
|
|
276
|
-
m.Data = r.bytes();
|
|
277
|
-
break;
|
|
278
|
-
default:
|
|
279
|
-
r.skipType(t & 7);
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
if (!m.hasOwnProperty("Type"))
|
|
284
|
-
throw $util.ProtocolError("missing required 'Type'", { instance: m });
|
|
285
|
-
if (!m.hasOwnProperty("Data"))
|
|
286
|
-
throw $util.ProtocolError("missing required 'Data'", { instance: m });
|
|
287
|
-
return m;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Creates a PrivateKey message from a plain object. Also converts values to their respective internal types.
|
|
292
|
-
* @function fromObject
|
|
293
|
-
* @memberof PrivateKey
|
|
294
|
-
* @static
|
|
295
|
-
* @param {Object.<string,*>} d Plain object
|
|
296
|
-
* @returns {PrivateKey} PrivateKey
|
|
297
|
-
*/
|
|
298
|
-
PrivateKey.fromObject = function fromObject(d) {
|
|
299
|
-
if (d instanceof PrivateKey)
|
|
300
|
-
return d;
|
|
301
|
-
var m = new PrivateKey();
|
|
302
|
-
switch (d.Type) {
|
|
303
|
-
case "RSA":
|
|
304
|
-
case 0:
|
|
305
|
-
m.Type = 0;
|
|
306
|
-
break;
|
|
307
|
-
case "Ed25519":
|
|
308
|
-
case 1:
|
|
309
|
-
m.Type = 1;
|
|
310
|
-
break;
|
|
311
|
-
case "Secp256k1":
|
|
312
|
-
case 2:
|
|
313
|
-
m.Type = 2;
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
if (d.Data != null) {
|
|
317
|
-
if (typeof d.Data === "string")
|
|
318
|
-
$util.base64.decode(d.Data, m.Data = $util.newBuffer($util.base64.length(d.Data)), 0);
|
|
319
|
-
else if (d.Data.length)
|
|
320
|
-
m.Data = d.Data;
|
|
321
|
-
}
|
|
322
|
-
return m;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Creates a plain object from a PrivateKey message. Also converts values to other types if specified.
|
|
327
|
-
* @function toObject
|
|
328
|
-
* @memberof PrivateKey
|
|
329
|
-
* @static
|
|
330
|
-
* @param {PrivateKey} m PrivateKey
|
|
331
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
332
|
-
* @returns {Object.<string,*>} Plain object
|
|
333
|
-
*/
|
|
334
|
-
PrivateKey.toObject = function toObject(m, o) {
|
|
335
|
-
if (!o)
|
|
336
|
-
o = {};
|
|
337
|
-
var d = {};
|
|
338
|
-
if (o.defaults) {
|
|
339
|
-
d.Type = o.enums === String ? "RSA" : 0;
|
|
340
|
-
if (o.bytes === String)
|
|
341
|
-
d.Data = "";
|
|
342
|
-
else {
|
|
343
|
-
d.Data = [];
|
|
344
|
-
if (o.bytes !== Array)
|
|
345
|
-
d.Data = $util.newBuffer(d.Data);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (m.Type != null && m.hasOwnProperty("Type")) {
|
|
349
|
-
d.Type = o.enums === String ? $root.KeyType[m.Type] : m.Type;
|
|
350
|
-
}
|
|
351
|
-
if (m.Data != null && m.hasOwnProperty("Data")) {
|
|
352
|
-
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;
|
|
353
|
-
}
|
|
354
|
-
return d;
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Converts this PrivateKey to JSON.
|
|
359
|
-
* @function toJSON
|
|
360
|
-
* @memberof PrivateKey
|
|
361
|
-
* @instance
|
|
362
|
-
* @returns {Object.<string,*>} JSON object
|
|
363
|
-
*/
|
|
364
|
-
PrivateKey.prototype.toJSON = function toJSON() {
|
|
365
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
366
|
-
};
|