@libp2p/config 1.0.3 → 1.1.0
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.
|
@@ -3,19 +3,19 @@ import { keychain } from '@libp2p/keychain';
|
|
|
3
3
|
import { defaultLogger } from '@libp2p/logger';
|
|
4
4
|
import { Key } from 'interface-datastore';
|
|
5
5
|
export async function loadOrCreateSelfKey(datastore, init = {}) {
|
|
6
|
+
const selfKey = init.selfKey ?? 'self';
|
|
6
7
|
const chain = keychain(init)({
|
|
7
8
|
datastore,
|
|
8
9
|
logger: defaultLogger()
|
|
9
10
|
});
|
|
10
|
-
const selfKey = new Key('/pkcs8/self');
|
|
11
11
|
let privateKey;
|
|
12
|
-
if (await datastore.has(selfKey)) {
|
|
13
|
-
privateKey = await chain.exportKey(
|
|
12
|
+
if (await datastore.has(new Key(`/pkcs8/${selfKey}`))) {
|
|
13
|
+
privateKey = await chain.exportKey(selfKey);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
privateKey = await generateKeyPair(init.keyType ?? 'Ed25519');
|
|
17
17
|
// persist the peer id in the keychain for next time
|
|
18
|
-
await chain.importKey(
|
|
18
|
+
await chain.importKey(selfKey, privateKey);
|
|
19
19
|
}
|
|
20
20
|
return privateKey;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-private-key.js","sourceRoot":"","sources":["../../src/load-private-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAczC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAE,SAAoB,EAAE,OAAmC,EAAE;IACpG,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,SAAS;QACT,MAAM,EAAE,aAAa,EAAE;KACxB,CAAC,CAAA;IAEF,
|
|
1
|
+
{"version":3,"file":"load-private-key.js","sourceRoot":"","sources":["../../src/load-private-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAczC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAE,SAAoB,EAAE,OAAmC,EAAE;IACpG,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,CAAA;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,SAAS;QACT,MAAM,EAAE,aAAa,EAAE;KACxB,CAAC,CAAA;IAEF,IAAI,UAAU,CAAA;IAEd,IAAI,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;QACtD,UAAU,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,IAAI,SAAS,CAAC,CAAA;QAE7D,oDAAoD;QACpD,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAC5C,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/config",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Helper functions to make dealing with libp2p config easier",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/config#readme",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/crypto": "^5.0.
|
|
49
|
-
"@libp2p/interface": "^2.
|
|
50
|
-
"@libp2p/keychain": "^5.0
|
|
51
|
-
"@libp2p/logger": "^5.1.
|
|
48
|
+
"@libp2p/crypto": "^5.0.12",
|
|
49
|
+
"@libp2p/interface": "^2.6.0",
|
|
50
|
+
"@libp2p/keychain": "^5.1.0",
|
|
51
|
+
"@libp2p/logger": "^5.1.9",
|
|
52
52
|
"interface-datastore": "^8.3.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
package/src/load-private-key.ts
CHANGED
|
@@ -16,21 +16,21 @@ export interface LoadOrCreateSelfKeyOptions extends KeychainInit {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export async function loadOrCreateSelfKey (datastore: Datastore, init: LoadOrCreateSelfKeyOptions = {}): Promise<PrivateKey> {
|
|
19
|
+
const selfKey = init.selfKey ?? 'self'
|
|
19
20
|
const chain = keychain(init)({
|
|
20
21
|
datastore,
|
|
21
22
|
logger: defaultLogger()
|
|
22
23
|
})
|
|
23
24
|
|
|
24
|
-
const selfKey = new Key('/pkcs8/self')
|
|
25
25
|
let privateKey
|
|
26
26
|
|
|
27
|
-
if (await datastore.has(selfKey)) {
|
|
28
|
-
privateKey = await chain.exportKey(
|
|
27
|
+
if (await datastore.has(new Key(`/pkcs8/${selfKey}`))) {
|
|
28
|
+
privateKey = await chain.exportKey(selfKey)
|
|
29
29
|
} else {
|
|
30
30
|
privateKey = await generateKeyPair(init.keyType ?? 'Ed25519')
|
|
31
31
|
|
|
32
32
|
// persist the peer id in the keychain for next time
|
|
33
|
-
await chain.importKey(
|
|
33
|
+
await chain.importKey(selfKey, privateKey)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
return privateKey
|