Comparing version 0.4.11 to 0.4.12
@@ -25,5 +25,3 @@ "use strict"; | ||
var sharedKey = ephemeralSK.encapsulate(receiverPK, (0, config_1.isHkdfKeyCompressed)()); | ||
var ephemeralPK = (0, config_1.isEphemeralKeyCompressed)() | ||
? ephemeralSK.publicKey.compressed | ||
: ephemeralSK.publicKey.uncompressed; | ||
var ephemeralPK = ephemeralSK.publicKey.toBytes((0, config_1.isEphemeralKeyCompressed)()); | ||
var encrypted = (0, utils_2.symEncrypt)(sharedKey, msg); | ||
@@ -30,0 +28,0 @@ return Buffer.from((0, utils_1.concatBytes)(ephemeralPK, encrypted)); |
@@ -6,2 +6,3 @@ import { PublicKey } from "./PublicKey"; | ||
readonly publicKey: PublicKey; | ||
/** @description From version 0.5.0, `Uint8Array` will be returned instead of `Buffer`. */ | ||
get secret(): Buffer; | ||
@@ -22,3 +23,3 @@ constructor(secret?: Uint8Array); | ||
* @param pk - Receiver's public key. | ||
* @param compressed - Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @param compressed - (default: `false`) Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @returns Shared secret, derived with HKDF-SHA256. | ||
@@ -25,0 +26,0 @@ */ |
@@ -24,2 +24,3 @@ "use strict"; | ||
Object.defineProperty(PrivateKey.prototype, "secret", { | ||
/** @description From version 0.5.0, `Uint8Array` will be returned instead of `Buffer`. */ | ||
get: function () { | ||
@@ -47,3 +48,3 @@ // TODO: Uint8Array | ||
* @param pk - Receiver's public key. | ||
* @param compressed - Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @param compressed - (default: `false`) Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @returns Shared secret, derived with HKDF-SHA256. | ||
@@ -53,5 +54,3 @@ */ | ||
if (compressed === void 0) { compressed = false; } | ||
var senderPoint = compressed | ||
? this.publicKey.compressed | ||
: this.publicKey.uncompressed; | ||
var senderPoint = this.publicKey.toBytes(compressed); | ||
var sharedPoint = this.multiply(pk, compressed); | ||
@@ -62,3 +61,3 @@ return (0, utils_2.getSharedKey)(senderPoint, sharedPoint); | ||
if (compressed === void 0) { compressed = false; } | ||
return (0, utils_2.getSharedPoint)(this.data, pk.compressed, compressed); | ||
return (0, utils_2.getSharedPoint)(this.data, pk.toBytes(true), compressed); | ||
}; | ||
@@ -65,0 +64,0 @@ PrivateKey.prototype.equals = function (other) { |
@@ -5,5 +5,10 @@ import type { PrivateKey } from "./PrivateKey"; | ||
private readonly data; | ||
private readonly dataUncompressed; | ||
private get _uncompressed(); | ||
/** @deprecated - use `PublicKey.toBytes(false)` instead. You may also need `Buffer.from`. */ | ||
get uncompressed(): Buffer; | ||
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */ | ||
get compressed(): Buffer; | ||
constructor(data: Uint8Array); | ||
toBytes(compressed?: boolean): Uint8Array; | ||
toHex(compressed?: boolean): string; | ||
@@ -16,3 +21,3 @@ /** | ||
* @param sk - Receiver's private key. | ||
* @param compressed - Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @param compressed - (default: `false`) Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @returns Shared secret, derived with HKDF-SHA256. | ||
@@ -19,0 +24,0 @@ */ |
@@ -8,3 +8,8 @@ "use strict"; | ||
function PublicKey(data) { | ||
this.data = (0, utils_2.convertPublicKeyFormat)(data, true); | ||
// data can be either compressed or uncompressed if secp256k1 | ||
var compressed = (0, utils_2.convertPublicKeyFormat)(data, true); | ||
var uncompressed = (0, utils_2.convertPublicKeyFormat)(data, false); | ||
this.data = compressed; | ||
this.dataUncompressed = | ||
compressed.length !== uncompressed.length ? uncompressed : null; | ||
} | ||
@@ -14,6 +19,13 @@ PublicKey.fromHex = function (hex) { | ||
}; | ||
Object.defineProperty(PublicKey.prototype, "_uncompressed", { | ||
get: function () { | ||
return this.dataUncompressed !== null ? this.dataUncompressed : this.data; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(PublicKey.prototype, "uncompressed", { | ||
/** @deprecated - use `PublicKey.toBytes(false)` instead. You may also need `Buffer.from`. */ | ||
get: function () { | ||
// TODO: Uint8Array | ||
return Buffer.from((0, utils_2.convertPublicKeyFormat)(this.data, false)); | ||
return Buffer.from(this._uncompressed); // TODO: Uint8Array | ||
}, | ||
@@ -24,5 +36,5 @@ enumerable: false, | ||
Object.defineProperty(PublicKey.prototype, "compressed", { | ||
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */ | ||
get: function () { | ||
// TODO: Uint8Array | ||
return Buffer.from(this.data); | ||
return Buffer.from(this.data); // TODO: Uint8Array | ||
}, | ||
@@ -32,10 +44,9 @@ enumerable: false, | ||
}); | ||
PublicKey.prototype.toBytes = function (compressed) { | ||
if (compressed === void 0) { compressed = true; } | ||
return compressed ? this.data : this._uncompressed; | ||
}; | ||
PublicKey.prototype.toHex = function (compressed) { | ||
if (compressed === void 0) { compressed = true; } | ||
if (compressed) { | ||
return (0, utils_1.bytesToHex)(this.data); | ||
} | ||
else { | ||
return (0, utils_1.bytesToHex)(this.uncompressed); | ||
} | ||
return (0, utils_1.bytesToHex)(this.toBytes(compressed)); | ||
}; | ||
@@ -48,3 +59,3 @@ /** | ||
* @param sk - Receiver's private key. | ||
* @param compressed - Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @param compressed - (default: `false`) Whether to use compressed or uncompressed public keys in the key derivation (secp256k1 only). | ||
* @returns Shared secret, derived with HKDF-SHA256. | ||
@@ -54,3 +65,3 @@ */ | ||
if (compressed === void 0) { compressed = false; } | ||
var senderPoint = compressed ? this.data : this.uncompressed; | ||
var senderPoint = this.toBytes(compressed); | ||
var sharedPoint = sk.multiply(this, compressed); | ||
@@ -57,0 +68,0 @@ return (0, utils_2.getSharedKey)(senderPoint, sharedPoint); |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.4.11", | ||
"version": "0.4.12", | ||
"engines": { | ||
@@ -17,0 +17,0 @@ "node": ">=16", |
@@ -28,3 +28,3 @@ # eciesjs | ||
const data = Buffer.from("hello world🌍") | ||
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.compressed, data)) | ||
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data)) | ||
console.log(Buffer.from(decrypted).toString()) | ||
@@ -46,4 +46,6 @@ ``` | ||
This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. Currently it's necessary to polyfill `Buffer` for backward compatibility. From v0.5.0, it can run in browsers as is. | ||
This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. The online demo is hosted [here](https://js-demo.ecies.org/). | ||
Currently it's necessary to polyfill `Buffer` for backward compatibility. From v0.5.0, it can run in browsers as is. | ||
If you want a WASM version to run directly in modern browsers or on some blockchains, you can also try [`ecies-wasm`](https://github.com/ecies/rs-wasm). | ||
@@ -53,6 +55,6 @@ | ||
For bun/deno, see [`example/runtime`](./example/runtime). There are some limitations currently: | ||
For bun/deno, see [`example/runtime`](./example/runtime). There are some limitations currently, mentioned in [`@ecies/ciphers`](https://github.com/ecies/js-ciphers#known-limitations): | ||
- `xchacha20` does not work on bun | ||
- Only `aes-256-gcm` with 12 bytes nonce works on deno | ||
- `node:crypto`'s `xchacha20` does not work on bun (pure JS implementation is used instead) | ||
- `aes-256-gcm` only works with 12 bytes nonce on deno (deno is not handling package exports correctly) | ||
@@ -91,3 +93,3 @@ ### React Native | ||
toHex(): string; | ||
encapsulate(pk: PublicKey): Uint8Array; | ||
encapsulate(pk: PublicKey, compressed?: boolean): Uint8Array; | ||
multiply(pk: PublicKey, compressed?: boolean): Uint8Array; | ||
@@ -102,3 +104,2 @@ equals(other: PrivateKey): boolean; | ||
readonly publicKey: PublicKey; | ||
private readonly data; | ||
``` | ||
@@ -113,4 +114,5 @@ | ||
constructor(data: Uint8Array); | ||
toBytes(compressed?: boolean): Uint8Array; | ||
toHex(compressed?: boolean): string; | ||
decapsulate(sk: PrivateKey): Uint8Array; | ||
decapsulate(sk: PrivateKey, compressed?: boolean): Uint8Array; | ||
equals(other: PublicKey): boolean; | ||
@@ -122,5 +124,6 @@ ``` | ||
```typescript | ||
/** @deprecated - use `PublicKey.toBytes(false)` instead. You may also need `Buffer.from`. */ | ||
get uncompressed(): Buffer; | ||
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */ | ||
get compressed(): Buffer; | ||
private readonly data; | ||
``` | ||
@@ -127,0 +130,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36877
569
192