@walletmesh/aztec-rpc-wallet 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/aztecRemoteWallet.d.ts +7 -6
- package/dist/aztecRemoteWallet.d.ts.map +1 -1
- package/dist/aztecRemoteWallet.js +15 -9
- package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
- package/dist/handlers/aztecAccountWallet.js +22 -22
- package/dist/serializers/account.d.ts +4 -7
- package/dist/serializers/account.d.ts.map +1 -1
- package/dist/serializers/account.js +28 -29
- package/dist/serializers/contract.d.ts +4 -56
- package/dist/serializers/contract.d.ts.map +1 -1
- package/dist/serializers/contract.js +62 -148
- package/dist/serializers/index.d.ts +1 -4
- package/dist/serializers/index.d.ts.map +1 -1
- package/dist/serializers/index.js +12 -12
- package/dist/serializers/log.d.ts +36 -83
- package/dist/serializers/log.d.ts.map +1 -1
- package/dist/serializers/log.js +96 -107
- package/dist/serializers/note.d.ts +14 -17
- package/dist/serializers/note.d.ts.map +1 -1
- package/dist/serializers/note.js +52 -29
- package/dist/serializers/transaction-utils.d.ts +44 -100
- package/dist/serializers/transaction-utils.d.ts.map +1 -1
- package/dist/serializers/transaction-utils.js +82 -118
- package/dist/serializers/transaction.d.ts +3 -6
- package/dist/serializers/transaction.d.ts.map +1 -1
- package/dist/serializers/transaction.js +39 -50
- package/dist/types.d.ts +8 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +5 -5
- package/src/aztecRemoteWallet.test.ts +33 -29
- package/src/aztecRemoteWallet.ts +25 -14
- package/src/handlers/aztecAccountWallet.test.ts +78 -75
- package/src/handlers/aztecAccountWallet.ts +32 -35
- package/src/serializers/account.test.ts +18 -17
- package/src/serializers/account.ts +31 -49
- package/src/serializers/contract.test.ts +14 -16
- package/src/serializers/contract.ts +75 -164
- package/src/serializers/index.test.ts +20 -8
- package/src/serializers/index.ts +16 -20
- package/src/serializers/log.test.ts +201 -28
- package/src/serializers/log.ts +153 -146
- package/src/serializers/note.test.ts +26 -28
- package/src/serializers/note.ts +60 -36
- package/src/serializers/transaction-utils.ts +135 -211
- package/src/serializers/transaction.test.ts +190 -30
- package/src/serializers/transaction.ts +51 -72
- package/src/types.ts +9 -8
- package/vitest.config.ts +1 -1
- package/dist/serializers/contract-utils.d.ts +0 -40
- package/dist/serializers/contract-utils.d.ts.map +0 -1
- package/dist/serializers/contract-utils.js +0 -102
- package/dist/serializers/core.d.ts +0 -110
- package/dist/serializers/core.d.ts.map +0 -1
- package/dist/serializers/core.js +0 -130
- package/dist/serializers/types.d.ts +0 -49
- package/dist/serializers/types.d.ts.map +0 -1
- package/dist/serializers/types.js +0 -22
- package/src/serializers/contract-utils.ts +0 -104
- package/src/serializers/core.test.ts +0 -56
- package/src/serializers/core.ts +0 -141
- package/src/serializers/types.ts +0 -58
package/src/serializers/core.ts
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
import { Fr, AztecAddress, CompleteAddress, AuthWitness, TxHash } from '@aztec/aztec.js';
|
2
|
-
import { encodeBase64, decodeBase64 } from './types.js';
|
3
|
-
import type { TypeSerializer } from './types.js';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Serializer for Fr (field element) values in the Aztec protocol.
|
7
|
-
* Handles conversion of field elements to/from base64-encoded strings for RPC transport.
|
8
|
-
* Field elements are fundamental to Aztec's cryptographic operations.
|
9
|
-
*/
|
10
|
-
export class FrSerializer implements TypeSerializer<Fr> {
|
11
|
-
/**
|
12
|
-
* Converts an Fr value to a base64-encoded string.
|
13
|
-
* @param value - The field element to serialize
|
14
|
-
* @returns Base64-encoded string representation
|
15
|
-
*/
|
16
|
-
serialize(value: Fr): string {
|
17
|
-
return encodeBase64(value.toString());
|
18
|
-
}
|
19
|
-
|
20
|
-
/**
|
21
|
-
* Reconstructs an Fr value from a base64-encoded string.
|
22
|
-
* @param data - The base64-encoded string to deserialize
|
23
|
-
* @returns Reconstructed field element
|
24
|
-
* @throws If the input string is not a valid field element representation
|
25
|
-
*/
|
26
|
-
deserialize(data: string): Fr {
|
27
|
-
return Fr.fromHexString(decodeBase64(data));
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* Serializer for Aztec protocol addresses.
|
33
|
-
* Handles conversion of AztecAddress instances to/from base64-encoded strings.
|
34
|
-
* Aztec addresses represent accounts and contracts in the protocol.
|
35
|
-
*/
|
36
|
-
export class AztecAddressSerializer implements TypeSerializer<AztecAddress> {
|
37
|
-
/**
|
38
|
-
* Converts an AztecAddress to a base64-encoded string.
|
39
|
-
* @param value - The Aztec address to serialize
|
40
|
-
* @returns Base64-encoded string representation
|
41
|
-
*/
|
42
|
-
serialize(value: AztecAddress): string {
|
43
|
-
return encodeBase64(value.toString());
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Reconstructs an AztecAddress from a base64-encoded string.
|
48
|
-
* @param data - The base64-encoded string to deserialize
|
49
|
-
* @returns Reconstructed Aztec address
|
50
|
-
* @throws If the input string is not a valid address representation
|
51
|
-
*/
|
52
|
-
deserialize(data: string): AztecAddress {
|
53
|
-
return AztecAddress.fromString(decodeBase64(data));
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
/**
|
58
|
-
* Serializer for complete Aztec addresses that include additional metadata.
|
59
|
-
* CompleteAddress extends AztecAddress with extra information needed for certain operations.
|
60
|
-
*/
|
61
|
-
export class CompleteAddressSerializer implements TypeSerializer<CompleteAddress> {
|
62
|
-
/**
|
63
|
-
* Converts a CompleteAddress to a base64-encoded string.
|
64
|
-
* @param value - The complete address to serialize
|
65
|
-
* @returns Base64-encoded string representation
|
66
|
-
*/
|
67
|
-
serialize(value: CompleteAddress): string {
|
68
|
-
return encodeBase64(value.toString());
|
69
|
-
}
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Reconstructs a CompleteAddress from a base64-encoded string.
|
73
|
-
* @param data - The base64-encoded string to deserialize
|
74
|
-
* @returns Reconstructed complete address
|
75
|
-
* @throws If the input string is not a valid complete address representation
|
76
|
-
*/
|
77
|
-
deserialize(data: string): CompleteAddress {
|
78
|
-
return CompleteAddress.fromString(decodeBase64(data));
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Serializer for authentication witnesses in the Aztec protocol.
|
84
|
-
* AuthWitness values are used to prove transaction authorization.
|
85
|
-
*/
|
86
|
-
export class AuthWitnessSerializer implements TypeSerializer<AuthWitness> {
|
87
|
-
/**
|
88
|
-
* Converts an AuthWitness to a base64-encoded string.
|
89
|
-
* @param value - The authentication witness to serialize
|
90
|
-
* @returns Base64-encoded string representation
|
91
|
-
*/
|
92
|
-
serialize(value: AuthWitness): string {
|
93
|
-
return encodeBase64(value.toString());
|
94
|
-
}
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Reconstructs an AuthWitness from a base64-encoded string.
|
98
|
-
* @param data - The base64-encoded string to deserialize
|
99
|
-
* @returns Reconstructed authentication witness
|
100
|
-
* @throws If the input string is not a valid auth witness representation
|
101
|
-
*/
|
102
|
-
deserialize(data: string): AuthWitness {
|
103
|
-
return AuthWitness.fromString(decodeBase64(data));
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
/**
|
108
|
-
* Serializer for transaction hashes in the Aztec protocol.
|
109
|
-
* TxHash values uniquely identify transactions and are used for lookups and references.
|
110
|
-
*/
|
111
|
-
export class TxHashSerializer implements TypeSerializer<TxHash> {
|
112
|
-
/**
|
113
|
-
* Converts a TxHash to a base64-encoded string.
|
114
|
-
* @param value - The transaction hash to serialize
|
115
|
-
* @returns Base64-encoded string representation
|
116
|
-
*/
|
117
|
-
serialize(value: TxHash): string {
|
118
|
-
return encodeBase64(value.toString());
|
119
|
-
}
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Reconstructs a TxHash from a base64-encoded string.
|
123
|
-
* @param data - The base64-encoded string to deserialize
|
124
|
-
* @returns Reconstructed transaction hash
|
125
|
-
* @throws If the input string is not a valid transaction hash representation
|
126
|
-
*/
|
127
|
-
deserialize(data: string): TxHash {
|
128
|
-
return TxHash.fromString(decodeBase64(data));
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
/**
|
133
|
-
* Pre-instantiated serializer instances for common Aztec types.
|
134
|
-
* These singletons should be used instead of creating new instances
|
135
|
-
* to ensure consistent serialization across the application.
|
136
|
-
*/
|
137
|
-
export const frSerializer = new FrSerializer();
|
138
|
-
export const aztecAddressSerializer = new AztecAddressSerializer();
|
139
|
-
export const completeAddressSerializer = new CompleteAddressSerializer();
|
140
|
-
export const authWitnessSerializer = new AuthWitnessSerializer();
|
141
|
-
export const txHashSerializer = new TxHashSerializer();
|
package/src/serializers/types.ts
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
import type { JSONRPCSerializedData, JSONRPCSerializer } from '@walletmesh/jsonrpc';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Base interface for type-specific serializers in the Aztec RPC wallet.
|
5
|
-
* Provides a standardized way to convert Aztec-specific types to and from string representations
|
6
|
-
* for network transmission. Each Aztec type (Fr, AztecAddress, etc.) implements this interface
|
7
|
-
* to ensure consistent serialization across the RPC layer.
|
8
|
-
*
|
9
|
-
* @typeParam T - The Aztec type being serialized (e.g., Fr, AztecAddress, TxHash)
|
10
|
-
*/
|
11
|
-
export interface TypeSerializer<T> {
|
12
|
-
/**
|
13
|
-
* Converts a value to its string representation for network transmission.
|
14
|
-
* Implementations should ensure the serialized form can be correctly deserialized
|
15
|
-
* back to the original type.
|
16
|
-
*
|
17
|
-
* @param value - The Aztec type value to serialize
|
18
|
-
* @returns A string representation suitable for network transmission
|
19
|
-
*/
|
20
|
-
serialize(value: T): string;
|
21
|
-
|
22
|
-
/**
|
23
|
-
* Reconstructs a value from its string representation.
|
24
|
-
* Implementations should validate the input string and throw appropriate errors
|
25
|
-
* if the data cannot be correctly deserialized.
|
26
|
-
*
|
27
|
-
* @param data - The string data to deserialize, previously created by serialize()
|
28
|
-
* @returns The reconstructed Aztec type value
|
29
|
-
* @throws If the data is invalid or cannot be deserialized
|
30
|
-
*/
|
31
|
-
deserialize(data: string): T;
|
32
|
-
}
|
33
|
-
|
34
|
-
// Re-export core JSON-RPC types from @walletmesh/jsonrpc
|
35
|
-
export type { JSONRPCSerializedData, JSONRPCSerializer };
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Helper function to encode data as base64 for safe network transmission.
|
39
|
-
* Used throughout the serializers to ensure consistent encoding of binary data.
|
40
|
-
*
|
41
|
-
* @param data - The string data to encode
|
42
|
-
* @returns Base64 encoded string
|
43
|
-
*/
|
44
|
-
export function encodeBase64(data: string): string {
|
45
|
-
return btoa(data);
|
46
|
-
}
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Helper function to decode base64 data back to its original form.
|
50
|
-
* Used throughout the serializers to decode data received over the network.
|
51
|
-
*
|
52
|
-
* @param data - The base64 encoded string to decode
|
53
|
-
* @returns Original decoded string
|
54
|
-
* @throws If the input is not valid base64
|
55
|
-
*/
|
56
|
-
export function decodeBase64(data: string): string {
|
57
|
-
return atob(data);
|
58
|
-
}
|