@aztec/wallet-sdk 0.0.1-commit.fcb71a6 → 3.0.0-devnet.2-patch.1
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 +241 -267
- package/dest/crypto.d.ts +183 -0
- package/dest/crypto.d.ts.map +1 -0
- package/dest/crypto.js +300 -0
- package/dest/manager/index.d.ts +4 -3
- package/dest/manager/index.d.ts.map +1 -1
- package/dest/manager/index.js +2 -0
- package/dest/manager/types.d.ts +22 -1
- package/dest/manager/types.d.ts.map +1 -1
- package/dest/manager/wallet_manager.d.ts +1 -1
- package/dest/manager/wallet_manager.d.ts.map +1 -1
- package/dest/manager/wallet_manager.js +34 -15
- package/dest/providers/extension/extension_provider.d.ts +53 -7
- package/dest/providers/extension/extension_provider.d.ts.map +1 -1
- package/dest/providers/extension/extension_provider.js +81 -13
- package/dest/providers/extension/extension_wallet.d.ts +140 -8
- package/dest/providers/extension/extension_wallet.d.ts.map +1 -1
- package/dest/providers/extension/extension_wallet.js +268 -46
- package/dest/providers/extension/index.d.ts +6 -4
- package/dest/providers/extension/index.d.ts.map +1 -1
- package/dest/providers/extension/index.js +2 -0
- package/dest/types.d.ts +92 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +10 -0
- package/package.json +10 -8
- package/src/crypto.ts +375 -0
- package/src/manager/index.ts +4 -8
- package/src/manager/types.ts +22 -0
- package/src/manager/wallet_manager.ts +43 -16
- package/src/providers/extension/extension_provider.ts +112 -17
- package/src/providers/extension/extension_wallet.ts +310 -55
- package/src/providers/extension/index.ts +5 -3
- package/src/{providers/types.ts → types.ts} +33 -6
- package/dest/providers/types.d.ts +0 -67
- package/dest/providers/types.d.ts.map +0 -1
- package/dest/providers/types.js +0 -3
package/dest/crypto.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exported public key in JWK format for transmission over untrusted channels.
|
|
3
|
+
*
|
|
4
|
+
* Contains only the public components of an ECDH P-256 key, safe to share.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExportedPublicKey {
|
|
7
|
+
/** Key type - always "EC" for elliptic curve */
|
|
8
|
+
kty: string;
|
|
9
|
+
/** Curve name - always "P-256" */
|
|
10
|
+
crv: string;
|
|
11
|
+
/** X coordinate (base64url encoded) */
|
|
12
|
+
x: string;
|
|
13
|
+
/** Y coordinate (base64url encoded) */
|
|
14
|
+
y: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Encrypted message payload containing ciphertext and initialization vector.
|
|
18
|
+
*
|
|
19
|
+
* Both fields are base64-encoded for safe transmission as JSON.
|
|
20
|
+
*/
|
|
21
|
+
export interface EncryptedPayload {
|
|
22
|
+
/** Initialization vector (base64 encoded, 12 bytes) */
|
|
23
|
+
iv: string;
|
|
24
|
+
/** Ciphertext (base64 encoded) */
|
|
25
|
+
ciphertext: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* ECDH key pair for secure communication.
|
|
29
|
+
*
|
|
30
|
+
* The private key should never be exported or transmitted.
|
|
31
|
+
* The public key can be exported via {@link exportPublicKey} for exchange.
|
|
32
|
+
*/
|
|
33
|
+
export interface SecureKeyPair {
|
|
34
|
+
/** Public key - safe to share */
|
|
35
|
+
publicKey: CryptoKey;
|
|
36
|
+
/** Private key - keep secret, used for key derivation */
|
|
37
|
+
privateKey: CryptoKey;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generates an ECDH P-256 key pair for key exchange.
|
|
41
|
+
*
|
|
42
|
+
* The generated key pair can be used to derive a shared secret with another
|
|
43
|
+
* party's public key using {@link deriveSharedKey}.
|
|
44
|
+
*
|
|
45
|
+
* @returns A new ECDH key pair
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const keyPair = await generateKeyPair();
|
|
50
|
+
* const publicKey = await exportPublicKey(keyPair.publicKey);
|
|
51
|
+
* // Send publicKey to the other party
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function generateKeyPair(): Promise<SecureKeyPair>;
|
|
55
|
+
/**
|
|
56
|
+
* Exports a public key to JWK format for transmission.
|
|
57
|
+
*
|
|
58
|
+
* The exported key contains only public components and is safe to transmit
|
|
59
|
+
* over untrusted channels.
|
|
60
|
+
*
|
|
61
|
+
* @param publicKey - The CryptoKey public key to export
|
|
62
|
+
* @returns The public key in JWK format
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const keyPair = await generateKeyPair();
|
|
67
|
+
* const exported = await exportPublicKey(keyPair.publicKey);
|
|
68
|
+
* // exported can be JSON serialized and sent to another party
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function exportPublicKey(publicKey: CryptoKey): Promise<ExportedPublicKey>;
|
|
72
|
+
/**
|
|
73
|
+
* Imports a public key from JWK format.
|
|
74
|
+
*
|
|
75
|
+
* Used to import the other party's public key for deriving a shared secret.
|
|
76
|
+
*
|
|
77
|
+
* @param exported - The public key in JWK format
|
|
78
|
+
* @returns A CryptoKey that can be used with {@link deriveSharedKey}
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Receive exported public key from other party
|
|
83
|
+
* const theirPublicKey = await importPublicKey(receivedPublicKey);
|
|
84
|
+
* const sharedKey = await deriveSharedKey(myPrivateKey, theirPublicKey);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function importPublicKey(exported: ExportedPublicKey): Promise<CryptoKey>;
|
|
88
|
+
/**
|
|
89
|
+
* Derives a shared AES-256-GCM key from ECDH key exchange.
|
|
90
|
+
*
|
|
91
|
+
* Both parties will derive the same shared key when using their own private key
|
|
92
|
+
* and the other party's public key. This is the core of ECDH key agreement.
|
|
93
|
+
*
|
|
94
|
+
* @param privateKey - Your ECDH private key
|
|
95
|
+
* @param publicKey - The other party's ECDH public key
|
|
96
|
+
* @returns An AES-256-GCM key for encryption/decryption
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Both parties derive the same key
|
|
101
|
+
* const sharedKeyA = await deriveSharedKey(privateKeyA, publicKeyB);
|
|
102
|
+
* const sharedKeyB = await deriveSharedKey(privateKeyB, publicKeyA);
|
|
103
|
+
* // sharedKeyA and sharedKeyB are equivalent
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function deriveSharedKey(privateKey: CryptoKey, publicKey: CryptoKey): Promise<CryptoKey>;
|
|
107
|
+
/**
|
|
108
|
+
* Encrypts data using AES-256-GCM.
|
|
109
|
+
*
|
|
110
|
+
* The data is JSON serialized before encryption. A random 12-byte IV is
|
|
111
|
+
* generated for each encryption operation.
|
|
112
|
+
*
|
|
113
|
+
* AES-GCM provides both confidentiality and authenticity - any tampering
|
|
114
|
+
* with the ciphertext will cause decryption to fail.
|
|
115
|
+
*
|
|
116
|
+
* @param key - The AES-GCM key (from {@link deriveSharedKey})
|
|
117
|
+
* @param data - The data to encrypt (will be JSON serialized)
|
|
118
|
+
* @returns The encrypted payload with IV and ciphertext
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const encrypted = await encrypt(sharedKey, { action: 'transfer', amount: 100 });
|
|
123
|
+
* // encrypted.iv and encrypted.ciphertext are base64 strings
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function encrypt(key: CryptoKey, data: unknown): Promise<EncryptedPayload>;
|
|
127
|
+
/**
|
|
128
|
+
* Decrypts data using AES-256-GCM.
|
|
129
|
+
*
|
|
130
|
+
* The decrypted data is JSON parsed before returning.
|
|
131
|
+
*
|
|
132
|
+
* @typeParam T - The expected type of the decrypted data
|
|
133
|
+
* @param key - The AES-GCM key (from {@link deriveSharedKey})
|
|
134
|
+
* @param payload - The encrypted payload from {@link encrypt}
|
|
135
|
+
* @returns The decrypted and parsed data
|
|
136
|
+
*
|
|
137
|
+
* @throws Error if decryption fails (wrong key or tampered ciphertext)
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const decrypted = await decrypt<{ action: string; amount: number }>(sharedKey, encrypted);
|
|
142
|
+
* console.log(decrypted.action); // 'transfer'
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function decrypt<T = unknown>(key: CryptoKey, payload: EncryptedPayload): Promise<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Hashes a shared AES key to a hex string for verification.
|
|
148
|
+
*
|
|
149
|
+
* This extracts the raw key material and hashes it with SHA-256,
|
|
150
|
+
* returning the first 16 bytes as a hex string.
|
|
151
|
+
*
|
|
152
|
+
* @param sharedKey - The AES-GCM shared key (must be extractable)
|
|
153
|
+
* @returns A hex string representation of the hash
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* const hash = await hashSharedSecret(sharedKey);
|
|
158
|
+
* const emoji = hashToEmoji(hash);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function hashSharedSecret(sharedKey: CryptoKey): Promise<string>;
|
|
162
|
+
/**
|
|
163
|
+
* Converts a hex hash to an emoji sequence for visual verification.
|
|
164
|
+
*
|
|
165
|
+
* This is used for anti-MITM verification - both the dApp and wallet
|
|
166
|
+
* independently compute the same emoji sequence from the shared secret.
|
|
167
|
+
* Users can visually compare the sequences to detect interception.
|
|
168
|
+
*
|
|
169
|
+
* Similar to SAS (Short Authentication String) in ZRTP/Signal.
|
|
170
|
+
*
|
|
171
|
+
* @param hash - Hex string from {@link hashSharedSecret}
|
|
172
|
+
* @param length - Number of emojis to generate (default: 4)
|
|
173
|
+
* @returns A string of emojis representing the hash
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const hash = await hashSharedSecret(sharedKey);
|
|
178
|
+
* const emoji = hashToEmoji(hash); // e.g., "🔵🦋🎯🐼"
|
|
179
|
+
* // Display to user for verification
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function hashToEmoji(hash: string, length?: number): string;
|
|
183
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3J5cHRvLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY3J5cHRvLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQW1DQTs7OztHQUlHO0FBQ0gsTUFBTSxXQUFXLGlCQUFpQjtJQUNoQyxnREFBZ0Q7SUFDaEQsR0FBRyxFQUFFLE1BQU0sQ0FBQztJQUNaLGtDQUFrQztJQUNsQyxHQUFHLEVBQUUsTUFBTSxDQUFDO0lBQ1osdUNBQXVDO0lBQ3ZDLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDVix1Q0FBdUM7SUFDdkMsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUNYO0FBRUQ7Ozs7R0FJRztBQUNILE1BQU0sV0FBVyxnQkFBZ0I7SUFDL0IsdURBQXVEO0lBQ3ZELEVBQUUsRUFBRSxNQUFNLENBQUM7SUFDWCxrQ0FBa0M7SUFDbEMsVUFBVSxFQUFFLE1BQU0sQ0FBQztDQUNwQjtBQUVEOzs7OztHQUtHO0FBQ0gsTUFBTSxXQUFXLGFBQWE7SUFDNUIsaUNBQWlDO0lBQ2pDLFNBQVMsRUFBRSxTQUFTLENBQUM7SUFDckIseURBQXlEO0lBQ3pELFVBQVUsRUFBRSxTQUFTLENBQUM7Q0FDdkI7QUFFRDs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHdCQUFzQixlQUFlLElBQUksT0FBTyxDQUFDLGFBQWEsQ0FBQyxDQWE5RDtBQUVEOzs7Ozs7Ozs7Ozs7Ozs7R0FlRztBQUNILHdCQUFzQixlQUFlLENBQUMsU0FBUyxFQUFFLFNBQVMsR0FBRyxP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CAQhG;AAoED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAO5E;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM,CAMpE"}
|
package/dest/crypto.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic utilities for secure wallet communication.
|
|
3
|
+
*
|
|
4
|
+
* This module provides ECDH key exchange and AES-GCM encryption primitives
|
|
5
|
+
* for establishing secure communication channels between dApps and wallet extensions.
|
|
6
|
+
*
|
|
7
|
+
* The crypto flow:
|
|
8
|
+
* 1. Both parties generate ECDH key pairs using {@link generateKeyPair}
|
|
9
|
+
* 2. Public keys are exchanged (exported via {@link exportPublicKey}, imported via {@link importPublicKey})
|
|
10
|
+
* 3. Both parties derive the same shared secret using {@link deriveSharedKey}
|
|
11
|
+
* 4. Messages are encrypted/decrypted using {@link encrypt} and {@link decrypt}
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Party A
|
|
16
|
+
* const keyPairA = await generateKeyPair();
|
|
17
|
+
* const publicKeyA = await exportPublicKey(keyPairA.publicKey);
|
|
18
|
+
*
|
|
19
|
+
* // Party B
|
|
20
|
+
* const keyPairB = await generateKeyPair();
|
|
21
|
+
* const publicKeyB = await exportPublicKey(keyPairB.publicKey);
|
|
22
|
+
*
|
|
23
|
+
* // Exchange public keys, then derive shared secret
|
|
24
|
+
* const importedB = await importPublicKey(publicKeyB);
|
|
25
|
+
* const sharedKeyA = await deriveSharedKey(keyPairA.privateKey, importedB);
|
|
26
|
+
*
|
|
27
|
+
* // Encrypt and decrypt
|
|
28
|
+
* const encrypted = await encrypt(sharedKeyA, { message: 'hello' });
|
|
29
|
+
* const decrypted = await decrypt(sharedKeyB, encrypted);
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @packageDocumentation
|
|
33
|
+
*/ import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
34
|
+
/**
|
|
35
|
+
* Generates an ECDH P-256 key pair for key exchange.
|
|
36
|
+
*
|
|
37
|
+
* The generated key pair can be used to derive a shared secret with another
|
|
38
|
+
* party's public key using {@link deriveSharedKey}.
|
|
39
|
+
*
|
|
40
|
+
* @returns A new ECDH key pair
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const keyPair = await generateKeyPair();
|
|
45
|
+
* const publicKey = await exportPublicKey(keyPair.publicKey);
|
|
46
|
+
* // Send publicKey to the other party
|
|
47
|
+
* ```
|
|
48
|
+
*/ export async function generateKeyPair() {
|
|
49
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
50
|
+
name: 'ECDH',
|
|
51
|
+
namedCurve: 'P-256'
|
|
52
|
+
}, true, [
|
|
53
|
+
'deriveKey'
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
publicKey: keyPair.publicKey,
|
|
57
|
+
privateKey: keyPair.privateKey
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Exports a public key to JWK format for transmission.
|
|
62
|
+
*
|
|
63
|
+
* The exported key contains only public components and is safe to transmit
|
|
64
|
+
* over untrusted channels.
|
|
65
|
+
*
|
|
66
|
+
* @param publicKey - The CryptoKey public key to export
|
|
67
|
+
* @returns The public key in JWK format
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const keyPair = await generateKeyPair();
|
|
72
|
+
* const exported = await exportPublicKey(keyPair.publicKey);
|
|
73
|
+
* // exported can be JSON serialized and sent to another party
|
|
74
|
+
* ```
|
|
75
|
+
*/ export async function exportPublicKey(publicKey) {
|
|
76
|
+
const jwk = await crypto.subtle.exportKey('jwk', publicKey);
|
|
77
|
+
return {
|
|
78
|
+
kty: jwk.kty,
|
|
79
|
+
crv: jwk.crv,
|
|
80
|
+
x: jwk.x,
|
|
81
|
+
y: jwk.y
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Imports a public key from JWK format.
|
|
86
|
+
*
|
|
87
|
+
* Used to import the other party's public key for deriving a shared secret.
|
|
88
|
+
*
|
|
89
|
+
* @param exported - The public key in JWK format
|
|
90
|
+
* @returns A CryptoKey that can be used with {@link deriveSharedKey}
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Receive exported public key from other party
|
|
95
|
+
* const theirPublicKey = await importPublicKey(receivedPublicKey);
|
|
96
|
+
* const sharedKey = await deriveSharedKey(myPrivateKey, theirPublicKey);
|
|
97
|
+
* ```
|
|
98
|
+
*/ export function importPublicKey(exported) {
|
|
99
|
+
return crypto.subtle.importKey('jwk', {
|
|
100
|
+
kty: exported.kty,
|
|
101
|
+
crv: exported.crv,
|
|
102
|
+
x: exported.x,
|
|
103
|
+
y: exported.y
|
|
104
|
+
}, {
|
|
105
|
+
name: 'ECDH',
|
|
106
|
+
namedCurve: 'P-256'
|
|
107
|
+
}, false, []);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Derives a shared AES-256-GCM key from ECDH key exchange.
|
|
111
|
+
*
|
|
112
|
+
* Both parties will derive the same shared key when using their own private key
|
|
113
|
+
* and the other party's public key. This is the core of ECDH key agreement.
|
|
114
|
+
*
|
|
115
|
+
* @param privateKey - Your ECDH private key
|
|
116
|
+
* @param publicKey - The other party's ECDH public key
|
|
117
|
+
* @returns An AES-256-GCM key for encryption/decryption
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Both parties derive the same key
|
|
122
|
+
* const sharedKeyA = await deriveSharedKey(privateKeyA, publicKeyB);
|
|
123
|
+
* const sharedKeyB = await deriveSharedKey(privateKeyB, publicKeyA);
|
|
124
|
+
* // sharedKeyA and sharedKeyB are equivalent
|
|
125
|
+
* ```
|
|
126
|
+
*/ export function deriveSharedKey(privateKey, publicKey) {
|
|
127
|
+
return crypto.subtle.deriveKey({
|
|
128
|
+
name: 'ECDH',
|
|
129
|
+
public: publicKey
|
|
130
|
+
}, privateKey, {
|
|
131
|
+
name: 'AES-GCM',
|
|
132
|
+
length: 256
|
|
133
|
+
}, true, [
|
|
134
|
+
'encrypt',
|
|
135
|
+
'decrypt'
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Encrypts data using AES-256-GCM.
|
|
140
|
+
*
|
|
141
|
+
* The data is JSON serialized before encryption. A random 12-byte IV is
|
|
142
|
+
* generated for each encryption operation.
|
|
143
|
+
*
|
|
144
|
+
* AES-GCM provides both confidentiality and authenticity - any tampering
|
|
145
|
+
* with the ciphertext will cause decryption to fail.
|
|
146
|
+
*
|
|
147
|
+
* @param key - The AES-GCM key (from {@link deriveSharedKey})
|
|
148
|
+
* @param data - The data to encrypt (will be JSON serialized)
|
|
149
|
+
* @returns The encrypted payload with IV and ciphertext
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const encrypted = await encrypt(sharedKey, { action: 'transfer', amount: 100 });
|
|
154
|
+
* // encrypted.iv and encrypted.ciphertext are base64 strings
|
|
155
|
+
* ```
|
|
156
|
+
*/ export async function encrypt(key, data) {
|
|
157
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
158
|
+
const encoded = new TextEncoder().encode(jsonStringify(data));
|
|
159
|
+
const ciphertext = await crypto.subtle.encrypt({
|
|
160
|
+
name: 'AES-GCM',
|
|
161
|
+
iv
|
|
162
|
+
}, key, encoded);
|
|
163
|
+
return {
|
|
164
|
+
iv: arrayBufferToBase64(iv),
|
|
165
|
+
ciphertext: arrayBufferToBase64(ciphertext)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Decrypts data using AES-256-GCM.
|
|
170
|
+
*
|
|
171
|
+
* The decrypted data is JSON parsed before returning.
|
|
172
|
+
*
|
|
173
|
+
* @typeParam T - The expected type of the decrypted data
|
|
174
|
+
* @param key - The AES-GCM key (from {@link deriveSharedKey})
|
|
175
|
+
* @param payload - The encrypted payload from {@link encrypt}
|
|
176
|
+
* @returns The decrypted and parsed data
|
|
177
|
+
*
|
|
178
|
+
* @throws Error if decryption fails (wrong key or tampered ciphertext)
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const decrypted = await decrypt<{ action: string; amount: number }>(sharedKey, encrypted);
|
|
183
|
+
* console.log(decrypted.action); // 'transfer'
|
|
184
|
+
* ```
|
|
185
|
+
*/ export async function decrypt(key, payload) {
|
|
186
|
+
const iv = base64ToArrayBuffer(payload.iv);
|
|
187
|
+
const ciphertext = base64ToArrayBuffer(payload.ciphertext);
|
|
188
|
+
const decrypted = await crypto.subtle.decrypt({
|
|
189
|
+
name: 'AES-GCM',
|
|
190
|
+
iv
|
|
191
|
+
}, key, ciphertext);
|
|
192
|
+
const decoded = new TextDecoder().decode(decrypted);
|
|
193
|
+
return JSON.parse(decoded);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Converts ArrayBuffer to base64 string.
|
|
197
|
+
* @internal
|
|
198
|
+
*/ function arrayBufferToBase64(buffer) {
|
|
199
|
+
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
200
|
+
let binary = '';
|
|
201
|
+
for(let i = 0; i < bytes.byteLength; i++){
|
|
202
|
+
binary += String.fromCharCode(bytes[i]);
|
|
203
|
+
}
|
|
204
|
+
return btoa(binary);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Converts base64 string to ArrayBuffer.
|
|
208
|
+
* @internal
|
|
209
|
+
*/ function base64ToArrayBuffer(base64) {
|
|
210
|
+
const binary = atob(base64);
|
|
211
|
+
const bytes = new Uint8Array(binary.length);
|
|
212
|
+
for(let i = 0; i < binary.length; i++){
|
|
213
|
+
bytes[i] = binary.charCodeAt(i);
|
|
214
|
+
}
|
|
215
|
+
return bytes.buffer;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Emoji alphabet for visual verification of shared secrets.
|
|
219
|
+
* 32 distinct, easily recognizable emojis for anti-spoofing verification.
|
|
220
|
+
* @internal
|
|
221
|
+
*/ const EMOJI_ALPHABET = [
|
|
222
|
+
'🔵',
|
|
223
|
+
'🟢',
|
|
224
|
+
'🔴',
|
|
225
|
+
'🟡',
|
|
226
|
+
'🟣',
|
|
227
|
+
'🟠',
|
|
228
|
+
'⚫',
|
|
229
|
+
'⚪',
|
|
230
|
+
'🌟',
|
|
231
|
+
'🌙',
|
|
232
|
+
'☀️',
|
|
233
|
+
'🌈',
|
|
234
|
+
'🔥',
|
|
235
|
+
'💧',
|
|
236
|
+
'🌸',
|
|
237
|
+
'🍀',
|
|
238
|
+
'🦋',
|
|
239
|
+
'🐬',
|
|
240
|
+
'🦊',
|
|
241
|
+
'🐼',
|
|
242
|
+
'🦁',
|
|
243
|
+
'🐯',
|
|
244
|
+
'🐸',
|
|
245
|
+
'🦉',
|
|
246
|
+
'🎵',
|
|
247
|
+
'🎨',
|
|
248
|
+
'🎯',
|
|
249
|
+
'🎲',
|
|
250
|
+
'🔔',
|
|
251
|
+
'💎',
|
|
252
|
+
'🔑',
|
|
253
|
+
'🏆'
|
|
254
|
+
];
|
|
255
|
+
/**
|
|
256
|
+
* Hashes a shared AES key to a hex string for verification.
|
|
257
|
+
*
|
|
258
|
+
* This extracts the raw key material and hashes it with SHA-256,
|
|
259
|
+
* returning the first 16 bytes as a hex string.
|
|
260
|
+
*
|
|
261
|
+
* @param sharedKey - The AES-GCM shared key (must be extractable)
|
|
262
|
+
* @returns A hex string representation of the hash
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* const hash = await hashSharedSecret(sharedKey);
|
|
267
|
+
* const emoji = hashToEmoji(hash);
|
|
268
|
+
* ```
|
|
269
|
+
*/ export async function hashSharedSecret(sharedKey) {
|
|
270
|
+
const rawKey = await crypto.subtle.exportKey('raw', sharedKey);
|
|
271
|
+
const hash = await crypto.subtle.digest('SHA-256', rawKey);
|
|
272
|
+
const bytes = new Uint8Array(hash.slice(0, 16));
|
|
273
|
+
return Array.from(bytes).map((b)=>b.toString(16).padStart(2, '0')).join('');
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Converts a hex hash to an emoji sequence for visual verification.
|
|
277
|
+
*
|
|
278
|
+
* This is used for anti-MITM verification - both the dApp and wallet
|
|
279
|
+
* independently compute the same emoji sequence from the shared secret.
|
|
280
|
+
* Users can visually compare the sequences to detect interception.
|
|
281
|
+
*
|
|
282
|
+
* Similar to SAS (Short Authentication String) in ZRTP/Signal.
|
|
283
|
+
*
|
|
284
|
+
* @param hash - Hex string from {@link hashSharedSecret}
|
|
285
|
+
* @param length - Number of emojis to generate (default: 4)
|
|
286
|
+
* @returns A string of emojis representing the hash
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const hash = await hashSharedSecret(sharedKey);
|
|
291
|
+
* const emoji = hashToEmoji(hash); // e.g., "🔵🦋🎯🐼"
|
|
292
|
+
* // Display to user for verification
|
|
293
|
+
* ```
|
|
294
|
+
*/ export function hashToEmoji(hash, length = 4) {
|
|
295
|
+
const bytes = [];
|
|
296
|
+
for(let i = 0; i < hash.length && bytes.length < length; i += 2){
|
|
297
|
+
bytes.push(parseInt(hash.slice(i, i + 2), 16));
|
|
298
|
+
}
|
|
299
|
+
return bytes.map((b)=>EMOJI_ALPHABET[b % EMOJI_ALPHABET.length]).join('');
|
|
300
|
+
}
|
package/dest/manager/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { WalletManager } from './wallet_manager.js';
|
|
2
|
-
export type { WalletManagerConfig, ExtensionWalletConfig, WebWalletConfig, WalletProviderType, WalletProvider, DiscoverWalletsOptions, } from './types.js';
|
|
3
|
-
export
|
|
2
|
+
export type { WalletManagerConfig, ExtensionWalletConfig, WebWalletConfig, WalletProviderType, WalletProvider, ProviderDisconnectionCallback, DiscoverWalletsOptions, } from './types.js';
|
|
3
|
+
export { WalletMessageType } from '../types.js';
|
|
4
|
+
export type { WalletInfo, WalletMessage, WalletResponse, DiscoveryRequest, DiscoveryResponse } from '../types.js';
|
|
4
5
|
export { ChainInfoSchema } from '@aztec/aztec.js/account';
|
|
5
6
|
export type { ChainInfo } from '@aztec/aztec.js/account';
|
|
6
7
|
export { WalletSchema } from '@aztec/aztec.js/wallet';
|
|
7
8
|
export { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUNwRCxZQUFZLEVBQ1YsbUJBQW1CLEVBQ25CLHFCQUFxQixFQUNyQixlQUFlLEVBQ2Ysa0JBQWtCLEVBQ2xCLGNBQWMsRUFDZCw2QkFBNkIsRUFDN0Isc0JBQXNCLEdBQ3ZCLE1BQU0sWUFBWSxDQUFDO0FBR3BCLE9BQU8sRUFBRSxpQkFBaUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUNoRCxZQUFZLEVBQUUsVUFBVSxFQUFFLGFBQWEsRUFBRSxjQUFjLEVBQUUsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFHbEgsT0FBTyxFQUFFLGVBQWUsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQzFELFlBQVksRUFBRSxTQUFTLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUN6RCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDdEQsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLDRCQUE0QixDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAGpB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGlH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dest/manager/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { WalletManager } from './wallet_manager.js';
|
|
2
|
+
// Re-export types and enums from providers for convenience
|
|
3
|
+
export { WalletMessageType } from '../types.js';
|
|
2
4
|
// Re-export commonly needed utilities for wallet integration
|
|
3
5
|
export { ChainInfoSchema } from '@aztec/aztec.js/account';
|
|
4
6
|
export { WalletSchema } from '@aztec/aztec.js/wallet';
|
package/dest/manager/types.d.ts
CHANGED
|
@@ -31,6 +31,10 @@ export interface WalletManagerConfig {
|
|
|
31
31
|
* Type of wallet provider
|
|
32
32
|
*/
|
|
33
33
|
export type WalletProviderType = 'extension' | 'web' | 'embedded';
|
|
34
|
+
/**
|
|
35
|
+
* Callback type for wallet disconnect events at the provider level.
|
|
36
|
+
*/
|
|
37
|
+
export type ProviderDisconnectionCallback = () => void;
|
|
34
38
|
/**
|
|
35
39
|
* A wallet provider that can connect to create a wallet instance.
|
|
36
40
|
* Chain information is already baked in from the discovery process.
|
|
@@ -51,6 +55,23 @@ export interface WalletProvider {
|
|
|
51
55
|
* @param appId - Application identifier for the requesting dapp
|
|
52
56
|
*/
|
|
53
57
|
connect(appId: string): Promise<Wallet>;
|
|
58
|
+
/**
|
|
59
|
+
* Disconnects the current wallet and cleans up resources.
|
|
60
|
+
* After calling this, the wallet returned from connect() should no longer be used.
|
|
61
|
+
* @returns A promise that resolves when disconnection is complete
|
|
62
|
+
*/
|
|
63
|
+
disconnect?(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Registers a callback to be invoked when the wallet disconnects unexpectedly.
|
|
66
|
+
* @param callback - Function to call when wallet disconnects
|
|
67
|
+
* @returns A function to unregister the callback
|
|
68
|
+
*/
|
|
69
|
+
onDisconnect?(callback: ProviderDisconnectionCallback): () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Returns whether the provider's wallet connection has been disconnected.
|
|
72
|
+
* @returns true if the wallet is no longer connected
|
|
73
|
+
*/
|
|
74
|
+
isDisconnected?(): boolean;
|
|
54
75
|
}
|
|
55
76
|
/**
|
|
56
77
|
* Options for discovering wallets
|
|
@@ -61,4 +82,4 @@ export interface DiscoverWalletsOptions {
|
|
|
61
82
|
/** Discovery timeout in milliseconds */
|
|
62
83
|
timeout?: number;
|
|
63
84
|
}
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
85
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ3pELE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRXJEOztHQUVHO0FBQ0gsTUFBTSxXQUFXLHFCQUFxQjtJQUNwQyw0Q0FBNEM7SUFDNUMsT0FBTyxFQUFFLE9BQU8sQ0FBQztJQUNqQix5REFBeUQ7SUFDekQsU0FBUyxDQUFDLEVBQUUsTUFBTSxFQUFFLENBQUM7SUFDckIseURBQXlEO0lBQ3pELFNBQVMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxDQUFDO0NBQ3RCO0FBRUQ7O0dBRUc7QUFDSCxNQUFNLFdBQVcsZUFBZTtJQUM5QixrQ0FBa0M7SUFDbEMsSUFBSSxFQUFFLE1BQU0sRUFBRSxDQUFDO0NBQ2hCO0FBRUQ7O0dBRUc7QUFDSCxNQUFNLFdBQVcsbUJBQW1CO0lBQ2xDLHFDQUFxQztJQUNyQyxVQUFVLENBQUMsRUFBRSxxQkFBcUIsQ0FBQztJQUNuQywrQkFBK0I7SUFDL0IsVUFBVSxDQUFDLEVBQUUsZUFBZSxDQUFDO0NBQzlCO0FBRUQ7O0dBRUc7QUFDSCxNQUFNLE1BQU0sa0JBQWtCLEdBQUcsV0FBVyxHQUFHLEtBQUssR0FBRyxVQUFVLENBQUM7QUFFbEU7O0dBRUc7QUFDS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CAAC;CAClB"}
|
|
@@ -24,4 +24,4 @@ export declare class WalletManager {
|
|
|
24
24
|
*/
|
|
25
25
|
private isExtensionAllowed;
|
|
26
26
|
}
|
|
27
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2FsbGV0X21hbmFnZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYW5hZ2VyL3dhbGxldF9tYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUNWLHNCQUFzQixFQUd0QixtQkFBbUIsRUFDbkIsY0FBYyxFQUNmLE1BQU0sWUFBWSxDQUFDO0FBRXBCOztHQUVHO0FBQ0gscUJBQWEsYUFBYTtJQUN4QixPQUFPLENBQUMsTUFBTSxDQUdaO0lBRUYsT0FBTyxlQUFpQjtJQUV4Qjs7O09BR0c7SUFDSCxNQUFNLENBQUMsU0FBUyxDQUFDLE1BQU0sRUFBRSxtQkFBbUIsR0FBRyxhQUFhLENBTzNEO0lBRUQ7Ozs7O09BS0c7SUFDRyxtQkFBbUIsQ0FBQyxPQUFPLEVBQUUsc0JBQXNCLEdBQUcsT0FBTyxDQUFDLGNBQWMsRUFBRSxDQUFDLENBdURwRjtJQUVEOzs7O09BSUc7SUFDSCxPQUFPLENBQUMsa0JBQWtCO0NBVzNCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"wallet_manager.d.ts","sourceRoot":"","sources":["../../src/manager/wallet_manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EAGtB,mBAAmB,EACnB,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAGZ;IAEF,OAAO,eAAiB;IAExB;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAO3D;IAED;;;;;OAKG;IACG,mBAAmB,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAuDpF;IAED;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;CAW3B"}
|
|
@@ -34,25 +34,47 @@ import { ExtensionProvider, ExtensionWallet } from '../providers/extension/index
|
|
|
34
34
|
*/ async getAvailableWallets(options) {
|
|
35
35
|
const providers = [];
|
|
36
36
|
const { chainInfo } = options;
|
|
37
|
-
// Discover extension wallets
|
|
38
37
|
if (this.config.extensions?.enabled) {
|
|
39
|
-
const
|
|
38
|
+
const discoveredWallets = await ExtensionProvider.discoverExtensions(chainInfo, options.timeout);
|
|
40
39
|
const extensionConfig = this.config.extensions;
|
|
41
|
-
for (const
|
|
42
|
-
|
|
43
|
-
if (!this.isExtensionAllowed(ext.id, extensionConfig)) {
|
|
40
|
+
for (const { info, port, sharedKey } of discoveredWallets){
|
|
41
|
+
if (!this.isExtensionAllowed(info.id, extensionConfig)) {
|
|
44
42
|
continue;
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
let extensionWallet = null;
|
|
45
|
+
const provider = {
|
|
46
|
+
id: info.id,
|
|
48
47
|
type: 'extension',
|
|
49
|
-
name:
|
|
50
|
-
icon:
|
|
48
|
+
name: info.name,
|
|
49
|
+
icon: info.icon,
|
|
51
50
|
metadata: {
|
|
52
|
-
version:
|
|
51
|
+
version: info.version,
|
|
52
|
+
verificationHash: info.verificationHash
|
|
53
53
|
},
|
|
54
|
-
connect: (appId)=>
|
|
55
|
-
|
|
54
|
+
connect: (appId)=>{
|
|
55
|
+
extensionWallet = ExtensionWallet.create(info, chainInfo, port, sharedKey, appId);
|
|
56
|
+
return Promise.resolve(extensionWallet.getWallet());
|
|
57
|
+
},
|
|
58
|
+
disconnect: async ()=>{
|
|
59
|
+
if (extensionWallet) {
|
|
60
|
+
await extensionWallet.disconnect();
|
|
61
|
+
extensionWallet = null;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
onDisconnect: (callback)=>{
|
|
65
|
+
if (extensionWallet) {
|
|
66
|
+
return extensionWallet.onDisconnect(callback);
|
|
67
|
+
}
|
|
68
|
+
return ()=>{};
|
|
69
|
+
},
|
|
70
|
+
isDisconnected: ()=>{
|
|
71
|
+
if (extensionWallet) {
|
|
72
|
+
return extensionWallet.isDisconnected();
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
providers.push(provider);
|
|
56
78
|
}
|
|
57
79
|
}
|
|
58
80
|
// TODO: Add web wallet discovery when implemented
|
|
@@ -63,15 +85,12 @@ import { ExtensionProvider, ExtensionWallet } from '../providers/extension/index
|
|
|
63
85
|
* @param extensionId - The extension ID to check
|
|
64
86
|
* @param config - Extension wallet configuration containing allow/block lists
|
|
65
87
|
*/ isExtensionAllowed(extensionId, config) {
|
|
66
|
-
// Check block list first
|
|
67
88
|
if (config.blockList && config.blockList.includes(extensionId)) {
|
|
68
89
|
return false;
|
|
69
90
|
}
|
|
70
|
-
// If allow list exists, extension must be in it
|
|
71
91
|
if (config.allowList && config.allowList.length > 0) {
|
|
72
92
|
return config.allowList.includes(extensionId);
|
|
73
93
|
}
|
|
74
|
-
// If no allow list, extension is allowed (unless blocked)
|
|
75
94
|
return true;
|
|
76
95
|
}
|
|
77
96
|
}
|