@bandeira-tech/b3nd-web 0.2.1 → 0.2.3
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/dist/apps/mod.d.ts +26 -17
- package/dist/apps/mod.js +1 -1
- package/dist/chunk-K3ZSSVHR.js +615 -0
- package/dist/{chunk-Z3LAGZSM.js → chunk-S7NJA6B6.js} +140 -26
- package/dist/{chunk-YJKJJ323.js → chunk-VAZUCGED.js} +24 -18
- package/dist/encrypt/mod.d.ts +1 -1
- package/dist/encrypt/mod.js +29 -3
- package/dist/mod-D02790g_.d.ts +241 -0
- package/dist/src/mod.web.d.ts +1 -1
- package/dist/src/mod.web.js +5 -5
- package/dist/wallet/mod.d.ts +86 -10
- package/dist/wallet/mod.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-FUMSJI3N.js +0 -327
- package/dist/mod-DHjjiF1o.d.ts +0 -111
package/dist/src/mod.web.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mod_exports
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-K3ZSSVHR.js";
|
|
4
|
+
import {
|
|
5
|
+
WalletClient
|
|
6
|
+
} from "../chunk-S7NJA6B6.js";
|
|
4
7
|
import {
|
|
5
8
|
HttpClient
|
|
6
9
|
} from "../chunk-LFUC4ETD.js";
|
|
@@ -12,10 +15,7 @@ import {
|
|
|
12
15
|
} from "../chunk-T43IWAQK.js";
|
|
13
16
|
import {
|
|
14
17
|
AppsClient
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import {
|
|
17
|
-
WalletClient
|
|
18
|
-
} from "../chunk-Z3LAGZSM.js";
|
|
18
|
+
} from "../chunk-VAZUCGED.js";
|
|
19
19
|
import "../chunk-MLKGABMK.js";
|
|
20
20
|
export {
|
|
21
21
|
AppsClient,
|
package/dist/wallet/mod.d.ts
CHANGED
|
@@ -70,10 +70,29 @@ interface ProxyWriteResponse {
|
|
|
70
70
|
ts: number;
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Read proxy request
|
|
75
|
+
*/
|
|
76
|
+
interface ProxyReadRequest {
|
|
77
|
+
uri: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read proxy response
|
|
81
|
+
*/
|
|
82
|
+
interface ProxyReadResponse {
|
|
83
|
+
success: boolean;
|
|
84
|
+
uri: string;
|
|
85
|
+
record?: {
|
|
86
|
+
data: unknown;
|
|
87
|
+
ts: number;
|
|
88
|
+
};
|
|
89
|
+
decrypted?: unknown;
|
|
90
|
+
error?: string;
|
|
91
|
+
}
|
|
73
92
|
/**
|
|
74
93
|
* API response wrapper
|
|
75
94
|
*/
|
|
76
|
-
interface ApiResponse
|
|
95
|
+
interface ApiResponse {
|
|
77
96
|
success: boolean;
|
|
78
97
|
error?: string;
|
|
79
98
|
[key: string]: unknown;
|
|
@@ -132,6 +151,36 @@ interface HealthResponse extends ApiResponse {
|
|
|
132
151
|
server: string;
|
|
133
152
|
timestamp: string;
|
|
134
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Google OAuth session (extended AuthSession with Google profile info)
|
|
156
|
+
*/
|
|
157
|
+
interface GoogleAuthSession extends AuthSession {
|
|
158
|
+
email: string;
|
|
159
|
+
name?: string;
|
|
160
|
+
picture?: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Google signup response
|
|
164
|
+
*/
|
|
165
|
+
interface GoogleSignupResponse extends ApiResponse {
|
|
166
|
+
username: string;
|
|
167
|
+
email: string;
|
|
168
|
+
name?: string;
|
|
169
|
+
picture?: string;
|
|
170
|
+
token: string;
|
|
171
|
+
expiresIn: number;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Google login response
|
|
175
|
+
*/
|
|
176
|
+
interface GoogleLoginResponse extends ApiResponse {
|
|
177
|
+
username: string;
|
|
178
|
+
email: string;
|
|
179
|
+
name?: string;
|
|
180
|
+
picture?: string;
|
|
181
|
+
token: string;
|
|
182
|
+
expiresIn: number;
|
|
183
|
+
}
|
|
135
184
|
|
|
136
185
|
/**
|
|
137
186
|
* B3nd Wallet Client
|
|
@@ -178,6 +227,8 @@ declare class WalletClient {
|
|
|
178
227
|
private fetchImpl;
|
|
179
228
|
private currentSession;
|
|
180
229
|
constructor(config: WalletClientConfig);
|
|
230
|
+
private buildUrl;
|
|
231
|
+
private buildAppKeyUrl;
|
|
181
232
|
/**
|
|
182
233
|
* Get the current authenticated session
|
|
183
234
|
*/
|
|
@@ -220,7 +271,7 @@ declare class WalletClient {
|
|
|
220
271
|
* Change password for current user
|
|
221
272
|
* Requires active authentication session
|
|
222
273
|
*/
|
|
223
|
-
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
274
|
+
changePassword(appKey: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
224
275
|
/**
|
|
225
276
|
* Request a password reset token
|
|
226
277
|
* Does not require authentication
|
|
@@ -234,35 +285,41 @@ declare class WalletClient {
|
|
|
234
285
|
/**
|
|
235
286
|
* Sign up with app token (scoped to an app)
|
|
236
287
|
*/
|
|
237
|
-
signupWithToken(
|
|
288
|
+
signupWithToken(appKey: string, tokenOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
|
|
238
289
|
/**
|
|
239
290
|
* Login with app token and session (scoped to an app)
|
|
240
291
|
*/
|
|
241
|
-
loginWithTokenSession(
|
|
292
|
+
loginWithTokenSession(appKey: string, tokenOrSession: string, sessionOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
|
|
242
293
|
/**
|
|
243
294
|
* Request password reset scoped to app token
|
|
244
295
|
*/
|
|
245
|
-
requestPasswordResetWithToken(
|
|
296
|
+
requestPasswordResetWithToken(appKey: string, tokenOrUsername: string, maybeUsername?: string): Promise<PasswordResetToken>;
|
|
246
297
|
/**
|
|
247
|
-
* Reset password scoped to app
|
|
298
|
+
* Reset password scoped to an app
|
|
248
299
|
*/
|
|
249
|
-
resetPasswordWithToken(
|
|
300
|
+
resetPasswordWithToken(appKey: string, _tokenOrUsername: string, usernameOrReset: string, resetToken?: string, newPassword?: string): Promise<AuthSession>;
|
|
250
301
|
/**
|
|
251
302
|
* Get public keys for the current authenticated user.
|
|
252
303
|
* Requires an active authentication session.
|
|
253
304
|
*/
|
|
254
|
-
getPublicKeys(): Promise<UserPublicKeys>;
|
|
305
|
+
getPublicKeys(appKey: string): Promise<UserPublicKeys>;
|
|
255
306
|
/**
|
|
256
307
|
* Proxy a write request through the wallet server
|
|
257
308
|
* The server signs the write with its identity key
|
|
258
309
|
* Requires active authentication session
|
|
259
310
|
*/
|
|
260
311
|
proxyWrite(request: ProxyWriteRequest): Promise<ProxyWriteResponse>;
|
|
312
|
+
/**
|
|
313
|
+
* Proxy a read request through the wallet server
|
|
314
|
+
* The server decrypts encrypted data using user's encryption key
|
|
315
|
+
* Requires active authentication session
|
|
316
|
+
*/
|
|
317
|
+
proxyRead(request: ProxyReadRequest): Promise<ProxyReadResponse>;
|
|
261
318
|
/**
|
|
262
319
|
* Convenience method: Get current user's public keys
|
|
263
320
|
* Requires active authentication session
|
|
264
321
|
*/
|
|
265
|
-
getMyPublicKeys(): Promise<UserPublicKeys>;
|
|
322
|
+
getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
|
|
266
323
|
/**
|
|
267
324
|
* Get server's public keys
|
|
268
325
|
*
|
|
@@ -273,6 +330,25 @@ declare class WalletClient {
|
|
|
273
330
|
identityPublicKeyHex: string;
|
|
274
331
|
encryptionPublicKeyHex: string;
|
|
275
332
|
}>;
|
|
333
|
+
/**
|
|
334
|
+
* Sign up with Google OAuth (scoped to app token)
|
|
335
|
+
* Returns session data with Google profile info - call setSession() to activate it
|
|
336
|
+
*
|
|
337
|
+
* @param token - App token from app server
|
|
338
|
+
* @param googleIdToken - Google ID token from Google Sign-In
|
|
339
|
+
* @returns GoogleAuthSession with username, JWT token, and Google profile info
|
|
340
|
+
*/
|
|
341
|
+
signupWithGoogle(appKey: string, token: string, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
342
|
+
/**
|
|
343
|
+
* Login with Google OAuth (scoped to app token and session)
|
|
344
|
+
* Returns session data with Google profile info - call setSession() to activate it
|
|
345
|
+
*
|
|
346
|
+
* @param token - App token from app server
|
|
347
|
+
* @param session - Session key from app server
|
|
348
|
+
* @param googleIdToken - Google ID token from Google Sign-In
|
|
349
|
+
* @returns GoogleAuthSession with username, JWT token, and Google profile info
|
|
350
|
+
*/
|
|
351
|
+
loginWithGoogle(appKey: string, token: string, session: string, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
276
352
|
}
|
|
277
353
|
|
|
278
|
-
export { type ApiResponse, type AuthSession, type ChangePasswordResponse, type HealthResponse, type LoginResponse, type PasswordResetToken, type ProxyWriteRequest, type ProxyWriteResponse, type PublicKeysResponse, type RequestPasswordResetResponse, type ResetPasswordResponse, type SignupResponse, type UserCredentials, type UserPublicKeys, WalletClient, type WalletClientConfig };
|
|
354
|
+
export { type ApiResponse, type AuthSession, type ChangePasswordResponse, type GoogleAuthSession, type GoogleLoginResponse, type GoogleSignupResponse, type HealthResponse, type LoginResponse, type PasswordResetToken, type ProxyReadRequest, type ProxyReadResponse, type ProxyWriteRequest, type ProxyWriteResponse, type PublicKeysResponse, type RequestPasswordResetResponse, type ResetPasswordResponse, type SignupResponse, type UserCredentials, type UserPublicKeys, WalletClient, type WalletClientConfig };
|
package/dist/wallet/mod.js
CHANGED
package/package.json
CHANGED
package/dist/chunk-FUMSJI3N.js
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__export
|
|
3
|
-
} from "./chunk-MLKGABMK.js";
|
|
4
|
-
|
|
5
|
-
// encrypt/mod.ts
|
|
6
|
-
var mod_exports = {};
|
|
7
|
-
__export(mod_exports, {
|
|
8
|
-
createAuthenticatedMessage: () => createAuthenticatedMessage,
|
|
9
|
-
createSignedEncryptedMessage: () => createSignedEncryptedMessage,
|
|
10
|
-
decrypt: () => decrypt,
|
|
11
|
-
decryptWithHex: () => decryptWithHex,
|
|
12
|
-
encrypt: () => encrypt,
|
|
13
|
-
generateEncryptionKeyPair: () => generateEncryptionKeyPair,
|
|
14
|
-
generateNonce: () => generateNonce,
|
|
15
|
-
generateRandomData: () => generateRandomData,
|
|
16
|
-
generateSigningKeyPair: () => generateSigningKeyPair,
|
|
17
|
-
sign: () => sign,
|
|
18
|
-
signWithHex: () => signWithHex,
|
|
19
|
-
verify: () => verify,
|
|
20
|
-
verifyAndDecrypt: () => verifyAndDecrypt
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// shared/encoding.ts
|
|
24
|
-
function encodeHex(bytes) {
|
|
25
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
26
|
-
}
|
|
27
|
-
function decodeHex(hex) {
|
|
28
|
-
if (hex.length % 2 !== 0) {
|
|
29
|
-
throw new Error("Invalid hex input");
|
|
30
|
-
}
|
|
31
|
-
const buffer = new ArrayBuffer(hex.length / 2);
|
|
32
|
-
const bytes = new Uint8Array(buffer);
|
|
33
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
34
|
-
bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
|
|
35
|
-
}
|
|
36
|
-
return bytes;
|
|
37
|
-
}
|
|
38
|
-
function encodeBase64(bytes) {
|
|
39
|
-
if (typeof Buffer !== "undefined") {
|
|
40
|
-
return Buffer.from(bytes).toString("base64");
|
|
41
|
-
}
|
|
42
|
-
let binary = "";
|
|
43
|
-
bytes.forEach((b) => binary += String.fromCharCode(b));
|
|
44
|
-
return btoa(binary);
|
|
45
|
-
}
|
|
46
|
-
function decodeBase64(b64) {
|
|
47
|
-
if (typeof Buffer !== "undefined") {
|
|
48
|
-
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
49
|
-
}
|
|
50
|
-
const binary = atob(b64);
|
|
51
|
-
const bytes = new Uint8Array(binary.length);
|
|
52
|
-
for (let i = 0; i < binary.length; i++) {
|
|
53
|
-
bytes[i] = binary.charCodeAt(i);
|
|
54
|
-
}
|
|
55
|
-
return bytes;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// encrypt/mod.ts
|
|
59
|
-
async function generateSigningKeyPair() {
|
|
60
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
61
|
-
{
|
|
62
|
-
name: "Ed25519",
|
|
63
|
-
namedCurve: "Ed25519"
|
|
64
|
-
},
|
|
65
|
-
true,
|
|
66
|
-
["sign", "verify"]
|
|
67
|
-
);
|
|
68
|
-
const publicKeyBytes = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
69
|
-
const privateKeyBytes = await crypto.subtle.exportKey(
|
|
70
|
-
"pkcs8",
|
|
71
|
-
keyPair.privateKey
|
|
72
|
-
);
|
|
73
|
-
return {
|
|
74
|
-
publicKey: keyPair.publicKey,
|
|
75
|
-
privateKey: keyPair.privateKey,
|
|
76
|
-
publicKeyHex: encodeHex(new Uint8Array(publicKeyBytes)),
|
|
77
|
-
privateKeyHex: encodeHex(new Uint8Array(privateKeyBytes))
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async function generateEncryptionKeyPair() {
|
|
81
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
82
|
-
{
|
|
83
|
-
name: "X25519",
|
|
84
|
-
namedCurve: "X25519"
|
|
85
|
-
},
|
|
86
|
-
true,
|
|
87
|
-
["deriveBits"]
|
|
88
|
-
);
|
|
89
|
-
const publicKeyBytes = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
90
|
-
return {
|
|
91
|
-
publicKey: keyPair.publicKey,
|
|
92
|
-
privateKey: keyPair.privateKey,
|
|
93
|
-
publicKeyHex: encodeHex(new Uint8Array(publicKeyBytes))
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async function sign(privateKey, payload) {
|
|
97
|
-
const encoder = new TextEncoder();
|
|
98
|
-
const data = encoder.encode(JSON.stringify(payload));
|
|
99
|
-
const signature = await crypto.subtle.sign("Ed25519", privateKey, data);
|
|
100
|
-
return encodeHex(new Uint8Array(signature));
|
|
101
|
-
}
|
|
102
|
-
async function signWithHex(privateKeyHex, payload) {
|
|
103
|
-
const privateKeyBytes = decodeHex(privateKeyHex).buffer;
|
|
104
|
-
const privateKey = await crypto.subtle.importKey(
|
|
105
|
-
"pkcs8",
|
|
106
|
-
privateKeyBytes,
|
|
107
|
-
{
|
|
108
|
-
name: "Ed25519",
|
|
109
|
-
namedCurve: "Ed25519"
|
|
110
|
-
},
|
|
111
|
-
false,
|
|
112
|
-
["sign"]
|
|
113
|
-
);
|
|
114
|
-
return await sign(privateKey, payload);
|
|
115
|
-
}
|
|
116
|
-
async function verify(publicKeyHex, signatureHex, payload) {
|
|
117
|
-
try {
|
|
118
|
-
const publicKeyBytes = decodeHex(publicKeyHex).buffer;
|
|
119
|
-
const publicKey = await crypto.subtle.importKey(
|
|
120
|
-
"raw",
|
|
121
|
-
publicKeyBytes,
|
|
122
|
-
{
|
|
123
|
-
name: "Ed25519",
|
|
124
|
-
namedCurve: "Ed25519"
|
|
125
|
-
},
|
|
126
|
-
false,
|
|
127
|
-
["verify"]
|
|
128
|
-
);
|
|
129
|
-
const encoder = new TextEncoder();
|
|
130
|
-
const data = encoder.encode(JSON.stringify(payload));
|
|
131
|
-
const signatureBytes = decodeHex(signatureHex).buffer;
|
|
132
|
-
return await crypto.subtle.verify(
|
|
133
|
-
"Ed25519",
|
|
134
|
-
publicKey,
|
|
135
|
-
signatureBytes,
|
|
136
|
-
data
|
|
137
|
-
);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
console.error("Verification error:", error);
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function encrypt(data, recipientPublicKeyHex) {
|
|
144
|
-
const ephemeralKeyPair = await generateEncryptionKeyPair();
|
|
145
|
-
const recipientPublicKeyBytes = decodeHex(recipientPublicKeyHex).buffer;
|
|
146
|
-
const recipientPublicKey = await crypto.subtle.importKey(
|
|
147
|
-
"raw",
|
|
148
|
-
recipientPublicKeyBytes,
|
|
149
|
-
{
|
|
150
|
-
name: "X25519",
|
|
151
|
-
namedCurve: "X25519"
|
|
152
|
-
},
|
|
153
|
-
false,
|
|
154
|
-
[]
|
|
155
|
-
);
|
|
156
|
-
const sharedSecret = await crypto.subtle.deriveBits(
|
|
157
|
-
{
|
|
158
|
-
name: "X25519",
|
|
159
|
-
public: recipientPublicKey
|
|
160
|
-
},
|
|
161
|
-
ephemeralKeyPair.privateKey,
|
|
162
|
-
256
|
|
163
|
-
);
|
|
164
|
-
const aesKey = await crypto.subtle.importKey(
|
|
165
|
-
"raw",
|
|
166
|
-
sharedSecret,
|
|
167
|
-
{
|
|
168
|
-
name: "AES-GCM",
|
|
169
|
-
length: 256
|
|
170
|
-
},
|
|
171
|
-
false,
|
|
172
|
-
["encrypt"]
|
|
173
|
-
);
|
|
174
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
175
|
-
const encoder = new TextEncoder();
|
|
176
|
-
const plaintext = encoder.encode(JSON.stringify(data));
|
|
177
|
-
const ciphertext = await crypto.subtle.encrypt(
|
|
178
|
-
{
|
|
179
|
-
name: "AES-GCM",
|
|
180
|
-
iv: nonce
|
|
181
|
-
},
|
|
182
|
-
aesKey,
|
|
183
|
-
plaintext
|
|
184
|
-
);
|
|
185
|
-
return {
|
|
186
|
-
data: encodeBase64(new Uint8Array(ciphertext)),
|
|
187
|
-
nonce: encodeBase64(nonce),
|
|
188
|
-
ephemeralPublicKey: ephemeralKeyPair.publicKeyHex
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
async function decrypt(encryptedPayload, recipientPrivateKey) {
|
|
192
|
-
if (!encryptedPayload.ephemeralPublicKey) {
|
|
193
|
-
throw new Error("Missing ephemeral public key");
|
|
194
|
-
}
|
|
195
|
-
const ephemeralPublicKeyBytes = decodeHex(
|
|
196
|
-
encryptedPayload.ephemeralPublicKey
|
|
197
|
-
).buffer;
|
|
198
|
-
const ephemeralPublicKey = await crypto.subtle.importKey(
|
|
199
|
-
"raw",
|
|
200
|
-
ephemeralPublicKeyBytes,
|
|
201
|
-
{
|
|
202
|
-
name: "X25519",
|
|
203
|
-
namedCurve: "X25519"
|
|
204
|
-
},
|
|
205
|
-
false,
|
|
206
|
-
[]
|
|
207
|
-
);
|
|
208
|
-
const sharedSecret = await crypto.subtle.deriveBits(
|
|
209
|
-
{
|
|
210
|
-
name: "X25519",
|
|
211
|
-
public: ephemeralPublicKey
|
|
212
|
-
},
|
|
213
|
-
recipientPrivateKey,
|
|
214
|
-
256
|
|
215
|
-
);
|
|
216
|
-
const aesKey = await crypto.subtle.importKey(
|
|
217
|
-
"raw",
|
|
218
|
-
sharedSecret,
|
|
219
|
-
{
|
|
220
|
-
name: "AES-GCM",
|
|
221
|
-
length: 256
|
|
222
|
-
},
|
|
223
|
-
false,
|
|
224
|
-
["decrypt"]
|
|
225
|
-
);
|
|
226
|
-
const ciphertext = new Uint8Array(decodeBase64(encryptedPayload.data));
|
|
227
|
-
const nonce = new Uint8Array(decodeBase64(encryptedPayload.nonce));
|
|
228
|
-
const plaintext = await crypto.subtle.decrypt(
|
|
229
|
-
{
|
|
230
|
-
name: "AES-GCM",
|
|
231
|
-
iv: nonce
|
|
232
|
-
},
|
|
233
|
-
aesKey,
|
|
234
|
-
ciphertext
|
|
235
|
-
);
|
|
236
|
-
const decoder = new TextDecoder();
|
|
237
|
-
const json = decoder.decode(plaintext);
|
|
238
|
-
return JSON.parse(json);
|
|
239
|
-
}
|
|
240
|
-
async function decryptWithHex(encryptedPayload, recipientPrivateKeyHex) {
|
|
241
|
-
const privateKeyBytes = decodeHex(recipientPrivateKeyHex).buffer;
|
|
242
|
-
const privateKey = await crypto.subtle.importKey(
|
|
243
|
-
"raw",
|
|
244
|
-
privateKeyBytes,
|
|
245
|
-
{
|
|
246
|
-
name: "X25519",
|
|
247
|
-
namedCurve: "X25519"
|
|
248
|
-
},
|
|
249
|
-
false,
|
|
250
|
-
["deriveBits"]
|
|
251
|
-
);
|
|
252
|
-
return await decrypt(encryptedPayload, privateKey);
|
|
253
|
-
}
|
|
254
|
-
async function createAuthenticatedMessage(payload, signers) {
|
|
255
|
-
const auth = await Promise.all(
|
|
256
|
-
signers.map(async (signer) => {
|
|
257
|
-
const signature = await sign(signer.privateKey, payload);
|
|
258
|
-
return {
|
|
259
|
-
pubkey: signer.publicKeyHex,
|
|
260
|
-
signature
|
|
261
|
-
};
|
|
262
|
-
})
|
|
263
|
-
);
|
|
264
|
-
return {
|
|
265
|
-
auth,
|
|
266
|
-
payload
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
async function createSignedEncryptedMessage(data, signers, recipientPublicKeyHex) {
|
|
270
|
-
const encrypted = await encrypt(data, recipientPublicKeyHex);
|
|
271
|
-
const auth = await Promise.all(
|
|
272
|
-
signers.map(async (signer) => {
|
|
273
|
-
const signature = await sign(signer.privateKey, encrypted);
|
|
274
|
-
return {
|
|
275
|
-
pubkey: signer.publicKeyHex,
|
|
276
|
-
signature
|
|
277
|
-
};
|
|
278
|
-
})
|
|
279
|
-
);
|
|
280
|
-
return {
|
|
281
|
-
auth,
|
|
282
|
-
payload: encrypted
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
async function verifyAndDecrypt(message, recipientPrivateKey) {
|
|
286
|
-
const verificationResults = await Promise.all(
|
|
287
|
-
message.auth.map(async (authEntry) => {
|
|
288
|
-
const verified2 = await verify(
|
|
289
|
-
authEntry.pubkey,
|
|
290
|
-
authEntry.signature,
|
|
291
|
-
message.payload
|
|
292
|
-
);
|
|
293
|
-
return { pubkey: authEntry.pubkey, verified: verified2 };
|
|
294
|
-
})
|
|
295
|
-
);
|
|
296
|
-
const verified = verificationResults.every((r) => r.verified);
|
|
297
|
-
const signers = verificationResults.filter((r) => r.verified).map((r) => r.pubkey);
|
|
298
|
-
const data = await decrypt(message.payload, recipientPrivateKey);
|
|
299
|
-
return {
|
|
300
|
-
data,
|
|
301
|
-
verified,
|
|
302
|
-
signers
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function generateNonce(length = 12) {
|
|
306
|
-
return crypto.getRandomValues(new Uint8Array(length));
|
|
307
|
-
}
|
|
308
|
-
function generateRandomData(size) {
|
|
309
|
-
return crypto.getRandomValues(new Uint8Array(size));
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export {
|
|
313
|
-
generateSigningKeyPair,
|
|
314
|
-
generateEncryptionKeyPair,
|
|
315
|
-
sign,
|
|
316
|
-
signWithHex,
|
|
317
|
-
verify,
|
|
318
|
-
encrypt,
|
|
319
|
-
decrypt,
|
|
320
|
-
decryptWithHex,
|
|
321
|
-
createAuthenticatedMessage,
|
|
322
|
-
createSignedEncryptedMessage,
|
|
323
|
-
verifyAndDecrypt,
|
|
324
|
-
generateNonce,
|
|
325
|
-
generateRandomData,
|
|
326
|
-
mod_exports
|
|
327
|
-
};
|
package/dist/mod-DHjjiF1o.d.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
interface KeyPair {
|
|
2
|
-
publicKey: CryptoKey;
|
|
3
|
-
privateKey: CryptoKey;
|
|
4
|
-
publicKeyHex: string;
|
|
5
|
-
privateKeyHex: string;
|
|
6
|
-
}
|
|
7
|
-
interface EncryptionKeyPair {
|
|
8
|
-
publicKey: CryptoKey;
|
|
9
|
-
privateKey: CryptoKey;
|
|
10
|
-
publicKeyHex: string;
|
|
11
|
-
}
|
|
12
|
-
interface EncryptedPayload {
|
|
13
|
-
data: string;
|
|
14
|
-
nonce: string;
|
|
15
|
-
ephemeralPublicKey?: string;
|
|
16
|
-
}
|
|
17
|
-
interface AuthenticatedMessage<T = unknown> {
|
|
18
|
-
auth: Array<{
|
|
19
|
-
pubkey: string;
|
|
20
|
-
signature: string;
|
|
21
|
-
}>;
|
|
22
|
-
payload: T;
|
|
23
|
-
}
|
|
24
|
-
interface SignedEncryptedMessage {
|
|
25
|
-
auth: Array<{
|
|
26
|
-
pubkey: string;
|
|
27
|
-
signature: string;
|
|
28
|
-
}>;
|
|
29
|
-
payload: EncryptedPayload;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Generate an Ed25519 keypair for signing
|
|
33
|
-
*/
|
|
34
|
-
declare function generateSigningKeyPair(): Promise<KeyPair>;
|
|
35
|
-
/**
|
|
36
|
-
* Generate an X25519 keypair for encryption (ECDH)
|
|
37
|
-
*/
|
|
38
|
-
declare function generateEncryptionKeyPair(): Promise<EncryptionKeyPair>;
|
|
39
|
-
/**
|
|
40
|
-
* Sign a payload with an Ed25519 private key
|
|
41
|
-
*/
|
|
42
|
-
declare function sign<T>(privateKey: CryptoKey, payload: T): Promise<string>;
|
|
43
|
-
/**
|
|
44
|
-
* Sign a payload with an Ed25519 private key from hex
|
|
45
|
-
*/
|
|
46
|
-
declare function signWithHex<T>(privateKeyHex: string, payload: T): Promise<string>;
|
|
47
|
-
/**
|
|
48
|
-
* Verify a signature using Ed25519 public key
|
|
49
|
-
*/
|
|
50
|
-
declare function verify<T>(publicKeyHex: string, signatureHex: string, payload: T): Promise<boolean>;
|
|
51
|
-
/**
|
|
52
|
-
* Encrypt data using X25519 ECDH + AES-GCM
|
|
53
|
-
* Uses ephemeral keypair for forward secrecy
|
|
54
|
-
*/
|
|
55
|
-
declare function encrypt(data: unknown, recipientPublicKeyHex: string): Promise<EncryptedPayload>;
|
|
56
|
-
/**
|
|
57
|
-
* Decrypt data using X25519 ECDH + AES-GCM
|
|
58
|
-
*/
|
|
59
|
-
declare function decrypt(encryptedPayload: EncryptedPayload, recipientPrivateKey: CryptoKey): Promise<unknown>;
|
|
60
|
-
/**
|
|
61
|
-
* Decrypt data using private key from hex
|
|
62
|
-
*/
|
|
63
|
-
declare function decryptWithHex(encryptedPayload: EncryptedPayload, recipientPrivateKeyHex: string): Promise<unknown>;
|
|
64
|
-
/**
|
|
65
|
-
* Create an authenticated message (signed but not encrypted)
|
|
66
|
-
*/
|
|
67
|
-
declare function createAuthenticatedMessage<T>(payload: T, signers: Array<{
|
|
68
|
-
privateKey: CryptoKey;
|
|
69
|
-
publicKeyHex: string;
|
|
70
|
-
}>): Promise<AuthenticatedMessage<T>>;
|
|
71
|
-
/**
|
|
72
|
-
* Create a signed and encrypted message
|
|
73
|
-
*/
|
|
74
|
-
declare function createSignedEncryptedMessage(data: unknown, signers: Array<{
|
|
75
|
-
privateKey: CryptoKey;
|
|
76
|
-
publicKeyHex: string;
|
|
77
|
-
}>, recipientPublicKeyHex: string): Promise<SignedEncryptedMessage>;
|
|
78
|
-
/**
|
|
79
|
-
* Verify and decrypt a signed encrypted message
|
|
80
|
-
*/
|
|
81
|
-
declare function verifyAndDecrypt(message: SignedEncryptedMessage, recipientPrivateKey: CryptoKey): Promise<{
|
|
82
|
-
data: unknown;
|
|
83
|
-
verified: boolean;
|
|
84
|
-
signers: string[];
|
|
85
|
-
}>;
|
|
86
|
-
declare function generateNonce(length?: number): Uint8Array;
|
|
87
|
-
declare function generateRandomData(size: number): Uint8Array;
|
|
88
|
-
|
|
89
|
-
type mod_AuthenticatedMessage<T = unknown> = AuthenticatedMessage<T>;
|
|
90
|
-
type mod_EncryptedPayload = EncryptedPayload;
|
|
91
|
-
type mod_EncryptionKeyPair = EncryptionKeyPair;
|
|
92
|
-
type mod_KeyPair = KeyPair;
|
|
93
|
-
type mod_SignedEncryptedMessage = SignedEncryptedMessage;
|
|
94
|
-
declare const mod_createAuthenticatedMessage: typeof createAuthenticatedMessage;
|
|
95
|
-
declare const mod_createSignedEncryptedMessage: typeof createSignedEncryptedMessage;
|
|
96
|
-
declare const mod_decrypt: typeof decrypt;
|
|
97
|
-
declare const mod_decryptWithHex: typeof decryptWithHex;
|
|
98
|
-
declare const mod_encrypt: typeof encrypt;
|
|
99
|
-
declare const mod_generateEncryptionKeyPair: typeof generateEncryptionKeyPair;
|
|
100
|
-
declare const mod_generateNonce: typeof generateNonce;
|
|
101
|
-
declare const mod_generateRandomData: typeof generateRandomData;
|
|
102
|
-
declare const mod_generateSigningKeyPair: typeof generateSigningKeyPair;
|
|
103
|
-
declare const mod_sign: typeof sign;
|
|
104
|
-
declare const mod_signWithHex: typeof signWithHex;
|
|
105
|
-
declare const mod_verify: typeof verify;
|
|
106
|
-
declare const mod_verifyAndDecrypt: typeof verifyAndDecrypt;
|
|
107
|
-
declare namespace mod {
|
|
108
|
-
export { type mod_AuthenticatedMessage as AuthenticatedMessage, type mod_EncryptedPayload as EncryptedPayload, type mod_EncryptionKeyPair as EncryptionKeyPair, type mod_KeyPair as KeyPair, type mod_SignedEncryptedMessage as SignedEncryptedMessage, mod_createAuthenticatedMessage as createAuthenticatedMessage, mod_createSignedEncryptedMessage as createSignedEncryptedMessage, mod_decrypt as decrypt, mod_decryptWithHex as decryptWithHex, mod_encrypt as encrypt, mod_generateEncryptionKeyPair as generateEncryptionKeyPair, mod_generateNonce as generateNonce, mod_generateRandomData as generateRandomData, mod_generateSigningKeyPair as generateSigningKeyPair, mod_sign as sign, mod_signWithHex as signWithHex, mod_verify as verify, mod_verifyAndDecrypt as verifyAndDecrypt };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export { type AuthenticatedMessage as A, type EncryptionKeyPair as E, type KeyPair as K, type SignedEncryptedMessage as S, type EncryptedPayload as a, generateEncryptionKeyPair as b, signWithHex as c, decrypt as d, encrypt as e, decryptWithHex as f, generateSigningKeyPair as g, createAuthenticatedMessage as h, createSignedEncryptedMessage as i, verifyAndDecrypt as j, generateNonce as k, generateRandomData as l, mod as m, sign as s, verify as v };
|