@aztec/foundation 0.8.10 → 0.8.12
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/dest/abi/function_selector.d.ts +9 -0
- package/dest/abi/function_selector.d.ts.map +1 -1
- package/dest/abi/function_selector.js +16 -1
- package/dest/eth-address/index.d.ts +1 -1
- package/dest/eth-address/index.js +3 -3
- package/dest/fields/coordinate.d.ts +1 -1
- package/dest/fields/coordinate.js +1 -1
- package/dest/fields/point.d.ts +1 -1
- package/dest/fields/point.js +1 -1
- package/dest/fifo/bounded_serial_queue.d.ts +3 -3
- package/dest/fifo/bounded_serial_queue.js +3 -3
- package/dest/fifo/serial_queue.d.ts +1 -1
- package/dest/fifo/serial_queue.js +1 -1
- package/dest/json-rpc/convert.js +1 -1
- package/dest/running-promise/index.d.ts +2 -2
- package/dest/running-promise/index.js +3 -3
- package/dest/sleep/index.d.ts +4 -4
- package/dest/sleep/index.js +4 -4
- package/package.json +1 -1
- package/src/abi/function_selector.ts +16 -0
- package/src/eth-address/index.ts +2 -2
- package/src/fields/coordinate.ts +1 -1
- package/src/fields/point.ts +1 -1
- package/src/fifo/bounded_serial_queue.ts +3 -3
- package/src/fifo/serial_queue.ts +1 -1
- package/src/json-rpc/README.md +1 -1
- package/src/json-rpc/convert.ts +1 -1
- package/src/running-promise/index.ts +3 -3
- package/src/sleep/index.ts +4 -4
|
@@ -64,6 +64,15 @@ export declare class FunctionSelector {
|
|
|
64
64
|
* @returns A Buffer containing the 4-byte function selector.
|
|
65
65
|
*/
|
|
66
66
|
static fromNameAndParameters(name: string, parameters: ABIParameter[]): FunctionSelector;
|
|
67
|
+
/**
|
|
68
|
+
* Create an AztecAddress instance from a hex-encoded string.
|
|
69
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
|
|
70
|
+
* Throws an error if the input length is invalid or address value is out of range.
|
|
71
|
+
*
|
|
72
|
+
* @param selector - The hex-encoded string representing the Aztec address.
|
|
73
|
+
* @returns An AztecAddress instance.
|
|
74
|
+
*/
|
|
75
|
+
static fromString(selector: string): FunctionSelector;
|
|
67
76
|
/**
|
|
68
77
|
* Creates an empty function selector.
|
|
69
78
|
* @returns An empty function selector.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function_selector.d.ts","sourceRoot":"","sources":["../../src/abi/function_selector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;GAEG;AACH,qBAAa,gBAAgB;IAMyC,KAAK,EAAE,MAAM;IALjF;;OAEG;IACH,OAAc,IAAI,SAAK;gBAEX,gDAAgD,CAAQ,KAAK,EAAE,MAAM;IAMjF;;;OAGG;IACI,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO;IAIxC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,gBAAgB;IAMlE;;;;OAIG;IACI,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,gBAAgB;IAI1C;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB;IAIzD;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE;IAQrE;;;OAGG;IACH,MAAM,CAAC,KAAK,IAAI,gBAAgB;CAGjC"}
|
|
1
|
+
{"version":3,"file":"function_selector.d.ts","sourceRoot":"","sources":["../../src/abi/function_selector.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,uBAAuB,CAAC;AAG9E,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;GAEG;AACH,qBAAa,gBAAgB;IAMyC,KAAK,EAAE,MAAM;IALjF;;OAEG;IACH,OAAc,IAAI,SAAK;gBAEX,gDAAgD,CAAQ,KAAK,EAAE,MAAM;IAMjF;;;OAGG;IACI,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO;IAIxC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,gBAAgB;IAMlE;;;;OAIG;IACI,OAAO;IAId;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,gBAAgB;IAI1C;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB;IAIzD;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE;IAQrE;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM;IAQlC;;;OAGG;IACH,MAAM,CAAC,KAAK,IAAI,gBAAgB;CAGjC"}
|
|
@@ -89,6 +89,21 @@ export class FunctionSelector {
|
|
|
89
89
|
// console.log(`Function selector for ${signature} is ${selector}`);
|
|
90
90
|
return selector;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Create an AztecAddress instance from a hex-encoded string.
|
|
94
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
|
|
95
|
+
* Throws an error if the input length is invalid or address value is out of range.
|
|
96
|
+
*
|
|
97
|
+
* @param selector - The hex-encoded string representing the Aztec address.
|
|
98
|
+
* @returns An AztecAddress instance.
|
|
99
|
+
*/
|
|
100
|
+
static fromString(selector) {
|
|
101
|
+
const buf = Buffer.from(selector.replace(/^0x/i, ''), 'hex');
|
|
102
|
+
if (buf.length !== FunctionSelector.SIZE) {
|
|
103
|
+
throw new Error(`Invalid length ${buf.length}.`);
|
|
104
|
+
}
|
|
105
|
+
return FunctionSelector.fromBuffer(buf);
|
|
106
|
+
}
|
|
92
107
|
/**
|
|
93
108
|
* Creates an empty function selector.
|
|
94
109
|
* @returns An empty function selector.
|
|
@@ -101,4 +116,4 @@ export class FunctionSelector {
|
|
|
101
116
|
* The size of the function selector in bytes.
|
|
102
117
|
*/
|
|
103
118
|
FunctionSelector.SIZE = 4;
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
119
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnVuY3Rpb25fc2VsZWN0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYWJpL2Z1bmN0aW9uX3NlbGVjdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBZ0IsdUJBQXVCLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM5RSxPQUFPLEVBQUUsVUFBVSxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3pFLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNsRCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDOUMsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBRTNEOztHQUVHO0FBQ0gsTUFBTSxPQUFPLGdCQUFnQjtJQU0zQixZQ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xNQUFNLEVBQUUsRUFBRSxDQUFDLEVBQUUsS0FBSyxDQUFDLENBQUM7UUFDN0QsSUFBSSxHQUFHLENBQUMsTUFBTSxLQUFLLGdCQUFnQixDQUFDLElBQUksRUFBRTtZQUN4QyxNQUFNLElBQUksS0FBSyxDQUFDLGtCQUFrQixHQUFHLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQztTQUNsRDtRQUNELE9BQU8sZ0JBQWdCLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQzFDLENBQUM7SUFFRDs7O09BR0c7SUFDSCxNQUFNLENBQUMsS0FBSztRQUNWLE9BQU8sSUFBSSxnQkFBZ0IsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUNqQyxDQUFDOztBQXRIRDs7R0FFRztBQUNXLHFCQUFJLEdBQUcsQ0FBQyxDQUFDIn0=
|
|
@@ -132,7 +132,7 @@ export declare class EthAddress {
|
|
|
132
132
|
/**
|
|
133
133
|
* Deserializes from a buffer or reader, corresponding to a write in cpp.
|
|
134
134
|
* @param buffer - Buffer to read from.
|
|
135
|
-
* @returns The
|
|
135
|
+
* @returns The EthAddress.
|
|
136
136
|
*/
|
|
137
137
|
static fromBuffer(buffer: Buffer | BufferReader): EthAddress;
|
|
138
138
|
/**
|
|
@@ -61,7 +61,7 @@ export class EthAddress {
|
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
63
|
else if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
|
|
64
|
-
// It's ALL lowercase or ALL
|
|
64
|
+
// It's ALL lowercase or ALL uppercase.
|
|
65
65
|
return true;
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
@@ -203,7 +203,7 @@ export class EthAddress {
|
|
|
203
203
|
/**
|
|
204
204
|
* Deserializes from a buffer or reader, corresponding to a write in cpp.
|
|
205
205
|
* @param buffer - Buffer to read from.
|
|
206
|
-
* @returns The
|
|
206
|
+
* @returns The EthAddress.
|
|
207
207
|
*/
|
|
208
208
|
static fromBuffer(buffer) {
|
|
209
209
|
const reader = BufferReader.asReader(buffer);
|
|
@@ -225,4 +225,4 @@ EthAddress.SIZE_IN_BYTES = 20;
|
|
|
225
225
|
* Represents a zero Ethereum address with 20 bytes filled with zeros.
|
|
226
226
|
*/
|
|
227
227
|
EthAddress.ZERO = new EthAddress(Buffer.alloc(EthAddress.SIZE_IN_BYTES));
|
|
228
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
228
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXRoLWFkZHJlc3MvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGVBQWUsRUFBRSxXQUFXLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUNsRSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDeEMsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXJEOzs7OztHQUtHO0FBQ0gsTUFBTSxPQUFPLFVBQVU7SUFVckIsWUFBb0IsTUFBYztRQUFkLFdBQU0sR0FBTixNQUFNLENBQVE7UUFDaEMsSUFBSSxNQUFNLENBQUMsTUFBTSxLQUFLLEVBQUUsRUFBRTtZQUN4QixJQUFJLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLEVBQUUsRUFBRSxDQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFDLENBQUMsRUFBRTtnQkFDakQsTUFBTSxJQUFJLEtBQUssQ0FBQywyQkFBMkIsTUFBTSxDQUFDLFFBQVEsQ0FBQyxLQUFLLENBQUMsRUFBRSxDQUFDLENBQUM7YUFDdEU7aUJ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UFDLENBQUMsQ0FBQztJQUN4RSxDQUFDO0lBRUQ7Ozs7T0FJRztJQUNILE1BQU0sQ0FBQyxVQUFVLENBQUMsTUFBNkI7UUFDN0MsTUFBTSxNQUFNLEdBQUcsWUFBWSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUM3QyxPQUFPLElBQUksVUFBVSxDQUFDLE1BQU0sQ0FBQyxVQUFVLEVBQUUsQ0FBQyxDQUFDO0lBQzdDLENBQUM7SUFFRDs7O09BR0c7SUFDSCxjQUFjO1FBQ1osT0FBTyxJQUFJLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDekIsQ0FBQzs7QUF2T0Q7O0dBRUc7QUFDVyx3QkFBYSxHQUFHLEVBQUUsQ0FBQztBQUNqQzs7R0FFRztBQUNXLGVBQUksR0FBRyxJQUFJLFVBQVUsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDIn0=
|
|
@@ -31,7 +31,7 @@ export declare class Coordinate {
|
|
|
31
31
|
*/
|
|
32
32
|
static random(): Coordinate;
|
|
33
33
|
/**
|
|
34
|
-
* serializes the
|
|
34
|
+
* serializes the object to buffer of 2 fields.
|
|
35
35
|
* @returns A buffer serialization of the object.
|
|
36
36
|
*/
|
|
37
37
|
toFieldsBuffer(): Buffer;
|
package/dest/fields/point.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare class Point {
|
|
|
65
65
|
y: bigint;
|
|
66
66
|
};
|
|
67
67
|
/**
|
|
68
|
-
* Converts the Point instance to a Buffer
|
|
68
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
69
69
|
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
70
70
|
* @returns A Buffer representation of the Point instance.
|
|
71
71
|
*/
|
package/dest/fields/point.js
CHANGED
|
@@ -69,7 +69,7 @@ export class Point {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
* Converts the Point instance to a Buffer
|
|
72
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
73
73
|
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
74
74
|
* @returns A Buffer representation of the Point instance.
|
|
75
75
|
*/
|
|
@@ -36,8 +36,8 @@ export declare class BoundedSerialQueue {
|
|
|
36
36
|
*/
|
|
37
37
|
end(): Promise<void>;
|
|
38
38
|
/**
|
|
39
|
-
* The caller will block until fn is
|
|
40
|
-
* The fn itself is execute
|
|
39
|
+
* The caller will block until fn is successfully enqueued.
|
|
40
|
+
* The fn itself is execute asynchronously and its result discarded.
|
|
41
41
|
* TODO(AD) do we need this if we have exec()?
|
|
42
42
|
* @param fn - The function to call once unblocked.
|
|
43
43
|
*/
|
|
@@ -45,7 +45,7 @@ export declare class BoundedSerialQueue {
|
|
|
45
45
|
/**
|
|
46
46
|
* The caller will block until fn is successfully executed, and it's result returned.
|
|
47
47
|
* @param fn - The function.
|
|
48
|
-
* @returns A promise that resolves with the result once
|
|
48
|
+
* @returns A promise that resolves with the result once executed.
|
|
49
49
|
*/
|
|
50
50
|
exec<T>(fn: () => Promise<T>): Promise<T>;
|
|
51
51
|
/**
|
|
@@ -48,8 +48,8 @@ export class BoundedSerialQueue {
|
|
|
48
48
|
return this.queue.end();
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* The caller will block until fn is
|
|
52
|
-
* The fn itself is execute
|
|
51
|
+
* The caller will block until fn is successfully enqueued.
|
|
52
|
+
* The fn itself is execute asynchronously and its result discarded.
|
|
53
53
|
* TODO(AD) do we need this if we have exec()?
|
|
54
54
|
* @param fn - The function to call once unblocked.
|
|
55
55
|
*/
|
|
@@ -71,7 +71,7 @@ export class BoundedSerialQueue {
|
|
|
71
71
|
/**
|
|
72
72
|
* The caller will block until fn is successfully executed, and it's result returned.
|
|
73
73
|
* @param fn - The function.
|
|
74
|
-
* @returns A promise that resolves with the result once
|
|
74
|
+
* @returns A promise that resolves with the result once executed.
|
|
75
75
|
*/
|
|
76
76
|
async exec(fn) {
|
|
77
77
|
await this.semaphore.acquire();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A more
|
|
2
|
+
* A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
|
|
3
3
|
*/
|
|
4
4
|
export declare class SerialQueue {
|
|
5
5
|
private readonly queue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MemoryFifo } from './memory_fifo.js';
|
|
2
2
|
/**
|
|
3
|
-
* A more
|
|
3
|
+
* A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
|
|
4
4
|
*/
|
|
5
5
|
export class SerialQueue {
|
|
6
6
|
constructor() {
|
package/dest/json-rpc/convert.js
CHANGED
|
@@ -98,7 +98,7 @@ export function convertFromJsonObj(cc, obj) {
|
|
|
98
98
|
* @returns The encoded object.
|
|
99
99
|
*/
|
|
100
100
|
export function convertToJsonObj(cc, obj) {
|
|
101
|
-
// Bigint is a primitive type that needs special handling since it's not
|
|
101
|
+
// Bigint is a primitive type that needs special handling since it's not serializable
|
|
102
102
|
if (typeof obj === 'bigint') {
|
|
103
103
|
return {
|
|
104
104
|
type: 'bigint',
|
|
@@ -16,7 +16,7 @@ export declare class RunningPromise {
|
|
|
16
16
|
*/
|
|
17
17
|
start(): void;
|
|
18
18
|
/**
|
|
19
|
-
* Stops the running promise, resolves any pending
|
|
19
|
+
* Stops the running promise, resolves any pending interruptible sleep,
|
|
20
20
|
* and waits for the currently executing function to complete.
|
|
21
21
|
*/
|
|
22
22
|
stop(): Promise<void>;
|
|
@@ -25,7 +25,7 @@ export declare class RunningPromise {
|
|
|
25
25
|
* The sleep duration is determined by 'timeInMs', and it can be terminated early if the 'interruptPromise' is resolved.
|
|
26
26
|
* @param timeInMs - The time in milliseconds.
|
|
27
27
|
*/
|
|
28
|
-
private
|
|
28
|
+
private interruptibleSleep;
|
|
29
29
|
/**
|
|
30
30
|
* Checks if the running promise is currently active.
|
|
31
31
|
* @returns True if the promise is running.
|
|
@@ -21,13 +21,13 @@ export class RunningPromise {
|
|
|
21
21
|
const poll = async () => {
|
|
22
22
|
while (this.running) {
|
|
23
23
|
await this.fn();
|
|
24
|
-
await this.
|
|
24
|
+
await this.interruptibleSleep(this.pollingInterval);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
this.runningPromise = poll();
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Stops the running promise, resolves any pending
|
|
30
|
+
* Stops the running promise, resolves any pending interruptible sleep,
|
|
31
31
|
* and waits for the currently executing function to complete.
|
|
32
32
|
*/
|
|
33
33
|
async stop() {
|
|
@@ -40,7 +40,7 @@ export class RunningPromise {
|
|
|
40
40
|
* The sleep duration is determined by 'timeInMs', and it can be terminated early if the 'interruptPromise' is resolved.
|
|
41
41
|
* @param timeInMs - The time in milliseconds.
|
|
42
42
|
*/
|
|
43
|
-
async
|
|
43
|
+
async interruptibleSleep(timeInMs) {
|
|
44
44
|
let timeout;
|
|
45
45
|
const sleepPromise = new Promise(resolve => {
|
|
46
46
|
timeout = setTimeout(resolve, timeInMs);
|
package/dest/sleep/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
|
|
3
3
|
* The sleep function can be interrupted at any time by calling the `interrupt` method, which can
|
|
4
4
|
* also specify whether the sleep should throw an error or just return. This is useful when you need
|
|
5
5
|
* to terminate long-running processes or perform cleanup tasks in response to external events.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
* const sleeper = new
|
|
8
|
+
* const sleeper = new InterruptibleSleep();
|
|
9
9
|
*
|
|
10
10
|
* async function longRunningTask() \{
|
|
11
11
|
* try \{
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
20
20
|
*/
|
|
21
|
-
export declare class
|
|
21
|
+
export declare class InterruptibleSleep {
|
|
22
22
|
private interruptResolve;
|
|
23
23
|
private interruptPromise;
|
|
24
24
|
private timeouts;
|
|
@@ -43,7 +43,7 @@ export declare class InterruptableSleep {
|
|
|
43
43
|
/**
|
|
44
44
|
* Puts the current execution context to sleep for a specified duration.
|
|
45
45
|
* This simulates a blocking sleep operation by using an asynchronous function and a Promise that resolves after the given duration.
|
|
46
|
-
* The sleep function can be interrupted by the 'interrupt' method of the
|
|
46
|
+
* The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
|
|
47
47
|
*
|
|
48
48
|
* @param ms - The duration in milliseconds for which the sleep operation should last.
|
|
49
49
|
* @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
|
package/dest/sleep/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InterruptError } from '../errors/index.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
|
|
4
4
|
* The sleep function can be interrupted at any time by calling the `interrupt` method, which can
|
|
5
5
|
* also specify whether the sleep should throw an error or just return. This is useful when you need
|
|
6
6
|
* to terminate long-running processes or perform cleanup tasks in response to external events.
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
-
* const sleeper = new
|
|
9
|
+
* const sleeper = new InterruptibleSleep();
|
|
10
10
|
*
|
|
11
11
|
* async function longRunningTask() \{
|
|
12
12
|
* try \{
|
|
@@ -19,7 +19,7 @@ import { InterruptError } from '../errors/index.js';
|
|
|
19
19
|
*
|
|
20
20
|
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
21
21
|
*/
|
|
22
|
-
export class
|
|
22
|
+
export class InterruptibleSleep {
|
|
23
23
|
constructor() {
|
|
24
24
|
this.interruptResolve = () => { };
|
|
25
25
|
this.interruptPromise = new Promise(resolve => (this.interruptResolve = resolve));
|
|
@@ -59,7 +59,7 @@ export class InterruptableSleep {
|
|
|
59
59
|
/**
|
|
60
60
|
* Puts the current execution context to sleep for a specified duration.
|
|
61
61
|
* This simulates a blocking sleep operation by using an asynchronous function and a Promise that resolves after the given duration.
|
|
62
|
-
* The sleep function can be interrupted by the 'interrupt' method of the
|
|
62
|
+
* The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
|
|
63
63
|
*
|
|
64
64
|
* @param ms - The duration in milliseconds for which the sleep operation should last.
|
|
65
65
|
* @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
|
package/package.json
CHANGED
|
@@ -104,6 +104,22 @@ export class FunctionSelector {
|
|
|
104
104
|
return selector;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Create an AztecAddress instance from a hex-encoded string.
|
|
109
|
+
* The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
|
|
110
|
+
* Throws an error if the input length is invalid or address value is out of range.
|
|
111
|
+
*
|
|
112
|
+
* @param selector - The hex-encoded string representing the Aztec address.
|
|
113
|
+
* @returns An AztecAddress instance.
|
|
114
|
+
*/
|
|
115
|
+
static fromString(selector: string) {
|
|
116
|
+
const buf = Buffer.from(selector.replace(/^0x/i, ''), 'hex');
|
|
117
|
+
if (buf.length !== FunctionSelector.SIZE) {
|
|
118
|
+
throw new Error(`Invalid length ${buf.length}.`);
|
|
119
|
+
}
|
|
120
|
+
return FunctionSelector.fromBuffer(buf);
|
|
121
|
+
}
|
|
122
|
+
|
|
107
123
|
/**
|
|
108
124
|
* Creates an empty function selector.
|
|
109
125
|
* @returns An empty function selector.
|
package/src/eth-address/index.ts
CHANGED
|
@@ -70,7 +70,7 @@ export class EthAddress {
|
|
|
70
70
|
// Does not have the basic requirements of an address.
|
|
71
71
|
return false;
|
|
72
72
|
} else if (/^(0x|0X)?[0-9a-f]{40}$/.test(address) || /^(0x|0X)?[0-9A-F]{40}$/.test(address)) {
|
|
73
|
-
// It's ALL lowercase or ALL
|
|
73
|
+
// It's ALL lowercase or ALL uppercase.
|
|
74
74
|
return true;
|
|
75
75
|
} else {
|
|
76
76
|
return EthAddress.checkAddressChecksum(address);
|
|
@@ -227,7 +227,7 @@ export class EthAddress {
|
|
|
227
227
|
/**
|
|
228
228
|
* Deserializes from a buffer or reader, corresponding to a write in cpp.
|
|
229
229
|
* @param buffer - Buffer to read from.
|
|
230
|
-
* @returns The
|
|
230
|
+
* @returns The EthAddress.
|
|
231
231
|
*/
|
|
232
232
|
static fromBuffer(buffer: Buffer | BufferReader): EthAddress {
|
|
233
233
|
const reader = BufferReader.asReader(buffer);
|
package/src/fields/coordinate.ts
CHANGED
package/src/fields/point.ts
CHANGED
|
@@ -78,7 +78,7 @@ export class Point {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
|
-
* Converts the Point instance to a Buffer
|
|
81
|
+
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
82
82
|
* The outputs buffer length will be 64, the length of both coordinates not represented as fields.
|
|
83
83
|
* @returns A Buffer representation of the Point instance.
|
|
84
84
|
*/
|
|
@@ -55,8 +55,8 @@ export class BoundedSerialQueue {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* The caller will block until fn is
|
|
59
|
-
* The fn itself is execute
|
|
58
|
+
* The caller will block until fn is successfully enqueued.
|
|
59
|
+
* The fn itself is execute asynchronously and its result discarded.
|
|
60
60
|
* TODO(AD) do we need this if we have exec()?
|
|
61
61
|
* @param fn - The function to call once unblocked.
|
|
62
62
|
*/
|
|
@@ -78,7 +78,7 @@ export class BoundedSerialQueue {
|
|
|
78
78
|
/**
|
|
79
79
|
* The caller will block until fn is successfully executed, and it's result returned.
|
|
80
80
|
* @param fn - The function.
|
|
81
|
-
* @returns A promise that resolves with the result once
|
|
81
|
+
* @returns A promise that resolves with the result once executed.
|
|
82
82
|
*/
|
|
83
83
|
public async exec<T>(fn: () => Promise<T>): Promise<T> {
|
|
84
84
|
await this.semaphore.acquire();
|
package/src/fifo/serial_queue.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MemoryFifo } from './memory_fifo.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A more
|
|
4
|
+
* A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
|
|
5
5
|
*/
|
|
6
6
|
export class SerialQueue {
|
|
7
7
|
private readonly queue = new MemoryFifo<() => Promise<void>>();
|
package/src/json-rpc/README.md
CHANGED
|
@@ -12,7 +12,7 @@ json-rpc
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
Each createJsonRpcClient and JsonRpcServer call needs a map of classes that will be translated in input and output values.
|
|
15
|
-
By default, Buffer is handled, but other
|
|
15
|
+
By default, Buffer is handled, but other user-made classes need to define toString() and static fromString() like so:
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
class PublicKey {
|
package/src/json-rpc/convert.ts
CHANGED
|
@@ -117,7 +117,7 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any {
|
|
|
117
117
|
* @returns The encoded object.
|
|
118
118
|
*/
|
|
119
119
|
export function convertToJsonObj(cc: ClassConverter, obj: any): any {
|
|
120
|
-
// Bigint is a primitive type that needs special handling since it's not
|
|
120
|
+
// Bigint is a primitive type that needs special handling since it's not serializable
|
|
121
121
|
if (typeof obj === 'bigint') {
|
|
122
122
|
return {
|
|
123
123
|
type: 'bigint',
|
|
@@ -20,14 +20,14 @@ export class RunningPromise {
|
|
|
20
20
|
const poll = async () => {
|
|
21
21
|
while (this.running) {
|
|
22
22
|
await this.fn();
|
|
23
|
-
await this.
|
|
23
|
+
await this.interruptibleSleep(this.pollingInterval);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
this.runningPromise = poll();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Stops the running promise, resolves any pending
|
|
30
|
+
* Stops the running promise, resolves any pending interruptible sleep,
|
|
31
31
|
* and waits for the currently executing function to complete.
|
|
32
32
|
*/
|
|
33
33
|
async stop(): Promise<void> {
|
|
@@ -41,7 +41,7 @@ export class RunningPromise {
|
|
|
41
41
|
* The sleep duration is determined by 'timeInMs', and it can be terminated early if the 'interruptPromise' is resolved.
|
|
42
42
|
* @param timeInMs - The time in milliseconds.
|
|
43
43
|
*/
|
|
44
|
-
private async
|
|
44
|
+
private async interruptibleSleep(timeInMs: number) {
|
|
45
45
|
let timeout!: NodeJS.Timeout;
|
|
46
46
|
const sleepPromise = new Promise(resolve => {
|
|
47
47
|
timeout = setTimeout(resolve, timeInMs);
|
package/src/sleep/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { InterruptError } from '../errors/index.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* InterruptibleSleep is a utility class that allows you to create an interruptible sleep function.
|
|
5
5
|
* The sleep function can be interrupted at any time by calling the `interrupt` method, which can
|
|
6
6
|
* also specify whether the sleep should throw an error or just return. This is useful when you need
|
|
7
7
|
* to terminate long-running processes or perform cleanup tasks in response to external events.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
|
-
* const sleeper = new
|
|
10
|
+
* const sleeper = new InterruptibleSleep();
|
|
11
11
|
*
|
|
12
12
|
* async function longRunningTask() \{
|
|
13
13
|
* try \{
|
|
@@ -20,7 +20,7 @@ import { InterruptError } from '../errors/index.js';
|
|
|
20
20
|
*
|
|
21
21
|
* setTimeout(() =\> sleeper.interrupt(true), 1500); // Interrupt the sleep after 1.5 seconds
|
|
22
22
|
*/
|
|
23
|
-
export class
|
|
23
|
+
export class InterruptibleSleep {
|
|
24
24
|
private interruptResolve: (shouldThrow: boolean) => void = () => {};
|
|
25
25
|
private interruptPromise = new Promise<boolean>(resolve => (this.interruptResolve = resolve));
|
|
26
26
|
private timeouts: NodeJS.Timeout[] = [];
|
|
@@ -61,7 +61,7 @@ export class InterruptableSleep {
|
|
|
61
61
|
/**
|
|
62
62
|
* Puts the current execution context to sleep for a specified duration.
|
|
63
63
|
* This simulates a blocking sleep operation by using an asynchronous function and a Promise that resolves after the given duration.
|
|
64
|
-
* The sleep function can be interrupted by the 'interrupt' method of the
|
|
64
|
+
* The sleep function can be interrupted by the 'interrupt' method of the InterruptibleSleep class.
|
|
65
65
|
*
|
|
66
66
|
* @param ms - The duration in milliseconds for which the sleep operation should last.
|
|
67
67
|
* @returns A Promise that resolves after the specified duration, allowing the use of 'await' to pause execution.
|