@olane/o-tools-common 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -9
- package/dist/vault/index.d.ts +0 -2
- package/dist/vault/index.d.ts.map +0 -1
- package/dist/vault/index.js +0 -1
- package/dist/vault/lib/encryption.d.ts +0 -41
- package/dist/vault/lib/encryption.d.ts.map +0 -1
- package/dist/vault/lib/encryption.js +0 -99
- package/dist/vault/methods/vault.methods.d.ts +0 -5
- package/dist/vault/methods/vault.methods.d.ts.map +0 -1
- package/dist/vault/methods/vault.methods.js +0 -37
- package/dist/vault/vault.tool.d.ts +0 -10
- package/dist/vault/vault.tool.d.ts.map +0 -1
- package/dist/vault/vault.tool.js +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-tools-common",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@eslint/eslintrc": "^3.3.1",
|
|
36
36
|
"@eslint/js": "^9.29.0",
|
|
37
|
-
"@olane/o-config": "
|
|
38
|
-
"@olane/o-core": "
|
|
39
|
-
"@olane/o-protocol": "
|
|
40
|
-
"@olane/o-tool": "
|
|
37
|
+
"@olane/o-config": "0.4.1",
|
|
38
|
+
"@olane/o-core": "0.4.1",
|
|
39
|
+
"@olane/o-protocol": "0.4.1",
|
|
40
|
+
"@olane/o-tool": "0.4.1",
|
|
41
41
|
"@tsconfig/node20": "^20.1.6",
|
|
42
42
|
"@types/jest": "^30.0.0",
|
|
43
43
|
"@typescript-eslint/eslint-plugin": "^8.34.1",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"typescript": "5.4.5"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@olane/o-config": "^0.4.
|
|
59
|
-
"@olane/o-core": "^0.4.
|
|
60
|
-
"@olane/o-protocol": "^0.4.
|
|
61
|
-
"@olane/o-tool": "^0.4.
|
|
58
|
+
"@olane/o-config": "^0.4.1",
|
|
59
|
+
"@olane/o-core": "^0.4.1",
|
|
60
|
+
"@olane/o-protocol": "^0.4.1",
|
|
61
|
+
"@olane/o-tool": "^0.4.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"debug": "^4.4.1",
|
package/dist/vault/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vault/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/vault/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './vault.tool.js';
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
interface EncryptedData {
|
|
2
|
-
encryptedText: string;
|
|
3
|
-
iv: string;
|
|
4
|
-
tag: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class EncryptionService {
|
|
7
|
-
private readonly config;
|
|
8
|
-
private readonly secretKey;
|
|
9
|
-
constructor(secretKey?: string);
|
|
10
|
-
/**
|
|
11
|
-
* Encrypts plain text using AES-256-GCM
|
|
12
|
-
* @param plainText - Text to encrypt
|
|
13
|
-
* @returns Promise<EncryptedData> - Object containing encrypted data, IV, and authentication tag
|
|
14
|
-
*/
|
|
15
|
-
encrypt(plainText: string): Promise<EncryptedData>;
|
|
16
|
-
/**
|
|
17
|
-
* Decrypts encrypted data
|
|
18
|
-
* @param encryptedData - Object containing encrypted text, IV, and tag
|
|
19
|
-
* @returns Promise<string> - Decrypted plain text
|
|
20
|
-
*/
|
|
21
|
-
decrypt(encryptedData: EncryptedData): Promise<string>;
|
|
22
|
-
/**
|
|
23
|
-
* Encrypts and returns base64 encoded string for easy storage
|
|
24
|
-
* @param plainText - Text to encrypt
|
|
25
|
-
* @returns Promise<string> - Base64 encoded encrypted data
|
|
26
|
-
*/
|
|
27
|
-
encryptToBase64(plainText: string): Promise<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Decrypts from base64 encoded string
|
|
30
|
-
* @param base64Data - Base64 encoded encrypted data
|
|
31
|
-
* @returns Promise<string> - Decrypted plain text
|
|
32
|
-
*/
|
|
33
|
-
decryptFromBase64(base64Data: string): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* Generates a new secret key
|
|
36
|
-
* @returns string - Hex encoded secret key
|
|
37
|
-
*/
|
|
38
|
-
static generateSecretKey(): string;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
41
|
-
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/vault/lib/encryption.ts"],"names":[],"mappings":"AAGA,UAAU,aAAa;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAUD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,SAAS,CAAC,EAAE,MAAM;IAoB9B;;;;OAIG;IACU,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA+B/D;;;;OAIG;IACU,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BnE;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMhE;;;;OAIG;IACU,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnE;;;OAGG;WACW,iBAAiB,IAAI,MAAM;CAG1C"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
export class EncryptionService {
|
|
3
|
-
constructor(secretKey) {
|
|
4
|
-
this.config = {
|
|
5
|
-
algorithm: 'aes-256-gcm',
|
|
6
|
-
keyLength: 32,
|
|
7
|
-
ivLength: 16,
|
|
8
|
-
tagLength: 16,
|
|
9
|
-
};
|
|
10
|
-
// Generate or use provided secret key
|
|
11
|
-
if (secretKey) {
|
|
12
|
-
this.secretKey = crypto.scryptSync(secretKey, 'salt', this.config.keyLength);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
this.secretKey = crypto.randomBytes(this.config.keyLength);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Encrypts plain text using AES-256-GCM
|
|
20
|
-
* @param plainText - Text to encrypt
|
|
21
|
-
* @returns Promise<EncryptedData> - Object containing encrypted data, IV, and authentication tag
|
|
22
|
-
*/
|
|
23
|
-
async encrypt(plainText) {
|
|
24
|
-
try {
|
|
25
|
-
// Generate random initialization vector
|
|
26
|
-
const iv = crypto.randomBytes(this.config.ivLength);
|
|
27
|
-
// Create cipher
|
|
28
|
-
const cipher = crypto.createCipheriv(this.config.algorithm, this.secretKey, iv);
|
|
29
|
-
// Encrypt the text
|
|
30
|
-
let encryptedText = cipher.update(plainText, 'utf8', 'hex');
|
|
31
|
-
encryptedText += cipher.final('hex');
|
|
32
|
-
// Get authentication tag for GCM mode
|
|
33
|
-
const tag = cipher.getAuthTag();
|
|
34
|
-
return {
|
|
35
|
-
encryptedText,
|
|
36
|
-
iv: iv.toString('hex'),
|
|
37
|
-
tag: tag.toString('hex'),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw new Error(`Encryption failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Decrypts encrypted data
|
|
46
|
-
* @param encryptedData - Object containing encrypted text, IV, and tag
|
|
47
|
-
* @returns Promise<string> - Decrypted plain text
|
|
48
|
-
*/
|
|
49
|
-
async decrypt(encryptedData) {
|
|
50
|
-
try {
|
|
51
|
-
const { encryptedText, iv, tag } = encryptedData;
|
|
52
|
-
// Convert hex strings back to buffers
|
|
53
|
-
const ivBuffer = Buffer.from(iv, 'hex');
|
|
54
|
-
const tagBuffer = Buffer.from(tag, 'hex');
|
|
55
|
-
// Create decipher
|
|
56
|
-
const decipher = crypto.createDecipheriv(this.config.algorithm, this.secretKey, ivBuffer);
|
|
57
|
-
decipher.setAuthTag(tagBuffer);
|
|
58
|
-
// Decrypt the text
|
|
59
|
-
let decryptedText = decipher.update(encryptedText, 'hex', 'utf8');
|
|
60
|
-
decryptedText += decipher.final('utf8');
|
|
61
|
-
return decryptedText;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
throw new Error(`Decryption failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Encrypts and returns base64 encoded string for easy storage
|
|
69
|
-
* @param plainText - Text to encrypt
|
|
70
|
-
* @returns Promise<string> - Base64 encoded encrypted data
|
|
71
|
-
*/
|
|
72
|
-
async encryptToBase64(plainText) {
|
|
73
|
-
const encryptedData = await this.encrypt(plainText);
|
|
74
|
-
const combined = JSON.stringify(encryptedData);
|
|
75
|
-
return Buffer.from(combined).toString('base64');
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Decrypts from base64 encoded string
|
|
79
|
-
* @param base64Data - Base64 encoded encrypted data
|
|
80
|
-
* @returns Promise<string> - Decrypted plain text
|
|
81
|
-
*/
|
|
82
|
-
async decryptFromBase64(base64Data) {
|
|
83
|
-
try {
|
|
84
|
-
const combined = Buffer.from(base64Data, 'base64').toString('utf8');
|
|
85
|
-
const encryptedData = JSON.parse(combined);
|
|
86
|
-
return await this.decrypt(encryptedData);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
throw new Error(`Base64 decryption failed: ${error instanceof Error ? error.message : 'Invalid format'}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Generates a new secret key
|
|
94
|
-
* @returns string - Hex encoded secret key
|
|
95
|
-
*/
|
|
96
|
-
static generateSecretKey() {
|
|
97
|
-
return crypto.randomBytes(32).toString('hex');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vault.methods.d.ts","sourceRoot":"","sources":["../../../src/vault/methods/vault.methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,eAAO,MAAM,YAAY,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAoClD,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const VAULT_PARAMS = {
|
|
2
|
-
get: {
|
|
3
|
-
name: 'get',
|
|
4
|
-
description: 'Retrieve data from the vault',
|
|
5
|
-
dependencies: [],
|
|
6
|
-
parameters: [
|
|
7
|
-
{
|
|
8
|
-
name: 'key',
|
|
9
|
-
type: 'string',
|
|
10
|
-
value: 'string',
|
|
11
|
-
description: 'The key to retrieve',
|
|
12
|
-
required: true,
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
store: {
|
|
17
|
-
name: 'store',
|
|
18
|
-
description: 'Store data in the vault',
|
|
19
|
-
dependencies: [],
|
|
20
|
-
parameters: [
|
|
21
|
-
{
|
|
22
|
-
name: 'key',
|
|
23
|
-
type: 'string',
|
|
24
|
-
value: 'string',
|
|
25
|
-
description: 'The key to store',
|
|
26
|
-
required: true,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'value',
|
|
30
|
-
type: 'string',
|
|
31
|
-
value: 'string',
|
|
32
|
-
description: 'The value to store',
|
|
33
|
-
required: true,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { oToolConfig, oVirtualTool, ToolResult } from '@olane/o-tool';
|
|
2
|
-
import { oRequest } from '@olane/o-core';
|
|
3
|
-
export declare class VaultTool extends oVirtualTool {
|
|
4
|
-
private encryptionService;
|
|
5
|
-
private store;
|
|
6
|
-
constructor(config: oToolConfig);
|
|
7
|
-
_tool_store(request: oRequest): Promise<ToolResult>;
|
|
8
|
-
_tool_get(request: oRequest): Promise<ToolResult>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=vault.tool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vault.tool.d.ts","sourceRoot":"","sources":["../../src/vault/vault.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AAInD,qBAAa,SAAU,SAAQ,YAAY;IACzC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,KAAK,CAAkC;gBAEnC,MAAM,EAAE,WAAW;IAUzB,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAanD,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;CAYxD"}
|
package/dist/vault/vault.tool.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { oVirtualTool } from '@olane/o-tool';
|
|
2
|
-
import { oAddress } from '@olane/o-core';
|
|
3
|
-
import { EncryptionService } from './lib/encryption.js';
|
|
4
|
-
import { VAULT_PARAMS } from './methods/vault.methods.js';
|
|
5
|
-
export class VaultTool extends oVirtualTool {
|
|
6
|
-
constructor(config) {
|
|
7
|
-
super({
|
|
8
|
-
...config,
|
|
9
|
-
address: new oAddress('o://vault'),
|
|
10
|
-
methods: VAULT_PARAMS,
|
|
11
|
-
description: 'Tool to store and retrieve sensitive data from the network',
|
|
12
|
-
});
|
|
13
|
-
this.store = new Map();
|
|
14
|
-
this.encryptionService = new EncryptionService();
|
|
15
|
-
}
|
|
16
|
-
async _tool_store(request) {
|
|
17
|
-
const params = request.params;
|
|
18
|
-
const { key, value } = params;
|
|
19
|
-
const b64key = btoa(key);
|
|
20
|
-
const encryptedValue = await this.encryptionService.encryptToBase64(value);
|
|
21
|
-
this.store.set(b64key, encryptedValue);
|
|
22
|
-
return {
|
|
23
|
-
message: 'Successfully stored value for key: ' + b64key,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async _tool_get(request) {
|
|
27
|
-
const params = request.params;
|
|
28
|
-
const { key } = params;
|
|
29
|
-
const b64key = btoa(key);
|
|
30
|
-
const encryptedValue = this.store.get(b64key);
|
|
31
|
-
const decryptedValue = await this.encryptionService.decryptFromBase64(encryptedValue);
|
|
32
|
-
return {
|
|
33
|
-
value: decryptedValue,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|