mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 12:38:03 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import type { EncryptedJsonEncoding, EncryptedJsonVersion } from './types.js';
|
||||
export declare const ENCODING: EncryptedJsonEncoding[];
|
||||
export declare const ENCODING_NONE: EncryptedJsonEncoding[];
|
||||
export declare const ENCODING_VERSION: EncryptedJsonVersion;
|
||||
export declare const NONCE_LENGTH = 24;
|
||||
export declare const SCRYPT_LENGTH: number;
|
||||
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SCRYPT_LENGTH = exports.NONCE_LENGTH = exports.ENCODING_VERSION = exports.ENCODING_NONE = exports.ENCODING = void 0;
|
||||
exports.ENCODING = ['scrypt', 'xsalsa20-poly1305'];
|
||||
exports.ENCODING_NONE = ['none'];
|
||||
exports.ENCODING_VERSION = '3';
|
||||
exports.NONCE_LENGTH = 24;
|
||||
exports.SCRYPT_LENGTH = 32 + (3 * 4);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { EncryptedJson } from './types.js';
|
||||
export declare function jsonDecrypt({ encoded, encoding }: EncryptedJson, passphrase?: string | null): Uint8Array;
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jsonDecrypt = jsonDecrypt;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const index_js_1 = require("../base64/index.js");
|
||||
const decryptData_js_1 = require("./decryptData.js");
|
||||
function jsonDecrypt({ encoded, encoding }, passphrase) {
|
||||
if (!encoded) {
|
||||
throw new Error('No encrypted data available to decode');
|
||||
}
|
||||
return (0, decryptData_js_1.jsonDecryptData)((0, util_1.isHex)(encoded)
|
||||
? (0, util_1.hexToU8a)(encoded)
|
||||
: (0, index_js_1.base64Decode)(encoded), passphrase, Array.isArray(encoding.type)
|
||||
? encoding.type
|
||||
: [encoding.type]);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { EncryptedJsonEncoding } from './types.js';
|
||||
export declare function jsonDecryptData(encrypted?: Uint8Array | null, passphrase?: string | null, encType?: EncryptedJsonEncoding[]): Uint8Array;
|
||||
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jsonDecryptData = jsonDecryptData;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const index_js_1 = require("../nacl/index.js");
|
||||
const index_js_2 = require("../scrypt/index.js");
|
||||
const constants_js_1 = require("./constants.js");
|
||||
function jsonDecryptData(encrypted, passphrase, encType = constants_js_1.ENCODING) {
|
||||
if (!encrypted) {
|
||||
throw new Error('No encrypted data available to decode');
|
||||
}
|
||||
else if (encType.includes('xsalsa20-poly1305') && !passphrase) {
|
||||
throw new Error('Password required to decode encrypted data');
|
||||
}
|
||||
let encoded = encrypted;
|
||||
if (passphrase) {
|
||||
let password;
|
||||
if (encType.includes('scrypt')) {
|
||||
const { params, salt } = (0, index_js_2.scryptFromU8a)(encrypted);
|
||||
password = (0, index_js_2.scryptEncode)(passphrase, salt, params).password;
|
||||
encrypted = encrypted.subarray(constants_js_1.SCRYPT_LENGTH);
|
||||
}
|
||||
else {
|
||||
password = (0, util_1.stringToU8a)(passphrase);
|
||||
}
|
||||
encoded = (0, index_js_1.naclDecrypt)(encrypted.subarray(constants_js_1.NONCE_LENGTH), encrypted.subarray(0, constants_js_1.NONCE_LENGTH), (0, util_1.u8aFixLength)(password, 256, true));
|
||||
}
|
||||
if (!encoded) {
|
||||
throw new Error('Unable to decode using the supplied passphrase');
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { EncryptedJson } from './types.js';
|
||||
export declare function jsonEncrypt(data: Uint8Array, contentType: string[], passphrase?: string | null): EncryptedJson;
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jsonEncrypt = jsonEncrypt;
|
||||
const util_1 = require("@pezkuwi/util");
|
||||
const index_js_1 = require("../nacl/index.js");
|
||||
const index_js_2 = require("../scrypt/index.js");
|
||||
const encryptFormat_js_1 = require("./encryptFormat.js");
|
||||
function jsonEncrypt(data, contentType, passphrase) {
|
||||
let isEncrypted = false;
|
||||
let encoded = data;
|
||||
if (passphrase) {
|
||||
const { params, password, salt } = (0, index_js_2.scryptEncode)(passphrase);
|
||||
const { encrypted, nonce } = (0, index_js_1.naclEncrypt)(encoded, password.subarray(0, 32));
|
||||
isEncrypted = true;
|
||||
encoded = (0, util_1.u8aConcat)((0, index_js_2.scryptToU8a)(salt, params), nonce, encrypted);
|
||||
}
|
||||
return (0, encryptFormat_js_1.jsonEncryptFormat)(encoded, contentType, isEncrypted);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import type { EncryptedJson } from './types.js';
|
||||
export declare function jsonEncryptFormat(encoded: Uint8Array, contentType: string[], isEncrypted: boolean): EncryptedJson;
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jsonEncryptFormat = jsonEncryptFormat;
|
||||
const index_js_1 = require("../base64/index.js");
|
||||
const constants_js_1 = require("./constants.js");
|
||||
function jsonEncryptFormat(encoded, contentType, isEncrypted) {
|
||||
return {
|
||||
encoded: (0, index_js_1.base64Encode)(encoded),
|
||||
encoding: {
|
||||
content: contentType,
|
||||
type: isEncrypted
|
||||
? constants_js_1.ENCODING
|
||||
: constants_js_1.ENCODING_NONE,
|
||||
version: constants_js_1.ENCODING_VERSION
|
||||
}
|
||||
};
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export { jsonDecrypt } from './decrypt.js';
|
||||
export { jsonDecryptData } from './decryptData.js';
|
||||
export { jsonEncrypt } from './encrypt.js';
|
||||
export { jsonEncryptFormat } from './encryptFormat.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.jsonEncryptFormat = exports.jsonEncrypt = exports.jsonDecryptData = exports.jsonDecrypt = void 0;
|
||||
var decrypt_js_1 = require("./decrypt.js");
|
||||
Object.defineProperty(exports, "jsonDecrypt", { enumerable: true, get: function () { return decrypt_js_1.jsonDecrypt; } });
|
||||
var decryptData_js_1 = require("./decryptData.js");
|
||||
Object.defineProperty(exports, "jsonDecryptData", { enumerable: true, get: function () { return decryptData_js_1.jsonDecryptData; } });
|
||||
var encrypt_js_1 = require("./encrypt.js");
|
||||
Object.defineProperty(exports, "jsonEncrypt", { enumerable: true, get: function () { return encrypt_js_1.jsonEncrypt; } });
|
||||
var encryptFormat_js_1 = require("./encryptFormat.js");
|
||||
Object.defineProperty(exports, "jsonEncryptFormat", { enumerable: true, get: function () { return encryptFormat_js_1.jsonEncryptFormat; } });
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export type EncryptedJsonVersion = '0' | '1' | '2' | '3';
|
||||
export type EncryptedJsonEncoding = 'none' | 'scrypt' | 'xsalsa20-poly1305';
|
||||
export interface EncryptedJsonDescriptor {
|
||||
/** Descriptor for the content */
|
||||
content: string[];
|
||||
/** The encoding (in current/latest versions this is always an array) */
|
||||
type: EncryptedJsonEncoding | EncryptedJsonEncoding[];
|
||||
/** The version of encoding applied */
|
||||
version: EncryptedJsonVersion;
|
||||
}
|
||||
export interface EncryptedJson {
|
||||
/** The encoded string */
|
||||
encoded: string;
|
||||
/** The encoding used */
|
||||
encoding: EncryptedJsonDescriptor;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Reference in New Issue
Block a user