@libp2p/crypto 1.0.12 → 1.0.14
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 +2 -2
- package/dist/src/aes/cipher-mode.d.ts.map +1 -1
- package/dist/src/aes/ciphers-browser.d.ts +4 -5
- package/dist/src/aes/ciphers-browser.d.ts.map +1 -1
- package/dist/src/aes/ciphers-browser.js.map +1 -1
- package/dist/src/aes/index.d.ts.map +1 -1
- package/dist/src/ciphers/aes-gcm.browser.d.ts.map +1 -1
- package/dist/src/ciphers/aes-gcm.d.ts.map +1 -1
- package/dist/src/hmac/index-browser.d.ts +1 -1
- package/dist/src/hmac/index-browser.d.ts.map +1 -1
- package/dist/src/hmac/index-browser.js.map +1 -1
- package/dist/src/hmac/index.d.ts +4 -3
- package/dist/src/hmac/index.d.ts.map +1 -1
- package/dist/src/hmac/index.js.map +1 -1
- package/dist/src/keys/ecdh-browser.d.ts.map +1 -1
- package/dist/src/keys/ecdh-browser.js.map +1 -1
- package/dist/src/keys/ed25519-browser.d.ts +3 -8
- package/dist/src/keys/ed25519-browser.d.ts.map +1 -1
- package/dist/src/keys/ed25519-browser.js.map +1 -1
- package/dist/src/keys/ed25519-class.d.ts +3 -3
- package/dist/src/keys/ed25519-class.d.ts.map +1 -1
- package/dist/src/keys/ed25519-class.js +1 -1
- package/dist/src/keys/ed25519-class.js.map +1 -1
- package/dist/src/keys/ed25519.d.ts +3 -8
- package/dist/src/keys/ed25519.d.ts.map +1 -1
- package/dist/src/keys/ed25519.js.map +1 -1
- package/dist/src/keys/exporter.d.ts +2 -1
- package/dist/src/keys/exporter.d.ts.map +1 -1
- package/dist/src/keys/exporter.js.map +1 -1
- package/dist/src/keys/importer.d.ts.map +1 -1
- package/dist/src/keys/interface.d.ts +19 -0
- package/dist/src/keys/interface.d.ts.map +1 -1
- package/dist/src/keys/jwk2pem.d.ts +6 -2
- package/dist/src/keys/jwk2pem.d.ts.map +1 -1
- package/dist/src/keys/jwk2pem.js.map +1 -1
- package/dist/src/keys/key-stretcher.d.ts +2 -12
- package/dist/src/keys/key-stretcher.d.ts.map +1 -1
- package/dist/src/keys/key-stretcher.js.map +1 -1
- package/dist/src/keys/keys.d.ts +3 -3
- package/dist/src/keys/keys.d.ts.map +1 -1
- package/dist/src/keys/keys.js +1 -0
- package/dist/src/keys/keys.js.map +1 -1
- package/dist/src/keys/rsa-browser.d.ts +3 -8
- package/dist/src/keys/rsa-browser.d.ts.map +1 -1
- package/dist/src/keys/rsa-browser.js.map +1 -1
- package/dist/src/keys/rsa-class.d.ts +5 -5
- package/dist/src/keys/rsa-class.d.ts.map +1 -1
- package/dist/src/keys/rsa-class.js.map +1 -1
- package/dist/src/keys/rsa-utils.d.ts.map +1 -1
- package/dist/src/keys/rsa.d.ts +3 -4
- package/dist/src/keys/rsa.d.ts.map +1 -1
- package/dist/src/keys/secp256k1-class.d.ts +2 -1
- package/dist/src/keys/secp256k1-class.d.ts.map +1 -1
- package/dist/src/keys/secp256k1-class.js +1 -1
- package/dist/src/keys/secp256k1-class.js.map +1 -1
- package/dist/src/keys/secp256k1.d.ts.map +1 -1
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js.map +1 -1
- package/dist/typedoc-urls.json +3 -0
- package/package.json +7 -8
- package/src/aes/cipher-mode.ts +1 -1
- package/src/aes/ciphers-browser.ts +6 -2
- package/src/aes/index.ts +1 -1
- package/src/ciphers/aes-gcm.browser.ts +3 -3
- package/src/ciphers/aes-gcm.ts +5 -5
- package/src/hmac/index-browser.ts +2 -2
- package/src/hmac/index.ts +6 -1
- package/src/keys/ecdh-browser.ts +6 -6
- package/src/keys/ed25519-browser.ts +6 -5
- package/src/keys/ed25519-class.ts +20 -19
- package/src/keys/ed25519.ts +6 -5
- package/src/keys/exporter.ts +2 -1
- package/src/keys/importer.ts +1 -1
- package/src/keys/index.ts +2 -2
- package/src/keys/interface.ts +15 -0
- package/src/keys/jwk2pem.ts +8 -3
- package/src/keys/key-stretcher.ts +3 -2
- package/src/keys/keys.ts +5 -4
- package/src/keys/rsa-browser.ts +10 -9
- package/src/keys/rsa-class.ts +21 -20
- package/src/keys/rsa-utils.ts +2 -2
- package/src/keys/rsa.ts +4 -4
- package/src/keys/secp256k1-class.ts +18 -17
- package/src/keys/secp256k1.ts +8 -8
- package/src/util.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa-utils.d.ts","sourceRoot":"","sources":["../../../src/keys/rsa-utils.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,uBAAuB,CAAA;AAS9B,wBAAgB,UAAU,CAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAiBzD;AAGD,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"rsa-utils.d.ts","sourceRoot":"","sources":["../../../src/keys/rsa-utils.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,uBAAuB,CAAA;AAS9B,wBAAgB,UAAU,CAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAiBzD;AAGD,wBAAgB,UAAU,CAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAiBvD;AAGD,wBAAgB,SAAS,CAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CASxD;AAGD,wBAAgB,SAAS,CAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAWtD"}
|
package/dist/src/keys/rsa.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import randomBytes from '../random-bytes.js';
|
|
3
2
|
import * as utils from './rsa-utils.js';
|
|
4
3
|
import type { JWKKeyPair } from './interface.js';
|
|
@@ -6,8 +5,8 @@ export { utils };
|
|
|
6
5
|
export declare function generateKey(bits: number): Promise<JWKKeyPair>;
|
|
7
6
|
export declare function unmarshalPrivateKey(key: JsonWebKey): Promise<JWKKeyPair>;
|
|
8
7
|
export { randomBytes as getRandomValues };
|
|
9
|
-
export declare function hashAndSign(key: JsonWebKey, msg: Uint8Array): Promise<
|
|
8
|
+
export declare function hashAndSign(key: JsonWebKey, msg: Uint8Array): Promise<Uint8Array>;
|
|
10
9
|
export declare function hashAndVerify(key: JsonWebKey, sig: Uint8Array, msg: Uint8Array): Promise<boolean>;
|
|
11
|
-
export declare function encrypt(key: JsonWebKey, bytes: Uint8Array):
|
|
12
|
-
export declare function decrypt(key: JsonWebKey, bytes: Uint8Array):
|
|
10
|
+
export declare function encrypt(key: JsonWebKey, bytes: Uint8Array): Uint8Array;
|
|
11
|
+
export declare function decrypt(key: JsonWebKey, bytes: Uint8Array): Uint8Array;
|
|
13
12
|
//# sourceMappingURL=rsa.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/keys/rsa.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsa.d.ts","sourceRoot":"","sources":["../../../src/keys/rsa.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAIhD,OAAO,EAAE,KAAK,EAAE,CAAA;AAEhB,wBAAsB,WAAW,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAcpE;AAGD,wBAAsB,mBAAmB,CAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAY/E;AAED,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,CAAA;AAEzC,wBAAsB,WAAW,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAKxF;AAED,wBAAsB,aAAa,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAKxG;AAID,wBAAgB,OAAO,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAGvE;AAED,wBAAgB,OAAO,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,CAGvE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Multibase } from 'multiformats';
|
|
1
2
|
export declare class Secp256k1PublicKey {
|
|
2
3
|
private readonly _key;
|
|
3
4
|
constructor(key: Uint8Array);
|
|
@@ -28,7 +29,7 @@ export declare class Secp256k1PrivateKey {
|
|
|
28
29
|
/**
|
|
29
30
|
* Exports the key into a password protected `format`
|
|
30
31
|
*/
|
|
31
|
-
export(password: string, format?: string): Promise<
|
|
32
|
+
export(password: string, format?: string): Promise<Multibase<'m'>>;
|
|
32
33
|
}
|
|
33
34
|
export declare function unmarshalSecp256k1PrivateKey(bytes: Uint8Array): Secp256k1PrivateKey;
|
|
34
35
|
export declare function unmarshalSecp256k1PublicKey(bytes: Uint8Array): Secp256k1PublicKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1-class.d.ts","sourceRoot":"","sources":["../../../src/keys/secp256k1-class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secp256k1-class.d.ts","sourceRoot":"","sources":["../../../src/keys/secp256k1-class.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;gBAEpB,GAAG,EAAE,UAAU;IAKtB,MAAM,CAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlE,OAAO,IAAK,UAAU;IAItB,IAAI,KAAK,IAAK,UAAU,CAKvB;IAED,MAAM,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO;IAIpB,IAAI,IAAK,OAAO,CAAC,UAAU,CAAC;CAKnC;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;gBAE1B,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,UAAU;IAO9C,IAAI,CAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAIrD,IAAI,MAAM,IAAK,kBAAkB,CAEhC;IAED,OAAO,IAAK,UAAU;IAItB,IAAI,KAAK,IAAK,UAAU,CAKvB;IAED,MAAM,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO;IAIpB,IAAI,IAAK,OAAO,CAAC,UAAU,CAAC;IAMlC;;;;;;OAMG;IACG,EAAE,IAAK,OAAO,CAAC,MAAM,CAAC;IAK5B;;OAEG;IACG,MAAM,CAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAe,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;CAOhF;AAED,wBAAgB,4BAA4B,CAAE,KAAK,EAAE,UAAU,GAAG,mBAAmB,CAEpF;AAED,wBAAgB,2BAA2B,CAAE,KAAK,EAAE,UAAU,GAAG,kBAAkB,CAElF;AAED,wBAAsB,eAAe,IAAK,OAAO,CAAC,mBAAmB,CAAC,CAGrE"}
|
|
@@ -89,7 +89,7 @@ export function unmarshalSecp256k1PublicKey(bytes) {
|
|
|
89
89
|
return new Secp256k1PublicKey(bytes);
|
|
90
90
|
}
|
|
91
91
|
export async function generateKeyPair() {
|
|
92
|
-
const privateKeyBytes =
|
|
92
|
+
const privateKeyBytes = crypto.generateKey();
|
|
93
93
|
return new Secp256k1PrivateKey(privateKeyBytes);
|
|
94
94
|
}
|
|
95
95
|
//# sourceMappingURL=secp256k1-class.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1-class.js","sourceRoot":"","sources":["../../../src/keys/secp256k1-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,YAAY,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"secp256k1-class.js","sourceRoot":"","sources":["../../../src/keys/secp256k1-class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,YAAY,MAAM,WAAW,CAAA;AAGzC,MAAM,OAAO,kBAAkB;IAG7B,YAAa,GAAe;QAC1B,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;IACjB,CAAC;IAED,KAAK,CAAC,MAAM,CAAE,IAAgB,EAAE,GAAe;QAC7C,OAAO,MAAM,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,OAAO;QACL,OAAO,MAAM,CA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1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["../../../src/keys/secp256k1.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,uBAAuB,KAAK,CAAA;AAElC,OAAO,EAAE,uBAAuB,IAAI,gBAAgB,EAAE,CAAA;AAEtD,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["../../../src/keys/secp256k1.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,uBAAuB,KAAK,CAAA;AAElC,OAAO,EAAE,uBAAuB,IAAI,gBAAgB,EAAE,CAAA;AAEtD,wBAAgB,WAAW,IAAK,UAAU,CAEzC;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAOxF;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxG;AAED,wBAAgB,iBAAiB,CAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAG9D;AAED,wBAAgB,mBAAmB,CAAE,GAAG,EAAE,UAAU,GAAG,UAAU,CAGhE;AAED,wBAAgB,kBAAkB,CAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAMzD;AAED,wBAAgB,iBAAiB,CAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAMxD;AAED,wBAAgB,gBAAgB,CAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAMpE"}
|
package/dist/src/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAE/B,OAAO,KAAK,MAAM,yBAAyB,CAAA;AAK3C,wBAAgB,yBAAyB,CAAE,GAAG,EAAE;IAAE,GAAG,EAAE,MAAM,GAAG,CAAA;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAE/B,OAAO,KAAK,MAAM,yBAAyB,CAAA;AAK3C,wBAAgB,yBAAyB,CAAE,GAAG,EAAE;IAAE,GAAG,EAAE,MAAM,GAAG,CAAA;CAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBxF;AAGD,wBAAgB,qBAAqB,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAGhF;AAED,wBAAgB,iBAAiB,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU,CASxE"}
|
package/dist/src/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAC/B,qCAAqC;AACrC,OAAO,KAAK,MAAM,yBAAyB,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/D,MAAM,UAAU,yBAAyB,CAAE,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,wBAAwB,CAAA;AAC/B,qCAAqC;AACrC,OAAO,KAAK,MAAM,yBAAyB,CAAA;AAC3C,OAAO,EAAE,UA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Ac,CAAC,CAAA;IAEnD,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAC9E,GAAG,GAAG,gBAAgB,CAAC,CAAC,IAAI,UAAU,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;KAChE;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/dist/typedoc-urls.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"AESCipher": "https://libp2p.github.io/js-libp2p-crypto/interfaces/aes.AESCipher.html",
|
|
3
3
|
"create": "https://libp2p.github.io/js-libp2p-crypto/functions/aes.create.html",
|
|
4
|
+
"HMAC": "https://libp2p.github.io/js-libp2p-crypto/interfaces/hmac.HMAC.html",
|
|
4
5
|
"pbkdf2": "https://libp2p.github.io/js-libp2p-crypto/functions/index.pbkdf2.html",
|
|
5
6
|
"randomBytes": "https://libp2p.github.io/js-libp2p-crypto/functions/index.randomBytes.html",
|
|
6
7
|
"Ed25519PrivateKey": "https://libp2p.github.io/js-libp2p-crypto/classes/keys._internal_.__home_runner_work_js_libp2p_crypto_js_libp2p_crypto_src_keys_ed25519_class_.Ed25519PrivateKey.html",
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
"unmarshalSecp256k1PublicKey": "https://libp2p.github.io/js-libp2p-crypto/functions/keys._internal_.__home_runner_work_js_libp2p_crypto_js_libp2p_crypto_src_keys_secp256k1_class_.unmarshalSecp256k1PublicKey.html",
|
|
21
22
|
"ECDHKey": "https://libp2p.github.io/js-libp2p-crypto/interfaces/keys._internal_.ECDHKey.html",
|
|
22
23
|
"ECDHKeyPair": "https://libp2p.github.io/js-libp2p-crypto/interfaces/keys._internal_.ECDHKeyPair.html",
|
|
24
|
+
"EnhancedKey": "https://libp2p.github.io/js-libp2p-crypto/interfaces/keys._internal_.EnhancedKey.html",
|
|
25
|
+
"EnhancedKeyPair": "https://libp2p.github.io/js-libp2p-crypto/interfaces/keys._internal_.EnhancedKeyPair.html",
|
|
23
26
|
"codec": "https://libp2p.github.io/js-libp2p-crypto/functions/keys.keysPBM.KeyType.codec.html",
|
|
24
27
|
"decode": "https://libp2p.github.io/js-libp2p-crypto/functions/keys.keysPBM.PrivateKey.decode.html",
|
|
25
28
|
"encode": "https://libp2p.github.io/js-libp2p-crypto/functions/keys.keysPBM.PrivateKey.encode.html",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/crypto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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",
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"scripts": {
|
|
166
166
|
"clean": "aegir clean",
|
|
167
167
|
"lint": "aegir lint",
|
|
168
|
-
"dep-check": "aegir dep-check",
|
|
168
|
+
"dep-check": "aegir dep-check -i protons",
|
|
169
169
|
"build": "aegir build",
|
|
170
170
|
"test": "aegir test",
|
|
171
171
|
"test:chrome": "aegir test -t browser",
|
|
@@ -185,17 +185,16 @@
|
|
|
185
185
|
"@noble/secp256k1": "^1.5.4",
|
|
186
186
|
"multiformats": "^11.0.0",
|
|
187
187
|
"node-forge": "^1.1.0",
|
|
188
|
-
"protons-runtime": "^
|
|
188
|
+
"protons-runtime": "^5.0.0",
|
|
189
|
+
"uint8arraylist": "^2.4.3",
|
|
189
190
|
"uint8arrays": "^4.0.2"
|
|
190
191
|
},
|
|
191
192
|
"devDependencies": {
|
|
192
193
|
"@types/mocha": "^10.0.0",
|
|
193
|
-
"aegir": "^
|
|
194
|
+
"aegir": "^38.1.2",
|
|
194
195
|
"benchmark": "^2.1.4",
|
|
195
|
-
"protons": "^
|
|
196
|
-
"
|
|
197
|
-
"util": "^0.12.3",
|
|
198
|
-
"wherearewe": "^2.0.1"
|
|
196
|
+
"protons": "^7.0.2",
|
|
197
|
+
"util": "^0.12.5"
|
|
199
198
|
},
|
|
200
199
|
"browser": {
|
|
201
200
|
"./dist/src/aes/ciphers.js": "./dist/src/aes/ciphers-browser.js",
|
package/src/aes/cipher-mode.ts
CHANGED
|
@@ -5,7 +5,11 @@ import forge from 'node-forge/lib/forge.js'
|
|
|
5
5
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
6
6
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface Cipher {
|
|
9
|
+
update: (data: Uint8Array) => Uint8Array
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher {
|
|
9
13
|
const cipher2 = forge.cipher.createCipher('AES-CTR', uint8ArrayToString(key, 'ascii'))
|
|
10
14
|
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') })
|
|
11
15
|
return {
|
|
@@ -16,7 +20,7 @@ export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array) {
|
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array) {
|
|
23
|
+
export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher {
|
|
20
24
|
const cipher2 = forge.cipher.createDecipher('AES-CTR', uint8ArrayToString(key, 'ascii'))
|
|
21
25
|
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') })
|
|
22
26
|
return {
|
package/src/aes/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface AESCipher {
|
|
|
6
6
|
decrypt: (data: Uint8Array) => Promise<Uint8Array>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export async function create (key: Uint8Array, iv: Uint8Array) { // eslint-disable-line require-await
|
|
9
|
+
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> { // eslint-disable-line require-await
|
|
10
10
|
const mode = cipherMode(key)
|
|
11
11
|
const cipher = ciphers.createCipheriv(mode, key, iv)
|
|
12
12
|
const decipher = ciphers.createDecipheriv(mode, key, iv)
|
|
@@ -5,7 +5,7 @@ import type { CreateOptions, AESCipher } from './interface.js'
|
|
|
5
5
|
|
|
6
6
|
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
|
|
7
7
|
|
|
8
|
-
export function create (opts?: CreateOptions) {
|
|
8
|
+
export function create (opts?: CreateOptions): AESCipher {
|
|
9
9
|
const algorithm = opts?.algorithm ?? 'AES-GCM'
|
|
10
10
|
let keyLength = opts?.keyLength ?? 16
|
|
11
11
|
const nonceLength = opts?.nonceLength ?? 12
|
|
@@ -20,7 +20,7 @@ export function create (opts?: CreateOptions) {
|
|
|
20
20
|
* Uses the provided password to derive a pbkdf2 key. The key
|
|
21
21
|
* will then be used to encrypt the data.
|
|
22
22
|
*/
|
|
23
|
-
async function encrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
|
|
23
|
+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
24
24
|
const salt = crypto.getRandomValues(new Uint8Array(saltLength))
|
|
25
25
|
const nonce = crypto.getRandomValues(new Uint8Array(nonceLength))
|
|
26
26
|
const aesGcm = { name: algorithm, iv: nonce }
|
|
@@ -45,7 +45,7 @@ export function create (opts?: CreateOptions) {
|
|
|
45
45
|
* this decryption cipher must be the same as those used to create
|
|
46
46
|
* the encryption cipher.
|
|
47
47
|
*/
|
|
48
|
-
async function decrypt (data: Uint8Array, password: string | Uint8Array) {
|
|
48
|
+
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
|
|
49
49
|
const salt = data.subarray(0, saltLength)
|
|
50
50
|
const nonce = data.subarray(saltLength, saltLength + nonceLength)
|
|
51
51
|
const ciphertext = data.subarray(saltLength + nonceLength)
|
package/src/ciphers/aes-gcm.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { CreateOptions, AESCipher } from './interface.js'
|
|
|
5
5
|
|
|
6
6
|
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
|
|
7
7
|
|
|
8
|
-
export function create (opts?: CreateOptions) {
|
|
8
|
+
export function create (opts?: CreateOptions): AESCipher {
|
|
9
9
|
const algorithm = opts?.algorithm ?? 'aes-128-gcm'
|
|
10
10
|
const keyLength = opts?.keyLength ?? 16
|
|
11
11
|
const nonceLength = opts?.nonceLength ?? 12
|
|
@@ -14,7 +14,7 @@ export function create (opts?: CreateOptions) {
|
|
|
14
14
|
const iterations = opts?.iterations ?? 32767
|
|
15
15
|
const algorithmTagLength = opts?.algorithmTagLength ?? 16
|
|
16
16
|
|
|
17
|
-
async function encryptWithKey (data: Uint8Array, key: Uint8Array) { // eslint-disable-line require-await
|
|
17
|
+
async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
18
18
|
const nonce = crypto.randomBytes(nonceLength)
|
|
19
19
|
|
|
20
20
|
// Create the cipher instance.
|
|
@@ -31,7 +31,7 @@ export function create (opts?: CreateOptions) {
|
|
|
31
31
|
* Uses the provided password to derive a pbkdf2 key. The key
|
|
32
32
|
* will then be used to encrypt the data.
|
|
33
33
|
*/
|
|
34
|
-
async function encrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
|
|
34
|
+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
35
35
|
// Generate a 128-bit salt using a CSPRNG.
|
|
36
36
|
const salt = crypto.randomBytes(saltLength)
|
|
37
37
|
|
|
@@ -53,7 +53,7 @@ export function create (opts?: CreateOptions) {
|
|
|
53
53
|
* this decryption cipher must be the same as those used to create
|
|
54
54
|
* the encryption cipher.
|
|
55
55
|
*/
|
|
56
|
-
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array) { // eslint-disable-line require-await
|
|
56
|
+
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
57
57
|
// Create Uint8Arrays of nonce, ciphertext and tag.
|
|
58
58
|
const nonce = ciphertextAndNonce.subarray(0, nonceLength)
|
|
59
59
|
const ciphertext = ciphertextAndNonce.subarray(nonceLength, ciphertextAndNonce.length - algorithmTagLength)
|
|
@@ -77,7 +77,7 @@ export function create (opts?: CreateOptions) {
|
|
|
77
77
|
* @param {Uint8Array} data - The data to decrypt
|
|
78
78
|
* @param {string|Uint8Array} password - A plain password
|
|
79
79
|
*/
|
|
80
|
-
async function decrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
|
|
80
|
+
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
81
81
|
// Create Uint8Arrays of salt and ciphertextAndNonce.
|
|
82
82
|
const salt = data.subarray(0, saltLength)
|
|
83
83
|
const ciphertextAndNonce = data.subarray(saltLength)
|
|
@@ -7,12 +7,12 @@ const hashTypes = {
|
|
|
7
7
|
SHA512: 'SHA-512'
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const sign = async (key: CryptoKey, data: Uint8Array) => {
|
|
10
|
+
const sign = async (key: CryptoKey, data: Uint8Array): Promise<Uint8Array> => {
|
|
11
11
|
const buf = await webcrypto.get().subtle.sign({ name: 'HMAC' }, key, data)
|
|
12
12
|
return new Uint8Array(buf, 0, buf.byteLength)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array) {
|
|
15
|
+
export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise<{ digest: (data: Uint8Array) => Promise<Uint8Array>, length: number }> {
|
|
16
16
|
const hash = hashTypes[hashType]
|
|
17
17
|
|
|
18
18
|
const key = await webcrypto.get().subtle.importKey(
|
package/src/hmac/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
2
|
import lengths from './lengths.js'
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export interface HMAC {
|
|
5
|
+
digest: (data: Uint8Array) => Promise<Uint8Array>
|
|
6
|
+
length: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function create (hash: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise<HMAC> {
|
|
5
10
|
const res = {
|
|
6
11
|
async digest (data: Uint8Array) { // eslint-disable-line require-await
|
|
7
12
|
const hmac = crypto.createHmac(hash.toLowerCase(), secret)
|
package/src/keys/ecdh-browser.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { base64urlToBuffer } from '../util.js'
|
|
|
4
4
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
5
5
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
6
6
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
7
|
-
import type { ECDHKey, ECDHKeyPair } from './interface.js'
|
|
7
|
+
import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from './interface.js'
|
|
8
8
|
|
|
9
9
|
const bits = {
|
|
10
10
|
'P-256': 256,
|
|
@@ -15,7 +15,7 @@ const bits = {
|
|
|
15
15
|
const curveTypes = Object.keys(bits)
|
|
16
16
|
const names = curveTypes.join(' / ')
|
|
17
17
|
|
|
18
|
-
export async function generateEphmeralKeyPair (curve: string) {
|
|
18
|
+
export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> {
|
|
19
19
|
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {
|
|
20
20
|
throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')
|
|
21
21
|
}
|
|
@@ -30,7 +30,7 @@ export async function generateEphmeralKeyPair (curve: string) {
|
|
|
30
30
|
)
|
|
31
31
|
|
|
32
32
|
// forcePrivate is used for testing only
|
|
33
|
-
const genSharedKey = async (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair) => {
|
|
33
|
+
const genSharedKey = async (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> => {
|
|
34
34
|
let privateKey
|
|
35
35
|
|
|
36
36
|
if (forcePrivate != null) {
|
|
@@ -92,7 +92,7 @@ const curveLengths = {
|
|
|
92
92
|
// Marshal converts a jwk encoded ECDH public key into the
|
|
93
93
|
// form specified in section 4.3.6 of ANSI X9.62. (This is the format
|
|
94
94
|
// go-ipfs uses)
|
|
95
|
-
function marshalPublicKey (jwk: JsonWebKey) {
|
|
95
|
+
function marshalPublicKey (jwk: JsonWebKey): Uint8Array {
|
|
96
96
|
if (jwk.crv == null || jwk.x == null || jwk.y == null) {
|
|
97
97
|
throw new CodeError('JWK was missing components', 'ERR_INVALID_PARAMETERS')
|
|
98
98
|
}
|
|
@@ -111,7 +111,7 @@ function marshalPublicKey (jwk: JsonWebKey) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// Unmarshal converts a point, serialized by Marshal, into an jwk encoded key
|
|
114
|
-
function unmarshalPublicKey (curve: string, key: Uint8Array) {
|
|
114
|
+
function unmarshalPublicKey (curve: string, key: Uint8Array): JWKEncodedPublicKey {
|
|
115
115
|
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {
|
|
116
116
|
throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')
|
|
117
117
|
}
|
|
@@ -131,7 +131,7 @@ function unmarshalPublicKey (curve: string, key: Uint8Array) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const unmarshalPrivateKey = (curve: string, key: ECDHKeyPair) => ({
|
|
134
|
+
const unmarshalPrivateKey = (curve: string, key: ECDHKeyPair): JWKEncodedPrivateKey => ({
|
|
135
135
|
...unmarshalPublicKey(curve, key.public),
|
|
136
136
|
d: uint8ArrayToString(key.private, 'base64url')
|
|
137
137
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ed from '@noble/ed25519'
|
|
2
|
+
import type { Uint8ArrayKeyPair } from './interface'
|
|
2
3
|
|
|
3
4
|
const PUBLIC_KEY_BYTE_LENGTH = 32
|
|
4
5
|
const PRIVATE_KEY_BYTE_LENGTH = 64 // private key is actually 32 bytes but for historical reasons we concat private and public keys
|
|
@@ -7,7 +8,7 @@ const KEYS_BYTE_LENGTH = 32
|
|
|
7
8
|
export { PUBLIC_KEY_BYTE_LENGTH as publicKeyLength }
|
|
8
9
|
export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength }
|
|
9
10
|
|
|
10
|
-
export async function generateKey () {
|
|
11
|
+
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
|
|
11
12
|
// the actual private key (32 bytes)
|
|
12
13
|
const privateKeyRaw = ed.utils.randomPrivateKey()
|
|
13
14
|
const publicKey = await ed.getPublicKey(privateKeyRaw)
|
|
@@ -24,7 +25,7 @@ export async function generateKey () {
|
|
|
24
25
|
/**
|
|
25
26
|
* Generate keypair from a 32 byte uint8array
|
|
26
27
|
*/
|
|
27
|
-
export async function generateKeyFromSeed (seed: Uint8Array) {
|
|
28
|
+
export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
|
|
28
29
|
if (seed.length !== KEYS_BYTE_LENGTH) {
|
|
29
30
|
throw new TypeError('"seed" must be 32 bytes in length.')
|
|
30
31
|
} else if (!(seed instanceof Uint8Array)) {
|
|
@@ -43,17 +44,17 @@ export async function generateKeyFromSeed (seed: Uint8Array) {
|
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array) {
|
|
47
|
+
export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array): Promise<Uint8Array> {
|
|
47
48
|
const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH)
|
|
48
49
|
|
|
49
50
|
return await ed.sign(msg, privateKeyRaw)
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
53
|
+
export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
|
|
53
54
|
return await ed.verify(sig, msg, publicKey)
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array) {
|
|
57
|
+
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array): Uint8Array {
|
|
57
58
|
const privateKey = new Uint8Array(PRIVATE_KEY_BYTE_LENGTH)
|
|
58
59
|
for (let i = 0; i < KEYS_BYTE_LENGTH; i++) {
|
|
59
60
|
privateKey[i] = privateKeyRaw[i]
|
|
@@ -6,6 +6,7 @@ import { identity } from 'multiformats/hashes/identity'
|
|
|
6
6
|
import * as crypto from './ed25519.js'
|
|
7
7
|
import * as pbm from './keys.js'
|
|
8
8
|
import { exporter } from './exporter.js'
|
|
9
|
+
import type { Multibase } from 'multiformats'
|
|
9
10
|
|
|
10
11
|
export class Ed25519PublicKey {
|
|
11
12
|
private readonly _key: Uint8Array
|
|
@@ -14,26 +15,26 @@ export class Ed25519PublicKey {
|
|
|
14
15
|
this._key = ensureKey(key, crypto.publicKeyLength)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
async verify (data: Uint8Array, sig: Uint8Array) { // eslint-disable-line require-await
|
|
18
|
+
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
|
|
18
19
|
return await crypto.hashAndVerify(this._key, sig, data)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
marshal () {
|
|
22
|
+
marshal (): Uint8Array {
|
|
22
23
|
return this._key
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
get bytes () {
|
|
26
|
+
get bytes (): Uint8Array {
|
|
26
27
|
return pbm.PublicKey.encode({
|
|
27
28
|
Type: pbm.KeyType.Ed25519,
|
|
28
29
|
Data: this.marshal()
|
|
29
30
|
}).subarray()
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
equals (key: any) {
|
|
33
|
+
equals (key: any): boolean {
|
|
33
34
|
return uint8ArrayEquals(this.bytes, key.bytes)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
async hash () {
|
|
37
|
+
async hash (): Promise<Uint8Array> {
|
|
37
38
|
const { bytes } = await sha256.digest(this.bytes)
|
|
38
39
|
|
|
39
40
|
return bytes
|
|
@@ -51,30 +52,30 @@ export class Ed25519PrivateKey {
|
|
|
51
52
|
this._publicKey = ensureKey(publicKey, crypto.publicKeyLength)
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
async sign (message: Uint8Array) { // eslint-disable-line require-await
|
|
55
|
+
async sign (message: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
|
|
55
56
|
return await crypto.hashAndSign(this._key, message)
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
get public () {
|
|
59
|
+
get public (): Ed25519PublicKey {
|
|
59
60
|
return new Ed25519PublicKey(this._publicKey)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
marshal () {
|
|
63
|
+
marshal (): Uint8Array {
|
|
63
64
|
return this._key
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
get bytes () {
|
|
67
|
+
get bytes (): Uint8Array {
|
|
67
68
|
return pbm.PrivateKey.encode({
|
|
68
69
|
Type: pbm.KeyType.Ed25519,
|
|
69
70
|
Data: this.marshal()
|
|
70
71
|
}).subarray()
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
equals (key: any) {
|
|
74
|
+
equals (key: any): boolean {
|
|
74
75
|
return uint8ArrayEquals(this.bytes, key.bytes)
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
async hash () {
|
|
78
|
+
async hash (): Promise<Uint8Array> {
|
|
78
79
|
const { bytes } = await sha256.digest(this.bytes)
|
|
79
80
|
|
|
80
81
|
return bytes
|
|
@@ -89,15 +90,15 @@ export class Ed25519PrivateKey {
|
|
|
89
90
|
*
|
|
90
91
|
* @returns {Promise<string>}
|
|
91
92
|
*/
|
|
92
|
-
async id () {
|
|
93
|
-
const encoding =
|
|
93
|
+
async id (): Promise<string> {
|
|
94
|
+
const encoding = identity.digest(this.public.bytes)
|
|
94
95
|
return base58btc.encode(encoding.bytes).substring(1)
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
99
|
* Exports the key into a password protected `format`
|
|
99
100
|
*/
|
|
100
|
-
async export (password: string, format = 'libp2p-key') {
|
|
101
|
+
async export (password: string, format = 'libp2p-key'): Promise<Multibase<'m'>> {
|
|
101
102
|
if (format === 'libp2p-key') {
|
|
102
103
|
return await exporter(this.bytes, password)
|
|
103
104
|
} else {
|
|
@@ -106,7 +107,7 @@ export class Ed25519PrivateKey {
|
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
export function unmarshalEd25519PrivateKey (bytes: Uint8Array) {
|
|
110
|
+
export function unmarshalEd25519PrivateKey (bytes: Uint8Array): Ed25519PrivateKey {
|
|
110
111
|
// Try the old, redundant public key version
|
|
111
112
|
if (bytes.length > crypto.privateKeyLength) {
|
|
112
113
|
bytes = ensureKey(bytes, crypto.privateKeyLength + crypto.publicKeyLength)
|
|
@@ -121,22 +122,22 @@ export function unmarshalEd25519PrivateKey (bytes: Uint8Array) {
|
|
|
121
122
|
return new Ed25519PrivateKey(privateKeyBytes, publicKeyBytes)
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export function unmarshalEd25519PublicKey (bytes: Uint8Array) {
|
|
125
|
+
export function unmarshalEd25519PublicKey (bytes: Uint8Array): Ed25519PublicKey {
|
|
125
126
|
bytes = ensureKey(bytes, crypto.publicKeyLength)
|
|
126
127
|
return new Ed25519PublicKey(bytes)
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
export async function generateKeyPair () {
|
|
130
|
+
export async function generateKeyPair (): Promise<Ed25519PrivateKey> {
|
|
130
131
|
const { privateKey, publicKey } = await crypto.generateKey()
|
|
131
132
|
return new Ed25519PrivateKey(privateKey, publicKey)
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
export async function generateKeyPairFromSeed (seed: Uint8Array) {
|
|
135
|
+
export async function generateKeyPairFromSeed (seed: Uint8Array): Promise<Ed25519PrivateKey> {
|
|
135
136
|
const { privateKey, publicKey } = await crypto.generateKeyFromSeed(seed)
|
|
136
137
|
return new Ed25519PrivateKey(privateKey, publicKey)
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
function ensureKey (key: Uint8Array, length: number) {
|
|
140
|
+
function ensureKey (key: Uint8Array, length: number): Uint8Array {
|
|
140
141
|
key = Uint8Array.from(key ?? [])
|
|
141
142
|
if (key.length !== length) {
|
|
142
143
|
throw new CodeError(`Key must be a Uint8Array of length ${length}, got ${key.length}`, 'ERR_INVALID_KEY_TYPE')
|
package/src/keys/ed25519.ts
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from 'crypto'
|
|
|
2
2
|
import { promisify } from 'util'
|
|
3
3
|
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
|
|
4
4
|
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
|
|
5
|
+
import type { Uint8ArrayKeyPair } from './interface.js'
|
|
5
6
|
|
|
6
7
|
const keypair = promisify(crypto.generateKeyPair)
|
|
7
8
|
|
|
@@ -34,7 +35,7 @@ function derivePublicKey (privateKey: Uint8Array): Uint8Array {
|
|
|
34
35
|
return uint8arrayFromString(jwk.x, 'base64url')
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export async function generateKey () {
|
|
38
|
+
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
|
|
38
39
|
const key = await keypair('ed25519', {
|
|
39
40
|
publicKeyEncoding: { type: 'spki', format: 'jwk' },
|
|
40
41
|
privateKeyEncoding: { type: 'pkcs8', format: 'jwk' }
|
|
@@ -54,7 +55,7 @@ export async function generateKey () {
|
|
|
54
55
|
/**
|
|
55
56
|
* Generate keypair from a 32 byte uint8array
|
|
56
57
|
*/
|
|
57
|
-
export async function generateKeyFromSeed (seed: Uint8Array) {
|
|
58
|
+
export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
|
|
58
59
|
if (seed.length !== KEYS_BYTE_LENGTH) {
|
|
59
60
|
throw new TypeError('"seed" must be 32 bytes in length.')
|
|
60
61
|
} else if (!(seed instanceof Uint8Array)) {
|
|
@@ -70,7 +71,7 @@ export async function generateKeyFromSeed (seed: Uint8Array) {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
export async function hashAndSign (key: Uint8Array, msg: Uint8Array) {
|
|
74
|
+
export async function hashAndSign (key: Uint8Array, msg: Uint8Array): Promise<Buffer> {
|
|
74
75
|
if (!(key instanceof Uint8Array)) {
|
|
75
76
|
throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.')
|
|
76
77
|
}
|
|
@@ -101,7 +102,7 @@ export async function hashAndSign (key: Uint8Array, msg: Uint8Array) {
|
|
|
101
102
|
return crypto.sign(null, msg, obj)
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
export async function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
|
|
105
|
+
export async function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
|
|
105
106
|
if (key.byteLength !== PUBLIC_KEY_BYTE_LENGTH) {
|
|
106
107
|
throw new TypeError('"key" must be 32 bytes in length.')
|
|
107
108
|
} else if (!(key instanceof Uint8Array)) {
|
|
@@ -126,7 +127,7 @@ export async function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint
|
|
|
126
127
|
return crypto.verify(null, msg, obj, sig)
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array) {
|
|
130
|
+
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array): Uint8Array {
|
|
130
131
|
const privateKey = new Uint8Array(PRIVATE_KEY_BYTE_LENGTH)
|
|
131
132
|
for (let i = 0; i < KEYS_BYTE_LENGTH; i++) {
|
|
132
133
|
privateKey[i] = privateKeyRaw[i]
|
package/src/keys/exporter.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Multibase } from 'multiformats'
|
|
1
2
|
import { base64 } from 'multiformats/bases/base64'
|
|
2
3
|
import * as ciphers from '../ciphers/aes-gcm.js'
|
|
3
4
|
|
|
@@ -6,7 +7,7 @@ import * as ciphers from '../ciphers/aes-gcm.js'
|
|
|
6
7
|
* The PrivateKey is encrypted via a password derived PBKDF2 key
|
|
7
8
|
* leveraging the aes-gcm cipher algorithm.
|
|
8
9
|
*/
|
|
9
|
-
export async function exporter (privateKey: Uint8Array, password: string) {
|
|
10
|
+
export async function exporter (privateKey: Uint8Array, password: string): Promise<Multibase<'m'>> {
|
|
10
11
|
const cipher = ciphers.create()
|
|
11
12
|
const encryptedKey = await cipher.encrypt(privateKey, password)
|
|
12
13
|
return base64.encode(encryptedKey)
|
package/src/keys/importer.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as ciphers from '../ciphers/aes-gcm.js'
|
|
|
6
6
|
* with the given password. The privateKey must have been exported
|
|
7
7
|
* using the same password and underlying cipher (aes-gcm)
|
|
8
8
|
*/
|
|
9
|
-
export async function importer (privateKey: string, password: string) {
|
|
9
|
+
export async function importer (privateKey: string, password: string): Promise<Uint8Array> {
|
|
10
10
|
const encryptedKey = base64.decode(privateKey)
|
|
11
11
|
const cipher = ciphers.create()
|
|
12
12
|
return await cipher.decrypt(encryptedKey, password)
|
package/src/keys/index.ts
CHANGED
|
@@ -25,12 +25,12 @@ export const supportedKeys = {
|
|
|
25
25
|
secp256k1: Secp256k1
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function unsupportedKey (type: string) {
|
|
28
|
+
function unsupportedKey (type: string): CodeError<Record<string, never>> {
|
|
29
29
|
const supported = Object.keys(supportedKeys).join(' / ')
|
|
30
30
|
return new CodeError(`invalid or unsupported key type ${type}. Must be ${supported}`, 'ERR_UNSUPPORTED_KEY_TYPE')
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function typeToKey (type: string) {
|
|
33
|
+
function typeToKey (type: string): typeof RSA | typeof Ed25519 | typeof Secp256k1 {
|
|
34
34
|
type = type.toLowerCase()
|
|
35
35
|
|
|
36
36
|
if (type === 'rsa' || type === 'ed25519' || type === 'secp256k1') {
|