claudeunmask 1.0.29 → 1.0.31
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/index.d.ts +25 -0
- package/index.js +70 -55
- package/index.min.js +1 -1
- package/package.json +8 -2
- package/notes.txt +0 -1
package/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// index.d.ts
|
|
2
|
+
export interface UnmaskResult {
|
|
3
|
+
data: any[];
|
|
4
|
+
errorCount: number;
|
|
5
|
+
unmaskCount: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function unmaskData(
|
|
9
|
+
inData: any[],
|
|
10
|
+
decryptionKey: string,
|
|
11
|
+
dailyKey: string
|
|
12
|
+
): Promise<UnmaskResult>;
|
|
13
|
+
|
|
14
|
+
export function deriveKeyFromPassword(
|
|
15
|
+
password: string,
|
|
16
|
+
salt: Uint8Array
|
|
17
|
+
): Promise<CryptoKey>;
|
|
18
|
+
|
|
19
|
+
export function decryptThisData(
|
|
20
|
+
ciphertext: Uint8Array,
|
|
21
|
+
key: CryptoKey,
|
|
22
|
+
iv: Uint8Array
|
|
23
|
+
): Promise<string>;
|
|
24
|
+
|
|
25
|
+
export function base64ToBytes(base64: string): Uint8Array;
|
package/index.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
/* v 1.0.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function getMessageDecoding(buffer) {
|
|
7
|
-
return new TextDecoder().decode(buffer);
|
|
8
|
-
}
|
|
1
|
+
/* v 1.0.31 */
|
|
2
|
+
// claudeunmask/index.js (or index.mjs)
|
|
3
|
+
const crypto = typeof window !== 'undefined'
|
|
4
|
+
? window.crypto
|
|
5
|
+
: require('crypto').webcrypto;
|
|
9
6
|
|
|
10
7
|
function base64ToBytes(base64) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
if (typeof Buffer !== 'undefined') {
|
|
9
|
+
// Node.js
|
|
10
|
+
return new Uint8Array(Buffer.from(base64, 'base64'));
|
|
11
|
+
} else {
|
|
12
|
+
// Browser
|
|
13
|
+
const binary = atob(base64);
|
|
14
|
+
const bytes = new Uint8Array(binary.length);
|
|
15
|
+
for (let i = 0; i < binary.length; i++) {
|
|
16
|
+
bytes[i] = binary.charCodeAt(i);
|
|
17
|
+
}
|
|
18
|
+
return bytes;
|
|
15
19
|
}
|
|
16
|
-
return bytes;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
function bytesToBase64(bytes) {
|
|
@@ -22,7 +25,8 @@
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
async function deriveKeyFromPassword(password, salt) {
|
|
25
|
-
const
|
|
28
|
+
const encoder = new TextEncoder();
|
|
29
|
+
const pwUtf8 = encoder.encode(password);
|
|
26
30
|
|
|
27
31
|
const keyMaterial = await crypto.subtle.importKey(
|
|
28
32
|
'raw',
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
['deriveKey']
|
|
33
37
|
);
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
return await crypto.subtle.deriveKey(
|
|
36
40
|
{
|
|
37
41
|
name: 'PBKDF2',
|
|
38
42
|
salt: salt,
|
|
@@ -44,64 +48,35 @@
|
|
|
44
48
|
true,
|
|
45
49
|
['encrypt', 'decrypt']
|
|
46
50
|
);
|
|
47
|
-
return derivedKey;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
async function decryptThisData(ciphertext, key, iv) {
|
|
54
|
+
const decoder = new TextDecoder();
|
|
51
55
|
try {
|
|
52
56
|
const plaintextBuffer = await crypto.subtle.decrypt(
|
|
53
57
|
{ name: 'AES-GCM', iv },
|
|
54
58
|
key,
|
|
55
59
|
ciphertext
|
|
56
60
|
);
|
|
57
|
-
return
|
|
61
|
+
return decoder.decode(new Uint8Array(plaintextBuffer));
|
|
58
62
|
} catch (error) {
|
|
59
63
|
throw Error ("Failed to decrypt");
|
|
60
64
|
}
|
|
61
65
|
return "";
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
var dailyKey = await window.prompt("Enter the daily key","crazy_string");
|
|
65
|
-
var retVal = [];
|
|
66
|
-
var enc = new TextEncoder();
|
|
67
|
-
var [tmpPassword, salt, theIV] = decryptionKey.split("-");
|
|
68
|
-
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
69
|
-
try {
|
|
70
|
-
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
71
|
-
} catch (error) {
|
|
72
|
-
throw Error ("Failed to decrypt the key");
|
|
73
|
-
}
|
|
74
|
-
const password = tmpPassword;
|
|
75
|
-
for (const curRec of inData) {
|
|
76
|
-
var tmpRec = {};
|
|
77
|
-
for (const [key, value] of Object.entries(curRec)) {
|
|
78
|
-
try {
|
|
79
|
-
if (typeof value === "string" && value.includes("m$k_")) {
|
|
80
|
-
var theData = base64ToBytes(curRec[key].replace ("m$k_", ""));
|
|
81
|
-
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
82
|
-
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
83
|
-
} else {
|
|
84
|
-
tmpRec[key] = value;
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
tmpRec[key] = "failed";
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
retVal.push(tmpRec);
|
|
91
|
-
}
|
|
92
|
-
return retVal;
|
|
93
|
-
}
|
|
67
|
+
|
|
94
68
|
async function unmaskData (inData, decryptionKey, dailyKey) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
const retVal = {
|
|
70
|
+
data: [],
|
|
71
|
+
errorCount: 0,
|
|
72
|
+
unmaskCount: 0
|
|
73
|
+
};
|
|
99
74
|
var enc = new TextEncoder();
|
|
100
75
|
var [tmpPassword, salt, theIV] = decryptionKey.split("-");
|
|
101
76
|
var haveError = 0;
|
|
102
77
|
for (var ii= 0; ii<=2; ii++) { // try to decrypt the daily key and the add = until it works or we've added 2
|
|
103
|
-
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
104
78
|
try {
|
|
79
|
+
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
105
80
|
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
106
81
|
// if we get here then we have a good daily key
|
|
107
82
|
haveError = 0;
|
|
@@ -122,7 +97,7 @@
|
|
|
122
97
|
try {
|
|
123
98
|
if (typeof value === "string" && value.includes("m$k_")) {
|
|
124
99
|
retVal.unmaskCount++;
|
|
125
|
-
|
|
100
|
+
const theData = base64ToBytes(value.replace ("m$k_", ""));
|
|
126
101
|
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
127
102
|
} else {
|
|
128
103
|
tmpRec[key] = value;
|
|
@@ -139,4 +114,44 @@
|
|
|
139
114
|
console.log ("an error happened", (100 * retVal.errorCount / retVal.unmaskCount));
|
|
140
115
|
}
|
|
141
116
|
return retVal;
|
|
142
|
-
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function decrypt(inData, decryptionKey) {
|
|
120
|
+
var dailyKey = await window.prompt("Enter the daily key","crazy_string");
|
|
121
|
+
var retVal = [];
|
|
122
|
+
var enc = new TextEncoder();
|
|
123
|
+
var [tmpPassword, salt, theIV] = decryptionKey.split("-");
|
|
124
|
+
const dailyKeyBinary = await deriveKeyFromPassword(dailyKey, base64ToBytes(salt));
|
|
125
|
+
try {
|
|
126
|
+
tmpPassword = await decryptThisData (base64ToBytes(tmpPassword), dailyKeyBinary, base64ToBytes(theIV));
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw Error ("Failed to decrypt the key");
|
|
129
|
+
}
|
|
130
|
+
const password = tmpPassword;
|
|
131
|
+
for (const curRec of inData) {
|
|
132
|
+
var tmpRec = {};
|
|
133
|
+
for (const [key, value] of Object.entries(curRec)) {
|
|
134
|
+
try {
|
|
135
|
+
if (typeof value === "string" && value.includes("m$k_")) {
|
|
136
|
+
var theData = base64ToBytes(curRec[key].replace ("m$k_", ""));
|
|
137
|
+
const encryptionKey = await deriveKeyFromPassword(password, base64ToBytes(salt));
|
|
138
|
+
tmpRec[key] = await decryptThisData (theData, encryptionKey, base64ToBytes(theIV));
|
|
139
|
+
} else {
|
|
140
|
+
tmpRec[key] = value;
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
tmpRec[key] = "failed";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
retVal.push(tmpRec);
|
|
147
|
+
}
|
|
148
|
+
return retVal;
|
|
149
|
+
}
|
|
150
|
+
// Export for both Node.js and browser
|
|
151
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
152
|
+
// Node.js
|
|
153
|
+
module.exports = { unmaskData, deriveKeyFromPassword, decryptThisData, base64ToBytes };
|
|
154
|
+
} else {
|
|
155
|
+
// Browser
|
|
156
|
+
window.claudeUnmask = { unmaskData, deriveKeyFromPassword, decryptThisData, base64ToBytes };
|
|
157
|
+
}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const crypto="undefined"!=typeof window?window.crypto:require("crypto").webcrypto;function base64ToBytes(e){if("undefined"!=typeof Buffer)return new Uint8Array(Buffer.from(e,"base64"));{let t=atob(e),a=new Uint8Array(t.length);for(let r=0;r<t.length;r++)a[r]=t.charCodeAt(r);return a}}function bytesToBase64(e){let t=String.fromCharCode(...e);return btoa(t)}async function deriveKeyFromPassword(e,t){let a=new TextEncoder,r=a.encode(e),o=await crypto.subtle.importKey("raw",r,"PBKDF2",!1,["deriveKey"]);return await crypto.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:1e5,hash:"SHA-256"},o,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}async function decryptThisData(e,t,a){let r=new TextDecoder;try{let o=await crypto.subtle.decrypt({name:"AES-GCM",iv:a},t,e);return r.decode(new Uint8Array(o))}catch(s){throw Error("Failed to decrypt")}return""}async function unmaskData(e,t,a){let r={data:[],errorCount:0,unmaskCount:0};new TextEncoder;for(var[o,s,n]=t.split("-"),y=0,i=0;i<=2;i++)try{let d=await deriveKeyFromPassword(a,base64ToBytes(s));o=await decryptThisData(base64ToBytes(o),d,base64ToBytes(n)),y=0;break}catch(c){y=1,a+="="}if(y)throw Error("Failed to decrypt the key");let l=o,p=await deriveKeyFromPassword(l,base64ToBytes(s));for(let u of e){var f={};for(let[w,h]of Object.entries(u))try{if("string"==typeof h&&h.includes("m$k_")){r.unmaskCount++;let m=base64ToBytes(h.replace("m$k_",""));f[w]=await decryptThisData(m,p,base64ToBytes(n))}else f[w]=h}catch(T){f[w]="failed",r.errorCount++}r.data.push(f)}return r.errorCount&&console.log("an error happened",100*r.errorCount/r.unmaskCount),r}async function decrypt(e,t){var a=await window.prompt("Enter the daily key","crazy_string"),r=[];new TextEncoder;var[o,s,n]=t.split("-");let y=await deriveKeyFromPassword(a,base64ToBytes(s));try{o=await decryptThisData(base64ToBytes(o),y,base64ToBytes(n))}catch(i){throw Error("Failed to decrypt the key")}let d=o;for(let c of e){var l={};for(let[p,u]of Object.entries(c))try{if("string"==typeof u&&u.includes("m$k_")){var f=base64ToBytes(c[p].replace("m$k_",""));let w=await deriveKeyFromPassword(d,base64ToBytes(s));l[p]=await decryptThisData(f,w,base64ToBytes(n))}else l[p]=u}catch(h){l[p]="failed"}r.push(l)}return r}"undefined"!=typeof module&&module.exports?module.exports={unmaskData,deriveKeyFromPassword,decryptThisData,base64ToBytes}:window.claudeUnmask={unmaskData,deriveKeyFromPassword,decryptThisData,base64ToBytes};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claudeunmask",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"description": "claude unmask test",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,5 +10,11 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"crypto-js": "^4.2.0"
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"types": "index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.min.js",
|
|
18
|
+
"index.d.ts"
|
|
19
|
+
]
|
|
14
20
|
}
|
package/notes.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ECHO is on.
|