diff --git a/ant/README.md b/ant/README.md index 95245cea..11b5cbd9 100644 --- a/ant/README.md +++ b/ant/README.md @@ -8,7 +8,7 @@ Using the ao-dev-cli. #### Install ```sh -curl -L https://arweave.net/BVhXa-OCcQV6xuhsoS6207uHkXcRz4UmR5xvQct1GXI | bash +curl -L https://arweave.net/iVthglhSN7G9LuJSU_h5Wy_lcEa0RE4VQmrtoBMj7Bw | bash ``` diff --git a/ant/package.json b/ant/package.json new file mode 100644 index 00000000..b4b36e08 --- /dev/null +++ b/ant/package.json @@ -0,0 +1,14 @@ +{ + "dependencies": { + "@permaweb/ao-loader": "^0.0.35", + "@permaweb/aoconnect": "^0.0.55", + "arweave": "^1.15.1" + }, + "type": "module", + "scripts": { + "build": "cd src && ao build && cd .. && yarn load-process", + "deploy": "cd src && ao publish process.wasm -w ../tools/key.json --tag=\"Memory-Limit\" --value=\"1-gb\" --tag=\"Compute-Limit\" --value=\"9000000000000\" && cd ..", + "load-process": "node tools/load-process.cjs", + "spawn": "node tools/spawn-ant.cjs" + } +} diff --git a/ant/src/initialize.lua b/ant/src/initialize.lua index 5eb7366d..6e7c007c 100644 --- a/ant/src/initialize.lua +++ b/ant/src/initialize.lua @@ -58,7 +58,7 @@ end function initialize.initializeProcessState(msg, env) if not Seeded then --math.randomseed(1234) - chance.seed(tonumber(msg["Block-Height"] .. stringToSeed(msg.Owner .. msg.Module .. msg.Id))) + chance.seed(tonumber(msg["Block-Height"] .. stringToSeed(msg.Owner .. env.Module.Id .. msg.Id))) math.random = function(...) local args = { ... } local n = #args diff --git a/ant/src/process.lua b/ant/src/process.lua index d1c168d6..ea6a5ae1 100644 --- a/ant/src/process.lua +++ b/ant/src/process.lua @@ -1,5 +1,5 @@ -- lib -Handlers = require(".handlers") +Handlers = Handlers or require(".handlers") local _ao = require("ao") local process = { _version = "0.2.0" } @@ -65,6 +65,7 @@ end function process.handle(msg, ao) ao.id = ao.env.Process.Id + print(json.encode(ao.env)) initialize.initializeProcessState(msg, ao.env) -- tagify msg @@ -83,7 +84,8 @@ function process.handle(msg, ao) ao.clearOutbox() -- Only trust messages from a signed owner or an Authority - if msg.From ~= msg.Owner and not ao.isTrusted(msg) then + -- skip this check for test messages in dev + if msg.Owner ~= "test" and msg.From ~= msg.Owner and not ao.isTrusted(msg) then Send({ Target = msg.From, Data = "Message is not trusted by this process!" }) print("Message is not trusted! From: " .. msg.From .. " - Owner: " .. msg.Owner) return ao.result({}) @@ -259,7 +261,8 @@ function process.handle(msg, ao) return utils.reply(permissionErr) end local tags = msg.Tags - local name, transactionId, ttlSeconds = tags["Sub-Domain"], tags["Transaction-Id"], tags["TTL-Seconds"] + local name, transactionId, ttlSeconds = + tags["Sub-Domain"], tags["Transaction-Id"], tonumber(tags["TTL-Seconds"]) local setRecordStatus, setRecordResult = pcall(records.setRecord, name, transactionId, ttlSeconds) if not setRecordStatus then return utils.reply(setRecordResult) diff --git a/ant/src/process.wasm b/ant/src/process.wasm index 0b2a8169..8f115bb6 100755 Binary files a/ant/src/process.wasm and b/ant/src/process.wasm differ diff --git a/ant/tools/load-process.cjs b/ant/tools/load-process.cjs new file mode 100644 index 00000000..a64863d6 --- /dev/null +++ b/ant/tools/load-process.cjs @@ -0,0 +1,50 @@ +const AoLoader = require( "@permaweb/ao-loader"); +const fs = require('fs'); +const path = require('path'); + +/* ao READ-ONLY Env Variables */ +const env = { + + Process: { + Id: "2", + Tags: [ + { name: "Authority", value: "XXXXXX" }, + ], + }, + Module: { + Id: "1", + Tags: [ + { name: "Authority", value: "YYYYYY" }, + ], + }, +}; + +async function main() { + +const wasmBinary = fs.readFileSync(path.join(__dirname, '../src/process.wasm') ); +// Create the handle function that executes the Wasm +const handle = await AoLoader(wasmBinary, { + format: "wasm32-unknown-emscripten", + inputEncoding: "JSON-1", + outputEncoding: "JSON-1", + memoryLimit: "524288000", // in bytes + computeLimit: 9e12.toString(), + extensions: [] +}); + +// To spawn a process, pass null as the buffer +const result = await handle(null, { + Id: "3", + ["Block-Height"]: "1", + // TEST INDICATES NOT TO RUN AUTHORITY CHECKS + Owner: "test", + Target: "XXXXX", + From: "YYYYYY", + Tags: [ + { name: "Action", value: "Set-Controller" }, + { name: "Controller", value: "".padEnd(43, '1') }, + ], +}, env); + +console.dir(result, { depth: null}); +} main(); \ No newline at end of file diff --git a/ant/tools/spawn-ant.cjs b/ant/tools/spawn-ant.cjs new file mode 100644 index 00000000..aeebc676 --- /dev/null +++ b/ant/tools/spawn-ant.cjs @@ -0,0 +1,68 @@ +const { connect, createDataItemSigner } = require( '@permaweb/aoconnect') +const fs = require('fs') +const path = require('path') +const Arweave = require('arweave') + + +const arweave = Arweave.init({ + host: 'arweave.net', + port: 443, + protocol: 'https', +}) + +const ao = connect({ + GATEWAY_URL: "https://arweave.net", +}) +const moduleId = "I1ecao-MFgB-0Kqhr83uYmQp9wdb5z-A-GsQmsCAkdk" +const scheduler = "_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA" + +async function main() { + + const wallet = fs.readFileSync(path.join(__dirname, 'key.json'), 'utf-8') + const address = await arweave.wallets.jwkToAddress(JSON.parse(wallet)) + const signer = createDataItemSigner(JSON.parse(wallet)) + + // const processId = await ao.spawn({ + // module: moduleId, + // scheduler, + // signer + // }) + const processId = "0lF7QU7EgNt4t5iiHOu32zEkR4zN1duAKwIzpSJ_bJ0" + console.log("Process ID:", processId) + console.log("Waiting 20 seconds to ensure process is readied.") + await new Promise((resolve) => setTimeout(resolve, 20_000)) + console.log("Continuing...") + + const testCases = [ + ["Set-Controller", {"Controller": "".padEnd(43, "1")}], + ["Remove-Controller", {"Controller": "".padEnd(43, "1")}], + ["Set-Name", {"Name": "Test Name"}], + ["Set-Ticker", {"Ticker": "TEST"}], + ["Set-Record", {"Transaction-Id": "".padEnd(43, '1'), "TTL-Seconds": "1000", "Sub-Domain": "@"}], + ["Set-Record", {"Transaction-Id": "".padEnd(43, '1'), "TTL-Seconds": "1000", "Sub-Domain": "bob"}], + ["Remove-Record", {"Sub-Domain": "bob"}], + ["Balance", {}], + ["Balance", {"Recipient": address}], + ["Balances", {}], + ["Get-Controllers", {}], + ["Get-Records", {}], + ["Get-Record", {"Sub-Domain": "@"}], + ] + + for (const [method, args] of testCases) { + const tags = args ? Object.entries(args).map(([key, value]) => ({name: key, value})) : [] + const result = await ao.dryrun({ + process: processId, + tags: [ + ...tags, + {name: "Action", value: method} + ], + signer + }) + + console.log(result) + } + +} + +main() \ No newline at end of file diff --git a/ant/yarn.lock b/ant/yarn.lock new file mode 100644 index 00000000..d0347778 --- /dev/null +++ b/ant/yarn.lock @@ -0,0 +1,185 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@fastify/busboy@^2.0.0": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" + integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== + +"@permaweb/ao-loader@^0.0.35": + version "0.0.35" + resolved "https://registry.yarnpkg.com/@permaweb/ao-loader/-/ao-loader-0.0.35.tgz#b525f70f3fda620148b245b8b6872c3d500348aa" + integrity sha512-vgDs2PYJqiKYnEVHYccP5VOjc+YkcinYW8YQa53fxYzy4D/KEWwiMnocz3zNb7L+6dKNT6EghHft7xMcs01WMQ== + +"@permaweb/ao-scheduler-utils@~0.0.16": + version "0.0.19" + resolved "https://registry.yarnpkg.com/@permaweb/ao-scheduler-utils/-/ao-scheduler-utils-0.0.19.tgz#69d35c19583624ace3f500f53b4b4d73fca883e1" + integrity sha512-xwIe9FqQ1UZxEYWvSGJDONz0xr4vDq2Ny1NeRUiO0dKYoonShN+oI1ULgrHocKOjOPNEgRX70vMCKGLe+3x70A== + dependencies: + lru-cache "^10.2.2" + ramda "^0.30.0" + zod "^3.23.5" + +"@permaweb/aoconnect@^0.0.55": + version "0.0.55" + resolved "https://registry.yarnpkg.com/@permaweb/aoconnect/-/aoconnect-0.0.55.tgz#d856a078d3702154ac58541d09478d25ed3acf2c" + integrity sha512-W2GtLZedVseuDkCKk4CmM9SFmi0DdrMKqvhMBm9xo65z+Mzr/t1TEjMJKRNzEA2qh5IdwM43sWJ5fmbBYLg6TQ== + dependencies: + "@permaweb/ao-scheduler-utils" "~0.0.16" + buffer "^6.0.3" + debug "^4.3.4" + hyper-async "^1.1.2" + mnemonist "^0.39.8" + ramda "^0.29.1" + warp-arbundles "^1.0.4" + zod "^3.22.4" + +arconnect@^0.4.2: + version "0.4.2" + resolved "https://registry.yarnpkg.com/arconnect/-/arconnect-0.4.2.tgz#83de7638fb46183e82d7ec7efb5594c5f7cdc806" + integrity sha512-Jkpd4QL3TVqnd3U683gzXmZUVqBUy17DdJDuL/3D9rkysLgX6ymJ2e+sR+xyZF5Rh42CBqDXWNMmCjBXeP7Gbw== + dependencies: + arweave "^1.10.13" + +arweave@^1.10.13, arweave@^1.13.7, arweave@^1.15.1: + version "1.15.1" + resolved "https://registry.yarnpkg.com/arweave/-/arweave-1.15.1.tgz#c6183136b20980c81a8cb77ce6fd9fb333e1a174" + integrity sha512-rT7FOwqdudd5npqp4xOYdDT2035LtpcqePjwirh4wjRiEtVsz1FZkRiM2Yj+fOAwYzOm/hNG0GDOipDSaiEGGQ== + dependencies: + arconnect "^0.4.2" + asn1.js "^5.4.1" + base64-js "^1.5.1" + bignumber.js "^9.0.2" + +asn1.js@^5.4.1: + version "5.4.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-5.4.1.tgz#11a980b84ebb91781ce35b0fdc2ee294e3783f07" + integrity sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA== + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + safer-buffer "^2.1.0" + +base64-js@^1.3.1, base64-js@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" + integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== + +base64url@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/base64url/-/base64url-3.0.1.tgz#6399d572e2bc3f90a9a8b22d5dbb0a32d33f788d" + integrity sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A== + +bignumber.js@^9.0.2: + version "9.1.2" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c" + integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug== + +bn.js@^4.0.0: + version "4.12.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" + integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== + +buffer@^6.0.3: + version "6.0.3" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" + integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== + dependencies: + base64-js "^1.3.1" + ieee754 "^1.2.1" + +debug@^4.3.4: + version "4.3.5" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e" + integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg== + dependencies: + ms "2.1.2" + +hyper-async@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/hyper-async/-/hyper-async-1.1.2.tgz#b9a83be36e726bface6f4a5b84f1a1a25bf19e6a" + integrity sha512-cnpOgKa+5FZOaccTtjduac1FrZuSc38/ftCp3vYJdUMt+7c+uvGDKLDK4MTNK8D3aFjIeveVrPcSgUPvzZLopg== + +ieee754@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" + integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== + +inherits@^2.0.1: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +lru-cache@^10.2.2: + version "10.2.2" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878" + integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ== + +minimalistic-assert@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" + integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A== + +mnemonist@^0.39.8: + version "0.39.8" + resolved "https://registry.yarnpkg.com/mnemonist/-/mnemonist-0.39.8.tgz#9078cd8386081afd986cca34b52b5d84ea7a4d38" + integrity sha512-vyWo2K3fjrUw8YeeZ1zF0fy6Mu59RHokURlld8ymdUPjMlD9EC9ov1/YPqTgqRvUN9nTr3Gqfz29LYAmu0PHPQ== + dependencies: + obliterator "^2.0.1" + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +obliterator@^2.0.1: + version "2.0.4" + resolved "https://registry.yarnpkg.com/obliterator/-/obliterator-2.0.4.tgz#fa650e019b2d075d745e44f1effeb13a2adbe816" + integrity sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ== + +ramda@^0.29.1: + version "0.29.1" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.29.1.tgz#408a6165b9555b7ba2fc62555804b6c5a2eca196" + integrity sha512-OfxIeWzd4xdUNxlWhgFazxsA/nl3mS4/jGZI5n00uWOoSSFRhC1b6gl6xvmzUamgmqELraWp0J/qqVlXYPDPyA== + +ramda@^0.30.0: + version "0.30.1" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.30.1.tgz#7108ac95673062b060025052cd5143ae8fc605bf" + integrity sha512-tEF5I22zJnuclswcZMc8bDIrwRHRzf+NqVEmqg50ShAZMP7MWeR/RGDthfM/p+BlqvF2fXAzpn8i+SJcYD3alw== + +safer-buffer@^2.1.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + +undici@^5.19.1: + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== + dependencies: + "@fastify/busboy" "^2.0.0" + +warp-arbundles@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/warp-arbundles/-/warp-arbundles-1.0.4.tgz#10c0cd662ab41b0dabad9159c7110f43425cc5cc" + integrity sha512-KeRac/EJ7VOK+v5+PSMh2SrzpCKOAFnJICLlqZWt6qPkDCzVwcrNE5wFxOlEk5U170ewMDAB3e86UHUblevXpw== + dependencies: + arweave "^1.13.7" + base64url "^3.0.1" + buffer "^6.0.3" + warp-isomorphic "^1.0.7" + +warp-isomorphic@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/warp-isomorphic/-/warp-isomorphic-1.0.7.tgz#abf1ee7bce44bec7c6b97547859e614876869aa7" + integrity sha512-fXHbUXwdYqPm9fRPz8mjv5ndPco09aMQuTe4kXfymzOq8V6F3DLsg9cIafxvjms9/mc6eijzkLBJ63yjEENEjA== + dependencies: + buffer "^6.0.3" + undici "^5.19.1" + +zod@^3.22.4, zod@^3.23.5: + version "3.23.8" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d" + integrity sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==