@bandeira-tech/b3nd-web 0.2.0 → 0.2.2
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-2D2RT2DW.js → chunk-2VOR4VLG.js} +118 -34
- package/dist/{chunk-XH4OLKBV.js → chunk-7U5JDFQW.js} +2 -5
- package/dist/chunk-K3ZSSVHR.js +615 -0
- package/dist/{chunk-PMBS2GFA.js → chunk-LFUC4ETD.js} +9 -12
- package/dist/{chunk-C2ZIFM22.js → chunk-T43IWAQK.js} +17 -24
- package/dist/{chunk-QHDBFVLU.js → chunk-VAZUCGED.js} +24 -22
- package/dist/clients/http/mod.d.ts +1 -1
- package/dist/clients/http/mod.js +1 -1
- package/dist/clients/local-storage/mod.d.ts +1 -1
- package/dist/clients/local-storage/mod.js +1 -1
- package/dist/clients/websocket/mod.d.ts +1 -1
- package/dist/clients/websocket/mod.js +1 -1
- 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 +2 -2
- package/dist/src/mod.web.js +6 -6
- package/dist/{types-Bw0Boe0n.d.ts → types-oQCx3U-_.d.ts} +2 -2
- package/dist/wallet/mod.d.ts +61 -10
- package/dist/wallet/mod.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-G6JDROB4.js +0 -327
- package/dist/mod-DHjjiF1o.d.ts +0 -111
package/dist/wallet/mod.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ interface ProxyWriteResponse {
|
|
|
73
73
|
/**
|
|
74
74
|
* API response wrapper
|
|
75
75
|
*/
|
|
76
|
-
interface ApiResponse
|
|
76
|
+
interface ApiResponse {
|
|
77
77
|
success: boolean;
|
|
78
78
|
error?: string;
|
|
79
79
|
[key: string]: unknown;
|
|
@@ -132,6 +132,36 @@ interface HealthResponse extends ApiResponse {
|
|
|
132
132
|
server: string;
|
|
133
133
|
timestamp: string;
|
|
134
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Google OAuth session (extended AuthSession with Google profile info)
|
|
137
|
+
*/
|
|
138
|
+
interface GoogleAuthSession extends AuthSession {
|
|
139
|
+
email: string;
|
|
140
|
+
name?: string;
|
|
141
|
+
picture?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Google signup response
|
|
145
|
+
*/
|
|
146
|
+
interface GoogleSignupResponse extends ApiResponse {
|
|
147
|
+
username: string;
|
|
148
|
+
email: string;
|
|
149
|
+
name?: string;
|
|
150
|
+
picture?: string;
|
|
151
|
+
token: string;
|
|
152
|
+
expiresIn: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Google login response
|
|
156
|
+
*/
|
|
157
|
+
interface GoogleLoginResponse extends ApiResponse {
|
|
158
|
+
username: string;
|
|
159
|
+
email: string;
|
|
160
|
+
name?: string;
|
|
161
|
+
picture?: string;
|
|
162
|
+
token: string;
|
|
163
|
+
expiresIn: number;
|
|
164
|
+
}
|
|
135
165
|
|
|
136
166
|
/**
|
|
137
167
|
* B3nd Wallet Client
|
|
@@ -178,6 +208,8 @@ declare class WalletClient {
|
|
|
178
208
|
private fetchImpl;
|
|
179
209
|
private currentSession;
|
|
180
210
|
constructor(config: WalletClientConfig);
|
|
211
|
+
private buildUrl;
|
|
212
|
+
private buildAppKeyUrl;
|
|
181
213
|
/**
|
|
182
214
|
* Get the current authenticated session
|
|
183
215
|
*/
|
|
@@ -220,7 +252,7 @@ declare class WalletClient {
|
|
|
220
252
|
* Change password for current user
|
|
221
253
|
* Requires active authentication session
|
|
222
254
|
*/
|
|
223
|
-
changePassword(oldPassword: string, newPassword: string): Promise<void>;
|
|
255
|
+
changePassword(appKey: string, oldPassword: string, newPassword: string): Promise<void>;
|
|
224
256
|
/**
|
|
225
257
|
* Request a password reset token
|
|
226
258
|
* Does not require authentication
|
|
@@ -234,24 +266,24 @@ declare class WalletClient {
|
|
|
234
266
|
/**
|
|
235
267
|
* Sign up with app token (scoped to an app)
|
|
236
268
|
*/
|
|
237
|
-
signupWithToken(
|
|
269
|
+
signupWithToken(appKey: string, tokenOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
|
|
238
270
|
/**
|
|
239
271
|
* Login with app token and session (scoped to an app)
|
|
240
272
|
*/
|
|
241
|
-
loginWithTokenSession(
|
|
273
|
+
loginWithTokenSession(appKey: string, tokenOrSession: string, sessionOrCredentials: string | UserCredentials, maybeCredentials?: UserCredentials): Promise<AuthSession>;
|
|
242
274
|
/**
|
|
243
275
|
* Request password reset scoped to app token
|
|
244
276
|
*/
|
|
245
|
-
requestPasswordResetWithToken(
|
|
277
|
+
requestPasswordResetWithToken(appKey: string, tokenOrUsername: string, maybeUsername?: string): Promise<PasswordResetToken>;
|
|
246
278
|
/**
|
|
247
|
-
* Reset password scoped to app
|
|
279
|
+
* Reset password scoped to an app
|
|
248
280
|
*/
|
|
249
|
-
resetPasswordWithToken(
|
|
281
|
+
resetPasswordWithToken(appKey: string, _tokenOrUsername: string, usernameOrReset: string, resetToken?: string, newPassword?: string): Promise<AuthSession>;
|
|
250
282
|
/**
|
|
251
283
|
* Get public keys for the current authenticated user.
|
|
252
284
|
* Requires an active authentication session.
|
|
253
285
|
*/
|
|
254
|
-
getPublicKeys(): Promise<UserPublicKeys>;
|
|
286
|
+
getPublicKeys(appKey: string): Promise<UserPublicKeys>;
|
|
255
287
|
/**
|
|
256
288
|
* Proxy a write request through the wallet server
|
|
257
289
|
* The server signs the write with its identity key
|
|
@@ -262,7 +294,7 @@ declare class WalletClient {
|
|
|
262
294
|
* Convenience method: Get current user's public keys
|
|
263
295
|
* Requires active authentication session
|
|
264
296
|
*/
|
|
265
|
-
getMyPublicKeys(): Promise<UserPublicKeys>;
|
|
297
|
+
getMyPublicKeys(appKey: string): Promise<UserPublicKeys>;
|
|
266
298
|
/**
|
|
267
299
|
* Get server's public keys
|
|
268
300
|
*
|
|
@@ -273,6 +305,25 @@ declare class WalletClient {
|
|
|
273
305
|
identityPublicKeyHex: string;
|
|
274
306
|
encryptionPublicKeyHex: string;
|
|
275
307
|
}>;
|
|
308
|
+
/**
|
|
309
|
+
* Sign up with Google OAuth (scoped to app token)
|
|
310
|
+
* Returns session data with Google profile info - call setSession() to activate it
|
|
311
|
+
*
|
|
312
|
+
* @param token - App token from app server
|
|
313
|
+
* @param googleIdToken - Google ID token from Google Sign-In
|
|
314
|
+
* @returns GoogleAuthSession with username, JWT token, and Google profile info
|
|
315
|
+
*/
|
|
316
|
+
signupWithGoogle(appKey: string, token: string, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
317
|
+
/**
|
|
318
|
+
* Login with Google OAuth (scoped to app token and session)
|
|
319
|
+
* Returns session data with Google profile info - call setSession() to activate it
|
|
320
|
+
*
|
|
321
|
+
* @param token - App token from app server
|
|
322
|
+
* @param session - Session key from app server
|
|
323
|
+
* @param googleIdToken - Google ID token from Google Sign-In
|
|
324
|
+
* @returns GoogleAuthSession with username, JWT token, and Google profile info
|
|
325
|
+
*/
|
|
326
|
+
loginWithGoogle(appKey: string, token: string, session: string, googleIdToken: string): Promise<GoogleAuthSession>;
|
|
276
327
|
}
|
|
277
328
|
|
|
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 };
|
|
329
|
+
export { type ApiResponse, type AuthSession, type ChangePasswordResponse, type GoogleAuthSession, type GoogleLoginResponse, type GoogleSignupResponse, 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 };
|
package/dist/wallet/mod.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bandeira-tech/b3nd-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Browser-focused B3nd SDK bundle",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/mod.web.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
42
|
"scripts": {
|
|
43
|
-
"build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts --dts --format esm --out-dir dist --clean",
|
|
43
|
+
"build": "tsup src/mod.web.ts wallet/mod.ts apps/mod.ts encrypt/mod.ts clients/http/mod.ts clients/local-storage/mod.ts clients/websocket/mod.ts --dts --format esm --out-dir dist --clean --tsconfig tsconfig.web.json",
|
|
44
44
|
"clean": "rm -rf dist",
|
|
45
45
|
"lint": "deno lint src/",
|
|
46
46
|
"format": "deno fmt src/"
|
package/dist/chunk-G6JDROB4.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 btoa === "function") {
|
|
40
|
-
let binary = "";
|
|
41
|
-
bytes.forEach((b) => binary += String.fromCharCode(b));
|
|
42
|
-
return btoa(binary);
|
|
43
|
-
}
|
|
44
|
-
return Buffer.from(bytes).toString("base64");
|
|
45
|
-
}
|
|
46
|
-
function decodeBase64(b64) {
|
|
47
|
-
if (typeof atob === "function") {
|
|
48
|
-
const binary = atob(b64);
|
|
49
|
-
const bytes = new Uint8Array(binary.length);
|
|
50
|
-
for (let i = 0; i < binary.length; i++) {
|
|
51
|
-
bytes[i] = binary.charCodeAt(i);
|
|
52
|
-
}
|
|
53
|
-
return bytes;
|
|
54
|
-
}
|
|
55
|
-
return new Uint8Array(Buffer.from(b64, "base64"));
|
|
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 };
|