@libp2p/crypto 0.22.9 → 0.22.12
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/index.d.ts +7 -5
- package/dist/src/keys/index.d.ts.map +1 -1
- package/dist/src/keys/index.js.map +1 -1
- package/dist/src/keys/keys.d.ts +23 -220
- package/dist/src/keys/keys.d.ts.map +1 -1
- package/dist/src/keys/keys.js +50 -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/package.json +17 -17
- package/src/keys/ecdh-browser.ts +0 -1
- package/src/keys/ed25519-class.ts +2 -2
- package/src/keys/index.ts +10 -7
- package/src/keys/keys.ts +66 -0
- package/src/keys/rsa-class.ts +2 -2
- package/src/keys/secp256k1-class.ts +2 -2
- package/src/keys/keys.d.ts +0 -146
- package/src/keys/keys.js +0 -366
package/src/keys/index.ts
CHANGED
|
@@ -11,11 +11,14 @@ import { importer } from './importer.js'
|
|
|
11
11
|
import * as RSA from './rsa-class.js'
|
|
12
12
|
import * as Ed25519 from './ed25519-class.js'
|
|
13
13
|
import * as Secp256k1 from './secp256k1-class.js'
|
|
14
|
+
import type { PrivateKey, PublicKey } from '@libp2p/interfaces/keys'
|
|
14
15
|
|
|
15
16
|
export { keyStretcher }
|
|
16
17
|
export { generateEphemeralKeyPair }
|
|
17
18
|
export { keysPBM }
|
|
18
19
|
|
|
20
|
+
export type KeyTypes = 'RSA' | 'Ed25519' | 'secp256k1'
|
|
21
|
+
|
|
19
22
|
export const supportedKeys = {
|
|
20
23
|
rsa: RSA,
|
|
21
24
|
ed25519: Ed25519,
|
|
@@ -38,13 +41,13 @@ function typeToKey (type: string) {
|
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
// Generates a keypair of the given type and bitsize
|
|
41
|
-
export async function generateKeyPair (type:
|
|
44
|
+
export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
|
|
42
45
|
return await typeToKey(type).generateKeyPair(bits ?? 2048)
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
// Generates a keypair of the given type and bitsize
|
|
46
49
|
// seed is a 32 byte uint8array
|
|
47
|
-
export async function generateKeyPairFromSeed (type:
|
|
50
|
+
export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
|
|
48
51
|
if (type.toLowerCase() !== 'ed25519') {
|
|
49
52
|
throw errcode(new Error('Seed key derivation is unimplemented for RSA or secp256k1'), 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE')
|
|
50
53
|
}
|
|
@@ -54,7 +57,7 @@ export async function generateKeyPairFromSeed (type: 'RSA' | 'Ed25519' | 'secp25
|
|
|
54
57
|
|
|
55
58
|
// Converts a protobuf serialized public key into its
|
|
56
59
|
// representative object
|
|
57
|
-
export function unmarshalPublicKey (buf: Uint8Array) {
|
|
60
|
+
export function unmarshalPublicKey (buf: Uint8Array): PublicKey {
|
|
58
61
|
const decoded = keysPBM.PublicKey.decode(buf)
|
|
59
62
|
const data = decoded.Data
|
|
60
63
|
|
|
@@ -71,7 +74,7 @@ export function unmarshalPublicKey (buf: Uint8Array) {
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
// Converts a public key object into a protobuf serialized public key
|
|
74
|
-
export function marshalPublicKey (key: { bytes: Uint8Array }, type?: string) {
|
|
77
|
+
export function marshalPublicKey (key: { bytes: Uint8Array }, type?: string): Uint8Array {
|
|
75
78
|
type = (type ?? 'rsa').toLowerCase()
|
|
76
79
|
typeToKey(type) // check type
|
|
77
80
|
return key.bytes
|
|
@@ -79,7 +82,7 @@ export function marshalPublicKey (key: { bytes: Uint8Array }, type?: string) {
|
|
|
79
82
|
|
|
80
83
|
// Converts a protobuf serialized private key into its
|
|
81
84
|
// representative object
|
|
82
|
-
export async function unmarshalPrivateKey (buf: Uint8Array) { // eslint-disable-line require-await
|
|
85
|
+
export async function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey> { // eslint-disable-line require-await
|
|
83
86
|
const decoded = keysPBM.PrivateKey.decode(buf)
|
|
84
87
|
const data = decoded.Data
|
|
85
88
|
|
|
@@ -96,7 +99,7 @@ export async function unmarshalPrivateKey (buf: Uint8Array) { // eslint-disable-
|
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
// Converts a private key object into a protobuf serialized private key
|
|
99
|
-
export function marshalPrivateKey (key: { bytes: Uint8Array }, type?: string) {
|
|
102
|
+
export function marshalPrivateKey (key: { bytes: Uint8Array }, type?: string): Uint8Array {
|
|
100
103
|
type = (type ?? 'rsa').toLowerCase()
|
|
101
104
|
typeToKey(type) // check type
|
|
102
105
|
return key.bytes
|
|
@@ -107,7 +110,7 @@ export function marshalPrivateKey (key: { bytes: Uint8Array }, type?: string) {
|
|
|
107
110
|
* @param {string} encryptedKey
|
|
108
111
|
* @param {string} password
|
|
109
112
|
*/
|
|
110
|
-
export async function importKey (encryptedKey: string, password: string) { // eslint-disable-line require-await
|
|
113
|
+
export async function importKey (encryptedKey: string, password: string): Promise<PrivateKey> { // eslint-disable-line require-await
|
|
111
114
|
try {
|
|
112
115
|
const key = await importer(encryptedKey, password)
|
|
113
116
|
return await unmarshalPrivateKey(key)
|
package/src/keys/keys.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
|
|
4
|
+
import { enumeration, encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
|
|
5
|
+
import type { Codec } from 'protons-runtime'
|
|
6
|
+
|
|
7
|
+
export enum KeyType {
|
|
8
|
+
RSA = 'RSA',
|
|
9
|
+
Ed25519 = 'Ed25519',
|
|
10
|
+
Secp256k1 = 'Secp256k1'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
enum __KeyTypeValues {
|
|
14
|
+
RSA = 0,
|
|
15
|
+
Ed25519 = 1,
|
|
16
|
+
Secp256k1 = 2
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export namespace KeyType {
|
|
20
|
+
export const codec = () => {
|
|
21
|
+
return enumeration<typeof KeyType>(__KeyTypeValues)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export interface PublicKey {
|
|
25
|
+
Type: KeyType
|
|
26
|
+
Data: Uint8Array
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export namespace PublicKey {
|
|
30
|
+
export const codec = (): Codec<PublicKey> => {
|
|
31
|
+
return message<PublicKey>({
|
|
32
|
+
1: { name: 'Type', codec: KeyType.codec() },
|
|
33
|
+
2: { name: 'Data', codec: bytes }
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const encode = (obj: PublicKey): Uint8Array => {
|
|
38
|
+
return encodeMessage(obj, PublicKey.codec())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const decode = (buf: Uint8Array): PublicKey => {
|
|
42
|
+
return decodeMessage(buf, PublicKey.codec())
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface PrivateKey {
|
|
47
|
+
Type: KeyType
|
|
48
|
+
Data: Uint8Array
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export namespace PrivateKey {
|
|
52
|
+
export const codec = (): Codec<PrivateKey> => {
|
|
53
|
+
return message<PrivateKey>({
|
|
54
|
+
1: { name: 'Type', codec: KeyType.codec() },
|
|
55
|
+
2: { name: 'Data', codec: bytes }
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const encode = (obj: PrivateKey): Uint8Array => {
|
|
60
|
+
return encodeMessage(obj, PrivateKey.codec())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const decode = (buf: Uint8Array): PrivateKey => {
|
|
64
|
+
return decodeMessage(buf, PrivateKey.codec())
|
|
65
|
+
}
|
|
66
|
+
}
|
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/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
|
-
};
|