修改后台权限
This commit is contained in:
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));
|
||||
}
|
||||
Reference in New Issue
Block a user