修改后台权限

This commit is contained in:
yoyuzh
2026-03-24 14:30:59 +08:00
parent 00f902f475
commit b2d9db7be9
9310 changed files with 1246063 additions and 48 deletions

24
node_modules/eciesjs/dist/config.d.ts generated vendored Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1 @@
export declare const IS_BUFFER_SUPPORTED: boolean;

4
node_modules/eciesjs/dist/types.js generated vendored Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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));
}