修改后台权限
This commit is contained in:
21
node_modules/eciesjs/LICENSE
generated
vendored
Normal file
21
node_modules/eciesjs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2026 Weiliang Li
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
213
node_modules/eciesjs/README.md
generated
vendored
Normal file
213
node_modules/eciesjs/README.md
generated
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
# eciesjs
|
||||
|
||||
[](https://app.codacy.com/app/ecies/js)
|
||||
[](https://github.com/ecies/js)
|
||||
[](https://www.npmjs.com/package/eciesjs)
|
||||
[](https://npm-stat.link/eciesjs)
|
||||
[](https://bundlephobia.com/package/eciesjs@latest)
|
||||
[](https://github.com/ecies/js/actions)
|
||||
[](https://codecov.io/gh/ecies/js)
|
||||
|
||||
Elliptic Curve Integrated Encryption Scheme for secp256k1/curve25519 in TypeScript.
|
||||
|
||||
This is the JavaScript/TypeScript version of [eciespy](https://github.com/ecies/py) with a built-in class-like secp256k1/curve25519 [API](#privatekey).
|
||||
|
||||
You can learn the details in [DETAILS.md](./DETAILS.md).
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install eciesjs
|
||||
```
|
||||
|
||||
We recommend using the latest JavaScript/TypeScript runtime although it's still possible to install on some old versions.
|
||||
|
||||
This library supports multiple platforms (browser, node, bun/deno, react native), see [Multi-platform Support](#multi-platform-support).
|
||||
|
||||
For security, see [Security](#security).
|
||||
|
||||
## Quick Start
|
||||
|
||||
```typescript
|
||||
// example/runtime/quick-start.js
|
||||
import { PrivateKey, decrypt, encrypt } from "eciesjs";
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
const sk = new PrivateKey();
|
||||
const data = encoder.encode("hello world🌍");
|
||||
const decrypted = decrypt(sk.secret, encrypt(sk.publicKey.toBytes(), data));
|
||||
console.log(decoder.decode(decrypted));
|
||||
```
|
||||
|
||||
Or run the example code:
|
||||
|
||||
```bash
|
||||
$ pnpm install && pnpm build && cd example/runtime && pnpm install && node quick-start.js
|
||||
hello world🌍
|
||||
```
|
||||
|
||||
See [Configuration](#configuration) to control with more granularity.
|
||||
|
||||
## Sponsors
|
||||
|
||||
<a href="https://dotenvx.com"><img alt="dotenvx" src="https://dotenvx.com/logo.png" width="200" height="200"/></a>
|
||||
|
||||
## API
|
||||
|
||||
### `encrypt(receiverRawPK: string | Uint8Array, data: Uint8Array): Uint8Array`
|
||||
|
||||
Parameters:
|
||||
|
||||
- `receiverRawPK` - Receiver's public key, hex `string` or `Uint8Array`
|
||||
- `data` - Data to encrypt
|
||||
|
||||
Returns: `Uint8Array`
|
||||
|
||||
### `decrypt(receiverRawSK: string | Uint8Array, data: Uint8Array): Uint8Array`
|
||||
|
||||
Parameters:
|
||||
|
||||
- `receiverRawSK` - Receiver's private key, hex `string` or `Uint8Array`
|
||||
- `data` - Data to decrypt
|
||||
|
||||
Returns: `Uint8Array`
|
||||
|
||||
### `PrivateKey`
|
||||
|
||||
- Methods
|
||||
|
||||
```typescript
|
||||
static fromHex(hex: string, curve?: EllipticCurve): PrivateKey;
|
||||
constructor(secret?: Uint8Array, curve?: EllipticCurve);
|
||||
toHex(): string;
|
||||
encapsulate(pk: PublicKey, compressed?: boolean): Uint8Array;
|
||||
multiply(pk: PublicKey, compressed?: boolean): Uint8Array;
|
||||
equals(other: PrivateKey): boolean;
|
||||
```
|
||||
|
||||
- Properties
|
||||
|
||||
```typescript
|
||||
get secret(): Uint8Array;
|
||||
readonly publicKey: PublicKey;
|
||||
```
|
||||
|
||||
### `PublicKey`
|
||||
|
||||
- Methods
|
||||
|
||||
```typescript
|
||||
static fromHex(hex: string, curve?: EllipticCurve): PublicKey;
|
||||
constructor(data: Uint8Array, curve?: EllipticCurve);
|
||||
toBytes(compressed?: boolean): Uint8Array;
|
||||
toHex(compressed?: boolean): string;
|
||||
decapsulate(sk: PrivateKey, compressed?: boolean): Uint8Array;
|
||||
equals(other: PublicKey): boolean;
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Following configurations are available.
|
||||
|
||||
- Elliptic curve: secp256k1 or curve25519 (x25519/ed25519)
|
||||
- Ephemeral key format in the payload: compressed or uncompressed (only for secp256k1)
|
||||
- Shared elliptic curve key format in the key derivation: compressed or uncompressed (only for secp256k1)
|
||||
- Symmetric cipher algorithm: AES-256-GCM or XChaCha20-Poly1305
|
||||
- Symmetric nonce length: 12 or 16 bytes (only for AES-256-GCM)
|
||||
|
||||
For compatibility, make sure different applications share the same configuration.
|
||||
|
||||
```ts
|
||||
export type EllipticCurve = "secp256k1" | "x25519" | "ed25519";
|
||||
export type SymmetricAlgorithm = "aes-256-gcm" | "xchacha20";
|
||||
export type NonceLength = 12 | 16;
|
||||
|
||||
export class Config {
|
||||
ellipticCurve: EllipticCurve = "secp256k1";
|
||||
isEphemeralKeyCompressed: boolean = false;
|
||||
isHkdfKeyCompressed: boolean = false;
|
||||
symmetricAlgorithm: SymmetricAlgorithm = "aes-256-gcm";
|
||||
symmetricNonceLength: NonceLength = 16;
|
||||
}
|
||||
|
||||
export const ECIES_CONFIG = new Config();
|
||||
```
|
||||
|
||||
### Elliptic curve configuration
|
||||
|
||||
On `ellipticCurve = "x25519"` or `ellipticCurve = "ed25519"`, x25519 (key exchange function on curve25519) or ed25519 (signature algorithm on curve25519) will be used for key exchange instead of secp256k1.
|
||||
|
||||
In this case, the payload would always be: `32 Bytes + Ciphered` regardless of `isEphemeralKeyCompressed`.
|
||||
|
||||
> If you don't know how to choose between x25519 and ed25519, just use the dedicated key exchange function x25519 for efficiency.
|
||||
>
|
||||
> Because any 32-byte data is a valid curve25519 public key, the payload would seem random. This property is excellent for circumventing censorship by adversaries.
|
||||
|
||||
### Secp256k1-specific configuration
|
||||
|
||||
On `isEphemeralKeyCompressed = true`, the payload would be: `33 Bytes + Ciphered` instead of `65 Bytes + Ciphered`.
|
||||
|
||||
On `isHkdfKeyCompressed = true`, the hkdf key would be derived from `ephemeral public key (compressed) + shared public key (compressed)` instead of `ephemeral public key (uncompressed) + shared public key (uncompressed)`.
|
||||
|
||||
### Symmetric cipher configuration
|
||||
|
||||
On `symmetricAlgorithm = "xchacha20"`, plaintext data would be encrypted with XChaCha20-Poly1305.
|
||||
|
||||
On `symmetricNonceLength = 12`, the nonce of AES-256-GCM would be 12 bytes. XChaCha20-Poly1305's nonce is always 24 bytes regardless of `symmetricNonceLength`.
|
||||
|
||||
### Which configuration should I choose?
|
||||
|
||||
For compatibility with other [ecies libraries](https://github.com/orgs/ecies/repositories), start with the default (secp256k1 with AES-256-GCM).
|
||||
|
||||
For speed and security, pick x25519 with XChaCha20-Poly1305.
|
||||
|
||||
If you know exactly what you are doing, configure as you wish or build your own ecies logic with this library.
|
||||
|
||||
## Multi-platform Support
|
||||
|
||||
| | Fully Supported |
|
||||
| ------------ | --------------- |
|
||||
| Node | ✅ |
|
||||
| Bun | ✅ |
|
||||
| Deno | ✅ (see below) |
|
||||
| Browser | ✅ |
|
||||
| React Native | ✅ |
|
||||
|
||||
Via [`@ecies/ciphers`](https://github.com/ecies/js-ciphers), `node:crypto`'s native implementation of AES-256-GCM and XChaCha20-Poly1305 is chosen if available.
|
||||
|
||||
### Browser
|
||||
|
||||
This library is browser-friendly, check the [`example/browser`](./example/browser) directory for details. You can check [the online demo](https://js-demo.ecies.org/) as well.
|
||||
|
||||
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).
|
||||
|
||||
### Bun/Deno
|
||||
|
||||
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):
|
||||
|
||||
- `chacha20-poly1305`'s pure JS implementation is used on bun (`node:crypto`'s `chacha20-poly1305` is not available due to lack of implementation);
|
||||
- `chacha20-poly1305` does not work on deno by default. You need to upgrade deno and run with `--conditions deno` (>=2.4.0) or `--unstable-node-conditions deno`(>=2.3.6,<2.4.0).
|
||||
|
||||
### React Native
|
||||
|
||||
See the [React Native demo](https://github.com/ecies/js-rn-demo).
|
||||
|
||||
## Security
|
||||
|
||||
To mitigate security risks, such as [supply chain attacks](https://slowmist.medium.com/supply-chain-attack-on-ledger-connect-kit-analyzing-the-impact-and-preventive-measures-1005e39422fd) and zero-day [vulnerabilities](https://github.com/advisories/GHSA-vjh7-7g9h-fjfh), we only use `node:crypto` and these audited dependencies:
|
||||
|
||||
- [noble-curves](https://github.com/paulmillr/noble-curves#security)
|
||||
- [noble-hashes](https://github.com/paulmillr/noble-hashes#security)
|
||||
- [noble-ciphers](https://github.com/paulmillr/noble-ciphers#security)
|
||||
|
||||
Every release is built on GitHub Actions with [provenance](https://www.npmjs.com/package/eciesjs#provenance).
|
||||
|
||||
This library is fully auditable as well. We're seeking funding for a professional third-party security audit to verify implementation and identify potential vulnerabilities.
|
||||
|
||||
If you rely on this library or value secure open-source cryptography, please consider [donating](https://github.com/sponsors/kigawas) to help fund this audit.
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG.md](./CHANGELOG.md).
|
||||
24
node_modules/eciesjs/dist/config.d.ts
generated
vendored
Normal file
24
node_modules/eciesjs/dist/config.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export type EllipticCurve = "secp256k1" | "x25519" | "ed25519";
|
||||
export type SymmetricAlgorithm = "aes-256-gcm" | "xchacha20" | "aes-256-cbc";
|
||||
export type NonceLength = 12 | 16;
|
||||
export declare class Config {
|
||||
ellipticCurve: EllipticCurve;
|
||||
isEphemeralKeyCompressed: boolean;
|
||||
isHkdfKeyCompressed: boolean;
|
||||
symmetricAlgorithm: SymmetricAlgorithm;
|
||||
symmetricNonceLength: NonceLength;
|
||||
get ephemeralKeySize(): number;
|
||||
}
|
||||
export declare const ECIES_CONFIG: Config;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const ellipticCurve: () => EllipticCurve;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const isEphemeralKeyCompressed: () => boolean;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const isHkdfKeyCompressed: () => boolean;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const symmetricAlgorithm: () => SymmetricAlgorithm;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const symmetricNonceLength: () => NonceLength;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
export declare const ephemeralKeySize: () => number;
|
||||
55
node_modules/eciesjs/dist/config.js
generated
vendored
Normal file
55
node_modules/eciesjs/dist/config.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ephemeralKeySize = exports.symmetricNonceLength = exports.symmetricAlgorithm = exports.isHkdfKeyCompressed = exports.isEphemeralKeyCompressed = exports.ellipticCurve = exports.ECIES_CONFIG = exports.Config = void 0;
|
||||
var consts_js_1 = require("./consts.js");
|
||||
var Config = /** @class */ (function () {
|
||||
function Config() {
|
||||
this.ellipticCurve = "secp256k1";
|
||||
this.isEphemeralKeyCompressed = false; // secp256k1 only
|
||||
this.isHkdfKeyCompressed = false; // secp256k1 only
|
||||
this.symmetricAlgorithm = "aes-256-gcm";
|
||||
this.symmetricNonceLength = 16; // aes-256-gcm only
|
||||
}
|
||||
Object.defineProperty(Config.prototype, "ephemeralKeySize", {
|
||||
get: function () {
|
||||
var mapping = {
|
||||
secp256k1: this.isEphemeralKeyCompressed
|
||||
? consts_js_1.COMPRESSED_PUBLIC_KEY_SIZE
|
||||
: consts_js_1.UNCOMPRESSED_PUBLIC_KEY_SIZE,
|
||||
x25519: consts_js_1.CURVE25519_PUBLIC_KEY_SIZE,
|
||||
ed25519: consts_js_1.CURVE25519_PUBLIC_KEY_SIZE,
|
||||
};
|
||||
/* v8 ignore else -- @preserve */
|
||||
if (this.ellipticCurve in mapping) {
|
||||
return mapping[this.ellipticCurve];
|
||||
}
|
||||
else {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
return Config;
|
||||
}());
|
||||
exports.Config = Config;
|
||||
exports.ECIES_CONFIG = new Config();
|
||||
// TODO: remove these after 0.5.0
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var ellipticCurve = function () { return exports.ECIES_CONFIG.ellipticCurve; };
|
||||
exports.ellipticCurve = ellipticCurve;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var isEphemeralKeyCompressed = function () { return exports.ECIES_CONFIG.isEphemeralKeyCompressed; };
|
||||
exports.isEphemeralKeyCompressed = isEphemeralKeyCompressed;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var isHkdfKeyCompressed = function () { return exports.ECIES_CONFIG.isHkdfKeyCompressed; };
|
||||
exports.isHkdfKeyCompressed = isHkdfKeyCompressed;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var symmetricAlgorithm = function () { return exports.ECIES_CONFIG.symmetricAlgorithm; };
|
||||
exports.symmetricAlgorithm = symmetricAlgorithm;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var symmetricNonceLength = function () { return exports.ECIES_CONFIG.symmetricNonceLength; };
|
||||
exports.symmetricNonceLength = symmetricNonceLength;
|
||||
/** @deprecated - use individual attribute instead */
|
||||
var ephemeralKeySize = function () { return exports.ECIES_CONFIG.ephemeralKeySize; };
|
||||
exports.ephemeralKeySize = ephemeralKeySize;
|
||||
7
node_modules/eciesjs/dist/consts.d.ts
generated
vendored
Normal file
7
node_modules/eciesjs/dist/consts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export declare const SECRET_KEY_LENGTH = 32;
|
||||
export declare const COMPRESSED_PUBLIC_KEY_SIZE = 33;
|
||||
export declare const UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;
|
||||
export declare const ETH_PUBLIC_KEY_SIZE = 64;
|
||||
export declare const CURVE25519_PUBLIC_KEY_SIZE = 32;
|
||||
export declare const XCHACHA20_NONCE_LENGTH = 24;
|
||||
export declare const AEAD_TAG_LENGTH = 16;
|
||||
12
node_modules/eciesjs/dist/consts.js
generated
vendored
Normal file
12
node_modules/eciesjs/dist/consts.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AEAD_TAG_LENGTH = exports.XCHACHA20_NONCE_LENGTH = exports.CURVE25519_PUBLIC_KEY_SIZE = exports.ETH_PUBLIC_KEY_SIZE = exports.UNCOMPRESSED_PUBLIC_KEY_SIZE = exports.COMPRESSED_PUBLIC_KEY_SIZE = exports.SECRET_KEY_LENGTH = void 0;
|
||||
// elliptic
|
||||
exports.SECRET_KEY_LENGTH = 32;
|
||||
exports.COMPRESSED_PUBLIC_KEY_SIZE = 33;
|
||||
exports.UNCOMPRESSED_PUBLIC_KEY_SIZE = 65;
|
||||
exports.ETH_PUBLIC_KEY_SIZE = 64;
|
||||
exports.CURVE25519_PUBLIC_KEY_SIZE = 32;
|
||||
// symmetric
|
||||
exports.XCHACHA20_NONCE_LENGTH = 24;
|
||||
exports.AEAD_TAG_LENGTH = 16;
|
||||
36
node_modules/eciesjs/dist/index.d.ts
generated
vendored
Normal file
36
node_modules/eciesjs/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Encrypts data with a receiver's public key.
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, this function will always return `Uint8Array`.
|
||||
* To preserve the pre-0.5.0 behavior of returning a `Buffer`, wrap the result with `Buffer.from(encrypt(...))`.
|
||||
*
|
||||
* @param receiverRawPK - Raw public key of the receiver, either as a hex `string` or a `Uint8Array`.
|
||||
* @param data - Data to encrypt.
|
||||
* @returns Encrypted payload, format: `public key || encrypted`.
|
||||
*/
|
||||
export declare function encrypt(receiverRawPK: string | Uint8Array, data: Uint8Array): Uint8Array;
|
||||
/**
|
||||
* Decrypts data with a receiver's private key.
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, this function will always return `Uint8Array`.
|
||||
* To preserve the pre-0.5.0 behavior of returning a `Buffer`, wrap the result with `Buffer.from(decrypt(...))`.
|
||||
*
|
||||
* @param receiverRawSK - Raw private key of the receiver, either as a hex `string` or a `Uint8Array`.
|
||||
* @param data - Data to decrypt.
|
||||
* @returns Decrypted plain text.
|
||||
*/
|
||||
export declare function decrypt(receiverRawSK: string | Uint8Array, data: Uint8Array): Uint8Array;
|
||||
export { ECIES_CONFIG } from "./config.js";
|
||||
export { PrivateKey, PublicKey } from "./keys/index.js";
|
||||
/** @deprecated - use `import * as utils from "eciesjs/utils"` instead. */
|
||||
export declare const utils: {
|
||||
aesEncrypt: (key: Uint8Array, plainText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
aesDecrypt: (key: Uint8Array, cipherText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
symEncrypt: (key: Uint8Array, plainText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
symDecrypt: (key: Uint8Array, cipherText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
decodeHex: (hex: string) => Uint8Array;
|
||||
getValidSecret: (curve?: import("./config.js").EllipticCurve) => Uint8Array;
|
||||
remove0x: (hex: string) => string;
|
||||
};
|
||||
79
node_modules/eciesjs/dist/index.js
generated
vendored
Normal file
79
node_modules/eciesjs/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.utils = exports.PublicKey = exports.PrivateKey = exports.ECIES_CONFIG = void 0;
|
||||
exports.encrypt = encrypt;
|
||||
exports.decrypt = decrypt;
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var config_js_1 = require("./config.js");
|
||||
var index_js_1 = require("./keys/index.js");
|
||||
var types_js_1 = require("./types.js");
|
||||
var index_js_2 = require("./utils/index.js");
|
||||
/**
|
||||
* Encrypts data with a receiver's public key.
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, this function will always return `Uint8Array`.
|
||||
* To preserve the pre-0.5.0 behavior of returning a `Buffer`, wrap the result with `Buffer.from(encrypt(...))`.
|
||||
*
|
||||
* @param receiverRawPK - Raw public key of the receiver, either as a hex `string` or a `Uint8Array`.
|
||||
* @param data - Data to encrypt.
|
||||
* @returns Encrypted payload, format: `public key || encrypted`.
|
||||
*/
|
||||
function encrypt(receiverRawPK, data) {
|
||||
var encrypted = _encrypt(receiverRawPK, data, config_js_1.ECIES_CONFIG);
|
||||
return types_js_1.IS_BUFFER_SUPPORTED ? Buffer.from(encrypted) : encrypted;
|
||||
}
|
||||
function _encrypt(receiverRawPK, data, config) {
|
||||
var curve = config.ellipticCurve;
|
||||
var ephemeralSK = new index_js_1.PrivateKey(undefined, curve);
|
||||
var receiverPK = receiverRawPK instanceof Uint8Array
|
||||
? new index_js_1.PublicKey(receiverRawPK, curve)
|
||||
: index_js_1.PublicKey.fromHex(receiverRawPK, curve);
|
||||
var sharedKey = ephemeralSK.encapsulate(receiverPK, config.isHkdfKeyCompressed);
|
||||
var ephemeralPK = ephemeralSK.publicKey.toBytes(config.isEphemeralKeyCompressed);
|
||||
var encrypted = (0, index_js_2.symEncrypt)(sharedKey, data);
|
||||
return (0, utils_1.concatBytes)(ephemeralPK, encrypted);
|
||||
}
|
||||
/**
|
||||
* Decrypts data with a receiver's private key.
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, this function will always return `Uint8Array`.
|
||||
* To preserve the pre-0.5.0 behavior of returning a `Buffer`, wrap the result with `Buffer.from(decrypt(...))`.
|
||||
*
|
||||
* @param receiverRawSK - Raw private key of the receiver, either as a hex `string` or a `Uint8Array`.
|
||||
* @param data - Data to decrypt.
|
||||
* @returns Decrypted plain text.
|
||||
*/
|
||||
function decrypt(receiverRawSK, data) {
|
||||
var decrypted = _decrypt(receiverRawSK, data);
|
||||
return types_js_1.IS_BUFFER_SUPPORTED ? Buffer.from(decrypted) : decrypted;
|
||||
}
|
||||
function _decrypt(receiverRawSK, data, config) {
|
||||
if (config === void 0) { config = config_js_1.ECIES_CONFIG; }
|
||||
var curve = config.ellipticCurve;
|
||||
var receiverSK = receiverRawSK instanceof Uint8Array
|
||||
? new index_js_1.PrivateKey(receiverRawSK, curve)
|
||||
: index_js_1.PrivateKey.fromHex(receiverRawSK, curve);
|
||||
var keySize = config.ephemeralKeySize;
|
||||
var ephemeralPK = new index_js_1.PublicKey(data.subarray(0, keySize), curve);
|
||||
var encrypted = data.subarray(keySize);
|
||||
var sharedKey = ephemeralPK.decapsulate(receiverSK, config.isHkdfKeyCompressed);
|
||||
return (0, index_js_2.symDecrypt)(sharedKey, encrypted);
|
||||
}
|
||||
var config_js_2 = require("./config.js");
|
||||
Object.defineProperty(exports, "ECIES_CONFIG", { enumerable: true, get: function () { return config_js_2.ECIES_CONFIG; } });
|
||||
var index_js_3 = require("./keys/index.js");
|
||||
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return index_js_3.PrivateKey; } });
|
||||
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return index_js_3.PublicKey; } });
|
||||
/** @deprecated - use `import * as utils from "eciesjs/utils"` instead. */
|
||||
exports.utils = {
|
||||
// TODO: remove these after 0.5.0
|
||||
aesEncrypt: index_js_2.aesEncrypt,
|
||||
aesDecrypt: index_js_2.aesDecrypt,
|
||||
symEncrypt: index_js_2.symEncrypt,
|
||||
symDecrypt: index_js_2.symDecrypt,
|
||||
decodeHex: index_js_2.decodeHex,
|
||||
getValidSecret: index_js_2.getValidSecret,
|
||||
remove0x: index_js_2.remove0x,
|
||||
};
|
||||
34
node_modules/eciesjs/dist/keys/PrivateKey.d.ts
generated
vendored
Normal file
34
node_modules/eciesjs/dist/keys/PrivateKey.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { EllipticCurve } from "../config.js";
|
||||
import { PublicKey } from "./PublicKey.js";
|
||||
export declare class PrivateKey {
|
||||
static fromHex(hex: string, curve?: EllipticCurve): PrivateKey;
|
||||
private readonly curve?;
|
||||
private readonly data;
|
||||
readonly publicKey: PublicKey;
|
||||
/**
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, `Uint8Array` will be returned instead of `Buffer`.
|
||||
*/
|
||||
get secret(): Uint8Array;
|
||||
constructor(secret?: Uint8Array, curve?: EllipticCurve);
|
||||
toHex(): string;
|
||||
/**
|
||||
* Derives a shared secret from ephemeral private key (this) and receiver's public key (pk).
|
||||
* @description The shared key is 32 bytes, derived with `HKDF-SHA256(senderPoint || sharedPoint)`. See implementation for details.
|
||||
*
|
||||
* There are some variations in different ECIES implementations:
|
||||
* which key derivation function to use, compressed or uncompressed `senderPoint`/`sharedPoint`, whether to include `senderPoint`, etc.
|
||||
*
|
||||
* Because the entropy of `senderPoint`, `sharedPoint` is enough high[1], we don't need salt to derive keys.
|
||||
*
|
||||
* [1]: Two reasons: the public keys are "random" bytes (albeit secp256k1 public keys are **not uniformly** random), and ephemeral keys are generated in every encryption.
|
||||
*
|
||||
* @param pk - Receiver's public key.
|
||||
* @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.
|
||||
*/
|
||||
encapsulate(pk: PublicKey, compressed?: boolean): Uint8Array;
|
||||
multiply(pk: PublicKey, compressed?: boolean): Uint8Array;
|
||||
equals(other: PrivateKey): boolean;
|
||||
}
|
||||
71
node_modules/eciesjs/dist/keys/PrivateKey.js
generated
vendored
Normal file
71
node_modules/eciesjs/dist/keys/PrivateKey.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PrivateKey = void 0;
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var types_js_1 = require("../types.js");
|
||||
var index_js_1 = require("../utils/index.js");
|
||||
var PublicKey_js_1 = require("./PublicKey.js");
|
||||
var PrivateKey = /** @class */ (function () {
|
||||
function PrivateKey(secret, curve) {
|
||||
this.curve = curve;
|
||||
if (secret === undefined) {
|
||||
this.data = (0, index_js_1.getValidSecret)(curve);
|
||||
}
|
||||
else if ((0, index_js_1.isValidPrivateKey)(secret, curve)) {
|
||||
this.data = secret;
|
||||
}
|
||||
else {
|
||||
throw new Error("Invalid private key");
|
||||
}
|
||||
this.publicKey = new PublicKey_js_1.PublicKey((0, index_js_1.getPublicKey)(this.data, curve), curve);
|
||||
}
|
||||
PrivateKey.fromHex = function (hex, curve) {
|
||||
return new PrivateKey((0, index_js_1.decodeHex)(hex), curve);
|
||||
};
|
||||
Object.defineProperty(PrivateKey.prototype, "secret", {
|
||||
/**
|
||||
* @description
|
||||
* In version 0.4.18, `Buffer` is returned when available, otherwise `Uint8Array`.
|
||||
* From version 0.5.0, `Uint8Array` will be returned instead of `Buffer`.
|
||||
*/
|
||||
get: function () {
|
||||
// TODO: Uint8Array only
|
||||
return types_js_1.IS_BUFFER_SUPPORTED ? Buffer.from(this.data) : this.data;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
PrivateKey.prototype.toHex = function () {
|
||||
return (0, utils_1.bytesToHex)(this.data);
|
||||
};
|
||||
/**
|
||||
* Derives a shared secret from ephemeral private key (this) and receiver's public key (pk).
|
||||
* @description The shared key is 32 bytes, derived with `HKDF-SHA256(senderPoint || sharedPoint)`. See implementation for details.
|
||||
*
|
||||
* There are some variations in different ECIES implementations:
|
||||
* which key derivation function to use, compressed or uncompressed `senderPoint`/`sharedPoint`, whether to include `senderPoint`, etc.
|
||||
*
|
||||
* Because the entropy of `senderPoint`, `sharedPoint` is enough high[1], we don't need salt to derive keys.
|
||||
*
|
||||
* [1]: Two reasons: the public keys are "random" bytes (albeit secp256k1 public keys are **not uniformly** random), and ephemeral keys are generated in every encryption.
|
||||
*
|
||||
* @param pk - Receiver's public key.
|
||||
* @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.
|
||||
*/
|
||||
PrivateKey.prototype.encapsulate = function (pk, compressed) {
|
||||
if (compressed === void 0) { compressed = false; }
|
||||
var senderPoint = this.publicKey.toBytes(compressed);
|
||||
var sharedPoint = this.multiply(pk, compressed);
|
||||
return (0, index_js_1.getSharedKey)(senderPoint, sharedPoint);
|
||||
};
|
||||
PrivateKey.prototype.multiply = function (pk, compressed) {
|
||||
if (compressed === void 0) { compressed = false; }
|
||||
return (0, index_js_1.getSharedPoint)(this.data, pk.toBytes(true), compressed, this.curve);
|
||||
};
|
||||
PrivateKey.prototype.equals = function (other) {
|
||||
return (0, utils_1.equalBytes)(this.data, other.data);
|
||||
};
|
||||
return PrivateKey;
|
||||
}());
|
||||
exports.PrivateKey = PrivateKey;
|
||||
26
node_modules/eciesjs/dist/keys/PublicKey.d.ts
generated
vendored
Normal file
26
node_modules/eciesjs/dist/keys/PublicKey.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { EllipticCurve } from "../config.js";
|
||||
import type { PrivateKey } from "./PrivateKey.js";
|
||||
export declare class PublicKey {
|
||||
static fromHex(hex: string, curve?: EllipticCurve): PublicKey;
|
||||
private readonly data;
|
||||
private readonly dataUncompressed;
|
||||
private get _uncompressed();
|
||||
/** @deprecated - use `PublicKey.toBytes(false)` instead. You may also need `Buffer.from`. */
|
||||
get uncompressed(): Uint8Array;
|
||||
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */
|
||||
get compressed(): Uint8Array;
|
||||
constructor(data: Uint8Array, curve?: EllipticCurve);
|
||||
toBytes(compressed?: boolean): Uint8Array;
|
||||
toHex(compressed?: boolean): string;
|
||||
/**
|
||||
* Derives a shared secret from receiver's private key (sk) and ephemeral public key (this).
|
||||
* Opposite of `encapsulate`.
|
||||
* @see PrivateKey.encapsulate
|
||||
*
|
||||
* @param sk - Receiver's private key.
|
||||
* @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.
|
||||
*/
|
||||
decapsulate(sk: PrivateKey, compressed?: boolean): Uint8Array;
|
||||
equals(other: PublicKey): boolean;
|
||||
}
|
||||
72
node_modules/eciesjs/dist/keys/PublicKey.js
generated
vendored
Normal file
72
node_modules/eciesjs/dist/keys/PublicKey.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PublicKey = void 0;
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var types_js_1 = require("../types.js");
|
||||
var index_js_1 = require("../utils/index.js");
|
||||
var PublicKey = /** @class */ (function () {
|
||||
function PublicKey(data, curve) {
|
||||
// data can be either compressed or uncompressed if secp256k1
|
||||
var compressed = (0, index_js_1.convertPublicKeyFormat)(data, true, curve);
|
||||
var uncompressed = (0, index_js_1.convertPublicKeyFormat)(data, false, curve);
|
||||
this.data = compressed;
|
||||
this.dataUncompressed =
|
||||
compressed.length !== uncompressed.length ? uncompressed : null;
|
||||
}
|
||||
PublicKey.fromHex = function (hex, curve) {
|
||||
return new PublicKey((0, index_js_1.hexToPublicKey)(hex, curve), curve);
|
||||
};
|
||||
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: delete
|
||||
return types_js_1.IS_BUFFER_SUPPORTED ? Buffer.from(this._uncompressed) : this._uncompressed;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(PublicKey.prototype, "compressed", {
|
||||
/** @deprecated - use `PublicKey.toBytes()` instead. You may also need `Buffer.from`. */
|
||||
get: function () {
|
||||
// TODO: delete
|
||||
return types_js_1.IS_BUFFER_SUPPORTED ? Buffer.from(this.data) : this.data;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
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; }
|
||||
return (0, utils_1.bytesToHex)(this.toBytes(compressed));
|
||||
};
|
||||
/**
|
||||
* Derives a shared secret from receiver's private key (sk) and ephemeral public key (this).
|
||||
* Opposite of `encapsulate`.
|
||||
* @see PrivateKey.encapsulate
|
||||
*
|
||||
* @param sk - Receiver's private key.
|
||||
* @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.
|
||||
*/
|
||||
PublicKey.prototype.decapsulate = function (sk, compressed) {
|
||||
if (compressed === void 0) { compressed = false; }
|
||||
var senderPoint = this.toBytes(compressed);
|
||||
var sharedPoint = sk.multiply(this, compressed);
|
||||
return (0, index_js_1.getSharedKey)(senderPoint, sharedPoint);
|
||||
};
|
||||
PublicKey.prototype.equals = function (other) {
|
||||
return (0, utils_1.equalBytes)(this.data, other.data);
|
||||
};
|
||||
return PublicKey;
|
||||
}());
|
||||
exports.PublicKey = PublicKey;
|
||||
2
node_modules/eciesjs/dist/keys/index.d.ts
generated
vendored
Normal file
2
node_modules/eciesjs/dist/keys/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { PrivateKey } from "./PrivateKey.js";
|
||||
export { PublicKey } from "./PublicKey.js";
|
||||
9
node_modules/eciesjs/dist/keys/index.js
generated
vendored
Normal file
9
node_modules/eciesjs/dist/keys/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PublicKey = exports.PrivateKey = void 0;
|
||||
// treat Buffer as Uint8array, i.e. no call of Buffer specific functions
|
||||
// finally Uint8Array only
|
||||
var PrivateKey_js_1 = require("./PrivateKey.js");
|
||||
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return PrivateKey_js_1.PrivateKey; } });
|
||||
var PublicKey_js_1 = require("./PublicKey.js");
|
||||
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return PublicKey_js_1.PublicKey; } });
|
||||
1
node_modules/eciesjs/dist/types.d.ts
generated
vendored
Normal file
1
node_modules/eciesjs/dist/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const IS_BUFFER_SUPPORTED: boolean;
|
||||
4
node_modules/eciesjs/dist/types.js
generated
vendored
Normal file
4
node_modules/eciesjs/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IS_BUFFER_SUPPORTED = void 0;
|
||||
exports.IS_BUFFER_SUPPORTED = typeof Buffer !== "undefined" && typeof Buffer.from === "function";
|
||||
7
node_modules/eciesjs/dist/utils/elliptic.d.ts
generated
vendored
Normal file
7
node_modules/eciesjs/dist/utils/elliptic.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { type EllipticCurve } from "../config.js";
|
||||
export declare const getValidSecret: (curve?: EllipticCurve) => Uint8Array;
|
||||
export declare const isValidPrivateKey: (secret: Uint8Array, curve?: EllipticCurve) => boolean;
|
||||
export declare const getPublicKey: (secret: Uint8Array, curve?: EllipticCurve) => Uint8Array;
|
||||
export declare const getSharedPoint: (sk: Uint8Array, pk: Uint8Array, compressed?: boolean, curve?: EllipticCurve) => Uint8Array;
|
||||
export declare const convertPublicKeyFormat: (pk: Uint8Array, compressed: boolean, curve?: EllipticCurve) => Uint8Array;
|
||||
export declare const hexToPublicKey: (hex: string, curve?: EllipticCurve) => Uint8Array;
|
||||
75
node_modules/eciesjs/dist/utils/elliptic.js
generated
vendored
Normal file
75
node_modules/eciesjs/dist/utils/elliptic.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.hexToPublicKey = exports.convertPublicKeyFormat = exports.getSharedPoint = exports.getPublicKey = exports.isValidPrivateKey = exports.getValidSecret = void 0;
|
||||
var webcrypto_1 = require("@noble/ciphers/webcrypto");
|
||||
var ed25519_1 = require("@noble/curves/ed25519");
|
||||
var secp256k1_1 = require("@noble/curves/secp256k1");
|
||||
var config_js_1 = require("../config.js");
|
||||
var consts_js_1 = require("../consts.js");
|
||||
var hex_js_1 = require("./hex.js");
|
||||
var getValidSecret = function (curve) {
|
||||
var key;
|
||||
do {
|
||||
key = (0, webcrypto_1.randomBytes)(consts_js_1.SECRET_KEY_LENGTH);
|
||||
} while (!(0, exports.isValidPrivateKey)(key, curve));
|
||||
return key;
|
||||
};
|
||||
exports.getValidSecret = getValidSecret;
|
||||
var isValidPrivateKey = function (secret, curve) {
|
||||
// on secp256k1: only key ∈ (0, group order) is valid
|
||||
// on curve25519: any 32-byte key is valid
|
||||
return _exec(curve, function (curve) { return curve.utils.isValidSecretKey(secret); }, function () { return true; }, function () { return true; });
|
||||
};
|
||||
exports.isValidPrivateKey = isValidPrivateKey;
|
||||
var getPublicKey = function (secret, curve) {
|
||||
return _exec(curve, function (curve) { return curve.getPublicKey(secret); }, function (curve) { return curve.getPublicKey(secret); }, function (curve) { return curve.getPublicKey(secret); });
|
||||
};
|
||||
exports.getPublicKey = getPublicKey;
|
||||
var getSharedPoint = function (sk, pk, compressed, curve) {
|
||||
return _exec(curve, function (curve) { return curve.getSharedSecret(sk, pk, compressed); }, function (curve) { return curve.getSharedSecret(sk, pk); }, function (curve) { return getSharedPointOnEd25519(curve, sk, pk); });
|
||||
};
|
||||
exports.getSharedPoint = getSharedPoint;
|
||||
var convertPublicKeyFormat = function (pk, compressed, curve) {
|
||||
// only for secp256k1
|
||||
return _exec(curve, function (curve) {
|
||||
return curve.getSharedSecret(Uint8Array.from(Array(31).fill(0).concat([1])), // 1 as private key
|
||||
pk, compressed);
|
||||
}, function () { return pk; }, function () { return pk; });
|
||||
};
|
||||
exports.convertPublicKeyFormat = convertPublicKeyFormat;
|
||||
var hexToPublicKey = function (hex, curve) {
|
||||
var decoded = (0, hex_js_1.decodeHex)(hex);
|
||||
return _exec(curve, function () { return compatEthPublicKey(decoded); }, function () { return decoded; }, function () { return decoded; });
|
||||
};
|
||||
exports.hexToPublicKey = hexToPublicKey;
|
||||
function _exec(curve, secp256k1Callback, x25519Callback, ed25519Callback) {
|
||||
var _curve = curve || config_js_1.ECIES_CONFIG.ellipticCurve; // TODO: remove after 0.5.0
|
||||
/* v8 ignore else -- @preserve */
|
||||
if (_curve === "secp256k1") {
|
||||
return secp256k1Callback(secp256k1_1.secp256k1);
|
||||
}
|
||||
else if (_curve === "x25519") {
|
||||
return x25519Callback(ed25519_1.x25519);
|
||||
}
|
||||
else if (_curve === "ed25519") {
|
||||
return ed25519Callback(ed25519_1.ed25519);
|
||||
}
|
||||
else {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
var compatEthPublicKey = function (pk) {
|
||||
if (pk.length === consts_js_1.ETH_PUBLIC_KEY_SIZE) {
|
||||
var fixed = new Uint8Array(1 + pk.length);
|
||||
fixed.set([0x04]);
|
||||
fixed.set(pk, 1);
|
||||
return fixed;
|
||||
}
|
||||
return pk;
|
||||
};
|
||||
var getSharedPointOnEd25519 = function (curve, sk, pk) {
|
||||
// Note: scalar is hashed from sk
|
||||
var scalar = curve.utils.getExtendedPublicKey(sk).scalar;
|
||||
var point = curve.Point.fromBytes(pk).multiply(scalar);
|
||||
return point.toBytes();
|
||||
};
|
||||
2
node_modules/eciesjs/dist/utils/hash.d.ts
generated
vendored
Normal file
2
node_modules/eciesjs/dist/utils/hash.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const deriveKey: (master: Uint8Array, salt?: Uint8Array, info?: Uint8Array) => Uint8Array;
|
||||
export declare const getSharedKey: (...parts: Uint8Array[]) => Uint8Array;
|
||||
19
node_modules/eciesjs/dist/utils/hash.js
generated
vendored
Normal file
19
node_modules/eciesjs/dist/utils/hash.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getSharedKey = exports.deriveKey = void 0;
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var hkdf_1 = require("@noble/hashes/hkdf");
|
||||
var sha2_1 = require("@noble/hashes/sha2");
|
||||
var deriveKey = function (master, salt, info) {
|
||||
// 32 bytes shared secret for aes256 and xchacha20 derived from HKDF-SHA256
|
||||
return (0, hkdf_1.hkdf)(sha2_1.sha256, master, salt, info, 32);
|
||||
};
|
||||
exports.deriveKey = deriveKey;
|
||||
var getSharedKey = function () {
|
||||
var parts = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
parts[_i] = arguments[_i];
|
||||
}
|
||||
return (0, exports.deriveKey)(utils_1.concatBytes.apply(void 0, parts));
|
||||
};
|
||||
exports.getSharedKey = getSharedKey;
|
||||
2
node_modules/eciesjs/dist/utils/hex.d.ts
generated
vendored
Normal file
2
node_modules/eciesjs/dist/utils/hex.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const remove0x: (hex: string) => string;
|
||||
export declare const decodeHex: (hex: string) => Uint8Array;
|
||||
10
node_modules/eciesjs/dist/utils/hex.js
generated
vendored
Normal file
10
node_modules/eciesjs/dist/utils/hex.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.decodeHex = exports.remove0x = void 0;
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var remove0x = function (hex) {
|
||||
return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
||||
};
|
||||
exports.remove0x = remove0x;
|
||||
var decodeHex = function (hex) { return (0, utils_1.hexToBytes)((0, exports.remove0x)(hex)); };
|
||||
exports.decodeHex = decodeHex;
|
||||
4
node_modules/eciesjs/dist/utils/index.d.ts
generated
vendored
Normal file
4
node_modules/eciesjs/dist/utils/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./elliptic.js";
|
||||
export * from "./hash.js";
|
||||
export * from "./hex.js";
|
||||
export * from "./symmetric.js";
|
||||
20
node_modules/eciesjs/dist/utils/index.js
generated
vendored
Normal file
20
node_modules/eciesjs/dist/utils/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./elliptic.js"), exports);
|
||||
__exportStar(require("./hash.js"), exports);
|
||||
__exportStar(require("./hex.js"), exports);
|
||||
__exportStar(require("./symmetric.js"), exports);
|
||||
6
node_modules/eciesjs/dist/utils/symmetric.d.ts
generated
vendored
Normal file
6
node_modules/eciesjs/dist/utils/symmetric.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare const symEncrypt: (key: Uint8Array, plainText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
export declare const symDecrypt: (key: Uint8Array, cipherText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
/** @deprecated - use `symEncrypt` instead. */
|
||||
export declare const aesEncrypt: (key: Uint8Array, plainText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
/** @deprecated - use `symDecrypt` instead. */
|
||||
export declare const aesDecrypt: (key: Uint8Array, cipherText: Uint8Array, AAD?: Uint8Array) => Uint8Array;
|
||||
63
node_modules/eciesjs/dist/utils/symmetric.js
generated
vendored
Normal file
63
node_modules/eciesjs/dist/utils/symmetric.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aesDecrypt = exports.aesEncrypt = exports.symDecrypt = exports.symEncrypt = void 0;
|
||||
var aes_1 = require("@ecies/ciphers/aes");
|
||||
var chacha_1 = require("@ecies/ciphers/chacha");
|
||||
var utils_1 = require("@noble/ciphers/utils");
|
||||
var webcrypto_1 = require("@noble/ciphers/webcrypto");
|
||||
var config_js_1 = require("../config.js");
|
||||
var consts_js_1 = require("../consts.js");
|
||||
var symEncrypt = function (key, plainText, AAD) {
|
||||
return _exec(_encrypt, config_js_1.ECIES_CONFIG.symmetricAlgorithm, config_js_1.ECIES_CONFIG.symmetricNonceLength, key, plainText, AAD);
|
||||
};
|
||||
exports.symEncrypt = symEncrypt;
|
||||
var symDecrypt = function (key, cipherText, AAD) {
|
||||
return _exec(_decrypt, config_js_1.ECIES_CONFIG.symmetricAlgorithm, config_js_1.ECIES_CONFIG.symmetricNonceLength, key, cipherText, AAD);
|
||||
};
|
||||
exports.symDecrypt = symDecrypt;
|
||||
/** @deprecated - use `symEncrypt` instead. */
|
||||
exports.aesEncrypt = exports.symEncrypt; // TODO: delete
|
||||
/** @deprecated - use `symDecrypt` instead. */
|
||||
exports.aesDecrypt = exports.symDecrypt; // TODO: delete
|
||||
function _exec(callback, algorithm, nonceLength, // aes-256-gcm only
|
||||
key, data, AAD) {
|
||||
if (algorithm === "aes-256-gcm") {
|
||||
return callback(aes_1.aes256gcm, key, data, nonceLength, consts_js_1.AEAD_TAG_LENGTH, AAD);
|
||||
}
|
||||
else if (algorithm === "xchacha20") {
|
||||
return callback(chacha_1.xchacha20, key, data, consts_js_1.XCHACHA20_NONCE_LENGTH, consts_js_1.AEAD_TAG_LENGTH, AAD);
|
||||
}
|
||||
else if (algorithm === "aes-256-cbc") {
|
||||
// NOT RECOMMENDED. There is neither AAD nor AEAD tag in cbc mode
|
||||
// aes-256-cbc always uses 16 bytes iv
|
||||
return callback(aes_1.aes256cbc, key, data, 16, 0);
|
||||
}
|
||||
else {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
}
|
||||
function _encrypt(func, key, data, nonceLength, tagLength, AAD) {
|
||||
var nonce = (0, webcrypto_1.randomBytes)(nonceLength);
|
||||
var cipher = func(key, nonce, AAD);
|
||||
// @noble/ciphers format: cipherText || tag
|
||||
var encrypted = cipher.encrypt(data);
|
||||
if (tagLength === 0) {
|
||||
return (0, utils_1.concatBytes)(nonce, encrypted);
|
||||
}
|
||||
var cipherTextLength = encrypted.length - tagLength;
|
||||
var cipherText = encrypted.subarray(0, cipherTextLength);
|
||||
var tag = encrypted.subarray(cipherTextLength);
|
||||
// ecies payload format: pk || nonce || tag || cipherText
|
||||
return (0, utils_1.concatBytes)(nonce, tag, cipherText);
|
||||
}
|
||||
function _decrypt(func, key, data, nonceLength, tagLength, AAD) {
|
||||
var nonce = data.subarray(0, nonceLength);
|
||||
var cipher = func(key, Uint8Array.from(nonce), AAD); // to reset byteOffset
|
||||
var encrypted = data.subarray(nonceLength);
|
||||
if (tagLength === 0) {
|
||||
return cipher.decrypt(encrypted);
|
||||
}
|
||||
var tag = encrypted.subarray(0, tagLength);
|
||||
var cipherText = encrypted.subarray(tagLength);
|
||||
return cipher.decrypt((0, utils_1.concatBytes)(cipherText, tag));
|
||||
}
|
||||
81
node_modules/eciesjs/package.json
generated
vendored
Normal file
81
node_modules/eciesjs/package.json
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "eciesjs",
|
||||
"description": "Elliptic Curve Integrated Encryption Scheme for secp256k1/curve25519",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Weiliang Li",
|
||||
"email": "to.be.impressive@gmail.com",
|
||||
"url": "https://github.com/kigawas"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ecies/js.git"
|
||||
},
|
||||
"version": "0.4.18",
|
||||
"engines": {
|
||||
"node": ">=16",
|
||||
"bun": ">=1",
|
||||
"deno": ">=2"
|
||||
},
|
||||
"keywords": [
|
||||
"secp256k1",
|
||||
"curve25519",
|
||||
"crypto",
|
||||
"elliptic curves",
|
||||
"ecies",
|
||||
"bitcoin",
|
||||
"ethereum",
|
||||
"cryptocurrency"
|
||||
],
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./config": {
|
||||
"types": "./dist/config.d.ts",
|
||||
"default": "./dist/config.js"
|
||||
},
|
||||
"./consts": {
|
||||
"types": "./dist/consts.d.ts",
|
||||
"default": "./dist/consts.js"
|
||||
},
|
||||
"./utils": {
|
||||
"types": "./dist/utils/index.d.ts",
|
||||
"default": "./dist/utils/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"check": "biome check",
|
||||
"check:fix": "biome check --fix",
|
||||
"build": "npx tsc",
|
||||
"test": "vitest",
|
||||
"test:browser": "node ./scripts/gen-browser-tests.mjs && cd tests-browser && pnpm test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ecies/ciphers": "^0.2.5",
|
||||
"@noble/ciphers": "^1.3.0",
|
||||
"@noble/curves": "^1.9.7",
|
||||
"@noble/hashes": "^1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "2.4.5",
|
||||
"@types/node": "^25.3.5",
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"typescript": "^5.9.3",
|
||||
"undici": "^7.22.0",
|
||||
"vitest": "^4.0.18"
|
||||
},
|
||||
"pnpm": {
|
||||
"onlyBuiltDependencies": [
|
||||
"@biomejs/biome",
|
||||
"esbuild"
|
||||
]
|
||||
},
|
||||
"packageManager": "pnpm@10.30.3+sha512.c961d1e0a2d8e354ecaa5166b822516668b7f44cb5bd95122d590dd81922f606f5473b6d23ec4a5be05e7fcd18e8488d47d978bbe981872f1145d06e9a740017"
|
||||
}
|
||||
Reference in New Issue
Block a user