volter 0.0.173 → 0.0.174

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/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ The Modlin Distributable License (MDL)
2
+
3
+ Copyright (c) 2025 Modlin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ Any use, distribution, modification, integration, or implementation of the
16
+ Software in another project must include clear and visible credit to the
17
+ Software and to its original author. This credit must be placed in all public
18
+ distributions, documentation, and any “About” or “Credits” section of the
19
+ implementing project.
20
+
21
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ THE SOFTWARE.
package/dist/crypto.js CHANGED
@@ -1,141 +1,2 @@
1
- var __create = Object.create;
2
- var __getProtoOf = Object.getPrototypeOf;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __toESM = (mod, isNodeMode, target) => {
7
- target = mod != null ? __create(__getProtoOf(mod)) : {};
8
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
- for (let key of __getOwnPropNames(mod))
10
- if (!__hasOwnProp.call(to, key))
11
- __defProp(to, key, {
12
- get: () => mod[key],
13
- enumerable: true
14
- });
15
- return to;
16
- };
17
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp(target, name, {
21
- get: all[name],
22
- enumerable: true,
23
- configurable: true,
24
- set: (newValue) => all[name] = () => newValue
25
- });
26
- };
27
-
28
- // src/crypto.ts
29
- function hash(password, hmac) {
30
- const hasher = new Bun.CryptoHasher("sha256", hmac);
31
- return hasher.update(password).digest("hex");
32
- }
33
- async function cryptoKey(raw) {
34
- if (raw) {
35
- if (raw instanceof CryptoKey)
36
- return raw;
37
- if (raw instanceof Uint8Array) {
38
- if (raw.length === 32) {
39
- return await crypto.subtle.importKey("raw", raw, { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
40
- }
41
- return await crypto.subtle.importKey("raw", raw, { name: "AES-GCM", length: 256 }, true, ["encrypt", "decrypt"]);
42
- }
43
- if (raw.length === 64) {
44
- return await crypto.subtle.importKey("raw", Uint8Array.fromHex(raw), {
45
- name: "AES-GCM",
46
- length: 256
47
- }, true, ["encrypt", "decrypt"]);
48
- } else {
49
- return await crypto.subtle.importKey("raw", Uint8Array.fromHex(hash(raw)), {
50
- name: "AES-GCM",
51
- length: 256
52
- }, true, ["encrypt", "decrypt"]);
53
- }
54
- } else {
55
- return await crypto.subtle.generateKey({
56
- name: "AES-GCM",
57
- length: 256
58
- }, true, ["encrypt", "decrypt"]);
59
- }
60
- }
61
- async function exportKey(key, format) {
62
- const buffer = await crypto.subtle.exportKey(format, key);
63
- return new Uint8Array(buffer).toBase64();
64
- }
65
- async function generateECDSAKeyPair() {
66
- return await crypto.subtle.generateKey({
67
- name: "ECDSA",
68
- namedCurve: "P-256"
69
- }, true, ["sign", "verify"]);
70
- }
71
- async function exportJWK(key) {
72
- return await crypto.subtle.exportKey("jwk", key);
73
- }
74
- async function importJWK(jwk, usage) {
75
- return await crypto.subtle.importKey("jwk", jwk, { name: "ECDSA", namedCurve: "P-256" }, true, usage);
76
- }
77
- async function sign(message, key) {
78
- const data = new TextEncoder().encode(message);
79
- const signature = await crypto.subtle.sign({
80
- name: "ECDSA",
81
- hash: { name: "SHA-256" }
82
- }, key, data);
83
- return new Uint8Array(signature);
84
- }
85
- async function verifySign(message, signature, key) {
86
- const data = new TextEncoder().encode(message);
87
- return await crypto.subtle.verify({
88
- name: "ECDSA",
89
- hash: { name: "SHA-256" }
90
- }, key, signature, data);
91
- }
92
- async function cipher(text, key) {
93
- const encoder = new TextEncoder;
94
- const data = encoder.encode(text);
95
- const iv = crypto.getRandomValues(new Uint8Array(12));
96
- const buffer = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, await cryptoKey(key), data);
97
- return {
98
- text: new Uint8Array(buffer).toHex(),
99
- iv,
100
- buffer
101
- };
102
- }
103
- async function decipher(cipher2, key) {
104
- const decoder = new TextDecoder;
105
- const buffer = await crypto.subtle.decrypt({ name: "AES-GCM", iv: cipher2.iv }, await cryptoKey(key), Uint8Array.fromHex(cipher2.text));
106
- const data = decoder.decode(buffer);
107
- return data;
108
- }
109
- async function keypair() {
110
- return await crypto.subtle.generateKey({
111
- name: "RSA-OAEP",
112
- modulusLength: 2048,
113
- publicExponent: new Uint8Array([1, 0, 1]),
114
- hash: { name: "SHA-256" }
115
- }, true, ["encrypt", "decrypt"]);
116
- }
117
- async function encrypt(text, key) {
118
- const data = new TextEncoder().encode(text);
119
- const buffer = await crypto.subtle.encrypt({ name: "RSA-OAEP" }, key, data);
120
- return new Uint8Array(buffer);
121
- }
122
- async function decrypt(text, key) {
123
- const buffer = await crypto.subtle.decrypt({ name: "RSA-OAEP" }, key, text);
124
- const data = new TextDecoder().decode(buffer);
125
- return data;
126
- }
127
- export {
128
- verifySign,
129
- sign,
130
- keypair,
131
- importJWK,
132
- hash,
133
- generateECDSAKeyPair,
134
- exportKey,
135
- exportJWK,
136
- encrypt,
137
- decrypt,
138
- decipher,
139
- cryptoKey,
140
- cipher
141
- };
1
+ // @bun
2
+ var c=Object.create;var{getPrototypeOf:s,defineProperty:o,getOwnPropertyNames:p}=Object;var u=Object.prototype.hasOwnProperty;var A=(e,t,r)=>{r=e!=null?c(s(e)):{};let n=t||!e||!e.__esModule?o(r,"default",{value:e,enumerable:!0}):r;for(let a of p(e))if(!u.call(n,a))o(n,a,{get:()=>e[a],enumerable:!0});return n};var d=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var m=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0,configurable:!0,set:(n)=>t[r]=()=>n})};var x=import.meta.require;function f(e,t){return new Bun.CryptoHasher("sha256",t).update(e).digest("hex")}async function i(e){if(e){if(e instanceof CryptoKey)return e;if(e instanceof Uint8Array){if(e.length===32)return await crypto.subtle.importKey("raw",e,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);return await crypto.subtle.importKey("raw",e,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}if(e.length===64)return await crypto.subtle.importKey("raw",Uint8Array.fromHex(e),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);else return await crypto.subtle.importKey("raw",Uint8Array.fromHex(f(e)),{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}else return await crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}async function C(e,t){let r=await crypto.subtle.exportKey(t,e);return new Uint8Array(r).toBase64()}async function K(){return await crypto.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"])}async function l(e){return await crypto.subtle.exportKey("jwk",e)}async function w(e,t){return await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:"P-256"},!0,t)}async function b(e,t){let r=new TextEncoder().encode(e),n=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},t,r);return new Uint8Array(n)}async function h(e,t,r){let n=new TextEncoder().encode(e);return await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},r,t,n)}async function E(e,t){let n=new TextEncoder().encode(e),a=crypto.getRandomValues(new Uint8Array(12)),y=await crypto.subtle.encrypt({name:"AES-GCM",iv:a},await i(t),n);return{text:new Uint8Array(y).toHex(),iv:a,buffer:y}}async function S(e,t){let r=new TextDecoder,n=await crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},await i(t),Uint8Array.fromHex(e.text));return r.decode(n)}async function P(){return await crypto.subtle.generateKey({name:"RSA-OAEP",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["encrypt","decrypt"])}async function U(e,t){let r=new TextEncoder().encode(e),n=await crypto.subtle.encrypt({name:"RSA-OAEP"},t,r);return new Uint8Array(n)}async function v(e,t){let r=await crypto.subtle.decrypt({name:"RSA-OAEP"},t,e);return new TextDecoder().decode(r)}export{h as verifySign,b as sign,P as keypair,w as importJWK,f as hash,K as generateECDSAKeyPair,C as exportKey,l as exportJWK,U as encrypt,v as decrypt,S as decipher,i as cryptoKey,E as cipher};