@pdg/crypto 1.0.5 → 1.0.7

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/README.md CHANGED
@@ -4,5 +4,5 @@ Typescript Crypto Module
4
4
 
5
5
  ## 설치
6
6
  ```
7
- npm install -D @pdg/crypto
7
+ npm install -D @pdg/crypto @types/base-64 @types/md5 @types/sha.js base-64 md5 sha.js
8
8
  ```
package/dist/index.esm.js CHANGED
@@ -1,6 +1,220 @@
1
- import _md5 from'md5';import _base64 from'base-64';import utf8 from'utf8';import sha from'sha.js';function md5(text) {
1
+ import _md5 from'md5';import _base64 from'base-64';import sha from'sha.js';import'crypto';function md5(text) {
2
2
  return _md5(text);
3
- }const base64 = {
3
+ }function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }var utf8$1 = {};/*! https://mths.be/utf8js v3.0.0 by @mathias */
6
+
7
+ var hasRequiredUtf8;
8
+
9
+ function requireUtf8 () {
10
+ if (hasRequiredUtf8) return utf8$1;
11
+ hasRequiredUtf8 = 1;
12
+ (function (exports$1) {
13
+ (function(root) {
14
+
15
+ var stringFromCharCode = String.fromCharCode;
16
+
17
+ // Taken from https://mths.be/punycode
18
+ function ucs2decode(string) {
19
+ var output = [];
20
+ var counter = 0;
21
+ var length = string.length;
22
+ var value;
23
+ var extra;
24
+ while (counter < length) {
25
+ value = string.charCodeAt(counter++);
26
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
27
+ // high surrogate, and there is a next character
28
+ extra = string.charCodeAt(counter++);
29
+ if ((extra & 0xFC00) == 0xDC00) { // low surrogate
30
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
31
+ } else {
32
+ // unmatched surrogate; only append this code unit, in case the next
33
+ // code unit is the high surrogate of a surrogate pair
34
+ output.push(value);
35
+ counter--;
36
+ }
37
+ } else {
38
+ output.push(value);
39
+ }
40
+ }
41
+ return output;
42
+ }
43
+
44
+ // Taken from https://mths.be/punycode
45
+ function ucs2encode(array) {
46
+ var length = array.length;
47
+ var index = -1;
48
+ var value;
49
+ var output = '';
50
+ while (++index < length) {
51
+ value = array[index];
52
+ if (value > 0xFFFF) {
53
+ value -= 0x10000;
54
+ output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
55
+ value = 0xDC00 | value & 0x3FF;
56
+ }
57
+ output += stringFromCharCode(value);
58
+ }
59
+ return output;
60
+ }
61
+
62
+ function checkScalarValue(codePoint) {
63
+ if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
64
+ throw Error(
65
+ 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
66
+ ' is not a scalar value'
67
+ );
68
+ }
69
+ }
70
+ /*--------------------------------------------------------------------------*/
71
+
72
+ function createByte(codePoint, shift) {
73
+ return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
74
+ }
75
+
76
+ function encodeCodePoint(codePoint) {
77
+ if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
78
+ return stringFromCharCode(codePoint);
79
+ }
80
+ var symbol = '';
81
+ if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
82
+ symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
83
+ }
84
+ else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
85
+ checkScalarValue(codePoint);
86
+ symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
87
+ symbol += createByte(codePoint, 6);
88
+ }
89
+ else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
90
+ symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
91
+ symbol += createByte(codePoint, 12);
92
+ symbol += createByte(codePoint, 6);
93
+ }
94
+ symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
95
+ return symbol;
96
+ }
97
+
98
+ function utf8encode(string) {
99
+ var codePoints = ucs2decode(string);
100
+ var length = codePoints.length;
101
+ var index = -1;
102
+ var codePoint;
103
+ var byteString = '';
104
+ while (++index < length) {
105
+ codePoint = codePoints[index];
106
+ byteString += encodeCodePoint(codePoint);
107
+ }
108
+ return byteString;
109
+ }
110
+
111
+ /*--------------------------------------------------------------------------*/
112
+
113
+ function readContinuationByte() {
114
+ if (byteIndex >= byteCount) {
115
+ throw Error('Invalid byte index');
116
+ }
117
+
118
+ var continuationByte = byteArray[byteIndex] & 0xFF;
119
+ byteIndex++;
120
+
121
+ if ((continuationByte & 0xC0) == 0x80) {
122
+ return continuationByte & 0x3F;
123
+ }
124
+
125
+ // If we end up here, it’s not a continuation byte
126
+ throw Error('Invalid continuation byte');
127
+ }
128
+
129
+ function decodeSymbol() {
130
+ var byte1;
131
+ var byte2;
132
+ var byte3;
133
+ var byte4;
134
+ var codePoint;
135
+
136
+ if (byteIndex > byteCount) {
137
+ throw Error('Invalid byte index');
138
+ }
139
+
140
+ if (byteIndex == byteCount) {
141
+ return false;
142
+ }
143
+
144
+ // Read first byte
145
+ byte1 = byteArray[byteIndex] & 0xFF;
146
+ byteIndex++;
147
+
148
+ // 1-byte sequence (no continuation bytes)
149
+ if ((byte1 & 0x80) == 0) {
150
+ return byte1;
151
+ }
152
+
153
+ // 2-byte sequence
154
+ if ((byte1 & 0xE0) == 0xC0) {
155
+ byte2 = readContinuationByte();
156
+ codePoint = ((byte1 & 0x1F) << 6) | byte2;
157
+ if (codePoint >= 0x80) {
158
+ return codePoint;
159
+ } else {
160
+ throw Error('Invalid continuation byte');
161
+ }
162
+ }
163
+
164
+ // 3-byte sequence (may include unpaired surrogates)
165
+ if ((byte1 & 0xF0) == 0xE0) {
166
+ byte2 = readContinuationByte();
167
+ byte3 = readContinuationByte();
168
+ codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
169
+ if (codePoint >= 0x0800) {
170
+ checkScalarValue(codePoint);
171
+ return codePoint;
172
+ } else {
173
+ throw Error('Invalid continuation byte');
174
+ }
175
+ }
176
+
177
+ // 4-byte sequence
178
+ if ((byte1 & 0xF8) == 0xF0) {
179
+ byte2 = readContinuationByte();
180
+ byte3 = readContinuationByte();
181
+ byte4 = readContinuationByte();
182
+ codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
183
+ (byte3 << 0x06) | byte4;
184
+ if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
185
+ return codePoint;
186
+ }
187
+ }
188
+
189
+ throw Error('Invalid UTF-8 detected');
190
+ }
191
+
192
+ var byteArray;
193
+ var byteCount;
194
+ var byteIndex;
195
+ function utf8decode(byteString) {
196
+ byteArray = ucs2decode(byteString);
197
+ byteCount = byteArray.length;
198
+ byteIndex = 0;
199
+ var codePoints = [];
200
+ var tmp;
201
+ while ((tmp = decodeSymbol()) !== false) {
202
+ codePoints.push(tmp);
203
+ }
204
+ return ucs2encode(codePoints);
205
+ }
206
+
207
+ /*--------------------------------------------------------------------------*/
208
+
209
+ root.version = '3.0.0';
210
+ root.encode = utf8encode;
211
+ root.decode = utf8decode;
212
+
213
+ }(exports$1));
214
+ } (utf8$1));
215
+ return utf8$1;
216
+ }var utf8Exports = requireUtf8();
217
+ var utf8 = /*@__PURE__*/getDefaultExportFromCjs(utf8Exports);const base64 = {
4
218
  encode(text) {
5
219
  return _base64.encode(utf8.encode(text));
6
220
  },
package/dist/index.js CHANGED
@@ -1,6 +1,220 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _md5=require('md5'),_base64=require('base-64'),utf8=require('utf8'),sha=require('sha.js');function md5(text) {
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var _md5=require('md5'),_base64=require('base-64'),sha=require('sha.js');require('crypto');function md5(text) {
2
2
  return _md5(text);
3
- }const base64 = {
3
+ }function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }var utf8$1 = {};/*! https://mths.be/utf8js v3.0.0 by @mathias */
6
+
7
+ var hasRequiredUtf8;
8
+
9
+ function requireUtf8 () {
10
+ if (hasRequiredUtf8) return utf8$1;
11
+ hasRequiredUtf8 = 1;
12
+ (function (exports$1) {
13
+ (function(root) {
14
+
15
+ var stringFromCharCode = String.fromCharCode;
16
+
17
+ // Taken from https://mths.be/punycode
18
+ function ucs2decode(string) {
19
+ var output = [];
20
+ var counter = 0;
21
+ var length = string.length;
22
+ var value;
23
+ var extra;
24
+ while (counter < length) {
25
+ value = string.charCodeAt(counter++);
26
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
27
+ // high surrogate, and there is a next character
28
+ extra = string.charCodeAt(counter++);
29
+ if ((extra & 0xFC00) == 0xDC00) { // low surrogate
30
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
31
+ } else {
32
+ // unmatched surrogate; only append this code unit, in case the next
33
+ // code unit is the high surrogate of a surrogate pair
34
+ output.push(value);
35
+ counter--;
36
+ }
37
+ } else {
38
+ output.push(value);
39
+ }
40
+ }
41
+ return output;
42
+ }
43
+
44
+ // Taken from https://mths.be/punycode
45
+ function ucs2encode(array) {
46
+ var length = array.length;
47
+ var index = -1;
48
+ var value;
49
+ var output = '';
50
+ while (++index < length) {
51
+ value = array[index];
52
+ if (value > 0xFFFF) {
53
+ value -= 0x10000;
54
+ output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
55
+ value = 0xDC00 | value & 0x3FF;
56
+ }
57
+ output += stringFromCharCode(value);
58
+ }
59
+ return output;
60
+ }
61
+
62
+ function checkScalarValue(codePoint) {
63
+ if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
64
+ throw Error(
65
+ 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
66
+ ' is not a scalar value'
67
+ );
68
+ }
69
+ }
70
+ /*--------------------------------------------------------------------------*/
71
+
72
+ function createByte(codePoint, shift) {
73
+ return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
74
+ }
75
+
76
+ function encodeCodePoint(codePoint) {
77
+ if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
78
+ return stringFromCharCode(codePoint);
79
+ }
80
+ var symbol = '';
81
+ if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
82
+ symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
83
+ }
84
+ else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
85
+ checkScalarValue(codePoint);
86
+ symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
87
+ symbol += createByte(codePoint, 6);
88
+ }
89
+ else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
90
+ symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
91
+ symbol += createByte(codePoint, 12);
92
+ symbol += createByte(codePoint, 6);
93
+ }
94
+ symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
95
+ return symbol;
96
+ }
97
+
98
+ function utf8encode(string) {
99
+ var codePoints = ucs2decode(string);
100
+ var length = codePoints.length;
101
+ var index = -1;
102
+ var codePoint;
103
+ var byteString = '';
104
+ while (++index < length) {
105
+ codePoint = codePoints[index];
106
+ byteString += encodeCodePoint(codePoint);
107
+ }
108
+ return byteString;
109
+ }
110
+
111
+ /*--------------------------------------------------------------------------*/
112
+
113
+ function readContinuationByte() {
114
+ if (byteIndex >= byteCount) {
115
+ throw Error('Invalid byte index');
116
+ }
117
+
118
+ var continuationByte = byteArray[byteIndex] & 0xFF;
119
+ byteIndex++;
120
+
121
+ if ((continuationByte & 0xC0) == 0x80) {
122
+ return continuationByte & 0x3F;
123
+ }
124
+
125
+ // If we end up here, it’s not a continuation byte
126
+ throw Error('Invalid continuation byte');
127
+ }
128
+
129
+ function decodeSymbol() {
130
+ var byte1;
131
+ var byte2;
132
+ var byte3;
133
+ var byte4;
134
+ var codePoint;
135
+
136
+ if (byteIndex > byteCount) {
137
+ throw Error('Invalid byte index');
138
+ }
139
+
140
+ if (byteIndex == byteCount) {
141
+ return false;
142
+ }
143
+
144
+ // Read first byte
145
+ byte1 = byteArray[byteIndex] & 0xFF;
146
+ byteIndex++;
147
+
148
+ // 1-byte sequence (no continuation bytes)
149
+ if ((byte1 & 0x80) == 0) {
150
+ return byte1;
151
+ }
152
+
153
+ // 2-byte sequence
154
+ if ((byte1 & 0xE0) == 0xC0) {
155
+ byte2 = readContinuationByte();
156
+ codePoint = ((byte1 & 0x1F) << 6) | byte2;
157
+ if (codePoint >= 0x80) {
158
+ return codePoint;
159
+ } else {
160
+ throw Error('Invalid continuation byte');
161
+ }
162
+ }
163
+
164
+ // 3-byte sequence (may include unpaired surrogates)
165
+ if ((byte1 & 0xF0) == 0xE0) {
166
+ byte2 = readContinuationByte();
167
+ byte3 = readContinuationByte();
168
+ codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
169
+ if (codePoint >= 0x0800) {
170
+ checkScalarValue(codePoint);
171
+ return codePoint;
172
+ } else {
173
+ throw Error('Invalid continuation byte');
174
+ }
175
+ }
176
+
177
+ // 4-byte sequence
178
+ if ((byte1 & 0xF8) == 0xF0) {
179
+ byte2 = readContinuationByte();
180
+ byte3 = readContinuationByte();
181
+ byte4 = readContinuationByte();
182
+ codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
183
+ (byte3 << 0x06) | byte4;
184
+ if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
185
+ return codePoint;
186
+ }
187
+ }
188
+
189
+ throw Error('Invalid UTF-8 detected');
190
+ }
191
+
192
+ var byteArray;
193
+ var byteCount;
194
+ var byteIndex;
195
+ function utf8decode(byteString) {
196
+ byteArray = ucs2decode(byteString);
197
+ byteCount = byteArray.length;
198
+ byteIndex = 0;
199
+ var codePoints = [];
200
+ var tmp;
201
+ while ((tmp = decodeSymbol()) !== false) {
202
+ codePoints.push(tmp);
203
+ }
204
+ return ucs2encode(codePoints);
205
+ }
206
+
207
+ /*--------------------------------------------------------------------------*/
208
+
209
+ root.version = '3.0.0';
210
+ root.encode = utf8encode;
211
+ root.decode = utf8decode;
212
+
213
+ }(exports$1));
214
+ } (utf8$1));
215
+ return utf8$1;
216
+ }var utf8Exports = requireUtf8();
217
+ var utf8 = /*@__PURE__*/getDefaultExportFromCjs(utf8Exports);const base64 = {
4
218
  encode(text) {
5
219
  return _base64.encode(utf8.encode(text));
6
220
  },
package/dist/sha1.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { BinaryToTextEncoding } from 'crypto';
1
+ import { type BinaryToTextEncoding } from 'crypto';
2
2
  export declare function sha1(text: string, encoding?: BinaryToTextEncoding): string;
3
3
  export default sha1;
package/dist/sha256.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { BinaryToTextEncoding } from 'crypto';
1
+ import { type BinaryToTextEncoding } from 'crypto';
2
2
  export declare function sha256(text: string, encoding?: BinaryToTextEncoding): string;
3
3
  export default sha256;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pdg/crypto",
3
3
  "title": "Typescript Crypto Module",
4
4
  "description": "Typescript Crypto Module",
5
- "version": "1.0.5",
5
+ "version": "1.0.7",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.esm.js",
@@ -30,14 +30,15 @@
30
30
  "scripts": {
31
31
  "dev": "cd examples && npm run dev",
32
32
  "watchman:del": "watchman watch-del \"${PWD}\" ; watchman watch-project \"${PWD}\"",
33
- "build": "npm run watchman:del && npm run test && npm run lint && rollup -c --bundleConfigAsCjs",
33
+ "build": "npm run watchman:del && npm run test && rollup -c --bundleConfigAsCjs",
34
34
  "git:commit": "node .git-commit.cjs",
35
35
  "git:push": "git push",
36
36
  "git:commit:push": "npm run git:commit && npm run git:push",
37
37
  "git:merge:mirror": "node .git-merge.cjs mirror main",
38
38
  "reset:gitignore": "git rm -r --cached . && git add .",
39
- "pub": "npm i && npm run build && npm publish --access=public && rm ./.git/hooks/pre-commit",
39
+ "pub": "npm i && npm run build && npm publish --access=public && [ -f ./.git/hooks/pre-commit ] && rm ./.git/hooks/pre-commit || true",
40
40
  "lint": "eslint './src/**/*.ts'",
41
+ "tsc": "tsc --noEmit",
41
42
  "reinstall": "npm run reinstall:module",
42
43
  "reinstall:module": "rm -rf node_modules && rm -f package-lock.json && npm i",
43
44
  "test": "jest"
@@ -50,15 +51,18 @@
50
51
  "typescript",
51
52
  "javascript"
52
53
  ],
53
- "dependencies": {
54
+ "peerDependencies": {
55
+ "@types/base-64": "^1.0.2",
56
+ "@types/md5": "2.3.6",
57
+ "@types/sha.js": "2.4.4",
54
58
  "base-64": "^1.0.0",
55
59
  "md5": "^2.3.0",
56
- "sha.js": "^2.4.12",
57
- "utf8": "^3.0.0"
60
+ "sha.js": "^2.4.12"
58
61
  },
59
62
  "devDependencies": {
60
63
  "@eslint/js": "9.39.1",
61
64
  "@rollup/plugin-commonjs": "29.0.0",
65
+ "@rollup/plugin-eslint": "^9.2.0",
62
66
  "@rollup/plugin-node-resolve": "16.0.3",
63
67
  "@types/base-64": "^1.0.2",
64
68
  "@types/jest": "29.5.14",
@@ -68,18 +72,22 @@
68
72
  "@types/utf8": "3.0.3",
69
73
  "@types/uuid": "10.0.0",
70
74
  "@typescript-eslint/parser": "8.49.0",
75
+ "base-64": "^1.0.0",
71
76
  "eslint": "9.39.1",
72
77
  "eslint-config-prettier": "10.1.8",
73
78
  "eslint-plugin-prettier": "5.5.4",
74
79
  "jest": "29.7.0",
80
+ "md5": "^2.3.0",
75
81
  "prettier": "3.7.4",
76
82
  "rollup": "4.53.3",
77
83
  "rollup-plugin-delete": "2.2.0",
78
84
  "rollup-plugin-peer-deps-external": "2.2.4",
79
85
  "rollup-plugin-typescript2": "0.36.0",
86
+ "sha.js": "^2.4.12",
80
87
  "ts-jest": "29.4.6",
81
88
  "ts-node": "10.9.2",
82
89
  "typescript": "5.9.3",
83
- "typescript-eslint": "8.49.0"
90
+ "typescript-eslint": "8.49.0",
91
+ "utf8": "^3.0.0"
84
92
  }
85
93
  }