Build WebAssembly data oracles that fetch external data for Newton Protocol policy evaluation
Data oracles are WebAssembly (WASM) components that fetch or compute external data at evaluation time. The Newton network executes your WASM, and the output is fed into your Rego policy as data.data.
export function run(wasm_args) { const args = JSON.parse(wasm_args); // Example: fetch an external API const response = httpFetch({ url: `https://api.example.com/data?symbol=${args.base_symbol}`, method: "GET", headers: [["Accept", "application/json"]], body: null, }); if (response.status !== 200) { return JSON.stringify({ error: "API request failed" }); } const body = JSON.parse( new TextDecoder().decode(new Uint8Array(response.body)) ); return JSON.stringify({ price: body.price, symbol: args.base_symbol, timestamp: Date.now(), });}
The httpFetch function is provided by the Newton WASM runtime — you do not need to import it. It maps to the http.fetch function defined in the WIT interface.