@libp2p/keychain 4.1.6 → 5.0.0-1210884ed
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/index.min.js +3 -3
- package/dist/src/index.d.ts +31 -51
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keychain.d.ts +9 -54
- package/dist/src/keychain.d.ts.map +1 -1
- package/dist/src/keychain.js +100 -255
- package/dist/src/keychain.js.map +1 -1
- package/dist/src/utils/constants.d.ts +4 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +4 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/export.d.ts +33 -0
- package/dist/src/utils/export.d.ts.map +1 -0
- package/dist/src/utils/export.js +183 -0
- package/dist/src/utils/export.js.map +1 -0
- package/dist/src/utils/import.d.ts +15 -0
- package/dist/src/utils/import.d.ts.map +1 -0
- package/dist/src/utils/import.js +137 -0
- package/dist/src/utils/import.js.map +1 -0
- package/package.json +9 -9
- package/src/index.ts +33 -56
- package/src/keychain.ts +113 -278
- package/src/utils/constants.ts +3 -0
- package/src/utils/export.ts +210 -0
- package/src/utils/import.ts +174 -0
- package/dist/src/errors.d.ts +0 -18
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -19
- package/dist/src/errors.js.map +0 -1
- package/dist/src/util.d.ts +0 -12
- package/dist/src/util.d.ts.map +0 -1
- package/dist/src/util.js +0 -17
- package/dist/src/util.js.map +0 -1
- package/dist/typedoc-urls.json +0 -14
- package/src/errors.ts +0 -17
- package/src/util.ts +0 -16
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { randomBytes } from '@libp2p/crypto'
|
|
2
|
+
import { AES_GCM } from '@libp2p/crypto/ciphers'
|
|
3
|
+
import { privateKeyToProtobuf } from '@libp2p/crypto/keys'
|
|
4
|
+
import webcrypto from '@libp2p/crypto/webcrypto'
|
|
5
|
+
import { InvalidParametersError, UnsupportedKeyTypeError } from '@libp2p/interface'
|
|
6
|
+
import { pbkdf2Async } from '@noble/hashes/pbkdf2'
|
|
7
|
+
import { sha512 } from '@noble/hashes/sha512'
|
|
8
|
+
import * as asn1js from 'asn1js'
|
|
9
|
+
import { base64 } from 'multiformats/bases/base64'
|
|
10
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
11
|
+
import { ITERATIONS, KEY_SIZE, SALT_LENGTH } from './constants.js'
|
|
12
|
+
import type { Ed25519PrivateKey, PrivateKey, RSAPrivateKey, Secp256k1PrivateKey } from '@libp2p/interface'
|
|
13
|
+
import type { Multibase } from 'multiformats/bases/interface'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Exports the given PrivateKey as a base64 encoded string.
|
|
17
|
+
* The PrivateKey is encrypted via a password derived PBKDF2 key
|
|
18
|
+
* leveraging the aes-gcm cipher algorithm.
|
|
19
|
+
*/
|
|
20
|
+
export async function exporter (privateKey: Uint8Array, password: string): Promise<Multibase<'m'>> {
|
|
21
|
+
const cipher = AES_GCM.create()
|
|
22
|
+
const encryptedKey = await cipher.encrypt(privateKey, password)
|
|
23
|
+
return base64.encode(encryptedKey)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ExportFormat = 'pkcs-8' | 'libp2p-key'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Converts an exported private key into its representative object.
|
|
30
|
+
*
|
|
31
|
+
* Supported formats are 'pem' (RSA only) and 'libp2p-key'.
|
|
32
|
+
*/
|
|
33
|
+
export async function exportPrivateKey (key: PrivateKey, password: string, format?: ExportFormat): Promise<Multibase<'m'>> {
|
|
34
|
+
if (key.type === 'RSA') {
|
|
35
|
+
return exportRSAPrivateKey(key, password, format)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (key.type === 'Ed25519') {
|
|
39
|
+
return exportEd25519PrivateKey(key, password, format)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (key.type === 'secp256k1') {
|
|
43
|
+
return exportSecp256k1PrivateKey(key, password, format)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new UnsupportedKeyTypeError()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Exports the key into a password protected `format`
|
|
51
|
+
*/
|
|
52
|
+
export async function exportEd25519PrivateKey (key: Ed25519PrivateKey, password: string, format: ExportFormat = 'libp2p-key'): Promise<Multibase<'m'>> {
|
|
53
|
+
if (format === 'libp2p-key') {
|
|
54
|
+
return exporter(privateKeyToProtobuf(key), password)
|
|
55
|
+
} else {
|
|
56
|
+
throw new InvalidParametersError(`export format '${format}' is not supported`)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Exports the key into a password protected `format`
|
|
62
|
+
*/
|
|
63
|
+
export async function exportSecp256k1PrivateKey (key: Secp256k1PrivateKey, password: string, format: ExportFormat = 'libp2p-key'): Promise<Multibase<'m'>> {
|
|
64
|
+
if (format === 'libp2p-key') {
|
|
65
|
+
return exporter(privateKeyToProtobuf(key), password)
|
|
66
|
+
} else {
|
|
67
|
+
throw new InvalidParametersError('Export format is not supported')
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Exports the key as libp2p-key - a aes-gcm encrypted value with the key
|
|
73
|
+
* derived from the password.
|
|
74
|
+
*
|
|
75
|
+
* To export it as a password protected PEM file, please use the `exportPEM`
|
|
76
|
+
* function from `@libp2p/rsa`.
|
|
77
|
+
*/
|
|
78
|
+
export async function exportRSAPrivateKey (key: RSAPrivateKey, password: string, format: ExportFormat = 'pkcs-8'): Promise<Multibase<'m'>> {
|
|
79
|
+
if (format === 'pkcs-8') {
|
|
80
|
+
return exportToPem(key, password)
|
|
81
|
+
} else if (format === 'libp2p-key') {
|
|
82
|
+
return exporter(privateKeyToProtobuf(key), password)
|
|
83
|
+
} else {
|
|
84
|
+
throw new InvalidParametersError('Export format is not supported')
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function exportToPem (privateKey: RSAPrivateKey, password: string): Promise<string> {
|
|
89
|
+
const crypto = webcrypto.get()
|
|
90
|
+
|
|
91
|
+
// PrivateKeyInfo
|
|
92
|
+
const keyWrapper = new asn1js.Sequence({
|
|
93
|
+
value: [
|
|
94
|
+
// version (0)
|
|
95
|
+
new asn1js.Integer({ value: 0 }),
|
|
96
|
+
|
|
97
|
+
// privateKeyAlgorithm
|
|
98
|
+
new asn1js.Sequence({
|
|
99
|
+
value: [
|
|
100
|
+
// rsaEncryption OID
|
|
101
|
+
new asn1js.ObjectIdentifier({
|
|
102
|
+
value: '1.2.840.113549.1.1.1'
|
|
103
|
+
}),
|
|
104
|
+
new asn1js.Null()
|
|
105
|
+
]
|
|
106
|
+
}),
|
|
107
|
+
|
|
108
|
+
// PrivateKey
|
|
109
|
+
new asn1js.OctetString({
|
|
110
|
+
valueHex: privateKey.raw
|
|
111
|
+
})
|
|
112
|
+
]
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const keyBuf = keyWrapper.toBER()
|
|
116
|
+
const keyArr = new Uint8Array(keyBuf, 0, keyBuf.byteLength)
|
|
117
|
+
const salt = randomBytes(SALT_LENGTH)
|
|
118
|
+
|
|
119
|
+
const encryptionKey = await pbkdf2Async(
|
|
120
|
+
sha512,
|
|
121
|
+
password,
|
|
122
|
+
salt, {
|
|
123
|
+
c: ITERATIONS,
|
|
124
|
+
dkLen: KEY_SIZE
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
const iv = randomBytes(16)
|
|
129
|
+
const cryptoKey = await crypto.subtle.importKey('raw', encryptionKey, 'AES-CBC', false, ['encrypt'])
|
|
130
|
+
const encrypted = await crypto.subtle.encrypt({
|
|
131
|
+
name: 'AES-CBC',
|
|
132
|
+
iv
|
|
133
|
+
}, cryptoKey, keyArr)
|
|
134
|
+
|
|
135
|
+
const pbkdf2Params = new asn1js.Sequence({
|
|
136
|
+
value: [
|
|
137
|
+
// salt
|
|
138
|
+
new asn1js.OctetString({ valueHex: salt }),
|
|
139
|
+
|
|
140
|
+
// iteration count
|
|
141
|
+
new asn1js.Integer({ value: ITERATIONS }),
|
|
142
|
+
|
|
143
|
+
// key length
|
|
144
|
+
new asn1js.Integer({ value: KEY_SIZE }),
|
|
145
|
+
|
|
146
|
+
// AlgorithmIdentifier
|
|
147
|
+
new asn1js.Sequence({
|
|
148
|
+
value: [
|
|
149
|
+
// hmacWithSHA512
|
|
150
|
+
new asn1js.ObjectIdentifier({ value: '1.2.840.113549.2.11' }),
|
|
151
|
+
new asn1js.Null()
|
|
152
|
+
]
|
|
153
|
+
})
|
|
154
|
+
]
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const encryptionAlgorithm = new asn1js.Sequence({
|
|
158
|
+
value: [
|
|
159
|
+
// pkcs5PBES2
|
|
160
|
+
new asn1js.ObjectIdentifier({
|
|
161
|
+
value: '1.2.840.113549.1.5.13'
|
|
162
|
+
}),
|
|
163
|
+
new asn1js.Sequence({
|
|
164
|
+
value: [
|
|
165
|
+
// keyDerivationFunc
|
|
166
|
+
new asn1js.Sequence({
|
|
167
|
+
value: [
|
|
168
|
+
// pkcs5PBKDF2
|
|
169
|
+
new asn1js.ObjectIdentifier({
|
|
170
|
+
value: '1.2.840.113549.1.5.12'
|
|
171
|
+
}),
|
|
172
|
+
// PBKDF2-params
|
|
173
|
+
pbkdf2Params
|
|
174
|
+
]
|
|
175
|
+
}),
|
|
176
|
+
|
|
177
|
+
// encryptionScheme
|
|
178
|
+
new asn1js.Sequence({
|
|
179
|
+
value: [
|
|
180
|
+
// aes256-CBC
|
|
181
|
+
new asn1js.ObjectIdentifier({
|
|
182
|
+
value: '2.16.840.1.101.3.4.1.42'
|
|
183
|
+
}),
|
|
184
|
+
// iv
|
|
185
|
+
new asn1js.OctetString({
|
|
186
|
+
valueHex: iv
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
})
|
|
190
|
+
]
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const finalWrapper = new asn1js.Sequence({
|
|
196
|
+
value: [
|
|
197
|
+
encryptionAlgorithm,
|
|
198
|
+
new asn1js.OctetString({ valueHex: encrypted })
|
|
199
|
+
]
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
const finalWrapperBuf = finalWrapper.toBER()
|
|
203
|
+
const finalWrapperArr = new Uint8Array(finalWrapperBuf, 0, finalWrapperBuf.byteLength)
|
|
204
|
+
|
|
205
|
+
return [
|
|
206
|
+
'-----BEGIN ENCRYPTED PRIVATE KEY-----',
|
|
207
|
+
...uint8ArrayToString(finalWrapperArr, 'base64pad').split(/(.{64})/).filter(Boolean),
|
|
208
|
+
'-----END ENCRYPTED PRIVATE KEY-----'
|
|
209
|
+
].join('\n')
|
|
210
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { AES_GCM } from '@libp2p/crypto/ciphers'
|
|
2
|
+
import { privateKeyFromProtobuf, privateKeyFromRaw } from '@libp2p/crypto/keys'
|
|
3
|
+
import webcrypto from '@libp2p/crypto/webcrypto'
|
|
4
|
+
import { InvalidParametersError } from '@libp2p/interface'
|
|
5
|
+
import { pbkdf2Async } from '@noble/hashes/pbkdf2'
|
|
6
|
+
import { sha512 } from '@noble/hashes/sha512'
|
|
7
|
+
import * as asn1js from 'asn1js'
|
|
8
|
+
import { base64 } from 'multiformats/bases/base64'
|
|
9
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
+
import { ITERATIONS, KEY_SIZE } from './constants.js'
|
|
11
|
+
import type { PrivateKey, RSAPrivateKey } from '@libp2p/interface'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Converts an exported private key into its representative object.
|
|
15
|
+
*
|
|
16
|
+
* Supported formats are 'pem' (RSA only) and 'libp2p-key'.
|
|
17
|
+
*/
|
|
18
|
+
export async function importPrivateKey (encryptedKey: string, password: string): Promise<PrivateKey> {
|
|
19
|
+
try {
|
|
20
|
+
const key = await importer(encryptedKey, password)
|
|
21
|
+
return privateKeyFromProtobuf(key)
|
|
22
|
+
} catch {
|
|
23
|
+
// Ignore and try the old pem decrypt
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!encryptedKey.includes('BEGIN')) {
|
|
27
|
+
throw new InvalidParametersError('Encrypted key was not a libp2p-key or a PEM file')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return importFromPem(encryptedKey, password)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to decrypt a base64 encoded PrivateKey string
|
|
35
|
+
* with the given password. The privateKey must have been exported
|
|
36
|
+
* using the same password and underlying cipher (aes-gcm)
|
|
37
|
+
*/
|
|
38
|
+
export async function importer (privateKey: string, password: string): Promise<Uint8Array> {
|
|
39
|
+
const encryptedKey = base64.decode(privateKey)
|
|
40
|
+
const cipher = AES_GCM.create()
|
|
41
|
+
return cipher.decrypt(encryptedKey, password)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function importFromPem (pem: string, password: string): Promise<RSAPrivateKey> {
|
|
45
|
+
const crypto = webcrypto.get()
|
|
46
|
+
let plaintext: Uint8Array
|
|
47
|
+
|
|
48
|
+
if (pem.includes('-----BEGIN ENCRYPTED PRIVATE KEY-----')) {
|
|
49
|
+
const key = uint8ArrayFromString(
|
|
50
|
+
pem
|
|
51
|
+
.replace('-----BEGIN ENCRYPTED PRIVATE KEY-----', '')
|
|
52
|
+
.replace('-----END ENCRYPTED PRIVATE KEY-----', '')
|
|
53
|
+
.replace(/\n/g, '')
|
|
54
|
+
.trim(),
|
|
55
|
+
'base64pad'
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
const { result } = asn1js.fromBER(key)
|
|
59
|
+
|
|
60
|
+
const {
|
|
61
|
+
iv,
|
|
62
|
+
salt,
|
|
63
|
+
iterations,
|
|
64
|
+
keySize,
|
|
65
|
+
cipherText
|
|
66
|
+
} = findEncryptedPEMData(result)
|
|
67
|
+
|
|
68
|
+
const encryptionKey = await pbkdf2Async(
|
|
69
|
+
sha512,
|
|
70
|
+
password,
|
|
71
|
+
salt, {
|
|
72
|
+
c: iterations,
|
|
73
|
+
dkLen: keySize
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const cryptoKey = await crypto.subtle.importKey('raw', encryptionKey, 'AES-CBC', false, ['decrypt'])
|
|
78
|
+
const decrypted = toUint8Array(await crypto.subtle.decrypt({
|
|
79
|
+
name: 'AES-CBC',
|
|
80
|
+
iv
|
|
81
|
+
}, cryptoKey, cipherText))
|
|
82
|
+
|
|
83
|
+
const { result: decryptedResult } = asn1js.fromBER(decrypted)
|
|
84
|
+
plaintext = findPEMData(decryptedResult)
|
|
85
|
+
} else if (pem.includes('-----BEGIN PRIVATE KEY-----')) {
|
|
86
|
+
const key = uint8ArrayFromString(
|
|
87
|
+
pem
|
|
88
|
+
.replace('-----BEGIN PRIVATE KEY-----', '')
|
|
89
|
+
.replace('-----END PRIVATE KEY-----', '')
|
|
90
|
+
.replace(/\n/g, '')
|
|
91
|
+
.trim(),
|
|
92
|
+
'base64pad'
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
const { result } = asn1js.fromBER(key)
|
|
96
|
+
|
|
97
|
+
plaintext = findPEMData(result)
|
|
98
|
+
} else {
|
|
99
|
+
throw new InvalidParametersError('Could not parse private key from PEM data')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const key = privateKeyFromRaw(plaintext)
|
|
103
|
+
|
|
104
|
+
if (key.type !== 'RSA') {
|
|
105
|
+
throw new InvalidParametersError('Could not parse RSA private key from PEM data')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return key
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function findEncryptedPEMData (root: any): { cipherText: Uint8Array, iv: Uint8Array, salt: Uint8Array, iterations: number, keySize: number } {
|
|
112
|
+
const encryptionAlgorithm = root.valueBlock.value[0]
|
|
113
|
+
const scheme = encryptionAlgorithm.valueBlock.value[0].toString()
|
|
114
|
+
|
|
115
|
+
if (scheme !== 'OBJECT IDENTIFIER : 1.2.840.113549.1.5.13') {
|
|
116
|
+
throw new InvalidParametersError('Only pkcs5PBES2 encrypted private keys are supported')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const keyDerivationFunc = encryptionAlgorithm.valueBlock.value[1].valueBlock.value[0]
|
|
120
|
+
const keyDerivationFuncName = keyDerivationFunc.valueBlock.value[0].toString()
|
|
121
|
+
|
|
122
|
+
if (keyDerivationFuncName !== 'OBJECT IDENTIFIER : 1.2.840.113549.1.5.12') {
|
|
123
|
+
throw new InvalidParametersError('Only pkcs5PBKDF2 key derivation functions are supported')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const pbkdf2Params = keyDerivationFunc.valueBlock.value[1]
|
|
127
|
+
|
|
128
|
+
const salt = toUint8Array(pbkdf2Params.valueBlock.value[0].getValue())
|
|
129
|
+
|
|
130
|
+
let iterations = ITERATIONS
|
|
131
|
+
let keySize = KEY_SIZE
|
|
132
|
+
|
|
133
|
+
if (pbkdf2Params.valueBlock.value.length === 3) {
|
|
134
|
+
iterations = Number((pbkdf2Params.valueBlock.value[1] as asn1js.Integer).toBigInt())
|
|
135
|
+
keySize = Number((pbkdf2Params.valueBlock.value[2]).toBigInt())
|
|
136
|
+
} else if (pbkdf2Params.valueBlock.value.length === 2) {
|
|
137
|
+
throw new InvalidParametersError('Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const encryptionScheme = encryptionAlgorithm.valueBlock.value[1].valueBlock.value[1]
|
|
141
|
+
const encryptionSchemeName = encryptionScheme.valueBlock.value[0].toString()
|
|
142
|
+
|
|
143
|
+
if (encryptionSchemeName === 'OBJECT IDENTIFIER : 1.2.840.113549.3.7') {
|
|
144
|
+
// des-EDE3-CBC
|
|
145
|
+
} else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 1.3.14.3.2.7') {
|
|
146
|
+
// des-CBC
|
|
147
|
+
} else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2') {
|
|
148
|
+
// aes128-CBC
|
|
149
|
+
} else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22') {
|
|
150
|
+
// aes192-CBC
|
|
151
|
+
} else if (encryptionSchemeName === 'OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42') {
|
|
152
|
+
// aes256-CBC
|
|
153
|
+
} else {
|
|
154
|
+
throw new InvalidParametersError('Only AES-CBC encryption schemes are supported')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const iv = toUint8Array(encryptionScheme.valueBlock.value[1].getValue())
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
cipherText: toUint8Array(root.valueBlock.value[1].getValue()),
|
|
161
|
+
salt,
|
|
162
|
+
iterations,
|
|
163
|
+
keySize,
|
|
164
|
+
iv
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function findPEMData (seq: any): Uint8Array {
|
|
169
|
+
return toUint8Array(seq.valueBlock.value[2].getValue())
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function toUint8Array (buf: ArrayBuffer): Uint8Array {
|
|
173
|
+
return new Uint8Array(buf, 0, buf.byteLength)
|
|
174
|
+
}
|
package/dist/src/errors.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare enum codes {
|
|
2
|
-
ERR_INVALID_PARAMETERS = "ERR_INVALID_PARAMETERS",
|
|
3
|
-
ERR_INVALID_KEY_NAME = "ERR_INVALID_KEY_NAME",
|
|
4
|
-
ERR_INVALID_KEY_TYPE = "ERR_INVALID_KEY_TYPE",
|
|
5
|
-
ERR_KEY_ALREADY_EXISTS = "ERR_KEY_ALREADY_EXISTS",
|
|
6
|
-
ERR_INVALID_KEY_SIZE = "ERR_INVALID_KEY_SIZE",
|
|
7
|
-
ERR_KEY_NOT_FOUND = "ERR_KEY_NOT_FOUND",
|
|
8
|
-
ERR_OLD_KEY_NAME_INVALID = "ERR_OLD_KEY_NAME_INVALID",
|
|
9
|
-
ERR_NEW_KEY_NAME_INVALID = "ERR_NEW_KEY_NAME_INVALID",
|
|
10
|
-
ERR_PASSWORD_REQUIRED = "ERR_PASSWORD_REQUIRED",
|
|
11
|
-
ERR_PEM_REQUIRED = "ERR_PEM_REQUIRED",
|
|
12
|
-
ERR_CANNOT_READ_KEY = "ERR_CANNOT_READ_KEY",
|
|
13
|
-
ERR_MISSING_PRIVATE_KEY = "ERR_MISSING_PRIVATE_KEY",
|
|
14
|
-
ERR_INVALID_OLD_PASS_TYPE = "ERR_INVALID_OLD_PASS_TYPE",
|
|
15
|
-
ERR_INVALID_NEW_PASS_TYPE = "ERR_INVALID_NEW_PASS_TYPE",
|
|
16
|
-
ERR_INVALID_PASS_LENGTH = "ERR_INVALID_PASS_LENGTH"
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/src/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK;IACf,sBAAsB,2BAA2B;IACjD,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;IAC7C,sBAAsB,2BAA2B;IACjD,oBAAoB,yBAAyB;IAC7C,iBAAiB,sBAAsB;IACvC,wBAAwB,6BAA6B;IACrD,wBAAwB,6BAA6B;IACrD,qBAAqB,0BAA0B;IAC/C,gBAAgB,qBAAqB;IACrC,mBAAmB,wBAAwB;IAC3C,uBAAuB,4BAA4B;IACnD,yBAAyB,8BAA8B;IACvD,yBAAyB,8BAA8B;IACvD,uBAAuB,4BAA4B;CACpD"}
|
package/dist/src/errors.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export var codes;
|
|
2
|
-
(function (codes) {
|
|
3
|
-
codes["ERR_INVALID_PARAMETERS"] = "ERR_INVALID_PARAMETERS";
|
|
4
|
-
codes["ERR_INVALID_KEY_NAME"] = "ERR_INVALID_KEY_NAME";
|
|
5
|
-
codes["ERR_INVALID_KEY_TYPE"] = "ERR_INVALID_KEY_TYPE";
|
|
6
|
-
codes["ERR_KEY_ALREADY_EXISTS"] = "ERR_KEY_ALREADY_EXISTS";
|
|
7
|
-
codes["ERR_INVALID_KEY_SIZE"] = "ERR_INVALID_KEY_SIZE";
|
|
8
|
-
codes["ERR_KEY_NOT_FOUND"] = "ERR_KEY_NOT_FOUND";
|
|
9
|
-
codes["ERR_OLD_KEY_NAME_INVALID"] = "ERR_OLD_KEY_NAME_INVALID";
|
|
10
|
-
codes["ERR_NEW_KEY_NAME_INVALID"] = "ERR_NEW_KEY_NAME_INVALID";
|
|
11
|
-
codes["ERR_PASSWORD_REQUIRED"] = "ERR_PASSWORD_REQUIRED";
|
|
12
|
-
codes["ERR_PEM_REQUIRED"] = "ERR_PEM_REQUIRED";
|
|
13
|
-
codes["ERR_CANNOT_READ_KEY"] = "ERR_CANNOT_READ_KEY";
|
|
14
|
-
codes["ERR_MISSING_PRIVATE_KEY"] = "ERR_MISSING_PRIVATE_KEY";
|
|
15
|
-
codes["ERR_INVALID_OLD_PASS_TYPE"] = "ERR_INVALID_OLD_PASS_TYPE";
|
|
16
|
-
codes["ERR_INVALID_NEW_PASS_TYPE"] = "ERR_INVALID_NEW_PASS_TYPE";
|
|
17
|
-
codes["ERR_INVALID_PASS_LENGTH"] = "ERR_INVALID_PASS_LENGTH";
|
|
18
|
-
})(codes || (codes = {}));
|
|
19
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,KAgBX;AAhBD,WAAY,KAAK;IACf,0DAAiD,CAAA;IACjD,sDAA6C,CAAA;IAC7C,sDAA6C,CAAA;IAC7C,0DAAiD,CAAA;IACjD,sDAA6C,CAAA;IAC7C,gDAAuC,CAAA;IACvC,8DAAqD,CAAA;IACrD,8DAAqD,CAAA;IACrD,wDAA+C,CAAA;IAC/C,8CAAqC,CAAA;IACrC,oDAA2C,CAAA;IAC3C,4DAAmD,CAAA;IACnD,gEAAuD,CAAA;IACvD,gEAAuD,CAAA;IACvD,4DAAmD,CAAA;AACrD,CAAC,EAhBW,KAAK,KAAL,KAAK,QAgBhB"}
|
package/dist/src/util.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds the first item in a collection that is matched in the
|
|
3
|
-
* `asyncCompare` function.
|
|
4
|
-
*
|
|
5
|
-
* `asyncCompare` is an async function that must
|
|
6
|
-
* resolve to either `true` or `false`.
|
|
7
|
-
*
|
|
8
|
-
* @param {Array} array
|
|
9
|
-
* @param {function(*)} asyncCompare - An async function that returns a boolean
|
|
10
|
-
*/
|
|
11
|
-
export declare function findAsync<T>(array: T[], asyncCompare: (val: T) => Promise<any>): Promise<T | undefined>;
|
|
12
|
-
//# sourceMappingURL=util.d.ts.map
|
package/dist/src/util.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAE,CAAC,EAAG,KAAK,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAK/G"}
|
package/dist/src/util.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds the first item in a collection that is matched in the
|
|
3
|
-
* `asyncCompare` function.
|
|
4
|
-
*
|
|
5
|
-
* `asyncCompare` is an async function that must
|
|
6
|
-
* resolve to either `true` or `false`.
|
|
7
|
-
*
|
|
8
|
-
* @param {Array} array
|
|
9
|
-
* @param {function(*)} asyncCompare - An async function that returns a boolean
|
|
10
|
-
*/
|
|
11
|
-
export async function findAsync(array, asyncCompare) {
|
|
12
|
-
const promises = array.map(asyncCompare);
|
|
13
|
-
const results = await Promise.all(promises);
|
|
14
|
-
const index = results.findIndex(result => result);
|
|
15
|
-
return array[index];
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=util.js.map
|
package/dist/src/util.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAM,KAAU,EAAE,YAAsC;IACrF,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACxC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAA;IACjD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"DEKConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.DEKConfig.html",
|
|
3
|
-
".:DEKConfig": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.DEKConfig.html",
|
|
4
|
-
"KeyInfo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeyInfo.html",
|
|
5
|
-
".:KeyInfo": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeyInfo.html",
|
|
6
|
-
"Keychain": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.Keychain.html",
|
|
7
|
-
".:Keychain": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.Keychain.html",
|
|
8
|
-
"KeychainComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainComponents.html",
|
|
9
|
-
".:KeychainComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainComponents.html",
|
|
10
|
-
"KeychainInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainInit.html",
|
|
11
|
-
".:KeychainInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_keychain.KeychainInit.html",
|
|
12
|
-
"keychain": "https://libp2p.github.io/js-libp2p/functions/_libp2p_keychain.keychain-1.html",
|
|
13
|
-
".:keychain": "https://libp2p.github.io/js-libp2p/functions/_libp2p_keychain.keychain-1.html"
|
|
14
|
-
}
|
package/src/errors.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export enum codes {
|
|
2
|
-
ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS',
|
|
3
|
-
ERR_INVALID_KEY_NAME = 'ERR_INVALID_KEY_NAME',
|
|
4
|
-
ERR_INVALID_KEY_TYPE = 'ERR_INVALID_KEY_TYPE',
|
|
5
|
-
ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS',
|
|
6
|
-
ERR_INVALID_KEY_SIZE = 'ERR_INVALID_KEY_SIZE',
|
|
7
|
-
ERR_KEY_NOT_FOUND = 'ERR_KEY_NOT_FOUND',
|
|
8
|
-
ERR_OLD_KEY_NAME_INVALID = 'ERR_OLD_KEY_NAME_INVALID',
|
|
9
|
-
ERR_NEW_KEY_NAME_INVALID = 'ERR_NEW_KEY_NAME_INVALID',
|
|
10
|
-
ERR_PASSWORD_REQUIRED = 'ERR_PASSWORD_REQUIRED',
|
|
11
|
-
ERR_PEM_REQUIRED = 'ERR_PEM_REQUIRED',
|
|
12
|
-
ERR_CANNOT_READ_KEY = 'ERR_CANNOT_READ_KEY',
|
|
13
|
-
ERR_MISSING_PRIVATE_KEY = 'ERR_MISSING_PRIVATE_KEY',
|
|
14
|
-
ERR_INVALID_OLD_PASS_TYPE = 'ERR_INVALID_OLD_PASS_TYPE',
|
|
15
|
-
ERR_INVALID_NEW_PASS_TYPE = 'ERR_INVALID_NEW_PASS_TYPE',
|
|
16
|
-
ERR_INVALID_PASS_LENGTH = 'ERR_INVALID_PASS_LENGTH'
|
|
17
|
-
}
|
package/src/util.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds the first item in a collection that is matched in the
|
|
3
|
-
* `asyncCompare` function.
|
|
4
|
-
*
|
|
5
|
-
* `asyncCompare` is an async function that must
|
|
6
|
-
* resolve to either `true` or `false`.
|
|
7
|
-
*
|
|
8
|
-
* @param {Array} array
|
|
9
|
-
* @param {function(*)} asyncCompare - An async function that returns a boolean
|
|
10
|
-
*/
|
|
11
|
-
export async function findAsync <T> (array: T[], asyncCompare: (val: T) => Promise<any>): Promise<T | undefined> {
|
|
12
|
-
const promises = array.map(asyncCompare)
|
|
13
|
-
const results = await Promise.all(promises)
|
|
14
|
-
const index = results.findIndex(result => result)
|
|
15
|
-
return array[index]
|
|
16
|
-
}
|