@aztec-foundation/bb-avm-sim 0.0.1-commit.b66364b
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 +29 -0
- package/dest/bin.d.ts +3 -0
- package/dest/bin.d.ts.map +1 -0
- package/dest/bin.js +15 -0
- package/dest/generated/api_types.d.ts +54 -0
- package/dest/generated/api_types.d.ts.map +1 -0
- package/dest/generated/api_types.js +123 -0
- package/dest/generated/async.d.ts +15 -0
- package/dest/generated/async.d.ts.map +1 -0
- package/dest/generated/async.js +43 -0
- package/dest/generated/sync.d.ts +15 -0
- package/dest/generated/sync.d.ts.map +1 -0
- package/dest/generated/sync.js +41 -0
- package/dest/index.d.ts +36 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +45 -0
- package/dest/platform.d.ts +4 -0
- package/dest/platform.d.ts.map +1 -0
- package/dest/platform.js +57 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @aztec-foundation/bb-avm-sim
|
|
2
|
+
|
|
3
|
+
Generated TypeScript IPC package for the Avm service.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { AvmService } from '@aztec-foundation/bb-avm-sim';
|
|
7
|
+
|
|
8
|
+
const service = await AvmService.spawn({ transport: 'uds' });
|
|
9
|
+
try {
|
|
10
|
+
const response = await service.bytes({ data: new Uint8Array([1, 2, 3]) });
|
|
11
|
+
} finally {
|
|
12
|
+
await service.destroy();
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The package resolves `bb-avm-sim` from `BB_AVM_SIM_PATH`,
|
|
17
|
+
an explicit `binaryPath`, or an installed/prepared arch package.
|
|
18
|
+
|
|
19
|
+
## Build
|
|
20
|
+
|
|
21
|
+
The package shell (package.json, tsconfig, src/index.ts, scripts/) is
|
|
22
|
+
generated; build through the owning project's `./bootstrap.sh`, which
|
|
23
|
+
regenerates and then runs `npm install --omit=optional && npm run build`.
|
|
24
|
+
|
|
25
|
+
To prepare per-architecture binary packages:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
npm run prepare_arch_packages -- linux-x64=/path/to/bb-avm-sim
|
|
29
|
+
```
|
package/dest/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dest/bin.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { findAvmBinary } from './platform.js';
|
|
4
|
+
const binaryPath = findAvmBinary();
|
|
5
|
+
if (!binaryPath) {
|
|
6
|
+
console.error("bb-avm-sim: native binary not found. Install the matching " +
|
|
7
|
+
"'@aztec-foundation/bb-avm-sim-<platform>' package, set BB_AVM_SIM_PATH, or pass its path.");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
|
|
11
|
+
if (result.error) {
|
|
12
|
+
console.error(result.error.message);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
process.exit(result.status ?? 1);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Schema version hash for compatibility checking */
|
|
2
|
+
export declare const SCHEMA_HASH = "b78dac843cac6b68df35236452e452f348f5dde3a205084e9b6a79da690eb6af";
|
|
3
|
+
export interface AvmSimulate {
|
|
4
|
+
inputs: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export interface AvmSimulateWithHints {
|
|
7
|
+
inputs: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface AvmSimulateResponse {
|
|
10
|
+
result: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export interface AvmSimulateWithHintsResponse {
|
|
13
|
+
result: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
export interface AvmErrorResponse {
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
interface MsgpackAvmSimulate {
|
|
19
|
+
inputs: Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
interface MsgpackAvmSimulateWithHints {
|
|
22
|
+
inputs: Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
interface MsgpackAvmSimulateResponse {
|
|
25
|
+
result: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
interface MsgpackAvmSimulateWithHintsResponse {
|
|
28
|
+
result: Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
interface MsgpackAvmErrorResponse {
|
|
31
|
+
message: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function toAvmSimulate(o: MsgpackAvmSimulate): AvmSimulate;
|
|
34
|
+
export declare function toAvmSimulateWithHints(o: MsgpackAvmSimulateWithHints): AvmSimulateWithHints;
|
|
35
|
+
export declare function toAvmSimulateResponse(o: MsgpackAvmSimulateResponse): AvmSimulateResponse;
|
|
36
|
+
export declare function toAvmSimulateWithHintsResponse(o: MsgpackAvmSimulateWithHintsResponse): AvmSimulateWithHintsResponse;
|
|
37
|
+
export declare function toAvmErrorResponse(o: MsgpackAvmErrorResponse): AvmErrorResponse;
|
|
38
|
+
export declare function fromAvmSimulate(o: AvmSimulate): MsgpackAvmSimulate;
|
|
39
|
+
export declare function fromAvmSimulateWithHints(o: AvmSimulateWithHints): MsgpackAvmSimulateWithHints;
|
|
40
|
+
export declare function fromAvmSimulateResponse(o: AvmSimulateResponse): MsgpackAvmSimulateResponse;
|
|
41
|
+
export declare function fromAvmSimulateWithHintsResponse(o: AvmSimulateWithHintsResponse): MsgpackAvmSimulateWithHintsResponse;
|
|
42
|
+
export declare function fromAvmErrorResponse(o: AvmErrorResponse): MsgpackAvmErrorResponse;
|
|
43
|
+
export interface AsyncApiBase {
|
|
44
|
+
simulate(command: AvmSimulate): Promise<AvmSimulateResponse>;
|
|
45
|
+
simulateWithHints(command: AvmSimulateWithHints): Promise<AvmSimulateWithHintsResponse>;
|
|
46
|
+
destroy(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export interface SyncApiBase {
|
|
49
|
+
simulate(command: AvmSimulate): AvmSimulateResponse;
|
|
50
|
+
simulateWithHints(command: AvmSimulateWithHints): AvmSimulateWithHintsResponse;
|
|
51
|
+
destroy(): void;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=api_types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api_types.d.ts","sourceRoot":"","sources":["../../src/generated/api_types.ts"],"names":[],"mappings":"AAEA,qDAAqD;AACrD,eAAO,MAAM,WAAW,qEAAqE,CAAC;AAsC9F,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,UAAU,2BAA2B;IACnC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,UAAU,0BAA0B;IAClC,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,UAAU,mCAAmC;IAC3C,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,UAAU,uBAAuB;IAC/B,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAKhE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,2BAA2B,GAAG,oBAAoB,CAK3F;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,0BAA0B,GAAG,mBAAmB,CAKxF;AAED,wBAAgB,8BAA8B,CAAC,CAAC,EAAE,mCAAmC,GAAG,4BAA4B,CAKnH;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,uBAAuB,GAAG,gBAAgB,CAK/E;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,GAAG,kBAAkB,CAKlE;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,oBAAoB,GAAG,2BAA2B,CAK7F;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,mBAAmB,GAAG,0BAA0B,CAK1F;AAED,wBAAgB,gCAAgC,CAAC,CAAC,EAAE,4BAA4B,GAAG,mCAAmC,CAKrH;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAKjF;AAGD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7D,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACxF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,mBAAmB,CAAC;IACpD,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAC/E,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// AUTOGENERATED FILE - DO NOT EDIT
|
|
2
|
+
/** Schema version hash for compatibility checking */
|
|
3
|
+
export const SCHEMA_HASH = 'b78dac843cac6b68df35236452e452f348f5dde3a205084e9b6a79da690eb6af';
|
|
4
|
+
// Runtime guards for wire types that JS cannot represent natively.
|
|
5
|
+
// TODO: migrate u64 fields to bigint end-to-end and drop these.
|
|
6
|
+
//
|
|
7
|
+
// Decode: msgpackr returns uint64/int64 wire values as bigint once they
|
|
8
|
+
// exceed 32 bits; values must fit in the JS safe integer range.
|
|
9
|
+
function assertU64(value, ctx) {
|
|
10
|
+
if (typeof value === "bigint") {
|
|
11
|
+
if (value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
12
|
+
throw new Error(`${ctx}: u64 value ${value} is outside JS safe integer range`);
|
|
13
|
+
}
|
|
14
|
+
return Number(value);
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
17
|
+
throw new Error(`${ctx}: u64 value ${value} is outside JS safe integer range`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
// Encode: msgpackr encodes JS numbers above 2^32 as float64, which strict
|
|
22
|
+
// u64 decoders reject; route them through bigint so the wire type stays uint.
|
|
23
|
+
function toWireU64(value, ctx) {
|
|
24
|
+
const checked = assertU64(value, ctx);
|
|
25
|
+
return checked > 0xffffffff ? BigInt(checked) : checked;
|
|
26
|
+
}
|
|
27
|
+
function assertBin32(value, ctx) {
|
|
28
|
+
if (value.length !== 32) {
|
|
29
|
+
throw new Error(`${ctx}: expected 32 bytes, got ${value.length}`);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
// Conversion functions (exported)
|
|
34
|
+
export function toAvmSimulate(o) {
|
|
35
|
+
if (o.inputs === undefined) {
|
|
36
|
+
throw new Error("Expected inputs in AvmSimulate deserialization");
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
return {
|
|
40
|
+
inputs: o.inputs,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function toAvmSimulateWithHints(o) {
|
|
44
|
+
if (o.inputs === undefined) {
|
|
45
|
+
throw new Error("Expected inputs in AvmSimulateWithHints deserialization");
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
return {
|
|
49
|
+
inputs: o.inputs,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function toAvmSimulateResponse(o) {
|
|
53
|
+
if (o.result === undefined) {
|
|
54
|
+
throw new Error("Expected result in AvmSimulateResponse deserialization");
|
|
55
|
+
}
|
|
56
|
+
;
|
|
57
|
+
return {
|
|
58
|
+
result: o.result,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function toAvmSimulateWithHintsResponse(o) {
|
|
62
|
+
if (o.result === undefined) {
|
|
63
|
+
throw new Error("Expected result in AvmSimulateWithHintsResponse deserialization");
|
|
64
|
+
}
|
|
65
|
+
;
|
|
66
|
+
return {
|
|
67
|
+
result: o.result,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function toAvmErrorResponse(o) {
|
|
71
|
+
if (o.message === undefined) {
|
|
72
|
+
throw new Error("Expected message in AvmErrorResponse deserialization");
|
|
73
|
+
}
|
|
74
|
+
;
|
|
75
|
+
return {
|
|
76
|
+
message: o.message,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export function fromAvmSimulate(o) {
|
|
80
|
+
if (o.inputs === undefined) {
|
|
81
|
+
throw new Error("Expected inputs in AvmSimulate serialization");
|
|
82
|
+
}
|
|
83
|
+
;
|
|
84
|
+
return {
|
|
85
|
+
inputs: o.inputs,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function fromAvmSimulateWithHints(o) {
|
|
89
|
+
if (o.inputs === undefined) {
|
|
90
|
+
throw new Error("Expected inputs in AvmSimulateWithHints serialization");
|
|
91
|
+
}
|
|
92
|
+
;
|
|
93
|
+
return {
|
|
94
|
+
inputs: o.inputs,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function fromAvmSimulateResponse(o) {
|
|
98
|
+
if (o.result === undefined) {
|
|
99
|
+
throw new Error("Expected result in AvmSimulateResponse serialization");
|
|
100
|
+
}
|
|
101
|
+
;
|
|
102
|
+
return {
|
|
103
|
+
result: o.result,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function fromAvmSimulateWithHintsResponse(o) {
|
|
107
|
+
if (o.result === undefined) {
|
|
108
|
+
throw new Error("Expected result in AvmSimulateWithHintsResponse serialization");
|
|
109
|
+
}
|
|
110
|
+
;
|
|
111
|
+
return {
|
|
112
|
+
result: o.result,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function fromAvmErrorResponse(o) {
|
|
116
|
+
if (o.message === undefined) {
|
|
117
|
+
throw new Error("Expected message in AvmErrorResponse serialization");
|
|
118
|
+
}
|
|
119
|
+
;
|
|
120
|
+
return {
|
|
121
|
+
message: o.message,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AsyncApiBase, AvmSimulate, AvmSimulateResponse, AvmSimulateWithHints, AvmSimulateWithHintsResponse } from './api_types.js';
|
|
2
|
+
export interface IpcClientAsync {
|
|
3
|
+
call(input: Uint8Array): Promise<Uint8Array>;
|
|
4
|
+
destroy(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export type IpcErrorFactory = (message: string) => Error;
|
|
7
|
+
export declare class AsyncApi implements AsyncApiBase {
|
|
8
|
+
protected backend: IpcClientAsync;
|
|
9
|
+
protected createError: IpcErrorFactory;
|
|
10
|
+
constructor(backend: IpcClientAsync, createError?: IpcErrorFactory);
|
|
11
|
+
simulate(command: AvmSimulate): Promise<AvmSimulateResponse>;
|
|
12
|
+
simulateWithHints(command: AvmSimulateWithHints): Promise<AvmSimulateWithHintsResponse>;
|
|
13
|
+
destroy(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/generated/async.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,4BAA4B,EAAoG,MAAM,gBAAgB,CAAC;AAEtO,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;AAQzD,qBAAa,QAAS,YAAW,YAAY;IAEzC,SAAS,CAAC,OAAO,EAAE,cAAc;IACjC,SAAS,CAAC,WAAW,EAAE,eAAe;gBAD5B,OAAO,EAAE,cAAc,EACvB,WAAW,GAAE,eAA+C;IAGxE,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAa5D,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAavF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// AUTOGENERATED FILE - DO NOT EDIT
|
|
2
|
+
import { Decoder, Encoder } from 'msgpackr';
|
|
3
|
+
import { fromAvmSimulate, fromAvmSimulateWithHints, toAvmSimulateResponse, toAvmSimulateWithHintsResponse } from './api_types.js';
|
|
4
|
+
async function msgpackCall(backend, input) {
|
|
5
|
+
const inputBuffer = new Encoder({ useRecords: false, variableMapSize: true }).pack(input);
|
|
6
|
+
const encodedResult = await backend.call(inputBuffer);
|
|
7
|
+
return new Decoder({ useRecords: false }).unpack(encodedResult);
|
|
8
|
+
}
|
|
9
|
+
export class AsyncApi {
|
|
10
|
+
backend;
|
|
11
|
+
createError;
|
|
12
|
+
constructor(backend, createError = message => new Error(message)) {
|
|
13
|
+
this.backend = backend;
|
|
14
|
+
this.createError = createError;
|
|
15
|
+
}
|
|
16
|
+
simulate(command) {
|
|
17
|
+
const msgpackCommand = fromAvmSimulate(command);
|
|
18
|
+
return msgpackCall(this.backend, [["AvmSimulate", msgpackCommand]]).then(([variantName, result]) => {
|
|
19
|
+
if (variantName === 'AvmErrorResponse') {
|
|
20
|
+
throw this.createError(result.message || 'Unknown error from server');
|
|
21
|
+
}
|
|
22
|
+
if (variantName !== 'AvmSimulateResponse') {
|
|
23
|
+
throw new Error(`Expected variant name 'AvmSimulateResponse' but got '${variantName}'`);
|
|
24
|
+
}
|
|
25
|
+
return toAvmSimulateResponse(result);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
simulateWithHints(command) {
|
|
29
|
+
const msgpackCommand = fromAvmSimulateWithHints(command);
|
|
30
|
+
return msgpackCall(this.backend, [["AvmSimulateWithHints", msgpackCommand]]).then(([variantName, result]) => {
|
|
31
|
+
if (variantName === 'AvmErrorResponse') {
|
|
32
|
+
throw this.createError(result.message || 'Unknown error from server');
|
|
33
|
+
}
|
|
34
|
+
if (variantName !== 'AvmSimulateWithHintsResponse') {
|
|
35
|
+
throw new Error(`Expected variant name 'AvmSimulateWithHintsResponse' but got '${variantName}'`);
|
|
36
|
+
}
|
|
37
|
+
return toAvmSimulateWithHintsResponse(result);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
destroy() {
|
|
41
|
+
return this.backend.destroy();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AvmSimulate, AvmSimulateResponse, AvmSimulateWithHints, AvmSimulateWithHintsResponse, SyncApiBase } from './api_types.js';
|
|
2
|
+
export interface IpcClientSync {
|
|
3
|
+
call(input: Uint8Array): Uint8Array;
|
|
4
|
+
destroy(): void;
|
|
5
|
+
}
|
|
6
|
+
export type IpcErrorFactory = (message: string) => Error;
|
|
7
|
+
export declare class SyncApi implements SyncApiBase {
|
|
8
|
+
protected backend: IpcClientSync;
|
|
9
|
+
protected createError: IpcErrorFactory;
|
|
10
|
+
constructor(backend: IpcClientSync, createError?: IpcErrorFactory);
|
|
11
|
+
simulate(command: AvmSimulate): AvmSimulateResponse;
|
|
12
|
+
simulateWithHints(command: AvmSimulateWithHints): AvmSimulateWithHintsResponse;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/generated/sync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,WAAW,EAAoG,MAAM,gBAAgB,CAAC;AAErO,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC;IACpC,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;AAQzD,qBAAa,OAAQ,YAAW,WAAW;IAEvC,SAAS,CAAC,OAAO,EAAE,aAAa;IAChC,SAAS,CAAC,WAAW,EAAE,eAAe;gBAD5B,OAAO,EAAE,aAAa,EACtB,WAAW,GAAE,eAA+C;IAGxE,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,mBAAmB;IAYnD,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,4BAA4B;IAY9E,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// AUTOGENERATED FILE - DO NOT EDIT
|
|
2
|
+
import { Decoder, Encoder } from 'msgpackr';
|
|
3
|
+
import { fromAvmSimulate, fromAvmSimulateWithHints, toAvmSimulateResponse, toAvmSimulateWithHintsResponse } from './api_types.js';
|
|
4
|
+
function msgpackCall(backend, input) {
|
|
5
|
+
const inputBuffer = new Encoder({ useRecords: false, variableMapSize: true }).pack(input);
|
|
6
|
+
const encodedResult = backend.call(inputBuffer);
|
|
7
|
+
return new Decoder({ useRecords: false }).unpack(encodedResult);
|
|
8
|
+
}
|
|
9
|
+
export class SyncApi {
|
|
10
|
+
backend;
|
|
11
|
+
createError;
|
|
12
|
+
constructor(backend, createError = message => new Error(message)) {
|
|
13
|
+
this.backend = backend;
|
|
14
|
+
this.createError = createError;
|
|
15
|
+
}
|
|
16
|
+
simulate(command) {
|
|
17
|
+
const msgpackCommand = fromAvmSimulate(command);
|
|
18
|
+
const [variantName, result] = msgpackCall(this.backend, [["AvmSimulate", msgpackCommand]]);
|
|
19
|
+
if (variantName === 'AvmErrorResponse') {
|
|
20
|
+
throw this.createError(result.message || 'Unknown error from server');
|
|
21
|
+
}
|
|
22
|
+
if (variantName !== 'AvmSimulateResponse') {
|
|
23
|
+
throw new Error(`Expected variant name 'AvmSimulateResponse' but got '${variantName}'`);
|
|
24
|
+
}
|
|
25
|
+
return toAvmSimulateResponse(result);
|
|
26
|
+
}
|
|
27
|
+
simulateWithHints(command) {
|
|
28
|
+
const msgpackCommand = fromAvmSimulateWithHints(command);
|
|
29
|
+
const [variantName, result] = msgpackCall(this.backend, [["AvmSimulateWithHints", msgpackCommand]]);
|
|
30
|
+
if (variantName === 'AvmErrorResponse') {
|
|
31
|
+
throw this.createError(result.message || 'Unknown error from server');
|
|
32
|
+
}
|
|
33
|
+
if (variantName !== 'AvmSimulateWithHintsResponse') {
|
|
34
|
+
throw new Error(`Expected variant name 'AvmSimulateWithHintsResponse' but got '${variantName}'`);
|
|
35
|
+
}
|
|
36
|
+
return toAvmSimulateWithHintsResponse(result);
|
|
37
|
+
}
|
|
38
|
+
destroy() {
|
|
39
|
+
this.backend.destroy();
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dest/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AsyncApi, type IpcErrorFactory } from './generated/async.js';
|
|
2
|
+
export * from './generated/api_types.js';
|
|
3
|
+
export { AsyncApi } from './generated/async.js';
|
|
4
|
+
export { SyncApi } from './generated/sync.js';
|
|
5
|
+
export type AvmTransport = 'uds';
|
|
6
|
+
export interface AvmServiceOptions {
|
|
7
|
+
binaryPath?: string;
|
|
8
|
+
transport?: AvmTransport;
|
|
9
|
+
logger?: (msg: string) => void;
|
|
10
|
+
connectTimeoutMs?: number;
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
extraArgs?: string[];
|
|
13
|
+
createError?: IpcErrorFactory;
|
|
14
|
+
/**
|
|
15
|
+
* Respawn the server on the next call after it dies, instead of failing all
|
|
16
|
+
* subsequent calls. Only enable for stateless servers: a respawned process
|
|
17
|
+
* remembers nothing, so any server-side session state held by callers would
|
|
18
|
+
* silently dangle.
|
|
19
|
+
*/
|
|
20
|
+
respawn?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Spawns and talks to a 'bb-avm-sim' server process. Process
|
|
24
|
+
* lifecycle — connectivity, death detection, optional respawn, teardown — is
|
|
25
|
+
* owned by the backend (see SpawnedProcessBackend in ipc-runtime); it never
|
|
26
|
+
* leaks onto this API. Failed calls carry a 'retry' property set to true when
|
|
27
|
+
* the failure was environmental and the operation may be retried.
|
|
28
|
+
*/
|
|
29
|
+
export declare class AvmService extends AsyncApi {
|
|
30
|
+
private spawnedBackend;
|
|
31
|
+
private constructor();
|
|
32
|
+
static spawn(options?: AvmServiceOptions): Promise<AvmService>;
|
|
33
|
+
getIpcPath(): string;
|
|
34
|
+
sendProcessSignal(signal: NodeJS.Signals): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGtE,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC;AAEjC,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IAClB,OAAO,CAAC,cAAc;IAA1C,OAAO;WAIM,KAAK,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,CAAC;IAoBxE,UAAU,IAAI,MAAM;IAIpB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI;CAGhD"}
|
package/dest/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { IpcSpawnError, SpawnedProcessBackend } from '@aztec-foundation/ipc-runtime';
|
|
2
|
+
import { AsyncApi } from './generated/async.js';
|
|
3
|
+
import { findAvmBinary } from './platform.js';
|
|
4
|
+
export * from './generated/api_types.js';
|
|
5
|
+
export { AsyncApi } from './generated/async.js';
|
|
6
|
+
export { SyncApi } from './generated/sync.js';
|
|
7
|
+
/**
|
|
8
|
+
* Spawns and talks to a 'bb-avm-sim' server process. Process
|
|
9
|
+
* lifecycle — connectivity, death detection, optional respawn, teardown — is
|
|
10
|
+
* owned by the backend (see SpawnedProcessBackend in ipc-runtime); it never
|
|
11
|
+
* leaks onto this API. Failed calls carry a 'retry' property set to true when
|
|
12
|
+
* the failure was environmental and the operation may be retried.
|
|
13
|
+
*/
|
|
14
|
+
export class AvmService extends AsyncApi {
|
|
15
|
+
spawnedBackend;
|
|
16
|
+
constructor(spawnedBackend, createError) {
|
|
17
|
+
super(spawnedBackend, createError);
|
|
18
|
+
this.spawnedBackend = spawnedBackend;
|
|
19
|
+
}
|
|
20
|
+
static async spawn(options = {}) {
|
|
21
|
+
const binaryPath = findAvmBinary(options.binaryPath);
|
|
22
|
+
if (!binaryPath) {
|
|
23
|
+
throw new IpcSpawnError('bb-avm-sim binary not found', /*retry=*/ false);
|
|
24
|
+
}
|
|
25
|
+
const backend = await SpawnedProcessBackend.spawn({
|
|
26
|
+
binaryPath,
|
|
27
|
+
binaryName: 'bb-avm-sim',
|
|
28
|
+
instancePrefix: 'avm',
|
|
29
|
+
ipcPathArgs: ["msgpack", "run", "--input", "{path}"],
|
|
30
|
+
transport: options.transport ?? 'uds',
|
|
31
|
+
logger: options.logger,
|
|
32
|
+
connectTimeoutMs: options.connectTimeoutMs,
|
|
33
|
+
env: options.env,
|
|
34
|
+
extraArgs: options.extraArgs,
|
|
35
|
+
respawn: options.respawn,
|
|
36
|
+
});
|
|
37
|
+
return new AvmService(backend, options.createError);
|
|
38
|
+
}
|
|
39
|
+
getIpcPath() {
|
|
40
|
+
return this.spawnedBackend.getIpcPath();
|
|
41
|
+
}
|
|
42
|
+
sendProcessSignal(signal) {
|
|
43
|
+
this.spawnedBackend.sendProcessSignal(signal);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,eAAe,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAgC7F,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwBhE;AAED,eAAO,MAAM,iBAAiB,eAAe,CAAC"}
|
package/dest/platform.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
const PLATFORM_TO_PACKAGE = {
|
|
6
|
+
'x86_64-linux': '@aztec-foundation/bb-avm-sim-linux-x64',
|
|
7
|
+
'x86_64-darwin': '@aztec-foundation/bb-avm-sim-darwin-x64',
|
|
8
|
+
'aarch64-linux': '@aztec-foundation/bb-avm-sim-linux-arm64',
|
|
9
|
+
'aarch64-darwin': '@aztec-foundation/bb-avm-sim-darwin-arm64',
|
|
10
|
+
};
|
|
11
|
+
function currentDir() {
|
|
12
|
+
return path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
}
|
|
14
|
+
function detectPlatform() {
|
|
15
|
+
if (process.arch === 'x64' && process.platform === 'linux')
|
|
16
|
+
return 'x86_64-linux';
|
|
17
|
+
if (process.arch === 'x64' && process.platform === 'darwin')
|
|
18
|
+
return 'x86_64-darwin';
|
|
19
|
+
if (process.arch === 'arm64' && process.platform === 'linux')
|
|
20
|
+
return 'aarch64-linux';
|
|
21
|
+
if (process.arch === 'arm64' && process.platform === 'darwin')
|
|
22
|
+
return 'aarch64-darwin';
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
function findArchPackageDir(platform) {
|
|
26
|
+
const packageName = PLATFORM_TO_PACKAGE[platform];
|
|
27
|
+
try {
|
|
28
|
+
const require = createRequire(import.meta.url);
|
|
29
|
+
return path.dirname(require.resolve(packageName + '/package.json'));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
const siblingPackageDir = path.join(currentDir(), '..', 'packages', packageName.split('/').pop());
|
|
33
|
+
return fs.existsSync(path.join(siblingPackageDir, 'package.json')) ? siblingPackageDir : null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function findAvmBinary(customPath) {
|
|
37
|
+
if (customPath) {
|
|
38
|
+
return fs.existsSync(customPath) ? path.resolve(customPath) : null;
|
|
39
|
+
}
|
|
40
|
+
const envPath = process.env.BB_AVM_SIM_PATH;
|
|
41
|
+
if (envPath) {
|
|
42
|
+
return fs.existsSync(envPath) ? path.resolve(envPath) : null;
|
|
43
|
+
}
|
|
44
|
+
const platform = detectPlatform();
|
|
45
|
+
if (!platform) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const archDir = findArchPackageDir(platform);
|
|
49
|
+
if (archDir) {
|
|
50
|
+
const candidate = path.join(archDir, 'bb-avm-sim');
|
|
51
|
+
if (fs.existsSync(candidate)) {
|
|
52
|
+
return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
export const ARCH_PACKAGE_STEM = 'bb-avm-sim';
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec-foundation/bb-avm-sim",
|
|
3
|
+
"version": "0.0.1-commit.b66364b",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"bb-avm-sim": "./dest/bin.js"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dest/index.d.ts",
|
|
11
|
+
"default": "./dest/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dest/",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf dest .tsbuildinfo",
|
|
20
|
+
"build": "tsc -p tsconfig.json",
|
|
21
|
+
"prepare_arch_packages": "./scripts/prepare_arch_packages.sh"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@aztec-foundation/ipc-runtime": "0.0.1-commit.b66364b",
|
|
25
|
+
"msgpackr": "^1.11.2",
|
|
26
|
+
"tslib": "^2.4.0"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"@aztec-foundation/bb-avm-sim-linux-x64": "0.0.1-commit.b66364b",
|
|
30
|
+
"@aztec-foundation/bb-avm-sim-darwin-x64": "0.0.1-commit.b66364b",
|
|
31
|
+
"@aztec-foundation/bb-avm-sim-linux-arm64": "0.0.1-commit.b66364b",
|
|
32
|
+
"@aztec-foundation/bb-avm-sim-darwin-arm64": "0.0.1-commit.b66364b"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.15.17",
|
|
36
|
+
"typescript": "^5.3.3"
|
|
37
|
+
}
|
|
38
|
+
}
|