@walletmesh/aztec-rpc-wallet 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/aztecRemoteWallet.d.ts +7 -6
  5. package/dist/aztecRemoteWallet.d.ts.map +1 -1
  6. package/dist/aztecRemoteWallet.js +15 -10
  7. package/dist/chainProvider.d.ts.map +1 -1
  8. package/dist/chainProvider.js +1 -1
  9. package/dist/errors.d.ts.map +1 -1
  10. package/dist/errors.js +1 -1
  11. package/dist/handlers/aztecAccountWallet.d.ts.map +1 -1
  12. package/dist/handlers/aztecAccountWallet.js +23 -23
  13. package/dist/handlers/transactions.d.ts.map +1 -1
  14. package/dist/handlers/transactions.js +11 -3
  15. package/dist/serializers/account.d.ts +19 -22
  16. package/dist/serializers/account.d.ts.map +1 -1
  17. package/dist/serializers/account.js +44 -45
  18. package/dist/serializers/contract.d.ts +11 -63
  19. package/dist/serializers/contract.d.ts.map +1 -1
  20. package/dist/serializers/contract.js +67 -153
  21. package/dist/serializers/index.d.ts +1 -4
  22. package/dist/serializers/index.d.ts.map +1 -1
  23. package/dist/serializers/index.js +12 -12
  24. package/dist/serializers/log.d.ts +38 -85
  25. package/dist/serializers/log.d.ts.map +1 -1
  26. package/dist/serializers/log.js +106 -115
  27. package/dist/serializers/note.d.ts +24 -27
  28. package/dist/serializers/note.d.ts.map +1 -1
  29. package/dist/serializers/note.js +67 -41
  30. package/dist/serializers/transaction-utils.d.ts +44 -100
  31. package/dist/serializers/transaction-utils.d.ts.map +1 -1
  32. package/dist/serializers/transaction-utils.js +89 -116
  33. package/dist/serializers/transaction.d.ts +15 -18
  34. package/dist/serializers/transaction.d.ts.map +1 -1
  35. package/dist/serializers/transaction.js +51 -62
  36. package/dist/types.d.ts +9 -9
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/types.js +1 -1
  39. package/package.json +9 -9
  40. package/src/aztecRemoteWallet.test.ts +34 -33
  41. package/src/aztecRemoteWallet.ts +25 -15
  42. package/src/chainProvider.ts +1 -7
  43. package/src/errors.ts +0 -1
  44. package/src/handlers/aztecAccountWallet.test.ts +78 -75
  45. package/src/handlers/aztecAccountWallet.ts +33 -36
  46. package/src/handlers/transactions.ts +16 -2
  47. package/src/serializers/account.test.ts +18 -17
  48. package/src/serializers/account.ts +46 -64
  49. package/src/serializers/contract.test.ts +14 -16
  50. package/src/serializers/contract.ts +77 -171
  51. package/src/serializers/index.test.ts +20 -8
  52. package/src/serializers/index.ts +16 -32
  53. package/src/serializers/log.test.ts +201 -28
  54. package/src/serializers/log.ts +162 -153
  55. package/src/serializers/note.test.ts +26 -28
  56. package/src/serializers/note.ts +71 -48
  57. package/src/serializers/transaction-utils.ts +147 -210
  58. package/src/serializers/transaction.test.ts +190 -30
  59. package/src/serializers/transaction.ts +62 -83
  60. package/src/types.ts +10 -9
  61. package/tsconfig.json +1 -1
  62. package/vitest.config.ts +1 -1
  63. package/dist/serializers/contract-utils.d.ts +0 -40
  64. package/dist/serializers/contract-utils.d.ts.map +0 -1
  65. package/dist/serializers/contract-utils.js +0 -102
  66. package/dist/serializers/core.d.ts +0 -110
  67. package/dist/serializers/core.d.ts.map +0 -1
  68. package/dist/serializers/core.js +0 -130
  69. package/dist/serializers/types.d.ts +0 -49
  70. package/dist/serializers/types.d.ts.map +0 -1
  71. package/dist/serializers/types.js +0 -22
  72. package/src/serializers/contract-utils.ts +0 -104
  73. package/src/serializers/core.test.ts +0 -56
  74. package/src/serializers/core.ts +0 -141
  75. package/src/serializers/types.ts +0 -58
@@ -1,56 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { Fr, AztecAddress, CompleteAddress, AuthWitness, TxHash } from '@aztec/aztec.js';
3
- import {
4
- frSerializer,
5
- aztecAddressSerializer,
6
- completeAddressSerializer,
7
- authWitnessSerializer,
8
- txHashSerializer,
9
- } from './core.js';
10
-
11
- describe('Core Serializers', () => {
12
- describe('FrSerializer', () => {
13
- it('should serialize and deserialize Fr values', () => {
14
- const original = Fr.random();
15
- const serialized = frSerializer.serialize(original);
16
- const deserialized = frSerializer.deserialize(serialized);
17
- expect(deserialized.toString()).toBe(original.toString());
18
- });
19
- });
20
-
21
- describe('AztecAddressSerializer', () => {
22
- it('should serialize and deserialize AztecAddress values', () => {
23
- const original = AztecAddress.random();
24
- const serialized = aztecAddressSerializer.serialize(original);
25
- const deserialized = aztecAddressSerializer.deserialize(serialized);
26
- expect(deserialized.toString()).toBe(original.toString());
27
- });
28
- });
29
-
30
- describe('CompleteAddressSerializer', () => {
31
- it('should serialize and deserialize CompleteAddress values', () => {
32
- const original = CompleteAddress.random();
33
- const serialized = completeAddressSerializer.serialize(original);
34
- const deserialized = completeAddressSerializer.deserialize(serialized);
35
- expect(deserialized.toString()).toBe(original.toString());
36
- });
37
- });
38
-
39
- describe('AuthWitnessSerializer', () => {
40
- it('should serialize and deserialize AuthWitness values', () => {
41
- const original = AuthWitness.random();
42
- const serialized = authWitnessSerializer.serialize(original);
43
- const deserialized = authWitnessSerializer.deserialize(serialized);
44
- expect(deserialized.toString()).toBe(original.toString());
45
- });
46
- });
47
-
48
- describe('TxHashSerializer', () => {
49
- it('should serialize and deserialize TxHash values', () => {
50
- const original = TxHash.random();
51
- const serialized = txHashSerializer.serialize(original);
52
- const deserialized = txHashSerializer.deserialize(serialized);
53
- expect(deserialized.toString()).toBe(original.toString());
54
- });
55
- });
56
- });
@@ -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();
@@ -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
- }